@memnexus-ai/mx-agent-cli 0.1.296 → 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/standards/decision-request.md +6 -57
  6. package/dist/standards/po-communication-standard.md +0 -34
  7. package/dist/standards/report-format.md +0 -90
  8. package/dist/standards/writing-standard.md +0 -312
  9. package/package.json +3 -1
  10. package/dist/__tests__/agent-attribution.test.d.ts +0 -16
  11. package/dist/__tests__/agent-attribution.test.d.ts.map +0 -1
  12. package/dist/__tests__/agent-attribution.test.js +0 -250
  13. package/dist/__tests__/agent-attribution.test.js.map +0 -1
  14. package/dist/__tests__/agents-md-canonicalization.test.d.ts +0 -23
  15. package/dist/__tests__/agents-md-canonicalization.test.d.ts.map +0 -1
  16. package/dist/__tests__/agents-md-canonicalization.test.js +0 -319
  17. package/dist/__tests__/agents-md-canonicalization.test.js.map +0 -1
  18. package/dist/__tests__/behavioral-compliance.test.d.ts +0 -8
  19. package/dist/__tests__/behavioral-compliance.test.d.ts.map +0 -1
  20. package/dist/__tests__/behavioral-compliance.test.js +0 -226
  21. package/dist/__tests__/behavioral-compliance.test.js.map +0 -1
  22. package/dist/__tests__/behavioral-extraction.test.d.ts +0 -12
  23. package/dist/__tests__/behavioral-extraction.test.d.ts.map +0 -1
  24. package/dist/__tests__/behavioral-extraction.test.js +0 -330
  25. package/dist/__tests__/behavioral-extraction.test.js.map +0 -1
  26. package/dist/__tests__/behavioral-git-read.test.d.ts +0 -21
  27. package/dist/__tests__/behavioral-git-read.test.d.ts.map +0 -1
  28. package/dist/__tests__/behavioral-git-read.test.js +0 -955
  29. package/dist/__tests__/behavioral-git-read.test.js.map +0 -1
  30. package/dist/__tests__/behavioral-injection.test.d.ts +0 -13
  31. package/dist/__tests__/behavioral-injection.test.d.ts.map +0 -1
  32. package/dist/__tests__/behavioral-injection.test.js +0 -384
  33. package/dist/__tests__/behavioral-injection.test.js.map +0 -1
  34. package/dist/__tests__/binary-smoke.test.d.ts +0 -12
  35. package/dist/__tests__/binary-smoke.test.d.ts.map +0 -1
  36. package/dist/__tests__/binary-smoke.test.js +0 -88
  37. package/dist/__tests__/binary-smoke.test.js.map +0 -1
  38. package/dist/__tests__/bootstrap-behavioral-contract.test.d.ts +0 -18
  39. package/dist/__tests__/bootstrap-behavioral-contract.test.d.ts.map +0 -1
  40. package/dist/__tests__/bootstrap-behavioral-contract.test.js +0 -104
  41. package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +0 -1
  42. package/dist/__tests__/bundle-config.test.d.ts +0 -18
  43. package/dist/__tests__/bundle-config.test.d.ts.map +0 -1
  44. package/dist/__tests__/bundle-config.test.js +0 -123
  45. package/dist/__tests__/bundle-config.test.js.map +0 -1
  46. package/dist/__tests__/catalog-interaction.test.d.ts +0 -25
  47. package/dist/__tests__/catalog-interaction.test.d.ts.map +0 -1
  48. package/dist/__tests__/catalog-interaction.test.js +0 -269
  49. package/dist/__tests__/catalog-interaction.test.js.map +0 -1
  50. package/dist/__tests__/catalog-named-memories.test.d.ts +0 -2
  51. package/dist/__tests__/catalog-named-memories.test.d.ts.map +0 -1
  52. package/dist/__tests__/catalog-named-memories.test.js +0 -204
  53. package/dist/__tests__/catalog-named-memories.test.js.map +0 -1
  54. package/dist/__tests__/catalog-origin-main.test.d.ts +0 -15
  55. package/dist/__tests__/catalog-origin-main.test.d.ts.map +0 -1
  56. package/dist/__tests__/catalog-origin-main.test.js +0 -305
  57. package/dist/__tests__/catalog-origin-main.test.js.map +0 -1
  58. package/dist/__tests__/catalog.test.d.ts +0 -2
  59. package/dist/__tests__/catalog.test.d.ts.map +0 -1
  60. package/dist/__tests__/catalog.test.js +0 -131
  61. package/dist/__tests__/catalog.test.js.map +0 -1
  62. package/dist/__tests__/claude-local-sanitizer.test.d.ts +0 -24
  63. package/dist/__tests__/claude-local-sanitizer.test.d.ts.map +0 -1
  64. package/dist/__tests__/claude-local-sanitizer.test.js +0 -906
  65. package/dist/__tests__/claude-local-sanitizer.test.js.map +0 -1
  66. package/dist/__tests__/claude-md-compose.test.d.ts +0 -17
  67. package/dist/__tests__/claude-md-compose.test.d.ts.map +0 -1
  68. package/dist/__tests__/claude-md-compose.test.js +0 -119
  69. package/dist/__tests__/claude-md-compose.test.js.map +0 -1
  70. package/dist/__tests__/claude-sync.test.d.ts +0 -2
  71. package/dist/__tests__/claude-sync.test.d.ts.map +0 -1
  72. package/dist/__tests__/claude-sync.test.js +0 -571
  73. package/dist/__tests__/claude-sync.test.js.map +0 -1
  74. package/dist/__tests__/cli-build-integration.test.d.ts +0 -2
  75. package/dist/__tests__/cli-build-integration.test.d.ts.map +0 -1
  76. package/dist/__tests__/cli-build-integration.test.js +0 -64
  77. package/dist/__tests__/cli-build-integration.test.js.map +0 -1
  78. package/dist/__tests__/cli-build.test.d.ts +0 -2
  79. package/dist/__tests__/cli-build.test.d.ts.map +0 -1
  80. package/dist/__tests__/cli-build.test.js +0 -640
  81. package/dist/__tests__/cli-build.test.js.map +0 -1
  82. package/dist/__tests__/codex-agent-gate.test.d.ts +0 -2
  83. package/dist/__tests__/codex-agent-gate.test.d.ts.map +0 -1
  84. package/dist/__tests__/codex-agent-gate.test.js +0 -480
  85. package/dist/__tests__/codex-agent-gate.test.js.map +0 -1
  86. package/dist/__tests__/codex-deploy-config.test.d.ts +0 -2
  87. package/dist/__tests__/codex-deploy-config.test.d.ts.map +0 -1
  88. package/dist/__tests__/codex-deploy-config.test.js +0 -1230
  89. package/dist/__tests__/codex-deploy-config.test.js.map +0 -1
  90. package/dist/__tests__/codex-trust-keys.test.d.ts +0 -2
  91. package/dist/__tests__/codex-trust-keys.test.d.ts.map +0 -1
  92. package/dist/__tests__/codex-trust-keys.test.js +0 -731
  93. package/dist/__tests__/codex-trust-keys.test.js.map +0 -1
  94. package/dist/__tests__/codex-write-race.test.d.ts +0 -2
  95. package/dist/__tests__/codex-write-race.test.d.ts.map +0 -1
  96. package/dist/__tests__/codex-write-race.test.js +0 -2253
  97. package/dist/__tests__/codex-write-race.test.js.map +0 -1
  98. package/dist/__tests__/completion-rows-discriminate.test.d.ts +0 -20
  99. package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +0 -1
  100. package/dist/__tests__/completion-rows-discriminate.test.js +0 -481
  101. package/dist/__tests__/completion-rows-discriminate.test.js.map +0 -1
  102. package/dist/__tests__/config-command.test.d.ts +0 -9
  103. package/dist/__tests__/config-command.test.d.ts.map +0 -1
  104. package/dist/__tests__/config-command.test.js +0 -75
  105. package/dist/__tests__/config-command.test.js.map +0 -1
  106. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +0 -2
  107. package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +0 -1
  108. package/dist/__tests__/config-fidelity-archived-symlinks.test.js +0 -127
  109. package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +0 -1
  110. package/dist/__tests__/config-fidelity-display.test.d.ts +0 -2
  111. package/dist/__tests__/config-fidelity-display.test.d.ts.map +0 -1
  112. package/dist/__tests__/config-fidelity-display.test.js +0 -77
  113. package/dist/__tests__/config-fidelity-display.test.js.map +0 -1
  114. package/dist/__tests__/config-fidelity-unreadable-fixture.d.ts +0 -32
  115. package/dist/__tests__/config-fidelity-unreadable-fixture.d.ts.map +0 -1
  116. package/dist/__tests__/config-fidelity-unreadable-fixture.js +0 -37
  117. package/dist/__tests__/config-fidelity-unreadable-fixture.js.map +0 -1
  118. package/dist/__tests__/config-fidelity.test.d.ts +0 -16
  119. package/dist/__tests__/config-fidelity.test.d.ts.map +0 -1
  120. package/dist/__tests__/config-fidelity.test.js +0 -2679
  121. package/dist/__tests__/config-fidelity.test.js.map +0 -1
  122. package/dist/__tests__/config-generation-gate.test.d.ts +0 -46
  123. package/dist/__tests__/config-generation-gate.test.d.ts.map +0 -1
  124. package/dist/__tests__/config-generation-gate.test.js +0 -435
  125. package/dist/__tests__/config-generation-gate.test.js.map +0 -1
  126. package/dist/__tests__/config-generation.test.d.ts +0 -7
  127. package/dist/__tests__/config-generation.test.d.ts.map +0 -1
  128. package/dist/__tests__/config-generation.test.js +0 -141
  129. package/dist/__tests__/config-generation.test.js.map +0 -1
  130. package/dist/__tests__/config-sync.test.d.ts +0 -10
  131. package/dist/__tests__/config-sync.test.d.ts.map +0 -1
  132. package/dist/__tests__/config-sync.test.js +0 -268
  133. package/dist/__tests__/config-sync.test.js.map +0 -1
  134. package/dist/__tests__/coordination-401-production-wiring.test.d.ts +0 -19
  135. package/dist/__tests__/coordination-401-production-wiring.test.d.ts.map +0 -1
  136. package/dist/__tests__/coordination-401-production-wiring.test.js +0 -286
  137. package/dist/__tests__/coordination-401-production-wiring.test.js.map +0 -1
  138. package/dist/__tests__/coordination-401-recovery.test.d.ts +0 -22
  139. package/dist/__tests__/coordination-401-recovery.test.d.ts.map +0 -1
  140. package/dist/__tests__/coordination-401-recovery.test.js +0 -601
  141. package/dist/__tests__/coordination-401-recovery.test.js.map +0 -1
  142. package/dist/__tests__/coordination-brief-pin.test.d.ts +0 -20
  143. package/dist/__tests__/coordination-brief-pin.test.d.ts.map +0 -1
  144. package/dist/__tests__/coordination-brief-pin.test.js +0 -66
  145. package/dist/__tests__/coordination-brief-pin.test.js.map +0 -1
  146. package/dist/__tests__/coordination-brief.test.d.ts +0 -9
  147. package/dist/__tests__/coordination-brief.test.d.ts.map +0 -1
  148. package/dist/__tests__/coordination-brief.test.js +0 -290
  149. package/dist/__tests__/coordination-brief.test.js.map +0 -1
  150. package/dist/__tests__/coordination-client.test.d.ts +0 -9
  151. package/dist/__tests__/coordination-client.test.d.ts.map +0 -1
  152. package/dist/__tests__/coordination-client.test.js +0 -517
  153. package/dist/__tests__/coordination-client.test.js.map +0 -1
  154. package/dist/__tests__/coordination-command.test.d.ts +0 -9
  155. package/dist/__tests__/coordination-command.test.d.ts.map +0 -1
  156. package/dist/__tests__/coordination-command.test.js +0 -1082
  157. package/dist/__tests__/coordination-command.test.js.map +0 -1
  158. package/dist/__tests__/coordination-credential-endpoint.test.d.ts +0 -24
  159. package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +0 -1
  160. package/dist/__tests__/coordination-credential-endpoint.test.js +0 -1292
  161. package/dist/__tests__/coordination-credential-endpoint.test.js.map +0 -1
  162. package/dist/__tests__/coordination-expected-team.test.d.ts +0 -19
  163. package/dist/__tests__/coordination-expected-team.test.d.ts.map +0 -1
  164. package/dist/__tests__/coordination-expected-team.test.js +0 -423
  165. package/dist/__tests__/coordination-expected-team.test.js.map +0 -1
  166. package/dist/__tests__/coordination-fallback.test.d.ts +0 -9
  167. package/dist/__tests__/coordination-fallback.test.d.ts.map +0 -1
  168. package/dist/__tests__/coordination-fallback.test.js +0 -192
  169. package/dist/__tests__/coordination-fallback.test.js.map +0 -1
  170. package/dist/__tests__/coordination-file-guards.test.d.ts +0 -29
  171. package/dist/__tests__/coordination-file-guards.test.d.ts.map +0 -1
  172. package/dist/__tests__/coordination-file-guards.test.js +0 -380
  173. package/dist/__tests__/coordination-file-guards.test.js.map +0 -1
  174. package/dist/__tests__/coordination-history.test.d.ts +0 -8
  175. package/dist/__tests__/coordination-history.test.d.ts.map +0 -1
  176. package/dist/__tests__/coordination-history.test.js +0 -447
  177. package/dist/__tests__/coordination-history.test.js.map +0 -1
  178. package/dist/__tests__/coordination-memory.test.d.ts +0 -14
  179. package/dist/__tests__/coordination-memory.test.d.ts.map +0 -1
  180. package/dist/__tests__/coordination-memory.test.js +0 -401
  181. package/dist/__tests__/coordination-memory.test.js.map +0 -1
  182. package/dist/__tests__/coordination-mode.test.d.ts +0 -13
  183. package/dist/__tests__/coordination-mode.test.d.ts.map +0 -1
  184. package/dist/__tests__/coordination-mode.test.js +0 -180
  185. package/dist/__tests__/coordination-mode.test.js.map +0 -1
  186. package/dist/__tests__/coordination-plain-shell-commands.test.d.ts +0 -22
  187. package/dist/__tests__/coordination-plain-shell-commands.test.d.ts.map +0 -1
  188. package/dist/__tests__/coordination-plain-shell-commands.test.js +0 -1875
  189. package/dist/__tests__/coordination-plain-shell-commands.test.js.map +0 -1
  190. package/dist/__tests__/coordination-provision.test.d.ts +0 -12
  191. package/dist/__tests__/coordination-provision.test.d.ts.map +0 -1
  192. package/dist/__tests__/coordination-provision.test.js +0 -103
  193. package/dist/__tests__/coordination-provision.test.js.map +0 -1
  194. package/dist/__tests__/coordination-render.test.d.ts +0 -9
  195. package/dist/__tests__/coordination-render.test.d.ts.map +0 -1
  196. package/dist/__tests__/coordination-render.test.js +0 -335
  197. package/dist/__tests__/coordination-render.test.js.map +0 -1
  198. package/dist/__tests__/coordination-setup.test.d.ts +0 -6
  199. package/dist/__tests__/coordination-setup.test.d.ts.map +0 -1
  200. package/dist/__tests__/coordination-setup.test.js +0 -448
  201. package/dist/__tests__/coordination-setup.test.js.map +0 -1
  202. package/dist/__tests__/coordination-status-plain-shell.test.d.ts +0 -19
  203. package/dist/__tests__/coordination-status-plain-shell.test.d.ts.map +0 -1
  204. package/dist/__tests__/coordination-status-plain-shell.test.js +0 -332
  205. package/dist/__tests__/coordination-status-plain-shell.test.js.map +0 -1
  206. package/dist/__tests__/coordination-status-registration.test.d.ts +0 -16
  207. package/dist/__tests__/coordination-status-registration.test.d.ts.map +0 -1
  208. package/dist/__tests__/coordination-status-registration.test.js +0 -480
  209. package/dist/__tests__/coordination-status-registration.test.js.map +0 -1
  210. package/dist/__tests__/coordination-token-multitenant.test.d.ts +0 -11
  211. package/dist/__tests__/coordination-token-multitenant.test.d.ts.map +0 -1
  212. package/dist/__tests__/coordination-token-multitenant.test.js +0 -106
  213. package/dist/__tests__/coordination-token-multitenant.test.js.map +0 -1
  214. package/dist/__tests__/coordination-token.test.d.ts +0 -11
  215. package/dist/__tests__/coordination-token.test.d.ts.map +0 -1
  216. package/dist/__tests__/coordination-token.test.js +0 -201
  217. package/dist/__tests__/coordination-token.test.js.map +0 -1
  218. package/dist/__tests__/coordination-wiring.test.d.ts +0 -11
  219. package/dist/__tests__/coordination-wiring.test.d.ts.map +0 -1
  220. package/dist/__tests__/coordination-wiring.test.js +0 -43
  221. package/dist/__tests__/coordination-wiring.test.js.map +0 -1
  222. package/dist/__tests__/creation-pr-class-check.test.d.ts +0 -17
  223. package/dist/__tests__/creation-pr-class-check.test.d.ts.map +0 -1
  224. package/dist/__tests__/creation-pr-class-check.test.js +0 -346
  225. package/dist/__tests__/creation-pr-class-check.test.js.map +0 -1
  226. package/dist/__tests__/creation-step6a-push-check.test.d.ts +0 -15
  227. package/dist/__tests__/creation-step6a-push-check.test.d.ts.map +0 -1
  228. package/dist/__tests__/creation-step6a-push-check.test.js +0 -150
  229. package/dist/__tests__/creation-step6a-push-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,1875 +0,0 @@
1
- /**
2
- * #507 follow-up, fix round on PR #525 -- every coordination command in a plain
3
- * shell, and what a refusal tells the operator.
4
- *
5
- * The red-team challenge on #525 (comment 5951655534) and the security review
6
- * (comment 5934585482) found, at e809e09:
7
- *
8
- * F2. `status` found the team from the git worktree of the current directory,
9
- * while `escalate`, memory mode and the outage fallback file still read
10
- * only CLAUDE_WORKTREE_PATH. `status` printed Ready and `escalate` exited 1.
11
- * F1. The refusal said "run this from the team's worktree" and named no
12
- * worktree and no command that creates a marker.
13
- * F3. The git topology call needed git 2.31 (`--path-format=absolute`).
14
- * Security. The cwd-located worktree was trusted with no owner check; `status`
15
- * printed raw marker bytes; nothing pinned the git child's stripped
16
- * environment or its timeout.
17
- *
18
- * Every fixture is a real git repository under the OS temp dir. The operator's
19
- * global config is mocked out, and every token and key here is a fake literal.
20
- */
21
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
22
- import { chmodSync, existsSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync, realpathSync, } from 'fs';
23
- import { execFileSync, spawnSync } from 'child_process';
24
- import { join } from 'path';
25
- import { tmpdir } from 'os';
26
- vi.mock('../lib/config.js', async (importOriginal) => {
27
- const actual = await importOriginal();
28
- return {
29
- ...actual,
30
- getConfigValue: () => undefined,
31
- loadConfig: () => ({}),
32
- getConfigPath: () => '/nonexistent-mx-agent-config-for-525/config.json',
33
- };
34
- });
35
- import { runEscalate, runStatus } from '../commands/coordination.js';
36
- import { runInit } from '../commands/init.js';
37
- import { ENV_KEY_USER_KEY, refreshCoordinationToken, resolveCoordinationToken } from '../lib/coordination-token.js';
38
- import { registrationLine } from '../commands/coordination.js';
39
- import { sanitizeField } from '../lib/coordination-render.js';
40
- import { GIT_CHILD_STRIP, GIT_TOPOLOGY_TIMEOUT_MS, defaultGitTopology, listMarkedWorktrees, locateCoordinationWorktree, markerNextStep, GIT_PATHSPEC_ENV, TRACKED_REMEDY, defaultTrackedCoordinationFiles, noMarkerLines, readTeamMarker, readWorktreeFile, } from '../lib/coordination-worktree.js';
41
- import { resolveMemoryTeam } from '../lib/coordination-memory.js';
42
- import { FALLBACK_FILENAME, worktreeRoot } from '../lib/coordination-fallback.js';
43
- import { ServiceUnreachableError, resetUrlFallbackWarning } from '../lib/coordination-client.js';
44
- const ENV_KEYS = [
45
- 'CLAUDE_WORKTREE_PATH', 'CLAUDE_WORKTREE_NAME', 'MX_PROJECT_ROOT', 'MX_PRODUCT_SLUG',
46
- 'MX_COORD_SERVICE_URL', 'MX_COORD_SERVICE_TOKEN', 'MX_COORD_ADMIN_TOKEN', 'MX_API_KEY',
47
- 'MX_COORDINATION_MODE', 'MX_COORD_EXPECT_TEAM', 'MX_COORD_EXPECT_PROJECT',
48
- 'GIT_LITERAL_PATHSPECS', 'GIT_NOGLOB_PATHSPECS', 'GIT_GLOB_PATHSPECS', 'GIT_ICASE_PATHSPECS',
49
- ];
50
- let base;
51
- let saved;
52
- let logs;
53
- let errs;
54
- function git(cwd, ...a) {
55
- const r = spawnSync('git', ['-c', 'user.email=t@e.com', '-c', 'user.name=t', ...a], { cwd, encoding: 'utf-8' });
56
- if (r.status !== 0)
57
- throw new Error(r.stderr);
58
- }
59
- /**
60
- * A project as `mx-agent new project` leaves it: a main checkout whose
61
- * mx-agent.config.json names `slug` and sets coordinationMode to queue, and
62
- * linked worktrees under `<main>/.worktrees/`.
63
- */
64
- function makeProject(name, slug, worktrees = ['alpha-20260101'], mode = 'queue') {
65
- const main = join(base, name);
66
- mkdirSync(main, { recursive: true });
67
- git(main, 'init', '-q', '-b', 'main');
68
- writeFileSync(join(main, 'mx-agent.config.json'), JSON.stringify({ projectSlug: slug, ...(mode ? { coordinationMode: mode } : {}) }));
69
- writeFileSync(join(main, '.gitignore'), '.worktrees/\n.mx-coordination-team\n');
70
- git(main, 'add', '-A');
71
- git(main, 'commit', '-q', '-m', 'init');
72
- const paths = worktrees.map((wt) => {
73
- const p = join(main, '.worktrees', wt);
74
- git(main, 'worktree', 'add', '-q', '-b', `worktree/${wt}`, p);
75
- // Pinned, not inherited: the locator refuses a group-writable worktree, and
76
- // under umask 0002 `git worktree add` makes one (#525 red-team N2).
77
- chmodSync(p, 0o755);
78
- return p;
79
- });
80
- return { main, worktrees: paths, worktree: paths[0] };
81
- }
82
- /** A queue client that accepts everything and records what was enqueued. */
83
- function recordingClient(enqueue) {
84
- return {
85
- enqueue,
86
- async drain() { return { messages: [], remaining: 0, batchId: '' }; },
87
- async confirmDrain() { },
88
- async ack() { },
89
- async history() { return { messages: [], nextBefore: '' }; },
90
- async respondToMessage() { return { messageId: '', obligationState: 'resolved', stateNote: null, stateChangedAt: '' }; },
91
- async getObligations() { return { owe: [], owed: [] }; },
92
- };
93
- }
94
- const noOffline = {
95
- readOriginRoster: () => ({ teams: null, source: 'origin/main', error: 'no ref in this test' }),
96
- readFileRoster: (p) => ({ teams: null, source: p, error: 'no file in this test' }),
97
- };
98
- function credentialDeps(fetchCredential) {
99
- return {
100
- project: 'life-planner',
101
- serviceUrl: 'https://mxagent.dev.memnexus.ai',
102
- readUserKey: () => 'test-user-key-not-real',
103
- fetchCredential,
104
- writeCache: () => true,
105
- };
106
- }
107
- const issued = () => vi.fn(async () => ({ status: 'issued', token: 'tok' }));
108
- /** Put the process in a plain shell at `dir`: no session variables, cwd there. */
109
- function plainShellAt(dir) {
110
- vi.spyOn(process, 'cwd').mockReturnValue(dir);
111
- }
112
- beforeEach(() => {
113
- base = realpathSync(mkdtempSync(join(tmpdir(), 'coord-525-plain-')));
114
- saved = {};
115
- for (const k of ENV_KEYS) {
116
- saved[k] = process.env[k];
117
- delete process.env[k];
118
- }
119
- process.env.MX_COORDINATION_MODE = 'queue';
120
- logs = [];
121
- errs = [];
122
- vi.spyOn(console, 'log').mockImplementation((m) => { logs.push(String(m)); });
123
- vi.spyOn(console, 'error').mockImplementation((m) => { errs.push(String(m)); });
124
- vi.spyOn(process.stderr, 'write').mockImplementation((() => true));
125
- vi.spyOn(process, 'exit').mockImplementation(((code) => { throw new Error(`process.exit(${code})`); }));
126
- resetUrlFallbackWarning();
127
- });
128
- afterEach(() => {
129
- vi.restoreAllMocks();
130
- for (const k of ENV_KEYS) {
131
- if (saved[k] === undefined)
132
- delete process.env[k];
133
- else
134
- process.env[k] = saved[k];
135
- }
136
- rmSync(base, { recursive: true, force: true });
137
- });
138
- // ── F2. Every command finds the team the same way ───────────────────────
139
- describe('F2: escalate, memory mode and the fallback file in a plain shell', () => {
140
- it('escalate sends from the marker team with no CLAUDE_WORKTREE_PATH and no --team', async () => {
141
- const { main, worktree } = makeProject('life-planner', 'life-planner');
142
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
143
- process.env.MX_PROJECT_ROOT = main;
144
- plainShellAt(worktree);
145
- const enqueue = vi.fn(async () => ({ messageId: 'm1', duplicate: false }));
146
- await runEscalate({ to: 'beta', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) });
147
- expect(process.exit).not.toHaveBeenCalled();
148
- expect(enqueue).toHaveBeenCalledTimes(1);
149
- expect(enqueue).toHaveBeenCalledWith(expect.objectContaining({ to: 'beta', from: 'alpha' }));
150
- expect(logs.join('\n')).toContain('escalated: m1 -> beta [p2]');
151
- });
152
- it('escalate from a subdirectory of the worktree finds the same team', async () => {
153
- const { main, worktree } = makeProject('life-planner', 'life-planner');
154
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
155
- const sub = join(worktree, 'src', 'deep');
156
- mkdirSync(sub, { recursive: true });
157
- process.env.MX_PROJECT_ROOT = main;
158
- plainShellAt(sub);
159
- const enqueue = vi.fn(async () => ({ messageId: 'm2', duplicate: false }));
160
- await runEscalate({ to: 'beta', priority: 'p1', body: 'hello' }, { client: recordingClient(enqueue) });
161
- expect(enqueue).toHaveBeenCalledWith(expect.objectContaining({ from: 'alpha' }));
162
- });
163
- it('an explicit --team still wins over the marker', async () => {
164
- const { main, worktree } = makeProject('life-planner', 'life-planner');
165
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
166
- process.env.MX_PROJECT_ROOT = main;
167
- plainShellAt(worktree);
168
- const enqueue = vi.fn(async () => ({ messageId: 'm3', duplicate: false }));
169
- await runEscalate({ to: 'beta', priority: 'p2', body: 'hello', team: 'gamma' }, { client: recordingClient(enqueue) });
170
- expect(enqueue).toHaveBeenCalledWith(expect.objectContaining({ from: 'gamma' }));
171
- });
172
- it('CLAUDE_WORKTREE_PATH still means that path only', async () => {
173
- const { main, worktree } = makeProject('life-planner', 'life-planner');
174
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
175
- const session = join(base, 'session');
176
- mkdirSync(session);
177
- writeFileSync(join(session, '.mx-coordination-team'), 'beta\n');
178
- process.env.MX_PROJECT_ROOT = main;
179
- process.env.CLAUDE_WORKTREE_PATH = session;
180
- plainShellAt(worktree);
181
- const enqueue = vi.fn(async () => ({ messageId: 'm4', duplicate: false }));
182
- await runEscalate({ to: 'gamma', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) });
183
- expect(enqueue).toHaveBeenCalledWith(expect.objectContaining({ from: 'beta' }));
184
- expect(resolveMemoryTeam()).toBe('beta');
185
- expect(worktreeRoot()).toBe(session);
186
- });
187
- it('memory mode resolves the same team from the marker', () => {
188
- const { main, worktree } = makeProject('life-planner', 'life-planner');
189
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
190
- process.env.MX_PROJECT_ROOT = main;
191
- plainShellAt(worktree);
192
- expect(resolveMemoryTeam()).toBe('alpha');
193
- expect(resolveMemoryTeam('gamma')).toBe('gamma');
194
- });
195
- it('on an outage the fallback entry is written at the worktree top, not in the subdirectory', async () => {
196
- const { main, worktree } = makeProject('life-planner', 'life-planner');
197
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
198
- const sub = join(worktree, 'src');
199
- mkdirSync(sub);
200
- process.env.MX_PROJECT_ROOT = main;
201
- plainShellAt(sub);
202
- const enqueue = vi.fn(async () => { throw new ServiceUnreachableError(new Error('down')); });
203
- await runEscalate({ to: 'beta', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) });
204
- expect(logs.join('\n')).toContain('queued locally, will flush on reconnect');
205
- expect(existsSync(join(worktree, FALLBACK_FILENAME))).toBe(true);
206
- expect(existsSync(join(sub, FALLBACK_FILENAME))).toBe(false);
207
- const entry = JSON.parse(readFileSync(join(worktree, FALLBACK_FILENAME), 'utf-8').trim());
208
- expect(entry).toMatchObject({ from: 'alpha', to: 'beta' });
209
- });
210
- it('where the locator refuses (the main checkout), the fallback root is still the current directory', () => {
211
- const { main } = makeProject('life-planner', 'life-planner');
212
- process.env.MX_PROJECT_ROOT = main;
213
- plainShellAt(main);
214
- expect(worktreeRoot()).toBe(main);
215
- });
216
- it('escalate with no team anywhere exits 1 and names the team worktrees it can see', async () => {
217
- const { main, worktree } = makeProject('life-planner', 'life-planner');
218
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
219
- process.env.MX_PROJECT_ROOT = main;
220
- plainShellAt(main);
221
- const enqueue = vi.fn(async () => ({ messageId: 'never', duplicate: false }));
222
- await expect(runEscalate({ to: 'beta', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) }))
223
- .rejects.toThrow('process.exit(1)');
224
- expect(enqueue).not.toHaveBeenCalled();
225
- const out = errs.join('\n');
226
- expect(out).toContain('could not determine your team');
227
- expect(out).toContain(`${worktree} (team alpha)`);
228
- });
229
- });
230
- // ── F1. The refusal names a next step that works ────────────────────────
231
- describe('F1: the next step when no marker is usable', () => {
232
- const unprovisioned = { resolveToken: async () => ({ status: 'unprovisioned', detail: 'test' }), ...noOffline };
233
- const okFetch = () => vi.fn(async (_url) => new Response('ok', { status: 200 }));
234
- it('status from the main checkout lists the team worktrees that hold a marker, by path and team', async () => {
235
- const { main, worktrees } = makeProject('life-planner', 'life-planner', ['alpha-20260101', 'beta-20260101', 'gamma-20260101']);
236
- writeFileSync(join(worktrees[0], '.mx-coordination-team'), 'alpha\n');
237
- writeFileSync(join(worktrees[1], '.mx-coordination-team'), 'beta\n');
238
- process.env.MX_PROJECT_ROOT = main;
239
- await runStatus({ fetch: okFetch(), locate: { cwd: main }, registration: unprovisioned });
240
- const out = logs.join('\n');
241
- expect(out).toContain('Team: not set');
242
- expect(out).toContain('Next step: run this command from a team worktree. These hold a .mx-coordination-team marker:');
243
- expect(out).toContain(` ${worktrees[0]} (team alpha)`);
244
- expect(out).toContain(` ${worktrees[1]} (team beta)`);
245
- // The third worktree has no marker, so it is not offered.
246
- expect(out).not.toContain(worktrees[2]);
247
- });
248
- it('status from the main checkout with no marked worktree says so, lists the unmarked ones, and names the command that writes a marker', async () => {
249
- const { main, worktree } = makeProject('life-planner', 'life-planner');
250
- process.env.MX_PROJECT_ROOT = main;
251
- await runStatus({ fetch: okFetch(), locate: { cwd: main }, registration: unprovisioned });
252
- const out = logs.join('\n');
253
- expect(out).toContain(`No team worktree under ${join(main, '.worktrees')} holds a .mx-coordination-team marker yet. These worktrees have none:`);
254
- expect(out).toContain(` ${worktree}\n`);
255
- expect(out).toContain("`mx-agent start <team>` writes the marker into that team's worktree before it launches the session.");
256
- expect(out).not.toContain('mx-agent new team');
257
- });
258
- it('status from the main checkout of a project with no team worktree names the command that creates one', async () => {
259
- const { main } = makeProject('life-planner', 'life-planner', []);
260
- process.env.MX_PROJECT_ROOT = main;
261
- await runStatus({ fetch: okFetch(), locate: { cwd: main }, registration: unprovisioned });
262
- const out = logs.join('\n');
263
- expect(out).toContain(`No team worktree under ${join(main, '.worktrees')} holds a .mx-coordination-team marker yet.`);
264
- expect(out).toContain('The project has no team worktree. `mx-agent new team` creates the team-builder worktree and starts its session.');
265
- expect(out).toContain("`mx-agent start <team>` writes the marker into that team's worktree before it launches the session.");
266
- });
267
- it('status from a linked worktree with no marker names the command that writes it', async () => {
268
- const { main, worktree } = makeProject('life-planner', 'life-planner');
269
- process.env.MX_PROJECT_ROOT = main;
270
- await runStatus({ fetch: okFetch(), locate: { cwd: worktree }, registration: unprovisioned });
271
- const out = logs.join('\n');
272
- expect(out).toContain('No team marker was found.');
273
- expect(out).toContain("`mx-agent start <team>` writes the marker into that team's worktree before it launches the session.");
274
- expect(out).not.toContain('run this command from a team worktree');
275
- });
276
- it('the token path gives the same next step from a linked worktree with no marker', async () => {
277
- const { main, worktree } = makeProject('life-planner', 'life-planner');
278
- const fetchCredential = issued();
279
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
280
- expect(res.status).toBe('unprovisioned');
281
- expect(res.detail).toContain('no coordination marker (.mx-coordination-team) in this worktree');
282
- expect(res.detail).toContain('`mx-agent start <team>` writes the marker into that team\'s worktree');
283
- expect(fetchCredential).not.toHaveBeenCalled();
284
- });
285
- it('a project whose config is not in queue mode is told the start command will not write the marker', () => {
286
- const { main, worktree } = makeProject('other', 'other', ['alpha-20260101'], '');
287
- const located = locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main });
288
- const lines = markerNextStep(located, { projectRoot: () => main });
289
- expect(lines.join('\n')).toContain('writes the marker only when mx-agent.config.json sets "coordinationMode" to "queue"');
290
- expect(lines.join('\n')).toContain(`and the file in ${main} does not.`);
291
- });
292
- it('the start remedy is true for a project `mx-agent new project` scaffolds: init writes coordinationMode queue', async () => {
293
- const root = join(base, 'scaffolded');
294
- mkdirSync(root);
295
- await runInit({ projectRoot: root, projectSlug: 'proj9', skipBootstrap: true });
296
- expect(JSON.parse(readFileSync(join(root, 'mx-agent.config.json'), 'utf-8')).coordinationMode).toBe('queue');
297
- const lines = markerNextStep({ ok: false, reason: 'main-checkout', top: root, detail: '' }, { projectRoot: () => root });
298
- expect(lines).toContain("`mx-agent start <team>` writes the marker into that team's worktree before it launches the session.");
299
- });
300
- it('outside any project the next step is the general one', () => {
301
- const noProject = () => { throw new Error('no project'); };
302
- const located = locateCoordinationWorktree({}, { gitTopology: () => undefined, projectRoot: noProject });
303
- expect(markerNextStep(located, { projectRoot: noProject })).toEqual([
304
- "Next step: run this from the team's worktree (the directory holding .mx-coordination-team), or inside an mx-agent start session.",
305
- ]);
306
- });
307
- it('a marker that does not hold a valid slug is never listed, and its bytes are never printed', () => {
308
- const { main, worktrees } = makeProject('life-planner', 'life-planner', ['alpha-20260101', 'evil-20260101']);
309
- writeFileSync(join(worktrees[0], '.mx-coordination-team'), 'alpha\n');
310
- writeFileSync(join(worktrees[1], '.mx-coordination-team'), 'te\x1b[31mRED\x1b[0mam\x1b]0;TITLE\x07\n');
311
- expect(listMarkedWorktrees(main)).toEqual([{ path: worktrees[0], team: 'alpha' }]);
312
- const text = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }).join('\n');
313
- expect(text).not.toContain('\x1b');
314
- expect(text).not.toContain('RED');
315
- });
316
- it('a marker that is a symbolic link is not followed when worktrees are listed', () => {
317
- const { main, worktree } = makeProject('life-planner', 'life-planner');
318
- const target = join(base, 'elsewhere');
319
- writeFileSync(target, 'alpha\n');
320
- symlinkSync(target, join(worktree, '.mx-coordination-team'));
321
- expect(listMarkedWorktrees(main)).toEqual([]);
322
- });
323
- });
324
- // ── The product owner's run, reproduced ─────────────────────────────────
325
- /**
326
- * His output, on 0.1.296-next.0, from `/workspace (main)` in Life Planner: a
327
- * credential-endpoint project in queue mode, run from the MAIN CHECKOUT with no
328
- * CLAUDE_WORKTREE_PATH and no global config. It printed `Team: not set`, then
329
- * said a roster "does not list this team", that "the team name came from the
330
- * worktree name", and recommended `coordination brief` and `coordination
331
- * setup`. No team was resolved, so the first two described a lookup that had no
332
- * subject, `brief` cannot run without a team, and `setup` needs an admin token
333
- * a credential-endpoint project never has.
334
- *
335
- * Nothing is injected below except the health ping: the token path, the
336
- * locator and the project root all run as they do in his shell.
337
- */
338
- describe('the Life Planner run: main checkout, credential-endpoint project, queue mode, plain shell', () => {
339
- /**
340
- * Every mx-agent command the output names. The words are the CLI's real
341
- * subcommands, so "the built-in mx-agent service URL" is not counted as one.
342
- */
343
- function commandsNamed(out) {
344
- return [...new Set(out.match(/mx-agent (?:coordination [a-z]+|new [a-z]+|start|provision|escalate|init|config)/g) ?? [])].sort();
345
- }
346
- async function runFromMainCheckout(main) {
347
- delete process.env.MX_COORDINATION_MODE; // the mode comes from mx-agent.config.json, as in his project
348
- plainShellAt(main);
349
- const fetchFn = vi.fn(async (_url) => new Response('ok', { status: 200 }));
350
- await runStatus({ fetch: fetchFn });
351
- expect(fetchFn).toHaveBeenCalledTimes(1);
352
- return logs.join('\n');
353
- }
354
- function expectNoFalseClaim(out) {
355
- expect(out).toContain('Project: life-planner');
356
- expect(out).toContain('Team: not set');
357
- expect(out).toContain('Coordination mode: queue');
358
- expect(out).toContain('Service URL: https://mxagent.dev.memnexus.ai (source: the built-in mx-agent service URL (nothing configured))');
359
- expect(out).toContain('Registered: unverified (source: no roster consulted: no team was resolved)');
360
- expect(out).toContain("? Could not verify — no team was resolved: CLAUDE_WORKTREE_PATH is unset and the current directory is the project's main checkout, not a team worktree");
361
- // No claim about a team that was never resolved.
362
- expect(out).not.toContain('does not list this team');
363
- expect(out).not.toContain('lists this team');
364
- expect(out).not.toContain('came from the worktree name');
365
- expect(out).not.toContain('The queue may hold this team');
366
- // No step that cannot work here.
367
- expect(out).not.toContain('coordination setup');
368
- expect(out).not.toContain('coordination brief');
369
- expect(out).not.toContain('MX_COORD_ADMIN_TOKEN');
370
- }
371
- it('with team worktrees that hold markers: lists them, and names no step that cannot work', async () => {
372
- const { main, worktrees } = makeProject('life-planner', 'life-planner', ['planner-20260925', 'team-builder-20260925']);
373
- writeFileSync(join(worktrees[0], '.mx-coordination-team'), 'planner\n');
374
- writeFileSync(join(worktrees[1], '.mx-coordination-team'), 'team-builder\n');
375
- const out = await runFromMainCheckout(main);
376
- expectNoFalseClaim(out);
377
- expect(out).toContain('Next step: run this command from a team worktree. These hold a .mx-coordination-team marker:');
378
- expect(out).toContain(` ${worktrees[0]} (team planner)`);
379
- expect(out).toContain(` ${worktrees[1]} (team team-builder)`);
380
- expect(commandsNamed(out)).toEqual([]);
381
- });
382
- it('with team worktrees but no marker: lists them and names the command that writes the marker', async () => {
383
- const { main, worktrees } = makeProject('life-planner', 'life-planner', ['planner-20260925', 'team-builder-20260925']);
384
- const out = await runFromMainCheckout(main);
385
- expectNoFalseClaim(out);
386
- expect(out).toContain('holds a .mx-coordination-team marker yet. These worktrees have none:');
387
- expect(out).toContain(` ${worktrees[0]}\n`);
388
- expect(out).toContain(` ${worktrees[1]}\n`);
389
- expect(out).toContain("`mx-agent start <team>` writes the marker into that team's worktree before it launches the session.");
390
- expect(out).toContain('Then run this command again from that worktree.');
391
- expect(commandsNamed(out)).toEqual(['mx-agent start']);
392
- });
393
- it('with no team worktree at all: names the command that creates one', async () => {
394
- const { main } = makeProject('life-planner', 'life-planner', []);
395
- const out = await runFromMainCheckout(main);
396
- expectNoFalseClaim(out);
397
- expect(commandsNamed(out)).toEqual(['mx-agent new team', 'mx-agent start']);
398
- });
399
- it('a credential-endpoint project with a team resolved is not sent to `coordination setup`', async () => {
400
- const { main, worktree } = makeProject('life-planner', 'life-planner');
401
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
402
- process.env.MX_PROJECT_ROOT = main;
403
- await runStatus({
404
- fetch: vi.fn(async (_url) => new Response('ok', { status: 200 })),
405
- locate: { cwd: worktree },
406
- registration: { resolveToken: async () => ({ status: 'unprovisioned', detail: 'no MemNexus user key is available on this machine' }), ...noOffline },
407
- });
408
- const out = logs.join('\n');
409
- expect(out).toContain('? Could not verify');
410
- expect(out).toContain('mx-agent coordination brief');
411
- expect(out).not.toContain('mx-agent coordination setup ');
412
- expect(out).toContain('This project needs no `coordination setup`');
413
- });
414
- it('a Key Vault project with a team resolved still names `coordination setup`', async () => {
415
- const { main, worktree } = makeProject('memnexus', 'memnexus', ['platform-20260101']);
416
- writeFileSync(join(worktree, '.mx-coordination-team'), 'platform\n');
417
- process.env.MX_PROJECT_ROOT = main;
418
- await runStatus({
419
- locate: { cwd: worktree },
420
- registration: { resolveToken: async () => ({ status: 'unprovisioned', detail: 'test' }), ...noOffline },
421
- });
422
- expect(logs.join('\n')).toContain('mx-agent coordination setup # registers the team if it is absent');
423
- });
424
- });
425
- // ── F3. git older than 2.31 ─────────────────────────────────────────────
426
- describe('F3: a git with no --path-format still locates a real worktree', () => {
427
- const real = execFileSync;
428
- /** git < 2.31 as a failure: the first call errors. */
429
- const failingFirstCall = (file, args, options) => {
430
- if (args.includes('--path-format=absolute'))
431
- throw new Error('unknown option: --path-format=absolute');
432
- return real(file, args, options);
433
- };
434
- /** git < 2.31 as it behaves: rev-parse prints the unknown flag back as a line. */
435
- const echoingFirstCall = (file, args, options) => {
436
- if (!args.includes('--path-format=absolute'))
437
- return real(file, args, options);
438
- return `--path-format=absolute\n${real(file, args.filter((a) => a !== '--path-format=absolute'), options)}`;
439
- };
440
- for (const [label, exec] of [['fails', failingFirstCall], ['echoes the flag', echoingFirstCall]]) {
441
- it(`first call ${label}: a linked worktree is located from its top-level and from a subdirectory`, () => {
442
- const { main, worktree } = makeProject('life-planner', 'life-planner');
443
- const sub = join(worktree, 'src', 'deep');
444
- mkdirSync(sub, { recursive: true });
445
- const gitTopology = (cwd) => defaultGitTopology(cwd, exec);
446
- expect(locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main, gitTopology }))
447
- .toEqual({ ok: true, root: worktree, source: 'git-toplevel' });
448
- expect(locateCoordinationWorktree({}, { cwd: sub, projectRoot: () => main, gitTopology }))
449
- .toEqual({ ok: true, root: worktree, source: 'git-toplevel' });
450
- });
451
- it(`first call ${label}: the main checkout is still refused, from its top-level and from a subdirectory`, () => {
452
- const { main } = makeProject('life-planner', 'life-planner');
453
- const sub = join(main, 'docs');
454
- mkdirSync(sub);
455
- const gitTopology = (cwd) => defaultGitTopology(cwd, exec);
456
- for (const cwd of [main, sub]) {
457
- const r = locateCoordinationWorktree({}, { cwd, projectRoot: () => main, gitTopology });
458
- expect(r.ok).toBe(false);
459
- if (!r.ok)
460
- expect(r.reason).toBe('main-checkout');
461
- }
462
- });
463
- }
464
- it('the fallback answer equals the one-call answer on this git', () => {
465
- const { worktree } = makeProject('life-planner', 'life-planner');
466
- const modern = defaultGitTopology(worktree)?.map((p) => realpathSync(p));
467
- const old = defaultGitTopology(worktree, failingFirstCall)?.map((p) => realpathSync(p));
468
- expect(modern).toHaveLength(3);
469
- expect(old).toEqual(modern);
470
- });
471
- it('a directory outside any repository is still undefined on both paths', () => {
472
- const plain = join(base, 'not-a-repo');
473
- mkdirSync(plain);
474
- expect(defaultGitTopology(plain)).toBeUndefined();
475
- expect(defaultGitTopology(plain, failingFirstCall)).toBeUndefined();
476
- });
477
- });
478
- // ── Security review of #525 ─────────────────────────────────────────────
479
- describe.skipIf(typeof process.getuid !== 'function')('security: the cwd-located worktree must be owned by the current user', () => {
480
- const uid = () => process.getuid();
481
- it("a top-level another user owns is refused, and no credential is requested", async () => {
482
- const { main, worktree } = makeProject('life-planner', 'life-planner');
483
- writeFileSync(join(worktree, '.mx-coordination-team'), 'forgedother\n');
484
- const locate = { cwd: worktree, projectRoot: () => main, statTop: () => ({ uid: uid() + 1, mode: 0o40755 }) };
485
- const r = locateCoordinationWorktree({}, locate);
486
- expect(r.ok).toBe(false);
487
- if (!r.ok) {
488
- expect(r.reason).toBe('not-owned');
489
- expect(r.detail).toContain('is not owned by the current user');
490
- }
491
- const fetchCredential = issued();
492
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate });
493
- expect(res.status).toBe('unprovisioned');
494
- expect(fetchCredential).not.toHaveBeenCalled();
495
- });
496
- it('a group-writable top-level is refused with its mode, and no credential is requested', async () => {
497
- const { main, worktree } = makeProject('life-planner', 'life-planner');
498
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
499
- chmodSync(worktree, 0o775);
500
- const locate = { cwd: worktree, projectRoot: () => main };
501
- const r = locateCoordinationWorktree({}, locate);
502
- expect(r.ok).toBe(false);
503
- if (!r.ok)
504
- expect(r.detail).toContain('is group- or world-writable (mode 775)');
505
- const fetchCredential = issued();
506
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate });
507
- expect(res.status).toBe('unprovisioned');
508
- expect(fetchCredential).not.toHaveBeenCalled();
509
- });
510
- it('a world-writable top-level is refused', () => {
511
- const { main, worktree } = makeProject('life-planner', 'life-planner');
512
- chmodSync(worktree, 0o757);
513
- const r = locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main });
514
- expect(r.ok).toBe(false);
515
- });
516
- it('a 0755 top-level the current user owns is accepted (the layout `git worktree add` makes under umask 022)', () => {
517
- const { main, worktree } = makeProject('life-planner', 'life-planner');
518
- chmodSync(worktree, 0o755);
519
- expect(locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main }))
520
- .toEqual({ ok: true, root: worktree, source: 'git-toplevel' });
521
- });
522
- it('CLAUDE_WORKTREE_PATH is not subject to the owner rule: behaviour there is unchanged', () => {
523
- const r = locateCoordinationWorktree({ CLAUDE_WORKTREE_PATH: '/some/session/worktree' }, { statTop: () => ({ uid: uid() + 1, mode: 0o40777 }) });
524
- expect(r).toEqual({ ok: true, root: '/some/session/worktree', source: 'CLAUDE_WORKTREE_PATH' });
525
- });
526
- it('a marker that is a symbolic link is not read on the git-toplevel source, and no credential is requested', async () => {
527
- const { main, worktree } = makeProject('life-planner', 'life-planner');
528
- const target = join(base, 'planted-marker');
529
- writeFileSync(target, 'forgedother\n');
530
- symlinkSync(target, join(worktree, '.mx-coordination-team'));
531
- const fetchCredential = issued();
532
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
533
- expect(res.status).toBe('unprovisioned');
534
- expect(res.detail).toContain('was not read: it is a symbolic link');
535
- expect(fetchCredential).not.toHaveBeenCalled();
536
- });
537
- it('a marker another user owns is not read on the git-toplevel source, and no credential is requested', async () => {
538
- const { main, worktree } = makeProject('life-planner', 'life-planner');
539
- writeFileSync(join(worktree, '.mx-coordination-team'), 'forgedother\n');
540
- // The directory passes (stubbed), so the refusal below is the FILE check:
541
- // the marker's real owner is not the uid this run claims to be.
542
- const other = uid() + 1;
543
- const locate = { cwd: worktree, projectRoot: () => main, uid: () => other, statTop: () => ({ uid: other, mode: 0o40755 }) };
544
- expect(locateCoordinationWorktree({}, locate).ok).toBe(true);
545
- const fetchCredential = issued();
546
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate });
547
- expect(res.status).toBe('unprovisioned');
548
- expect(res.detail).toContain('was not read: it is not owned by the current user');
549
- expect(fetchCredential).not.toHaveBeenCalled();
550
- });
551
- it('a credential cache that is a symbolic link is not used as the token on the git-toplevel source', async () => {
552
- const { main, worktree } = makeProject('life-planner', 'life-planner');
553
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
554
- const target = join(base, 'planted-cache');
555
- writeFileSync(target, 'planted-token-not-real\n');
556
- symlinkSync(target, join(worktree, '.mx-coordination-token--life-planner--alpha'));
557
- const fetchCredential = issued();
558
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
559
- expect(res.status).toBe('resolved');
560
- expect(res.source).toBe('credential');
561
- expect(res.token).toBe('tok');
562
- expect(fetchCredential).toHaveBeenCalledTimes(1);
563
- });
564
- it('a regular cache file the current user owns is still used, and no request is made', async () => {
565
- const { main, worktree } = makeProject('life-planner', 'life-planner');
566
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
567
- writeFileSync(join(worktree, '.mx-coordination-token--life-planner--alpha'), 'cached-token-not-real\n', { mode: 0o600 });
568
- const fetchCredential = issued();
569
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
570
- expect(res.status).toBe('resolved');
571
- expect(res.source).toBe('cache');
572
- expect(fetchCredential).not.toHaveBeenCalled();
573
- });
574
- });
575
- describe('security: status never prints raw marker bytes (Informational 1)', () => {
576
- const okFetch = () => vi.fn(async (_url) => new Response('ok', { status: 200 }));
577
- it('a marker holding escape sequences prints as "invalid marker"', async () => {
578
- const { main, worktree } = makeProject('life-planner', 'life-planner');
579
- writeFileSync(join(worktree, '.mx-coordination-team'), 'te\x1b[31mRED\x1b[0mam\x1b]0;TITLE\x07\n');
580
- process.env.MX_PROJECT_ROOT = main;
581
- await runStatus({
582
- fetch: okFetch(),
583
- locate: { cwd: worktree },
584
- registration: { resolveToken: async () => ({ status: 'unprovisioned', detail: 'test' }), ...noOffline },
585
- });
586
- const out = logs.join('\n');
587
- expect(out).toContain('Team: invalid marker\n');
588
- expect(out).not.toContain('\x1b');
589
- expect(out).not.toContain('\x07');
590
- expect(out).not.toContain('RED');
591
- expect(out).toContain('does not hold a valid team slug');
592
- });
593
- it('a marker holding a valid slug still prints the slug', async () => {
594
- const { main, worktree } = makeProject('life-planner', 'life-planner');
595
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
596
- process.env.MX_PROJECT_ROOT = main;
597
- await runStatus({
598
- fetch: okFetch(),
599
- locate: { cwd: worktree },
600
- registration: { resolveToken: async () => ({ status: 'unprovisioned', detail: 'test' }), ...noOffline },
601
- });
602
- expect(logs.join('\n')).toContain('Team: alpha (marker in');
603
- });
604
- });
605
- describe('security: the git child process (Informational 2)', () => {
606
- function capture(answer) {
607
- const calls = [];
608
- return { calls, exec: (file, args, options) => { calls.push({ file, args, options }); return answer(args); } };
609
- }
610
- beforeEach(() => {
611
- process.env.MX_COORD_SERVICE_TOKEN = 'fake-service-token';
612
- process.env.MX_COORD_ADMIN_TOKEN = 'fake-admin-token';
613
- process.env.MX_API_KEY = 'fake-user-key';
614
- });
615
- it('the strip list names the three credential variables', () => {
616
- expect([...GIT_CHILD_STRIP].sort()).toEqual(['MX_API_KEY', 'MX_COORD_ADMIN_TOKEN', 'MX_COORD_SERVICE_TOKEN']);
617
- expect(GIT_CHILD_STRIP).toContain(ENV_KEY_USER_KEY);
618
- });
619
- it('runs git with an argument array, a 5 s timeout, and none of the three credentials in its environment', () => {
620
- const { exec, calls } = capture(() => '/p/.worktrees/a\n/p/.git/worktrees/a\n/p/.git\n');
621
- expect(defaultGitTopology('/p/.worktrees/a', exec)).toEqual(['/p/.worktrees/a', '/p/.git/worktrees/a', '/p/.git']);
622
- expect(calls).toHaveLength(1);
623
- const { file, args, options } = calls[0];
624
- expect(file).toBe('git');
625
- expect(args).toEqual(['-c', 'core.fsmonitor=false', 'rev-parse', '--path-format=absolute', '--show-toplevel', '--git-dir', '--git-common-dir']);
626
- expect(GIT_TOPOLOGY_TIMEOUT_MS).toBe(5_000);
627
- expect(options.timeout).toBe(5_000);
628
- expect(options.cwd).toBe('/p/.worktrees/a');
629
- expect(options).not.toHaveProperty('shell');
630
- for (const k of ['MX_COORD_SERVICE_TOKEN', 'MX_COORD_ADMIN_TOKEN', 'MX_API_KEY']) {
631
- expect(options.env).not.toHaveProperty(k);
632
- }
633
- // The rest of the environment is passed through: git needs PATH and HOME.
634
- expect(options.env.PATH).toBe(process.env.PATH);
635
- // The parent's own environment is untouched.
636
- expect(process.env.MX_API_KEY).toBe('fake-user-key');
637
- });
638
- it('every call on the older-git path has the same timeout and the same stripped environment', () => {
639
- const { exec, calls } = capture((args) => {
640
- if (args.includes('--path-format=absolute'))
641
- throw new Error('unknown option');
642
- return args.includes('--show-toplevel') ? '/p/.worktrees/a\n' : '/p/.git/worktrees/a\n/p/.git\n';
643
- });
644
- expect(defaultGitTopology('/p/.worktrees/a/src', exec)).toEqual(['/p/.worktrees/a', '/p/.git/worktrees/a', '/p/.git']);
645
- expect(calls).toHaveLength(3);
646
- // The two git dirs are asked for from the top-level, not from the subdirectory.
647
- expect(calls[2].options.cwd).toBe('/p/.worktrees/a');
648
- for (const c of calls) {
649
- expect(c.options.timeout).toBe(5_000);
650
- for (const k of ['MX_COORD_SERVICE_TOKEN', 'MX_COORD_ADMIN_TOKEN', 'MX_API_KEY']) {
651
- expect(c.options.env).not.toHaveProperty(k);
652
- }
653
- }
654
- });
655
- it('a relative answer on the older-git path is resolved against the top-level', () => {
656
- const { exec } = capture((args) => {
657
- if (args.includes('--path-format=absolute'))
658
- throw new Error('unknown option');
659
- return args.includes('--show-toplevel') ? '/p\n' : '.git\n.git\n';
660
- });
661
- expect(defaultGitTopology('/p/docs', exec)).toEqual(['/p', '/p/.git', '/p/.git']);
662
- });
663
- });
664
- // ── Fix round 3: reviews at eba08f4 ─────────────────────────────────────
665
- /**
666
- * For hand-made entries, which are not git worktrees: git cannot say what is
667
- * tracked there, so the answer is given (nothing is tracked).
668
- */
669
- const NOT_TRACKED = { trackedFiles: () => [] };
670
- /** A hand-made entry under `<main>/.worktrees/`: a directory with a `.git` file, mode 0755. */
671
- function fakeWorktree(main, name, marker) {
672
- const p = join(main, '.worktrees', name);
673
- mkdirSync(p, { recursive: true });
674
- chmodSync(p, 0o755);
675
- writeFileSync(join(p, '.git'), 'gitdir: /nowhere\n');
676
- if (marker !== undefined)
677
- writeFileSync(join(p, '.mx-coordination-team'), marker);
678
- return p;
679
- }
680
- describe.skipIf(typeof process.getuid !== 'function')('N1: a worktree the locator refused is reported as refused, by every command', () => {
681
- const unprovisioned = { resolveToken: async () => ({ status: 'unprovisioned', detail: 'test' }), ...noOffline };
682
- const okFetch = () => vi.fn(async (_url) => new Response('ok', { status: 200 }));
683
- const CHMOD = 'is group- or world-writable (mode 775); `chmod go-w` on that directory makes it usable';
684
- function expectNoContradiction(out, worktree) {
685
- expect(out).toContain(CHMOD);
686
- expect(out).not.toContain('No team marker was found');
687
- expect(out).not.toContain('this directory names none');
688
- expect(out).not.toContain('run this command from a team worktree');
689
- expect(out).not.toContain(`${worktree} (team`);
690
- }
691
- it('status from a group-writable worktree prints the chmod remedy and does not send the operator back to it', async () => {
692
- const { main, worktree } = makeProject('life-planner', 'life-planner');
693
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
694
- chmodSync(worktree, 0o775);
695
- process.env.MX_PROJECT_ROOT = main;
696
- await runStatus({ fetch: okFetch(), locate: { cwd: worktree }, registration: unprovisioned });
697
- const out = logs.join('\n');
698
- expectNoContradiction(out, worktree);
699
- expect(out).toContain('No team was looked up, because the worktree of this directory was not used.');
700
- });
701
- it('escalate from a group-writable worktree exits 1 with the chmod remedy and no worktree list', async () => {
702
- const { main, worktree } = makeProject('life-planner', 'life-planner');
703
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
704
- chmodSync(worktree, 0o775);
705
- process.env.MX_PROJECT_ROOT = main;
706
- plainShellAt(worktree);
707
- const enqueue = vi.fn(async () => ({ messageId: 'never', duplicate: false }));
708
- await expect(runEscalate({ to: 'beta', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) }))
709
- .rejects.toThrow('process.exit(1)');
710
- expect(enqueue).not.toHaveBeenCalled();
711
- expectNoContradiction(errs.join('\n'), worktree);
712
- });
713
- it('the token path detail for a group-writable worktree ends with the chmod remedy and lists nothing', async () => {
714
- const { main, worktree } = makeProject('life-planner', 'life-planner');
715
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
716
- chmodSync(worktree, 0o775);
717
- const fetchCredential = issued();
718
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
719
- expect(res.status).toBe('unprovisioned');
720
- expectNoContradiction(res.detail ?? '', worktree);
721
- expect(res.detail).toMatch(/cannot locate the coordination marker$/);
722
- expect(fetchCredential).not.toHaveBeenCalled();
723
- });
724
- it('noMarkerLines for a refused worktree is the locator detail and nothing else', () => {
725
- const { main, worktree } = makeProject('life-planner', 'life-planner');
726
- chmodSync(worktree, 0o775);
727
- const located = locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main });
728
- expect(located.ok).toBe(false);
729
- if (!located.ok)
730
- expect(noMarkerLines(located, { projectRoot: () => main })).toEqual([`${located.detail}.`]);
731
- expect(markerNextStep(located, { projectRoot: () => main })).toEqual([]);
732
- });
733
- it('from the main checkout a group-writable worktree is not offered as a place to go: it is listed as not usable, with the remedy', async () => {
734
- const { main, worktrees } = makeProject('life-planner', 'life-planner', ['alpha-20260101', 'beta-20260101']);
735
- writeFileSync(join(worktrees[0], '.mx-coordination-team'), 'alpha\n');
736
- writeFileSync(join(worktrees[1], '.mx-coordination-team'), 'beta\n');
737
- chmodSync(worktrees[1], 0o775);
738
- process.env.MX_PROJECT_ROOT = main;
739
- await runStatus({ fetch: okFetch(), locate: { cwd: main }, registration: unprovisioned });
740
- const out = logs.join('\n');
741
- expect(out).toContain(` ${worktrees[0]} (team alpha)`);
742
- expect(out).not.toContain('(team beta)');
743
- expect(out).toContain('These worktrees are not usable as they are:');
744
- expect(out).toContain(` the git worktree at ${worktrees[1]} ${CHMOD}`);
745
- expect(listMarkedWorktrees(main)).toEqual([{ path: worktrees[0], team: 'alpha' }]);
746
- });
747
- it('from the main checkout with only a refused worktree: no worktree is called usable', () => {
748
- const { main, worktree } = makeProject('life-planner', 'life-planner');
749
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
750
- chmodSync(worktree, 0o775);
751
- const lines = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main });
752
- expect(lines).toEqual([
753
- `No usable team worktree under ${join(main, '.worktrees')} holds a .mx-coordination-team marker yet.`,
754
- 'These worktrees are not usable as they are:',
755
- ` the git worktree at ${worktree} ${CHMOD}`,
756
- ]);
757
- });
758
- it("a worktree another user owns is not offered either, and its marker is not read", () => {
759
- const { main, worktree } = makeProject('life-planner', 'life-planner');
760
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
761
- const other = process.getuid() + 1;
762
- const lines = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main, statTop: () => ({ uid: other, mode: 0o40755 }) });
763
- expect(lines.join('\n')).not.toContain('(team alpha)');
764
- expect(lines.join('\n')).toContain(`the git worktree at ${worktree} is not owned by the current user`);
765
- });
766
- });
767
- describe.skipIf(typeof process.getuid !== 'function')('N3: the not-owned refusal names a remedy, and the remedy works for every command that prints it', () => {
768
- const realUid = () => process.getuid();
769
- it('the detail names CLAUDE_WORKTREE_PATH with the directory, and says what setting it means', () => {
770
- const { main, worktree } = makeProject('life-planner', 'life-planner');
771
- const r = locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main, statTop: () => ({ uid: realUid() + 1, mode: 0o40755 }) });
772
- expect(r.ok).toBe(false);
773
- if (!r.ok) {
774
- expect(r.detail).toBe(`CLAUDE_WORKTREE_PATH is unset and the git worktree at ${worktree} is not owned by the current user, so it was not used. ` +
775
- 'If no other user can write to that directory (for example a bind mount that reports a different uid), ' +
776
- 'set CLAUDE_WORKTREE_PATH to that directory for this one command. ' +
777
- 'A directory named that way gets no owner check: its marker picks the team, ' +
778
- 'and the credential cache is read from it and written to it');
779
- // The directory is named once, in prose. Another uid chose its name, so
780
- // it is never printed after the `=` of an assignment an operator could paste.
781
- expect(r.detail).not.toContain('CLAUDE_WORKTREE_PATH=');
782
- expect(r.detail.split(worktree)).toHaveLength(2);
783
- }
784
- });
785
- it('with the directory reading as another uid, every command refuses in a plain shell and works with CLAUDE_WORKTREE_PATH set', async () => {
786
- const { main, worktree } = makeProject('life-planner', 'life-planner');
787
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
788
- process.env.MX_PROJECT_ROOT = main;
789
- plainShellAt(worktree);
790
- // A bind mount that reports another owner: this process is a uid the
791
- // directory and its files do not belong to.
792
- const other = realUid() + 1;
793
- vi.spyOn(process, 'getuid').mockReturnValue(other);
794
- // Refused, and each refusal carries the remedy.
795
- expect(resolveMemoryTeam()).not.toBe('alpha');
796
- const refusedFetch = issued();
797
- const refused = await resolveCoordinationToken({ ...credentialDeps(refusedFetch) });
798
- expect(refused.status).toBe('unprovisioned');
799
- expect(refused.detail).toContain('set CLAUDE_WORKTREE_PATH to that directory for this one command');
800
- expect(refusedFetch).not.toHaveBeenCalled();
801
- const never = vi.fn(async () => ({ messageId: 'never', duplicate: false }));
802
- await expect(runEscalate({ to: 'beta', priority: 'p2', body: 'hello' }, { client: recordingClient(never) }))
803
- .rejects.toThrow('process.exit(1)');
804
- expect(errs.join('\n')).toContain('set CLAUDE_WORKTREE_PATH to that directory for this one command');
805
- // The remedy, followed.
806
- process.env.CLAUDE_WORKTREE_PATH = worktree;
807
- expect(locateCoordinationWorktree(process.env)).toEqual({ ok: true, root: worktree, source: 'CLAUDE_WORKTREE_PATH' });
808
- expect(resolveMemoryTeam()).toBe('alpha');
809
- expect(worktreeRoot()).toBe(worktree);
810
- const enqueue = vi.fn(async () => ({ messageId: 'm9', duplicate: false }));
811
- await runEscalate({ to: 'beta', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) });
812
- expect(enqueue).toHaveBeenCalledWith(expect.objectContaining({ from: 'alpha' }));
813
- const fetchCredential = issued();
814
- const res = await resolveCoordinationToken({ ...credentialDeps(fetchCredential) });
815
- expect(res.status).toBe('resolved');
816
- expect(res.slug).toBe('alpha');
817
- logs.length = 0;
818
- await runStatus({
819
- fetch: vi.fn(async (_url) => new Response('ok', { status: 200 })),
820
- registration: { client: recordingClient(enqueue), ...noOffline },
821
- });
822
- expect(logs.join('\n')).toMatch(/Team: {14}alpha\n/);
823
- expect(logs.join('\n')).toContain('✓ Ready');
824
- });
825
- });
826
- describe('security Informational 1: a worktree path is printed only through sanitizeField', () => {
827
- it('status in a worktree whose name holds escape sequences prints none of them on the Team or Registered line', async () => {
828
- const { main } = makeProject('life-planner', 'life-planner', []);
829
- // The directory name holds the escape sequences; the branch name cannot.
830
- const worktree = join(main, '.worktrees', 'te\x1b[31mam\x1b]0;TITLE\x07');
831
- git(main, 'worktree', 'add', '-q', '-b', 'worktree/esc', worktree);
832
- chmodSync(worktree, 0o755);
833
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
834
- process.env.MX_PROJECT_ROOT = main;
835
- await runStatus({
836
- fetch: vi.fn(async (_url) => new Response('ok', { status: 200 })),
837
- locate: { cwd: worktree },
838
- registration: {
839
- resolveToken: async () => ({ status: 'unprovisioned', detail: 'test' }),
840
- readOriginRoster: () => ({ teams: null, source: 'origin/main', error: 'no ref in this test' }),
841
- },
842
- });
843
- const team = logs.find((l) => l.includes('Team:')) ?? '';
844
- const registered = logs.find((l) => l.includes('Registered:')) ?? '';
845
- expect(team).toContain('Team: alpha (marker in ');
846
- expect(team).toContain(`(marker in ${sanitizeField(worktree)}, the git worktree of the current directory)`);
847
- expect(registered).toContain('coordination-rosters.generated.json');
848
- for (const line of [team, registered]) {
849
- expect(line).not.toContain('\x1b');
850
- expect(line).not.toContain('\x07');
851
- }
852
- });
853
- it('registrationLine strips control bytes from any source it is given', () => {
854
- const line = registrationLine({ verdict: 'could-not-verify', kind: 'offline-file', source: 'offline roster from /p/te\x1b[31mam/x.json', credentialResolved: false });
855
- expect(line).toBe('unverified (source: offline roster from /p/team/x.json)');
856
- expect(sanitizeField('/p/te\x1b[31mam/x.json')).toBe('/p/team/x.json');
857
- });
858
- });
859
- describe('security mutants that survived at eba08f4', () => {
860
- const ESC_NAME = 'te\x1b[31mam\x1b]0;TITLE\x07';
861
- it('M08: a listed MARKED worktree path holds no control bytes', () => {
862
- const { main } = makeProject('life-planner', 'life-planner', []);
863
- fakeWorktree(main, ESC_NAME, 'alpha\n');
864
- const marked = listMarkedWorktrees(main, NOT_TRACKED);
865
- expect(marked).toEqual([{ path: sanitizeField(join(main, '.worktrees', ESC_NAME)), team: 'alpha' }]);
866
- expect(marked[0].path).not.toContain('\x1b');
867
- expect(marked[0].path).not.toContain('\x07');
868
- });
869
- it('M08b: a listed UNMARKED worktree path holds no control bytes', () => {
870
- const { main } = makeProject('life-planner', 'life-planner', []);
871
- fakeWorktree(main, ESC_NAME);
872
- const text = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main }).join('\n');
873
- expect(text).toContain(` ${sanitizeField(join(main, '.worktrees', ESC_NAME))}\n`);
874
- expect(text).not.toContain('\x1b');
875
- expect(text).not.toContain('\x07');
876
- });
877
- it('M09: more than 20 worktrees print 20 and a count of the rest, marked and unmarked', () => {
878
- const { main } = makeProject('life-planner', 'life-planner', []);
879
- for (let i = 0; i < 25; i++)
880
- fakeWorktree(main, `team${String(i).padStart(2, '0')}-20260101`, `team${String(i).padStart(2, '0')}\n`);
881
- const marked = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main, ...NOT_TRACKED });
882
- expect(marked.filter((l) => l.includes('(team team'))).toHaveLength(20);
883
- expect(marked[marked.length - 1]).toBe(' and 5 more');
884
- expect(marked).toHaveLength(22);
885
- const other = makeProject('other-planner', 'other-planner', []);
886
- for (let i = 0; i < 23; i++)
887
- fakeWorktree(other.main, `wt${String(i).padStart(2, '0')}`);
888
- const unmarked = markerNextStep({ ok: false, reason: 'main-checkout', top: other.main, detail: '' }, { projectRoot: () => other.main });
889
- expect(unmarked.filter((l) => l.startsWith(` ${other.main}`))).toHaveLength(20);
890
- expect(unmarked).toContain(' and 3 more');
891
- });
892
- it('M17: a marker or cache larger than 64 KB is read up to 64 KB and no further', () => {
893
- const { worktree } = makeProject('life-planner', 'life-planner');
894
- const path = join(worktree, '.mx-coordination-team');
895
- writeFileSync(path, `alpha\n${'x'.repeat(200 * 1024)}`);
896
- const read = readWorktreeFile({ root: worktree, source: 'git-toplevel' }, path);
897
- expect(read.kind).toBe('ok');
898
- if (read.kind === 'ok')
899
- expect(read.text).toHaveLength(64 * 1024);
900
- });
901
- it.skipIf(typeof process.getuid !== 'function')('M19: the not-owned detail holds no control bytes from the path, for the owner and the mode refusal', () => {
902
- const uid = process.getuid();
903
- const top = `/p/.worktrees/${ESC_NAME}`;
904
- const gitTopology = () => [top, '/p/.git/worktrees/x', '/p/.git'];
905
- for (const st of [{ uid: uid + 1, mode: 0o40755 }, { uid, mode: 0o40775 }]) {
906
- const r = locateCoordinationWorktree({}, { cwd: '/p', gitTopology, projectRoot: () => '/p', statTop: () => st });
907
- expect(r.ok).toBe(false);
908
- if (!r.ok) {
909
- expect(r.reason).toBe('not-owned');
910
- expect(r.detail).toContain(sanitizeField(top));
911
- expect(r.detail).not.toContain('\x1b');
912
- expect(r.detail).not.toContain('\x07');
913
- }
914
- }
915
- });
916
- });
917
- // ── Fix round 4: reviews at 082c7d8 ─────────────────────────────────────
918
- /**
919
- * The red-team's fixture, and the layout #527 reports for a real consumer
920
- * project: `.mx-coordination-team` holding `product` is COMMITTED on main, so
921
- * every worktree checks it out.
922
- */
923
- function makeTrackedMarkerProject() {
924
- const main = join(base, 'life-planner');
925
- mkdirSync(main, { recursive: true });
926
- git(main, 'init', '-q', '-b', 'main');
927
- writeFileSync(join(main, 'mx-agent.config.json'), JSON.stringify({ projectSlug: 'life-planner', coordinationMode: 'queue' }));
928
- writeFileSync(join(main, '.gitignore'), '.worktrees/\n.mx-coordination-token--*\n');
929
- writeFileSync(join(main, '.mx-coordination-team'), 'product\n');
930
- git(main, 'add', '-A');
931
- git(main, 'add', '-f', '.mx-coordination-team');
932
- git(main, 'commit', '-q', '-m', 'init with a tracked marker');
933
- const worktrees = ['personal-coach-20260927', 'engineering-20260927'].map((wt) => {
934
- const p = join(main, '.worktrees', wt);
935
- git(main, 'worktree', 'add', '-q', '-b', `worktree/${wt}`, p);
936
- chmodSync(p, 0o755);
937
- return p;
938
- });
939
- return { main, worktrees };
940
- }
941
- const cacheFilesIn = (dir) => readdirSync(dir).filter((f) => f.startsWith('.mx-coordination-token--'));
942
- /** The token path as a plain shell runs it: real locator, real cache writer, fake credential fetch. */
943
- function plainShellTokenDeps(fetchCredential) {
944
- return {
945
- project: 'life-planner',
946
- serviceUrl: 'https://mxagent.dev.memnexus.ai',
947
- readUserKey: () => 'test-user-key-not-real',
948
- fetchCredential,
949
- };
950
- }
951
- describe('red-team finding 1: a cwd-located marker that is tracked in git names no team', () => {
952
- const okFetch = () => vi.fn(async (_url) => new Response('ok', { status: 200 }));
953
- it('each worktree checks out the tracked marker (the fixture is the one the finding used)', () => {
954
- const { worktrees } = makeTrackedMarkerProject();
955
- for (const wt of worktrees) {
956
- expect(readFileSync(join(wt, '.mx-coordination-team'), 'utf-8')).toBe('product\n');
957
- expect(defaultTrackedCoordinationFiles(wt)).toEqual(['.mx-coordination-team']);
958
- }
959
- });
960
- for (const index of [0, 1]) {
961
- it(`worktree ${index + 1}: the token path requests nothing, caches nothing, and names the remedy`, async () => {
962
- const { main, worktrees } = makeTrackedMarkerProject();
963
- const wt = worktrees[index];
964
- process.env.MX_PROJECT_ROOT = main;
965
- plainShellAt(wt);
966
- const fetchCredential = issued();
967
- const res = await resolveCoordinationToken(plainShellTokenDeps(fetchCredential));
968
- expect(res.status).toBe('misconfigured');
969
- expect(res.token).toBeUndefined();
970
- expect(res.slug).toBeUndefined();
971
- // The reason, then the whole remedy, once.
972
- expect(res.detail).toBe(`the .mx-coordination-team marker in ${wt} is tracked or staged in git on the branch that worktree has checked out, so it is not that worktree's own marker and was not used. ${TRACKED_REMEDY.join(' ')}`);
973
- const refreshed = await refreshCoordinationToken('rejected-token-not-real', plainShellTokenDeps(fetchCredential));
974
- expect(refreshed.status).toBe('misconfigured');
975
- expect(fetchCredential).not.toHaveBeenCalled();
976
- expect(cacheFilesIn(wt)).toEqual([]);
977
- });
978
- it(`worktree ${index + 1}: status prints no resolved team and no Ready`, async () => {
979
- const { main, worktrees } = makeTrackedMarkerProject();
980
- const wt = worktrees[index];
981
- process.env.MX_PROJECT_ROOT = main;
982
- plainShellAt(wt);
983
- // The real token path, so nothing in this test hands status a credential.
984
- await runStatus({ fetch: okFetch(), registration: { ...noOffline } });
985
- const out = logs.join('\n');
986
- expect(out).toContain('Team: not set');
987
- expect(out).not.toMatch(/Team: +product/);
988
- expect(out).not.toContain('✓ Ready');
989
- expect(out).not.toContain('Token cached: yes');
990
- expect(out).toContain('Registered: unverified (source: no roster consulted: no team was resolved)');
991
- // The reason once, on the Status line. The remedy once, under it. Neither
992
- // a second time through the token path.
993
- expect(out.split('is tracked or staged in git on the branch that worktree has checked out')).toHaveLength(2);
994
- for (const line of TRACKED_REMEDY)
995
- expect(out.split(line)).toHaveLength(2);
996
- expect(out).not.toContain('The live service gave no answer either');
997
- expect(out).toContain('No team was looked up, because the marker in this worktree was not used.');
998
- expect(out).not.toContain('No team marker was found');
999
- expect(out).not.toContain('this directory names none');
1000
- expect(cacheFilesIn(wt)).toEqual([]);
1001
- });
1002
- it(`worktree ${index + 1}: escalate exits 1 and sends nothing; memory mode does not use the marker`, async () => {
1003
- const { main, worktrees } = makeTrackedMarkerProject();
1004
- const wt = worktrees[index];
1005
- process.env.MX_PROJECT_ROOT = main;
1006
- plainShellAt(wt);
1007
- const enqueue = vi.fn(async () => ({ messageId: 'never', duplicate: false }));
1008
- await expect(runEscalate({ to: 'product', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) }))
1009
- .rejects.toThrow('process.exit(1)');
1010
- expect(enqueue).not.toHaveBeenCalled();
1011
- const out = errs.join('\n');
1012
- expect(out.split('is tracked or staged in git on the branch that worktree has checked out')).toHaveLength(2);
1013
- for (const line of TRACKED_REMEDY)
1014
- expect(out.split(line)).toHaveLength(2);
1015
- expect(out).not.toContain('No team marker was found');
1016
- expect(resolveMemoryTeam()).not.toBe('product');
1017
- });
1018
- }
1019
- it('the main-checkout listing shows neither worktree as (team product): both are under the not-usable list with the reason', () => {
1020
- const { main, worktrees } = makeTrackedMarkerProject();
1021
- const lines = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main });
1022
- const text = lines.join('\n');
1023
- expect(text).not.toContain('(team product)');
1024
- expect(listMarkedWorktrees(main)).toEqual([]);
1025
- expect(text).toContain('These worktrees are not usable as they are:');
1026
- // A short reason per worktree, and the remedy once under the list.
1027
- for (const wt of worktrees) {
1028
- expect(lines).toContain(` the .mx-coordination-team marker in ${wt} is tracked or staged in git on the branch that worktree has checked out, so it is not that worktree's own marker and was not used`);
1029
- }
1030
- for (const line of TRACKED_REMEDY)
1031
- expect(text.split(line)).toHaveLength(2);
1032
- expect(lines.slice(-TRACKED_REMEDY.length)).toEqual([...TRACKED_REMEDY]);
1033
- });
1034
- it('a tracked credential cache file refuses the worktree too, with no file name from disk next to a command', async () => {
1035
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1036
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1037
- writeFileSync(join(worktree, '.mx-coordination-token--life-planner--alpha'), 'committed-token-not-real\n');
1038
- git(worktree, 'add', '-f', '.mx-coordination-token--life-planner--alpha');
1039
- git(worktree, 'commit', '-q', '-m', 'a cache file committed by mistake');
1040
- const fetchCredential = issued();
1041
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
1042
- expect(res.status).toBe('misconfigured');
1043
- expect(res.token).toBeUndefined();
1044
- expect(res.detail).toContain(`a credential cache file (.mx-coordination-token--*) in ${worktree} is tracked or staged in git on the branch that worktree has checked out, so the marker and the cache there were not used. ${TRACKED_REMEDY[0]}`);
1045
- expect(res.detail).not.toContain('life-planner--alpha');
1046
- expect(fetchCredential).not.toHaveBeenCalled();
1047
- });
1048
- it('when git cannot say whether the marker is tracked, the marker is refused (could not check is not checked)', async () => {
1049
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1050
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1051
- const locate = { cwd: worktree, projectRoot: () => main, trackedFiles: () => undefined };
1052
- const read = readTeamMarker({ root: worktree, source: 'git-toplevel' }, locate);
1053
- expect(read).toMatchObject({ kind: 'refused', reason: 'tracked-unknown' });
1054
- const fetchCredential = issued();
1055
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate });
1056
- expect(res.status).toBe('misconfigured');
1057
- expect(res.detail).toBe(`git could not say whether the .mx-coordination-team marker in ${worktree} is tracked or staged, so the marker was not used. Run \`git ls-files\` in that directory to see the error.`);
1058
- expect(fetchCredential).not.toHaveBeenCalled();
1059
- });
1060
- it('the tracked question runs through the hardened git call: argv array, stripped environment, timeout; a failure is undefined', () => {
1061
- process.env.MX_COORD_SERVICE_TOKEN = 'fake-service-token';
1062
- process.env.MX_COORD_ADMIN_TOKEN = 'fake-admin-token';
1063
- process.env.MX_API_KEY = 'fake-user-key';
1064
- const calls = [];
1065
- const exec = (file, args, options) => { calls.push({ file, args, options }); return '.mx-coordination-team\0.mx-coordination-token--p--t\0'; };
1066
- expect(defaultTrackedCoordinationFiles('/p/.worktrees/a', exec)).toEqual(['.mx-coordination-team', '.mx-coordination-token--p--t']);
1067
- expect(calls).toHaveLength(1);
1068
- expect(calls[0].file).toBe('git');
1069
- expect(calls[0].args).toEqual(['-c', 'core.fsmonitor=false', 'ls-files', '-z', '--', ':(icase).mx-coordination-team', ':(icase).mx-coordination-token--*']);
1070
- expect(calls[0].options.cwd).toBe('/p/.worktrees/a');
1071
- expect(calls[0].options.timeout).toBe(5_000);
1072
- expect(calls[0].options).not.toHaveProperty('shell');
1073
- for (const k of ['MX_COORD_SERVICE_TOKEN', 'MX_COORD_ADMIN_TOKEN', 'MX_API_KEY'])
1074
- expect(calls[0].options.env).not.toHaveProperty(k);
1075
- expect(defaultTrackedCoordinationFiles('/p', () => { throw new Error('timed out'); })).toBeUndefined();
1076
- expect(defaultTrackedCoordinationFiles('/p', () => '')).toEqual([]);
1077
- });
1078
- // #548 flipped this test on purpose. Until #548 it was named "the tracked marker
1079
- // is used exactly as at 082c7d8 (this PR does not fix sessions, #527 does)" and
1080
- // pinned that a session acted as `product`. A session `mx-agent start` launches
1081
- // now carries MX_COORD_EXPECT_TEAM, and every coordination command refuses the
1082
- // mismatched marker before any credential. The case without the variable is
1083
- // kept below it, unchanged, because #548 criterion 7b requires exactly that.
1084
- it('CLAUDE_WORKTREE_PATH and MX_COORD_EXPECT_TEAM set: the tracked marker is refused by escalate and status, and nothing is sent (#548 fixes sessions)', async () => {
1085
- const { main, worktrees } = makeTrackedMarkerProject();
1086
- const wt = worktrees[0];
1087
- writeFileSync(join(wt, '.mx-code-context.json'), JSON.stringify({ team: 'personal-coach' }));
1088
- process.env.MX_PROJECT_ROOT = main;
1089
- process.env.CLAUDE_WORKTREE_PATH = wt;
1090
- process.env.MX_COORD_EXPECT_TEAM = 'personal-coach';
1091
- plainShellAt(wt);
1092
- // readTeamMarker itself is unchanged for every caller (#548 criterion 9).
1093
- expect(readTeamMarker({ root: wt, source: 'CLAUDE_WORKTREE_PATH' })).toEqual({ kind: 'ok', line: 'product' });
1094
- const enqueue = vi.fn(async () => ({ messageId: 'never', duplicate: false }));
1095
- await expect(runEscalate({ to: 'engineering', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) }))
1096
- .rejects.toThrow('process.exit(1)');
1097
- expect(enqueue).not.toHaveBeenCalled();
1098
- await expect(runStatus({ fetch: okFetch(), registration: { client: recordingClient(enqueue), ...noOffline } }))
1099
- .rejects.toThrow('process.exit(1)');
1100
- expect(logs.join('\n')).not.toMatch(/Team: +product/);
1101
- const out = errs.join('\n');
1102
- expect(out).toContain(`The .mx-coordination-team marker at ${join(wt, '.mx-coordination-team')} names team "product", but this session was started as team "personal-coach"`);
1103
- expect(cacheFilesIn(wt)).toEqual([]);
1104
- });
1105
- it('CLAUDE_WORKTREE_PATH set and MX_COORD_EXPECT_TEAM absent: the tracked marker is used exactly as at 082c7d8 (#548 criterion 7b)', async () => {
1106
- const { main, worktrees } = makeTrackedMarkerProject();
1107
- const wt = worktrees[0];
1108
- writeFileSync(join(wt, '.mx-code-context.json'), JSON.stringify({ team: 'personal-coach' }));
1109
- process.env.MX_PROJECT_ROOT = main;
1110
- process.env.CLAUDE_WORKTREE_PATH = wt;
1111
- plainShellAt(wt);
1112
- expect(readTeamMarker({ root: wt, source: 'CLAUDE_WORKTREE_PATH' })).toEqual({ kind: 'ok', line: 'product' });
1113
- const fetchCredential = issued();
1114
- const res = await resolveCoordinationToken({ ...plainShellTokenDeps(fetchCredential), writeCache: () => true });
1115
- expect(res.status).toBe('resolved');
1116
- expect(res.slug).toBe('product');
1117
- expect(fetchCredential.mock.calls[0][0].team).toBe('product');
1118
- expect(resolveMemoryTeam()).toBe('product');
1119
- const enqueue = vi.fn(async () => ({ messageId: 'm1', duplicate: false }));
1120
- await runEscalate({ to: 'engineering', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) });
1121
- expect(enqueue).toHaveBeenCalledWith(expect.objectContaining({ from: 'product' }));
1122
- await runStatus({ fetch: okFetch(), registration: { client: recordingClient(enqueue), ...noOffline } });
1123
- expect(logs.join('\n')).toMatch(/Team: {14}product\n/);
1124
- });
1125
- });
1126
- describe('red-team finding 1: a cwd-located marker that disagrees with .mx-code-context.json names no team', () => {
1127
- const okFetch = () => vi.fn(async (_url) => new Response('ok', { status: 200 }));
1128
- /** An UNTRACKED marker `product` in a worktree whose code-context file says `personal-coach`. */
1129
- function mismatch() {
1130
- const { main, worktree } = makeProject('life-planner', 'life-planner', ['personal-coach-20260927']);
1131
- writeFileSync(join(worktree, '.mx-coordination-team'), 'product\n');
1132
- writeFileSync(join(worktree, '.mx-code-context.json'), JSON.stringify({ product: 'life-planner', team: 'personal-coach' }));
1133
- process.env.MX_PROJECT_ROOT = main;
1134
- plainShellAt(worktree);
1135
- return { main, worktree };
1136
- }
1137
- it('the token path requests nothing, caches nothing, and names both values and both files', async () => {
1138
- const { worktree } = mismatch();
1139
- const fetchCredential = issued();
1140
- const res = await resolveCoordinationToken(plainShellTokenDeps(fetchCredential));
1141
- expect(res.status).toBe('identity-mismatch');
1142
- expect(res.token).toBeUndefined();
1143
- expect(res.detail).toContain(`the .mx-coordination-team marker in ${worktree} names team "product" and .mx-code-context.json in the same worktree names team "personal-coach"`);
1144
- const refreshed = await refreshCoordinationToken('rejected-token-not-real', plainShellTokenDeps(fetchCredential));
1145
- expect(refreshed.status).toBe('identity-mismatch');
1146
- expect(fetchCredential).not.toHaveBeenCalled();
1147
- expect(cacheFilesIn(worktree)).toEqual([]);
1148
- });
1149
- it('status prints no resolved team and no Ready; escalate exits 1; memory mode and the listing do not use the marker', async () => {
1150
- const { main, worktree } = mismatch();
1151
- await runStatus({ fetch: okFetch(), registration: { ...noOffline } });
1152
- const out = logs.join('\n');
1153
- expect(out).toContain('Team: not set');
1154
- expect(out).not.toMatch(/Team: +product/);
1155
- expect(out).not.toContain('✓ Ready');
1156
- expect(out).toContain('names team "product" and .mx-code-context.json in the same worktree names team "personal-coach"');
1157
- expect(out).not.toContain('No team marker was found');
1158
- const enqueue = vi.fn(async () => ({ messageId: 'never', duplicate: false }));
1159
- await expect(runEscalate({ to: 'product', priority: 'p2', body: 'hello' }, { client: recordingClient(enqueue) }))
1160
- .rejects.toThrow('process.exit(1)');
1161
- expect(enqueue).not.toHaveBeenCalled();
1162
- expect(errs.join('\n')).toContain('names team "product"');
1163
- expect(resolveMemoryTeam()).not.toBe('product');
1164
- const text = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main }).join('\n');
1165
- expect(text).not.toContain('(team product)');
1166
- expect(text).toContain('These worktrees are not usable as they are:');
1167
- expect(cacheFilesIn(worktree)).toEqual([]);
1168
- });
1169
- const controls = [
1170
- ['no code-context file', undefined],
1171
- ['a code-context file that agrees', (wt) => writeFileSync(join(wt, '.mx-code-context.json'), JSON.stringify({ team: 'alpha' }))],
1172
- ['a code-context file that is not JSON', (wt) => writeFileSync(join(wt, '.mx-code-context.json'), '{ not json')],
1173
- ['a code-context file with no team', (wt) => writeFileSync(join(wt, '.mx-code-context.json'), JSON.stringify({ product: 'life-planner' }))],
1174
- ['a code-context file whose team is not a valid slug', (wt) => writeFileSync(join(wt, '.mx-code-context.json'), JSON.stringify({ team: 'Not A Slug\x1b[31m' }))],
1175
- ['a code-context file that is a symbolic link (unreadable, so not evidence)', (wt) => {
1176
- writeFileSync(join(base, 'elsewhere.json'), JSON.stringify({ team: 'beta' }));
1177
- symlinkSync(join(base, 'elsewhere.json'), join(wt, '.mx-code-context.json'));
1178
- }],
1179
- ];
1180
- for (const [label, setup] of controls) {
1181
- it(`control: an untracked marker with ${label} resolves the marker's team`, async () => {
1182
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1183
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1184
- setup?.(worktree);
1185
- expect(readTeamMarker({ root: worktree, source: 'git-toplevel' })).toEqual({ kind: 'ok', line: 'alpha' });
1186
- const fetchCredential = issued();
1187
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
1188
- expect(res.status).toBe('resolved');
1189
- expect(res.slug).toBe('alpha');
1190
- expect(fetchCredential.mock.calls[0][0].team).toBe('alpha');
1191
- });
1192
- }
1193
- });
1194
- describe.skipIf(typeof process.getuid !== 'function')('round 4 small items', () => {
1195
- it('N09: more than 20 refused worktrees print 20 and a count of the rest', () => {
1196
- const { main } = makeProject('life-planner', 'life-planner', []);
1197
- for (let i = 0; i < 25; i++)
1198
- chmodSync(fakeWorktree(main, `gw${String(i).padStart(2, '0')}`, 'alpha\n'), 0o775);
1199
- const lines = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main, ...NOT_TRACKED });
1200
- const at = lines.indexOf('These worktrees are not usable as they are:');
1201
- expect(at).toBeGreaterThan(-1);
1202
- const refused = lines.slice(at + 1);
1203
- expect(refused.filter((l) => l.includes('is group- or world-writable (mode 775)'))).toHaveLength(20);
1204
- expect(refused[refused.length - 1]).toBe(' and 5 more');
1205
- expect(refused).toHaveLength(21);
1206
- });
1207
- it('a symbolic link under .worktrees/ is reported as a link, with no chmod advice and no team', () => {
1208
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1209
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1210
- const link = join(main, '.worktrees', 'linked');
1211
- symlinkSync(worktree, link);
1212
- const lines = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main });
1213
- const about = lines.filter((l) => l.includes(link));
1214
- expect(about).toEqual([` ${link} is a symbolic link, not a worktree directory, so it was not used; run the command from the directory it points to`]);
1215
- expect(lines.join('\n')).not.toContain('mode 777');
1216
- expect(lines.join('\n')).not.toContain('chmod');
1217
- // The real directory is still listed, once, under its own path.
1218
- expect(lines).toContain(` ${worktree} (team alpha)`);
1219
- });
1220
- });
1221
- // ── Fix round 5: reviews at 2b8c8fd ─────────────────────────────────────
1222
- /** Every backticked `git ...` span the remedy prints, in order. */
1223
- const printedGitCommands = () => TRACKED_REMEDY.flatMap((line) => [...line.matchAll(/`(git [^`]+)`/g)].map((m) => m[1]));
1224
- /** The check of step 2a: lists what is staged other than the marker and the cache files. */
1225
- const isCheckStep = (command) => command.startsWith('git diff --cached --name-status');
1226
- /** The check of step 1a: lists the marker and the cache files still in the index. */
1227
- const isRemovalCheckStep = (command) => command.startsWith('git ls-files');
1228
- /** The end check of step 2e: reports each of the two files as ignored or not. */
1229
- const isEndCheckStep = (command) => command.startsWith('git status');
1230
- /** The printed commands up to and including the check of step 2a. */
1231
- const throughCheck = () => printedGitCommands().slice(0, printedGitCommands().findIndex(isCheckStep) + 1);
1232
- /** An identity for the printed `git commit`, which runs through a shell with no `-c user.*`. */
1233
- const PRINTED_COMMIT_ENV = { GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@e.com', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@e.com' };
1234
- /**
1235
- * The environment the printed commands run in: no inherited GIT_* variable (a
1236
- * pathspec switch such as GIT_LITERAL_PATHSPECS would change what every printed
1237
- * pathspec means) and no coordination credential, as `runGit` strips them
1238
- * (security review of PR #561, INFO). Then the commit identity.
1239
- */
1240
- function printedCommandEnv() {
1241
- const env = {};
1242
- for (const [k, v] of Object.entries(process.env)) {
1243
- if (!k.startsWith('GIT_') && !GIT_CHILD_STRIP.includes(k))
1244
- env[k] = v;
1245
- }
1246
- return { ...env, ...PRINTED_COMMIT_ENV };
1247
- }
1248
- /** The printed `git add` of step 2b, whatever pathspec form it takes. */
1249
- const isAddStep = (command) => command.startsWith('git add ') && command.includes('.gitignore');
1250
- /** The two ignore rules step 2 names: its backticked spans that are not commands. */
1251
- function printedIgnoreRules() {
1252
- const line = TRACKED_REMEDY.find((l) => l.includes('Add two lines'));
1253
- if (line === undefined)
1254
- throw new Error('the remedy names no ignore rules');
1255
- const rules = [...line.matchAll(/`([^`]+)`/g)].map((m) => m[1]).filter((span) => !span.startsWith('git '));
1256
- expect(rules).toEqual(['.mx-coordination-team', '.mx-coordination-token--*']);
1257
- return rules;
1258
- }
1259
- /**
1260
- * The manual edit of step 2: each rule as a line of .gitignore, leaving out a
1261
- * line it already holds, plus any exact case-variant name step 1 removed
1262
- * (`extra`), as step 2b says.
1263
- */
1264
- function addPrintedIgnoreRules(dir, extra = []) {
1265
- const path = join(dir, '.gitignore');
1266
- const before = existsSync(path) ? readFileSync(path, 'utf-8') : '';
1267
- const held = new Set(before.split('\n'));
1268
- const added = [...printedIgnoreRules(), ...extra].filter((rule) => !held.has(rule));
1269
- const sep = before === '' || before.endsWith('\n') ? '' : '\n';
1270
- writeFileSync(path, `${before}${sep}${added.map((rule) => `${rule}\n`).join('')}`);
1271
- }
1272
- /**
1273
- * Follow the remedy in `dir` as an operator who reads it literally does: run
1274
- * every git command it prints, exactly as printed, through a shell, and make
1275
- * the .gitignore edit of step 2 by hand just before the printed
1276
- * `git add` of step 2b.
1277
- *
1278
- * The checks of steps 1a and 2a exit 0 whatever they print, so this function
1279
- * carries the text's stop rule: when either prints any line, it stops there
1280
- * and returns that output, and nothing after it runs (#540). The end check of
1281
- * step 2e is returned in `output` for the test to read.
1282
- *
1283
- * `skipRemoval` does not run the printed `git rm` of step 1. It stands in for a
1284
- * step 1 that matched nothing, on another git version or for an odd name
1285
- * (red-team, Step 6 on PR #561). `extraIgnore` is the case-variant name step 2b
1286
- * tells the operator to add. `beforeCommit` runs just before the printed
1287
- * `git commit`, for a fixture that changes the index there.
1288
- *
1289
- * The step 1a listing is printed twice, at 1a and again at the start of 2e.
1290
- * Both stop the steps when they print a line; `output` holds the later run.
1291
- *
1292
- * Every other command must exit 0, except the printed `git commit` when
1293
- * `nothingToCommit` is set: the text says a non-zero exit is expected there
1294
- * when .gitignore already held both lines and step 1 removed nothing.
1295
- *
1296
- * `from: 'check'` resumes at the check, which is what the text says to do after
1297
- * the operator commits or unstages the files it printed.
1298
- *
1299
- * `cwd` is where the operator pastes the commands, `dir` or any directory
1300
- * inside it: the refusal fires from any of them (security review of PR #561).
1301
- * The .gitignore edit is always made in `dir`, the worktree's top directory,
1302
- * as step 2b says.
1303
- *
1304
- * Criterion 8 of #540 needs the regression test to fail on the text at
1305
- * 93f738a, whose step 2 printed no command and said in prose to "commit both
1306
- * changes". When the remedy prints no `git commit`, the operator follows that
1307
- * prose with a plain `git commit`, which commits everything staged. The current
1308
- * text always prints a `git commit` (the span list test pins it), so that
1309
- * branch models only the text #540 replaced.
1310
- */
1311
- function followPrintedRemedy(dir, opts = {}) {
1312
- const commands = printedGitCommands();
1313
- const start = opts.from === 'check' ? commands.findIndex(isCheckStep) : 0;
1314
- expect(start).toBeGreaterThanOrEqual(0);
1315
- const run = { ran: [], output: {} };
1316
- let edited = false;
1317
- for (const command of commands.slice(start)) {
1318
- if (opts.skipRemoval && command.startsWith('git rm '))
1319
- continue;
1320
- if (isAddStep(command)) {
1321
- addPrintedIgnoreRules(dir, opts.extraIgnore);
1322
- edited = true;
1323
- }
1324
- if (command.startsWith('git commit'))
1325
- opts.beforeCommit?.();
1326
- const r = spawnSync('bash', ['-c', command], { cwd: opts.cwd ?? dir, encoding: 'utf-8', env: printedCommandEnv() });
1327
- run.ran.push(command);
1328
- run.output[command] = r.stdout;
1329
- if (command.startsWith('git commit')) {
1330
- run.commitStatus = r.status ?? -1;
1331
- if (opts.nothingToCommit && r.status !== 0)
1332
- continue;
1333
- }
1334
- if (r.status !== 0)
1335
- throw new Error(`${command}: ${r.stderr}`);
1336
- if ((isCheckStep(command) || isRemovalCheckStep(command)) && r.stdout.trim() !== '') {
1337
- run.stopped = r.stdout;
1338
- run.stoppedAt = command;
1339
- return run;
1340
- }
1341
- }
1342
- if (!commands.some((c) => c.startsWith('git commit'))) {
1343
- if (!edited)
1344
- addPrintedIgnoreRules(dir);
1345
- git(dir, 'add', '.gitignore');
1346
- git(dir, 'commit', '-q', '-m', 'stop tracking the coordination marker');
1347
- }
1348
- return run;
1349
- }
1350
- /** Steps 3 and 4: delete the leftover file, then what `mx-agent start <team>` does to the marker (start.ts step 5a). */
1351
- function deleteLeftoverThenStartWritesMarker(dir, team) {
1352
- rmSync(join(dir, '.mx-coordination-team'), { force: true });
1353
- if (!existsSync(join(dir, '.mx-coordination-team')))
1354
- writeFileSync(join(dir, '.mx-coordination-team'), team);
1355
- }
1356
- describe('QA M2, red-team A and C: the tracked-file remedy works when followed exactly', () => {
1357
- const tokenIn = (main, wt, fetchCredential) => resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: wt, projectRoot: () => main } });
1358
- it('the remedy names both files, both ignore rules, the per-branch scope, and what start does', () => {
1359
- const text = TRACKED_REMEDY.join('\n');
1360
- expect(text).toContain("`git rm --cached -f --ignore-unmatch -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'`");
1361
- expect(text).toContain('`.mx-coordination-team` and `.mx-coordination-token--*`');
1362
- expect(text).toContain('Git tracks files per branch and every worktree has its own branch');
1363
- expect(text).toContain('Every other worktree stays refused until its own branch stops tracking the files');
1364
- expect(text).toContain('the branch that holds the commit from step 2d');
1365
- expect(text).toContain("3. On this first pass, before step 4, delete the .mx-coordination-team file left in that worktree's top directory.");
1366
- expect(text).toContain('If you repeat these steps after step 4, skip this step: the marker is then the one step 4 wrote for this team.');
1367
- expect(text).toContain('for a worktree directory named <team>-<date>, the part before the date');
1368
- expect(text).toContain('then opens a session');
1369
- // #540: check, stage, show, commit, and what each result means.
1370
- expect(text).toContain('If it prints any line, stop: a commit now would include those files.');
1371
- expect(text).toContain('Nothing has been committed yet. The removals from step 1 stay staged and the files stay on disk, so a commit you make now records those removals too. After you have committed or unstaged the printed files yourself, run step 2a again.');
1372
- expect(text).toContain('Steps 1 and 2a match the two names in any letter case, the way the check that refused this worktree does, so step 1 has already removed a marker or cache file whose name differs only in case, and step 2a does not print one.');
1373
- expect(text).toContain('If .gitignore already held every line it prints nothing, which is expected, and step 2d then reports nothing to commit unless step 1 removed a file.');
1374
- // QA W2 and W3 at 5f31405: the count includes exact case-variant names and, on a repeat, the operator's own correction.
1375
- expect(text).toContain('2 added, plus one for each exact name you added in step 2b (fewer if .gitignore already held a line), and 0 deleted.');
1376
- expect(text).toContain('On a repeat after you corrected .gitignore in step 2e, it also counts your own correction, for example 0 and 1 when you removed a negation line, which is expected.');
1377
- expect(text).toContain("to the .gitignore in the worktree's top directory");
1378
- expect(text).toContain('from any directory inside it');
1379
- // Red-team, Step 6 on PR #561: a positive check after step 1, an end check, a failed commit, case-variant names.
1380
- expect(text).toContain('It must print nothing. If it prints a line, stop: step 1 did not remove that file from the index, and a commit would record it. Nothing has been committed.');
1381
- expect(text).toContain('in five parts');
1382
- expect(text).toContain('Every line it prints must start with !!, which means git ignores that file.');
1383
- expect(text).toContain('for example because a later negation line such as !.mx-* includes it again');
1384
- // Security Should Fix and QA W1 at 5f31405: 2e repeats the listing, and says what each status output means.
1385
- expect(text).not.toContain('Any other line means git still tracks the file');
1386
- expect(text).toContain("` again. It must print nothing. A line means git still tracks that file: start again at step 1. Then run `git status");
1387
- expect(text).toContain('A line with any other status means git still tracks that file and it has changes: start again at step 1.');
1388
- expect(text).toContain('Empty output means neither file is on disk, which is fine once the listing before it printed nothing.');
1389
- expect(text).toContain('If the commit fails for another reason, for example a pre-commit hook or commit signing, nothing was committed and everything stays staged: fix the cause and run step 2d again.');
1390
- expect(text).toContain('If step 1 removed a file whose name differs from these only in letter case, add that exact name as a line too; on a case-insensitive file system this is unnecessary but harmless.');
1391
- expect(text).toContain('It should print the lines added, the lines deleted and .gitignore: 2 added');
1392
- expect(text).toContain('there is nothing to commit: git says so and exits non-zero, which is expected here');
1393
- // Constants only: nothing from disk can be inside a printed command.
1394
- expect([...text.matchAll(/`([^`]+)`/g)].map((m) => m[1])).toEqual([
1395
- "git rm --cached -f --ignore-unmatch -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1396
- "git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1397
- "git diff --cached --name-status -- ':(top)' ':(top,exclude,icase,glob).mx-coordination-tea[m]' ':(top,exclude,icase,glob).mx-coordination-token--*'",
1398
- '.mx-coordination-team',
1399
- '.mx-coordination-token--*',
1400
- "git add ':(top).gitignore'",
1401
- "git diff --cached --numstat -- ':(top).gitignore'",
1402
- "git commit -m 'Stop tracking the coordination marker and token cache files'",
1403
- "git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1404
- "git status --porcelain --ignored=matching --untracked-files=all -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1405
- 'mx-agent start <team>',
1406
- 'start',
1407
- ]);
1408
- });
1409
- it('two existing worktrees on their own branches: the one where the steps are followed resolves, the other stays refused', async () => {
1410
- const { main, worktrees } = makeTrackedMarkerProject();
1411
- const [first, second] = worktrees;
1412
- expect((await tokenIn(main, first, issued())).status).toBe('misconfigured');
1413
- // Steps 1 to 4, in the first worktree, as printed.
1414
- const run = followPrintedRemedy(first);
1415
- expect(run.stopped).toBeUndefined();
1416
- expect(run.ran).toEqual(printedGitCommands());
1417
- expect(run.ran).toHaveLength(8);
1418
- deleteLeftoverThenStartWritesMarker(first, 'personal-coach');
1419
- const fetchCredential = issued();
1420
- const fixed = await tokenIn(main, first, fetchCredential);
1421
- expect(fixed.status).toBe('resolved');
1422
- expect(fixed.slug).toBe('personal-coach');
1423
- expect(fetchCredential.mock.calls[0][0].team).toBe('personal-coach');
1424
- // The second worktree is on its own branch. Nothing was done there.
1425
- const untouched = issued();
1426
- const still = await tokenIn(main, second, untouched);
1427
- expect(still.status).toBe('misconfigured');
1428
- expect(untouched).not.toHaveBeenCalled();
1429
- const listing = markerNextStep({ ok: false, reason: 'main-checkout', top: main, detail: '' }, { projectRoot: () => main });
1430
- expect(listing).toContain(` ${first} (team personal-coach)`);
1431
- expect(listing.join('\n')).not.toContain(`${second} (team`);
1432
- });
1433
- it('the QA M2 path stays refused: the untrack commit on the base branch alone does not reach an existing worktree', async () => {
1434
- const { main, worktrees } = makeTrackedMarkerProject();
1435
- const [first] = worktrees;
1436
- // What QA did at 2b8c8fd: steps 1 and 2 on the base branch, steps 3 and 4 in the worktree.
1437
- expect(followPrintedRemedy(main).stopped).toBeUndefined();
1438
- deleteLeftoverThenStartWritesMarker(first, 'personal-coach');
1439
- const fetchCredential = issued();
1440
- const res = await tokenIn(main, first, fetchCredential);
1441
- expect(res.status).toBe('misconfigured');
1442
- expect(fetchCredential).not.toHaveBeenCalled();
1443
- });
1444
- it('the other route the remedy names: merging the branch that holds the commit, then steps 3 and 4', async () => {
1445
- const { main, worktrees } = makeTrackedMarkerProject();
1446
- const [first, second] = worktrees;
1447
- expect(followPrintedRemedy(first).stopped).toBeUndefined();
1448
- git(second, 'merge', '-q', '--no-edit', 'worktree/personal-coach-20260927');
1449
- expect(defaultTrackedCoordinationFiles(second)).toEqual([]);
1450
- deleteLeftoverThenStartWritesMarker(second, 'engineering');
1451
- const res = await tokenIn(main, second, issued());
1452
- expect(res.status).toBe('resolved');
1453
- expect(res.slug).toBe('engineering');
1454
- });
1455
- it('a credential cache file that is staged and not committed is refused as tracked or staged, and step 1 clears it', async () => {
1456
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1457
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1458
- const cache = join(worktree, '.mx-coordination-token--life-planner--alpha');
1459
- writeFileSync(cache, 'staged-token-not-real\n', { mode: 0o600 });
1460
- // What `mx-agent start` does where no ignore rule covers the cache (start.ts, `git add -A`).
1461
- git(worktree, 'add', '-A');
1462
- // The file changes after it was staged, as a refreshed token would change it.
1463
- writeFileSync(cache, 'rotated-token-not-real\n', { mode: 0o600 });
1464
- const refusedFetch = issued();
1465
- const refused = await tokenIn(main, worktree, refusedFetch);
1466
- expect(refused.status).toBe('misconfigured');
1467
- expect(refused.detail).toContain('is tracked or staged in git on the branch that worktree has checked out');
1468
- expect(refused.detail).not.toContain('life-planner--alpha');
1469
- expect(refusedFetch).not.toHaveBeenCalled();
1470
- expect(followPrintedRemedy(worktree).stopped).toBeUndefined();
1471
- expect(existsSync(cache)).toBe(true);
1472
- const fetchCredential = issued();
1473
- const res = await tokenIn(main, worktree, fetchCredential);
1474
- expect(res.status).toBe('resolved');
1475
- expect(res.source).toBe('cache');
1476
- expect(fetchCredential).not.toHaveBeenCalled();
1477
- });
1478
- });
1479
- // ── #540: step 2 commits only what the remedy means to commit ───────────
1480
- const MARKER = '.mx-coordination-team';
1481
- const CACHE = '.mx-coordination-token--x--y';
1482
- const REMEDY_COMMIT_MESSAGE = 'Stop tracking the coordination marker and token cache files';
1483
- function gitOut(cwd, ...a) {
1484
- const r = spawnSync('git', ['-c', 'user.email=t@e.com', '-c', 'user.name=t', ...a], { cwd, encoding: 'utf-8' });
1485
- if (r.status !== 0)
1486
- throw new Error(r.stderr);
1487
- return r.stdout;
1488
- }
1489
- /**
1490
- * The fixture #540's success criteria name. A linked worktree whose .gitignore
1491
- * holds neither rule, with the marker and the cache file `.mx-coordination-token--x--y`
1492
- * both staged.
1493
- *
1494
- * - 'tracked': HEAD holds the marker and the cache file (#527's layout), and
1495
- * the worktree has staged new contents for both.
1496
- * - 'staged-only': HEAD holds neither, and both are staged as new files, as
1497
- * `mx-agent start` staged them with `git add -A` in Life Planner (1b).
1498
- */
1499
- function makeRemedyFixture(variant) {
1500
- const main = join(base, 'life-planner');
1501
- mkdirSync(main, { recursive: true });
1502
- git(main, 'init', '-q', '-b', 'main');
1503
- writeFileSync(join(main, 'mx-agent.config.json'), JSON.stringify({ projectSlug: 'life-planner', coordinationMode: 'queue' }));
1504
- writeFileSync(join(main, '.gitignore'), '.worktrees/\n');
1505
- // A subdirectory with its own tracked .gitignore, where an operator may paste the steps.
1506
- mkdirSync(join(main, 'sub'));
1507
- writeFileSync(join(main, 'sub', '.gitignore'), '*.log\n');
1508
- if (variant === 'tracked') {
1509
- writeFileSync(join(main, MARKER), 'product\n');
1510
- writeFileSync(join(main, CACHE), 'committed-token-not-real\n', { mode: 0o600 });
1511
- }
1512
- git(main, 'add', '-A');
1513
- git(main, 'commit', '-q', '-m', 'init');
1514
- const wt = join(main, '.worktrees', 'personal-coach-20260927');
1515
- git(main, 'worktree', 'add', '-q', '-b', 'worktree/personal-coach-20260927', wt);
1516
- chmodSync(wt, 0o755);
1517
- writeFileSync(join(wt, MARKER), 'personal-coach\n');
1518
- writeFileSync(join(wt, CACHE), 'staged-token-not-real\n', { mode: 0o600 });
1519
- git(wt, 'add', '--', MARKER, CACHE);
1520
- expect(gitOut(wt, 'diff', '--cached', '--name-status')).toBe(variant === 'tracked' ? `M\t${MARKER}\nM\t${CACHE}\n` : `A\t${MARKER}\nA\t${CACHE}\n`);
1521
- return wt;
1522
- }
1523
- const headOf = (dir) => gitOut(dir, 'rev-parse', 'HEAD').trim();
1524
- const stagedIn = (dir) => gitOut(dir, 'diff', '--cached', '--name-status');
1525
- const showHead = (dir) => gitOut(dir, 'show', '--name-status', '--format=', 'HEAD');
1526
- const NUMSTAT = "git diff --cached --numstat -- ':(top).gitignore'";
1527
- const END_CHECK = "git status --porcelain --ignored=matching --untracked-files=all -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'";
1528
- const BOTH_IGNORED = `!! ${MARKER}\n!! ${CACHE}\n`;
1529
- /** Criterion 3: both files untracked, ignored and still on disk with the contents they had. */
1530
- function expectUntrackedIgnoredOnDisk(wt) {
1531
- expect(gitOut(wt, 'ls-files', '--', MARKER, CACHE)).toBe('');
1532
- expect(gitOut(wt, 'check-ignore', '--', MARKER, CACHE)).toBe(`${MARKER}\n${CACHE}\n`);
1533
- expect(readFileSync(join(wt, MARKER), 'utf-8')).toBe('personal-coach\n');
1534
- expect(readFileSync(join(wt, CACHE), 'utf-8')).toBe('staged-token-not-real\n');
1535
- }
1536
- describe('#540: the printed step 2 commits only the ignore rules and the removal of the two files', () => {
1537
- it('criterion 1 (regression, criterion 8): a staged notes.txt is printed by the check and the steps stop with nothing committed', () => {
1538
- const wt = makeRemedyFixture('tracked');
1539
- writeFileSync(join(wt, 'notes.txt'), 'the operator\'s own work\n');
1540
- git(wt, 'add', 'notes.txt');
1541
- const before = headOf(wt);
1542
- const run = followPrintedRemedy(wt);
1543
- // Nothing was committed, and notes.txt is still staged, not discarded.
1544
- expect(headOf(wt)).toBe(before);
1545
- expect(stagedIn(wt)).toContain('A\tnotes.txt\n');
1546
- expect(readFileSync(join(wt, 'notes.txt'), 'utf-8')).toBe('the operator\'s own work\n');
1547
- // The check printed notes.txt, and only notes.txt: the marker and the cache are excluded.
1548
- expect(run.stopped).toBe('A\tnotes.txt\n');
1549
- expect(run.ran).toEqual(throughCheck());
1550
- // The steps stopped before the .gitignore edit.
1551
- expect(readFileSync(join(wt, '.gitignore'), 'utf-8')).toBe('.worktrees/\n');
1552
- });
1553
- it('criterion 1a: once the operator unstages notes.txt, the check prints nothing and the commit is exactly .gitignore and the two removals', () => {
1554
- const wt = makeRemedyFixture('tracked');
1555
- writeFileSync(join(wt, 'notes.txt'), 'the operator\'s own work\n');
1556
- git(wt, 'add', 'notes.txt');
1557
- const before = headOf(wt);
1558
- expect(followPrintedRemedy(wt).stopped).toBe('A\tnotes.txt\n');
1559
- // The operator unstages it, which the text leaves to them, then runs the check again.
1560
- git(wt, 'restore', '--staged', 'notes.txt');
1561
- const run = followPrintedRemedy(wt, { from: 'check' });
1562
- expect(run.stopped).toBeUndefined();
1563
- expect(run.output[printedGitCommands().find(isCheckStep)]).toBe('');
1564
- expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
1565
- expect(run.commitStatus).toBe(0);
1566
- expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
1567
- expect(showHead(wt)).toBe(`M\t.gitignore\nD\t${MARKER}\nD\t${CACHE}\n`);
1568
- // notes.txt is untouched: on disk, untracked, not in the commit.
1569
- expect(gitOut(wt, 'status', '--porcelain', '--', 'notes.txt')).toBe('?? notes.txt\n');
1570
- expectUntrackedIgnoredOnDisk(wt);
1571
- });
1572
- it('criterion 1b, the Life Planner case: a marker and a cache file only staged give a commit of .gitignore alone', () => {
1573
- const wt = makeRemedyFixture('staged-only');
1574
- const before = headOf(wt);
1575
- const run = followPrintedRemedy(wt);
1576
- expect(run.stopped).toBeUndefined();
1577
- expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
1578
- expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
1579
- expect(showHead(wt)).toBe('M\t.gitignore\n');
1580
- expect(gitOut(wt, 'show', 'HEAD:.gitignore')).toBe(`.worktrees/\n${MARKER}\n.mx-coordination-token--*\n`);
1581
- expect(stagedIn(wt)).toBe('');
1582
- expectUntrackedIgnoredOnDisk(wt);
1583
- });
1584
- it('criterion 1c: an unrelated .gitignore edit already staged is printed by the check and the steps stop with nothing committed', () => {
1585
- const wt = makeRemedyFixture('tracked');
1586
- writeFileSync(join(wt, '.gitignore'), '.worktrees/\nbuild/\n');
1587
- git(wt, 'add', '.gitignore');
1588
- const before = headOf(wt);
1589
- const run = followPrintedRemedy(wt);
1590
- expect(run.stopped).toBe('M\t.gitignore\n');
1591
- expect(headOf(wt)).toBe(before);
1592
- // The operator's staged .gitignore is as they left it: no rule was added to it.
1593
- expect(gitOut(wt, 'show', ':.gitignore')).toBe('.worktrees/\nbuild/\n');
1594
- expect(readFileSync(join(wt, '.gitignore'), 'utf-8')).toBe('.worktrees/\nbuild/\n');
1595
- });
1596
- it('criteria 2 and 3: with nothing else staged, the commit is exactly the intended change and both files end untracked, ignored and on disk', () => {
1597
- const wt = makeRemedyFixture('tracked');
1598
- const before = headOf(wt);
1599
- const run = followPrintedRemedy(wt);
1600
- expect(run.stopped).toBeUndefined();
1601
- expect(run.ran).toEqual(printedGitCommands());
1602
- expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
1603
- expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
1604
- expect(gitOut(wt, 'log', '-1', '--format=%s').trim()).toBe(REMEDY_COMMIT_MESSAGE);
1605
- expect(run.output[END_CHECK]).toBe(BOTH_IGNORED);
1606
- expect(showHead(wt)).toBe(`M\t.gitignore\nD\t${MARKER}\nD\t${CACHE}\n`);
1607
- expect(gitOut(wt, 'show', 'HEAD:.gitignore')).toBe(`.worktrees/\n${MARKER}\n.mx-coordination-token--*\n`);
1608
- expect(stagedIn(wt)).toBe('');
1609
- expectUntrackedIgnoredOnDisk(wt);
1610
- });
1611
- it('a second pass changes nothing: the commit finds nothing to commit and exits non-zero, as the text says', () => {
1612
- const wt = makeRemedyFixture('tracked');
1613
- followPrintedRemedy(wt);
1614
- const after = headOf(wt);
1615
- const again = followPrintedRemedy(wt, { nothingToCommit: true });
1616
- expect(again.stopped).toBeUndefined();
1617
- expect(again.output[NUMSTAT]).toBe('');
1618
- expect(again.commitStatus).not.toBe(0);
1619
- expect(headOf(wt)).toBe(after);
1620
- expectUntrackedIgnoredOnDisk(wt);
1621
- });
1622
- it('QA M2: .gitignore already holds both lines, so step 2c prints nothing and step 2d commits only the removals', () => {
1623
- const wt = makeRemedyFixture('tracked');
1624
- writeFileSync(join(wt, '.gitignore'), `.worktrees/\n${MARKER}\n.mx-coordination-token--*\n`);
1625
- git(wt, 'commit', '-q', '-m', 'the rules, committed earlier', '--', '.gitignore');
1626
- const before = headOf(wt);
1627
- const run = followPrintedRemedy(wt);
1628
- expect(run.stopped).toBeUndefined();
1629
- expect(run.output[NUMSTAT]).toBe('');
1630
- expect(run.commitStatus).toBe(0);
1631
- expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
1632
- expect(showHead(wt)).toBe(`D\t${MARKER}\nD\t${CACHE}\n`);
1633
- expectUntrackedIgnoredOnDisk(wt);
1634
- });
1635
- it('a staged marker whose name differs only in case is removed from the index by step 1 and never committed', () => {
1636
- const wt = makeRemedyFixture('staged-only');
1637
- // core.ignorecase is false on this fixture, so git tracks the two names apart.
1638
- writeFileSync(join(wt, '.MX-Coordination-Team'), 'product\n');
1639
- git(wt, 'add', '.MX-Coordination-Team');
1640
- const run = followPrintedRemedy(wt, { extraIgnore: ['.MX-Coordination-Team'] });
1641
- expect(run.stopped).toBeUndefined();
1642
- expect(showHead(wt)).toBe('M\t.gitignore\n');
1643
- expect(run.output[END_CHECK]).toBe(`!! .MX-Coordination-Team\n${BOTH_IGNORED}`);
1644
- expect(gitOut(wt, 'ls-files', '--', '.MX-Coordination-Team')).toBe('');
1645
- expect(existsSync(join(wt, '.MX-Coordination-Team'))).toBe(true);
1646
- });
1647
- it('security review of PR #561 (Should Fix): a committed, unchanged .MX-Coordination-Team ends untracked', () => {
1648
- const wt = makeRemedyFixture('staged-only');
1649
- writeFileSync(join(wt, '.MX-Coordination-Team'), 'product\n');
1650
- git(wt, 'add', '.MX-Coordination-Team');
1651
- git(wt, 'commit', '-q', '-m', 'a case-variant marker committed by mistake', '--', '.MX-Coordination-Team');
1652
- expect(gitOut(wt, 'diff', '--cached', '--name-status', '--', '.MX-Coordination-Team')).toBe('');
1653
- expect(defaultTrackedCoordinationFiles(wt)).toContain('.MX-Coordination-Team');
1654
- const run = followPrintedRemedy(wt, { extraIgnore: ['.MX-Coordination-Team'] });
1655
- expect(run.stopped).toBeUndefined();
1656
- expect(showHead(wt)).toBe('D\t.MX-Coordination-Team\nM\t.gitignore\n');
1657
- expect(run.output[END_CHECK]).toBe(`!! .MX-Coordination-Team\n${BOTH_IGNORED}`);
1658
- expect(gitOut(wt, 'ls-files', '--', '.MX-Coordination-Team')).toBe('');
1659
- expect(existsSync(join(wt, '.MX-Coordination-Team'))).toBe(true);
1660
- expectUntrackedIgnoredOnDisk(wt);
1661
- });
1662
- it('security review of PR #561 (Must Fix, a): pasted in a subdirectory, the staged-only case commits no credential cache file', () => {
1663
- const wt = makeRemedyFixture('staged-only');
1664
- const before = headOf(wt);
1665
- const run = followPrintedRemedy(wt, { cwd: join(wt, 'sub') });
1666
- expect(run.stopped).toBeUndefined();
1667
- expect(gitOut(wt, 'rev-parse', 'HEAD~1').trim()).toBe(before);
1668
- const committed = gitOut(wt, 'show', '--name-only', '--format=', 'HEAD');
1669
- expect(committed).not.toContain('.mx-coordination-token--');
1670
- expect(committed).not.toContain(MARKER);
1671
- expect(showHead(wt)).toBe('M\t.gitignore\n');
1672
- expect(gitOut(wt, 'show', 'HEAD:sub/.gitignore')).toBe('*.log\n');
1673
- expect(run.output[NUMSTAT]).toBe('2\t0\t.gitignore\n');
1674
- expectUntrackedIgnoredOnDisk(wt);
1675
- });
1676
- it('security review of PR #561 (Must Fix, b): pasted in a subdirectory, the check prints a top-level staged notes.txt and the steps stop', () => {
1677
- const wt = makeRemedyFixture('tracked');
1678
- writeFileSync(join(wt, 'notes.txt'), 'the operator\'s own work\n');
1679
- git(wt, 'add', 'notes.txt');
1680
- const before = headOf(wt);
1681
- const run = followPrintedRemedy(wt, { cwd: join(wt, 'sub') });
1682
- expect(headOf(wt)).toBe(before);
1683
- expect(stagedIn(wt)).toContain('A\tnotes.txt\n');
1684
- expect(run.stopped).toBe('A\tnotes.txt\n');
1685
- expect(run.ran).toEqual(throughCheck());
1686
- });
1687
- it('red-team on PR #561, item 1: a step 1 that removed nothing is caught by step 1a before any commit', () => {
1688
- const wt = makeRemedyFixture('staged-only');
1689
- const before = headOf(wt);
1690
- const run = followPrintedRemedy(wt, { skipRemoval: true });
1691
- // No commit, and the cache is still staged, not committed.
1692
- expect(headOf(wt)).toBe(before);
1693
- expect(stagedIn(wt)).toContain(`A\t${CACHE}\n`);
1694
- expect(run.stoppedAt).toBe(printedGitCommands().find(isRemovalCheckStep));
1695
- expect(run.stopped).toBe(`${MARKER}\n${CACHE}\n`);
1696
- expect(run.output[END_CHECK]).toBeUndefined();
1697
- });
1698
- it('security Should Fix and QA W1 at 5f31405: a committed, unchanged cache file at step 2e is printed by the repeated listing, though status prints nothing for it', () => {
1699
- const wt = makeRemedyFixture('tracked');
1700
- // Someone re-adds the cache after step 1a; the step 2d commit then records it.
1701
- const run = followPrintedRemedy(wt, { beforeCommit: () => git(wt, 'add', '-f', '--', CACHE) });
1702
- expect(gitOut(wt, 'ls-files', '--', CACHE)).toBe(`${CACHE}\n`);
1703
- expect(gitOut(wt, 'diff', 'HEAD', '--name-only', '--', CACHE)).toBe('');
1704
- // The repeated listing at the start of step 2e prints it, and the steps stop there.
1705
- expect(run.stopped).toBe(`${CACHE}\n`);
1706
- expect(run.stoppedAt).toBe(printedGitCommands().find(isRemovalCheckStep));
1707
- expect(run.ran).toEqual(printedGitCommands().slice(0, printedGitCommands().findIndex(isEndCheckStep)));
1708
- // The status command alone would not have shown it: no line names the tracked, unchanged cache.
1709
- const status = spawnSync('bash', ['-c', END_CHECK], { cwd: wt, encoding: 'utf-8', env: printedCommandEnv() });
1710
- expect(status.stdout).toBe(`!! ${MARKER}\n`);
1711
- });
1712
- it('QA W3 at 5f31405: with an exact case-variant name added in step 2b, step 2c counts 3 added', () => {
1713
- const wt = makeRemedyFixture('staged-only');
1714
- writeFileSync(join(wt, '.MX-Coordination-Team'), 'product\n');
1715
- git(wt, 'add', '.MX-Coordination-Team');
1716
- const run = followPrintedRemedy(wt, { extraIgnore: ['.MX-Coordination-Team'] });
1717
- expect(run.output[NUMSTAT]).toBe('3\t0\t.gitignore\n');
1718
- });
1719
- it('red-team on PR #561, item 2: a negation line in .gitignore shows in step 2e as files that are not ignored', () => {
1720
- const wt = makeRemedyFixture('tracked');
1721
- writeFileSync(join(wt, '.gitignore'), `.worktrees/\n${MARKER}\n.mx-coordination-token--*\n!.mx-*\n`);
1722
- git(wt, 'commit', '-q', '-m', 'rules, then a negation that defeats them', '--', '.gitignore');
1723
- const run = followPrintedRemedy(wt);
1724
- expect(run.stopped).toBeUndefined();
1725
- expect(showHead(wt)).toBe(`D\t${MARKER}\nD\t${CACHE}\n`);
1726
- expect(run.output[END_CHECK]).toBe(`?? ${MARKER}\n?? ${CACHE}\n`);
1727
- expect(gitOut(wt, 'ls-files', '--', MARKER, CACHE)).toBe('');
1728
- });
1729
- it('red-team on PR #561, item 2: step 2e runs from a subdirectory and reports top-level paths', () => {
1730
- const wt = makeRemedyFixture('tracked');
1731
- const run = followPrintedRemedy(wt, { cwd: join(wt, 'sub') });
1732
- expect(run.output[END_CHECK]).toBe(BOTH_IGNORED);
1733
- });
1734
- it('criteria 4 and 5: no printed command discards or sweeps in other work, and every one is a constant', () => {
1735
- const text = TRACKED_REMEDY.join('\n');
1736
- const commands = printedGitCommands();
1737
- expect(commands).toEqual([
1738
- "git rm --cached -f --ignore-unmatch -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1739
- "git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1740
- "git diff --cached --name-status -- ':(top)' ':(top,exclude,icase,glob).mx-coordination-tea[m]' ':(top,exclude,icase,glob).mx-coordination-token--*'",
1741
- "git add ':(top).gitignore'",
1742
- "git diff --cached --numstat -- ':(top).gitignore'",
1743
- `git commit -m '${REMEDY_COMMIT_MESSAGE}'`,
1744
- "git ls-files -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1745
- "git status --porcelain --ignored=matching --untracked-files=all -- ':(top,icase,glob).mx-coordination-tea[m]' ':(top,icase,glob).mx-coordination-token--*'",
1746
- ]);
1747
- const banned = [
1748
- /\bgit\s+add\s+(-A|--all)\b/,
1749
- /\bgit\s+add\s+\.(\s|$)/,
1750
- /\bgit\s+commit\b[^`]*\s(-a|--all|-[a-zA-Z]*a[a-zA-Z]*)(\s|$)/,
1751
- /\breset\b/,
1752
- /\brestore\b/,
1753
- /\bcheckout\s+--\s+\./,
1754
- /\bstash\b/,
1755
- /\bclean\b/,
1756
- ];
1757
- for (const command of commands) {
1758
- for (const pattern of banned)
1759
- expect(command).not.toMatch(pattern);
1760
- }
1761
- // The prose names none of them either, so no operator reads one as an instruction.
1762
- for (const pattern of banned)
1763
- expect(text).not.toMatch(pattern);
1764
- // The commit names no path: a pathspec commit takes paths from the working tree
1765
- // and would re-add the marker step 1 removed from the index (red-team, v37).
1766
- expect(commands.filter((c) => c.startsWith('git commit'))).toEqual([`git commit -m '${REMEDY_COMMIT_MESSAGE}'`]);
1767
- // Each printed check pathspec survives the shell: bash passes git the exclude
1768
- // patterns unexpanded, so a file named like the pattern is not substituted in.
1769
- const check = commands.find(isCheckStep);
1770
- const echoed = spawnSync('bash', ['-c', `printf '%s\\n' ${check.slice('git diff --cached --name-status -- '.length)}`], { cwd: base, encoding: 'utf-8' });
1771
- expect(echoed.stdout).toBe(":(top)\n:(top,exclude,icase,glob).mx-coordination-tea[m]\n:(top,exclude,icase,glob).mx-coordination-token--*\n");
1772
- // Every printed pathspec is anchored at the top of the worktree, so none depends on the current directory.
1773
- for (const command of commands) {
1774
- const pathspecs = command.includes(' -- ') ? command.slice(command.indexOf(' -- ') + 4).split(' ') : command.startsWith('git add ') ? [command.slice('git add '.length)] : [];
1775
- for (const spec of pathspecs)
1776
- expect(spec).toMatch(/^':\(top[,)]/);
1777
- }
1778
- });
1779
- });
1780
- describe('security review at 2b8c8fd: the git calls', () => {
1781
- /** A script that leaves a sentinel file when git runs it. */
1782
- function sentinelScript(name) {
1783
- const sentinel = join(base, `${name}.ran`);
1784
- const script = join(base, `${name}.sh`);
1785
- writeFileSync(script, `#!/bin/sh\necho ran >> '${sentinel}'\n`, { mode: 0o755 });
1786
- return { script, sentinel };
1787
- }
1788
- it('Should Fix 1: a repository whose config sets core.fsmonitor to a program does not get it run', () => {
1789
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1790
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1791
- const { script, sentinel } = sentinelScript('fsmonitor');
1792
- git(main, 'config', 'core.fsmonitor', script);
1793
- // The fixture is real: plain git runs the program when it reads the index.
1794
- spawnSync('git', ['ls-files'], { cwd: worktree, encoding: 'utf-8' });
1795
- expect(existsSync(sentinel)).toBe(true);
1796
- rmSync(sentinel);
1797
- expect(locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main }).ok).toBe(true);
1798
- expect(readTeamMarker({ root: worktree, source: 'git-toplevel' })).toEqual({ kind: 'ok', line: 'alpha' });
1799
- expect(defaultTrackedCoordinationFiles(worktree)).toEqual([]);
1800
- expect(listMarkedWorktrees(main)).toEqual([{ path: worktree, team: 'alpha' }]);
1801
- expect(existsSync(sentinel)).toBe(false);
1802
- });
1803
- it('no other program-valued config key runs a program through the two git commands this module uses', () => {
1804
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1805
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1806
- writeFileSync(join(worktree, '.gitattributes'), '* filter=probe diff=probe\n');
1807
- const { script, sentinel } = sentinelScript('config');
1808
- const hooks = join(base, 'hooks');
1809
- mkdirSync(hooks);
1810
- for (const hook of ['post-index-change', 'reference-transaction', 'post-checkout', 'pre-auto-gc']) {
1811
- writeFileSync(join(hooks, hook), `#!/bin/sh\necho ran >> '${sentinel}'\n`, { mode: 0o755 });
1812
- }
1813
- for (const [key, value] of [
1814
- ['core.pager', script], ['pager.ls-files', script], ['pager.rev-parse', script],
1815
- ['core.editor', script], ['core.sshCommand', script], ['core.askPass', script],
1816
- ['credential.helper', `!${script}`], ['core.hooksPath', hooks],
1817
- ['filter.probe.clean', script], ['filter.probe.smudge', script], ['filter.probe.process', script],
1818
- ['diff.probe.textconv', script], ['diff.external', script], ['core.alternateRefsCommand', script],
1819
- ['alias.ls-files', `!${script}`], ['alias.rev-parse', `!${script}`],
1820
- ])
1821
- git(main, 'config', key, value);
1822
- expect(locateCoordinationWorktree({}, { cwd: worktree, projectRoot: () => main }))
1823
- .toEqual({ ok: true, root: worktree, source: 'git-toplevel' });
1824
- expect(readTeamMarker({ root: worktree, source: 'git-toplevel' })).toEqual({ kind: 'ok', line: 'alpha' });
1825
- expect(existsSync(sentinel)).toBe(false);
1826
- });
1827
- it('Should Fix 2: a marker tracked under another letter case is refused', () => {
1828
- const { worktree } = makeProject('life-planner', 'life-planner');
1829
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1830
- writeFileSync(join(worktree, '.MX-Coordination-Team'), 'product\n');
1831
- git(worktree, 'add', '-f', '.MX-Coordination-Team');
1832
- expect(defaultTrackedCoordinationFiles(worktree)).toEqual(['.MX-Coordination-Team']);
1833
- expect(readTeamMarker({ root: worktree, source: 'git-toplevel' })).toMatchObject({ kind: 'refused', reason: 'tracked' });
1834
- });
1835
- it('Should Fix 2: a cache file tracked under another letter case is refused', () => {
1836
- const { worktree } = makeProject('life-planner', 'life-planner');
1837
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1838
- writeFileSync(join(worktree, '.MX-COORDINATION-TOKEN--life-planner--alpha'), 'committed-token-not-real\n');
1839
- git(worktree, 'add', '-f', '.MX-COORDINATION-TOKEN--life-planner--alpha');
1840
- expect(readTeamMarker({ root: worktree, source: 'git-toplevel' })).toMatchObject({ kind: 'refused', reason: 'tracked' });
1841
- });
1842
- it('Informational 1: GIT_LITERAL_PATHSPECS in the operator environment does not hide a tracked cache file', async () => {
1843
- const { main, worktree } = makeProject('life-planner', 'life-planner');
1844
- writeFileSync(join(worktree, '.mx-coordination-team'), 'alpha\n');
1845
- writeFileSync(join(worktree, '.mx-coordination-token--life-planner--alpha'), 'committed-token-not-real\n');
1846
- git(worktree, 'add', '-f', '.mx-coordination-token--life-planner--alpha');
1847
- process.env.GIT_LITERAL_PATHSPECS = '1';
1848
- process.env.GIT_NOGLOB_PATHSPECS = '1';
1849
- expect(defaultTrackedCoordinationFiles(worktree)).toEqual(['.mx-coordination-token--life-planner--alpha']);
1850
- const fetchCredential = issued();
1851
- const res = await resolveCoordinationToken({ env: {}, ...credentialDeps(fetchCredential), locate: { cwd: worktree, projectRoot: () => main } });
1852
- expect(res.status).toBe('misconfigured');
1853
- expect(res.token).toBeUndefined();
1854
- expect(fetchCredential).not.toHaveBeenCalled();
1855
- });
1856
- it('Informational 1: the four pathspec variables are removed from every git child environment', () => {
1857
- expect([...GIT_PATHSPEC_ENV].sort()).toEqual(['GIT_GLOB_PATHSPECS', 'GIT_ICASE_PATHSPECS', 'GIT_LITERAL_PATHSPECS', 'GIT_NOGLOB_PATHSPECS']);
1858
- for (const k of GIT_PATHSPEC_ENV)
1859
- process.env[k] = '1';
1860
- const envs = [];
1861
- const exec = (_file, args, options) => {
1862
- envs.push(options.env);
1863
- if (args.includes('ls-files'))
1864
- return '';
1865
- return '/p/.worktrees/a\n/p/.git/worktrees/a\n/p/.git\n';
1866
- };
1867
- defaultTrackedCoordinationFiles('/p/.worktrees/a', exec);
1868
- defaultGitTopology('/p/.worktrees/a', exec);
1869
- expect(envs).toHaveLength(2);
1870
- for (const env of envs)
1871
- for (const k of GIT_PATHSPEC_ENV)
1872
- expect(env).not.toHaveProperty(k);
1873
- });
1874
- });
1875
- //# sourceMappingURL=coordination-plain-shell-commands.test.js.map