Files
rohitg00--agentmemory/test/opencode-auto-context.test.ts
wehub-resource-sync 979fb22d7c
CI / test (20, macos-latest) (push) Waiting to run
CI / test (20, ubuntu-latest) (push) Waiting to run
CI / test (22, macos-latest) (push) Waiting to run
CI / test (22, ubuntu-latest) (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:01:18 +08:00

38 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { readFileSync } from "node:fs";
// OpenCode plugin needs zero-config memory injection. Plugin
// already wires experimental.chat.system.transform; this PR threads
// the /session/start context through a cache so injection happens
// without a second /context fetch and is documented as the
// SessionStart-equivalent behaviour.
describe("OpenCode plugin auto-context injection (#431)", () => {
const plugin = readFileSync(
"plugin/opencode/agentmemory-capture.ts",
"utf-8",
);
it("captures context returned by POST /session/start", () => {
expect(plugin).toMatch(/startContextCache\s*=\s*new Map<string,\s*string>/);
expect(plugin).toMatch(
/postJson\(["']\/session\/start["']/,
);
// Snapshot `activeSessionId` into a local before the await so the cached
// context binds to the session that opened it, not a later one.
expect(plugin).toMatch(
/const\s+sessionId\s*=\s*activeSessionId[\s\S]*?startContextCache\.set\(sessionId/,
);
});
it("chat.system.transform reads cached context first, falls back to /context", () => {
expect(plugin).toMatch(/startContextCache\.get\(sid\)/);
expect(plugin).toMatch(/postJson\(["']\/context["']/);
expect(plugin).toMatch(/startContextCache\.delete\(sid\)/);
});
it("session.deleted clears the cache to avoid stale entries", () => {
const deletedBlock = plugin.slice(plugin.indexOf("session.deleted"));
expect(deletedBlock).toMatch(/startContextCache\.delete\(sid\)/);
});
});