Files
gstack/test/paid-shard-settlement.test.ts
T
Garry Tan dcaea52800 v1.91.7.0 feat: add functional QA and pre-publication docs checks (#2983)
* feat: add surface-aware exploratory QA and ship documentation gates

* test: preserve delegated QA setup authority after main integration

* fix(qa): clarify exploration order and preserve report artifacts

* test(qa): follow the shared setup reference directly

* refactor(ship): make verification and recovery routes explicit

* test(ship): align evidence and review guards with explicit routes

* fix(workflows): clarify ship recovery and functional QA evidence

* fix(workflows): clarify approval recovery and full QA coverage

* refactor(workflows): order review transactions and clarify ship state

* fix(ship): clarify final verification and fail closed at publication

* fix(evals): attribute native atomic documentation writes

* fix(ship): clarify recovery and documentation lifecycle guidance

* fix(test): preserve observed native placeholder styling in CI

* fix(codex): report watchdog timeouts without a process-exit race

* Checkpoint functional QA implementation and workflow validation repairs

* Fix documentation and shared-review fixture contracts

* docs: clarify judge reuse and evaluation supervision

* test: align review evidence and selected case contracts

* test: verify append-only documentation checkpoints and recovery

* fix: qualify QA workflows and CI validation repairs

* fix: launch shared-libs fixture scripts on Windows

* fix: qualify QA deadlines, fixture isolation, and shard cleanup

* fix: preserve qualified QA and cancellation repairs

* fix: enforce functional fixture authority and share strict event decoding

* fix: retain free-test evidence and explain recovery

* fix: reject malformed native evidence after decoder consolidation

* test: use reliable capture for telemetry privacy filters

* test: refresh measured quick coverage and document validation costs

* Fix native fixture receipts and preserve VM validation evidence

* Align negative judge controls with upstream clarity policy

* Fix report-only QA preparation and public evidence handling

* Clarify QA-only preparation and current-report preservation

* Stream Ship quality judgments with an explicit 64k response contract

* Validate compact judge reasoning locally with supported wire schema

* Align functional QA fixture instructions with evidence acceptance

* Bind native browser diagnostics to execution evidence and align review verdicts

* Preserve native diagnostic line boundaries

* Serialize functional QA evidence from native captures

* Keep large QA evidence fixture payload out of Windows argv
2026-09-29 06:07:35 -07:00

84 lines
3.5 KiB
TypeScript

import { expect, test } from 'bun:test';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { spawnSync } from 'node:child_process';
const root = path.resolve(import.meta.dir, '..');
test.each(['complete', 'delayed', 'stalled', 'closed', 'error'])('paid spool settlement through the registered caller: %s', scenario => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'paid-spool-'));
try {
const script = `
import fs from 'node:fs';
import { EventEmitter } from 'node:events';
import { mock } from 'bun:test';
const scenario = ${JSON.stringify(scenario)};
const directory = ${JSON.stringify(dir)};
let opened = 0, ended = 0, destroyed = 0;
mock.module('node:fs', () => ({ ...fs, createWriteStream(filename) {
opened++;
const fd = fs.openSync(filename, 'wx', 0o600);
let closed = false;
const stream = new EventEmitter();
stream.writableFinished = false;
stream.destroyed = false;
stream.write = chunk => { fs.writeSync(fd, chunk); return true; };
stream.destroy = () => {
if (!closed) { fs.closeSync(fd); closed = true; destroyed++; }
stream.destroyed = true;
queueMicrotask(() => stream.emit('close'));
return stream;
};
stream.end = callback => {
ended++;
const finish = () => {
stream.writableFinished = true;
stream.emit('finish');
callback?.();
stream.destroy();
};
if (scenario === 'complete') queueMicrotask(finish);
if (scenario === 'delayed') setTimeout(finish, 25);
if (scenario === 'closed') stream.destroy();
if (scenario === 'error') queueMicrotask(() => stream.emit('error', new Error('fixture spool failure')));
return stream;
};
return stream;
}}));
const { runPaidShards } = await import(${JSON.stringify(path.join(root, 'scripts/test-paid-shards.ts'))});
const lines = [];
const started = Date.now();
const result = await runPaidShards([['spool-control']], {
rootDir: ${JSON.stringify(root)}, timeoutMs: 1_000, jobs: 1, logDir: directory,
commandFor: () => ({ command: process.execPath, args: ['-e', 'console.log("retained evidence"); console.log("Ran 1 tests across 1 files. [1ms]")'] }),
log: line => lines.push(line),
});
console.log('SETTLEMENT_RESULT:' + JSON.stringify({ result, elapsed: Date.now() - started, opened, ended, destroyed, lines }));
`;
const child = spawnSync(process.execPath, ['-e', script], {
cwd: root, encoding: 'utf8', timeout: 10_000,
env: { ...process.env, EVALS: '', EVALS_TIER: '', EVALS_SHARD_TIMEOUT_MS: '' },
});
expect(child.error, child.stderr).toBeUndefined();
expect(child.status, child.stderr).toBe(0);
const line = child.stdout.split('\n').find(line => line.startsWith('SETTLEMENT_RESULT:'));
expect(line).toBeDefined();
const facts = JSON.parse(line!.slice('SETTLEMENT_RESULT:'.length));
expect(facts.opened).toBe(1);
expect(facts.ended).toBe(1);
expect(facts.destroyed).toBe(1);
expect(facts.elapsed).toBeLessThan(2_500);
expect(facts.result.executed).toBe(1);
expect(facts.result.neverStarted).toBe(0);
expect(facts.result.outcomes[0].status).toBe(
['complete', 'delayed'].includes(scenario) ? 'passed' : scenario === 'stalled' ? 'timed-out' : 'failed',
);
const logs = fs.readdirSync(dir).filter(name => name.endsWith('.log'));
expect(logs).toHaveLength(1);
expect(fs.readFileSync(path.join(dir, logs[0]), 'utf8')).toBe('retained evidence\nRan 1 tests across 1 files. [1ms]\n');
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
}, 30_000);