@1agh/maude 0.28.1 → 0.30.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 (372) hide show
  1. package/README.md +3 -3
  2. package/{plugins/design/dev-server → apps/studio}/ai-banner.tsx +1 -2
  3. package/apps/studio/annotations-align.ts +149 -0
  4. package/apps/studio/annotations-bindings.ts +197 -0
  5. package/{plugins/design/dev-server → apps/studio}/annotations-context-toolbar.tsx +681 -151
  6. package/apps/studio/annotations-groups.ts +270 -0
  7. package/apps/studio/annotations-layer.tsx +4537 -0
  8. package/apps/studio/annotations-model.ts +2077 -0
  9. package/apps/studio/annotations-snap.ts +125 -0
  10. package/{plugins/design/dev-server → apps/studio}/api.ts +616 -70
  11. package/{plugins/design/dev-server → apps/studio}/artboard-activity-overlay.tsx +1 -1
  12. package/{plugins/design/dev-server → apps/studio}/artboard-marquee.tsx +1 -1
  13. package/apps/studio/bin/_motion-sample-playwright.mjs +129 -0
  14. package/{plugins/design/dev-server → apps/studio}/bin/_png-playwright.mjs +1 -1
  15. package/apps/studio/bin/annotate.mjs +732 -0
  16. package/apps/studio/bin/annotate.sh +17 -0
  17. package/{plugins/design/dev-server → apps/studio}/bin/canvas-edit.sh +1 -1
  18. package/{plugins/design/dev-server → apps/studio}/bin/draw-proof.sh +37 -2
  19. package/{plugins/design/dev-server → apps/studio}/bin/preflight.sh +1 -1
  20. package/apps/studio/bin/read-annotations.mjs +573 -0
  21. package/apps/studio/bin/read-annotations.sh +11 -0
  22. package/{plugins/design/dev-server → apps/studio}/bin/runtime-health.sh +1 -1
  23. package/{plugins/design/dev-server → apps/studio}/bin/screenshot.sh +62 -2
  24. package/{plugins/design/dev-server → apps/studio}/bin/server-up.sh +9 -3
  25. package/apps/studio/bin/to-lottie-verify.html +68 -0
  26. package/apps/studio/bin/to-lottie.sh +128 -0
  27. package/{plugins/design/dev-server → apps/studio}/build.ts +6 -4
  28. package/{plugins/design/dev-server → apps/studio}/canvas-arrowheads.ts +79 -10
  29. package/{plugins/design/dev-server → apps/studio}/canvas-comment-mount.tsx +1 -1
  30. package/apps/studio/canvas-create.ts +104 -0
  31. package/{plugins/design/dev-server → apps/studio}/canvas-cursors.ts +48 -12
  32. package/{plugins/design/dev-server → apps/studio}/canvas-edit.ts +257 -7
  33. package/{plugins/design/dev-server → apps/studio}/canvas-icons.tsx +165 -1
  34. package/{plugins/design/dev-server → apps/studio}/canvas-lib-inline.ts +1 -1
  35. package/{plugins/design/dev-server → apps/studio}/canvas-lib-resolver.ts +1 -1
  36. package/{plugins/design/dev-server → apps/studio}/canvas-lib.tsx +31 -12
  37. package/{plugins/design/dev-server → apps/studio}/canvas-shell.tsx +360 -48
  38. package/apps/studio/client/app.jsx +6742 -0
  39. package/apps/studio/client/canvas-url.js +81 -0
  40. package/{plugins/design/dev-server → apps/studio}/client/comments-overlay.css +41 -27
  41. package/apps/studio/client/index.html +16 -0
  42. package/apps/studio/client/styles/1-tokens-maude.css +296 -0
  43. package/apps/studio/client/styles/3-shell-maude.css +1161 -0
  44. package/{plugins/design/dev-server → apps/studio}/client/styles/3-shell.css +129 -0
  45. package/apps/studio/client/styles/4-components-maude.css +74 -0
  46. package/{plugins/design/dev-server → apps/studio}/client/styles/4-components.css +396 -34
  47. package/apps/studio/client/styles/5-maude-overrides.css +137 -0
  48. package/{plugins/design/dev-server → apps/studio}/client/styles/_index.css +9 -0
  49. package/{plugins/design/dev-server → apps/studio}/client/styles.css +1 -1
  50. package/apps/studio/client/tour/overlay.jsx +279 -0
  51. package/apps/studio/client/tour/usage-tour.js +48 -0
  52. package/apps/studio/client/whats-new-seen.js +52 -0
  53. package/apps/studio/client/whats-new.jsx +250 -0
  54. package/{plugins/design/dev-server → apps/studio}/commands/annotation-strokes-command.ts +2 -2
  55. package/{plugins/design/dev-server → apps/studio}/commands/equal-spacing-command.ts +1 -1
  56. package/{plugins/design/dev-server → apps/studio}/commands/move-artboards-command.ts +2 -2
  57. package/{plugins/design/dev-server → apps/studio}/comments-overlay.tsx +32 -11
  58. package/{plugins/design/dev-server → apps/studio}/context-menu.tsx +5 -4
  59. package/{plugins/design/dev-server → apps/studio}/contextual-toolbar.tsx +18 -7
  60. package/{plugins/design/dev-server → apps/studio}/cursors-overlay.tsx +21 -21
  61. package/apps/studio/dist/client.bundle.js +25545 -0
  62. package/apps/studio/dist/comment-mount.js +2046 -0
  63. package/apps/studio/dist/styles.css +8018 -0
  64. package/apps/studio/dom-selection.ts +342 -0
  65. package/apps/studio/draw/animate.ts +333 -0
  66. package/{plugins/design/dev-server → apps/studio}/draw/brush.ts +1 -1
  67. package/{plugins/design/dev-server → apps/studio}/draw/composition.ts +1 -1
  68. package/{plugins/design/dev-server → apps/studio}/draw/geometry.ts +1 -1
  69. package/{plugins/design/dev-server → apps/studio}/draw/index.ts +4 -1
  70. package/{plugins/design/dev-server → apps/studio}/draw/layout.ts +1 -1
  71. package/apps/studio/draw/morph.ts +204 -0
  72. package/{plugins/design/dev-server → apps/studio}/draw/optimize.ts +1 -1
  73. package/{plugins/design/dev-server → apps/studio}/draw/palette.ts +1 -1
  74. package/{plugins/design/dev-server → apps/studio}/draw/primitives.ts +1 -1
  75. package/apps/studio/draw/serialize-animate.ts +324 -0
  76. package/{plugins/design/dev-server → apps/studio}/draw/serialize.ts +9 -3
  77. package/apps/studio/draw/test/animate.test.ts +172 -0
  78. package/apps/studio/draw/test/morph.test.ts +107 -0
  79. package/apps/studio/draw/test/serialize-animate.test.ts +142 -0
  80. package/{plugins/design/dev-server → apps/studio}/equal-spacing-detector.ts +1 -1
  81. package/{plugins/design/dev-server → apps/studio}/equal-spacing-handles.tsx +7 -29
  82. package/{plugins/design/dev-server → apps/studio}/export-dialog.tsx +16 -4
  83. package/{plugins/design/dev-server → apps/studio}/history.ts +20 -3
  84. package/{plugins/design/dev-server → apps/studio}/http.ts +226 -6
  85. package/{plugins/design/dev-server → apps/studio}/input-router.tsx +15 -1
  86. package/{plugins/design/dev-server → apps/studio}/inspect.ts +50 -4
  87. package/{plugins/design/dev-server → apps/studio}/marquee-overlay.tsx +5 -2
  88. package/{plugins/design/dev-server → apps/studio}/participants-chrome.tsx +2 -8
  89. package/{plugins/design/dev-server → apps/studio}/paths.ts +15 -11
  90. package/{plugins/design/dev-server → apps/studio}/server.ts +23 -2
  91. package/{plugins/design/dev-server → apps/studio}/sync/agent.ts +231 -57
  92. package/{plugins/design/dev-server → apps/studio}/sync/codec.ts +45 -0
  93. package/apps/studio/sync/cold-start.ts +158 -0
  94. package/{plugins/design/dev-server → apps/studio}/sync/connection-state.ts +58 -2
  95. package/{plugins/design/dev-server → apps/studio}/sync/index.ts +563 -221
  96. package/apps/studio/sync/journal.ts +190 -0
  97. package/apps/studio/sync/migrate-seed.ts +321 -0
  98. package/{plugins/design/dev-server → apps/studio}/sync/projection.ts +22 -3
  99. package/{plugins/design/dev-server → apps/studio}/sync/status.ts +15 -4
  100. package/{plugins/design/dev-server → apps/studio}/test/activity.test.ts +1 -7
  101. package/apps/studio/test/annotate-write.test.ts +184 -0
  102. package/apps/studio/test/annotations-align.test.ts +88 -0
  103. package/apps/studio/test/annotations-bindings.test.ts +124 -0
  104. package/apps/studio/test/annotations-groups.test.ts +231 -0
  105. package/{plugins/design/dev-server → apps/studio}/test/annotations-layer.test.ts +63 -0
  106. package/{plugins/design/dev-server → apps/studio}/test/annotations-roundtrip.test.ts +97 -0
  107. package/apps/studio/test/annotations-snap.test.ts +79 -0
  108. package/apps/studio/test/annotations-text-format.test.ts +396 -0
  109. package/apps/studio/test/asset-api.test.ts +149 -0
  110. package/apps/studio/test/canvas-create-api.test.ts +361 -0
  111. package/{plugins/design/dev-server → apps/studio}/test/canvas-cursors.test.ts +2 -0
  112. package/apps/studio/test/canvas-edit.test.ts +319 -0
  113. package/{plugins/design/dev-server → apps/studio}/test/canvas-lib-resolver.test.ts +1 -1
  114. package/apps/studio/test/canvas-media-drop.test.ts +158 -0
  115. package/{plugins/design/dev-server → apps/studio}/test/canvas-origin-gate.test.ts +25 -1
  116. package/apps/studio/test/canvas-url.test.ts +99 -0
  117. package/{plugins/design/dev-server → apps/studio}/test/collab-bridge.test.ts +0 -2
  118. package/{plugins/design/dev-server → apps/studio}/test/collab-room.test.ts +2 -7
  119. package/{plugins/design/dev-server → apps/studio}/test/csp-canvas-shell.test.ts +5 -0
  120. package/apps/studio/test/csrf-write-guard.test.ts +52 -0
  121. package/apps/studio/test/figjam-v3-model.test.ts +342 -0
  122. package/apps/studio/test/fixtures/figjam-v3-groups-bindings.svg +1 -0
  123. package/apps/studio/test/index-data-canvas-ds.test.ts +97 -0
  124. package/apps/studio/test/motion-sample.test.ts +35 -0
  125. package/{plugins/design/dev-server → apps/studio}/test/perf-harness.ts +1 -1
  126. package/{plugins/design/dev-server → apps/studio}/test/phase-3.6-smoke.test.ts +3 -1
  127. package/apps/studio/test/read-annotations.test.ts +409 -0
  128. package/{plugins/design/dev-server → apps/studio}/test/sanitize-annotation-svg.test.ts +108 -2
  129. package/{plugins/design/dev-server → apps/studio}/test/shared-doc-convergence.test.ts +1 -1
  130. package/apps/studio/test/shared-doc-migrate.test.ts +369 -0
  131. package/apps/studio/test/sync-agent.test.ts +575 -0
  132. package/{plugins/design/dev-server → apps/studio}/test/sync-codec.test.ts +65 -0
  133. package/apps/studio/test/sync-cold-start.test.ts +244 -0
  134. package/{plugins/design/dev-server → apps/studio}/test/sync-connection-state.test.ts +68 -0
  135. package/{plugins/design/dev-server → apps/studio}/test/sync-hardening.test.ts +0 -8
  136. package/{plugins/design/dev-server → apps/studio}/test/sync-hubs-config.test.ts +0 -1
  137. package/apps/studio/test/sync-incident-replay.test.ts +211 -0
  138. package/apps/studio/test/sync-journal.test.ts +176 -0
  139. package/{plugins/design/dev-server → apps/studio}/test/sync-runtime.test.ts +360 -5
  140. package/{plugins/design/dev-server → apps/studio}/test/sync-status.test.ts +66 -0
  141. package/apps/studio/test/tour-overlay.test.tsx +56 -0
  142. package/apps/studio/test/use-annotation-resize.test.ts +402 -0
  143. package/{plugins/design/dev-server → apps/studio}/test/use-artboard-drag.test.ts +0 -1
  144. package/{plugins/design/dev-server → apps/studio}/test/use-collab.test.ts +0 -0
  145. package/{plugins/design/dev-server → apps/studio}/test/use-tool-mode.test.tsx +8 -2
  146. package/apps/studio/test/whats-new.test.ts +101 -0
  147. package/apps/studio/text-imports.d.ts +9 -0
  148. package/{plugins/design/dev-server → apps/studio}/tool-palette.tsx +15 -70
  149. package/{plugins/design/dev-server → apps/studio}/undo-hud.tsx +1 -2
  150. package/{plugins/design/dev-server → apps/studio}/undo-stack.ts +1 -1
  151. package/{plugins/design/dev-server → apps/studio}/use-agent-presence.tsx +5 -3
  152. package/apps/studio/use-annotation-resize.tsx +912 -0
  153. package/{plugins/design/dev-server → apps/studio}/use-annotation-selection.tsx +17 -5
  154. package/{plugins/design/dev-server → apps/studio}/use-annotations-visibility.tsx +1 -1
  155. package/{plugins/design/dev-server → apps/studio}/use-artboard-drag.tsx +1 -1
  156. package/{plugins/design/dev-server → apps/studio}/use-canvas-activity.tsx +3 -3
  157. package/apps/studio/use-canvas-media-drop.tsx +343 -0
  158. package/{plugins/design/dev-server → apps/studio}/use-collab.tsx +21 -16
  159. package/{plugins/design/dev-server → apps/studio}/use-cursor-modifiers.tsx +1 -1
  160. package/{plugins/design/dev-server → apps/studio}/use-keyboard-discipline.tsx +5 -2
  161. package/{plugins/design/dev-server → apps/studio}/use-selection-set.tsx +18 -1
  162. package/{plugins/design/dev-server → apps/studio}/use-snap-guides.tsx +1 -1
  163. package/{plugins/design/dev-server → apps/studio}/use-tool-mode.tsx +8 -2
  164. package/{plugins/design/dev-server → apps/studio}/use-undo-stack.tsx +1 -1
  165. package/apps/studio/whats-new.json +264 -0
  166. package/apps/studio/whats-new.schema.json +86 -0
  167. package/apps/studio/whats-new.ts +87 -0
  168. package/cli/bin/maude.mjs +10 -0
  169. package/cli/commands/design-link.test.mjs +84 -0
  170. package/cli/commands/design.mjs +16 -7
  171. package/cli/commands/design.test.mjs +40 -0
  172. package/cli/commands/help.mjs +8 -2
  173. package/cli/commands/hub.mjs +3 -3
  174. package/cli/commands/hub.test.mjs +1 -1
  175. package/cli/commands/scenario-report.mjs +2 -9
  176. package/cli/lib/design-link.mjs +51 -1
  177. package/cli/lib/flow-design-integration.test.mjs +1 -1
  178. package/cli/lib/gitignore-block.mjs +1 -0
  179. package/cli/lib/plugin-cli-reachability.test.mjs +8 -7
  180. package/cli/lib/preflight.mjs +1 -1
  181. package/package.json +15 -15
  182. package/plugins/design/templates/_shell.html +28 -4
  183. package/plugins/design/templates/brief-board.tsx.template +61 -0
  184. package/plugins/design/templates/canvas.tsx.template +1 -1
  185. package/plugins/design/templates/design-system-inspiration/core/config.json.tpl +1 -1
  186. package/plugins/design/templates/design-system-inspiration/core/preview/_motion-readme.md.tpl +1 -1
  187. package/plugins/flow/.claude-plugin/config.schema.json +16 -0
  188. package/plugins/design/dev-server/annotations-layer.tsx +0 -3402
  189. package/plugins/design/dev-server/client/app.jsx +0 -2985
  190. package/plugins/design/dev-server/client/index.html +0 -15
  191. package/plugins/design/dev-server/dist/client.bundle.js +0 -20692
  192. package/plugins/design/dev-server/dist/comment-mount.js +0 -1924
  193. package/plugins/design/dev-server/dist/styles.css +0 -2710
  194. package/plugins/design/dev-server/dom-selection.ts +0 -156
  195. package/plugins/design/dev-server/sync/migrate-seed.ts +0 -163
  196. package/plugins/design/dev-server/test/canvas-edit.test.ts +0 -139
  197. package/plugins/design/dev-server/test/shared-doc-migrate.test.ts +0 -159
  198. package/plugins/design/dev-server/test/sync-agent.test.ts +0 -305
  199. package/plugins/design/dev-server/test/use-annotation-resize.test.ts +0 -200
  200. package/plugins/design/dev-server/use-annotation-resize.tsx +0 -449
  201. /package/{plugins/design/dev-server → apps/studio}/activity.ts +0 -0
  202. /package/{plugins/design/dev-server → apps/studio}/bin/_enumerate-artboards-playwright.mjs +0 -0
  203. /package/{plugins/design/dev-server → apps/studio}/bin/_html-playwright.mjs +0 -0
  204. /package/{plugins/design/dev-server → apps/studio}/bin/_pdf-playwright.mjs +0 -0
  205. /package/{plugins/design/dev-server → apps/studio}/bin/_pptx-playwright.mjs +0 -0
  206. /package/{plugins/design/dev-server → apps/studio}/bin/_pw-launch.mjs +0 -0
  207. /package/{plugins/design/dev-server → apps/studio}/bin/_screenshot-playwright.mjs +0 -0
  208. /package/{plugins/design/dev-server → apps/studio}/bin/_svg-optimize.mjs +0 -0
  209. /package/{plugins/design/dev-server → apps/studio}/bin/_svg-playwright.mjs +0 -0
  210. /package/{plugins/design/dev-server → apps/studio}/bin/asset-sweep.sh +0 -0
  211. /package/{plugins/design/dev-server → apps/studio}/bin/bootstrap-check.sh +0 -0
  212. /package/{plugins/design/dev-server → apps/studio}/bin/check-runtime-bundles.sh +0 -0
  213. /package/{plugins/design/dev-server → apps/studio}/bin/draw-build.sh +0 -0
  214. /package/{plugins/design/dev-server → apps/studio}/bin/handoff.sh +0 -0
  215. /package/{plugins/design/dev-server → apps/studio}/bin/prep.sh +0 -0
  216. /package/{plugins/design/dev-server → apps/studio}/bin/scenario-report.mjs +0 -0
  217. /package/{plugins/design/dev-server → apps/studio}/bin/slug.sh +0 -0
  218. /package/{plugins/design/dev-server → apps/studio}/bin/smoke.sh +0 -0
  219. /package/{plugins/design/dev-server → apps/studio}/bin/svg-optimize.sh +0 -0
  220. /package/{plugins/design/dev-server → apps/studio}/bin/visual-sanity.sh +0 -0
  221. /package/{plugins/design/dev-server → apps/studio}/boot-self-heal.ts +0 -0
  222. /package/{plugins/design/dev-server → apps/studio}/canvas-build.ts +0 -0
  223. /package/{plugins/design/dev-server → apps/studio}/canvas-header.ts +0 -0
  224. /package/{plugins/design/dev-server → apps/studio}/canvas-meta.schema.json +0 -0
  225. /package/{plugins/design/dev-server → apps/studio}/canvas-pipeline.ts +0 -0
  226. /package/{plugins/design/dev-server → apps/studio}/client/hmr.mjs +0 -0
  227. /package/{plugins/design/dev-server → apps/studio}/client/iframe-lazy.mjs +0 -0
  228. /package/{plugins/design/dev-server → apps/studio}/client/styles/0-reset.css +0 -0
  229. /package/{plugins/design/dev-server → apps/studio}/client/styles/1-tokens.css +0 -0
  230. /package/{plugins/design/dev-server → apps/studio}/client/styles/2-layout.css +0 -0
  231. /package/{plugins/design/dev-server → apps/studio}/client/styles/5-utilities.css +0 -0
  232. /package/{plugins/design/dev-server → apps/studio}/collab/ai-activity.ts +0 -0
  233. /package/{plugins/design/dev-server → apps/studio}/collab/awareness-bridge.ts +0 -0
  234. /package/{plugins/design/dev-server → apps/studio}/collab/git-lifecycle.ts +0 -0
  235. /package/{plugins/design/dev-server → apps/studio}/collab/index.ts +0 -0
  236. /package/{plugins/design/dev-server → apps/studio}/collab/persistence.ts +0 -0
  237. /package/{plugins/design/dev-server → apps/studio}/collab/protocol.ts +0 -0
  238. /package/{plugins/design/dev-server → apps/studio}/collab/registry.ts +0 -0
  239. /package/{plugins/design/dev-server → apps/studio}/collab/room.ts +0 -0
  240. /package/{plugins/design/dev-server → apps/studio}/config.schema.json +0 -0
  241. /package/{plugins/design/dev-server → apps/studio}/context.ts +0 -0
  242. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/.min-sizes.json +0 -0
  243. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/lib0_decoding.js +0 -0
  244. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/lib0_encoding.js +0 -0
  245. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/motion.js +0 -0
  246. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/motion_react.js +0 -0
  247. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/pixi-js.js +0 -0
  248. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react-dom.js +0 -0
  249. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react-dom_client.js +0 -0
  250. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react.js +0 -0
  251. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react_jsx-dev-runtime.js +0 -0
  252. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react_jsx-runtime.js +0 -0
  253. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/y-protocols_awareness.js +0 -0
  254. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/y-protocols_sync.js +0 -0
  255. /package/{plugins/design/dev-server → apps/studio}/dist/runtime/yjs.js +0 -0
  256. /package/{plugins/design/dev-server → apps/studio}/draw/test/brush.test.ts +0 -0
  257. /package/{plugins/design/dev-server → apps/studio}/draw/test/composition.test.ts +0 -0
  258. /package/{plugins/design/dev-server → apps/studio}/draw/test/geometry.test.ts +0 -0
  259. /package/{plugins/design/dev-server → apps/studio}/draw/test/gradient.test.ts +0 -0
  260. /package/{plugins/design/dev-server → apps/studio}/draw/test/layout.test.ts +0 -0
  261. /package/{plugins/design/dev-server → apps/studio}/draw/test/optimize.test.ts +0 -0
  262. /package/{plugins/design/dev-server → apps/studio}/draw/test/palette.test.ts +0 -0
  263. /package/{plugins/design/dev-server → apps/studio}/draw/test/primitives.test.ts +0 -0
  264. /package/{plugins/design/dev-server → apps/studio}/draw/test/serialize.test.ts +0 -0
  265. /package/{plugins/design/dev-server → apps/studio}/examples/README.md +0 -0
  266. /package/{plugins/design/dev-server → apps/studio}/examples/perf-100-artboards.tsx +0 -0
  267. /package/{plugins/design/dev-server → apps/studio}/exporters/_browser-bundles.ts +0 -0
  268. /package/{plugins/design/dev-server → apps/studio}/exporters/canva-handoff-prompt.ts +0 -0
  269. /package/{plugins/design/dev-server → apps/studio}/exporters/canva.ts +0 -0
  270. /package/{plugins/design/dev-server → apps/studio}/exporters/html.ts +0 -0
  271. /package/{plugins/design/dev-server → apps/studio}/exporters/index.ts +0 -0
  272. /package/{plugins/design/dev-server → apps/studio}/exporters/pdf.ts +0 -0
  273. /package/{plugins/design/dev-server → apps/studio}/exporters/png.ts +0 -0
  274. /package/{plugins/design/dev-server → apps/studio}/exporters/pptx.ts +0 -0
  275. /package/{plugins/design/dev-server → apps/studio}/exporters/scope.ts +0 -0
  276. /package/{plugins/design/dev-server → apps/studio}/exporters/svg.ts +0 -0
  277. /package/{plugins/design/dev-server → apps/studio}/exporters/zip.ts +0 -0
  278. /package/{plugins/design/dev-server → apps/studio}/fs-watch.ts +0 -0
  279. /package/{plugins/design/dev-server → apps/studio}/handoff.ts +0 -0
  280. /package/{plugins/design/dev-server → apps/studio}/hmr-broadcast.ts +0 -0
  281. /package/{plugins/design/dev-server → apps/studio}/locator.ts +0 -0
  282. /package/{plugins/design/dev-server → apps/studio}/mem.ts +0 -0
  283. /package/{plugins/design/dev-server → apps/studio}/runtime-bundle.ts +0 -0
  284. /package/{plugins/design/dev-server → apps/studio}/server.mjs +0 -0
  285. /package/{plugins/design/dev-server → apps/studio}/sync/atomic-write.ts +0 -0
  286. /package/{plugins/design/dev-server → apps/studio}/sync/echo-guard.ts +0 -0
  287. /package/{plugins/design/dev-server → apps/studio}/sync/fs-mirror.ts +0 -0
  288. /package/{plugins/design/dev-server → apps/studio}/sync/hubs-config.ts +0 -0
  289. /package/{plugins/design/dev-server → apps/studio}/sync/materialize.ts +0 -0
  290. /package/{plugins/design/dev-server → apps/studio}/sync/origins.ts +0 -0
  291. /package/{plugins/design/dev-server → apps/studio}/sync/untrusted.ts +0 -0
  292. /package/{plugins/design/dev-server → apps/studio}/test/_helpers.ts +0 -0
  293. /package/{plugins/design/dev-server → apps/studio}/test/active-state.test.ts +0 -0
  294. /package/{plugins/design/dev-server → apps/studio}/test/ai-activity.test.ts +0 -0
  295. /package/{plugins/design/dev-server → apps/studio}/test/annotation-strokes-command.test.ts +0 -0
  296. /package/{plugins/design/dev-server → apps/studio}/test/annotations-api.test.ts +0 -0
  297. /package/{plugins/design/dev-server → apps/studio}/test/annotations-draw-modifiers.test.ts +0 -0
  298. /package/{plugins/design/dev-server → apps/studio}/test/artboard-activity-overlay.test.tsx +0 -0
  299. /package/{plugins/design/dev-server → apps/studio}/test/binary-smoke.test.ts +0 -0
  300. /package/{plugins/design/dev-server → apps/studio}/test/boot-self-heal.test.ts +0 -0
  301. /package/{plugins/design/dev-server → apps/studio}/test/bundle-smoke.test.ts +0 -0
  302. /package/{plugins/design/dev-server → apps/studio}/test/canvas-build.test.ts +0 -0
  303. /package/{plugins/design/dev-server → apps/studio}/test/canvas-header.test.ts +0 -0
  304. /package/{plugins/design/dev-server → apps/studio}/test/canvas-hmr-runtime.test.tsx +0 -0
  305. /package/{plugins/design/dev-server → apps/studio}/test/canvas-lib-inline.test.ts +0 -0
  306. /package/{plugins/design/dev-server → apps/studio}/test/canvas-lib-motion.test.ts +0 -0
  307. /package/{plugins/design/dev-server → apps/studio}/test/canvas-meta-api.test.ts +0 -0
  308. /package/{plugins/design/dev-server → apps/studio}/test/canvas-pipeline.test.ts +0 -0
  309. /package/{plugins/design/dev-server → apps/studio}/test/canvas-route.test.ts +0 -0
  310. /package/{plugins/design/dev-server → apps/studio}/test/collab-annotations-bridge.test.ts +0 -0
  311. /package/{plugins/design/dev-server → apps/studio}/test/collab-awareness-bridge.test.ts +0 -0
  312. /package/{plugins/design/dev-server → apps/studio}/test/collab-loopback.test.ts +0 -0
  313. /package/{plugins/design/dev-server → apps/studio}/test/collab-protocol.test.ts +0 -0
  314. /package/{plugins/design/dev-server → apps/studio}/test/collab-reseed-guard.test.ts +0 -0
  315. /package/{plugins/design/dev-server → apps/studio}/test/collab-stress.test.ts +0 -0
  316. /package/{plugins/design/dev-server → apps/studio}/test/comment-mount.test.ts +0 -0
  317. /package/{plugins/design/dev-server → apps/studio}/test/comments-api.test.ts +0 -0
  318. /package/{plugins/design/dev-server → apps/studio}/test/compile-entry.test.ts +0 -0
  319. /package/{plugins/design/dev-server → apps/studio}/test/context-resolve-tokens.test.ts +0 -0
  320. /package/{plugins/design/dev-server → apps/studio}/test/equal-spacing-detector.test.ts +0 -0
  321. /package/{plugins/design/dev-server → apps/studio}/test/exporters/canva.test.ts +0 -0
  322. /package/{plugins/design/dev-server → apps/studio}/test/exporters/endpoint.test.ts +0 -0
  323. /package/{plugins/design/dev-server → apps/studio}/test/exporters/history.test.ts +0 -0
  324. /package/{plugins/design/dev-server → apps/studio}/test/exporters/html.test.ts +0 -0
  325. /package/{plugins/design/dev-server → apps/studio}/test/exporters/pdf.test.ts +0 -0
  326. /package/{plugins/design/dev-server → apps/studio}/test/exporters/png.test.ts +0 -0
  327. /package/{plugins/design/dev-server → apps/studio}/test/exporters/pptx-deck.test.ts +0 -0
  328. /package/{plugins/design/dev-server → apps/studio}/test/exporters/pptx.test.ts +0 -0
  329. /package/{plugins/design/dev-server → apps/studio}/test/exporters/pw-launch.test.ts +0 -0
  330. /package/{plugins/design/dev-server → apps/studio}/test/exporters/scope.test.ts +0 -0
  331. /package/{plugins/design/dev-server → apps/studio}/test/exporters/svg.test.ts +0 -0
  332. /package/{plugins/design/dev-server → apps/studio}/test/exporters/zip.test.ts +0 -0
  333. /package/{plugins/design/dev-server → apps/studio}/test/fixtures/phase-20-annotations.svg +0 -0
  334. /package/{plugins/design/dev-server → apps/studio}/test/fixtures/phase-21-annotations.svg +0 -0
  335. /package/{plugins/design/dev-server → apps/studio}/test/fs-watch.test.ts +0 -0
  336. /package/{plugins/design/dev-server → apps/studio}/test/git-lifecycle.test.ts +0 -0
  337. /package/{plugins/design/dev-server → apps/studio}/test/handoff-static-frames.test.ts +0 -0
  338. /package/{plugins/design/dev-server → apps/studio}/test/handoff.test.ts +0 -0
  339. /package/{plugins/design/dev-server → apps/studio}/test/history-rollback.test.ts +0 -0
  340. /package/{plugins/design/dev-server → apps/studio}/test/hmr-broadcast.test.ts +0 -0
  341. /package/{plugins/design/dev-server → apps/studio}/test/hmr-classify.test.ts +0 -0
  342. /package/{plugins/design/dev-server → apps/studio}/test/input-router.test.ts +0 -0
  343. /package/{plugins/design/dev-server → apps/studio}/test/locator.test.ts +0 -0
  344. /package/{plugins/design/dev-server → apps/studio}/test/marquee-overlay.test.ts +0 -0
  345. /package/{plugins/design/dev-server → apps/studio}/test/move-artboards-command.test.ts +0 -0
  346. /package/{plugins/design/dev-server → apps/studio}/test/participants-chrome.test.ts +0 -0
  347. /package/{plugins/design/dev-server → apps/studio}/test/paths.test.ts +0 -0
  348. /package/{plugins/design/dev-server → apps/studio}/test/runtime-bundle-error-mapping.test.ts +0 -0
  349. /package/{plugins/design/dev-server → apps/studio}/test/runtime-bundle.test.ts +0 -0
  350. /package/{plugins/design/dev-server → apps/studio}/test/server-lifecycle.test.ts +0 -0
  351. /package/{plugins/design/dev-server → apps/studio}/test/shared-doc-foundation.test.ts +0 -0
  352. /package/{plugins/design/dev-server → apps/studio}/test/shared-doc-projection.test.ts +0 -0
  353. /package/{plugins/design/dev-server → apps/studio}/test/snap-distance-pill.test.ts +0 -0
  354. /package/{plugins/design/dev-server → apps/studio}/test/sync-atomic-write.test.ts +0 -0
  355. /package/{plugins/design/dev-server → apps/studio}/test/sync-echo-guard.test.ts +0 -0
  356. /package/{plugins/design/dev-server → apps/studio}/test/sync-fs-mirror.test.ts +0 -0
  357. /package/{plugins/design/dev-server → apps/studio}/test/sync-meta-codec.test.ts +0 -0
  358. /package/{plugins/design/dev-server → apps/studio}/test/sync-untrusted.test.ts +0 -0
  359. /package/{plugins/design/dev-server → apps/studio}/test/system-endpoint.test.ts +0 -0
  360. /package/{plugins/design/dev-server → apps/studio}/test/tool-palette.test.tsx +0 -0
  361. /package/{plugins/design/dev-server → apps/studio}/test/undo-stack.test.ts +0 -0
  362. /package/{plugins/design/dev-server → apps/studio}/test/use-agent-presence.test.tsx +0 -0
  363. /package/{plugins/design/dev-server → apps/studio}/test/use-annotation-selection.test.tsx +0 -0
  364. /package/{plugins/design/dev-server → apps/studio}/test/use-canvas-activity.test.tsx +0 -0
  365. /package/{plugins/design/dev-server → apps/studio}/test/use-cursor-modifiers.test.ts +0 -0
  366. /package/{plugins/design/dev-server → apps/studio}/test/use-keyboard-discipline.test.ts +0 -0
  367. /package/{plugins/design/dev-server → apps/studio}/test/use-selection-set.test.tsx +0 -0
  368. /package/{plugins/design/dev-server → apps/studio}/test/use-snap-guides.test.ts +0 -0
  369. /package/{plugins/design/dev-server → apps/studio}/test/use-undo-stack.test.tsx +0 -0
  370. /package/{plugins/design/dev-server → apps/studio}/test/ws-handshake.test.ts +0 -0
  371. /package/{plugins/design/dev-server → apps/studio}/tsconfig.json +0 -0
  372. /package/{plugins/design/dev-server → apps/studio}/ws.ts +0 -0
@@ -0,0 +1,369 @@
1
+ // Phase 9.2 (DDR-064) Phase E — the one-time authoritative seed (Task 9).
2
+ //
3
+ // Pins the fix for Risk 1, the duplication-on-merge trap: a shared doc must be
4
+ // populated from ONE source. These tests prove migrateSeed never duplicates
5
+ // comments and is idempotent across re-runs (server restarts).
6
+
7
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
8
+ import { mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
9
+ import { tmpdir } from 'node:os';
10
+ import { join } from 'node:path';
11
+ import * as Y from 'yjs';
12
+
13
+ import { createPersistence, Y_TYPES } from '../collab/persistence.ts';
14
+ import type { Context } from '../context.ts';
15
+ import { applyCommentsToDoc, applyCssToDoc, applyHtmlToDoc } from '../sync/codec.ts';
16
+ import { hashBytes } from '../sync/echo-guard.ts';
17
+ import { docIsEmpty, migrateSeed } from '../sync/migrate-seed.ts';
18
+
19
+ let dir: string;
20
+ beforeEach(() => {
21
+ dir = mkdtempSync(join(tmpdir(), 'migrate-seed-'));
22
+ });
23
+ afterEach(() => {
24
+ rmSync(dir, { recursive: true, force: true });
25
+ });
26
+
27
+ function paths() {
28
+ return {
29
+ html: join(dir, 'screen.html'),
30
+ comments: join(dir, 'screen.comments.json'),
31
+ annotations: join(dir, 'screen.annotations.svg'),
32
+ meta: join(dir, 'screen.meta.json'),
33
+ css: join(dir, 'screen.css'),
34
+ };
35
+ }
36
+
37
+ describe('docIsEmpty', () => {
38
+ test('true for a fresh doc, false once any type is populated', () => {
39
+ const doc = new Y.Doc();
40
+ expect(docIsEmpty(doc)).toBe(true);
41
+ doc.getArray(Y_TYPES.comments).push([{ id: 'c1' }]);
42
+ expect(docIsEmpty(doc)).toBe(false);
43
+ });
44
+ });
45
+
46
+ describe('migrateSeed — adopt (hub was empty)', () => {
47
+ test('seeds an empty doc from local files and reports local-adopt', async () => {
48
+ const p = paths();
49
+ writeFileSync(p.html, '<main>local body</main>');
50
+ writeFileSync(p.comments, JSON.stringify([{ id: 'c1', text: 'local' }]));
51
+
52
+ const doc = new Y.Doc();
53
+ const result = await migrateSeed({ slug: 's', doc, paths: p });
54
+
55
+ expect(result).toBe('local-adopt');
56
+ expect(doc.getText('html').toString()).toBe('<main>local body</main>');
57
+ expect(doc.getArray(Y_TYPES.comments).toArray()).toEqual([{ id: 'c1', text: 'local' }]);
58
+ });
59
+
60
+ test('empty doc + no local files → "empty" (nothing to seed)', async () => {
61
+ const doc = new Y.Doc();
62
+ expect(await migrateSeed({ slug: 's', doc, paths: paths() })).toBe('empty');
63
+ expect(docIsEmpty(doc)).toBe(true);
64
+ });
65
+ });
66
+
67
+ describe('migrateSeed — idempotent (no duplication on re-run)', () => {
68
+ test('adopting twice leaves comments un-duplicated', async () => {
69
+ const p = paths();
70
+ writeFileSync(
71
+ p.comments,
72
+ JSON.stringify([
73
+ { id: 'c1', text: 'x' },
74
+ { id: 'c2', text: 'y' },
75
+ ])
76
+ );
77
+
78
+ const doc = new Y.Doc();
79
+ expect(await migrateSeed({ slug: 's', doc, paths: p })).toBe('local-adopt');
80
+ expect(doc.getArray(Y_TYPES.comments).length).toBe(2);
81
+
82
+ // Second run (e.g. server restart): the doc is now non-empty → hub-wins
83
+ // branch → no re-adopt → still exactly 2 comments, byte-identical.
84
+ expect(await migrateSeed({ slug: 's', doc, paths: p })).toBe('hub-wins');
85
+ expect(doc.getArray(Y_TYPES.comments).toArray()).toEqual([
86
+ { id: 'c1', text: 'x' },
87
+ { id: 'c2', text: 'y' },
88
+ ]);
89
+ });
90
+ });
91
+
92
+ describe('room file-seed disable (the other half of the Risk-1 fix)', () => {
93
+ test('persistence.seed is a no-op for a pinned slug — never touches api or the doc', async () => {
94
+ let apiCalled = false;
95
+ // Minimal api stub; seed must short-circuit before reaching it.
96
+ const api = {
97
+ loadCommentsForFile: async () => {
98
+ apiCalled = true;
99
+ return [];
100
+ },
101
+ loadAnnotations: async () => {
102
+ apiCalled = true;
103
+ return null;
104
+ },
105
+ } as unknown as import('../api.ts').Api;
106
+ const ctx = { paths: { designRoot: dir } } as unknown as Context;
107
+
108
+ const persistence = createPersistence({
109
+ ctx,
110
+ api,
111
+ fileForSlug: async () => 'ui/x.html',
112
+ // Mirrors createCollab's predicate: don't seed a pinned (provider-attached)
113
+ // slug under sharedDoc — the migrate-seed + provider own population.
114
+ shouldSeed: (slug) => slug !== 'pinned',
115
+ });
116
+
117
+ const doc = new Y.Doc();
118
+ await persistence.seed('pinned', doc);
119
+ // Returned before touching the api or mutating the doc → no duplicate items
120
+ // can be introduced by the file-seed after the migrate-seed ran.
121
+ expect(apiCalled).toBe(false);
122
+ expect(docIsEmpty(doc)).toBe(true);
123
+ });
124
+ });
125
+
126
+ describe('migrateSeed — hub-wins (the duplication trap avoided)', () => {
127
+ test('a doc already holding hub comments is NOT merged with the local file → no dup', async () => {
128
+ const p = paths();
129
+ // Local file (e.g. copied via git) holds the SAME logical comment id…
130
+ writeFileSync(p.comments, JSON.stringify([{ id: 'c1', text: 'from disk' }]));
131
+
132
+ // …but the doc already received it from the hub (a DIFFERENT CRDT item).
133
+ const doc = new Y.Doc();
134
+ applyCommentsToDoc(doc, [{ id: 'c1', text: 'from hub' }], 'hub');
135
+
136
+ const result = await migrateSeed({ slug: 's', doc, paths: p });
137
+
138
+ // Hub wins; the local file is NOT pushed as a second item — exactly ONE c1
139
+ // (DDR-102 id-union keeps the doc's version for a shared id).
140
+ expect(result).toBe('hub-wins');
141
+ expect(doc.getArray(Y_TYPES.comments).toArray()).toEqual([{ id: 'c1', text: 'from hub' }]);
142
+ });
143
+
144
+ test('snapshots divergent local files to historyDir before the hub-wins overwrite', async () => {
145
+ const p = paths();
146
+ writeFileSync(p.html, '<main>LOCAL divergent</main>');
147
+ writeFileSync(p.comments, JSON.stringify([{ id: 'local' }]));
148
+
149
+ const doc = new Y.Doc();
150
+ applyHtmlToDoc(doc, '<main>HUB</main>', 'hub'); // doc holds hub state
151
+
152
+ const historyDir = join(dir, '_history', 's');
153
+ // DDR-102: this divergence (no journal, no doc stamp) resolves
154
+ // conflict-hub-wins — the legacy whole-set safety copy still happens.
155
+ const result = await migrateSeed({ slug: 's', doc, paths: p, historyDir });
156
+
157
+ expect(result).toBe('conflict-hub-wins');
158
+ // The pre-migration snapshot captured the local files for rollback.
159
+ const snapped = readdirSync(join(historyDir, 'pre-shared-doc-migration'));
160
+ expect(snapped).toContain('screen.html');
161
+ expect(snapped).toContain('screen.comments.json');
162
+ });
163
+ });
164
+
165
+ // ---------------------------------------------------------------------------
166
+ // DDR-102 — the shared-doc path consumes the same cold-start decision table:
167
+ // journal-gated fast-forward, dual snapshot + newest-wins on divergence,
168
+ // comments id-union.
169
+ describe('migrateSeed — DDR-102 divergence matrix', () => {
170
+ function makeJournal(initial: Record<string, { bodyHash: string }> = {}) {
171
+ const entries = new Map(Object.entries(initial));
172
+ return {
173
+ get: (slug: string) => entries.get(slug) ?? null,
174
+ record: (slug: string, hashes: { bodyHash?: string; cssHash?: string }) => {
175
+ const prev = entries.get(slug);
176
+ entries.set(slug, { bodyHash: hashes.bodyHash ?? prev?.bodyHash ?? '' });
177
+ },
178
+ invalidateIfHubChanged: () => {},
179
+ flush: () => {},
180
+ stop: () => {},
181
+ size: () => entries.size,
182
+ };
183
+ }
184
+
185
+ test('journal match → fast-forward (hub keeps), no snapshot, no conflict', async () => {
186
+ const p = paths();
187
+ writeFileSync(p.html, '<main>synced-v1</main>');
188
+ const doc = new Y.Doc();
189
+ applyHtmlToDoc(doc, '<main>hub-v2</main>', 'hub');
190
+
191
+ const journal = makeJournal({ s: { bodyHash: hashBytes('<main>synced-v1</main>') } });
192
+ const snapshots: string[] = [];
193
+ const conflicts: unknown[] = [];
194
+ const result = await migrateSeed({
195
+ slug: 's',
196
+ doc,
197
+ paths: p,
198
+ journal,
199
+ snapshot: async (_c, reason) => {
200
+ snapshots.push(reason);
201
+ return 'ts';
202
+ },
203
+ onConflict: (info) => {
204
+ conflicts.push(info);
205
+ },
206
+ });
207
+
208
+ expect(result).toBe('hub-wins');
209
+ expect(doc.getText('html').toString()).toBe('<main>hub-v2</main>'); // doc untouched
210
+ expect(snapshots).toHaveLength(0);
211
+ expect(conflicts).toHaveLength(0);
212
+ });
213
+
214
+ test('diverged + local newer → conflict-local-wins: doc REBUILT from local in one MIGRATION tx', async () => {
215
+ const p = paths();
216
+ writeFileSync(p.html, '<main>local-newer</main>');
217
+ writeFileSync(p.css, '.local{}');
218
+ const doc = new Y.Doc();
219
+ doc.transact(() => {
220
+ applyHtmlToDoc(doc, '<main>hub-older</main>', 'hub');
221
+ applyCssToDoc(doc, '.hub{}', 'hub');
222
+ doc.getMap('syncMeta').set('bodyEditAt', Date.now() - 60_000);
223
+ });
224
+
225
+ const snapshots: Array<{ content: string; reason: string }> = [];
226
+ const conflicts: Array<{ winner?: string; snapshots?: { local?: string; hub?: string } }> = [];
227
+ const result = await migrateSeed({
228
+ slug: 's',
229
+ doc,
230
+ paths: p,
231
+ journal: makeJournal(),
232
+ snapshot: async (content, reason) => {
233
+ snapshots.push({ content, reason });
234
+ return `ts-${snapshots.length}`;
235
+ },
236
+ onConflict: (info) => {
237
+ conflicts.push(info);
238
+ },
239
+ });
240
+
241
+ expect(result).toBe('conflict-local-wins');
242
+ expect(doc.getText('html').toString()).toBe('<main>local-newer</main>');
243
+ // css follows the body winner.
244
+ expect(doc.getText('css').toString()).toBe('.local{}');
245
+ // Dual snapshot captured BOTH pre-resolution versions.
246
+ expect(snapshots.map((s) => s.reason)).toEqual(['pre-sync-local', 'pre-sync-hub']);
247
+ expect(snapshots[0].content).toBe('<main>local-newer</main>');
248
+ expect(snapshots[1].content).toBe('<main>hub-older</main>');
249
+ expect(conflicts[0].winner).toBe('local');
250
+ expect(conflicts[0].snapshots).toEqual({ local: 'ts-1', hub: 'ts-2' });
251
+ });
252
+
253
+ test('diverged + hub newer (stamp) → conflict-hub-wins: doc untouched', async () => {
254
+ const p = paths();
255
+ writeFileSync(p.html, '<main>local-older</main>');
256
+ const doc = new Y.Doc();
257
+ doc.transact(() => {
258
+ applyHtmlToDoc(doc, '<main>hub-newer</main>', 'hub');
259
+ doc.getMap('syncMeta').set('bodyEditAt', Date.now() + 60_000);
260
+ });
261
+
262
+ const conflicts: Array<{ winner?: string }> = [];
263
+ const result = await migrateSeed({
264
+ slug: 's',
265
+ doc,
266
+ paths: p,
267
+ journal: makeJournal(),
268
+ onConflict: (info) => {
269
+ conflicts.push(info);
270
+ },
271
+ });
272
+
273
+ expect(result).toBe('conflict-hub-wins');
274
+ expect(doc.getText('html').toString()).toBe('<main>hub-newer</main>');
275
+ expect(conflicts[0].winner).toBe('hub');
276
+ });
277
+
278
+ test('doc holds comments but NO body + local body → body-seed-up (gap closed)', async () => {
279
+ const p = paths();
280
+ writeFileSync(p.html, '<main>only-local-body</main>');
281
+ const doc = new Y.Doc();
282
+ doc.getArray(Y_TYPES.comments).push([{ id: 'h1' }]); // doc non-empty, body empty
283
+
284
+ const result = await migrateSeed({ slug: 's', doc, paths: p, journal: makeJournal() });
285
+
286
+ expect(result).toBe('body-seed-up');
287
+ expect(doc.getText('html').toString()).toBe('<main>only-local-body</main>');
288
+ // Hub comments survive untouched.
289
+ expect(doc.getArray(Y_TYPES.comments).toArray()).toEqual([{ id: 'h1' }]);
290
+ });
291
+
292
+ test('comments id-union: local-only comments survive a hub-wins cutover', async () => {
293
+ const p = paths();
294
+ writeFileSync(p.html, '<main>same</main>');
295
+ writeFileSync(
296
+ p.comments,
297
+ JSON.stringify([
298
+ { id: 'c1', text: 'shared' },
299
+ { id: 'c3', text: 'local-only' },
300
+ ])
301
+ );
302
+ const doc = new Y.Doc();
303
+ doc.transact(() => {
304
+ applyHtmlToDoc(doc, '<main>same</main>', 'hub');
305
+ applyCommentsToDoc(
306
+ doc,
307
+ [
308
+ { id: 'c1', text: 'shared (hub copy wins)' },
309
+ { id: 'c2', text: 'hub-only' },
310
+ ],
311
+ 'hub'
312
+ );
313
+ });
314
+
315
+ const result = await migrateSeed({ slug: 's', doc, paths: p });
316
+
317
+ expect(result).toBe('hub-wins');
318
+ expect(doc.getArray(Y_TYPES.comments).toArray()).toEqual([
319
+ { id: 'c1', text: 'shared (hub copy wins)' },
320
+ { id: 'c2', text: 'hub-only' },
321
+ { id: 'c3', text: 'local-only' },
322
+ ]);
323
+ });
324
+ });
325
+
326
+ // DDR-102 fail-closed (security review F1) — the shared-doc path must also
327
+ // refuse a hub-wins cutover when the local snapshot didn't land.
328
+ describe('migrateSeed — fail-closed on snapshot failure (DDR-102 F1)', () => {
329
+ function makeJournal() {
330
+ const entries = new Map<string, { bodyHash: string }>();
331
+ return {
332
+ get: (slug: string) => entries.get(slug) ?? null,
333
+ record: (slug: string, h: { bodyHash?: string; cssHash?: string }) =>
334
+ entries.set(slug, { bodyHash: h.bodyHash ?? entries.get(slug)?.bodyHash ?? '' }),
335
+ invalidateIfHubChanged: () => {},
336
+ flush: () => {},
337
+ stop: () => {},
338
+ size: () => entries.size,
339
+ };
340
+ }
341
+
342
+ test('hub newer BUT local snapshot null → rebuild doc from local (no overwrite), conflict-local-wins', async () => {
343
+ const p = paths();
344
+ writeFileSync(p.html, '<main>local-work</main>');
345
+ const doc = new Y.Doc();
346
+ doc.transact(() => {
347
+ applyHtmlToDoc(doc, '<main>hub-stale</main>', 'hub');
348
+ doc.getMap('syncMeta').set('bodyEditAt', Date.now() + 60_000); // hub would win
349
+ });
350
+
351
+ const conflicts: Array<{ winner?: string; snapshotFailed?: boolean }> = [];
352
+ const result = await migrateSeed({
353
+ slug: 's',
354
+ doc,
355
+ paths: p,
356
+ journal: makeJournal(),
357
+ snapshot: async () => null, // _history write fails
358
+ onConflict: (info) => {
359
+ conflicts.push(info);
360
+ },
361
+ });
362
+
363
+ // Doc rebuilt from local → projection would write local back (no loss).
364
+ expect(result).toBe('conflict-local-wins');
365
+ expect(doc.getText('html').toString()).toBe('<main>local-work</main>');
366
+ expect(conflicts[0].winner).toBe('local');
367
+ expect(conflicts[0].snapshotFailed).toBe(true);
368
+ });
369
+ });