Skip to content

Commit bd0b8db

Browse files
authored
Merge pull request #171 from chenjiyong/master
Add support info regression coverage
2 parents d0e620b + bbbb402 commit bd0b8db

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

test/context-support-e2e.mjs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,46 +177,71 @@ async function runTest() {
177177
console.log(" ✅ support decision works correctly");
178178

179179
// ----------------------------------------------------------------
180-
// Scenario 2: contextualize — should create linked entry
180+
// Scenario 2: merge — should update support_info on merged memory
181181
// ----------------------------------------------------------------
182-
console.log("Test 2: contextualize decision creates linked entry...");
182+
console.log("Test 2: merge decision updates support_info...");
183+
dedupDecision = "merge";
184+
dedupContextLabel = "late_night";
185+
logs.length = 0;
186+
187+
const stats2 = await extractor.extractAndPersist(
188+
"用户再次确认深夜也会喝乌龙茶。",
189+
"test-session",
190+
{ scope: "test", scopeFilter: ["test"] },
191+
);
192+
193+
const entries2 = await store.list(["test"], undefined, 10, 0);
194+
assert.equal(entries2.length, 1, "merge should NOT create new entry");
195+
assert.equal(stats2.merged, 1, "merged count should be 1");
196+
197+
const meta2 = JSON.parse(entries2[0].metadata || "{}");
198+
const si2 = parseSupportInfo(meta2.support_info);
199+
const lateNightSlice = si2.slices.find(s => s.context === "late_night");
200+
assert.ok(lateNightSlice, "late_night slice should exist after merge");
201+
assert.equal(lateNightSlice.confirmations, 1, "late_night confirmations should be 1");
202+
console.log(" ✅ merge decision works correctly");
203+
204+
// ----------------------------------------------------------------
205+
// Scenario 3: contextualize — should create linked entry
206+
// ----------------------------------------------------------------
207+
console.log("Test 3: contextualize decision creates linked entry...");
183208
dedupDecision = "contextualize";
184209
dedupContextLabel = "night";
185210
logs.length = 0;
186211

187-
const stats2 = await extractor.extractAndPersist(
212+
const stats3 = await extractor.extractAndPersist(
188213
"用户说晚上改喝花茶。",
189214
"test-session",
190215
{ scope: "test", scopeFilter: ["test"] },
191216
);
192217

193-
const entries2 = await store.list(["test"], undefined, 10, 0);
194-
assert.equal(entries2.length, 2, "contextualize should create 1 new entry");
195-
assert.equal(stats2.created, 1, "created count should be 1");
218+
const entries3 = await store.list(["test"], undefined, 10, 0);
219+
assert.equal(entries3.length, 2, "contextualize should create 1 new entry");
220+
assert.equal(stats3.created, 1, "created count should be 1");
196221
console.log(" ✅ contextualize decision works correctly");
197222

198223
// ----------------------------------------------------------------
199-
// Scenario 3: contradict — should record contradiction + new entry
224+
// Scenario 4: contradict — should record contradiction + new entry
200225
// ----------------------------------------------------------------
201-
console.log("Test 3: contradict decision records contradiction...");
226+
console.log("Test 4: contradict decision records contradiction...");
202227
dedupDecision = "contradict";
203228
dedupContextLabel = "weekend";
204229
logs.length = 0;
205230

206-
const stats3 = await extractor.extractAndPersist(
231+
const stats4 = await extractor.extractAndPersist(
207232
"用户说周末不喝茶了。",
208233
"test-session",
209234
{ scope: "test", scopeFilter: ["test"] },
210235
);
211236

212-
const entries3 = await store.list(["test"], undefined, 10, 0);
213-
assert.equal(entries3.length, 3, "contradict should create 1 new entry");
214-
assert.equal(stats3.created, 1, "created count should be 1");
237+
const entries4 = await store.list(["test"], undefined, 10, 0);
238+
assert.equal(entries4.length, 3, "contradict should create 1 new entry");
239+
assert.equal(stats4.created, 1, "created count should be 1");
215240

216241
// Check contradictions recorded on some existing entry
217242
// (with constant vectors, dedup may match any existing entry)
218243
let foundWeekend = false;
219-
for (const entry of entries3) {
244+
for (const entry of entries4) {
220245
const meta = JSON.parse(entry.metadata || "{}");
221246
const si = parseSupportInfo(meta.support_info);
222247
const weekendSlice = si.slices.find(s => s.context === "weekend");

test/smart-extractor-branches.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ const plugin = jiti("../index.ts");
1919
const { MemoryStore } = jiti("../src/store.ts");
2020
const { createEmbedder } = jiti("../src/embedder.ts");
2121
const { buildSmartMetadata, stringifySmartMetadata } = jiti("../src/smart-metadata.ts");
22+
const { NoisePrototypeBank } = jiti("../src/noise-prototypes.ts");
2223

2324
const EMBEDDING_DIMENSIONS = 2560;
2425

26+
// This suite exercises extraction/dedup/merge branch behavior rather than
27+
// the embedding-based noise filter. Force the noise bank off so deterministic
28+
// mock embeddings do not accidentally classify normal user text as noise.
29+
NoisePrototypeBank.prototype.isNoise = () => false;
30+
2531
function createDeterministicEmbedding(text, dimensions = EMBEDDING_DIMENSIONS) {
2632
void text;
2733
const value = 1 / Math.sqrt(dimensions);

0 commit comments

Comments
 (0)