Files
rohitg00__agentmemory/test/opencode-auto-context.test.ts
Rohit Ghumare fd197dfda4 chore(release): v0.9.22 (#659)
Bump version across package.json + plugin manifests + version.ts +
types.ts ExportFormat union + export-import allow-list.

Strip issue-number stamps (// #NNN:) from new-wave source + test
files. CHANGELOG.md v0.9.22 entry bundles every PR merged since
v0.9.21 across Fixed / Added / Docs / Infrastructure.

1171/1171 vitest pass.
2026-05-26 10:53:03 +01: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\)/);
});
});