From c51d859a7a2fbf8d1cf98c3818b2bd15e690b302 Mon Sep 17 00:00:00 2001 From: genie Date: Fri, 17 Apr 2026 22:29:15 +0000 Subject: [PATCH] fix(test): isolate buildClaudeCommand tests from host ~/.genie/config.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/genie-commands/__tests__/session.test.ts | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/genie-commands/__tests__/session.test.ts b/src/genie-commands/__tests__/session.test.ts index ee2434214..b470007c0 100644 --- a/src/genie-commands/__tests__/session.test.ts +++ b/src/genie-commands/__tests__/session.test.ts @@ -7,9 +7,14 @@ * Run with: bun test src/genie-commands/__tests__/session.test.ts */ -import { afterEach, beforeEach, describe, expect, test } from 'bun:test'; +import { afterEach, beforeEach, describe, expect, spyOn, test } from 'bun:test'; import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'; import { basename, join } from 'node:path'; +// Import the real genie-config module so we can spyOn individual exports. +// Using spyOn instead of mock.module avoids leaking an incomplete mock to +// other test files (bun 1.3.x leaks mock.module across parallel workers — +// see PR #1169). Pattern mirrors src/term-commands/init-bootstrap.test.ts. +import * as genieConfig from '../../lib/genie-config.js'; import { HEARTBEAT_TEMPLATE, SOUL_TEMPLATE, scaffoldAgentFiles } from '../../templates/index.js'; import { buildClaudeCommand, getAgentsFilePath, sanitizeWindowName } from '../session.js'; @@ -18,6 +23,23 @@ import { buildClaudeCommand, getAgentsFilePath, sanitizeWindowName } from '../se // ============================================================================ describe('buildClaudeCommand', () => { + // Pin promptMode so tests asserting --append-system-prompt-file don't depend + // on the host's ~/.genie/config.json. Without this, a host configured with + // promptMode: "system" causes buildTeamLeadCommand to emit --system-prompt-file + // instead, failing the append-system-prompt-file assertions below. + // Closes the tail surfaced during PR #1169 QA. + let loadGenieConfigSyncSpy: ReturnType; + + beforeEach(() => { + loadGenieConfigSyncSpy = spyOn(genieConfig, 'loadGenieConfigSync').mockReturnValue({ + promptMode: 'append', + } as ReturnType); + }); + + afterEach(() => { + loadGenieConfigSyncSpy.mockRestore(); + }); + test('always contains --team-name flag', () => { const cmd = buildClaudeCommand('genie'); expect(cmd).toContain('--team-name');