@1agh/maude 1.0.11 → 1.3.0

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 (567) hide show
  1. package/README.md +3 -1
  2. package/apps/studio/acp/bridge.ts +18 -13
  3. package/apps/studio/acp/index.ts +43 -7
  4. package/apps/studio/acp/transcript-io.ts +394 -0
  5. package/apps/studio/acp/transcript.ts +103 -38
  6. package/apps/studio/annotations-layer.tsx +191 -116
  7. package/apps/studio/annotations-model.ts +39 -0
  8. package/apps/studio/annotations-sync.ts +50 -0
  9. package/apps/studio/api.ts +821 -55
  10. package/apps/studio/bin/_import-figma.mjs +57 -11
  11. package/apps/studio/bin/_seed-fixture.mjs +163 -0
  12. package/apps/studio/bin/annotate.mjs +3 -1
  13. package/apps/studio/bin/server-up.sh +17 -2
  14. package/apps/studio/canvas-edit.ts +391 -7
  15. package/apps/studio/canvas-imports.ts +89 -0
  16. package/apps/studio/canvas-lib.tsx +82 -18
  17. package/apps/studio/canvas-notice-message.ts +16 -0
  18. package/apps/studio/canvas-notifications.tsx +19 -0
  19. package/apps/studio/canvas-shell.tsx +57 -6
  20. package/apps/studio/client/app.jsx +943 -248
  21. package/apps/studio/client/apply-edit-request.ts +55 -0
  22. package/apps/studio/client/export-center.jsx +125 -67
  23. package/apps/studio/client/github.js +38 -1
  24. package/apps/studio/client/index-loader.ts +76 -0
  25. package/apps/studio/client/panels/CloudBar.jsx +52 -6
  26. package/apps/studio/client/panels/GitPanel.jsx +103 -0
  27. package/apps/studio/client/panels/OnboardingWizard.jsx +36 -7
  28. package/apps/studio/client/panels/RepoBranchSwitcher.jsx +92 -27
  29. package/apps/studio/client/panels/SourceConflictPanel.jsx +166 -0
  30. package/apps/studio/client/panels/SyncPanel.jsx +238 -4
  31. package/apps/studio/client/panels/TeamProjects.jsx +376 -0
  32. package/apps/studio/client/panels/file-deep-link-dialog.jsx +54 -0
  33. package/apps/studio/client/photo-knobs.jsx +3 -0
  34. package/apps/studio/client/report-bug.jsx +19 -1
  35. package/apps/studio/client/share-dialog.jsx +91 -0
  36. package/apps/studio/client/share-link.js +94 -0
  37. package/apps/studio/client/styles/3-shell-maude.css +69 -18
  38. package/apps/studio/client/styles/4-components.css +44 -1
  39. package/apps/studio/client/tree-row-menu.jsx +48 -3
  40. package/apps/studio/client/whats-new.jsx +26 -32
  41. package/apps/studio/cloud/endpoints.ts +132 -0
  42. package/apps/studio/collab/index.ts +4 -0
  43. package/apps/studio/collab/persistence.ts +137 -17
  44. package/apps/studio/collab/registry.ts +19 -21
  45. package/apps/studio/collab/room.ts +13 -2
  46. package/apps/studio/context.ts +59 -0
  47. package/apps/studio/debug-bundle.ts +13 -0
  48. package/apps/studio/dist/client.bundle.js +1911 -1879
  49. package/apps/studio/dist/runtime/.min-sizes.json +1 -0
  50. package/apps/studio/dist/runtime/sonner.js +1 -0
  51. package/apps/studio/dist/styles.css +1 -1
  52. package/apps/studio/export-dialog.tsx +54 -0
  53. package/apps/studio/exporters/degraded.ts +19 -3
  54. package/apps/studio/exporters/ghostscript.ts +194 -0
  55. package/apps/studio/exporters/pdf-fonts.ts +261 -0
  56. package/apps/studio/exporters/pdf.ts +152 -3
  57. package/apps/studio/exporters/remote.ts +36 -1
  58. package/apps/studio/fs-watch.ts +45 -1
  59. package/apps/studio/http.ts +296 -19
  60. package/apps/studio/inspect.ts +19 -0
  61. package/apps/studio/managed-projects.ts +150 -0
  62. package/apps/studio/mem.ts +45 -9
  63. package/apps/studio/notifications.tsx +292 -0
  64. package/apps/studio/runtime-bundle.ts +2 -0
  65. package/apps/studio/server.ts +69 -6
  66. package/apps/studio/sync/accepted-cold-start.ts +225 -0
  67. package/apps/studio/sync/accepted-link.ts +320 -0
  68. package/apps/studio/sync/action-stage.ts +343 -0
  69. package/apps/studio/sync/agent.ts +104 -45
  70. package/apps/studio/sync/asset-push.ts +1 -47
  71. package/apps/studio/sync/cell-file-events.ts +3 -0
  72. package/apps/studio/sync/codec.ts +192 -34
  73. package/apps/studio/sync/cold-start-apply.ts +7 -0
  74. package/apps/studio/sync/cold-start.ts +118 -22
  75. package/apps/studio/sync/comment-identity.ts +68 -0
  76. package/apps/studio/sync/connection-state.ts +15 -1
  77. package/apps/studio/sync/ctl-provider.ts +15 -2
  78. package/apps/studio/sync/document-discovery.ts +81 -0
  79. package/apps/studio/sync/file-ledger.ts +117 -0
  80. package/apps/studio/sync/file-membership.ts +10 -2
  81. package/apps/studio/sync/file-plane.ts +926 -47
  82. package/apps/studio/sync/index.ts +1786 -36
  83. package/apps/studio/sync/journal-client.ts +13 -1
  84. package/apps/studio/sync/migrate-seed.ts +150 -22
  85. package/apps/studio/sync/poke.ts +4 -2
  86. package/apps/studio/sync/presentation.ts +311 -5
  87. package/apps/studio/sync/projection.ts +820 -23
  88. package/apps/studio/sync/repeated-module.ts +73 -0
  89. package/apps/studio/sync/retry-after.ts +169 -0
  90. package/apps/studio/sync/revision-barrier.ts +129 -0
  91. package/apps/studio/sync/seed-progress.ts +218 -0
  92. package/apps/studio/sync/seed-repair.ts +46 -0
  93. package/apps/studio/sync/source-merge.ts +100 -0
  94. package/apps/studio/sync/source-ops.ts +289 -0
  95. package/apps/studio/sync/source-recovery.ts +70 -0
  96. package/apps/studio/sync/source-validation.ts +56 -0
  97. package/apps/studio/sync/status.ts +201 -6
  98. package/apps/studio/sync/transaction-client.ts +460 -0
  99. package/apps/studio/sync/transport-error.ts +111 -0
  100. package/apps/studio/sync/writer-registry.ts +236 -0
  101. package/apps/studio/text-caret.ts +35 -0
  102. package/apps/studio/undo-hud.tsx +9 -87
  103. package/apps/studio/use-canvas-media-drop.tsx +4 -39
  104. package/apps/studio/whats-new.json +173 -0
  105. package/cli/bin/maude.mjs +2 -0
  106. package/cli/commands/codex.mjs +191 -0
  107. package/cli/commands/harness.mjs +1051 -0
  108. package/cli/commands/help.mjs +13 -0
  109. package/cli/lib/design-link.mjs +190 -2
  110. package/cli/lib/harness/capabilities.mjs +302 -0
  111. package/cli/lib/harness/codex-runtime.mjs +892 -0
  112. package/cli/lib/harness/compatibility.mjs +27 -0
  113. package/cli/lib/harness/discover-claude.mjs +1393 -0
  114. package/cli/lib/harness/managed-state.mjs +1296 -0
  115. package/cli/lib/harness/model.mjs +86 -0
  116. package/cli/lib/harness/secrets.mjs +390 -0
  117. package/cli/lib/harness/targets/codex.mjs +1141 -0
  118. package/cli/lib/harness/targets/opencode.mjs +807 -0
  119. package/cli/lib/harness/transaction.mjs +1099 -0
  120. package/cli/lib/hubs-config.mjs +35 -8
  121. package/cli/templates/harness/opencode/maude-projector.ts +58 -0
  122. package/docs/harness-capability-matrix.md +125 -0
  123. package/docs/harness-environment-projection.md +95 -0
  124. package/package.json +33 -9
  125. package/plugins/design/dependencies.json +3 -3
  126. package/plugins/design/templates/_shell.html +47 -0
  127. package/plugins/flow/.claude-plugin/config.schema.json +8 -0
  128. package/plugins/flow/dependencies.json +3 -3
  129. package/apps/studio/.ai/cache/_stats.json +0 -7
  130. package/apps/studio/bin/_agent-browser-safe.test.mjs +0 -165
  131. package/apps/studio/bin/_curl-local.test.mjs +0 -280
  132. package/apps/studio/bin/_pw-launch.test.mjs +0 -90
  133. package/apps/studio/bin/_smart-frames.test.mjs +0 -195
  134. package/apps/studio/bin/_transcribe.test.mjs +0 -80
  135. package/apps/studio/bun.lock +0 -928
  136. package/apps/studio/draw/test/animate.test.ts +0 -172
  137. package/apps/studio/draw/test/brush.test.ts +0 -213
  138. package/apps/studio/draw/test/composition.test.ts +0 -141
  139. package/apps/studio/draw/test/geometry.test.ts +0 -199
  140. package/apps/studio/draw/test/gradient.test.ts +0 -167
  141. package/apps/studio/draw/test/layout.test.ts +0 -120
  142. package/apps/studio/draw/test/morph.test.ts +0 -107
  143. package/apps/studio/draw/test/optimize.test.ts +0 -40
  144. package/apps/studio/draw/test/palette.test.ts +0 -123
  145. package/apps/studio/draw/test/primitives.test.ts +0 -129
  146. package/apps/studio/draw/test/serialize-animate.test.ts +0 -142
  147. package/apps/studio/draw/test/serialize.test.ts +0 -105
  148. package/apps/studio/figma/assets.test.ts +0 -464
  149. package/apps/studio/figma/client.test.ts +0 -395
  150. package/apps/studio/figma/codegen-client.test.ts +0 -276
  151. package/apps/studio/figma/codegen-fonts.test.ts +0 -103
  152. package/apps/studio/figma/codegen-values.test.ts +0 -179
  153. package/apps/studio/figma/comments-to-strokes.test.ts +0 -194
  154. package/apps/studio/figma/fig-decode.test.ts +0 -788
  155. package/apps/studio/figma/fig-differential.test.ts +0 -182
  156. package/apps/studio/figma/fig-translator.test.ts +0 -192
  157. package/apps/studio/figma/fig-vector.test.ts +0 -113
  158. package/apps/studio/figma/from-codegen.test.ts +0 -408
  159. package/apps/studio/figma/sanitize.test.ts +0 -325
  160. package/apps/studio/figma/tailwind-map.test.ts +0 -142
  161. package/apps/studio/figma/to-artboard.test.ts +0 -808
  162. package/apps/studio/figma/to-render.test.ts +0 -180
  163. package/apps/studio/figma/to-strokes-roundtrip.test.ts +0 -152
  164. package/apps/studio/figma/to-strokes.test.ts +0 -705
  165. package/apps/studio/figma/to-tokens.test.ts +0 -321
  166. package/apps/studio/figma/url.test.ts +0 -167
  167. package/apps/studio/footage/schema.test.ts +0 -287
  168. package/apps/studio/generation/adapters/groq.test.ts +0 -80
  169. package/apps/studio/generation/audio-library.test.ts +0 -95
  170. package/apps/studio/generation/captions.test.ts +0 -78
  171. package/apps/studio/generation/elevenlabs.test.ts +0 -223
  172. package/apps/studio/generation/gemini.test.ts +0 -350
  173. package/apps/studio/generation/jobs.test.ts +0 -128
  174. package/apps/studio/generation/keys.test.ts +0 -75
  175. package/apps/studio/generation/prefs.test.ts +0 -95
  176. package/apps/studio/generation/types.test.ts +0 -123
  177. package/apps/studio/generation/whisper-models.test.ts +0 -179
  178. package/apps/studio/test/_helpers.ts +0 -108
  179. package/apps/studio/test/acp-activity-endpoint.test.ts +0 -183
  180. package/apps/studio/test/acp-activity.test.ts +0 -154
  181. package/apps/studio/test/acp-ai-activity.test.ts +0 -182
  182. package/apps/studio/test/acp-attachment-serve.test.ts +0 -74
  183. package/apps/studio/test/acp-bootstrap-brief.test.ts +0 -178
  184. package/apps/studio/test/acp-branch-guard.test.ts +0 -123
  185. package/apps/studio/test/acp-bridge-lifetime.test.ts +0 -475
  186. package/apps/studio/test/acp-bridge.test.ts +0 -545
  187. package/apps/studio/test/acp-capabilities.test.ts +0 -123
  188. package/apps/studio/test/acp-caps-bridge.test.ts +0 -279
  189. package/apps/studio/test/acp-commands.test.ts +0 -119
  190. package/apps/studio/test/acp-elicitation-bridge.test.ts +0 -480
  191. package/apps/studio/test/acp-elicitation.test.ts +0 -251
  192. package/apps/studio/test/acp-env.test.ts +0 -95
  193. package/apps/studio/test/acp-mode-banner.test.ts +0 -45
  194. package/apps/studio/test/acp-origin-gate.test.ts +0 -160
  195. package/apps/studio/test/acp-permission-prompt.test.ts +0 -251
  196. package/apps/studio/test/acp-permission.test.ts +0 -278
  197. package/apps/studio/test/acp-plugin-bootstrap.test.ts +0 -89
  198. package/apps/studio/test/acp-session-allowed-tools.test.ts +0 -235
  199. package/apps/studio/test/acp-session-plugins.test.ts +0 -209
  200. package/apps/studio/test/acp-toolgroup.test.ts +0 -76
  201. package/apps/studio/test/acp-transcript-view.test.ts +0 -71
  202. package/apps/studio/test/acp-transcript.test.ts +0 -238
  203. package/apps/studio/test/acp-usage-bridge.test.ts +0 -141
  204. package/apps/studio/test/acp-usage.test.ts +0 -143
  205. package/apps/studio/test/acp-write-gate.test.ts +0 -323
  206. package/apps/studio/test/acp-write-scope.test.ts +0 -533
  207. package/apps/studio/test/active-state.test.ts +0 -186
  208. package/apps/studio/test/activity.test.ts +0 -189
  209. package/apps/studio/test/ai-activity.test.ts +0 -113
  210. package/apps/studio/test/annotate-write.test.ts +0 -1074
  211. package/apps/studio/test/annotation-strokes-command.test.ts +0 -166
  212. package/apps/studio/test/annotations-align.test.ts +0 -88
  213. package/apps/studio/test/annotations-api.test.ts +0 -145
  214. package/apps/studio/test/annotations-bindings.test.ts +0 -262
  215. package/apps/studio/test/annotations-draw-modifiers.test.ts +0 -206
  216. package/apps/studio/test/annotations-groups.test.ts +0 -231
  217. package/apps/studio/test/annotations-layer.test.ts +0 -1011
  218. package/apps/studio/test/annotations-roundtrip.test.ts +0 -663
  219. package/apps/studio/test/annotations-snap.test.ts +0 -135
  220. package/apps/studio/test/annotations-text-format.test.ts +0 -396
  221. package/apps/studio/test/artboard-activity-overlay.test.tsx +0 -56
  222. package/apps/studio/test/artboard-guides-overlay.test.tsx +0 -152
  223. package/apps/studio/test/artboard-hug-commit.test.ts +0 -36
  224. package/apps/studio/test/artboard-kinds.test.tsx +0 -83
  225. package/apps/studio/test/artboard-selection-attrs.test.ts +0 -69
  226. package/apps/studio/test/asset-api.test.ts +0 -149
  227. package/apps/studio/test/assets-s3.test.ts +0 -249
  228. package/apps/studio/test/binary-smoke.test.ts +0 -47
  229. package/apps/studio/test/boot-self-heal.test.ts +0 -87
  230. package/apps/studio/test/browse-posture.test.tsx +0 -107
  231. package/apps/studio/test/bundle-smoke.test.ts +0 -46
  232. package/apps/studio/test/camera-reveal.test.tsx +0 -173
  233. package/apps/studio/test/canvas-artifacts.test.ts +0 -125
  234. package/apps/studio/test/canvas-build-sandbox.test.ts +0 -69
  235. package/apps/studio/test/canvas-build.test.ts +0 -141
  236. package/apps/studio/test/canvas-create-api.test.ts +0 -676
  237. package/apps/studio/test/canvas-cursors.test.ts +0 -164
  238. package/apps/studio/test/canvas-edit.test.ts +0 -470
  239. package/apps/studio/test/canvas-freshness-deps.test.ts +0 -64
  240. package/apps/studio/test/canvas-header.test.ts +0 -127
  241. package/apps/studio/test/canvas-hide-chrome.test.ts +0 -88
  242. package/apps/studio/test/canvas-hmr-runtime.test.tsx +0 -114
  243. package/apps/studio/test/canvas-lib-inline.test.ts +0 -146
  244. package/apps/studio/test/canvas-lib-motion.test.ts +0 -131
  245. package/apps/studio/test/canvas-lib-resolver.test.ts +0 -111
  246. package/apps/studio/test/canvas-list-watch.test.ts +0 -388
  247. package/apps/studio/test/canvas-media-drop.test.ts +0 -187
  248. package/apps/studio/test/canvas-meta-api.test.ts +0 -707
  249. package/apps/studio/test/canvas-move-api.test.ts +0 -587
  250. package/apps/studio/test/canvas-origin-gate.test.ts +0 -417
  251. package/apps/studio/test/canvas-pipeline.test.ts +0 -180
  252. package/apps/studio/test/canvas-rects.test.ts +0 -198
  253. package/apps/studio/test/canvas-reorder.test.ts +0 -211
  254. package/apps/studio/test/canvas-route.test.ts +0 -179
  255. package/apps/studio/test/canvas-shell-base.test.ts +0 -107
  256. package/apps/studio/test/canvas-shell-build-error.test.ts +0 -52
  257. package/apps/studio/test/canvas-url.test.ts +0 -138
  258. package/apps/studio/test/canvas-wheel-delta.test.ts +0 -42
  259. package/apps/studio/test/canvas-zoom-floor.test.ts +0 -73
  260. package/apps/studio/test/capture-core.test.ts +0 -32
  261. package/apps/studio/test/capture-determinism-shape.test.ts +0 -135
  262. package/apps/studio/test/chat-attachments.test.ts +0 -117
  263. package/apps/studio/test/chat-context.test.ts +0 -129
  264. package/apps/studio/test/chat-markdown.test.tsx +0 -58
  265. package/apps/studio/test/clip-addressing.test.ts +0 -738
  266. package/apps/studio/test/clip-ops.test.ts +0 -922
  267. package/apps/studio/test/cloud-build.test.ts +0 -95
  268. package/apps/studio/test/cloud-connect-note.test.ts +0 -135
  269. package/apps/studio/test/cloud-endpoints.test.ts +0 -590
  270. package/apps/studio/test/cloud-history-hardening.test.ts +0 -165
  271. package/apps/studio/test/cloud-history-posture.test.ts +0 -230
  272. package/apps/studio/test/cloud-managed-save-surfaces.test.ts +0 -90
  273. package/apps/studio/test/cloud-renew.test.ts +0 -205
  274. package/apps/studio/test/cloud-session-role.test.ts +0 -161
  275. package/apps/studio/test/cloud-shell-surfaces.test.ts +0 -170
  276. package/apps/studio/test/cold-start-apply.test.ts +0 -303
  277. package/apps/studio/test/collab-annotations-bridge.test.ts +0 -55
  278. package/apps/studio/test/collab-awareness-bridge.test.ts +0 -223
  279. package/apps/studio/test/collab-bridge.test.ts +0 -79
  280. package/apps/studio/test/collab-loopback.test.ts +0 -63
  281. package/apps/studio/test/collab-origin-gate.test.ts +0 -323
  282. package/apps/studio/test/collab-protocol.test.ts +0 -146
  283. package/apps/studio/test/collab-readonly-gate.test.ts +0 -194
  284. package/apps/studio/test/collab-reseed-guard.test.ts +0 -78
  285. package/apps/studio/test/collab-room.test.ts +0 -188
  286. package/apps/studio/test/collab-session-survival.test.tsx +0 -176
  287. package/apps/studio/test/collab-stress.test.ts +0 -129
  288. package/apps/studio/test/comment-mount.test.ts +0 -97
  289. package/apps/studio/test/comment-relay-origin-gate.test.ts +0 -117
  290. package/apps/studio/test/comments-api.test.ts +0 -277
  291. package/apps/studio/test/comments-fs-rebroadcast.test.ts +0 -155
  292. package/apps/studio/test/comments-overlay.test.ts +0 -117
  293. package/apps/studio/test/compile-entry.test.ts +0 -133
  294. package/apps/studio/test/component-map.test.ts +0 -48
  295. package/apps/studio/test/config-projection.test.ts +0 -104
  296. package/apps/studio/test/config-reload.test.ts +0 -230
  297. package/apps/studio/test/config-version.test.ts +0 -88
  298. package/apps/studio/test/context-resolve-tokens.test.ts +0 -97
  299. package/apps/studio/test/convert-to-absolute.test.ts +0 -333
  300. package/apps/studio/test/credential-grammar.test.ts +0 -107
  301. package/apps/studio/test/csp-canvas-shell.test.ts +0 -62
  302. package/apps/studio/test/csrf-write-guard.test.ts +0 -141
  303. package/apps/studio/test/debug-bundle.test.ts +0 -105
  304. package/apps/studio/test/design-setup-readiness.test.ts +0 -155
  305. package/apps/studio/test/detach-component.test.ts +0 -94
  306. package/apps/studio/test/dns-rebinding-guard.test.ts +0 -101
  307. package/apps/studio/test/dom-selection.test.ts +0 -198
  308. package/apps/studio/test/dynamic-text-edit.test.ts +0 -162
  309. package/apps/studio/test/edit-css-occurrence.test.ts +0 -81
  310. package/apps/studio/test/edit-persistence.test.ts +0 -91
  311. package/apps/studio/test/edit-scope-api.test.ts +0 -119
  312. package/apps/studio/test/edit-source-command.test.ts +0 -142
  313. package/apps/studio/test/edit-suppress.test.ts +0 -170
  314. package/apps/studio/test/editing-presence.test.ts +0 -103
  315. package/apps/studio/test/element-resize.test.ts +0 -136
  316. package/apps/studio/test/element-structural-api.test.ts +0 -434
  317. package/apps/studio/test/element-structural-edit.test.ts +0 -750
  318. package/apps/studio/test/ensure-browser.test.ts +0 -92
  319. package/apps/studio/test/equal-spacing-detector.test.ts +0 -257
  320. package/apps/studio/test/export-assemble.test.ts +0 -53
  321. package/apps/studio/test/export-browser-lane.test.ts +0 -126
  322. package/apps/studio/test/export-capture-fidelity.test.ts +0 -146
  323. package/apps/studio/test/export-capture-hygiene.test.ts +0 -675
  324. package/apps/studio/test/export-center.test.tsx +0 -287
  325. package/apps/studio/test/export-e2e-lanes.test.ts +0 -857
  326. package/apps/studio/test/export-format-scope-coherence.test.ts +0 -89
  327. package/apps/studio/test/export-lane.test.ts +0 -245
  328. package/apps/studio/test/export-shim-multi-capture.test.ts +0 -83
  329. package/apps/studio/test/exporters/canva.test.ts +0 -63
  330. package/apps/studio/test/exporters/degraded-propagation.test.ts +0 -123
  331. package/apps/studio/test/exporters/endpoint.test.ts +0 -121
  332. package/apps/studio/test/exporters/history.test.ts +0 -107
  333. package/apps/studio/test/exporters/html.test.ts +0 -26
  334. package/apps/studio/test/exporters/jobs.test.ts +0 -342
  335. package/apps/studio/test/exporters/pdf.test.ts +0 -85
  336. package/apps/studio/test/exporters/png.test.ts +0 -103
  337. package/apps/studio/test/exporters/pptx-deck.test.ts +0 -112
  338. package/apps/studio/test/exporters/pptx.test.ts +0 -31
  339. package/apps/studio/test/exporters/pw-launch.test.ts +0 -49
  340. package/apps/studio/test/exporters/runtime.test.ts +0 -59
  341. package/apps/studio/test/exporters/scope.test.ts +0 -292
  342. package/apps/studio/test/exporters/svg.test.ts +0 -29
  343. package/apps/studio/test/exporters/unsupported-media.test.ts +0 -123
  344. package/apps/studio/test/exporters/zip.test.ts +0 -104
  345. package/apps/studio/test/fetch-asset-gate.test.ts +0 -189
  346. package/apps/studio/test/figjam-v3-model.test.ts +0 -342
  347. package/apps/studio/test/figma-explode.test.ts +0 -438
  348. package/apps/studio/test/figma-provenance.test.ts +0 -108
  349. package/apps/studio/test/figma-routes.test.ts +0 -294
  350. package/apps/studio/test/file-lock.test.ts +0 -84
  351. package/apps/studio/test/fixtures/backgrounding-claude-auth.sh +0 -12
  352. package/apps/studio/test/fixtures/fake-claude-auth.mjs +0 -23
  353. package/apps/studio/test/fixtures/figjam-v3-groups-bindings.svg +0 -1
  354. package/apps/studio/test/fixtures/mock-acp-agent-caps.mjs +0 -158
  355. package/apps/studio/test/fixtures/mock-acp-agent-commands.mjs +0 -44
  356. package/apps/studio/test/fixtures/mock-acp-agent-elicit-flood.mjs +0 -46
  357. package/apps/studio/test/fixtures/mock-acp-agent-elicit-url.mjs +0 -42
  358. package/apps/studio/test/fixtures/mock-acp-agent-elicit.mjs +0 -63
  359. package/apps/studio/test/fixtures/mock-acp-agent-permission-flood.mjs +0 -51
  360. package/apps/studio/test/fixtures/mock-acp-agent-permission.mjs +0 -50
  361. package/apps/studio/test/fixtures/mock-acp-agent-slow.mjs +0 -45
  362. package/apps/studio/test/fixtures/mock-acp-agent-usage.mjs +0 -56
  363. package/apps/studio/test/fixtures/mock-acp-agent-wedged.mjs +0 -37
  364. package/apps/studio/test/fixtures/mock-acp-agent-write.mjs +0 -118
  365. package/apps/studio/test/fixtures/mock-acp-agent.mjs +0 -69
  366. package/apps/studio/test/fixtures/noisy-claude-auth.mjs +0 -27
  367. package/apps/studio/test/fixtures/perf-canvas.mjs +0 -201
  368. package/apps/studio/test/fixtures/phase-20-annotations.svg +0 -1
  369. package/apps/studio/test/fixtures/phase-21-annotations.svg +0 -1
  370. package/apps/studio/test/fixtures/tiny-subset.woff2 +0 -0
  371. package/apps/studio/test/fixtures/video-comp-fixture.tsx +0 -82
  372. package/apps/studio/test/fixtures/wedged-claude-auth.sh +0 -11
  373. package/apps/studio/test/footage-store.test.ts +0 -100
  374. package/apps/studio/test/fs-mkdir-api.test.ts +0 -248
  375. package/apps/studio/test/fs-watch.test.ts +0 -41
  376. package/apps/studio/test/gemma-models.test.ts +0 -245
  377. package/apps/studio/test/generate-route.test.ts +0 -106
  378. package/apps/studio/test/git-api.test.ts +0 -0
  379. package/apps/studio/test/git-branches.test.ts +0 -341
  380. package/apps/studio/test/git-cloud-posture.test.ts +0 -59
  381. package/apps/studio/test/git-grouping.test.ts +0 -106
  382. package/apps/studio/test/git-lifecycle.test.ts +0 -100
  383. package/apps/studio/test/git-log-format.test.ts +0 -95
  384. package/apps/studio/test/git-safe-rel.test.ts +0 -132
  385. package/apps/studio/test/git-system-engine.test.ts +0 -135
  386. package/apps/studio/test/git-watch.test.ts +0 -97
  387. package/apps/studio/test/github-api.test.ts +0 -577
  388. package/apps/studio/test/grid-track-handles.test.ts +0 -160
  389. package/apps/studio/test/handoff-static-frames.test.ts +0 -215
  390. package/apps/studio/test/handoff.test.ts +0 -329
  391. package/apps/studio/test/history-rollback.test.ts +0 -88
  392. package/apps/studio/test/hmr-broadcast.test.ts +0 -236
  393. package/apps/studio/test/hmr-classify.test.ts +0 -87
  394. package/apps/studio/test/hub-link.test.ts +0 -80
  395. package/apps/studio/test/identity-cache.test.ts +0 -83
  396. package/apps/studio/test/import-asset-browser.test.ts +0 -64
  397. package/apps/studio/test/import-asset-route.test.ts +0 -71
  398. package/apps/studio/test/import-asset.test.ts +0 -427
  399. package/apps/studio/test/import-brand-browser.test.ts +0 -88
  400. package/apps/studio/test/import-brand-route.test.ts +0 -120
  401. package/apps/studio/test/import-brand.test.ts +0 -206
  402. package/apps/studio/test/import-figma.test.ts +0 -667
  403. package/apps/studio/test/import-tokens.test.ts +0 -722
  404. package/apps/studio/test/index-data-canvas-ds.test.ts +0 -97
  405. package/apps/studio/test/input-router.test.ts +0 -757
  406. package/apps/studio/test/inspect-script-syntax.test.ts +0 -53
  407. package/apps/studio/test/inspect-selections.test.ts +0 -219
  408. package/apps/studio/test/knob-props-authored.test.ts +0 -87
  409. package/apps/studio/test/layers-synthetic-groups.test.ts +0 -96
  410. package/apps/studio/test/locator.test.ts +0 -214
  411. package/apps/studio/test/marquee-overlay.test.ts +0 -94
  412. package/apps/studio/test/media-commit-chain.test.ts +0 -210
  413. package/apps/studio/test/mode-toggle.test.tsx +0 -226
  414. package/apps/studio/test/motion-sample.test.ts +0 -35
  415. package/apps/studio/test/move-artboards-command.test.ts +0 -108
  416. package/apps/studio/test/participants-chrome.test.ts +0 -65
  417. package/apps/studio/test/paths.test.ts +0 -88
  418. package/apps/studio/test/pdf-print-boxes.test.ts +0 -359
  419. package/apps/studio/test/peer-selection-follows-camera.test.tsx +0 -131
  420. package/apps/studio/test/perf-harness.ts +0 -193
  421. package/apps/studio/test/phase-3.6-smoke.test.ts +0 -79
  422. package/apps/studio/test/photo-bg-remove-validation.test.ts +0 -71
  423. package/apps/studio/test/photo-canvas-bundle.test.ts +0 -79
  424. package/apps/studio/test/photo-edit-api.test.ts +0 -201
  425. package/apps/studio/test/photo-filters.test.ts +0 -149
  426. package/apps/studio/test/photo-pipeline.test.ts +0 -106
  427. package/apps/studio/test/photo-taxonomy.test.ts +0 -96
  428. package/apps/studio/test/print-marks.test.ts +0 -113
  429. package/apps/studio/test/print-units.test.ts +0 -173
  430. package/apps/studio/test/read-annotations.test.ts +0 -727
  431. package/apps/studio/test/read-only-gate.test.ts +0 -188
  432. package/apps/studio/test/read-only-role.test.ts +0 -95
  433. package/apps/studio/test/readiness.test.ts +0 -337
  434. package/apps/studio/test/remote-ahead-behind-cache.test.ts +0 -89
  435. package/apps/studio/test/reorder-api.test.ts +0 -210
  436. package/apps/studio/test/repo-concurrency.test.ts +0 -146
  437. package/apps/studio/test/repo-lock.test.ts +0 -350
  438. package/apps/studio/test/report-proxy.test.ts +0 -125
  439. package/apps/studio/test/ripple.test.ts +0 -197
  440. package/apps/studio/test/runtime-bundle-error-mapping.test.ts +0 -43
  441. package/apps/studio/test/runtime-bundle.test.ts +0 -69
  442. package/apps/studio/test/sanitize-annotation-svg.test.ts +0 -238
  443. package/apps/studio/test/scaffold-design.test.ts +0 -122
  444. package/apps/studio/test/server-lifecycle.test.ts +0 -38
  445. package/apps/studio/test/session-runtime-state.test.ts +0 -226
  446. package/apps/studio/test/session-scope.test.ts +0 -100
  447. package/apps/studio/test/shared-doc-cell-pairing.test.ts +0 -642
  448. package/apps/studio/test/shared-doc-convergence.test.ts +0 -265
  449. package/apps/studio/test/shared-doc-foundation.test.ts +0 -63
  450. package/apps/studio/test/shared-doc-migrate.test.ts +0 -369
  451. package/apps/studio/test/shared-doc-projection.test.ts +0 -238
  452. package/apps/studio/test/shell-importmap.test.ts +0 -56
  453. package/apps/studio/test/sizing-mode.test.ts +0 -102
  454. package/apps/studio/test/slash-commands.test.ts +0 -117
  455. package/apps/studio/test/snap-distance-pill.test.ts +0 -68
  456. package/apps/studio/test/spacing-handles.test.ts +0 -138
  457. package/apps/studio/test/specimen-select.test.ts +0 -88
  458. package/apps/studio/test/sync-agent.test.ts +0 -660
  459. package/apps/studio/test/sync-annotations-cold-start.test.ts +0 -302
  460. package/apps/studio/test/sync-asset-push.test.ts +0 -931
  461. package/apps/studio/test/sync-atomic-write.test.ts +0 -62
  462. package/apps/studio/test/sync-attach-incremental.test.ts +0 -527
  463. package/apps/studio/test/sync-autocommit.test.ts +0 -537
  464. package/apps/studio/test/sync-canvas-path.test.ts +0 -200
  465. package/apps/studio/test/sync-cell-write-nudge.test.ts +0 -346
  466. package/apps/studio/test/sync-codec.test.ts +0 -230
  467. package/apps/studio/test/sync-cold-seed-dedup.test.ts +0 -187
  468. package/apps/studio/test/sync-cold-start.test.ts +0 -304
  469. package/apps/studio/test/sync-connect-honesty.test.ts +0 -114
  470. package/apps/studio/test/sync-connection-state.test.ts +0 -337
  471. package/apps/studio/test/sync-ctl-channel.test.ts +0 -508
  472. package/apps/studio/test/sync-decide-file.test.ts +0 -420
  473. package/apps/studio/test/sync-doc-name.test.ts +0 -281
  474. package/apps/studio/test/sync-echo-guard.test.ts +0 -96
  475. package/apps/studio/test/sync-file-ledger.test.ts +0 -334
  476. package/apps/studio/test/sync-file-membership.test.ts +0 -347
  477. package/apps/studio/test/sync-file-plane.test.ts +0 -976
  478. package/apps/studio/test/sync-file-pull.test.ts +0 -333
  479. package/apps/studio/test/sync-fresh-link-parity.test.ts +0 -267
  480. package/apps/studio/test/sync-fs-mirror.test.ts +0 -181
  481. package/apps/studio/test/sync-hardening.test.ts +0 -586
  482. package/apps/studio/test/sync-hub-listing.test.ts +0 -46
  483. package/apps/studio/test/sync-hubs-config.test.ts +0 -133
  484. package/apps/studio/test/sync-incident-replay.test.ts +0 -211
  485. package/apps/studio/test/sync-journal.test.ts +0 -176
  486. package/apps/studio/test/sync-meta-codec.test.ts +0 -199
  487. package/apps/studio/test/sync-migrate-flat-fallback.test.ts +0 -98
  488. package/apps/studio/test/sync-move-retirement.test.ts +0 -231
  489. package/apps/studio/test/sync-panel-surface.test.ts +0 -153
  490. package/apps/studio/test/sync-path-pull.test.ts +0 -531
  491. package/apps/studio/test/sync-presentation.test.ts +0 -262
  492. package/apps/studio/test/sync-pull-budget.test.ts +0 -169
  493. package/apps/studio/test/sync-remote-docs.test.ts +0 -333
  494. package/apps/studio/test/sync-resync-routes.test.ts +0 -168
  495. package/apps/studio/test/sync-runtime.test.ts +0 -1675
  496. package/apps/studio/test/sync-seed-defers-to-hub.test.ts +0 -83
  497. package/apps/studio/test/sync-settings-routes.test.ts +0 -195
  498. package/apps/studio/test/sync-settings.test.ts +0 -151
  499. package/apps/studio/test/sync-status.test.ts +0 -261
  500. package/apps/studio/test/sync-supervisor.test.ts +0 -262
  501. package/apps/studio/test/sync-tombstone-apply.test.ts +0 -111
  502. package/apps/studio/test/sync-trash.test.ts +0 -132
  503. package/apps/studio/test/sync-two-peer-discovery.test.ts +0 -343
  504. package/apps/studio/test/sync-untrusted.test.ts +0 -103
  505. package/apps/studio/test/system-endpoint.test.ts +0 -144
  506. package/apps/studio/test/text-editability-stamp.test.ts +0 -131
  507. package/apps/studio/test/timeline-comp-target.test.ts +0 -139
  508. package/apps/studio/test/timeline-media-cache.test.ts +0 -41
  509. package/apps/studio/test/timeline-parse.test.ts +0 -184
  510. package/apps/studio/test/timeline-scale.test.ts +0 -65
  511. package/apps/studio/test/timeline-snap.test.ts +0 -85
  512. package/apps/studio/test/tool-palette-insert-anchor.test.ts +0 -86
  513. package/apps/studio/test/tool-palette.test.tsx +0 -55
  514. package/apps/studio/test/tour-overlay.test.tsx +0 -90
  515. package/apps/studio/test/trusted-request-host.test.ts +0 -66
  516. package/apps/studio/test/undo-sequence-byte-compare.test.ts +0 -211
  517. package/apps/studio/test/undo-stack.test.ts +0 -244
  518. package/apps/studio/test/use-agent-presence.test.tsx +0 -117
  519. package/apps/studio/test/use-annotation-resize.test.ts +0 -402
  520. package/apps/studio/test/use-annotation-selection.test.tsx +0 -77
  521. package/apps/studio/test/use-artboard-drag.test.ts +0 -324
  522. package/apps/studio/test/use-canvas-activity.test.tsx +0 -206
  523. package/apps/studio/test/use-collab.test.ts +0 -0
  524. package/apps/studio/test/use-cursor-modifiers.test.ts +0 -59
  525. package/apps/studio/test/use-keyboard-discipline.test.ts +0 -27
  526. package/apps/studio/test/use-selection-set.test.tsx +0 -166
  527. package/apps/studio/test/use-snap-guides.test.ts +0 -271
  528. package/apps/studio/test/use-tool-mode.test.tsx +0 -186
  529. package/apps/studio/test/use-undo-stack.test.tsx +0 -223
  530. package/apps/studio/test/video-asset.test.ts +0 -163
  531. package/apps/studio/test/video-comp-fixture.test.ts +0 -50
  532. package/apps/studio/test/video-comp.test.ts +0 -270
  533. package/apps/studio/test/video-encode-lib.test.ts +0 -63
  534. package/apps/studio/test/video-render-bridge.test.ts +0 -171
  535. package/apps/studio/test/whats-new.test.ts +0 -113
  536. package/apps/studio/test/whisper-setup.test.ts +0 -97
  537. package/apps/studio/test/workspace-containment.test.ts +0 -382
  538. package/apps/studio/test/workspace-signin.test.ts +0 -292
  539. package/apps/studio/test/ws-handshake.test.ts +0 -33
  540. package/cli/commands/cache.test.mjs +0 -166
  541. package/cli/commands/design-link.test.mjs +0 -419
  542. package/cli/commands/design.test.mjs +0 -240
  543. package/cli/commands/doctor.test.mjs +0 -237
  544. package/cli/commands/hub-workspace.test.mjs +0 -275
  545. package/cli/commands/hub.test.mjs +0 -225
  546. package/cli/commands/kg.test.mjs +0 -142
  547. package/cli/commands/preflight.test.mjs +0 -46
  548. package/cli/lib/argv.test.mjs +0 -46
  549. package/cli/lib/cache.test.mjs +0 -303
  550. package/cli/lib/cell-plan.test.mjs +0 -225
  551. package/cli/lib/config-lint.test.mjs +0 -117
  552. package/cli/lib/ddr-to-kgai.test.mjs +0 -118
  553. package/cli/lib/design-ownership.test.mjs +0 -329
  554. package/cli/lib/fetch-asset.test.mjs +0 -213
  555. package/cli/lib/figma-codegen-reachability.test.mjs +0 -104
  556. package/cli/lib/figma-import-controls.test.mjs +0 -70
  557. package/cli/lib/flow-design-integration.test.mjs +0 -165
  558. package/cli/lib/gitignore-block.test.mjs +0 -136
  559. package/cli/lib/gitignore-drift.test.mjs +0 -156
  560. package/cli/lib/hubs-config.test.mjs +0 -165
  561. package/cli/lib/pkg-root.test.mjs +0 -111
  562. package/cli/lib/plugin-cli-reachability.test.mjs +0 -57
  563. package/cli/lib/plugin-name-namespace.test.mjs +0 -71
  564. package/cli/lib/reconstruct-toolset.test.mjs +0 -194
  565. package/cli/lib/stack-detect.test.mjs +0 -121
  566. package/cli/lib/update-check.test.mjs +0 -32
  567. package/cli/lib/workspace-plan.test.mjs +0 -699
@@ -1,976 +0,0 @@
1
- // The file plane, both directions — Sync v2 Increment 3 (DDR-226 §§3–7).
2
- //
3
- // `decide-file.ts` proves the TABLE and `file-ledger.ts` proves the ORDERING.
4
- // This proves the thing neither can: that a real pass reads a journal, scans a
5
- // real tree, and carries out what the table said — moving bytes the right way,
6
- // parking what must be parked, and refusing what a receiver must refuse.
7
- //
8
- // The hub here is a fixture, not a stub of our own logic: it answers the real
9
- // wire shapes (`GET /api/journal`, `GET /_project-file/`, `PUT /api/file/`)
10
- // and enforces the compare-and-swap, so a client that gets the protocol wrong
11
- // fails here rather than in production.
12
-
13
- import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
14
- import { createHash } from 'node:crypto';
15
- import {
16
- existsSync,
17
- mkdirSync,
18
- mkdtempSync,
19
- readdirSync,
20
- readFileSync,
21
- rmSync,
22
- statSync,
23
- symlinkSync,
24
- writeFileSync,
25
- } from 'node:fs';
26
- import { tmpdir } from 'node:os';
27
- import { join } from 'node:path';
28
-
29
- import { createFileLedger, type FileLedger } from '../sync/file-ledger.ts';
30
- import {
31
- createFilePlane,
32
- DELETE_BUDGET_PER_WINDOW,
33
- foldRemote,
34
- REANCHOR_HOLD_RECOVERY_MS,
35
- REANCHOR_STORM_LIMIT,
36
- scanLocalFiles,
37
- } from '../sync/file-plane.ts';
38
-
39
- const HUB = 'https://hub.test';
40
- const sha = (s: string | Uint8Array) => createHash('sha256').update(s).digest('hex');
41
-
42
- let root: string;
43
- let ledger: FileLedger;
44
-
45
- beforeEach(() => {
46
- root = mkdtempSync(join(tmpdir(), 'file-plane-'));
47
- mkdirSync(join(root, 'system/ds'), { recursive: true });
48
- mkdirSync(join(root, 'assets'), { recursive: true });
49
- writeFileSync(join(root, 'config.json'), '{"canvasGroups":[{"path":"system"},{"path":"ui"}]}');
50
- ledger = createFileLedger({ designRoot: root, hubUrl: HUB, flushMs: 0 });
51
- });
52
- afterEach(() => {
53
- rmSync(root, { recursive: true, force: true });
54
- });
55
-
56
- /** A hub that answers the real routes and enforces the real preconditions. */
57
- function fakeHub(initial: Record<string, string> = {}) {
58
- let seq = 0;
59
- const rows = new Map<
60
- string,
61
- { seq: number; sha256: string | null; size: number; body: string; deleted?: boolean }
62
- >();
63
- const puts: { rel: string; expect: string | null; body: string }[] = [];
64
- const deletes: string[] = [];
65
- let lieAboutSize = false;
66
- let forceReanchor = false;
67
- let reanchorBudget = 0;
68
- let epochValue = 'epoch-1';
69
- const add = (rel: string, body: string) => {
70
- seq += 1;
71
- rows.set(rel, { seq, sha256: sha(body), size: body.length, body });
72
- };
73
- for (const [rel, body] of Object.entries(initial)) add(rel, body);
74
-
75
- const fetchImpl = (async (url: string, init?: RequestInit) => {
76
- const u = new URL(String(url));
77
- if (u.pathname === '/api/journal') {
78
- const since = Number(u.searchParams.get('since') ?? '0');
79
- const askedEpoch = u.searchParams.get('epoch');
80
- if (reanchorBudget > 0) {
81
- reanchorBudget -= 1;
82
- return new Response(JSON.stringify({ epoch: epochValue, head: seq, reanchor: true }), {
83
- status: 200,
84
- });
85
- }
86
- if (forceReanchor) {
87
- return new Response(JSON.stringify({ epoch: epochValue, head: seq, reanchor: true }), {
88
- status: 200,
89
- });
90
- }
91
- if (askedEpoch && askedEpoch !== epochValue) {
92
- return new Response(JSON.stringify({ epoch: epochValue, head: seq, reanchor: true }), {
93
- status: 200,
94
- });
95
- }
96
- if (since > seq) {
97
- return new Response(JSON.stringify({ epoch: epochValue, head: seq, reanchor: true }), {
98
- status: 200,
99
- });
100
- }
101
- const entries = [...rows.entries()]
102
- .filter(([, r]) => r.seq > since)
103
- .map(([path, r]) => ({
104
- seq: r.seq,
105
- path,
106
- sha256: r.sha256,
107
- size: lieAboutSize ? 0 : r.size,
108
- mtimeMs: 0,
109
- class: 'companion-text',
110
- deleted: r.deleted === true,
111
- }))
112
- .sort((a, b) => a.seq - b.seq);
113
- return new Response(
114
- JSON.stringify({ epoch: epochValue, head: seq, entries, truncated: false }),
115
- {
116
- status: 200,
117
- }
118
- );
119
- }
120
- if (u.pathname.startsWith('/_project-file/')) {
121
- const rel = decodeURIComponent(u.pathname.slice('/_project-file/'.length));
122
- const row = rows.get(rel);
123
- if (!row) return new Response('nope', { status: 404 });
124
- return new Response(row.body, { status: 200 });
125
- }
126
- if (u.pathname.startsWith('/api/file/') && init?.method === 'DELETE') {
127
- const rel = u.pathname
128
- .slice('/api/file/'.length)
129
- .split('/')
130
- .map(decodeURIComponent)
131
- .join('/');
132
- const headers = new Headers(init.headers as HeadersInit);
133
- const expect = headers.get('x-maude-expect-hash');
134
- const current = rows.get(rel)?.sha256 ?? null;
135
- if (expect && expect !== 'none' && current !== expect) {
136
- return new Response(JSON.stringify({ error: 'moved', current }), { status: 409 });
137
- }
138
- deletes.push(rel);
139
- seq += 1;
140
- rows.set(rel, { seq, sha256: null, size: 0, body: '', deleted: true });
141
- return new Response(JSON.stringify({ ok: true, path: rel, deleted: true, seq }), {
142
- status: 200,
143
- });
144
- }
145
- if (u.pathname.startsWith('/api/file/') && init?.method === 'PUT') {
146
- const rel = u.pathname
147
- .slice('/api/file/'.length)
148
- .split('/')
149
- .map(decodeURIComponent)
150
- .join('/');
151
- const headers = new Headers(init.headers as HeadersInit);
152
- const expect = headers.get('x-maude-expect-hash');
153
- const current = rows.get(rel)?.sha256 ?? null;
154
- const wantsAbsent = expect === 'none';
155
- if (expect && !(wantsAbsent ? current === null : current === expect)) {
156
- return new Response(JSON.stringify({ error: 'moved', current }), { status: 409 });
157
- }
158
- const body = Buffer.from(init.body as ArrayBuffer).toString('utf8');
159
- puts.push({ rel, expect, body });
160
- add(rel, body);
161
- return new Response(JSON.stringify({ ok: true, seq, sha256: sha(body) }), { status: 200 });
162
- }
163
- return new Response('not found', { status: 404 });
164
- }) as unknown as typeof fetch;
165
-
166
- /**
167
- * A rewind: the log comes back from an older generation. Rows above `to` are
168
- * gone and the head moves back — which is what makes a peer's cursor
169
- * unhonourable and forces the re-anchor.
170
- */
171
- const rewindTo = (to: number) => {
172
- for (const [rel, r] of [...rows]) if (r.seq > to) rows.delete(rel);
173
- seq = to;
174
- };
175
-
176
- return {
177
- fetchImpl,
178
- rows,
179
- puts,
180
- add,
181
- rewindTo,
182
- deletes,
183
- /** Tombstone a path hub-side, as another peer's delete would. */
184
- tombstone: (rel: string) => {
185
- seq += 1;
186
- rows.set(rel, { seq, sha256: null, size: 0, body: '', deleted: true });
187
- },
188
- epoch: () => epochValue,
189
- head: () => seq,
190
- /** Declare every row as costing nothing — the A1 primitive. */
191
- understateSizes: () => {
192
- lieAboutSize = true;
193
- },
194
- /** Answer `reanchor` to everything — the hostile-hub shape. */
195
- alwaysReanchor: () => {
196
- forceReanchor = true;
197
- },
198
- /** Answer `reanchor` for the next `n` requests only. */
199
- reanchorFor: (n: number) => {
200
- reanchorBudget = n;
201
- },
202
- /** A LEGITIMATE epoch rotation (a restore, DDR-226 §3). */
203
- rotateEpoch: () => {
204
- epochValue = `epoch-${Math.abs(seq) + 2}`;
205
- },
206
- };
207
- }
208
-
209
- const plane = (hub: ReturnType<typeof fakeHub>, over = {}) =>
210
- createFilePlane({
211
- designRoot: root,
212
- hubUrl: HUB,
213
- token: () => 'tok',
214
- ledger,
215
- allowCodeModules: false,
216
- label: 'laptop',
217
- fetchImpl: hub.fetchImpl,
218
- log: { log() {}, warn() {} },
219
- now: () => 1_700_000_000_000,
220
- ...over,
221
- });
222
-
223
- const read = (rel: string) => readFileSync(join(root, rel), 'utf8');
224
- const write = (rel: string, body: string) => {
225
- mkdirSync(join(root, rel, '..'), { recursive: true });
226
- writeFileSync(join(root, rel), body);
227
- };
228
-
229
- describe('scanning', () => {
230
- test('admits the plane and leaves plane A alone', () => {
231
- write('system/ds/brand.css', ':root{}');
232
- write('assets/a.png', 'PNG');
233
- write('ui/home.tsx', 'export default null');
234
- write('ui/home.meta.json', '{}');
235
- const found = scanLocalFiles(root, ledger, [{ path: 'system' }, { path: 'ui' }]);
236
- expect([...found.keys()].sort()).toEqual(['assets/a.png', 'system/ds/brand.css']);
237
- });
238
-
239
- test('a SETTLED file is answered from the stat cache, unread', () => {
240
- write('system/ds/brand.css', ':root{}');
241
- const first = scanLocalFiles(root, ledger);
242
- const found = first.get('system/ds/brand.css')!;
243
- // An old mtime is a trustworthy identity: nothing can have changed inside
244
- // the timestamp's resolution, because the timestamp is not recent.
245
- ledger.noteLocal('system/ds/brand.css', found.hash, found.size, Date.now() - 60_000);
246
- expect(ledger.cachedHash('system/ds/brand.css', found.size, Date.now() - 60_000)).toBe(
247
- found.hash
248
- );
249
- });
250
-
251
- test('a file written MOMENTS ago is re-read, whatever the stamp says', () => {
252
- // The mtime-granularity trap, and it is not hypothetical: `v1` → `v2` is a
253
- // same-length edit, and two writes inside the filesystem's timestamp
254
- // resolution are indistinguishable by `(size, mtime)`. Trusting the cache
255
- // there means a real edit is never noticed at all.
256
- write('system/ds/brand.css', 'v1');
257
- const first = scanLocalFiles(root, ledger);
258
- const found = first.get('system/ds/brand.css')!;
259
- expect(ledger.cachedHash('system/ds/brand.css', found.size, found.mtimeMs)).toBeNull();
260
- });
261
-
262
- test('and the watcher can invalidate a path outright', () => {
263
- write('system/ds/brand.css', ':root{}');
264
- const found = scanLocalFiles(root, ledger).get('system/ds/brand.css')!;
265
- ledger.noteLocal('system/ds/brand.css', found.hash, found.size, Date.now() - 60_000);
266
- ledger.noteChanged('system/ds/brand.css');
267
- expect(ledger.cachedHash('system/ds/brand.css', found.size, Date.now() - 60_000)).toBeNull();
268
- });
269
-
270
- test('never descends into runtime state', () => {
271
- mkdirSync(join(root, '_history/x'), { recursive: true });
272
- writeFileSync(join(root, '_history/x/old.css'), 'x');
273
- mkdirSync(join(root, '_trash'), { recursive: true });
274
- writeFileSync(join(root, '_trash/dead.css'), 'x');
275
- expect([...scanLocalFiles(root, ledger).keys()]).toEqual([]);
276
- });
277
- });
278
-
279
- describe('foldRemote', () => {
280
- test('the newest row per path wins', () => {
281
- const folded = foldRemote([
282
- { seq: 1, path: 'a', sha256: 'x', size: 1, mtimeMs: 0, class: '', deleted: false },
283
- { seq: 5, path: 'a', sha256: 'y', size: 1, mtimeMs: 0, class: '', deleted: false },
284
- { seq: 3, path: 'a', sha256: 'z', size: 1, mtimeMs: 0, class: '', deleted: false },
285
- ]);
286
- expect(folded.get('a')?.sha256).toBe('y');
287
- });
288
- });
289
-
290
- describe('down — the hub has something we do not', () => {
291
- test('it lands, verified, and the ancestor follows', async () => {
292
- const hub = fakeHub({ 'system/ds/brand.css': ':root{--a:1}' });
293
- const res = await plane(hub).reconcile();
294
- expect(res.pulled).toEqual(['system/ds/brand.css']);
295
- expect(read('system/ds/brand.css')).toBe(':root{--a:1}');
296
- expect(ledger.ancestorOf('system/ds/brand.css')).toBe(sha(':root{--a:1}'));
297
- expect(ledger.cursor()).toBe(hub.head());
298
- });
299
-
300
- test('a hub that serves the WRONG bytes lands nothing', async () => {
301
- // The hub may refuse to serve; it must never be able to substitute.
302
- const hub = fakeHub({ 'system/ds/brand.css': 'real' });
303
- hub.rows.set('system/ds/brand.css', {
304
- ...hub.rows.get('system/ds/brand.css')!,
305
- body: 'TAMPERED',
306
- });
307
- const res = await plane(hub).reconcile();
308
- expect(res.pulled).toEqual([]);
309
- expect(existsSync(join(root, 'system/ds/brand.css'))).toBe(false);
310
- expect(res.failed[0]?.reason).toContain('hash mismatch');
311
- expect(ledger.ancestorOf('system/ds/brand.css')).toBeNull();
312
- });
313
-
314
- test('a code module is REFUSED unless this machine vouches for the hub', async () => {
315
- const hub = fakeHub({ 'system/ds/preview/_x.ts': 'export const a = 1' });
316
- const res = await plane(hub).reconcile();
317
- expect(res.pulled).toEqual([]);
318
- expect(res.dropped[0]?.reason).toContain('owner-vouched');
319
- });
320
-
321
- test('…and lands when it does', async () => {
322
- const hub = fakeHub({ 'system/ds/preview/_x.ts': 'export const a = 1' });
323
- const res = await plane(hub, { allowCodeModules: true }).reconcile();
324
- expect(res.pulled).toEqual(['system/ds/preview/_x.ts']);
325
- });
326
-
327
- test('a refusal HOLDS on later passes, when the delta no longer mentions it', async () => {
328
- // The hole this closes had teeth. Admission used to run only for paths the
329
- // current page carried — but a cursor read is silent about everything that
330
- // did not just change. So a code module refused on the pass that
331
- // introduced it sailed through on the very next tick, sourced from the
332
- // remembered remote with no gate in front of it. Admission belongs to the
333
- // OFFER, not to the notification.
334
- const hub = fakeHub({ 'system/ds/preview/_x.ts': 'export const a = 1' });
335
- const first = await plane(hub).reconcile();
336
- expect(first.pulled).toEqual([]);
337
- expect(first.dropped.length).toBe(1);
338
-
339
- const second = await plane(hub).reconcile();
340
- expect(second.pulled).toEqual([]);
341
- expect(second.dropped.length).toBe(1);
342
- expect(existsSync(join(root, 'system/ds/preview/_x.ts'))).toBe(false);
343
-
344
- const third = await plane(hub).reconcile();
345
- expect(third.pulled).toEqual([]);
346
- });
347
-
348
- test('a path THIS peer classifies differently is dropped, not negotiated', async () => {
349
- // `config.json` is `never` here whatever the hub says about it.
350
- const hub = fakeHub({ 'config.json': '{"evil":true}' });
351
- const res = await plane(hub).reconcile();
352
- expect(res.dropped.some((d) => d.rel === 'config.json')).toBe(true);
353
- expect(read('config.json')).toContain('canvasGroups');
354
- });
355
-
356
- test('a refused path is reported but never becomes a stored row', async () => {
357
- // A hostile page used to cost two persistent writes per junk path — one
358
- // from `noteRemote` before any classifier ran, one from the `stuck` row
359
- // after — neither pruned by count, both surviving a restart, and both
360
- // re-walked in the union on every later pass.
361
- const hub = fakeHub();
362
- for (let i = 0; i < 200; i++) hub.add(`junk/payload-${i}.exe`, 'x');
363
- const p = plane(hub);
364
- const res = await p.reconcile();
365
-
366
- expect(res.dropped.length).toBeGreaterThan(0);
367
- const receipt = p.doruceka();
368
- const stored = Object.keys(receipt).filter((k) => k.startsWith('junk/'));
369
- expect(stored).toEqual([]);
370
- });
371
- });
372
-
373
- describe('up — we have something the hub does not', () => {
374
- test('it uploads with a "hub must hold nothing" precondition', async () => {
375
- const hub = fakeHub();
376
- write('system/ds/brand.css', 'mine');
377
- const res = await plane(hub).reconcile();
378
- expect(res.pushed).toEqual(['system/ds/brand.css']);
379
- expect(hub.puts[0]?.expect).toBe('none');
380
- expect(ledger.ancestorOf('system/ds/brand.css')).toBe(sha('mine'));
381
- });
382
-
383
- test('a local edit uploads with the hub state we decided FROM', async () => {
384
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
385
- await plane(hub).reconcile(); // pull v1, ancestor = v1
386
- write('system/ds/brand.css', 'v2');
387
- const res = await plane(hub).reconcile();
388
- expect(res.pushed).toEqual(['system/ds/brand.css']);
389
- expect(hub.puts.at(-1)?.expect).toBe(sha('v1'));
390
- });
391
-
392
- test('a hub that LOST a file gets it back — absence is not authority', async () => {
393
- // The real shape of this, and the reason it needs a rewind rather than a
394
- // deletion: the journal is APPEND-ONLY, so a hub cannot quietly drop a
395
- // row. A file vanishes from its side only when the log itself rewinds —
396
- // a restore from an older generation whose tail could not be replayed.
397
- // That rewind is exactly what makes our cursor unhonourable, so the pass
398
- // re-anchors, reads the whole compaction, and only THEN is entitled to
399
- // conclude the hub no longer has the file.
400
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
401
- await plane(hub).reconcile();
402
- expect(read('system/ds/brand.css')).toBe('v1');
403
-
404
- hub.rewindTo(0); // the generation predates the file entirely
405
- const res = await plane(hub).reconcile();
406
-
407
- expect(res.reanchored).toBe(true);
408
- expect(res.pushed).toEqual(['system/ds/brand.css']);
409
- expect(read('system/ds/brand.css')).toBe('v1');
410
- });
411
-
412
- test('a DELTA silence is never read as "the hub lost it"', async () => {
413
- // The counterpart, and the bug this guards: a cursor read returns only
414
- // what changed. If silence meant absence, every converged file would be
415
- // re-uploaded on every single pass.
416
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
417
- await plane(hub).reconcile();
418
- const second = await plane(hub).reconcile();
419
- expect(second.pushed).toEqual([]);
420
- expect(second.pulled).toEqual([]);
421
- });
422
- });
423
-
424
- describe('the compare-and-swap is what makes concurrency safe', () => {
425
- test('a push against a moved hub is REFUSED and reported, not forced', async () => {
426
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
427
- await plane(hub).reconcile();
428
- // Both sides move: we edit, and someone else lands v2 on the hub.
429
- write('system/ds/brand.css', 'mine');
430
- hub.add('system/ds/brand.css', 'theirs');
431
- // Decide from the STALE view by pushing before re-reading.
432
- const p = plane(hub);
433
- // First pass sees theirs and conflicts (both moved).
434
- const res = await p.reconcile();
435
- expect(res.conflicts.length).toBe(1);
436
- // The local version is parked where a person can find it…
437
- const parked = readdirSync(join(root, 'system/ds')).find((n) => n.includes('maude-conflict'));
438
- expect(parked).toBeDefined();
439
- expect(readFileSync(join(root, 'system/ds', parked!), 'utf8')).toBe('mine');
440
- // …and the hub's version is what sits at the canonical path.
441
- expect(read('system/ds/brand.css')).toBe('theirs');
442
- });
443
-
444
- test('the conflict copy travels UP, so both ends see it', async () => {
445
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
446
- await plane(hub).reconcile();
447
- write('system/ds/brand.css', 'mine');
448
- hub.add('system/ds/brand.css', 'theirs');
449
- await plane(hub).reconcile();
450
- const uploaded = hub.puts.find((p) => p.rel.includes('maude-conflict'));
451
- expect(uploaded?.body).toBe('mine');
452
- });
453
-
454
- test('a conflict copy is NEVER named like Syncthing’s', async () => {
455
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
456
- await plane(hub).reconcile();
457
- write('system/ds/brand.css', 'mine');
458
- hub.add('system/ds/brand.css', 'theirs');
459
- await plane(hub).reconcile();
460
- const names = readdirSync(join(root, 'system/ds'));
461
- expect(names.some((n) => n.includes('maude-conflict'))).toBe(true);
462
- expect(names.some((n) => n.includes('sync-conflict'))).toBe(false);
463
- });
464
- });
465
-
466
- describe('the converged steady state is free', () => {
467
- test('a second pass moves nothing and reports agreement', async () => {
468
- const hub = fakeHub({ 'system/ds/brand.css': 'v1', 'assets/a.png': 'PNG' });
469
- await plane(hub).reconcile();
470
- const second = await plane(hub).reconcile();
471
- expect(second.pulled).toEqual([]);
472
- expect(second.pushed).toEqual([]);
473
- expect(second.synced).toBeGreaterThan(0);
474
- });
475
-
476
- test('and it costs ONE journal read, from the cursor', async () => {
477
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
478
- await plane(hub).reconcile();
479
- const before = ledger.cursor();
480
- expect(before).toBe(hub.head());
481
- const asked: string[] = [];
482
- const counting = (async (url: string, init?: RequestInit) => {
483
- asked.push(String(url));
484
- return hub.fetchImpl(url as never, init as never);
485
- }) as unknown as typeof fetch;
486
- await plane(hub, { fetchImpl: counting }).reconcile();
487
- expect(asked.filter((u) => u.includes('/api/journal')).length).toBe(1);
488
- expect(asked.some((u) => u.includes('/_project-file/'))).toBe(false);
489
- });
490
- });
491
-
492
- describe('re-anchoring fails CLOSED', () => {
493
- test('a foreign epoch re-reads from zero rather than assuming quiet', async () => {
494
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
495
- await plane(hub).reconcile();
496
- // The hub's log restarted under a new epoch.
497
- ledger.setPosition('epoch-OLD', 99);
498
- const res = await plane(hub).reconcile();
499
- expect(res.reanchored).toBe(true);
500
- expect(ledger.epoch()).toBe('epoch-1');
501
- });
502
-
503
- test('a degraded epoch never overwrites local work — it parks theirs beside it', async () => {
504
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
505
- await plane(hub).reconcile();
506
- write('system/ds/brand.css', 'my unsent work');
507
- // Pretend our anchor belongs to a log the hub no longer has, WITHOUT
508
- // going through the reanchor path (the degraded-read case).
509
- ledger.setPosition('epoch-GONE', 0);
510
- hub.add('system/ds/brand.css', 'their newer');
511
- const res = await plane(hub, { fetchImpl: hub.fetchImpl }).reconcile();
512
- // Either way the local bytes survive; that is the invariant.
513
- expect(read('system/ds/brand.css')).not.toBe('their newer');
514
- expect(res.pulled).toEqual([]);
515
- });
516
- });
517
-
518
- describe('the doručenka answers "where is this file"', () => {
519
- test('a pulled file reads on-hub; an unsent one reads local-only', async () => {
520
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
521
- write('assets/local.png', 'only here');
522
- const p = plane(hub);
523
- await p.reconcile();
524
- const states = p.doruceka();
525
- expect(states['system/ds/brand.css']).toBe('on-hub');
526
- // It was pushed in the same pass, so it is on the hub too — the point is
527
- // that NOTHING reads as delivered without having got there.
528
- expect(['on-hub', 'local-only']).toContain(states['assets/local.png']);
529
- });
530
-
531
- test('a CONVERGED file reads on-hub, not local-only', async () => {
532
- // The lie this closes, seen live in a local run: a delta never mentions a
533
- // settled file, so reading the page instead of the remembered remote made
534
- // every converged file report `local-only` — a panel saying "not
535
- // delivered" about files that had been on the hub for hours.
536
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
537
- const p = plane(hub);
538
- await p.reconcile();
539
- await p.reconcile(); // the converged pass, where the delta is silent
540
- expect(p.doruceka()['system/ds/brand.css']).toBe('on-hub');
541
- });
542
-
543
- test('a REFUSED path says it is refused, not that it is merely local', async () => {
544
- // A refusal outranks everything (DDR-214). A code module this peer
545
- // declines is not "local-only" — it is not here, and will not be.
546
- const hub = fakeHub({ 'system/ds/preview/_x.ts': 'export const a = 1' });
547
- const p = plane(hub);
548
- await p.reconcile();
549
- expect(p.doruceka()['system/ds/preview/_x.ts']).toBe('stuck');
550
- });
551
-
552
- test('a failure is named, not swallowed', async () => {
553
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
554
- const broken = (async (url: string, init?: RequestInit) => {
555
- if (String(url).includes('/_project-file/')) return new Response('no', { status: 500 });
556
- return hub.fetchImpl(url as never, init as never);
557
- }) as unknown as typeof fetch;
558
- const p = plane(hub, { fetchImpl: broken });
559
- const res = await p.reconcile();
560
- expect(res.failed.length).toBe(1);
561
- expect(p.doruceka()['system/ds/brand.css']).toBe('stuck');
562
- expect(ledger.row('system/ds/brand.css')?.reason).toContain('500');
563
- });
564
- });
565
-
566
- describe('deletion stays OFF until its breakers ship', () => {
567
- test('a file deleted here is HELD — neither resurrected nor propagated', async () => {
568
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
569
- await plane(hub).reconcile();
570
- rmSync(join(root, 'system/ds/brand.css'));
571
- const res = await plane(hub).reconcile();
572
- expect(res.pulled).toEqual([]); // not resurrected
573
- expect(hub.rows.has('system/ds/brand.css')).toBe(true); // not deleted upstream
574
- expect(existsSync(join(root, 'system/ds/brand.css'))).toBe(false);
575
- });
576
-
577
- test('but an EDIT still beats a delete', async () => {
578
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
579
- await plane(hub).reconcile();
580
- rmSync(join(root, 'system/ds/brand.css'));
581
- hub.add('system/ds/brand.css', 'somebody edited it');
582
- const res = await plane(hub).reconcile();
583
- expect(res.pulled).toEqual(['system/ds/brand.css']);
584
- expect(read('system/ds/brand.css')).toBe('somebody edited it');
585
- });
586
- });
587
-
588
- describe('the F6 budget applies to this lane too', () => {
589
- test('a pass stops on bytes and resumes next time', async () => {
590
- const hub = fakeHub({
591
- 'system/ds/a.css': 'x'.repeat(400),
592
- 'system/ds/b.css': 'y'.repeat(400),
593
- 'system/ds/c.css': 'z'.repeat(400),
594
- });
595
- const first = await plane(hub, { maxPassBytes: 900 }).reconcile();
596
- expect(first.pulled.length).toBe(2);
597
- expect(first.budgetExhausted).toBe(true);
598
- const second = await plane(hub, { maxPassBytes: 900 }).reconcile();
599
- expect(second.pulled.length).toBe(1);
600
- });
601
-
602
- // The budget caps a TRANSFER, not a claim. `size` is the hub's number, and
603
- // the hub is untrusted (DDR-054) — a row declaring 0 for a 512 MB body is
604
- // one field away from landing 100 GB in a pass against a budget that never
605
- // moved. So the wire is charged, not the row.
606
- test('an understated size does not buy a bigger transfer', async () => {
607
- const hub = fakeHub({
608
- 'system/ds/a.css': 'x'.repeat(400),
609
- 'system/ds/b.css': 'y'.repeat(400),
610
- 'system/ds/c.css': 'z'.repeat(400),
611
- });
612
- hub.understateSizes();
613
- const pass = await plane(hub, { maxPassBytes: 900 }).reconcile();
614
- expect(pass.budgetExhausted).toBe(true);
615
- expect(pass.pulled.length).toBeLessThan(3);
616
- });
617
-
618
- test('a body larger than the whole budget is refused before it is buffered', async () => {
619
- const hub = fakeHub({ 'system/ds/a.css': 'x'.repeat(4000) });
620
- hub.understateSizes();
621
- const pass = await plane(hub, { maxPassBytes: 100 }).reconcile();
622
- expect(pass.pulled.length).toBe(0);
623
- expect(pass.failed.length + (pass.budgetExhausted ? 1 : 0)).toBeGreaterThan(0);
624
- });
625
- });
626
-
627
- describe("the receiver defends its own root, not just the hub's", () => {
628
- test('a symlinked intermediate directory cannot land bytes outside the root', async () => {
629
- // Lexical traversal is refused upstream by the classifier's shape gate, so
630
- // this is the case that was genuinely uncovered: `writeFileSync` and
631
- // `renameSync` follow DIRECTORY symlinks happily, and the hub defends this
632
- // on its own write surfaces while the receiver did not.
633
- const outside = mkdtempSync(join(tmpdir(), 'plane-outside-'));
634
- mkdirSync(join(root, 'system'), { recursive: true });
635
- symlinkSync(outside, join(root, 'system/escaped'), 'dir');
636
-
637
- const hub = fakeHub({ 'system/escaped/stolen.css': 'PAYLOAD' });
638
- const res = await plane(hub).reconcile();
639
-
640
- expect(existsSync(join(outside, 'stolen.css'))).toBe(false);
641
- expect(res.pulled).toEqual([]);
642
- expect(res.failed.length + res.dropped.length).toBeGreaterThan(0);
643
- });
644
-
645
- test('a pull into directories that do not exist yet keeps its full path', async () => {
646
- // The fresh-link case, and the bug the containment fix introduced: the
647
- // deepest EXISTING ancestor of `system/deep/nested/a.css` in an empty tree
648
- // is the design root itself, so resolving to that and appending the
649
- // basename produced `<root>/a.css`. Every file in a first sync would have
650
- // landed flattened at the top level.
651
- const hub = fakeHub({ 'system/deep/nested/a.css': '.deep{}' });
652
- const res = await plane(hub).reconcile();
653
-
654
- expect(res.pulled).toEqual(['system/deep/nested/a.css']);
655
- expect(read('system/deep/nested/a.css')).toBe('.deep{}');
656
- expect(existsSync(join(root, 'a.css'))).toBe(false);
657
- });
658
-
659
- test('refuses to replace a directory sitting where a file belongs', async () => {
660
- mkdirSync(join(root, 'system/ds/brand.css'), { recursive: true });
661
- const hub = fakeHub({ 'system/ds/brand.css': ':root{}' });
662
- const res = await plane(hub).reconcile();
663
- expect(res.pulled).toEqual([]);
664
- expect(statSync(join(root, 'system/ds/brand.css')).isDirectory()).toBe(true);
665
- });
666
- });
667
-
668
- describe('a hub that re-anchors forever is not obeyed forever', () => {
669
- test('the storm limit holds the pass instead of parking a copy per tick', async () => {
670
- const hub = fakeHub({ 'system/ds/brand.css': 'theirs' });
671
- write('system/ds/brand.css', 'mine');
672
- const p = plane(hub);
673
-
674
- // Every request answers `reanchor`, which is the shape a hostile hub uses
675
- // to keep `degraded` true and make every diverged path park a fresh copy.
676
- hub.alwaysReanchor();
677
-
678
- let held = false;
679
- for (let i = 0; i < REANCHOR_STORM_LIMIT + 3; i++) {
680
- const res = await p.reconcile();
681
- if (res.reanchorHeld) held = true;
682
- }
683
- expect(held).toBe(true);
684
- expect(read('system/ds/brand.css')).toBe('mine');
685
- });
686
-
687
- test('F-11: the hold is a window, not a brick — a retry is allowed after recovery', async () => {
688
- const hub = fakeHub({ 'system/ds/brand.css': 'theirs' });
689
- write('system/ds/brand.css', 'mine');
690
- let clock = 1_700_000_000_000;
691
- const p = plane(hub, { now: () => clock });
692
- hub.alwaysReanchor();
693
-
694
- // Drive it into the held state.
695
- let lastHeld = false;
696
- for (let i = 0; i < REANCHOR_STORM_LIMIT + 3; i++) {
697
- lastHeld = (await p.reconcile()).reanchorHeld === true;
698
- }
699
- expect(lastHeld).toBe(true);
700
-
701
- // Still inside the window: held again — the storm stays capped.
702
- clock += 60_000;
703
- expect((await p.reconcile()).reanchorHeld).toBe(true);
704
-
705
- // Past the window: exactly one fresh attempt happens (not held). The hub
706
- // still answers reanchor, so nothing lands — but the plane is provably not
707
- // bricked until a restart, which is what F-11 reported.
708
- clock += REANCHOR_HOLD_RECOVERY_MS;
709
- expect((await p.reconcile()).reanchorHeld).not.toBe(true);
710
- });
711
-
712
- test('the degraded park happens once per remote hash, not once per pass', async () => {
713
- // Converge first, so there is a real ancestor to be degraded away from.
714
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
715
- const p = plane(hub);
716
- await p.reconcile();
717
- expect(read('system/ds/brand.css')).toBe('v1');
718
-
719
- // Now both sides move, and the hub's log restarts — a legitimate event
720
- // (DDR-226 §3), not only a hostile one. Under `degraded` the ancestor
721
- // stops being overwrite authority, so their copy is parked beside ours.
722
- write('system/ds/brand.css', 'mine');
723
- hub.add('system/ds/brand.css', 'theirs');
724
- hub.rotateEpoch();
725
-
726
- const first = await p.reconcile();
727
- expect(first.reanchored).toBe(true);
728
- expect(first.conflicts.length).toBe(1);
729
- const parkedHub = readdirSync(join(root, 'system/ds')).filter((f) => f.includes('-hub.css'));
730
- expect(parkedHub.length).toBe(1);
731
-
732
- // The bug was UNBOUNDED: the decision is `noop`, so the ancestor never
733
- // moves and the next pass finds the identical state — and the copy name
734
- // carries a millisecond stamp, so every pass wrote a NEW file, which was
735
- // then scanned as `create-up` and uploaded back. Settling is the property.
736
- for (let i = 0; i < 6; i++) await p.reconcile();
737
- const after = readdirSync(join(root, 'system/ds')).filter((f) => f.includes('-hub.css'));
738
- expect(after).toEqual(parkedHub);
739
-
740
- const last = await p.reconcile();
741
- expect(last.conflicts).toEqual([]);
742
- });
743
-
744
- test('a repeated degraded pass re-parks nothing — the remote hash is remembered', async () => {
745
- // The memo, exercised directly. `alwaysReanchor` would hit the storm
746
- // breaker after five, which would mask the thing under test; this stays
747
- // under it, so what stops the second park is the memo and only the memo.
748
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
749
- const p = plane(hub);
750
- await p.reconcile();
751
-
752
- write('system/ds/brand.css', 'mine');
753
- hub.add('system/ds/brand.css', 'theirs');
754
-
755
- hub.reanchorFor(1);
756
- const first = await p.reconcile();
757
- expect(first.conflicts.length).toBe(1);
758
-
759
- // Degraded again, same remote hash, still under the storm limit.
760
- hub.reanchorFor(1);
761
- const second = await p.reconcile();
762
- const copies = readdirSync(join(root, 'system/ds')).filter((f) => f.includes('-hub.css'));
763
- expect(copies.length).toBe(1);
764
- expect(second.conflicts.some((c) => c.copy?.includes('-hub.css'))).toBe(false);
765
- });
766
- });
767
-
768
- describe('F2/F3 — plane disjointness survives a fresh link', () => {
769
- // The synthesis line for this gate reads "empty-tree in-group `.css`
770
- // classifies canvas-owned by default". The shipped classifier does the
771
- // OPPOSITE on purpose, and the reason is an RCA: defaulting group css to
772
- // canvas-owned is what lost five real stylesheets (`brand.css`,
773
- // `_layout.css` — files with no sibling body at all, which would then travel
774
- // on no lane whatsoever). Defaulting to the flowing side is recoverable; the
775
- // other direction silently drops content.
776
- //
777
- // What has to be true for that choice to be safe is not the default but the
778
- // CONVERGENCE: the moment the body exists, the css must leave the file plane,
779
- // so the two lanes never both own it for longer than one pass.
780
- test('a sibling-less css flows, and the file plane releases it once the body lands', async () => {
781
- const hub = fakeHub({ 'ui/home.css': '.a{}' });
782
- const p = plane(hub);
783
-
784
- const first = await p.reconcile();
785
- expect(first.pulled).toEqual(['ui/home.css']);
786
-
787
- // Plane A delivers the body — the canvas doc lane, which this plane never
788
- // touches. From here the css is that canvas's Yjs lane, not a file.
789
- write('ui/home.tsx', 'export default null');
790
-
791
- const second = await p.reconcile();
792
- expect(second.pulled).toEqual([]);
793
- const scanned = scanLocalFiles(root, ledger, [{ path: 'system' }, { path: 'ui' }]);
794
- expect(scanned.has('ui/home.css')).toBe(false);
795
- });
796
-
797
- test('a design-system stylesheet with no body anywhere keeps flowing — the RCA case', async () => {
798
- const hub = fakeHub({ 'system/ds/brand.css': ':root{}', 'system/ds/preview/_layout.css': 'x' });
799
- const res = await plane(hub).reconcile();
800
- expect(res.pulled.sort()).toEqual(['system/ds/brand.css', 'system/ds/preview/_layout.css']);
801
- });
802
-
803
- test('config.json is never a plane member in either direction', async () => {
804
- // The seed-before-first-pull half: a synced config is a hub rewriting the
805
- // hub URL and the canvas groups — its own trust anchors.
806
- write('config.json', '{"canvasGroups":[{"path":"system"},{"path":"ui"}],"mine":true}');
807
- const hub = fakeHub({ 'config.json': '{"evil":true}' });
808
- const res = await plane(hub).reconcile();
809
- expect(res.pushed).toEqual([]);
810
- expect(read('config.json')).toContain('"mine"');
811
- });
812
- });
813
-
814
- describe('deletion propagates — Increment 6', () => {
815
- const propagating = (hub: ReturnType<typeof fakeHub>) => plane(hub, { propagateDeletes: true });
816
-
817
- test('gone here, unchanged there ⇒ the hub is told, and the row is a tombstone', async () => {
818
- const hub = fakeHub({ 'system/ds/brand.css': ':root{}' });
819
- const p = propagating(hub);
820
- await p.reconcile();
821
- expect(existsSync(join(root, 'system/ds/brand.css'))).toBe(true);
822
-
823
- rmSync(join(root, 'system/ds/brand.css'));
824
- const res = await p.reconcile();
825
-
826
- expect(res.deleted.map((d) => d.rel)).toEqual(['system/ds/brand.css']);
827
- expect(hub.deletes).toEqual(['system/ds/brand.css']);
828
- });
829
-
830
- test('gone here, but CHANGED there ⇒ an edit beats a delete and the file comes back', async () => {
831
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
832
- const p = propagating(hub);
833
- await p.reconcile();
834
-
835
- rmSync(join(root, 'system/ds/brand.css'));
836
- hub.add('system/ds/brand.css', 'v2'); // somebody edited it meanwhile
837
-
838
- const res = await p.reconcile();
839
- expect(hub.deletes).toEqual([]);
840
- expect(read('system/ds/brand.css')).toBe('v2');
841
- expect(res.deleted).toEqual([]);
842
- });
843
-
844
- test('the hub deleted it and we never touched it ⇒ quarantined, never unlinked', async () => {
845
- const hub = fakeHub({ 'system/ds/brand.css': ':root{}' });
846
- const p = propagating(hub);
847
- await p.reconcile();
848
-
849
- hub.tombstone('system/ds/brand.css');
850
- const res = await p.reconcile();
851
-
852
- expect(existsSync(join(root, 'system/ds/brand.css'))).toBe(false);
853
- const parked = res.deleted[0]?.parked;
854
- expect(parked?.startsWith('_trash/')).toBe(true);
855
- expect(read(parked as string)).toBe(':root{}');
856
- });
857
-
858
- test('the hub deleted it but WE changed it ⇒ kept and pushed back', async () => {
859
- const hub = fakeHub({ 'system/ds/brand.css': 'v1' });
860
- const p = propagating(hub);
861
- await p.reconcile();
862
-
863
- write('system/ds/brand.css', 'mine');
864
- hub.tombstone('system/ds/brand.css');
865
-
866
- const res = await p.reconcile();
867
- expect(read('system/ds/brand.css')).toBe('mine');
868
- expect(res.deleted).toEqual([]);
869
- expect(hub.puts.some((x) => x.rel === 'system/ds/brand.css' && x.body === 'mine')).toBe(true);
870
- });
871
-
872
- test('off ⇒ an absence propagates nothing, which is the pre-Increment-6 posture', async () => {
873
- const hub = fakeHub({ 'system/ds/brand.css': ':root{}' });
874
- const p = plane(hub, { propagateDeletes: false });
875
- await p.reconcile();
876
- rmSync(join(root, 'system/ds/brand.css'));
877
- const res = await p.reconcile();
878
- expect(hub.deletes).toEqual([]);
879
- expect(res.deleted).toEqual([]);
880
- });
881
- });
882
-
883
- describe('the deletion breakers — the only protection now that this ships ON', () => {
884
- test("a branch switch does not become everyone else's deletion", async () => {
885
- const seeded: Record<string, string> = {};
886
- for (let i = 0; i < 20; i++) seeded[`system/ds/f${i}.css`] = `.a${i}{}`;
887
- const hub = fakeHub(seeded);
888
- const p = plane(hub, { propagateDeletes: true });
889
- await p.reconcile();
890
-
891
- // `git checkout other-branch` — the design folder empties.
892
- for (let i = 0; i < 20; i++) rmSync(join(root, `system/ds/f${i}.css`));
893
-
894
- const res = await p.reconcile();
895
- expect(hub.deletes).toEqual([]);
896
- expect(res.deleteHeld?.direction).toBe('out');
897
- expect(res.deleteHeld?.count).toBe(20);
898
- });
899
-
900
- test('a tombstone storm does not empty this disk either', async () => {
901
- const seeded: Record<string, string> = {};
902
- for (let i = 0; i < 20; i++) seeded[`system/ds/f${i}.css`] = `.a${i}{}`;
903
- const hub = fakeHub(seeded);
904
- const p = plane(hub, { propagateDeletes: true });
905
- await p.reconcile();
906
-
907
- for (let i = 0; i < 20; i++) hub.tombstone(`system/ds/f${i}.css`);
908
-
909
- const res = await p.reconcile();
910
- expect(res.deleteHeld?.direction).toBe('in');
911
- expect(existsSync(join(root, 'system/ds/f0.css'))).toBe(true);
912
- expect(res.deleted).toEqual([]);
913
- });
914
-
915
- test('a patient drain is caught too — the budget remembers across passes', async () => {
916
- // The finding this exists for: the first breaker counted ONE PASS and
917
- // reset. Two per pass was under every arm of it at every project size, so
918
- // a hub poking every 10s could remove a file every five seconds forever
919
- // and never trip anything. A rate limit is the wrong control for a
920
- // cumulative harm.
921
- const seeded: Record<string, string> = {};
922
- for (let i = 0; i < 60; i++) seeded[`system/ds/f${i}.css`] = `.a${i}{}`;
923
- const hub = fakeHub(seeded);
924
- const p = plane(hub, { propagateDeletes: true });
925
- await p.reconcile();
926
-
927
- let applied = 0;
928
- let held = false;
929
- // Two at a time — deliberately under the burst arm AND under the
930
- // proportion arm (2/60 is 3%), which is exactly the attacker's cadence.
931
- for (let round = 0; round < 20 && !held; round++) {
932
- hub.tombstone(`system/ds/f${round * 2}.css`);
933
- hub.tombstone(`system/ds/f${round * 2 + 1}.css`);
934
- const res = await p.reconcile();
935
- applied += res.deleted.length;
936
- if (res.deleteHeld) held = true;
937
- }
938
-
939
- expect(held).toBe(true);
940
- expect(applied).toBeLessThanOrEqual(DELETE_BUDGET_PER_WINDOW);
941
- });
942
-
943
- test('the budget survives a restart — a new plane over the same ledger still remembers', async () => {
944
- const seeded: Record<string, string> = {};
945
- for (let i = 0; i < 60; i++) seeded[`system/ds/f${i}.css`] = `.a${i}{}`;
946
- const hub = fakeHub(seeded);
947
- await plane(hub, { propagateDeletes: true }).reconcile();
948
-
949
- for (let round = 0; round < 20; round++) {
950
- hub.tombstone(`system/ds/f${round * 2}.css`);
951
- hub.tombstone(`system/ds/f${round * 2 + 1}.css`);
952
- // A FRESH plane each round, as a restarted dev-server would be. The
953
- // ledger is the same, and the budget lives there — otherwise "restart
954
- // the app" is the bypass.
955
- const res = await plane(hub, { propagateDeletes: true }).reconcile();
956
- if (res.deleteHeld) {
957
- expect(round).toBeGreaterThan(0);
958
- return;
959
- }
960
- }
961
- throw new Error('the budget did not survive being reconstructed');
962
- });
963
-
964
- test('an ordinary single delete is not a storm', async () => {
965
- const seeded: Record<string, string> = {};
966
- for (let i = 0; i < 20; i++) seeded[`system/ds/f${i}.css`] = `.a${i}{}`;
967
- const hub = fakeHub(seeded);
968
- const p = plane(hub, { propagateDeletes: true });
969
- await p.reconcile();
970
-
971
- rmSync(join(root, 'system/ds/f3.css'));
972
- const res = await p.reconcile();
973
- expect(res.deleteHeld).toBeUndefined();
974
- expect(hub.deletes).toEqual(['system/ds/f3.css']);
975
- });
976
- });