@1agh/maude 1.0.11 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/apps/studio/acp/bridge.ts +18 -13
- package/apps/studio/acp/index.ts +43 -7
- package/apps/studio/acp/transcript-io.ts +394 -0
- package/apps/studio/acp/transcript.ts +103 -38
- package/apps/studio/annotations-layer.tsx +191 -116
- package/apps/studio/annotations-model.ts +39 -0
- package/apps/studio/annotations-sync.ts +50 -0
- package/apps/studio/api.ts +821 -55
- package/apps/studio/bin/_import-figma.mjs +57 -11
- package/apps/studio/bin/_seed-fixture.mjs +163 -0
- package/apps/studio/bin/annotate.mjs +3 -1
- package/apps/studio/bin/server-up.sh +17 -2
- package/apps/studio/canvas-edit.ts +391 -7
- package/apps/studio/canvas-imports.ts +89 -0
- package/apps/studio/canvas-lib.tsx +82 -18
- package/apps/studio/canvas-notice-message.ts +16 -0
- package/apps/studio/canvas-notifications.tsx +19 -0
- package/apps/studio/canvas-shell.tsx +57 -6
- package/apps/studio/client/app.jsx +943 -248
- package/apps/studio/client/apply-edit-request.ts +55 -0
- package/apps/studio/client/export-center.jsx +125 -67
- package/apps/studio/client/github.js +38 -1
- package/apps/studio/client/index-loader.ts +76 -0
- package/apps/studio/client/panels/CloudBar.jsx +52 -6
- package/apps/studio/client/panels/GitPanel.jsx +103 -0
- package/apps/studio/client/panels/OnboardingWizard.jsx +36 -7
- package/apps/studio/client/panels/RepoBranchSwitcher.jsx +92 -27
- package/apps/studio/client/panels/SourceConflictPanel.jsx +166 -0
- package/apps/studio/client/panels/SyncPanel.jsx +238 -4
- package/apps/studio/client/panels/TeamProjects.jsx +376 -0
- package/apps/studio/client/panels/file-deep-link-dialog.jsx +54 -0
- package/apps/studio/client/photo-knobs.jsx +3 -0
- package/apps/studio/client/report-bug.jsx +19 -1
- package/apps/studio/client/share-dialog.jsx +91 -0
- package/apps/studio/client/share-link.js +94 -0
- package/apps/studio/client/styles/3-shell-maude.css +69 -18
- package/apps/studio/client/styles/4-components.css +44 -1
- package/apps/studio/client/tree-row-menu.jsx +48 -3
- package/apps/studio/client/whats-new.jsx +26 -32
- package/apps/studio/cloud/endpoints.ts +132 -0
- package/apps/studio/collab/index.ts +4 -0
- package/apps/studio/collab/persistence.ts +137 -17
- package/apps/studio/collab/registry.ts +19 -21
- package/apps/studio/collab/room.ts +13 -2
- package/apps/studio/context.ts +59 -0
- package/apps/studio/debug-bundle.ts +13 -0
- package/apps/studio/dist/client.bundle.js +1911 -1879
- package/apps/studio/dist/runtime/.min-sizes.json +1 -0
- package/apps/studio/dist/runtime/sonner.js +1 -0
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/export-dialog.tsx +54 -0
- package/apps/studio/exporters/degraded.ts +19 -3
- package/apps/studio/exporters/ghostscript.ts +194 -0
- package/apps/studio/exporters/pdf-fonts.ts +261 -0
- package/apps/studio/exporters/pdf.ts +152 -3
- package/apps/studio/exporters/remote.ts +36 -1
- package/apps/studio/fs-watch.ts +45 -1
- package/apps/studio/http.ts +296 -19
- package/apps/studio/inspect.ts +19 -0
- package/apps/studio/managed-projects.ts +150 -0
- package/apps/studio/mem.ts +45 -9
- package/apps/studio/notifications.tsx +292 -0
- package/apps/studio/runtime-bundle.ts +2 -0
- package/apps/studio/server.ts +69 -6
- package/apps/studio/sync/accepted-cold-start.ts +225 -0
- package/apps/studio/sync/accepted-link.ts +320 -0
- package/apps/studio/sync/action-stage.ts +343 -0
- package/apps/studio/sync/agent.ts +104 -45
- package/apps/studio/sync/asset-push.ts +1 -47
- package/apps/studio/sync/cell-file-events.ts +3 -0
- package/apps/studio/sync/codec.ts +192 -34
- package/apps/studio/sync/cold-start-apply.ts +7 -0
- package/apps/studio/sync/cold-start.ts +118 -22
- package/apps/studio/sync/comment-identity.ts +68 -0
- package/apps/studio/sync/connection-state.ts +15 -1
- package/apps/studio/sync/ctl-provider.ts +15 -2
- package/apps/studio/sync/document-discovery.ts +81 -0
- package/apps/studio/sync/file-ledger.ts +117 -0
- package/apps/studio/sync/file-membership.ts +10 -2
- package/apps/studio/sync/file-plane.ts +926 -47
- package/apps/studio/sync/index.ts +1786 -36
- package/apps/studio/sync/journal-client.ts +13 -1
- package/apps/studio/sync/migrate-seed.ts +150 -22
- package/apps/studio/sync/poke.ts +4 -2
- package/apps/studio/sync/presentation.ts +311 -5
- package/apps/studio/sync/projection.ts +820 -23
- package/apps/studio/sync/repeated-module.ts +73 -0
- package/apps/studio/sync/retry-after.ts +169 -0
- package/apps/studio/sync/revision-barrier.ts +129 -0
- package/apps/studio/sync/seed-progress.ts +218 -0
- package/apps/studio/sync/seed-repair.ts +46 -0
- package/apps/studio/sync/source-merge.ts +100 -0
- package/apps/studio/sync/source-ops.ts +289 -0
- package/apps/studio/sync/source-recovery.ts +70 -0
- package/apps/studio/sync/source-validation.ts +56 -0
- package/apps/studio/sync/status.ts +201 -6
- package/apps/studio/sync/transaction-client.ts +460 -0
- package/apps/studio/sync/transport-error.ts +111 -0
- package/apps/studio/sync/writer-registry.ts +236 -0
- package/apps/studio/text-caret.ts +35 -0
- package/apps/studio/undo-hud.tsx +9 -87
- package/apps/studio/use-canvas-media-drop.tsx +4 -39
- package/apps/studio/whats-new.json +173 -0
- package/cli/bin/maude.mjs +2 -0
- package/cli/commands/codex.mjs +191 -0
- package/cli/commands/harness.mjs +1051 -0
- package/cli/commands/help.mjs +13 -0
- package/cli/lib/design-link.mjs +190 -2
- package/cli/lib/harness/capabilities.mjs +302 -0
- package/cli/lib/harness/codex-runtime.mjs +892 -0
- package/cli/lib/harness/compatibility.mjs +27 -0
- package/cli/lib/harness/discover-claude.mjs +1393 -0
- package/cli/lib/harness/managed-state.mjs +1296 -0
- package/cli/lib/harness/model.mjs +86 -0
- package/cli/lib/harness/secrets.mjs +390 -0
- package/cli/lib/harness/targets/codex.mjs +1141 -0
- package/cli/lib/harness/targets/opencode.mjs +807 -0
- package/cli/lib/harness/transaction.mjs +1099 -0
- package/cli/lib/hubs-config.mjs +35 -8
- package/cli/templates/harness/opencode/maude-projector.ts +58 -0
- package/docs/harness-capability-matrix.md +125 -0
- package/docs/harness-environment-projection.md +95 -0
- package/package.json +33 -9
- package/plugins/design/dependencies.json +3 -3
- package/plugins/design/templates/_shell.html +47 -0
- package/plugins/flow/.claude-plugin/config.schema.json +8 -0
- package/plugins/flow/dependencies.json +3 -3
- package/apps/studio/.ai/cache/_stats.json +0 -7
- package/apps/studio/bin/_agent-browser-safe.test.mjs +0 -165
- package/apps/studio/bin/_curl-local.test.mjs +0 -280
- package/apps/studio/bin/_pw-launch.test.mjs +0 -90
- package/apps/studio/bin/_smart-frames.test.mjs +0 -195
- package/apps/studio/bin/_transcribe.test.mjs +0 -80
- package/apps/studio/bun.lock +0 -928
- package/apps/studio/draw/test/animate.test.ts +0 -172
- package/apps/studio/draw/test/brush.test.ts +0 -213
- package/apps/studio/draw/test/composition.test.ts +0 -141
- package/apps/studio/draw/test/geometry.test.ts +0 -199
- package/apps/studio/draw/test/gradient.test.ts +0 -167
- package/apps/studio/draw/test/layout.test.ts +0 -120
- package/apps/studio/draw/test/morph.test.ts +0 -107
- package/apps/studio/draw/test/optimize.test.ts +0 -40
- package/apps/studio/draw/test/palette.test.ts +0 -123
- package/apps/studio/draw/test/primitives.test.ts +0 -129
- package/apps/studio/draw/test/serialize-animate.test.ts +0 -142
- package/apps/studio/draw/test/serialize.test.ts +0 -105
- package/apps/studio/figma/assets.test.ts +0 -464
- package/apps/studio/figma/client.test.ts +0 -395
- package/apps/studio/figma/codegen-client.test.ts +0 -276
- package/apps/studio/figma/codegen-fonts.test.ts +0 -103
- package/apps/studio/figma/codegen-values.test.ts +0 -179
- package/apps/studio/figma/comments-to-strokes.test.ts +0 -194
- package/apps/studio/figma/fig-decode.test.ts +0 -788
- package/apps/studio/figma/fig-differential.test.ts +0 -182
- package/apps/studio/figma/fig-translator.test.ts +0 -192
- package/apps/studio/figma/fig-vector.test.ts +0 -113
- package/apps/studio/figma/from-codegen.test.ts +0 -408
- package/apps/studio/figma/sanitize.test.ts +0 -325
- package/apps/studio/figma/tailwind-map.test.ts +0 -142
- package/apps/studio/figma/to-artboard.test.ts +0 -808
- package/apps/studio/figma/to-render.test.ts +0 -180
- package/apps/studio/figma/to-strokes-roundtrip.test.ts +0 -152
- package/apps/studio/figma/to-strokes.test.ts +0 -705
- package/apps/studio/figma/to-tokens.test.ts +0 -321
- package/apps/studio/figma/url.test.ts +0 -167
- package/apps/studio/footage/schema.test.ts +0 -287
- package/apps/studio/generation/adapters/groq.test.ts +0 -80
- package/apps/studio/generation/audio-library.test.ts +0 -95
- package/apps/studio/generation/captions.test.ts +0 -78
- package/apps/studio/generation/elevenlabs.test.ts +0 -223
- package/apps/studio/generation/gemini.test.ts +0 -350
- package/apps/studio/generation/jobs.test.ts +0 -128
- package/apps/studio/generation/keys.test.ts +0 -75
- package/apps/studio/generation/prefs.test.ts +0 -95
- package/apps/studio/generation/types.test.ts +0 -123
- package/apps/studio/generation/whisper-models.test.ts +0 -179
- package/apps/studio/test/_helpers.ts +0 -108
- package/apps/studio/test/acp-activity-endpoint.test.ts +0 -183
- package/apps/studio/test/acp-activity.test.ts +0 -154
- package/apps/studio/test/acp-ai-activity.test.ts +0 -182
- package/apps/studio/test/acp-attachment-serve.test.ts +0 -74
- package/apps/studio/test/acp-bootstrap-brief.test.ts +0 -178
- package/apps/studio/test/acp-branch-guard.test.ts +0 -123
- package/apps/studio/test/acp-bridge-lifetime.test.ts +0 -475
- package/apps/studio/test/acp-bridge.test.ts +0 -545
- package/apps/studio/test/acp-capabilities.test.ts +0 -123
- package/apps/studio/test/acp-caps-bridge.test.ts +0 -279
- package/apps/studio/test/acp-commands.test.ts +0 -119
- package/apps/studio/test/acp-elicitation-bridge.test.ts +0 -480
- package/apps/studio/test/acp-elicitation.test.ts +0 -251
- package/apps/studio/test/acp-env.test.ts +0 -95
- package/apps/studio/test/acp-mode-banner.test.ts +0 -45
- package/apps/studio/test/acp-origin-gate.test.ts +0 -160
- package/apps/studio/test/acp-permission-prompt.test.ts +0 -251
- package/apps/studio/test/acp-permission.test.ts +0 -278
- package/apps/studio/test/acp-plugin-bootstrap.test.ts +0 -89
- package/apps/studio/test/acp-session-allowed-tools.test.ts +0 -235
- package/apps/studio/test/acp-session-plugins.test.ts +0 -209
- package/apps/studio/test/acp-toolgroup.test.ts +0 -76
- package/apps/studio/test/acp-transcript-view.test.ts +0 -71
- package/apps/studio/test/acp-transcript.test.ts +0 -238
- package/apps/studio/test/acp-usage-bridge.test.ts +0 -141
- package/apps/studio/test/acp-usage.test.ts +0 -143
- package/apps/studio/test/acp-write-gate.test.ts +0 -323
- package/apps/studio/test/acp-write-scope.test.ts +0 -533
- package/apps/studio/test/active-state.test.ts +0 -186
- package/apps/studio/test/activity.test.ts +0 -189
- package/apps/studio/test/ai-activity.test.ts +0 -113
- package/apps/studio/test/annotate-write.test.ts +0 -1074
- package/apps/studio/test/annotation-strokes-command.test.ts +0 -166
- package/apps/studio/test/annotations-align.test.ts +0 -88
- package/apps/studio/test/annotations-api.test.ts +0 -145
- package/apps/studio/test/annotations-bindings.test.ts +0 -262
- package/apps/studio/test/annotations-draw-modifiers.test.ts +0 -206
- package/apps/studio/test/annotations-groups.test.ts +0 -231
- package/apps/studio/test/annotations-layer.test.ts +0 -1011
- package/apps/studio/test/annotations-roundtrip.test.ts +0 -663
- package/apps/studio/test/annotations-snap.test.ts +0 -135
- package/apps/studio/test/annotations-text-format.test.ts +0 -396
- package/apps/studio/test/artboard-activity-overlay.test.tsx +0 -56
- package/apps/studio/test/artboard-guides-overlay.test.tsx +0 -152
- package/apps/studio/test/artboard-hug-commit.test.ts +0 -36
- package/apps/studio/test/artboard-kinds.test.tsx +0 -83
- package/apps/studio/test/artboard-selection-attrs.test.ts +0 -69
- package/apps/studio/test/asset-api.test.ts +0 -149
- package/apps/studio/test/assets-s3.test.ts +0 -249
- package/apps/studio/test/binary-smoke.test.ts +0 -47
- package/apps/studio/test/boot-self-heal.test.ts +0 -87
- package/apps/studio/test/browse-posture.test.tsx +0 -107
- package/apps/studio/test/bundle-smoke.test.ts +0 -46
- package/apps/studio/test/camera-reveal.test.tsx +0 -173
- package/apps/studio/test/canvas-artifacts.test.ts +0 -125
- package/apps/studio/test/canvas-build-sandbox.test.ts +0 -69
- package/apps/studio/test/canvas-build.test.ts +0 -141
- package/apps/studio/test/canvas-create-api.test.ts +0 -676
- package/apps/studio/test/canvas-cursors.test.ts +0 -164
- package/apps/studio/test/canvas-edit.test.ts +0 -470
- package/apps/studio/test/canvas-freshness-deps.test.ts +0 -64
- package/apps/studio/test/canvas-header.test.ts +0 -127
- package/apps/studio/test/canvas-hide-chrome.test.ts +0 -88
- package/apps/studio/test/canvas-hmr-runtime.test.tsx +0 -114
- package/apps/studio/test/canvas-lib-inline.test.ts +0 -146
- package/apps/studio/test/canvas-lib-motion.test.ts +0 -131
- package/apps/studio/test/canvas-lib-resolver.test.ts +0 -111
- package/apps/studio/test/canvas-list-watch.test.ts +0 -388
- package/apps/studio/test/canvas-media-drop.test.ts +0 -187
- package/apps/studio/test/canvas-meta-api.test.ts +0 -707
- package/apps/studio/test/canvas-move-api.test.ts +0 -587
- package/apps/studio/test/canvas-origin-gate.test.ts +0 -417
- package/apps/studio/test/canvas-pipeline.test.ts +0 -180
- package/apps/studio/test/canvas-rects.test.ts +0 -198
- package/apps/studio/test/canvas-reorder.test.ts +0 -211
- package/apps/studio/test/canvas-route.test.ts +0 -179
- package/apps/studio/test/canvas-shell-base.test.ts +0 -107
- package/apps/studio/test/canvas-shell-build-error.test.ts +0 -52
- package/apps/studio/test/canvas-url.test.ts +0 -138
- package/apps/studio/test/canvas-wheel-delta.test.ts +0 -42
- package/apps/studio/test/canvas-zoom-floor.test.ts +0 -73
- package/apps/studio/test/capture-core.test.ts +0 -32
- package/apps/studio/test/capture-determinism-shape.test.ts +0 -135
- package/apps/studio/test/chat-attachments.test.ts +0 -117
- package/apps/studio/test/chat-context.test.ts +0 -129
- package/apps/studio/test/chat-markdown.test.tsx +0 -58
- package/apps/studio/test/clip-addressing.test.ts +0 -738
- package/apps/studio/test/clip-ops.test.ts +0 -922
- package/apps/studio/test/cloud-build.test.ts +0 -95
- package/apps/studio/test/cloud-connect-note.test.ts +0 -135
- package/apps/studio/test/cloud-endpoints.test.ts +0 -590
- package/apps/studio/test/cloud-history-hardening.test.ts +0 -165
- package/apps/studio/test/cloud-history-posture.test.ts +0 -230
- package/apps/studio/test/cloud-managed-save-surfaces.test.ts +0 -90
- package/apps/studio/test/cloud-renew.test.ts +0 -205
- package/apps/studio/test/cloud-session-role.test.ts +0 -161
- package/apps/studio/test/cloud-shell-surfaces.test.ts +0 -170
- package/apps/studio/test/cold-start-apply.test.ts +0 -303
- package/apps/studio/test/collab-annotations-bridge.test.ts +0 -55
- package/apps/studio/test/collab-awareness-bridge.test.ts +0 -223
- package/apps/studio/test/collab-bridge.test.ts +0 -79
- package/apps/studio/test/collab-loopback.test.ts +0 -63
- package/apps/studio/test/collab-origin-gate.test.ts +0 -323
- package/apps/studio/test/collab-protocol.test.ts +0 -146
- package/apps/studio/test/collab-readonly-gate.test.ts +0 -194
- package/apps/studio/test/collab-reseed-guard.test.ts +0 -78
- package/apps/studio/test/collab-room.test.ts +0 -188
- package/apps/studio/test/collab-session-survival.test.tsx +0 -176
- package/apps/studio/test/collab-stress.test.ts +0 -129
- package/apps/studio/test/comment-mount.test.ts +0 -97
- package/apps/studio/test/comment-relay-origin-gate.test.ts +0 -117
- package/apps/studio/test/comments-api.test.ts +0 -277
- package/apps/studio/test/comments-fs-rebroadcast.test.ts +0 -155
- package/apps/studio/test/comments-overlay.test.ts +0 -117
- package/apps/studio/test/compile-entry.test.ts +0 -133
- package/apps/studio/test/component-map.test.ts +0 -48
- package/apps/studio/test/config-projection.test.ts +0 -104
- package/apps/studio/test/config-reload.test.ts +0 -230
- package/apps/studio/test/config-version.test.ts +0 -88
- package/apps/studio/test/context-resolve-tokens.test.ts +0 -97
- package/apps/studio/test/convert-to-absolute.test.ts +0 -333
- package/apps/studio/test/credential-grammar.test.ts +0 -107
- package/apps/studio/test/csp-canvas-shell.test.ts +0 -62
- package/apps/studio/test/csrf-write-guard.test.ts +0 -141
- package/apps/studio/test/debug-bundle.test.ts +0 -105
- package/apps/studio/test/design-setup-readiness.test.ts +0 -155
- package/apps/studio/test/detach-component.test.ts +0 -94
- package/apps/studio/test/dns-rebinding-guard.test.ts +0 -101
- package/apps/studio/test/dom-selection.test.ts +0 -198
- package/apps/studio/test/dynamic-text-edit.test.ts +0 -162
- package/apps/studio/test/edit-css-occurrence.test.ts +0 -81
- package/apps/studio/test/edit-persistence.test.ts +0 -91
- package/apps/studio/test/edit-scope-api.test.ts +0 -119
- package/apps/studio/test/edit-source-command.test.ts +0 -142
- package/apps/studio/test/edit-suppress.test.ts +0 -170
- package/apps/studio/test/editing-presence.test.ts +0 -103
- package/apps/studio/test/element-resize.test.ts +0 -136
- package/apps/studio/test/element-structural-api.test.ts +0 -434
- package/apps/studio/test/element-structural-edit.test.ts +0 -750
- package/apps/studio/test/ensure-browser.test.ts +0 -92
- package/apps/studio/test/equal-spacing-detector.test.ts +0 -257
- package/apps/studio/test/export-assemble.test.ts +0 -53
- package/apps/studio/test/export-browser-lane.test.ts +0 -126
- package/apps/studio/test/export-capture-fidelity.test.ts +0 -146
- package/apps/studio/test/export-capture-hygiene.test.ts +0 -675
- package/apps/studio/test/export-center.test.tsx +0 -287
- package/apps/studio/test/export-e2e-lanes.test.ts +0 -857
- package/apps/studio/test/export-format-scope-coherence.test.ts +0 -89
- package/apps/studio/test/export-lane.test.ts +0 -245
- package/apps/studio/test/export-shim-multi-capture.test.ts +0 -83
- package/apps/studio/test/exporters/canva.test.ts +0 -63
- package/apps/studio/test/exporters/degraded-propagation.test.ts +0 -123
- package/apps/studio/test/exporters/endpoint.test.ts +0 -121
- package/apps/studio/test/exporters/history.test.ts +0 -107
- package/apps/studio/test/exporters/html.test.ts +0 -26
- package/apps/studio/test/exporters/jobs.test.ts +0 -342
- package/apps/studio/test/exporters/pdf.test.ts +0 -85
- package/apps/studio/test/exporters/png.test.ts +0 -103
- package/apps/studio/test/exporters/pptx-deck.test.ts +0 -112
- package/apps/studio/test/exporters/pptx.test.ts +0 -31
- package/apps/studio/test/exporters/pw-launch.test.ts +0 -49
- package/apps/studio/test/exporters/runtime.test.ts +0 -59
- package/apps/studio/test/exporters/scope.test.ts +0 -292
- package/apps/studio/test/exporters/svg.test.ts +0 -29
- package/apps/studio/test/exporters/unsupported-media.test.ts +0 -123
- package/apps/studio/test/exporters/zip.test.ts +0 -104
- package/apps/studio/test/fetch-asset-gate.test.ts +0 -189
- package/apps/studio/test/figjam-v3-model.test.ts +0 -342
- package/apps/studio/test/figma-explode.test.ts +0 -438
- package/apps/studio/test/figma-provenance.test.ts +0 -108
- package/apps/studio/test/figma-routes.test.ts +0 -294
- package/apps/studio/test/file-lock.test.ts +0 -84
- package/apps/studio/test/fixtures/backgrounding-claude-auth.sh +0 -12
- package/apps/studio/test/fixtures/fake-claude-auth.mjs +0 -23
- package/apps/studio/test/fixtures/figjam-v3-groups-bindings.svg +0 -1
- package/apps/studio/test/fixtures/mock-acp-agent-caps.mjs +0 -158
- package/apps/studio/test/fixtures/mock-acp-agent-commands.mjs +0 -44
- package/apps/studio/test/fixtures/mock-acp-agent-elicit-flood.mjs +0 -46
- package/apps/studio/test/fixtures/mock-acp-agent-elicit-url.mjs +0 -42
- package/apps/studio/test/fixtures/mock-acp-agent-elicit.mjs +0 -63
- package/apps/studio/test/fixtures/mock-acp-agent-permission-flood.mjs +0 -51
- package/apps/studio/test/fixtures/mock-acp-agent-permission.mjs +0 -50
- package/apps/studio/test/fixtures/mock-acp-agent-slow.mjs +0 -45
- package/apps/studio/test/fixtures/mock-acp-agent-usage.mjs +0 -56
- package/apps/studio/test/fixtures/mock-acp-agent-wedged.mjs +0 -37
- package/apps/studio/test/fixtures/mock-acp-agent-write.mjs +0 -118
- package/apps/studio/test/fixtures/mock-acp-agent.mjs +0 -69
- package/apps/studio/test/fixtures/noisy-claude-auth.mjs +0 -27
- package/apps/studio/test/fixtures/perf-canvas.mjs +0 -201
- package/apps/studio/test/fixtures/phase-20-annotations.svg +0 -1
- package/apps/studio/test/fixtures/phase-21-annotations.svg +0 -1
- package/apps/studio/test/fixtures/tiny-subset.woff2 +0 -0
- package/apps/studio/test/fixtures/video-comp-fixture.tsx +0 -82
- package/apps/studio/test/fixtures/wedged-claude-auth.sh +0 -11
- package/apps/studio/test/footage-store.test.ts +0 -100
- package/apps/studio/test/fs-mkdir-api.test.ts +0 -248
- package/apps/studio/test/fs-watch.test.ts +0 -41
- package/apps/studio/test/gemma-models.test.ts +0 -245
- package/apps/studio/test/generate-route.test.ts +0 -106
- package/apps/studio/test/git-api.test.ts +0 -0
- package/apps/studio/test/git-branches.test.ts +0 -341
- package/apps/studio/test/git-cloud-posture.test.ts +0 -59
- package/apps/studio/test/git-grouping.test.ts +0 -106
- package/apps/studio/test/git-lifecycle.test.ts +0 -100
- package/apps/studio/test/git-log-format.test.ts +0 -95
- package/apps/studio/test/git-safe-rel.test.ts +0 -132
- package/apps/studio/test/git-system-engine.test.ts +0 -135
- package/apps/studio/test/git-watch.test.ts +0 -97
- package/apps/studio/test/github-api.test.ts +0 -577
- package/apps/studio/test/grid-track-handles.test.ts +0 -160
- package/apps/studio/test/handoff-static-frames.test.ts +0 -215
- package/apps/studio/test/handoff.test.ts +0 -329
- package/apps/studio/test/history-rollback.test.ts +0 -88
- package/apps/studio/test/hmr-broadcast.test.ts +0 -236
- package/apps/studio/test/hmr-classify.test.ts +0 -87
- package/apps/studio/test/hub-link.test.ts +0 -80
- package/apps/studio/test/identity-cache.test.ts +0 -83
- package/apps/studio/test/import-asset-browser.test.ts +0 -64
- package/apps/studio/test/import-asset-route.test.ts +0 -71
- package/apps/studio/test/import-asset.test.ts +0 -427
- package/apps/studio/test/import-brand-browser.test.ts +0 -88
- package/apps/studio/test/import-brand-route.test.ts +0 -120
- package/apps/studio/test/import-brand.test.ts +0 -206
- package/apps/studio/test/import-figma.test.ts +0 -667
- package/apps/studio/test/import-tokens.test.ts +0 -722
- package/apps/studio/test/index-data-canvas-ds.test.ts +0 -97
- package/apps/studio/test/input-router.test.ts +0 -757
- package/apps/studio/test/inspect-script-syntax.test.ts +0 -53
- package/apps/studio/test/inspect-selections.test.ts +0 -219
- package/apps/studio/test/knob-props-authored.test.ts +0 -87
- package/apps/studio/test/layers-synthetic-groups.test.ts +0 -96
- package/apps/studio/test/locator.test.ts +0 -214
- package/apps/studio/test/marquee-overlay.test.ts +0 -94
- package/apps/studio/test/media-commit-chain.test.ts +0 -210
- package/apps/studio/test/mode-toggle.test.tsx +0 -226
- package/apps/studio/test/motion-sample.test.ts +0 -35
- package/apps/studio/test/move-artboards-command.test.ts +0 -108
- package/apps/studio/test/participants-chrome.test.ts +0 -65
- package/apps/studio/test/paths.test.ts +0 -88
- package/apps/studio/test/pdf-print-boxes.test.ts +0 -359
- package/apps/studio/test/peer-selection-follows-camera.test.tsx +0 -131
- package/apps/studio/test/perf-harness.ts +0 -193
- package/apps/studio/test/phase-3.6-smoke.test.ts +0 -79
- package/apps/studio/test/photo-bg-remove-validation.test.ts +0 -71
- package/apps/studio/test/photo-canvas-bundle.test.ts +0 -79
- package/apps/studio/test/photo-edit-api.test.ts +0 -201
- package/apps/studio/test/photo-filters.test.ts +0 -149
- package/apps/studio/test/photo-pipeline.test.ts +0 -106
- package/apps/studio/test/photo-taxonomy.test.ts +0 -96
- package/apps/studio/test/print-marks.test.ts +0 -113
- package/apps/studio/test/print-units.test.ts +0 -173
- package/apps/studio/test/read-annotations.test.ts +0 -727
- package/apps/studio/test/read-only-gate.test.ts +0 -188
- package/apps/studio/test/read-only-role.test.ts +0 -95
- package/apps/studio/test/readiness.test.ts +0 -337
- package/apps/studio/test/remote-ahead-behind-cache.test.ts +0 -89
- package/apps/studio/test/reorder-api.test.ts +0 -210
- package/apps/studio/test/repo-concurrency.test.ts +0 -146
- package/apps/studio/test/repo-lock.test.ts +0 -350
- package/apps/studio/test/report-proxy.test.ts +0 -125
- package/apps/studio/test/ripple.test.ts +0 -197
- package/apps/studio/test/runtime-bundle-error-mapping.test.ts +0 -43
- package/apps/studio/test/runtime-bundle.test.ts +0 -69
- package/apps/studio/test/sanitize-annotation-svg.test.ts +0 -238
- package/apps/studio/test/scaffold-design.test.ts +0 -122
- package/apps/studio/test/server-lifecycle.test.ts +0 -38
- package/apps/studio/test/session-runtime-state.test.ts +0 -226
- package/apps/studio/test/session-scope.test.ts +0 -100
- package/apps/studio/test/shared-doc-cell-pairing.test.ts +0 -642
- package/apps/studio/test/shared-doc-convergence.test.ts +0 -265
- package/apps/studio/test/shared-doc-foundation.test.ts +0 -63
- package/apps/studio/test/shared-doc-migrate.test.ts +0 -369
- package/apps/studio/test/shared-doc-projection.test.ts +0 -238
- package/apps/studio/test/shell-importmap.test.ts +0 -56
- package/apps/studio/test/sizing-mode.test.ts +0 -102
- package/apps/studio/test/slash-commands.test.ts +0 -117
- package/apps/studio/test/snap-distance-pill.test.ts +0 -68
- package/apps/studio/test/spacing-handles.test.ts +0 -138
- package/apps/studio/test/specimen-select.test.ts +0 -88
- package/apps/studio/test/sync-agent.test.ts +0 -660
- package/apps/studio/test/sync-annotations-cold-start.test.ts +0 -302
- package/apps/studio/test/sync-asset-push.test.ts +0 -931
- package/apps/studio/test/sync-atomic-write.test.ts +0 -62
- package/apps/studio/test/sync-attach-incremental.test.ts +0 -527
- package/apps/studio/test/sync-autocommit.test.ts +0 -537
- package/apps/studio/test/sync-canvas-path.test.ts +0 -200
- package/apps/studio/test/sync-cell-write-nudge.test.ts +0 -346
- package/apps/studio/test/sync-codec.test.ts +0 -230
- package/apps/studio/test/sync-cold-seed-dedup.test.ts +0 -187
- package/apps/studio/test/sync-cold-start.test.ts +0 -304
- package/apps/studio/test/sync-connect-honesty.test.ts +0 -114
- package/apps/studio/test/sync-connection-state.test.ts +0 -337
- package/apps/studio/test/sync-ctl-channel.test.ts +0 -508
- package/apps/studio/test/sync-decide-file.test.ts +0 -420
- package/apps/studio/test/sync-doc-name.test.ts +0 -281
- package/apps/studio/test/sync-echo-guard.test.ts +0 -96
- package/apps/studio/test/sync-file-ledger.test.ts +0 -334
- package/apps/studio/test/sync-file-membership.test.ts +0 -347
- package/apps/studio/test/sync-file-plane.test.ts +0 -976
- package/apps/studio/test/sync-file-pull.test.ts +0 -333
- package/apps/studio/test/sync-fresh-link-parity.test.ts +0 -267
- package/apps/studio/test/sync-fs-mirror.test.ts +0 -181
- package/apps/studio/test/sync-hardening.test.ts +0 -586
- package/apps/studio/test/sync-hub-listing.test.ts +0 -46
- package/apps/studio/test/sync-hubs-config.test.ts +0 -133
- package/apps/studio/test/sync-incident-replay.test.ts +0 -211
- package/apps/studio/test/sync-journal.test.ts +0 -176
- package/apps/studio/test/sync-meta-codec.test.ts +0 -199
- package/apps/studio/test/sync-migrate-flat-fallback.test.ts +0 -98
- package/apps/studio/test/sync-move-retirement.test.ts +0 -231
- package/apps/studio/test/sync-panel-surface.test.ts +0 -153
- package/apps/studio/test/sync-path-pull.test.ts +0 -531
- package/apps/studio/test/sync-presentation.test.ts +0 -262
- package/apps/studio/test/sync-pull-budget.test.ts +0 -169
- package/apps/studio/test/sync-remote-docs.test.ts +0 -333
- package/apps/studio/test/sync-resync-routes.test.ts +0 -168
- package/apps/studio/test/sync-runtime.test.ts +0 -1675
- package/apps/studio/test/sync-seed-defers-to-hub.test.ts +0 -83
- package/apps/studio/test/sync-settings-routes.test.ts +0 -195
- package/apps/studio/test/sync-settings.test.ts +0 -151
- package/apps/studio/test/sync-status.test.ts +0 -261
- package/apps/studio/test/sync-supervisor.test.ts +0 -262
- package/apps/studio/test/sync-tombstone-apply.test.ts +0 -111
- package/apps/studio/test/sync-trash.test.ts +0 -132
- package/apps/studio/test/sync-two-peer-discovery.test.ts +0 -343
- package/apps/studio/test/sync-untrusted.test.ts +0 -103
- package/apps/studio/test/system-endpoint.test.ts +0 -144
- package/apps/studio/test/text-editability-stamp.test.ts +0 -131
- package/apps/studio/test/timeline-comp-target.test.ts +0 -139
- package/apps/studio/test/timeline-media-cache.test.ts +0 -41
- package/apps/studio/test/timeline-parse.test.ts +0 -184
- package/apps/studio/test/timeline-scale.test.ts +0 -65
- package/apps/studio/test/timeline-snap.test.ts +0 -85
- package/apps/studio/test/tool-palette-insert-anchor.test.ts +0 -86
- package/apps/studio/test/tool-palette.test.tsx +0 -55
- package/apps/studio/test/tour-overlay.test.tsx +0 -90
- package/apps/studio/test/trusted-request-host.test.ts +0 -66
- package/apps/studio/test/undo-sequence-byte-compare.test.ts +0 -211
- package/apps/studio/test/undo-stack.test.ts +0 -244
- package/apps/studio/test/use-agent-presence.test.tsx +0 -117
- package/apps/studio/test/use-annotation-resize.test.ts +0 -402
- package/apps/studio/test/use-annotation-selection.test.tsx +0 -77
- package/apps/studio/test/use-artboard-drag.test.ts +0 -324
- package/apps/studio/test/use-canvas-activity.test.tsx +0 -206
- package/apps/studio/test/use-collab.test.ts +0 -0
- package/apps/studio/test/use-cursor-modifiers.test.ts +0 -59
- package/apps/studio/test/use-keyboard-discipline.test.ts +0 -27
- package/apps/studio/test/use-selection-set.test.tsx +0 -166
- package/apps/studio/test/use-snap-guides.test.ts +0 -271
- package/apps/studio/test/use-tool-mode.test.tsx +0 -186
- package/apps/studio/test/use-undo-stack.test.tsx +0 -223
- package/apps/studio/test/video-asset.test.ts +0 -163
- package/apps/studio/test/video-comp-fixture.test.ts +0 -50
- package/apps/studio/test/video-comp.test.ts +0 -270
- package/apps/studio/test/video-encode-lib.test.ts +0 -63
- package/apps/studio/test/video-render-bridge.test.ts +0 -171
- package/apps/studio/test/whats-new.test.ts +0 -113
- package/apps/studio/test/whisper-setup.test.ts +0 -97
- package/apps/studio/test/workspace-containment.test.ts +0 -382
- package/apps/studio/test/workspace-signin.test.ts +0 -292
- package/apps/studio/test/ws-handshake.test.ts +0 -33
- package/cli/commands/cache.test.mjs +0 -166
- package/cli/commands/design-link.test.mjs +0 -419
- package/cli/commands/design.test.mjs +0 -240
- package/cli/commands/doctor.test.mjs +0 -237
- package/cli/commands/hub-workspace.test.mjs +0 -275
- package/cli/commands/hub.test.mjs +0 -225
- package/cli/commands/kg.test.mjs +0 -142
- package/cli/commands/preflight.test.mjs +0 -46
- package/cli/lib/argv.test.mjs +0 -46
- package/cli/lib/cache.test.mjs +0 -303
- package/cli/lib/cell-plan.test.mjs +0 -225
- package/cli/lib/config-lint.test.mjs +0 -117
- package/cli/lib/ddr-to-kgai.test.mjs +0 -118
- package/cli/lib/design-ownership.test.mjs +0 -329
- package/cli/lib/fetch-asset.test.mjs +0 -213
- package/cli/lib/figma-codegen-reachability.test.mjs +0 -104
- package/cli/lib/figma-import-controls.test.mjs +0 -70
- package/cli/lib/flow-design-integration.test.mjs +0 -165
- package/cli/lib/gitignore-block.test.mjs +0 -136
- package/cli/lib/gitignore-drift.test.mjs +0 -156
- package/cli/lib/hubs-config.test.mjs +0 -165
- package/cli/lib/pkg-root.test.mjs +0 -111
- package/cli/lib/plugin-cli-reachability.test.mjs +0 -57
- package/cli/lib/plugin-name-namespace.test.mjs +0 -71
- package/cli/lib/reconstruct-toolset.test.mjs +0 -194
- package/cli/lib/stack-detect.test.mjs +0 -121
- package/cli/lib/update-check.test.mjs +0 -32
- package/cli/lib/workspace-plan.test.mjs +0 -699
|
@@ -1,1675 +0,0 @@
|
|
|
1
|
-
// Sync runtime wiring tests — Phase 9 Task 4.
|
|
2
|
-
//
|
|
3
|
-
// Uses an in-memory ProviderFactory so we don't need to start a Hocuspocus
|
|
4
|
-
// server. The agents do real Y.Doc work; the test verifies the runtime
|
|
5
|
-
// honors linkedHub config, discovers canvases, wires up agents, and
|
|
6
|
-
// dispatches fs events through the bus correctly.
|
|
7
|
-
|
|
8
|
-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
9
|
-
import {
|
|
10
|
-
chmodSync,
|
|
11
|
-
existsSync,
|
|
12
|
-
mkdirSync,
|
|
13
|
-
mkdtempSync,
|
|
14
|
-
readdirSync,
|
|
15
|
-
readFileSync,
|
|
16
|
-
rmSync,
|
|
17
|
-
writeFileSync,
|
|
18
|
-
} from 'node:fs';
|
|
19
|
-
import { tmpdir } from 'node:os';
|
|
20
|
-
import { join } from 'node:path';
|
|
21
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
22
|
-
import * as Y from 'yjs';
|
|
23
|
-
|
|
24
|
-
import { Y_TYPES } from '../collab/persistence.ts';
|
|
25
|
-
import { createRegistry } from '../collab/registry.ts';
|
|
26
|
-
import type { RoomCallbacks } from '../collab/room.ts';
|
|
27
|
-
import type { Context, DevServerConfig } from '../context.ts';
|
|
28
|
-
import { createBus } from '../context.ts';
|
|
29
|
-
import { createConnectionMonitor } from '../sync/connection-state.ts';
|
|
30
|
-
import {
|
|
31
|
-
type AwarenessRegistry,
|
|
32
|
-
buildNoSyncablePayload,
|
|
33
|
-
classifyAuthFailure,
|
|
34
|
-
createSyncRuntime,
|
|
35
|
-
discoverCanvases,
|
|
36
|
-
type SyncProvider,
|
|
37
|
-
scanCanvases,
|
|
38
|
-
toWsUrl,
|
|
39
|
-
validExpiry,
|
|
40
|
-
} from '../sync/index.ts';
|
|
41
|
-
import { createSyncStatusStore } from '../sync/status.ts';
|
|
42
|
-
|
|
43
|
-
let dir: string;
|
|
44
|
-
let cfgPathEnv: string | undefined;
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
dir = mkdtempSync(join(tmpdir(), 'sync-runtime-'));
|
|
48
|
-
cfgPathEnv = process.env.HUBS_CONFIG_PATH;
|
|
49
|
-
// Point hubs.json to a temp file we control.
|
|
50
|
-
process.env.HUBS_CONFIG_PATH = join(dir, 'hubs.json');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(() => {
|
|
54
|
-
// Node's process.env stringifies on assignment; assigning undefined yields
|
|
55
|
-
// the literal string "undefined". delete is the correct restoration.
|
|
56
|
-
if (cfgPathEnv === undefined) delete process.env.HUBS_CONFIG_PATH;
|
|
57
|
-
else process.env.HUBS_CONFIG_PATH = cfgPathEnv;
|
|
58
|
-
rmSync(dir, { recursive: true, force: true });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
function writeHubsConfig(url: string, token: string): void {
|
|
62
|
-
const cfgPath = process.env.HUBS_CONFIG_PATH;
|
|
63
|
-
if (!cfgPath) throw new Error('HUBS_CONFIG_PATH not set by beforeEach');
|
|
64
|
-
writeFileSync(cfgPath, JSON.stringify({ hubs: { [url]: { token, linkedAt: 1 } } }));
|
|
65
|
-
// Match the CLI's saveHubsConfig mode so the DDR-054 §2h mode-warning
|
|
66
|
-
// doesn't fire on every test.
|
|
67
|
-
chmodSync(cfgPath, 0o600);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function makeCtx(linkedHub?: DevServerConfig['linkedHub'], canvasOrigin?: string): Context {
|
|
71
|
-
// Minimal Context — only the fields the sync runtime touches.
|
|
72
|
-
const designRoot = join(dir, 'design');
|
|
73
|
-
mkdirSync(join(designRoot, 'ui'), { recursive: true });
|
|
74
|
-
mkdirSync(join(designRoot, '_comments'), { recursive: true });
|
|
75
|
-
return {
|
|
76
|
-
// T3 (9.1-B) — `canvasOrigin` set === the CSP/sandbox split is active
|
|
77
|
-
// (MAUDE_CANVAS_ORIGIN_SPLIT=1). The `.tsx` sync opt-in is gated on it.
|
|
78
|
-
canvasOrigin,
|
|
79
|
-
cfg: {
|
|
80
|
-
name: 'test',
|
|
81
|
-
projectLabel: null,
|
|
82
|
-
designRoot: 'design',
|
|
83
|
-
canvasGroups: [{ label: 'Canvases', path: 'ui' }],
|
|
84
|
-
rootClass: 'app',
|
|
85
|
-
themeDefault: 'dark',
|
|
86
|
-
tokensCssRel: 'system/colors.css',
|
|
87
|
-
teamAccentDefault: null,
|
|
88
|
-
handoffTargets: [],
|
|
89
|
-
newCanvasDir: 'ui',
|
|
90
|
-
newComponentDir: 'ui/components',
|
|
91
|
-
linkedHub,
|
|
92
|
-
_source: 'defaults',
|
|
93
|
-
},
|
|
94
|
-
projectLabel: 'test',
|
|
95
|
-
paths: {
|
|
96
|
-
repoRoot: dir,
|
|
97
|
-
designRel: 'design',
|
|
98
|
-
designRoot,
|
|
99
|
-
serverInfoFile: join(designRoot, '_server.json'),
|
|
100
|
-
activeFile: join(designRoot, '_active.json'),
|
|
101
|
-
commentsDir: join(designRoot, '_comments'),
|
|
102
|
-
canvasStateDir: join(designRoot, '_canvas-state'),
|
|
103
|
-
historyDir: join(designRoot, '_history'),
|
|
104
|
-
tokensUrlRel: 'design/system/colors.css',
|
|
105
|
-
systemDirRel: 'system',
|
|
106
|
-
},
|
|
107
|
-
bus: createBus(),
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function inMemoryProviderFactory(): {
|
|
112
|
-
factory: (args: { url: string; token: string; documentName: string }) => SyncProvider;
|
|
113
|
-
peerOf: (slug: string) => Y.Doc;
|
|
114
|
-
} {
|
|
115
|
-
// Map of slug -> { local, peer } Y.Docs cross-linked via applyUpdate.
|
|
116
|
-
const peers = new Map<string, { local: Y.Doc; peer: Y.Doc }>();
|
|
117
|
-
const TRANSPORT = Symbol('test-transport');
|
|
118
|
-
|
|
119
|
-
function factory(args: {
|
|
120
|
-
url: string;
|
|
121
|
-
token: string;
|
|
122
|
-
documentName: string;
|
|
123
|
-
document?: Y.Doc;
|
|
124
|
-
}): SyncProvider {
|
|
125
|
-
// Phase 9.2 (DDR-064): when the runtime injects a doc (sharedDoc ON), the
|
|
126
|
-
// provider MUST attach to it — that's the whole point of convergence. The
|
|
127
|
-
// peer is a second doc cross-linked through a mock transport, modelling
|
|
128
|
-
// "another machine on the hub". We own `local` only when we created it, so
|
|
129
|
-
// we don't destroy the registry-owned shared doc on teardown.
|
|
130
|
-
const ownsLocal = !args.document;
|
|
131
|
-
const local = args.document ?? new Y.Doc();
|
|
132
|
-
const peer = new Y.Doc();
|
|
133
|
-
local.on('update', (update: Uint8Array, origin: unknown) => {
|
|
134
|
-
if (origin === TRANSPORT) return;
|
|
135
|
-
Y.applyUpdate(peer, update, TRANSPORT);
|
|
136
|
-
});
|
|
137
|
-
peer.on('update', (update: Uint8Array, origin: unknown) => {
|
|
138
|
-
if (origin === TRANSPORT) return;
|
|
139
|
-
Y.applyUpdate(local, update, TRANSPORT);
|
|
140
|
-
});
|
|
141
|
-
peers.set(args.documentName, { local, peer });
|
|
142
|
-
return {
|
|
143
|
-
document: local,
|
|
144
|
-
awareness: new Awareness(local),
|
|
145
|
-
async onceSynced() {
|
|
146
|
-
// Synced immediately for the in-memory pair.
|
|
147
|
-
},
|
|
148
|
-
destroy() {
|
|
149
|
-
if (ownsLocal) local.destroy();
|
|
150
|
-
peer.destroy();
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
factory,
|
|
157
|
-
peerOf(slug: string): Y.Doc {
|
|
158
|
-
const entry = peers.get(slug);
|
|
159
|
-
if (!entry) throw new Error(`no provider for slug ${slug}`);
|
|
160
|
-
return entry.peer;
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
describe('createSyncRuntime', () => {
|
|
166
|
-
test('returns null when linkedHub is absent (solo mode)', () => {
|
|
167
|
-
const ctx = makeCtx(undefined);
|
|
168
|
-
expect(createSyncRuntime(ctx)).toBeNull();
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test('returns null when token is missing from hubs.json', () => {
|
|
172
|
-
const ctx = makeCtx({ url: 'https://hub.example.com', linkedAt: 1 });
|
|
173
|
-
// No hubs.json written — token lookup returns null.
|
|
174
|
-
expect(createSyncRuntime(ctx)).toBeNull();
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('starts agents for each discovered canvas', async () => {
|
|
178
|
-
const url = 'https://hub.example.com';
|
|
179
|
-
writeHubsConfig(url, 'mau_test');
|
|
180
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
181
|
-
|
|
182
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
183
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'modal.html'), '<dialog>x</dialog>');
|
|
184
|
-
|
|
185
|
-
const { factory } = inMemoryProviderFactory();
|
|
186
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory });
|
|
187
|
-
expect(runtime).not.toBeNull();
|
|
188
|
-
|
|
189
|
-
await runtime?.start();
|
|
190
|
-
expect(runtime?.size()).toBe(2);
|
|
191
|
-
expect(runtime?.agentFor('ui-screen')).toBeDefined();
|
|
192
|
-
expect(runtime?.agentFor('ui-modal')).toBeDefined();
|
|
193
|
-
|
|
194
|
-
await runtime?.stop();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('9.1-D: TSX-only project surfaces zero-syncable loudly (no silent no-op)', async () => {
|
|
198
|
-
const url = 'https://hub.example.com';
|
|
199
|
-
writeHubsConfig(url, 'mau_test');
|
|
200
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
201
|
-
|
|
202
|
-
// Real (TSX-only) project: discovery admits .html only, so these don't sync.
|
|
203
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export default () => null;');
|
|
204
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'modal.tsx'), 'export default () => null;');
|
|
205
|
-
|
|
206
|
-
const events: unknown[] = [];
|
|
207
|
-
ctx.bus.on('sync:status', (p) => events.push(p));
|
|
208
|
-
|
|
209
|
-
const { factory } = inMemoryProviderFactory();
|
|
210
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory });
|
|
211
|
-
await runtime?.start();
|
|
212
|
-
|
|
213
|
-
// No agents — but the state is now LOUD, not silent.
|
|
214
|
-
expect(runtime?.size()).toBe(0);
|
|
215
|
-
|
|
216
|
-
const syncFile = join(ctx.paths.designRoot, '_sync.json');
|
|
217
|
-
expect(existsSync(syncFile)).toBe(true);
|
|
218
|
-
const payload = JSON.parse(readFileSync(syncFile, 'utf8'));
|
|
219
|
-
expect(payload.notSyncable).toBe(true);
|
|
220
|
-
expect(payload.tsxCount).toBe(2);
|
|
221
|
-
expect(payload.canvases).toBe(0);
|
|
222
|
-
expect(payload.url).toBe(url);
|
|
223
|
-
expect(payload.reason).toContain('DDR-060');
|
|
224
|
-
|
|
225
|
-
// The browser banner gets the same payload over the bus.
|
|
226
|
-
expect(events).toHaveLength(1);
|
|
227
|
-
expect((events[0] as { notSyncable?: boolean }).notSyncable).toBe(true);
|
|
228
|
-
|
|
229
|
-
await runtime?.stop();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
test('adopt mode: pushes local disk state up to the hub on first sync', async () => {
|
|
233
|
-
const url = 'https://hub.example.com';
|
|
234
|
-
writeHubsConfig(url, 'mau_test');
|
|
235
|
-
const ctx = makeCtx({ url, linkedAt: 1, adopt: true });
|
|
236
|
-
|
|
237
|
-
writeFileSync(
|
|
238
|
-
join(ctx.paths.designRoot, 'ui', 'screen.html'),
|
|
239
|
-
'<button>local-bootstrap</button>'
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
const { factory, peerOf } = inMemoryProviderFactory();
|
|
243
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory });
|
|
244
|
-
await runtime?.start();
|
|
245
|
-
|
|
246
|
-
// Reconcile fires after onceSynced() resolves — give one tick.
|
|
247
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
248
|
-
|
|
249
|
-
expect(peerOf('ui-screen').getText('html').toString()).toBe('<button>local-bootstrap</button>');
|
|
250
|
-
await runtime?.stop();
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test('bus fs:any event dispatches through the agent', async () => {
|
|
254
|
-
const url = 'https://hub.example.com';
|
|
255
|
-
writeHubsConfig(url, 'mau_test');
|
|
256
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
257
|
-
|
|
258
|
-
const htmlPath = join(ctx.paths.designRoot, 'ui', 'screen.html');
|
|
259
|
-
writeFileSync(htmlPath, '');
|
|
260
|
-
|
|
261
|
-
const { factory, peerOf } = inMemoryProviderFactory();
|
|
262
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory });
|
|
263
|
-
await runtime?.start();
|
|
264
|
-
|
|
265
|
-
// Simulate a local edit: write to disk, then fire the bus event the
|
|
266
|
-
// existing fs-watch.ts would emit.
|
|
267
|
-
writeFileSync(htmlPath, '<button>local</button>');
|
|
268
|
-
ctx.bus.emit('fs:any', 'ui/screen.html');
|
|
269
|
-
|
|
270
|
-
// Wait for fs-mirror's 250ms quiet window + agent flush slack.
|
|
271
|
-
await new Promise((res) => setTimeout(res, 400));
|
|
272
|
-
|
|
273
|
-
expect(peerOf('ui-screen').getText('html').toString()).toBe('<button>local</button>');
|
|
274
|
-
await runtime?.stop();
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
test('attaches each provider awareness to the registry and detaches on stop', async () => {
|
|
278
|
-
const url = 'https://hub.example.com';
|
|
279
|
-
writeHubsConfig(url, 'mau_test');
|
|
280
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
281
|
-
|
|
282
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
283
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'modal.html'), '<dialog>x</dialog>');
|
|
284
|
-
|
|
285
|
-
const attached: string[] = [];
|
|
286
|
-
let detachCount = 0;
|
|
287
|
-
const registry: AwarenessRegistry = {
|
|
288
|
-
attachHubAwareness(slug, _awareness) {
|
|
289
|
-
attached.push(slug);
|
|
290
|
-
return () => {
|
|
291
|
-
detachCount++;
|
|
292
|
-
};
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const { factory } = inMemoryProviderFactory();
|
|
297
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
298
|
-
await runtime?.start();
|
|
299
|
-
|
|
300
|
-
expect(attached.sort()).toEqual(['ui-modal', 'ui-screen']);
|
|
301
|
-
|
|
302
|
-
await runtime?.stop();
|
|
303
|
-
expect(detachCount).toBe(2);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test('Task 8: provider going offline drives the status to offline + surfaces queued edits', async () => {
|
|
307
|
-
const url = 'https://hub.example.com';
|
|
308
|
-
writeHubsConfig(url, 'mau_test');
|
|
309
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
310
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
311
|
-
|
|
312
|
-
// Provider stub that exposes onStatus so the test can drive WS transitions.
|
|
313
|
-
let emitStatus: ((s: 'connected' | 'connecting' | 'disconnected') => void) | null = null;
|
|
314
|
-
const doc = new Y.Doc();
|
|
315
|
-
const factory = () => ({
|
|
316
|
-
document: doc,
|
|
317
|
-
onStatus(cb: (s: 'connected' | 'connecting' | 'disconnected') => void) {
|
|
318
|
-
emitStatus = cb;
|
|
319
|
-
return () => {
|
|
320
|
-
emitStatus = null;
|
|
321
|
-
};
|
|
322
|
-
},
|
|
323
|
-
async onceSynced() {},
|
|
324
|
-
destroy() {
|
|
325
|
-
doc.destroy();
|
|
326
|
-
},
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// Fake-timer monitor so the 30s grace window fires deterministically.
|
|
330
|
-
let nowMs = 1_000;
|
|
331
|
-
const timers: Array<{ fireAt: number; cb: () => void }> = [];
|
|
332
|
-
const monitor = createConnectionMonitor({
|
|
333
|
-
graceMs: 30_000,
|
|
334
|
-
now: () => nowMs,
|
|
335
|
-
setTimer: (cb, ms) => {
|
|
336
|
-
const t = { fireAt: nowMs + ms, cb };
|
|
337
|
-
timers.push(t);
|
|
338
|
-
return t as unknown as ReturnType<typeof setTimeout>;
|
|
339
|
-
},
|
|
340
|
-
clearTimer: (h) => {
|
|
341
|
-
const i = timers.indexOf(h as unknown as { fireAt: number; cb: () => void });
|
|
342
|
-
if (i >= 0) timers.splice(i, 1);
|
|
343
|
-
},
|
|
344
|
-
onChange: (snap) => store.update(snap),
|
|
345
|
-
});
|
|
346
|
-
const writes: import('../sync/status.ts').SyncStatusPayload[] = [];
|
|
347
|
-
const store = createSyncStatusStore({
|
|
348
|
-
url,
|
|
349
|
-
canvases: 1,
|
|
350
|
-
write: (p) => writes.push(p),
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
const runtime = createSyncRuntime(ctx, {
|
|
354
|
-
providerFactory: factory,
|
|
355
|
-
connectionMonitor: monitor,
|
|
356
|
-
statusStore: store,
|
|
357
|
-
});
|
|
358
|
-
await runtime?.start();
|
|
359
|
-
|
|
360
|
-
// Connected → online.
|
|
361
|
-
emitStatus?.('connected');
|
|
362
|
-
expect(runtime?.status()?.state).toBe('online');
|
|
363
|
-
|
|
364
|
-
// Disconnect, advance past the grace window → offline.
|
|
365
|
-
emitStatus?.('disconnected');
|
|
366
|
-
nowMs += 31_000;
|
|
367
|
-
for (const t of [...timers]) {
|
|
368
|
-
if (t.fireAt <= nowMs) {
|
|
369
|
-
timers.splice(timers.indexOf(t), 1);
|
|
370
|
-
t.cb();
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
const offlineStatus = runtime?.status();
|
|
374
|
-
expect(offlineStatus?.state).toBe('offline');
|
|
375
|
-
expect(offlineStatus?.url).toBe(url);
|
|
376
|
-
expect(offlineStatus?.offlineSince).not.toBeNull();
|
|
377
|
-
// _sync.json mirror got the offline payload too.
|
|
378
|
-
expect(writes.at(-1)?.state).toBe('offline');
|
|
379
|
-
|
|
380
|
-
// Reconnect → back online with a green flash.
|
|
381
|
-
emitStatus?.('connected');
|
|
382
|
-
expect(runtime?.status()?.state).toBe('online');
|
|
383
|
-
expect(runtime?.status()?.flash).toBe('synced');
|
|
384
|
-
|
|
385
|
-
await runtime?.stop();
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
test('writes _sync.json on a clean fast connect (regression: status must not read "idle" while sync is healthy)', async () => {
|
|
389
|
-
const url = 'https://hub.example.com';
|
|
390
|
-
writeHubsConfig(url, 'mau_test');
|
|
391
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
392
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
393
|
-
|
|
394
|
-
// Provider that — like the real wrapper after the fix — reports its current
|
|
395
|
-
// status the instant a subscriber attaches, and is already synced. No later
|
|
396
|
-
// WS *transition* fires (the monitor starts 'online', so a 'connected' note
|
|
397
|
-
// is a no-op), so the only thing that writes `_sync.json` is the runtime's
|
|
398
|
-
// initial status persist. Before the fix this left the file absent and
|
|
399
|
-
// `maude design status` reported "idle / sync agent not running".
|
|
400
|
-
const doc = new Y.Doc();
|
|
401
|
-
const factory = () => ({
|
|
402
|
-
document: doc,
|
|
403
|
-
onStatus(cb: (s: 'connected' | 'connecting' | 'disconnected') => void) {
|
|
404
|
-
cb('connected');
|
|
405
|
-
return () => {};
|
|
406
|
-
},
|
|
407
|
-
async onceSynced() {},
|
|
408
|
-
destroy() {
|
|
409
|
-
doc.destroy();
|
|
410
|
-
},
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory });
|
|
414
|
-
await runtime?.start();
|
|
415
|
-
|
|
416
|
-
// Live status reflects an online agent...
|
|
417
|
-
expect(runtime?.status()?.state).toBe('online');
|
|
418
|
-
// ...and it has been persisted to _sync.json (what `maude design status` reads).
|
|
419
|
-
const syncFile = join(ctx.paths.designRoot, '_sync.json');
|
|
420
|
-
expect(existsSync(syncFile)).toBe(true);
|
|
421
|
-
const payload = JSON.parse(readFileSync(syncFile, 'utf8'));
|
|
422
|
-
expect(payload.state).toBe('online');
|
|
423
|
-
expect(payload.canvases).toBe(1);
|
|
424
|
-
expect(payload.notSyncable).toBeUndefined();
|
|
425
|
-
|
|
426
|
-
await runtime?.stop();
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
test('DDR-102: reconcile over divergent local content records a diverged conflict + snapshots both sides', async () => {
|
|
430
|
-
const url = 'https://hub.example.com';
|
|
431
|
-
writeHubsConfig(url, 'mau_test');
|
|
432
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
433
|
-
// Local disk has divergent, non-empty content (and no journal — divergence).
|
|
434
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>LOCAL EDIT</button>');
|
|
435
|
-
|
|
436
|
-
// Provider whose doc already carries different hub state. No syncMeta
|
|
437
|
-
// stamp (older peer) → newest-wins falls back to hub.
|
|
438
|
-
const factory = () => {
|
|
439
|
-
const document = new Y.Doc();
|
|
440
|
-
document.getText('html').insert(0, '<button>HUB STATE</button>');
|
|
441
|
-
return {
|
|
442
|
-
document,
|
|
443
|
-
async onceSynced() {},
|
|
444
|
-
destroy() {
|
|
445
|
-
document.destroy();
|
|
446
|
-
},
|
|
447
|
-
};
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory });
|
|
451
|
-
await runtime?.start();
|
|
452
|
-
// Reconcile fires after onceSynced resolves.
|
|
453
|
-
await new Promise((res) => setTimeout(res, 20));
|
|
454
|
-
|
|
455
|
-
const status = runtime?.status();
|
|
456
|
-
expect(status?.conflicts.length).toBeGreaterThanOrEqual(1);
|
|
457
|
-
const conflict = status?.conflicts[0];
|
|
458
|
-
expect(conflict?.kind).toBe('cold-start-diverged');
|
|
459
|
-
expect(conflict?.winner).toBe('hub');
|
|
460
|
-
// Both pre-resolution versions were snapshotted to _history/<slug>/.
|
|
461
|
-
expect(conflict?.snapshots?.local).toBeDefined();
|
|
462
|
-
expect(conflict?.snapshots?.hub).toBeDefined();
|
|
463
|
-
const historyDir = join(ctx.paths.historyDir, 'ui-screen');
|
|
464
|
-
const blobs = readdirSync(historyDir).filter((f) => f.endsWith('.html'));
|
|
465
|
-
expect(blobs.length).toBe(2);
|
|
466
|
-
// The loser (local) is recoverable byte-identical from its snapshot.
|
|
467
|
-
const metas = readdirSync(historyDir).filter((f) => f.endsWith('.json'));
|
|
468
|
-
const snapshotContents = blobs.map((f) => readFileSync(join(historyDir, f), 'utf8'));
|
|
469
|
-
expect(snapshotContents).toContain('<button>LOCAL EDIT</button>');
|
|
470
|
-
expect(snapshotContents).toContain('<button>HUB STATE</button>');
|
|
471
|
-
expect(metas.length).toBe(2);
|
|
472
|
-
// Hub won → disk now carries hub state.
|
|
473
|
-
expect(readFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), 'utf8')).toBe(
|
|
474
|
-
'<button>HUB STATE</button>'
|
|
475
|
-
);
|
|
476
|
-
await runtime?.stop();
|
|
477
|
-
});
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
// Phase 9.2 (DDR-064) — the convergence core: ONE shared Y.Doc per canvas, the
|
|
481
|
-
// hub provider attached to it instead of a fresh doc. These prove (Task 3) that
|
|
482
|
-
// browser↔hub propagation flows through the single doc with the in-process
|
|
483
|
-
// relay RETIRED, and (Task 3 lifecycle) that a provider-pinned room survives the
|
|
484
|
-
// last-browser-leaves drop. Flag-OFF behavior is covered by every other test in
|
|
485
|
-
// this file running with `ctx.sharedDoc` unset.
|
|
486
|
-
describe('shared-doc convergence (MAUDE_SHARED_DOC ON)', () => {
|
|
487
|
-
function noopCallbacks(): RoomCallbacks {
|
|
488
|
-
return { async seed() {}, async persistJson() {}, async persistBinary() {} };
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/** The real registry wrapped to COUNT relay calls, so a test can assert the
|
|
492
|
-
* wholesale syncRoomFrom* clobber path was never used under sharedDoc. All
|
|
493
|
-
* other methods delegate to the real registry (closures over its state). */
|
|
494
|
-
function countingRegistry() {
|
|
495
|
-
const real = createRegistry(noopCallbacks());
|
|
496
|
-
let relayCalls = 0;
|
|
497
|
-
let awarenessAttaches = 0;
|
|
498
|
-
const wrapped: AwarenessRegistry & {
|
|
499
|
-
getDoc(slug: string): Y.Doc;
|
|
500
|
-
peek: typeof real.peek;
|
|
501
|
-
get: typeof real.get;
|
|
502
|
-
drop: typeof real.drop;
|
|
503
|
-
destroyAll: typeof real.destroyAll;
|
|
504
|
-
relayCalls(): number;
|
|
505
|
-
awarenessAttaches(): number;
|
|
506
|
-
} = {
|
|
507
|
-
getDoc: (slug) => real.getDoc(slug),
|
|
508
|
-
peek: (slug) => real.peek(slug),
|
|
509
|
-
get: (slug) => real.get(slug),
|
|
510
|
-
drop: (slug) => real.drop(slug),
|
|
511
|
-
destroyAll: () => real.destroyAll(),
|
|
512
|
-
pin: (slug) => real.pin(slug),
|
|
513
|
-
unpin: (slug) => real.unpin(slug),
|
|
514
|
-
attachHubAwareness: (slug, awareness) => {
|
|
515
|
-
awarenessAttaches++;
|
|
516
|
-
return real.attachHubAwareness(slug, awareness);
|
|
517
|
-
},
|
|
518
|
-
syncRoomFromComments: (slug, comments) => {
|
|
519
|
-
relayCalls++;
|
|
520
|
-
real.syncRoomFromComments(slug, comments);
|
|
521
|
-
},
|
|
522
|
-
syncRoomFromAnnotations: (slug, svg) => {
|
|
523
|
-
relayCalls++;
|
|
524
|
-
real.syncRoomFromAnnotations(slug, svg);
|
|
525
|
-
},
|
|
526
|
-
relayCalls: () => relayCalls,
|
|
527
|
-
awarenessAttaches: () => awarenessAttaches,
|
|
528
|
-
};
|
|
529
|
-
return wrapped;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
test('browser edit on the shared doc reaches the hub peer with NO relay', async () => {
|
|
533
|
-
const url = 'https://hub.example.com';
|
|
534
|
-
writeHubsConfig(url, 'mau_test');
|
|
535
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
536
|
-
ctx.sharedDoc = true; // flag ON
|
|
537
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
538
|
-
|
|
539
|
-
const registry = countingRegistry();
|
|
540
|
-
const { factory, peerOf } = inMemoryProviderFactory();
|
|
541
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
542
|
-
await runtime?.start();
|
|
543
|
-
|
|
544
|
-
// The provider is attached to the SAME doc the registry hands the browser.
|
|
545
|
-
const shared = registry.getDoc('ui-screen');
|
|
546
|
-
// Browser-style edit — a doc mutation whose origin is NOT the agent origin
|
|
547
|
-
// (exactly what a browser conn or the inspector-write path produces).
|
|
548
|
-
shared.getArray(Y_TYPES.comments).push([{ id: 'c1', text: 'hi' }]);
|
|
549
|
-
|
|
550
|
-
// Converges to the hub peer through the provider transport — one doc.
|
|
551
|
-
expect(peerOf('ui-screen').getArray(Y_TYPES.comments).toArray()).toEqual([
|
|
552
|
-
{ id: 'c1', text: 'hi' },
|
|
553
|
-
]);
|
|
554
|
-
// And the wholesale relay (the Phase 9.1 clobber path) was NEVER invoked.
|
|
555
|
-
expect(registry.relayCalls()).toBe(0);
|
|
556
|
-
|
|
557
|
-
await runtime?.stop();
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
test('hub-pushed edit lands in the shared doc (provider applies to the room doc)', async () => {
|
|
561
|
-
const url = 'https://hub.example.com';
|
|
562
|
-
writeHubsConfig(url, 'mau_test');
|
|
563
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
564
|
-
ctx.sharedDoc = true;
|
|
565
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
566
|
-
|
|
567
|
-
const registry = countingRegistry();
|
|
568
|
-
const { factory, peerOf } = inMemoryProviderFactory();
|
|
569
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
570
|
-
await runtime?.start();
|
|
571
|
-
|
|
572
|
-
// Another machine on the hub adds a comment → reaches our shared doc.
|
|
573
|
-
peerOf('ui-screen')
|
|
574
|
-
.getArray(Y_TYPES.comments)
|
|
575
|
-
.push([{ id: 'h1', text: 'from peer' }]);
|
|
576
|
-
expect(registry.getDoc('ui-screen').getArray(Y_TYPES.comments).toArray()).toEqual([
|
|
577
|
-
{ id: 'h1', text: 'from peer' },
|
|
578
|
-
]);
|
|
579
|
-
expect(registry.relayCalls()).toBe(0);
|
|
580
|
-
|
|
581
|
-
await runtime?.stop();
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
test('two-way merge: concurrent comment + annotation on both sides converge (no clobber)', async () => {
|
|
585
|
-
const url = 'https://hub.example.com';
|
|
586
|
-
writeHubsConfig(url, 'mau_test');
|
|
587
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
588
|
-
ctx.sharedDoc = true;
|
|
589
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
590
|
-
|
|
591
|
-
const registry = countingRegistry();
|
|
592
|
-
const { factory, peerOf } = inMemoryProviderFactory();
|
|
593
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
594
|
-
await runtime?.start();
|
|
595
|
-
|
|
596
|
-
const shared = registry.getDoc('ui-screen');
|
|
597
|
-
const peer = peerOf('ui-screen');
|
|
598
|
-
// Local adds a comment; the hub peer concurrently sets an annotation.
|
|
599
|
-
shared.getArray(Y_TYPES.comments).push([{ id: 'local-c', text: 'mine' }]);
|
|
600
|
-
peer.getMap(Y_TYPES.annotations).set('svg', '<svg><rect/></svg>');
|
|
601
|
-
|
|
602
|
-
// Both survive on both replicas — the CRDT merged, nothing clobbered.
|
|
603
|
-
expect(shared.getArray(Y_TYPES.comments).toArray()).toEqual([{ id: 'local-c', text: 'mine' }]);
|
|
604
|
-
expect(shared.getMap(Y_TYPES.annotations).get('svg')).toBe('<svg><rect/></svg>');
|
|
605
|
-
expect(peer.getArray(Y_TYPES.comments).toArray()).toEqual([{ id: 'local-c', text: 'mine' }]);
|
|
606
|
-
expect(peer.getMap(Y_TYPES.annotations).get('svg')).toBe('<svg><rect/></svg>');
|
|
607
|
-
expect(registry.relayCalls()).toBe(0);
|
|
608
|
-
|
|
609
|
-
await runtime?.stop();
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
test('a provider-pinned shared room survives the last-browser-leaves drop, released on stop', async () => {
|
|
613
|
-
const url = 'https://hub.example.com';
|
|
614
|
-
writeHubsConfig(url, 'mau_test');
|
|
615
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
616
|
-
ctx.sharedDoc = true;
|
|
617
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
618
|
-
|
|
619
|
-
const registry = countingRegistry();
|
|
620
|
-
const { factory } = inMemoryProviderFactory();
|
|
621
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
622
|
-
await runtime?.start();
|
|
623
|
-
|
|
624
|
-
// The room exists (created by getDoc at attach) with zero browser conns.
|
|
625
|
-
expect(registry.peek('ui-screen')).not.toBeNull();
|
|
626
|
-
// The last-browser-leaves close handler calls drop; pinned → NOT destroyed,
|
|
627
|
-
// or the doc would be yanked out from under the live provider.
|
|
628
|
-
await registry.drop('ui-screen');
|
|
629
|
-
expect(registry.peek('ui-screen')).not.toBeNull();
|
|
630
|
-
|
|
631
|
-
// Runtime stop releases the pin → drop now destroys normally.
|
|
632
|
-
await runtime?.stop();
|
|
633
|
-
await registry.drop('ui-screen');
|
|
634
|
-
expect(registry.peek('ui-screen')).toBeNull();
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
test('Task 4 — the provider awareness is still bridged on the shared-doc path', async () => {
|
|
638
|
-
const url = 'https://hub.example.com';
|
|
639
|
-
writeHubsConfig(url, 'mau_test');
|
|
640
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
641
|
-
ctx.sharedDoc = true;
|
|
642
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
643
|
-
|
|
644
|
-
const registry = countingRegistry();
|
|
645
|
-
const { factory } = inMemoryProviderFactory();
|
|
646
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
647
|
-
await runtime?.start();
|
|
648
|
-
|
|
649
|
-
// Presence bridging is mode-independent (the attachHubAwareness call sits
|
|
650
|
-
// outside the sharedDoc branch). Confirm it still fires here so cursors
|
|
651
|
-
// relay cross-machine under the new path too.
|
|
652
|
-
expect(registry.awarenessAttaches()).toBe(1);
|
|
653
|
-
|
|
654
|
-
await runtime?.stop();
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
test('Task 11 — status surfaces the shared-doc model in _sync.json', async () => {
|
|
658
|
-
const url = 'https://hub.example.com';
|
|
659
|
-
writeHubsConfig(url, 'mau_test');
|
|
660
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
661
|
-
ctx.sharedDoc = true;
|
|
662
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.html'), '<button>hi</button>');
|
|
663
|
-
|
|
664
|
-
const registry = countingRegistry();
|
|
665
|
-
const { factory } = inMemoryProviderFactory();
|
|
666
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
667
|
-
await runtime?.start();
|
|
668
|
-
|
|
669
|
-
expect(runtime?.status()?.sharedDoc).toBe(true);
|
|
670
|
-
const payload = JSON.parse(readFileSync(join(ctx.paths.designRoot, '_sync.json'), 'utf8'));
|
|
671
|
-
expect(payload.sharedDoc).toBe(true);
|
|
672
|
-
|
|
673
|
-
await runtime?.stop();
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
// Phase D (Task 8) — the body-gating security invariant under the shared-doc
|
|
677
|
-
// path: a `.tsx` body crosses the hub ONLY with the syncable opt-in (Lock 1) +
|
|
678
|
-
// the canvasOrigin sandbox (Lock 2). The gate is discovery-exclusion: an
|
|
679
|
-
// opted-out `.tsx` is never in the sync set, so no provider attaches to a doc
|
|
680
|
-
// for it and its body is never exposed (DDR-054 F1 / DDR-060).
|
|
681
|
-
test('Phase D — an opted-OUT .tsx body never gets a shared doc/provider (gate holds)', async () => {
|
|
682
|
-
const url = 'https://hub.example.com';
|
|
683
|
-
writeHubsConfig(url, 'mau_test');
|
|
684
|
-
// canvasOrigin set === Lock 2 (sandbox) active.
|
|
685
|
-
const ctx = makeCtx({ url, linkedAt: 1 }, 'http://localhost:9');
|
|
686
|
-
ctx.sharedDoc = true;
|
|
687
|
-
|
|
688
|
-
// Opted-IN .tsx (Lock 1 + Lock 2 both set) → body may sync.
|
|
689
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'opted.tsx'), 'export default () => null;');
|
|
690
|
-
writeFileSync(
|
|
691
|
-
join(ctx.paths.designRoot, 'ui', 'opted.meta.json'),
|
|
692
|
-
JSON.stringify({ syncable: true })
|
|
693
|
-
);
|
|
694
|
-
// Opted-OUT .tsx (no Lock 1) → body MUST NOT cross the hub.
|
|
695
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'secret.tsx'), 'export default () => SECRET;');
|
|
696
|
-
writeFileSync(
|
|
697
|
-
join(ctx.paths.designRoot, 'ui', 'secret.meta.json'),
|
|
698
|
-
JSON.stringify({ syncable: false })
|
|
699
|
-
);
|
|
700
|
-
|
|
701
|
-
const registry = countingRegistry();
|
|
702
|
-
const { factory } = inMemoryProviderFactory();
|
|
703
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory, registry });
|
|
704
|
-
await runtime?.start();
|
|
705
|
-
|
|
706
|
-
// Only the opted-in canvas is in the sync set.
|
|
707
|
-
expect(runtime?.size()).toBe(1);
|
|
708
|
-
// The opted-in canvas got a shared doc (room created via getDoc)…
|
|
709
|
-
expect(registry.peek('ui-opted')).not.toBeNull();
|
|
710
|
-
// …the opted-out one NEVER did — no provider, no doc, body unexposed.
|
|
711
|
-
expect(registry.peek('ui-secret')).toBeNull();
|
|
712
|
-
|
|
713
|
-
// The untrusted marker lists ONLY the body-exposing (opted-in) canvas.
|
|
714
|
-
const index = JSON.parse(
|
|
715
|
-
readFileSync(join(ctx.paths.designRoot, '_untrusted', 'INDEX.json'), 'utf8')
|
|
716
|
-
);
|
|
717
|
-
const markedSlugs = index.canvases.map((c: { slug: string }) => c.slug);
|
|
718
|
-
expect(markedSlugs).toEqual(['ui-opted']);
|
|
719
|
-
|
|
720
|
-
await runtime?.stop();
|
|
721
|
-
});
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
describe('discoverCanvases', () => {
|
|
725
|
-
test('finds .html files but EXCLUDES .tsx (DDR-054 §2b)', async () => {
|
|
726
|
-
const ctx = makeCtx({ url: 'https://h.example.com', linkedAt: 1 });
|
|
727
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '');
|
|
728
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'b.tsx'), '');
|
|
729
|
-
|
|
730
|
-
const list = await discoverCanvases(ctx);
|
|
731
|
-
const slugs = list.map((c) => c.slug).sort();
|
|
732
|
-
// .tsx is deliberately refused — hostile-hub-pushed JSX would be
|
|
733
|
-
// transpiled and executed in iframe same-origin. Solo-mode editing
|
|
734
|
-
// of .tsx is unaffected.
|
|
735
|
-
expect(slugs).toEqual(['ui-a']);
|
|
736
|
-
});
|
|
737
|
-
|
|
738
|
-
test('skips dirs starting with _ (e.g. _history, _comments)', async () => {
|
|
739
|
-
const ctx = makeCtx({ url: 'https://h.example.com', linkedAt: 1 });
|
|
740
|
-
mkdirSync(join(ctx.paths.designRoot, 'ui', '_history'));
|
|
741
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', '_history', 'snap.html'), '');
|
|
742
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'real.html'), '');
|
|
743
|
-
|
|
744
|
-
const list = await discoverCanvases(ctx);
|
|
745
|
-
expect(list.map((c) => c.slug)).toEqual(['ui-real']);
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
// T3 (9.1-B) — opted-in .tsx sync, gated on the sandbox split.
|
|
749
|
-
test('admits an opted-in .tsx ONLY when the split is active (Lock1⊃Lock2)', async () => {
|
|
750
|
-
const HUB = { url: 'https://h.example.com', linkedAt: 1 };
|
|
751
|
-
// split ACTIVE (canvasOrigin set) + sidecar opts in → admitted, body = .tsx.
|
|
752
|
-
const ctx = makeCtx(HUB, 'http://localhost:9');
|
|
753
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'opted.tsx'), 'export default () => null;');
|
|
754
|
-
writeFileSync(
|
|
755
|
-
join(ctx.paths.designRoot, 'ui', 'opted.meta.json'),
|
|
756
|
-
JSON.stringify({ syncable: true })
|
|
757
|
-
);
|
|
758
|
-
const list = await discoverCanvases(ctx);
|
|
759
|
-
const opted = list.find((c) => c.slug === 'ui-opted');
|
|
760
|
-
expect(opted).toBeDefined();
|
|
761
|
-
expect(opted?.html).toBe(join(ctx.paths.designRoot, 'ui', 'opted.tsx'));
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
test('does NOT admit an opted-in .tsx when the split is OFF (the coupling)', async () => {
|
|
765
|
-
// Same opt-in, but canvasOrigin undefined → sandbox not in force → refused.
|
|
766
|
-
const ctx = makeCtx({ url: 'https://h.example.com', linkedAt: 1 });
|
|
767
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'opted.tsx'), 'export default () => null;');
|
|
768
|
-
writeFileSync(
|
|
769
|
-
join(ctx.paths.designRoot, 'ui', 'opted.meta.json'),
|
|
770
|
-
JSON.stringify({ syncable: true })
|
|
771
|
-
);
|
|
772
|
-
const list = await discoverCanvases(ctx);
|
|
773
|
-
expect(list.map((c) => c.slug)).not.toContain('ui-opted');
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
test('does NOT admit a .tsx without the opt-in even when the split is active', async () => {
|
|
777
|
-
const ctx = makeCtx({ url: 'https://h.example.com', linkedAt: 1 }, 'http://localhost:9');
|
|
778
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'plain.tsx'), 'export default () => null;');
|
|
779
|
-
// sidecar present but syncable:false → still refused.
|
|
780
|
-
writeFileSync(
|
|
781
|
-
join(ctx.paths.designRoot, 'ui', 'plain.meta.json'),
|
|
782
|
-
JSON.stringify({ syncable: false, title: 'Plain' })
|
|
783
|
-
);
|
|
784
|
-
const list = await discoverCanvases(ctx);
|
|
785
|
-
expect(list.map((c) => c.slug)).not.toContain('ui-plain');
|
|
786
|
-
});
|
|
787
|
-
});
|
|
788
|
-
|
|
789
|
-
describe('scanCanvases', () => {
|
|
790
|
-
test('tallies .tsx canvases separately from syncable .html', async () => {
|
|
791
|
-
const ctx = makeCtx({ url: 'https://h.example.com', linkedAt: 1 });
|
|
792
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '');
|
|
793
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'b.tsx'), '');
|
|
794
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'c.tsx'), '');
|
|
795
|
-
|
|
796
|
-
const scan = await scanCanvases(ctx);
|
|
797
|
-
expect(scan.canvases.map((c) => c.slug)).toEqual(['ui-a']);
|
|
798
|
-
expect(scan.tsxCount).toBe(2);
|
|
799
|
-
});
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
// DDR-079 (was DDR-072) — TSX sync defaults ON. A .tsx with no explicit sidecar
|
|
803
|
-
// verdict syncs by default; `syncTsx: false` opts the project out; the per-canvas
|
|
804
|
-
// sidecar still wins; the Lock-2 sandbox coupling is preserved.
|
|
805
|
-
describe('scanCanvases — project-level syncTsx default-on (DDR-079)', () => {
|
|
806
|
-
test('explicit syncTsx:true + sandbox ON admits a .tsx WITHOUT a per-canvas opt-in', async () => {
|
|
807
|
-
const ctx = makeCtx(
|
|
808
|
-
{ url: 'https://h.example.com', linkedAt: 1, syncTsx: true },
|
|
809
|
-
'http://localhost:9'
|
|
810
|
-
);
|
|
811
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'free.tsx'), 'export default () => null;');
|
|
812
|
-
const scan = await scanCanvases(ctx);
|
|
813
|
-
const free = scan.canvases.find((c) => c.slug === 'ui-free');
|
|
814
|
-
expect(free).toBeDefined();
|
|
815
|
-
expect(free?.html).toBe(join(ctx.paths.designRoot, 'ui', 'free.tsx'));
|
|
816
|
-
expect(scan.tsxCount).toBe(0);
|
|
817
|
-
});
|
|
818
|
-
|
|
819
|
-
test('syncTsx:true is INERT when the sandbox split is OFF (Lock-2 coupling preserved)', async () => {
|
|
820
|
-
// canvasOrigin undefined → sandbox not in force → no .tsx syncs, flag or not.
|
|
821
|
-
const ctx = makeCtx({ url: 'https://h.example.com', linkedAt: 1, syncTsx: true });
|
|
822
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'free.tsx'), 'export default () => null;');
|
|
823
|
-
const scan = await scanCanvases(ctx);
|
|
824
|
-
expect(scan.canvases.map((c) => c.slug)).not.toContain('ui-free');
|
|
825
|
-
expect(scan.tsxCount).toBe(1);
|
|
826
|
-
});
|
|
827
|
-
|
|
828
|
-
test('per-canvas "syncable": false OVERRIDES syncTsx:true (sidecar wins)', async () => {
|
|
829
|
-
const ctx = makeCtx(
|
|
830
|
-
{ url: 'https://h.example.com', linkedAt: 1, syncTsx: true },
|
|
831
|
-
'http://localhost:9'
|
|
832
|
-
);
|
|
833
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'secret.tsx'), 'export default () => null;');
|
|
834
|
-
writeFileSync(
|
|
835
|
-
join(ctx.paths.designRoot, 'ui', 'secret.meta.json'),
|
|
836
|
-
JSON.stringify({ syncable: false, title: 'Secret' })
|
|
837
|
-
);
|
|
838
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'open.tsx'), 'export default () => null;');
|
|
839
|
-
const scan = await scanCanvases(ctx);
|
|
840
|
-
const slugs = scan.canvases.map((c) => c.slug);
|
|
841
|
-
expect(slugs).toContain('ui-open'); // no sidecar → project default
|
|
842
|
-
expect(slugs).not.toContain('ui-secret'); // explicit opt-out wins
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
test('DDR-079: without the flag (syncTsx absent) a .tsx is admitted BY DEFAULT', async () => {
|
|
846
|
-
const ctx = makeCtx({ url: 'https://h.example.com', linkedAt: 1 }, 'http://localhost:9');
|
|
847
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'plain.tsx'), 'export default () => null;');
|
|
848
|
-
const scan = await scanCanvases(ctx);
|
|
849
|
-
expect(scan.canvases.map((c) => c.slug)).toContain('ui-plain'); // default ON
|
|
850
|
-
expect(scan.tsxCount).toBe(0);
|
|
851
|
-
});
|
|
852
|
-
|
|
853
|
-
test('DDR-079: syncTsx:false opts the whole project OUT (.tsx not admitted)', async () => {
|
|
854
|
-
const ctx = makeCtx(
|
|
855
|
-
{ url: 'https://h.example.com', linkedAt: 1, syncTsx: false },
|
|
856
|
-
'http://localhost:9'
|
|
857
|
-
);
|
|
858
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'plain.tsx'), 'export default () => null;');
|
|
859
|
-
const scan = await scanCanvases(ctx);
|
|
860
|
-
expect(scan.canvases.map((c) => c.slug)).not.toContain('ui-plain');
|
|
861
|
-
expect(scan.tsxCount).toBe(1);
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
test('DDR-079: per-canvas "syncable": true still admits one .tsx even when project opted out', async () => {
|
|
865
|
-
const ctx = makeCtx(
|
|
866
|
-
{ url: 'https://h.example.com', linkedAt: 1, syncTsx: false },
|
|
867
|
-
'http://localhost:9'
|
|
868
|
-
);
|
|
869
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'keep.tsx'), 'export default () => null;');
|
|
870
|
-
writeFileSync(
|
|
871
|
-
join(ctx.paths.designRoot, 'ui', 'keep.meta.json'),
|
|
872
|
-
JSON.stringify({ syncable: true, title: 'Keep' })
|
|
873
|
-
);
|
|
874
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'drop.tsx'), 'export default () => null;');
|
|
875
|
-
const scan = await scanCanvases(ctx);
|
|
876
|
-
const slugs = scan.canvases.map((c) => c.slug);
|
|
877
|
-
expect(slugs).toContain('ui-keep'); // sidecar opt-in wins over project opt-out
|
|
878
|
-
expect(slugs).not.toContain('ui-drop'); // project opted out
|
|
879
|
-
});
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
describe('buildNoSyncablePayload', () => {
|
|
883
|
-
test('TSX-only project: reason names the count + DDR-060', () => {
|
|
884
|
-
const p = buildNoSyncablePayload('https://h.example.com', 3, '/proj/.design');
|
|
885
|
-
expect(p.notSyncable).toBe(true);
|
|
886
|
-
expect(p.tsxCount).toBe(3);
|
|
887
|
-
expect(p.reason).toContain('3 TSX canvas(es)');
|
|
888
|
-
expect(p.reason).toContain('DDR-060');
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
test('empty project: reason reports no canvases under the design root', () => {
|
|
892
|
-
const p = buildNoSyncablePayload('https://h.example.com', 0, '/proj/.design');
|
|
893
|
-
expect(p.tsxCount).toBe(0);
|
|
894
|
-
expect(p.reason).toContain('no canvases found under /proj/.design');
|
|
895
|
-
});
|
|
896
|
-
});
|
|
897
|
-
|
|
898
|
-
describe('toWsUrl', () => {
|
|
899
|
-
test('https → wss', () => {
|
|
900
|
-
expect(toWsUrl('https://hub.example.com')).toBe('wss://hub.example.com');
|
|
901
|
-
});
|
|
902
|
-
test('http → ws', () => {
|
|
903
|
-
expect(toWsUrl('http://localhost:1234')).toBe('ws://localhost:1234');
|
|
904
|
-
});
|
|
905
|
-
test('passthrough for ws://', () => {
|
|
906
|
-
expect(toWsUrl('ws://localhost:1234')).toBe('ws://localhost:1234');
|
|
907
|
-
});
|
|
908
|
-
});
|
|
909
|
-
|
|
910
|
-
// DDR-102 — WS multiplexing: the default factory shares ONE
|
|
911
|
-
// HocuspocusProviderWebsocket per hub URL across all providers.
|
|
912
|
-
describe('createDefaultProviderFactory — shared socket multiplexing', () => {
|
|
913
|
-
class FakeEmitter {
|
|
914
|
-
handlers = new Map<string, Set<(arg?: unknown) => void>>();
|
|
915
|
-
on(evt: string, cb: (arg?: unknown) => void) {
|
|
916
|
-
if (!this.handlers.has(evt)) this.handlers.set(evt, new Set());
|
|
917
|
-
this.handlers.get(evt)?.add(cb);
|
|
918
|
-
}
|
|
919
|
-
off(evt: string, cb: (arg?: unknown) => void) {
|
|
920
|
-
this.handlers.get(evt)?.delete(cb);
|
|
921
|
-
}
|
|
922
|
-
emit(evt: string, arg?: unknown) {
|
|
923
|
-
for (const cb of this.handlers.get(evt) ?? []) cb(arg);
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
function makeFakeModule() {
|
|
928
|
-
const sockets: Array<{ url: string; destroyed: boolean }> = [];
|
|
929
|
-
const providers: Array<{
|
|
930
|
-
name: string;
|
|
931
|
-
attached: boolean;
|
|
932
|
-
destroyed: boolean;
|
|
933
|
-
socket: unknown;
|
|
934
|
-
}> = [];
|
|
935
|
-
|
|
936
|
-
class HocuspocusProviderWebsocket extends FakeEmitter {
|
|
937
|
-
url: string;
|
|
938
|
-
status = 'connecting';
|
|
939
|
-
destroyed = false;
|
|
940
|
-
constructor(cfg: { url: string }) {
|
|
941
|
-
super();
|
|
942
|
-
this.url = cfg.url;
|
|
943
|
-
sockets.push(this);
|
|
944
|
-
}
|
|
945
|
-
destroy() {
|
|
946
|
-
this.destroyed = true;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
class HocuspocusProvider extends FakeEmitter {
|
|
951
|
-
configuration: { name: string; websocketProvider: unknown; document: unknown };
|
|
952
|
-
awareness = undefined;
|
|
953
|
-
synced = false;
|
|
954
|
-
attached = false;
|
|
955
|
-
destroyed = false;
|
|
956
|
-
name: string;
|
|
957
|
-
socket: unknown;
|
|
958
|
-
constructor(cfg: { name: string; websocketProvider: unknown; document: unknown }) {
|
|
959
|
-
super();
|
|
960
|
-
this.configuration = cfg;
|
|
961
|
-
this.name = cfg.name;
|
|
962
|
-
this.socket = cfg.websocketProvider;
|
|
963
|
-
providers.push(this);
|
|
964
|
-
}
|
|
965
|
-
attach() {
|
|
966
|
-
this.attached = true;
|
|
967
|
-
}
|
|
968
|
-
destroy() {
|
|
969
|
-
this.destroyed = true;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
return { mod: { HocuspocusProviderWebsocket, HocuspocusProvider }, sockets, providers };
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
test('N providers for one hub URL share ONE socket, each explicitly attached', async () => {
|
|
977
|
-
const { mod, sockets, providers } = makeFakeModule();
|
|
978
|
-
const { createDefaultProviderFactory } = await import('../sync/index.ts');
|
|
979
|
-
const factory = createDefaultProviderFactory(async () => mod);
|
|
980
|
-
|
|
981
|
-
await factory({ url: 'https://hub.example.com', token: 't', documentName: 'ui-a' });
|
|
982
|
-
await factory({ url: 'https://hub.example.com', token: 't', documentName: 'ui-b' });
|
|
983
|
-
await factory({ url: 'https://hub.example.com', token: 't', documentName: 'ui-c' });
|
|
984
|
-
|
|
985
|
-
expect(sockets).toHaveLength(1);
|
|
986
|
-
expect(sockets[0].url).toBe('wss://hub.example.com');
|
|
987
|
-
expect(providers).toHaveLength(3);
|
|
988
|
-
for (const p of providers) {
|
|
989
|
-
expect(p.attached).toBe(true);
|
|
990
|
-
expect(p.socket).toBe(sockets[0]);
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
|
|
994
|
-
test('provider destroy() detaches only; dispose() destroys the shared socket', async () => {
|
|
995
|
-
const { mod, sockets, providers } = makeFakeModule();
|
|
996
|
-
const { createDefaultProviderFactory } = await import('../sync/index.ts');
|
|
997
|
-
const factory = createDefaultProviderFactory(async () => mod);
|
|
998
|
-
|
|
999
|
-
const p1 = await factory({ url: 'https://h.example.com', token: 't', documentName: 'ui-a' });
|
|
1000
|
-
p1.destroy();
|
|
1001
|
-
expect(providers[0].destroyed).toBe(true);
|
|
1002
|
-
expect(sockets[0].destroyed).toBe(false); // socket survives provider death
|
|
1003
|
-
|
|
1004
|
-
factory.dispose();
|
|
1005
|
-
expect(sockets[0].destroyed).toBe(true);
|
|
1006
|
-
});
|
|
1007
|
-
|
|
1008
|
-
test('onStatus seeds from the SOCKET status and forwards provider status events', async () => {
|
|
1009
|
-
const { mod, sockets, providers } = makeFakeModule();
|
|
1010
|
-
const { createDefaultProviderFactory } = await import('../sync/index.ts');
|
|
1011
|
-
const factory = createDefaultProviderFactory(async () => mod);
|
|
1012
|
-
|
|
1013
|
-
const wrapped = await factory({
|
|
1014
|
-
url: 'https://h.example.com',
|
|
1015
|
-
token: 't',
|
|
1016
|
-
documentName: 'ui-a',
|
|
1017
|
-
});
|
|
1018
|
-
const seen: string[] = [];
|
|
1019
|
-
const unsub = wrapped.onStatus?.((s) => seen.push(s));
|
|
1020
|
-
// Seeded from socket.status ('connecting') immediately.
|
|
1021
|
-
expect(seen).toEqual(['connecting']);
|
|
1022
|
-
// Provider-level forwarded events keep flowing.
|
|
1023
|
-
(providers[0] as unknown as FakeEmitter).emit('status', { status: 'connected' });
|
|
1024
|
-
expect(seen).toEqual(['connecting', 'connected']);
|
|
1025
|
-
unsub?.();
|
|
1026
|
-
(providers[0] as unknown as FakeEmitter).emit('status', { status: 'disconnected' });
|
|
1027
|
-
expect(seen).toEqual(['connecting', 'connected']); // unsubscribed
|
|
1028
|
-
expect(sockets).toHaveLength(1);
|
|
1029
|
-
});
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
|
-
// DDR-102 — auth-failure intelligence (classification, aggregation,
|
|
1033
|
-
// destroy-on-permanent + re-probe) and the honest settled boot summary.
|
|
1034
|
-
describe('validExpiry — a hub-reported deadline sane enough to schedule against', () => {
|
|
1035
|
-
const NOW = 1_000_000_000_000;
|
|
1036
|
-
test('accepts a plausible future integer', () => {
|
|
1037
|
-
expect(validExpiry(NOW + 12 * 60 * 60 * 1000, NOW)).toBe(NOW + 12 * 60 * 60 * 1000);
|
|
1038
|
-
});
|
|
1039
|
-
test('rejects a past or present stamp (falls to the invalid-token path instead)', () => {
|
|
1040
|
-
expect(validExpiry(NOW - 1, NOW)).toBeNull();
|
|
1041
|
-
expect(validExpiry(NOW, NOW)).toBeNull();
|
|
1042
|
-
});
|
|
1043
|
-
test('rejects an absurdly far-future stamp (the setTimeout-overflow trap)', () => {
|
|
1044
|
-
expect(validExpiry(NOW + 60 * 24 * 60 * 60 * 1000, NOW)).toBeNull(); // 60 days
|
|
1045
|
-
});
|
|
1046
|
-
test('rejects non-integers and non-numbers', () => {
|
|
1047
|
-
expect(validExpiry(NOW + 1000.5, NOW)).toBeNull();
|
|
1048
|
-
expect(validExpiry('soon', NOW)).toBeNull();
|
|
1049
|
-
expect(validExpiry(Number.NaN, NOW)).toBeNull();
|
|
1050
|
-
expect(validExpiry(Number.POSITIVE_INFINITY, NOW)).toBeNull();
|
|
1051
|
-
expect(validExpiry(undefined, NOW)).toBeNull();
|
|
1052
|
-
});
|
|
1053
|
-
});
|
|
1054
|
-
|
|
1055
|
-
describe('classifyAuthFailure — permanent classes outrank the transient ones', () => {
|
|
1056
|
-
test('the invalid-token bucket refusal classifies as invalid-token, not rate-limit', () => {
|
|
1057
|
-
// The hub's invalid-token bucket says BOTH things. Filing it under
|
|
1058
|
-
// rate-limit (transient) made the runtime retry into the very bucket
|
|
1059
|
-
// refusing it — the alligators incident's 1840-vs-138 log ratio.
|
|
1060
|
-
expect(classifyAuthFailure('invalid token — rate limited, retry in up to 60s')).toBe(
|
|
1061
|
-
'invalid-token'
|
|
1062
|
-
);
|
|
1063
|
-
});
|
|
1064
|
-
|
|
1065
|
-
test('plain reasons still land in their own classes', () => {
|
|
1066
|
-
expect(classifyAuthFailure('invalid token')).toBe('invalid-token');
|
|
1067
|
-
expect(classifyAuthFailure('token not authorized for this documentName')).toBe(
|
|
1068
|
-
'not-authorized'
|
|
1069
|
-
);
|
|
1070
|
-
expect(classifyAuthFailure('rate limit exceeded for this token — retry in up to 60s')).toBe(
|
|
1071
|
-
'rate-limit'
|
|
1072
|
-
);
|
|
1073
|
-
expect(classifyAuthFailure('permission-denied')).toBe('generic');
|
|
1074
|
-
});
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
describe('DDR-102 — auth-failure intelligence + boot summary', () => {
|
|
1078
|
-
function fakeTimerQueue() {
|
|
1079
|
-
let nextId = 1;
|
|
1080
|
-
const timers = new Map<number, { cb: () => void; ms: number }>();
|
|
1081
|
-
return {
|
|
1082
|
-
setTimer: (cb: () => void, ms: number) => {
|
|
1083
|
-
const id = nextId++;
|
|
1084
|
-
timers.set(id, { cb, ms });
|
|
1085
|
-
return id as unknown as ReturnType<typeof setTimeout>;
|
|
1086
|
-
},
|
|
1087
|
-
clearTimer: (h: ReturnType<typeof setTimeout>) => {
|
|
1088
|
-
timers.delete(h as unknown as number);
|
|
1089
|
-
},
|
|
1090
|
-
/** Fire every pending timer with ms <= maxMs (one sweep). */
|
|
1091
|
-
fire(maxMs: number) {
|
|
1092
|
-
for (const [id, t] of [...timers.entries()]) {
|
|
1093
|
-
if (t.ms <= maxMs) {
|
|
1094
|
-
timers.delete(id);
|
|
1095
|
-
t.cb();
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
},
|
|
1099
|
-
pending: () => timers.size,
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
/** Stub factory whose providers expose onAuthFailed + track destroys. */
|
|
1104
|
-
function authStubFactory() {
|
|
1105
|
-
const made: Array<{
|
|
1106
|
-
documentName: string;
|
|
1107
|
-
token: string | undefined;
|
|
1108
|
-
destroyed: boolean;
|
|
1109
|
-
emitAuthFailure: (reason: string) => void;
|
|
1110
|
-
document: Y.Doc;
|
|
1111
|
-
}> = [];
|
|
1112
|
-
const factory = (args: { documentName: string; token?: string; document?: Y.Doc }) => {
|
|
1113
|
-
const document = args.document ?? new Y.Doc();
|
|
1114
|
-
const cbs = new Set<(info: { reason: string }) => void>();
|
|
1115
|
-
const entry = {
|
|
1116
|
-
documentName: args.documentName,
|
|
1117
|
-
token: args.token,
|
|
1118
|
-
destroyed: false,
|
|
1119
|
-
emitAuthFailure: (reason: string) => {
|
|
1120
|
-
for (const cb of cbs) cb({ reason });
|
|
1121
|
-
},
|
|
1122
|
-
document,
|
|
1123
|
-
};
|
|
1124
|
-
made.push(entry);
|
|
1125
|
-
return {
|
|
1126
|
-
document,
|
|
1127
|
-
onAuthFailed(cb: (info: { reason: string }) => void) {
|
|
1128
|
-
cbs.add(cb);
|
|
1129
|
-
return () => cbs.delete(cb);
|
|
1130
|
-
},
|
|
1131
|
-
onceSynced() {
|
|
1132
|
-
return new Promise<void>(() => {}); // never settles (rejected docs)
|
|
1133
|
-
},
|
|
1134
|
-
destroy() {
|
|
1135
|
-
entry.destroyed = true;
|
|
1136
|
-
},
|
|
1137
|
-
};
|
|
1138
|
-
};
|
|
1139
|
-
return { factory, made };
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
test('classification + ONE aggregated warn + destroy-on-permanent + re-probe', async () => {
|
|
1143
|
-
const url = 'https://hub.example.com';
|
|
1144
|
-
writeHubsConfig(url, 'mau_test');
|
|
1145
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1146
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1147
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'b.html'), '<b/>');
|
|
1148
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'c.html'), '<c/>');
|
|
1149
|
-
|
|
1150
|
-
const timers = fakeTimerQueue();
|
|
1151
|
-
const { factory, made } = authStubFactory();
|
|
1152
|
-
const warns: string[] = [];
|
|
1153
|
-
const origWarn = console.warn;
|
|
1154
|
-
console.warn = (...args: unknown[]) => {
|
|
1155
|
-
warns.push(args.map(String).join(' '));
|
|
1156
|
-
};
|
|
1157
|
-
|
|
1158
|
-
try {
|
|
1159
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1160
|
-
providerFactory: factory,
|
|
1161
|
-
auth: {
|
|
1162
|
-
warnDebounceMs: 2_000,
|
|
1163
|
-
reprobeMs: 300_000,
|
|
1164
|
-
settleTimeoutMs: 15_000,
|
|
1165
|
-
setTimer: timers.setTimer,
|
|
1166
|
-
clearTimer: timers.clearTimer,
|
|
1167
|
-
},
|
|
1168
|
-
});
|
|
1169
|
-
await runtime?.start();
|
|
1170
|
-
expect(made).toHaveLength(3);
|
|
1171
|
-
// readdir order is not deterministic — address providers by slug.
|
|
1172
|
-
const bySlug = (slug: string) => {
|
|
1173
|
-
const m = made.find((p) => p.documentName === slug);
|
|
1174
|
-
if (!m) throw new Error(`no provider for ${slug}`);
|
|
1175
|
-
return m;
|
|
1176
|
-
};
|
|
1177
|
-
|
|
1178
|
-
// Hub rejects: a + b permanently (scope), c transiently (rate limit).
|
|
1179
|
-
bySlug('ui-a').emitAuthFailure('token not authorized for this documentName');
|
|
1180
|
-
bySlug('ui-b').emitAuthFailure('token not authorized for this documentName');
|
|
1181
|
-
bySlug('ui-c').emitAuthFailure('rate limit exceeded for this token');
|
|
1182
|
-
|
|
1183
|
-
// Per-slug statuses are honest immediately.
|
|
1184
|
-
const status = runtime?.status();
|
|
1185
|
-
expect(status?.docs?.rejected).toBe(3);
|
|
1186
|
-
expect(status?.rejectedSlugs?.sort()).toEqual(['ui-a', 'ui-b', 'ui-c']);
|
|
1187
|
-
|
|
1188
|
-
// Permanent classes destroyed (retry storm stopped); transient keeps its
|
|
1189
|
-
// provider (built-in backoff).
|
|
1190
|
-
expect(bySlug('ui-a').destroyed).toBe(true);
|
|
1191
|
-
expect(bySlug('ui-b').destroyed).toBe(true);
|
|
1192
|
-
expect(bySlug('ui-c').destroyed).toBe(false);
|
|
1193
|
-
|
|
1194
|
-
// No warn yet (debounced); ONE aggregated warn after the window.
|
|
1195
|
-
const authWarnsBefore = warns.filter((w) => w.includes('auth rejections')).length;
|
|
1196
|
-
expect(authWarnsBefore).toBe(0);
|
|
1197
|
-
timers.fire(2_000);
|
|
1198
|
-
const authWarns = warns.filter((w) => w.includes('auth rejections'));
|
|
1199
|
-
expect(authWarns).toHaveLength(1);
|
|
1200
|
-
// Reason-specific hints, both classes in the one warn.
|
|
1201
|
-
expect(authWarns[0]).toContain('not-authorized');
|
|
1202
|
-
expect(authWarns[0]).toContain('rate-limit');
|
|
1203
|
-
expect(authWarns[0]).toContain('mint a hub-wide token');
|
|
1204
|
-
expect(authWarns[0]).toContain('HUB_CONN_RATE_LIMIT');
|
|
1205
|
-
|
|
1206
|
-
// Re-probe (5 min): the two permanently-rejected docs reconnect with the
|
|
1207
|
-
// SAME doc instance (agent wiring survives the provider swap).
|
|
1208
|
-
const docA = bySlug('ui-a').document;
|
|
1209
|
-
timers.fire(300_000);
|
|
1210
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1211
|
-
const reprobed = made.slice(3);
|
|
1212
|
-
expect(reprobed.map((m) => m.documentName).sort()).toEqual(['ui-a', 'ui-b']);
|
|
1213
|
-
expect(reprobed.find((m) => m.documentName === 'ui-a')?.document).toBe(docA);
|
|
1214
|
-
|
|
1215
|
-
await runtime?.stop();
|
|
1216
|
-
} finally {
|
|
1217
|
-
console.warn = origWarn;
|
|
1218
|
-
}
|
|
1219
|
-
});
|
|
1220
|
-
|
|
1221
|
-
test('invalid-token triggers ONE silent renewal and an immediate re-probe with the fresh token', async () => {
|
|
1222
|
-
const url = 'https://hub.example.com';
|
|
1223
|
-
writeHubsConfig(url, 'mau_stale');
|
|
1224
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1225
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1226
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'b.html'), '<b/>');
|
|
1227
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'c.html'), '<c/>');
|
|
1228
|
-
|
|
1229
|
-
const timers = fakeTimerQueue();
|
|
1230
|
-
const { factory, made } = authStubFactory();
|
|
1231
|
-
let renewCalls = 0;
|
|
1232
|
-
const origWarn = console.warn;
|
|
1233
|
-
const origLog = console.log;
|
|
1234
|
-
console.warn = () => {};
|
|
1235
|
-
console.log = () => {};
|
|
1236
|
-
try {
|
|
1237
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1238
|
-
providerFactory: factory,
|
|
1239
|
-
auth: {
|
|
1240
|
-
warnDebounceMs: 2_000,
|
|
1241
|
-
reprobeMs: 300_000,
|
|
1242
|
-
settleTimeoutMs: 15_000,
|
|
1243
|
-
setTimer: timers.setTimer,
|
|
1244
|
-
clearTimer: timers.clearTimer,
|
|
1245
|
-
renewCredential: async () => {
|
|
1246
|
-
renewCalls++;
|
|
1247
|
-
return { token: 'mau_fresh', expiresAt: null };
|
|
1248
|
-
},
|
|
1249
|
-
},
|
|
1250
|
-
});
|
|
1251
|
-
await runtime?.start();
|
|
1252
|
-
expect(made).toHaveLength(3);
|
|
1253
|
-
expect(made.every((m) => m.token === 'mau_stale')).toBe(true);
|
|
1254
|
-
|
|
1255
|
-
// The whole burst rejects with the expired credential…
|
|
1256
|
-
for (const m of made.slice(0, 3)) m.emitAuthFailure('invalid token');
|
|
1257
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1258
|
-
|
|
1259
|
-
// …ONE renewal (single-flight), and the re-probe happened NOW — no
|
|
1260
|
-
// 5-minute wait — with the fresh token on every reconnected provider.
|
|
1261
|
-
expect(renewCalls).toBe(1);
|
|
1262
|
-
const reprobed = made.slice(3);
|
|
1263
|
-
expect(reprobed.map((m) => m.documentName).sort()).toEqual(['ui-a', 'ui-b', 'ui-c']);
|
|
1264
|
-
expect(reprobed.every((m) => m.token === 'mau_fresh')).toBe(true);
|
|
1265
|
-
|
|
1266
|
-
await runtime?.stop();
|
|
1267
|
-
} finally {
|
|
1268
|
-
console.warn = origWarn;
|
|
1269
|
-
console.log = origLog;
|
|
1270
|
-
}
|
|
1271
|
-
});
|
|
1272
|
-
|
|
1273
|
-
test('F1: a hub refusing on VOLUME cannot drive a renewal storm — the cap stops it', async () => {
|
|
1274
|
-
// The regression this whole review turned on. A cell refusing its own
|
|
1275
|
-
// clients with "invalid token — rate limited" classifies permanent →
|
|
1276
|
-
// triggers renewal → renewal succeeds (token was fine) → reprobe → every
|
|
1277
|
-
// reconnected doc is refused again → loop. Reproduced at 2342/s before the
|
|
1278
|
-
// cap. Here every reconnected provider auto-re-rejects, so without the cap
|
|
1279
|
-
// this test would spin forever; with it, renewals are bounded.
|
|
1280
|
-
const url = 'https://hub.example.com';
|
|
1281
|
-
writeHubsConfig(url, 'mau_stale');
|
|
1282
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1283
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1284
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'b.html'), '<b/>');
|
|
1285
|
-
|
|
1286
|
-
let renewCalls = 0;
|
|
1287
|
-
let providersMade = 0;
|
|
1288
|
-
const origWarn = console.warn;
|
|
1289
|
-
const origLog = console.log;
|
|
1290
|
-
console.warn = () => {};
|
|
1291
|
-
console.log = () => {};
|
|
1292
|
-
// Every provider auto-rejects with the volume-refusal string the moment a
|
|
1293
|
-
// failure handler is attached — modelling a full hub bucket.
|
|
1294
|
-
const factory = (args: { documentName: string; token?: string; document?: Y.Doc }) => {
|
|
1295
|
-
const document = args.document ?? new Y.Doc();
|
|
1296
|
-
providersMade++;
|
|
1297
|
-
return {
|
|
1298
|
-
document,
|
|
1299
|
-
onAuthFailed(cb: (info: { reason: string }) => void) {
|
|
1300
|
-
queueMicrotask(() => cb({ reason: 'invalid token — rate limited, retry in up to 60s' }));
|
|
1301
|
-
return () => {};
|
|
1302
|
-
},
|
|
1303
|
-
onceSynced: () => new Promise<void>(() => {}),
|
|
1304
|
-
destroy() {},
|
|
1305
|
-
};
|
|
1306
|
-
};
|
|
1307
|
-
try {
|
|
1308
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1309
|
-
providerFactory: factory,
|
|
1310
|
-
auth: {
|
|
1311
|
-
warnDebounceMs: 2_000,
|
|
1312
|
-
reprobeMs: 300_000,
|
|
1313
|
-
settleTimeoutMs: 15_000,
|
|
1314
|
-
setTimer: () => 0 as unknown as ReturnType<typeof setTimeout>,
|
|
1315
|
-
clearTimer: () => {},
|
|
1316
|
-
renewMinIntervalMs: 0, // isolate the CAP from the floor
|
|
1317
|
-
renewCredential: async () => {
|
|
1318
|
-
renewCalls++;
|
|
1319
|
-
return { token: `mau_fresh_${renewCalls}`, expiresAt: null };
|
|
1320
|
-
},
|
|
1321
|
-
},
|
|
1322
|
-
});
|
|
1323
|
-
await runtime?.start();
|
|
1324
|
-
// Let the storm run itself out — if the cap failed, this never settles
|
|
1325
|
-
// and the test times out (which is itself the failure signal).
|
|
1326
|
-
for (let i = 0; i < 20; i++) await new Promise((res) => setTimeout(res, 5));
|
|
1327
|
-
|
|
1328
|
-
// Bounded by the cap (default 3), NOT thousands.
|
|
1329
|
-
expect(renewCalls).toBeLessThanOrEqual(3);
|
|
1330
|
-
expect(renewCalls).toBeGreaterThan(0);
|
|
1331
|
-
// Providers created is likewise bounded — no runaway reconnect fan-out.
|
|
1332
|
-
expect(providersMade).toBeLessThan(20);
|
|
1333
|
-
await runtime?.stop();
|
|
1334
|
-
} finally {
|
|
1335
|
-
console.warn = origWarn;
|
|
1336
|
-
console.log = origLog;
|
|
1337
|
-
}
|
|
1338
|
-
});
|
|
1339
|
-
|
|
1340
|
-
test('F1: the frequency floor collapses a rapid second burst to no extra renewal', async () => {
|
|
1341
|
-
const url = 'https://hub.example.com';
|
|
1342
|
-
writeHubsConfig(url, 'mau_stale');
|
|
1343
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1344
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1345
|
-
|
|
1346
|
-
let renewCalls = 0;
|
|
1347
|
-
let clock = 1_000_000;
|
|
1348
|
-
const origWarn = console.warn;
|
|
1349
|
-
const origLog = console.log;
|
|
1350
|
-
console.warn = () => {};
|
|
1351
|
-
console.log = () => {};
|
|
1352
|
-
const { factory, made } = authStubFactory();
|
|
1353
|
-
try {
|
|
1354
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1355
|
-
providerFactory: factory,
|
|
1356
|
-
auth: {
|
|
1357
|
-
warnDebounceMs: 2_000,
|
|
1358
|
-
reprobeMs: 300_000,
|
|
1359
|
-
settleTimeoutMs: 15_000,
|
|
1360
|
-
setTimer: () => 0 as unknown as ReturnType<typeof setTimeout>,
|
|
1361
|
-
clearTimer: () => {},
|
|
1362
|
-
now: () => clock,
|
|
1363
|
-
renewMinIntervalMs: 60_000,
|
|
1364
|
-
renewCredential: async () => {
|
|
1365
|
-
renewCalls++;
|
|
1366
|
-
return { token: 'mau_fresh', expiresAt: null };
|
|
1367
|
-
},
|
|
1368
|
-
},
|
|
1369
|
-
});
|
|
1370
|
-
await runtime?.start();
|
|
1371
|
-
made[0]?.emitAuthFailure('invalid token');
|
|
1372
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1373
|
-
expect(renewCalls).toBe(1);
|
|
1374
|
-
// A second rejection 10 s later (inside the 60 s floor) → no new renewal.
|
|
1375
|
-
clock += 10_000;
|
|
1376
|
-
made[0]?.emitAuthFailure('invalid token');
|
|
1377
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1378
|
-
expect(renewCalls).toBe(1);
|
|
1379
|
-
// Past the floor → renewal is allowed again.
|
|
1380
|
-
clock += 60_000;
|
|
1381
|
-
made[0]?.emitAuthFailure('invalid token');
|
|
1382
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1383
|
-
expect(renewCalls).toBe(2);
|
|
1384
|
-
await runtime?.stop();
|
|
1385
|
-
} finally {
|
|
1386
|
-
console.warn = origWarn;
|
|
1387
|
-
console.log = origLog;
|
|
1388
|
-
}
|
|
1389
|
-
});
|
|
1390
|
-
|
|
1391
|
-
test('a failed renewal changes nothing — rejected docs wait for the slow re-probe as before', async () => {
|
|
1392
|
-
const url = 'https://hub.example.com';
|
|
1393
|
-
writeHubsConfig(url, 'mau_stale');
|
|
1394
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1395
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1396
|
-
|
|
1397
|
-
const timers = fakeTimerQueue();
|
|
1398
|
-
const { factory, made } = authStubFactory();
|
|
1399
|
-
const origWarn = console.warn;
|
|
1400
|
-
const origLog = console.log;
|
|
1401
|
-
console.warn = () => {};
|
|
1402
|
-
console.log = () => {};
|
|
1403
|
-
try {
|
|
1404
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1405
|
-
providerFactory: factory,
|
|
1406
|
-
auth: {
|
|
1407
|
-
warnDebounceMs: 2_000,
|
|
1408
|
-
reprobeMs: 300_000,
|
|
1409
|
-
settleTimeoutMs: 15_000,
|
|
1410
|
-
setTimer: timers.setTimer,
|
|
1411
|
-
clearTimer: timers.clearTimer,
|
|
1412
|
-
renewCredential: async () => null, // signed out / revoked / self-hosted
|
|
1413
|
-
},
|
|
1414
|
-
});
|
|
1415
|
-
await runtime?.start();
|
|
1416
|
-
made[0]?.emitAuthFailure('invalid token');
|
|
1417
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1418
|
-
|
|
1419
|
-
// No immediate re-probe (the renewal failed) — the doc stays rejected…
|
|
1420
|
-
expect(made).toHaveLength(1);
|
|
1421
|
-
expect(runtime?.status()?.docs?.rejected).toBe(1);
|
|
1422
|
-
// …until the slow re-probe fires, with the ORIGINAL token (unchanged).
|
|
1423
|
-
timers.fire(300_000);
|
|
1424
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1425
|
-
expect(made).toHaveLength(2);
|
|
1426
|
-
expect(made[1]?.token).toBe('mau_stale');
|
|
1427
|
-
|
|
1428
|
-
await runtime?.stop();
|
|
1429
|
-
} finally {
|
|
1430
|
-
console.warn = origWarn;
|
|
1431
|
-
console.log = origLog;
|
|
1432
|
-
}
|
|
1433
|
-
});
|
|
1434
|
-
|
|
1435
|
-
test('a stored expiry arms a pre-expiry renewal at ~80% of the remaining life', async () => {
|
|
1436
|
-
const url = 'https://hub.example.com';
|
|
1437
|
-
const cfgPath = process.env.HUBS_CONFIG_PATH;
|
|
1438
|
-
if (!cfgPath) throw new Error('HUBS_CONFIG_PATH not set by beforeEach');
|
|
1439
|
-
writeFileSync(
|
|
1440
|
-
cfgPath,
|
|
1441
|
-
JSON.stringify({
|
|
1442
|
-
hubs: { [url]: { token: 'mau_stale', linkedAt: 1, expiresAt: Date.now() + 100_000 } },
|
|
1443
|
-
})
|
|
1444
|
-
);
|
|
1445
|
-
chmodSync(cfgPath, 0o600);
|
|
1446
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1447
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1448
|
-
|
|
1449
|
-
const timers = fakeTimerQueue();
|
|
1450
|
-
const { factory } = authStubFactory();
|
|
1451
|
-
let renewCalls = 0;
|
|
1452
|
-
const origWarn = console.warn;
|
|
1453
|
-
const origLog = console.log;
|
|
1454
|
-
console.warn = () => {};
|
|
1455
|
-
console.log = () => {};
|
|
1456
|
-
try {
|
|
1457
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1458
|
-
providerFactory: factory,
|
|
1459
|
-
auth: {
|
|
1460
|
-
warnDebounceMs: 2_000,
|
|
1461
|
-
reprobeMs: 300_000,
|
|
1462
|
-
settleTimeoutMs: 15_000,
|
|
1463
|
-
setTimer: timers.setTimer,
|
|
1464
|
-
clearTimer: timers.clearTimer,
|
|
1465
|
-
renewCredential: async () => {
|
|
1466
|
-
renewCalls++;
|
|
1467
|
-
return { token: 'mau_fresh', expiresAt: null };
|
|
1468
|
-
},
|
|
1469
|
-
},
|
|
1470
|
-
});
|
|
1471
|
-
await runtime?.start();
|
|
1472
|
-
// 100 s of life left → the renewal timer sits at 80 s, so a 30 s sweep
|
|
1473
|
-
// must not reach it (only the settle timers live down there)…
|
|
1474
|
-
timers.fire(30_000);
|
|
1475
|
-
await new Promise((res) => setTimeout(res, 5));
|
|
1476
|
-
expect(renewCalls).toBe(0);
|
|
1477
|
-
// …and the 80 s sweep fires it, once, without any rejection happening.
|
|
1478
|
-
timers.fire(80_000);
|
|
1479
|
-
await new Promise((res) => setTimeout(res, 5));
|
|
1480
|
-
expect(renewCalls).toBe(1);
|
|
1481
|
-
|
|
1482
|
-
await runtime?.stop();
|
|
1483
|
-
} finally {
|
|
1484
|
-
console.warn = origWarn;
|
|
1485
|
-
console.log = origLog;
|
|
1486
|
-
}
|
|
1487
|
-
});
|
|
1488
|
-
|
|
1489
|
-
test('a successful re-probe clears the refusal, and the reconcile is a separate word', async () => {
|
|
1490
|
-
// A REGRESSION GUARD, not a falsifier — this already held. It is here
|
|
1491
|
-
// because the clear moved: it used to sit at the BOTTOM of the
|
|
1492
|
-
// post-handshake path, below a reconcile that can throw into a rejection
|
|
1493
|
-
// `settleWait` swallows, so a document that reconnected fine but failed to
|
|
1494
|
-
// settle on disk would have kept telling the user to go fix a credential
|
|
1495
|
-
// that was never the problem. The clear now runs on the handshake, and the
|
|
1496
|
-
// reconcile reports separately (`pending` vs `connected`) and loudly.
|
|
1497
|
-
const url = 'https://hub.example.com';
|
|
1498
|
-
writeHubsConfig(url, 'mau_test');
|
|
1499
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1500
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1501
|
-
|
|
1502
|
-
const timers = fakeTimerQueue();
|
|
1503
|
-
const origWarn = console.warn;
|
|
1504
|
-
const origLog = console.log;
|
|
1505
|
-
console.warn = () => {};
|
|
1506
|
-
console.log = () => {};
|
|
1507
|
-
|
|
1508
|
-
let round = 0;
|
|
1509
|
-
const factory = (args: { documentName: string; document?: Y.Doc }) => {
|
|
1510
|
-
const document = args.document ?? new Y.Doc();
|
|
1511
|
-
const first = round++ === 0;
|
|
1512
|
-
return {
|
|
1513
|
-
document,
|
|
1514
|
-
onAuthFailed(cb: (info: { reason: string }) => void) {
|
|
1515
|
-
if (first) queueMicrotask(() => cb({ reason: 'token not authorized' }));
|
|
1516
|
-
return () => {};
|
|
1517
|
-
},
|
|
1518
|
-
onceSynced: () => (first ? new Promise<void>(() => {}) : Promise.resolve()),
|
|
1519
|
-
destroy() {},
|
|
1520
|
-
};
|
|
1521
|
-
};
|
|
1522
|
-
|
|
1523
|
-
try {
|
|
1524
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1525
|
-
providerFactory: factory,
|
|
1526
|
-
auth: {
|
|
1527
|
-
warnDebounceMs: 2_000,
|
|
1528
|
-
reprobeMs: 300_000,
|
|
1529
|
-
settleTimeoutMs: 15_000,
|
|
1530
|
-
setTimer: timers.setTimer,
|
|
1531
|
-
clearTimer: timers.clearTimer,
|
|
1532
|
-
},
|
|
1533
|
-
});
|
|
1534
|
-
await runtime?.start();
|
|
1535
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1536
|
-
expect(runtime?.status().docs?.rejected).toBe(1);
|
|
1537
|
-
|
|
1538
|
-
timers.fire(300_000);
|
|
1539
|
-
await new Promise((res) => setTimeout(res, 40));
|
|
1540
|
-
|
|
1541
|
-
expect(runtime?.status().docs?.rejected).toBe(0);
|
|
1542
|
-
expect(runtime?.status().rejectedSlugs ?? []).toEqual([]);
|
|
1543
|
-
|
|
1544
|
-
await runtime?.stop();
|
|
1545
|
-
} finally {
|
|
1546
|
-
console.warn = origWarn;
|
|
1547
|
-
console.log = origLog;
|
|
1548
|
-
}
|
|
1549
|
-
});
|
|
1550
|
-
|
|
1551
|
-
test('a new process never serves the previous one’s verdict, not even mid-boot', async () => {
|
|
1552
|
-
// `_sync.json` is a file and `/_sync-status` returns whatever is in it. The
|
|
1553
|
-
// first honest snapshot of a run is not written until every provider has
|
|
1554
|
-
// been built — after a scan AND a listing fetch that waits up to 6 seconds.
|
|
1555
|
-
// For that whole window the CLI and the browser banner were reading the
|
|
1556
|
-
// LAST run's counters as current. So the window is what this asserts: the
|
|
1557
|
-
// fetch is held open, and the file must ALREADY be clean.
|
|
1558
|
-
const url = 'https://hub.example.com';
|
|
1559
|
-
writeHubsConfig(url, 'mau_test');
|
|
1560
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1561
|
-
const statusFile = join(ctx.paths.designRoot, '_sync.json');
|
|
1562
|
-
writeFileSync(
|
|
1563
|
-
statusFile,
|
|
1564
|
-
JSON.stringify({
|
|
1565
|
-
url,
|
|
1566
|
-
canvases: 76,
|
|
1567
|
-
state: 'online',
|
|
1568
|
-
docs: { synced: 0, pending: 3, rejected: 73 },
|
|
1569
|
-
rejectedSlugs: ['ui-a', 'ui-b'],
|
|
1570
|
-
})
|
|
1571
|
-
);
|
|
1572
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'a.html'), '<a/>');
|
|
1573
|
-
|
|
1574
|
-
const realFetch = globalThis.fetch;
|
|
1575
|
-
let releaseListing: () => void = () => {};
|
|
1576
|
-
const listingReached = new Promise<void>((res) => {
|
|
1577
|
-
globalThis.fetch = (async () => {
|
|
1578
|
-
res();
|
|
1579
|
-
await new Promise<void>((r) => {
|
|
1580
|
-
releaseListing = r;
|
|
1581
|
-
});
|
|
1582
|
-
return new Response(JSON.stringify({ documents: [] }), { status: 200 });
|
|
1583
|
-
}) as typeof fetch;
|
|
1584
|
-
});
|
|
1585
|
-
|
|
1586
|
-
try {
|
|
1587
|
-
const { factory } = inMemoryProviderFactory();
|
|
1588
|
-
const runtime = createSyncRuntime(ctx, { providerFactory: factory });
|
|
1589
|
-
const booting = runtime?.start();
|
|
1590
|
-
await listingReached;
|
|
1591
|
-
|
|
1592
|
-
// Mid-boot, with the listing still in flight — exactly where the stale
|
|
1593
|
-
// file used to be authoritative.
|
|
1594
|
-
const midBoot = JSON.parse(readFileSync(statusFile, 'utf8'));
|
|
1595
|
-
expect(midBoot.docs.rejected).toBe(0);
|
|
1596
|
-
expect(midBoot.rejectedSlugs ?? []).toEqual([]);
|
|
1597
|
-
expect(midBoot.state).toBe('connecting');
|
|
1598
|
-
|
|
1599
|
-
releaseListing();
|
|
1600
|
-
await booting;
|
|
1601
|
-
await runtime?.stop();
|
|
1602
|
-
} finally {
|
|
1603
|
-
globalThis.fetch = realFetch;
|
|
1604
|
-
}
|
|
1605
|
-
});
|
|
1606
|
-
|
|
1607
|
-
test('boot summary prints AFTER settle with honest counts (not the premature N/N)', async () => {
|
|
1608
|
-
const url = 'https://hub.example.com';
|
|
1609
|
-
writeHubsConfig(url, 'mau_test');
|
|
1610
|
-
const ctx = makeCtx({ url, linkedAt: 1 });
|
|
1611
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'good.html'), '<g/>');
|
|
1612
|
-
writeFileSync(join(ctx.paths.designRoot, 'ui', 'bad.html'), '<b/>');
|
|
1613
|
-
|
|
1614
|
-
const timers = fakeTimerQueue();
|
|
1615
|
-
const logs: string[] = [];
|
|
1616
|
-
const origLog = console.log;
|
|
1617
|
-
const origWarn = console.warn;
|
|
1618
|
-
console.log = (...args: unknown[]) => {
|
|
1619
|
-
logs.push(args.map(String).join(' '));
|
|
1620
|
-
};
|
|
1621
|
-
console.warn = () => {};
|
|
1622
|
-
|
|
1623
|
-
// 'good' syncs immediately; 'bad' is auth-rejected and never settles.
|
|
1624
|
-
const { factory, made } = authStubFactory();
|
|
1625
|
-
const mixedFactory = (args: { documentName: string; document?: Y.Doc }) => {
|
|
1626
|
-
if (args.documentName === 'ui-good') {
|
|
1627
|
-
const document = args.document ?? new Y.Doc();
|
|
1628
|
-
return {
|
|
1629
|
-
document,
|
|
1630
|
-
async onceSynced() {},
|
|
1631
|
-
destroy() {},
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
return factory(args);
|
|
1635
|
-
};
|
|
1636
|
-
|
|
1637
|
-
try {
|
|
1638
|
-
const runtime = createSyncRuntime(ctx, {
|
|
1639
|
-
providerFactory: mixedFactory,
|
|
1640
|
-
auth: {
|
|
1641
|
-
settleTimeoutMs: 15_000,
|
|
1642
|
-
warnDebounceMs: 2_000,
|
|
1643
|
-
setTimer: timers.setTimer,
|
|
1644
|
-
clearTimer: timers.clearTimer,
|
|
1645
|
-
},
|
|
1646
|
-
});
|
|
1647
|
-
await runtime?.start();
|
|
1648
|
-
made.find((m) => m.documentName === 'ui-bad')?.emitAuthFailure('invalid token');
|
|
1649
|
-
// Boot prints the linking line immediately, NOT a premature N/N.
|
|
1650
|
-
expect(logs.some((l) => l.includes('linking to'))).toBe(true);
|
|
1651
|
-
expect(logs.some((l) => l.includes('synced'))).toBe(false);
|
|
1652
|
-
|
|
1653
|
-
// Let the good handshake's microtask chain run, then hit the ceiling.
|
|
1654
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1655
|
-
timers.fire(15_000);
|
|
1656
|
-
await new Promise((res) => setTimeout(res, 10));
|
|
1657
|
-
|
|
1658
|
-
const summary = logs.find((l) => l.includes('synced'));
|
|
1659
|
-
expect(summary).toBeDefined();
|
|
1660
|
-
expect(summary).toContain('1/2 synced');
|
|
1661
|
-
expect(summary).toContain('1 auth-rejected');
|
|
1662
|
-
expect(summary).toContain('ui-bad');
|
|
1663
|
-
expect(summary).toContain('invalid-token');
|
|
1664
|
-
|
|
1665
|
-
// lastSyncAt reflects the real reconcile activity of the good canvas.
|
|
1666
|
-
expect(runtime?.status()?.lastSyncAt).not.toBeNull();
|
|
1667
|
-
expect(runtime?.status()?.docs?.synced).toBe(1);
|
|
1668
|
-
|
|
1669
|
-
await runtime?.stop();
|
|
1670
|
-
} finally {
|
|
1671
|
-
console.log = origLog;
|
|
1672
|
-
console.warn = origWarn;
|
|
1673
|
-
}
|
|
1674
|
-
});
|
|
1675
|
-
});
|