Skip to content

Commit a4f229a

Browse files
igorcostaAutohand Evolve
andcommitted
Exit export fixtures without interrupting completed sessions
Use the explicit exit command after checking exported files, and leave a PTY that already finished alone. Continue requiring exit code zero and all privacy assertions for Markdown, JSON, and HTML exports. Remove the generic composer-marker wait so multiline drafts and inspector screens retain their existing Ctrl+C shutdown behavior. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent 4073185 commit a4f229a

4 files changed

Lines changed: 21 additions & 38 deletions

File tree

‎src/testing/drivers/tuistory-driver.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,7 @@ export async function exitInteractive(session: Pick<Session, 'exitInfo' | 'text'
6363
expectCleanExit(session);
6464
return;
6565
}
66-
const screen = await waitForTerminalScreen(session, {
67-
timeout: 10_000,
68-
waitFor: text => Boolean(session.exitInfo) || isEnding(text)
69-
|| text.includes('Press Ctrl+C again to exit') || /^\s*❯(?:\s|$)/mu.test(text),
70-
});
71-
if (session.exitInfo) {
72-
expectCleanExit(session);
73-
return;
74-
}
66+
const screen = await session.text({ immediate: true });
7567
// Redraws can clear the visible teardown marker after Ink has released raw mode.
7668
if (isEnding(screen)) {
7769
await waitForExit(session);

‎src/testing/scenarios/exportPrivacyScenario.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ export async function runExportPrivacyScenario(session: Session, format: 'md' |
2626
await session.waitForText('Secrets redacted:', { timeout: 10_000 });
2727
return session.readAll();
2828
}
29+
30+
export async function exitAfterExport(session: Session): Promise<void> {
31+
if (session.exitInfo) return;
32+
try {
33+
await session.waitForText('❯', { timeout: 10_000 });
34+
if (session.exitInfo) return;
35+
await session.type('/exit');
36+
await session.text({ timeout: 10_000, waitFor: screen =>
37+
screen.split('\n').some(line => line.includes('❯') && line.includes('/exit')) });
38+
await session.press('enter');
39+
} catch (error) {
40+
if (!session.exitInfo) throw error;
41+
}
42+
}

‎tests/testing/tuistory-driver.test.ts‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,6 @@ afterEach(() => {
3131
});
3232

3333
describe('interactive terminal shutdown', () => {
34-
it('waits for the composer to regain input after a modal prints its result', async () => {
35-
vi.useFakeTimers();
36-
const baseline = vi.getTimerCount();
37-
let exitInfo: Session['exitInfo'] = null;
38-
let rawMode = false;
39-
const press = vi.fn<Session['press']>(async () => {
40-
exitInfo = { exitCode: rawMode ? 0 : 130, signal: 0 };
41-
});
42-
const session = {
43-
get exitInfo() { return exitInfo; },
44-
getRawOutput: () => '',
45-
text: vi.fn<Session['text']>(async options => {
46-
if (options?.immediate) return 'Secrets redacted: 2';
47-
await new Promise<void>(resolve => setTimeout(resolve, 100));
48-
rawMode = true;
49-
return '❯';
50-
}),
51-
press,
52-
};
53-
const settled = exitInteractive(session).catch((error: unknown) => error);
54-
await vi.advanceTimersByTimeAsync(100);
55-
expect(await settled).toBeUndefined();
56-
expect(press).toHaveBeenCalledOnce();
57-
expect(vi.getTimerCount()).toBe(baseline);
58-
});
59-
6034
it('does not send another Ctrl+C when teardown output was cleared from the viewport', async () => {
6135
vi.useFakeTimers();
6236
const baseline = vi.getTimerCount();

‎tests/tuistory/session-safety.tuistory.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import fs from 'node:fs/promises';
33
import path from 'node:path';
44
import { afterEach, describe, expect, it } from 'vitest';
55
import type { Session } from 'tuistory';
6-
import { runExportPrivacyScenario } from '../../src/testing/scenarios/exportPrivacyScenario.js';
6+
import { exitAfterExport, runExportPrivacyScenario } from '../../src/testing/scenarios/exportPrivacyScenario.js';
77
import {
8-
createMockAutohandAINativeSequenceServer, createTempAutohandHome, exitInteractive, launchBuiltAutohand, waitForExit,
8+
createMockAutohandAINativeSequenceServer, createTempAutohandHome, expectCleanExit, launchBuiltAutohand, waitForExit,
99
type MockNativeToolServer, type TuistoryTempState,
1010
} from './helpers/autohandTuistory.js';
1111

@@ -50,7 +50,10 @@ describe('CLI session safety', () => {
5050
if (format === 'json') expect(() => JSON.parse(content)).not.toThrow();
5151
expect(output).toMatch(/Secrets redacted: [1-9]/);
5252
expect((await fs.readdir(state.workspaceRoot)).some(file => file.endsWith('.' + format) && file !== 'package.json')).toBe(false);
53-
await exitInteractive(session); sessions.splice(sessions.indexOf(session), 1);
53+
await exitAfterExport(session);
54+
await waitForExit(session);
55+
expectCleanExit(session);
56+
sessions.splice(sessions.indexOf(session), 1);
5457
}, 60_000);
5558

5659
it('--auto-commit commits the agent test while leaving user edits and notes uncommitted', async () => {

0 commit comments

Comments
 (0)