@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.
- package/README.md +3 -3
- package/{plugins/design/dev-server → apps/studio}/ai-banner.tsx +1 -2
- package/apps/studio/annotations-align.ts +149 -0
- package/apps/studio/annotations-bindings.ts +197 -0
- package/{plugins/design/dev-server → apps/studio}/annotations-context-toolbar.tsx +681 -151
- package/apps/studio/annotations-groups.ts +270 -0
- package/apps/studio/annotations-layer.tsx +4537 -0
- package/apps/studio/annotations-model.ts +2077 -0
- package/apps/studio/annotations-snap.ts +125 -0
- package/{plugins/design/dev-server → apps/studio}/api.ts +616 -70
- package/{plugins/design/dev-server → apps/studio}/artboard-activity-overlay.tsx +1 -1
- package/{plugins/design/dev-server → apps/studio}/artboard-marquee.tsx +1 -1
- package/apps/studio/bin/_motion-sample-playwright.mjs +129 -0
- package/{plugins/design/dev-server → apps/studio}/bin/_png-playwright.mjs +1 -1
- package/apps/studio/bin/annotate.mjs +732 -0
- package/apps/studio/bin/annotate.sh +17 -0
- package/{plugins/design/dev-server → apps/studio}/bin/canvas-edit.sh +1 -1
- package/{plugins/design/dev-server → apps/studio}/bin/draw-proof.sh +37 -2
- package/{plugins/design/dev-server → apps/studio}/bin/preflight.sh +1 -1
- package/apps/studio/bin/read-annotations.mjs +573 -0
- package/apps/studio/bin/read-annotations.sh +11 -0
- package/{plugins/design/dev-server → apps/studio}/bin/runtime-health.sh +1 -1
- package/{plugins/design/dev-server → apps/studio}/bin/screenshot.sh +62 -2
- package/{plugins/design/dev-server → apps/studio}/bin/server-up.sh +9 -3
- package/apps/studio/bin/to-lottie-verify.html +68 -0
- package/apps/studio/bin/to-lottie.sh +128 -0
- package/{plugins/design/dev-server → apps/studio}/build.ts +6 -4
- package/{plugins/design/dev-server → apps/studio}/canvas-arrowheads.ts +79 -10
- package/{plugins/design/dev-server → apps/studio}/canvas-comment-mount.tsx +1 -1
- package/apps/studio/canvas-create.ts +104 -0
- package/{plugins/design/dev-server → apps/studio}/canvas-cursors.ts +48 -12
- package/{plugins/design/dev-server → apps/studio}/canvas-edit.ts +257 -7
- package/{plugins/design/dev-server → apps/studio}/canvas-icons.tsx +165 -1
- package/{plugins/design/dev-server → apps/studio}/canvas-lib-inline.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/canvas-lib-resolver.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/canvas-lib.tsx +31 -12
- package/{plugins/design/dev-server → apps/studio}/canvas-shell.tsx +360 -48
- package/apps/studio/client/app.jsx +6742 -0
- package/apps/studio/client/canvas-url.js +81 -0
- package/{plugins/design/dev-server → apps/studio}/client/comments-overlay.css +41 -27
- package/apps/studio/client/index.html +16 -0
- package/apps/studio/client/styles/1-tokens-maude.css +296 -0
- package/apps/studio/client/styles/3-shell-maude.css +1161 -0
- package/{plugins/design/dev-server → apps/studio}/client/styles/3-shell.css +129 -0
- package/apps/studio/client/styles/4-components-maude.css +74 -0
- package/{plugins/design/dev-server → apps/studio}/client/styles/4-components.css +396 -34
- package/apps/studio/client/styles/5-maude-overrides.css +137 -0
- package/{plugins/design/dev-server → apps/studio}/client/styles/_index.css +9 -0
- package/{plugins/design/dev-server → apps/studio}/client/styles.css +1 -1
- package/apps/studio/client/tour/overlay.jsx +279 -0
- package/apps/studio/client/tour/usage-tour.js +48 -0
- package/apps/studio/client/whats-new-seen.js +52 -0
- package/apps/studio/client/whats-new.jsx +250 -0
- package/{plugins/design/dev-server → apps/studio}/commands/annotation-strokes-command.ts +2 -2
- package/{plugins/design/dev-server → apps/studio}/commands/equal-spacing-command.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/commands/move-artboards-command.ts +2 -2
- package/{plugins/design/dev-server → apps/studio}/comments-overlay.tsx +32 -11
- package/{plugins/design/dev-server → apps/studio}/context-menu.tsx +5 -4
- package/{plugins/design/dev-server → apps/studio}/contextual-toolbar.tsx +18 -7
- package/{plugins/design/dev-server → apps/studio}/cursors-overlay.tsx +21 -21
- package/apps/studio/dist/client.bundle.js +25545 -0
- package/apps/studio/dist/comment-mount.js +2046 -0
- package/apps/studio/dist/styles.css +8018 -0
- package/apps/studio/dom-selection.ts +342 -0
- package/apps/studio/draw/animate.ts +333 -0
- package/{plugins/design/dev-server → apps/studio}/draw/brush.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/draw/composition.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/draw/geometry.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/draw/index.ts +4 -1
- package/{plugins/design/dev-server → apps/studio}/draw/layout.ts +1 -1
- package/apps/studio/draw/morph.ts +204 -0
- package/{plugins/design/dev-server → apps/studio}/draw/optimize.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/draw/palette.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/draw/primitives.ts +1 -1
- package/apps/studio/draw/serialize-animate.ts +324 -0
- package/{plugins/design/dev-server → apps/studio}/draw/serialize.ts +9 -3
- package/apps/studio/draw/test/animate.test.ts +172 -0
- package/apps/studio/draw/test/morph.test.ts +107 -0
- package/apps/studio/draw/test/serialize-animate.test.ts +142 -0
- package/{plugins/design/dev-server → apps/studio}/equal-spacing-detector.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/equal-spacing-handles.tsx +7 -29
- package/{plugins/design/dev-server → apps/studio}/export-dialog.tsx +16 -4
- package/{plugins/design/dev-server → apps/studio}/history.ts +20 -3
- package/{plugins/design/dev-server → apps/studio}/http.ts +226 -6
- package/{plugins/design/dev-server → apps/studio}/input-router.tsx +15 -1
- package/{plugins/design/dev-server → apps/studio}/inspect.ts +50 -4
- package/{plugins/design/dev-server → apps/studio}/marquee-overlay.tsx +5 -2
- package/{plugins/design/dev-server → apps/studio}/participants-chrome.tsx +2 -8
- package/{plugins/design/dev-server → apps/studio}/paths.ts +15 -11
- package/{plugins/design/dev-server → apps/studio}/server.ts +23 -2
- package/{plugins/design/dev-server → apps/studio}/sync/agent.ts +231 -57
- package/{plugins/design/dev-server → apps/studio}/sync/codec.ts +45 -0
- package/apps/studio/sync/cold-start.ts +158 -0
- package/{plugins/design/dev-server → apps/studio}/sync/connection-state.ts +58 -2
- package/{plugins/design/dev-server → apps/studio}/sync/index.ts +563 -221
- package/apps/studio/sync/journal.ts +190 -0
- package/apps/studio/sync/migrate-seed.ts +321 -0
- package/{plugins/design/dev-server → apps/studio}/sync/projection.ts +22 -3
- package/{plugins/design/dev-server → apps/studio}/sync/status.ts +15 -4
- package/{plugins/design/dev-server → apps/studio}/test/activity.test.ts +1 -7
- package/apps/studio/test/annotate-write.test.ts +184 -0
- package/apps/studio/test/annotations-align.test.ts +88 -0
- package/apps/studio/test/annotations-bindings.test.ts +124 -0
- package/apps/studio/test/annotations-groups.test.ts +231 -0
- package/{plugins/design/dev-server → apps/studio}/test/annotations-layer.test.ts +63 -0
- package/{plugins/design/dev-server → apps/studio}/test/annotations-roundtrip.test.ts +97 -0
- package/apps/studio/test/annotations-snap.test.ts +79 -0
- package/apps/studio/test/annotations-text-format.test.ts +396 -0
- package/apps/studio/test/asset-api.test.ts +149 -0
- package/apps/studio/test/canvas-create-api.test.ts +361 -0
- package/{plugins/design/dev-server → apps/studio}/test/canvas-cursors.test.ts +2 -0
- package/apps/studio/test/canvas-edit.test.ts +319 -0
- package/{plugins/design/dev-server → apps/studio}/test/canvas-lib-resolver.test.ts +1 -1
- package/apps/studio/test/canvas-media-drop.test.ts +158 -0
- package/{plugins/design/dev-server → apps/studio}/test/canvas-origin-gate.test.ts +25 -1
- package/apps/studio/test/canvas-url.test.ts +99 -0
- package/{plugins/design/dev-server → apps/studio}/test/collab-bridge.test.ts +0 -2
- package/{plugins/design/dev-server → apps/studio}/test/collab-room.test.ts +2 -7
- package/{plugins/design/dev-server → apps/studio}/test/csp-canvas-shell.test.ts +5 -0
- package/apps/studio/test/csrf-write-guard.test.ts +52 -0
- package/apps/studio/test/figjam-v3-model.test.ts +342 -0
- package/apps/studio/test/fixtures/figjam-v3-groups-bindings.svg +1 -0
- package/apps/studio/test/index-data-canvas-ds.test.ts +97 -0
- package/apps/studio/test/motion-sample.test.ts +35 -0
- package/{plugins/design/dev-server → apps/studio}/test/perf-harness.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/test/phase-3.6-smoke.test.ts +3 -1
- package/apps/studio/test/read-annotations.test.ts +409 -0
- package/{plugins/design/dev-server → apps/studio}/test/sanitize-annotation-svg.test.ts +108 -2
- package/{plugins/design/dev-server → apps/studio}/test/shared-doc-convergence.test.ts +1 -1
- package/apps/studio/test/shared-doc-migrate.test.ts +369 -0
- package/apps/studio/test/sync-agent.test.ts +575 -0
- package/{plugins/design/dev-server → apps/studio}/test/sync-codec.test.ts +65 -0
- package/apps/studio/test/sync-cold-start.test.ts +244 -0
- package/{plugins/design/dev-server → apps/studio}/test/sync-connection-state.test.ts +68 -0
- package/{plugins/design/dev-server → apps/studio}/test/sync-hardening.test.ts +0 -8
- package/{plugins/design/dev-server → apps/studio}/test/sync-hubs-config.test.ts +0 -1
- package/apps/studio/test/sync-incident-replay.test.ts +211 -0
- package/apps/studio/test/sync-journal.test.ts +176 -0
- package/{plugins/design/dev-server → apps/studio}/test/sync-runtime.test.ts +360 -5
- package/{plugins/design/dev-server → apps/studio}/test/sync-status.test.ts +66 -0
- package/apps/studio/test/tour-overlay.test.tsx +56 -0
- package/apps/studio/test/use-annotation-resize.test.ts +402 -0
- package/{plugins/design/dev-server → apps/studio}/test/use-artboard-drag.test.ts +0 -1
- package/{plugins/design/dev-server → apps/studio}/test/use-collab.test.ts +0 -0
- package/{plugins/design/dev-server → apps/studio}/test/use-tool-mode.test.tsx +8 -2
- package/apps/studio/test/whats-new.test.ts +101 -0
- package/apps/studio/text-imports.d.ts +9 -0
- package/{plugins/design/dev-server → apps/studio}/tool-palette.tsx +15 -70
- package/{plugins/design/dev-server → apps/studio}/undo-hud.tsx +1 -2
- package/{plugins/design/dev-server → apps/studio}/undo-stack.ts +1 -1
- package/{plugins/design/dev-server → apps/studio}/use-agent-presence.tsx +5 -3
- package/apps/studio/use-annotation-resize.tsx +912 -0
- package/{plugins/design/dev-server → apps/studio}/use-annotation-selection.tsx +17 -5
- package/{plugins/design/dev-server → apps/studio}/use-annotations-visibility.tsx +1 -1
- package/{plugins/design/dev-server → apps/studio}/use-artboard-drag.tsx +1 -1
- package/{plugins/design/dev-server → apps/studio}/use-canvas-activity.tsx +3 -3
- package/apps/studio/use-canvas-media-drop.tsx +343 -0
- package/{plugins/design/dev-server → apps/studio}/use-collab.tsx +21 -16
- package/{plugins/design/dev-server → apps/studio}/use-cursor-modifiers.tsx +1 -1
- package/{plugins/design/dev-server → apps/studio}/use-keyboard-discipline.tsx +5 -2
- package/{plugins/design/dev-server → apps/studio}/use-selection-set.tsx +18 -1
- package/{plugins/design/dev-server → apps/studio}/use-snap-guides.tsx +1 -1
- package/{plugins/design/dev-server → apps/studio}/use-tool-mode.tsx +8 -2
- package/{plugins/design/dev-server → apps/studio}/use-undo-stack.tsx +1 -1
- package/apps/studio/whats-new.json +264 -0
- package/apps/studio/whats-new.schema.json +86 -0
- package/apps/studio/whats-new.ts +87 -0
- package/cli/bin/maude.mjs +10 -0
- package/cli/commands/design-link.test.mjs +84 -0
- package/cli/commands/design.mjs +16 -7
- package/cli/commands/design.test.mjs +40 -0
- package/cli/commands/help.mjs +8 -2
- package/cli/commands/hub.mjs +3 -3
- package/cli/commands/hub.test.mjs +1 -1
- package/cli/commands/scenario-report.mjs +2 -9
- package/cli/lib/design-link.mjs +51 -1
- package/cli/lib/flow-design-integration.test.mjs +1 -1
- package/cli/lib/gitignore-block.mjs +1 -0
- package/cli/lib/plugin-cli-reachability.test.mjs +8 -7
- package/cli/lib/preflight.mjs +1 -1
- package/package.json +15 -15
- package/plugins/design/templates/_shell.html +28 -4
- package/plugins/design/templates/brief-board.tsx.template +61 -0
- package/plugins/design/templates/canvas.tsx.template +1 -1
- package/plugins/design/templates/design-system-inspiration/core/config.json.tpl +1 -1
- package/plugins/design/templates/design-system-inspiration/core/preview/_motion-readme.md.tpl +1 -1
- package/plugins/flow/.claude-plugin/config.schema.json +16 -0
- package/plugins/design/dev-server/annotations-layer.tsx +0 -3402
- package/plugins/design/dev-server/client/app.jsx +0 -2985
- package/plugins/design/dev-server/client/index.html +0 -15
- package/plugins/design/dev-server/dist/client.bundle.js +0 -20692
- package/plugins/design/dev-server/dist/comment-mount.js +0 -1924
- package/plugins/design/dev-server/dist/styles.css +0 -2710
- package/plugins/design/dev-server/dom-selection.ts +0 -156
- package/plugins/design/dev-server/sync/migrate-seed.ts +0 -163
- package/plugins/design/dev-server/test/canvas-edit.test.ts +0 -139
- package/plugins/design/dev-server/test/shared-doc-migrate.test.ts +0 -159
- package/plugins/design/dev-server/test/sync-agent.test.ts +0 -305
- package/plugins/design/dev-server/test/use-annotation-resize.test.ts +0 -200
- package/plugins/design/dev-server/use-annotation-resize.tsx +0 -449
- /package/{plugins/design/dev-server → apps/studio}/activity.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_enumerate-artboards-playwright.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_html-playwright.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_pdf-playwright.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_pptx-playwright.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_pw-launch.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_screenshot-playwright.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_svg-optimize.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/_svg-playwright.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/asset-sweep.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/bootstrap-check.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/check-runtime-bundles.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/draw-build.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/handoff.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/prep.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/scenario-report.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/slug.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/smoke.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/svg-optimize.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/bin/visual-sanity.sh +0 -0
- /package/{plugins/design/dev-server → apps/studio}/boot-self-heal.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/canvas-build.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/canvas-header.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/canvas-meta.schema.json +0 -0
- /package/{plugins/design/dev-server → apps/studio}/canvas-pipeline.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/client/hmr.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/client/iframe-lazy.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/client/styles/0-reset.css +0 -0
- /package/{plugins/design/dev-server → apps/studio}/client/styles/1-tokens.css +0 -0
- /package/{plugins/design/dev-server → apps/studio}/client/styles/2-layout.css +0 -0
- /package/{plugins/design/dev-server → apps/studio}/client/styles/5-utilities.css +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/ai-activity.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/awareness-bridge.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/git-lifecycle.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/index.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/persistence.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/protocol.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/registry.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/collab/room.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/config.schema.json +0 -0
- /package/{plugins/design/dev-server → apps/studio}/context.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/.min-sizes.json +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/lib0_decoding.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/lib0_encoding.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/motion.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/motion_react.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/pixi-js.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react-dom.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react-dom_client.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react_jsx-dev-runtime.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/react_jsx-runtime.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/y-protocols_awareness.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/y-protocols_sync.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/dist/runtime/yjs.js +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/brush.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/composition.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/geometry.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/gradient.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/layout.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/optimize.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/palette.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/primitives.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/draw/test/serialize.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/examples/README.md +0 -0
- /package/{plugins/design/dev-server → apps/studio}/examples/perf-100-artboards.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/_browser-bundles.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/canva-handoff-prompt.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/canva.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/html.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/index.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/pdf.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/png.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/pptx.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/scope.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/svg.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/exporters/zip.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/fs-watch.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/handoff.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/hmr-broadcast.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/locator.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/mem.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/runtime-bundle.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/server.mjs +0 -0
- /package/{plugins/design/dev-server → apps/studio}/sync/atomic-write.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/sync/echo-guard.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/sync/fs-mirror.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/sync/hubs-config.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/sync/materialize.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/sync/origins.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/sync/untrusted.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/_helpers.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/active-state.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/ai-activity.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/annotation-strokes-command.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/annotations-api.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/annotations-draw-modifiers.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/artboard-activity-overlay.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/binary-smoke.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/boot-self-heal.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/bundle-smoke.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-build.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-header.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-hmr-runtime.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-lib-inline.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-lib-motion.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-meta-api.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-pipeline.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/canvas-route.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/collab-annotations-bridge.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/collab-awareness-bridge.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/collab-loopback.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/collab-protocol.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/collab-reseed-guard.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/collab-stress.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/comment-mount.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/comments-api.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/compile-entry.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/context-resolve-tokens.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/equal-spacing-detector.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/canva.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/endpoint.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/history.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/html.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/pdf.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/png.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/pptx-deck.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/pptx.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/pw-launch.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/scope.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/svg.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/exporters/zip.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/fixtures/phase-20-annotations.svg +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/fixtures/phase-21-annotations.svg +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/fs-watch.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/git-lifecycle.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/handoff-static-frames.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/handoff.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/history-rollback.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/hmr-broadcast.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/hmr-classify.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/input-router.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/locator.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/marquee-overlay.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/move-artboards-command.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/participants-chrome.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/paths.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/runtime-bundle-error-mapping.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/runtime-bundle.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/server-lifecycle.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/shared-doc-foundation.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/shared-doc-projection.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/snap-distance-pill.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/sync-atomic-write.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/sync-echo-guard.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/sync-fs-mirror.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/sync-meta-codec.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/sync-untrusted.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/system-endpoint.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/tool-palette.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/undo-stack.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-agent-presence.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-annotation-selection.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-canvas-activity.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-cursor-modifiers.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-keyboard-discipline.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-selection-set.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-snap-guides.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/use-undo-stack.test.tsx +0 -0
- /package/{plugins/design/dev-server → apps/studio}/test/ws-handshake.test.ts +0 -0
- /package/{plugins/design/dev-server → apps/studio}/tsconfig.json +0 -0
- /package/{plugins/design/dev-server → apps/studio}/ws.ts +0 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
// Sync-agent integration tests — Phase 9 Task 4.
|
|
2
|
+
//
|
|
3
|
+
// Uses an in-memory pair of Y.Docs cross-linked via Y.applyUpdate as a stand-in
|
|
4
|
+
// for HocuspocusProvider's transport. The agent under test owns docB; docA
|
|
5
|
+
// represents "another peer talking to the hub". Updates flow:
|
|
6
|
+
//
|
|
7
|
+
// docA → encode → applyUpdate(docB) → agent observes → write to disk
|
|
8
|
+
// disk → onRead → applyFromFs → applyHtmlToDoc(docB) → encode → docA
|
|
9
|
+
//
|
|
10
|
+
// This lets us validate the whole bidi loop, echo prevention, and the
|
|
11
|
+
// 100-event stress scenario from the plan without booting a real hub.
|
|
12
|
+
|
|
13
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
14
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import * as Y from 'yjs';
|
|
18
|
+
|
|
19
|
+
import { type CanvasSyncAgent, createCanvasSyncAgent } from '../sync/agent.ts';
|
|
20
|
+
import { applyHtmlToDoc, htmlFromDoc } from '../sync/codec.ts';
|
|
21
|
+
import { createEchoGuard, hashBytes } from '../sync/echo-guard.ts';
|
|
22
|
+
import { createFsReader } from '../sync/fs-mirror.ts';
|
|
23
|
+
|
|
24
|
+
let dir: string;
|
|
25
|
+
let agent: CanvasSyncAgent;
|
|
26
|
+
let docA: Y.Doc;
|
|
27
|
+
let docB: Y.Doc;
|
|
28
|
+
|
|
29
|
+
function paths() {
|
|
30
|
+
return {
|
|
31
|
+
html: join(dir, 'screen.html'),
|
|
32
|
+
comments: join(dir, '_comments', 'screen.json'),
|
|
33
|
+
annotations: join(dir, 'screen.annotations.svg'),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
dir = mkdtempSync(join(tmpdir(), 'sync-agent-'));
|
|
39
|
+
docA = new Y.Doc();
|
|
40
|
+
docB = new Y.Doc();
|
|
41
|
+
// Mirror docA→docB and docB→docA, ignoring transient origin objects from
|
|
42
|
+
// the transport itself (we use a symbol).
|
|
43
|
+
const TRANSPORT = Symbol('transport');
|
|
44
|
+
docA.on('update', (update: Uint8Array, origin: unknown) => {
|
|
45
|
+
if (origin === TRANSPORT) return;
|
|
46
|
+
Y.applyUpdate(docB, update, TRANSPORT);
|
|
47
|
+
});
|
|
48
|
+
docB.on('update', (update: Uint8Array, origin: unknown) => {
|
|
49
|
+
if (origin === TRANSPORT) return;
|
|
50
|
+
Y.applyUpdate(docA, update, TRANSPORT);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
agent?.stop();
|
|
56
|
+
rmSync(dir, { recursive: true, force: true });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function makeAgent(extra: { adopt?: boolean; flushMs?: number } = {}): CanvasSyncAgent {
|
|
60
|
+
const a = createCanvasSyncAgent({
|
|
61
|
+
slug: 'screen',
|
|
62
|
+
doc: docB,
|
|
63
|
+
paths: paths(),
|
|
64
|
+
echoGuard: createEchoGuard(),
|
|
65
|
+
flushMs: 0, // synchronous flush; the agent uses queueMicrotask
|
|
66
|
+
...extra,
|
|
67
|
+
});
|
|
68
|
+
a.start();
|
|
69
|
+
return a;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe('CanvasSyncAgent — hub → disk (Flow B)', () => {
|
|
73
|
+
test('writes HTML to disk when other peer mutates the doc', async () => {
|
|
74
|
+
agent = makeAgent();
|
|
75
|
+
// Other peer types into docA — propagates to docB via the in-memory
|
|
76
|
+
// transport, which our agent observes.
|
|
77
|
+
applyHtmlToDoc(docA, '<button>v1</button>');
|
|
78
|
+
await agent.flush();
|
|
79
|
+
|
|
80
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>v1</button>');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('debounces multiple rapid peer edits into one disk write', async () => {
|
|
84
|
+
agent = makeAgent({ flushMs: 30 });
|
|
85
|
+
for (let i = 0; i < 10; i++) {
|
|
86
|
+
applyHtmlToDoc(docA, `<button>v${i}</button>`);
|
|
87
|
+
}
|
|
88
|
+
await new Promise((res) => setTimeout(res, 80));
|
|
89
|
+
|
|
90
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>v9</button>');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('writes comments JSON when Y.Array changes', async () => {
|
|
94
|
+
agent = makeAgent();
|
|
95
|
+
docA.transact(() => {
|
|
96
|
+
docA.getArray('comments').push([{ id: 'c1', body: 'hello' }]);
|
|
97
|
+
});
|
|
98
|
+
await agent.flush();
|
|
99
|
+
|
|
100
|
+
const written = JSON.parse(readFileSync(paths().comments, 'utf8'));
|
|
101
|
+
expect(written).toEqual([{ id: 'c1', body: 'hello' }]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('writes annotations SVG when Y.Map.svg changes', async () => {
|
|
105
|
+
agent = makeAgent();
|
|
106
|
+
docA.transact(() => {
|
|
107
|
+
docA.getMap('annotations').set('svg', '<svg>annot</svg>');
|
|
108
|
+
});
|
|
109
|
+
await agent.flush();
|
|
110
|
+
|
|
111
|
+
expect(readFileSync(paths().annotations, 'utf8')).toBe('<svg>annot</svg>');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('CanvasSyncAgent — disk → hub (Flow A)', () => {
|
|
116
|
+
test('applies disk HTML to doc when applyFromFs is called', () => {
|
|
117
|
+
agent = makeAgent();
|
|
118
|
+
const bytes = new TextEncoder().encode('<div>local-edit</div>');
|
|
119
|
+
const changed = agent.applyFromFs({
|
|
120
|
+
path: paths().html,
|
|
121
|
+
bytes,
|
|
122
|
+
hash: hashBytes(bytes),
|
|
123
|
+
});
|
|
124
|
+
expect(changed).toBe(true);
|
|
125
|
+
expect(htmlFromDoc(docA)).toBe('<div>local-edit</div>');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('parses + applies comments JSON from disk', () => {
|
|
129
|
+
agent = makeAgent();
|
|
130
|
+
const snap = [{ id: 'c2' }];
|
|
131
|
+
const str = `${JSON.stringify(snap, null, 2)}\n`;
|
|
132
|
+
const bytes = new TextEncoder().encode(str);
|
|
133
|
+
agent.applyFromFs({ path: paths().comments, bytes, hash: hashBytes(bytes) });
|
|
134
|
+
expect(docA.getArray('comments').toArray()).toEqual(snap);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('applies annotations SVG from disk', () => {
|
|
138
|
+
agent = makeAgent();
|
|
139
|
+
const bytes = new TextEncoder().encode('<svg>x</svg>');
|
|
140
|
+
agent.applyFromFs({ path: paths().annotations, bytes, hash: hashBytes(bytes) });
|
|
141
|
+
expect(docA.getMap<string>('annotations').get('svg')).toBe('<svg>x</svg>');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('drops the fs-watch echo of its own atomic write', async () => {
|
|
145
|
+
agent = makeAgent();
|
|
146
|
+
// Peer edits → agent writes to disk → echo guard recorded.
|
|
147
|
+
applyHtmlToDoc(docA, '<button>hi</button>');
|
|
148
|
+
await agent.flush();
|
|
149
|
+
|
|
150
|
+
// Simulate the fs.watch firing for the path we just wrote.
|
|
151
|
+
const bytes = readFileSync(paths().html);
|
|
152
|
+
const u8 = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
153
|
+
const changed = agent.applyFromFs({
|
|
154
|
+
path: paths().html,
|
|
155
|
+
bytes: u8,
|
|
156
|
+
hash: hashBytes(u8),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(changed).toBe(false);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('CanvasSyncAgent — cold start reconciliation', () => {
|
|
164
|
+
test('hub-wins (default): overwrites disk when doc differs', async () => {
|
|
165
|
+
// Local disk has stale content.
|
|
166
|
+
writeFileSync(paths().html, '<old>');
|
|
167
|
+
// Hub state arrives via docA (propagated to docB before reconcile runs).
|
|
168
|
+
applyHtmlToDoc(docA, '<new>');
|
|
169
|
+
|
|
170
|
+
agent = makeAgent();
|
|
171
|
+
await agent.reconcile();
|
|
172
|
+
|
|
173
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<new>');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('adopt mode: pushes local disk state up to the doc', async () => {
|
|
177
|
+
writeFileSync(paths().html, '<button>local</button>');
|
|
178
|
+
// Hub has stale content.
|
|
179
|
+
applyHtmlToDoc(docA, '<old-hub>');
|
|
180
|
+
|
|
181
|
+
agent = makeAgent({ adopt: true });
|
|
182
|
+
await agent.reconcile();
|
|
183
|
+
|
|
184
|
+
expect(htmlFromDoc(docA)).toBe('<button>local</button>');
|
|
185
|
+
expect(htmlFromDoc(docB)).toBe('<button>local</button>');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('adopt mode is one-shot — second reconcile is hub-wins', async () => {
|
|
189
|
+
writeFileSync(paths().html, '<button>local-v1</button>');
|
|
190
|
+
agent = makeAgent({ adopt: true });
|
|
191
|
+
await agent.reconcile();
|
|
192
|
+
|
|
193
|
+
// Hub changes the value.
|
|
194
|
+
applyHtmlToDoc(docA, '<button>hub-v2</button>');
|
|
195
|
+
|
|
196
|
+
// Disk reverts to a stale local-only state.
|
|
197
|
+
writeFileSync(paths().html, '<button>local-v3</button>');
|
|
198
|
+
await agent.reconcile();
|
|
199
|
+
|
|
200
|
+
// Hub state won this time.
|
|
201
|
+
expect(htmlFromDoc(docB)).toBe('<button>hub-v2</button>');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('empty hub doc does NOT clobber a non-empty local body — seeds local up instead (data-loss guard)', async () => {
|
|
205
|
+
// Local holds the real canvas body; the hub is fresh — no state for this
|
|
206
|
+
// slug yet (docB starts empty → docHtml === ''). The old behaviour wrote
|
|
207
|
+
// the empty doc over disk and emptied the file; the guard must keep local.
|
|
208
|
+
writeFileSync(paths().html, '<button>real-canvas</button>');
|
|
209
|
+
|
|
210
|
+
let conflicts = 0;
|
|
211
|
+
agent = createCanvasSyncAgent({
|
|
212
|
+
slug: 'screen',
|
|
213
|
+
doc: docB,
|
|
214
|
+
paths: paths(),
|
|
215
|
+
echoGuard: createEchoGuard(),
|
|
216
|
+
flushMs: 0,
|
|
217
|
+
onConflict: () => {
|
|
218
|
+
conflicts++;
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
agent.start();
|
|
222
|
+
await agent.reconcile();
|
|
223
|
+
|
|
224
|
+
// The local body MUST survive — an empty hub must never empty a real canvas.
|
|
225
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>real-canvas</button>');
|
|
226
|
+
// …and it is seeded UP to the hub instead of being discarded (local→doc).
|
|
227
|
+
expect(htmlFromDoc(docA)).toBe('<button>real-canvas</button>');
|
|
228
|
+
// An empty-hub seed is not a "hub overwrote your local" conflict.
|
|
229
|
+
expect(conflicts).toBe(0);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('identical disk + doc states: no disk write', async () => {
|
|
233
|
+
writeFileSync(paths().html, '<button>same</button>');
|
|
234
|
+
applyHtmlToDoc(docA, '<button>same</button>');
|
|
235
|
+
|
|
236
|
+
agent = makeAgent();
|
|
237
|
+
let writes = 0;
|
|
238
|
+
const customAgent = createCanvasSyncAgent({
|
|
239
|
+
slug: 'screen',
|
|
240
|
+
doc: docB,
|
|
241
|
+
paths: paths(),
|
|
242
|
+
echoGuard: createEchoGuard(),
|
|
243
|
+
flushMs: 0,
|
|
244
|
+
writer: () => {
|
|
245
|
+
writes++;
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
customAgent.start();
|
|
249
|
+
await customAgent.reconcile();
|
|
250
|
+
customAgent.stop();
|
|
251
|
+
|
|
252
|
+
expect(writes).toBe(0);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('CanvasSyncAgent — stress: 100 rapid disk writes converge with no echo loop', () => {
|
|
257
|
+
test('100-event scenario from plan validate', async () => {
|
|
258
|
+
// Wire up fs-mirror against the temp dir so this looks like the production
|
|
259
|
+
// flow: file writes → fs.watch → fs-mirror debounce → agent.applyFromFs.
|
|
260
|
+
agent = makeAgent({ flushMs: 20 });
|
|
261
|
+
|
|
262
|
+
const reader = createFsReader({
|
|
263
|
+
rootDir: dir,
|
|
264
|
+
quietMs: 15,
|
|
265
|
+
accept: (p) => p.endsWith('.html'),
|
|
266
|
+
onRead: async (evt) => {
|
|
267
|
+
agent.applyFromFs({
|
|
268
|
+
path: join(dir, evt.path),
|
|
269
|
+
bytes: evt.bytes,
|
|
270
|
+
hash: evt.hash,
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Track how many times the doc transitioned — should be bounded, no echo
|
|
276
|
+
// loop multiplying it.
|
|
277
|
+
let docUpdates = 0;
|
|
278
|
+
docB.on('update', () => {
|
|
279
|
+
docUpdates++;
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
for (let i = 0; i < 100; i++) {
|
|
283
|
+
writeFileSync(paths().html, `<button>${i}</button>`);
|
|
284
|
+
reader.notify('screen.html');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Let everything settle: reader quiet (15ms), agent flush (20ms) + slack.
|
|
288
|
+
await new Promise((res) => setTimeout(res, 200));
|
|
289
|
+
await reader.flush();
|
|
290
|
+
await agent.flush();
|
|
291
|
+
reader.stop();
|
|
292
|
+
|
|
293
|
+
// Doc + disk + peer all converge on the last write.
|
|
294
|
+
const last = '<button>99</button>';
|
|
295
|
+
expect(htmlFromDoc(docB)).toBe(last);
|
|
296
|
+
expect(htmlFromDoc(docA)).toBe(last);
|
|
297
|
+
expect(readFileSync(paths().html, 'utf8')).toBe(last);
|
|
298
|
+
|
|
299
|
+
// Update count must be bounded — strictly < 100 transitions (debounce did
|
|
300
|
+
// its job) AND < 200 (no echo loop running 2x amplification).
|
|
301
|
+
expect(docUpdates).toBeLessThan(200);
|
|
302
|
+
// Also: it should be > 0 — we DID see real syncs.
|
|
303
|
+
expect(docUpdates).toBeGreaterThan(0);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
// DDR-102 — cold-start conflict protocol (journal-gated fast-forward, dual
|
|
309
|
+
// snapshot, newest-wins, comments id-union).
|
|
310
|
+
describe('CanvasSyncAgent — DDR-102 cold-start conflict protocol', () => {
|
|
311
|
+
interface SnapCall {
|
|
312
|
+
content: string;
|
|
313
|
+
reason: string;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function makeJournal(initial: Record<string, { bodyHash: string }> = {}) {
|
|
317
|
+
const entries = new Map(Object.entries(initial));
|
|
318
|
+
const records: Array<{ slug: string; hashes: Record<string, string | undefined> }> = [];
|
|
319
|
+
return {
|
|
320
|
+
journal: {
|
|
321
|
+
get: (slug: string) => entries.get(slug) ?? null,
|
|
322
|
+
record: (slug: string, hashes: { bodyHash?: string; cssHash?: string }) => {
|
|
323
|
+
records.push({ slug, hashes });
|
|
324
|
+
const prev = entries.get(slug);
|
|
325
|
+
entries.set(slug, { bodyHash: hashes.bodyHash ?? prev?.bodyHash ?? '' });
|
|
326
|
+
},
|
|
327
|
+
invalidateIfHubChanged: () => {},
|
|
328
|
+
flush: () => {},
|
|
329
|
+
stop: () => {},
|
|
330
|
+
size: () => entries.size,
|
|
331
|
+
},
|
|
332
|
+
records,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function protocolAgent(extra: {
|
|
337
|
+
journal?: ReturnType<typeof makeJournal>['journal'];
|
|
338
|
+
snapshots?: SnapCall[];
|
|
339
|
+
conflicts?: unknown[];
|
|
340
|
+
}) {
|
|
341
|
+
const a = createCanvasSyncAgent({
|
|
342
|
+
slug: 'screen',
|
|
343
|
+
doc: docB,
|
|
344
|
+
paths: paths(),
|
|
345
|
+
echoGuard: createEchoGuard(),
|
|
346
|
+
flushMs: 0,
|
|
347
|
+
journal: extra.journal,
|
|
348
|
+
snapshot: extra.snapshots
|
|
349
|
+
? async (content, reason) => {
|
|
350
|
+
extra.snapshots?.push({ content, reason });
|
|
351
|
+
return `ts-${extra.snapshots?.length}`;
|
|
352
|
+
}
|
|
353
|
+
: undefined,
|
|
354
|
+
onConflict: (info) => {
|
|
355
|
+
extra.conflicts?.push(info);
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
a.start();
|
|
359
|
+
return a;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
test('journal match → silent fast-forward: hub overwrites disk, NO snapshot, NO conflict', async () => {
|
|
363
|
+
const { setHtml } = await import('node:fs').then(() => ({ setHtml: writeFileSync }));
|
|
364
|
+
setHtml(paths().html, '<button>synced-v1</button>');
|
|
365
|
+
applyHtmlToDoc(docA, '<button>hub-v2</button>');
|
|
366
|
+
|
|
367
|
+
const { journal } = makeJournal({
|
|
368
|
+
screen: { bodyHash: hashBytes('<button>synced-v1</button>') },
|
|
369
|
+
});
|
|
370
|
+
const snapshots: SnapCall[] = [];
|
|
371
|
+
const conflicts: unknown[] = [];
|
|
372
|
+
agent = protocolAgent({ journal, snapshots, conflicts });
|
|
373
|
+
await agent.reconcile();
|
|
374
|
+
|
|
375
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>hub-v2</button>');
|
|
376
|
+
expect(snapshots).toHaveLength(0);
|
|
377
|
+
expect(conflicts).toHaveLength(0);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('diverged + local newer → local wins, BOTH sides snapshotted, conflict recorded', async () => {
|
|
381
|
+
writeFileSync(paths().html, '<button>local-newer</button>');
|
|
382
|
+
// Hub doc carries different body with an OLDER bodyEditAt stamp.
|
|
383
|
+
docA.transact(() => {
|
|
384
|
+
applyHtmlToDoc(docA, '<button>hub-older</button>');
|
|
385
|
+
docA.getMap('syncMeta').set('bodyEditAt', Date.now() - 60_000);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const { journal } = makeJournal(); // no entry → divergence
|
|
389
|
+
const snapshots: SnapCall[] = [];
|
|
390
|
+
const conflicts: Array<{ kind: string; winner?: string; snapshots?: object }> = [];
|
|
391
|
+
agent = protocolAgent({ journal, snapshots, conflicts });
|
|
392
|
+
await agent.reconcile();
|
|
393
|
+
|
|
394
|
+
// Local body survives on disk AND is pushed up to the hub.
|
|
395
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>local-newer</button>');
|
|
396
|
+
expect(htmlFromDoc(docA)).toBe('<button>local-newer</button>');
|
|
397
|
+
// Dual snapshot: local first, hub second.
|
|
398
|
+
expect(snapshots.map((s) => s.reason)).toEqual(['pre-sync-local', 'pre-sync-hub']);
|
|
399
|
+
expect(snapshots[0].content).toBe('<button>local-newer</button>');
|
|
400
|
+
expect(snapshots[1].content).toBe('<button>hub-older</button>');
|
|
401
|
+
// Conflict entry carries winner + snapshot refs.
|
|
402
|
+
expect(conflicts).toHaveLength(1);
|
|
403
|
+
expect(conflicts[0].kind).toBe('cold-start-diverged');
|
|
404
|
+
expect(conflicts[0].winner).toBe('local');
|
|
405
|
+
expect(conflicts[0].snapshots).toBeDefined();
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test('diverged + hub newer → hub wins, both sides snapshotted', async () => {
|
|
409
|
+
writeFileSync(paths().html, '<button>local-older</button>');
|
|
410
|
+
docA.transact(() => {
|
|
411
|
+
applyHtmlToDoc(docA, '<button>hub-newer</button>');
|
|
412
|
+
docA.getMap('syncMeta').set('bodyEditAt', Date.now() + 60_000);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const { journal } = makeJournal();
|
|
416
|
+
const snapshots: SnapCall[] = [];
|
|
417
|
+
const conflicts: Array<{ winner?: string }> = [];
|
|
418
|
+
agent = protocolAgent({ journal, snapshots, conflicts });
|
|
419
|
+
await agent.reconcile();
|
|
420
|
+
|
|
421
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>hub-newer</button>');
|
|
422
|
+
expect(snapshots.map((s) => s.reason)).toEqual(['pre-sync-local', 'pre-sync-hub']);
|
|
423
|
+
expect(conflicts[0].winner).toBe('hub');
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
test('DDR-064 empty-hub guard is bit-identical: seed-local-up, no snapshot, no conflict', async () => {
|
|
427
|
+
writeFileSync(paths().html, '<button>real-canvas</button>');
|
|
428
|
+
// docA/docB empty — fresh hub.
|
|
429
|
+
const { journal } = makeJournal();
|
|
430
|
+
const snapshots: SnapCall[] = [];
|
|
431
|
+
const conflicts: unknown[] = [];
|
|
432
|
+
agent = protocolAgent({ journal, snapshots, conflicts });
|
|
433
|
+
await agent.reconcile();
|
|
434
|
+
|
|
435
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>real-canvas</button>');
|
|
436
|
+
expect(htmlFromDoc(docA)).toBe('<button>real-canvas</button>');
|
|
437
|
+
expect(snapshots).toHaveLength(0);
|
|
438
|
+
expect(conflicts).toHaveLength(0);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test('journal checkpoints: doc→disk flush and disk→doc apply both record', async () => {
|
|
442
|
+
const { journal, records } = makeJournal();
|
|
443
|
+
agent = createCanvasSyncAgent({
|
|
444
|
+
slug: 'screen',
|
|
445
|
+
doc: docB,
|
|
446
|
+
paths: paths(),
|
|
447
|
+
echoGuard: createEchoGuard(),
|
|
448
|
+
flushMs: 0,
|
|
449
|
+
journal,
|
|
450
|
+
});
|
|
451
|
+
agent.start();
|
|
452
|
+
|
|
453
|
+
// Hub edit → disk write → checkpoint.
|
|
454
|
+
applyHtmlToDoc(docA, '<button>from-hub</button>');
|
|
455
|
+
await agent.flush();
|
|
456
|
+
expect(records.some((r) => r.hashes.bodyHash === hashBytes('<button>from-hub</button>'))).toBe(
|
|
457
|
+
true
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
// Local edit → doc apply → checkpoint.
|
|
461
|
+
const bytes = new TextEncoder().encode('<button>from-disk</button>');
|
|
462
|
+
agent.applyFromFs({ path: paths().html, bytes, hash: hashBytes(bytes) });
|
|
463
|
+
expect(records.some((r) => r.hashes.bodyHash === hashBytes(bytes))).toBe(true);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test('comments id-union: doc order first, local-only appended, both sides converge', async () => {
|
|
467
|
+
// Local file has c1 + c3; hub doc has c1 + c2.
|
|
468
|
+
const localComments = [
|
|
469
|
+
{ id: 'c1', body: 'shared' },
|
|
470
|
+
{ id: 'c3', body: 'local-only' },
|
|
471
|
+
];
|
|
472
|
+
mkdirSync(join(dir, '_comments'), { recursive: true });
|
|
473
|
+
writeFileSync(paths().comments, `${JSON.stringify(localComments, null, 2)}\n`);
|
|
474
|
+
docA.transact(() => {
|
|
475
|
+
docA.getArray('comments').push([
|
|
476
|
+
{ id: 'c1', body: 'shared' },
|
|
477
|
+
{ id: 'c2', body: 'hub-only' },
|
|
478
|
+
]);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
agent = protocolAgent({});
|
|
482
|
+
await agent.reconcile();
|
|
483
|
+
|
|
484
|
+
const expectUnion = [
|
|
485
|
+
{ id: 'c1', body: 'shared' },
|
|
486
|
+
{ id: 'c2', body: 'hub-only' },
|
|
487
|
+
{ id: 'c3', body: 'local-only' },
|
|
488
|
+
];
|
|
489
|
+
// Doc (and the peer) hold the union…
|
|
490
|
+
expect(docA.getArray('comments').toArray()).toEqual(expectUnion);
|
|
491
|
+
// …and the disk file was rewritten to the union too.
|
|
492
|
+
expect(JSON.parse(readFileSync(paths().comments, 'utf8'))).toEqual(expectUnion);
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
test('comments union with empty hub doc keeps + pushes local comments', async () => {
|
|
496
|
+
const localComments = [{ id: 'c9', body: 'only-local' }];
|
|
497
|
+
mkdirSync(join(dir, '_comments'), { recursive: true });
|
|
498
|
+
writeFileSync(paths().comments, `${JSON.stringify(localComments, null, 2)}\n`);
|
|
499
|
+
|
|
500
|
+
agent = protocolAgent({});
|
|
501
|
+
await agent.reconcile();
|
|
502
|
+
|
|
503
|
+
expect(docA.getArray('comments').toArray()).toEqual(localComments);
|
|
504
|
+
expect(JSON.parse(readFileSync(paths().comments, 'utf8'))).toEqual(localComments);
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// ---------------------------------------------------------------------------
|
|
509
|
+
// DDR-102 fail-closed (security review F1): a hub-wins resolution must NEVER
|
|
510
|
+
// overwrite local when the local snapshot didn't land — keep local + push up.
|
|
511
|
+
describe('CanvasSyncAgent — fail-closed on snapshot failure (DDR-102 F1)', () => {
|
|
512
|
+
function failClosedAgent(
|
|
513
|
+
snapshotImpl: (content: string, reason: string) => Promise<string | null>,
|
|
514
|
+
conflicts: unknown[]
|
|
515
|
+
) {
|
|
516
|
+
const a = createCanvasSyncAgent({
|
|
517
|
+
slug: 'screen',
|
|
518
|
+
doc: docB,
|
|
519
|
+
paths: paths(),
|
|
520
|
+
echoGuard: createEchoGuard(),
|
|
521
|
+
flushMs: 0,
|
|
522
|
+
// No journal → every diff is divergence (conflict path).
|
|
523
|
+
snapshot: snapshotImpl,
|
|
524
|
+
onConflict: (info) => {
|
|
525
|
+
conflicts.push(info);
|
|
526
|
+
},
|
|
527
|
+
});
|
|
528
|
+
a.start();
|
|
529
|
+
return a;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
test('hub newer BUT local snapshot returns null → REFUSE overwrite, keep local, push up', async () => {
|
|
533
|
+
writeFileSync(paths().html, '<button>local-work</button>');
|
|
534
|
+
// Hub doc carries a NEWER stamp so newest-wins would pick hub.
|
|
535
|
+
docA.transact(() => {
|
|
536
|
+
applyHtmlToDoc(docA, '<button>hub-stale</button>');
|
|
537
|
+
docA.getMap('syncMeta').set('bodyEditAt', Date.now() + 60_000);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
const conflicts: Array<{ winner?: string; snapshotFailed?: boolean }> = [];
|
|
541
|
+
// Snapshot writer that FAILS (disk full / read-only _history): returns null.
|
|
542
|
+
agent = failClosedAgent(async () => null, conflicts);
|
|
543
|
+
await agent.reconcile();
|
|
544
|
+
|
|
545
|
+
// Local work survives on disk (NOT overwritten by hub-stale) …
|
|
546
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>local-work</button>');
|
|
547
|
+
// … and is pushed UP to the hub (nothing lost on either side).
|
|
548
|
+
expect(htmlFromDoc(docA)).toBe('<button>local-work</button>');
|
|
549
|
+
// The conflict is recorded with the degraded-snapshot flag + flipped winner.
|
|
550
|
+
expect(conflicts).toHaveLength(1);
|
|
551
|
+
expect(conflicts[0].winner).toBe('local');
|
|
552
|
+
expect(conflicts[0].snapshotFailed).toBe(true);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
test('hub newer + local snapshot SUCCEEDS → normal hub-wins (control)', async () => {
|
|
556
|
+
writeFileSync(paths().html, '<button>local-work</button>');
|
|
557
|
+
docA.transact(() => {
|
|
558
|
+
applyHtmlToDoc(docA, '<button>hub-newer</button>');
|
|
559
|
+
docA.getMap('syncMeta').set('bodyEditAt', Date.now() + 60_000);
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
const conflicts: Array<{ winner?: string; snapshotFailed?: boolean }> = [];
|
|
563
|
+
// Only the local snapshot succeeds; hub snapshot can fail without changing
|
|
564
|
+
// the outcome (local is the loser when hub wins).
|
|
565
|
+
agent = failClosedAgent(
|
|
566
|
+
async (_c, reason) => (reason === 'pre-sync-local' ? 'ts-local' : null),
|
|
567
|
+
conflicts
|
|
568
|
+
);
|
|
569
|
+
await agent.reconcile();
|
|
570
|
+
|
|
571
|
+
expect(readFileSync(paths().html, 'utf8')).toBe('<button>hub-newer</button>');
|
|
572
|
+
expect(conflicts[0].winner).toBe('hub');
|
|
573
|
+
expect(conflicts[0].snapshotFailed).toBeUndefined();
|
|
574
|
+
});
|
|
575
|
+
});
|
|
@@ -12,8 +12,10 @@ import {
|
|
|
12
12
|
applyAnnotationsToDoc,
|
|
13
13
|
applyCommentsToDoc,
|
|
14
14
|
applyHtmlToDoc,
|
|
15
|
+
bodyEditAtFromDoc,
|
|
15
16
|
commentsFromDoc,
|
|
16
17
|
htmlFromDoc,
|
|
18
|
+
stampBodyEdit,
|
|
17
19
|
Y_SYNC_TYPES,
|
|
18
20
|
} from '../sync/codec.ts';
|
|
19
21
|
|
|
@@ -163,3 +165,66 @@ describe('Annotations codec', () => {
|
|
|
163
165
|
expect(doc.getMap<string>(Y_TYPES.annotations).get('svg')).toBe('<svg>x</svg>');
|
|
164
166
|
});
|
|
165
167
|
});
|
|
168
|
+
|
|
169
|
+
// syncMeta lane — DDR-102. The doc-side body-edit stamp the cold-start
|
|
170
|
+
// newest-wins decision reads. Dedicated Y.Map lane because meta's
|
|
171
|
+
// `last_modified` is in META_LOCAL_KEYS (per-machine, never syncs).
|
|
172
|
+
describe('syncMeta codec (DDR-102)', () => {
|
|
173
|
+
test('bodyEditAtFromDoc returns null on a fresh doc (older-peer interop)', () => {
|
|
174
|
+
const doc = new Y.Doc();
|
|
175
|
+
expect(bodyEditAtFromDoc(doc)).toBeNull();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('stampBodyEdit → bodyEditAtFromDoc round-trip with explicit nowMs', () => {
|
|
179
|
+
const doc = new Y.Doc();
|
|
180
|
+
stampBodyEdit(doc, undefined, 1_700_000_000_000);
|
|
181
|
+
expect(bodyEditAtFromDoc(doc)).toBe(1_700_000_000_000);
|
|
182
|
+
const by = doc.getMap<unknown>(Y_SYNC_TYPES.syncMeta).get('by');
|
|
183
|
+
expect(typeof by).toBe('string');
|
|
184
|
+
expect((by as string).length).toBeGreaterThan(0);
|
|
185
|
+
expect((by as string).length).toBeLessThanOrEqual(32);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('stampBodyEdit defaults to Date.now()', () => {
|
|
189
|
+
const doc = new Y.Doc();
|
|
190
|
+
const before = Date.now();
|
|
191
|
+
stampBodyEdit(doc);
|
|
192
|
+
const after = Date.now();
|
|
193
|
+
const at = bodyEditAtFromDoc(doc);
|
|
194
|
+
expect(at).not.toBeNull();
|
|
195
|
+
expect(at as number).toBeGreaterThanOrEqual(before);
|
|
196
|
+
expect(at as number).toBeLessThanOrEqual(after);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('a hostile/garbage bodyEditAt value reads as null', () => {
|
|
200
|
+
const doc = new Y.Doc();
|
|
201
|
+
doc.getMap<unknown>(Y_SYNC_TYPES.syncMeta).set('bodyEditAt', 'not-a-number');
|
|
202
|
+
expect(bodyEditAtFromDoc(doc)).toBeNull();
|
|
203
|
+
doc.getMap<unknown>(Y_SYNC_TYPES.syncMeta).set('bodyEditAt', Number.POSITIVE_INFINITY);
|
|
204
|
+
expect(bodyEditAtFromDoc(doc)).toBeNull();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('body apply + stamp wrapped in one transaction emits ONE update', () => {
|
|
208
|
+
const doc = new Y.Doc();
|
|
209
|
+
let updates = 0;
|
|
210
|
+
doc.on('update', () => {
|
|
211
|
+
updates++;
|
|
212
|
+
});
|
|
213
|
+
const origin = { agent: 'test' };
|
|
214
|
+
doc.transact(() => {
|
|
215
|
+
applyHtmlToDoc(doc, '<div>v1</div>', origin);
|
|
216
|
+
stampBodyEdit(doc, origin, 123);
|
|
217
|
+
}, origin);
|
|
218
|
+
expect(updates).toBe(1);
|
|
219
|
+
expect(htmlFromDoc(doc)).toBe('<div>v1</div>');
|
|
220
|
+
expect(bodyEditAtFromDoc(doc)).toBe(123);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('the stamp syncs to a peer doc via update exchange', () => {
|
|
224
|
+
const a = new Y.Doc();
|
|
225
|
+
const b = new Y.Doc();
|
|
226
|
+
a.on('update', (u: Uint8Array) => Y.applyUpdate(b, u));
|
|
227
|
+
stampBodyEdit(a, undefined, 456);
|
|
228
|
+
expect(bodyEditAtFromDoc(b)).toBe(456);
|
|
229
|
+
});
|
|
230
|
+
});
|