diff --git a/src/cron/isolated-agent.auth-profile-propagation.test.ts b/src/cron/isolated-agent.auth-profile-propagation.test.ts index 382a0dd23ab..3072b7145c6 100644 --- a/src/cron/isolated-agent.auth-profile-propagation.test.ts +++ b/src/cron/isolated-agent.auth-profile-propagation.test.ts @@ -82,15 +82,6 @@ describe("runCronIsolatedAgentTurn auth profile propagation (#20624)", () => { 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"); }); }); diff --git a/src/cron/service.issue-regressions.test.ts b/src/cron/service.issue-regressions.test.ts index 45211389fc1..66dc3a03108 100644 --- a/src/cron/service.issue-regressions.test.ts +++ b/src/cron/service.issue-regressions.test.ts @@ -124,6 +124,10 @@ async function writeCronJobs(storePath: string, jobs: CronJob[]) { 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: { storePath: string; cronEnabled?: boolean; @@ -214,26 +218,20 @@ describe("Cron issue regressions", () => { it("repairs isolated every jobs missing createdAtMs and sets nextWakeAtMs", async () => { const store = makeStorePath(); - await fs.writeFile( - store.storePath, - JSON.stringify({ - version: 1, - jobs: [ - { - id: "legacy-isolated", - agentId: "feature-dev_planner", - sessionKey: "agent:main:main", - name: "legacy isolated", - enabled: true, - schedule: { kind: "every", everyMs: 300_000 }, - sessionTarget: "isolated", - wakeMode: "now", - payload: { kind: "agentTurn", message: "poll workflow queue" }, - state: {}, - }, - ], - }), - ); + await writeCronStoreSnapshot(store.storePath, [ + { + id: "legacy-isolated", + agentId: "feature-dev_planner", + sessionKey: "agent:main:main", + name: "legacy isolated", + enabled: true, + schedule: { kind: "every", everyMs: 300_000 }, + sessionTarget: "isolated", + wakeMode: "now", + payload: { kind: "agentTurn", message: "poll workflow queue" }, + state: {}, + }, + ]); const cron = new CronService({ cronEnabled: true, @@ -330,30 +328,19 @@ describe("Cron issue regressions", () => { it("treats persisted jobs with missing enabled as enabled during update()", async () => { const store = makeStorePath(); const now = Date.parse("2026-02-06T10:05:00.000Z"); - await fs.writeFile( - store.storePath, - JSON.stringify( - { - version: 1, - jobs: [ - { - id: "missing-enabled-update", - name: "legacy missing enabled", - createdAtMs: now - 60_000, - updatedAtMs: now - 60_000, - schedule: { kind: "cron", expr: "0 */2 * * *", tz: "UTC" }, - sessionTarget: "main", - wakeMode: "next-heartbeat", - payload: { kind: "systemEvent", text: "legacy" }, - state: {}, - }, - ], - }, - null, - 2, - ), - "utf-8", - ); + await writeCronStoreSnapshot(store.storePath, [ + { + id: "missing-enabled-update", + name: "legacy missing enabled", + createdAtMs: now - 60_000, + updatedAtMs: now - 60_000, + schedule: { kind: "cron", expr: "0 */2 * * *", tz: "UTC" }, + sessionTarget: "main", + wakeMode: "next-heartbeat", + payload: { kind: "systemEvent", text: "legacy" }, + state: {}, + }, + ]); const cron = await startCronForStore({ storePath: store.storePath, cronEnabled: false }); @@ -374,30 +361,19 @@ describe("Cron issue regressions", () => { const store = makeStorePath(); const now = Date.parse("2026-02-06T10:05:00.000Z"); const dueAt = now - 30_000; - await fs.writeFile( - store.storePath, - JSON.stringify( - { - version: 1, - jobs: [ - { - id: "missing-enabled-due", - name: "legacy due job", - createdAtMs: dueAt - 60_000, - updatedAtMs: 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", - ); + await writeCronStoreSnapshot(store.storePath, [ + { + id: "missing-enabled-due", + name: "legacy due job", + createdAtMs: dueAt - 60_000, + updatedAtMs: dueAt, + schedule: { kind: "at", at: new Date(dueAt).toISOString() }, + sessionTarget: "main", + wakeMode: "now", + payload: { kind: "systemEvent", text: "missing-enabled-due" }, + state: { nextRunAtMs: dueAt }, + }, + ]); const enqueueSystemEvent = vi.fn(); const cron = await startCronForStore({ @@ -1402,36 +1378,25 @@ describe("Cron issue regressions", () => { const now = Date.parse("2026-02-06T10:05:00.000Z"); const staleRunningAtMs = now - 2 * 60 * 60 * 1000 - 1; - await fs.writeFile( - store.storePath, - JSON.stringify( - { - version: 1, - jobs: [ - { - id: "stale-running", - name: "stale-running", - enabled: true, - createdAtMs: now - 3_600_000, - updatedAtMs: now - 3_600_000, - schedule: { kind: "at", at: new Date(now - 60_000).toISOString() }, - sessionTarget: "main", - wakeMode: "now", - payload: { kind: "systemEvent", text: "stale-running" }, - state: { - runningAtMs: staleRunningAtMs, - lastRunAtMs: now - 3_600_000, - lastStatus: "ok", - nextRunAtMs: now - 60_000, - }, - }, - ], + await writeCronStoreSnapshot(store.storePath, [ + { + id: "stale-running", + name: "stale-running", + enabled: true, + createdAtMs: now - 3_600_000, + updatedAtMs: now - 3_600_000, + schedule: { kind: "at", at: new Date(now - 60_000).toISOString() }, + sessionTarget: "main", + wakeMode: "now", + payload: { kind: "systemEvent", text: "stale-running" }, + state: { + runningAtMs: staleRunningAtMs, + lastRunAtMs: now - 3_600_000, + lastStatus: "ok", + nextRunAtMs: now - 60_000, }, - null, - 2, - ), - "utf-8", - ); + }, + ]); const enqueueSystemEvent = vi.fn(); const state = createCronServiceState({ diff --git a/src/slack/monitor/message-handler/prepare.test.ts b/src/slack/monitor/message-handler/prepare.test.ts index d503e16c346..578eb6e153a 100644 --- a/src/slack/monitor/message-handler/prepare.test.ts +++ b/src/slack/monitor/message-handler/prepare.test.ts @@ -24,9 +24,7 @@ describe("slack prepareSlackMessage inbound contract", () => { if (!fixtureRoot) { throw new Error("fixtureRoot missing"); } - const dir = path.join(fixtureRoot, `case-${caseId++}`); - fs.mkdirSync(dir); - return { dir, storePath: path.join(dir, "sessions.json") }; + return { storePath: path.join(fixtureRoot, `case-${caseId++}.sessions.json`) }; } beforeAll(() => { diff --git a/test/git-hooks-pre-commit.test.ts b/test/git-hooks-pre-commit.test.ts index b966bedaae8..018fcce7090 100644 --- a/test/git-hooks-pre-commit.test.ts +++ b/test/git-hooks-pre-commit.test.ts @@ -8,12 +8,13 @@ const baseGitEnv = { GIT_CONFIG_NOSYSTEM: "1", GIT_TERMINAL_PROMPT: "0", }; +const baseRunEnv: NodeJS.ProcessEnv = { ...process.env, ...baseGitEnv }; const run = (cwd: string, cmd: string, args: string[] = [], env?: NodeJS.ProcessEnv) => { return execFileSync(cmd, args, { cwd, encoding: "utf8", - env: { ...process.env, ...baseGitEnv, ...env }, + env: env ? { ...baseRunEnv, ...env } : baseRunEnv, }).trim(); }; diff --git a/test/scripts/ios-team-id.test.ts b/test/scripts/ios-team-id.test.ts index eda6aec80ae..f2a9037f020 100644 --- a/test/scripts/ios-team-id.test.ts +++ b/test/scripts/ios-team-id.test.ts @@ -84,10 +84,11 @@ function runScript( stdout: string; stderr: string; } { - const cacheKey = JSON.stringify({ - homeDir, - extraEnv: Object.entries(extraEnv).toSorted(([a], [b]) => a.localeCompare(b)), - }); + const extraEnvKey = Object.keys(extraEnv) + .toSorted((a, b) => a.localeCompare(b)) + .map((key) => `${key}=${extraEnv[key] ?? ""}`) + .join("\u0001"); + const cacheKey = `${homeDir}\u0000${extraEnvKey}`; const cached = runScriptCache.get(cacheKey); if (cached) { return cached;