-
Notifications
You must be signed in to change notification settings - Fork 29
feat(adal): add AdaL harness integration #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // @vitest-environment node | ||
| /** | ||
| * Guards the CLI allowlist in bin/failproofai.mjs against drift. | ||
| * | ||
| * The allowlist used to be duplicated once per subcommand parser (--hook, | ||
| * policies --install, policies --uninstall, policy add/remove). Adding a new CLI | ||
| * to only some copies made it installable but NOT removable, which is how the | ||
| * AdaL integration first shipped. It is now a single module-scope `VALID_CLIS` | ||
| * shared by every parser; these tests fail if anyone reintroduces a local copy | ||
| * or lets the list drift from INTEGRATION_TYPES. | ||
| */ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import { INTEGRATION_TYPES } from "../../src/hooks/types"; | ||
|
|
||
| const BIN_SOURCE = readFileSync(resolve(__dirname, "../../bin/failproofai.mjs"), "utf-8"); | ||
|
|
||
| describe("bin/failproofai.mjs CLI allowlist", () => { | ||
| it("declares exactly one VALID_CLIS set (no per-parser copies)", () => { | ||
| const declarations = BIN_SOURCE.match(/const VALID_CLIS = new Set\(/g) ?? []; | ||
| expect(declarations).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("covers every INTEGRATION_TYPES entry", () => { | ||
| const block = BIN_SOURCE.split("const VALID_CLIS = new Set(")[1]?.split("]);")[0] ?? ""; | ||
| for (const cli of INTEGRATION_TYPES) { | ||
| expect(block).toContain(`"${cli}"`); | ||
| } | ||
|
Comment on lines
+25
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert exact allowlist equality. This only checks that 🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| it("is consulted by every subcommand parser that accepts --cli", () => { | ||
| // install, uninstall, and policy add/remove each guard with VALID_CLIS.has. | ||
| const uses = BIN_SOURCE.match(/VALID_CLIS\.has\(/g) ?? []; | ||
| expect(uses.length).toBeGreaterThanOrEqual(3); | ||
|
Comment on lines
+32
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Validate each parser independently.
🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| it("accepts adal in the --hook parser as well", () => { | ||
| expect(BIN_SOURCE).toContain('cliArg === "adal"'); | ||
| }); | ||
|
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Cover every integration in the Checking only 🤖 Prompt for AI Agents |
||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // @vitest-environment node | ||
| /** | ||
| * AdaL payload canonicalization. | ||
| * | ||
| * AdaL is the only integration that needs NO event map: its lifecycle event | ||
| * names are already the canonical PascalCase forms, so they must survive | ||
| * canonicalization byte-for-byte. Tool names, however, are snake_case | ||
| * internally and must map onto the Claude vocabulary that builtin policies | ||
| * match on (Bash / Read / Write / Edit / …). | ||
| */ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { canonicalizeToolName, canonicalizeToolInput } from "../../src/hooks/tool-name-canonicalize"; | ||
| import { ADAL_TOOL_MAP, HOOK_EVENT_TYPES } from "../../src/hooks/types"; | ||
| import { adal } from "../../src/hooks/integrations"; | ||
|
|
||
| describe("AdaL event names need no mapping", () => { | ||
| it("every event AdaL fires is already a canonical HookEventType", () => { | ||
| for (const event of adal.eventTypes) { | ||
| expect(HOOK_EVENT_TYPES).toContain(event); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("canonicalizeToolName(cli: adal)", () => { | ||
| it("maps AdaL shell and search tools onto the Claude vocabulary", () => { | ||
| expect(canonicalizeToolName("bash", "adal")).toBe("Bash"); | ||
| expect(canonicalizeToolName("grep", "adal")).toBe("Grep"); | ||
| expect(canonicalizeToolName("glob", "adal")).toBe("Glob"); | ||
| }); | ||
|
|
||
| it("maps every AdaL file tool onto Read/Write/Edit", () => { | ||
| expect(canonicalizeToolName("read_file", "adal")).toBe("Read"); | ||
| expect(canonicalizeToolName("read_image", "adal")).toBe("Read"); | ||
| expect(canonicalizeToolName("write_file", "adal")).toBe("Write"); | ||
| expect(canonicalizeToolName("create_file", "adal")).toBe("Write"); | ||
| expect(canonicalizeToolName("rewrite_file", "adal")).toBe("Write"); | ||
| expect(canonicalizeToolName("replace_by_string", "adal")).toBe("Edit"); | ||
| expect(canonicalizeToolName("delete_lines", "adal")).toBe("Edit"); | ||
| }); | ||
|
|
||
| it("maps AdaL web tools", () => { | ||
| expect(canonicalizeToolName("fetch_url", "adal")).toBe("WebFetch"); | ||
| expect(canonicalizeToolName("web_search", "adal")).toBe("WebSearch"); | ||
| }); | ||
|
|
||
| it("passes unknown and MCP tool names through unchanged", () => { | ||
| expect(canonicalizeToolName("mcp__my-server__exec", "adal")).toBe("mcp__my-server__exec"); | ||
| expect(canonicalizeToolName("some_future_tool", "adal")).toBe("some_future_tool"); | ||
| }); | ||
|
|
||
| it("leaves undefined alone", () => { | ||
| expect(canonicalizeToolName(undefined, "adal")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("every ADAL_TOOL_MAP target is a name builtin policies recognise", () => { | ||
| for (const canonical of Object.values(ADAL_TOOL_MAP)) { | ||
| expect(canonical[0]).toBe(canonical[0].toUpperCase()); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("canonicalizeToolInput(cli: adal)", () => { | ||
| it("maps create_file's new_string body onto content so write builtins fire", () => { | ||
| const out = canonicalizeToolInput("Write", { file_path: "/tmp/a.txt", new_string: "secret" }, "adal"); | ||
| expect(out).toEqual({ file_path: "/tmp/a.txt", content: "secret" }); | ||
| }); | ||
|
|
||
| it("leaves already-canonical file paths untouched", () => { | ||
| const input = { file_path: "/tmp/a.txt" }; | ||
| expect(canonicalizeToolInput("Read", input, "adal")).toEqual(input); | ||
| }); | ||
|
|
||
| it("leaves bash command input untouched", () => { | ||
| const input = { command: "ls -la" }; | ||
| expect(canonicalizeToolInput("Bash", input, "adal")).toEqual(input); | ||
| }); | ||
|
|
||
| it("passes arrays and non-objects through verbatim", () => { | ||
| expect(canonicalizeToolInput("Write", ["a", "b"], "adal")).toEqual(["a", "b"]); | ||
| expect(canonicalizeToolInput("Write", undefined, "adal")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("is idempotent when input is already canonical", () => { | ||
| const once = canonicalizeToolInput("Write", { content: "x" }, "adal"); | ||
| expect(canonicalizeToolInput("Write", once, "adal")).toEqual({ content: "x" }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.