Skip to content

Commit 018e5da

Browse files
committed
chore(skill-memory): rebase onto upstream v0.33.0 (migrations v70/71/72)
Upstream v0.33.0 added migrations v54-v69 (authority identity, mirror cursors, live-memory resnapshots, mural, message-FTS convergence), colliding with the skill-memory slots. Renumbered skill P1/P2/P3a to v70/71/72; LATEST_SUPPORTED_VERSION 69 -> 72. Also adapts our tests to two upstream contract changes: - executeStatus is async on this branch; upstream's new cortexkit#241 clamp tests needed await (they were added against the sync signature). - the historian output contract now requires the tiered paraphrase structure, so the skill_observations fixtures emit <p1> instead of a flat compartment body (same update upstream made to its e2e fixtures). - promotion.test.ts: upstream's two new embedding tests used the global mock.module('./embedding') this branch removed (CI mock bleed); they now use the non-global provider-factory seam.
1 parent 416d4a1 commit 018e5da

7 files changed

Lines changed: 205 additions & 329 deletions

File tree

‎packages/plugin/src/features/magic-context/memory/promotion.test.ts‎

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:te
44
import { Database } from "../../../shared/sqlite";
55
import { closeQuietly } from "../../../shared/sqlite-helpers";
66
import { CATEGORY_DEFAULT_TTL } from "./constants";
7+
import type { EmbeddingProvider } from "./embedding-provider";
78
import { computeNormalizedHash } from "./normalize-hash";
89

910
const mockLog = mock(() => {});
@@ -23,6 +24,13 @@ const {
2324
insertMemory,
2425
} = await import("./storage-memory");
2526
const { embedPromotedFacts, promoteSessionFactsDurable } = await import("./promotion");
27+
const {
28+
_resetProjectEmbeddingRegistryForTests,
29+
_setTestProviderFactoryForProject,
30+
registerProjectEmbedding,
31+
} = await import("./embedding");
32+
const { runMigrations } = await import("../migrations");
33+
const { initializeDatabase } = await import("../storage-db");
2634

2735
let db: Database | null = null;
2836

@@ -99,6 +107,8 @@ afterEach(() => {
99107
db = null;
100108
}
101109
}
110+
_resetProjectEmbeddingRegistryForTests();
111+
_setTestProviderFactoryForProject(null);
102112
});
103113

104114
describe("promotion", () => {
@@ -385,18 +395,35 @@ describe("promotion", () => {
385395

386396
describe("#given best-effort embedding of promoted facts", () => {
387397
it("stores the vector under the registered model when the memory is unchanged", async () => {
388-
db = makeMemoryDatabase();
398+
_resetProjectEmbeddingRegistryForTests();
399+
400+
db = new Database(":memory:");
401+
initializeDatabase(db);
402+
runMigrations(db);
403+
const snapshot = registerProjectEmbedding(
404+
db,
405+
"/repo/project",
406+
{ provider: "local", model: "mock-model" },
407+
{ memoryEnabled: true, gitCommitEnabled: false },
408+
"/repo/project",
409+
);
410+
_setTestProviderFactoryForProject(
411+
(): EmbeddingProvider => ({
412+
modelId: "mock:model",
413+
initialize: async () => true,
414+
embed: async (_text: string) => new Float32Array([1, 2]),
415+
embedBatch: async (texts: string[]) =>
416+
texts.map(() => new Float32Array([1, 2])),
417+
dispose: async () => {},
418+
isLoaded: () => true,
419+
}),
420+
);
421+
389422
const memory = insertMemory(db, {
390423
projectPath: "/repo/project",
391424
category: "ARCHITECTURE_DECISIONS",
392425
content: "Embed promoted facts eagerly",
393426
});
394-
mockEmbedText.mockImplementation(async () => ({
395-
vector: new Float32Array([1, 2]),
396-
modelId: "mock:model",
397-
chunkModelId: "mock:chunk",
398-
generation: 1,
399-
}));
400427

401428
await embedPromotedFacts(db, "ses-1", "/repo/project", [
402429
{ memoryId: memory.id, content: memory.content },
@@ -406,31 +433,52 @@ describe("promotion", () => {
406433
model_id: string;
407434
}>;
408435
expect(rows).toHaveLength(1);
409-
expect(rows[0].model_id).toBe("mock:model");
436+
expect(rows[0].model_id).toBe(snapshot.modelId);
410437
});
411438

412439
it("discards the stale vector when the memory is edited while embedding is in flight", async () => {
413-
db = makeMemoryDatabase();
440+
_resetProjectEmbeddingRegistryForTests();
441+
442+
db = new Database(":memory:");
443+
initializeDatabase(db);
444+
runMigrations(db);
445+
registerProjectEmbedding(
446+
db,
447+
"/repo/project",
448+
{ provider: "local", model: "mock-model" },
449+
{ memoryEnabled: true, gitCommitEnabled: false },
450+
"/repo/project",
451+
);
452+
453+
let resolveStarted: (() => void) | undefined;
454+
const started = new Promise<void>((resolve) => {
455+
resolveStarted = resolve;
456+
});
457+
let releaseBlocker: (() => void) | undefined;
458+
const blocker = new Promise<void>((resolve) => {
459+
releaseBlocker = resolve;
460+
});
461+
_setTestProviderFactoryForProject(
462+
(): EmbeddingProvider => ({
463+
modelId: "mock:model",
464+
initialize: async () => true,
465+
embed: async (_text: string): Promise<Float32Array> => {
466+
resolveStarted?.();
467+
await blocker;
468+
return new Float32Array([1, 2]);
469+
},
470+
embedBatch: async (texts: string[]) =>
471+
texts.map(() => new Float32Array([1, 2])),
472+
dispose: async () => {},
473+
isLoaded: () => true,
474+
}),
475+
);
476+
414477
const memory = insertMemory(db, {
415478
projectPath: "/repo/project",
416479
category: "ARCHITECTURE_DECISIONS",
417480
content: "Original promoted content",
418481
});
419-
let release: (() => void) | undefined;
420-
const started = new Promise<void>((resolve) => {
421-
mockEmbedText.mockImplementation(async () => {
422-
resolve();
423-
await new Promise<void>((done) => {
424-
release = done;
425-
});
426-
return {
427-
vector: new Float32Array([1, 2]),
428-
modelId: "mock:model",
429-
chunkModelId: "mock:chunk",
430-
generation: 1,
431-
};
432-
});
433-
});
434482

435483
const inFlight = embedPromotedFacts(db, "ses-1", "/repo/project", [
436484
{ memoryId: memory.id, content: memory.content },
@@ -441,7 +489,7 @@ describe("promotion", () => {
441489
db.prepare(
442490
"UPDATE memories SET content = ?, normalized_hash = ?, updated_at = ? WHERE id = ?",
443491
).run("Edited promoted content", "edited-hash", Date.now(), memory.id);
444-
release?.();
492+
releaseBlocker?.();
445493
await inFlight;
446494

447495
const count = (

‎packages/plugin/src/features/magic-context/migrations-v55.test.ts‎

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)