Skip to content

fix(test): isolate buildClaudeCommand tests from host ~/.genie/config.json - #1171

Merged
namastex888 merged 1 commit into
devfrom
fix/session-test-host-env-robustness
Apr 17, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/session-test-host-env-robustness

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

Summary

Two tests in src/genie-commands/__tests__/session.test.ts — buildClaudeCommand > with system prompt file references it via --append-system-prompt-file and buildClaudeCommand > file path is passed directly, no content inlined — implicitly assumed the host machine's ~/.genie/config.json had promptMode unset or "append". On any host configured with promptMode: "system", buildTeamLeadCommand emits --system-prompt-file instead, and the assertions fail.

This fragility was previously masked by the leaking mock.module('../lib/genie-config.js', ...) from init-*.test.ts that PR #1169 replaced with spyOn. Removing the leak unmasked this latent weakness.

Closes the tail surfaced during PR #1169 QA — tests no longer depend on host ~/.genie/config.json.

Fix

Mirror PR #1169's spyOn pattern inside the buildClaudeCommand describe block:

  • Import * as genieConfig from '../../lib/genie-config.js'
  • spyOn(genieConfig, 'loadGenieConfigSync').mockReturnValue({ promptMode: 'append' }) in beforeEach
  • loadGenieConfigSyncSpy.mockRestore() in afterEach

Scope: 1 file touched (src/genie-commands/__tests__/session.test.ts). Production code in src/lib/team-lead-command.ts is untouched — this is a test-only hygiene fix.

BEFORE / AFTER reproducer

BEFORE (on origin/dev, host ~/.genie/config.json has promptMode: "system")

$ bun test src/genie-commands/__tests__/session.test.ts
...
(fail) buildClaudeCommand > with system prompt file references it via --append-system-prompt-file [3.00ms]
  Expected to contain: "--append-system-prompt-file"
  Received: "... --system-prompt-file '/tmp/test-agents.md'"

(fail) buildClaudeCommand > file path is passed directly, no content inlined [1.00ms]
  Expected to contain: "--append-system-prompt-file"
  Received: "... --system-prompt-file '/path/to/AGENTS.md'"

 29 pass
 2 fail

AFTER (this branch, both host scenarios)

# host config contains promptMode: "system"
$ bun test src/genie-commands/__tests__/session.test.ts
 31 pass
 0 fail
 52 expect() calls
Ran 31 tests across 1 file. [2.45s]

# host config moved aside
$ mv ~/.genie/config.json ~/.genie/config.json.bak
$ bun test src/genie-commands/__tests__/session.test.ts
 31 pass
 0 fail
 52 expect() calls
Ran 31 tests across 1 file. [2.37s]

Full suite

$ bun run check
 2501 pass
 0 fail
 5714 expect() calls
Ran 2501 tests across 128 files. [52.13s]

Test plan

  • Reproduce failure on origin/dev with host promptMode: "system" (29/2)
  • Apply fix — confirm 31/0 with host promptMode: "system"
  • Confirm 31/0 with host config moved aside (no regression on clean machines)
  • bun run check — 2501/0
  • Diff review — 1 file, +23/-1, no production code touched

🤖 Generated with Claude Code

….json

Two tests in src/genie-commands/__tests__/session.test.ts — "with system
prompt file references it via --append-system-prompt-file" and "file path
is passed directly, no content inlined" — implicitly assumed the host
machine's ~/.genie/config.json had promptMode unset or "append". On any
machine with promptMode: "system", buildTeamLeadCommand emits
--system-prompt-file instead, causing the assertions to fail.

The fragility was previously masked by the leaking mock.module in
init-*.test.ts that PR #1169 replaced with spyOn. Removing the leak
unmasked this latent weakness.

Fix: mirror PR #1169's spyOn pattern in the buildClaudeCommand describe
block — spy on genie-config.loadGenieConfigSync in beforeEach and
mockRestore in afterEach, pinning promptMode: "append" for the suite.
Production code in team-lead-command.ts is untouched; this is a
test-only hygiene fix.

Closes the tail surfaced during PR #1169 QA — tests no longer depend on
host ~/.genie/config.json.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: eceeb002-92f1-4d49-8915-c3d000b7c3df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/session-test-host-env-robustness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the session.test.ts file to stabilize tests by mocking the loadGenieConfigSync function. By using spyOn to pin the promptMode to 'append', the tests are now independent of the host's local configuration and avoid mock leakage issues associated with mock.module in Bun. I have no feedback to provide as no issues were identified.

@namastex888
namastex888 merged commit 6c051de into dev Apr 17, 2026
6 checks passed
automagik-genie pushed a commit that referenced this pull request Apr 17, 2026
…-robustness

fix(test): isolate buildClaudeCommand tests from host ~/.genie/config.json
@automagik-genie
automagik-genie deleted the fix/session-test-host-env-robustness branch September 25, 2026 04:50
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.

1 participant