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,11 +218,7 @@ 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({
version: 1,
jobs: [
{ {
id: "legacy-isolated", id: "legacy-isolated",
agentId: "feature-dev_planner", agentId: "feature-dev_planner",
@@ -231,9 +231,7 @@ describe("Cron issue regressions", () => {
payload: { kind: "agentTurn", message: "poll workflow queue" }, payload: { kind: "agentTurn", message: "poll workflow queue" },
state: {}, state: {},
}, },
], ]);
}),
);
const cron = new CronService({ const cron = new CronService({
cronEnabled: true, cronEnabled: true,
@@ -330,12 +328,7 @@ 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(
{
version: 1,
jobs: [
{ {
id: "missing-enabled-update", id: "missing-enabled-update",
name: "legacy missing enabled", name: "legacy missing enabled",
@@ -347,13 +340,7 @@ describe("Cron issue regressions", () => {
payload: { kind: "systemEvent", text: "legacy" }, payload: { kind: "systemEvent", text: "legacy" },
state: {}, state: {},
}, },
], ]);
},
null,
2,
),
"utf-8",
);
const cron = await startCronForStore({ storePath: store.storePath, cronEnabled: false }); const cron = await startCronForStore({ storePath: store.storePath, cronEnabled: false });
@@ -374,12 +361,7 @@ 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(
{
version: 1,
jobs: [
{ {
id: "missing-enabled-due", id: "missing-enabled-due",
name: "legacy due job", name: "legacy due job",
@@ -391,13 +373,7 @@ describe("Cron issue regressions", () => {
payload: { kind: "systemEvent", text: "missing-enabled-due" }, payload: { kind: "systemEvent", text: "missing-enabled-due" },
state: { nextRunAtMs: dueAt }, state: { nextRunAtMs: dueAt },
}, },
], ]);
},
null,
2,
),
"utf-8",
);
const enqueueSystemEvent = vi.fn(); const enqueueSystemEvent = vi.fn();
const cron = await startCronForStore({ const cron = await startCronForStore({
@@ -1402,12 +1378,7 @@ 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(
{
version: 1,
jobs: [
{ {
id: "stale-running", id: "stale-running",
name: "stale-running", name: "stale-running",
@@ -1425,13 +1396,7 @@ describe("Cron issue regressions", () => {
nextRunAtMs: now - 60_000, 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;