Skip to content

Commit 02f5738

Browse files
authored
Merge pull request #2541 from github/squad/2540-isolate-cli-tests
fix(test): isolate CLI fixtures for sanitized releases
2 parents e6ec513 + 7b42f36 commit 02f5738

6 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎test/acceptance/features/hostile-pipe-mode.feature‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Feature: Hostile — Non-TTY pipe mode
1414

1515
Scenario: Status works when piped (non-TTY)
1616
Given a non-TTY environment
17+
And the current directory has a ".squad" directory
1718
When I run "squad status" in non-TTY mode
1819
Then the output contains "Squad Status"
1920
And the exit code is 0

‎test/acceptance/features/hostile-tiny-terminal.feature‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ Feature: Hostile — Tiny terminal (40x10)
1414

1515
Scenario: Status command works at 40x10
1616
Given a terminal size of 40 columns by 10 rows
17+
And the current directory has a ".squad" directory
1718
When I run "squad status" with that terminal size
1819
Then the output contains "Squad Status"
1920
And the exit code is 0
2021

2122
Scenario: Doctor command works at 40x10
2223
Given a terminal size of 40 columns by 10 rows
24+
And the current directory has a ".squad" directory
2325
When I run "squad doctor" with that terminal size
2426
Then the exit code is 0
2527

‎test/acceptance/hostile.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { afterEach } from 'vitest';
77
import { join } from 'node:path';
88
import { createRegistry, runFeature } from './support/runner.js';
9-
import { registerCLISteps } from './steps/cli-steps.js';
9+
import { cleanupAcceptanceTempDirs, registerCLISteps } from './steps/cli-steps.js';
1010
import { registerHostileSteps } from './steps/hostile-steps.js';
1111
import { TerminalHarness } from './harness.js';
1212

@@ -16,7 +16,7 @@ const registry = createRegistry();
1616
registerHostileSteps(registry);
1717
registerCLISteps(registry);
1818

19-
// Cleanup harnesses after each test
19+
// Cleanup harnesses and temp dirs after each test
2020
afterEach(async (context) => {
2121
const harness = (context as Record<string, unknown>).harness as TerminalHarness | undefined;
2222
if (harness) {
@@ -26,6 +26,7 @@ afterEach(async (context) => {
2626
if (rapidHarnesses) {
2727
await Promise.all(rapidHarnesses.map(h => h.close()));
2828
}
29+
cleanupAcceptanceTempDirs();
2930
});
3031

3132
const featuresDir = join(__dirname, 'features');

‎test/acceptance/steps/cli-steps.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function registerCLISteps(registry: StepDefinitions): void {
4040
// #2015 isolation). Mirrors the sibling "without a .squad directory"
4141
// step's use of an isolated temp dir, and downstream "I run" steps pick
4242
// up context.tempDir automatically.
43-
const tempDir = mkdtempSync(join(tmpdir(), 'squad-e2e-'));
43+
const tempDir = makeTempDir();
4444
// consult/check commands gate on "is this a git repo" before the
4545
// .squad check, so the sandbox must actually be a git repo (same
4646
// convention as test/cli/consult.test.ts, test/sdk/consult.test.ts).

‎test/acceptance/steps/hostile-steps.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ export function registerHostileSteps(registry: StepDefinitions): void {
9393
const args = command.replace(/^squad\s*/, '').split(/\s+/).filter(Boolean);
9494
const cols = context.terminalCols as number;
9595
const rows = context.terminalRows as number;
96+
const cwd = context.tempDir as string | undefined;
9697

97-
const harness = await TerminalHarness.spawnWithArgs(args, { cols, rows });
98-
try { await harness.waitForExit(5000); } catch { /* timeout ok */ }
98+
const harness = await TerminalHarness.spawnWithArgs(args, { cols, rows, cwd });
99+
try { await harness.waitForExit(15000); } catch { /* timeout ok */ }
99100
context.harness = harness;
100101
context.output = harness.getOutput();
101102
context.exitCode = harness.getExitCode();
@@ -111,9 +112,11 @@ export function registerHostileSteps(registry: StepDefinitions): void {
111112
if (!match) throw new Error('Pattern match failed');
112113
const command = match[1];
113114
const args = command.replace(/^squad\s*/, '').split(/\s+/).filter(Boolean);
115+
const cwd = context.tempDir as string | undefined;
114116

115117
// Force non-TTY via env
116118
const harness = await TerminalHarness.spawnWithArgs(args, {
119+
cwd,
117120
env: { TERM: 'dumb', NO_COLOR: '1', FORCE_COLOR: '0' }
118121
});
119122
try { await harness.waitForExit(5000); } catch { /* timeout ok */ }

‎test/ux-gates.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
*/
55

66
import { describe, it, expect, afterEach } from 'vitest';
7+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
8+
import { tmpdir } from 'node:os';
9+
import { join } from 'node:path';
710
import { TerminalHarness } from './acceptance/harness.js';
811

912
describe('UX Gates', () => {
1013
let harness: TerminalHarness | null = null;
14+
let projectDir: string | null = null;
1115

1216
afterEach(async () => {
1317
if (harness) {
1418
await harness.close();
1519
harness = null;
1620
}
21+
if (projectDir) {
22+
rmSync(projectDir, { recursive: true, force: true });
23+
projectDir = null;
24+
}
1725
});
1826

1927
it('No overflow beyond terminal width (80 chars)', async () => {
@@ -64,8 +72,11 @@ describe('UX Gates', () => {
6472
});
6573

6674
it('Status command shows clear output structure', async () => {
67-
harness = await TerminalHarness.spawnWithArgs(['status']);
68-
await harness.waitForExit(5000);
75+
projectDir = mkdtempSync(join(tmpdir(), 'squad-ux-gates-'));
76+
mkdirSync(join(projectDir, '.squad'));
77+
writeFileSync(join(projectDir, '.squad', 'team.md'), '# UX test team\n');
78+
harness = await TerminalHarness.spawnWithArgs(['status'], { cwd: projectDir });
79+
expect(await harness.waitForExit(5000)).toBe(0);
6980

7081
const output = harness.captureFrame();
7182

0 commit comments

Comments
 (0)