dsh-config-manager 0.8.2 → 0.10.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/lib/adapters/mcp.js +51 -15
- package/lib/adapters/messages.d.ts +1 -0
- package/lib/adapters/messages.js +2 -0
- package/lib/adapters/patch-key-guard.d.ts +23 -0
- package/lib/adapters/patch-key-guard.js +13 -0
- package/lib/adapters/plugin-data.d.ts +19 -5
- package/lib/adapters/plugin-data.js +76 -22
- package/lib/adapters/plugins.d.ts +14 -1
- package/lib/adapters/plugins.js +204 -6
- package/lib/adapters/prompts.js +15 -4
- package/lib/adapters/test-helpers.d.ts +15 -1
- package/lib/adapters/test-helpers.js +11 -0
- package/lib/cli/actions.d.ts +7 -105
- package/lib/cli/actions.js +16 -172
- package/lib/cli/control-state.d.ts +54 -0
- package/lib/cli/control-state.js +107 -0
- package/lib/cli/help.d.ts +1 -1
- package/lib/cli/help.js +21 -14
- package/lib/cli/index.js +132 -104
- package/lib/cli/sessions-repair.js +58 -22
- package/lib/cli/web/client-script.d.ts +1 -1
- package/lib/cli/web/client-script.js +71 -5
- package/lib/cli/web/page.d.ts +9 -19
- package/lib/cli/web/page.js +277 -173
- package/lib/cli/web/routes.js +85 -25
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +196 -75
- package/lib/client.js +8139 -7487
- package/lib/core/backup.d.ts +0 -4
- package/lib/core/backup.js +21 -4
- package/lib/core/boot-rescue.d.ts +1 -1
- package/lib/core/boot-rescue.js +12 -1
- package/lib/core/boot-safety.js +37 -2
- package/lib/core/conflict-decisions.js +2 -1
- package/lib/core/exporter.js +22 -1
- package/lib/core/journal.d.ts +54 -4
- package/lib/core/journal.js +158 -35
- package/lib/core/local-plugin-host.d.ts +29 -0
- package/lib/core/local-plugin-host.js +55 -48
- package/lib/core/messages.d.ts +17 -0
- package/lib/core/messages.js +34 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +20 -2
- package/lib/core/patch-chain.d.ts +65 -0
- package/lib/core/patch-chain.js +100 -0
- package/lib/core/patch-document.d.ts +32 -4
- package/lib/core/patch-document.js +48 -17
- package/lib/core/patch-secret-guard.d.ts +49 -0
- package/lib/core/patch-secret-guard.js +164 -0
- package/lib/core/reconcile.d.ts +8 -0
- package/lib/core/reconcile.js +18 -3
- package/lib/core/reinstall.d.ts +2 -0
- package/lib/core/reinstall.js +6 -2
- package/lib/core/restore.js +31 -6
- package/lib/core/section-sanitize.d.ts +32 -0
- package/lib/core/section-sanitize.js +13 -0
- package/lib/core/snapshot-diff.d.ts +30 -0
- package/lib/core/snapshot-diff.js +56 -20
- package/lib/core/startup-barrier.js +8 -2
- package/lib/core/types.d.ts +38 -1
- package/lib/core/update-check.js +51 -2
- package/lib/foreign/kernel.js +9 -2
- package/lib/foreign/read-claude-plugins.js +29 -11
- package/lib/foreign/read-dsh.js +31 -2
- package/lib/foreign/session-ir.js +50 -9
- package/lib/foreign/session-read.d.ts +8 -0
- package/lib/foreign/session-read.js +26 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +42 -47
- package/lib/profiles/dsh-profile-io.d.ts +20 -0
- package/lib/profiles/dsh-profile-io.js +27 -0
- package/lib/profiles/dsh-profile-manager.d.ts +27 -0
- package/lib/profiles/dsh-profile-manager.js +45 -4
- package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
- package/lib/profiles/dsh-profile-runtime.js +16 -3
- package/lib/profiles/process-control.d.ts +18 -1
- package/lib/profiles/process-control.js +25 -1
- package/lib/routes/profiles.js +2 -1
- package/lib/routes/sync.js +19 -1
- package/lib/schema/types.d.ts +11 -0
- package/lib/security/redaction.js +22 -6
- package/lib/sync/autosync-repeat.d.ts +27 -0
- package/lib/sync/autosync-repeat.js +23 -0
- package/lib/sync/autosync-scheduler.d.ts +47 -2
- package/lib/sync/autosync-scheduler.js +217 -53
- package/lib/sync/baseline-heal.js +7 -0
- package/lib/sync/baseline-record.d.ts +67 -0
- package/lib/sync/baseline-record.js +74 -0
- package/lib/sync/blob-store.js +13 -0
- package/lib/sync/content-diff.d.ts +39 -0
- package/lib/sync/content-diff.js +46 -0
- package/lib/sync/git/git-transport.d.ts +32 -1
- package/lib/sync/git/git-transport.js +146 -26
- package/lib/sync/github-auth.d.ts +17 -1
- package/lib/sync/github-auth.js +37 -1
- package/lib/sync/local-changes.d.ts +15 -0
- package/lib/sync/local-changes.js +39 -0
- package/lib/sync/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/merge-keyed.d.ts +68 -0
- package/lib/sync/merge-keyed.js +124 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/patch-line-identity.d.ts +19 -0
- package/lib/sync/patch-line-identity.js +99 -0
- package/lib/sync/pending-merge.d.ts +41 -0
- package/lib/sync/pending-merge.js +61 -0
- package/lib/sync/plugin-removals.d.ts +15 -15
- package/lib/sync/plugin-removals.js +134 -83
- package/lib/sync/push-skip.d.ts +55 -0
- package/lib/sync/push-skip.js +70 -0
- package/lib/sync/s3/s3-transport.d.ts +14 -2
- package/lib/sync/s3/s3-transport.js +72 -48
- package/lib/sync/sync-engine.d.ts +44 -51
- package/lib/sync/sync-engine.js +160 -194
- package/lib/sync/sync-history.d.ts +7 -0
- package/lib/sync/sync-state.d.ts +28 -0
- package/lib/sync/sync-state.js +20 -0
- package/lib/sync/transport.d.ts +12 -3
- package/lib/sync/transport.js +13 -4
- package/lib/sync/webdav/webdav-transport.d.ts +19 -2
- package/lib/sync/webdav/webdav-transport.js +81 -40
- package/lib/sync/workspace-merge.d.ts +8 -2
- package/lib/ui/artifact-view.d.ts +1 -1
- package/lib/ui/commands.js +5 -11
- package/lib/ui/dsh-profiles-view.d.ts +8 -3
- package/lib/ui/dsh-profiles-view.js +9 -5
- package/lib/ui/foreign-view.d.ts +14 -0
- package/lib/ui/foreign-view.js +34 -0
- package/lib/ui/i18n.d.ts +7 -1
- package/lib/ui/i18n.js +15 -2
- package/lib/ui/menu-placement.js +1 -1
- package/lib/ui/migration-consult-view.d.ts +11 -0
- package/lib/ui/migration-consult-view.js +15 -0
- package/lib/ui/overview-view.d.ts +7 -0
- package/lib/ui/overview-view.js +3 -0
- package/lib/ui/report.d.ts +9 -0
- package/lib/ui/report.js +17 -4
- package/lib/ui/selection-model.d.ts +10 -2
- package/lib/ui/selection-model.js +23 -3
- package/lib/utils/async-once.d.ts +11 -0
- package/lib/utils/async-once.js +15 -0
- package/lib/utils/patch-chain-read.d.ts +51 -0
- package/lib/utils/patch-chain-read.js +240 -0
- package/lib/utils/patch-yaml.d.ts +39 -1
- package/lib/utils/patch-yaml.js +82 -2
- package/lib/utils/paths.d.ts +13 -0
- package/lib/utils/paths.js +35 -0
- package/lib/utils/workdir-lock.js +18 -3
- package/package.json +3 -2
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +52 -14
- package/src/adapters/messages.ts +2 -0
- package/src/adapters/patch-key-guard.ts +29 -0
- package/src/adapters/plugin-data.test.ts +126 -0
- package/src/adapters/plugin-data.ts +97 -26
- package/src/adapters/plugins.test.ts +403 -0
- package/src/adapters/plugins.ts +198 -8
- package/src/adapters/prompts.ts +15 -4
- package/src/adapters/test-helpers.ts +15 -1
- package/src/cli/actions.test.ts +74 -1
- package/src/cli/actions.ts +27 -246
- package/src/cli/control-state.ts +143 -0
- package/src/cli/help.ts +21 -14
- package/src/cli/index.ts +123 -107
- package/src/cli/sessions-repair.ts +55 -22
- package/src/cli/web/client-script.ts +71 -5
- package/src/cli/web/page.ts +327 -208
- package/src/cli/web/routes.ts +85 -25
- package/src/cli/web/web.test.ts +65 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/ConfigManagerSection.tsx +8 -4
- package/src/client/about/AboutPanel.tsx +9 -12
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- package/src/client/api.ts +2 -1
- package/src/client/chat/ChatEntryView.tsx +2 -2
- package/src/client/chat/rollback-entry-view.ts +6 -1
- package/src/client/common/CommandPalette.tsx +6 -3
- package/src/client/common/ConfirmDialog.tsx +29 -12
- package/src/client/common/ContentPicker.tsx +24 -24
- package/src/client/common/Modal.tsx +12 -5
- package/src/client/common/MoreMenu.tsx +4 -1
- package/src/client/common/RunsCenter.tsx +103 -32
- package/src/client/common/Select.tsx +2 -2
- package/src/client/common/floating-bounds.ts +1 -1
- package/src/client/common/floating-units.test.ts +1 -2
- package/src/client/common/plan-text-redaction.test.ts +190 -5
- package/src/client/common/runs-center-guard.test.ts +60 -0
- package/src/client/common/runs-center-view.test.ts +128 -0
- package/src/client/common/runs-center-view.ts +96 -0
- package/src/client/common/section-title-action.test.ts +66 -0
- package/src/client/common/ui.tsx +93 -30
- package/src/client/config-manager.module.css +1515 -270
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +22 -25
- package/src/client/environment/maintenance/DiskUsageCard.tsx +69 -96
- package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
- package/src/client/export/ExportView.tsx +7 -16
- package/src/client/history/HistoryPanel.tsx +88 -28
- package/src/client/history/history-locales.ts +3 -3
- package/src/client/home/BackupScheduleCard.tsx +77 -69
- package/src/client/home/HomePanel.tsx +47 -12
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +67 -9
- package/src/client/import/ImportWizardView.tsx +4 -4
- package/src/client/import/PathMappingForm.tsx +36 -9
- package/src/client/import/PathPickerDialog.tsx +2 -1
- package/src/client/import/import-wizard-split.test.ts +1 -1
- package/src/client/import/import-wizard-steps.tsx +51 -39
- package/src/client/import/use-import-wizard-controller.test.ts +129 -0
- package/src/client/import/use-import-wizard-controller.ts +116 -22
- package/src/client/library/ArtifactRow.tsx +2 -2
- package/src/client/library/BackupInspectView.tsx +21 -15
- package/src/client/library/LibraryActions.tsx +116 -28
- package/src/client/library/LibraryPanel.tsx +14 -15
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +15 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +4 -2
- package/src/client/locales/import.ts +5 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +2 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketImportReview.tsx +4 -4
- package/src/client/market/MarketPanel.tsx +58 -56
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +8 -15
- package/src/client/market/MyConfigsWizard.tsx +7 -12
- package/src/client/market/market-locales.ts +0 -6
- package/src/client/market/my-configs-split.test.ts +2 -1
- package/src/client/nav-menu-clip-guard.test.ts +52 -0
- package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
- package/src/client/recovery/RecoveryPanel.tsx +35 -22
- package/src/client/recovery/RollbackCard.tsx +132 -75
- package/src/client/recovery/RollbackFileChanges.tsx +40 -27
- package/src/client/recovery/SessionHealthCard.tsx +2 -2
- package/src/client/recovery/SessionHealthDialog.tsx +5 -7
- package/src/client/recovery/SessionLayoutSection.tsx +3 -5
- package/src/client/recovery/recovery-locales.ts +12 -8
- package/src/client/recovery/rollback-enabled.ts +29 -0
- package/src/client/recovery/use-recovery-write.ts +5 -0
- package/src/client/run-store.test.ts +30 -0
- package/src/client/run-store.ts +21 -1
- package/src/client/sync/AddChannelCard.tsx +65 -0
- package/src/client/sync/AutosyncCard.tsx +184 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +5 -7
- package/src/client/sync/PushPreviewCard.tsx +2 -1
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +130 -133
- package/src/client/sync/SyncLogList.tsx +29 -14
- package/src/client/sync/SyncPanel.tsx +188 -185
- package/src/client/sync/SyncProbeRow.tsx +5 -7
- package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
- package/src/client/sync/SyncSecuritySection.tsx +157 -0
- package/src/client/sync/SyncSettingsDialog.tsx +293 -0
- package/src/client/sync/SyncSettingsView.test.ts +26 -8
- package/src/client/sync/WorkDirCard.tsx +2 -4
- package/src/client/sync/config-clear-guard.test.ts +94 -0
- package/src/client/sync/config-clear-guard.ts +98 -0
- package/src/client/sync/config-dirty.test.ts +91 -0
- package/src/client/sync/config-dirty.ts +88 -0
- package/src/client/sync/history-model.test.ts +2 -0
- package/src/client/sync/history-model.ts +5 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +13 -1
- package/src/client/sync/sync-locales.ts +95 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-push-preview.test.ts +9 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +76 -4
- package/src/core/backup.test.ts +61 -1
- package/src/core/backup.ts +21 -4
- package/src/core/boot-rescue.test.ts +35 -0
- package/src/core/boot-rescue.ts +13 -2
- package/src/core/boot-safety.test.ts +25 -0
- package/src/core/boot-safety.ts +37 -2
- package/src/core/conflict-decisions.ts +2 -1
- package/src/core/exporter.ts +21 -1
- package/src/core/journal.test.ts +183 -0
- package/src/core/journal.ts +163 -25
- package/src/core/local-plugin-host.test.ts +68 -2
- package/src/core/local-plugin-host.ts +31 -4
- package/src/core/messages.ts +34 -0
- package/src/core/migration-history.test.ts +27 -0
- package/src/core/migration-history.ts +12 -4
- package/src/core/model-tools.test.ts +67 -0
- package/src/core/model-tools.ts +22 -4
- package/src/core/patch-chain.test.ts +83 -0
- package/src/core/patch-chain.ts +150 -0
- package/src/core/patch-document.test.ts +48 -1
- package/src/core/patch-document.ts +66 -15
- package/src/core/patch-layers.test.ts +1 -1
- package/src/core/patch-secret-guard.test.ts +110 -0
- package/src/core/patch-secret-guard.ts +176 -0
- package/src/core/reconcile.ts +32 -4
- package/src/core/reinstall.ts +8 -2
- package/src/core/restore.ts +32 -7
- package/src/core/section-sanitize.ts +37 -0
- package/src/core/smoke.test.ts +2 -1
- package/src/core/snapshot-diff.test.ts +73 -1
- package/src/core/snapshot-diff.ts +66 -21
- package/src/core/startup-barrier.test.ts +64 -0
- package/src/core/startup-barrier.ts +8 -2
- package/src/core/types.ts +43 -2
- package/src/core/update-check.test.ts +40 -0
- package/src/core/update-check.ts +53 -2
- package/src/foreign/claude-code.test.ts +5 -0
- package/src/foreign/claude-plugins.test.ts +57 -0
- package/src/foreign/claude-sessions-bytes.test.ts +7 -1
- package/src/foreign/dsh.test.ts +23 -0
- package/src/foreign/kernel.ts +9 -2
- package/src/foreign/read-claude-plugins.ts +32 -11
- package/src/foreign/read-dsh.ts +33 -2
- package/src/foreign/session-ir.test.ts +67 -0
- package/src/foreign/session-ir.ts +54 -14
- package/src/foreign/session-read.ts +23 -0
- package/src/index.facade.test.ts +186 -6
- package/src/index.ts +53 -47
- package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
- package/src/profiles/dsh-profile-io.ts +29 -0
- package/src/profiles/dsh-profile-manager.test.ts +30 -0
- package/src/profiles/dsh-profile-manager.ts +53 -5
- package/src/profiles/dsh-profile-runtime.test.ts +29 -7
- package/src/profiles/dsh-profile-runtime.ts +17 -3
- package/src/profiles/process-control.test.ts +97 -0
- package/src/profiles/process-control.ts +28 -1
- package/src/routes/profiles.ts +2 -1
- package/src/routes/sync.ts +19 -1
- package/src/schema/types.ts +16 -1
- package/src/security/redaction.test.ts +31 -0
- package/src/security/redaction.ts +23 -6
- package/src/security/security.test.ts +1 -1
- package/src/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +515 -0
- package/src/sync/autosync-scheduler.ts +225 -51
- package/src/sync/baseline-heal.ts +6 -0
- package/src/sync/baseline-record.ts +135 -0
- package/src/sync/blob-store.test.ts +16 -0
- package/src/sync/blob-store.ts +13 -0
- package/src/sync/content-diff.test.ts +95 -0
- package/src/sync/content-diff.ts +79 -0
- package/src/sync/git/git-transport.test.ts +151 -4
- package/src/sync/git/git-transport.ts +143 -27
- package/src/sync/github-auth.test.ts +26 -1
- package/src/sync/github-auth.ts +37 -1
- package/src/sync/local-changes.ts +40 -0
- package/src/sync/merge-apply-plan.ts +117 -0
- package/src/sync/merge-keyed.test.ts +167 -0
- package/src/sync/merge-keyed.ts +160 -0
- package/src/sync/messages.ts +3 -0
- package/src/sync/patch-line-identity.test.ts +73 -0
- package/src/sync/patch-line-identity.ts +105 -0
- package/src/sync/pending-merge.test.ts +41 -0
- package/src/sync/pending-merge.ts +85 -0
- package/src/sync/plugin-removals.test.ts +199 -39
- package/src/sync/plugin-removals.ts +150 -64
- package/src/sync/push-skip.test.ts +326 -0
- package/src/sync/push-skip.ts +102 -0
- package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
- package/src/sync/s3/s3-transport.ts +76 -42
- package/src/sync/sync-config.test.ts +39 -12
- package/src/sync/sync-device-identity.test.ts +3 -0
- package/src/sync/sync-engine.test.ts +465 -12
- package/src/sync/sync-engine.ts +189 -193
- package/src/sync/sync-history.ts +7 -0
- package/src/sync/sync-state.ts +48 -0
- package/src/sync/transport.test.ts +13 -1
- package/src/sync/transport.ts +12 -4
- package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
- package/src/sync/webdav/webdav-transport.ts +86 -34
- package/src/sync/workspace-merge.ts +9 -2
- package/src/ui/artifact-view.ts +1 -1
- package/src/ui/commands.test.ts +11 -0
- package/src/ui/commands.ts +5 -14
- package/src/ui/dsh-profiles-view.test.ts +16 -0
- package/src/ui/dsh-profiles-view.ts +11 -5
- package/src/ui/foreign-view.test.ts +49 -0
- package/src/ui/foreign-view.ts +47 -0
- package/src/ui/i18n.ts +15 -2
- package/src/ui/menu-placement.ts +1 -1
- package/src/ui/migration-consult-view.test.ts +20 -1
- package/src/ui/migration-consult-view.ts +17 -0
- package/src/ui/overview-view.ts +10 -0
- package/src/ui/report.test.ts +25 -1
- package/src/ui/report.ts +15 -4
- package/src/ui/selection-model.test.ts +29 -1
- package/src/ui/selection-model.ts +25 -4
- package/src/utils/async-once.ts +14 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-chain-read.test.ts +171 -0
- package/src/utils/patch-chain-read.ts +259 -0
- package/src/utils/patch-yaml.test.ts +215 -3
- package/src/utils/patch-yaml.ts +98 -2
- package/src/utils/paths.test.ts +14 -1
- package/src/utils/paths.ts +35 -0
- package/src/utils/workdir-lock.test.ts +69 -0
- package/src/utils/workdir-lock.ts +17 -3
- package/lib/ui/path-mapping.d.ts +0 -38
- package/lib/ui/path-mapping.js +0 -75
- package/src/client/common/InfoHint.tsx +0 -289
- package/src/client/common/info-hint-guard.test.ts +0 -1119
- package/src/client/sync/DecryptPasswordCard.tsx +0 -48
- package/src/client/sync/SecurityOptionsCard.tsx +0 -97
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
- package/src/ui/path-mapping.test.ts +0 -67
- package/src/ui/path-mapping.ts +0 -103
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* audit-sync sync-P6-1 / sync-P6-4(P3)的回归钉子(S3 兼容通道,与 WebDAV 同型同口径):
|
|
3
|
+
*
|
|
4
|
+
* P6-1:delete 必须先条件写索引、后删对象。旧顺序在索引 PUT 冲突时留下「索引指向已删对象」的条目,
|
|
5
|
+
* list 不校验存在性 ⇒ 别的设备 pull 到该 id 即 notfound 硬失败。最坏情况改为「孤儿对象」:
|
|
6
|
+
* 索引里不存在、list 看不到、pull 不会命中,重跑 delete 可补删。
|
|
7
|
+
*
|
|
8
|
+
* P6-4:blob 索引的「读失败」与「确实没有索引」必须分开(404 才是空);读失败一律中止,
|
|
9
|
+
* 绝不用一次整体 PUT 把已登记条目覆盖掉。
|
|
10
|
+
*/
|
|
11
|
+
import test from 'node:test'
|
|
12
|
+
import assert from 'node:assert/strict'
|
|
13
|
+
|
|
14
|
+
import { S3Transport, S3TransportError } from './s3-transport.ts'
|
|
15
|
+
import type { S3RequestFn, S3Response, S3TransportOptions } from './s3-transport.ts'
|
|
16
|
+
import type { SyncSnapshot } from '../transport.ts'
|
|
17
|
+
import { s3Msg } from './messages.ts'
|
|
18
|
+
|
|
19
|
+
const ENDPOINT = 'https://minio.example.com:9000'
|
|
20
|
+
const BUCKET = 'demo-bucket'
|
|
21
|
+
const PREFIX = 'dsh-config-manager'
|
|
22
|
+
const ACCESS_KEY_ID = 'AKIAIOSFODNN7EXAMPLE'
|
|
23
|
+
const SECRET = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'
|
|
24
|
+
const BASE_OBJECT = ENDPOINT + '/' + BUCKET + '/' + PREFIX
|
|
25
|
+
const BLOBS_PREFIX = BASE_OBJECT + '/blobs/'
|
|
26
|
+
const INDEX_URL = BASE_OBJECT + '/index.json'
|
|
27
|
+
const BLOBS_INDEX_URL = BASE_OBJECT + '/blobs-index.json'
|
|
28
|
+
const SNAPSHOT_URL = BASE_OBJECT + '/snap-001.json'
|
|
29
|
+
const OLD_HASH = 'a'.repeat(64)
|
|
30
|
+
const NEW_HASH = 'b'.repeat(64)
|
|
31
|
+
|
|
32
|
+
interface S3Call { method: string; url: string; headers: Record<string, string>; body?: string }
|
|
33
|
+
|
|
34
|
+
function res(status: number, bodyText = '', headers?: Record<string, string>): S3Response {
|
|
35
|
+
return {
|
|
36
|
+
status,
|
|
37
|
+
ok: status >= 200 && status < 300,
|
|
38
|
+
...(headers !== undefined ? { headers } : {}),
|
|
39
|
+
async text() { return bodyText; },
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function record(calls: S3Call[], handler: (m: S3Call) => S3Response): S3RequestFn {
|
|
44
|
+
return async (method, url, opts = {}) => {
|
|
45
|
+
const rec: S3Call = { method, url, headers: opts.headers ?? {}, ...(opts.body !== undefined ? { body: opts.body } : {}) };
|
|
46
|
+
calls.push(rec);
|
|
47
|
+
return handler(rec);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function makeOptions(request: S3RequestFn): S3TransportOptions {
|
|
52
|
+
return {
|
|
53
|
+
provider: 'minio',
|
|
54
|
+
endpoint: ENDPOINT,
|
|
55
|
+
region: 'us-east-1',
|
|
56
|
+
bucket: BUCKET,
|
|
57
|
+
accessKeyId: ACCESS_KEY_ID,
|
|
58
|
+
credentials: { getSecretAccessKey: async () => SECRET },
|
|
59
|
+
pathStyle: true,
|
|
60
|
+
request,
|
|
61
|
+
now: () => new Date('2026-10-18T10:00:00.000Z'),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const META = {
|
|
66
|
+
id: 'snap-001',
|
|
67
|
+
createdAt: '2026-10-18T09:00:00.000Z',
|
|
68
|
+
sections: {},
|
|
69
|
+
manifest: { schemaVersion: 1, dshVersion: '1', platform: 'win32', sectionIds: [], containsSecrets: false },
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function sessionsSnapshot(): SyncSnapshot {
|
|
73
|
+
return {
|
|
74
|
+
id: 'snap-001',
|
|
75
|
+
createdAt: '2026-10-18T10:00:00.000Z',
|
|
76
|
+
manifest: {
|
|
77
|
+
schemaVersion: 1,
|
|
78
|
+
dshVersion: '1.2.3',
|
|
79
|
+
platform: 'win32',
|
|
80
|
+
sectionIds: ['sessions'],
|
|
81
|
+
containsSecrets: false,
|
|
82
|
+
},
|
|
83
|
+
sections: {
|
|
84
|
+
sessions: {
|
|
85
|
+
version: 1,
|
|
86
|
+
files: [
|
|
87
|
+
{ relativePath: 's1.jsonl', data: new TextEncoder().encode('one'), contentHash: OLD_HASH },
|
|
88
|
+
{ relativePath: 's2.jsonl', data: new TextEncoder().encode('two'), contentHash: NEW_HASH },
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
} as unknown as SyncSnapshot;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const callsOf = (calls: S3Call[], method: string, url: string): S3Call[] =>
|
|
96
|
+
calls.filter((c) => c.method === method && c.url === url);
|
|
97
|
+
|
|
98
|
+
/* ---------------- P6-1:删除顺序 ---------------- */
|
|
99
|
+
|
|
100
|
+
test('P6-1(删除路径):索引写回 412 → 快照对象零 DELETE(绝不留「索引指向已删对象」)', async () => {
|
|
101
|
+
const calls: S3Call[] = [];
|
|
102
|
+
const t = new S3Transport(makeOptions(record(calls, (m) => {
|
|
103
|
+
if (m.method === 'GET' && m.url === INDEX_URL) return res(200, JSON.stringify([META]), { etag: '"v1-del"' });
|
|
104
|
+
if (m.method === 'PUT' && m.url === INDEX_URL) return res(412, 'precondition failed');
|
|
105
|
+
if (m.method === 'DELETE' && m.url === SNAPSHOT_URL) return res(204, '');
|
|
106
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
107
|
+
})));
|
|
108
|
+
|
|
109
|
+
await assert.rejects(
|
|
110
|
+
() => t.delete('snap-001'),
|
|
111
|
+
(err: unknown) => {
|
|
112
|
+
assert.ok(err instanceof S3TransportError);
|
|
113
|
+
assert.equal(err.kind, 'conflict');
|
|
114
|
+
assert.equal(err.message, s3Msg('sync.s3.concurrentWrite', { status: '412', url: INDEX_URL }));
|
|
115
|
+
return true;
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
assert.equal(callsOf(calls, 'DELETE', SNAPSHOT_URL).length, 0, '索引没写成功就绝不许删对象');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('P6-1(删除路径):成功路径顺序 = 先条件写索引(if-match),后 DELETE 快照对象', async () => {
|
|
122
|
+
const calls: S3Call[] = [];
|
|
123
|
+
const t = new S3Transport(makeOptions(record(calls, (m) => {
|
|
124
|
+
if (m.method === 'GET' && m.url === INDEX_URL) return res(200, JSON.stringify([META]), { etag: '"v1-del"' });
|
|
125
|
+
if (m.method === 'PUT' && m.url === INDEX_URL) return res(200, '');
|
|
126
|
+
if (m.method === 'DELETE' && m.url === SNAPSHOT_URL) return res(204, '');
|
|
127
|
+
if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(404, '');
|
|
128
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
129
|
+
})));
|
|
130
|
+
|
|
131
|
+
await t.delete('snap-001');
|
|
132
|
+
|
|
133
|
+
const puts = callsOf(calls, 'PUT', INDEX_URL);
|
|
134
|
+
assert.equal(puts.length, 1);
|
|
135
|
+
assert.equal(puts[0]!.headers['if-match'], '"v1-del"', '索引写回仍是条件写');
|
|
136
|
+
assert.equal(puts[0]!.body, '[]');
|
|
137
|
+
const putAt = calls.findIndex((c) => c.method === 'PUT' && c.url === INDEX_URL);
|
|
138
|
+
const delAt = calls.findIndex((c) => c.method === 'DELETE' && c.url === SNAPSHOT_URL);
|
|
139
|
+
assert.ok(putAt >= 0 && delAt >= 0);
|
|
140
|
+
assert.ok(putAt < delAt, '索引必须先落盘,再删对象(P6-1)');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('P6-1(删除路径):索引无该 id 且对象存在 → 只删对象,不写回索引', async () => {
|
|
144
|
+
const calls: S3Call[] = [];
|
|
145
|
+
const t = new S3Transport(makeOptions(record(calls, (m) => {
|
|
146
|
+
if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1-del"' });
|
|
147
|
+
if (m.method === 'DELETE' && m.url === SNAPSHOT_URL) return res(204, '');
|
|
148
|
+
if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(404, '');
|
|
149
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
150
|
+
})));
|
|
151
|
+
|
|
152
|
+
await t.delete('snap-001');
|
|
153
|
+
|
|
154
|
+
assert.equal(callsOf(calls, 'PUT', INDEX_URL).length, 0, '索引无变化就不写回(N1③ 口径)');
|
|
155
|
+
assert.equal(callsOf(calls, 'DELETE', SNAPSHOT_URL).length, 1, '孤儿对象仍按用户意图删掉');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
/* ---------------- P6-4:blob 索引三态读 ---------------- */
|
|
159
|
+
|
|
160
|
+
test('P6-4:blob 索引 GET 500 → 上传可重试失败,快照与 blobs-index 零写入', async () => {
|
|
161
|
+
const calls: S3Call[] = [];
|
|
162
|
+
const t = new S3Transport(makeOptions(record(calls, (m) => {
|
|
163
|
+
if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
|
|
164
|
+
if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(503, 'backend down');
|
|
165
|
+
if (m.method === 'PUT' && m.url === SNAPSHOT_URL) return res(200, '');
|
|
166
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
167
|
+
})));
|
|
168
|
+
|
|
169
|
+
await assert.rejects(
|
|
170
|
+
() => t.upload(sessionsSnapshot()),
|
|
171
|
+
(err: unknown) => {
|
|
172
|
+
assert.ok(err instanceof S3TransportError);
|
|
173
|
+
assert.equal(err.kind, 'server');
|
|
174
|
+
assert.equal(err.retryable, true);
|
|
175
|
+
return true;
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
assert.equal(callsOf(calls, 'PUT', SNAPSHOT_URL).length, 0, '读不出来就零写入');
|
|
179
|
+
assert.equal(callsOf(calls, 'PUT', BLOBS_INDEX_URL).length, 0, '绝不整体覆盖');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('P6-4:blob 索引 200 + 坏 JSON → protocol 错误,绝不覆盖成只有本次条目', async () => {
|
|
183
|
+
const calls: S3Call[] = [];
|
|
184
|
+
const t = new S3Transport(makeOptions(record(calls, (m) => {
|
|
185
|
+
if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
|
|
186
|
+
if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(200, '{not-json');
|
|
187
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
188
|
+
})));
|
|
189
|
+
|
|
190
|
+
await assert.rejects(
|
|
191
|
+
() => t.upload(sessionsSnapshot()),
|
|
192
|
+
(err: unknown) => {
|
|
193
|
+
assert.ok(err instanceof S3TransportError);
|
|
194
|
+
assert.equal(err.kind, 'protocol');
|
|
195
|
+
assert.equal(err.retryable, false);
|
|
196
|
+
return true;
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
assert.equal(callsOf(calls, 'PUT', BLOBS_INDEX_URL).length, 0);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('P6-4:写回前再读 blobs-index 失败 → 绝不 PUT(已登记条目不得被覆盖掉)', async () => {
|
|
203
|
+
const calls: S3Call[] = [];
|
|
204
|
+
let blobIdxReads = 0;
|
|
205
|
+
const t = new S3Transport(makeOptions(record(calls, (m) => {
|
|
206
|
+
if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
|
|
207
|
+
if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) {
|
|
208
|
+
blobIdxReads += 1;
|
|
209
|
+
return blobIdxReads === 1 ? res(200, JSON.stringify({ [OLD_HASH]: 1 })) : res(500, 'flaky');
|
|
210
|
+
}
|
|
211
|
+
if (m.method === 'PUT' && m.url === SNAPSHOT_URL) return res(200, '');
|
|
212
|
+
if (m.method === 'PUT' && m.url === INDEX_URL) return res(200, '');
|
|
213
|
+
if (m.method === 'PUT' && m.url.startsWith(BLOBS_PREFIX)) return res(200, '');
|
|
214
|
+
if (m.method === 'PUT' && m.url === BLOBS_INDEX_URL) return res(200, '');
|
|
215
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
216
|
+
})));
|
|
217
|
+
|
|
218
|
+
await assert.rejects(
|
|
219
|
+
() => t.upload(sessionsSnapshot()),
|
|
220
|
+
(err: unknown) => {
|
|
221
|
+
assert.ok(err instanceof S3TransportError);
|
|
222
|
+
assert.equal(err.kind, 'server');
|
|
223
|
+
return true;
|
|
224
|
+
},
|
|
225
|
+
);
|
|
226
|
+
assert.equal(blobIdxReads, 2, '跳过判定一次 + 合并写回一次');
|
|
227
|
+
assert.equal(callsOf(calls, 'PUT', BLOBS_INDEX_URL).length, 0, '读失败时绝不整体 PUT(P6-4 的核心)');
|
|
228
|
+
assert.equal(callsOf(calls, 'PUT', SNAPSHOT_URL).length, 1, '快照已落盘:本次 blob 漏登记只占空间,不误删');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('P6-4:blob 索引 404(确实没有索引)→ 照常上传并新建索引', async () => {
|
|
232
|
+
const calls: S3Call[] = [];
|
|
233
|
+
const t = new S3Transport(makeOptions(record(calls, (m) => {
|
|
234
|
+
if (m.method === 'GET' && m.url === INDEX_URL) return res(200, '[]', { etag: '"v1"' });
|
|
235
|
+
if (m.method === 'GET' && m.url === BLOBS_INDEX_URL) return res(404, '');
|
|
236
|
+
if (m.method === 'PUT' && m.url === SNAPSHOT_URL) return res(200, '');
|
|
237
|
+
if (m.method === 'PUT' && m.url === INDEX_URL) return res(200, '');
|
|
238
|
+
if (m.method === 'PUT' && m.url === BLOBS_INDEX_URL) return res(200, '');
|
|
239
|
+
if (m.method === 'PUT' && m.url.startsWith(BLOBS_PREFIX)) return res(200, '');
|
|
240
|
+
return res(500, 'unexpected ' + m.method + ' ' + m.url);
|
|
241
|
+
})));
|
|
242
|
+
|
|
243
|
+
await t.upload(sessionsSnapshot());
|
|
244
|
+
|
|
245
|
+
const puts = callsOf(calls, 'PUT', BLOBS_INDEX_URL);
|
|
246
|
+
assert.equal(puts.length, 1, '缺资源 = 空是安全的,必须照常建索引');
|
|
247
|
+
const written = JSON.parse(puts[0]!.body ?? '{}') as Record<string, number>;
|
|
248
|
+
assert.deepEqual(Object.keys(written).sort(), [OLD_HASH, NEW_HASH].sort());
|
|
249
|
+
});
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
import type { BlobRefsSection, BlobSink } from '../blob-store.ts';
|
|
37
37
|
import {
|
|
38
38
|
classifyHttpStatus, classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS,
|
|
39
|
-
isEncryptedSections, sectionsEqual, SyncTransportError, withSyncRetry,
|
|
39
|
+
isEncryptedSections, isPreconditionFailedStatus, sectionsEqual, SyncTransportError, withSyncRetry,
|
|
40
40
|
} from '../transport.ts';
|
|
41
41
|
import type {
|
|
42
42
|
SyncProbeResult, SyncRetryOptions, SyncSnapshot, SyncSnapshotMeta, SyncTransport, SyncTransportErrorOptions,
|
|
@@ -85,15 +85,6 @@ function conditionalHeaders(
|
|
|
85
85
|
return guarded ? { 'x-oss-forbid-overwrite': 'true' } : { 'if-none-match': '*' };
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/**
|
|
89
|
-
* 条件写失败判定:412 恒是;409 仅在**确实带了条件写头**时才算
|
|
90
|
-
* (无条件的 409 另有含义,不吞;条件写头的存在由调用方显式告知)。
|
|
91
|
-
*/
|
|
92
|
-
function isConcurrentWrite(status: number, guarded: boolean): boolean {
|
|
93
|
-
if (status === 412) return true;
|
|
94
|
-
return status === 409 && guarded;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
88
|
/** 请求选项:headers / body / 覆盖默认超时(ms;0 = 不超时) */
|
|
98
89
|
export interface S3RequestOptions {
|
|
99
90
|
headers?: Record<string, string>;
|
|
@@ -372,27 +363,43 @@ export class S3Transport implements SyncTransport {
|
|
|
372
363
|
// audit-sync sync-N1(P0):与 WebDAV 同型 —— 写路径**不接受 404 = 空集合**。索引真缺失时
|
|
373
364
|
// 「远端一条快照都没有」是缺信息而非事实,沿用空索引会覆盖 index.json 并用空引用集回收 blob。
|
|
374
365
|
const { entries: idx, missing: indexMissing, etag: idxEtag } = await this.readIndexDetailed(secret);
|
|
375
|
-
const
|
|
376
|
-
if (
|
|
377
|
-
|
|
366
|
+
const key = snapshotKey(this.target.prefix, id);
|
|
367
|
+
if (indexMissing) {
|
|
368
|
+
// audit-sync sync-N1(P0):索引真缺失(404)= 缺信息而非「集合为空」→ **不写回索引、不触发 GC**,
|
|
369
|
+
// 其余快照与其引用的 blob 原样保留(与 WebDAV 同型)。目标快照文件按用户意图删除(404 视为成功)。
|
|
370
|
+
const del = await this.send('DELETE', key, { secret });
|
|
371
|
+
if (!del.res.ok && del.res.status !== 404) {
|
|
372
|
+
throw new S3TransportError(await this.failText('DELETE', del.url, del.res, secret), classifyHttpStatus(del.res.status));
|
|
373
|
+
}
|
|
374
|
+
return;
|
|
378
375
|
}
|
|
379
|
-
// audit-sync sync-N1(P0):索引真缺失(404)= 缺信息而非「集合为空」→ **不写回索引、不触发 GC**,
|
|
380
|
-
// 其余快照与其引用的 blob 原样保留(与 WebDAV 同型)。目标快照文件已按用户意图删除。
|
|
381
|
-
if (indexMissing) return;
|
|
382
376
|
const remaining = idx.filter((m) => m.id !== id);
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
377
|
+
const entryPresent = remaining.length !== idx.length;
|
|
378
|
+
// audit-sync sync-P6-1(P3):与 WebDAV 同型 —— **先写索引、后删对象**。
|
|
379
|
+
// 反序(旧实现先 DELETE 对象)的伤害:索引 PUT 408/412/409 冲突时本次删除已抛错中止,但对象没了
|
|
380
|
+
// ⇒ 索引留下指向不存在对象的条目;list() 不校验存在性,别的设备 pull 到该 id 即 notfound 硬失败。
|
|
381
|
+
// 调整顺序后的**最坏情况**:索引摘除成功而对象 DELETE 失败 ⇒ 远端留一个索引里不存在、list() 看不到、
|
|
382
|
+
// pull 不会命中的孤儿对象(只占空间);重跑 delete 会把对象补删(404 视为成功)。
|
|
383
|
+
if (entryPresent) {
|
|
384
|
+
const condHeaders = conditionalHeaders(idxEtag, false, this.target.conditionalWrite);
|
|
385
|
+
await this.reassertIndexEtag(idxEtag, secret);
|
|
386
|
+
const putIdx = await this.send('PUT', indexKey(this.target.prefix), {
|
|
387
|
+
body: JSON.stringify(remaining),
|
|
388
|
+
secret,
|
|
389
|
+
headers: condHeaders,
|
|
390
|
+
});
|
|
391
|
+
const idxFailure = await this.conditionalFailure('PUT', putIdx.url, putIdx.res, Object.keys(condHeaders).length > 0, secret);
|
|
392
|
+
if (idxFailure !== undefined) throw idxFailure;
|
|
393
|
+
if (!putIdx.res.ok) {
|
|
394
|
+
throw new S3TransportError(await this.failText('PUT', putIdx.url, putIdx.res, secret), classifyHttpStatus(putIdx.res.status));
|
|
395
|
+
}
|
|
395
396
|
}
|
|
397
|
+
// 索引已摘除(或本来就无该 id)后才动对象:404 = 不存在,视为成功
|
|
398
|
+
const del = await this.send('DELETE', key, { secret });
|
|
399
|
+
if (!del.res.ok && del.res.status !== 404) {
|
|
400
|
+
throw new S3TransportError(await this.failText('DELETE', del.url, del.res, secret), classifyHttpStatus(del.res.status));
|
|
401
|
+
}
|
|
402
|
+
if (!entryPresent && !del.res.ok) return; // 索引无该 id 且对象本就不存在 → 静默成功,无 GC 可做
|
|
396
403
|
await this.gcBlobStore(secret, remaining).catch(() => undefined);
|
|
397
404
|
}
|
|
398
405
|
|
|
@@ -435,7 +442,7 @@ export class S3Transport implements SyncTransport {
|
|
|
435
442
|
}
|
|
436
443
|
|
|
437
444
|
/**
|
|
438
|
-
* 条件写失败分类(issue #109 第二层复核):`
|
|
445
|
+
* 条件写失败分类(issue #109 第二层复核):`isPreconditionFailedStatus` 只看「状态码像不像」,
|
|
439
446
|
* 这里再问报文一句确认「对象确实已存在」。OSS 的 **409 不止 FileAlreadyExists** ——
|
|
440
447
|
* FileImmutable(Bucket 数据处于保护状态,删改都会被拒)同为 409,一律按并发写报
|
|
441
448
|
* 「别的设备改过索引」就是假话。报文读不出时仍按并发写处理(宁可让用户重跑一次,
|
|
@@ -448,7 +455,8 @@ export class S3Transport implements SyncTransport {
|
|
|
448
455
|
guarded: boolean,
|
|
449
456
|
secret: string,
|
|
450
457
|
): Promise<S3TransportError | undefined> {
|
|
451
|
-
|
|
458
|
+
// 判定与 WebDAV 通道共用 transport.ts 的唯一实现(412 恒算;409 仅在真的带了条件头时算)
|
|
459
|
+
if (!isPreconditionFailedStatus(res.status, { guarded })) return undefined;
|
|
452
460
|
if (res.status !== 409) return this.concurrentWrite(url, res.status);
|
|
453
461
|
// 只有 forbid-overwrite 方言的 409 有两种含义(FileAlreadyExists / FileImmutable);
|
|
454
462
|
// etag 方言的 409 由各家自定语义,报文不可当作判据 —— 沿用「带条件头的 409 = 并发写」。
|
|
@@ -671,7 +679,6 @@ export class S3Transport implements SyncTransport {
|
|
|
671
679
|
|
|
672
680
|
/* ---------------- P1-4:内容寻址 blob 仓 ---------------- */
|
|
673
681
|
|
|
674
|
-
/** 读取 blob 索引(哈希 → 写入时间 ms);缺失/损坏 → 空(GC 只会「少删」,不会误删) */
|
|
675
682
|
/**
|
|
676
683
|
* 远端是否已存在历史内容(t66)。判据 = **blob 仓索引对象存在**:它是本通道唯一的、
|
|
677
684
|
* 无需列举整个桶就能读到的「这里以前写过」证据(本实现未用 ListObjects)。
|
|
@@ -700,21 +707,48 @@ export class S3Transport implements SyncTransport {
|
|
|
700
707
|
}
|
|
701
708
|
}
|
|
702
709
|
|
|
710
|
+
/** 读取 blob 索引(哈希 → 写入时间 ms);只读失败即抛,绝不回落成空索引,见 readBlobIndexDetailed。 */
|
|
703
711
|
private async readBlobIndex(secret: string): Promise<Record<string, number>> {
|
|
712
|
+
return (await this.readBlobIndexDetailed(secret)).index;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* audit-sync sync-P6-4(P3):与 WebDAV 同型 —— 「读失败」与「确实没有索引」必须分开。
|
|
717
|
+
*
|
|
718
|
+
* 旧实现把非 404 与坏 JSON 一律当成空索引,紧接着 appendBlobIndex 读→合并→整体 PUT 覆盖,
|
|
719
|
+
* 一次 5xx 抖动就把远端已登记条目全丢掉(GC 从此看不见这些 blob,等于远端漏账)。三态语义:
|
|
720
|
+
* - 404 → missing = true:桶里确实没有 blob 索引,按空处理是安全的(不会被覆盖成假集合);
|
|
721
|
+
* - 其它非 2xx(5xx / 403 / …)→ 抛错(可重试):读不出来就**不许**整体覆盖;
|
|
722
|
+
* - 200 但坏 JSON / 非对象 → 抛 protocol(不可重试):索引损坏是远端状态问题,覆盖写会抹掉残存记录。
|
|
723
|
+
*
|
|
724
|
+
* 最坏情况(可重试失败):本可跳过的 blob 被重传一遍,或本次 blob 漏登记(只占空间,不误删)。
|
|
725
|
+
*/
|
|
726
|
+
private async readBlobIndexDetailed(secret: string): Promise<{ index: Record<string, number>; missing: boolean }> {
|
|
704
727
|
const sent = await this.send('GET', blobIndexKey(this.target.prefix), { secret });
|
|
705
|
-
if (sent.res.status === 404) return {};
|
|
706
|
-
if (!sent.res.ok)
|
|
728
|
+
if (sent.res.status === 404) return { index: {}, missing: true };
|
|
729
|
+
if (!sent.res.ok) {
|
|
730
|
+
throw new S3TransportError(await this.failText('GET', sent.url, sent.res, secret), classifyHttpStatus(sent.res.status));
|
|
731
|
+
}
|
|
732
|
+
let parsed: unknown;
|
|
707
733
|
try {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
734
|
+
parsed = parseJsonSafe(await sent.res.text());
|
|
735
|
+
} catch (err) {
|
|
736
|
+
throw new S3TransportError(
|
|
737
|
+
this.o.msg('sync.s3.indexInvalid', { url: sent.url, err: this.mask(String((err as Error)?.message ?? ''), secret) }),
|
|
738
|
+
{ kind: 'protocol', retryable: false },
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
742
|
+
throw new S3TransportError(
|
|
743
|
+
this.o.msg('sync.s3.indexInvalid', { url: sent.url, err: 'not an object' }),
|
|
744
|
+
{ kind: 'protocol', retryable: false },
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
const out: Record<string, number> = {};
|
|
748
|
+
for (const [hash, at] of Object.entries(parsed as Record<string, unknown>)) {
|
|
749
|
+
if (BLOB_HASH_RE.test(hash) && typeof at === 'number' && Number.isFinite(at)) out[hash] = at;
|
|
717
750
|
}
|
|
751
|
+
return { index: out, missing: false };
|
|
718
752
|
}
|
|
719
753
|
|
|
720
754
|
private async writeBlobIndex(secret: string, index: Record<string, number>): Promise<void> {
|
|
@@ -378,11 +378,14 @@ async function collectSourceFiles(dir: string): Promise<string[]> {
|
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
/**
|
|
381
|
-
* t32
|
|
382
|
-
*
|
|
383
|
-
*
|
|
381
|
+
* t32 源码守卫:通道字面量数组只允许出现在**唯一声明处**,不得有任何镜像。
|
|
382
|
+
*
|
|
383
|
+
* 历史教训:autosync-scheduler 把同一个数组写了两遍,漏改一处即某通道永不排期;
|
|
384
|
+
* 后来允许「带 satisfies 穷尽标记的客户端镜像」,但 satisfies 只拦「少写通道」,
|
|
385
|
+
* 拦不住顺序/拼写漂移,而且命令面板的镜像真的漏了 s3/gist(审计 P10-1)。
|
|
386
|
+
* 因此口径收紧为零镜像:要用通道清单就运行时 import `SYNC_CHANNELS`。
|
|
384
387
|
*/
|
|
385
|
-
test('t32
|
|
388
|
+
test('t32 源码守卫:地面代码里通道数组只有一处声明(其余零镜像)', async () => {
|
|
386
389
|
// 声明处已迁到**零依赖**的 utils/shared-constants.ts(client 半必须能运行时 import;
|
|
387
390
|
// sync/sync-config.ts 依赖 node:fs,不能被浏览器半 import)——本守卫的意图不变:
|
|
388
391
|
// 通道数组全仓只允许一处声明,其余只允许带穷尽检查标记的镜像。
|
|
@@ -421,17 +424,41 @@ test('t32 源码守卫:地面代码里通道数组只有一处声明(其余
|
|
|
421
424
|
'sync-config.ts 不得再自己声明通道数组',
|
|
422
425
|
);
|
|
423
426
|
const others = hits.filter((h) => h.text !== canonical[0]!.text || h.file !== canonical[0]!.file);
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
//
|
|
431
|
-
const hostDupes =
|
|
427
|
+
assert.deepEqual(
|
|
428
|
+
others,
|
|
429
|
+
[],
|
|
430
|
+
'除 SYNC_CHANNELS 外不得再写通道数组(含 satisfies 镜像):改为运行时 import 唯一事实源',
|
|
431
|
+
);
|
|
432
|
+
// 宿主 sync 目录不得再出现通道数组字面量(本用例已全局零镜像,这条只把错误信息指向宿主侧)
|
|
433
|
+
// 注意:从 hits 重新筛,而不是复用已断言为 [] 的 others(node:assert 会把 others 收窄成 never[])
|
|
434
|
+
const hostDupes = hits.filter((h) => h.file.startsWith('sync/') || h.file.startsWith('core/'));
|
|
432
435
|
assert.deepEqual(hostDupes, [], '宿主代码不得出现第二处通道数组: ' + JSON.stringify(hostDupes));
|
|
433
436
|
});
|
|
434
437
|
|
|
438
|
+
/**
|
|
439
|
+
* t32b 语义守卫(审计 P10-5):**派生清单必须等于权威声明**。
|
|
440
|
+
*
|
|
441
|
+
* t32 只看源码文本形状,抄漏一个通道(P10-1 的 commands.ts 只写了 git/webdav)也能过。
|
|
442
|
+
* 这条用例真实 import 命令面板与唯一事实源,逐项比对 —— 少抄 / 多抄 / 顺序漂移都必然红。
|
|
443
|
+
*/
|
|
444
|
+
test('t32b 命令面板的同步通道搜索词 == SYNC_CHANNELS(真实 import 比对)', async () => {
|
|
445
|
+
const { COMMANDS } = await import('../ui/commands.ts');
|
|
446
|
+
const goSync = COMMANDS.find((c) => c.id === 'go.sync');
|
|
447
|
+
assert.ok(goSync, '命令表必须有 go.sync,否则同步入口在面板里搜不到');
|
|
448
|
+
const channelKeywords = (goSync.keywords ?? []).filter((k) =>
|
|
449
|
+
(SYNC_CHANNELS as readonly string[]).includes(k),
|
|
450
|
+
);
|
|
451
|
+
assert.deepEqual(
|
|
452
|
+
channelKeywords,
|
|
453
|
+
[...SYNC_CHANNELS],
|
|
454
|
+
'go.sync 的通道搜索词必须逐项等于 SYNC_CHANNELS(顺序也算;别再手写清单)',
|
|
455
|
+
);
|
|
456
|
+
// 每个通道都必须真的能搜到这条命令(关键词在 filterKeywords 里是独立命中项)
|
|
457
|
+
for (const channel of SYNC_CHANNELS) {
|
|
458
|
+
assert.ok(goSync.keywords?.includes(channel), '通道 ' + channel + ' 搜不到「同步」命令');
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
435
462
|
/**
|
|
436
463
|
* t33/B7 源码守卫(t40 的 findings B7-GUARD-SCOPE 收尾 / t47 落地):
|
|
437
464
|
* src/index.ts(host 路由层)不得再手写通道数组字面量与裸通道三元判定 ——
|
|
@@ -208,6 +208,9 @@ test('⑥ push:快照 manifest 带 deviceId/deviceName,与 sync-state 落盘
|
|
|
208
208
|
assert.equal(state.deviceId, deviceId, 'manifest 的 deviceId 必须就是同步身份落盘值');
|
|
209
209
|
assert.equal(state.deviceName, deviceName);
|
|
210
210
|
|
|
211
|
+
// issue 140:内容没变的推送会被跳过(不新建快照),所以这里必须真改内容,
|
|
212
|
+
// 才能验证「同一台设备连续 push 的 device 身份稳定」这件事本身。
|
|
213
|
+
ctx.settings.ns.set('general', { value: { theme: 'light', language: 'zh-CN' }, revision: 2, secrets: [] });
|
|
211
214
|
await engine.push({ snapshotId: 'sync-dev-2' });
|
|
212
215
|
const second = transport.snapshots.get('sync-dev-2');
|
|
213
216
|
assert.ok(second !== undefined);
|