Files
gstack/test/readme-throughput.test.ts
Garry TanandClaude Fable 5 3e674e4c01 fix: sweep — every sync spawn in the test trees carries a timeout (436 sites, 157 files)
spawnSync/execSync/Bun.spawnSync BLOCK the main thread, so bun's in-process
per-test timeout can never fire while one waits — a hung child (stdin read,
network probe, dead daemon) wedges the whole shard until the runner's
external wall-clock SIGKILL. This exact class reached main: free-tests run
33262077256, test/gstack-memory-ingest.test.ts (normally 2.3s) held shard 2
at the 360s wall while its five siblings finished in ~65s.

Mechanical sweep in two waves (12 + 4 fan-out agents, every edit verified
against its call site): default timeout: 30_000 (matches the free runner's
per-test budget), 120_000 for genuinely slow ops (installs, builds,
playwright, provider CLIs), helper wrappers fixed ONCE where call sites
route through them. Sites that only LOOK like calls (string fixtures, grep
needles, comments) were skipped with reasons — the enforcement commit that
follows marks them exempt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 04:49:57 +00:00

115 lines
3.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* scripts/update-readme-throughput.ts + README anchor + CI pending-marker gate.
*
* Coverage:
* - Happy path: JSON present, anchor gets replaced with number + anchor preserved
* - Missing JSON: script writes PENDING marker, CI would reject
* - Invalid JSON: script errors, README untouched
* - CI gate: committed README must not contain PENDING marker
*/
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import { spawnSync } from 'child_process';
const ROOT = path.resolve(import.meta.dir, '..');
const SCRIPT = path.join(ROOT, 'scripts', 'update-readme-throughput.ts');
const ANCHOR = '<!-- GSTACK-THROUGHPUT-PLACEHOLDER -->';
const PENDING = 'GSTACK-THROUGHPUT-PENDING';
let tmpDir: string;
let tmpReadme: string;
let tmpJsonPath: string;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-readme-test-'));
tmpReadme = path.join(tmpDir, 'README.md');
fs.mkdirSync(path.join(tmpDir, 'docs'), { recursive: true });
tmpJsonPath = path.join(tmpDir, 'docs', 'throughput-2013-vs-2026.json');
});
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
function runScript(cwd: string): { stdout: string; stderr: string; status: number } {
const res = spawnSync('bun', ['run', SCRIPT], {
encoding: 'utf-8',
cwd,
env: { ...process.env },
timeout: 30_000,
});
return {
stdout: (res.stdout ?? '').trim(),
stderr: (res.stderr ?? '').trim(),
status: res.status ?? -1,
};
}
describe('update-readme-throughput script', () => {
test('happy path: JSON present → anchor replaced with number', () => {
fs.writeFileSync(tmpReadme, `gstack hero: ${ANCHOR} 2013 pro-rata.\n`);
fs.writeFileSync(tmpJsonPath, JSON.stringify({
multiples: { logical_lines_added: 12.3 },
}));
const result = runScript(tmpDir);
expect(result.status).toBe(0);
const updated = fs.readFileSync(tmpReadme, 'utf-8');
expect(updated).toContain('12.3×');
expect(updated).toContain(ANCHOR); // anchor stays for next run
expect(updated).not.toContain(PENDING);
});
test('missing JSON: PENDING marker written (CI rejects)', () => {
fs.writeFileSync(tmpReadme, `gstack hero: ${ANCHOR} 2013 pro-rata.\n`);
// No JSON written
const result = runScript(tmpDir);
expect(result.status).toBe(0);
const updated = fs.readFileSync(tmpReadme, 'utf-8');
expect(updated).toContain(PENDING);
expect(updated).toContain(ANCHOR); // anchor preserved for next run
});
test('JSON with null multiple: PENDING marker written (honest missing state)', () => {
fs.writeFileSync(tmpReadme, `gstack hero: ${ANCHOR} 2013 pro-rata.\n`);
fs.writeFileSync(tmpJsonPath, JSON.stringify({
multiples: { logical_lines_added: null },
}));
const result = runScript(tmpDir);
expect(result.status).toBe(0);
const updated = fs.readFileSync(tmpReadme, 'utf-8');
expect(updated).toContain(PENDING);
expect(updated).not.toMatch(/null×/);
});
test('anchor already replaced: script is a no-op', () => {
fs.writeFileSync(tmpReadme, 'gstack hero: 7.0× already set.\n');
// No anchor in README → nothing to replace
const result = runScript(tmpDir);
expect(result.status).toBe(0);
const updated = fs.readFileSync(tmpReadme, 'utf-8');
expect(updated).toBe('gstack hero: 7.0× already set.\n');
});
});
describe('CI gate: committed README must not contain PENDING marker', () => {
// This is the core reason the PENDING marker exists. A commit that lands
// the README with the pending string means the build didn't run.
test('real README.md does not contain GSTACK-THROUGHPUT-PENDING', () => {
const readmePath = path.join(ROOT, 'README.md');
if (!fs.existsSync(readmePath)) return; // Fresh clone edge-case
const content = fs.readFileSync(readmePath, 'utf-8');
expect(content).not.toContain(PENDING);
});
});