Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(test:stress): resolve receipts written outside the checkout, keep partial manifests, name an unreachable server
garrytan31b2889fa0f0
diff --git a/scripts/stress/gate.ts b/scripts/stress/gate.tsindex 733f949a52..1fed331a06 100644--- a/scripts/stress/gate.ts+++ b/scripts/stress/gate.ts@@ -308,12 +308,12 @@ export function missingWork(plan: Plan, manifests: Manifest[]): string[] {return missing;}-export interface JobTiming { name: string; created_at: string; started_at: string | null; completed_at: string | null }+export interface JobTiming { name: string; conclusion?: string | null; created_at: string; started_at: string | null; completed_at: string | null }const p95 = (xs: number[]) => { const s = [...xs].sort((a, b) => a - b); return s.length ? s[Math.min(s.length - 1, Math.ceil(0.95 * s.length) - 1)]! : 0; };/** p95 queue (created → started) and completion (created → completed) minutes of the shard jobs, and their runner-minutes. */export function shardTimings(jobs: JobTiming[]): { shards: number; p95QueueMin: number; p95CompletionMin: number; runnerMin: number } {- const shards = jobs.filter(j => /Stress shard|Race hunt shard/.test(j.name) && j.started_at && j.completed_at);+ const shards = jobs.filter(j => /Stress shard|Race hunt shard/.test(j.name) && j.conclusion !== 'skipped' && j.started_at && j.completed_at);const min = (a: string, b: string) => (Date.parse(b) - Date.parse(a)) / 60_000;return {shards: shards.length,diff --git a/scripts/stress/run.ts b/scripts/stress/run.tsindex 634f326819..be83baf6aa 100644--- a/scripts/stress/run.ts+++ b/scripts/stress/run.ts@@ -105,7 +105,16 @@ class PgServer {urlFor(db: string): string { const u = new URL(this.adminUrl); u.pathname = `/${db}`; return u.toString(); }private async sql<T>(fn: (sql: ReturnType<typeof postgres>) => Promise<T>): Promise<T> {const sql = postgres(this.adminUrl, { max: 1, onnotice: () => {}, connect_timeout: 10 });- try { return await fn(sql); } finally { await sql.end({ timeout: 5 }); }+ try {+ return await fn(sql);+ } catch (e) {+ const err = e as Error & { code?: string; errors?: Array<{ code?: string }> };+ const code = err.code ?? err.errors?.map(x => x.code).filter(Boolean).join('/') ?? '';+ if (!err.message || /ECONNREFUSED|ENOTFOUND|ETIMEDOUT|CONNECT_TIMEOUT/.test(code + err.message)) {+ throw new Error(`cannot reach the stress database server ${redact(this.adminUrl)} (${code || err.name}). Why: every database iteration clones its own database there. Fix: start the server (or unset GBRAIN_STRESS_ADMIN_URL/DATABASE_URL so --postgres starts a container) and re-run`);+ }+ throw e;+ } finally { await sql.end({ timeout: 5 }).catch(() => {}); }}async create(index: number): Promise<string> {if (!this.template) {@@ -325,7 +334,7 @@ const relativeToRoot = (p: string) => p.startsWith(ROOT) ? p.slice(ROOT.length +function killTree(pid: number) { try { process.kill(-pid, 'SIGTERM'); } catch { /* gone */ } setTimeout(() => { try { process.kill(-pid, 'SIGKILL'); } catch { /* gone */ } }, 5000).unref(); }function executedIdentities(dir: string): string[] {- const full = join(ROOT, dir);+ const full = resolve(ROOT, dir);const report = readdirSync(full).find(f => f.endsWith('.junit.xml'));if (!report) return [];try { return parseJUnit(readFileSync(join(full, report), 'utf8')).filter(c => c.status === 'pass' || c.status === 'fail').map(c => c.test); } catch { return []; }@@ -455,6 +464,8 @@ async function main(argv: string[]): Promise<number> {process.on('SIGTERM', onSignal(143));const results: FileResult[] = [];+ let setupMs = 0;+ const runStarted = Date.now();try {if (needsDb.length) {if (!args.postgres) {@@ -471,9 +482,8 @@ async function main(argv: string[]): Promise<number> {if (built.status !== 0) throw new Error(`building the pre-feature executable failed (scripts/build-shared-skills-baseline.sh): ${built.stderr.trim().split('\n').pop()}`);ctx.oldBinary = bin;}- const setupMs = Date.now() - setupStarted;+ setupMs = Date.now() - setupStarted;log(` setup ${(setupMs / 1000).toFixed(1)}s`);- const runStarted = Date.now();for (const p of plan) {if (p.reason) { results.push({ file: p.file, profile: p.profile.name, env: p.profile.env, arm: p.profile.arm, status: 'not-stressed', reason: p.reason, seedBase: 0, firstIteration: 1, iterations: [], reproduce: '' }); continue; }const items = args.work ? args.work.filter(w => w.file === p.file) : [{ file: p.file, first: args.firstIteration, count: args.iterations }];@@ -483,7 +493,8 @@ async function main(argv: string[]): Promise<number> {const manifest = writeManifest(ctx, results, selection, setupMs, runMs);return summarize(results, manifest, setupMs, runMs);} catch (e) {- console.error(`test:stress: ${(e as Error).message}\n Docs: ${STRESS_DOCS}`);+ console.error(`test:stress: ${(e as Error).message || String(e)}\n Docs: ${STRESS_DOCS}`);+ if (results.length) writeManifest(ctx, results, selection, setupMs, Date.now() - runStarted);return 2;} finally {await ctx.pg?.close().catch(() => {});diff --git a/test/scripts/stress-gate.test.ts b/test/scripts/stress-gate.test.tsindex 923f498389..a89b758f90 100644--- a/test/scripts/stress-gate.test.ts+++ b/test/scripts/stress-gate.test.ts@@ -175,7 +175,7 @@ describe('report', () => {test('p95 queue and completion come from the shard jobs only', () => {const t = (name: string, c: number, s: number, e: number) => ({ name, created_at: new Date(c * 60_000).toISOString(), started_at: new Date(s * 60_000).toISOString(), completed_at: new Date(e * 60_000).toISOString() });- const timings = shardTimings([t('stress-changed-tests / Stress shard 1', 0, 1, 11), t('stress-changed-tests / Stress shard 2', 0, 3, 23), t('test (1)', 0, 0, 99)]);+ const timings = shardTimings([t('stress-changed-tests / Stress shard 1', 0, 1, 11), t('stress-changed-tests / Stress shard 2', 0, 3, 23), t('test (1)', 0, 0, 99), { ...t('race-hunt / Race hunt shard ${{ matrix.shard }}', 0, 0, 0), conclusion: 'skipped' }]);expect(timings).toEqual({ shards: 2, p95QueueMin: 3, p95CompletionMin: 23, runnerMin: 30 });});});diff --git a/test/scripts/test-stress.test.ts b/test/scripts/test-stress.test.tsindex c0c4efd233..67cae18233 100644--- a/test/scripts/test-stress.test.ts+++ b/test/scripts/test-stress.test.ts@@ -26,8 +26,11 @@ function stress(root: string, ...args: string[]) {const env: Record<string, string | undefined> = { ...process.env, GBRAIN_STRESS_ROOT: root };delete env.DATABASE_URL;delete env.GITHUB_SHA;- const r = spawnSync(process.execPath, [RUNNER, ...args, '--out', join(root, 'out')], { encoding: 'utf8', env, timeout: 120_000 });- const manifestPath = join(root, 'out', 'stress-manifest.json');+ // CI writes receipts outside the checkout ($RUNNER_TEMP); so does this test.+ const out = mkdtempSync(join(tmpdir(), 'gbrain-test-stress-out-'));+ dirs.push(out);+ const r = spawnSync(process.execPath, [RUNNER, ...args, '--out', out], { encoding: 'utf8', env, timeout: 120_000 });+ const manifestPath = join(out, 'stress-manifest.json');return { code: r.status, out: `${r.stdout}\n${r.stderr}`, manifest: existsSync(manifestPath) ? JSON.parse(readFileSync(manifestPath, 'utf8')) : undefined };}@@ -40,7 +43,7 @@ describe('test:stress runner', () => {expect(file).toMatchObject({ file: 'test/stable.test.ts', profile: 'unit', env: 'no-database', status: 'pass', seedBase: 40 });expect(file.iterations.map((it: { index: number; seed: number; executed: number }) => [it.index, it.seed, it.executed])).toEqual([[1, 40, 2], [2, 41, 2], [3, 42, 2]]);for (const it of file.iterations) {- const dir = join(root, it.receipt);+ const dir = it.receipt;expect(readdirSync(dir).filter(f => f.endsWith('.junit.xml') || f.endsWith('.receipt')).sort()).toEqual(['stress--stable.test.ts-i' + it.index + '--primary.receipt', 'stress.junit.xml']);}expect(r.out).toContain('setup');