Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(test:stress): stress a wrapper-laned PostgreSQL arm through its test/e2e wrapper

garrytana7d63ab7e484
diff --git a/scripts/stress/README.md b/scripts/stress/README.md
index 686d66feb9..fbbf10d188 100644
--- a/scripts/stress/README.md
+++ b/scripts/stress/README.md
@@ -54,7 +54,7 @@ passed, 1 a failure, 2 a usage or setup error, 130/143 cancelled.
| `unit` | `*.test.ts` | `bun test --timeout=60000`, `DATABASE_URL` unset |
| `serial` | `*.serial.test.ts` | `bun test --max-concurrency=1 --timeout=120000`, `DATABASE_URL` unset; files run one at a time |
| `slow` | `*.slow.test.ts` | the workflow's pull-request values (`SPECIAL_FILES` in `plan.ts`: export scale at 10,001 pages, the pre-feature executable built for the old-binary suite) |
-| `postgres-arm` | a file with a `DATABASE_URL`-gated arm, with `--postgres` | `bun --no-env-file test --timeout=120000` with a fresh `DATABASE_URL`: both arms, as in `unit-postgres-arms` |
+| `postgres-arm` | a file with a `DATABASE_URL`-gated arm laned by `test/postgres-unit-arms.txt` or a `DATABASE_URL` workflow step, with `--postgres` | `bun --no-env-file test --timeout=120000` with a fresh `DATABASE_URL`: both arms, as in `unit-postgres-arms`. A file whose arm runs only through a `test/e2e/` wrapper (`registerPostgresTests`) runs in its suffix profile and its wrapper is stressed as an `e2e` file |
| `e2e` | `test/e2e/*.test.ts`, with `--postgres` | `bash scripts/run-e2e.sh <file>` with a fresh `DATABASE_URL` |
Paid-provider files (`*.live.test.ts`, `test/live/`,
diff --git a/scripts/stress/gate.ts b/scripts/stress/gate.ts
index 1fed331a06..3cbeeb2c9d 100644
--- a/scripts/stress/gate.ts
+++ b/scripts/stress/gate.ts
@@ -24,6 +24,7 @@ import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statS
import { dirname, join, resolve } from 'node:path';
import { inert, restClient, type GitHubClient } from '../lib/gh-issue.ts';
import { postgresArm } from '../check-postgres-lane-coverage.ts';
+import { armMode } from './plan.ts';
import { readArmsList } from '../postgres-unit-arms.ts';
import {
DEFAULT_ITERATIONS, RACE_HUNT_DOCS, STRESS_DOCS, allTestFiles, changedFiles, expandHelper, iterationEstimateMs,
@@ -68,8 +69,7 @@ function classify(root: string, files: string[], weights: Weights): { stress: Ar
if (!existsSync(join(root, file))) { notStressed.push({ file, reason: 'no such file at the head commit' }); continue; }
const reason = notStressedReason(file, live);
if (reason) { notStressed.push({ file, reason }); continue; }
- const armed = !file.startsWith('test/e2e/') && postgresArm(join(root, file)) !== null;
- const profile = profileFor(file, { armed, postgres: true });
+ const profile = profileFor(file, { armed: armMode(root, file).armed, postgres: true });
const perIterationMs = iterationEstimateMs(file, profile.name, weights);
stress.push({ file, profile: profile.name, iterations: DEFAULT_ITERATIONS, estimateMs: 0, perIterationMs, setupMs: profile.prereq ? 180_000 : 0 });
}
@@ -112,6 +112,7 @@ export function planGate(root: string, input: GatePlanInput, weights = loadWeigh
} else {
return emptyPlan('gate', 'not a PR event');
}
+ files = withWrappers(root, files);
const { stress, notStressed } = classify(root, files, weights);
const shards = planShards(stress, DEFAULT_ITERATIONS, GATE_SHARD_BUDGET_MS);
return {
@@ -122,6 +123,11 @@ export function planGate(root: string, input: GatePlanInput, weights = loadWeigh
};
}
+/** Add the test/e2e wrapper that owns each file's PostgreSQL arm. */
+function withWrappers(root: string, files: string[]): string[] {
+ return [...new Set([...files, ...files.map(f => armMode(root, f).wrapper).filter((w): w is string => !!w && existsSync(join(root, w)))])].sort();
+}
+
const estimateOf = (shards: Shard[], file: string) => shards.flatMap(s => s.items).filter(i => i.file === file).reduce((s, i) => s + i.estimateMs, 0);
function resolveSha(root: string, ref: string): string {
diff --git a/scripts/stress/plan.ts b/scripts/stress/plan.ts
index 7b8c8bd3d9..65edd88343 100644
--- a/scripts/stress/plan.ts
+++ b/scripts/stress/plan.ts
@@ -11,6 +11,7 @@ import { spawnSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { dirname, join, normalize, relative } from 'node:path';
+import { postgresArm, postgresLanes } from '../check-postgres-lane-coverage.ts';
export const STRESS_DOCS = 'docs/TESTING.md#stress-gate';
export const RACE_HUNT_DOCS = 'docs/TESTING.md#race-hunt';
@@ -78,6 +79,22 @@ export function profileFor(file: string, opts: { armed: boolean; postgres: boole
return { ...base, ...special, vars: { ...base.vars, ...(special.vars ?? {}) }, name: base.name, env: base.env, arm: base.arm };
}
+let lanes: Map<string, string> | undefined;
+
+/**
+ * How a file's DATABASE_URL-gated PostgreSQL arm runs. A file in
+ * test/postgres-unit-arms.txt or a DATABASE_URL workflow step runs it with
+ * DATABASE_URL set (`armed`); a file whose only lane is a test/e2e wrapper
+ * (registerPostgresTests, GBRAIN_TEST_BACKEND=postgres) runs it only through
+ * that wrapper, so the wrapper is stressed instead.
+ */
+export function armMode(root: string, file: string): { armed: boolean; wrapper?: string } {
+ if (file.startsWith('test/e2e/') || !existsSync(join(root, file)) || !postgresArm(join(root, file))) return { armed: false };
+ lanes ??= postgresLanes();
+ const lane = lanes.get(file);
+ return lane?.startsWith('test/e2e/') ? { armed: false, wrapper: lane } : { armed: true };
+}
+
/** Database URLs and tokens never reach a printed line. */
export function redact(text: string): string {
return text
diff --git a/scripts/stress/run.ts b/scripts/stress/run.ts
index be83baf6aa..5899d9a734 100644
--- a/scripts/stress/run.ts
+++ b/scripts/stress/run.ts
@@ -33,9 +33,8 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync
import { join, resolve } from 'node:path';
import postgres from '#postgres';
import { parseJUnit, type TestCase } from '../ci-executed-counts.ts';
-import { postgresArm } from '../check-postgres-lane-coverage.ts';
import {
- DEFAULT_ITERATIONS, STRESS_DOCS, TEST_PATH_RE, allTestFiles, changedFiles, defaultSeed, expandHelper,
+ DEFAULT_ITERATIONS, STRESS_DOCS, TEST_PATH_RE, allTestFiles, armMode, changedFiles, defaultSeed, expandHelper,
notStressedReason, parseFileList, profileFor, redact, reproduceLine, validRef, type HelperExpansion, type Profile,
} from './plan.ts';
@@ -431,10 +430,16 @@ async function main(argv: string[]): Promise<number> {
const liveKeyOnly = new Set(existsSync(livePath) ? readFileSync(livePath, 'utf8').split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#')) : []);
const missing = selection.files.filter(f => !existsSync(join(ROOT, f)));
if (missing.length) { console.error(`test:stress: no such file: ${missing.join(', ')}. Fix: pass repo-relative paths of existing test files. Docs: ${STRESS_DOCS}`); return 2; }
+ if (args.postgres && !args.work) {
+ for (const f of [...selection.files]) {
+ const wrapper = armMode(ROOT, f).wrapper;
+ if (wrapper && existsSync(join(ROOT, wrapper)) && !selection.files.includes(wrapper)) { selection.files.push(wrapper); log(` ${f}: its PostgreSQL arm runs through ${wrapper}; stressing that wrapper too`); }
+ }
+ }
const plan = selection.files.map(file => {
const reason = notStressedReason(file, liveKeyOnly);
- const armed = !file.startsWith('test/e2e/') && postgresArm(join(ROOT, file)) !== null;
- return { file, reason, armed, profile: profileFor(file, { armed, postgres: args.postgres }) };
+ const mode = armMode(ROOT, file);
+ return { file, reason, armed: mode.armed || !!mode.wrapper, profile: profileFor(file, { armed: mode.armed, postgres: args.postgres }) };
});
const needsDb = plan.filter(p => !p.reason && p.profile.env === 'database');
for (const p of plan) {
diff --git a/test/scripts/stress-gate.test.ts b/test/scripts/stress-gate.test.ts
index a89b758f90..ef7dd9d39d 100644
--- a/test/scripts/stress-gate.test.ts
+++ b/test/scripts/stress-gate.test.ts
@@ -76,6 +76,20 @@ describe('gate plan', () => {
});
});
+describe('PostgreSQL arm routing', () => {
+ // A wrapper-laned arm (registerPostgresTests) never runs with DATABASE_URL
+ // alone; the #5927 replay flagged it "never connected" 10 of 10 times.
+ test('a file whose arm runs through a test/e2e wrapper is stressed with that wrapper', () => {
+ const plan = isPlan(planGate(REPO, { event: 'workflow_dispatch', stressFiles: 'test/autopilot-auto-drain-dispatch.test.ts' }, weights()));
+ expect(plan.files.map(f => [f.file, f.profile])).toEqual([['test/autopilot-auto-drain-dispatch.test.ts', 'unit'], ['test/e2e/autopilot-auto-drain-dispatch.test.ts', 'e2e']]);
+ });
+
+ test('a listed unit-lane arm runs both arms against a fresh database', () => {
+ const plan = isPlan(planGate(REPO, { event: 'workflow_dispatch', stressFiles: 'test/managed-lint.test.ts' }, weights()));
+ expect(plan.files.map(f => [f.file, f.profile])).toEqual([['test/managed-lint.test.ts', 'postgres-arm']]);
+ });
+});
+
describe('race hunt plan', () => {
const list = (n: number) => Array.from({ length: n }, (_, i) => `test/arm-${String(i).padStart(2, '0')}.test.ts`);
function armsRepo(n: number) {