mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 06:04:33 +01:00
* Say when /ship's test step hit its time limit, and keep long file lists off the remote test command line gstack-ship-preflight stopped gstack-pregate after a fixed hour and printed 'PREGATE: unreadable (exit 143)'. The whole step's budget is now --step-timeout <s> (default 3600), and a stop at it prints 'PREGATE: time limit hit' with the way out: push and let CI's full run carry the tests, or a larger budget. The test_backend command pregate prints for a small machine put every selected file into one argument, which Linux refuses past 128 KiB. The files now reach the VM in a setup script named by its content. Also adds an arg-limit troubleshooting entry and says the Windows job has eight shards. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Read the small-machine file list from the setup script in the hidden-folder path test The remote command now names a setup script instead of the files, so the test checks that the script lists the ./-prefixed path. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Keep a test path with a newline out of the remote file list A selected test path containing a newline, or equal to the list's end marker, could end the setup script's file list early and run the rest as shell on the test VM. Such paths now keep the quoted inline command. Review-Finding: p1/outside-voice#1 reader=outside-voice Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Mark the preflight half of the Step 5 time limit to-do as done Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
115 lines
8.4 KiB
TypeScript
115 lines
8.4 KiB
TypeScript
/**
|
|
* GST-2640 (gbrain #3965): the lanes check ran `bun test {files}` with bare repo-relative paths. Bun 1.4.4 reads a bare
|
|
* path as a name filter whose search skips hidden folders, so a selected test under .github/scripts/ ran nothing, Bun
|
|
* exited 1 and the lane failed with PREGATE_LANE_FAILED on a green test. The fixture repo has its test under
|
|
* .github/scripts/; the failing control proves the lane still judges that test instead of passing it unrun.
|
|
*/
|
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
import { buildContext } from '../lib/pregate/context';
|
|
import { runPregate } from '../lib/pregate/index';
|
|
import { explicitPath, testFileArgs } from '../lib/test-paths';
|
|
import { runAt } from '../lib/base-red';
|
|
import { perFileCommand } from '../lib/ci-carry';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { cleanup, commit, makeFixtureRepo, type FixtureRepo } from './helpers/pregate-fixture';
|
|
|
|
const repos: FixtureRepo[] = [];
|
|
afterEach(() => { while (repos.length) cleanup(repos.pop()!); });
|
|
|
|
const TEST = '.github/scripts/select.test.mjs';
|
|
const GREEN = "import { expect, test } from 'bun:test';\nimport { pick } from './select.mjs';\ntest('picks the first lane', () => expect(pick(['a', 'b'])).toBe('a'));\n";
|
|
const RED = "import { expect, test } from 'bun:test';\nimport { pick } from './select.mjs';\ntest('picks the last lane', () => expect(pick(['a', 'b'])).toBe('b'));\n";
|
|
const DETECTED = { $schema: 'https://github.com/garrytan/gstack/docs/pregate.md#pregate-v1', dependencies: { '.github/scripts/**': [TEST], 'docs/**': [], 'README.md': [] } };
|
|
const DECLARED = { ...DETECTED, runner: 'bun test {files}' };
|
|
|
|
async function lanes(policy: Record<string, unknown>, files: Record<string, string>, unlink: string[] = [], machine: { cores: number; testBackend: string } = { cores: 64, testBackend: 'local' }) {
|
|
const repo = makeFixtureRepo({ pregate: policy, baseFiles: { 'bun.lock': '' } });
|
|
repos.push(repo);
|
|
commit(repo, { '.github/scripts/select.mjs': 'export const pick = (lanes) => lanes[0];\n', ...files }, 'add the lane selector');
|
|
for (const rel of unlink) fs.rmSync(path.join(repo.work, rel));
|
|
const loaded = buildContext({ repoRoot: repo.work, base: 'main', policyFrom: 'base', allowRepoCommands: true, env: { ...process.env, ...repo.env }, progress: () => {}, ...machine } as never);
|
|
if (!('ctx' in loaded)) throw new Error('fixture context refused');
|
|
const file = await runPregate(loaded.ctx, { stage: 'tests', only: ['lanes'] });
|
|
return file.checks.find(c => c.id === 'lanes')!;
|
|
}
|
|
|
|
describe('explicit test paths for bun test', () => {
|
|
// Value: protects=every relative test path reaches bun test as a path; fails_when=a bare path (Bun's name filter) or a doubled ./ is passed;
|
|
// why_new=GST-2640; seam=the pure helper the lanes, remote-gate, docs-only, base-red and CI-carry commands share
|
|
test('adds ./ to a bare relative path, keeps explicit ones, and leaves other runners alone', () => {
|
|
expect(['.github/scripts/x.test.mjs', 'test/a.test.ts', './b.test.ts', '../c.test.ts', '/abs/d.test.ts'].map(explicitPath))
|
|
.toEqual(['./.github/scripts/x.test.mjs', './test/a.test.ts', './b.test.ts', '../c.test.ts', '/abs/d.test.ts']);
|
|
expect(testFileArgs('bun test --timeout=30000 {files}', ['.github/x.test.ts'])).toEqual(['./.github/x.test.ts']);
|
|
expect(testFileArgs('bun --no-env-file --config=/dev/null test {files}', ['.github/x.test.ts'])).toEqual(['./.github/x.test.ts']);
|
|
expect(testFileArgs('npx vitest run {files}', ['.github/x.test.ts'])).toEqual(['.github/x.test.ts']);
|
|
});
|
|
|
|
// Value: protects=perFileCommand single-quotes each path after anchoring it with one ./; fails_when=quoting runs before the prefix, ./ doubles, or an absolute path gains ./;
|
|
// why_new=no test called perFileCommand after it moved to explicitPath; seam=none; no_claim=bash execution of the command (string only)
|
|
test('perFileCommand anchors and quotes per-file paths', () => {
|
|
expect(perFileCommand('bun test {files}', [".github/it's.test.ts", './a.test.ts', '/abs/b.test.ts']))
|
|
.toBe("bun test './.github/it'\\''s.test.ts' './a.test.ts' '/abs/b.test.ts'");
|
|
});
|
|
});
|
|
|
|
describe.skipIf(process.platform === 'win32')('lanes check on a test under a hidden folder', () => {
|
|
// Value: protects=a green test under .github/ passes the lane, with the runner detected from bun.lock or declared;
|
|
// fails_when=bun test gets the bare path, runs nothing and exits 1 (PREGATE_LANE_FAILED);
|
|
// why_new=GST-2640, gbrain #3965 blocked /ship on bun 1.4.4; seam=runPregate --only lanes on a fixture repo that runs bun test
|
|
for (const [name, policy] of [['detected', DETECTED], ['declared', DECLARED]] as const) {
|
|
test(`a green hidden-folder test passes the lane (${name} runner)`, async () => {
|
|
const result = await lanes(policy, { [TEST]: GREEN });
|
|
expect(result.lines).toContainEqual(expect.stringContaining("bun test './.github/scripts/select.test.mjs'"));
|
|
// The fixture's windows.yml claims every test, so the green local lane leaves a windows obligation instead of a bare pass.
|
|
expect(result).toMatchObject({ status: 'requires-remote', detail: '1 tests ran in 1 file(s), exit 0; 1 requires-remote obligation(s)' });
|
|
}, 120_000);
|
|
}
|
|
|
|
// Value: protects=the remote-gate command a small machine records carries ./-prefixed bun paths; fails_when=remoteObligation drops testFileArgs and records the bare .github path;
|
|
// why_new=only the local lane was tested; seam=none (runPregate on a 4-core ubicloud-backend context); no_claim=the remote VM run itself
|
|
test('a small machine records the remote-gate command with ./ paths', async () => {
|
|
const result = await lanes(DETECTED, { [TEST]: GREEN }, [], { cores: 4, testBackend: 'ubicloud' });
|
|
expect(result.status).toBe('requires-remote');
|
|
const run = result.lines?.find(l => l.startsWith('run: ')) ?? '';
|
|
const listed = fs.readFileSync(/--setup '([^']+)'/.exec(run)![1]!, 'utf8').split('\n');
|
|
expect(listed).toContain('./.github/scripts/select.test.mjs');
|
|
expect(listed).not.toContain('.github/scripts/select.test.mjs');
|
|
}, 120_000);
|
|
|
|
// Value: protects=the lane still runs and judges a hidden-folder test; fails_when=the fix passes the lane without running the test
|
|
test('a failing hidden-folder test still fails the lane', async () => {
|
|
const result = await lanes(DETECTED, { [TEST]: RED });
|
|
expect(result).toMatchObject({ status: 'fail', code: 'PREGATE_LANE_FAILED', detail: expect.stringContaining('1 failed of 1 ran') });
|
|
}, 120_000);
|
|
|
|
// Value: protects=AGENTS.md's rule that a missing test file never reaches Bun, which drops a missing ./ path beside a present one
|
|
// without an error; fails_when=selection hands bun test a path the working tree no longer has
|
|
test('a declared test file missing from the working tree is never passed to bun test', async () => {
|
|
const gone = '.github/scripts/gone.test.mjs';
|
|
const result = await lanes({ ...DETECTED, dependencies: { ...DETECTED.dependencies, '.github/scripts/**': [TEST, gone] } }, { [TEST]: GREEN, [gone]: GREEN }, [gone]);
|
|
expect(result.lines).toContain("ran: bun test './.github/scripts/select.test.mjs'");
|
|
expect(result.lines?.join('\n')).not.toContain('gone.test.mjs');
|
|
}, 120_000);
|
|
});
|
|
|
|
describe.skipIf(process.platform === 'win32')('base-red select anchors bun test paths', () => {
|
|
// Value: protects=runAt hands a bun select ./-prefixed, quoted paths; fails_when=runAt drops testFileArgs and passes the bare .github path;
|
|
// why_new=no test reached runAt's select string; seam=none (runAt's existing Runner parameter); no_claim=bun execution (recording runner)
|
|
test('runAt passes ./-prefixed paths to a bun select', () => {
|
|
const repo = makeFixtureRepo({ pregate: DETECTED });
|
|
repos.push(repo);
|
|
const prev = process.env.GSTACK_STATE_ROOT;
|
|
process.env.GSTACK_STATE_ROOT = path.join(repo.work, '..', 'state');
|
|
try {
|
|
const seen: string[] = [];
|
|
const sha = execFileSync('git', ['-C', repo.work, 'rev-parse', 'HEAD'], { encoding: 'utf8', timeout: 10_000 }).trim();
|
|
runAt(repo.work, sha, { select: 'bun test {files}', timeout_sec: 30 } as never, [TEST, 'test/a.test.ts'], (_d, cmd) => { seen.push(cmd); return { status: 0, out: '' }; });
|
|
expect(seen).toEqual(["bun test './.github/scripts/select.test.mjs' './test/a.test.ts'"]);
|
|
} finally {
|
|
if (prev === undefined) delete process.env.GSTACK_STATE_ROOT; else process.env.GSTACK_STATE_ROOT = prev;
|
|
}
|
|
});
|
|
});
|