| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | import * as NodeAssert from "node:assert/strict"; |
| 2 | |
| 3 | import { describe, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { buildOpenCodePermissionRules } from "./opencodeRuntime.ts"; |
| 6 | |
| 7 | function actionFor( |
| 8 | runtimeMode: Parameters<typeof buildOpenCodePermissionRules>[0], |
| 9 | permission: string, |
| 10 | ) { |
| 11 | return buildOpenCodePermissionRules(runtimeMode).find((rule) => rule.permission === permission) |
| 12 | ?.action; |
| 13 | } |
| 14 | |
| 15 | describe("buildOpenCodePermissionRules", () => { |
| 16 | it("pre-approves edits once the user has chosen to auto-accept them", () => { |
| 17 | NodeAssert.equal(actionFor("auto-accept-edits", "edit"), "allow"); |
| 18 | }); |
| 19 | |
| 20 | it("still asks before editing when approval is required", () => { |
| 21 | NodeAssert.equal(actionFor("approval-required", "edit"), "ask"); |
| 22 | }); |
| 23 | |
| 24 | // Documented in docs/user/permission-modes.md: providers without an AI |
| 25 | // reviewer, OpenCode among them, fall back to Supervised for "auto". |
| 26 | it("leaves auto asking, as the docs say it does without a reviewer", () => { |
| 27 | NodeAssert.equal(actionFor("auto", "edit"), "ask"); |
| 28 | }); |
| 29 | |
| 30 | it("keeps asking for everything else in the auto modes", () => { |
| 31 | for (const runtimeMode of ["auto-accept-edits", "auto"] as const) { |
| 32 | NodeAssert.equal(actionFor(runtimeMode, "bash"), "ask"); |
| 33 | NodeAssert.equal(actionFor(runtimeMode, "webfetch"), "ask"); |
| 34 | NodeAssert.equal(actionFor(runtimeMode, "external_directory"), "ask"); |
| 35 | NodeAssert.equal(actionFor(runtimeMode, "*"), "ask"); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | it("allows everything only under full access", () => { |
| 40 | NodeAssert.deepEqual(buildOpenCodePermissionRules("full-access"), [ |
| 41 | { permission: "*", pattern: "*", action: "allow" }, |
| 42 | ]); |
| 43 | }); |
| 44 | }); |