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
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* #132
|
|
2
|
+
* #132 / #145:跟随远端删除插件的判据 + plugins 分区的按键三方合并。
|
|
3
3
|
*
|
|
4
4
|
* 接缝(seam):
|
|
5
5
|
* 1. planPluginRemovals —— 「哪些已装插件该被删」的唯一判据(开关、祖先、远端、本机三方);
|
|
6
|
-
* 2. mergePluginsSection —— plugins
|
|
6
|
+
* 2. mergePluginsSection —— plugins 分区的按键三方合并(否则通用 JSON 合并对数组两侧各改即冲突,
|
|
7
7
|
* 会把「远端删 X + 本机新装 Y」误报成整分区冲突,让删除永远进不了自动应用)。
|
|
8
8
|
*
|
|
9
|
+
* issue #145 起两者解耦:合并**恒参与**(开关不再决定钩子是否介入),开关只管「远端删了要不要真删」。
|
|
9
10
|
* 两个函数都是纯函数、零 I/O:引擎与 UI 都只读它们的返回值。
|
|
10
11
|
*/
|
|
11
12
|
import { test } from 'node:test';
|
|
12
13
|
import assert from 'node:assert/strict';
|
|
13
14
|
|
|
14
15
|
import { mergePluginsSection, planPluginRemovals } from './plugin-removals.ts';
|
|
15
|
-
import type { PluginEntry, PluginsSection } from '../schema/types.ts';
|
|
16
|
+
import type { PatchLine, PluginEntry, PluginsSection } from '../schema/types.ts';
|
|
16
17
|
|
|
17
18
|
function entry(name: string, version: string, extra: Partial<PluginEntry> = {}): PluginEntry {
|
|
18
19
|
return { name, version, isBundle: false, inBundles: [], enabled: true, ...extra };
|
|
@@ -130,15 +131,24 @@ test('planPluginRemovals: 没有祖先(首次同步)→ 一律不删(无
|
|
|
130
131
|
assert.deepEqual(plan.kept, []);
|
|
131
132
|
});
|
|
132
133
|
|
|
133
|
-
/* ------------------------------------------------------------------
|
|
134
|
+
/* ------------------------------------------------------------------ 合并:按键三方 */
|
|
134
135
|
|
|
135
|
-
/**
|
|
136
|
+
/** 开关打开:远端删了、本机未改的条目会被真的删掉(删除判据用同一份开关)。 */
|
|
136
137
|
const ON = { deletePlugins: true };
|
|
137
138
|
|
|
138
139
|
function section(plugins: PluginEntry[], extra: Partial<PluginsSection> = {}): PluginsSection {
|
|
139
140
|
return { version: 1, plugins, patch: [], ...extra };
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
function line(file: string, lineId: string, raw: unknown, redactedPaths?: string[]): PatchLine {
|
|
144
|
+
return { file, lineId, raw, ...(redactedPaths === undefined ? {} : { redactedPaths }) };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function names(res: { merged: unknown } | undefined): string[] {
|
|
148
|
+
assert.ok(res !== undefined);
|
|
149
|
+
return ((res.merged as PluginsSection).plugins ?? []).map((p) => p.name);
|
|
150
|
+
}
|
|
151
|
+
|
|
142
152
|
test('mergePluginsSection: 远端删 X、本机新装 Y → 合并结果只留 Y,不报冲突', () => {
|
|
143
153
|
const res = mergePluginsSection(
|
|
144
154
|
section([entry('alpha', '1.2.0'), entry('y', '2.0.0')]),
|
|
@@ -146,9 +156,8 @@ test('mergePluginsSection: 远端删 X、本机新装 Y → 合并结果只留 Y
|
|
|
146
156
|
section([entry('alpha', '1.2.0')]),
|
|
147
157
|
ON,
|
|
148
158
|
);
|
|
149
|
-
assert.
|
|
150
|
-
assert.deepEqual(res
|
|
151
|
-
assert.deepEqual((res.merged as PluginsSection).plugins.map((p) => p.name), ['y']);
|
|
159
|
+
assert.deepEqual(res?.conflicts, []);
|
|
160
|
+
assert.deepEqual(names(res), ['y']);
|
|
152
161
|
});
|
|
153
162
|
|
|
154
163
|
test('mergePluginsSection: 本机升级 X、远端删 X → modify-delete 冲突(不静默删也不静默留)', () => {
|
|
@@ -158,28 +167,22 @@ test('mergePluginsSection: 本机升级 X、远端删 X → modify-delete 冲突
|
|
|
158
167
|
section([entry('alpha', '1.2.0')]),
|
|
159
168
|
ON,
|
|
160
169
|
);
|
|
161
|
-
assert.
|
|
162
|
-
assert.equal(res
|
|
163
|
-
assert.equal(res
|
|
164
|
-
assert.equal(res.conflicts[0]!.reason, 'modify-delete');
|
|
170
|
+
assert.equal(res?.conflicts.length, 1);
|
|
171
|
+
assert.equal(res?.conflicts[0]!.path, 'plugins.alpha');
|
|
172
|
+
assert.equal(res?.conflicts[0]!.reason, 'modify-delete');
|
|
165
173
|
});
|
|
166
174
|
|
|
167
175
|
test('mergePluginsSection: 两侧同版本 → 保留,两侧同删 → 消失', () => {
|
|
168
|
-
const same = mergePluginsSection(
|
|
169
|
-
|
|
170
|
-
section([entry('alpha', '1.2.0')]),
|
|
171
|
-
undefined,
|
|
172
|
-
ON,
|
|
173
|
-
);
|
|
174
|
-
assert.deepEqual((same!.merged as PluginsSection).plugins.map((p) => p.name), ['alpha']);
|
|
176
|
+
const same = mergePluginsSection(section([entry('alpha', '1.2.0')]), section([entry('alpha', '1.2.0')]), undefined, ON);
|
|
177
|
+
assert.deepEqual(names(same), ['alpha']);
|
|
175
178
|
const both = mergePluginsSection(section([]), section([]), section([entry('alpha', '1.2.0')]), ON);
|
|
176
|
-
assert.deepEqual((both
|
|
179
|
+
assert.deepEqual(names(both), []);
|
|
177
180
|
});
|
|
178
181
|
|
|
179
182
|
test('mergePluginsSection: 无祖先时本机独有/远端独有都保留(不按删除解释)', () => {
|
|
180
183
|
const res = mergePluginsSection(section([entry('mine', '1.0.0')]), section([entry('theirs', '1.0.0')]), undefined, ON);
|
|
181
|
-
assert.deepEqual(res
|
|
182
|
-
assert.deepEqual((res
|
|
184
|
+
assert.deepEqual(res?.conflicts, []);
|
|
185
|
+
assert.deepEqual(names(res).sort(), ['mine', 'theirs']);
|
|
183
186
|
});
|
|
184
187
|
|
|
185
188
|
test('mergePluginsSection: 两侧把同一插件改到不同版本 → both-modified 冲突', () => {
|
|
@@ -189,33 +192,190 @@ test('mergePluginsSection: 两侧把同一插件改到不同版本 → both-modi
|
|
|
189
192
|
section([entry('alpha', '1.2.0')]),
|
|
190
193
|
ON,
|
|
191
194
|
);
|
|
192
|
-
assert.equal(res
|
|
193
|
-
assert.equal(res
|
|
195
|
+
assert.equal(res?.conflicts.length, 1);
|
|
196
|
+
assert.equal(res?.conflicts[0]!.reason, 'both-modified');
|
|
194
197
|
});
|
|
195
198
|
|
|
196
|
-
test('mergePluginsSection:
|
|
199
|
+
test('mergePluginsSection: 开关关着 + 远端删了本机未改的插件 → 保留(合并仍参与,绝不交回通用路径)', () => {
|
|
197
200
|
const res = mergePluginsSection(
|
|
198
|
-
section([entry('alpha', '1.2.0')], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
|
|
199
|
-
section([entry('alpha', '1.2.0')], { pnpmWorkspace: 'onlyBuiltDependencies: [b]\n' }),
|
|
200
201
|
section([entry('alpha', '1.2.0')]),
|
|
202
|
+
section([]),
|
|
203
|
+
section([entry('alpha', '1.2.0')]),
|
|
204
|
+
{ deletePlugins: false },
|
|
205
|
+
);
|
|
206
|
+
assert.ok(res !== undefined, '关着开关也必须参与:否则 patch 行等与卸载无关的改动会整分区冲突');
|
|
207
|
+
assert.deepEqual(res.conflicts, []);
|
|
208
|
+
assert.deepEqual(names(res), ['alpha'], '包还在盘上,删了只会下一轮复活 —— 保留才是诚实结果');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('mergePluginsSection: 不传钩子(缺省开关关)也能按名/按行合并', () => {
|
|
212
|
+
const res = mergePluginsSection(
|
|
213
|
+
section([entry('alpha', '1.2.0')], { patch: [line('cfg.yml', 'l1', { a: 1 })] }),
|
|
214
|
+
section([], { patch: [line('cfg.yml', 'l2', { b: 2 })] }),
|
|
215
|
+
section([entry('alpha', '1.2.0')], { patch: [line('cfg.yml', 'l1', { a: 1 })] }),
|
|
216
|
+
);
|
|
217
|
+
assert.ok(res !== undefined);
|
|
218
|
+
assert.deepEqual(res.conflicts, []);
|
|
219
|
+
assert.deepEqual(names(res), ['alpha']);
|
|
220
|
+
assert.deepEqual((res.merged as PluginsSection).patch.map((p) => p.lineId), ['l1', 'l2']);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('mergePluginsSection: 自身插件远端删了也保留、两侧改不同版本时本机胜,且都不报冲突', () => {
|
|
224
|
+
const deleted = mergePluginsSection(
|
|
225
|
+
section([entry(SELF, '0.9.1')]),
|
|
226
|
+
section([]),
|
|
227
|
+
section([entry(SELF, '0.9.1')]),
|
|
228
|
+
{ ...ON, selfPluginName: SELF },
|
|
229
|
+
);
|
|
230
|
+
assert.deepEqual(deleted?.conflicts, []);
|
|
231
|
+
assert.deepEqual(names(deleted), [SELF]);
|
|
232
|
+
const changed = mergePluginsSection(
|
|
233
|
+
section([entry(SELF, '0.9.2')]),
|
|
234
|
+
section([entry(SELF, '0.9.3')]),
|
|
235
|
+
section([entry(SELF, '0.9.1')]),
|
|
236
|
+
{ ...ON, selfPluginName: SELF },
|
|
237
|
+
);
|
|
238
|
+
assert.deepEqual(changed?.conflicts, []);
|
|
239
|
+
assert.deepEqual(names(changed), [SELF]);
|
|
240
|
+
assert.equal(((changed!.merged as PluginsSection).plugins[0]!).version, '0.9.2');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test('mergePluginsSection: patch 行按 file+lineId 配对 —— 同一行两侧都改 → both-modified(路径带文件名+行号)', () => {
|
|
244
|
+
const res = mergePluginsSection(
|
|
245
|
+
section([], { patch: [line('cfg.yml', 'l1', { timeout: 10 })] }),
|
|
246
|
+
section([], { patch: [line('cfg.yml', 'l1', { timeout: 20 })] }),
|
|
247
|
+
section([], { patch: [line('cfg.yml', 'l1', { timeout: 1 })] }),
|
|
201
248
|
ON,
|
|
202
249
|
);
|
|
203
|
-
assert.equal(res,
|
|
250
|
+
assert.equal(res?.conflicts.length, 1);
|
|
251
|
+
assert.equal(res?.conflicts[0]!.reason, 'both-modified');
|
|
252
|
+
assert.equal(res?.conflicts[0]!.path, 'patch.cfg.yml#l1', '同文件多行要能分辨');
|
|
204
253
|
});
|
|
205
254
|
|
|
206
|
-
test('mergePluginsSection:
|
|
207
|
-
|
|
255
|
+
test('mergePluginsSection: 同 lineId 不同文件不撞键(两行都保留)', () => {
|
|
256
|
+
const res = mergePluginsSection(
|
|
257
|
+
section([], { patch: [line('a.yml', 'l1', { x: 1 })] }),
|
|
258
|
+
section([], { patch: [line('b.yml', 'l1', { y: 1 })] }),
|
|
259
|
+
undefined,
|
|
260
|
+
ON,
|
|
261
|
+
);
|
|
262
|
+
assert.deepEqual(res?.conflicts, []);
|
|
263
|
+
assert.deepEqual((res!.merged as PluginsSection).patch.map((p) => p.file).sort(), ['a.yml', 'b.yml']);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('mergePluginsSection: 导出侧剥空 + redactedPaths 与远端明文是同一行(门②,不报冲突)', () => {
|
|
267
|
+
// 本机(导出侧):secret 被剥成空串并记进 redactedPaths;远端/祖先:明文、无该字段。
|
|
268
|
+
const redacted = line('cfg.yml', 'l1', { token: '', keep: 1 }, ['raw.token']);
|
|
269
|
+
const plain = line('cfg.yml', 'l1', { token: 'sk-live-123', keep: 1 });
|
|
270
|
+
const res = mergePluginsSection(section([], { patch: [redacted] }), section([], { patch: [plain] }), section([], { patch: [plain] }), ON);
|
|
271
|
+
assert.deepEqual(res?.conflicts, [], '被剥空的叶子按三侧 redactedPaths 并集归一化后是同一身份');
|
|
272
|
+
// 身份相同 → 保留本机那一行(导出侧形态):redactedPaths 原样留下,写回守卫据此换回本机明文。
|
|
273
|
+
const merged = (res!.merged as PluginsSection).patch[0]!;
|
|
274
|
+
assert.deepEqual(merged.raw, { token: '', keep: 1 });
|
|
275
|
+
assert.deepEqual(merged.redactedPaths, ['raw.token']);
|
|
276
|
+
// 归一化只抹「被声明剥空」的叶子,绝不挡真实改动:远端把 keep 改了 → 采用远端那一行。
|
|
277
|
+
const changed = line('cfg.yml', 'l1', { token: 'sk-live-123', keep: 2 });
|
|
278
|
+
const res2 = mergePluginsSection(section([], { patch: [redacted] }), section([], { patch: [changed] }), section([], { patch: [plain] }), ON);
|
|
279
|
+
assert.deepEqual(res2?.conflicts, []);
|
|
280
|
+
assert.deepEqual((res2!.merged as PluginsSection).patch[0]!.raw, { token: 'sk-live-123', keep: 2 });
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test('mergePluginsSection: 不在 redactedPaths 里的字段真改了 → 仍然 both-modified', () => {
|
|
284
|
+
const redacted = line('cfg.yml', 'l1', { token: '', keep: 2 }, ['raw.token']);
|
|
285
|
+
const remote = line('cfg.yml', 'l1', { token: 'sk-other', keep: 3 });
|
|
286
|
+
const res = mergePluginsSection(
|
|
287
|
+
section([], { patch: [redacted] }),
|
|
288
|
+
section([], { patch: [remote] }),
|
|
289
|
+
section([], { patch: [line('cfg.yml', 'l1', { token: 'sk-base', keep: 1 })] }),
|
|
290
|
+
ON,
|
|
291
|
+
);
|
|
292
|
+
assert.equal(res?.conflicts.length, 1);
|
|
293
|
+
assert.equal(res?.conflicts[0]!.reason, 'both-modified');
|
|
208
294
|
});
|
|
209
295
|
|
|
210
|
-
test('mergePluginsSection:
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
section([entry('alpha', '1.2.0')]),
|
|
216
|
-
{ deletePlugins: false },
|
|
217
|
-
),
|
|
296
|
+
test('mergePluginsSection: 合并输出保留本机行的 redactedPaths(写回守卫要靠它)', () => {
|
|
297
|
+
const redacted = line('cfg.yml', 'l1', { token: '', keep: 1 }, ['raw.token']);
|
|
298
|
+
const res = mergePluginsSection(
|
|
299
|
+
section([], { patch: [redacted] }),
|
|
300
|
+
section([], { patch: [line('cfg.yml', 'l1', { token: '', keep: 1 }, ['raw.token']), line('cfg.yml', 'l2', { b: 2 })] }),
|
|
218
301
|
undefined,
|
|
219
|
-
|
|
302
|
+
ON,
|
|
303
|
+
);
|
|
304
|
+
assert.deepEqual(res?.conflicts, []);
|
|
305
|
+
const kept = (res!.merged as PluginsSection).patch.find((p) => p.lineId === 'l1')!;
|
|
306
|
+
assert.deepEqual(kept.redactedPaths, ['raw.token']);
|
|
307
|
+
assert.equal((res!.merged as PluginsSection).patch.length, 2);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('mergePluginsSection: pnpmWorkspace 单侧改动取该侧,两侧都改 → overlap 冲突(不猜用哪一份)', () => {
|
|
311
|
+
const oneSide = mergePluginsSection(
|
|
312
|
+
section([], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
|
|
313
|
+
section([], { pnpmWorkspace: 'onlyBuiltDependencies: [b]\n' }),
|
|
314
|
+
section([], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
|
|
315
|
+
ON,
|
|
316
|
+
);
|
|
317
|
+
assert.deepEqual(oneSide?.conflicts, []);
|
|
318
|
+
assert.equal((oneSide!.merged as PluginsSection).pnpmWorkspace, 'onlyBuiltDependencies: [b]\n');
|
|
319
|
+
const both = mergePluginsSection(
|
|
320
|
+
section([], { pnpmWorkspace: 'onlyBuiltDependencies: [b]\n' }),
|
|
321
|
+
section([], { pnpmWorkspace: 'onlyBuiltDependencies: [c]\n' }),
|
|
322
|
+
section([], { pnpmWorkspace: 'onlyBuiltDependencies: [a]\n' }),
|
|
323
|
+
ON,
|
|
324
|
+
);
|
|
325
|
+
assert.equal(both?.conflicts.length, 1);
|
|
326
|
+
assert.equal(both?.conflicts[0]!.path, 'pnpmWorkspace');
|
|
327
|
+
assert.equal(both?.conflicts[0]!.reason, 'overlap');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test('mergePluginsSection: 三侧 pnpmWorkspace 都是 null → 原样保留(不抹成缺键,复审 P0-1)', () => {
|
|
331
|
+
const res = mergePluginsSection(section([], { pnpmWorkspace: null }), section([], { pnpmWorkspace: null }), section([], { pnpmWorkspace: null }), ON);
|
|
332
|
+
assert.deepEqual(res?.conflicts, []);
|
|
333
|
+
assert.ok('pnpmWorkspace' in (res!.merged as PluginsSection), 'null 是合法值,删掉会让合并结果与两侧都不等 ⇒ 每轮假合并');
|
|
334
|
+
assert.equal((res!.merged as PluginsSection).pnpmWorkspace, null);
|
|
335
|
+
assert.equal(res?.mergePoints, 0);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('mergePluginsSection: 本机关掉插件、远端升版本 → 版本听远端,启停留本机(复审 P0-2)', () => {
|
|
339
|
+
const res = mergePluginsSection(
|
|
340
|
+
section([entry('alpha', '1.2.0', { enabled: false })]),
|
|
341
|
+
section([entry('alpha', '1.3.0')]),
|
|
342
|
+
section([entry('alpha', '1.2.0')]),
|
|
343
|
+
ON,
|
|
220
344
|
);
|
|
345
|
+
assert.deepEqual(res?.conflicts, []);
|
|
346
|
+
const merged = (res!.merged as PluginsSection).plugins[0]!;
|
|
347
|
+
assert.equal(merged.version, '1.3.0');
|
|
348
|
+
assert.equal(merged.enabled, false, '本机停用是用户意图,不能被远端版本覆盖');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test('mergePluginsSection: 开关打开时远端删 patch 行也不跟删(开关只管插件,复审 P1-1)', () => {
|
|
352
|
+
const kept = line('cfg.yml', 'l1', { a: 1 });
|
|
353
|
+
const res = mergePluginsSection(section([], { patch: [kept] }), section([]), section([], { patch: [kept] }), ON);
|
|
354
|
+
assert.deepEqual(res?.conflicts, []);
|
|
355
|
+
assert.deepEqual((res!.merged as PluginsSection).patch.map((p) => p.lineId), ['l1']);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test('mergePluginsSection: patch 行重复 file+lineId → 整轮交回通用路径(不静默吞条目,复审 P1-2)', () => {
|
|
359
|
+
const dup = [line('cfg.yml', 'l1', { a: 1 }), line('cfg.yml', 'l1', { a: 2 })];
|
|
360
|
+
assert.equal(mergePluginsSection(section([], { patch: dup }), section([], { patch: dup }), undefined, ON), undefined);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('mergePluginsSection: patch 冲突路径带 lineId(同文件两行能分辨,复审 P2)', () => {
|
|
364
|
+
const res = mergePluginsSection(
|
|
365
|
+
section([], { patch: [line('cfg.yml', 'l7', { a: 2 })] }),
|
|
366
|
+
section([], { patch: [line('cfg.yml', 'l7', { a: 3 })] }),
|
|
367
|
+
section([], { patch: [line('cfg.yml', 'l7', { a: 1 })] }),
|
|
368
|
+
ON,
|
|
369
|
+
);
|
|
370
|
+
assert.equal(res?.conflicts[0]!.path, 'patch.cfg.yml#l7');
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
test('mergePluginsSection: 远端独有的未知字段被采纳(不被本机形状吞掉,复审 P2)', () => {
|
|
374
|
+
const remote = { ...section([]), pluginsMeta: { scanned: true } } as unknown as PluginsSection;
|
|
375
|
+
const res = mergePluginsSection(section([]), remote, undefined, ON);
|
|
376
|
+
assert.deepEqual((res!.merged as unknown as { pluginsMeta: unknown }).pluginsMeta, { scanned: true });
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test('mergePluginsSection: 形状不认识 → undefined(畸形数据交通用路径的形状闸门)', () => {
|
|
380
|
+
assert.equal(mergePluginsSection({ version: 2 } as unknown as PluginsSection, section([]), undefined, ON), undefined);
|
|
221
381
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* #132
|
|
2
|
+
* #132 / #145:同步「跟随远端删除插件」的**唯一判据**,以及 plugins 分区的按键三方合并。
|
|
3
3
|
*
|
|
4
4
|
* 为什么必须单独一个模块:
|
|
5
5
|
* 1. 删除判定是纯逻辑(开关 × 祖先 × 远端 × 本机),散进引擎里既测不了也说不清;
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
* 且不逐字相等 → 冲突」,而本分区的日常形态恰恰是「A 机卸载了 X、B 机新装了 Y」,通用路径
|
|
8
8
|
* 会把它报成整分区冲突,于是删除永远进不了自动应用(issue #132 的行为表 A→B 走不通)。
|
|
9
9
|
*
|
|
10
|
+
* issue #145 把两件事彻底解耦(本条是 #132 的语义修正):
|
|
11
|
+
* - **合并恒参与**:开关不再决定钩子是否介入。以前关着开关 = 整个分区交回通用 JSON 合并,
|
|
12
|
+
* 于是与卸载无关的改动(patch 行新增一行)也会因为「数组两侧都改」而整分区冲突;
|
|
13
|
+
* - **开关只管删除**:`deletePlugins` 只决定「远端删了、本机未改的条目要不要真的删」,关着就
|
|
14
|
+
* 保留本机条目(包还在盘上,删了也只会下一轮复活)。
|
|
15
|
+
* - 外壳条目(patch 行 / 本地 tarball / patch 文件)同一口径:跟随三方合并,删除也受同一个开关。
|
|
16
|
+
*
|
|
10
17
|
* 删除判据(缺一不可,全部满足才删):
|
|
11
18
|
* - 开关打开(`SyncSelection.deletePlugins`,缺省关);
|
|
12
19
|
* - **祖先**里有它(A 机那轮同步见过的状态)——没有祖先就没有「谁删了它」的证据;
|
|
@@ -19,10 +26,14 @@
|
|
|
19
26
|
*
|
|
20
27
|
* 纯函数、零 I/O:引擎调用它拿计划,UI 调用它拿「将删除」清单。
|
|
21
28
|
*/
|
|
22
|
-
import type { PluginEntry, PluginsSection, SectionData } from '../schema/types.ts';
|
|
29
|
+
import type { LocalPluginTarball, PatchLine, PluginEntry, PluginsSection, PnpmPatchFile, SectionData } from '../schema/types.ts';
|
|
23
30
|
import type { MergeConflict } from './merge.ts';
|
|
24
|
-
import type { GranularMergeOutcome } from './workspace-merge.ts';
|
|
31
|
+
import type { GranularMergeHooks, GranularMergeOutcome } from './workspace-merge.ts';
|
|
25
32
|
import { isBundlesOnlyEntry } from '../core/plugin-cli.ts';
|
|
33
|
+
import { mergeKeyedList } from './merge-keyed.ts';
|
|
34
|
+
import { patchIdentityContext, patchLineIdentity } from './patch-line-identity.ts';
|
|
35
|
+
import type { PatchIdentityContext } from './patch-line-identity.ts';
|
|
36
|
+
import { mergeJsonValues } from './text-merge.ts';
|
|
26
37
|
|
|
27
38
|
/** 一条「该卸载」的结论(version = 祖先/本机一致的版本,用于报告与回滚重装目标)。 */
|
|
28
39
|
export interface PluginRemoval {
|
|
@@ -125,84 +136,159 @@ function entryKey(e: PluginEntry): string {
|
|
|
125
136
|
return [e.version ?? '', e.spec ?? '', e.bundlesOnly === true ? '1' : '0'].join('\u0000');
|
|
126
137
|
}
|
|
127
138
|
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
/** patch 行的键分隔符:file 与 lineId 各自可能含任意字符,用 NUL 才不会撞键。 */
|
|
140
|
+
const PATCH_KEY_SEP = '\u0000';
|
|
141
|
+
|
|
142
|
+
/** patch 行的身份键 = file + lineId(同一文件里 lineId 才是行身份;issue #145)。 */
|
|
143
|
+
function patchLineKey(line: PatchLine): string {
|
|
144
|
+
return [line.file ?? '', line.lineId ?? ''].join(PATCH_KEY_SEP);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 本地 tarball 的身份(同包名 = 同一条目;内容变了才算改过)。 */
|
|
148
|
+
function tarballIdentity(t: LocalPluginTarball): string {
|
|
149
|
+
return JSON.stringify({ version: t.version ?? '', relativePath: t.relativePath ?? '', base64: t.base64 ?? '' });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** patch 文件的身份(同相对路径 = 同一条目)。 */
|
|
153
|
+
function patchFileIdentity(f: PnpmPatchFile): string {
|
|
154
|
+
return JSON.stringify({ relativePath: f.relativePath ?? '', base64: f.base64 ?? '' });
|
|
137
155
|
}
|
|
138
156
|
|
|
139
157
|
/**
|
|
140
|
-
* plugins
|
|
158
|
+
* plugins 分区的按键三方合并(`merge.ts` 的 `GRANULAR_MERGES.plugins`)。
|
|
141
159
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* - 只有本机:有祖先且与祖先相同 → 跟随远端删除(真删除);无祖先 → 本机独有,保留;有祖先且不同 →
|
|
145
|
-
* modify-delete 冲突(用户在 A 机卸载、B 机却升级过它,不能替用户选);
|
|
146
|
-
* - 只有远端:有祖先且与祖先相同 → 本机删除,跟随(不复活);无祖先 → 远端独有,采纳;有祖先且不同 →
|
|
147
|
-
* delete-modify 冲突;
|
|
148
|
-
* - 两侧都没有:消失。
|
|
160
|
+
* 逐条规则见 `merge-keyed.ts`;本函数只负责「四条有序集合各用什么键与身份」以及
|
|
161
|
+
* `pnpmWorkspace` 原文的三方(两侧都改且不同 → overlap 交人工,与通用 JSON 合并同口径)。
|
|
149
162
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
163
|
+
* 形状不认识(`version !== 1` 或缺 plugins 数组)时返回 `undefined`:畸形数据交回通用路径的
|
|
164
|
+
* 形状闸门,这里不另造第二套拒绝逻辑。
|
|
152
165
|
*/
|
|
153
166
|
export function mergePluginsSection(
|
|
154
167
|
local: SectionData,
|
|
155
168
|
remote: SectionData,
|
|
156
169
|
ancestor: SectionData | undefined,
|
|
157
|
-
hooks:
|
|
170
|
+
hooks: GranularMergeHooks = {},
|
|
158
171
|
): GranularMergeOutcome | undefined {
|
|
159
|
-
// 开关关着 → 钩子不参与(交回通用合并 = 与 #132 之前逐字一致)。若照常「跟随远端删除」,
|
|
160
|
-
// 合并结果会丢掉本机条目:插件包还在盘上,下一轮导出会把它当「本机独有」推回远端 = 复活。
|
|
161
|
-
if (hooks.deletePlugins !== true) return undefined;
|
|
162
172
|
const l = asPlugins(local);
|
|
163
173
|
const r = asPlugins(remote);
|
|
164
174
|
if (l === undefined || r === undefined) return undefined;
|
|
165
175
|
const a = ancestor === undefined ? undefined : asPlugins(ancestor);
|
|
166
176
|
if (ancestor !== undefined && a === undefined) return undefined;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
177
|
+
|
|
178
|
+
// 开关只决定「远端删了要不要真删」,不再决定钩子是否介入(issue #145 解耦)。
|
|
179
|
+
const followDelete = hooks.deletePlugins === true;
|
|
180
|
+
const selfName = hooks.selfPluginName ?? '';
|
|
181
|
+
|
|
182
|
+
const plugins = mergeKeyedList<PluginEntry>({
|
|
183
|
+
local: l.plugins,
|
|
184
|
+
remote: r.plugins,
|
|
185
|
+
ancestor: a?.plugins,
|
|
186
|
+
spec: {
|
|
187
|
+
keyOf: (p) => (typeof p.name === 'string' ? p.name : ''),
|
|
188
|
+
identityOf: (p) => entryKey(p),
|
|
189
|
+
pathOf: (name) => `plugins.${name}`,
|
|
190
|
+
followDelete,
|
|
191
|
+
// 自身条目永不删、永不报冲突:删了等于把正在跑的宿主插件卸掉。
|
|
192
|
+
keepLocal: (p) => selfName !== '' && p.name === selfName,
|
|
193
|
+
// 版本/来源听远端(本机没改过它才走这条分支),启停是本机 UI 态 —— 恒留本机,
|
|
194
|
+
// 否则远端升一次版本就把用户在本机关掉的插件改回启用(复审 P0-2)。
|
|
195
|
+
compose: (local, remote) => ({ ...remote, enabled: local.enabled }),
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
const patch = mergeKeyedList<PatchLine>({
|
|
199
|
+
local: l.patch ?? [],
|
|
200
|
+
remote: r.patch ?? [],
|
|
201
|
+
ancestor: a?.patch,
|
|
202
|
+
spec: {
|
|
203
|
+
keyOf: patchLineKey,
|
|
204
|
+
// 身份按三侧 redactedPaths 并集归一化:本机被剥空、远端明文的同一行算「没改过」(门②)。
|
|
205
|
+
// 并集路径每键只解析一次(上下文),三侧各自比较时复用 —— 行多时不再逐次重解析。
|
|
206
|
+
identityContextOf: (peers) => patchIdentityContext(peers),
|
|
207
|
+
identityOf: (line, peers, context) => patchLineIdentity(line, peers, context as PatchIdentityContext | undefined),
|
|
208
|
+
// 冲突路径带 lineId:同一文件里两行各自冲突时必须能分辨(复审 P2)。
|
|
209
|
+
pathOf: (key) => {
|
|
210
|
+
const [file = '', lineId = ''] = key.split(PATCH_KEY_SEP);
|
|
211
|
+
return `patch.${file}#${lineId}`;
|
|
212
|
+
},
|
|
213
|
+
// 外壳列表**不跟随删除**:deletePlugins 的语义是「远端删了插件」,不是「远端删了 MCP 配置」
|
|
214
|
+
// —— 跟着删会把本机还在用的 patch 行 / tarball 一起丢掉(复审 P1-1)。
|
|
215
|
+
followDelete: false,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
const tarballs = mergeKeyedList<LocalPluginTarball>({
|
|
219
|
+
local: l.localTarballs ?? [],
|
|
220
|
+
remote: r.localTarballs ?? [],
|
|
221
|
+
ancestor: a?.localTarballs,
|
|
222
|
+
spec: {
|
|
223
|
+
keyOf: (t) => (typeof t.packageName === 'string' ? t.packageName : ''),
|
|
224
|
+
identityOf: (t) => tarballIdentity(t),
|
|
225
|
+
pathOf: (key) => `localTarballs.${key}`,
|
|
226
|
+
followDelete: false, // 同上:开关只管插件清单(复审 P1-1)
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
const files = mergeKeyedList<PnpmPatchFile>({
|
|
230
|
+
local: l.patchFiles ?? [],
|
|
231
|
+
remote: r.patchFiles ?? [],
|
|
232
|
+
ancestor: a?.patchFiles,
|
|
233
|
+
spec: {
|
|
234
|
+
keyOf: (f) => (typeof f.relativePath === 'string' ? f.relativePath : ''),
|
|
235
|
+
identityOf: (f) => patchFileIdentity(f),
|
|
236
|
+
pathOf: (key) => `patchFiles.${key}`,
|
|
237
|
+
followDelete: false, // 同上:开关只管插件清单(复审 P1-1)
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// 形状不支持按键合并(同键重复 / 非对象条目 / 无身份键):交回通用路径,
|
|
242
|
+
// 绝不在这里「留一条丢一条」(复审 P1-2)。
|
|
243
|
+
if (plugins.malformed || patch.malformed || tarballs.malformed || files.malformed) return undefined;
|
|
244
|
+
|
|
245
|
+
const conflicts: MergeConflict[] = [
|
|
246
|
+
...plugins.conflicts,
|
|
247
|
+
...patch.conflicts,
|
|
248
|
+
...tarballs.conflicts,
|
|
249
|
+
...files.conflicts,
|
|
250
|
+
];
|
|
251
|
+
let mergePoints = plugins.mergePoints + patch.mergePoints + tarballs.mergePoints + files.mergePoints;
|
|
252
|
+
|
|
253
|
+
// pnpm-workspace 原文:标量/对象三方。两侧都改且不同 → overlap(不猜用哪一份)。
|
|
254
|
+
// null 与「没有这个键」在语义上是同一件事(adapter 没有 patch 组时导出 null),
|
|
255
|
+
// 但三方合并之后必须按**原始形态**写回:本机原本带这个键就继续写 null,不能抹成缺键(复审 P0-1)。
|
|
256
|
+
const wsCarried = 'pnpmWorkspace' in l || 'pnpmWorkspace' in r;
|
|
257
|
+
const wsLocal = l.pnpmWorkspace ?? null;
|
|
258
|
+
const wsRemote = r.pnpmWorkspace ?? null;
|
|
259
|
+
const wsAncestor = a?.pnpmWorkspace ?? null;
|
|
260
|
+
const ws = mergeJsonValues(wsAncestor, wsLocal, wsRemote, 'pnpmWorkspace');
|
|
261
|
+
const wsMerged = ws.ok ? (ws.merged as string | null | undefined) : undefined;
|
|
262
|
+
if (!ws.ok) {
|
|
263
|
+
for (const _ of ws.conflicts) {
|
|
264
|
+
conflicts.push({
|
|
265
|
+
path: 'pnpmWorkspace',
|
|
266
|
+
kind: 'key',
|
|
267
|
+
reason: 'overlap',
|
|
268
|
+
autoMergeAttempted: true,
|
|
269
|
+
local: wsLocal ?? null,
|
|
270
|
+
remote: wsRemote ?? null,
|
|
271
|
+
ancestor: wsAncestor ?? null,
|
|
272
|
+
});
|
|
191
273
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (entryKey(lp) === entryKey(ap)) { mergePoints += 1; continue; } // 本机未改、远端删 → 跟随删除
|
|
195
|
-
conflict(`plugins.${name}`, 'modify-delete', lp, undefined, ap);
|
|
196
|
-
}
|
|
197
|
-
// 只有远端有的
|
|
198
|
-
for (const rp of r.plugins) {
|
|
199
|
-
const name = rp.name;
|
|
200
|
-
if (l.plugins.some((p) => p.name === name)) continue;
|
|
201
|
-
const ap = aMap.get(name);
|
|
202
|
-
if (ap === undefined) { merged.push(rp); mergePoints += 1; continue; } // 远端独有
|
|
203
|
-
if (entryKey(rp) === entryKey(ap)) { mergePoints += 1; continue; } // 远端未改、本机删 → 跟随删除
|
|
204
|
-
conflict(`plugins.${name}`, 'delete-modify', undefined, rp, ap);
|
|
274
|
+
} else if (wsMerged !== wsLocal) {
|
|
275
|
+
mergePoints += 1;
|
|
205
276
|
}
|
|
277
|
+
|
|
206
278
|
if (conflicts.length > 0) return { merged: l as SectionData, conflicts, mergePoints };
|
|
207
|
-
|
|
279
|
+
|
|
280
|
+
// 以远端为底再盖本机:远端独有的未知/将来字段被采纳,而不是被本机形状悄悄吞掉(复审 P2)。
|
|
281
|
+
const next: PluginsSection & Record<string, unknown> = { ...r, ...l };
|
|
282
|
+
next.plugins = plugins.merged;
|
|
283
|
+
next.patch = patch.merged;
|
|
284
|
+
// 可选字段只在「本机或合并结果里确实有」时写回:不擅自在载荷里新增空字段。
|
|
285
|
+
if (l.localTarballs !== undefined || tarballs.merged.length > 0) next.localTarballs = tarballs.merged;
|
|
286
|
+
else delete next.localTarballs;
|
|
287
|
+
if (l.patchFiles !== undefined || files.merged.length > 0) next.patchFiles = files.merged;
|
|
288
|
+
else delete next.patchFiles;
|
|
289
|
+
// 只有「两侧都没带这个键、合并也没产出值」才删键;否则原样写回(含 null)。
|
|
290
|
+
// 把 null 抹成缺键会让合并结果与两侧都不等 ⇒ 每轮都判「已合并」,永不收敛(复审 P0-1)。
|
|
291
|
+
if (wsMerged === undefined || (wsMerged === null && !wsCarried)) delete next.pnpmWorkspace;
|
|
292
|
+
else next.pnpmWorkspace = wsMerged;
|
|
293
|
+
return { merged: next as SectionData, conflicts: [], mergePoints };
|
|
208
294
|
}
|