mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 06:04:33 +01:00
/ship's test step says when it hits its time limit, and long test file lists no longer overflow the remote command (GST-2958) (#4429)
* 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>
This commit is contained in:
1 parent
e8c8625bd6
commit
aeb74eb00b
11 files changed
+146
-20
No files matched your search
@@ -73,8 +73,9 @@ describe.skipIf(process.platform === 'win32')('lanes check on a test under a hid
|
||||
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: ')) ?? '';
|
||||
expect(run).toContain('./.github/scripts/select.test.mjs');
|
||||
expect(run).not.toMatch(/'\.github\/scripts/);
|
||||
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
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
* one test per file argument, so the lane's count proves every file reached a runner.
|
||||
*/
|
||||
import { afterEach, describe, expect, test } from 'bun:test';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { argBudget, argChunks } from '../lib/pregate/checks/lanes';
|
||||
import { buildContext } from '../lib/pregate/context';
|
||||
import { classifyEnvironment } from '../lib/pregate/environment';
|
||||
@@ -24,18 +27,18 @@ const RUNNER = [
|
||||
'process.exit(failed ? 1 : 0);',
|
||||
].join('\n');
|
||||
|
||||
async function lanesOver(tests: string[]) {
|
||||
async function pregateOver(tests: string[], machine: { cores: number; testBackend: string }) {
|
||||
const repo = makeFixtureRepo({
|
||||
pregate: { ...BASE_PREGATE, runner: 'node scripts/count.js {files}', dependencies: { ...BASE_PREGATE.dependencies, 'src/big/**': tests } },
|
||||
baseFiles: Object.fromEntries([...tests.map(t => [t, "require('node:test');\n"]), ['src/big/.keep', ''], ['scripts/count.js', `${RUNNER}\n`]]),
|
||||
});
|
||||
repos.push(repo);
|
||||
commit(repo, { 'src/big/f.js': 'exports.n = 1;\n' }, 'touch the big tree');
|
||||
const loaded = buildContext({ repoRoot: repo.work, base: 'main', policyFrom: 'base', allowRepoCommands: true, env: { ...process.env, ...repo.env }, progress: () => {}, cores: 64, testBackend: 'local' });
|
||||
const loaded = buildContext({ repoRoot: repo.work, base: 'main', policyFrom: 'base', allowRepoCommands: true, env: { ...process.env, ...repo.env }, progress: () => {}, ...machine });
|
||||
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')!;
|
||||
return runPregate(loaded.ctx, { stage: 'tests', only: ['lanes'] });
|
||||
}
|
||||
const lanesOver = async (tests: string[]) => (await pregateOver(tests, { cores: 64, testBackend: 'local' })).checks.find(c => c.id === 'lanes')!;
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('a local lane whose file list is over the per-argument limit', () => {
|
||||
// Value: protects=a unit group whose quoted file list is over Linux's 128 KiB per-argument cap still launches and every file
|
||||
@@ -54,6 +57,35 @@ describe.skipIf(process.platform === 'win32')('a local lane whose file list is o
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('the test backend command for a file list over the per-argument limit', () => {
|
||||
// Value: protects=on a small machine with a remote test_backend, the printed command passes the selected files in a setup
|
||||
// script, so it stays short and, run the way ubi-runner runs it on the VM (setup, then bash -c <command>), every file reaches
|
||||
// the runner; fails_when=the files go back into the command, which reaches the VM as one argument (E2BIG on Linux);
|
||||
// why_new=the remote-gate half of #4424; seam=runPregate --only lanes, the setup file, bash; no_claim=ubi-runner's transport
|
||||
test('the files travel in the setup script, the command stays short, and running both reaches every file', async () => {
|
||||
const tests = Array.from({ length: FILES }, (_, i) => name(i));
|
||||
const quoted = tests.map(t => `'${t}'`).join(' ');
|
||||
expect(quoted.length).toBeGreaterThan(128 * 1024);
|
||||
if (process.platform === 'linux') expect((spawnSync('bash', ['-c', `true ${quoted}`], { timeout: 30_000 }).error as NodeJS.ErrnoException | undefined)?.code).toBe('E2BIG');
|
||||
const file = await pregateOver(tests, { cores: 4, testBackend: 'ubicloud' });
|
||||
expect(file.checks.find(c => c.id === 'lanes')!.status).toBe('requires-remote');
|
||||
const command = file.requires_remote!.find(o => o.lane === 'test_backend/ubicloud')!.command!;
|
||||
expect(command.length).toBeLessThan(2048);
|
||||
const argv = spawnSync('bash', ['-c', 'eval "set -- $1"; printf "%s\\0" "$@"', '_', command], { encoding: 'utf8', timeout: 30_000 }).stdout.split('\0').slice(0, -1);
|
||||
expect(argv.slice(1, 3)).toEqual(['run', '--src']);
|
||||
expect(argv[4]).toBe('--setup');
|
||||
expect(argv[6]).toBe('--');
|
||||
const setup = fs.readFileSync(argv[5]!, 'utf8');
|
||||
expect(setup.split('\n').filter(l => l.startsWith('test/big/'))).toEqual(tests);
|
||||
const vm = repos.at(-1)!;
|
||||
const env = { ...process.env, HOME: fs.mkdtempSync(path.join(vm.root, 'vm-home-')) };
|
||||
expect(spawnSync('bash', [argv[5]!], { cwd: vm.work, env, timeout: 30_000 }).status).toBe(0);
|
||||
const ran = spawnSync('bash', ['-c', argv[7]!], { cwd: vm.work, env, encoding: 'utf8', timeout: 60_000 });
|
||||
expect(ran.stdout).toContain(`ℹ tests ${FILES}\n`);
|
||||
expect(ran.status).toBe(0);
|
||||
}, 120_000);
|
||||
});
|
||||
|
||||
describe('argChunks and argBudget', () => {
|
||||
// Value: protects=the split keeps order, drops nothing and keeps each chunk's quoted text under the budget, with an oversized
|
||||
// argument alone in its chunk, and the budget stays under Linux's per-argument cap and shrinks with the environment;
|
||||
|
||||
@@ -68,11 +68,21 @@ describe('small machines record the test tier for the remote gate (C4)', () => {
|
||||
expect(viaBackend.lanes.status).toBe('requires-remote');
|
||||
const obligation = viaBackend.file.requires_remote![0]!;
|
||||
expect(obligation.lane).toBe('test_backend/ubicloud');
|
||||
expect(obligation.command).toMatch(/scripts\/ubicloud\/ubi-runner\.sh run --src '.*\/work' -- 'node --test '\\''test\/util\.test\.js'\\'''$/);
|
||||
expect(obligation.command).toMatch(/scripts\/ubicloud\/ubi-runner\.sh run --src '.*\/work' --setup '(.*\/remote-files\/[0-9a-f]{16}\.sh)' -- 'mapfile -t PREGATE_FILES < ~\/\.pregate-files\.txt && node --test "\$\{PREGATE_FILES\[@\]\}"'$/);
|
||||
expect(fs.readFileSync(/--setup '([^']+)'/.exec(obligation.command!)![1]!, 'utf8')).toBe("cat > ~/.pregate-files.txt <<'PREGATE_FILES'\ntest/util.test.js\nPREGATE_FILES\n");
|
||||
expect((await lanesOn(backend, { cores: 4, testBackend: 'local' })).lanes.status).toBe('pass');
|
||||
expect((await lanesOn(gated(), { cores: 16, testBackend: 'local' })).lanes.status).toBe('pass');
|
||||
});
|
||||
|
||||
test.skipIf(process.platform === 'win32')('a selected test path the file list cannot hold (a newline) keeps the quoted inline command, so it cannot end the list and run as shell', async () => {
|
||||
const backend = gated(BASE_PREGATE);
|
||||
const odd = 'test/odd\nPREGATE_FILES\nname.test.js';
|
||||
commit(backend, { [odd]: "require('node:test')('ok', () => {});\n" });
|
||||
const command = (await lanesOn(backend, { cores: 4, testBackend: 'ubicloud' })).file.requires_remote![0]!.command!;
|
||||
expect(command).not.toContain('--setup');
|
||||
expect(command).toContain(odd);
|
||||
});
|
||||
|
||||
test('`clear` on the remote_gate obligation needs the gate\'s PREGATE_REMOTE receipt for the tested tree; a run URL or a bad receipt leaves it uncleared', async () => {
|
||||
const repo = gated();
|
||||
const fileAt = path.join(repo.work, '.gstack/tmp/pregate.json');
|
||||
|
||||
@@ -412,6 +412,26 @@ describe('gstack-ship-preflight Step 5 pregate: head policy and timeout_s (GST-4
|
||||
expect(u.stdout + u.stderr).toContain('--timeout needs whole seconds from 1 to 3600');
|
||||
}
|
||||
});
|
||||
|
||||
// Value: protects=a caller sets the whole Step 5 pregate's budget, and a kill at that limit says the limit was hit and names the
|
||||
// way out instead of "unreadable (exit 143)"; fails_when=the budget is a fixed hour, or a timed-out pregate reads as unreadable;
|
||||
// why_new=Vorflux via FOUN-32: gbrain's unit and serial suite ran past the fixed hour on 8-core Linux; seam=gstack-pregate under
|
||||
// preflight's spawn limit; no_claim=the finish fallback's own pregate limit
|
||||
test('--step-timeout bounds the whole Step 5 pregate, and a kill at the limit says so with the way out', () => {
|
||||
const slow = "const test = require('node:test');\ntest('slow', async () => { await new Promise(r => setTimeout(r, 30000)); });\n";
|
||||
const f = fx(base({ timeout_s: 600 }), { 'test/slow.serial.test.js': slow });
|
||||
const r = f.run(PREFLIGHT, ['--tests-only', '--base', 'main', '--step-timeout', '3', '--lane', LANE]);
|
||||
expect(r.status).toBe(3);
|
||||
expect(lineOf(r.stdout, 'PREGATE')).toMatch(/^PREGATE: time limit hit \(Step 5's whole pregate ran past its 3 s budget, --step-timeout, and was stopped with exit \S+; no verdict\)$/);
|
||||
expect(lineOf(r.stdout, 'STOP')).toBe("STOP: the tests are longer than this step's 3 s budget on this machine: push, let CI's full run at this tree carry them (gstack-ci-carry wait --base main, then rerun --tests-only; gbrain docs/ci-event-parity.md#ship-lanes), or rerun --tests-only with --step-timeout <s> above 3");
|
||||
expect(r.stdout).not.toContain('unreadable');
|
||||
expect(r.stdout).not.toContain('LANE: tests');
|
||||
for (const bad of ['0', '86401', '1.5', 'x']) {
|
||||
const u = f.run(PREFLIGHT, ['--tests-only', '--base', 'main', '--step-timeout', bad, '--lane', LANE]);
|
||||
expect(u.status).toBe(2);
|
||||
expect(u.stdout + u.stderr).toContain('--step-timeout needs whole seconds from 1 to 86400');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-ship-preflight during an open /ship run (GST-1204)', () => {
|
||||
|
||||
Reference in new issue
Block a user