@memnexus-ai/mx-agent-cli 0.1.249 → 0.1.251

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.
@@ -11,41 +11,115 @@
11
11
  import { describe, it, expect } from 'vitest';
12
12
  import { readFileSync, readdirSync, statSync } from 'fs';
13
13
  import { join } from 'path';
14
- import { decideCodexAgentGate, extractAgentName, parseProvenGuardsArgs, } from '../commands/codex-agent-gate.js';
14
+ import { AGENT_NAME_FIELD, decideCodexAgentGate, extractAgentName, parseProvenGuardsArgs, } from '../commands/codex-agent-gate.js';
15
15
  import { CODEX_AGENT_GATE_COMMAND, buildCodexHooksJson } from '../lib/runtime/codex-config.js';
16
16
  const PROVEN = ['git-mutation-guard', 'named-memory-write-guard'];
17
+ /**
18
+ * A SubagentStart payload shaped like codex-cli 0.145.0's embedded
19
+ * `subagent-start.command.input` schema. Every `required` property is present, so a
20
+ * test that removes one is testing a real mutation rather than an already-invalid
21
+ * payload.
22
+ */
17
23
  function payload(fields) {
18
- return JSON.stringify({ hook_event_name: 'SubagentStart', session_id: 'abc', ...fields });
24
+ return JSON.stringify({
25
+ agent_id: 'agent_01HZ',
26
+ agent_type: 'git-expert',
27
+ cwd: '/workspace/.worktrees/wt',
28
+ hook_event_name: 'SubagentStart',
29
+ model: 'gpt-5.5',
30
+ permission_mode: 'default',
31
+ session_id: 'abc',
32
+ transcript_path: '/tmp/transcript.jsonl',
33
+ turn_id: 'turn_1',
34
+ ...fields,
35
+ });
19
36
  }
20
- describe('extractAgentName — payload field tolerance', () => {
21
- it('reads the plausible field names Codex might use', () => {
22
- for (const field of ['agent_name', 'agentName', 'subagent_type', 'subagentType', 'agent', 'agent_type', 'name']) {
23
- expect(extractAgentName(JSON.parse(payload({ [field]: 'git-expert' })))).toBe('git-expert');
37
+ describe('extractAgentName — reads the ONE verified field (NEW-6)', () => {
38
+ it('reads agent_type, the field the shipped schema marks required', () => {
39
+ expect(AGENT_NAME_FIELD).toBe('agent_type');
40
+ expect(extractAgentName(JSON.parse(payload({ agent_type: 'memory-creator' })))).toBe('memory-creator');
41
+ });
42
+ it('reads NOTHING ELSE — the schema sets additionalProperties:false', () => {
43
+ // Each of these was accepted before the field name was established. A genuine
44
+ // Codex payload cannot carry them, so accepting them only added ways for a
45
+ // non-genuine payload to name itself something the eligibility table allows.
46
+ for (const field of ['agent_name', 'agentName', 'subagent_type', 'subagentType', 'agent', 'name']) {
47
+ const p = JSON.parse(payload({ [field]: 'git-expert' }));
48
+ delete p[AGENT_NAME_FIELD];
49
+ expect(extractAgentName(p)).toBeNull();
24
50
  }
25
51
  });
26
- it('looks one level into a wrapper object', () => {
27
- expect(extractAgentName(JSON.parse(payload({ subagent: { name: 'red-team' } })))).toBe('red-team');
28
- expect(extractAgentName(JSON.parse(payload({ agent_info: { name: 'bar-raiser' } })))).toBe('bar-raiser');
52
+ it('does not descend into a wrapper object', () => {
53
+ for (const key of ['subagent', 'agent_info']) {
54
+ const p = JSON.parse(payload({ [key]: { agent_type: 'red-team' } }));
55
+ delete p[AGENT_NAME_FIELD];
56
+ expect(extractAgentName(p)).toBeNull();
57
+ }
29
58
  });
30
- it('IGNORES tool_input — the one wrapper whose contents the model writes', () => {
31
- // A name read from tool_input is a name the gated party chose. Ignoring it can
32
- // only widen the fail-closed path: an unresolved name is refused, never allowed.
33
- expect(extractAgentName(JSON.parse(payload({ tool_input: { agent_name: 'bar-raiser' } })))).toBeNull();
34
- const decision = decideCodexAgentGate({
35
- rawPayload: payload({ tool_input: { agent_name: 'git-expert' } }),
36
- provenGuards: ['git-mutation-guard'],
37
- });
38
- expect(decision.exitCode).toBe(2);
59
+ it('IGNORES tool_input — the one field whose contents the model writes', () => {
60
+ // A name read from tool_input is a name the gated party chose for itself.
61
+ const p = JSON.parse(payload({ tool_input: { agent_type: 'git-expert' } }));
62
+ delete p[AGENT_NAME_FIELD];
63
+ expect(extractAgentName(p)).toBeNull();
64
+ const raw = JSON.stringify(p);
65
+ expect(decideCodexAgentGate({ rawPayload: raw, provenGuards: ['git-mutation-guard'] }).exitCode).toBe(2);
39
66
  });
40
67
  it('trims surrounding whitespace', () => {
41
- expect(extractAgentName(JSON.parse(payload({ agent_name: ' git-expert \n' })))).toBe('git-expert');
68
+ expect(extractAgentName(JSON.parse(payload({ agent_type: ' git-expert \n' })))).toBe('git-expert');
42
69
  });
43
- it('returns null when no field carries a name', () => {
44
- expect(extractAgentName(JSON.parse(payload({})))).toBeNull();
45
- expect(extractAgentName(JSON.parse(payload({ agent_name: ' ' })))).toBeNull();
46
- expect(extractAgentName(JSON.parse(payload({ agent_name: 42 })))).toBeNull();
70
+ it('returns null for absent, blank, non-string and non-object input', () => {
71
+ const missing = JSON.parse(payload({}));
72
+ delete missing[AGENT_NAME_FIELD];
73
+ expect(extractAgentName(missing)).toBeNull();
74
+ expect(extractAgentName(JSON.parse(payload({ agent_type: ' ' })))).toBeNull();
75
+ expect(extractAgentName(JSON.parse(payload({ agent_type: 42 })))).toBeNull();
76
+ expect(extractAgentName(JSON.parse(payload({ agent_type: { nested: 'git-expert' } })))).toBeNull();
47
77
  expect(extractAgentName(null)).toBeNull();
48
78
  expect(extractAgentName('a string')).toBeNull();
79
+ expect(extractAgentName([{ agent_type: 'git-expert' }])).toBeNull();
80
+ });
81
+ });
82
+ describe('MUTATION CHECK — narrowing the field list did not open the gate', () => {
83
+ // The risk in shrinking seven candidates to one is that a payload which no longer
84
+ // resolves starts being ALLOWED instead of refused. These assert the opposite: for
85
+ // every agent in the eligibility table, and with every guard claimed proven, a
86
+ // payload whose agent_type is missing is still exit 2.
87
+ const AGENTS = ['git-expert', 'memory-creator', 'security-reviewer', 'bar-raiser', 'prd-writer'];
88
+ it('refuses when agent_type is absent, however generous --proven-guards is', () => {
89
+ for (const agent of AGENTS) {
90
+ // Name present in every OTHER plausible field, and in a wrapper, and in
91
+ // tool_input — the exact payload the old seven-candidate list would have
92
+ // resolved and allowed.
93
+ const mutated = JSON.parse(payload({
94
+ agent_name: agent,
95
+ agentName: agent,
96
+ subagent_type: agent,
97
+ subagentType: agent,
98
+ agent,
99
+ name: agent,
100
+ subagent: { agent_type: agent },
101
+ agent_info: { agent_type: agent },
102
+ tool_input: { agent_type: agent },
103
+ }));
104
+ delete mutated[AGENT_NAME_FIELD];
105
+ const d = decideCodexAgentGate({
106
+ rawPayload: JSON.stringify(mutated),
107
+ provenGuards: [...PROVEN, 'worktree-guard', 'mx-guard-hook'],
108
+ });
109
+ expect(d.exitCode).toBe(2);
110
+ expect(d.message).toMatch(/no agent name found/);
111
+ expect(d.agent).toBeUndefined();
112
+ }
113
+ });
114
+ it('names the field it required, so an operator can diagnose a payload change', () => {
115
+ const missing = JSON.parse(payload({}));
116
+ delete missing[AGENT_NAME_FIELD];
117
+ const d = decideCodexAgentGate({ rawPayload: JSON.stringify(missing) });
118
+ expect(d.message).toContain('agent_type');
119
+ expect(d.message).toMatch(/subagent-start\.command\.input/);
120
+ });
121
+ it('an empty payload object is refused, not treated as an unnamed allow', () => {
122
+ expect(decideCodexAgentGate({ rawPayload: '{}' }).exitCode).toBe(2);
49
123
  });
50
124
  });
51
125
  describe('decideCodexAgentGate — fails CLOSED on unusable input', () => {
@@ -57,22 +131,24 @@ describe('decideCodexAgentGate — fails CLOSED on unusable input', () => {
57
131
  it('refuses an empty payload (stdin never opened)', () => {
58
132
  expect(decideCodexAgentGate({ rawPayload: '' }).exitCode).toBe(2);
59
133
  });
60
- it('refuses when no agent name can be identified, and says which fields it checked', () => {
61
- const d = decideCodexAgentGate({ rawPayload: payload({}) });
134
+ it('refuses when no agent name can be identified, and names the field it needed', () => {
135
+ const missing = JSON.parse(payload({}));
136
+ delete missing[AGENT_NAME_FIELD];
137
+ const d = decideCodexAgentGate({ rawPayload: JSON.stringify(missing) });
62
138
  expect(d.exitCode).toBe(2);
63
139
  expect(d.message).toMatch(/no agent name found/);
64
- expect(d.message).toMatch(/agent_name/);
140
+ expect(d.message).toMatch(/agent_type/);
65
141
  });
66
142
  });
67
143
  describe('decideCodexAgentGate — FR-14b: security-reviewer refused at runtime', () => {
68
144
  it('blocks security-reviewer', () => {
69
- const d = decideCodexAgentGate({ rawPayload: payload({ agent_name: 'security-reviewer' }) });
145
+ const d = decideCodexAgentGate({ rawPayload: payload({ agent_type: 'security-reviewer' }) });
70
146
  expect(d.exitCode).toBe(2);
71
147
  expect(d.message).toMatch(/Run security review in a Claude session/);
72
148
  });
73
149
  it('blocks it even when every guard is claimed proven', () => {
74
150
  const d = decideCodexAgentGate({
75
- rawPayload: payload({ agent_name: 'security-reviewer' }),
151
+ rawPayload: payload({ agent_type: 'security-reviewer' }),
76
152
  provenGuards: [...PROVEN, 'worktree-guard'],
77
153
  });
78
154
  expect(d.exitCode).toBe(2);
@@ -81,37 +157,37 @@ describe('decideCodexAgentGate — FR-14b: security-reviewer refused at runtime'
81
157
  describe('decideCodexAgentGate — FR-14a / FR-15 at runtime', () => {
82
158
  it('blocks bar-raiser and red-team as in-session subagents', () => {
83
159
  for (const agent of ['bar-raiser', 'red-team']) {
84
- const d = decideCodexAgentGate({ rawPayload: payload({ agent_name: agent }), provenGuards: PROVEN });
160
+ const d = decideCodexAgentGate({ rawPayload: payload({ agent_type: agent }), provenGuards: PROVEN });
85
161
  expect(d.exitCode).toBe(2);
86
162
  expect(d.message).toMatch(/read-only wrapper process/);
87
163
  }
88
164
  });
89
165
  it('blocks every Bash-holding agent with no proven guards — the pre-G-7 state', () => {
90
166
  for (const agent of ['git-expert', 'memory-creator', 'dogfood-auditor', 'prd-writer']) {
91
- const d = decideCodexAgentGate({ rawPayload: payload({ agent_name: agent }) });
167
+ const d = decideCodexAgentGate({ rawPayload: payload({ agent_type: agent }) });
92
168
  expect(d.exitCode).toBe(2);
93
169
  expect(d.message).toMatch(/not verified firing/);
94
170
  }
95
171
  });
96
172
  it('allows an agent once ITS OWN guard is proven', () => {
97
173
  expect(decideCodexAgentGate({
98
- rawPayload: payload({ agent_name: 'git-expert' }),
174
+ rawPayload: payload({ agent_type: 'git-expert' }),
99
175
  provenGuards: ['git-mutation-guard'],
100
176
  }).exitCode).toBe(0);
101
177
  });
102
178
  it('does not let one guard\'s proof unlock a different agent', () => {
103
179
  expect(decideCodexAgentGate({
104
- rawPayload: payload({ agent_name: 'memory-creator' }),
180
+ rawPayload: payload({ agent_type: 'memory-creator' }),
105
181
  provenGuards: ['git-mutation-guard'],
106
182
  }).exitCode).toBe(2);
107
183
  });
108
184
  it('blocks an unclassified agent', () => {
109
- const d = decideCodexAgentGate({ rawPayload: payload({ agent_name: 'brand-new-agent' }), provenGuards: PROVEN });
185
+ const d = decideCodexAgentGate({ rawPayload: payload({ agent_type: 'brand-new-agent' }), provenGuards: PROVEN });
110
186
  expect(d.exitCode).toBe(2);
111
187
  expect(d.message).toMatch(/no entry in the per-agent safety mechanism table/);
112
188
  });
113
189
  it('prefixes refusals so the operator knows which control fired', () => {
114
- const d = decideCodexAgentGate({ rawPayload: payload({ agent_name: 'git-expert' }) });
190
+ const d = decideCodexAgentGate({ rawPayload: payload({ agent_type: 'git-expert' }) });
115
191
  expect(d.message).toMatch(/^codex agent gate: /);
116
192
  });
117
193
  });
@@ -1 +1 @@
1
- {"version":3,"file":"codex-agent-gate.test.js","sourceRoot":"","sources":["../../src/__tests__/codex-agent-gate.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE/F,MAAM,MAAM,GAAG,CAAC,oBAAoB,EAAE,0BAA0B,CAAC,CAAC;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.
10
10
  */
11
11
  import { describe, it, expect, beforeEach, afterEach } from 'vitest';
12
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
13
- import { join } from 'path';
12
+ import { spawnSync } from 'child_process';
13
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'fs';
14
+ import { join, resolve } from 'path';
14
15
  import { tmpdir } from 'os';
15
- import { AGENTS_OVERRIDE_FILENAME, CODEX_AGENT_GATE_COMMAND, CODEX_APPROVAL_POLICY, CODEX_CANONICAL_FOLD_NOTICE, CODEX_CONFIG_FILENAME, CODEX_DEFAULT_MODEL, CODEX_HOOKS_FILENAME, CODEX_MARKER_DEGRADATION_NOTICE, CODEX_SANDBOX_MODE, PHASE1_PORTED_GUARDS, PROJECT_DOC_MAX_BYTES, VERIFIED_CODEX_VERSION, buildAgentsOverride, buildCodexConfigToml, buildCodexHooksJson, codexHookCommand, codexHookTrustPreconditions, deployCodexConfig, measureInstructionChain, phase1HookEntries, resolveMemnexusMcpServer, tomlString, } from '../lib/runtime/codex-config.js';
16
+ import { AGENTS_OVERRIDE_FILENAME, CODEX_AGENT_GATE_COMMAND, CODEX_APPROVAL_POLICY, CODEX_CANONICAL_FOLD_NOTICE, CODEX_CONFIG_FILENAME, CODEX_DEFAULT_MODEL, CODEX_HOOKS_FILENAME, CODEX_MARKER_DEGRADATION_NOTICE, CODEX_SANDBOX_MODE, PHASE1_PORTED_GUARDS, PROJECT_DOC_MAX_BYTES, VERIFIED_CODEX_VERSION, assertNoHooksGrant, buildAgentsOverride, buildCodexConfigToml, buildCodexHooksJson, codexHookCommand, codexHookTrustPreconditions, deployCodexConfig, measureInstructionChain, phase1HookEntries, resolveGitWritableRoots, resolveMemnexusMcpServer, tomlString, } from '../lib/runtime/codex-config.js';
16
17
  import { buildClaudeLocalContent } from '../lib/claude.js';
17
18
  let root;
18
19
  let worktree;
@@ -513,6 +514,269 @@ describe('deployCodexConfig — idempotent artifact deployment', () => {
513
514
  expect(doc.hooks.SubagentStart[0].hooks[0].command).toContain('--proven-guards git-mutation-guard');
514
515
  });
515
516
  });
517
+ /**
518
+ * ─── writable_roots: the git directory lives OUTSIDE the worktree ───────────────
519
+ *
520
+ * A live Codex session on 2026-07-31 could not run `git stash`:
521
+ * "Unable to create '/workspace/.git/worktrees/<name>/index.lock': Read-only file
522
+ * system". `sandbox_mode = "workspace-write"` with no [sandbox_workspace_write]
523
+ * section makes the session directory the only writable root, and a worktree's `.git`
524
+ * is a pointer file to a directory outside it — so every git write failed.
525
+ *
526
+ * THE FIRST FIX — one root, the git dir — DID NOT WORK AND WAS UNSAFE. Direct
527
+ * observation of the sandbox mount table (`codex sandbox`, real sandbox, no model
528
+ * call) showed Codex re-binds `<common>/worktrees/<name>` READ-ONLY after applying
529
+ * writable_roots, so the nested path a parent root was supposed to cover came back
530
+ * read-only and index.lock still failed. The same root also granted write to
531
+ * `<common>/hooks`, whose contents execute OUTSIDE the sandbox on the next git
532
+ * command — a sandbox escape.
533
+ *
534
+ * These tests are the regression gate for the corrected, least-privilege set. Two
535
+ * MUTATION CHECKS below re-create the two ways this can regress — a `hooks`-granting
536
+ * root, and a dropped per-worktree admin path — and prove the assertions REJECT them,
537
+ * so a test that would pass with the fix undone cannot masquerade as coverage.
538
+ */
539
+ /** Run git for test fixtures. Identity is passed per-invocation, never written to a global config. */
540
+ function git(cwd, ...args) {
541
+ const r = spawnSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@example.invalid', '-c', 'commit.gpgsign=false', '-C', cwd, ...args], { encoding: 'utf-8', stdio: 'pipe' });
542
+ if (r.status !== 0)
543
+ throw new Error(`git ${args.join(' ')} failed: ${r.stderr}`);
544
+ }
545
+ /** Parse `writable_roots = [...]` out of a generated config, or null when absent. */
546
+ function parseWritableRoots(toml) {
547
+ const section = toml.split(/^\[sandbox_workspace_write\]$/m)[1];
548
+ if (section === undefined)
549
+ return null;
550
+ const line = section.split(/^\[/m)[0].match(/^writable_roots = \[(.*)\]$/m);
551
+ if (!line)
552
+ return null;
553
+ return [...line[1].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) => m[1].replace(/\\(.)/g, '$1'));
554
+ }
555
+ /**
556
+ * The path-coverage question Codex asks, reproduced without Codex: under
557
+ * `workspace-write`, a write is permitted when the target sits inside the session
558
+ * directory or inside a declared writable root.
559
+ */
560
+ function wouldPermitWrite(toml, sessionDir, target) {
561
+ const roots = [sessionDir, ...(parseWritableRoots(toml) ?? [])];
562
+ return roots.some((r) => target === r || target.startsWith(r.endsWith('/') ? r : `${r}/`));
563
+ }
564
+ describe('buildCodexConfigToml — writable_roots covers the git directory', () => {
565
+ let repo;
566
+ beforeEach(() => {
567
+ repo = realpathSync(mkdtempSync(join(tmpdir(), 'mx-codex-repo-')));
568
+ git(repo, 'init', '-q', '-b', 'main');
569
+ writeFileSync(join(repo, 'f.txt'), 'x');
570
+ git(repo, 'add', 'f.txt');
571
+ git(repo, 'commit', '-qm', 'init');
572
+ });
573
+ afterEach(() => {
574
+ rmSync(repo, { recursive: true, force: true });
575
+ });
576
+ describe('linked worktree — the shape every agent team runs in', () => {
577
+ let wt;
578
+ beforeEach(() => {
579
+ wt = join(repo, 'wt-linked');
580
+ git(repo, 'worktree', 'add', '-q', '-b', 'feature', wt);
581
+ // The defining property: .git is a POINTER FILE, not a directory.
582
+ expect(statSync(join(wt, '.git')).isFile()).toBe(true);
583
+ });
584
+ it('emits exactly the four least-privilege roots — three common subdirs + the admin dir', () => {
585
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
586
+ expect(toml).toContain('[sandbox_workspace_write]');
587
+ expect(parseWritableRoots(toml)).toEqual([
588
+ join(repo, '.git', 'objects'),
589
+ join(repo, '.git', 'refs'),
590
+ join(repo, '.git', 'logs'),
591
+ join(repo, '.git', 'worktrees', 'wt-linked'),
592
+ ]);
593
+ });
594
+ it('NEVER emits the git dir or the common dir itself — that is the hooks escape', () => {
595
+ const roots = parseWritableRoots(buildCodexConfigToml({ projectRoot: root, worktreePath: wt })) ?? [];
596
+ expect(roots).not.toContain(join(repo, '.git'));
597
+ // …so `<common>/hooks` — the ONLY hooks directory git actually runs, since `hooks`
598
+ // is a git COMMON path even for a linked worktree — stays read-only. That is the
599
+ // whole point: a file there executes outside the sandbox on the next git command.
600
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
601
+ expect(wouldPermitWrite(toml, wt, join(repo, '.git', 'hooks', 'post-commit'))).toBe(false);
602
+ // Proof that the common dir is where hooks resolve, so the writable admin dir is
603
+ // not an equivalent grant: git reports the common path for `hooks`.
604
+ const hooksPath = spawnSync('git', ['-C', wt, 'rev-parse', '--git-path', 'hooks'], {
605
+ encoding: 'utf-8',
606
+ }).stdout.trim();
607
+ expect(resolve(wt, hooksPath)).toBe(join(repo, '.git', 'hooks'));
608
+ });
609
+ it('permits the exact write that failed live: <common>/worktrees/<name>/index.lock', () => {
610
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
611
+ const indexLock = join(repo, '.git', 'worktrees', 'wt-linked', 'index.lock');
612
+ expect(existsSync(join(repo, '.git', 'worktrees', 'wt-linked'))).toBe(true);
613
+ expect(wouldPermitWrite(toml, wt, indexLock)).toBe(true);
614
+ });
615
+ it('MUTATION CHECK (no-section) — the assertions FAIL against the original pre-fix config', () => {
616
+ // The generator as it first shipped: identical except the section is absent. If
617
+ // this block ever passes, the tests above are not testing what they claim to.
618
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
619
+ const preFix = toml.replace(/# Git write boundary[\s\S]*?\n\n/, '');
620
+ expect(preFix).not.toContain('[sandbox_workspace_write]');
621
+ expect(parseWritableRoots(preFix)).toBeNull();
622
+ expect(wouldPermitWrite(preFix, wt, join(repo, '.git', 'worktrees', 'wt-linked', 'index.lock'))).toBe(false);
623
+ // And the fixed config differs from it — i.e. the section really is emitted.
624
+ expect(toml).not.toBe(preFix);
625
+ });
626
+ it('MUTATION CHECK (hooks) — a root that grants hooks/ is rejected, not emitted', () => {
627
+ // Re-create the broad-root config that "fixed" the stash failure. Two things must
628
+ // hold: the hooks-coverage assertion catches it, and the code refuses to build it.
629
+ const broad = buildCodexConfigToml({ projectRoot: root, worktreePath: wt }).replace(/^writable_roots = \[.*\]$/m, `writable_roots = ["${join(repo, '.git')}"]`);
630
+ expect(wouldPermitWrite(broad, wt, join(repo, '.git', 'hooks', 'post-commit'))).toBe(true);
631
+ expect(() => assertNoHooksGrant([join(repo, '.git')], [join(repo, '.git')])).toThrow(/sandbox escape/);
632
+ // A subdir root is fine; the git-dir root is not — the discriminator is real.
633
+ expect(() => assertNoHooksGrant([join(repo, '.git', 'objects')], [join(repo, '.git')])).not.toThrow();
634
+ });
635
+ it('MUTATION CHECK (dropped admin dir) — the exact bug being fixed is caught', () => {
636
+ // Drop `<common>/worktrees/<name>` from the emitted set, which is what relying on
637
+ // the parent root amounted to. index.lock must then be denied.
638
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
639
+ const adminDir = join(repo, '.git', 'worktrees', 'wt-linked');
640
+ const dropped = toml.replace(new RegExp(`,\\s*"${adminDir.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"`), '');
641
+ expect(parseWritableRoots(dropped)).not.toContain(adminDir);
642
+ expect(wouldPermitWrite(dropped, wt, join(adminDir, 'index.lock'))).toBe(false);
643
+ // The real config still permits it — so the mutation, not the fixture, is the cause.
644
+ expect(wouldPermitWrite(toml, wt, join(adminDir, 'index.lock'))).toBe(true);
645
+ });
646
+ it('covers objects, refs and refs/stash — commit, branch and stash, not just staging', () => {
647
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
648
+ for (const p of [
649
+ join(repo, '.git', 'objects', 'ab', 'cdef'),
650
+ join(repo, '.git', 'refs', 'heads', 'feature'),
651
+ join(repo, '.git', 'refs', 'stash'),
652
+ join(repo, '.git', 'logs', 'HEAD'),
653
+ join(repo, '.git', 'worktrees', 'wt-linked', 'index.lock'),
654
+ join(repo, '.git', 'worktrees', 'wt-linked', 'HEAD'),
655
+ join(repo, '.git', 'worktrees', 'wt-linked', 'rebase-merge', 'done'),
656
+ ]) {
657
+ expect(wouldPermitWrite(toml, wt, p)).toBe(true);
658
+ }
659
+ });
660
+ it('KNOWN GAP — packed-refs at the git-dir top level is NOT writable', () => {
661
+ // Documented limitation, asserted so it cannot change unnoticed: `git gc` and
662
+ // `git pack-refs` will fail in a Codex session. Covering it means granting the
663
+ // git-dir top level, which reopens the hooks escape. Decision item, not a bug fix.
664
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
665
+ expect(wouldPermitWrite(toml, wt, join(repo, '.git', 'packed-refs'))).toBe(false);
666
+ });
667
+ it('does not grant write to the main working tree, its siblings, or another team\'s gitdir', () => {
668
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
669
+ expect(wouldPermitWrite(toml, wt, join(repo, 'f.txt'))).toBe(false);
670
+ expect(wouldPermitWrite(toml, wt, join(repo, 'other-worktree', 'secrets'))).toBe(false);
671
+ expect(wouldPermitWrite(toml, wt, join(repo, '.github', 'workflows', 'ci.yml'))).toBe(false);
672
+ // The broad root granted this; the narrow set must not.
673
+ expect(wouldPermitWrite(toml, wt, join(repo, '.git', 'worktrees', 'other-team', 'index'))).toBe(false);
674
+ expect(wouldPermitWrite(toml, wt, join(repo, '.git', 'config'))).toBe(false);
675
+ });
676
+ it('keeps every previously declared setting exactly as it was', () => {
677
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
678
+ expect(toml).toContain(`sandbox_mode = "${CODEX_SANDBOX_MODE}"`);
679
+ expect(toml).toContain(`approval_policy = "${CODEX_APPROVAL_POLICY}"`);
680
+ expect(toml).toContain(`project_doc_max_bytes = ${PROJECT_DOC_MAX_BYTES}`);
681
+ expect(toml).toContain('project_doc_fallback_filenames = ["CLAUDE.md"]');
682
+ expect(toml).toContain('[mcp_servers.memnexus]');
683
+ // Widening writable_roots is the fix; weakening the sandbox is not.
684
+ expect(toml).not.toContain('danger-full-access');
685
+ });
686
+ it('puts every top-level key before the first table header (valid TOML)', () => {
687
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: wt });
688
+ const lines = toml.split('\n').filter((l) => l.trim() !== '' && !l.trim().startsWith('#'));
689
+ const firstTable = lines.findIndex((l) => l.startsWith('['));
690
+ const strayKey = lines.findIndex((l, i) => i > firstTable && /^(model|sandbox_mode|approval_policy|project_doc)/.test(l));
691
+ expect(firstTable).toBeGreaterThan(0);
692
+ expect(strayKey).toBe(-1);
693
+ // ... and the sandbox table precedes the MCP table, each key under its own header.
694
+ expect(lines.indexOf('[sandbox_workspace_write]')).toBeLessThan(lines.indexOf('[mcp_servers.memnexus]'));
695
+ });
696
+ });
697
+ describe('plain repository — `mx-agent new project` outside this monorepo', () => {
698
+ it('emits three roots and NO worktrees entry — git dir and common dir are the same', () => {
699
+ // Codex read-only-binds a `.git` directory inside the working tree too (verified
700
+ // on 0.145.0), so a plain clone needs these roots exactly as a worktree does.
701
+ expect(statSync(join(repo, '.git')).isDirectory()).toBe(true);
702
+ const toml = buildCodexConfigToml({ projectRoot: root, worktreePath: repo });
703
+ expect(parseWritableRoots(toml)).toEqual([
704
+ join(repo, '.git', 'objects'),
705
+ join(repo, '.git', 'refs'),
706
+ join(repo, '.git', 'logs'),
707
+ ]);
708
+ expect(parseWritableRoots(toml)).not.toContain(join(repo, '.git'));
709
+ expect(wouldPermitWrite(toml, join(repo, 'src'), join(repo, '.git', 'objects', 'ab', 'cd'))).toBe(true);
710
+ expect(wouldPermitWrite(toml, join(repo, 'src'), join(repo, '.git', 'hooks', 'post-commit'))).toBe(false);
711
+ });
712
+ });
713
+ describe('resolveGitWritableRoots', () => {
714
+ it('emits the per-worktree admin dir explicitly rather than relying on its parent', () => {
715
+ const wt = join(repo, 'wt2');
716
+ git(repo, 'worktree', 'add', '-q', '-b', 'f2', wt);
717
+ const { roots, diagnostics } = resolveGitWritableRoots(wt);
718
+ expect(roots).toEqual([
719
+ join(repo, '.git', 'objects'),
720
+ join(repo, '.git', 'refs'),
721
+ join(repo, '.git', 'logs'),
722
+ join(repo, '.git', 'worktrees', 'wt2'),
723
+ ]);
724
+ expect(roots).not.toContain(join(repo, '.git'));
725
+ expect(diagnostics).toEqual([]);
726
+ });
727
+ it('resolves from the .git pointer file when git itself cannot answer', () => {
728
+ // Detached copy: a `gitdir:` pointer with no reachable repository, so `git
729
+ // rev-parse` fails and the file-reading fallback is the only path left.
730
+ const orphan = mkdtempSync(join(tmpdir(), 'mx-codex-orphan-'));
731
+ writeFileSync(join(orphan, '.git'), `gitdir: ${join(repo, '.git', 'worktrees', 'gone')}\n`);
732
+ const { roots } = resolveGitWritableRoots(orphan);
733
+ expect(roots).toEqual([
734
+ join(repo, '.git', 'objects'),
735
+ join(repo, '.git', 'refs'),
736
+ join(repo, '.git', 'logs'),
737
+ join(repo, '.git', 'worktrees', 'gone'),
738
+ ]);
739
+ expect(roots).not.toContain(join(repo, '.git'));
740
+ rmSync(orphan, { recursive: true, force: true });
741
+ });
742
+ it('warns instead of silently emitting nothing when resolution fails', () => {
743
+ // The pre-fix failure mode was silence. A directory that is not a repository must
744
+ // produce a warning naming the consequence.
745
+ const notARepo = mkdtempSync(join(tmpdir(), 'mx-codex-norepo-'));
746
+ const { roots, diagnostics } = resolveGitWritableRoots(notARepo);
747
+ expect(roots).toEqual([]);
748
+ expect(diagnostics).toHaveLength(1);
749
+ expect(diagnostics[0].level).toBe('warn');
750
+ expect(diagnostics[0].code).toBe('codex-git-dir-unresolved');
751
+ expect(diagnostics[0].message).toMatch(/every git write .* will fail/);
752
+ rmSync(notARepo, { recursive: true, force: true });
753
+ });
754
+ });
755
+ describe('deployCodexConfig', () => {
756
+ it('writes the section for the worktree it deploys into, not the project root', () => {
757
+ const wt = join(repo, 'wt3');
758
+ git(repo, 'worktree', 'add', '-q', '-b', 'f3', wt);
759
+ deployCodexConfig({ projectRoot: root, worktreePath: wt, worktreeName: 'wt3', branch: 'f3', slot: 0 });
760
+ const toml = readFileSync(join(wt, CODEX_CONFIG_FILENAME), 'utf-8');
761
+ expect(parseWritableRoots(toml)).toEqual([
762
+ join(repo, '.git', 'objects'),
763
+ join(repo, '.git', 'refs'),
764
+ join(repo, '.git', 'logs'),
765
+ join(repo, '.git', 'worktrees', 'wt3'),
766
+ ]);
767
+ });
768
+ it('surfaces the unresolved-git-dir warning to the launch banner', () => {
769
+ const result = deployCodexConfig({
770
+ projectRoot: root,
771
+ worktreePath: worktree, // a bare temp dir: not a git repository
772
+ worktreeName: 'demo',
773
+ branch: null,
774
+ slot: 0,
775
+ });
776
+ expect(result.warnings.join('\n')).toMatch(/Could not resolve the git directory/);
777
+ });
778
+ });
779
+ });
516
780
  describe('version pinning', () => {
517
781
  it('pins the Codex version whose behaviour was probed for this adapter', () => {
518
782
  // Bumping this constant without re-running the hook/sandbox/stdin probes is the