pi-mega-compact 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -108,6 +108,13 @@ export function ensureGameStateWatcherImpl(self, view) {
108
108
  }
109
109
  }
110
110
  });
111
+ // The watcher is a cache-eviction convenience, never a reason to stay
112
+ // alive: an active+referenced fs_event handle holds node's event loop
113
+ // open, so a runtime that was never dispose()d (every extension test, and
114
+ // any `pi -p` run that skips session_shutdown) hangs the process after all
115
+ // work is done. unref'd like the perf interval — while pi runs there are
116
+ // always other referenced handles, so the watcher still fires normally.
117
+ self.gameStateWatcher.unref?.();
111
118
  self.gameStateWatchDir = self.currentStateDir;
112
119
  }
113
120
  catch {
@@ -1,3 +1,18 @@
1
+ // This file exercises the sync node:sqlite memory ops only, but every
2
+ // applyMemoryOps() write also fires indexMemoryWrite() → upsertMemoryEmbedding()
3
+ // at the machine-wide PGlite index, fire-and-forget, keyed by repoKey(stateDir)
4
+ // — which for these tmp state dirs is the tmp path itself. Left alone that lands
5
+ // in the developer's real ~/.pi/mega-compact-vector, where the rows stay
6
+ // eligible for cross-repo recall forever: a live session can be handed
7
+ // "threshold is 50k" and "the threshold is 100k" from this file as if they were
8
+ // another project's memories. scripts/run-tests.mjs sets MEGACOMPACT_INDEX_DIR
9
+ // per child, so the suite was already safe; running the file directly was not.
10
+ //
11
+ // Disabling PGlite is the same guard memoryRoundtrip.test.ts uses for the same
12
+ // reason, and it also keeps the file's exit clean (no WASM handle, and no
13
+ // initdb still running when the first test ends). MEGACOMPACT_INDEX_DIR is set
14
+ // as well so the isolation holds if a later test needs the index re-enabled.
15
+ process.env.MEGACOMPACT_PGLITE_DISABLED = "true";
1
16
  import { test } from "node:test";
2
17
  import assert from "node:assert/strict";
3
18
  import { mkdtempSync, rmSync } from "node:fs";
@@ -6,6 +21,7 @@ import { join } from "node:path";
6
21
  import { applyMemoryOps } from "./memoryOps.js";
7
22
  import { addMemory, listMemories, replaceMemory, referenceMemory, MEMORY_MAX_CHARS, } from "./store/sqlite.js";
8
23
  const baseTmp = mkdtempSync(join(tmpdir(), "mc-memops-"));
24
+ process.env.MEGACOMPACT_INDEX_DIR = join(baseTmp, "index");
9
25
  test("applyMemoryOps: ADD inserts a new memory", async () => {
10
26
  const dir = join(baseTmp, "add");
11
27
  await applyMemoryOps([{ op: "add", memory: { content: "we use node:sqlite as the store", category: "decision", sourceTurn: 0 } }], dir);
@@ -14,6 +14,8 @@ import { disposePerf, type PerfContext } from "./perf.js";
14
14
 
15
15
  export interface GameWatcherLike {
16
16
  close(): void;
17
+ /** fs.FSWatcher has it; test doubles need not. */
18
+ unref?(): unknown;
17
19
  }
18
20
 
19
21
  export interface GameStateContext {
@@ -142,6 +144,13 @@ export function ensureGameStateWatcherImpl(self: GameStateContext, view: GameSta
142
144
  }
143
145
  },
144
146
  );
147
+ // The watcher is a cache-eviction convenience, never a reason to stay
148
+ // alive: an active+referenced fs_event handle holds node's event loop
149
+ // open, so a runtime that was never dispose()d (every extension test, and
150
+ // any `pi -p` run that skips session_shutdown) hangs the process after all
151
+ // work is done. unref'd like the perf interval — while pi runs there are
152
+ // always other referenced handles, so the watcher still fires normally.
153
+ self.gameStateWatcher.unref?.();
145
154
  self.gameStateWatchDir = self.currentStateDir;
146
155
  } catch {
147
156
  /* non-fatal: missing dir / platform issue — next snapshot re-queries */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Layered, local, vector-backed context compressor for pi — supersede/collapse/cluster compaction with deduped inline recall.",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
@@ -1,3 +1,18 @@
1
+ // This file exercises the sync node:sqlite memory ops only, but every
2
+ // applyMemoryOps() write also fires indexMemoryWrite() → upsertMemoryEmbedding()
3
+ // at the machine-wide PGlite index, fire-and-forget, keyed by repoKey(stateDir)
4
+ // — which for these tmp state dirs is the tmp path itself. Left alone that lands
5
+ // in the developer's real ~/.pi/mega-compact-vector, where the rows stay
6
+ // eligible for cross-repo recall forever: a live session can be handed
7
+ // "threshold is 50k" and "the threshold is 100k" from this file as if they were
8
+ // another project's memories. scripts/run-tests.mjs sets MEGACOMPACT_INDEX_DIR
9
+ // per child, so the suite was already safe; running the file directly was not.
10
+ //
11
+ // Disabling PGlite is the same guard memoryRoundtrip.test.ts uses for the same
12
+ // reason, and it also keeps the file's exit clean (no WASM handle, and no
13
+ // initdb still running when the first test ends). MEGACOMPACT_INDEX_DIR is set
14
+ // as well so the isolation holds if a later test needs the index re-enabled.
15
+ process.env.MEGACOMPACT_PGLITE_DISABLED = "true";
1
16
  import { test } from "node:test";
2
17
  import assert from "node:assert/strict";
3
18
  import { mkdtempSync, rmSync } from "node:fs";
@@ -13,6 +28,7 @@ import {
13
28
  } from "./store/sqlite.js";
14
29
 
15
30
  const baseTmp = mkdtempSync(join(tmpdir(), "mc-memops-"));
31
+ process.env.MEGACOMPACT_INDEX_DIR = join(baseTmp, "index");
16
32
 
17
33
  test("applyMemoryOps: ADD inserts a new memory", async () => {
18
34
  const dir = join(baseTmp, "add");