forked from nicobailon/pi-subagents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletion-dedupe.test.ts
More file actions
36 lines (32 loc) · 1.36 KB
/
completion-dedupe.test.ts
File metadata and controls
36 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { buildCompletionKey, getGlobalSeenMap, markSeenWithTtl } from "./completion-dedupe.ts";
describe("buildCompletionKey", () => {
it("uses id as canonical key when present", () => {
const key = buildCompletionKey({ id: "run-123", agent: "reviewer", timestamp: 123 }, "fallback");
assert.equal(key, "id:run-123");
});
it("builds deterministic fallback key when id is missing", () => {
const a = buildCompletionKey({ agent: "reviewer", timestamp: 123, taskIndex: 1, totalTasks: 2, success: true }, "x");
const b = buildCompletionKey({ agent: "reviewer", timestamp: 123, taskIndex: 1, totalTasks: 2, success: true }, "x");
assert.equal(a, b);
});
});
describe("markSeenWithTtl", () => {
it("returns true only for duplicates within ttl", () => {
const seen = new Map<string, number>();
const ttlMs = 1000;
assert.equal(markSeenWithTtl(seen, "k", 100, ttlMs), false);
assert.equal(markSeenWithTtl(seen, "k", 200, ttlMs), true);
assert.equal(markSeenWithTtl(seen, "k", 1201, ttlMs), false);
});
});
describe("getGlobalSeenMap", () => {
it("returns the same map for the same global store key", () => {
const a = getGlobalSeenMap("__test_seen_key__");
a.set("x", 1);
const b = getGlobalSeenMap("__test_seen_key__");
assert.equal(b.get("x"), 1);
assert.equal(a, b);
});
});