Owner ruling (2026-09-23, amendment to 04e336d): no hardcoded fallback exists anywhere. contextWindow(record, limits) resolves the denominator ONLY from the live index (provider:id -> contextWindow straight from pi's catalog); a model missing from it (historical session, package update, failed fetch) reads limit null and the meter renders usage-only — the honest-render precedent, never a fake window. - src/core/prices.ts: the 1354-entry CONTEXT_LIMITS table (65KB) and its generation apparatus deleted; the fold returns limit: number | null. PRICES untouched (regen verified byte-identical via the reworked sync-pricing script). - scripts/sync-pricing.ts: generates PRICES only; contextWindow leaves the priced map, the guard, and the template. - The dock meter's owner-selected treatment: the activity feed carries the limit server-side. catalogContextLimits() (server/model-catalog.ts) builds the index over the same keyed providers the picker federates; activityFeed() joins it onto every running job (ActivityJob.contextLimit, null when the model is missing — the dock reads it off the feed, no client-side table, no regression while the UI's catalog-join chunk lands). - components/activity-dock.tsx: toBlobs reads job.contextLimit (import of CONTEXT_LIMITS gone); stats-bar renders usage-only on null limit (mechanical interim — UI stream's join chunk follows). - tests: usage.test.ts pins the no-fallback contract (index hit / absent / empty / missing-model -> null); activity-feed.test.ts pins the server join (catalog model -> 1048576, unknown -> null, no-usage -> null); render pins updated to the interim usage-only render.
101 lines
4.7 KiB
TypeScript
101 lines
4.7 KiB
TypeScript
/**
|
|
* Activity-feed tests — the dock's composition (server/observability.ts).
|
|
*
|
|
* Real stores with fixture chats/jobs, cleaned up in a top-level test.
|
|
* Verifies the cross-chat gathering, running-only filtering, title joins,
|
|
* stable oldest-first ordering, and busy-chat reporting.
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import * as fs from "node:fs";
|
|
import * as path from "node:path";
|
|
|
|
import { chatStore } from "../src/store/chats.ts";
|
|
import { jobStore } from "../src/store/jobs.ts";
|
|
import { PATHS } from "../config.ts";
|
|
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() });
|
|
|
|
const feed = activityFeed();
|
|
const feedJobs = feed.jobs.filter((j) => [jobA.id, jobB.id, jobB2.id].includes(j.id));
|
|
assert.equal(feedJobs.length, 3); // done job filtered out
|
|
for (const j of feedJobs) {
|
|
assert.ok(j.title.length > 0, "title joined onto every job");
|
|
assert.equal(typeof j.chatId, "string");
|
|
}
|
|
// title join is the chat's title
|
|
assert.equal(feedJobs.find((j) => j.id === jobA.id)?.title, "feed chat A");
|
|
// oldest-first on updatedAt: jobA/jobB created before jobB2's bump
|
|
const order = feedJobs.map((j) => j.id);
|
|
assert.equal(order.indexOf(jobB2.id), order.length - 1);
|
|
|
|
// extraction runs are absent when the pipeline is idle (registry empty)
|
|
assert.deepEqual(feed.extractions, []);
|
|
} finally {
|
|
fs.unlinkSync(`${PATHS.chats}/${chatA.id}.json`);
|
|
fs.unlinkSync(`${PATHS.chats}/${chatB.id}.json`);
|
|
const jobsDir = path.join(PATHS.data, "jobs");
|
|
for (const id of createdJobs) {
|
|
fs.unlinkSync(path.join(jobsDir, `${id}.json`));
|
|
}
|
|
}
|
|
});
|
|
|
|
test("activityFeed: contextLimit is the server's live-catalog join (owner amendment, 2026-09-23)", () => {
|
|
// keyed-provider federation — the same env-key pattern as the
|
|
// model-catalog tests; file-local (each test file is its own process)
|
|
process.env.OPENROUTER_API_KEY ??= "test-key-openrouter-catalog";
|
|
const chat = chatStore.createChat("limit join chat");
|
|
const createdJobs: string[] = [];
|
|
const usageFor = (model: string) => ({
|
|
model,
|
|
inputTokens: 1_000,
|
|
outputTokens: 100,
|
|
cacheReadTokens: 0,
|
|
cacheWriteTokens: 0,
|
|
reasoningTokens: 0,
|
|
steps: 1,
|
|
});
|
|
try {
|
|
const known = jobStore.createJob({ kind: "research", chatId: chat.id, toolCallId: "tc_known" });
|
|
const unknown = jobStore.createJob({ kind: "research", chatId: chat.id, toolCallId: "tc_unknown" });
|
|
const bare = jobStore.createJob({ kind: "research", chatId: chat.id, toolCallId: "tc_bare" });
|
|
createdJobs.push(known.id, unknown.id, bare.id);
|
|
jobStore.updateJob(known.id, { usage: usageFor("openrouter:z-ai/glm-5.3-flash") });
|
|
jobStore.updateJob(unknown.id, { usage: usageFor("nope/unknown") });
|
|
|
|
const feed = activityFeed();
|
|
const knownJob = feed.jobs.find((j) => j.id === known.id)!;
|
|
assert.equal(knownJob.contextLimit, 1_048_576, "pi's catalog, joined server-side onto the feed");
|
|
const unknownJob = feed.jobs.find((j) => j.id === unknown.id)!;
|
|
assert.equal(unknownJob.contextLimit, null, "missing from the live catalog → null, never a guessed window");
|
|
const bareJob = feed.jobs.find((j) => j.id === bare.id)!;
|
|
assert.equal(bareJob.contextLimit, null, "no usage yet → no context line");
|
|
} finally {
|
|
fs.unlinkSync(`${PATHS.chats}/${chat.id}.json`);
|
|
const jobsDir = path.join(PATHS.data, "jobs");
|
|
for (const id of createdJobs) {
|
|
fs.unlinkSync(path.join(jobsDir, `${id}.json`));
|
|
}
|
|
}
|
|
});
|