Skip to content

test: jiti module cache conflict breaks auto-recall tests (output=undefined) #358

@jlin53882

Description

@jlin53882

Diagnostic Scripts and Test Results

Scripts Used (in order)

1. diagnostic4.mjs — Confirmed 401 error in real retrieve()

// Key finding: retrieve() mock NOT called (0 times), real embedding API called
// Result: [WARN] recall failed: Error: Embedding provider authentication failed (401 invalid_api_key)

2. diagnostic5.mjs — Confirmed jiti cache separation

// Result:
MemoryRetriever (ts) === MemoryRetriever (js): false   // different class
MemoryRetriever prototype (ts) === (js): false         // different prototype
createRetriever (ts) === createRetriever (js): false   // different factory functions

3. diagnostic6.mjs — Confirmed .ts and .js are different caches

// Result:
createRetriever from .ts: retrieve() called 1 times, returned 1 entries  // mock works
createRetriever from .js: retrieve() called 0 times, returned 0 entries  // mock doesn't work

4. fix-verify-a.mjs — Confirmed Plan A works

// Fix: mock createRetriever on .js module BEFORE importing index.ts
// Result:
Output: object (SUCCESS!)    not undefined
prependContext: <relevant-memories>...  ← correct content

5. diag-reassign.mjs — Confirmed ES module live binding works after import

// Result:
After importing index.ts:
reassignCalled: false   import happened, then reassign
  [mockCreateRetriever] called!   mock works
After plugin.register():
reassignCalled: true (should be true if reassign works)

Final Fix Applied

In test/recall-text-cleanup.test.mjs, changed module-level and test-body imports from .ts to .js to match index.ts:

// BEFORE (broken):
const retrieverModuleForMock = jiti("../src/retriever.ts");   // ← wrong cache
const embedderModuleForMock = jiti("../src/embedder.ts");     // ← wrong cache
// ...
const retrieverMod = jiti("../src/retriever.ts");            // ← wrong cache in test body
const embedderMod = jiti("../src/embedder.ts");              // ← wrong cache in test body

// AFTER (fixed):
const retrieverModuleForMock = jiti("../src/retriever.js");  // ← same cache as index.ts
const embedderModuleForMock = jiti("../src/embedder.js");    // ← same cache as index.ts
// ...
const retrieverMod = jiti("../src/retriever.js");             // ← same cache in test body
const embedderMod = jiti("../src/embedder.js");             // ← same cache in test body

Test Results

Before fix:

✖ removes retrieval metadata from auto-recall injected text (444ms)
✖ applies auto-recall item/char budgets before injecting context (101ms)
✖ auto-recall only injects confirmed non-archived memories (70ms)
✖ filters USER.md-exclusive facts from auto-recall injected text (72ms)
✖ filters legacy addressing memories from auto-recall injected text (70ms)

tests 15 | pass 10 | fail 5

After fix:

✔ removes retrieval metadata from auto-recall injected text (124ms)
✔ applies auto-recall item/char budgets before injecting context (40ms)
✔ auto-recall only injects confirmed non-archived memories (36ms)
✔ filters USER.md-exclusive facts from auto-recall injected text (37ms)
✔ filters legacy addressing memories from auto-recall injected text (32ms)

tests 15 | pass 15 | fail 0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions