perf(test): trim fixture and serialization overhead in integration suites

This commit is contained in:
Peter Steinberger
2026-03-03 01:08:52 +00:00
parent 588fbd5b68
commit d7bafae387
5 changed files with 70 additions and 114 deletions

View File

@@ -82,15 +82,6 @@ describe("runCronIsolatedAgentTurn auth profile propagation (#20624)", () => {
authProfileIdSource?: string; authProfileIdSource?: string;
}; };
console.log(`authProfileId passed to runEmbeddedPiAgent: ${callArgs?.authProfileId}`);
console.log(`authProfileIdSource passed: ${callArgs?.authProfileIdSource}`);
if (!callArgs?.authProfileId) {
console.log("❌ BUG CONFIRMED: isolated cron session does NOT pass authProfileId");
console.log(" This causes 401 errors when using providers that require auth profiles");
}
// This assertion will FAIL on main — proving the bug
expect(callArgs?.authProfileId).toBe("openrouter:default"); expect(callArgs?.authProfileId).toBe("openrouter:default");
}); });
}); });

View File

@@ -124,6 +124,10 @@ async function writeCronJobs(storePath: string, jobs: CronJob[]) {
await fs.writeFile(storePath, JSON.stringify({ version: 1, jobs }), "utf-8"); await fs.writeFile(storePath, JSON.stringify({ version: 1, jobs }), "utf-8");
} }
async function writeCronStoreSnapshot(storePath: string, jobs: unknown[]) {
await fs.writeFile(storePath, JSON.stringify({ version: 1, jobs }), "utf-8");
}
async function startCronForStore(params: { async function startCronForStore(params: {
storePath: string; storePath: string;
cronEnabled?: boolean; cronEnabled?: boolean;
@@ -214,26 +218,20 @@ describe("Cron issue regressions", () => {
it("repairs isolated every jobs missing createdAtMs and sets nextWakeAtMs", async () => { it("repairs isolated every jobs missing createdAtMs and sets nextWakeAtMs", async () => {
const store = makeStorePath(); const store = makeStorePath();
await fs.writeFile( await writeCronStoreSnapshot(store.storePath, [
store.storePath, {
JSON.stringify({ id: "legacy-isolated",
version: 1, agentId: "feature-dev_planner",
jobs: [ sessionKey: "agent:main:main",
{ name: "legacy isolated",
id: "legacy-isolated", enabled: true,
agentId: "feature-dev_planner", schedule: { kind: "every", everyMs: 300_000 },
sessionKey: "agent:main:main", sessionTarget: "isolated",
name: "legacy isolated", wakeMode: "now",
enabled: true, payload: { kind: "agentTurn", message: "poll workflow queue" },
schedule: { kind: "every", everyMs: 300_000 }, state: {},
sessionTarget: "isolated", },
wakeMode: "now", ]);
payload: { kind: "agentTurn", message: "poll workflow queue" },
state: {},
},
],
}),
);
const cron = new CronService({ const cron = new CronService({
cronEnabled: true, cronEnabled: true,
@@ -330,30 +328,19 @@ describe("Cron issue regressions", () => {
it("treats persisted jobs with missing enabled as enabled during update()", async () => { it("treats persisted jobs with missing enabled as enabled during update()", async () => {
const store = makeStorePath(); const store = makeStorePath();
const now = Date.parse("2026-02-06T10:05:00.000Z"); const now = Date.parse("2026-02-06T10:05:00.000Z");
await fs.writeFile( await writeCronStoreSnapshot(store.storePath, [
store.storePath, {
JSON.stringify( id: "missing-enabled-update",
{ name: "legacy missing enabled",
version: 1, createdAtMs: now - 60_000,
jobs: [ updatedAtMs: now - 60_000,
{ schedule: { kind: "cron", expr: "0 */2 * * *", tz: "UTC" },
id: "missing-enabled-update", sessionTarget: "main",
name: "legacy missing enabled", wakeMode: "next-heartbeat",
createdAtMs: now - 60_000, payload: { kind: "systemEvent", text: "legacy" },
updatedAtMs: now - 60_000, state: {},
schedule: { kind: "cron", expr: "0 */2 * * *", tz: "UTC" }, },
sessionTarget: "main", ]);
wakeMode: "next-heartbeat",
payload: { kind: "systemEvent", text: "legacy" },
state: {},
},
],
},
null,
2,
),
"utf-8",
);
const cron = await startCronForStore({ storePath: store.storePath, cronEnabled: false }); const cron = await startCronForStore({ storePath: store.storePath, cronEnabled: false });
@@ -374,30 +361,19 @@ describe("Cron issue regressions", () => {
const store = makeStorePath(); const store = makeStorePath();
const now = Date.parse("2026-02-06T10:05:00.000Z"); const now = Date.parse("2026-02-06T10:05:00.000Z");
const dueAt = now - 30_000; const dueAt = now - 30_000;
await fs.writeFile( await writeCronStoreSnapshot(store.storePath, [
store.storePath, {
JSON.stringify( id: "missing-enabled-due",
{ name: "legacy due job",
version: 1, createdAtMs: dueAt - 60_000,
jobs: [ updatedAtMs: dueAt,
{ schedule: { kind: "at", at: new Date(dueAt).toISOString() },
id: "missing-enabled-due", sessionTarget: "main",
name: "legacy due job", wakeMode: "now",
createdAtMs: dueAt - 60_000, payload: { kind: "systemEvent", text: "missing-enabled-due" },
updatedAtMs: dueAt, state: { nextRunAtMs: dueAt },
schedule: { kind: "at", at: new Date(dueAt).toISOString() }, },
sessionTarget: "main", ]);
wakeMode: "now",
payload: { kind: "systemEvent", text: "missing-enabled-due" },
state: { nextRunAtMs: dueAt },
},
],
},
null,
2,
),
"utf-8",
);
const enqueueSystemEvent = vi.fn(); const enqueueSystemEvent = vi.fn();
const cron = await startCronForStore({ const cron = await startCronForStore({
@@ -1402,36 +1378,25 @@ describe("Cron issue regressions", () => {
const now = Date.parse("2026-02-06T10:05:00.000Z"); const now = Date.parse("2026-02-06T10:05:00.000Z");
const staleRunningAtMs = now - 2 * 60 * 60 * 1000 - 1; const staleRunningAtMs = now - 2 * 60 * 60 * 1000 - 1;
await fs.writeFile( await writeCronStoreSnapshot(store.storePath, [
store.storePath, {
JSON.stringify( id: "stale-running",
{ name: "stale-running",
version: 1, enabled: true,
jobs: [ createdAtMs: now - 3_600_000,
{ updatedAtMs: now - 3_600_000,
id: "stale-running", schedule: { kind: "at", at: new Date(now - 60_000).toISOString() },
name: "stale-running", sessionTarget: "main",
enabled: true, wakeMode: "now",
createdAtMs: now - 3_600_000, payload: { kind: "systemEvent", text: "stale-running" },
updatedAtMs: now - 3_600_000, state: {
schedule: { kind: "at", at: new Date(now - 60_000).toISOString() }, runningAtMs: staleRunningAtMs,
sessionTarget: "main", lastRunAtMs: now - 3_600_000,
wakeMode: "now", lastStatus: "ok",
payload: { kind: "systemEvent", text: "stale-running" }, nextRunAtMs: now - 60_000,
state: {
runningAtMs: staleRunningAtMs,
lastRunAtMs: now - 3_600_000,
lastStatus: "ok",
nextRunAtMs: now - 60_000,
},
},
],
}, },
null, },
2, ]);
),
"utf-8",
);
const enqueueSystemEvent = vi.fn(); const enqueueSystemEvent = vi.fn();
const state = createCronServiceState({ const state = createCronServiceState({

View File

@@ -24,9 +24,7 @@ describe("slack prepareSlackMessage inbound contract", () => {
if (!fixtureRoot) { if (!fixtureRoot) {
throw new Error("fixtureRoot missing"); throw new Error("fixtureRoot missing");
} }
const dir = path.join(fixtureRoot, `case-${caseId++}`); return { storePath: path.join(fixtureRoot, `case-${caseId++}.sessions.json`) };
fs.mkdirSync(dir);
return { dir, storePath: path.join(dir, "sessions.json") };
} }
beforeAll(() => { beforeAll(() => {

View File

@@ -8,12 +8,13 @@ const baseGitEnv = {
GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_NOSYSTEM: "1",
GIT_TERMINAL_PROMPT: "0", GIT_TERMINAL_PROMPT: "0",
}; };
const baseRunEnv: NodeJS.ProcessEnv = { ...process.env, ...baseGitEnv };
const run = (cwd: string, cmd: string, args: string[] = [], env?: NodeJS.ProcessEnv) => { const run = (cwd: string, cmd: string, args: string[] = [], env?: NodeJS.ProcessEnv) => {
return execFileSync(cmd, args, { return execFileSync(cmd, args, {
cwd, cwd,
encoding: "utf8", encoding: "utf8",
env: { ...process.env, ...baseGitEnv, ...env }, env: env ? { ...baseRunEnv, ...env } : baseRunEnv,
}).trim(); }).trim();
}; };

View File

@@ -84,10 +84,11 @@ function runScript(
stdout: string; stdout: string;
stderr: string; stderr: string;
} { } {
const cacheKey = JSON.stringify({ const extraEnvKey = Object.keys(extraEnv)
homeDir, .toSorted((a, b) => a.localeCompare(b))
extraEnv: Object.entries(extraEnv).toSorted(([a], [b]) => a.localeCompare(b)), .map((key) => `${key}=${extraEnv[key] ?? ""}`)
}); .join("\u0001");
const cacheKey = `${homeDir}\u0000${extraEnvKey}`;
const cached = runScriptCache.get(cacheKey); const cached = runScriptCache.get(cacheKey);
if (cached) { if (cached) {
return cached; return cached;