@memnexus-ai/mx-agent-cli 0.1.296-next.7 → 0.1.297

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.
Files changed (736) hide show
  1. package/dist/commands/create.d.ts +36 -0
  2. package/dist/commands/create.d.ts.map +1 -1
  3. package/dist/commands/create.js +85 -8
  4. package/dist/commands/create.js.map +1 -1
  5. package/dist/lib/templates.d.ts +1 -1
  6. package/dist/lib/templates.d.ts.map +1 -1
  7. package/dist/lib/templates.js +39 -3
  8. package/dist/lib/templates.js.map +1 -1
  9. package/dist/standards/decision-request.md +6 -57
  10. package/dist/standards/po-communication-standard.md +0 -34
  11. package/dist/standards/report-format.md +0 -90
  12. package/dist/standards/writing-standard.md +0 -312
  13. package/package.json +3 -1
  14. package/dist/__tests__/agent-attribution.test.d.ts +0 -16
  15. package/dist/__tests__/agent-attribution.test.d.ts.map +0 -1
  16. package/dist/__tests__/agent-attribution.test.js +0 -250
  17. package/dist/__tests__/agent-attribution.test.js.map +0 -1
  18. package/dist/__tests__/agents-md-canonicalization.test.d.ts +0 -23
  19. package/dist/__tests__/agents-md-canonicalization.test.d.ts.map +0 -1
  20. package/dist/__tests__/agents-md-canonicalization.test.js +0 -319
  21. package/dist/__tests__/agents-md-canonicalization.test.js.map +0 -1
  22. package/dist/__tests__/behavioral-compliance.test.d.ts +0 -8
  23. package/dist/__tests__/behavioral-compliance.test.d.ts.map +0 -1
  24. package/dist/__tests__/behavioral-compliance.test.js +0 -226
  25. package/dist/__tests__/behavioral-compliance.test.js.map +0 -1
  26. package/dist/__tests__/behavioral-extraction.test.d.ts +0 -12
  27. package/dist/__tests__/behavioral-extraction.test.d.ts.map +0 -1
  28. package/dist/__tests__/behavioral-extraction.test.js +0 -330
  29. package/dist/__tests__/behavioral-extraction.test.js.map +0 -1
  30. package/dist/__tests__/behavioral-git-read.test.d.ts +0 -21
  31. package/dist/__tests__/behavioral-git-read.test.d.ts.map +0 -1
  32. package/dist/__tests__/behavioral-git-read.test.js +0 -955
  33. package/dist/__tests__/behavioral-git-read.test.js.map +0 -1
  34. package/dist/__tests__/behavioral-injection.test.d.ts +0 -13
  35. package/dist/__tests__/behavioral-injection.test.d.ts.map +0 -1
  36. package/dist/__tests__/behavioral-injection.test.js +0 -384
  37. package/dist/__tests__/behavioral-injection.test.js.map +0 -1
  38. package/dist/__tests__/binary-smoke.test.d.ts +0 -12
  39. package/dist/__tests__/binary-smoke.test.d.ts.map +0 -1
  40. package/dist/__tests__/binary-smoke.test.js +0 -88
  41. package/dist/__tests__/binary-smoke.test.js.map +0 -1
  42. package/dist/__tests__/bootstrap-behavioral-contract.test.d.ts +0 -18
  43. package/dist/__tests__/bootstrap-behavioral-contract.test.d.ts.map +0 -1
  44. package/dist/__tests__/bootstrap-behavioral-contract.test.js +0 -104
  45. package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +0 -1
  46. package/dist/__tests__/bundle-config.test.d.ts +0 -18
  47. package/dist/__tests__/bundle-config.test.d.ts.map +0 -1
  48. package/dist/__tests__/bundle-config.test.js +0 -123
  49. package/dist/__tests__/bundle-config.test.js.map +0 -1
  50. package/dist/__tests__/catalog-interaction.test.d.ts +0 -25
  51. package/dist/__tests__/catalog-interaction.test.d.ts.map +0 -1
  52. package/dist/__tests__/catalog-interaction.test.js +0 -269
  53. package/dist/__tests__/catalog-interaction.test.js.map +0 -1
  54. package/dist/__tests__/catalog-named-memories.test.d.ts +0 -2
  55. package/dist/__tests__/catalog-named-memories.test.d.ts.map +0 -1
  56. package/dist/__tests__/catalog-named-memories.test.js +0 -204
  57. package/dist/__tests__/catalog-named-memories.test.js.map +0 -1
  58. package/dist/__tests__/catalog-origin-main.test.d.ts +0 -15
  59. package/dist/__tests__/catalog-origin-main.test.d.ts.map +0 -1
  60. package/dist/__tests__/catalog-origin-main.test.js +0 -305
  61. package/dist/__tests__/catalog-origin-main.test.js.map +0 -1
  62. package/dist/__tests__/catalog.test.d.ts +0 -2
  63. package/dist/__tests__/catalog.test.d.ts.map +0 -1
  64. package/dist/__tests__/catalog.test.js +0 -131
  65. package/dist/__tests__/catalog.test.js.map +0 -1
  66. package/dist/__tests__/claude-local-sanitizer.test.d.ts +0 -24
  67. package/dist/__tests__/claude-local-sanitizer.test.d.ts.map +0 -1
  68. package/dist/__tests__/claude-local-sanitizer.test.js +0 -906
  69. package/dist/__tests__/claude-local-sanitizer.test.js.map +0 -1
  70. package/dist/__tests__/claude-md-compose.test.d.ts +0 -17
  71. package/dist/__tests__/claude-md-compose.test.d.ts.map +0 -1
  72. package/dist/__tests__/claude-md-compose.test.js +0 -119
  73. package/dist/__tests__/claude-md-compose.test.js.map +0 -1
  74. package/dist/__tests__/claude-sync.test.d.ts +0 -2
  75. package/dist/__tests__/claude-sync.test.d.ts.map +0 -1
  76. package/dist/__tests__/claude-sync.test.js +0 -571
  77. package/dist/__tests__/claude-sync.test.js.map +0 -1
  78. package/dist/__tests__/cli-build-integration.test.d.ts +0 -2
  79. package/dist/__tests__/cli-build-integration.test.d.ts.map +0 -1
  80. package/dist/__tests__/cli-build-integration.test.js +0 -64
  81. package/dist/__tests__/cli-build-integration.test.js.map +0 -1
  82. package/dist/__tests__/cli-build.test.d.ts +0 -2
  83. package/dist/__tests__/cli-build.test.d.ts.map +0 -1
  84. package/dist/__tests__/cli-build.test.js +0 -640
  85. package/dist/__tests__/cli-build.test.js.map +0 -1
  86. package/dist/__tests__/codex-agent-gate.test.d.ts +0 -2
  87. package/dist/__tests__/codex-agent-gate.test.d.ts.map +0 -1
  88. package/dist/__tests__/codex-agent-gate.test.js +0 -480
  89. package/dist/__tests__/codex-agent-gate.test.js.map +0 -1
  90. package/dist/__tests__/codex-deploy-config.test.d.ts +0 -2
  91. package/dist/__tests__/codex-deploy-config.test.d.ts.map +0 -1
  92. package/dist/__tests__/codex-deploy-config.test.js +0 -1230
  93. package/dist/__tests__/codex-deploy-config.test.js.map +0 -1
  94. package/dist/__tests__/codex-trust-keys.test.d.ts +0 -2
  95. package/dist/__tests__/codex-trust-keys.test.d.ts.map +0 -1
  96. package/dist/__tests__/codex-trust-keys.test.js +0 -731
  97. package/dist/__tests__/codex-trust-keys.test.js.map +0 -1
  98. package/dist/__tests__/codex-write-race.test.d.ts +0 -2
  99. package/dist/__tests__/codex-write-race.test.d.ts.map +0 -1
  100. package/dist/__tests__/codex-write-race.test.js +0 -2253
  101. package/dist/__tests__/codex-write-race.test.js.map +0 -1
  102. package/dist/__tests__/completion-rows-discriminate.test.d.ts +0 -20
  103. package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +0 -1
  104. package/dist/__tests__/completion-rows-discriminate.test.js +0 -481
  105. package/dist/__tests__/completion-rows-discriminate.test.js.map +0 -1
  106. package/dist/__tests__/config-command.test.d.ts +0 -9
  107. package/dist/__tests__/config-command.test.d.ts.map +0 -1
  108. package/dist/__tests__/config-command.test.js +0 -75
  109. package/dist/__tests__/config-command.test.js.map +0 -1
  110. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +0 -2
  111. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +0 -1
  112. package/dist/__tests__/config-fidelity-archived-symlinks.test.js +0 -127
  113. package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +0 -1
  114. package/dist/__tests__/config-fidelity-display.test.d.ts +0 -2
  115. package/dist/__tests__/config-fidelity-display.test.d.ts.map +0 -1
  116. package/dist/__tests__/config-fidelity-display.test.js +0 -77
  117. package/dist/__tests__/config-fidelity-display.test.js.map +0 -1
  118. package/dist/__tests__/config-fidelity-unreadable-fixture.d.ts +0 -32
  119. package/dist/__tests__/config-fidelity-unreadable-fixture.d.ts.map +0 -1
  120. package/dist/__tests__/config-fidelity-unreadable-fixture.js +0 -37
  121. package/dist/__tests__/config-fidelity-unreadable-fixture.js.map +0 -1
  122. package/dist/__tests__/config-fidelity.test.d.ts +0 -16
  123. package/dist/__tests__/config-fidelity.test.d.ts.map +0 -1
  124. package/dist/__tests__/config-fidelity.test.js +0 -2679
  125. package/dist/__tests__/config-fidelity.test.js.map +0 -1
  126. package/dist/__tests__/config-generation-gate.test.d.ts +0 -46
  127. package/dist/__tests__/config-generation-gate.test.d.ts.map +0 -1
  128. package/dist/__tests__/config-generation-gate.test.js +0 -435
  129. package/dist/__tests__/config-generation-gate.test.js.map +0 -1
  130. package/dist/__tests__/config-generation.test.d.ts +0 -7
  131. package/dist/__tests__/config-generation.test.d.ts.map +0 -1
  132. package/dist/__tests__/config-generation.test.js +0 -141
  133. package/dist/__tests__/config-generation.test.js.map +0 -1
  134. package/dist/__tests__/config-sync.test.d.ts +0 -10
  135. package/dist/__tests__/config-sync.test.d.ts.map +0 -1
  136. package/dist/__tests__/config-sync.test.js +0 -268
  137. package/dist/__tests__/config-sync.test.js.map +0 -1
  138. package/dist/__tests__/coordination-401-production-wiring.test.d.ts +0 -19
  139. package/dist/__tests__/coordination-401-production-wiring.test.d.ts.map +0 -1
  140. package/dist/__tests__/coordination-401-production-wiring.test.js +0 -286
  141. package/dist/__tests__/coordination-401-production-wiring.test.js.map +0 -1
  142. package/dist/__tests__/coordination-401-recovery.test.d.ts +0 -22
  143. package/dist/__tests__/coordination-401-recovery.test.d.ts.map +0 -1
  144. package/dist/__tests__/coordination-401-recovery.test.js +0 -601
  145. package/dist/__tests__/coordination-401-recovery.test.js.map +0 -1
  146. package/dist/__tests__/coordination-brief-pin.test.d.ts +0 -20
  147. package/dist/__tests__/coordination-brief-pin.test.d.ts.map +0 -1
  148. package/dist/__tests__/coordination-brief-pin.test.js +0 -66
  149. package/dist/__tests__/coordination-brief-pin.test.js.map +0 -1
  150. package/dist/__tests__/coordination-brief.test.d.ts +0 -9
  151. package/dist/__tests__/coordination-brief.test.d.ts.map +0 -1
  152. package/dist/__tests__/coordination-brief.test.js +0 -290
  153. package/dist/__tests__/coordination-brief.test.js.map +0 -1
  154. package/dist/__tests__/coordination-client.test.d.ts +0 -9
  155. package/dist/__tests__/coordination-client.test.d.ts.map +0 -1
  156. package/dist/__tests__/coordination-client.test.js +0 -517
  157. package/dist/__tests__/coordination-client.test.js.map +0 -1
  158. package/dist/__tests__/coordination-command.test.d.ts +0 -9
  159. package/dist/__tests__/coordination-command.test.d.ts.map +0 -1
  160. package/dist/__tests__/coordination-command.test.js +0 -1082
  161. package/dist/__tests__/coordination-command.test.js.map +0 -1
  162. package/dist/__tests__/coordination-credential-endpoint.test.d.ts +0 -24
  163. package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +0 -1
  164. package/dist/__tests__/coordination-credential-endpoint.test.js +0 -1292
  165. package/dist/__tests__/coordination-credential-endpoint.test.js.map +0 -1
  166. package/dist/__tests__/coordination-expected-team.test.d.ts +0 -19
  167. package/dist/__tests__/coordination-expected-team.test.d.ts.map +0 -1
  168. package/dist/__tests__/coordination-expected-team.test.js +0 -423
  169. package/dist/__tests__/coordination-expected-team.test.js.map +0 -1
  170. package/dist/__tests__/coordination-fallback.test.d.ts +0 -9
  171. package/dist/__tests__/coordination-fallback.test.d.ts.map +0 -1
  172. package/dist/__tests__/coordination-fallback.test.js +0 -192
  173. package/dist/__tests__/coordination-fallback.test.js.map +0 -1
  174. package/dist/__tests__/coordination-file-guards.test.d.ts +0 -29
  175. package/dist/__tests__/coordination-file-guards.test.d.ts.map +0 -1
  176. package/dist/__tests__/coordination-file-guards.test.js +0 -380
  177. package/dist/__tests__/coordination-file-guards.test.js.map +0 -1
  178. package/dist/__tests__/coordination-history.test.d.ts +0 -8
  179. package/dist/__tests__/coordination-history.test.d.ts.map +0 -1
  180. package/dist/__tests__/coordination-history.test.js +0 -447
  181. package/dist/__tests__/coordination-history.test.js.map +0 -1
  182. package/dist/__tests__/coordination-memory.test.d.ts +0 -14
  183. package/dist/__tests__/coordination-memory.test.d.ts.map +0 -1
  184. package/dist/__tests__/coordination-memory.test.js +0 -401
  185. package/dist/__tests__/coordination-memory.test.js.map +0 -1
  186. package/dist/__tests__/coordination-mode.test.d.ts +0 -13
  187. package/dist/__tests__/coordination-mode.test.d.ts.map +0 -1
  188. package/dist/__tests__/coordination-mode.test.js +0 -180
  189. package/dist/__tests__/coordination-mode.test.js.map +0 -1
  190. package/dist/__tests__/coordination-plain-shell-commands.test.d.ts +0 -22
  191. package/dist/__tests__/coordination-plain-shell-commands.test.d.ts.map +0 -1
  192. package/dist/__tests__/coordination-plain-shell-commands.test.js +0 -1875
  193. package/dist/__tests__/coordination-plain-shell-commands.test.js.map +0 -1
  194. package/dist/__tests__/coordination-provision.test.d.ts +0 -12
  195. package/dist/__tests__/coordination-provision.test.d.ts.map +0 -1
  196. package/dist/__tests__/coordination-provision.test.js +0 -103
  197. package/dist/__tests__/coordination-provision.test.js.map +0 -1
  198. package/dist/__tests__/coordination-render.test.d.ts +0 -9
  199. package/dist/__tests__/coordination-render.test.d.ts.map +0 -1
  200. package/dist/__tests__/coordination-render.test.js +0 -335
  201. package/dist/__tests__/coordination-render.test.js.map +0 -1
  202. package/dist/__tests__/coordination-setup.test.d.ts +0 -6
  203. package/dist/__tests__/coordination-setup.test.d.ts.map +0 -1
  204. package/dist/__tests__/coordination-setup.test.js +0 -448
  205. package/dist/__tests__/coordination-setup.test.js.map +0 -1
  206. package/dist/__tests__/coordination-status-plain-shell.test.d.ts +0 -19
  207. package/dist/__tests__/coordination-status-plain-shell.test.d.ts.map +0 -1
  208. package/dist/__tests__/coordination-status-plain-shell.test.js +0 -332
  209. package/dist/__tests__/coordination-status-plain-shell.test.js.map +0 -1
  210. package/dist/__tests__/coordination-status-registration.test.d.ts +0 -16
  211. package/dist/__tests__/coordination-status-registration.test.d.ts.map +0 -1
  212. package/dist/__tests__/coordination-status-registration.test.js +0 -480
  213. package/dist/__tests__/coordination-status-registration.test.js.map +0 -1
  214. package/dist/__tests__/coordination-token-multitenant.test.d.ts +0 -11
  215. package/dist/__tests__/coordination-token-multitenant.test.d.ts.map +0 -1
  216. package/dist/__tests__/coordination-token-multitenant.test.js +0 -106
  217. package/dist/__tests__/coordination-token-multitenant.test.js.map +0 -1
  218. package/dist/__tests__/coordination-token.test.d.ts +0 -11
  219. package/dist/__tests__/coordination-token.test.d.ts.map +0 -1
  220. package/dist/__tests__/coordination-token.test.js +0 -201
  221. package/dist/__tests__/coordination-token.test.js.map +0 -1
  222. package/dist/__tests__/coordination-wiring.test.d.ts +0 -11
  223. package/dist/__tests__/coordination-wiring.test.d.ts.map +0 -1
  224. package/dist/__tests__/coordination-wiring.test.js +0 -43
  225. package/dist/__tests__/coordination-wiring.test.js.map +0 -1
  226. package/dist/__tests__/creation-pr-class-check.test.d.ts +0 -17
  227. package/dist/__tests__/creation-pr-class-check.test.d.ts.map +0 -1
  228. package/dist/__tests__/creation-pr-class-check.test.js +0 -346
  229. package/dist/__tests__/creation-pr-class-check.test.js.map +0 -1
  230. package/dist/__tests__/decision-check.test.d.ts +0 -2
  231. package/dist/__tests__/decision-check.test.d.ts.map +0 -1
  232. package/dist/__tests__/decision-check.test.js +0 -105
  233. package/dist/__tests__/decision-check.test.js.map +0 -1
  234. package/dist/__tests__/digest-fail-closed.test.d.ts +0 -16
  235. package/dist/__tests__/digest-fail-closed.test.d.ts.map +0 -1
  236. package/dist/__tests__/digest-fail-closed.test.js +0 -248
  237. package/dist/__tests__/digest-fail-closed.test.js.map +0 -1
  238. package/dist/__tests__/digest-team-omission.test.d.ts +0 -15
  239. package/dist/__tests__/digest-team-omission.test.d.ts.map +0 -1
  240. package/dist/__tests__/digest-team-omission.test.js +0 -247
  241. package/dist/__tests__/digest-team-omission.test.js.map +0 -1
  242. package/dist/__tests__/doctor-config-fidelity.test.d.ts +0 -19
  243. package/dist/__tests__/doctor-config-fidelity.test.d.ts.map +0 -1
  244. package/dist/__tests__/doctor-config-fidelity.test.js +0 -324
  245. package/dist/__tests__/doctor-config-fidelity.test.js.map +0 -1
  246. package/dist/__tests__/doctor-framework-version.test.d.ts +0 -2
  247. package/dist/__tests__/doctor-framework-version.test.d.ts.map +0 -1
  248. package/dist/__tests__/doctor-framework-version.test.js +0 -146
  249. package/dist/__tests__/doctor-framework-version.test.js.map +0 -1
  250. package/dist/__tests__/doctor-worktree-path.test.d.ts +0 -17
  251. package/dist/__tests__/doctor-worktree-path.test.d.ts.map +0 -1
  252. package/dist/__tests__/doctor-worktree-path.test.js +0 -158
  253. package/dist/__tests__/doctor-worktree-path.test.js.map +0 -1
  254. package/dist/__tests__/doctor.test.d.ts +0 -20
  255. package/dist/__tests__/doctor.test.d.ts.map +0 -1
  256. package/dist/__tests__/doctor.test.js +0 -849
  257. package/dist/__tests__/doctor.test.js.map +0 -1
  258. package/dist/__tests__/event-shipper.test.d.ts +0 -16
  259. package/dist/__tests__/event-shipper.test.d.ts.map +0 -1
  260. package/dist/__tests__/event-shipper.test.js +0 -287
  261. package/dist/__tests__/event-shipper.test.js.map +0 -1
  262. package/dist/__tests__/fleet-data.test.d.ts +0 -2
  263. package/dist/__tests__/fleet-data.test.d.ts.map +0 -1
  264. package/dist/__tests__/fleet-data.test.js +0 -501
  265. package/dist/__tests__/fleet-data.test.js.map +0 -1
  266. package/dist/__tests__/fleet-devpod.test.d.ts +0 -12
  267. package/dist/__tests__/fleet-devpod.test.d.ts.map +0 -1
  268. package/dist/__tests__/fleet-devpod.test.js +0 -260
  269. package/dist/__tests__/fleet-devpod.test.js.map +0 -1
  270. package/dist/__tests__/fleet-tmux.test.d.ts +0 -2
  271. package/dist/__tests__/fleet-tmux.test.d.ts.map +0 -1
  272. package/dist/__tests__/fleet-tmux.test.js +0 -289
  273. package/dist/__tests__/fleet-tmux.test.js.map +0 -1
  274. package/dist/__tests__/fleet.test.d.ts +0 -16
  275. package/dist/__tests__/fleet.test.d.ts.map +0 -1
  276. package/dist/__tests__/fleet.test.js +0 -75
  277. package/dist/__tests__/fleet.test.js.map +0 -1
  278. package/dist/__tests__/generate-claude.test.d.ts +0 -18
  279. package/dist/__tests__/generate-claude.test.d.ts.map +0 -1
  280. package/dist/__tests__/generate-claude.test.js +0 -1015
  281. package/dist/__tests__/generate-claude.test.js.map +0 -1
  282. package/dist/__tests__/gh-remote.test.d.ts +0 -2
  283. package/dist/__tests__/gh-remote.test.d.ts.map +0 -1
  284. package/dist/__tests__/gh-remote.test.js +0 -136
  285. package/dist/__tests__/gh-remote.test.js.map +0 -1
  286. package/dist/__tests__/git-env.test.d.ts +0 -14
  287. package/dist/__tests__/git-env.test.d.ts.map +0 -1
  288. package/dist/__tests__/git-env.test.js +0 -131
  289. package/dist/__tests__/git-env.test.js.map +0 -1
  290. package/dist/__tests__/git-identity-isolation.test.d.ts +0 -33
  291. package/dist/__tests__/git-identity-isolation.test.d.ts.map +0 -1
  292. package/dist/__tests__/git-identity-isolation.test.js +0 -626
  293. package/dist/__tests__/git-identity-isolation.test.js.map +0 -1
  294. package/dist/__tests__/harness-extract.test.d.ts +0 -19
  295. package/dist/__tests__/harness-extract.test.d.ts.map +0 -1
  296. package/dist/__tests__/harness-extract.test.js +0 -566
  297. package/dist/__tests__/harness-extract.test.js.map +0 -1
  298. package/dist/__tests__/harness-wiring.test.d.ts +0 -16
  299. package/dist/__tests__/harness-wiring.test.d.ts.map +0 -1
  300. package/dist/__tests__/harness-wiring.test.js +0 -469
  301. package/dist/__tests__/harness-wiring.test.js.map +0 -1
  302. package/dist/__tests__/hook-completeness.test.d.ts +0 -13
  303. package/dist/__tests__/hook-completeness.test.d.ts.map +0 -1
  304. package/dist/__tests__/hook-completeness.test.js +0 -238
  305. package/dist/__tests__/hook-completeness.test.js.map +0 -1
  306. package/dist/__tests__/hook-heal.test.d.ts +0 -8
  307. package/dist/__tests__/hook-heal.test.d.ts.map +0 -1
  308. package/dist/__tests__/hook-heal.test.js +0 -156
  309. package/dist/__tests__/hook-heal.test.js.map +0 -1
  310. package/dist/__tests__/human-turn-classifier.test.d.ts +0 -17
  311. package/dist/__tests__/human-turn-classifier.test.d.ts.map +0 -1
  312. package/dist/__tests__/human-turn-classifier.test.js +0 -311
  313. package/dist/__tests__/human-turn-classifier.test.js.map +0 -1
  314. package/dist/__tests__/init-coordination-url.test.d.ts +0 -11
  315. package/dist/__tests__/init-coordination-url.test.d.ts.map +0 -1
  316. package/dist/__tests__/init-coordination-url.test.js +0 -217
  317. package/dist/__tests__/init-coordination-url.test.js.map +0 -1
  318. package/dist/__tests__/isolation-probe.test.d.ts +0 -15
  319. package/dist/__tests__/isolation-probe.test.d.ts.map +0 -1
  320. package/dist/__tests__/isolation-probe.test.js +0 -611
  321. package/dist/__tests__/isolation-probe.test.js.map +0 -1
  322. package/dist/__tests__/leader-lock.test.d.ts +0 -12
  323. package/dist/__tests__/leader-lock.test.d.ts.map +0 -1
  324. package/dist/__tests__/leader-lock.test.js +0 -293
  325. package/dist/__tests__/leader-lock.test.js.map +0 -1
  326. package/dist/__tests__/memory-archive-checks.test.d.ts +0 -22
  327. package/dist/__tests__/memory-archive-checks.test.d.ts.map +0 -1
  328. package/dist/__tests__/memory-archive-checks.test.js +0 -748
  329. package/dist/__tests__/memory-archive-checks.test.js.map +0 -1
  330. package/dist/__tests__/memory-archive-prep.test.d.ts +0 -8
  331. package/dist/__tests__/memory-archive-prep.test.d.ts.map +0 -1
  332. package/dist/__tests__/memory-archive-prep.test.js +0 -524
  333. package/dist/__tests__/memory-archive-prep.test.js.map +0 -1
  334. package/dist/__tests__/memory-autocreate.test.d.ts +0 -10
  335. package/dist/__tests__/memory-autocreate.test.d.ts.map +0 -1
  336. package/dist/__tests__/memory-autocreate.test.js +0 -709
  337. package/dist/__tests__/memory-autocreate.test.js.map +0 -1
  338. package/dist/__tests__/memory-log-result.test.d.ts +0 -13
  339. package/dist/__tests__/memory-log-result.test.d.ts.map +0 -1
  340. package/dist/__tests__/memory-log-result.test.js +0 -149
  341. package/dist/__tests__/memory-log-result.test.js.map +0 -1
  342. package/dist/__tests__/memory-named-exists.test.d.ts +0 -16
  343. package/dist/__tests__/memory-named-exists.test.d.ts.map +0 -1
  344. package/dist/__tests__/memory-named-exists.test.js +0 -288
  345. package/dist/__tests__/memory-named-exists.test.js.map +0 -1
  346. package/dist/__tests__/message-bus.test.d.ts +0 -10
  347. package/dist/__tests__/message-bus.test.d.ts.map +0 -1
  348. package/dist/__tests__/message-bus.test.js +0 -526
  349. package/dist/__tests__/message-bus.test.js.map +0 -1
  350. package/dist/__tests__/monitor.test.d.ts +0 -6
  351. package/dist/__tests__/monitor.test.d.ts.map +0 -1
  352. package/dist/__tests__/monitor.test.js +0 -458
  353. package/dist/__tests__/monitor.test.js.map +0 -1
  354. package/dist/__tests__/mx-agent-cli-pin-validation.test.d.ts +0 -2
  355. package/dist/__tests__/mx-agent-cli-pin-validation.test.d.ts.map +0 -1
  356. package/dist/__tests__/mx-agent-cli-pin-validation.test.js +0 -232
  357. package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +0 -1
  358. package/dist/__tests__/mx-agent-cli-version-pin.test.d.ts +0 -2
  359. package/dist/__tests__/mx-agent-cli-version-pin.test.d.ts.map +0 -1
  360. package/dist/__tests__/mx-agent-cli-version-pin.test.js +0 -236
  361. package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +0 -1
  362. package/dist/__tests__/new-project-first-team.test.d.ts +0 -15
  363. package/dist/__tests__/new-project-first-team.test.d.ts.map +0 -1
  364. package/dist/__tests__/new-project-first-team.test.js +0 -444
  365. package/dist/__tests__/new-project-first-team.test.js.map +0 -1
  366. package/dist/__tests__/otel-env.test.d.ts +0 -2
  367. package/dist/__tests__/otel-env.test.d.ts.map +0 -1
  368. package/dist/__tests__/otel-env.test.js +0 -127
  369. package/dist/__tests__/otel-env.test.js.map +0 -1
  370. package/dist/__tests__/pager-fail-closed.test.d.ts +0 -19
  371. package/dist/__tests__/pager-fail-closed.test.d.ts.map +0 -1
  372. package/dist/__tests__/pager-fail-closed.test.js +0 -229
  373. package/dist/__tests__/pager-fail-closed.test.js.map +0 -1
  374. package/dist/__tests__/pr-set-body.test.d.ts +0 -29
  375. package/dist/__tests__/pr-set-body.test.d.ts.map +0 -1
  376. package/dist/__tests__/pr-set-body.test.js +0 -314
  377. package/dist/__tests__/pr-set-body.test.js.map +0 -1
  378. package/dist/__tests__/prior-sync-failure.test.d.ts +0 -2
  379. package/dist/__tests__/prior-sync-failure.test.d.ts.map +0 -1
  380. package/dist/__tests__/prior-sync-failure.test.js +0 -81
  381. package/dist/__tests__/prior-sync-failure.test.js.map +0 -1
  382. package/dist/__tests__/project-config.test.d.ts +0 -2
  383. package/dist/__tests__/project-config.test.d.ts.map +0 -1
  384. package/dist/__tests__/project-config.test.js +0 -458
  385. package/dist/__tests__/project-config.test.js.map +0 -1
  386. package/dist/__tests__/provision-behavioral-contract.test.d.ts +0 -13
  387. package/dist/__tests__/provision-behavioral-contract.test.d.ts.map +0 -1
  388. package/dist/__tests__/provision-behavioral-contract.test.js +0 -548
  389. package/dist/__tests__/provision-behavioral-contract.test.js.map +0 -1
  390. package/dist/__tests__/provision-catalog-precondition.test.d.ts +0 -26
  391. package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +0 -1
  392. package/dist/__tests__/provision-catalog-precondition.test.js +0 -622
  393. package/dist/__tests__/provision-catalog-precondition.test.js.map +0 -1
  394. package/dist/__tests__/provision-completion-rows.test.d.ts +0 -17
  395. package/dist/__tests__/provision-completion-rows.test.d.ts.map +0 -1
  396. package/dist/__tests__/provision-completion-rows.test.js +0 -3473
  397. package/dist/__tests__/provision-completion-rows.test.js.map +0 -1
  398. package/dist/__tests__/provision-copy-containment.test.d.ts +0 -19
  399. package/dist/__tests__/provision-copy-containment.test.d.ts.map +0 -1
  400. package/dist/__tests__/provision-copy-containment.test.js +0 -187
  401. package/dist/__tests__/provision-copy-containment.test.js.map +0 -1
  402. package/dist/__tests__/provision-identity-gate.test.d.ts +0 -20
  403. package/dist/__tests__/provision-identity-gate.test.d.ts.map +0 -1
  404. package/dist/__tests__/provision-identity-gate.test.js +0 -602
  405. package/dist/__tests__/provision-identity-gate.test.js.map +0 -1
  406. package/dist/__tests__/provision-resume.test.d.ts +0 -26
  407. package/dist/__tests__/provision-resume.test.d.ts.map +0 -1
  408. package/dist/__tests__/provision-resume.test.js +0 -1344
  409. package/dist/__tests__/provision-resume.test.js.map +0 -1
  410. package/dist/__tests__/provision-roleguide-anchors.test.d.ts +0 -27
  411. package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +0 -1
  412. package/dist/__tests__/provision-roleguide-anchors.test.js +0 -747
  413. package/dist/__tests__/provision-roleguide-anchors.test.js.map +0 -1
  414. package/dist/__tests__/provision-row12-stub-server.test.d.ts +0 -21
  415. package/dist/__tests__/provision-row12-stub-server.test.d.ts.map +0 -1
  416. package/dist/__tests__/provision-row12-stub-server.test.js +0 -264
  417. package/dist/__tests__/provision-row12-stub-server.test.js.map +0 -1
  418. package/dist/__tests__/provision-skeleton-fill.test.d.ts +0 -16
  419. package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +0 -1
  420. package/dist/__tests__/provision-skeleton-fill.test.js +0 -490
  421. package/dist/__tests__/provision-skeleton-fill.test.js.map +0 -1
  422. package/dist/__tests__/provision-step8-commit.test.d.ts +0 -40
  423. package/dist/__tests__/provision-step8-commit.test.d.ts.map +0 -1
  424. package/dist/__tests__/provision-step8-commit.test.js +0 -529
  425. package/dist/__tests__/provision-step8-commit.test.js.map +0 -1
  426. package/dist/__tests__/provision-teambuilder-flow.test.d.ts +0 -22
  427. package/dist/__tests__/provision-teambuilder-flow.test.d.ts.map +0 -1
  428. package/dist/__tests__/provision-teambuilder-flow.test.js +0 -253
  429. package/dist/__tests__/provision-teambuilder-flow.test.js.map +0 -1
  430. package/dist/__tests__/provision-write-integrity.test.d.ts +0 -18
  431. package/dist/__tests__/provision-write-integrity.test.d.ts.map +0 -1
  432. package/dist/__tests__/provision-write-integrity.test.js +0 -141
  433. package/dist/__tests__/provision-write-integrity.test.js.map +0 -1
  434. package/dist/__tests__/repo-guard-wiring.test.d.ts +0 -21
  435. package/dist/__tests__/repo-guard-wiring.test.d.ts.map +0 -1
  436. package/dist/__tests__/repo-guard-wiring.test.js +0 -638
  437. package/dist/__tests__/repo-guard-wiring.test.js.map +0 -1
  438. package/dist/__tests__/report-format.test.d.ts +0 -2
  439. package/dist/__tests__/report-format.test.d.ts.map +0 -1
  440. package/dist/__tests__/report-format.test.js +0 -219
  441. package/dist/__tests__/report-format.test.js.map +0 -1
  442. package/dist/__tests__/row15-detail-sanitizer.test.d.ts +0 -20
  443. package/dist/__tests__/row15-detail-sanitizer.test.d.ts.map +0 -1
  444. package/dist/__tests__/row15-detail-sanitizer.test.js +0 -61
  445. package/dist/__tests__/row15-detail-sanitizer.test.js.map +0 -1
  446. package/dist/__tests__/rows-9-10-zero-remotes.test.d.ts +0 -32
  447. package/dist/__tests__/rows-9-10-zero-remotes.test.d.ts.map +0 -1
  448. package/dist/__tests__/rows-9-10-zero-remotes.test.js +0 -203
  449. package/dist/__tests__/rows-9-10-zero-remotes.test.js.map +0 -1
  450. package/dist/__tests__/runtime-claude-adapter.test.d.ts +0 -2
  451. package/dist/__tests__/runtime-claude-adapter.test.d.ts.map +0 -1
  452. package/dist/__tests__/runtime-claude-adapter.test.js +0 -70
  453. package/dist/__tests__/runtime-claude-adapter.test.js.map +0 -1
  454. package/dist/__tests__/runtime-codex-adapter.test.d.ts +0 -2
  455. package/dist/__tests__/runtime-codex-adapter.test.d.ts.map +0 -1
  456. package/dist/__tests__/runtime-codex-adapter.test.js +0 -558
  457. package/dist/__tests__/runtime-codex-adapter.test.js.map +0 -1
  458. package/dist/__tests__/runtime-codex-config.test.d.ts +0 -2
  459. package/dist/__tests__/runtime-codex-config.test.d.ts.map +0 -1
  460. package/dist/__tests__/runtime-codex-config.test.js +0 -1421
  461. package/dist/__tests__/runtime-codex-config.test.js.map +0 -1
  462. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +0 -2
  463. package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +0 -1
  464. package/dist/__tests__/runtime-codex-gateway-pilot.test.js +0 -309
  465. package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +0 -1
  466. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +0 -2
  467. package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +0 -1
  468. package/dist/__tests__/runtime-codex-gateway-provider.test.js +0 -163
  469. package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +0 -1
  470. package/dist/__tests__/runtime-codex-guard-proof.test.d.ts +0 -2
  471. package/dist/__tests__/runtime-codex-guard-proof.test.d.ts.map +0 -1
  472. package/dist/__tests__/runtime-codex-guard-proof.test.js +0 -822
  473. package/dist/__tests__/runtime-codex-guard-proof.test.js.map +0 -1
  474. package/dist/__tests__/runtime-codex-version-pin.test.d.ts +0 -2
  475. package/dist/__tests__/runtime-codex-version-pin.test.d.ts.map +0 -1
  476. package/dist/__tests__/runtime-codex-version-pin.test.js +0 -86
  477. package/dist/__tests__/runtime-codex-version-pin.test.js.map +0 -1
  478. package/dist/__tests__/runtime-identity.test.d.ts +0 -2
  479. package/dist/__tests__/runtime-identity.test.d.ts.map +0 -1
  480. package/dist/__tests__/runtime-identity.test.js +0 -117
  481. package/dist/__tests__/runtime-identity.test.js.map +0 -1
  482. package/dist/__tests__/runtime-resolve.test.d.ts +0 -2
  483. package/dist/__tests__/runtime-resolve.test.d.ts.map +0 -1
  484. package/dist/__tests__/runtime-resolve.test.js +0 -172
  485. package/dist/__tests__/runtime-resolve.test.js.map +0 -1
  486. package/dist/__tests__/security-posture.test.d.ts +0 -8
  487. package/dist/__tests__/security-posture.test.d.ts.map +0 -1
  488. package/dist/__tests__/security-posture.test.js +0 -82
  489. package/dist/__tests__/security-posture.test.js.map +0 -1
  490. package/dist/__tests__/session-model.test.d.ts +0 -2
  491. package/dist/__tests__/session-model.test.d.ts.map +0 -1
  492. package/dist/__tests__/session-model.test.js +0 -74
  493. package/dist/__tests__/session-model.test.js.map +0 -1
  494. package/dist/__tests__/session-pause-provisioning.test.d.ts +0 -19
  495. package/dist/__tests__/session-pause-provisioning.test.d.ts.map +0 -1
  496. package/dist/__tests__/session-pause-provisioning.test.js +0 -115
  497. package/dist/__tests__/session-pause-provisioning.test.js.map +0 -1
  498. package/dist/__tests__/session-reclamation.test.d.ts +0 -15
  499. package/dist/__tests__/session-reclamation.test.d.ts.map +0 -1
  500. package/dist/__tests__/session-reclamation.test.js +0 -73
  501. package/dist/__tests__/session-reclamation.test.js.map +0 -1
  502. package/dist/__tests__/session-record-disclosure.test.d.ts +0 -24
  503. package/dist/__tests__/session-record-disclosure.test.d.ts.map +0 -1
  504. package/dist/__tests__/session-record-disclosure.test.js +0 -494
  505. package/dist/__tests__/session-record-disclosure.test.js.map +0 -1
  506. package/dist/__tests__/session-status.test.d.ts +0 -11
  507. package/dist/__tests__/session-status.test.d.ts.map +0 -1
  508. package/dist/__tests__/session-status.test.js +0 -76
  509. package/dist/__tests__/session-status.test.js.map +0 -1
  510. package/dist/__tests__/session.test.d.ts +0 -15
  511. package/dist/__tests__/session.test.d.ts.map +0 -1
  512. package/dist/__tests__/session.test.js +0 -366
  513. package/dist/__tests__/session.test.js.map +0 -1
  514. package/dist/__tests__/shim-deploy-safety.test.d.ts +0 -24
  515. package/dist/__tests__/shim-deploy-safety.test.d.ts.map +0 -1
  516. package/dist/__tests__/shim-deploy-safety.test.js +0 -174
  517. package/dist/__tests__/shim-deploy-safety.test.js.map +0 -1
  518. package/dist/__tests__/slug-validation.test.d.ts +0 -13
  519. package/dist/__tests__/slug-validation.test.d.ts.map +0 -1
  520. package/dist/__tests__/slug-validation.test.js +0 -202
  521. package/dist/__tests__/slug-validation.test.js.map +0 -1
  522. package/dist/__tests__/standards-injection.test.d.ts +0 -2
  523. package/dist/__tests__/standards-injection.test.d.ts.map +0 -1
  524. package/dist/__tests__/standards-injection.test.js +0 -179
  525. package/dist/__tests__/standards-injection.test.js.map +0 -1
  526. package/dist/__tests__/start-config-conflict.test.d.ts +0 -17
  527. package/dist/__tests__/start-config-conflict.test.d.ts.map +0 -1
  528. package/dist/__tests__/start-config-conflict.test.js +0 -101
  529. package/dist/__tests__/start-config-conflict.test.js.map +0 -1
  530. package/dist/__tests__/start-interactive-role.test.d.ts +0 -22
  531. package/dist/__tests__/start-interactive-role.test.d.ts.map +0 -1
  532. package/dist/__tests__/start-interactive-role.test.js +0 -204
  533. package/dist/__tests__/start-interactive-role.test.js.map +0 -1
  534. package/dist/__tests__/start-rebase-never-ran.test.d.ts +0 -25
  535. package/dist/__tests__/start-rebase-never-ran.test.d.ts.map +0 -1
  536. package/dist/__tests__/start-rebase-never-ran.test.js +0 -227
  537. package/dist/__tests__/start-rebase-never-ran.test.js.map +0 -1
  538. package/dist/__tests__/start-report-generation-capture.test.d.ts +0 -17
  539. package/dist/__tests__/start-report-generation-capture.test.d.ts.map +0 -1
  540. package/dist/__tests__/start-report-generation-capture.test.js +0 -127
  541. package/dist/__tests__/start-report-generation-capture.test.js.map +0 -1
  542. package/dist/__tests__/start-report-integration.test.d.ts +0 -12
  543. package/dist/__tests__/start-report-integration.test.d.ts.map +0 -1
  544. package/dist/__tests__/start-report-integration.test.js +0 -138
  545. package/dist/__tests__/start-report-integration.test.js.map +0 -1
  546. package/dist/__tests__/start-runtime-wiring.test.d.ts +0 -31
  547. package/dist/__tests__/start-runtime-wiring.test.d.ts.map +0 -1
  548. package/dist/__tests__/start-runtime-wiring.test.js +0 -735
  549. package/dist/__tests__/start-runtime-wiring.test.js.map +0 -1
  550. package/dist/__tests__/start-stash.test.d.ts +0 -2
  551. package/dist/__tests__/start-stash.test.d.ts.map +0 -1
  552. package/dist/__tests__/start-stash.test.js +0 -131
  553. package/dist/__tests__/start-stash.test.js.map +0 -1
  554. package/dist/__tests__/start-sync-hardstop.test.d.ts +0 -15
  555. package/dist/__tests__/start-sync-hardstop.test.d.ts.map +0 -1
  556. package/dist/__tests__/start-sync-hardstop.test.js +0 -280
  557. package/dist/__tests__/start-sync-hardstop.test.js.map +0 -1
  558. package/dist/__tests__/start-team-identity.test.d.ts +0 -25
  559. package/dist/__tests__/start-team-identity.test.d.ts.map +0 -1
  560. package/dist/__tests__/start-team-identity.test.js +0 -307
  561. package/dist/__tests__/start-team-identity.test.js.map +0 -1
  562. package/dist/__tests__/startup-health-render.test.d.ts +0 -11
  563. package/dist/__tests__/startup-health-render.test.d.ts.map +0 -1
  564. package/dist/__tests__/startup-health-render.test.js +0 -60
  565. package/dist/__tests__/startup-health-render.test.js.map +0 -1
  566. package/dist/__tests__/startup-policy.test.d.ts +0 -2
  567. package/dist/__tests__/startup-policy.test.d.ts.map +0 -1
  568. package/dist/__tests__/startup-policy.test.js +0 -27
  569. package/dist/__tests__/startup-policy.test.js.map +0 -1
  570. package/dist/__tests__/startup-report.test.d.ts +0 -13
  571. package/dist/__tests__/startup-report.test.d.ts.map +0 -1
  572. package/dist/__tests__/startup-report.test.js +0 -278
  573. package/dist/__tests__/startup-report.test.js.map +0 -1
  574. package/dist/__tests__/startup-shipper.test.d.ts +0 -13
  575. package/dist/__tests__/startup-shipper.test.d.ts.map +0 -1
  576. package/dist/__tests__/startup-shipper.test.js +0 -149
  577. package/dist/__tests__/startup-shipper.test.js.map +0 -1
  578. package/dist/__tests__/stream-input-controller.test.d.ts +0 -10
  579. package/dist/__tests__/stream-input-controller.test.d.ts.map +0 -1
  580. package/dist/__tests__/stream-input-controller.test.js +0 -167
  581. package/dist/__tests__/stream-input-controller.test.js.map +0 -1
  582. package/dist/__tests__/team-memory-commands.test.d.ts +0 -11
  583. package/dist/__tests__/team-memory-commands.test.d.ts.map +0 -1
  584. package/dist/__tests__/team-memory-commands.test.js +0 -240
  585. package/dist/__tests__/team-memory-commands.test.js.map +0 -1
  586. package/dist/__tests__/team-name-propagation.test.d.ts +0 -13
  587. package/dist/__tests__/team-name-propagation.test.d.ts.map +0 -1
  588. package/dist/__tests__/team-name-propagation.test.js +0 -198
  589. package/dist/__tests__/team-name-propagation.test.js.map +0 -1
  590. package/dist/__tests__/team-token-probe.test.d.ts +0 -16
  591. package/dist/__tests__/team-token-probe.test.d.ts.map +0 -1
  592. package/dist/__tests__/team-token-probe.test.js +0 -295
  593. package/dist/__tests__/team-token-probe.test.js.map +0 -1
  594. package/dist/__tests__/template-budget.test.d.ts +0 -2
  595. package/dist/__tests__/template-budget.test.d.ts.map +0 -1
  596. package/dist/__tests__/template-budget.test.js +0 -119
  597. package/dist/__tests__/template-budget.test.js.map +0 -1
  598. package/dist/__tests__/template-sync.test.d.ts +0 -19
  599. package/dist/__tests__/template-sync.test.d.ts.map +0 -1
  600. package/dist/__tests__/template-sync.test.js +0 -480
  601. package/dist/__tests__/template-sync.test.js.map +0 -1
  602. package/dist/__tests__/test-project.test.d.ts +0 -18
  603. package/dist/__tests__/test-project.test.d.ts.map +0 -1
  604. package/dist/__tests__/test-project.test.js +0 -465
  605. package/dist/__tests__/test-project.test.js.map +0 -1
  606. package/dist/__tests__/tracked-instruction-files.test.d.ts +0 -21
  607. package/dist/__tests__/tracked-instruction-files.test.d.ts.map +0 -1
  608. package/dist/__tests__/tracked-instruction-files.test.js +0 -489
  609. package/dist/__tests__/tracked-instruction-files.test.js.map +0 -1
  610. package/dist/__tests__/unlock.test.d.ts +0 -11
  611. package/dist/__tests__/unlock.test.d.ts.map +0 -1
  612. package/dist/__tests__/unlock.test.js +0 -100
  613. package/dist/__tests__/unlock.test.js.map +0 -1
  614. package/dist/__tests__/usage-per-call-grouping.test.d.ts +0 -25
  615. package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +0 -1
  616. package/dist/__tests__/usage-per-call-grouping.test.js +0 -952
  617. package/dist/__tests__/usage-per-call-grouping.test.js.map +0 -1
  618. package/dist/__tests__/usage-pricing.test.d.ts +0 -20
  619. package/dist/__tests__/usage-pricing.test.d.ts.map +0 -1
  620. package/dist/__tests__/usage-pricing.test.js +0 -176
  621. package/dist/__tests__/usage-pricing.test.js.map +0 -1
  622. package/dist/__tests__/usage-subagent-discovery.test.d.ts +0 -17
  623. package/dist/__tests__/usage-subagent-discovery.test.d.ts.map +0 -1
  624. package/dist/__tests__/usage-subagent-discovery.test.js +0 -213
  625. package/dist/__tests__/usage-subagent-discovery.test.js.map +0 -1
  626. package/dist/__tests__/verify-hooks-check-all.test.d.ts +0 -32
  627. package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +0 -1
  628. package/dist/__tests__/verify-hooks-check-all.test.js +0 -563
  629. package/dist/__tests__/verify-hooks-check-all.test.js.map +0 -1
  630. package/dist/__tests__/verify-hooks-heal-log.test.d.ts +0 -11
  631. package/dist/__tests__/verify-hooks-heal-log.test.d.ts.map +0 -1
  632. package/dist/__tests__/verify-hooks-heal-log.test.js +0 -172
  633. package/dist/__tests__/verify-hooks-heal-log.test.js.map +0 -1
  634. package/dist/__tests__/worker-cap.test.d.ts +0 -14
  635. package/dist/__tests__/worker-cap.test.d.ts.map +0 -1
  636. package/dist/__tests__/worker-cap.test.js +0 -97
  637. package/dist/__tests__/worker-cap.test.js.map +0 -1
  638. package/dist/__tests__/worktree-link-repair.test.d.ts +0 -2
  639. package/dist/__tests__/worktree-link-repair.test.d.ts.map +0 -1
  640. package/dist/__tests__/worktree-link-repair.test.js +0 -471
  641. package/dist/__tests__/worktree-link-repair.test.js.map +0 -1
  642. package/dist/__tests__/worktree-sync-fixture.test.d.ts +0 -17
  643. package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +0 -1
  644. package/dist/__tests__/worktree-sync-fixture.test.js +0 -519
  645. package/dist/__tests__/worktree-sync-fixture.test.js.map +0 -1
  646. package/dist/__tests__/worktree-sync-hardening.test.d.ts +0 -13
  647. package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +0 -1
  648. package/dist/__tests__/worktree-sync-hardening.test.js +0 -919
  649. package/dist/__tests__/worktree-sync-hardening.test.js.map +0 -1
  650. package/dist/__tests__/worktree-sync-shell-free.test.d.ts +0 -25
  651. package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +0 -1
  652. package/dist/__tests__/worktree-sync-shell-free.test.js +0 -185
  653. package/dist/__tests__/worktree-sync-shell-free.test.js.map +0 -1
  654. package/dist/__tests__/worktree.test.d.ts +0 -2
  655. package/dist/__tests__/worktree.test.d.ts.map +0 -1
  656. package/dist/__tests__/worktree.test.js +0 -168
  657. package/dist/__tests__/worktree.test.js.map +0 -1
  658. package/dist/lib/code-context-file.test.d.ts +0 -19
  659. package/dist/lib/code-context-file.test.d.ts.map +0 -1
  660. package/dist/lib/code-context-file.test.js +0 -202
  661. package/dist/lib/code-context-file.test.js.map +0 -1
  662. package/dist/lib/harness/console/announce.test.d.ts +0 -2
  663. package/dist/lib/harness/console/announce.test.d.ts.map +0 -1
  664. package/dist/lib/harness/console/announce.test.js +0 -104
  665. package/dist/lib/harness/console/announce.test.js.map +0 -1
  666. package/dist/lib/harness/console/by-session.test.d.ts +0 -2
  667. package/dist/lib/harness/console/by-session.test.d.ts.map +0 -1
  668. package/dist/lib/harness/console/by-session.test.js +0 -86
  669. package/dist/lib/harness/console/by-session.test.js.map +0 -1
  670. package/dist/lib/harness/console/console.test.d.ts +0 -2
  671. package/dist/lib/harness/console/console.test.d.ts.map +0 -1
  672. package/dist/lib/harness/console/console.test.js +0 -269
  673. package/dist/lib/harness/console/console.test.js.map +0 -1
  674. package/dist/lib/harness/console/decision-request.test.d.ts +0 -2
  675. package/dist/lib/harness/console/decision-request.test.d.ts.map +0 -1
  676. package/dist/lib/harness/console/decision-request.test.js +0 -75
  677. package/dist/lib/harness/console/decision-request.test.js.map +0 -1
  678. package/dist/lib/harness/console/rank.test.d.ts +0 -2
  679. package/dist/lib/harness/console/rank.test.d.ts.map +0 -1
  680. package/dist/lib/harness/console/rank.test.js +0 -124
  681. package/dist/lib/harness/console/rank.test.js.map +0 -1
  682. package/dist/lib/harness/console/render.test.d.ts +0 -2
  683. package/dist/lib/harness/console/render.test.d.ts.map +0 -1
  684. package/dist/lib/harness/console/render.test.js +0 -96
  685. package/dist/lib/harness/console/render.test.js.map +0 -1
  686. package/dist/lib/harness/console/replay-cli.test.d.ts +0 -2
  687. package/dist/lib/harness/console/replay-cli.test.d.ts.map +0 -1
  688. package/dist/lib/harness/console/replay-cli.test.js +0 -96
  689. package/dist/lib/harness/console/replay-cli.test.js.map +0 -1
  690. package/dist/lib/harness/console/replay.test.d.ts +0 -2
  691. package/dist/lib/harness/console/replay.test.d.ts.map +0 -1
  692. package/dist/lib/harness/console/replay.test.js +0 -81
  693. package/dist/lib/harness/console/replay.test.js.map +0 -1
  694. package/dist/lib/harness/console/turn-reader.test.d.ts +0 -2
  695. package/dist/lib/harness/console/turn-reader.test.d.ts.map +0 -1
  696. package/dist/lib/harness/console/turn-reader.test.js +0 -108
  697. package/dist/lib/harness/console/turn-reader.test.js.map +0 -1
  698. package/dist/lib/harness/credential.test.d.ts +0 -2
  699. package/dist/lib/harness/credential.test.d.ts.map +0 -1
  700. package/dist/lib/harness/credential.test.js +0 -74
  701. package/dist/lib/harness/credential.test.js.map +0 -1
  702. package/dist/lib/harness/evaluate.test.d.ts +0 -2
  703. package/dist/lib/harness/evaluate.test.d.ts.map +0 -1
  704. package/dist/lib/harness/evaluate.test.js +0 -621
  705. package/dist/lib/harness/evaluate.test.js.map +0 -1
  706. package/dist/lib/harness/gate.test.d.ts +0 -2
  707. package/dist/lib/harness/gate.test.d.ts.map +0 -1
  708. package/dist/lib/harness/gate.test.js +0 -111
  709. package/dist/lib/harness/gate.test.js.map +0 -1
  710. package/dist/lib/harness/self-check.test.d.ts +0 -2
  711. package/dist/lib/harness/self-check.test.d.ts.map +0 -1
  712. package/dist/lib/harness/self-check.test.js +0 -43
  713. package/dist/lib/harness/self-check.test.js.map +0 -1
  714. package/dist/lib/harness/transcript.test.d.ts +0 -2
  715. package/dist/lib/harness/transcript.test.d.ts.map +0 -1
  716. package/dist/lib/harness/transcript.test.js +0 -118
  717. package/dist/lib/harness/transcript.test.js.map +0 -1
  718. package/dist/lib/projects-registry.test.d.ts +0 -2
  719. package/dist/lib/projects-registry.test.d.ts.map +0 -1
  720. package/dist/lib/projects-registry.test.js +0 -176
  721. package/dist/lib/projects-registry.test.js.map +0 -1
  722. package/dist/lib/roster.test.d.ts +0 -15
  723. package/dist/lib/roster.test.d.ts.map +0 -1
  724. package/dist/lib/roster.test.js +0 -299
  725. package/dist/lib/roster.test.js.map +0 -1
  726. package/dist/lib/vault.test.d.ts +0 -17
  727. package/dist/lib/vault.test.d.ts.map +0 -1
  728. package/dist/lib/vault.test.js +0 -169
  729. package/dist/lib/vault.test.js.map +0 -1
  730. package/dist/lib/window-view.test.d.ts +0 -2
  731. package/dist/lib/window-view.test.d.ts.map +0 -1
  732. package/dist/lib/window-view.test.js +0 -168
  733. package/dist/lib/window-view.test.js.map +0 -1
  734. package/dist/standards/fail-loud-standard.md +0 -495
  735. package/dist/standards/known-issues-standard.md +0 -380
  736. package/dist/standards/rulings.md +0 -104
@@ -1,2253 +0,0 @@
1
- /**
2
- * The Codex artifact write path, under a filesystem that changes UNDER IT (#4875 round 6).
3
- *
4
- * ─── WHY THESE TESTS EXIST, AND WHY THEY ARE NOT IN THE OTHER FILE ────────────
5
- * Every other test of this write path observes a filesystem that holds still. The findings
6
- * this file covers are all of the form "the name was checked, and then the object behind
7
- * the name changed" — a TOCTOU race that the reviewer could only demonstrate
8
- * probabilistically, by running 40,000 deploys against a process swapping `.codex` for a
9
- * symlink to the main repo's `.codex` and counting how many landed there (4 fleet-wide
10
- * overwrites of `.codex/hooks.json`, all four reported by the deploy as WRITTEN).
11
- *
12
- * A test that reproduces a race by racing is a test that fails one run in a thousand and
13
- * proves nothing on the other 999. So the swap is performed DETERMINISTICALLY, from inside
14
- * the syscall the race has to beat: `fs` is mocked with a pass-through that calls a test
15
- * hook immediately before `openSync` and immediately after the content `writeFileSync`.
16
- * Every filesystem operation is real — the hook only decides WHEN the attacker moves.
17
- *
18
- * `vi.mock('fs')` rather than the `vi.spyOn(fs, …)` the review suggested: the `fs` ESM
19
- * namespace object is frozen, so `spyOn` fails with "Cannot redefine property". The mock
20
- * factory is the same instrument by another route, and it also gives the M8 assertion
21
- * below a complete record of every `unlinkSync` the deploy performed.
22
- */
23
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
24
- import { execFileSync } from 'child_process';
25
- import { join } from 'path';
26
- import { tmpdir } from 'os';
27
- const race = vi.hoisted(() => ({
28
- /** Runs immediately BEFORE a real `openSync`, with the path it is about to open. */
29
- beforeOpen: null,
30
- /** Runs immediately AFTER a real fd-based `writeFileSync`, with the temp path. */
31
- afterWrite: null,
32
- /** Runs immediately AFTER a real `renameSync`, with the DESTINATION path. */
33
- afterRename: null,
34
- /**
35
- * Runs immediately AFTER a real path-based `lstatSync`, with the path, the real result,
36
- * and whether the caller asked for `bigint` stats. Returning a value REPLACES the stat
37
- * the caller sees; throwing makes the `lstat` fail. This is the only instrument that can
38
- * put the filesystem into states a test cannot build with real syscalls — a directory on
39
- * a different DEVICE with the same inode number, and a directory that exists but cannot
40
- * be examined — both of which are fail-closed branches with no other way to reach them.
41
- */
42
- onLstat: null,
43
- /**
44
- * The path behind every descriptor the deploy read a whole file from. The deploy reads
45
- * by descriptor in two places — the roleguide, and the acceptance comparing the landed
46
- * artifact bytes — so this is how a test asks whether an attacker-influenced artifact was
47
- * read into memory in full (SF-4).
48
- */
49
- fdReads: [],
50
- /**
51
- * Runs immediately BEFORE a real fd-based `readFileSync`, with the path behind the
52
- * descriptor. Throwing makes the read fail — the only way to reach the acceptance's own
53
- * `catch`, which is a fail-CLOSED branch (round 9 SF-C completeness pass).
54
- */
55
- onFdRead: null,
56
- /** fd → the path it was opened on, so an fd-based read can be attributed. */
57
- fdPaths: new Map(),
58
- /**
59
- * Runs immediately BEFORE a real `closeSync`, with the path behind the descriptor.
60
- * Throwing makes the `close` fail — the only way to reach the write-back errors `close`
61
- * reports (ENOSPC, EDQUOT, EIO, ESTALE) without an exhausted or failing filesystem. The
62
- * descriptor is still closed for real afterwards, so a throwing hook leaks nothing.
63
- */
64
- onClose: null,
65
- /** Every path the deploy passed to `unlinkSync`, in order. */
66
- unlinked: [],
67
- /** Every path the deploy passed to `openSync`, in order. */
68
- opened: [],
69
- /**
70
- * ── THE CALLS THAT BOUND A DESCRIPTOR'S LIFETIME, IN ORDER (#4908) ───────────
71
- * `open`, `rename`, `lstat` and `close`, each recorded with the PATH behind it. #4908's
72
- * remediation is not another check — it is a LIFETIME: the temp file's descriptor is
73
- * held open across the rename and the install check so the kernel cannot recycle the
74
- * inode NUMBER the check compares. A lifetime has no verdict to assert, and the only
75
- * filesystem-independent way to observe one is the ORDER of the calls that bound it.
76
- */
77
- timeline: [],
78
- /** The last temp path opened — the write is fd-based, so it carries no path. */
79
- lastOpened: '',
80
- }));
81
- vi.mock('fs', async (importOriginal) => {
82
- const actual = await importOriginal();
83
- const patched = {
84
- ...actual,
85
- openSync: ((path, flags, mode) => {
86
- if (typeof path === 'string') {
87
- race.lastOpened = path;
88
- race.opened.push(path);
89
- race.beforeOpen?.(path);
90
- }
91
- const fd = actual.openSync(path, flags, mode);
92
- if (typeof path === 'string') {
93
- race.fdPaths.set(fd, path);
94
- race.timeline.push(`open ${path}`);
95
- }
96
- return fd;
97
- }),
98
- closeSync: ((fd) => {
99
- const path = race.fdPaths.get(fd);
100
- if (path !== undefined)
101
- race.timeline.push(`close ${path}`);
102
- if (path !== undefined && race.onClose) {
103
- // The real `close` still runs, whatever the hook decides — a kernel that reports a
104
- // write-back error from `close` has released the descriptor all the same, and a
105
- // test that skipped it would leak one per deploy.
106
- let failure;
107
- try {
108
- race.onClose(path);
109
- }
110
- catch (err) {
111
- failure = err;
112
- }
113
- const result = actual.closeSync(fd);
114
- if (failure !== undefined)
115
- throw failure;
116
- return result;
117
- }
118
- return actual.closeSync(fd);
119
- }),
120
- lstatSync: ((path, options) => {
121
- const real = actual.lstatSync(path, options);
122
- if (typeof path === 'string')
123
- race.timeline.push(`lstat ${path}`);
124
- if (typeof path === 'string' && race.onLstat) {
125
- const bigint = Boolean(options?.bigint);
126
- const replaced = race.onLstat(path, real, bigint);
127
- if (replaced !== undefined)
128
- return replaced;
129
- }
130
- return real;
131
- }),
132
- renameSync: ((from, to) => {
133
- const result = actual.renameSync(from, to);
134
- if (typeof to === 'string')
135
- race.timeline.push(`rename ${to}`);
136
- if (typeof to === 'string')
137
- race.afterRename?.(to);
138
- return result;
139
- }),
140
- writeFileSync: ((file, data, options) => {
141
- const opened = race.lastOpened;
142
- const result = actual.writeFileSync(file, data, options);
143
- if (typeof file === 'number')
144
- race.afterWrite?.(opened);
145
- return result;
146
- }),
147
- readFileSync: ((file, options) => {
148
- if (typeof file === 'number') {
149
- const path = race.fdPaths.get(file) ?? `fd:${file}`;
150
- race.fdReads.push(path);
151
- race.onFdRead?.(path);
152
- }
153
- return actual.readFileSync(file, options);
154
- }),
155
- unlinkSync: ((path) => {
156
- race.unlinked.push(String(path));
157
- return actual.unlinkSync(path);
158
- }),
159
- };
160
- return { ...patched, default: patched };
161
- });
162
- const { chmodSync, closeSync, constants: fsConstants, existsSync, linkSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, renameSync, rmSync, symlinkSync, unlinkSync, writeFileSync, writeSync, } = await import('fs');
163
- const { deployCodexConfigOnly, resolveCodexDeployTarget } = await import('../commands/codex-deploy-config.js');
164
- const { BEHAVIORAL_END_MARKER, BEHAVIORAL_START_MARKER } = await import('../lib/behavioral-injection.js');
165
- const { AGENTS_OVERRIDE_FILENAME, CODEX_CONFIG_FILENAME, CODEX_HOOKS_FILENAME } = await import('../lib/runtime/codex-config.js');
166
- const TEAM = 'demo';
167
- /**
168
- * A real stat with some members replaced — the `onLstat` instrument's only way to build the
169
- * states real syscalls cannot build inside one deploy. Everything not named in `patch`
170
- * answers exactly as the kernel answered, including the type predicates, which are bound
171
- * back to the real stat because they read its private mode field.
172
- */
173
- const statReporting = (real, patch) => new Proxy(real, {
174
- get(target, prop, receiver) {
175
- if (typeof prop === 'string' && prop in patch)
176
- return patch[prop];
177
- const value = Reflect.get(target, prop, receiver);
178
- return typeof value === 'function'
179
- ? value.bind(target)
180
- : value;
181
- },
182
- });
183
- let root;
184
- let worktree;
185
- /** Stands in for the MAIN REPO — the destination every one of these attacks aims at. */
186
- let mainCodex;
187
- const MAIN_HOOKS_SENTINEL = '{"MAIN_REPO":"do-not-touch"}';
188
- const MAIN_OVERRIDE_SENTINEL = '# MAIN override — do-not-touch\n';
189
- beforeEach(() => {
190
- race.beforeOpen = null;
191
- race.afterWrite = null;
192
- race.afterRename = null;
193
- race.onLstat = null;
194
- race.onFdRead = null;
195
- race.onClose = null;
196
- race.unlinked = [];
197
- race.opened = [];
198
- race.timeline = [];
199
- race.fdReads = [];
200
- race.fdPaths = new Map();
201
- race.lastOpened = '';
202
- root = mkdtempSync(join(tmpdir(), 'mx-race-root-'));
203
- worktree = join(root, '.worktrees', `${TEAM}-20260101`);
204
- mkdirSync(worktree, { recursive: true });
205
- const teams = join(root, 'mx-agent-system', 'teams');
206
- mkdirSync(teams, { recursive: true });
207
- writeFileSync(join(teams, `${TEAM}.md`), `# Team: ${TEAM}\n\nDisplay name: ${TEAM}\nRoleguide: \`mx-agent-system/roleguides/${TEAM}-leader.md\`\n\n## Named Memories (Source of Truth)\n\n- \`memnexus-${TEAM}-leader-state\`\n`);
208
- const roleguides = join(root, 'mx-agent-system', 'roleguides');
209
- mkdirSync(roleguides, { recursive: true });
210
- writeFileSync(join(roleguides, `${TEAM}-leader.md`), `# ${TEAM} leader\n\n${BEHAVIORAL_START_MARKER}\n## Checks\n\n- Do the thing.\n${BEHAVIORAL_END_MARKER}\n`);
211
- // The main repo's fleet-wide files, with sentinels: under OpenAI bug #27133 the main
212
- // repo's .codex/hooks.json governs every Codex session in the fleet, and its
213
- // AGENTS.override.md REPLACES AGENTS.md for every main-repo session.
214
- mainCodex = join(root, '.codex');
215
- mkdirSync(mainCodex, { recursive: true });
216
- writeFileSync(join(mainCodex, 'hooks.json'), MAIN_HOOKS_SENTINEL);
217
- writeFileSync(join(root, AGENTS_OVERRIDE_FILENAME), MAIN_OVERRIDE_SENTINEL);
218
- });
219
- afterEach(() => {
220
- race.beforeOpen = null;
221
- race.afterWrite = null;
222
- race.afterRename = null;
223
- race.onLstat = null;
224
- race.onFdRead = null;
225
- race.onClose = null;
226
- rmSync(root, { recursive: true, force: true });
227
- });
228
- const deploy = () => {
229
- const resolved = resolveCodexDeployTarget({ projectRoot: root, path: worktree, team: TEAM });
230
- if ('error' in resolved)
231
- throw new Error(`unexpected refusal: ${resolved.error}`);
232
- return deployCodexConfigOnly(resolved.target);
233
- };
234
- /** Replace `<worktree>/.codex` with a symlink to the MAIN repo's `.codex`. */
235
- function swapCodexDirForASymlinkToMainRepo() {
236
- const real = join(worktree, '.codex');
237
- renameSync(real, `${real}.real`);
238
- symlinkSync(mainCodex, real);
239
- }
240
- function restoreCodexDir() {
241
- const real = join(worktree, '.codex');
242
- if (lstatSync(real).isSymbolicLink())
243
- unlinkSync(real);
244
- renameSync(`${real}.real`, real);
245
- }
246
- const mainRepoTemps = () => readdirSync(mainCodex).filter((entry) => entry.includes('.mx-tmp-'));
247
- /**
248
- * ─────────────────────── THE MUST FIX (round 6) ───────────────────────────────
249
- * `containedWriteRefusal` walks NAMES. Write-aside-and-rename widened the gap between that
250
- * walk and the install from two syscalls to seven — lstat, the second containment walk,
251
- * open, fstat, fchmod, the entire content write, rename — and a directory symlink planted
252
- * inside that gap sent the temp file, and then the deploy's own `renameSync`, into the main
253
- * repo. Measured at 40,000 deploys per build under identical swapper pressure: predecessor
254
- * 5 window hits / 0 main-repo overwrites; this build 135 hits / 4 overwrites, all four
255
- * reported as WRITTEN, plus 33 `.mx-tmp-*` files left inside the main repo.
256
- *
257
- * (Label correction, #4897: the "predecessor" arm was originally labelled as commit
258
- * `85fe36faf`; the round-7 reviewer rebuilt both arms from source and found that arm was a
259
- * hand-made hybrid rather than that commit. Re-measured against the real commit, the
260
- * conclusion was unchanged.)
261
- *
262
- * The remediation identifies the parent directory by `{dev, ino}` before the open and
263
- * re-checks it twice. Both checks are exercised below, at the two points the swap can land.
264
- */
265
- describe('write path — the parent directory is identified, not just named', () => {
266
- it('a directory swapped between the containment check and the open writes NOTHING into the swapped directory', () => {
267
- expect(deploy().ok).toBe(true);
268
- let bytesWrittenIntoTheSwappedDirectory = false;
269
- race.beforeOpen = (path) => {
270
- if (!path.includes('hooks.json.mx-tmp-'))
271
- return;
272
- race.beforeOpen = null;
273
- swapCodexDirForASymlinkToMainRepo();
274
- };
275
- race.afterWrite = (tmpPath) => {
276
- if (tmpPath.includes('hooks.json.mx-tmp-'))
277
- bytesWrittenIntoTheSwappedDirectory = true;
278
- };
279
- const outcome = deploy();
280
- // NOT ONE BYTE. This is the whole point of checking with the temp open and empty
281
- // rather than only before the rename: the later check would refuse the INSTALL, but
282
- // the 4983-byte hooks file would already have been written inside the main repo.
283
- expect(bytesWrittenIntoTheSwappedDirectory).toBe(false);
284
- expect(outcome.ok).toBe(false);
285
- expect(outcome.writeRefusals.join('\n')).toContain('was REPLACED');
286
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
287
- // The main repo is untouched: its sentinel survives, no worktree hooks file was
288
- // installed over it, and no temp file was left behind inside it. Pre-fix, the deploy
289
- // wrote the full worktree hooks.json here and reported it as written.
290
- expect(readFileSync(join(mainCodex, 'hooks.json'), 'utf-8')).toBe(MAIN_HOOKS_SENTINEL);
291
- expect(mainRepoTemps()).toEqual([]);
292
- });
293
- it('a directory swapped after the content is written is refused BEFORE the rename installs it', () => {
294
- expect(deploy().ok).toBe(true);
295
- race.afterWrite = (tmpPath) => {
296
- if (!tmpPath.includes('hooks.json.mx-tmp-'))
297
- return;
298
- race.afterWrite = null;
299
- swapCodexDirForASymlinkToMainRepo();
300
- };
301
- const outcome = deploy();
302
- expect(outcome.ok).toBe(false);
303
- expect(outcome.writeRefusals.join('\n')).toContain('was REPLACED');
304
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
305
- expect(readFileSync(join(mainCodex, 'hooks.json'), 'utf-8')).toBe(MAIN_HOOKS_SENTINEL);
306
- expect(mainRepoTemps()).toEqual([]);
307
- // The worktree's own previously deployed artifact is intact — this refusal costs the
308
- // redeploy, not the file.
309
- restoreCodexDir();
310
- expect(readFileSync(join(worktree, CODEX_HOOKS_FILENAME), 'utf-8')).toContain('PreToolUse');
311
- });
312
- it('the refusal names both directory identities, so an operator can see WHICH directory answered', () => {
313
- expect(deploy().ok).toBe(true);
314
- race.beforeOpen = (path) => {
315
- if (!path.includes('hooks.json.mx-tmp-'))
316
- return;
317
- race.beforeOpen = null;
318
- swapCodexDirForASymlinkToMainRepo();
319
- };
320
- const refusal = deploy().writeRefusals.join('\n');
321
- expect(refusal).toMatch(/device \d+\/inode \d+ when containment passed/);
322
- expect(refusal).toContain('a SYMLINK, which resolves wherever its target points');
323
- expect(refusal).toContain('Nothing was installed.');
324
- });
325
- it('an undisturbed deploy still writes all three artifacts', () => {
326
- const outcome = deploy();
327
- expect(outcome.ok).toBe(true);
328
- expect(outcome.written.sort()).toEqual([AGENTS_OVERRIDE_FILENAME, CODEX_CONFIG_FILENAME, CODEX_HOOKS_FILENAME].sort());
329
- expect(outcome.writeRefusals).toEqual([]);
330
- expect(outcome.writeFailures).toEqual([]);
331
- });
332
- });
333
- /**
334
- * ───────────────── SF-M (round 7): THE FAIL-CLOSED BRANCHES, PINNED ───────────
335
- * The round-7 reviewer ran seven mutants past the eight the implementer ran, and three
336
- * survived with the whole suite green. The shipped code is CORRECT in all three — nothing
337
- * below changes it. What was missing was an assertion that would notice if a later edit
338
- * broke one, and one of the three (RV-2) is a single line away from turning a refusal into
339
- * a write into the main repo:
340
- *
341
- * RV-1 `assertSameDirectory` compares `ino` and ignores `dev` — two directories on
342
- * different filesystems that happen to share an inode number compare EQUAL.
343
- * RV-2 `assertSameDirectory`'s `catch` RETURNS instead of throwing — the directory that
344
- * cannot be examined goes from fail-CLOSED to fail-OPEN.
345
- * RV-3 `directoryIdentity` accepts a symlinked parent at capture — the identity then
346
- * describes the LINK, both later checks agree with it, and every byte plus the
347
- * install lands wherever the link points.
348
- *
349
- * Two of the three cannot be built out of real syscalls in a unit test: nothing a test can
350
- * do gives one name the same inode number on two devices, and a directory that exists but
351
- * cannot be `lstat`ed needs a permission change that would break the rename too, which
352
- * would hide the fail-open. So `lstatSync` is instrumented the same way `openSync` already
353
- * is — a real call whose result the test may replace or make fail, at a moment the test
354
- * chooses. The filesystem stays real everywhere else, including for the containment walk,
355
- * which takes NON-bigint stats and so is never touched by the hooks below.
356
- */
357
- describe('write path — the directory-identity comparison itself (SF-M mutation pins)', () => {
358
- /** The same stat, reporting a different DEVICE. `dev` is a bigint under `bigint: true`. */
359
- const onAnotherDevice = (real) => new Proxy(real, {
360
- get(target, prop, receiver) {
361
- if (prop === 'dev')
362
- return Reflect.get(target, prop) + 1n;
363
- const value = Reflect.get(target, prop, receiver);
364
- return typeof value === 'function'
365
- ? value.bind(target)
366
- : value;
367
- },
368
- });
369
- /**
370
- * The same stat, of the same device and inode number, reporting that it is NOT a
371
- * directory — what an inode number reused by a non-directory looks like to `lstat`.
372
- */
373
- const notADirectory = (real) => statReporting(real, { isDirectory: () => false });
374
- const worktreeCodexDir = () => join(worktree, '.codex');
375
- it('RV-1: a parent with the SAME inode number on a DIFFERENT DEVICE is refused', () => {
376
- expect(deploy().ok).toBe(true);
377
- race.beforeOpen = (path) => {
378
- if (!path.includes('hooks.json.mx-tmp-'))
379
- return;
380
- race.beforeOpen = null;
381
- // The identity was captured one syscall ago. From here the name answers with the
382
- // same inode number on another device — a different directory by every measure
383
- // except the one a `ino`-only comparison makes.
384
- race.onLstat = (p, real, bigint) => p === worktreeCodexDir() && bigint ? onAnotherDevice(real) : undefined;
385
- };
386
- const outcome = deploy();
387
- race.onLstat = null;
388
- expect(outcome.ok).toBe(false);
389
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
390
- const refusal = outcome.writeRefusals.join('\n');
391
- expect(refusal).toContain('was REPLACED');
392
- // The pin: the two identities differ ONLY in `dev`, so a comparison that reads `ino`
393
- // alone calls them the same directory and writes.
394
- const identities = /device (\d+)\/inode (\d+) when containment passed, and is now device (\d+)\/inode (\d+)/.exec(refusal);
395
- expect(identities).not.toBeNull();
396
- const [, expectedDev, expectedIno, observedDev, observedIno] = identities;
397
- expect(observedIno).toBe(expectedIno);
398
- expect(observedDev).not.toBe(expectedDev);
399
- });
400
- it('RV-2: a parent that cannot be EXAMINED is refused, never written into', () => {
401
- expect(deploy().ok).toBe(true);
402
- const hooks = join(worktree, CODEX_HOOKS_FILENAME);
403
- const installedInode = lstatSync(hooks).ino;
404
- race.beforeOpen = (path) => {
405
- if (!path.includes('hooks.json.mx-tmp-'))
406
- return;
407
- race.beforeOpen = null;
408
- race.onLstat = (p, _real, bigint) => {
409
- if (p !== worktreeCodexDir() || !bigint)
410
- return undefined;
411
- const err = new Error(`EACCES: permission denied, lstat '${p}'`);
412
- err.code = 'EACCES';
413
- throw err;
414
- };
415
- };
416
- const outcome = deploy();
417
- race.onLstat = null;
418
- // Fail-CLOSED: a refusal, and the artifact on disk is the one the previous deploy
419
- // installed — same inode, so nothing was renamed over it. Under the mutant this
420
- // deploy completes, reports ok, and the inode changes.
421
- expect(outcome.ok).toBe(false);
422
- const refusal = outcome.writeRefusals.join('\n');
423
- expect(refusal).toContain('unexaminable');
424
- expect(refusal).toContain('EACCES');
425
- expect(refusal).toContain('Nothing was installed.');
426
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
427
- expect(lstatSync(hooks).ino).toBe(installedInode);
428
- });
429
- /**
430
- * ── RV-4 (round 9 SF-A): THE TYPE CLAUSE IN `assertSameDirectory` ────────────
431
- * `st.isDirectory()` in `assertSameDirectory` was unpinned — removing it left all 38
432
- * tests green. RV-3 pins the equivalent clause in `directoryIdentity`, at CAPTURE time;
433
- * this is the clause that runs at every RE-CHECK, and it is the last thing standing in
434
- * the same inode-reuse class the round-9 MUST FIX turns on: an inode NUMBER is not a
435
- * durable identity, so a directory that is removed and replaced by a non-directory
436
- * taking its number compares EQUAL on `{dev, ino}`.
437
- *
438
- * That state cannot be built with real syscalls inside one deploy — the same reason RV-1
439
- * and RV-2 use the instrument — so the parent's re-check `lstat` answers with its own
440
- * real device and inode number and `isDirectory() → false`, which is exactly what the
441
- * reused number would produce.
442
- */
443
- it('RV-4: a parent with a MATCHING dev/ino that is no longer a DIRECTORY is refused', () => {
444
- expect(deploy().ok).toBe(true);
445
- let fired = false;
446
- race.beforeOpen = (path) => {
447
- if (!path.includes('hooks.json.mx-tmp-'))
448
- return;
449
- race.beforeOpen = null;
450
- race.onLstat = (p, real, bigint) => {
451
- if (fired || p !== worktreeCodexDir() || !bigint)
452
- return undefined;
453
- fired = true;
454
- return notADirectory(real);
455
- };
456
- };
457
- const outcome = deploy();
458
- race.onLstat = null;
459
- expect(fired).toBe(true);
460
- expect(outcome.ok).toBe(false);
461
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
462
- const refusal = outcome.writeRefusals.join('\n');
463
- expect(refusal).toContain('was REPLACED');
464
- // The pin: dev and ino are UNCHANGED, so a comparison that stops at `{dev, ino}` calls
465
- // this the same directory and writes into it. Only the type clause refuses it.
466
- expect(refusal).toContain('not a directory at all');
467
- const identities = /device (\d+)\/inode (\d+) when containment passed, and is now not a directory at all/.exec(refusal);
468
- expect(identities).not.toBeNull();
469
- const [, expectedDev, expectedIno] = identities;
470
- const real = lstatSync(worktreeCodexDir(), { bigint: true });
471
- expect(expectedDev).toBe(String(real.dev));
472
- expect(expectedIno).toBe(String(real.ino));
473
- });
474
- it('RV-3: a parent that became a SYMLINK before its identity was captured opens nothing inside it', () => {
475
- expect(deploy().ok).toBe(true);
476
- let swapped = false;
477
- race.onLstat = (p, _real, bigint) => {
478
- if (swapped || p !== worktreeCodexDir() || !bigint)
479
- return undefined;
480
- // The first bigint `lstat` of the parent IS the identity capture — the containment
481
- // walk takes non-bigint stats. Swap underneath it, so what it identifies is a
482
- // symlink to the main repo's `.codex`, and let it take its own stat of the result.
483
- swapped = true;
484
- race.opened = [];
485
- swapCodexDirForASymlinkToMainRepo();
486
- return lstatSync(p, { bigint: true });
487
- };
488
- const outcome = deploy();
489
- race.onLstat = null;
490
- restoreCodexDir();
491
- expect(swapped).toBe(true);
492
- expect(outcome.ok).toBe(false);
493
- expect(outcome.writeRefusals.join('\n')).toContain('it is not a real directory');
494
- // The pin: capture refuses BEFORE the open, so not one temp file is created inside the
495
- // link's destination. Accept the symlink at capture and the identity describes the
496
- // LINK, both later checks agree with it, and the bytes — and the install — land in the
497
- // main repo.
498
- expect(race.opened.filter((path) => path.includes('.mx-tmp-') && path.startsWith(`${worktreeCodexDir()}/`))).toEqual([]);
499
- expect(mainRepoTemps()).toEqual([]);
500
- expect(readFileSync(join(mainCodex, 'hooks.json'), 'utf-8')).toBe(MAIN_HOOKS_SENTINEL);
501
- });
502
- /**
503
- * ── ROUND 11 MAJOR D: THE TYPE CLAUSE AT CAPTURE, WHICH RV-3 DOES NOT PIN ────
504
- * `directoryIdentity` refuses on two clauses — `!st.isDirectory()` and
505
- * `st.isSymbolicLink()` — and only the second had a test. RV-3 above swaps in a SYMLINK,
506
- * which the symlink clause catches on its own, so removing `!st.isDirectory()` left the
507
- * whole suite green. RV-4 pins the same question at RE-CHECK time; this is CAPTURE time,
508
- * where the consequence is worse: the identity the whole write path is then anchored to
509
- * is the identity of an object that is not a directory, and every later check agrees with
510
- * it, so the deploy runs to completion and reports success.
511
- *
512
- * The object is a non-directory that is ALSO not a symlink — a FIFO, a regular file or a
513
- * socket swapped in at capture time — because anything a symlink can do is already
514
- * refused. Reachable with real syscalls by the same rmdir-and-fast-recreate race RP14
515
- * demonstrates against a file; built here with the instrument, so the pin is
516
- * deterministic and does not depend on winning an allocator race.
517
- *
518
- * Removing `st.isSymbolicLink()` INSTEAD also leaves the suite green, and that one is an
519
- * EQUIVALENT mutant, not a gap: `lstat` on a symlink never reports `isDirectory() === true`,
520
- * so the type clause already covers every case the symlink clause covers. It is listed
521
- * here so it is not miscounted as a survivor next round.
522
- */
523
- it('RV-5: a parent that is NOT A DIRECTORY and not a symlink is refused at CAPTURE, before anything is opened', () => {
524
- expect(deploy().ok).toBe(true);
525
- let fired = false;
526
- race.opened = [];
527
- race.onLstat = (p, real, bigint) => {
528
- // The first bigint `lstat` of the parent IS the identity capture — the containment
529
- // walk takes non-bigint stats.
530
- if (fired || p !== worktreeCodexDir() || !bigint)
531
- return undefined;
532
- fired = true;
533
- return notADirectory(real);
534
- };
535
- const outcome = deploy();
536
- race.onLstat = null;
537
- expect(fired).toBe(true);
538
- expect(outcome.ok).toBe(false);
539
- const refusal = outcome.writeRefusals.join('\n');
540
- // The poisoned capture is the first one of this deploy, which is `config.toml`; the two
541
- // later artifacts take their own captures and are unaffected.
542
- expect(refusal).toContain('it is not a real directory');
543
- expect(outcome.written).not.toContain(CODEX_CONFIG_FILENAME);
544
- // The pin, in two halves. First: the object is not a SYMLINK, so the symlink clause
545
- // cannot be what refused it — only the type clause can.
546
- expect(lstatSync(worktreeCodexDir()).isSymbolicLink()).toBe(false);
547
- // Second: capture refuses BEFORE the open, so that artifact's temp file is never
548
- // created at all. Accept a non-directory here and the identity is captured from it,
549
- // both later re-checks compare equal to it, and the deploy writes and reports success
550
- // against a parent it never validated.
551
- expect(race.opened.filter((path) => path.includes(`${CODEX_CONFIG_FILENAME}.mx-tmp-`))).toEqual([]);
552
- });
553
- });
554
- /**
555
- * ── ROUND 11 MAJOR D: THE TEMP FILE'S OWN LINK COUNT ─────────────────────────
556
- * Immediately after creating the temp file with `O_EXCL`, the write path `fstat`s its own
557
- * descriptor and refuses if the link count is anything but 1. The code calls this defence
558
- * in depth and its comment says it "should be unreachable", which is very likely right —
559
- * `O_EXCL` creates a name that did not exist, so nothing can already be pointing at it.
560
- *
561
- * It was not counted either way in round 10's "19 mutants, 1 survivor" tally, and it does
562
- * survive removal. It is pinned here rather than disclosed as an exception, because it is
563
- * cheap to pin and "should be unreachable" is precisely the reasoning this file has had to
564
- * retract three times: the round-8 disclosure said `!open.isFile()` could not be the sole
565
- * cause of a rejection, and RP14 disproved it.
566
- *
567
- * A second name is created against the temp file in the window between the `open` and the
568
- * `fstat` — real `link(2)`, no forged stat — so the descriptor genuinely reports 2. What
569
- * the check is protecting is real: with it removed the deploy writes the content, renames,
570
- * and reports success, while a second name to that inode is held outside the artifact path.
571
- */
572
- describe('write path — the temp file this deploy created has exactly ONE name', () => {
573
- it('a second name created against the temp file between the open and the fstat is refused', () => {
574
- expect(deploy().ok).toBe(true);
575
- const secondName = join(worktree, 'temp-second-name.md');
576
- let tmpPath = '';
577
- let linked = false;
578
- let nlinkAtFstat = 0n;
579
- race.beforeOpen = (path) => {
580
- if (!path.includes('hooks.json.mx-tmp-'))
581
- return;
582
- race.beforeOpen = null;
583
- tmpPath = path;
584
- // Fires at the identity re-check that runs immediately after the open and before the
585
- // `fstat` — the one window in which the temp file exists and has not yet been
586
- // measured. The stat itself is left untouched.
587
- race.onLstat = (p, _real, bigint) => {
588
- if (linked || p !== join(worktree, '.codex') || !bigint)
589
- return undefined;
590
- linked = true;
591
- linkSync(tmpPath, secondName);
592
- // Measured HERE, not at the end of the test: the refusal path unlinks the temp
593
- // file, which drops the count back to 1 before any assertion could see it.
594
- nlinkAtFstat = lstatSync(tmpPath, { bigint: true }).nlink;
595
- return undefined;
596
- };
597
- };
598
- const outcome = deploy();
599
- race.onLstat = null;
600
- expect(linked).toBe(true);
601
- // The precondition, measured: the second name really is a second name for the very
602
- // inode the deploy just created, so the descriptor's link count is genuinely 2 — no
603
- // forged stat is involved, this is what `fstat` on the deploy's own fd returns.
604
- expect(nlinkAtFstat).toBe(2n);
605
- expect(outcome.ok).toBe(false);
606
- const refusal = outcome.writeRefusals.join('\n');
607
- expect(refusal).toContain('the temporary file this deploy just created');
608
- expect(refusal).toContain('already has 2 names');
609
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
610
- unlinkSync(secondName);
611
- });
612
- });
613
- /**
614
- * ─────────────────────────── SF-I (round 5) ───────────────────────────────────
615
- * The other way to lose this race has nothing to do with the parent directory: the TEMP
616
- * PATH is unlinked and replaced — with a symlink, or with a hardlink to a main-repo file —
617
- * between the write and the rename. `rename` does not follow symlinks, so the deploy's own
618
- * `renameSync` installs the attacker's entry at the artifact path. The reviewer executed
619
- * it at 3000 deploys per mode: 29 symlinks and 37 hardlinks installed, and all 66 reported
620
- * `ok = true` with the artifact listed as WRITTEN.
621
- *
622
- * No privilege boundary is crossed — the bytes went to the fd's own inode — but the deploy
623
- * asserted success over an artifact it did not install. The remediation verifies the
624
- * install: what is at the path afterwards must be the very inode this call wrote.
625
- */
626
- describe('write path — the install is verified, so a substituted artifact is not reported as written', () => {
627
- const substituteTempWith = (kind, target) => (tmpPath) => {
628
- if (!tmpPath.includes(`${AGENTS_OVERRIDE_FILENAME}.mx-tmp-`))
629
- return;
630
- race.afterWrite = null;
631
- unlinkSync(tmpPath);
632
- if (kind === 'symlink')
633
- symlinkSync(target, tmpPath);
634
- else
635
- linkSync(target, tmpPath);
636
- };
637
- it('a temp path substituted with a SYMLINK is a failed write, not a written artifact', () => {
638
- race.afterWrite = substituteTempWith('symlink', join(root, AGENTS_OVERRIDE_FILENAME));
639
- const outcome = deploy();
640
- expect(outcome.ok).toBe(false);
641
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
642
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
643
- expect(outcome.writeFailures.join('\n')).toContain('SYMLINK');
644
- // The bytes went to the fd, never through the link: the main repo is unchanged.
645
- expect(readFileSync(join(root, AGENTS_OVERRIDE_FILENAME), 'utf-8')).toBe(MAIN_OVERRIDE_SENTINEL);
646
- });
647
- it('a temp path substituted with a HARDLINK to a main-repo file is a failed write too', () => {
648
- race.afterWrite = substituteTempWith('hardlink', join(root, AGENTS_OVERRIDE_FILENAME));
649
- const outcome = deploy();
650
- expect(outcome.ok).toBe(false);
651
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
652
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
653
- expect(readFileSync(join(root, AGENTS_OVERRIDE_FILENAME), 'utf-8')).toBe(MAIN_OVERRIDE_SENTINEL);
654
- });
655
- it('the substituted entry is left in place, and the NEXT deploy refuses it on containment', () => {
656
- race.afterWrite = substituteTempWith('symlink', join(root, AGENTS_OVERRIDE_FILENAME));
657
- expect(deploy().ok).toBe(false);
658
- expect(lstatSync(join(worktree, AGENTS_OVERRIDE_FILENAME)).isSymbolicLink()).toBe(true);
659
- // Fails closed rather than quietly writing through the link a previous deploy installed.
660
- const next = deploy();
661
- expect(next.ok).toBe(false);
662
- expect(next.writeRefusals.join('\n')).toContain('SYMLINK');
663
- expect(readFileSync(join(root, AGENTS_OVERRIDE_FILENAME), 'utf-8')).toBe(MAIN_OVERRIDE_SENTINEL);
664
- });
665
- it('the mixed-state report MEASURES the substituted artifact instead of claiming it was written', () => {
666
- race.afterWrite = substituteTempWith('symlink', join(root, AGENTS_OVERRIDE_FILENAME));
667
- const text = deploy()
668
- .lines.map((l) => l.text)
669
- .join('\n');
670
- expect(text).toContain('PARTIAL DEPLOY');
671
- expect(text).toContain('must not be launched');
672
- expect(text).toMatch(/AGENTS\.override\.md: a SYMLINK, not a file/);
673
- });
674
- });
675
- /**
676
- * ────────────── SF-L (round 7): THE ONE BENIGN CAUSE OF A DIFFERENT INODE ─────
677
- * The install check above compares inodes, and there is exactly one way for that to fail
678
- * with nothing wrong: a second LEGITIMATE deploy renames its own byte-identical artifact
679
- * into the same path between this deploy's `renameSync` and its verifying `lstat`. The
680
- * file on disk is correct and the deploy called it a failed write — and since #4896 made
681
- * a failed write refuse the launch, `mx-agent start` then exits 1. Concurrent deploys are
682
- * the scenario the rename design exists to make safe, so a false alarm there is the one
683
- * worth removing.
684
- *
685
- * A different inode is now accepted only when what landed is indistinguishable from this
686
- * deploy's own output: a regular file, ONE name, identical bytes. The two malicious
687
- * substitutions are unchanged, and the last two tests here are the proof — a symlink fails
688
- * `isFile()` and a hardlink fails `nlink === 1` even when its content matches exactly.
689
- *
690
- * The instrument is the same one the rest of the file uses: `renameSync` calls a test hook
691
- * with the destination immediately after the real rename, which is precisely the window
692
- * the race occupies.
693
- */
694
- describe('write path — a concurrent IDENTICAL redeploy is not reported as a failure (SF-L)', () => {
695
- const override = () => join(worktree, AGENTS_OVERRIDE_FILENAME);
696
- /**
697
- * What a second honest deploy does: land its own copy of the same bytes, atomically, at
698
- * the mode `modeForInstalledArtifact` computes. The `chmod` is not decoration — a real
699
- * deploy `fchmod`s the temp file before the rename, and the acceptance compares the mode
700
- * (SF-2), so a helper that left it to the ambient umask would be testing the umask.
701
- */
702
- const landAnotherFileAt = (destination, bytes, mode = 0o644) => {
703
- const staged = `${destination}.another-deploy`;
704
- writeFileSync(staged, bytes);
705
- chmodSync(staged, mode);
706
- renameSync(staged, destination);
707
- };
708
- it('a second deploy landing IDENTICAL bytes between the rename and the check is a SUCCESS', () => {
709
- let concurrentInode = 0n;
710
- race.afterRename = (destination) => {
711
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
712
- return;
713
- race.afterRename = null;
714
- landAnotherFileAt(destination, readFileSync(destination));
715
- concurrentInode = lstatSync(destination, { bigint: true }).ino;
716
- };
717
- const outcome = deploy();
718
- // The inode at the path is NOT the one this deploy installed — and the deploy still
719
- // reports the artifact as written, because the bytes are its own output.
720
- expect(lstatSync(override(), { bigint: true }).ino).toBe(concurrentInode);
721
- expect(outcome.ok).toBe(true);
722
- expect(outcome.written).toContain(AGENTS_OVERRIDE_FILENAME);
723
- expect(outcome.writeFailures).toEqual([]);
724
- expect(outcome.writeRefusals).toEqual([]);
725
- });
726
- it('the launch is not aborted by that race', async () => {
727
- race.afterRename = (destination) => {
728
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
729
- return;
730
- race.afterRename = null;
731
- landAnotherFileAt(destination, readFileSync(destination));
732
- };
733
- const { CodexAdapter } = await import('../lib/runtime/codex-adapter.js');
734
- const codex = new CodexAdapter({ projectRoot: root });
735
- expect(() => codex.deployConfig({
736
- worktreePath: worktree,
737
- worktreeName: `${TEAM}-20260101`,
738
- branch: 'demo-branch',
739
- slot: 0,
740
- teamName: TEAM,
741
- baseBranch: 'main',
742
- initialPrompt: 'x',
743
- })).not.toThrow();
744
- });
745
- it('a file with DIFFERENT bytes landing in that window is still a failed write', () => {
746
- race.afterRename = (destination) => {
747
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
748
- return;
749
- race.afterRename = null;
750
- landAnotherFileAt(destination, '# not what this deploy generated\n');
751
- };
752
- const outcome = deploy();
753
- expect(outcome.ok).toBe(false);
754
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
755
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
756
- });
757
- /**
758
- * ── SF-4 (round 8): A FILE OF THE WRONG SIZE IS NEVER READ ──────────────────
759
- * The acceptance ends in `readFileSync(fd)`, which allocates the WHOLE landed file, and
760
- * the landed file is attacker-influenced by construction. A size pre-check makes the
761
- * wrong-sized case cost one `lstat` field instead of a full read. The outcome is
762
- * identical either way, so the assertion is on the READ, not on the verdict.
763
- */
764
- it('a file of the wrong SIZE is rejected without being read into memory', () => {
765
- race.afterRename = (destination) => {
766
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
767
- return;
768
- race.afterRename = null;
769
- landAnotherFileAt(destination, '# not what this deploy generated\n');
770
- };
771
- race.fdReads = [];
772
- const outcome = deploy();
773
- expect(outcome.ok).toBe(false);
774
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
775
- expect(race.fdReads.filter((p) => p.endsWith(AGENTS_OVERRIDE_FILENAME))).toEqual([]);
776
- });
777
- it('a file of the RIGHT size is still read and compared, so the pre-check is not the verdict', () => {
778
- race.afterRename = (destination) => {
779
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
780
- return;
781
- race.afterRename = null;
782
- landAnotherFileAt(destination, readFileSync(destination));
783
- };
784
- race.fdReads = [];
785
- expect(deploy().ok).toBe(true);
786
- expect(race.fdReads.filter((p) => p.endsWith(AGENTS_OVERRIDE_FILENAME))).toEqual([override()]);
787
- });
788
- /**
789
- * ── ROUND 11 MUST FIX A: THE BYTE COMPARISON ITSELF WAS UNPINNED ────────────
790
- * `landedIsThisDeploysOwnContent` ends in `readFileSync(fd).equals(...)`, and that is the
791
- * ONE check on this path an attacker cannot satisfy by construction. Size, mode 0644,
792
- * uid, nlink 1, `{dev, ino}` and the containment walk are all trivially matched by a file
793
- * the attacker builds; the deploy's own generated bytes are not.
794
- *
795
- * It was nevertheless unpinned, and three rounds of mutation testing did not notice,
796
- * because the mutation was taken in the WRONG DIRECTION. `return false` — the check
797
- * refusing everything — fails three tests, because it breaks the benign-race ACCEPTANCE
798
- * this describe block exists for, and was recorded as killed. `return true` — the check
799
- * ACCEPTING everything, which is the only direction that matters for a control — left all
800
- * 1939 tests green.
801
- *
802
- * The gap in coverage was exact. The one different-bytes test above uses bytes of a
803
- * DIFFERENT LENGTH, so it dies at the `landed.size` pre-check and never reaches the
804
- * comparison; the one same-size test lands IDENTICAL bytes and asserts success. Nothing
805
- * in the suite landed a same-size, different-bytes file. This does.
806
- *
807
- * The running code refuses it (confirmed by probe before this test was written), so this
808
- * is a missing pin rather than a live hole — but an unpinned control is one refactor away
809
- * from being a live hole, and this is the control that matters most.
810
- */
811
- it('MUST FIX: a file of the RIGHT size with DIFFERENT bytes is refused by the byte comparison alone', () => {
812
- let landedBytes = Buffer.alloc(0);
813
- let ownBytes = Buffer.alloc(0);
814
- race.afterRename = (destination) => {
815
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
816
- return;
817
- race.afterRename = null;
818
- ownBytes = readFileSync(destination);
819
- // Same LENGTH, different CONTENT: a first line the attacker chose, padded out with
820
- // `#` to exactly the byte count this deploy generated. Every size-shaped question
821
- // about this file answers "correct", so the size pre-check cannot be what refuses it.
822
- const head = Buffer.from('# SUBSTITUTED — NOT THIS DEPLOY\'S OUTPUT\n', 'utf-8');
823
- landedBytes = Buffer.concat([head, Buffer.alloc(ownBytes.length - head.length, 0x23)]);
824
- landAnotherFileAt(destination, landedBytes);
825
- };
826
- const outcome = deploy();
827
- // The preconditions, stated as measurement: the entry at the artifact path is a regular
828
- // file, one name, mode 0644, owned by this process, and EXACTLY the size of this
829
- // deploy's own output — so every check in the acceptance except the byte comparison
830
- // answers yes, and only `equals` can refuse it.
831
- const landed = lstatSync(override(), { bigint: true });
832
- expect(landed.isFile()).toBe(true);
833
- expect(landed.nlink).toBe(1n);
834
- expect(Number(landed.mode) & 0o777).toBe(0o644);
835
- expect(landed.uid).toBe(BigInt(process.geteuid?.() ?? 0));
836
- expect(landed.size).toBe(BigInt(ownBytes.length));
837
- expect(readFileSync(override()).equals(ownBytes)).toBe(false);
838
- // And the file really was read and compared — a size pre-check that had rejected it
839
- // would leave no read of this path on the record.
840
- expect(race.fdReads.filter((p) => p.endsWith(AGENTS_OVERRIDE_FILENAME))).toEqual([override()]);
841
- expect(outcome.ok).toBe(false);
842
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
843
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
844
- });
845
- /**
846
- * ── SF-2 (round 8): THE MODE IS PART OF THE ARTIFACT ────────────────────────
847
- * The reviewer's probe P2: a distinct regular file with IDENTICAL bytes at mode 0666.
848
- * The acceptance checked type, link count and bytes only, so it said yes — `ok=true`,
849
- * the artifact reported as written, and `AGENTS.override.md` left world-writable, which
850
- * Codex reads as a REPLACEMENT for `AGENTS.md`. A deploy must not certify an instruction
851
- * file that anyone on the box can rewrite.
852
- */
853
- it('a WORLD-WRITABLE file with identical bytes is NOT accepted as this deploy own output', () => {
854
- race.afterRename = (destination) => {
855
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
856
- return;
857
- race.afterRename = null;
858
- landAnotherFileAt(destination, readFileSync(destination), 0o666);
859
- };
860
- const outcome = deploy();
861
- expect(outcome.ok).toBe(false);
862
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
863
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
864
- // The bad entry is left in place by design, and it is the world-writable one — which
865
- // is exactly why reporting it as written was wrong.
866
- expect(lstatSync(override()).mode & 0o777).toBe(0o666);
867
- });
868
- it('a SYMLINK with identical content substituted in that window still fails (SF-I preserved)', () => {
869
- const decoy = join(root, 'decoy-identical.md');
870
- race.afterRename = (destination) => {
871
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
872
- return;
873
- race.afterRename = null;
874
- // Same bytes, reached through a link: content equality alone must not accept it.
875
- writeFileSync(decoy, readFileSync(destination));
876
- unlinkSync(destination);
877
- symlinkSync(decoy, destination);
878
- };
879
- const outcome = deploy();
880
- expect(outcome.ok).toBe(false);
881
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
882
- expect(outcome.writeFailures.join('\n')).toContain('a SYMLINK');
883
- expect(lstatSync(override()).isSymbolicLink()).toBe(true);
884
- });
885
- it('a HARDLINK to a main-repo file with identical content still fails (SF-I preserved)', () => {
886
- const mainFile = join(root, 'main-repo-target.md');
887
- race.afterRename = (destination) => {
888
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
889
- return;
890
- race.afterRename = null;
891
- // The hard case for a content-equality rule: byte-identical AND a regular file. The
892
- // second name is what disqualifies it — a later write through this path would reach
893
- // the main repo's file.
894
- writeFileSync(mainFile, readFileSync(destination));
895
- unlinkSync(destination);
896
- linkSync(mainFile, destination);
897
- };
898
- const outcome = deploy();
899
- expect(outcome.ok).toBe(false);
900
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
901
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
902
- expect(outcome.writeFailures.join('\n')).toContain('2 name(s)');
903
- });
904
- });
905
- /**
906
- * ───── ROUND 8: THE WINDOW BETWEEN THE VERIFYING lstat AND THE ACCEPTANCE ─────
907
- * SF-L (above) added a second, narrower window to this write path and nothing tested it.
908
- * The acceptance takes an `lstat` of the artifact path and then RE-OPENS THAT NAME, so
909
- * everything the acceptance decides can be decided against a different object than the one
910
- * that was `lstat`ed — if an attacker moves in between.
911
- *
912
- * Every SF-I test substitutes BEFORE the `lstat`, which means `landed.isFile()` is already
913
- * false and the code short-circuits: not one existing test reaches the re-open with a
914
- * hostile object present. That is why four mutants survived a green suite (round 8 SF-3),
915
- * and why the FIFO hang below (round 8 MUST FIX) went unnoticed.
916
- *
917
- * Reaching the re-open at all takes two steps, so these tests do both: a second HONEST
918
- * deploy lands its own byte-identical artifact between this deploy's `renameSync` and its
919
- * verifying `lstat` (the benign race SF-L exists for — it is what makes the inode differ
920
- * and the acceptance run), and only then does the attacker substitute, timed off that
921
- * `lstat` via the `onLstat` instrument.
922
- */
923
- describe('write path — the acceptance re-open decides on ONE object (round 8)', () => {
924
- const override = () => join(worktree, AGENTS_OVERRIDE_FILENAME);
925
- /**
926
- * What a second honest deploy leaves at the path: a different inode, the same bytes, and
927
- * the same mode — `modeForInstalledArtifact` is deterministic, so two honest deploys of
928
- * the same artifact compute the same 0644 and `fchmod` to it.
929
- */
930
- const landAnotherHonestDeployAt = (destination) => {
931
- const staged = `${destination}.another-deploy`;
932
- writeFileSync(staged, readFileSync(destination));
933
- chmodSync(staged, 0o644);
934
- renameSync(staged, destination);
935
- };
936
- /**
937
- * Put the deploy into the one state that reaches the acceptance re-open, then run
938
- * `substitute` inside the `lstat` → `open` window. The hook returns `undefined`, so the
939
- * deploy keeps the stat taken BEFORE the substitution — which is exactly the attacker's
940
- * position: the code has already decided what it believes is at the path.
941
- */
942
- const honestRaceThenSubstitute = (artifactRel, substitute) => {
943
- race.afterRename = (destination) => {
944
- if (!destination.endsWith(artifactRel))
945
- return;
946
- race.afterRename = null;
947
- landAnotherHonestDeployAt(destination);
948
- race.onLstat = (p, _real, bigint) => {
949
- if (p !== destination || !bigint)
950
- return undefined;
951
- race.onLstat = null;
952
- substitute(p);
953
- return undefined;
954
- };
955
- };
956
- };
957
- /**
958
- * ── THE MUST FIX: A FIFO IN THAT WINDOW USED TO HANG THE PROCESS FOREVER ────
959
- * `open(O_RDONLY)` on a FIFO blocks in the kernel until a writer arrives, and no writer
960
- * ever arrives here. `openSync` is synchronous, so `mx-agent start` hung indefinitely —
961
- * no timeout, no log line, nothing written. The reviewer's repro could not even be
962
- * stopped by vitest's own 20-second test timeout; the run had to be killed from outside.
963
- * `O_NONBLOCK` makes the open return immediately and the `!open.isFile()` check rejects
964
- * the FIFO, so the deploy fails closed the way it did before SF-L existed.
965
- */
966
- it('a FIFO substituted in that window is refused, and does NOT hang the deploy', () => {
967
- const startedAt = Date.now();
968
- honestRaceThenSubstitute(AGENTS_OVERRIDE_FILENAME, (path) => {
969
- unlinkSync(path);
970
- execFileSync('mkfifo', [path]);
971
- });
972
- const outcome = deploy();
973
- // The pin. Without `O_NONBLOCK` this line is never reached: the deploy is still inside
974
- // `openSync` when the test runner is killed.
975
- expect(Date.now() - startedAt).toBeLessThan(10_000);
976
- expect(lstatSync(override()).isFIFO()).toBe(true);
977
- expect(outcome.ok).toBe(false);
978
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
979
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
980
- });
981
- /**
982
- * The narrower window INSIDE the acceptance: between its containment walk (which
983
- * `lstat`s each path component without `bigint`) and the `open` that resolves the same
984
- * name again. This is the window `O_NOFOLLOW` exists for, and the only one in which the
985
- * walk cannot see what the open will get.
986
- */
987
- const afterTheContainmentWalkSubstitute = (artifactRel, substitute) => {
988
- race.afterRename = (destination) => {
989
- if (!destination.endsWith(artifactRel))
990
- return;
991
- race.afterRename = null;
992
- landAnotherHonestDeployAt(destination);
993
- race.onLstat = (p, _real, bigint) => {
994
- // The acceptance's walk is the first NON-bigint lstat of the artifact path after
995
- // the rename; the verifying lstat before it takes bigint stats.
996
- if (bigint || p !== destination)
997
- return undefined;
998
- race.onLstat = null;
999
- substitute(p);
1000
- return undefined;
1001
- };
1002
- };
1003
- };
1004
- /**
1005
- * ── SF-3: THE RE-OPEN MUST NOT FOLLOW A LINK ────────────────────────────────
1006
- * A symlink planted after the walk and before the open, pointing at the very file the
1007
- * walk approved. Every check the acceptance makes on the OBJECT then passes — same
1008
- * inode, one name, right mode, right bytes — so `O_NOFOLLOW` on the open is the only
1009
- * thing that refuses it. Without `O_NOFOLLOW` the deploy certifies an artifact path that
1010
- * is a symlink, which is the SF-I property this file exists to protect.
1011
- */
1012
- it('SF-3: a SYMLINK substituted after the containment walk is refused by the open itself', () => {
1013
- const decoy = join(root, 'decoy-same-inode.md');
1014
- afterTheContainmentWalkSubstitute(AGENTS_OVERRIDE_FILENAME, (path) => {
1015
- // Move the approved file aside and leave a link to it: the open, if it follows, gets
1016
- // back the identical inode the acceptance is looking for.
1017
- renameSync(path, decoy);
1018
- symlinkSync(decoy, path);
1019
- });
1020
- const outcome = deploy();
1021
- expect(lstatSync(override()).isSymbolicLink()).toBe(true);
1022
- expect(outcome.ok).toBe(false);
1023
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1024
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1025
- });
1026
- /**
1027
- * ── SF-3: THE fstat IS BOUND TO THE ENTRY THAT WAS lstatED ──────────────────
1028
- * A DIFFERENT regular file with identical bytes, the same mode and one name. Type, link
1029
- * count, mode, owner and bytes all agree; only `{dev, ino}` says it is not the object the
1030
- * acceptance decided about. That comparison is the "decided on one object, not on a name
1031
- * examined twice" claim, and nothing tested it.
1032
- */
1033
- it('SF-3: a DIFFERENT file with identical bytes in that window fails the dev/ino binding', () => {
1034
- let approvedBytes = Buffer.alloc(0);
1035
- let approvedInode = 0n;
1036
- afterTheContainmentWalkSubstitute(AGENTS_OVERRIDE_FILENAME, (path) => {
1037
- approvedBytes = readFileSync(path);
1038
- approvedInode = lstatSync(path, { bigint: true }).ino;
1039
- const other = `${path}.attacker`;
1040
- writeFileSync(other, approvedBytes);
1041
- chmodSync(other, 0o644);
1042
- renameSync(other, path);
1043
- });
1044
- const outcome = deploy();
1045
- expect(outcome.ok).toBe(false);
1046
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1047
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1048
- // The substitute really is byte-identical and correctly moded — the only thing wrong
1049
- // with it is that it is a different inode.
1050
- expect(readFileSync(override()).equals(approvedBytes)).toBe(true);
1051
- expect(lstatSync(override(), { bigint: true }).ino).not.toBe(approvedInode);
1052
- expect(lstatSync(override()).mode & 0o777).toBe(0o644);
1053
- });
1054
- /**
1055
- * ── SF-3 + QA: EXACTLY ONE nlink CHECK REMOVED IS DETECTED ──────────────────
1056
- * There are two link-count checks — one on the `lstat`ed entry, one on the `fstat` of the
1057
- * open descriptor — and each backstops the other, so removing either one alone left the
1058
- * suite green. These two tests separate them: the first is a second name that exists at
1059
- * `lstat` time and is gone by the open (only the lstat-side check sees it), the second is
1060
- * a second name created after the containment walk (only the fstat-side check sees it).
1061
- */
1062
- it('SF-3: a second name present at the lstat and gone by the open is refused (lstat-side nlink)', () => {
1063
- const secondName = join(worktree, 'second-name.md');
1064
- race.afterRename = (destination) => {
1065
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1066
- return;
1067
- race.afterRename = null;
1068
- landAnotherHonestDeployAt(destination);
1069
- linkSync(destination, secondName);
1070
- race.onLstat = (p, _real, bigint) => {
1071
- if (p !== destination || !bigint)
1072
- return undefined;
1073
- race.onLstat = null;
1074
- // The verifying lstat has already recorded nlink = 2. Dropping the extra name now
1075
- // means every later look — the containment walk, the fstat — sees nlink = 1.
1076
- unlinkSync(secondName);
1077
- return undefined;
1078
- };
1079
- };
1080
- const outcome = deploy();
1081
- expect(outcome.ok).toBe(false);
1082
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1083
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1084
- });
1085
- it('SF-3: a second name created after the containment walk is refused (fstat-side nlink)', () => {
1086
- const secondName = join(worktree, 'second-name.md');
1087
- afterTheContainmentWalkSubstitute(AGENTS_OVERRIDE_FILENAME, (path) => {
1088
- // After the walk, so the walk's own nlink check saw one name. Only the fstat on the
1089
- // open descriptor can still notice.
1090
- linkSync(path, secondName);
1091
- });
1092
- const outcome = deploy();
1093
- expect(outcome.ok).toBe(false);
1094
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1095
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1096
- expect(lstatSync(override()).nlink).toBe(2);
1097
- });
1098
- /**
1099
- * ── ROUND 9 SF-C, COMPLETENESS PASS: THE PARENT CHECK INSIDE THE ACCEPTANCE ─
1100
- * Round 9 MUST FIX 2 turned the acceptance's parent-identity check from a throw into a
1101
- * predicate. That is the right report, and it cost a pin: the only test that reached the
1102
- * check used a SYMLINKED parent, which the acceptance's containment walk refuses too, so
1103
- * with the check deleted outright the suite stayed green. A survivor introduced by a
1104
- * remediation is exactly the failure mode round 9 exists to stop, so it is pinned here.
1105
- *
1106
- * The state the walk cannot see, built with real syscalls: the artifact's own inode is
1107
- * MOVED into a fresh real directory, and that directory is renamed over `.codex`. Nothing
1108
- * along the path is a symlink and nothing has a second name, so containment passes; the
1109
- * descriptor carries the same `{dev, ino}`, one name, mode 0644, the right owner and
1110
- * byte-identical content, so every check on the OBJECT passes. Only the parent's identity
1111
- * says this artifact is sitting in a directory the deploy never validated.
1112
- */
1113
- it('SF-C: an artifact MOVED into a fresh directory renamed over the parent is refused', () => {
1114
- const codexDir = join(worktree, '.codex');
1115
- let swapped = false;
1116
- // ── ROUND 11 MAJOR C: THE PRECONDITION IS MEASURED, NOT ASSUMED ───────────
1117
- // QA saw this test fail once in ten full-suite runs, on `outcome.ok === true`, and it
1118
- // could not be reproduced afterwards: 45 full-suite runs (25 of them under eight-way
1119
- // CPU contention), 100 runs of this file alone, and 40 of those under a process
1120
- // churning directory creation and removal in `/tmp` to stress the inode allocator —
1121
- // zero failures. No mechanism was found in the test or in the code, so nothing here is
1122
- // a fix and no retry, timeout or `sequential` has been added to hide it.
1123
- //
1124
- // What IS added is the measurement that makes a recurrence conclusive instead of
1125
- // ambiguous. The refusal this test asserts depends on exactly one property: the entry
1126
- // at `.codex` after the swap must be a DIFFERENT directory from the one whose identity
1127
- // the deploy captured. The fresh directory is created while the original is still
1128
- // live, so on any filesystem that gives live objects distinct identities the two must
1129
- // differ — measured directly on this container's overlayfs `/tmp`, 20,000 fresh
1130
- // directories against one live directory produced 0 collisions, though a number is
1131
- // handed straight back once its object is freed.
1132
- //
1133
- // Recording both identities splits the next failure in two. Identities EQUAL: the
1134
- // filesystem reused a live directory's number, the precondition never held, and the
1135
- // fault is here. Identities DIFFERENT and `ok` still true: the parent-identity check
1136
- // accepted a parent it had never validated, which is a real defect in the write path
1137
- // and a far bigger finding than a flaky test.
1138
- let parentBefore = { dev: 0n, ino: 0n };
1139
- let parentAfter = { dev: 0n, ino: 0n };
1140
- honestRaceThenSubstitute(CODEX_HOOKS_FILENAME, (path) => {
1141
- const before = lstatSync(codexDir, { bigint: true });
1142
- parentBefore = { dev: before.dev, ino: before.ino };
1143
- const fresh = join(worktree, '.codex-fresh');
1144
- mkdirSync(fresh);
1145
- // The inode survives a rename, so the object the acceptance is about is unchanged —
1146
- // only the directory holding it is a different one.
1147
- renameSync(path, join(fresh, 'hooks.json'));
1148
- renameSync(codexDir, join(worktree, '.codex-old'));
1149
- renameSync(fresh, codexDir);
1150
- const after = lstatSync(codexDir, { bigint: true });
1151
- parentAfter = { dev: after.dev, ino: after.ino };
1152
- swapped = true;
1153
- });
1154
- const outcome = deploy();
1155
- expect(swapped).toBe(true);
1156
- // Containment is intact — a real directory, a real file, no symlink, one name — which
1157
- // is why the walk cannot refuse this and the parent-identity check must.
1158
- expect(lstatSync(codexDir).isDirectory()).toBe(true);
1159
- expect(lstatSync(join(worktree, CODEX_HOOKS_FILENAME)).nlink).toBe(1);
1160
- // The precondition, asserted BEFORE the outcome so a failure names the right cause.
1161
- expect(parentAfter).not.toEqual(parentBefore);
1162
- expect(outcome.ok).toBe(false);
1163
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
1164
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1165
- });
1166
- /**
1167
- * The same check's FAIL-CLOSED half: a parent that cannot be examined at all. RV-2 pins
1168
- * this for the two pre-install call sites, where it throws; this is the acceptance's
1169
- * copy, where it returns false. A `catch` that answered "yes, same directory" would
1170
- * certify an artifact whose parent the deploy could not look at.
1171
- */
1172
- it('SF-C: a parent that cannot be EXAMINED during the acceptance is refused', () => {
1173
- const codexDir = join(worktree, '.codex');
1174
- let refused = false;
1175
- race.afterRename = (destination) => {
1176
- if (!destination.endsWith(CODEX_HOOKS_FILENAME))
1177
- return;
1178
- race.afterRename = null;
1179
- landAnotherHonestDeployAt(destination);
1180
- race.onLstat = (p, _real, bigint) => {
1181
- if (p !== codexDir || !bigint)
1182
- return undefined;
1183
- race.onLstat = null;
1184
- refused = true;
1185
- const err = new Error(`EACCES: permission denied, lstat '${p}'`);
1186
- err.code = 'EACCES';
1187
- throw err;
1188
- };
1189
- };
1190
- const outcome = deploy();
1191
- race.onLstat = null;
1192
- expect(refused).toBe(true);
1193
- expect(outcome.ok).toBe(false);
1194
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
1195
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1196
- });
1197
- /**
1198
- * The acceptance's own `catch`, around the `fstat` and the content read. It is the last
1199
- * fail-closed branch on this path and nothing reached it: the read only happens once
1200
- * every other check has passed, so making it FAIL needs an instrument. A `catch` that
1201
- * returned true would certify an artifact this deploy could not read.
1202
- */
1203
- it('SF-C: a content read that FAILS is a refusal, not an acceptance', () => {
1204
- let threw = false;
1205
- race.afterRename = (destination) => {
1206
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1207
- return;
1208
- race.afterRename = null;
1209
- landAnotherHonestDeployAt(destination);
1210
- race.onFdRead = (path) => {
1211
- if (!path.endsWith(AGENTS_OVERRIDE_FILENAME))
1212
- return;
1213
- race.onFdRead = null;
1214
- threw = true;
1215
- const err = new Error('EIO: i/o error, read');
1216
- err.code = 'EIO';
1217
- throw err;
1218
- };
1219
- };
1220
- const outcome = deploy();
1221
- race.onFdRead = null;
1222
- expect(threw).toBe(true);
1223
- expect(outcome.ok).toBe(false);
1224
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1225
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1226
- });
1227
- /**
1228
- * ── ROUND 11 SHOULD FIX E: THE VERIFYING lstat'S OWN CATCH ──────────────────
1229
- * The acceptance path starts one level up from everything else in this describe block:
1230
- * after `renameSync` returns, the caller takes `landed = lstatSync(absPath)`, and THAT
1231
- * call has its own `catch`, which throws "was renamed into place but could not then be
1232
- * examined … Treating the write as FAILED."
1233
- *
1234
- * Nothing asserted that string anywhere in `src/`, and mutating the throw to a silent
1235
- * `return` left the file green — the deploy would then report an artifact as WRITTEN on
1236
- * the strength of a `rename` that returned, having been unable to look at what is now at
1237
- * the path. That is the same class as the SF-C "parent that cannot be EXAMINED" pin one
1238
- * level down, and it is reachable with the same instrument.
1239
- */
1240
- it('SF-E: an artifact that cannot be EXAMINED after the rename is a FAILED write, not a written one', () => {
1241
- let threw = false;
1242
- race.afterRename = (destination) => {
1243
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1244
- return;
1245
- race.afterRename = null;
1246
- race.onLstat = (p, _real, bigint) => {
1247
- if (p !== destination || !bigint)
1248
- return undefined;
1249
- race.onLstat = null;
1250
- threw = true;
1251
- const err = new Error(`EACCES: permission denied, lstat '${p}'`);
1252
- err.code = 'EACCES';
1253
- throw err;
1254
- };
1255
- };
1256
- const outcome = deploy();
1257
- race.onLstat = null;
1258
- expect(threw).toBe(true);
1259
- expect(outcome.ok).toBe(false);
1260
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1261
- const failure = outcome.writeFailures.join('\n');
1262
- // The message is the pin: it must say the rename SUCCEEDED and the check did not, which
1263
- // is a different operator instruction from "nothing was installed".
1264
- expect(failure).toContain('was renamed into place but could not then be examined');
1265
- expect(failure).toContain('EACCES');
1266
- expect(failure).toContain('Treating the write as FAILED');
1267
- });
1268
- /**
1269
- * ── ROUND 9 MUST FIX: AN INODE NUMBER IS NOT A DURABLE IDENTITY (RP14) ──────
1270
- * Round 8 reported `!open.isFile()` as an unkillable mutant, on the reasoning that it
1271
- * "cannot be the sole cause of a rejection once the `{dev, ino}` binding is present,
1272
- * because an identical inode has an identical type". THAT REASONING IS WRONG, and this
1273
- * test is the disproof. An inode NUMBER is not a durable identity: unlink the object that
1274
- * holds it and the number is free, and the next object created on that filesystem can
1275
- * take it and be of ANY TYPE.
1276
- *
1277
- * The reviewer's RP14, reproduced here with real syscalls only — no forged stats, unlike
1278
- * the two SF-C pins below:
1279
- * 1. An honest concurrent redeploy lands a byte-identical artifact between this
1280
- * deploy's `renameSync` and its verifying `lstat` (SF-L), which is what makes the
1281
- * inode differ and the acceptance run at all.
1282
- * 2. At the verifying `lstat`, the attacker reads the bytes, records the inode number,
1283
- * UNLINKS the artifact, and creates FIFOs until one takes that same number — the
1284
- * reviewer measured 322 of 400 trials on this filesystem.
1285
- * 3. It pre-buffers this deploy's exact bytes into the FIFO (open the read end, open
1286
- * the write end, write, close the write end), so `readFileSync` on the acceptance's
1287
- * non-blocking descriptor drains the buffer and then sees a clean EOF.
1288
- *
1289
- * Every other check agrees: nlink 1, mode 0644, uid, size, the containment walk (which
1290
- * refuses symlinks and second names, not FIFOs), and both halves of the `{dev, ino}`
1291
- * binding. With `!open.isFile()` removed the deploy certifies a FIFO as
1292
- * `AGENTS.override.md` — `ok=true`, artifact listed as written — and Codex reads that
1293
- * file as a REPLACEMENT for `AGENTS.md`.
1294
- *
1295
- * The reuse is a race with the filesystem's own allocator, so it is a PRECONDITION, not
1296
- * an assertion: the whole deploy is retried while it is not achieved, and the test skips
1297
- * rather than fails if the allocator never hands the number back.
1298
- */
1299
- it('MUST FIX: a FIFO that REUSES the artifact inode number is refused by the fstat type check (RP14)', (ctx) => {
1300
- const ATTEMPTS = 8;
1301
- const PROBES = 150;
1302
- let reused = false;
1303
- let targetIno = 0n;
1304
- let readFd = -1;
1305
- let outcome = null;
1306
- for (let attempt = 0; attempt < ATTEMPTS && !reused; attempt++) {
1307
- // A previous attempt that failed to win the inode leaves the artifact path empty or
1308
- // holding a FIFO; either way the next deploy must start from a plain state.
1309
- if (existsSync(override()) && !lstatSync(override()).isFile())
1310
- unlinkSync(override());
1311
- race.afterRename = (destination) => {
1312
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1313
- return;
1314
- race.afterRename = null;
1315
- landAnotherHonestDeployAt(destination);
1316
- race.onLstat = (p, _real, bigint) => {
1317
- if (p !== destination || !bigint)
1318
- return undefined;
1319
- race.onLstat = null;
1320
- const bytes = readFileSync(destination);
1321
- targetIno = lstatSync(destination, { bigint: true }).ino;
1322
- unlinkSync(destination);
1323
- // The losing probes are KEPT, not unlinked: unlinking each one returns its
1324
- // number to the head of the allocator's free list and hands it straight back on
1325
- // the next call, so the target number never surfaces. Holding them drains the
1326
- // list down to it — in practice within two or three probes, since the number
1327
- // freed just before the target is this deploy's own replaced artifact.
1328
- const probes = [];
1329
- let winner = null;
1330
- for (let i = 0; i < PROBES && winner === null; i++) {
1331
- const probe = `${destination}.fifo-probe-${i}`;
1332
- execFileSync('mkfifo', [probe]);
1333
- probes.push(probe);
1334
- if (lstatSync(probe, { bigint: true }).ino === targetIno)
1335
- winner = probe;
1336
- }
1337
- if (winner !== null) {
1338
- chmodSync(winner, 0o644);
1339
- renameSync(winner, destination);
1340
- reused = true;
1341
- }
1342
- for (const probe of probes)
1343
- if (probe !== winner)
1344
- unlinkSync(probe);
1345
- // Lost the allocator race: the path is left empty, this deploy fails closed on
1346
- // the open, and the outer loop tries the whole thing again.
1347
- if (!reused)
1348
- return undefined;
1349
- // Pre-buffer the bytes. The read end is held open for the rest of the deploy so
1350
- // the data survives; the write end is closed so the acceptance's read sees EOF.
1351
- readFd = openSync(destination, fsConstants.O_RDONLY | fsConstants.O_NONBLOCK);
1352
- const writeFd = openSync(destination, fsConstants.O_WRONLY);
1353
- writeSync(writeFd, bytes);
1354
- closeSync(writeFd);
1355
- return undefined;
1356
- };
1357
- };
1358
- outcome = deploy();
1359
- race.afterRename = null;
1360
- race.onLstat = null;
1361
- if (readFd >= 0) {
1362
- closeSync(readFd);
1363
- readFd = -1;
1364
- }
1365
- }
1366
- if (!reused) {
1367
- console.warn(`RP14 SKIPPED: the filesystem never returned inode ${targetIno} to a new FIFO in ` +
1368
- `${ATTEMPTS} deploys of ${PROBES} probes — the mutant this test kills is unreachable ` +
1369
- 'on this filesystem, not absent from the code');
1370
- ctx.skip();
1371
- return;
1372
- }
1373
- const landed = lstatSync(override(), { bigint: true });
1374
- // The precondition, stated as measurement: the entry at the artifact path is a FIFO
1375
- // wearing the inode number of the regular file the acceptance had just `lstat`ed. Every
1376
- // check but the descriptor type check therefore answers yes.
1377
- expect(landed.isFIFO()).toBe(true);
1378
- expect(landed.ino).toBe(targetIno);
1379
- expect(landed.nlink).toBe(1n);
1380
- expect(Number(landed.mode) & 0o777).toBe(0o644);
1381
- expect(outcome?.ok).toBe(false);
1382
- expect(outcome?.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1383
- expect(outcome?.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1384
- });
1385
- /**
1386
- * ── ROUND 11 MUST FIX B: RP14 IS REAL, AND IT IS FILESYSTEM-CONDITIONAL ─────
1387
- * RP14 above is the SOLE killer of `!open.isFile()`, and it treats inode reuse as a
1388
- * PRECONDITION — if the allocator never hands the number back it calls `ctx.skip()`. That
1389
- * makes the strength of a MUST FIX pin depend on what backs the temp directory, and the
1390
- * two reviewers measured different filesystems and both were right:
1391
- *
1392
- * overlayfs (`/tmp` in this container) 25 of 25 runs reuse achieved, never skipped
1393
- * ext4 (`/workspace`) 13 of 13 runs reuse achieved, never skipped
1394
- * tmpfs (`/dev/shm`) 0 of 3 runs SKIPPED every time
1395
- *
1396
- * and decisively: with `!open.isFile()` DELETED and `TMPDIR=/dev/shm`, the file reports
1397
- * `44 passed | 1 skipped`, rc=0. On tmpfs the round-8 MUST FIX regresses silently.
1398
- *
1399
- * The fix is not to find out what CI's `/tmp` is backed by — that is a fact about the
1400
- * runner, and it can change without anyone touching this repo. It is to remove the
1401
- * dependency. RP14 STAYS, because a real-syscall demonstration that the attack is
1402
- * reachable is worth having; this test sits beside it and pins the same check
1403
- * deterministically, on any filesystem, using the `statReporting` instrument the SF-C
1404
- * pins below already use.
1405
- *
1406
- * The object at the path is a REAL `mkfifo` FIFO, pre-buffered with this deploy's exact
1407
- * bytes. Only the verifying `lstat` is forged, and only in the two fields a real inode
1408
- * reuse would have supplied for free: it reports a regular file of the artifact's size,
1409
- * carrying the FIFO's own `{dev, ino}`, `nlink` 1 and mode 0644. Every check downstream
1410
- * then agrees — the containment walk (which refuses symlinks and second names, not
1411
- * FIFOs), both halves of the `{dev, ino}` binding against the open descriptor, the link
1412
- * count, the mode, the owner, and the byte comparison, which reads the pre-buffered bytes
1413
- * and finds them equal. `open.isFile()` on the descriptor is the only thing left that can
1414
- * refuse it.
1415
- *
1416
- * WHAT THE FORGERY MODELS, AND WHAT IT DOES NOT CLAIM (#4897 INFO-1). "Only the verifying
1417
- * `lstat` is forged" is true, but do not read it as saying the composite state above is
1418
- * one a single kernel call could hand back. It is not: an inode's type lives in its mode
1419
- * bits, so a REAL `lstat` of a FIFO always reports a FIFO. What this pins is a faithful
1420
- * MODEL of RP14's two-instant sequence — a regular file at `lstat` time, a FIFO by `open`
1421
- * time, the same inode number across both — collapsed into one stat so the pin lands on
1422
- * any filesystem. The STATE is reachable, which is what makes the check worth pinning; it
1423
- * is the single-call RENDERING of it that is synthetic. The pin is valid either way.
1424
- */
1425
- it('MUST FIX: a FIFO reported by lstat as a regular file is refused by the fstat type check (deterministic RP14)', () => {
1426
- let fired = false;
1427
- let readFd = -1;
1428
- let fifoIno = 0n;
1429
- let installedIno = 0n;
1430
- race.afterRename = (destination) => {
1431
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1432
- return;
1433
- race.afterRename = null;
1434
- const bytes = readFileSync(destination);
1435
- installedIno = lstatSync(destination, { bigint: true }).ino;
1436
- // The FIFO is created ASIDE and renamed over the artifact, not created at the
1437
- // artifact's own name after unlinking it. Unlinking first frees this deploy's inode
1438
- // number and the allocator hands it straight back to the FIFO — which is #4908,
1439
- // inode reuse at the PRIMARY install check, a separate finding with its own PR. This
1440
- // test is about the acceptance, so it must not land on that: allocating the FIFO
1441
- // while the artifact still holds its number guarantees the two differ, which is what
1442
- // makes the call site's `{dev, ino}` comparison fail and the acceptance run at all.
1443
- const aside = `${destination}.fifo-aside`;
1444
- execFileSync('mkfifo', [aside]);
1445
- chmodSync(aside, 0o644);
1446
- // Pre-buffer this deploy's own bytes. The read end is held open for the rest of the
1447
- // deploy so the data survives; the write end is closed so the acceptance's own
1448
- // non-blocking read drains the buffer and then sees a clean EOF. Without this the
1449
- // content comparison, not the type check, would be doing the refusing.
1450
- readFd = openSync(aside, fsConstants.O_RDONLY | fsConstants.O_NONBLOCK);
1451
- const writeFd = openSync(aside, fsConstants.O_WRONLY);
1452
- writeSync(writeFd, bytes);
1453
- closeSync(writeFd);
1454
- // A FIFO keeps its inode across a rename, so what arrives at the artifact path is the
1455
- // object already holding this deploy's bytes.
1456
- renameSync(aside, destination);
1457
- fifoIno = lstatSync(destination, { bigint: true }).ino;
1458
- race.onLstat = (p, real, bigint) => {
1459
- if (fired || p !== destination || !bigint)
1460
- return undefined;
1461
- fired = true;
1462
- // What a real inode-number reuse would have handed the deploy: an entry that
1463
- // answers "regular file" and carries the right size. Everything else — including
1464
- // `{dev, ino}` — is the FIFO's own, unforged.
1465
- return statReporting(real, {
1466
- isFile: () => true,
1467
- isFIFO: () => false,
1468
- size: BigInt(bytes.length),
1469
- });
1470
- };
1471
- };
1472
- const outcome = deploy();
1473
- race.onLstat = null;
1474
- if (readFd >= 0)
1475
- closeSync(readFd);
1476
- expect(fired).toBe(true);
1477
- // The precondition, measured against the REAL filesystem, not the forged stat: what is
1478
- // at the artifact path is a FIFO, with one name, mode 0644, and the inode the deploy's
1479
- // `lstat` reported — so the `{dev, ino}` binding to the open descriptor agrees.
1480
- const real = lstatSync(override(), { bigint: true });
1481
- expect(real.isFIFO()).toBe(true);
1482
- expect(real.ino).toBe(fifoIno);
1483
- expect(real.nlink).toBe(1n);
1484
- expect(Number(real.mode) & 0o777).toBe(0o644);
1485
- // And it is NOT the inode this deploy installed — so the acceptance really ran, and
1486
- // this test is not quietly re-testing #4908.
1487
- expect(fifoIno).not.toBe(installedIno);
1488
- expect(outcome.ok).toBe(false);
1489
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1490
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1491
- });
1492
- /**
1493
- * ── ROUND 9 SF-C: THE TWO CHECKS THE ROUND-8 DISCLOSURE MISSED ──────────────
1494
- * QA re-derived the mutation matrix by hand and found FOUR survivors where round 8
1495
- * reported two. The two undisclosed ones are pinned here.
1496
- *
1497
- * `landed.isFile()` — the LSTAT-side type check at the top of the acceptance, a separate
1498
- * and earlier check from the `open.isFile()` one on the descriptor. Every currently
1499
- * reachable non-regular object is also caught by the size pre-check below it (a FIFO and
1500
- * a socket both `lstat` as size 0, and no generated artifact is empty), which is what
1501
- * masked it. That masking is incidental: the artifacts' sizes are not a security
1502
- * property, and the check that says "this acceptance is about a REGULAR FILE" is this
1503
- * one. So it is pinned against the state the size check cannot mask — a stat that agrees
1504
- * on every field and reports the entry is not a regular file.
1505
- */
1506
- it('SF-C: a landed entry that is not a REGULAR FILE is refused (lstat-side type check)', () => {
1507
- let fired = false;
1508
- race.afterRename = (destination) => {
1509
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1510
- return;
1511
- race.afterRename = null;
1512
- race.onLstat = (p, real, bigint) => {
1513
- if (fired || p !== destination || !bigint)
1514
- return undefined;
1515
- fired = true;
1516
- return statReporting(real, { isFile: () => false });
1517
- };
1518
- };
1519
- const outcome = deploy();
1520
- race.onLstat = null;
1521
- expect(fired).toBe(true);
1522
- expect(outcome.ok).toBe(false);
1523
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1524
- const failure = outcome.writeFailures.join('\n');
1525
- expect(failure).toContain('NOT the file this deploy wrote');
1526
- expect(failure).toContain('a non-regular file');
1527
- });
1528
- /**
1529
- * `open.dev` ALONE. Round 8 reported `dev` and `ino` killed as a pair, which is true when
1530
- * both are cut together — but cutting `dev` on its own left the suite green, because
1531
- * every substitution the suite performs also produces a DIFFERENT INODE NUMBER, and the
1532
- * `ino` half then does all the work. A same-number-different-device object is the one
1533
- * case `ino` cannot answer, and it is the same class as RV-1 one level down: this is the
1534
- * comparison that binds the OPEN DESCRIPTOR to the entry that was `lstat`ed, and half of
1535
- * a two-field identity is not an identity.
1536
- */
1537
- it('SF-C: an open descriptor on another DEVICE with the same inode number is refused', () => {
1538
- let fired = false;
1539
- let realDev = 0n;
1540
- let realIno = 0n;
1541
- race.afterRename = (destination) => {
1542
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1543
- return;
1544
- race.afterRename = null;
1545
- race.onLstat = (p, real, bigint) => {
1546
- if (fired || p !== destination || !bigint)
1547
- return undefined;
1548
- fired = true;
1549
- realDev = real.dev;
1550
- realIno = real.ino;
1551
- return statReporting(real, { dev: realDev + 1n });
1552
- };
1553
- };
1554
- const outcome = deploy();
1555
- race.onLstat = null;
1556
- expect(fired).toBe(true);
1557
- expect(outcome.ok).toBe(false);
1558
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1559
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1560
- // The pin: nothing moved the file, so the descriptor the acceptance opened and the
1561
- // entry it `lstat`ed carry the SAME inode number — the `ino` half of the comparison
1562
- // agrees, and only the `dev` half can refuse this.
1563
- const now = lstatSync(override(), { bigint: true });
1564
- expect(now.ino).toBe(realIno);
1565
- expect(now.dev).toBe(realDev);
1566
- });
1567
- /**
1568
- * ── SF-1: A BYTE-IDENTICAL FILE SOMEWHERE ELSE IS NOT THIS DEPLOY'S ARTIFACT ─
1569
- * The reviewer's probe P3, reproduced: a byte-identical copy of the artifact in the main
1570
- * repo, and `<worktree>/.codex` swapped for a symlink to it AFTER the rename, so the
1571
- * verifying `lstat` resolves into the main repo. Content equality alone said yes and the
1572
- * deploy reported the artifact as WRITTEN; the pre-SF-L code refused.
1573
- *
1574
- * ── AND IT IS REPORTED AS WHAT IT IS (round 9 MUST FIX 2) ───────────────────
1575
- * This test used to assert the refusal text `assertSameDirectory` produces — including
1576
- * "Nothing was installed." — for a state in which the rename had ALREADY SUCCEEDED and a
1577
- * 4983-byte artifact was on disk. Both halves of that message are false here ("the bytes
1578
- * would land outside this worktree": they already landed, inside it), and a
1579
- * `ContainedWriteRefusal` filed it under `writeRefusals`, telling the operator a
1580
- * containment refusal had happened when what happened was a post-install directory swap.
1581
- * The security property is unchanged and still asserted — refused, not written, main repo
1582
- * untouched. What changed is that the report now says the true thing: the acceptance
1583
- * returns false, the caller's own "NOT the file this deploy wrote" error fires, and it
1584
- * classifies as a write FAILURE.
1585
- */
1586
- it('SF-1: a byte-identical file reached through a SWAPPED parent is a failed write, not a containment refusal', () => {
1587
- expect(deploy().ok).toBe(true);
1588
- race.afterRename = (destination) => {
1589
- if (!destination.endsWith(CODEX_HOOKS_FILENAME))
1590
- return;
1591
- race.afterRename = null;
1592
- // The install itself succeeded into the real directory. The attacker then makes the
1593
- // NAME point at the main repo and puts this deploy's own bytes there, so every
1594
- // content-shaped question about the path answers "correct".
1595
- const bytes = readFileSync(destination);
1596
- swapCodexDirForASymlinkToMainRepo();
1597
- writeFileSync(destination, bytes);
1598
- chmodSync(destination, 0o644);
1599
- };
1600
- const outcome = deploy();
1601
- restoreCodexDir();
1602
- // The artifact this deploy installed is on disk, in the real directory, holding this
1603
- // deploy's own bytes — which is why "Nothing was installed" was the wrong thing to say.
1604
- const installed = readFileSync(join(worktree, CODEX_HOOKS_FILENAME), 'utf-8');
1605
- expect(installed.length).toBeGreaterThan(0);
1606
- writeFileSync(join(mainCodex, 'hooks.json'), MAIN_HOOKS_SENTINEL);
1607
- expect(outcome.ok).toBe(false);
1608
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
1609
- // CLASSIFICATION: a write failure, not a containment refusal. Nothing about this
1610
- // artifact belongs in `writeRefusals` — the write was not refused, it happened.
1611
- expect(outcome.writeRefusals).toEqual([]);
1612
- const failure = outcome.writeFailures.join('\n');
1613
- expect(failure).toContain('NOT the file this deploy wrote');
1614
- // MESSAGE: no claim that nothing was installed, and no claim that bytes would land
1615
- // outside the worktree — the bytes landed inside it, at the path this deploy chose.
1616
- expect(failure).not.toContain('Nothing was installed');
1617
- expect(failure).not.toContain('would land outside this worktree');
1618
- });
1619
- /**
1620
- * ── SF-1, THE SECOND ANCHOR: THE WHOLE PATH, NOT JUST THE PARENT ─────────────
1621
- * The parent-identity check cannot see anything ABOVE the parent. Here the worktree
1622
- * directory is MOVED — so `.codex` keeps its inode and the parent check agrees — and a
1623
- * symlink is left in its place. The artifact path now names a file outside the worktree
1624
- * this deploy was told to write, and only the containment walk can tell.
1625
- */
1626
- it('SF-1: a worktree root replaced by a SYMLINK is refused even when the parent inode is unchanged', () => {
1627
- const moved = join(root, 'moved-worktree');
1628
- honestRaceThenSubstitute(CODEX_HOOKS_FILENAME, () => {
1629
- renameSync(worktree, moved);
1630
- symlinkSync(moved, worktree);
1631
- });
1632
- const outcome = deploy();
1633
- unlinkSync(worktree);
1634
- renameSync(moved, worktree);
1635
- expect(outcome.ok).toBe(false);
1636
- expect(outcome.written).not.toContain(CODEX_HOOKS_FILENAME);
1637
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1638
- });
1639
- });
1640
- /**
1641
- * ───────── #4908: AN INODE NUMBER IS NOT A DURABLE IDENTITY, AT CHECK 3 ───────
1642
- * RP14 (above) proved the point against the ACCEPTANCE. RP12 proves it against the PRIMARY
1643
- * install check, the one every honest deploy is decided by: `landed.dev !== opened.dev ||
1644
- * landed.ino !== opened.ino`.
1645
- *
1646
- * The attack is three syscalls. Between `renameSync` and the verifying `lstatSync`, unlink
1647
- * the just-installed artifact — nothing holds it once the descriptor is closed, so the
1648
- * kernel frees its inode number — and create a regular file of attacker-controlled content.
1649
- * It takes the freed number, and every field the check compares agrees. Measured before the
1650
- * fix: reuse on attempt 0, `ok=true`, `AGENTS.override.md` listed as WRITTEN, and
1651
- * `# ATTACKER CONTENT` on disk — a file Codex reads as a REPLACEMENT for `AGENTS.md`. The
1652
- * reviewer measured 322 of 400 trials in a tighter variant. It reproduced identically
1653
- * against `origin/main` and shipped in the published CLI: pre-existing, not introduced by
1654
- * #4897. CVSS 7.1 (AV:L/AC:H/PR:L/UI:N/S:C/C:N/I:H/A:N), CWE-367.
1655
- *
1656
- * The fix is a LIFETIME, not a fourth field: the temp file's descriptor is held open across
1657
- * the rename and the check, which PINS the inode so its number cannot be recycled while the
1658
- * check runs.
1659
- *
1660
- * inode reuse WITHOUT holding an fd open: 200/200
1661
- * inode reuse WHILE holding an fd open: 0/200
1662
- *
1663
- * (`birthtimeNs`/`ctimeNs` were tested as an alternative and rejected: both are
1664
- * byte-identical across the two creations, because the timestamps are coarser than the race
1665
- * window.)
1666
- *
1667
- * ── WHY THERE ARE TWO TESTS, AND WHY ONE OF THEM IS STRUCTURAL ───────────────
1668
- * The first test below is the attack, with real syscalls only. It is filesystem-conditional
1669
- * in the same way RP14 is (round 11 MUST FIX B measured reuse on overlayfs and ext4 and
1670
- * never on tmpfs) — but the conditionality runs the OTHER way here, and that is worse: on a
1671
- * filesystem that never recycles, the attack silently fails to land and the test passes
1672
- * against UNFIXED code. That is exactly the fail-OPEN direction a mutation pin exists to
1673
- * catch (KI-METHOD-MUTATE-FAIL-OPEN).
1674
- *
1675
- * So the second test pins the mechanism directly and lands on any filesystem. It is
1676
- * structural — it asserts the ORDER of `open`, `rename`, the verifying `lstat` and `close`
1677
- * — because the remediation adds no check and therefore produces no verdict to assert. A
1678
- * descriptor's lifetime is observable only as the interval between the two calls that bound
1679
- * it. Reverting the fix (closing at the write, as the code did before) moves `close` above
1680
- * `rename` and this test fails, on tmpfs as readily as on overlayfs.
1681
- */
1682
- describe('write path — the installed inode is PINNED across the install check (#4908)', () => {
1683
- const override = () => join(worktree, AGENTS_OVERRIDE_FILENAME);
1684
- const ATTACKER = '# ATTACKER CONTENT — not what this deploy generated\n';
1685
- /**
1686
- * The temp path this deploy opened for `AGENTS.override.md`, taken from the timeline
1687
- * rather than guessed: the name carries a pid and six random bytes.
1688
- */
1689
- const tempPathFor = (artifact) => {
1690
- const opened = race.timeline
1691
- .filter((entry) => entry.startsWith('open '))
1692
- .map((entry) => entry.slice('open '.length))
1693
- .filter((path) => path.includes(`${artifact}.mx-tmp-`));
1694
- expect(opened).toHaveLength(1);
1695
- return opened[0];
1696
- };
1697
- /** `<artifact>.mx-tmp-<pid>-<hex>` back to `<artifact>` — the destination it renames to. */
1698
- const absPathOfTemp = (tmpPath) => tmpPath.replace(/\.mx-tmp-\d+-[0-9a-f]+$/, '');
1699
- /**
1700
- * RP12, executed. The attacker unlinks the artifact this deploy just installed and
1701
- * creates regular files until one takes its inode NUMBER back, then renames the winner
1702
- * over the artifact path. Losing probes are KEPT until the end for the reason RP14 gives:
1703
- * unlinking each one returns its number to the head of the free list and hands it
1704
- * straight back, so the target number never surfaces.
1705
- *
1706
- * ── WHERE THE ATTACK ACTUALLY RUNS (security review INFO-1) ──────────────────
1707
- * This docstring used to say the attacker moves "between `renameSync` and the verifying
1708
- * `lstatSync`". It does not. The `afterRename` hook fires INSIDE the mocked `renameSync`,
1709
- * before control returns to the write path and before `installed = true` — so what this
1710
- * test covers is an attacker who wins the race from the instant the directory entry is
1711
- * replaced, which is the earliest point the installed artifact is reachable by name and
1712
- * strictly harder for the deploy to survive than the real window. The real rename → `lstat`
1713
- * window is not reachable from any hook this harness exposes; it is pinned instead by the
1714
- * deterministic ordering test below (`close` after the verifying `lstat`, mutant M2).
1715
- *
1716
- * With the descriptor held open the allocator CANNOT return that number — which is the
1717
- * assertion — and the attacker's file therefore lands with a different one, fails the
1718
- * `{dev, ino}` comparison, fails the byte comparison in the benign-race acceptance behind
1719
- * it, and is reported as a failed write. Both halves are asserted: the number was not
1720
- * recycled, AND attacker content was never certified as this deploy's output.
1721
- */
1722
- it('MUST FIX: an attacker file that REUSES the installed inode number is NOT reported as written (RP12)', () => {
1723
- const PROBES = 64;
1724
- let installedIno = 0n;
1725
- let finalIno = 0n;
1726
- let reused = false;
1727
- let probesTried = 0;
1728
- race.afterRename = (destination) => {
1729
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1730
- return;
1731
- race.afterRename = null;
1732
- installedIno = lstatSync(destination, { bigint: true }).ino;
1733
- unlinkSync(destination);
1734
- const probes = [];
1735
- let winner = null;
1736
- for (let i = 0; i < PROBES && winner === null; i++) {
1737
- const probe = `${destination}.ino-probe-${i}`;
1738
- writeFileSync(probe, ATTACKER);
1739
- chmodSync(probe, 0o644);
1740
- probes.push(probe);
1741
- probesTried = i + 1;
1742
- if (lstatSync(probe, { bigint: true }).ino === installedIno)
1743
- winner = probe;
1744
- }
1745
- if (winner !== null) {
1746
- renameSync(winner, destination);
1747
- reused = true;
1748
- }
1749
- else {
1750
- // The allocator did not hand the number back. The attacker still installs the
1751
- // content — the deploy must refuse it either way, and this keeps the on-disk
1752
- // state identical in both arms so only the INODE differs between them.
1753
- writeFileSync(destination, ATTACKER);
1754
- chmodSync(destination, 0o644);
1755
- }
1756
- for (const probe of probes)
1757
- if (probe !== winner)
1758
- unlinkSync(probe);
1759
- finalIno = lstatSync(destination, { bigint: true }).ino;
1760
- };
1761
- const outcome = deploy();
1762
- race.afterRename = null;
1763
- // The attack was pressed all the way home: attacker content really is at the artifact
1764
- // path, so the only question left is what the deploy SAID about it.
1765
- expect(readFileSync(override(), 'utf-8')).toBe(ATTACKER);
1766
- // The property #4908 buys, stated directly: an open descriptor pins the inode, so the
1767
- // number this deploy installed was not available to any of the attacker's probes.
1768
- expect(reused).toBe(false);
1769
- expect(finalIno).not.toBe(installedIno);
1770
- expect(probesTried).toBe(PROBES);
1771
- // And the consequence: no false green. Before the fix this deploy reported ok=true with
1772
- // the artifact listed as written.
1773
- expect(outcome.ok).toBe(false);
1774
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1775
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1776
- });
1777
- /**
1778
- * The deterministic half. No attacker, no allocator, no filesystem dependency: an
1779
- * undisturbed deploy, asserting that the descriptor it opened for the temp file is still
1780
- * open when the install check reads the path — `open` → `rename` → the verifying `lstat`
1781
- * → `close`, in that order.
1782
- *
1783
- * The verifying `lstat` is identified as the first `lstat` of the DESTINATION after the
1784
- * rename; the walks before the rename lstat the same name, which is why the index is
1785
- * taken relative to the rename rather than absolutely.
1786
- *
1787
- * ── THIS IS THE SOLE GUARD AGAINST M2, AND IT COVERS ALL THREE ARTIFACTS ─────
1788
- * An independent QA mutation pass found that moving the `close` to AFTER the rename but
1789
- * BEFORE the verifying `lstat` (mutant M2) survives RP12 above. It has to: RP12's attacker
1790
- * runs from the `afterRename` hook, which fires INSIDE the mocked `renameSync` — earlier
1791
- * than the point M2 moves the `close` to — so the descriptor is still open when the probes
1792
- * run in both the mutated and unmutated builds. Nothing else in this file observes the
1793
- * rename → `lstat` window. Deleting or weakening the `iClose > iVerify` assertion below
1794
- * therefore drops #4908's regression guard silently, with the suite still green.
1795
- *
1796
- * So the ordering is asserted for EVERY artifact this deploy writes, not just
1797
- * `AGENTS.override.md`: M2 applied to any one of the three is caught.
1798
- */
1799
- it('MUST FIX: the temp descriptor is still open when the install check reads the path (#4908)', () => {
1800
- expect(deploy().ok).toBe(true);
1801
- for (const artifact of [
1802
- AGENTS_OVERRIDE_FILENAME,
1803
- CODEX_CONFIG_FILENAME,
1804
- CODEX_HOOKS_FILENAME,
1805
- ]) {
1806
- const tmpPath = tempPathFor(artifact);
1807
- const destination = absPathOfTemp(tmpPath);
1808
- const iOpen = race.timeline.indexOf(`open ${tmpPath}`);
1809
- const iRename = race.timeline.indexOf(`rename ${destination}`);
1810
- const iClose = race.timeline.indexOf(`close ${tmpPath}`);
1811
- const iVerify = race.timeline.findIndex((entry, index) => index > iRename && entry === `lstat ${destination}`);
1812
- expect(iOpen).toBeGreaterThanOrEqual(0);
1813
- expect(iRename).toBeGreaterThan(iOpen);
1814
- expect(iVerify).toBeGreaterThan(iRename);
1815
- // M2's pin, and the reason for the message: the verifying `lstat` — the one whose
1816
- // `{dev, ino}` the install check compares — must run BEFORE the descriptor is closed.
1817
- // Closing at the write, where this code closed before #4908, puts `close` above the
1818
- // `rename`; closing between the rename and the check (M2) leaves the inode number
1819
- // free for exactly the window the check occupies. Both are refused here.
1820
- expect(iClose, `${artifact}: close ran before the verifying lstat, so the inode was unpinned for the check`).toBeGreaterThan(iVerify);
1821
- }
1822
- });
1823
- /**
1824
- * The cost of moving a `close` into an outer `finally` is a descriptor leak if any path
1825
- * out of the function misses it. Both paths are checked: a clean deploy, and a deploy
1826
- * whose install check FAILS (the SF-I symlink substitution, which throws from the middle
1827
- * of the region the descriptor is now held across).
1828
- */
1829
- it('every temp descriptor this deploy opens is closed exactly once — honest path', () => {
1830
- expect(deploy().ok).toBe(true);
1831
- const temps = race.timeline
1832
- .filter((entry) => entry.startsWith('open ') && entry.includes('.mx-tmp-'))
1833
- .map((entry) => entry.slice('open '.length));
1834
- expect(temps.length).toBe(3);
1835
- for (const tmp of temps) {
1836
- expect(race.timeline.filter((entry) => entry === `close ${tmp}`)).toHaveLength(1);
1837
- }
1838
- });
1839
- it('every temp descriptor this deploy opens is closed exactly once — failed install', () => {
1840
- const decoy = join(root, 'decoy.md');
1841
- writeFileSync(decoy, ATTACKER);
1842
- race.afterWrite = (tmpPath) => {
1843
- if (!tmpPath.includes(`${AGENTS_OVERRIDE_FILENAME}.mx-tmp-`))
1844
- return;
1845
- race.afterWrite = null;
1846
- // The SF-I substitution: the temp path is replaced with a symlink between the write
1847
- // and the rename, so `renameSync` installs the attacker's entry and the install
1848
- // check throws — from inside the region the descriptor is now held across.
1849
- unlinkSync(tmpPath);
1850
- symlinkSync(decoy, tmpPath);
1851
- };
1852
- const outcome = deploy();
1853
- race.afterWrite = null;
1854
- expect(outcome.ok).toBe(false);
1855
- expect(outcome.writeFailures.join('\n')).toContain('a SYMLINK');
1856
- const temps = race.timeline
1857
- .filter((entry) => entry.startsWith('open ') && entry.includes('.mx-tmp-'))
1858
- .map((entry) => entry.slice('open '.length));
1859
- expect(temps.length).toBeGreaterThan(0);
1860
- for (const tmp of temps) {
1861
- expect(race.timeline.filter((entry) => entry === `close ${tmp}`)).toHaveLength(1);
1862
- }
1863
- });
1864
- /**
1865
- * ── THE `close` ITSELF MUST STILL BE ABLE TO FAIL THE WRITE (#4908 round 2) ───
1866
- * Moving the `close` into an outer `finally` came with a `catch {}` that suppressed EVERY
1867
- * `close` error. That was a fail-closed → fail-open REGRESSION: before #4908 the `close`
1868
- * sat in an inner `finally` with no `catch`, so a failure PROPAGATED and the artifact was
1869
- * reported as a FAILED write. Measured on the first version of the fix, with `closeSync`
1870
- * forced to EIO on `.mx-tmp-` descriptors — FIXED: `ok=true`, all three artifacts listed
1871
- * as WRITTEN, no failures; PARENT commit: `ok=false`, nothing written, and a failure
1872
- * naming the EIO. And mutating production `closeSync` to throw unconditionally passed all
1873
- * 55 tests in this file — nothing observed it at all.
1874
- *
1875
- * `close` is where DEFERRED WRITE-BACK errors surface (ENOSPC, EDQUOT, EIO, ESTALE, and
1876
- * on Linux any error recorded against the file since the open), so suppressing it on the
1877
- * SUCCESS path means the deploy's own bytes never reached the disk and the deploy said
1878
- * the artifact was written. `AGENTS.override.md` REPLACES `AGENTS.md`, so the end state is
1879
- * a worktree launching on a truncated or empty instruction file, certified green.
1880
- *
1881
- * This is the test that kills the always-throw mutation.
1882
- */
1883
- it('MUST FIX: a `close` that FAILS on the honest path is a FAILED write, not a written one', () => {
1884
- let closesFailed = 0;
1885
- race.onClose = (path) => {
1886
- if (!path.includes(`${AGENTS_OVERRIDE_FILENAME}.mx-tmp-`))
1887
- return;
1888
- closesFailed += 1;
1889
- const err = new Error('EIO: i/o error, close');
1890
- err.code = 'EIO';
1891
- throw err;
1892
- };
1893
- const outcome = deploy();
1894
- race.onClose = null;
1895
- // Nothing else went wrong: the rename landed, the install check passed, and the ONLY
1896
- // thing that failed is the `close`. So this asserts the `close` alone can fail a write.
1897
- expect(closesFailed).toBe(1);
1898
- expect(existsSync(override())).toBe(true);
1899
- expect(outcome.ok).toBe(false);
1900
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1901
- const failure = outcome.writeFailures.join('\n');
1902
- expect(failure).toContain('could not be closed');
1903
- expect(failure).toContain('EIO');
1904
- expect(failure).toContain('Treating the write as FAILED');
1905
- // The report is MIXED-STATE, not all-or-nothing: the two artifacts whose descriptors
1906
- // closed cleanly are still reported as written (#4896/#4897).
1907
- expect(outcome.written).toContain(CODEX_CONFIG_FILENAME);
1908
- expect(outcome.written).toContain(CODEX_HOOKS_FILENAME);
1909
- });
1910
- /**
1911
- * The other half of the same rule, and the reason the suppression exists at all. On a
1912
- * FAILURE path an error is already propagating, and an exception thrown from a `finally`
1913
- * REPLACES it — so rethrowing a `close` failure there would discard the refusal text
1914
- * naming what is really on disk, which is the mixed-state lie #4896/#4897 exist to remove.
1915
- *
1916
- * Both things fail at once here: the SF-I symlink substitution makes the install check
1917
- * throw, AND the `close` of that same descriptor fails. The report must be the SYMLINK.
1918
- */
1919
- it('a `close` that fails on a FAILURE path does not replace the refusal that is propagating', () => {
1920
- const decoy = join(root, 'decoy.md');
1921
- writeFileSync(decoy, ATTACKER);
1922
- let closesFailed = 0;
1923
- race.afterWrite = (tmpPath) => {
1924
- if (!tmpPath.includes(`${AGENTS_OVERRIDE_FILENAME}.mx-tmp-`))
1925
- return;
1926
- race.afterWrite = null;
1927
- unlinkSync(tmpPath);
1928
- symlinkSync(decoy, tmpPath);
1929
- };
1930
- race.onClose = (path) => {
1931
- if (!path.includes(`${AGENTS_OVERRIDE_FILENAME}.mx-tmp-`))
1932
- return;
1933
- closesFailed += 1;
1934
- const err = new Error('EIO: i/o error, close');
1935
- err.code = 'EIO';
1936
- throw err;
1937
- };
1938
- const outcome = deploy();
1939
- race.afterWrite = null;
1940
- race.onClose = null;
1941
- expect(closesFailed).toBe(1);
1942
- expect(outcome.ok).toBe(false);
1943
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1944
- const failure = outcome.writeFailures.join('\n');
1945
- // The ORIGINAL refusal survives, naming what is really at the artifact path…
1946
- expect(failure).toContain('a SYMLINK');
1947
- expect(failure).toContain('NOT the file this deploy wrote');
1948
- // …and is not overwritten by the `close` failure that happened on the way out.
1949
- expect(failure).not.toContain('could not be closed');
1950
- });
1951
- /**
1952
- * ── M3: HALF OF A TWO-FIELD IDENTITY IS NOT AN IDENTITY (coverage gap) ───────
1953
- * An independent QA mutation pass found that weakening the primary install check to
1954
- * `landed.ino !== opened.ino` — dropping the `landed.dev !== opened.dev` half — SURVIVED
1955
- * every one of the five tests #4908 added. It was caught only incidentally, by the
1956
- * pre-existing round-8 test `SF-C: an open descriptor on another DEVICE with the same
1957
- * inode number is refused`, which lives in a different describe block and could be deleted
1958
- * or rewritten without anyone noticing that #4908's regression guard went with it.
1959
- *
1960
- * It matters HERE because `dev` is what the pinned descriptor is compared on. The whole
1961
- * point of holding the fd open is that `{dev, ino}` names the object this deploy installed;
1962
- * an inode number on its own is exactly the non-identity #4908 exists to stop trusting,
1963
- * and every other substitution in this file also changes the number, so `ino` covers for
1964
- * `dev` in all of them. This is the one state it cannot: same number, different device.
1965
- */
1966
- it('M3: an entry with the installed inode NUMBER on a different DEVICE is not reported as written', () => {
1967
- let fired = false;
1968
- let realDev = 0n;
1969
- let realIno = 0n;
1970
- race.afterRename = (destination) => {
1971
- if (!destination.endsWith(AGENTS_OVERRIDE_FILENAME))
1972
- return;
1973
- race.afterRename = null;
1974
- race.onLstat = (p, real, bigint) => {
1975
- if (fired || p !== destination || !bigint)
1976
- return undefined;
1977
- fired = true;
1978
- realDev = real.dev;
1979
- realIno = real.ino;
1980
- return statReporting(real, { dev: realDev + 1n });
1981
- };
1982
- };
1983
- const outcome = deploy();
1984
- race.onLstat = null;
1985
- expect(fired).toBe(true);
1986
- // The `ino` half AGREES — nothing moved the file — so only the `dev` half can refuse.
1987
- const now = lstatSync(override(), { bigint: true });
1988
- expect(now.ino).toBe(realIno);
1989
- expect(now.dev).toBe(realDev);
1990
- expect(outcome.ok).toBe(false);
1991
- expect(outcome.written).not.toContain(AGENTS_OVERRIDE_FILENAME);
1992
- expect(outcome.writeFailures.join('\n')).toContain('NOT the file this deploy wrote');
1993
- });
1994
- /**
1995
- * The honest path is unchanged. Holding a descriptor open changes nothing an operator or
1996
- * a second deploy can observe: the artifacts are written, with the right bytes and the
1997
- * right mode, and the benign concurrent-redeploy acceptance (SF-L) still accepts.
1998
- */
1999
- it('an undisturbed deploy still writes all three artifacts, unchanged', () => {
2000
- const outcome = deploy();
2001
- expect(outcome.ok).toBe(true);
2002
- expect(outcome.written).toContain(AGENTS_OVERRIDE_FILENAME);
2003
- expect(outcome.written).toContain(CODEX_CONFIG_FILENAME);
2004
- expect(outcome.written).toContain(CODEX_HOOKS_FILENAME);
2005
- expect(outcome.writeFailures).toEqual([]);
2006
- expect(outcome.writeRefusals).toEqual([]);
2007
- expect(lstatSync(override()).isFile()).toBe(true);
2008
- expect(lstatSync(override()).mode & 0o777).toBe(0o644);
2009
- expect(readdirSync(join(worktree, '.codex')).filter((e) => e.includes('.mx-tmp-'))).toEqual([]);
2010
- // The deploy is repeatable: a redeploy over its own output succeeds too.
2011
- expect(deploy().ok).toBe(true);
2012
- });
2013
- });
2014
- /**
2015
- * ─────── SF-K (round 7): THE RESIDUAL IS DECLARED, SO IT MUST BE FINDABLE ─────
2016
- * The residual this write path cannot close: `<worktree>/.codex` is swapped for a symlink
2017
- * to the main repo's `.codex` before the `open`, and RESTORED before the first identity
2018
- * check. Both checks then pass — every `lstat` of the name sees the original directory —
2019
- * but the temp file was created behind the swapped name, so its ~1301 bytes are in the
2020
- * MAIN REPO, the `rename` resolves the temp name in the restored directory and fails
2021
- * ENOENT, and the cleanup `unlink` misses for the same reason. Measured 1 in 6,000 deploys
2022
- * at a 5-microsecond swapper hold.
2023
- *
2024
- * The deploy already fails closed and reports nothing as written; what it did not do was
2025
- * say WHERE the litter is, so an operator had no way to find it. These tests pin the
2026
- * reporting. They do not claim the residual is closed — closing it needs `openat`, which
2027
- * Node does not expose.
2028
- *
2029
- * The restore is timed off the first identity check's `lstat`, which is the moment the
2030
- * measured attack has to hit.
2031
- */
2032
- describe('write path — a temp file that outlives the deploy is NAMED (SF-K)', () => {
2033
- it('the swap-and-restore residual reports the temp path it left in the main repo', () => {
2034
- expect(deploy().ok).toBe(true);
2035
- let restored = false;
2036
- race.beforeOpen = (path) => {
2037
- if (!path.includes('hooks.json.mx-tmp-'))
2038
- return;
2039
- race.beforeOpen = null;
2040
- // Swapped: this `openSync` creates the temp inside the MAIN repo's .codex.
2041
- swapCodexDirForASymlinkToMainRepo();
2042
- race.onLstat = (p, _real, bigint) => {
2043
- if (restored || p !== join(worktree, '.codex') || !bigint)
2044
- return undefined;
2045
- // Restored before the first identity check looks — so the check sees the original
2046
- // directory, agrees, and the deploy proceeds with a temp file it can no longer name.
2047
- restored = true;
2048
- restoreCodexDir();
2049
- return lstatSync(p, { bigint: true });
2050
- };
2051
- };
2052
- const outcome = deploy();
2053
- race.onLstat = null;
2054
- expect(restored).toBe(true);
2055
- const temps = mainRepoTemps();
2056
- expect(temps).toHaveLength(1);
2057
- expect(outcome.ok).toBe(false);
2058
- const report = [...outcome.writeFailures, ...outcome.writeRefusals].join('\n');
2059
- expect(report).toContain('LEFT BEHIND');
2060
- // The whole point: the operator can find the file. The reported path is the name the
2061
- // deploy used — the same basename, in the directory the operator must now look in.
2062
- expect(report).toContain(join(worktree, '.codex', temps[0]));
2063
- expect(report).toContain('the cleanup unlink found NOTHING at that name');
2064
- // Stated as the residual it is, in the corrected wording: inert, not live.
2065
- expect(report).toContain('no bytes reach a LIVE path outside the worktree');
2066
- expect(report).toContain('bytes can reach an INERT one');
2067
- // The main repo's own fleet-wide file is untouched — this is litter, not a write.
2068
- expect(readFileSync(join(mainCodex, 'hooks.json'), 'utf-8')).toBe(MAIN_HOOKS_SENTINEL);
2069
- unlinkSync(join(mainCodex, temps[0]));
2070
- });
2071
- /**
2072
- * ── INFO-2 (round 8): NOT SAID WHEN THE FILE IS GONE ────────────────────────
2073
- * The parent directory moved, so the note used to fire — but the cleanup `unlink`
2074
- * SUCCEEDED (it followed the swapped name and removed the temp), so there is nothing
2075
- * left behind and the operator was being sent to hunt for a file that does not exist.
2076
- */
2077
- it('a refusal whose cleanup unlink SUCCEEDED says nothing about a file left behind', () => {
2078
- expect(deploy().ok).toBe(true);
2079
- race.beforeOpen = (path) => {
2080
- if (!path.includes('hooks.json.mx-tmp-'))
2081
- return;
2082
- race.beforeOpen = null;
2083
- swapCodexDirForASymlinkToMainRepo();
2084
- };
2085
- const outcome = deploy();
2086
- restoreCodexDir();
2087
- expect(outcome.ok).toBe(false);
2088
- const refusal = outcome.writeRefusals.join('\n');
2089
- expect(refusal).toContain('was REPLACED');
2090
- expect(refusal).not.toContain('LEFT BEHIND');
2091
- // And the claim is true: the temp file really is gone from where it was created.
2092
- expect(mainRepoTemps()).toEqual([]);
2093
- });
2094
- /**
2095
- * The parent moved AND the cleanup missed — the note fires, and it says BOTH reasons.
2096
- * `.codex` is swapped for a symlink to the main repo (so the temp is created there) and
2097
- * then replaced with a fresh empty directory before the first identity check: the check
2098
- * refuses, the unlink resolves into the new directory and finds nothing, and the temp is
2099
- * still sitting in the main repo where only this note can point an operator at it.
2100
- */
2101
- it('a refusal whose cleanup MISSED names the temp path and both reasons', () => {
2102
- expect(deploy().ok).toBe(true);
2103
- const codexDir = join(worktree, '.codex');
2104
- let replaced = false;
2105
- race.beforeOpen = (path) => {
2106
- if (!path.includes('hooks.json.mx-tmp-'))
2107
- return;
2108
- race.beforeOpen = null;
2109
- swapCodexDirForASymlinkToMainRepo();
2110
- race.onLstat = (p, _real, bigint) => {
2111
- if (replaced || p !== codexDir || !bigint)
2112
- return undefined;
2113
- replaced = true;
2114
- unlinkSync(codexDir);
2115
- mkdirSync(codexDir);
2116
- return undefined;
2117
- };
2118
- };
2119
- const outcome = deploy();
2120
- race.onLstat = null;
2121
- expect(replaced).toBe(true);
2122
- expect(outcome.ok).toBe(false);
2123
- const refusal = outcome.writeRefusals.join('\n');
2124
- expect(refusal).toContain('LEFT BEHIND');
2125
- expect(refusal).toMatch(/hooks\.json\.mx-tmp-\d+-[0-9a-f]+/);
2126
- expect(refusal).toContain('is no longer the one this deploy checked');
2127
- expect(refusal).toContain('the cleanup unlink found NOTHING at that name');
2128
- const temps = mainRepoTemps();
2129
- expect(temps).toHaveLength(1);
2130
- rmSync(codexDir, { recursive: true });
2131
- renameSync(`${codexDir}.real`, codexDir);
2132
- unlinkSync(join(mainCodex, temps[0]));
2133
- });
2134
- it('an ordinary deploy says nothing about temp files, because there are none', () => {
2135
- const outcome = deploy();
2136
- expect(outcome.ok).toBe(true);
2137
- expect(outcome.lines.map((l) => l.text).join('\n')).not.toContain('LEFT BEHIND');
2138
- expect(mainRepoTemps()).toEqual([]);
2139
- expect(readdirSync(join(worktree, '.codex')).filter((e) => e.includes('.mx-tmp-'))).toEqual([]);
2140
- });
2141
- });
2142
- /**
2143
- * MUTANT M8, ASSERTED ON BEHAVIOUR RATHER THAN ON SOURCE TEXT (round 5 recommendation).
2144
- *
2145
- * The property is that the destination is never destroyed before a replacement exists —
2146
- * the defect that left 2466 of 2500 racing deploys with a ZERO-BYTE AGENTS.override.md,
2147
- * which Codex reads INSTEAD of AGENTS.md. The old proof grepped `codex-config.ts` for
2148
- * `unlinkSync(absPath)`, which passes for any spelling the grep does not anticipate. This
2149
- * one records every `unlinkSync` the deploy actually performs. Temp-path unlinks are
2150
- * expected — that is the litter cleanup — so the assertion is specifically that no
2151
- * DESTINATION path is ever unlinked.
2152
- */
2153
- describe('write path — the destination is never unlinked (mutant M8, behaviourally)', () => {
2154
- const destinations = () => [CODEX_CONFIG_FILENAME, CODEX_HOOKS_FILENAME, AGENTS_OVERRIDE_FILENAME].map((rel) => join(worktree, rel));
2155
- it('a first deploy unlinks no destination', () => {
2156
- expect(deploy().ok).toBe(true);
2157
- expect(race.unlinked.filter((p) => destinations().includes(p))).toEqual([]);
2158
- });
2159
- it('a REDEPLOY over existing artifacts unlinks no destination either', () => {
2160
- expect(deploy().ok).toBe(true);
2161
- race.unlinked = [];
2162
- expect(deploy().ok).toBe(true);
2163
- expect(race.unlinked.filter((p) => destinations().includes(p))).toEqual([]);
2164
- // And every unlink that did happen was of a temp path.
2165
- for (const path of race.unlinked)
2166
- expect(path).toContain('.mx-tmp-');
2167
- });
2168
- it('a deploy whose write FAILS unlinks its temp, and still not the destination', () => {
2169
- expect(deploy().ok).toBe(true);
2170
- const hooks = join(worktree, CODEX_HOOKS_FILENAME);
2171
- const before = readFileSync(hooks, 'utf-8');
2172
- race.unlinked = [];
2173
- race.afterWrite = (tmpPath) => {
2174
- if (!tmpPath.includes('hooks.json.mx-tmp-'))
2175
- return;
2176
- race.afterWrite = null;
2177
- // Force the rename to fail: make the containment identity check refuse.
2178
- swapCodexDirForASymlinkToMainRepo();
2179
- };
2180
- expect(deploy().ok).toBe(false);
2181
- restoreCodexDir();
2182
- expect(race.unlinked.filter((p) => destinations().includes(p))).toEqual([]);
2183
- expect(readFileSync(hooks, 'utf-8')).toBe(before);
2184
- });
2185
- });
2186
- /**
2187
- * Gap 2 — the LAUNCH path must enforce what the deploy path already reports.
2188
- *
2189
- * `CodexAdapter.deployConfig` printed the mixed-state warning and returned. Executed with
2190
- * `MX_AGENT_CODEX_PHASE1_DEV=1` (the documented hatch, and the only way a Codex session
2191
- * runs while G-7 is unpassed): a deploy in which ALL THREE artifacts failed printed
2192
- * `DEPLOY FAILED … must not be launched`, and `assertLaunchAllowed` then returned ALLOWED.
2193
- * The session would have started with no containment guards, no declared sandbox_mode or
2194
- * approval_policy, and no MemNexus MCP server.
2195
- */
2196
- describe('launch path — a failed write is a failed deploy', () => {
2197
- const launchContext = () => ({
2198
- worktreePath: worktree,
2199
- worktreeName: `${TEAM}-20260101`,
2200
- branch: 'demo-branch',
2201
- slot: 0,
2202
- teamName: TEAM,
2203
- baseBranch: 'main',
2204
- initialPrompt: 'x',
2205
- });
2206
- const adapter = async () => {
2207
- const { CodexAdapter } = await import('../lib/runtime/codex-adapter.js');
2208
- return new CodexAdapter({ projectRoot: root });
2209
- };
2210
- it('deployConfig REFUSES when an artifact could not be written', async () => {
2211
- // A directory where hooks.json belongs: the write fails, the deploy reports it, and
2212
- // the launch must not proceed on the remaining two artifacts.
2213
- mkdirSync(join(worktree, CODEX_HOOKS_FILENAME), { recursive: true });
2214
- writeFileSync(join(worktree, CODEX_HOOKS_FILENAME, 'occupant'), 'x');
2215
- const codex = await adapter();
2216
- expect(() => codex.deployConfig(launchContext())).toThrow(/refusing to launch --runtime codex/);
2217
- });
2218
- it('the refusal carries the MEASURED state, not a restatement of the failure count', async () => {
2219
- mkdirSync(join(worktree, CODEX_HOOKS_FILENAME), { recursive: true });
2220
- writeFileSync(join(worktree, CODEX_HOOKS_FILENAME, 'occupant'), 'x');
2221
- const codex = await adapter();
2222
- let message = '';
2223
- try {
2224
- codex.deployConfig(launchContext());
2225
- }
2226
- catch (err) {
2227
- message = err instanceof Error ? err.message : String(err);
2228
- }
2229
- expect(message).toContain('must not be launched');
2230
- expect(message).toMatch(/hooks\.json: a DIRECTORY, not a file/);
2231
- });
2232
- it('a CONTAINMENT refusal refuses the launch as well as an I/O failure', async () => {
2233
- mkdirSync(join(worktree, '.codex'), { recursive: true });
2234
- symlinkSync(join(root, AGENTS_OVERRIDE_FILENAME), join(worktree, AGENTS_OVERRIDE_FILENAME));
2235
- const codex = await adapter();
2236
- expect(() => codex.deployConfig(launchContext())).toThrow(/refusing to launch --runtime codex/);
2237
- expect(readFileSync(join(root, AGENTS_OVERRIDE_FILENAME), 'utf-8')).toBe(MAIN_OVERRIDE_SENTINEL);
2238
- });
2239
- it('the happy path still deploys and does not throw', async () => {
2240
- const codex = await adapter();
2241
- expect(() => codex.deployConfig(launchContext())).not.toThrow();
2242
- for (const rel of [CODEX_CONFIG_FILENAME, CODEX_HOOKS_FILENAME, AGENTS_OVERRIDE_FILENAME]) {
2243
- expect(existsSync(join(worktree, rel))).toBe(true);
2244
- }
2245
- });
2246
- it('a 0000 artifact does not survive a deploy, so the guards it registers can be read', () => {
2247
- expect(deploy().ok).toBe(true);
2248
- chmodSync(join(worktree, CODEX_HOOKS_FILENAME), 0o000);
2249
- expect(deploy().ok).toBe(true);
2250
- expect(lstatSync(join(worktree, CODEX_HOOKS_FILENAME)).mode & 0o400).toBe(0o400);
2251
- });
2252
- });
2253
- //# sourceMappingURL=codex-write-race.test.js.map