diff --git a/next-env.d.ts b/next-env.d.ts index a419cbe..ce4e94a 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,7 +1,7 @@ /// /// -import "./.next/dev/types/routes.d.ts"; -import "./.next/dev/types/root-params.d.ts"; +import "./.next/types/routes.d.ts"; +import "./.next/types/root-params.d.ts"; // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/src/store/jobs.ts b/src/store/jobs.ts index b1d3d8e..d32bd6c 100644 --- a/src/store/jobs.ts +++ b/src/store/jobs.ts @@ -48,11 +48,13 @@ function getJob(id: string): JobRecord | null { } } -/** Merge a partial patch into the record (identity fields are immutable). */ +/** Merge a partial patch into the record (identity fields are immutable). + * An explicit patch.updatedAt is honored (tests pin deterministic order); + * otherwise the merge bumps it to now. */ function updateJob(id: string, patch: JobPatch): JobRecord | null { const record = getJob(id); if (!record) return null; - const next: JobRecord = { ...record, ...patch, updatedAt: new Date().toISOString() }; + const next: JobRecord = { ...record, ...patch, updatedAt: patch.updatedAt ?? new Date().toISOString() }; fs.writeFileSync(jobFile(id), JSON.stringify(next, null, "\t"), "utf-8"); return next; } diff --git a/tests/activity-feed.test.ts b/tests/activity-feed.test.ts index 7819cfd..2c65c28 100644 --- a/tests/activity-feed.test.ts +++ b/tests/activity-feed.test.ts @@ -18,12 +18,19 @@ import { activityFeed } from "../src/server/observability.ts"; test("activityFeed: running jobs across ALL chats, running-only, title-joined, oldest first", () => { const chatA = chatStore.createChat("feed chat A"); const chatB = chatStore.createChat("feed chat B"); + // job ids tracked as created — the finally cleanup stays scoped to them even + // if the test throws mid-way (test files run as concurrent processes over + // the shared data/ scratch; wiping the whole jobs dir would delete other + // processes' live fixtures — the wave-4 flake lesson) + const createdJobs: string[] = []; try { const jobA = jobStore.createJob({ kind: "research", chatId: chatA.id, toolCallId: "tc_a" }); const jobB = jobStore.createJob({ kind: "demo", chatId: chatB.id, toolCallId: "tc_b" }); const jobDone = jobStore.createJob({ kind: "research", chatId: chatA.id, toolCallId: "tc_done" }); + createdJobs.push(jobA.id, jobB.id, jobDone.id); jobStore.updateJob(jobDone.id, { status: "done" }); const jobB2 = jobStore.createJob({ kind: "research", chatId: chatB.id, toolCallId: "tc_b2" }); + createdJobs.push(jobB2.id); // make jobB2 the MOST recently active → should still sort AFTER jobA/jobB (oldest-first). // Explicit later timestamp: the real bump can land in the same ms as creation. jobStore.updateJob(jobB2.id, { activity: "second step", updatedAt: new Date(Date.now() + 10).toISOString() }); @@ -47,6 +54,8 @@ test("activityFeed: running jobs across ALL chats, running-only, title-joined, o fs.unlinkSync(`${PATHS.chats}/${chatA.id}.json`); fs.unlinkSync(`${PATHS.chats}/${chatB.id}.json`); const jobsDir = path.join(PATHS.data, "jobs"); - for (const f of fs.readdirSync(jobsDir)) fs.unlinkSync(path.join(jobsDir, f)); + for (const id of createdJobs) { + fs.unlinkSync(path.join(jobsDir, `${id}.json`)); + } } });