feat: upgrade investigation and presentation runtime
This commit is contained in:
@@ -163,7 +163,7 @@ describe("OpencodeRuntimeAdapter.generateText", () => {
|
||||
}) as OpencodeRuntimeAdapter;
|
||||
try {
|
||||
expect(await runtime.generateText("recommend questions", { providerID: "test", modelID: "fast" }, controller.signal)).toBe("generated suggestions");
|
||||
expect(calls[0]).toMatchObject({ model: { providerID: "test", id: "fast" } });
|
||||
expect(calls[0]).toMatchObject({ agent: "prompt-suggestions", model: { providerID: "test", id: "fast" }, permissions: [{ action: "*", resource: "*", effect: "deny" }] });
|
||||
expect(calls[1]).toBe("catalog ready");
|
||||
expect(calls[2]).toEqual({ input: { sessionID: "temporary-generator", prompt: "recommend questions" }, signal: controller.signal });
|
||||
expect(calls[3]).toEqual({ sessionID: "temporary-generator" });
|
||||
@@ -225,7 +225,7 @@ describe("resolveEmbeddedOpencodePort", () => {
|
||||
});
|
||||
|
||||
describe("OpencodeRuntimeAdapter.warmup", () => {
|
||||
const toolIds = [...PRODUCT_MCP_TOOL_IDS, ...LOCAL_QUERY_TOOL_IDS, "websearch", "shell", "final_answer", "present_answer", "locate_features", "zoom_to_map", "show_chart", "view_history", "memory_manager", "skill_manager", "render_scada_analysis", "clear_scada_analysis", "publish_execution_plan", "publish_task_report", "publish_task_progress", "publish_task_presentation", "propose_task_action", "add_task_human_evidence", "request_task_data_access", "todowrite", "send_task_message", "reply_agent_message"];
|
||||
const toolIds = [...PRODUCT_MCP_TOOL_IDS, ...LOCAL_QUERY_TOOL_IDS, "websearch", "shell", "ask_user", "ask_task_user", "final_answer", "present_answer", "memory_manager", "skill_manager", "present_view", "publish_execution_plan", "publish_task_report", "publish_task_progress", "publish_task_presentation", "propose_task_action", "add_task_human_evidence", "request_task_data_access", "todowrite", "send_task_message", "reply_agent_message"];
|
||||
async function createWarmupRuntime(missing: string[] = [], invalidModel?: string, delayedMcp = false,
|
||||
search: { providers?: readonly string[]; selection?: false | { provider: string }; unavailable?: boolean; extraTools?: readonly string[] } = {}) {
|
||||
const root = await mkdtemp(join(tmpdir(), "warmup-workspace-test-"));
|
||||
@@ -300,8 +300,8 @@ describe("OpencodeRuntimeAdapter.warmup", () => {
|
||||
} finally { await cleanup(); }
|
||||
});
|
||||
it("fails readiness if a business tool was lost and still cleans up", async () => {
|
||||
const { runtime, calls, cleanup } = await createWarmupRuntime(["render_scada_analysis"]);
|
||||
try { await expect(runtime.warmup()).rejects.toThrow("business tools missing: render_scada_analysis");
|
||||
const { runtime, calls, cleanup } = await createWarmupRuntime(["present_view"]);
|
||||
try { await expect(runtime.warmup()).rejects.toThrow("business tools missing: present_view");
|
||||
expect(calls.at(-1)).toBe("session.remove"); } finally { await cleanup(); }
|
||||
});
|
||||
it("waits for native MCP catalog publication before reporting ready", async () => {
|
||||
@@ -313,9 +313,9 @@ describe("OpencodeRuntimeAdapter.warmup", () => {
|
||||
} finally { await cleanup(); }
|
||||
});
|
||||
it("rejects an invalid non-default model before readiness and cleans up the session", async () => {
|
||||
const { runtime, calls, cleanup } = await createWarmupRuntime([], "waternetwork/gpt-6.1-sol");
|
||||
const { runtime, calls, cleanup } = await createWarmupRuntime([], "waternetwork/gpt-5.6-sol");
|
||||
try {
|
||||
await expect(runtime.warmup()).rejects.toThrow("waternetwork/gpt-6.1-sol: not_advertised");
|
||||
await expect(runtime.warmup()).rejects.toThrow("waternetwork/gpt-5.6-sol: not_advertised");
|
||||
expect(calls).not.toContain("model.list");
|
||||
expect(calls.at(-1)).toBe("session.remove");
|
||||
} finally { await cleanup(); }
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
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 }[];
|
||||
@@ -10,6 +20,7 @@ describe("OpenCode 2 permissions", () => {
|
||||
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");
|
||||
@@ -20,4 +31,8 @@ describe("OpenCode 2 permissions", () => {
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,8 +21,8 @@ describe("task agent isolation", () => {
|
||||
expect(config.agents[TASK_READER_AGENT].permissions.map((rule) => rule.action)).toEqual([
|
||||
"*", ...PRODUCT_MCP_READ_TOOL_IDS,
|
||||
]);
|
||||
expect(PRODUCT_MCP_READ_TOOL_IDS).toHaveLength(42);
|
||||
expect(PRODUCT_MCP_TOOL_IDS).toHaveLength(67);
|
||||
expect(PRODUCT_MCP_READ_TOOL_IDS).toHaveLength(45);
|
||||
expect(PRODUCT_MCP_TOOL_IDS).toHaveLength(71);
|
||||
expect(PRODUCT_MCP_TOOL_IDS.some((name) => /publish|approve|execute|shell/.test(name))).toBeFalse();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user