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
|
@@ -82,6 +82,22 @@ test('blob-store: 缺 blob → 硬失败(绝不静默降级成空分区)', a
|
|
|
82
82
|
await assert.rejects(() => refsToSection(refs, sink), /blob 缺失/);
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
+
test('blob-store: blob 内容与引用哈希不符 → 硬失败,绝不把错误字节当会话写回(审计 P6-3)', async () => {
|
|
86
|
+
const sink = new MemBlobSink();
|
|
87
|
+
const refs = await sectionToBlobRefs(filesSection([['--p--/a/session.jsonl.zstd', 'REAL-BYTES']]), sink);
|
|
88
|
+
const hash = refs.blobRefs[0]?.blobHash;
|
|
89
|
+
assert.ok(hash !== undefined);
|
|
90
|
+
// 远端被改坏(同哈希槽位放另一段字节):长度也变了,sizeBytes 一并拦住
|
|
91
|
+
sink.blobs.set(hash, { bytes: new TextEncoder().encode('TAMPERED'), mtimeMs: Date.now() });
|
|
92
|
+
await assert.rejects(() => refsToSection(refs, sink), /校验不符/);
|
|
93
|
+
|
|
94
|
+
// 只坏在内容、长度凑巧相同:仍然靠 sha256 拦下
|
|
95
|
+
const sameLen = new TextEncoder().encode('TAMPERED-#'); // 与 'REAL-BYTES' 同为 10 字节
|
|
96
|
+
assert.equal(sameLen.byteLength, 10);
|
|
97
|
+
sink.blobs.set(hash, { bytes: sameLen, mtimeMs: Date.now() });
|
|
98
|
+
await assert.rejects(() => refsToSection(refs, sink), /校验不符/);
|
|
99
|
+
});
|
|
100
|
+
|
|
85
101
|
test('blob-store: referencedBlobHashes 只认引用形态', () => {
|
|
86
102
|
assert.equal(referencedBlobHashes(filesSection([['a', 'B']])).size, 0, '普通 FilesSection(含 data)不算引用');
|
|
87
103
|
assert.deepEqual([...referencedBlobHashes({ version: 1, blobRefs: [{ relativePath: 'a', blobHash: 'h1', sizeBytes: 1 }] })], ['h1']);
|
package/src/sync/blob-store.ts
CHANGED
|
@@ -98,6 +98,19 @@ export async function refsToSection(refs: BlobRefsSection, sink: BlobSink): Prom
|
|
|
98
98
|
if (data === null) {
|
|
99
99
|
throw new Error(engineMsg('sync.blobMissing', { hash: ref.blobHash, path: ref.relativePath }));
|
|
100
100
|
}
|
|
101
|
+
// 内容寻址仓的引用自带 sha256(+ 字节数),取回后必须自证(审计 P6-3)。
|
|
102
|
+
// 注释承诺「远端仓被清理坏/被手工删过」必须硬失败,但此前只覆盖「删了」:
|
|
103
|
+
// 内容被改、半截写、base64 传输丢字符都会畅通无阻地把错误字节当成会话原样写回,
|
|
104
|
+
// 而「静默损坏」比「硬失败」更糟 —— 用户看不到任何错误,只发现对话内容变了。
|
|
105
|
+
const actualHash = sha256Hex(data);
|
|
106
|
+
if (actualHash !== ref.blobHash || (ref.sizeBytes !== undefined && data.byteLength !== ref.sizeBytes)) {
|
|
107
|
+
throw new Error(engineMsg('sync.blobCorrupt', {
|
|
108
|
+
hash: ref.blobHash,
|
|
109
|
+
path: ref.relativePath,
|
|
110
|
+
actual: actualHash,
|
|
111
|
+
size: String(data.byteLength),
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
101
114
|
files.push({ relativePath: ref.relativePath, data, contentHash: ref.blobHash });
|
|
102
115
|
}
|
|
103
116
|
return { version: 1, files };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* issue #140:同步「内容是否变化」判定层(唯一实现)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一个纯函数:拉取(hasNewRemoteSnapshot)与推送(push 是否新建快照)必须
|
|
5
|
+
* 用同一把尺子,否则会出现「拉取说没变、推送说变了」的自相矛盾状态。
|
|
6
|
+
*
|
|
7
|
+
* G-44:本文件只吃**调用方给出的远端观测**(SyncSnapshotMeta.sections),绝不接受
|
|
8
|
+
* 「本机基线」冒充远端现状 —— 那是 recordBaseline 一参两用的事故模式。
|
|
9
|
+
*/
|
|
10
|
+
import test from 'node:test';
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
|
|
13
|
+
import { diffSnapshotContent, hashSections } from './content-diff.ts';
|
|
14
|
+
import type { ManifestSummary, SyncSnapshotMeta } from './transport.ts';
|
|
15
|
+
import type { SectionData, SectionId } from '../schema/types.ts';
|
|
16
|
+
|
|
17
|
+
const manifest: ManifestSummary = {
|
|
18
|
+
schemaVersion: 3,
|
|
19
|
+
dshVersion: '0.0.0-test',
|
|
20
|
+
platform: 'win32',
|
|
21
|
+
sectionIds: ['settings'],
|
|
22
|
+
containsSecrets: false,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function meta(id: string, sections: Partial<Record<SectionId, string>>): SyncSnapshotMeta {
|
|
26
|
+
return { id, createdAt: '2026-11-14T00:00:00.000Z', sections, manifest };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const A = 'hash-a';
|
|
30
|
+
const B = 'hash-b';
|
|
31
|
+
|
|
32
|
+
test('diffSnapshotContent:远端最新与对照侧哈希相同 → same-content(changed=false)', () => {
|
|
33
|
+
const result = diffSnapshotContent(meta('s2', { settings: A, ui: B }), { settings: A, ui: B });
|
|
34
|
+
assert.equal(result.reason, 'same-content');
|
|
35
|
+
assert.equal(result.changed, false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('diffSnapshotContent:id 变了但分区哈希集合相同 → false(只看内容,不看 id)', () => {
|
|
39
|
+
// 同一内容被重新推了一次(旧行为每推一次一个新 id)——这不是「远端有新东西」。
|
|
40
|
+
assert.equal(diffSnapshotContent(meta('s3', { settings: A }), { settings: A }).changed, false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('diffSnapshotContent:任一分区哈希变化 → content-changed(changed=true)', () => {
|
|
44
|
+
const result = diffSnapshotContent(meta('s3', { settings: B }), { settings: A });
|
|
45
|
+
assert.equal(result.reason, 'content-changed');
|
|
46
|
+
assert.equal(result.changed, true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('diffSnapshotContent:分区键集合变化(新增/缺失)→ changed=true(集合相等才算没变)', () => {
|
|
50
|
+
// 远端多一个分区
|
|
51
|
+
assert.equal(diffSnapshotContent(meta('s3', { settings: A, ui: B }), { settings: A }).changed, true);
|
|
52
|
+
// 远端少一个分区
|
|
53
|
+
assert.equal(diffSnapshotContent(meta('s3', { settings: A }), { settings: A, ui: B }).changed, true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('diffSnapshotContent:远端 sections 为空(加密快照 / 旧通道不给哈希)→ unknown', () => {
|
|
57
|
+
const encrypted = diffSnapshotContent(meta('s9', {}), { settings: A });
|
|
58
|
+
assert.equal(encrypted.reason, 'unknown');
|
|
59
|
+
// unknown 的 changed 恒 false:调用方必须按 reason 回落(推送按旧行为新建、拉取比 id),
|
|
60
|
+
// 绝不能把「读不到」当成「没变」直接跳过。
|
|
61
|
+
assert.equal(encrypted.changed, false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('diffSnapshotContent:没有远端 / 没有对照侧 → unknown(绝不猜)', () => {
|
|
65
|
+
assert.equal(diffSnapshotContent(undefined, { settings: A }).reason, 'unknown');
|
|
66
|
+
assert.equal(diffSnapshotContent(null, { settings: A }).reason, 'unknown');
|
|
67
|
+
assert.equal(diffSnapshotContent(meta('s1', { settings: A }), undefined).reason, 'unknown');
|
|
68
|
+
assert.equal(diffSnapshotContent(meta('s1', { settings: A }), {}).reason, 'unknown');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('diffSnapshotContent:local 优先于 baseline(推送场景传本次导出)', () => {
|
|
72
|
+
const remote = meta('s2', { settings: B });
|
|
73
|
+
const baseline = { settings: A };
|
|
74
|
+
const local = { settings: B }; // 本机已改成与远端一致
|
|
75
|
+
assert.equal(diffSnapshotContent(remote, baseline, local).changed, false);
|
|
76
|
+
// local 省略 → 用 baseline 比(拉取场景:比的是上次记录的远端观测)
|
|
77
|
+
assert.equal(diffSnapshotContent(remote, baseline).changed, true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('hashSections:逐分区签名(与 state.sections / 远端观测同一口径)', () => {
|
|
81
|
+
const sections: Partial<Record<SectionId, SectionData>> = {
|
|
82
|
+
settings: { value: { ui: 'dark' } } as unknown as SectionData,
|
|
83
|
+
ui: { value: { mode: 'dark' } } as unknown as SectionData,
|
|
84
|
+
};
|
|
85
|
+
const hashes = hashSections(sections);
|
|
86
|
+
assert.deepEqual(Object.keys(hashes).sort(), ['settings', 'ui']);
|
|
87
|
+
// 同内容两次 ⇒ 同哈希;改一个值 ⇒ 该分区哈希变
|
|
88
|
+
assert.deepEqual(hashSections(sections), hashes);
|
|
89
|
+
const changed = hashSections({ settings: { value: { ui: 'light' } } as unknown as SectionData });
|
|
90
|
+
assert.notEqual(changed.settings, hashes.settings);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('hashSections:空载荷 → 空对象(调用方据此判 unknown,而不是「相同」)', () => {
|
|
94
|
+
assert.deepEqual(hashSections({}), {});
|
|
95
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* issue #140:同步内容的**唯一**判定点(拉取与推送共用)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:id 只是「哪一次推送」,与「内容是否相同」是两件事。
|
|
5
|
+
* - 拉取侧只比 id ⇒ 远端每次新 id(哪怕分区哈希逐字相同)都会被判成「有新生」,白跑
|
|
6
|
+
* download + 三方合并;合并后内容没变,下一轮又来一次。
|
|
7
|
+
* - 推送侧每次生成新 id ⇒ 内容没变也 upload、也建目录、也推进远端保留链。
|
|
8
|
+
*
|
|
9
|
+
* 判据(三条,缺一不可):
|
|
10
|
+
* 1. 只比**分区哈希集合**,不比 manifest(createdAt/deviceId/dshVersion 天然不同);
|
|
11
|
+
* 2. 键集也必须相等:远端有而对照侧没有的分区算「变了」(否则「多推了一个分区」会被漏判);
|
|
12
|
+
* 3. 任一观测缺失 ⇒ `unknown`,由调用方**回落**到 id 比较 —— 绝不把「读不到」猜成「没变」
|
|
13
|
+
* (加密快照的 sections 恒为空对象,就是这条的主要来源)。
|
|
14
|
+
*
|
|
15
|
+
* G-44(docs/known-issues/known-gaps.md):对照侧必须是「上次记录下来的**远端**观测」
|
|
16
|
+
* (sync-state.lastRemoteSections),或本次调用自己刚导出的本地载荷。
|
|
17
|
+
* 绝不允许拿 sync-state.sections(本机文件 hash,可能含本机未推送的改动)当远端观测 ——
|
|
18
|
+
* 一参两用会让「本机改过、远端没改」被判成「远端变过」,拉取侧每轮空转。
|
|
19
|
+
*/
|
|
20
|
+
import type { SectionData, SectionId } from '../schema/types.ts';
|
|
21
|
+
import type { SyncSnapshotMeta } from './transport.ts';
|
|
22
|
+
import { hashSection } from './sync-state.ts';
|
|
23
|
+
import type { SectionHashes } from './sync-state.ts';
|
|
24
|
+
|
|
25
|
+
/** 判定结论的三种取值(`unknown` 不是失败,是「没有可用观测」) */
|
|
26
|
+
export type ContentDiffReason = 'same-content' | 'content-changed' | 'unknown';
|
|
27
|
+
|
|
28
|
+
export interface ContentDiffResult {
|
|
29
|
+
/** `unknown` 恒为 false —— 调用方必须自己决定回落策略,绝不能把它当「变了」或「没变」 */
|
|
30
|
+
changed: boolean;
|
|
31
|
+
reason: ContentDiffReason;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 分区导出载荷 → 分区哈希(推送上行 / 本地观测共用;与 sync-state 记的基线同口径) */
|
|
35
|
+
export function hashSections(sections: Partial<Record<SectionId, SectionData>>): SectionHashes {
|
|
36
|
+
const out: SectionHashes = {};
|
|
37
|
+
for (const [sid, data] of Object.entries(sections)) {
|
|
38
|
+
if (data === undefined) continue;
|
|
39
|
+
out[sid as SectionId] = hashSection(data);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 是否「有观测」(undefined / 空对象都算没有:空集合无法证伪任何内容) */
|
|
45
|
+
function hasObservation(hashes: SectionHashes | undefined | null): hashes is SectionHashes {
|
|
46
|
+
return hashes !== undefined && hashes !== null && Object.keys(hashes).length > 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 远端快照内容 vs 对照观测(`local` 优先,缺省用 `baseline`)。
|
|
51
|
+
*
|
|
52
|
+
* @param remote 远端快照元数据(transport.list() 的元素;`undefined` = 远端没有快照/列表读不到)
|
|
53
|
+
* @param baseline 上次记录的**远端**分区哈希(sync-state.lastRemoteSections)
|
|
54
|
+
* @param local 本次刚导出的本地分区哈希(推送路径用;拉取路径不传)
|
|
55
|
+
*/
|
|
56
|
+
export function diffSnapshotContent(
|
|
57
|
+
remote: SyncSnapshotMeta | undefined | null,
|
|
58
|
+
baseline: SectionHashes | undefined | null,
|
|
59
|
+
local?: SectionHashes | null,
|
|
60
|
+
): ContentDiffResult {
|
|
61
|
+
const reference = local ?? baseline;
|
|
62
|
+
if (remote === undefined || remote === null) return { changed: false, reason: 'unknown' };
|
|
63
|
+
const remoteHashes = remote.sections;
|
|
64
|
+
// 加密快照的 sections 恒为空对象(transport.ts:53-55)→ 无从比较,回落 id。
|
|
65
|
+
if (!hasObservation(remoteHashes)) return { changed: false, reason: 'unknown' };
|
|
66
|
+
if (!hasObservation(reference)) return { changed: false, reason: 'unknown' };
|
|
67
|
+
|
|
68
|
+
// 键集对称:任一侧缺键都算内容变了(新增/收窄分区的推送必须产生新快照)。
|
|
69
|
+
for (const sid of Object.keys(remoteHashes) as SectionId[]) {
|
|
70
|
+
const recorded = reference[sid];
|
|
71
|
+
if (recorded === undefined || recorded !== remoteHashes[sid]) {
|
|
72
|
+
return { changed: true, reason: 'content-changed' };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const sid of Object.keys(reference) as SectionId[]) {
|
|
76
|
+
if (remoteHashes[sid] === undefined) return { changed: true, reason: 'content-changed' };
|
|
77
|
+
}
|
|
78
|
+
return { changed: false, reason: 'same-content' };
|
|
79
|
+
}
|
|
@@ -718,6 +718,153 @@ test('集成:同内容重复 upload → 第二次不产生新 commit(git 天
|
|
|
718
718
|
assert.equal(listed.length, 1, '远端仍只有 1 条快照(同 id 覆盖语义)');
|
|
719
719
|
});
|
|
720
720
|
|
|
721
|
+
/** 递归读目录树(相对路径 → 文本内容):用于断言 latest/ 与快照目录逐文件一致 */
|
|
722
|
+
async function readTree(root: string): Promise<Map<string, string>> {
|
|
723
|
+
const out = new Map<string, string>();
|
|
724
|
+
const walk = async (dir: string, prefix: string): Promise<void> => {
|
|
725
|
+
for (const name of (await fs.readdir(dir)).sort()) {
|
|
726
|
+
const full = path.join(dir, name);
|
|
727
|
+
const rel = prefix === '' ? name : prefix + '/' + name;
|
|
728
|
+
const stat = await fs.stat(full);
|
|
729
|
+
if (stat.isDirectory()) await walk(full, rel);
|
|
730
|
+
else out.set(rel, await fs.readFile(full, 'utf8'));
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
await walk(root, '');
|
|
734
|
+
return out;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
test('issue #141:明文 upload 在同一次 commit 内派生 latest/,与 snapshots/<id>/ 逐文件一致且 list 不计入', async (t) => {
|
|
738
|
+
const bare = await makeBareRepo(t);
|
|
739
|
+
const workDir = await makeTempDir(t);
|
|
740
|
+
const transport = new GitTransport({ repoUrl: bare, workDir, credentials: { getToken: async () => TEST_TOKEN } });
|
|
741
|
+
await transport.upload(sampleSnapshot());
|
|
742
|
+
|
|
743
|
+
const snapTree = await readTree(path.join(workDir, 'snapshots', 'snap-001'));
|
|
744
|
+
const latestTree = await readTree(path.join(workDir, 'latest'));
|
|
745
|
+
assert.deepEqual([...latestTree.keys()].sort(), [...snapTree.keys()].sort(), 'latest/ 与快照目录的文件清单必须一致');
|
|
746
|
+
for (const [rel, content] of snapTree) {
|
|
747
|
+
assert.equal(latestTree.get(rel), content, 'latest/' + rel + ' 与快照内容不一致');
|
|
748
|
+
}
|
|
749
|
+
// manifest 保留真实快照 id(反向识别用),不是 'latest'
|
|
750
|
+
const manifest = JSON.parse(await fs.readFile(path.join(workDir, 'latest', 'manifest.json'), 'utf8')) as { id: string };
|
|
751
|
+
assert.equal(manifest.id, 'snap-001');
|
|
752
|
+
|
|
753
|
+
// 只写不读:list 仍只有 1 条(顶层多一个目录天然被忽略)
|
|
754
|
+
assert.deepEqual((await transport.list()).map((m) => m.id), ['snap-001']);
|
|
755
|
+
|
|
756
|
+
// 同一次 push:latest/ 与 snapshots/ 必须落在同一个提交里
|
|
757
|
+
const log = await runRealGit(['log', '--format=%s', '--all'], bare);
|
|
758
|
+
assert.equal(log.stdout.trim().split('\n').filter(Boolean).length, 1, 'latest/ 绝不允许单独占一个 commit');
|
|
759
|
+
const tree = await runRealGit(['ls-tree', '-r', '--name-only', 'HEAD'], bare);
|
|
760
|
+
assert.ok(tree.stdout.includes('latest/manifest.json'), '远端缺 latest/manifest.json: ' + tree.stdout);
|
|
761
|
+
assert.ok(tree.stdout.includes('snapshots/snap-001/manifest.json'));
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
test('issue #141:latest/ 建成后紧接着再 push 同一内容 → 视图不重建、不产生新 commit', async (t) => {
|
|
765
|
+
const bare = await makeBareRepo(t);
|
|
766
|
+
const workDir = await makeTempDir(t);
|
|
767
|
+
const transport = new GitTransport({ repoUrl: bare, workDir, credentials: { getToken: async () => TEST_TOKEN } });
|
|
768
|
+
await transport.upload(sampleSnapshot());
|
|
769
|
+
const before = await readTree(path.join(workDir, 'latest'));
|
|
770
|
+
|
|
771
|
+
await transport.upload(sampleSnapshot());
|
|
772
|
+
const log = await runRealGit(['log', '--format=%s', '--all'], bare);
|
|
773
|
+
assert.equal(log.stdout.trim().split('\n').filter(Boolean).length, 1, '内容无变化 → 不得产生新 commit');
|
|
774
|
+
assert.deepEqual(await readTree(path.join(workDir, 'latest')), before, 'latest/ 应保持指向既有快照');
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
test('issue #141:加密快照不写 latest/(没有明文镜像,也不造密文副本)', async (t) => {
|
|
778
|
+
const bare = await makeBareRepo(t);
|
|
779
|
+
const workDir = await makeTempDir(t);
|
|
780
|
+
const transport = new GitTransport({ repoUrl: bare, workDir, credentials: { getToken: async () => TEST_TOKEN } });
|
|
781
|
+
await transport.upload(await encryptedSnapshot());
|
|
782
|
+
|
|
783
|
+
const hasLatest = await fs.stat(path.join(workDir, 'latest')).then(() => true).catch(() => false);
|
|
784
|
+
assert.equal(hasLatest, false, '加密快照不得生成 latest/ 明文视图');
|
|
785
|
+
const tree = await runRealGit(['ls-tree', '-r', '--name-only', 'HEAD'], bare);
|
|
786
|
+
assert.ok(!tree.stdout.includes('latest/'), '远端不得出现 latest/: ' + tree.stdout);
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
test('issue #141:latest/ 永远指向最新那份 —— 后推一份更旧的快照不回退视图', async (t) => {
|
|
790
|
+
const bare = await makeBareRepo(t);
|
|
791
|
+
const workDir = await makeTempDir(t);
|
|
792
|
+
const transport = new GitTransport({ repoUrl: bare, workDir, credentials: { getToken: async () => TEST_TOKEN } });
|
|
793
|
+
await transport.upload(sampleSnapshot({ id: 'snap-new', createdAt: '2026-08-16T14:00:00.000Z' }));
|
|
794
|
+
await transport.upload(sampleSnapshot({ id: 'snap-old', createdAt: '2026-08-16T12:00:00.000Z' }));
|
|
795
|
+
|
|
796
|
+
const manifest = JSON.parse(await fs.readFile(path.join(workDir, 'latest', 'manifest.json'), 'utf8')) as { id: string };
|
|
797
|
+
assert.equal(manifest.id, 'snap-new', 'out-of-order 上传不得把 latest/ 回退成更旧的快照');
|
|
798
|
+
// 两份都还在(保留策略不受影响),latest/ 只镜像最新那份
|
|
799
|
+
assert.deepEqual((await transport.list()).map((m) => m.id).sort(), ['snap-new', 'snap-old']);
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
test('issue #141:用户手工删掉远端 latest/ 后 list/download 不报错,下一次 push 重建视图', async (t) => {
|
|
803
|
+
const bare = await makeBareRepo(t);
|
|
804
|
+
const workDir = await makeTempDir(t);
|
|
805
|
+
const transport = new GitTransport({ repoUrl: bare, workDir, credentials: { getToken: async () => TEST_TOKEN } });
|
|
806
|
+
await transport.upload(sampleSnapshot());
|
|
807
|
+
|
|
808
|
+
// 另开一个工作副本模拟「有人在远端删了 latest/ 并推送」
|
|
809
|
+
const otherRoot = await makeTempDir(t);
|
|
810
|
+
const other = path.join(otherRoot, 'clone');
|
|
811
|
+
const cloned = await runRealGit(['clone', bare, other], otherRoot);
|
|
812
|
+
assert.equal(cloned.code, 0, 'clone 失败: ' + cloned.stderr);
|
|
813
|
+
await runRealGit(['config', 'user.name', 'other'], other);
|
|
814
|
+
await runRealGit(['config', 'user.email', 'other@local'], other);
|
|
815
|
+
const removed = await runRealGit(['rm', '-r', '-q', 'latest'], other);
|
|
816
|
+
assert.equal(removed.code, 0, 'git rm 失败: ' + removed.stderr);
|
|
817
|
+
await runRealGit(['commit', '-m', 'drop latest'], other);
|
|
818
|
+
const pushed = await runRealGit(['push', 'origin', 'HEAD'], other);
|
|
819
|
+
assert.equal(pushed.code, 0, 'push 失败: ' + pushed.stderr);
|
|
820
|
+
|
|
821
|
+
// 允许远端没有 latest/:读路径完全不受影响
|
|
822
|
+
assert.deepEqual((await transport.list()).map((m) => m.id), ['snap-001']);
|
|
823
|
+
assert.deepEqual(await transport.download('snap-001'), sampleSnapshot());
|
|
824
|
+
|
|
825
|
+
// 派生视图可重建:再推同样的内容会把 latest/ 补回来(且这确实是一次真实提交)
|
|
826
|
+
await transport.upload(sampleSnapshot());
|
|
827
|
+
const tree = await runRealGit(['ls-tree', '-r', '--name-only', 'HEAD'], bare);
|
|
828
|
+
assert.ok(tree.stdout.includes('latest/manifest.json'), 'latest/ 应可重建: ' + tree.stdout);
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
test('issue #141:存量工作副本的 sparse cone 不含 latest/ 时,首次 push 自动补齐 cone 后仍能推上去', async (t) => {
|
|
832
|
+
const bare = await makeBareRepo(t);
|
|
833
|
+
const workDir = await makeTempDir(t);
|
|
834
|
+
await runRealGit(['init'], workDir);
|
|
835
|
+
await runRealGit(['config', 'user.name', 'test'], workDir);
|
|
836
|
+
await runRealGit(['config', 'user.email', 'test@local'], workDir);
|
|
837
|
+
await runRealGit(['config', 'core.sparseCheckout', 'true'], workDir);
|
|
838
|
+
await fs.mkdir(path.join(workDir, '.git', 'info'), { recursive: true });
|
|
839
|
+
// 旧版本建的 cone:只有三个快照面
|
|
840
|
+
await fs.writeFile(
|
|
841
|
+
path.join(workDir, '.git', 'info', 'sparse-checkout'),
|
|
842
|
+
'/snapshots/\n/snapshots-encrypted/\n/blobs/\n',
|
|
843
|
+
);
|
|
844
|
+
|
|
845
|
+
const transport = new GitTransport({ repoUrl: bare, workDir, credentials: { getToken: async () => TEST_TOKEN } });
|
|
846
|
+
await transport.upload(sampleSnapshot());
|
|
847
|
+
|
|
848
|
+
const cone = await fs.readFile(path.join(workDir, '.git', 'info', 'sparse-checkout'), 'utf8');
|
|
849
|
+
assert.ok(cone.includes('/latest/'), 'cone 必须补齐 latest/,否则 git add 会拒收: ' + cone);
|
|
850
|
+
const tree = await runRealGit(['ls-tree', '-r', '--name-only', 'HEAD'], bare);
|
|
851
|
+
assert.ok(tree.stdout.includes('latest/manifest.json'), 'cone 补齐后 latest/ 应推上去: ' + tree.stdout);
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
test('issue #141:删除被 latest/ 镜像的那份快照 → 视图随同一提交移除,不留悬空视图', async (t) => {
|
|
855
|
+
const bare = await makeBareRepo(t);
|
|
856
|
+
const workDir = await makeTempDir(t);
|
|
857
|
+
const transport = new GitTransport({ repoUrl: bare, workDir, credentials: { getToken: async () => TEST_TOKEN } });
|
|
858
|
+
await transport.upload(sampleSnapshot());
|
|
859
|
+
await transport.delete('snap-001');
|
|
860
|
+
|
|
861
|
+
const hasLatest = await fs.stat(path.join(workDir, 'latest')).then(() => true).catch(() => false);
|
|
862
|
+
assert.equal(hasLatest, false, '被删快照的视图不得残留在工作副本');
|
|
863
|
+
const tree = await runRealGit(['ls-tree', '-r', '--name-only', 'HEAD'], bare);
|
|
864
|
+
assert.ok(!tree.stdout.includes('latest/'), '远端不得留下指向已删快照的 latest/: ' + tree.stdout);
|
|
865
|
+
assert.deepEqual(await transport.list(), []);
|
|
866
|
+
});
|
|
867
|
+
|
|
721
868
|
test('集成:token 不泄漏到快照文件内容与 commit message(真实 git 全链路)', async (t) => {
|
|
722
869
|
const bare = await makeBareRepo(t);
|
|
723
870
|
const workDir = await makeTempDir(t);
|
|
@@ -1118,7 +1265,7 @@ test('issue #122:网络子命令一律带低速上限,本地子命令不带'
|
|
|
1118
1265
|
for (const c of local) assert.ok(!c.args.join(' ').includes('lowSpeedLimit'), '本地命令不该带 http 配置: ' + c.args.join(' '));
|
|
1119
1266
|
});
|
|
1120
1267
|
|
|
1121
|
-
test('issue #122:首次 clone 走 partial clone + sparse-checkout,只 materialize
|
|
1268
|
+
test('issue #122:首次 clone 走 partial clone + sparse-checkout,只 materialize 四个同步目录(含 latest 派生视图)', async (t) => {
|
|
1122
1269
|
const dir = await makeTempDir(t); // 空目录 → 走 clone
|
|
1123
1270
|
const calls: CallRecord[] = [];
|
|
1124
1271
|
const transport = new GitTransport(makeOptions({ workDir: dir, exec: mockExec(calls) }));
|
|
@@ -1132,7 +1279,7 @@ test('issue #122:首次 clone 走 partial clone + sparse-checkout,只 materi
|
|
|
1132
1279
|
assert.ok(sparse !== undefined, '必须设置 sparse-checkout');
|
|
1133
1280
|
assert.equal(
|
|
1134
1281
|
stripProtocolGuards(sparse.args.join(' ')),
|
|
1135
|
-
'sparse-checkout set --cone snapshots snapshots-encrypted blobs',
|
|
1282
|
+
'sparse-checkout set --cone snapshots snapshots-encrypted blobs latest',
|
|
1136
1283
|
'sparse 面必须与同步目录同源: ' + sparse.args.join(' '),
|
|
1137
1284
|
);
|
|
1138
1285
|
assert.equal(calls.filter((c) => c.args.includes('checkout')).length, 1, 'sparse 之后必须 checkout 一次');
|
|
@@ -1956,10 +2103,10 @@ test('issue #131 集成:子目录前缀 —— 上传/列表/下载/删除都
|
|
|
1956
2103
|
assert.equal(root.code, 0, 'ls-tree 失败: ' + root.stderr);
|
|
1957
2104
|
assert.deepEqual(root.stdout.split('\n').filter(Boolean), [subdir], '仓库根必须只有子目录前缀');
|
|
1958
2105
|
|
|
1959
|
-
// 前缀下的同步目录(无外置 blob
|
|
2106
|
+
// 前缀下的同步目录(无外置 blob 时建 snapshots + 派生视图 latest;issue #141)
|
|
1960
2107
|
const inner = await runRealGit(['-c', 'core.quotePath=false', 'ls-tree', '--name-only', 'HEAD:' + subdir], bare);
|
|
1961
2108
|
assert.equal(inner.code, 0, 'ls-tree 子目录失败: ' + inner.stderr);
|
|
1962
|
-
assert.deepEqual(inner.stdout.split('\n').filter(Boolean), ['snapshots'], '子目录下必须是同步目录');
|
|
2109
|
+
assert.deepEqual(inner.stdout.split('\n').filter(Boolean), ['latest', 'snapshots'], '子目录下必须是同步目录');
|
|
1963
2110
|
|
|
1964
2111
|
// 工作副本同样落在前缀下
|
|
1965
2112
|
assert.ok(await fs.stat(path.join(workDir, subdir, 'snapshots', 'snap-001', 'manifest.json')));
|