Skip to content

Commit 8595299

Browse files
committed
fixign flasky tuistory tests
1 parent 46383a6 commit 8595299

12 files changed

Lines changed: 200 additions & 42 deletions

‎.github/workflows/README.md‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ This directory contains automated CI/CD workflows for the Autohand CLI project.
1515
- Alpha bumps the patch from the latest stable tag and appends the short SHA
1616
- Stable releases use the current `package.json` version unless manually overridden
1717

18-
2. **Builds binaries** for all platforms:
18+
2. **Runs fast tests and built terminal tests in separate parallel jobs**
19+
20+
3. **Builds binaries** for all platforms:
1921
- macOS Apple Silicon (`autohand-macos-arm64`)
2022
- macOS Intel (`autohand-macos-x64`)
2123
- Linux x64 (`autohand-linux-x64`)
2224
- Linux ARM64 (`autohand-linux-arm64`)
2325
- Windows x64 (`autohand-windows-x64.exe`)
2426

25-
3. **Generates release notes** from the correct previous release tag
27+
4. **Generates release notes** from the correct previous release tag
2628

27-
4. **Creates GitHub Release** with binaries attached
29+
5. **Creates GitHub Release** with binaries attached
2830

29-
5. **Updates the public Homebrew tap** from the verified release archives (stable releases only)
31+
6. **Updates the public Homebrew tap** from the verified release archives (stable releases only)
3032

31-
6. **Publishes to npm** (stable releases only)
33+
7. **Publishes to npm**
34+
- Alpha releases use the `alpha` dist-tag
35+
- Stable releases use the `latest` dist-tag
3236

3337
**Release Channels:**
3438
- **main push** → `v1.2.4-alpha.abc1234` (next patch from the latest stable tag plus short SHA)
@@ -42,9 +46,10 @@ This directory contains automated CI/CD workflows for the Autohand CLI project.
4246

4347
**What it does:**
4448
1. Type checking
45-
2. Build verification
46-
3. Test execution
47-
4. Multi-platform build test
49+
2. Fast test execution
50+
3. Built terminal tests in a separate parallel job
51+
4. Build verification
52+
5. Multi-platform build test
4853

4954
### 🤖 Model catalog pull requests (`model-catalog-pr.yml`)
5055

‎.github/workflows/ci.yml‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v7
20-
with:
21-
# The built terminal tests assert the CLI renders the latest stable
22-
# release tag, which they find with `git tag --merged HEAD`. The
23-
# default shallow checkout fetches no tags, so that suite passes
24-
# locally and fails here.
25-
fetch-depth: 0
2620

2721
- name: Setup Bun
2822
uses: oven-sh/setup-bun@v2
@@ -39,17 +33,37 @@ jobs:
3933
- name: Type check
4034
run: bun run typecheck
4135

42-
- name: Build
43-
run: bun run build
44-
4536
- name: Run tests
46-
run: bun run test
37+
run: bun run test:ci
38+
39+
tuistory:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v7
43+
with:
44+
# The built terminal tests assert the CLI renders the latest stable
45+
# release tag, which they find with `git tag --merged HEAD`.
46+
fetch-depth: 0
47+
48+
- name: Setup Bun
49+
uses: oven-sh/setup-bun@v2
50+
with:
51+
bun-version: 1.2.22
52+
53+
- name: Install build tools (Ubuntu)
54+
run: sudo apt-get update && sudo apt-get install -y build-essential python3 make g++
55+
56+
- name: Install dependencies
57+
run: bun install --frozen-lockfile
58+
59+
- name: Build CLI for terminal tests
60+
run: bun run build
4761

4862
- name: Run built terminal tests
4963
run: bun run test:tuistory
5064

5165
build-test:
52-
needs: test
66+
needs: [test, tuistory]
5367
runs-on: ${{ matrix.os }}
5468
strategy:
5569
matrix:

‎.github/workflows/release.yml‎

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,21 @@ jobs:
112112
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
113113
echo "🎯 Version: ${NEW_VERSION} (${CHANNEL})"
114114
115+
- name: Validate npm publishing credentials
116+
env:
117+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
118+
run: |
119+
if [ -z "$NPM_TOKEN" ]; then
120+
echo "::error::NPM_TOKEN is required for npm publishing"
121+
exit 1
122+
fi
123+
115124
test:
116125
needs: prepare
117126
if: needs.prepare.outputs.should_release == 'true'
118127
runs-on: ubuntu-latest
119128
steps:
120129
- uses: actions/checkout@v7
121-
with:
122-
# This job runs the built terminal tests, which assert the CLI renders
123-
# the latest stable release tag found via `git tag --merged HEAD`. The
124-
# default shallow checkout fetches no tags.
125-
fetch-depth: 0
126130

127131
- name: Setup Bun
128132
uses: oven-sh/setup-bun@v2
@@ -138,14 +142,33 @@ jobs:
138142
- name: Run tests
139143
run: bun run test:ci
140144

145+
tuistory:
146+
needs: prepare
147+
if: needs.prepare.outputs.should_release == 'true'
148+
runs-on: ubuntu-latest
149+
steps:
150+
- uses: actions/checkout@v7
151+
with:
152+
# The built terminal tests assert the CLI renders the latest stable
153+
# release tag found via `git tag --merged HEAD`.
154+
fetch-depth: 0
155+
156+
- name: Setup Bun
157+
uses: oven-sh/setup-bun@v2
158+
with:
159+
bun-version: 1.2.22
160+
161+
- name: Install dependencies
162+
run: bun install --frozen-lockfile
163+
141164
- name: Build CLI for terminal tests
142165
run: bun run build
143166

144167
- name: Run built terminal tests
145168
run: bun run test:tuistory
146169

147170
build:
148-
needs: [prepare, test]
171+
needs: [prepare, test, tuistory]
149172
if: needs.prepare.outputs.should_release == 'true'
150173
runs-on: ${{ matrix.os }}
151174
strategy:
@@ -423,21 +446,34 @@ jobs:
423446
echo "Homebrew tap updated to v${VERSION}"
424447
fi
425448
426-
- name: Build JS dist for npm
427-
if: needs.prepare.outputs.channel == 'release'
449+
- name: Build and verify npm package
428450
run: |
429451
bun install --frozen-lockfile
452+
npm version "${{ needs.prepare.outputs.version }}" --no-git-tag-version --allow-same-version
430453
bun run build
454+
npm pack --dry-run
431455
ls -lh dist/
432456
433-
- name: Publish to npm (release only)
434-
if: needs.prepare.outputs.channel == 'release'
457+
- name: Publish to npm
435458
env:
436459
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
437460
run: |
438461
if [ -z "$NPM_TOKEN" ]; then
439-
echo "⚠️ NPM_TOKEN not set, skipping npm publish"
440-
exit 0
462+
echo "::error::NPM_TOKEN is required for npm publishing"
463+
exit 1
441464
fi
465+
442466
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
443-
npm publish --access public
467+
VERSION="${{ needs.prepare.outputs.version }}"
468+
if [ "${{ needs.prepare.outputs.channel }}" = "alpha" ]; then
469+
NPM_DIST_TAG="alpha"
470+
else
471+
NPM_DIST_TAG="latest"
472+
fi
473+
474+
if npm view "autohand-cli@$VERSION" version --json > /dev/null 2>&1; then
475+
echo "autohand-cli@$VERSION is already published; updating the $NPM_DIST_TAG dist-tag"
476+
npm dist-tag add "autohand-cli@$VERSION" "$NPM_DIST_TAG"
477+
else
478+
npm publish --access public --tag "$NPM_DIST_TAG"
479+
fi
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Autohand AI LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
export function hasTerminalProcessPid(screen: string, pid: number): boolean {
8+
return new RegExp(`\\bpid\\s+${pid}(?!\\d)`, 'u').test(screen);
9+
}

‎tests/ci/releaseWorkflow.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Autohand AI LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
import { readFileSync } from 'node:fs';
7+
import path from 'node:path';
8+
import { describe, expect, it } from 'vitest';
9+
import { parse as parseYaml } from 'yaml';
10+
11+
interface WorkflowStep {
12+
name?: string;
13+
if?: string;
14+
env?: Record<string, string>;
15+
run?: string;
16+
}
17+
18+
interface ReleaseWorkflow {
19+
jobs: {
20+
release: {
21+
steps: WorkflowStep[];
22+
};
23+
};
24+
}
25+
26+
const WORKFLOW_PATH = path.resolve(import.meta.dirname, '../../.github/workflows/release.yml');
27+
28+
function loadReleaseSteps(): WorkflowStep[] {
29+
const workflow = parseYaml(readFileSync(WORKFLOW_PATH, 'utf8')) as ReleaseWorkflow;
30+
return workflow.jobs.release.steps;
31+
}
32+
33+
describe('release workflow', () => {
34+
it('builds, verifies, and publishes alpha packages with the alpha npm dist-tag', () => {
35+
const steps = loadReleaseSteps();
36+
const buildStep = steps.find((step) => step.name === 'Build and verify npm package');
37+
const publishStep = steps.find((step) => step.name === 'Publish to npm');
38+
39+
expect(buildStep?.if).toBeUndefined();
40+
expect(buildStep?.run).toContain(
41+
'npm version "${{ needs.prepare.outputs.version }}" --no-git-tag-version --allow-same-version',
42+
);
43+
expect(buildStep?.run).toContain('bun run build');
44+
expect(buildStep?.run).toContain('npm pack --dry-run');
45+
46+
expect(publishStep?.if).toBeUndefined();
47+
expect(publishStep?.env).toEqual({
48+
NPM_TOKEN: '${{ secrets.NPM_TOKEN }}',
49+
});
50+
expect(publishStep?.run).toContain('NPM_DIST_TAG="alpha"');
51+
expect(publishStep?.run).toContain('npm publish --access public --tag "$NPM_DIST_TAG"');
52+
expect(publishStep?.run).toContain('NPM_TOKEN is required for npm publishing');
53+
expect(publishStep?.run).not.toContain('skipping npm publish');
54+
});
55+
});

‎tests/ci/workflowCheckout.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ describe('CI workflow checkout', () => {
6363
expect(offenders).toEqual([]);
6464
});
6565

66+
it('runs built terminal tests in dedicated jobs, separate from fast tests', () => {
67+
for (const workflow of ['ci.yml', 'release.yml']) {
68+
const workflowJobs = readWorkflowJobs().filter((job) => job.workflow === workflow);
69+
const tuistoryJobs = workflowJobs.filter((job) => job.body.includes('test:tuistory'));
70+
71+
expect(tuistoryJobs.map((job) => job.name), workflow).toEqual(['tuistory']);
72+
expect(tuistoryJobs[0]?.body, workflow).not.toContain('run: bun run test:ci');
73+
expect(tuistoryJobs[0]?.body, workflow).not.toMatch(/run: bun run test\s*$/mu);
74+
}
75+
});
76+
6677
it('keeps every checkout pinned to a major version', () => {
6778
for (const file of readdirSync(WORKFLOW_DIR).filter((name) => name.endsWith('.yml'))) {
6879
const contents = readFileSync(path.join(WORKFLOW_DIR, file), 'utf8');

‎tests/core/SessionDiffStatsTracker.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const GIT_ENV = {
2020
const GIT_EXEC_OPTIONS = {
2121
env: GIT_ENV,
2222
stdio: 'ignore',
23-
timeout: 10_000,
23+
timeout: 30_000,
2424
} as const;
2525

2626
async function createRepo(): Promise<string> {

‎tests/installLocalScript.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ describe('dependency install guardrails', () => {
203203
expect(releaseWorkflow).toContain('run: bun run test:ci');
204204
});
205205

206-
it('runs built terminal tests in the Linux test gates', () => {
206+
it('runs built terminal tests in dedicated Linux jobs', () => {
207207
for (const workflowPath of ['.github/workflows/ci.yml', '.github/workflows/release.yml']) {
208208
const workflow = readFileSync(workflowPath, 'utf8');
209209

210-
expect(workflow).toMatch(/test:\n(?:.|\n)*?runs-on: ubuntu-latest(?:.|\n)*?run: bun run test:tuistory/);
210+
expect(workflow).toMatch(/tuistory:\n(?:.|\n)*?runs-on: ubuntu-latest(?:.|\n)*?run: bun run test:tuistory/);
211211
}
212212
});
213213

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Autohand AI LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
import { describe, expect, it } from 'vitest';
7+
import { hasTerminalProcessPid } from '../../src/testing/assertions/terminalOutput.js';
8+
9+
describe('terminal output assertions', () => {
10+
it('matches a process pid when the terminal wraps between the label and value', () => {
11+
const screen = [
12+
'Background processes:',
13+
'1 node task.js (pid',
14+
'11482, running 0m00s)',
15+
].join('\n');
16+
17+
expect(hasTerminalProcessPid(screen, 11482)).toBe(true);
18+
expect(hasTerminalProcessPid(screen, 1148)).toBe(false);
19+
});
20+
});

‎tests/tuistory/built-cli.tuistory.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { execFileSync } from 'node:child_process';
1414
import path from 'node:path';
1515
import packageJson from '../../package.json' with { type: 'json' };
1616
import { SLASH_COMMANDS } from '../../src/core/slashCommands.js';
17+
import { hasTerminalProcessPid } from '../../src/testing/assertions/terminalOutput.js';
1718
import { getHelpOrderedSlashCommands } from '../../src/ui/inputPrompt.js';
1819
import {
1920
clearComposerInput,
@@ -1789,16 +1790,20 @@ describe('interactive built CLI Tuistory tests', () => {
17891790
await waitForComposer(session);
17901791
await session.type('/ps');
17911792
await session.press('enter');
1792-
await session.waitForText(`pid ${pid}`, { timeout: 30_000 });
1793+
await session.text({
1794+
timeout: 30_000,
1795+
waitFor: (text) => hasTerminalProcessPid(text, pid),
1796+
});
17931797
const psOutput = session.readAll();
1794-
expect(psOutput).toContain(`pid ${pid}`);
1798+
expect(hasTerminalProcessPid(psOutput, pid), psOutput).toBe(true);
17951799
expect(psOutput).toMatch(/^1\s{2}/m);
17961800

17971801
await waitForComposer(session);
17981802
await session.type('/stop 1');
17991803
await session.press('enter');
18001804
await session.waitForText('Stopped', { timeout: 30_000 });
1801-
expect(session.readAll()).toContain(`pid ${pid}`);
1805+
const stopOutput = session.readAll();
1806+
expect(hasTerminalProcessPid(stopOutput, pid), stopOutput).toBe(true);
18021807

18031808
const exitDeadline = Date.now() + 5_000;
18041809
let processExited = false;
@@ -1901,7 +1906,10 @@ describe('interactive built CLI Tuistory tests', () => {
19011906
// made this fail on loaded CI runners without testing anything extra.
19021907
await session.type('/ps');
19031908
await session.press('enter');
1904-
await session.waitForText(`pid ${pid}`, { timeout: 30_000 });
1909+
await session.text({
1910+
timeout: 30_000,
1911+
waitFor: (text) => hasTerminalProcessPid(text, pid),
1912+
});
19051913
expect(session.readAll()).not.toContain('Background task started and slow command finished.');
19061914

19071915
await session.type('/stop 1');

0 commit comments

Comments
 (0)