92 lines
3.4 KiB
TypeScript
92 lines
3.4 KiB
TypeScript
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 () => {
|
|
const config = JSON.parse(await readFile("opencode.json", "utf8")) as {
|
|
permission?: Record<string, string | Record<string, string>>;
|
|
};
|
|
const permission = config.permission ?? {};
|
|
const bash = permission.bash as Record<string, string> | undefined;
|
|
const edit = permission.edit as Record<string, string> | undefined;
|
|
const read = permission.read as Record<string, string> | undefined;
|
|
|
|
expect(permission["*"]).toBe("ask");
|
|
expect(permission.external_directory).toBe("deny");
|
|
expect(permission.task).toBe("deny");
|
|
expect(permission.question).toBe("allow");
|
|
expect(permission.todowrite).toBe("allow");
|
|
expect(read?.["*"]).toBe("allow");
|
|
expect(read?.["data/**"]).toBe("deny");
|
|
expect(read?.["**/logs/**"]).toBe("deny");
|
|
expect(edit?.["*"]).toBe("ask");
|
|
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/*"]).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",
|
|
});
|
|
});
|
|
});
|