fix(agent): isolate conversation workspaces
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import storeRenderRef, {
|
||||
resolveStoreRenderFilePath,
|
||||
} from "../../.opencode/tools/store_render_ref.js";
|
||||
|
||||
describe("internal OpenCode permissions", () => {
|
||||
it("keeps protected paths denied in every approval mode", async () => {
|
||||
@@ -23,8 +26,66 @@ describe("internal OpenCode permissions", () => {
|
||||
expect(edit?.["data/**"]).toBe("deny");
|
||||
expect(edit?.["**/logs/**"]).toBe("deny");
|
||||
expect(bash?.["*"]).toBe("ask");
|
||||
expect(bash?.["rm *"]).toBe("ask");
|
||||
expect(bash?.["rm -rf *"]).toBe("deny");
|
||||
expect(bash?.["rm -fr *"]).toBe("deny");
|
||||
expect(bash?.["rm -r -f *"]).toBe("deny");
|
||||
expect(bash?.["rm -f -r *"]).toBe("deny");
|
||||
expect(bash?.["rm --recursive --force *"]).toBe("deny");
|
||||
expect(bash?.["rm --force --recursive *"]).toBe("deny");
|
||||
expect(bash?.["*.env*"]).toBe("deny");
|
||||
expect(bash?.["*data/*"]).toBe("deny");
|
||||
expect(bash?.["*logs/*"]).toBe("deny");
|
||||
expect(bash?.["*data/*"]).toBeUndefined();
|
||||
expect(bash?.["*logs/*"]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("store_render_ref arguments", () => {
|
||||
it("accepts the observed camelCase alias without changing snake_case precedence", () => {
|
||||
expect(
|
||||
resolveStoreRenderFilePath({
|
||||
filePath: "/app/data/conversation-workspaces/chat-1/partition.json",
|
||||
}),
|
||||
).toBe("/app/data/conversation-workspaces/chat-1/partition.json");
|
||||
|
||||
expect(
|
||||
resolveStoreRenderFilePath({
|
||||
file_path: "/app/data/conversation-workspaces/chat-1/preferred.json",
|
||||
filePath: "/app/data/conversation-workspaces/chat-1/compatibility.json",
|
||||
}),
|
||||
).toBe("/app/data/conversation-workspaces/chat-1/preferred.json");
|
||||
});
|
||||
|
||||
it("forwards a camelCase compatibility argument as file_path", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
let requestBody: unknown;
|
||||
globalThis.fetch = (async (
|
||||
_input: RequestInfo | URL,
|
||||
init?: RequestInit,
|
||||
) => {
|
||||
requestBody = JSON.parse(String(init?.body));
|
||||
return new Response('{"render_ref":"res-test"}');
|
||||
}) as unknown as typeof fetch;
|
||||
|
||||
try {
|
||||
const definition = storeRenderRef as unknown as {
|
||||
args: Record<string, unknown>;
|
||||
execute: (args: unknown, context: unknown) => Promise<unknown>;
|
||||
};
|
||||
expect(definition.args.filePath).toBeDefined();
|
||||
await definition.execute(
|
||||
{
|
||||
reason: "regression test",
|
||||
filePath: "/app/data/conversation-workspaces/chat-1/partition.json",
|
||||
},
|
||||
{ sessionID: "session-test" } as never,
|
||||
);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
|
||||
expect(requestBody).toEqual({
|
||||
session_id: "session-test",
|
||||
file_path: "/app/data/conversation-workspaces/chat-1/partition.json",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user