fix(server): preserve usage cache outside walked roots (#8540)
Co-authored-by: Simone <[email protected]>
This commit is contained in:
1 parent
f47e74004a
commit
6d15c5bbc3
2 files changed
+26
-1
No files matched your search
@@ -193,6 +193,20 @@ describe("pruneScanCache with an unwalked root", () => {
|
||||
expect(removed).toBe(0);
|
||||
expect(cache.size).toBe(1);
|
||||
});
|
||||
|
||||
it("keeps entries under a sibling path that only shares the walked root prefix", () => {
|
||||
const cache = cacheWith([["/claude/projects-copy/a.jsonl", 5000, [record()]]]);
|
||||
|
||||
const removed = pruneScanCache(cache, {
|
||||
livePaths: new Set(),
|
||||
walkedRoots: ["/claude/projects"],
|
||||
windowStartMs: 4000,
|
||||
retentionCutoffMs: 1000,
|
||||
});
|
||||
|
||||
expect(removed).toBe(0);
|
||||
expect(cache.size).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dedupeWithinFile", () => {
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
*
|
||||
* @module usageScanCache
|
||||
*/
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as NodePath from "node:path";
|
||||
|
||||
import type { UsageProviderKind } from "@t3tools/contracts";
|
||||
|
||||
import type { UsageRecord } from "./usageTranscripts.ts";
|
||||
@@ -229,7 +232,15 @@ export function pruneScanCache(cache: ScanCache, options: PruneOptions): number
|
||||
let removed = 0;
|
||||
for (const [path, entry] of cache) {
|
||||
const agedOut = entry.mtimeMs < options.retentionCutoffMs;
|
||||
const underWalkedRoot = options.walkedRoots.some((root) => path.startsWith(root));
|
||||
const underWalkedRoot = options.walkedRoots.some((root) => {
|
||||
const relative = NodePath.relative(root, path);
|
||||
return (
|
||||
relative === "" ||
|
||||
(relative !== ".." &&
|
||||
!relative.startsWith(`..${NodePath.sep}`) &&
|
||||
!NodePath.isAbsolute(relative))
|
||||
);
|
||||
});
|
||||
const deleted =
|
||||
underWalkedRoot && entry.mtimeMs >= options.windowStartMs && !options.livePaths.has(path);
|
||||
if (agedOut || deleted) {
|
||||
|
||||
Reference in new issue
Block a user