Skip to content

test(adapters/detect): cover config-directory branch and env-var priority chain#287

Merged
mksglu merged 7 commits intomksglu:nextfrom
sebastianbreguel:test/adapters-detect-matrix
Apr 16, 2026
Merged

test(adapters/detect): cover config-directory branch and env-var priority chain#287
mksglu merged 7 commits intomksglu:nextfrom
sebastianbreguel:test/adapters-detect-matrix

Conversation

@sebastianbreguel
Copy link
Copy Markdown
Contributor

What

Adds tests/adapters/detect-config-dir.test.ts — 18 new assertions covering the medium-confidence config-directory branch of `detectPlatform()` and the env-var priority chain.

Why

`src/adapters/detect.ts` has three detection tiers: env vars (high), config dirs (medium), fallback (low). The existing `tests/adapters/detect.test.ts` covers high-confidence detection thoroughly (env vars, clientInfo, CONTEXT_MODE_PLATFORM override, adapter dispatch) but leaves the medium-confidence branch at lines 128-210 — roughly 80 source lines — completely untested. Any reorder or removal of a config-dir check could regress platform detection for users who rely on dir-based auto-detect.

This is particularly relevant now that Pi is in-scope (per #279, #283 merged today) — its only detection path is `~/.pi/`, and until this PR it had zero test coverage.

Coverage added

Config directory branches (11 tests)

Mocks `node:fs.existsSync` via `vi.mock` to force each path.

  • 7 direct-home dirs: `/.claude`, `/.gemini`, `/.codex`, `/.cursor`, `/.kiro`, `/.pi`, `~/.openclaw`
  • 3 XDG dirs: `/.config/kilo`, `/.config/opencode`, `~/.config/zed`
  • Low-confidence claude-code fallback when no dirs exist
  • Priority: `/.claude` > `/.gemini`, env var > config dir, `CONTEXT_MODE_PLATFORM` > config dir

Env-var priority chain (4 tests)

Locks the ordering in `detect.ts`:

  • `CLAUDE_PROJECT_DIR` beats `GEMINI_CLI`
  • `GEMINI_CLI` beats `OPENCLAW_HOME`
  • `OPENCLAW_HOME` beats `KILO`
  • `CODEX_THREAD_ID` beats `CURSOR_TRACE_ID`

The existing file only tested cursor > vscode-copilot priority.

Test plan

  • `npm test -- tests/adapters/detect-config-dir.test.ts tests/adapters/detect.test.ts` → 58/58 pass
  • `npm run typecheck` → clean
  • Rebased on `next`

Pure additions, no runtime behavior changes.

h4rvey-g and others added 3 commits April 14, 2026 15:49
* feat: add Pi package manifest

* docs: update Pi install instructions

---------

Co-authored-by: Harvey Guo <harveyguo@HarveydeMac-mini.local>
…tes (mksglu#285)

test(executor): cover background mode, cleanupBackgrounded, and hardCapBytes

Three untested paths in PolyglotExecutor:
- background: true returns partial output with backgrounded flag
- cleanupBackgrounded() kills detached processes (zombie prevention)
- hardCapBytes kills process when stdout+stderr exceeds byte limit
…rity chain

The existing detect.test.ts covers env vars, clientInfo, and the
CONTEXT_MODE_PLATFORM override, but leaves the medium-confidence
config-dir branch (detect.ts:128-210, ~80 lines) completely untested.

Adds a new file that mocks `node:fs.existsSync` via `vi.mock` and
exercises each branch:

- 7 direct-home dirs: ~/.claude, ~/.gemini, ~/.codex, ~/.cursor,
  ~/.kiro, ~/.pi, ~/.openclaw
- 3 XDG dirs: ~/.config/kilo, ~/.config/opencode, ~/.config/zed
- Fallback to low-confidence claude-code when no dirs exist
- Priority locks: env var > config dir, CONTEXT_MODE_PLATFORM > config dir,
  ~/.claude > ~/.gemini ordering
- Env-var priority chain: CLAUDE > GEMINI > OPENCLAW > KILO, CODEX > CURSOR

Pi platform detection (now in-scope per mksglu#279, mksglu#283) gets its first
dedicated test. 18 new assertions, 0 runtime changes, 40 existing
detect tests unaffected.
@mksglu
Copy link
Copy Markdown
Owner

mksglu commented Apr 14, 2026

Hi Thanks, are we sure PLATFORM_ENV_VARS variables is correct and exist in code-base? If it's, that's seems duplicate Strings in here. If not, how we even sure these keys are valid? @sebastianbreguel

sebastianbreguel and others added 2 commits April 14, 2026 23:00
…rrogates, marker boundaries (mksglu#286)

Adds 10 focused assertions to tests/truncate.test.ts covering gaps left by
the mksglu#273 surrogate-pair fix:

- 3-byte UTF-8 (CJK) cap sweep — fills the gap between ASCII and 4-byte emoji
- ZWJ emoji sequence cap sweep — modern emoji with chained surrogate pairs
- Lone low surrogate in input — round-trips safely through UTF-8
- Mixed-width input unchanged when cap >= input byte length
- capBytes marker-boundary arithmetic (cap == markerBytes, cap == markerBytes+1)
- escapeXML consecutive reserved runs + non-idempotent re-escape lock
- truncateJSON exact-size and cap == size-1 boundaries

All 29 tests in the file pass. Typecheck clean. Pure additions — no
runtime behavior changes.
… of truth

Addresses PR review feedback: the test file hardcoded a literal list of
env-var names that duplicated the strings used inside detectPlatform().
If detect.ts renamed a var, the test's cleanup list would silently drift.

- Export PLATFORM_ENV_VARS from src/adapters/detect.ts as the canonical
  (platform, envVars) priority table.
- Replace the 8 per-platform if-blocks with a single loop over the table.
  Same priority order, same reason strings, same behavior.
- Test imports PLATFORM_ENV_VARS and derives its cleanup list from it,
  so any future rename in detect.ts is automatically picked up.
@sebastianbreguel
Copy link
Copy Markdown
Contributor Author

sebastianbreguel commented Apr 14, 2026

Good catch — it was a local hardcoded array. Pushed c10aa6a: exports PLATFORM_ENV_VARS from detect.ts as the priority table, detectPlatform() iterates it, test imports it. Same behavior, no drift. 58/58 pass, typecheck clean.

@mksglu
Copy link
Copy Markdown
Owner

mksglu commented Apr 16, 2026

Good coverage work. The PLATFORM_ENV_VARS extraction is a clean DRY refactor and the config-dir mock pattern is solid. Pi detection having zero test coverage was a real gap. Merging.

@mksglu mksglu merged commit af6d943 into mksglu:next Apr 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants