mixdog 0.9.152 → 0.9.154

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 (300) hide show
  1. package/LICENSES/browser-import-NOTICE.txt +11 -0
  2. package/NOTICE.md +11 -0
  3. package/README.md +8 -10
  4. package/package.json +19 -3
  5. package/scripts/computer-task-cost-report.mjs +144 -0
  6. package/scripts/run-office-live-tests.mjs +32 -0
  7. package/src/agents/front-worker/AGENT.md +13 -0
  8. package/src/agents/front-worker/agent.json +6 -0
  9. package/src/agents/heavy-worker/AGENT.md +10 -11
  10. package/src/agents/heavy-worker/agent.json +1 -1
  11. package/src/agents/maintainer/AGENT.md +0 -2
  12. package/src/agents/reviewer/AGENT.md +9 -13
  13. package/src/agents/reviewer/agent.json +1 -1
  14. package/src/agents/security/AGENT.md +14 -0
  15. package/src/agents/security/agent.json +6 -0
  16. package/src/agents/worker/AGENT.md +8 -8
  17. package/src/agents/worker/agent.json +1 -1
  18. package/src/agents/writer/AGENT.md +14 -0
  19. package/src/agents/writer/agent.json +6 -0
  20. package/src/rules/agent/00-common.md +4 -7
  21. package/src/rules/lead/01-general.md +0 -3
  22. package/src/rules/shared/10-tool-workflow.md +10 -2
  23. package/src/rules/shared/60-verification.md +2 -0
  24. package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +183 -26
  25. package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +4 -0
  26. package/src/runtime/agent/orchestrator/cache-break-trace.mjs +109 -0
  27. package/src/runtime/agent/orchestrator/config.mjs +7 -2
  28. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -3
  29. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +9 -1
  30. package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +30 -9
  31. package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +18 -26
  32. package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +25 -2
  33. package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +103 -10
  34. package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +68 -0
  35. package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +36 -11
  36. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +140 -86
  37. package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +9 -13
  38. package/src/runtime/agent/orchestrator/session/agent-loop.mjs +72 -4
  39. package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +61 -0
  40. package/src/runtime/agent/orchestrator/session/compact/handoff.mjs +0 -22
  41. package/src/runtime/agent/orchestrator/session/compact/messages.mjs +2 -2
  42. package/src/runtime/agent/orchestrator/session/compact/runner.mjs +11 -23
  43. package/src/runtime/agent/orchestrator/session/compact/summary.mjs +28 -269
  44. package/src/runtime/agent/orchestrator/session/compact.mjs +0 -6
  45. package/src/runtime/agent/orchestrator/session/context-utils.mjs +86 -11
  46. package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +17 -1
  47. package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +12 -8
  48. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +110 -2
  49. package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +3 -16
  50. package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +80 -18
  51. package/src/runtime/agent/orchestrator/session/loop/steering.mjs +6 -0
  52. package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +3 -0
  53. package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -0
  54. package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +80 -21
  55. package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +33 -72
  56. package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +21 -2
  57. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +25 -51
  58. package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +3 -0
  59. package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +4 -110
  60. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +39 -15
  61. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +14 -4
  62. package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +41 -8
  63. package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +129 -12
  64. package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +2 -2
  65. package/src/runtime/agent/orchestrator/session/store/listing.mjs +8 -1
  66. package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +15 -1
  67. package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +36 -2
  68. package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +157 -30
  69. package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +57 -0
  70. package/src/runtime/agent/orchestrator/session/store.mjs +3 -1
  71. package/src/runtime/agent/orchestrator/session/tool-batch.mjs +22 -0
  72. package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -6
  73. package/src/runtime/agent/orchestrator/tools/progress-message.mjs +4 -0
  74. package/src/runtime/attachments/pdf-extract.mjs +3 -0
  75. package/src/runtime/attachments/pdfjs-runtime.mjs +13 -0
  76. package/src/runtime/browser-bridge/action-schema.mjs +251 -0
  77. package/src/runtime/browser-bridge/client.mjs +75 -26
  78. package/src/runtime/browser-bridge/tool-defs.mjs +132 -15
  79. package/src/runtime/computer-bridge/action-schema.mjs +653 -0
  80. package/src/runtime/computer-bridge/client.mjs +211 -28
  81. package/src/runtime/computer-bridge/tool-defs.mjs +25 -45
  82. package/src/runtime/office/assurance-benchmark.mjs +358 -0
  83. package/src/runtime/office/assurance.mjs +833 -0
  84. package/src/runtime/office/benchmark.mjs +496 -0
  85. package/src/runtime/office/capabilities.mjs +551 -0
  86. package/src/runtime/office/com-adapter.mjs +283 -0
  87. package/src/runtime/office/content-model.mjs +183 -0
  88. package/src/runtime/office/contract-benchmark.mjs +105 -0
  89. package/src/runtime/office/design-library.mjs +1562 -0
  90. package/src/runtime/office/design-system.mjs +1966 -0
  91. package/src/runtime/office/index.mjs +2413 -0
  92. package/src/runtime/office/journal.mjs +82 -0
  93. package/src/runtime/office/office-com-host.ps1 +3781 -0
  94. package/src/runtime/office/office-com-session-host.ps1 +855 -0
  95. package/src/runtime/office/ooxml-validator.mjs +271 -0
  96. package/src/runtime/office/pagination.mjs +132 -0
  97. package/src/runtime/office/pdf-adapter.mjs +591 -0
  98. package/src/runtime/office/pdf-analysis.mjs +372 -0
  99. package/src/runtime/office/pdf-render.mjs +167 -0
  100. package/src/runtime/office/pdf-security.mjs +63 -0
  101. package/src/runtime/office/polish-benchmark.mjs +190 -0
  102. package/src/runtime/office/portable-ooxml.mjs +1867 -0
  103. package/src/runtime/office/quality-live-benchmark.mjs +486 -0
  104. package/src/runtime/office/quality-pipeline.mjs +136 -0
  105. package/src/runtime/office/tabular.mjs +302 -0
  106. package/src/runtime/office/templates/mixdog-executive.pptx +0 -0
  107. package/src/runtime/office/templates/mixdog-executive.pptx.mixdog.json +190 -0
  108. package/src/runtime/office/tool-defs.mjs +113 -0
  109. package/src/runtime/office/visual-diff.mjs +89 -0
  110. package/src/runtime/office/xlsx-assertions.mjs +172 -0
  111. package/src/runtime/office/xlsx-contract.mjs +147 -0
  112. package/src/runtime/shared/agent-route-config.mjs +9 -0
  113. package/src/runtime/shared/tool-execution-contract.mjs +16 -0
  114. package/src/runtime/shared/tool-surface.mjs +9 -0
  115. package/src/session-runtime/context-status.mjs +9 -3
  116. package/src/session-runtime/deferred-tool-delta.mjs +104 -0
  117. package/src/session-runtime/goal-runtime.mjs +617 -197
  118. package/src/session-runtime/lifecycle-api.mjs +50 -8
  119. package/src/session-runtime/provider-request-snapshot.mjs +33 -9
  120. package/src/session-runtime/resource-api.mjs +31 -94
  121. package/src/session-runtime/runtime-core.mjs +78 -26
  122. package/src/session-runtime/session-lifecycle.mjs +34 -12
  123. package/src/session-runtime/session-title.mjs +2 -2
  124. package/src/session-runtime/session-turn-api.mjs +15 -14
  125. package/src/session-runtime/tool-catalog-data.mjs +1 -1
  126. package/src/session-runtime/tool-catalog.mjs +38 -99
  127. package/src/session-runtime/tool-defs.mjs +6 -1
  128. package/src/session-runtime/tool-surface.mjs +18 -8
  129. package/src/session-runtime/workflow-agents-api.mjs +8 -25
  130. package/src/session-runtime/workflow.mjs +8 -6
  131. package/src/standalone/agent-tool/helpers.mjs +2 -2
  132. package/src/standalone/agent-tool/job-views.mjs +3 -1
  133. package/src/standalone/agent-tool/notify.mjs +5 -1
  134. package/src/standalone/agent-tool/render.mjs +3 -0
  135. package/src/standalone/agent-tool/spawn-flow.mjs +61 -16
  136. package/src/standalone/agent-tool/tool-def.mjs +1 -1
  137. package/src/standalone/agent-tool/worker-index.mjs +123 -0
  138. package/src/standalone/agent-tool/worker-rows.mjs +2 -1
  139. package/src/standalone/agent-tool.mjs +57 -10
  140. package/src/standalone/daemon.mjs +105 -6
  141. package/src/standalone/session-runtime-host.mjs +61 -48
  142. package/src/standalone/session-runtime-inline-host.mjs +34 -127
  143. package/src/standalone/session-runtime-worker.mjs +20 -198
  144. package/src/standalone/session-service.mjs +632 -7
  145. package/src/tui/dist/index.mjs +24 -1
  146. package/src/tui/lib/voice-setup.mjs +4 -1
  147. package/src/tui/session/context-state.mjs +2 -13
  148. package/src/tui/session/goal-continuation.mjs +38 -7
  149. package/src/tui/session/session-api-ext.mjs +9 -0
  150. package/src/tui/session/session-api.mjs +15 -1
  151. package/src/tui/session/session-flow.mjs +25 -1
  152. package/src/tui/session/turn.mjs +88 -16
  153. package/src/tui/session-local.mjs +25 -3
  154. package/src/vendor/statusline/src/gateway/route-meta.mjs +31 -0
  155. package/scripts/generate-voice-runtime-manifest.test.mjs +0 -135
  156. package/scripts/native-binary-arch.test.mjs +0 -111
  157. package/scripts/patch-replay.test.mjs +0 -94
  158. package/src/headless-exec.test.mjs +0 -539
  159. package/src/runtime/agent/orchestrator/agent-trace-timing.test.mjs +0 -57
  160. package/src/runtime/agent/orchestrator/context/collect-skills.test.mjs +0 -153
  161. package/src/runtime/agent/orchestrator/mcp/cancellation.test.mjs +0 -139
  162. package/src/runtime/agent/orchestrator/mcp/features.test.mjs +0 -66
  163. package/src/runtime/agent/orchestrator/mcp/security.test.mjs +0 -80
  164. package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.test.mjs +0 -90
  165. package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.test.mjs +0 -215
  166. package/src/runtime/agent/orchestrator/providers/antigravity-oauth.test.mjs +0 -165
  167. package/src/runtime/agent/orchestrator/providers/media-parity.test.mjs +0 -142
  168. package/src/runtime/agent/orchestrator/providers/openai-codex-identity.test.mjs +0 -153
  169. package/src/runtime/agent/orchestrator/providers/openai-codex-model.test.mjs +0 -24
  170. package/src/runtime/agent/orchestrator/providers/openai-ws-delta-parity.test.mjs +0 -190
  171. package/src/runtime/agent/orchestrator/providers/provider-replay.test.mjs +0 -235
  172. package/src/runtime/agent/orchestrator/providers/sse-framing.test.mjs +0 -719
  173. package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.test.mjs +0 -40
  174. package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +0 -176
  175. package/src/runtime/agent/orchestrator/session/compaction-read-reset.test.mjs +0 -161
  176. package/src/runtime/agent/orchestrator/session/eager-dispatch.test.mjs +0 -115
  177. package/src/runtime/agent/orchestrator/session/evidence-union.test.mjs +0 -228
  178. package/src/runtime/agent/orchestrator/session/image-strip-recovery.test.mjs +0 -245
  179. package/src/runtime/agent/orchestrator/session/lossless-tool-output.test.mjs +0 -125
  180. package/src/runtime/agent/orchestrator/session/manager/pending-messages-persistence.test.mjs +0 -325
  181. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.test.mjs +0 -70
  182. package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.test.mjs +0 -457
  183. package/src/runtime/agent/orchestrator/session/provider-prefix-guard.test.mjs +0 -117
  184. package/src/runtime/agent/orchestrator/session/reduction-metrics.test.mjs +0 -87
  185. package/src/runtime/agent/orchestrator/session/store/serialize.test.mjs +0 -60
  186. package/src/runtime/agent/orchestrator/session/store-summary-reader.test.mjs +0 -583
  187. package/src/runtime/agent/orchestrator/session/task-wait-control.test.mjs +0 -78
  188. package/src/runtime/agent/orchestrator/tools/builtin/absence-absorption.test.mjs +0 -43
  189. package/src/runtime/agent/orchestrator/tools/builtin/absolute-glob-expand.test.mjs +0 -63
  190. package/src/runtime/agent/orchestrator/tools/builtin/bash-tool-cwd-env.test.mjs +0 -14
  191. package/src/runtime/agent/orchestrator/tools/builtin/edit-encoding-eol.test.mjs +0 -224
  192. package/src/runtime/agent/orchestrator/tools/builtin/edit-sequential-occupation.test.mjs +0 -224
  193. package/src/runtime/agent/orchestrator/tools/builtin/enoent-outside-project.test.mjs +0 -56
  194. package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +0 -103
  195. package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.test.mjs +0 -30
  196. package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +0 -390
  197. package/src/runtime/agent/orchestrator/tools/builtin/git-repo-rw-lock.test.mjs +0 -83
  198. package/src/runtime/agent/orchestrator/tools/builtin/grep-output-budget.test.mjs +0 -31
  199. package/src/runtime/agent/orchestrator/tools/builtin/grep-single-file-rescue.test.mjs +0 -106
  200. package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.test.mjs +0 -102
  201. package/src/runtime/agent/orchestrator/tools/builtin/list-tool-integrity.test.mjs +0 -152
  202. package/src/runtime/agent/orchestrator/tools/builtin/native-search-health.test.mjs +0 -24
  203. package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.test.mjs +0 -24
  204. package/src/runtime/agent/orchestrator/tools/builtin/noise-dir-visibility.test.mjs +0 -69
  205. package/src/runtime/agent/orchestrator/tools/builtin/read-glob-survey.test.mjs +0 -71
  206. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.test.mjs +0 -56
  207. package/src/runtime/agent/orchestrator/tools/builtin/search-builders.test.mjs +0 -16
  208. package/src/runtime/agent/orchestrator/tools/builtin/search-glob-top-k.test.mjs +0 -39
  209. package/src/runtime/agent/orchestrator/tools/builtin/write-symlink.test.mjs +0 -153
  210. package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-anchor-relocation.test.mjs +0 -55
  211. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.test.mjs +0 -88
  212. package/src/runtime/agent/orchestrator/tools/code-graph/loose-file-target.test.mjs +0 -72
  213. package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.test.mjs +0 -54
  214. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.test.mjs +0 -20
  215. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-search-scope.test.mjs +0 -55
  216. package/src/runtime/agent/orchestrator/tools/code-graph/text-span-mask.test.mjs +0 -268
  217. package/src/runtime/agent/orchestrator/tools/env-scrub.test.mjs +0 -57
  218. package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.test.mjs +0 -19
  219. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.test.mjs +0 -104
  220. package/src/runtime/agent/orchestrator/tools/patch/engine-contract-gate.test.mjs +0 -661
  221. package/src/runtime/agent/orchestrator/tools/patch/patch-codec-eol.test.mjs +0 -552
  222. package/src/runtime/agent/orchestrator/tools/patch/patch-symlink.test.mjs +0 -141
  223. package/src/runtime/agent/orchestrator/tools/patch/v4a-pure-move.test.mjs +0 -57
  224. package/src/runtime/agent/orchestrator/tools/patch/v4a-section-coalesce.test.mjs +0 -81
  225. package/src/runtime/agent/orchestrator/tools/spawn-binary-fetcher.test.mjs +0 -52
  226. package/src/runtime/attachments/store.test.mjs +0 -209
  227. package/src/runtime/channels/lib/voice-runtime-fetcher.test.mjs +0 -17
  228. package/src/runtime/channels/lib/webhook/deliveries.test.mjs +0 -18
  229. package/src/runtime/channels/lib/webhook/relay-tunnel.test.mjs +0 -68
  230. package/src/runtime/media/adapters/codex-image.test.mjs +0 -22
  231. package/src/runtime/media/download.test.mjs +0 -52
  232. package/src/runtime/media/renditions.test.mjs +0 -99
  233. package/src/runtime/media/store.test.mjs +0 -159
  234. package/src/runtime/memory/lib/archive-security.test.mjs +0 -128
  235. package/src/runtime/memory/lib/embedding-model-config.test.mjs +0 -33
  236. package/src/runtime/memory/lib/http-wire.test.mjs +0 -15
  237. package/src/runtime/memory/lib/memory-cycle-packets.test.mjs +0 -49
  238. package/src/runtime/memory/lib/memory-cycle2-shared.test.mjs +0 -78
  239. package/src/runtime/memory/lib/memory-embedding-migration.test.mjs +0 -50
  240. package/src/runtime/memory/lib/pg/process.test.mjs +0 -36
  241. package/src/runtime/memory/lib/trace-store.test.mjs +0 -57
  242. package/src/runtime/memory/lib/transcript-ingest.test.mjs +0 -52
  243. package/src/runtime/shared/background-tasks.test.mjs +0 -78
  244. package/src/runtime/shared/bounded-download.test.mjs +0 -41
  245. package/src/runtime/shared/channel-notification-routing.test.mjs +0 -25
  246. package/src/runtime/shared/child-spawn-remote.test.mjs +0 -124
  247. package/src/runtime/shared/remote-intent.test.mjs +0 -40
  248. package/src/runtime/shared/resource-admission.test.mjs +0 -43
  249. package/src/runtime/shared/runtime-root.test.mjs +0 -34
  250. package/src/runtime/shared/schedule-time.test.mjs +0 -29
  251. package/src/runtime/shared/session-runtime-health.test.mjs +0 -83
  252. package/src/runtime/shared/skill-document.test.mjs +0 -81
  253. package/src/runtime/shared/tool-surface.test.mjs +0 -87
  254. package/src/runtime/shared/update-checker.test.mjs +0 -33
  255. package/src/runtime/shared/user-cwd.test.mjs +0 -43
  256. package/src/runtime/shared/webhook-session-run.test.mjs +0 -14
  257. package/src/session-runtime/agent-disable.test.mjs +0 -123
  258. package/src/session-runtime/cwd-plugins.test.mjs +0 -75
  259. package/src/session-runtime/cwd-tool-routing.test.mjs +0 -61
  260. package/src/session-runtime/global-extensions.test.mjs +0 -28
  261. package/src/session-runtime/goal-runtime.test.mjs +0 -108
  262. package/src/session-runtime/lifecycle-api.test.mjs +0 -21
  263. package/src/session-runtime/model-settings-persist.test.mjs +0 -105
  264. package/src/session-runtime/notification-bus.test.mjs +0 -148
  265. package/src/session-runtime/plugin-mcp-standard.test.mjs +0 -177
  266. package/src/session-runtime/prewarm.test.mjs +0 -52
  267. package/src/session-runtime/provider-request-snapshot.test.mjs +0 -37
  268. package/src/session-runtime/resource-api-global.test.mjs +0 -69
  269. package/src/session-runtime/session-lifecycle.test.mjs +0 -125
  270. package/src/session-runtime/session-title.test.mjs +0 -36
  271. package/src/session-runtime/skills-api.test.mjs +0 -99
  272. package/src/session-runtime/tool-policy-surface.test.mjs +0 -331
  273. package/src/standalone/agent-tool/helpers.test.mjs +0 -62
  274. package/src/standalone/agent-tool/notify.test.mjs +0 -37
  275. package/src/standalone/agent-tool/spawn-flow.test.mjs +0 -63
  276. package/src/standalone/channel-restart.test.mjs +0 -145
  277. package/src/standalone/channel-session-router.test.mjs +0 -37
  278. package/src/standalone/channel-worker-heartbeat.test.mjs +0 -30
  279. package/src/standalone/hook-bus/handlers.test.mjs +0 -88
  280. package/src/standalone/plugin-admin.test.mjs +0 -173
  281. package/src/standalone/session-runtime-agent-control-client.test.mjs +0 -71
  282. package/src/standalone/session-runtime-dispatch-cancel.test.mjs +0 -139
  283. package/src/standalone/session-runtime-host-factory.test.mjs +0 -31
  284. package/src/standalone/session-runtime-host-health.test.mjs +0 -160
  285. package/src/standalone/session-runtime-inline-host.test.mjs +0 -83
  286. package/src/standalone/session-runtime-provider-cooldown.test.mjs +0 -80
  287. package/src/standalone/session-runtime-shard-host.test.mjs +0 -569
  288. package/src/standalone/session-runtime-shard-router.test.mjs +0 -101
  289. package/src/tui/app/live-spinner-visibility.test.mjs +0 -44
  290. package/src/tui/app/panel-epoch.test.mjs +0 -1009
  291. package/src/tui/app/panel-handoff.test.mjs +0 -311
  292. package/src/tui/app/prompt-submit.test.mjs +0 -206
  293. package/src/tui/session/completion-card-restore.test.mjs +0 -111
  294. package/src/tui/session/goal-continuation.test.mjs +0 -84
  295. package/src/tui/session/oauth-flows.test.mjs +0 -134
  296. package/src/tui/session/queue-helpers.test.mjs +0 -46
  297. package/src/tui/session/session-action-surface.test.mjs +0 -108
  298. package/src/tui/session/task-wait-submit.test.mjs +0 -80
  299. package/src/tui/session/tool-result-status.test.mjs +0 -131
  300. package/src/tui/session/tui-steering-persist.test.mjs +0 -104
@@ -1,552 +0,0 @@
1
- // apply_patch byte fidelity: a rewrite may only change the lines a hunk
2
- // replaces. Encoding (BOM/codec) and every untouched line terminator survive.
3
- import { test } from 'node:test';
4
- import assert from 'node:assert/strict';
5
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
6
- import { tmpdir } from 'node:os';
7
- import { join } from 'node:path';
8
-
9
- import {
10
- cloneTextLinesForPatch,
11
- decodePatchTargetBuffer,
12
- encodePatchTargetContent,
13
- detectPatchTargetCodec,
14
- joinTextLinesForPatch,
15
- patchTargetUsesUtf16,
16
- localTerminatorForWindow,
17
- setFinalNewlineForPatch,
18
- spliceTextLinesForPatch,
19
- splitTextLinesForPatch,
20
- terminatorsForUnifiedOps,
21
- } from './matcher.mjs';
22
- import { plusWindowCoversMatch } from './v4a-convert.mjs';
23
- import { executePatchTool } from '../patch.mjs';
24
- import { closeNativePatchServerForTests } from './native-server.mjs';
25
-
26
- function makeDir() {
27
- return mkdtempSync(join(tmpdir(), 'mixdog-patch-codec-'));
28
- }
29
-
30
- test('a replaced line keeps its own terminator and untouched lines keep theirs', () => {
31
- const lines = splitTextLinesForPatch('a\r\nb\nc\r\n');
32
- const next = cloneTextLinesForPatch(lines);
33
- spliceTextLinesForPatch(next, 1, 1, ['B']);
34
- assert.equal(joinTextLinesForPatch(next), 'a\r\nB\nc\r\n');
35
- });
36
-
37
- test('extra inserted lines adopt the local convention only', () => {
38
- const lines = splitTextLinesForPatch('a\r\nb\nc\r\n');
39
- const next = cloneTextLinesForPatch(lines);
40
- spliceTextLinesForPatch(next, 1, 1, ['B', 'B2']);
41
- assert.equal(joinTextLinesForPatch(next), 'a\r\nB\nB2\nc\r\n');
42
- });
43
-
44
- test('a multi-run hunk keeps every untouched terminator', () => {
45
- // Two change runs with interior context: op-wise mapping is the only thing
46
- // that can place `MID`'s CRLF and `T`'s LF correctly.
47
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('H\r\nA\nMID\r\nC\nT\n'));
48
- const ops = ['context', 'delete', 'add', 'context', 'delete', 'add', 'context'];
49
- const newTerms = terminatorsForUnifiedOps(
50
- ops,
51
- lines.terminators.slice(0, 5),
52
- localTerminatorForWindow(lines, 0, 5),
53
- );
54
- spliceTextLinesForPatch(lines, 0, 5, ['H', 'A2', 'MID', 'C2', 'T'], newTerms);
55
- assert.equal(joinTextLinesForPatch(lines), 'H\r\nA2\nMID\r\nC2\nT\n');
56
- });
57
-
58
- test('a moved line does not drag a neighbouring terminator', () => {
59
- // `-A`, ` MID`, `+A`: MID is untouched and must keep its CRLF.
60
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('H\r\nA\nMID\r\nT\n'));
61
- const ops = ['context', 'delete', 'context', 'add', 'context'];
62
- const newTerms = terminatorsForUnifiedOps(
63
- ops,
64
- lines.terminators.slice(0, 4),
65
- localTerminatorForWindow(lines, 0, 4),
66
- );
67
- spliceTextLinesForPatch(lines, 0, 4, ['H', 'MID', 'A', 'T'], newTerms);
68
- assert.equal(joinTextLinesForPatch(lines), 'H\r\nMID\r\nA\nT\n');
69
- });
70
-
71
- test('a short NUL-containing file is undecidable, never UTF-16', () => {
72
- // UTF-8 `61 00` was classified UTF-16LE and rewritten as 78000a006100.
73
- assert.equal(detectPatchTargetCodec(Buffer.from([0x61, 0x00])).certain, false);
74
- assert.equal(detectPatchTargetCodec(Buffer.from([0x61, 0x00, 0x62, 0x00])).certain, false);
75
- // A real BOM-less UTF-16 file (enough evidence) is still detected.
76
- const real = Buffer.from('hello world, this is utf-16 text\n', 'utf16le');
77
- assert.equal(detectPatchTargetCodec(real).encoding, 'utf16le');
78
- });
79
-
80
- test('a parity flip past the old sample window is refused', () => {
81
- const buf = Buffer.alloc(9000);
82
- for (let i = 0; i < buf.length; i += 2) { buf[i] = 0x61; buf[i + 1] = 0x00; }
83
- buf[8200] = 0x00; // even offset → conflicting parity, beyond byte 8192
84
- assert.equal(detectPatchTargetCodec(buf).certain, false);
85
- });
86
-
87
- test('a bounded prefix can never decide a codec', () => {
88
- const real = Buffer.from('hello world, this is utf-16 text\n', 'utf16le');
89
- assert.equal(detectPatchTargetCodec(real, { partial: true }).certain, false);
90
- });
91
-
92
- test('a backward move across two contexts keeps its own terminator', () => {
93
- // `+A` precedes its `-A`: the identity pool must span the whole hunk.
94
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('C1\nC2\nA\r\n'));
95
- const ops = [
96
- { op: 'add', line: 'A' },
97
- { op: 'context', line: 'C1' },
98
- { op: 'context', line: 'C2' },
99
- { op: 'delete', line: 'A' },
100
- ];
101
- const newTerms = terminatorsForUnifiedOps(
102
- ops,
103
- lines.terminators.slice(0, 3),
104
- localTerminatorForWindow(lines, 0, 3),
105
- );
106
- spliceTextLinesForPatch(lines, 0, 3, ['A', 'C1', 'C2'], newTerms);
107
- assert.equal(joinTextLinesForPatch(lines), 'A\r\nC1\nC2\n');
108
- });
109
-
110
- test('a move across context keeps the moved line own terminator', () => {
111
- // `-A`, ` MID`, `+A`: context must not clear the identity pool.
112
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('A\r\nMID\nT\n'));
113
- const ops = [
114
- { op: 'delete', line: 'A' },
115
- { op: 'context', line: 'MID' },
116
- { op: 'add', line: 'A' },
117
- { op: 'context', line: 'T' },
118
- ];
119
- const newTerms = terminatorsForUnifiedOps(
120
- ops,
121
- lines.terminators.slice(0, 3),
122
- localTerminatorForWindow(lines, 0, 3),
123
- );
124
- spliceTextLinesForPatch(lines, 0, 3, ['MID', 'A', 'T'], newTerms);
125
- assert.equal(joinTextLinesForPatch(lines), 'MID\nA\r\nT\n');
126
- });
127
-
128
- test('duplicate deletes are claimed in order, not first-fit', () => {
129
- // D/X/D → X/D must take the FINAL D's LF, not the first D's CRLF.
130
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('D\r\nX\nD\nT\n'));
131
- const ops = [
132
- { op: 'delete', line: 'D' },
133
- { op: 'delete', line: 'X' },
134
- { op: 'delete', line: 'D' },
135
- { op: 'add', line: 'X' },
136
- { op: 'add', line: 'D' },
137
- { op: 'context', line: 'T' },
138
- ];
139
- const newTerms = terminatorsForUnifiedOps(
140
- ops,
141
- lines.terminators.slice(0, 4),
142
- localTerminatorForWindow(lines, 0, 4),
143
- );
144
- spliceTextLinesForPatch(lines, 0, 4, ['X', 'D', 'T'], newTerms);
145
- assert.equal(joinTextLinesForPatch(lines), 'X\nD\nT\n');
146
- });
147
-
148
- test('a shrinking hunk keeps the following untouched line terminator', () => {
149
- // 2 old lines → 1 new line: positional mapping used to shift `keep` onto a
150
- // deleted line's CRLF.
151
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('ctx\r\nold1\nold2\r\nkeep\n'));
152
- spliceTextLinesForPatch(lines, 0, 4, ['ctx', 'NEW', 'keep']);
153
- assert.equal(joinTextLinesForPatch(lines), 'ctx\r\nNEW\nkeep\n');
154
- });
155
-
156
- test('a growing hunk gives only the surplus lines the local convention', () => {
157
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('ctx\r\nold\nkeep\n'));
158
- spliceTextLinesForPatch(lines, 0, 3, ['ctx', 'NEW1', 'NEW2', 'keep']);
159
- assert.equal(joinTextLinesForPatch(lines), 'ctx\r\nNEW1\nNEW2\nkeep\n');
160
- });
161
-
162
- test('a file without a final newline does not gain one', () => {
163
- const lines = splitTextLinesForPatch('a\nb');
164
- const next = cloneTextLinesForPatch(lines);
165
- spliceTextLinesForPatch(next, 0, 1, ['A']);
166
- assert.equal(joinTextLinesForPatch(next), 'A\nb');
167
- });
168
-
169
- test('a CR-only file still round-trips', () => {
170
- const lines = splitTextLinesForPatch('a\rb\r');
171
- assert.deepEqual([...lines], ['a', 'b']);
172
- const next = cloneTextLinesForPatch(lines);
173
- spliceTextLinesForPatch(next, 0, 1, ['A']);
174
- assert.equal(joinTextLinesForPatch(next), 'A\rb\r');
175
- });
176
-
177
- test('a lone CR inside an LF file stays line content', () => {
178
- const lines = splitTextLinesForPatch('a\rb\nc\n');
179
- assert.deepEqual([...lines], ['a\rb', 'c']);
180
- assert.equal(joinTextLinesForPatch(cloneTextLinesForPatch(lines)), 'a\rb\nc\n');
181
- });
182
-
183
- test('deleting the tail line keeps the terminator of the line above it', () => {
184
- // The reviewer's repro: "a\r\nb" (no final newline). Deleting `b` must not
185
- // strip the CRLF that belongs to the untouched line `a`.
186
- const lines = splitTextLinesForPatch('a\r\nb');
187
- const next = cloneTextLinesForPatch(lines);
188
- spliceTextLinesForPatch(next, 1, 1, []);
189
- assert.equal(joinTextLinesForPatch(next), 'a\r\n');
190
-
191
- const lfLines = cloneTextLinesForPatch(splitTextLinesForPatch('a\nb'));
192
- spliceTextLinesForPatch(lfLines, 1, 1, []);
193
- assert.equal(joinTextLinesForPatch(lfLines), 'a\n');
194
- });
195
-
196
- test('an explicit no-newline-at-EOF intent still wins', () => {
197
- const lines = cloneTextLinesForPatch(splitTextLinesForPatch('a\r\nb\r\n'));
198
- spliceTextLinesForPatch(lines, 1, 1, ['B']);
199
- setFinalNewlineForPatch(lines, false);
200
- assert.equal(joinTextLinesForPatch(lines), 'a\r\nB');
201
-
202
- const restored = cloneTextLinesForPatch(splitTextLinesForPatch('a\r\nb'));
203
- spliceTextLinesForPatch(restored, 1, 1, ['B']);
204
- setFinalNewlineForPatch(restored, true);
205
- assert.equal(joinTextLinesForPatch(restored), 'a\r\nB\r\n');
206
- });
207
-
208
- test('the peel-plus window may refine a match but never relocate it', () => {
209
- // Half-open containment: `start + length` is the index one PAST the
210
- // window, i.e. a different location. `<=` there re-introduced the no-op.
211
- assert.equal(plusWindowCoversMatch(2, 2, 1), false);
212
- assert.equal(plusWindowCoversMatch(2, 2, 2), true);
213
- assert.equal(plusWindowCoversMatch(2, 2, 3), true);
214
- assert.equal(plusWindowCoversMatch(2, 2, 4), false);
215
- assert.equal(plusWindowCoversMatch(2, 2, -1), true);
216
- });
217
-
218
- test('UTF-16BE patch content round-trips byte for byte', () => {
219
- const buf = Buffer.concat([
220
- Buffer.from([0xFE, 0xFF]),
221
- Buffer.from('hi\r\n', 'utf16le').swap16(),
222
- ]);
223
- const { text, enc } = decodePatchTargetBuffer(buf, 'x.txt');
224
- assert.equal(text, 'hi\r\n');
225
- assert.deepEqual([...encodePatchTargetContent(text, enc)], [...buf]);
226
- });
227
-
228
- test('a UTF-8 BOM round-trips and a BOM-less buffer stays BOM-less', () => {
229
- const withBom = Buffer.concat([Buffer.from([0xEF, 0xBB, 0xBF]), Buffer.from('hi\n')]);
230
- const decodedBom = decodePatchTargetBuffer(withBom, 'x.txt');
231
- assert.equal(decodedBom.text, 'hi\n');
232
- assert.deepEqual([...encodePatchTargetContent(decodedBom.text, decodedBom.enc)], [...withBom]);
233
-
234
- const plain = decodePatchTargetBuffer(Buffer.from('hi\n'), 'x.txt');
235
- assert.equal(encodePatchTargetContent(plain.text, plain.enc), 'hi\n');
236
- });
237
-
238
- test('malformed UTF-16 (odd payload) is refused instead of losing the byte', () => {
239
- const buf = Buffer.concat([
240
- Buffer.from([0xFF, 0xFE]),
241
- Buffer.from('ab', 'utf16le'),
242
- Buffer.from([0x41]),
243
- ]);
244
- assert.throws(() => decodePatchTargetBuffer(buf, 'x.txt'), /malformed UTF-16/);
245
- });
246
-
247
- test('a UTF-16 update routes to the BOM-preserving writer', async (t) => {
248
- const dir = makeDir();
249
- const file = join(dir, 'poly.txt');
250
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
251
- writeFileSync(file, Buffer.concat([
252
- Buffer.from([0xFF, 0xFE]),
253
- Buffer.from('alpha\r\nkeep\r\n', 'utf16le'),
254
- ]));
255
- assert.equal(patchTargetUsesUtf16(file), true);
256
-
257
- const result = String(await executePatchTool('apply_patch', {
258
- base_path: dir,
259
- patch: `*** Begin Patch
260
- *** Update File: poly.txt
261
- @@
262
- -alpha
263
- +omega
264
- keep
265
- *** End Patch
266
- `,
267
- }, dir, {}));
268
-
269
- assert.match(result, /\(JS\)/);
270
- const raw = readFileSync(file);
271
- assert.deepEqual([raw[0], raw[1]], [0xFF, 0xFE]);
272
- assert.equal(raw.subarray(2).toString('utf16le'), 'omega\r\nkeep\r\n');
273
- });
274
-
275
- test('a UTF-16 tail deletion leaves every other byte identical', async (t) => {
276
- const dir = makeDir();
277
- const file = join(dir, 'tail.txt');
278
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
279
- const before = Buffer.concat([
280
- Buffer.from([0xFF, 0xFE]),
281
- Buffer.from('a\r\nb', 'utf16le'),
282
- ]);
283
- writeFileSync(file, before);
284
-
285
- const result = String(await executePatchTool('apply_patch', {
286
- base_path: dir,
287
- patch: `*** Begin Patch
288
- *** Update File: tail.txt
289
- @@
290
- a
291
- -b
292
- *** End Patch
293
- `,
294
- }, dir, {}));
295
-
296
- assert.doesNotMatch(result, /^Error/);
297
- const after = readFileSync(file);
298
- const expected = Buffer.concat([Buffer.from([0xFF, 0xFE]), Buffer.from('a\r\n', 'utf16le')]);
299
- assert.deepEqual([...after], [...expected]);
300
- // Byte-prefix equality: the untouched head (BOM + "a\r\n") is unchanged.
301
- assert.deepEqual([...after], [...before.subarray(0, expected.length)]);
302
- });
303
-
304
- // The UTF-8 in-base route runs inside the Rust engine when its artifact
305
- // satisfies the engine contract, and inside the JS writer when it does not.
306
- // Either way the byte contract must hold, so this runs unconditionally.
307
- test('a UTF-8 tail deletion leaves every other byte identical', async (t) => {
308
- const dir = makeDir();
309
- const file = join(dir, 'tail8.txt');
310
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
311
- const before = Buffer.from('a\r\nb');
312
- writeFileSync(file, before);
313
-
314
- const result = String(await executePatchTool('apply_patch', {
315
- base_path: dir,
316
- patch: `*** Begin Patch
317
- *** Update File: tail8.txt
318
- @@
319
- a
320
- -b
321
- *** End Patch
322
- `,
323
- }, dir, {}));
324
-
325
- assert.doesNotMatch(result, /^Error/);
326
- const after = readFileSync(file);
327
- assert.deepEqual([...after], [...Buffer.from('a\r\n')]);
328
- assert.deepEqual([...after], [...before.subarray(0, after.length)]);
329
- });
330
-
331
- test('an invalid-UTF-8 target is refused on the native route too', async (t) => {
332
- const dir = makeDir();
333
- const file = join(dir, 'latin1.txt');
334
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
335
- const before = Buffer.from([0x6F, 0x6C, 0x64, 0x0A, 0xFF, 0x0A]); // "old\n<FF>\n"
336
- writeFileSync(file, before);
337
-
338
- const result = String(await executePatchTool('apply_patch', {
339
- base_path: dir,
340
- patch: `*** Begin Patch
341
- *** Update File: latin1.txt
342
- @@
343
- -old
344
- +new
345
- *** End Patch
346
- `,
347
- }, dir, {}));
348
-
349
- assert.match(result, /neither valid UTF-8/);
350
- assert.deepEqual([...readFileSync(file)], [...before]);
351
- });
352
-
353
- test('a UTF-16 shrinking hunk leaves the trailing context byte-identical', async (t) => {
354
- const dir = makeDir();
355
- const file = join(dir, 'shrink.txt');
356
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
357
- const before = Buffer.concat([
358
- Buffer.from([0xFF, 0xFE]),
359
- Buffer.from('ctx\r\nold1\nold2\r\nkeep\n', 'utf16le'),
360
- ]);
361
- writeFileSync(file, before);
362
-
363
- const result = String(await executePatchTool('apply_patch', {
364
- base_path: dir,
365
- patch: `*** Begin Patch
366
- *** Update File: shrink.txt
367
- @@
368
- ctx
369
- -old1
370
- -old2
371
- +NEW
372
- keep
373
- *** End Patch
374
- `,
375
- }, dir, {}));
376
-
377
- assert.doesNotMatch(result, /^Error/);
378
- const after = readFileSync(file);
379
- assert.deepEqual([after[0], after[1]], [0xFF, 0xFE]);
380
- assert.equal(after.subarray(2).toString('utf16le'), 'ctx\r\nNEW\nkeep\n');
381
- // The untouched head (BOM + "ctx\r\n") and tail ("keep\n") are byte-equal.
382
- const headBytes = 2 + Buffer.byteLength('ctx\r\n', 'utf16le');
383
- assert.deepEqual([...after.subarray(0, headBytes)], [...before.subarray(0, headBytes)]);
384
- const tailBytes = Buffer.byteLength('keep\n', 'utf16le');
385
- assert.deepEqual(
386
- [...after.subarray(after.length - tailBytes)],
387
- [...before.subarray(before.length - tailBytes)],
388
- );
389
- });
390
-
391
- test('a UTF-16 multi-run hunk keeps the interior context byte-identical', async (t) => {
392
- const dir = makeDir();
393
- const file = join(dir, 'multi.txt');
394
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
395
- const before = Buffer.concat([
396
- Buffer.from([0xFF, 0xFE]),
397
- Buffer.from('H\r\nA\nMID\r\nC\nT\n', 'utf16le'),
398
- ]);
399
- writeFileSync(file, before);
400
-
401
- const result = String(await executePatchTool('apply_patch', {
402
- base_path: dir,
403
- patch: `*** Begin Patch
404
- *** Update File: multi.txt
405
- @@
406
- H
407
- -A
408
- +A2
409
- MID
410
- -C
411
- +C2
412
- T
413
- *** End Patch
414
- `,
415
- }, dir, {}));
416
-
417
- assert.doesNotMatch(result, /^Error/);
418
- const after = readFileSync(file);
419
- assert.deepEqual([after[0], after[1]], [0xFF, 0xFE]);
420
- assert.equal(after.subarray(2).toString('utf16le'), 'H\r\nA2\nMID\r\nC2\nT\n');
421
- // `MID\r\n` and the trailing `T\n` are untouched bytes.
422
- assert.ok(after.includes(Buffer.from('MID\r\n', 'utf16le')));
423
- assert.ok(after.includes(Buffer.from('T\n', 'utf16le')));
424
- });
425
-
426
- test('a UTF-16 moved line leaves the line it crossed byte-identical', async (t) => {
427
- const dir = makeDir();
428
- const file = join(dir, 'moved.txt');
429
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
430
- writeFileSync(file, Buffer.concat([
431
- Buffer.from([0xFF, 0xFE]),
432
- Buffer.from('H\r\nA\nMID\r\nT\n', 'utf16le'),
433
- ]));
434
-
435
- const result = String(await executePatchTool('apply_patch', {
436
- base_path: dir,
437
- patch: `*** Begin Patch
438
- *** Update File: moved.txt
439
- @@
440
- H
441
- -A
442
- MID
443
- +A
444
- T
445
- *** End Patch
446
- `,
447
- }, dir, {}));
448
-
449
- assert.doesNotMatch(result, /^Error/);
450
- const after = readFileSync(file);
451
- assert.equal(after.subarray(2).toString('utf16le'), 'H\r\nMID\r\nA\nT\n');
452
- });
453
-
454
- test('a BOM-less UTF-16 target is detected and stays in its own codec', async (t) => {
455
- const dir = makeDir();
456
- const file = join(dir, 'nobom.txt');
457
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
458
- // UTF-16LE with NO BOM (long enough to be decidable — a short NUL-bearing
459
- // file is refused instead, see the tiny-file test). Routing by BOM presence
460
- // sent this to the UTF-8 engine, which produced mixed bytes
461
- // (72006f006f0074000a616c706861).
462
- const before = Buffer.from('root\nsecond line of plain text\n', 'utf16le');
463
- writeFileSync(file, before);
464
- assert.equal(patchTargetUsesUtf16(file), true);
465
- assert.equal(detectPatchTargetCodec(before).encoding, 'utf16le');
466
-
467
- const result = String(await executePatchTool('apply_patch', {
468
- base_path: dir,
469
- patch: `*** Begin Patch
470
- *** Update File: nobom.txt
471
- @@
472
- +alpha
473
- root
474
- *** End Patch
475
- `,
476
- }, dir, {}));
477
-
478
- assert.doesNotMatch(result, /^Error/);
479
- const after = readFileSync(file);
480
- assert.equal(after.toString('utf16le'), 'alpha\nroot\nsecond line of plain text\n');
481
- assert.notDeepEqual([after[0], after[1]], [0xFF, 0xFE]); // no BOM invented
482
- assert.deepEqual([...after.subarray(after.length - before.length)], [...before]);
483
- });
484
-
485
- test('a two-byte UTF-8 file with a stray NUL is refused, not rewritten as UTF-16', async (t) => {
486
- const dir = makeDir();
487
- const file = join(dir, 'tiny.txt');
488
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
489
- const before = Buffer.from([0x61, 0x00]); // "a" + NUL — was destroyed as 78000a006100
490
- writeFileSync(file, before);
491
-
492
- const result = String(await executePatchTool('apply_patch', {
493
- base_path: dir,
494
- patch: `*** Begin Patch
495
- *** Update File: tiny.txt
496
- @@
497
- -a
498
- +x
499
- *** End Patch
500
- `,
501
- }, dir, {}));
502
-
503
- assert.match(result, /decidable text encoding|NUL bytes/);
504
- assert.deepEqual([...readFileSync(file)], [...before]);
505
- });
506
-
507
- test('a file whose codec cannot be decided is refused without a write', async (t) => {
508
- const dir = makeDir();
509
- const file = join(dir, 'undecidable.txt');
510
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
511
- // NULs on BOTH parities: neither UTF-8 text nor a UTF-16 pattern.
512
- const before = Buffer.from([0x61, 0x00, 0x00, 0x62, 0x0a, 0x6f, 0x6c, 0x64, 0x0a]);
513
- writeFileSync(file, before);
514
- assert.equal(detectPatchTargetCodec(before).certain, false);
515
-
516
- const result = String(await executePatchTool('apply_patch', {
517
- base_path: dir,
518
- patch: `*** Begin Patch
519
- *** Update File: undecidable.txt
520
- @@
521
- -old
522
- +new
523
- *** End Patch
524
- `,
525
- }, dir, {}));
526
-
527
- assert.match(result, /decidable text encoding|NUL bytes/);
528
- assert.deepEqual([...readFileSync(file)], [...before]);
529
- });
530
-
531
- test('a genuine addition is not relocated onto a lookalike "+" line', async (t) => {
532
- const dir = makeDir();
533
- const file = join(dir, 'a.md');
534
- t.after(() => { rmSync(dir, { recursive: true, force: true }); void closeNativePatchServerForTests?.(); });
535
- // `+ marker` exists further down, and ['alpha', '+ marker'] is a unique
536
- // window there — the peel-plus recovery tier must not drag the hunk to it.
537
- writeFileSync(file, 'alpha\nbeta\nalpha\n+ marker\n');
538
-
539
- const result = String(await executePatchTool('apply_patch', {
540
- base_path: dir,
541
- patch: `*** Begin Patch
542
- *** Update File: a.md
543
- @@
544
- alpha
545
- + marker
546
- *** End Patch
547
- `,
548
- }, dir, {}));
549
-
550
- assert.doesNotMatch(result, /^Error/);
551
- assert.equal(readFileSync(file, 'utf8'), 'alpha\n marker\nbeta\nalpha\n+ marker\n');
552
- });
@@ -1,141 +0,0 @@
1
- // apply_patch through a symlink. The TOCTOU snapshot has to follow the link
2
- // exactly the way atomicWrite does; an lstat of the link inode never matches
3
- // the followed stat, which rejected every such patch as "changed on disk".
4
- // The link itself must also survive the atomic rename.
5
- import { test } from 'node:test';
6
- import assert from 'node:assert/strict';
7
- import {
8
- lstatSync,
9
- mkdirSync,
10
- mkdtempSync,
11
- readFileSync,
12
- rmSync,
13
- symlinkSync,
14
- writeFileSync,
15
- } from 'node:fs';
16
- import { tmpdir } from 'node:os';
17
- import { join } from 'node:path';
18
-
19
- import { executePatchTool } from '../patch.mjs';
20
- import { closeNativePatchServerForTests } from './native-server.mjs';
21
-
22
- // Windows without Developer Mode / admin rights refuses symlink creation
23
- // (EPERM), so the host capability decides whether this case can run at all.
24
- function symlinkSupported(dir) {
25
- try {
26
- writeFileSync(join(dir, 'probe.txt'), 'x');
27
- symlinkSync(join(dir, 'probe.txt'), join(dir, 'probe.link'));
28
- return true;
29
- } catch {
30
- return false;
31
- }
32
- }
33
-
34
- const asHeaderPath = (p) => p.replace(/\\/g, '/');
35
-
36
- test('apply_patch updates a symlinked file through the link', async (t) => {
37
- const dir = mkdtempSync(join(tmpdir(), 'mixdog-patch-symlink-'));
38
- t.after(() => {
39
- rmSync(dir, { recursive: true, force: true });
40
- void closeNativePatchServerForTests?.();
41
- });
42
- if (!symlinkSupported(dir)) {
43
- t.skip('symlink creation is not permitted on this host');
44
- return;
45
- }
46
- // Target outside base_path — the shape that routes to the JS writer, and
47
- // the exact shape of the nginx sites-enabled/default case from the bench.
48
- const base = join(dir, 'app');
49
- mkdirSync(base);
50
- const real = join(dir, 'sites-available.conf');
51
- const link = join(dir, 'sites-enabled.conf');
52
- writeFileSync(real, 'root /var/www/html;\nindex index.html;\n');
53
- symlinkSync(real, link);
54
-
55
- const result = String(await executePatchTool('apply_patch', {
56
- base_path: base,
57
- patch: `*** Begin Patch
58
- *** Update File: ${asHeaderPath(link)}
59
- @@
60
- -root /var/www/html;
61
- +root /usr/share/novnc;
62
- index index.html;
63
- *** End Patch
64
- `,
65
- }, base, {}));
66
-
67
- assert.doesNotMatch(result, /^Error/);
68
- assert.doesNotMatch(result, /changed on disk/);
69
- assert.equal(readFileSync(real, 'utf8'), 'root /usr/share/novnc;\nindex index.html;\n');
70
- assert.equal(readFileSync(link, 'utf8'), 'root /usr/share/novnc;\nindex index.html;\n');
71
- // The link is still a link: the write landed on its target, not on top of it.
72
- assert.equal(lstatSync(link).isSymbolicLink(), true);
73
- });
74
-
75
- test('an in-base symlinked target is patched through the link', async (t) => {
76
- const dir = mkdtempSync(join(tmpdir(), 'mixdog-patch-symlink-'));
77
- t.after(() => {
78
- rmSync(dir, { recursive: true, force: true });
79
- void closeNativePatchServerForTests?.();
80
- });
81
- if (!symlinkSupported(dir)) {
82
- t.skip('symlink creation is not permitted on this host');
83
- return;
84
- }
85
- // Inside base_path the native engine would normally take this entry; a
86
- // symlinked target has to be routed to the JS writer instead, because the
87
- // engine renames its output over the path it was handed.
88
- const real = join(dir, 'real.conf');
89
- const link = join(dir, 'link.conf');
90
- writeFileSync(real, 'keep\nold\n');
91
- symlinkSync(real, link);
92
-
93
- const result = String(await executePatchTool('apply_patch', {
94
- base_path: dir,
95
- patch: `*** Begin Patch
96
- *** Update File: link.conf
97
- @@
98
- keep
99
- -old
100
- +new
101
- *** End Patch
102
- `,
103
- }, dir, {}));
104
-
105
- assert.doesNotMatch(result, /^Error/);
106
- assert.equal(readFileSync(real, 'utf8'), 'keep\nnew\n');
107
- assert.equal(lstatSync(link).isSymbolicLink(), true);
108
- });
109
-
110
- test('a second patch through the same link still sees a fresh snapshot', async (t) => {
111
- const dir = mkdtempSync(join(tmpdir(), 'mixdog-patch-symlink-'));
112
- t.after(() => {
113
- rmSync(dir, { recursive: true, force: true });
114
- void closeNativePatchServerForTests?.();
115
- });
116
- if (!symlinkSupported(dir)) {
117
- t.skip('symlink creation is not permitted on this host');
118
- return;
119
- }
120
- const base = join(dir, 'app');
121
- mkdirSync(base);
122
- const real = join(dir, 'real.conf');
123
- const link = join(dir, 'link.conf');
124
- writeFileSync(real, 'a\nb\n');
125
- symlinkSync(real, link);
126
-
127
- const patch = (from, to) => `*** Begin Patch
128
- *** Update File: ${asHeaderPath(link)}
129
- @@
130
- -${from}
131
- +${to}
132
- b
133
- *** End Patch
134
- `;
135
- const first = String(await executePatchTool('apply_patch', { base_path: base, patch: patch('a', 'A') }, base, {}));
136
- assert.doesNotMatch(first, /^Error/);
137
- const second = String(await executePatchTool('apply_patch', { base_path: base, patch: patch('A', 'AA') }, base, {}));
138
- assert.doesNotMatch(second, /^Error/);
139
- assert.equal(readFileSync(real, 'utf8'), 'AA\nb\n');
140
- assert.equal(lstatSync(link).isSymbolicLink(), true);
141
- });