Skip to content

Commit 16b91c8

Browse files
ualtinokAlfonso
andcommitted
test: de-flake two CI-timing test defects (#330, #333)
#330 storage-embedding-measurements cap test: the eviction-boundary test inserted MEASUREMENT_CORPUS_SESSION_ROW_CAP + 5 = 2005 disk-backed rows with no declared timeout, so its verdict was a function of machine speed against bun's default 5s per-test budget. Make the cap injectable via an optional parameter on recordEmbeddingMeasurement (defaulting to the production 2000) and exercise the boundary at cap=25. The invariant under test — "keeps the newest rows when the cap is exceeded" — is scale-independent, so a small cap proves it in ~90ms instead of ~7s and removes the hardware dependence entirely rather than raising the ceiling above it. #333 message-index-async boot-quiet test: the "rebuilds when removal overtakes a boot-quiet reconciliation" test asserted behavior inside a fixed 80ms wall-clock await, so under CI load the race window (a ~20ms boot-quiet timer, two scheduling hops, and two DB cycles) didn't close in time and the verdict flipped on timing rather than behavior. Replace the fixed await with the existing waitUntil() helper polling the observable outcome (reads === 2 AND isSessionReconciled) with a generous 5s ceiling — the assertion now waits FOR the state, not FOR a duration. Both fixes verified to still bite on real regressions: - #330: disabling the overflow DELETE makes the test fail (rows.length != cap). - #333: removing the clear-and-reindex rebuild makes the test time out waiting for the reconciled state. - #333 race confirmed: with boot-quiet expiring at ~100ms (after the old 80ms budget), the original wait(80) fails; the waitUntil version passes under the same shrunk window, proving the fix waits for state, not duration. Co-Authored-By: Alfonso <[email protected]>
1 parent 72456d3 commit 16b91c8

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)