From 759680d4c8a086c7ed1eeaf9357f8ee8bb531ba3 Mon Sep 17 00:00:00 2001 From: davidj4t <65033682+davidj4tech@users.noreply.github.com> Date: Wed, 29 Jul 2026 22:58:34 +1000 Subject: [PATCH] test(memoryOps): stop the memory-op tests writing into the real machine-wide index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit applyMemoryOps() mirrors every write into the machine-wide PGlite memory index via the fire-and-forget indexMemoryWrite() → upsertMemoryEmbedding(), keyed by repoKey(stateDir). For this file's tmp state dirs that key is the tmp path itself, so running the file wrote rows like /tmp/mc-memops-w3XL9J/add "we use node:sqlite as the store" /tmp/mc-memops-w3XL9J/dup "threshold is 50k" /tmp/mc-memops-w3XL9J/replace "the threshold is 100k" into the developer's real ~/.pi/mega-compact-vector. They persist, and cross-repo recall is enabled by default and searches the global index with no repo filter (src/recall.ts falls back to a 0.3 cosine floor), so a live session in an unrelated project can be handed a stale test assertion — the contradictory 50k/100k pair included — as if it were another project's memory. Found on a real machine holding 33 such rows and nothing else. scripts/run-tests.mjs already sets MEGACOMPACT_INDEX_DIR per child, so the suite was never the leak; invoking the file directly was. Disables PGlite for the file (the same guard memoryRoundtrip.test.ts uses, for the same reason — these suites exercise the sync node:sqlite path only) and points MEGACOMPACT_INDEX_DIR at the per-run tmp dir so the isolation still holds if a later test re-enables the index. Verified: on the current code a run adds 3 rows to the live index; with this change three consecutive runs add none. The file also gets faster and quieter — 9/9 in <1s instead of 11s, with no "asynchronous activity after the test ended" from an initdb still running past the first test. --- src/memoryOps.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/memoryOps.test.ts b/src/memoryOps.test.ts index 8ddbc63..3be38c9 100644 --- a/src/memoryOps.test.ts +++ b/src/memoryOps.test.ts @@ -1,3 +1,18 @@ +// This file exercises the sync node:sqlite memory ops only, but every +// applyMemoryOps() write also fires indexMemoryWrite() → upsertMemoryEmbedding() +// at the machine-wide PGlite index, fire-and-forget, keyed by repoKey(stateDir) +// — which for these tmp state dirs is the tmp path itself. Left alone that lands +// in the developer's real ~/.pi/mega-compact-vector, where the rows stay +// eligible for cross-repo recall forever: a live session can be handed +// "threshold is 50k" and "the threshold is 100k" from this file as if they were +// another project's memories. scripts/run-tests.mjs sets MEGACOMPACT_INDEX_DIR +// per child, so the suite was already safe; running the file directly was not. +// +// Disabling PGlite is the same guard memoryRoundtrip.test.ts uses for the same +// reason, and it also keeps the file's exit clean (no WASM handle, and no +// initdb still running when the first test ends). MEGACOMPACT_INDEX_DIR is set +// as well so the isolation holds if a later test needs the index re-enabled. +process.env.MEGACOMPACT_PGLITE_DISABLED = "true"; import { test } from "node:test"; import assert from "node:assert/strict"; import { mkdtempSync, rmSync } from "node:fs"; @@ -13,6 +28,7 @@ import { } from "./store/sqlite.js"; const baseTmp = mkdtempSync(join(tmpdir(), "mc-memops-")); +process.env.MEGACOMPACT_INDEX_DIR = join(baseTmp, "index"); test("applyMemoryOps: ADD inserts a new memory", async () => { const dir = join(baseTmp, "add");