chore: import upstream snapshot with attribution
CI / test (20, macos-latest) (push) Has been cancelled
CI / test (20, ubuntu-latest) (push) Has been cancelled
CI / test (22, macos-latest) (push) Has been cancelled
CI / test (22, ubuntu-latest) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:01:18 +08:00
commit 979fb22d7c
613 changed files with 113494 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
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\)/);
});
});