@webpieces/ai-hook-rules 0.4.909 → 0.4.911

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/ai-hook-rules",
3
- "version": "0.4.909",
3
+ "version": "0.4.911",
4
4
  "description": "Independent source edit rules and source hook for AI coding agents.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -23,18 +23,18 @@
23
23
  "directory": "packages/tooling/ai-hook-rules"
24
24
  },
25
25
  "dependencies": {
26
- "@webpieces/hook-runtime": "0.4.909",
27
- "@webpieces/rules-config": "0.4.909",
26
+ "@webpieces/hook-runtime": "0.4.911",
27
+ "@webpieces/rules-config": "0.4.911",
28
28
  "inversify": "7.10.4",
29
29
  "reflect-metadata": "0.2.2",
30
- "@webpieces/tooling-common": "0.4.909",
31
- "@webpieces/rules-sdk": "0.4.909"
30
+ "@webpieces/tooling-common": "0.4.911",
31
+ "@webpieces/rules-sdk": "0.4.911"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
36
  "devDependencies": {
37
- "@webpieces/tooling-testkit": "0.4.909"
37
+ "@webpieces/tooling-testkit": "0.4.911"
38
38
  },
39
39
  "types": "./src/index.d.ts",
40
40
  "bin": {
@@ -50,7 +50,7 @@ export declare const GOLDEN_FIXTURES: readonly GoldenFixture[];
50
50
  /**
51
51
  * Builds ONE throwaway git repo per fixture and returns it with the payload's `<REPO>` resolved.
52
52
  *
53
- * A FRESH repo per fixture, not one shared: the hook writes `.webpieces/` state (the decision log, the
53
+ * A FRESH repo per fixture, not one shared: the hook writes `.webpieces-logs/` state (the decision log, the
54
54
  * main-sync cache) as it runs, so a shared tree would let fixture N's leftovers decide fixture N+1's
55
55
  * verdict — an order-dependent suite, which is the one kind of golden test worse than none.
56
56
  *
@@ -148,7 +148,7 @@ const CRASHING_RULE_MODULE = "throw new Error('boom from a custom rule module');
148
148
  /**
149
149
  * Builds ONE throwaway git repo per fixture and returns it with the payload's `<REPO>` resolved.
150
150
  *
151
- * A FRESH repo per fixture, not one shared: the hook writes `.webpieces/` state (the decision log, the
151
+ * A FRESH repo per fixture, not one shared: the hook writes `.webpieces-logs/` state (the decision log, the
152
152
  * main-sync cache) as it runs, so a shared tree would let fixture N's leftovers decide fixture N+1's
153
153
  * verdict — an order-dependent suite, which is the one kind of golden test worse than none.
154
154
  *
@@ -1 +1 @@
1
- {"version":3,"file":"hook-app-fixtures.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/hook-app-fixtures.ts"],"names":[],"mappings":";;;;AAAA,oDAO8B;AAC9B,4CAAgD;AAChD,gEAA2D;AAC3D,gEAA0D;AAC1D,iDAAyC;AACzC,+CAAyB;AAEzB,mDAA6B;AAI7B;;;;;;;;;;;GAWG;AAEH,yFAAyF;AACzF,MAAa,aAAa;IACtB,2DAA2D;IAClD,IAAI,CAAS;IACtB,sDAAsD;IAC7C,IAAI,CAAW;IACxB;;;OAGG;IACM,KAAK,CAAS;IACvB,4FAA4F;IACnF,eAAe,CAAU;IAElC,YAAY,IAAY,EAAE,IAAc,EAAE,KAAa,EAAE,kBAA2B,KAAK;QACrF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;CACJ;AAnBD,sCAmBC;AAED,gGAAgG;AAChG,MAAa,eAAe;IACf,IAAI,CAAS;IACb,IAAI,CAAS;IACb,KAAK,CAAS;IAEvB,YAAY,IAAY,EAAE,IAAY,EAAE,KAAa;QACjD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB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EAAE,6BAA6B,CAAC,CAAC;QAC9C,OAAO,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,kBAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACvF,CAAC;IAEO,UAAU,CAAC,OAAsB;QACrC,IAAI,CAAC,OAAO,CAAC,eAAe;YAAE,OAAO,IAAI,CAAC,UAAU,CAAC;QACrD,iMAAiM;QACjM,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAA4B,CAAC;QACrE,MAAM,CAAC,OAAO,CAAkC,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,MAAM,CAC7E,IAAI,wBAAY,EAAE,EAClB,EAAE,IAAI,EAAE,IAAI,EAAE,CACjB,CAAC;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAEO,GAAG,CAAC,IAAY,EAAE,IAAY;QAClC,IAAA,wBAAQ,EAAC,OAAO,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;CACJ;AApFD,8CAoFC","sourcesContent":["import {\n ConfigObject,\n FieldDef,\n OwnedRuleDefinition,\n RuleContribution,\n RuleHelp,\n RulePackManifest,\n} from '@webpieces/rules-sdk';\nimport { rulePackManifest } from '../rule-pack';\nimport { policyFixture } from '@webpieces/tooling-testkit';\nimport { specTempDirs } from '@webpieces/tooling-testkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\n\nimport { HookMode } from '@webpieces/hook-runtime';\n\n/**\n * THE WIRE BYTES the golden tests drive, and the throwaway repo they are judged against.\n *\n * Everything here exists so a reader can see EXACTLY what a harness sends: the payloads are built from\n * the measured envelope key sets (see the fixture docs on GoldenFixture below), not from anything the\n * hook itself produces, and the repo is a real `git init` with a frozen webpieces.config.json rather\n * than whatever tree the suite happens to be running in. A golden computed against the live repo would\n * change verdict with the branch you are standing on.\n *\n * This is NOT a spec file, deliberately: `tsconfig.lib.json` excludes `*.spec.ts`, so a payload builder\n * living in one would never be type-checked by the build.\n */\n\n/** How one PreToolUse call is presented to the hook. Data class per CLAUDE.md rule 1. */\nexport class GoldenFixture {\n /** Stable key into `__goldens__/hook-app-goldens.json`. */\n readonly name: string;\n /** Which hook binary's mode — `guards` or `rules`. */\n readonly mode: HookMode;\n /**\n * The raw stdin bytes. A STRING, never an object, because malformed stdin is one of the fixtures\n * and a shape that cannot express \"not JSON\" would quietly drop the case that matters most.\n */\n readonly stdin: string;\n /** True ⇒ the fixture repo also gets a `rulesDir` whose one module throws when required. */\n readonly crashingRuntime: boolean;\n\n constructor(name: string, mode: HookMode, stdin: string, crashingRuntime: boolean = false) {\n this.name = name;\n this.mode = mode;\n this.stdin = stdin;\n this.crashingRuntime = crashingRuntime;\n }\n}\n\n/** A built fixture repo: where it lives, and the stdin bytes with `<REPO>` resolved into it. */\nexport class PreparedFixture {\n readonly repo: string;\n readonly root: string;\n readonly stdin: string;\n\n constructor(repo: string, root: string, stdin: string) {\n this.repo = repo;\n this.root = root;\n this.stdin = stdin;\n }\n}\n\n/**\n * The placeholder that stands for the fixture repo's absolute path, in BOTH directions: payloads are\n * written with it and it is substituted in before the run; golden bytes are compared with the real\n * path substituted back out. Guard reports legitimately name absolute paths (the git-workflow doc\n * pointer, the blocked file), and a golden that hard-coded one machine's `/var/folders/...` would be\n * a golden nobody else could run.\n */\nexport const REPO_TOKEN = '<REPO>';\n\nconst CLAUDE_ENVELOPE = {\n hook_event_name: 'PreToolUse',\n session_id: 'sess-golden',\n transcript_path: '/dev/null',\n cwd: REPO_TOKEN,\n};\n\n/**\n * The Codex additions, MEASURED from codex-cli 0.151.0: it uses Claude's key names and merely ADDS\n * `model`, `turn_id`, `tool_use_id` and `permission_mode`. `turn_id` is the one discriminator (see\n * detect-ai.ts). `agent_id` empty ⇒ the coordinator, populated ⇒ a subagent — identical semantics in\n * both harnesses.\n */\nconst CODEX_ENVELOPE = {\n ...CLAUDE_ENVELOPE,\n model: 'gpt-5-codex',\n turn_id: 'turn-golden',\n tool_use_id: 'call_1',\n permission_mode: 'default',\n agent_type: 'default',\n agent_id: '',\n};\n\n// Codex's edit tool. MEASURED: the tool is named `apply_patch`, it carries `tool_input.command` (not\n// file_path), hunk headers are a bare `@@`, and ONE patch may carry many files with mixed operations.\nconst PATCH_ADD_JS = '*** Begin Patch\\n*** Add File: src/foo.js\\n+var x = 1;\\n*** End Patch\\n';\nconst PATCH_ADD_TS =\n '*** Begin Patch\\n*** Add File: scripts/added.ts\\n+export const b = 2;\\n*** End Patch\\n';\n\n/**\n * Serializes ONE PreToolUse envelope to the bytes a harness would put on stdin. A class rather than a\n * module-scope function because that is the repo rule, and the one instance below is built at module\n * load so the fixture table can stay a plain literal list.\n */\nclass WirePayload {\n // webpieces-disable no-any-unknown -- these objects ARE the wire envelope; JSON.stringify of a plain object is the payload under test, and naming a type for it would assert a shape the fixtures exist to state literally\n write(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n envelope: Record<string, unknown>,\n toolName: string,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n toolInput: Record<string, unknown>,\n ): string {\n return JSON.stringify({ ...envelope, tool_name: toolName, tool_input: toolInput });\n }\n}\n\nconst WIRE = new WirePayload();\n\n/**\n * ONE fixture per row of the coverage the composed pipeline had none of before: for BOTH harnesses a\n * Bash deny (the ANSI-red systemMessage), a file-tool deny (NO systemMessage), an allow, a read-only\n * tool, malformed stdin, and a fail-closed crash.\n */\nexport const GOLDEN_FIXTURES: readonly GoldenFixture[] = [\n // ── Claude Code ────────────────────────────────────────────────────────────────────────────────\n // A Bash deny. `git merge` is blocked on every branch, so this verdict does not depend on repo\n // state — and a Bash deny is the ONE case that carries the red `systemMessage`.\n // The read-only tool: log-and-allow, and the only guard that can deny it is a stale `main`.\n // Write / Edit / MultiEdit denies — all three must emit NO systemMessage.\n new GoldenFixture(\n 'claude/write-deny',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Write', {\n file_path: `${REPO_TOKEN}/src/foo.js`,\n content: 'var x = 1;\\n',\n }),\n ),\n new GoldenFixture(\n 'claude/edit-deny',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Edit', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n old_string: 'const a = 1;',\n new_string: 'const { a } = b;',\n }),\n ),\n new GoldenFixture(\n 'claude/multiedit-deny',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'MultiEdit', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n edits: [{ old_string: 'const a = 1;', new_string: 'const { a } = b;' }],\n }),\n ),\n new GoldenFixture(\n 'claude/write-allow',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Write', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n content: 'export const a = 1;\\n',\n }),\n ),\n new GoldenFixture(\n 'claude/crash',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Write', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n content: 'export const a = 1;\\n',\n }),\n true,\n ),\n\n // ── Codex ──────────────────────────────────────────────────────────────────────────────────────\n // Codex has no Read tool: a read arrives as `Bash` running a pager, which read parity turns into a\n // read-scoped verdict ON TOP of the bash guards.\n new GoldenFixture(\n 'codex/apply-patch-deny',\n 'rules',\n WIRE.write(CODEX_ENVELOPE, 'apply_patch', { command: PATCH_ADD_JS }),\n ),\n new GoldenFixture(\n 'codex/apply-patch-allow',\n 'rules',\n WIRE.write(CODEX_ENVELOPE, 'apply_patch', { command: PATCH_ADD_TS }),\n ),\n new GoldenFixture(\n 'codex/crash',\n 'rules',\n WIRE.write(CODEX_ENVELOPE, 'apply_patch', { command: PATCH_ADD_TS }),\n true,\n ),\n];\n\n// A rules module that blows up the moment it is required — the shortest honest way to reach the hook's\n// fail-closed boundary from OUTSIDE the hook, i.e. without stubbing anything the pipeline owns.\nconst CRASHING_RULE_MODULE = \"throw new Error('boom from a custom rule module');\\n\";\n\n/**\n * Builds ONE throwaway git repo per fixture and returns it with the payload's `<REPO>` resolved.\n *\n * A FRESH repo per fixture, not one shared: the hook writes `.webpieces/` state (the decision log, the\n * main-sync cache) as it runs, so a shared tree would let fixture N's leftovers decide fixture N+1's\n * verdict — an order-dependent suite, which is the one kind of golden test worse than none.\n *\n * `realpathSync` matters on macOS: `os.tmpdir()` hands back `/var/folders/...` which resolves to\n * `/private/var/...`, and the L1 location guard compares the payload's cwd against the resolved repo\n * root. Without it every fixture denies with \"run git from the repo root\" instead of the verdict under\n * test.\n */\nexport class GoldenRepoBuilder {\n private readonly configJson: string;\n\n constructor() {\n this.configJson = fs.readFileSync(\n path.join(__dirname, '__goldens__', 'fixture-webpieces.config.json'),\n 'utf8',\n );\n }\n\n build(fixture: GoldenFixture): PreparedFixture {\n const root = specTempDirs.makeReal('wp-hook-golden-');\n const repo = path.join(root, 'repo');\n fs.mkdirSync(repo);\n this.git(repo, 'init -q -b main');\n // The developer's own commit hooks would otherwise fire inside this throwaway repo.\n this.git(repo, 'config core.hooksPath /dev/null');\n this.git(repo, 'config user.email t@t.co');\n this.git(repo, 'config user.name tester');\n const manifests = policyFixture\n .manifests()\n .map((pack: RulePackManifest) =>\n pack.packageName === rulePackManifest.packageName ? rulePackManifest : pack,\n );\n if (fixture.crashingRuntime) {\n const seed = Object.assign(new ConfigObject(), { mode: 'ON' });\n const definition = new OwnedRuleDefinition(\n 'client-crash',\n { mode: new FieldDef('string', ['ON', 'OFF']) },\n 1,\n {},\n seed,\n 'rules',\n new RuleHelp('Client failure fixture', 'Repair {configFile}.'),\n );\n manifests.push(\n new RulePackManifest(\n '@client/crash',\n '1.0.0-fixture',\n 3,\n [definition],\n [\n new RuleContribution(\n 'client-crash',\n '@client/crash',\n 'source-hook',\n './crash-runtime.cjs',\n ),\n ],\n [],\n [],\n ),\n );\n }\n policyFixture.writeOwnerConfig(repo, JSON.parse(this.repoConfig(fixture)), manifests);\n fs.writeFileSync(path.join(repo, 'f.txt'), 'hello\\n');\n fs.mkdirSync(path.join(repo, 'scripts'));\n fs.writeFileSync(path.join(repo, 'scripts', 'ok.ts'), 'const a = 1;\\n');\n if (fixture.crashingRuntime) {\n fs.writeFileSync(path.join(repo, 'crash-runtime.cjs'), CRASHING_RULE_MODULE);\n }\n this.git(repo, 'add -A');\n this.git(repo, 'commit -qm init');\n // A local origin/main, so `origin/main..<branch>` resolves exactly as it does in a real clone.\n this.git(repo, 'update-ref refs/remotes/origin/main HEAD');\n // A feature branch, because that is where an agent actually works.\n this.git(repo, 'checkout -q -b dean/fixture');\n return new PreparedFixture(repo, root, fixture.stdin.split(REPO_TOKEN).join(repo));\n }\n\n private repoConfig(fixture: GoldenFixture): string {\n if (!fixture.crashingRuntime) return this.configJson;\n // webpieces-disable no-any-unknown -- the frozen fixture config is data on disk; re-parsing it into a named type here would be a second declaration of a file whose whole point is being literal\n const parsed = JSON.parse(this.configJson) as Record<string, unknown>;\n (parsed['rules'] as Record<string, ConfigObject>)['client-crash'] = Object.assign(\n new ConfigObject(),\n { mode: 'ON' },\n );\n return JSON.stringify(parsed, null, 4);\n }\n\n private git(repo: string, args: string): void {\n execSync(`git ${args}`, { cwd: repo, encoding: 'utf8' });\n }\n}\n"]}
1
+ {"version":3,"file":"hook-app-fixtures.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/adapters/hook-app-fixtures.ts"],"names":[],"mappings":";;;;AAAA,oDAO8B;AAC9B,4CAAgD;AAChD,gEAA2D;AAC3D,gEAA0D;AAC1D,iDAAyC;AACzC,+CAAyB;AAEzB,mDAA6B;AAI7B;;;;;;;;;;;GAWG;AAEH,yFAAyF;AACzF,MAAa,aAAa;IACtB,2DAA2D;IAClD,IAAI,CAAS;IACtB,sDAAsD;IAC7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,IAAY,EAAE,IAAY;QAClC,IAAA,wBAAQ,EAAC,OAAO,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;CACJ;AApFD,8CAoFC","sourcesContent":["import {\n ConfigObject,\n FieldDef,\n OwnedRuleDefinition,\n RuleContribution,\n RuleHelp,\n RulePackManifest,\n} from '@webpieces/rules-sdk';\nimport { rulePackManifest } from '../rule-pack';\nimport { policyFixture } from '@webpieces/tooling-testkit';\nimport { specTempDirs } from '@webpieces/tooling-testkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\n\nimport { HookMode } from '@webpieces/hook-runtime';\n\n/**\n * THE WIRE BYTES the golden tests drive, and the throwaway repo they are judged against.\n *\n * Everything here exists so a reader can see EXACTLY what a harness sends: the payloads are built from\n * the measured envelope key sets (see the fixture docs on GoldenFixture below), not from anything the\n * hook itself produces, and the repo is a real `git init` with a frozen webpieces.config.json rather\n * than whatever tree the suite happens to be running in. A golden computed against the live repo would\n * change verdict with the branch you are standing on.\n *\n * This is NOT a spec file, deliberately: `tsconfig.lib.json` excludes `*.spec.ts`, so a payload builder\n * living in one would never be type-checked by the build.\n */\n\n/** How one PreToolUse call is presented to the hook. Data class per CLAUDE.md rule 1. */\nexport class GoldenFixture {\n /** Stable key into `__goldens__/hook-app-goldens.json`. */\n readonly name: string;\n /** Which hook binary's mode — `guards` or `rules`. */\n readonly mode: HookMode;\n /**\n * The raw stdin bytes. A STRING, never an object, because malformed stdin is one of the fixtures\n * and a shape that cannot express \"not JSON\" would quietly drop the case that matters most.\n */\n readonly stdin: string;\n /** True ⇒ the fixture repo also gets a `rulesDir` whose one module throws when required. */\n readonly crashingRuntime: boolean;\n\n constructor(name: string, mode: HookMode, stdin: string, crashingRuntime: boolean = false) {\n this.name = name;\n this.mode = mode;\n this.stdin = stdin;\n this.crashingRuntime = crashingRuntime;\n }\n}\n\n/** A built fixture repo: where it lives, and the stdin bytes with `<REPO>` resolved into it. */\nexport class PreparedFixture {\n readonly repo: string;\n readonly root: string;\n readonly stdin: string;\n\n constructor(repo: string, root: string, stdin: string) {\n this.repo = repo;\n this.root = root;\n this.stdin = stdin;\n }\n}\n\n/**\n * The placeholder that stands for the fixture repo's absolute path, in BOTH directions: payloads are\n * written with it and it is substituted in before the run; golden bytes are compared with the real\n * path substituted back out. Guard reports legitimately name absolute paths (the git-workflow doc\n * pointer, the blocked file), and a golden that hard-coded one machine's `/var/folders/...` would be\n * a golden nobody else could run.\n */\nexport const REPO_TOKEN = '<REPO>';\n\nconst CLAUDE_ENVELOPE = {\n hook_event_name: 'PreToolUse',\n session_id: 'sess-golden',\n transcript_path: '/dev/null',\n cwd: REPO_TOKEN,\n};\n\n/**\n * The Codex additions, MEASURED from codex-cli 0.151.0: it uses Claude's key names and merely ADDS\n * `model`, `turn_id`, `tool_use_id` and `permission_mode`. `turn_id` is the one discriminator (see\n * detect-ai.ts). `agent_id` empty ⇒ the coordinator, populated ⇒ a subagent — identical semantics in\n * both harnesses.\n */\nconst CODEX_ENVELOPE = {\n ...CLAUDE_ENVELOPE,\n model: 'gpt-5-codex',\n turn_id: 'turn-golden',\n tool_use_id: 'call_1',\n permission_mode: 'default',\n agent_type: 'default',\n agent_id: '',\n};\n\n// Codex's edit tool. MEASURED: the tool is named `apply_patch`, it carries `tool_input.command` (not\n// file_path), hunk headers are a bare `@@`, and ONE patch may carry many files with mixed operations.\nconst PATCH_ADD_JS = '*** Begin Patch\\n*** Add File: src/foo.js\\n+var x = 1;\\n*** End Patch\\n';\nconst PATCH_ADD_TS =\n '*** Begin Patch\\n*** Add File: scripts/added.ts\\n+export const b = 2;\\n*** End Patch\\n';\n\n/**\n * Serializes ONE PreToolUse envelope to the bytes a harness would put on stdin. A class rather than a\n * module-scope function because that is the repo rule, and the one instance below is built at module\n * load so the fixture table can stay a plain literal list.\n */\nclass WirePayload {\n // webpieces-disable no-any-unknown -- these objects ARE the wire envelope; JSON.stringify of a plain object is the payload under test, and naming a type for it would assert a shape the fixtures exist to state literally\n write(\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n envelope: Record<string, unknown>,\n toolName: string,\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n toolInput: Record<string, unknown>,\n ): string {\n return JSON.stringify({ ...envelope, tool_name: toolName, tool_input: toolInput });\n }\n}\n\nconst WIRE = new WirePayload();\n\n/**\n * ONE fixture per row of the coverage the composed pipeline had none of before: for BOTH harnesses a\n * Bash deny (the ANSI-red systemMessage), a file-tool deny (NO systemMessage), an allow, a read-only\n * tool, malformed stdin, and a fail-closed crash.\n */\nexport const GOLDEN_FIXTURES: readonly GoldenFixture[] = [\n // ── Claude Code ────────────────────────────────────────────────────────────────────────────────\n // A Bash deny. `git merge` is blocked on every branch, so this verdict does not depend on repo\n // state — and a Bash deny is the ONE case that carries the red `systemMessage`.\n // The read-only tool: log-and-allow, and the only guard that can deny it is a stale `main`.\n // Write / Edit / MultiEdit denies — all three must emit NO systemMessage.\n new GoldenFixture(\n 'claude/write-deny',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Write', {\n file_path: `${REPO_TOKEN}/src/foo.js`,\n content: 'var x = 1;\\n',\n }),\n ),\n new GoldenFixture(\n 'claude/edit-deny',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Edit', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n old_string: 'const a = 1;',\n new_string: 'const { a } = b;',\n }),\n ),\n new GoldenFixture(\n 'claude/multiedit-deny',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'MultiEdit', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n edits: [{ old_string: 'const a = 1;', new_string: 'const { a } = b;' }],\n }),\n ),\n new GoldenFixture(\n 'claude/write-allow',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Write', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n content: 'export const a = 1;\\n',\n }),\n ),\n new GoldenFixture(\n 'claude/crash',\n 'rules',\n WIRE.write(CLAUDE_ENVELOPE, 'Write', {\n file_path: `${REPO_TOKEN}/scripts/ok.ts`,\n content: 'export const a = 1;\\n',\n }),\n true,\n ),\n\n // ── Codex ──────────────────────────────────────────────────────────────────────────────────────\n // Codex has no Read tool: a read arrives as `Bash` running a pager, which read parity turns into a\n // read-scoped verdict ON TOP of the bash guards.\n new GoldenFixture(\n 'codex/apply-patch-deny',\n 'rules',\n WIRE.write(CODEX_ENVELOPE, 'apply_patch', { command: PATCH_ADD_JS }),\n ),\n new GoldenFixture(\n 'codex/apply-patch-allow',\n 'rules',\n WIRE.write(CODEX_ENVELOPE, 'apply_patch', { command: PATCH_ADD_TS }),\n ),\n new GoldenFixture(\n 'codex/crash',\n 'rules',\n WIRE.write(CODEX_ENVELOPE, 'apply_patch', { command: PATCH_ADD_TS }),\n true,\n ),\n];\n\n// A rules module that blows up the moment it is required — the shortest honest way to reach the hook's\n// fail-closed boundary from OUTSIDE the hook, i.e. without stubbing anything the pipeline owns.\nconst CRASHING_RULE_MODULE = \"throw new Error('boom from a custom rule module');\\n\";\n\n/**\n * Builds ONE throwaway git repo per fixture and returns it with the payload's `<REPO>` resolved.\n *\n * A FRESH repo per fixture, not one shared: the hook writes `.webpieces-logs/` state (the decision log, the\n * main-sync cache) as it runs, so a shared tree would let fixture N's leftovers decide fixture N+1's\n * verdict — an order-dependent suite, which is the one kind of golden test worse than none.\n *\n * `realpathSync` matters on macOS: `os.tmpdir()` hands back `/var/folders/...` which resolves to\n * `/private/var/...`, and the L1 location guard compares the payload's cwd against the resolved repo\n * root. Without it every fixture denies with \"run git from the repo root\" instead of the verdict under\n * test.\n */\nexport class GoldenRepoBuilder {\n private readonly configJson: string;\n\n constructor() {\n this.configJson = fs.readFileSync(\n path.join(__dirname, '__goldens__', 'fixture-webpieces.config.json'),\n 'utf8',\n );\n }\n\n build(fixture: GoldenFixture): PreparedFixture {\n const root = specTempDirs.makeReal('wp-hook-golden-');\n const repo = path.join(root, 'repo');\n fs.mkdirSync(repo);\n this.git(repo, 'init -q -b main');\n // The developer's own commit hooks would otherwise fire inside this throwaway repo.\n this.git(repo, 'config core.hooksPath /dev/null');\n this.git(repo, 'config user.email t@t.co');\n this.git(repo, 'config user.name tester');\n const manifests = policyFixture\n .manifests()\n .map((pack: RulePackManifest) =>\n pack.packageName === rulePackManifest.packageName ? rulePackManifest : pack,\n );\n if (fixture.crashingRuntime) {\n const seed = Object.assign(new ConfigObject(), { mode: 'ON' });\n const definition = new OwnedRuleDefinition(\n 'client-crash',\n { mode: new FieldDef('string', ['ON', 'OFF']) },\n 1,\n {},\n seed,\n 'rules',\n new RuleHelp('Client failure fixture', 'Repair {configFile}.'),\n );\n manifests.push(\n new RulePackManifest(\n '@client/crash',\n '1.0.0-fixture',\n 3,\n [definition],\n [\n new RuleContribution(\n 'client-crash',\n '@client/crash',\n 'source-hook',\n './crash-runtime.cjs',\n ),\n ],\n [],\n [],\n ),\n );\n }\n policyFixture.writeOwnerConfig(repo, JSON.parse(this.repoConfig(fixture)), manifests);\n fs.writeFileSync(path.join(repo, 'f.txt'), 'hello\\n');\n fs.mkdirSync(path.join(repo, 'scripts'));\n fs.writeFileSync(path.join(repo, 'scripts', 'ok.ts'), 'const a = 1;\\n');\n if (fixture.crashingRuntime) {\n fs.writeFileSync(path.join(repo, 'crash-runtime.cjs'), CRASHING_RULE_MODULE);\n }\n this.git(repo, 'add -A');\n this.git(repo, 'commit -qm init');\n // A local origin/main, so `origin/main..<branch>` resolves exactly as it does in a real clone.\n this.git(repo, 'update-ref refs/remotes/origin/main HEAD');\n // A feature branch, because that is where an agent actually works.\n this.git(repo, 'checkout -q -b dean/fixture');\n return new PreparedFixture(repo, root, fixture.stdin.split(REPO_TOKEN).join(repo));\n }\n\n private repoConfig(fixture: GoldenFixture): string {\n if (!fixture.crashingRuntime) return this.configJson;\n // webpieces-disable no-any-unknown -- the frozen fixture config is data on disk; re-parsing it into a named type here would be a second declaration of a file whose whole point is being literal\n const parsed = JSON.parse(this.configJson) as Record<string, unknown>;\n (parsed['rules'] as Record<string, ConfigObject>)['client-crash'] = Object.assign(\n new ConfigObject(),\n { mode: 'ON' },\n );\n return JSON.stringify(parsed, null, 4);\n }\n\n private git(repo: string, args: string): void {\n execSync(`git ${args}`, { cwd: repo, encoding: 'utf8' });\n }\n}\n"]}