From 7b42f36bc8a3ee17f86056f7a2c2a68dc77340c6 Mon Sep 17 00:00:00 2001 From: Copilot Date: Thu, 19 Nov 2026 09:53:10 +0200 Subject: [PATCH] fix(test): isolate terminal acceptance squad fixtures Use temporary project squads for status and doctor success scenarios so sanitized release checkouts do not depend on live repository state. Preserve the existing no-squad failure checks. Relates to #2540. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../acceptance/features/hostile-pipe-mode.feature | 1 + .../features/hostile-tiny-terminal.feature | 2 ++ test/acceptance/hostile.test.ts | 5 +++-- test/acceptance/steps/cli-steps.ts | 2 +- test/acceptance/steps/hostile-steps.ts | 7 +++++-- test/ux-gates.test.ts | 15 +++++++++++++-- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/test/acceptance/features/hostile-pipe-mode.feature b/test/acceptance/features/hostile-pipe-mode.feature index 937730627..4461939c6 100644 --- a/test/acceptance/features/hostile-pipe-mode.feature +++ b/test/acceptance/features/hostile-pipe-mode.feature @@ -14,6 +14,7 @@ Feature: Hostile — Non-TTY pipe mode Scenario: Status works when piped (non-TTY) Given a non-TTY environment + And the current directory has a ".squad" directory When I run "squad status" in non-TTY mode Then the output contains "Squad Status" And the exit code is 0 diff --git a/test/acceptance/features/hostile-tiny-terminal.feature b/test/acceptance/features/hostile-tiny-terminal.feature index 80debafde..d86677079 100644 --- a/test/acceptance/features/hostile-tiny-terminal.feature +++ b/test/acceptance/features/hostile-tiny-terminal.feature @@ -14,12 +14,14 @@ Feature: Hostile — Tiny terminal (40x10) Scenario: Status command works at 40x10 Given a terminal size of 40 columns by 10 rows + And the current directory has a ".squad" directory When I run "squad status" with that terminal size Then the output contains "Squad Status" And the exit code is 0 Scenario: Doctor command works at 40x10 Given a terminal size of 40 columns by 10 rows + And the current directory has a ".squad" directory When I run "squad doctor" with that terminal size Then the exit code is 0 diff --git a/test/acceptance/hostile.test.ts b/test/acceptance/hostile.test.ts index 2b5653706..fdb7a00cd 100644 --- a/test/acceptance/hostile.test.ts +++ b/test/acceptance/hostile.test.ts @@ -6,7 +6,7 @@ import { afterEach } from 'vitest'; import { join } from 'node:path'; import { createRegistry, runFeature } from './support/runner.js'; -import { registerCLISteps } from './steps/cli-steps.js'; +import { cleanupAcceptanceTempDirs, registerCLISteps } from './steps/cli-steps.js'; import { registerHostileSteps } from './steps/hostile-steps.js'; import { TerminalHarness } from './harness.js'; @@ -16,7 +16,7 @@ const registry = createRegistry(); registerHostileSteps(registry); registerCLISteps(registry); -// Cleanup harnesses after each test +// Cleanup harnesses and temp dirs after each test afterEach(async (context) => { const harness = (context as Record).harness as TerminalHarness | undefined; if (harness) { @@ -26,6 +26,7 @@ afterEach(async (context) => { if (rapidHarnesses) { await Promise.all(rapidHarnesses.map(h => h.close())); } + cleanupAcceptanceTempDirs(); }); const featuresDir = join(__dirname, 'features'); diff --git a/test/acceptance/steps/cli-steps.ts b/test/acceptance/steps/cli-steps.ts index 1179f8378..0c75850b5 100644 --- a/test/acceptance/steps/cli-steps.ts +++ b/test/acceptance/steps/cli-steps.ts @@ -40,7 +40,7 @@ export function registerCLISteps(registry: StepDefinitions): void { // #2015 isolation). Mirrors the sibling "without a .squad directory" // step's use of an isolated temp dir, and downstream "I run" steps pick // up context.tempDir automatically. - const tempDir = mkdtempSync(join(tmpdir(), 'squad-e2e-')); + const tempDir = makeTempDir(); // consult/check commands gate on "is this a git repo" before the // .squad check, so the sandbox must actually be a git repo (same // convention as test/cli/consult.test.ts, test/sdk/consult.test.ts). diff --git a/test/acceptance/steps/hostile-steps.ts b/test/acceptance/steps/hostile-steps.ts index 0274fef31..a179837ac 100644 --- a/test/acceptance/steps/hostile-steps.ts +++ b/test/acceptance/steps/hostile-steps.ts @@ -93,9 +93,10 @@ export function registerHostileSteps(registry: StepDefinitions): void { const args = command.replace(/^squad\s*/, '').split(/\s+/).filter(Boolean); const cols = context.terminalCols as number; const rows = context.terminalRows as number; + const cwd = context.tempDir as string | undefined; - const harness = await TerminalHarness.spawnWithArgs(args, { cols, rows }); - try { await harness.waitForExit(5000); } catch { /* timeout ok */ } + const harness = await TerminalHarness.spawnWithArgs(args, { cols, rows, cwd }); + try { await harness.waitForExit(15000); } catch { /* timeout ok */ } context.harness = harness; context.output = harness.getOutput(); context.exitCode = harness.getExitCode(); @@ -111,9 +112,11 @@ export function registerHostileSteps(registry: StepDefinitions): void { if (!match) throw new Error('Pattern match failed'); const command = match[1]; const args = command.replace(/^squad\s*/, '').split(/\s+/).filter(Boolean); + const cwd = context.tempDir as string | undefined; // Force non-TTY via env const harness = await TerminalHarness.spawnWithArgs(args, { + cwd, env: { TERM: 'dumb', NO_COLOR: '1', FORCE_COLOR: '0' } }); try { await harness.waitForExit(5000); } catch { /* timeout ok */ } diff --git a/test/ux-gates.test.ts b/test/ux-gates.test.ts index 0ff81c1f0..1c4b0f7cf 100644 --- a/test/ux-gates.test.ts +++ b/test/ux-gates.test.ts @@ -4,16 +4,24 @@ */ import { describe, it, expect, afterEach } from 'vitest'; +import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; import { TerminalHarness } from './acceptance/harness.js'; describe('UX Gates', () => { let harness: TerminalHarness | null = null; + let projectDir: string | null = null; afterEach(async () => { if (harness) { await harness.close(); harness = null; } + if (projectDir) { + rmSync(projectDir, { recursive: true, force: true }); + projectDir = null; + } }); it('No overflow beyond terminal width (80 chars)', async () => { @@ -64,8 +72,11 @@ describe('UX Gates', () => { }); it('Status command shows clear output structure', async () => { - harness = await TerminalHarness.spawnWithArgs(['status']); - await harness.waitForExit(5000); + projectDir = mkdtempSync(join(tmpdir(), 'squad-ux-gates-')); + mkdirSync(join(projectDir, '.squad')); + writeFileSync(join(projectDir, '.squad', 'team.md'), '# UX test team\n'); + harness = await TerminalHarness.spawnWithArgs(['status'], { cwd: projectDir }); + expect(await harness.waitForExit(5000)).toBe(0); const output = harness.captureFrame();