MCPcopy Create free account
hub / github.com/cortexkit/magic-context / seedMemory

Function seedMemory

packages/e2e-tests/tests/memory-injection.test.ts:62–84  ·  view source on GitHub ↗

* Seed a project-scoped memory row directly. We use a writable handle distinct * from the harness's read-only cached handle.

(h: TestHarness, projectIdentity: string, content: string)

Source from the content-addressed store, hash-verified

60 * from the harness's read-only cached handle.
61 */
62function seedMemory(h: TestHarness, projectIdentity: string, content: string): void {
63 // Plugin v0.16+ — shared cortexkit/magic-context path.
64 const dbPath = join(h.opencode.env.dataDir, "cortexkit", "magic-context", "context.db");
65 const db = openTestDb(dbPath);
66 try {
67 const now = Date.now();
68 // Use the production hash helper so this matches the value the plugin
69 // stores when it promotes a memory. Plugin uses Bun.CryptoHasher("md5"),
70 // which is stable across Bun versions (unlike Bun.hash).
71 const normalizedHash = computeNormalizedHash(content);
72 db.prepare(
73 `INSERT INTO memories (
74 project_path, category, content, normalized_hash,
75 source_session_id, source_type,
76 seen_count, retrieval_count,
77 first_seen_at, created_at, updated_at, last_seen_at,
78 status
79 ) VALUES (?, 'USER_DIRECTIVES', ?, ?, NULL, 'historian', 5, 0, ?, ?, ?, ?, 'active')`,
80 ).run(projectIdentity, content, normalizedHash, now, now, now, now);
81 } finally {
82 db.close();
83 }
84}
85
86describe("memory injection", () => {
87 it("injects <project-memory> on first turn even with no compartments", async () => {

Callers 1

Calls 5

openTestDbFunction · 0.90
computeNormalizedHashFunction · 0.90
runMethod · 0.65
prepareMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected