Files
next-tjwater-agent/tests/runtime/opencodeConfig.test.ts
T
jiang 6336157ff4
Generic Container CI/CD / test-build-publish (push) Successful in 1m6s
Agent CI/CD / build-test-publish-and-deploy (push) Successful in 1m7s
feat: upgrade investigation and presentation runtime
2026-10-30 17:30:19 +08:00

39 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { readFile } from "node:fs/promises";
import { serviceOpencodeConfig } from "../../src/runtime/opencode2-config.js";
import { TASK_READER_AGENT } from "../../src/runtime/task-agent-policy.js";
describe("OpenCode 2 permissions", () => {
it("keeps one-shot recommendations separate from the business chat protocol and denies all tools", async () => {
const config = serviceOpencodeConfig({});
const generator = config.agents["prompt-suggestions"];
expect(generator.system).toBe(await readFile(".opencode/agents/prompt-suggestions.md", "utf8"));
expect(generator.system).not.toBe(config.agents.instruction.system);
expect(generator.model).toBe(config.agents.instruction.model);
expect(generator.permissions).toEqual([{ action: "*", resource: "*", effect: "deny" }]);
});
it("keeps protected paths denied, shell/edit gated and subagents disabled", async () => {
const config = JSON.parse(await readFile("opencode.json", "utf8"));
const rules = config.permissions as { action: string; resource: string; effect: string }[];
const effect = (action: string, resource: string) => rules.find((rule) => rule.action === action && rule.resource === resource)?.effect;
expect(effect("*", "*")).toBe("ask");
expect(effect("external_directory", "*")).toBe("deny");
expect(effect("subagent", "*")).toBe("deny");
expect(effect("question", "*")).toBe("allow");
expect(effect("ask_user", "*")).toBe("allow");
expect(effect("todowrite", "*")).toBe("allow");
for (const action of ["read", "edit"]) {
for (const path of [".env", "*.env", "data/**", "**/logs/**"]) expect(effect(action, path)).toBe("deny");
}
expect(effect("edit", "*")).toBe("ask");
expect(effect("shell", "*")).toBe("ask");
for (const pattern of ["*.env*", "*data/*", "*logs/*"]) expect(effect("shell", pattern)).toBe("deny");
expect(config.permission).toBeUndefined();
expect(config.experimental?.continue_loop_on_deny).toBeUndefined();
});
it("lets each parent subagent call provide the reader prompt", () => {
const reader = serviceOpencodeConfig({}).agents[TASK_READER_AGENT];
expect(reader).not.toHaveProperty("system");
});
});