Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/mcp/snapshotProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function createSnapshotProvider(
}

const currentMtime = cached.mtimeMs;
if (!staleCache || staleCache.mtimeMs !== currentMtime || now() - staleCache.at > ttl) {
if (!staleCache || staleCache.mtimeMs !== currentMtime || now() - staleCache.at >= ttl) {
staleCache = {
value: await isSnapshotStale(projectRoot, cached.snapshot),
at: now(),
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/test/mcp-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ test("snapshot provider re-reads only when snapshot.json changes", async () => {
}
});

test("staleTtlMs: 0 re-checks staleness on every call, even within the same millisecond", async () => {
const projectRoot = await mkdtemp(join(tmpdir(), "devmap-mcp-ttl-"));
await mkdir(join(projectRoot, "src"), { recursive: true });
await writeFile(join(projectRoot, "package.json"), JSON.stringify({ name: "ttl-app", version: "1.0.0" }));
await writeFile(join(projectRoot, "src", "index.ts"), "export const a = 1;\n");
await saveSnapshot(projectRoot, await createProjectMap(projectRoot));
// A frozen clock stands in for a fast machine where both calls land in one millisecond.
const provider = createSnapshotProvider(projectRoot, { staleTtlMs: 0, now: () => 1_000 });

try {
assert.equal((await provider.get()).stale, false);
await writeFile(join(projectRoot, "src", "extra.ts"), "export const b = 2;\n");
assert.equal((await provider.get()).stale, true);
} finally {
await rm(projectRoot, { recursive: true, force: true });
}
});

test("query helpers: limits, path resolution, and truncation", async () => {
assert.equal(clampLimit(undefined, 20), 20);
assert.equal(clampLimit(0), 1);
Expand Down
Loading