Skip to content

Commit 5b7238c

Browse files
committed
test(#330,#333): injectable measurement cap (boundary at cap+5, 87ms) + state-wait replaces 80ms wall-clock in boot-quiet rebuild test — both mutation-proven to still bite
Co-Authored-By: Alfonso <[email protected]>
2 parents 1902969 + 16b91c8 commit 5b7238c

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎packages/plugin/src/features/magic-context/message-index-async.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,14 @@ describe("message-index-async", () => {
372372
scheduleClearAndReindex(db, sessionId, readSurviving);
373373
expect(isSessionReconciled(sessionId)).toBe(false);
374374

375-
await wait(80);
375+
// Wait for the observable outcome rather than a fixed wall-clock budget.
376+
// Both the boot-quiet reconciliation and the clear-and-reindex must have
377+
// run (reads === 2) and the rebuild must have re-marked the session
378+
// reconciled. A fixed `await wait(80)` made the verdict a function of
379+
// how fast the runner closed two scheduling hops plus two DB cycles
380+
// inside one window, which flips under CI load. Waiting for the state
381+
// (with a generous ceiling) makes a slow runner slow rather than red.
382+
await waitUntil(() => reads === 2 && isSessionReconciled(sessionId));
376383

377384
expect(reads).toBe(2);
378385
expect(countMessageRows(db, sessionId, "m-survivor")).toBe(1);

‎packages/plugin/src/features/magic-context/storage-embedding-measurements.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { join } from "node:path";
55
import { closeDatabase, openDatabase } from "./storage";
66
import {
77
listEmbeddingMeasurements,
8-
MEASUREMENT_CORPUS_SESSION_ROW_CAP,
98
normalizedQueryHash,
109
recordEmbeddingMeasurement,
1110
} from "./storage-embedding-measurements";
@@ -60,8 +59,15 @@ describe("embedding measurement corpus", () => {
6059
dirs.push(dir);
6160
process.env.XDG_DATA_HOME = dir;
6261
const db = openDatabase();
62+
// The cap is injectable so the eviction boundary can be exercised at a
63+
// small scale instead of the production 2000-row cap. The invariant
64+
// under test — "keeps the newest rows when the cap is exceeded" — is
65+
// scale-independent, so a small cap proves it in milliseconds rather
66+
// than ~7s of disk-backed inserts (which previously timed out on
67+
// slower hardware against bun's default 5s per-test budget).
68+
const cap = 25;
6369
const overflow = 5;
64-
const total = MEASUREMENT_CORPUS_SESSION_ROW_CAP + overflow;
70+
const total = cap + overflow;
6571
for (let i = 0; i < total; i++) {
6672
recordEmbeddingMeasurement(db, {
6773
sessionId: "ses-cap",
@@ -84,11 +90,11 @@ describe("embedding measurement corpus", () => {
8490
shadowEpoch: 0,
8591
corpusHash: `corpus-${i}`,
8692
coverage: {},
87-
});
93+
}, cap);
8894
}
8995

9096
const rows = listEmbeddingMeasurements(db, "ses-cap");
91-
expect(rows).toHaveLength(MEASUREMENT_CORPUS_SESSION_ROW_CAP);
97+
expect(rows).toHaveLength(cap);
9298
// The oldest `overflow` rows were pruned; the newest cap rows survive.
9399
expect(rows[0].query_text_hash).toBe(normalizedQueryHash(`query ${overflow}`));
94100
expect(rows[rows.length - 1].query_text_hash).toBe(

‎packages/plugin/src/features/magic-context/storage-embedding-measurements.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const MEASUREMENT_CORPUS_SESSION_ROW_CAP = 2000;
6161
export function recordEmbeddingMeasurement(
6262
db: Database,
6363
input: EmbeddingMeasurementInput,
64+
cap = MEASUREMENT_CORPUS_SESSION_ROW_CAP,
6465
): boolean {
6566
const queryTextHash = normalizedQueryHash(input.queryText);
6667
const dedupKey = queryTextHash;
@@ -108,7 +109,7 @@ export function recordEmbeddingMeasurement(
108109
)
109110
.get(input.sessionId) as { count: number }
110111
).count;
111-
const overflow = rowCount - MEASUREMENT_CORPUS_SESSION_ROW_CAP;
112+
const overflow = rowCount - cap;
112113
if (overflow > 0) {
113114
db.prepare(
114115
`DELETE FROM embedding_measurement_corpus

0 commit comments

Comments
 (0)