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
|
@@ -364,6 +364,73 @@ test('config_sync_push:复用 SyncEngine.push(内存 transport),返回 s
|
|
|
364
364
|
}
|
|
365
365
|
})
|
|
366
366
|
|
|
367
|
+
test('config_sync_push:内容未变 → 如实回传 skipped=unchanged(issue #140:不再造重复快照)', async () => {
|
|
368
|
+
const { deps, tmp, transport } = await makeDeps()
|
|
369
|
+
try {
|
|
370
|
+
await writeSyncConfig(deps.syncDir, { schemaVersion: 2, transport: 'git', git: { repoUrl: 'https://github.com/u/r.git' } })
|
|
371
|
+
const tools = createModelTools(deps)
|
|
372
|
+
const first = (await tools.syncPush({ channel: 'git' })) as { ok: boolean; snapshotId: string }
|
|
373
|
+
assert.equal(first.ok, true)
|
|
374
|
+
const uploads = transport.calls.filter((c) => c === 'upload').length
|
|
375
|
+
|
|
376
|
+
const second = (await tools.syncPush({ channel: 'git' })) as {
|
|
377
|
+
ok: boolean; snapshotId: string; skipped?: string; adoptedSnapshotId?: string
|
|
378
|
+
}
|
|
379
|
+
assert.equal(second.ok, true)
|
|
380
|
+
assert.equal(second.skipped, 'unchanged', '模型必须看到「内容没变」,而不是「又推了一版」')
|
|
381
|
+
assert.equal(second.snapshotId, first.snapshotId, '沿用既有快照 id')
|
|
382
|
+
assert.equal(second.adoptedSnapshotId, first.snapshotId)
|
|
383
|
+
assert.equal(transport.calls.filter((c) => c === 'upload').length, uploads, '一次 upload 都不发')
|
|
384
|
+
|
|
385
|
+
const forced = (await tools.syncPush({ channel: 'git', force: true })) as { ok: boolean; skipped?: string }
|
|
386
|
+
assert.equal(forced.skipped, undefined, 'force 覆盖跳过判定')
|
|
387
|
+
assert.equal(transport.calls.filter((c) => c === 'upload').length, uploads + 1, 'force 才真的上传')
|
|
388
|
+
} finally {
|
|
389
|
+
await fs.rm(tmp, { recursive: true, force: true })
|
|
390
|
+
}
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
test('config_sync_push:用户放行的可选分区必须进引擎(issue #138:显式 mcp 不再 skipNonPortable)', async () => {
|
|
394
|
+
const { deps, tmp, transport, ctx } = await makeDeps()
|
|
395
|
+
try {
|
|
396
|
+
await writeSyncConfig(deps.syncDir, { schemaVersion: 2, transport: 'git', git: { repoUrl: 'https://github.com/u/r.git' } })
|
|
397
|
+
// mcp adapter 的数据源:一行 dsh-mcp-client patch(与 sync-engine.test.ts 的 seedMcp 同形)
|
|
398
|
+
ctx.patchFile.lines.set('mcp-citra', {
|
|
399
|
+
lineId: 'mcp-citra',
|
|
400
|
+
raw: {
|
|
401
|
+
id: 'mcp-citra',
|
|
402
|
+
name: 'dsh-mcp-client',
|
|
403
|
+
config: { serverName: 'citra', command: 'npx', args: ['-y', '@sylphx/citra'] },
|
|
404
|
+
},
|
|
405
|
+
})
|
|
406
|
+
// 真实装配口径:宿主把 'auto' 档交给 deps.optInSections;这里故意混入 sessions 验证永久排除。
|
|
407
|
+
const seenOptIn: (readonly SectionId[])[] = []
|
|
408
|
+
const inner = deps.makeSyncEngine
|
|
409
|
+
const tools = createModelTools({
|
|
410
|
+
...deps,
|
|
411
|
+
makeSyncEngine: (cfg, engineOpts) => {
|
|
412
|
+
seenOptIn.push(engineOpts?.optInSections ?? [])
|
|
413
|
+
return inner(cfg, engineOpts)
|
|
414
|
+
},
|
|
415
|
+
optInSections: () => ['mcp', 'sessions'],
|
|
416
|
+
})
|
|
417
|
+
const out = (await tools.syncPush({ channel: 'git', sections: ['settings', 'mcp'] })) as {
|
|
418
|
+
ok: boolean; sections: string[]; warnings: string[]
|
|
419
|
+
}
|
|
420
|
+
assert.equal(out.ok, true)
|
|
421
|
+
assert.ok(out.sections.includes('mcp'), '显式放行的 mcp 必须进入快照: ' + out.sections.join(','))
|
|
422
|
+
assert.ok(!out.sections.includes('sessions'), 'sessions 永不上行')
|
|
423
|
+
assert.deepEqual(seenOptIn[seenOptIn.length - 1], ['mcp'], '引擎收到的可选分区 = 放行集合 − sessions')
|
|
424
|
+
assert.ok(
|
|
425
|
+
!out.warnings.some((w) => w.includes('mcp')),
|
|
426
|
+
'放行后不得再报 skipNonPortable: ' + out.warnings.join(' | '),
|
|
427
|
+
)
|
|
428
|
+
assert.ok(transport.calls.includes('upload'), 'push 写远端')
|
|
429
|
+
} finally {
|
|
430
|
+
await fs.rm(tmp, { recursive: true, force: true })
|
|
431
|
+
}
|
|
432
|
+
})
|
|
433
|
+
|
|
367
434
|
test('config_sync_pull:空远端 → 零写入空差异', async () => {
|
|
368
435
|
const { deps, tmp, transport, ctx } = await makeDeps()
|
|
369
436
|
try {
|
package/src/core/model-tools.ts
CHANGED
|
@@ -80,8 +80,8 @@ export interface ModelToolsDeps {
|
|
|
80
80
|
syncDir: string
|
|
81
81
|
/**
|
|
82
82
|
* SyncEngine 工厂(git/webdav 按配置分支构造传输;与 host 路由同一来源)。
|
|
83
|
-
* D5:agent 侧按工具决定 optInSections
|
|
84
|
-
*
|
|
83
|
+
* D5:agent 侧按工具决定 optInSections —— 推送 / 拉取 / 预览 / 合并一律带用户放行的 'auto' 档,
|
|
84
|
+
* 再剔除 sessions(与 docs/architecture/agent-tools.md 的工具面口径同一份事实)。
|
|
85
85
|
*/
|
|
86
86
|
makeSyncEngine: (cfg: SyncConfig, opts?: { optInSections?: readonly SectionId[] }) => SyncEngine
|
|
87
87
|
/** 插件版本(manifest.exporter.version) */
|
|
@@ -163,13 +163,20 @@ async function resolveSyncTarget(
|
|
|
163
163
|
return { cfg, channel: ch }
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* 解析同步引擎(推送 / 拉取)。
|
|
168
|
+
* D5:与 preview/apply 同一口径 —— 引擎构造期必须拿到用户放行的 'auto' 档可选分区,
|
|
169
|
+
* 否则显式传 mcp 会在 pushTargets 里被判成非 portable 并 skipNonPortable(issue #138 ④)。
|
|
170
|
+
*/
|
|
167
171
|
async function resolveEngine(
|
|
168
172
|
deps: ModelToolsDeps,
|
|
169
173
|
channel?: SyncTransportType,
|
|
170
174
|
): Promise<{ engine: SyncEngine; channel: SyncTransportType }> {
|
|
171
175
|
const target = await resolveSyncTarget(deps, channel)
|
|
172
|
-
return {
|
|
176
|
+
return {
|
|
177
|
+
engine: deps.makeSyncEngine(target.cfg, { optInSections: agentOptInSections(deps, target.channel) }),
|
|
178
|
+
channel: target.channel,
|
|
179
|
+
}
|
|
173
180
|
}
|
|
174
181
|
|
|
175
182
|
/* ------------------------------------------------------------ 结构化结论与摘要 */
|
|
@@ -572,6 +579,9 @@ export function createModelTools(deps: ModelToolsDeps) {
|
|
|
572
579
|
...(sections === undefined ? {} : { sections }),
|
|
573
580
|
...(encrypt ? { encrypt: true, includeSecrets: false, password: password ?? '' } : {}),
|
|
574
581
|
...(input.force === true ? { force: true } : {}),
|
|
582
|
+
// 空数组 = 连磁盘待裁决一起扣(issue #146):agent 的手动推送与 GUI 同口径,
|
|
583
|
+
// 否则「跑一次 push 工具」就能把用户挂着未裁决的分区整块覆盖掉。
|
|
584
|
+
skipSections: [],
|
|
575
585
|
})
|
|
576
586
|
const report = await runWithMutationLock(deps.host.mutationLock, { op: 'model-sync-push', isBlocked: () => deps.host.safeModeIsBlocked?.() ?? false }, async (lockCtx) => {
|
|
577
587
|
if (deps.host.phase3Recovery !== undefined && lockCtx !== null) {
|
|
@@ -594,6 +604,14 @@ export function createModelTools(deps: ModelToolsDeps) {
|
|
|
594
604
|
// 否则模型会把它当成「推送成功但内容为空」继续往下走。
|
|
595
605
|
...(report.conflict === true ? { conflict: true } : {}),
|
|
596
606
|
...(report.adoptedBase === undefined ? {} : { adoptedBase: report.adoptedBase }),
|
|
607
|
+
// issue #140:内容与远端最新一致 ⇒ 引擎什么都没写(不 upload、不建目录)。
|
|
608
|
+
// 不透传的话模型会把「ok:true + snapshotId」读成「又推了一份新快照」。
|
|
609
|
+
...(report.skipped === 'unchanged'
|
|
610
|
+
? { skipped: 'unchanged' as const, adoptedSnapshotId: report.adoptedSnapshotId ?? report.snapshotId }
|
|
611
|
+
// issue #146:目标分区全被未裁决冲突扣下 ⇒ 一个分区都没推,绝不读成「推成功」
|
|
612
|
+
: report.skipped === 'all-conflicted'
|
|
613
|
+
? { skipped: 'all-conflicted' as const }
|
|
614
|
+
: {}),
|
|
597
615
|
...(report.message === undefined ? {} : { message: report.message }),
|
|
598
616
|
...(encrypt ? { passwordSource: stored === undefined ? 'argument' : 'stored' } : {}),
|
|
599
617
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生效 patch 链索引(issue #144)。
|
|
3
|
+
*
|
|
4
|
+
* 「这个 id 已存在吗」必须按**整条链**判定:bundle 层(`dsh.bundle.patch`,按
|
|
5
|
+
* `dsh.profile.bundles` 顺序)→ profile 层 → home 层 → overlays。只看 home/profile 两个
|
|
6
|
+
* 文件会把 bundle 已提供的 id 当成「本机没有」,于是写第二条 `- insert:` 成员,宿主
|
|
7
|
+
* compose 后同一 id 两份新增来源 —— 插件保存配置时报
|
|
8
|
+
* `Configuration for "X" is overridden by a home patch or command-line overlay`。
|
|
9
|
+
*/
|
|
10
|
+
import test from 'node:test';
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
|
|
13
|
+
import { patchChainIndex, providedByOtherLayers, readPatchChainIndex } from './patch-chain.ts';
|
|
14
|
+
import type { PatchChainRead } from './patch-chain.ts';
|
|
15
|
+
|
|
16
|
+
const BUNDLE = 'bundles:demo-bundle/cordis.patch.yml';
|
|
17
|
+
const PROFILE = 'profiles/web/cordis.patch.yml';
|
|
18
|
+
const HOME = 'cordis.patch.yml';
|
|
19
|
+
|
|
20
|
+
test('#144 链索引:同一 id 跨层合流(层按合并序、name 取首个声明者、记 insert 形态)', () => {
|
|
21
|
+
const index = patchChainIndex({
|
|
22
|
+
sources: [
|
|
23
|
+
{ file: BUNDLE, doc: [{ insert: [{ id: 'remote-ssh', name: '@zhangfengshun/dsh-remote-ssh', config: { port: 22 } }] }] },
|
|
24
|
+
{ file: PROFILE, doc: [{ id: 'remote-ssh', disabled: false }, { id: 'local-only' }] },
|
|
25
|
+
{ file: HOME, doc: [{ id: 'remote-ssh', disabled: true }] },
|
|
26
|
+
],
|
|
27
|
+
failures: [],
|
|
28
|
+
});
|
|
29
|
+
const entry = index.get('remote-ssh');
|
|
30
|
+
assert.deepEqual(entry?.layers, [BUNDLE, PROFILE, HOME], '层按宿主合并序去重');
|
|
31
|
+
assert.deepEqual(entry?.insertLayers, [BUNDLE], '只有 bundle 层是「新增」来源,其余是覆盖行');
|
|
32
|
+
assert.equal(entry?.name, '@zhangfengshun/dsh-remote-ssh', 'name 取首个声明它的层(写覆盖行要与之一致)');
|
|
33
|
+
assert.deepEqual(index.get('local-only'), { id: 'local-only', layers: [PROFILE], insertLayers: [] });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('#144 链索引:写某一层时「别的层是否提供」不含本层自己', () => {
|
|
37
|
+
const read: PatchChainRead = {
|
|
38
|
+
sources: [
|
|
39
|
+
{ file: PROFILE, doc: [{ id: 'dup' }, { id: 'only-here' }] },
|
|
40
|
+
{ file: HOME, doc: [{ id: 'dup' }] },
|
|
41
|
+
],
|
|
42
|
+
failures: [],
|
|
43
|
+
};
|
|
44
|
+
const byOther = providedByOtherLayers(patchChainIndex(read), PROFILE);
|
|
45
|
+
assert.deepEqual([...byOther.keys()], ['dup'], '仅在本层的 id 不算「已存在」,仍然可以 insert');
|
|
46
|
+
assert.deepEqual(byOther.get('dup')?.layers, [PROFILE, HOME], 'layers 保留全部提供者,调用方按需筛');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('#144 链索引:读不出来的层只进 failures,不贡献 id 也不抛错(fail-open)', () => {
|
|
50
|
+
const read: PatchChainRead = {
|
|
51
|
+
sources: [{ file: HOME, doc: [{ id: 'x' }] }],
|
|
52
|
+
failures: [{ file: BUNDLE, reason: 'package not installed in this profile' }],
|
|
53
|
+
};
|
|
54
|
+
assert.deepEqual([...patchChainIndex(read).keys()], ['x']);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('#144 readPatchChainIndex:门面没实现该能力 → index 为 null(判定退化为两层,绝不阻断写入)', async () => {
|
|
58
|
+
assert.deepEqual(await readPatchChainIndex({}), { index: null, failures: [] });
|
|
59
|
+
const read = await readPatchChainIndex({
|
|
60
|
+
readPatchChain: async () => ({ sources: [{ file: BUNDLE, doc: [{ insert: [{ id: 'y' }] }] }], failures: [] }),
|
|
61
|
+
});
|
|
62
|
+
assert.deepEqual(read.index?.get('y'), { id: 'y', layers: [BUNDLE], insertLayers: [BUNDLE] });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('#144 readPatchChainIndex:读链抛错 → 退化为两层并登记失败(不把异常抛给导入)', async () => {
|
|
66
|
+
const read = await readPatchChainIndex({
|
|
67
|
+
readPatchChain: async () => { throw new Error('manifest unreadable') },
|
|
68
|
+
});
|
|
69
|
+
assert.equal(read.index, null);
|
|
70
|
+
assert.equal(read.failures.length, 1);
|
|
71
|
+
assert.match(read.failures[0]?.reason ?? '', /manifest unreadable/);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('#144 readPatchChainIndex:读不出来的层随结果上报(判据缺口必须可见)', async () => {
|
|
75
|
+
const read = await readPatchChainIndex({
|
|
76
|
+
readPatchChain: async () => ({
|
|
77
|
+
sources: [{ file: HOME, doc: [{ id: 'x' }] }],
|
|
78
|
+
failures: [{ file: 'bundles:gone', reason: 'package not installed in this profile' }],
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
assert.deepEqual([...read.index?.keys() ?? []], ['x']);
|
|
82
|
+
assert.equal(read.failures[0]?.file, 'bundles:gone');
|
|
83
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生效 patch 链(issue #144)。
|
|
3
|
+
*
|
|
4
|
+
* DSH 启动时把**多层** patch 合并到同一份 plugin 树上(dsh-app-boot 的 readProfilePatches):
|
|
5
|
+
* bundle 层(各 bundle 的 `dsh.bundle.patch`,按 `dsh.profile.bundles` 顺序)
|
|
6
|
+
* → profile 层(`profiles/<profile>/cordis.patch.yml`)
|
|
7
|
+
* → home 层(`cordis.patch.yml`)→ overlays。
|
|
8
|
+
*
|
|
9
|
+
* 同一个 id 只能有**一份**「新增」来源:两处 `- insert:` 成员会把同一条目插两次,宿主
|
|
10
|
+
* composeEntries 之后拿到的 config 变成数组 / 取到没有 config 的那份,于是插件自己的
|
|
11
|
+
* ConfigEditor 落盘时报
|
|
12
|
+
* `Configuration for "X" is overridden by a home patch or command-line overlay` —— 报错把原因
|
|
13
|
+
* 说反了(真正的原因是「我们插了第二份」,issue #144)。
|
|
14
|
+
*
|
|
15
|
+
* 于是「这个 id 存在吗」必须按**整条链**判定,而不是只看两个 patch 文件(issue #144 之前的
|
|
16
|
+
* 判据只覆盖 home/profile 两层,见 `patchLayerRels`):
|
|
17
|
+
* - 链上已存在 ⇒ 只能写**顶层覆盖行**(`- id: X`,带 config;写 name 时必须与既有条目一致,
|
|
18
|
+
* 否则宿主 `patch: name mismatch … skipping` 整行跳过);
|
|
19
|
+
* - 链上不存在 ⇒ 只能写 `- insert:` 成员(顶层行会被 `patch: entry not found` 丢弃)。
|
|
20
|
+
*
|
|
21
|
+
* 本模块只做**纯计算**(core 层零依赖、不碰 YAML / IO):各层文档由宿主门面读好交进来。
|
|
22
|
+
* 三个消费点共用同一份索引 —— 导入判定(计划项 Create / Update)、写前降级(insert → 覆盖行)、
|
|
23
|
+
* 覆盖行孤儿守卫(整链没人提供该 id ⇒ 拒写)。
|
|
24
|
+
*/
|
|
25
|
+
import { patchDocumentEntries } from './patch-document.ts';
|
|
26
|
+
|
|
27
|
+
/** 生效链上的一层:层身份 + 已解析的文档。 */
|
|
28
|
+
export interface PatchChainSource {
|
|
29
|
+
/**
|
|
30
|
+
* 层身份。前两种与 `patch-layers.ts` 同口径(相对 homeDir 的 POSIX 路径);bundle 层用
|
|
31
|
+
* `bundles:<包名>/<patch 文件>` —— 它不是本机可写的层,只用于判重与取 name。
|
|
32
|
+
*/
|
|
33
|
+
file: string;
|
|
34
|
+
doc: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 读不出来的层(fail-open:判定只做加强,但缺口必须能上报,不能静默变成「确知没有」)。 */
|
|
38
|
+
export interface PatchChainFailure {
|
|
39
|
+
file: string;
|
|
40
|
+
reason: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 门面读到的整条链(宿主合并序)与读失败的层。 */
|
|
44
|
+
export interface PatchChainRead {
|
|
45
|
+
/** 宿主合并序:bundle 层在前,然后 profile 层、home 层 */
|
|
46
|
+
sources: PatchChainSource[];
|
|
47
|
+
/** 读不出来 / 解析不了的层 */
|
|
48
|
+
failures: PatchChainFailure[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 链上某个 id 的合流结果。 */
|
|
52
|
+
export interface PatchChainEntry {
|
|
53
|
+
id: string;
|
|
54
|
+
/** 条目声明的 name(写顶层覆盖行时必须与之一致,否则宿主整行跳过;`alignOverrideNames` 用它校正) */
|
|
55
|
+
name?: string;
|
|
56
|
+
/** 提供该 id 的层(按合并序去重) */
|
|
57
|
+
layers: string[];
|
|
58
|
+
/** 其中**以 `- insert:` 成员形式**提供该 id 的层(>=2 就是「两条新增抢同一 id」的坏状态) */
|
|
59
|
+
insertLayers: string[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 写回结果(`applyPatchChanges` 的返回值):被降级的 insert id。 */
|
|
63
|
+
export interface PatchWriteOutcome {
|
|
64
|
+
/**
|
|
65
|
+
* 本次被**降级为顶层覆盖行**的 id:调用方要求 insert,但链上已有其他层提供该 id
|
|
66
|
+
* (issue #144 的存量修复;正常路径在计划阶段就已判定,这里只是最后一道兜底)。
|
|
67
|
+
*/
|
|
68
|
+
downgraded: string[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 把整条链折成 id → 层/形态索引(顺序 = 宿主合并序,先出现者优先记 name)。 */
|
|
72
|
+
export function patchChainIndex(read: PatchChainRead): Map<string, PatchChainEntry> {
|
|
73
|
+
const index = new Map<string, PatchChainEntry>();
|
|
74
|
+
for (const source of read.sources) {
|
|
75
|
+
for (const entry of patchDocumentEntries(source.doc)) {
|
|
76
|
+
const known = index.get(entry.id);
|
|
77
|
+
if (known === undefined) {
|
|
78
|
+
const fresh: PatchChainEntry = { id: entry.id, layers: [source.file], insertLayers: [] };
|
|
79
|
+
if (entry.name !== undefined) fresh.name = entry.name;
|
|
80
|
+
if (entry.inInsert) fresh.insertLayers.push(source.file);
|
|
81
|
+
index.set(entry.id, fresh);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (!known.layers.includes(source.file)) known.layers.push(source.file);
|
|
85
|
+
if (entry.inInsert && !known.insertLayers.includes(source.file)) known.insertLayers.push(source.file);
|
|
86
|
+
// name 取**第一个**声明它的层:宿主按既有条目的 name 校验覆盖行,低优先级层的同名条目最终也会被覆盖
|
|
87
|
+
if (known.name === undefined && entry.name !== undefined) known.name = entry.name;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return index;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 链上「**本文件之外**的层」提供的 id(写这一层时的判据)。 */
|
|
94
|
+
export function providedByOtherLayers(
|
|
95
|
+
index: Map<string, PatchChainEntry>,
|
|
96
|
+
file: string,
|
|
97
|
+
): Map<string, PatchChainEntry> {
|
|
98
|
+
const out = new Map<string, PatchChainEntry>();
|
|
99
|
+
for (const [id, entry] of index) {
|
|
100
|
+
if (entry.layers.some((layer) => layer !== file)) out.set(id, entry);
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 把待写的**顶层行**里的 `name` 校正成链上既有条目的 name(issue #144 的验收标准之一)。
|
|
107
|
+
*
|
|
108
|
+
* 为什么必须校正:宿主对覆盖行做 `name === target.name` 校验,不一致就
|
|
109
|
+
* `patch: name mismatch … skipping` 把整行丢掉 —— 快照来自另一台机器(裸名)而目标机由
|
|
110
|
+
* bundle 提供(scoped 名)时,导入会报「成功」但一个字节都没生效,原报错照旧。
|
|
111
|
+
* `insert` 块成员不动(那是新增,name 由来源决定)。
|
|
112
|
+
*/
|
|
113
|
+
export function alignOverrideNames(
|
|
114
|
+
items: readonly unknown[],
|
|
115
|
+
index: Map<string, PatchChainEntry>,
|
|
116
|
+
): unknown[] {
|
|
117
|
+
return items.map((item) => {
|
|
118
|
+
if (item === null || typeof item !== 'object' || Array.isArray(item)) return item;
|
|
119
|
+
const obj = item as Record<string, unknown>;
|
|
120
|
+
if ('insert' in obj) return item;
|
|
121
|
+
const id = obj['id'];
|
|
122
|
+
if (typeof id !== 'string' || id === '') return item;
|
|
123
|
+
const wanted = index.get(id)?.name;
|
|
124
|
+
if (wanted === undefined || obj['name'] === wanted) return item;
|
|
125
|
+
return { ...obj, name: wanted };
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** 读整条链的结果:索引 + 读不出来的层(后者供报告面提示「判据不完整」)。 */
|
|
130
|
+
export interface PatchChainIndexRead {
|
|
131
|
+
/** 门面没实现该能力(老宿主 / 测试替身)→ `null`(判定退化为两层) */
|
|
132
|
+
index: Map<string, PatchChainEntry> | null;
|
|
133
|
+
failures: PatchChainFailure[];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 读整条链并折成索引。门面没实现 `readPatchChain`、或读链本身抛错 → `index: null`
|
|
138
|
+
* (判定退化为两层 patch 文件,绝不因为链读失败阻断写入)。
|
|
139
|
+
*/
|
|
140
|
+
export async function readPatchChainIndex(
|
|
141
|
+
patchFile: { readPatchChain?: () => Promise<PatchChainRead> },
|
|
142
|
+
): Promise<PatchChainIndexRead> {
|
|
143
|
+
if (patchFile.readPatchChain === undefined) return { index: null, failures: [] };
|
|
144
|
+
try {
|
|
145
|
+
const read = await patchFile.readPatchChain();
|
|
146
|
+
return { index: patchChainIndex(read), failures: read.failures };
|
|
147
|
+
} catch (err) {
|
|
148
|
+
return { index: null, failures: [{ file: 'patch-chain', reason: err instanceof Error ? err.message : String(err) }] };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -11,7 +11,8 @@ import test from 'node:test';
|
|
|
11
11
|
import assert from 'node:assert/strict';
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
|
-
describePatchDocument, describePatchLayoutDrift, PatchPromoteRefusedError,
|
|
14
|
+
describePatchDocument, describePatchLayoutDrift, PatchPromoteRefusedError, patchDocumentEntries,
|
|
15
|
+
planPatchDocument, unprovidedTopLevelIds,
|
|
15
16
|
} from './patch-document.ts';
|
|
16
17
|
|
|
17
18
|
const DOC = [
|
|
@@ -105,3 +106,49 @@ test('#133 写后自检:布局不一致时给出可读差异(一致返回 nu
|
|
|
105
106
|
assert.match(String(drift), /insert=\[mcp-a, mcp-b\]/);
|
|
106
107
|
assert.match(String(drift), /got insert=\[\]/);
|
|
107
108
|
});
|
|
109
|
+
|
|
110
|
+
/* ------------------- issue #144:跨层「这个 id 存在吗」的两个判据原语 ------------------- */
|
|
111
|
+
|
|
112
|
+
test('#144 patchDocumentEntries:读出 name 与形态(insert 成员 / 顶层行),坏条目跳过', () => {
|
|
113
|
+
assert.deepEqual(patchDocumentEntries([
|
|
114
|
+
{ id: 'top', name: 'pkg-top', disabled: true },
|
|
115
|
+
{ insert: [{ id: 'in-a', name: 'pkg-a', config: { x: 1 } }, { id: 'in-b' }, { name: 'no-id' }] },
|
|
116
|
+
{ id: 42 },
|
|
117
|
+
null,
|
|
118
|
+
{ insert: 'not-an-array' },
|
|
119
|
+
]), [
|
|
120
|
+
{ id: 'top', name: 'pkg-top', inInsert: false },
|
|
121
|
+
{ id: 'in-a', name: 'pkg-a', inInsert: true },
|
|
122
|
+
{ id: 'in-b', inInsert: true },
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('#144 unprovidedTopLevelIds:别的层 insert 过它 = 已提供(覆盖合法),只有整链都没人才拒绝', () => {
|
|
127
|
+
const bundleLayer = [{ insert: [{ id: 'remote-ssh', name: '@zhangfengshun/dsh-remote-ssh' }] }];
|
|
128
|
+
// 旧判据(promotedTopLevelIds)在这里反过来拒绝 —— 那正是 #144 里 6 个 id 被误拒的成因
|
|
129
|
+
assert.deepEqual(unprovidedTopLevelIds([bundleLayer, []], ['remote-ssh']), []);
|
|
130
|
+
assert.deepEqual(unprovidedTopLevelIds([bundleLayer], ['ghost']), ['ghost'], '整链没人提供 → 宿主 not found 丢弃,必须拒绝');
|
|
131
|
+
assert.deepEqual(unprovidedTopLevelIds([], ['ghost']), ['ghost'], '读不出来的层由调用方丢弃后同样按「没人提供」处理');
|
|
132
|
+
assert.deepEqual(unprovidedTopLevelIds([bundleLayer], []), []);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('#144 forceTopLevel:本层已有 insert 成员时,带标记的 update 必须搬到顶层(否则仍是两条新增)', () => {
|
|
136
|
+
const plan = planPatchDocument(DOC, [
|
|
137
|
+
{ lineId: 'mcp-a', raw: { id: 'mcp-a', name: 'dsh-mcp-client', config: { transport: 'stdio', command: 'uvx' } }, action: 'update', forceTopLevel: true },
|
|
138
|
+
]);
|
|
139
|
+
assert.deepEqual(plan.topLevelIds, ['top-a', 'top-b', 'mcp-a'], 'id 必须变成顶层行(覆盖),不再占新增位');
|
|
140
|
+
assert.deepEqual(plan.insertIds, ['mcp-b'], '另两个成员不动');
|
|
141
|
+
const block = plan.items.find((item) => Array.isArray((item as Record<string, unknown>)['insert'])) as { insert: { id: string }[] };
|
|
142
|
+
assert.deepEqual(block.insert.map((e) => e.id), ['mcp-b'], '块里不得再留 mcp-a');
|
|
143
|
+
const row = plan.items.find((item) => (item as Record<string, unknown>)['id'] === 'mcp-a') as { config: { command: string } };
|
|
144
|
+
assert.equal(row.config.command, 'uvx', '配置照样写进去');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('#144 forceTopLevel:原条目不在文档里时也直接落顶层行(幂等重放不产生第二条新增)', () => {
|
|
148
|
+
const plan = planPatchDocument(DOC, [
|
|
149
|
+
{ lineId: 'ghost', raw: { id: 'ghost', config: { a: 1 } }, action: 'update', forceTopLevel: true },
|
|
150
|
+
]);
|
|
151
|
+
assert.deepEqual(plan.topLevelIds, ['top-a', 'top-b', 'ghost']);
|
|
152
|
+
assert.deepEqual(plan.insertIds, ['mcp-a', 'mcp-b']);
|
|
153
|
+
});
|
|
154
|
+
|
|
@@ -20,6 +20,14 @@ export interface PatchLineChange {
|
|
|
20
20
|
lineId: string;
|
|
21
21
|
raw: unknown;
|
|
22
22
|
action: 'insert' | 'update' | 'remove';
|
|
23
|
+
/**
|
|
24
|
+
* 强制这一行落在**顶层**(覆盖行),即使本层还留着同名 insert 成员(issue #144 的存量修复)。
|
|
25
|
+
*
|
|
26
|
+
* 不变①的例外,只在调用方**知道该 id 已被别的层提供**时置位:此时本层的旧 insert 成员与
|
|
27
|
+
* 别处的 insert 是两条新增抢同一个 id(宿主 compose 后取到没有 config 的那份,插件保存配置
|
|
28
|
+
* 必然报 overridden)。光把 action 改成 update 不够 —— 归属按原文档决定,insert 成员会原地留下。
|
|
29
|
+
*/
|
|
30
|
+
forceTopLevel?: boolean;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export interface PatchDocumentPlan {
|
|
@@ -61,22 +69,54 @@ function blockMembers(value: unknown): Record<string, unknown>[] | null {
|
|
|
61
69
|
return insert.filter((entry): entry is Record<string, unknown> => entry !== null && typeof entry === 'object');
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
/**
|
|
73
|
+
* 文档里的一条条目:id、它声明的 name、以及出现在 insert 块里还是顶层。
|
|
74
|
+
*
|
|
75
|
+
* 为什么把 name 一起读出来:写**顶层覆盖行**时宿主会校验 `name === target.name`,不一致就
|
|
76
|
+
* `patch: name mismatch … skipping` 整行跳过(issue #144 的条目都来自 bundle 层,name 在那边)。
|
|
77
|
+
*/
|
|
78
|
+
export interface PatchDocumentEntry {
|
|
79
|
+
id: string;
|
|
80
|
+
/** 条目里声明的 name(没写就没有;覆盖行不写 name 也合法) */
|
|
81
|
+
name?: string;
|
|
82
|
+
/** true = `- insert:` 块成员(新增);false = 顶层行(覆盖) */
|
|
83
|
+
inInsert: boolean;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 读出文档里的全部条目(不判重、保持文档顺序)。 */
|
|
87
|
+
export function patchDocumentEntries(doc: unknown): PatchDocumentEntry[] {
|
|
88
|
+
const entries: PatchDocumentEntry[] = [];
|
|
89
|
+
if (!Array.isArray(doc)) return entries;
|
|
69
90
|
for (const item of doc) {
|
|
70
91
|
const members = blockMembers(item);
|
|
71
92
|
if (members !== null) {
|
|
72
93
|
for (const member of members) {
|
|
73
94
|
const id = entryId(member);
|
|
74
|
-
if (id
|
|
95
|
+
if (id === null) continue;
|
|
96
|
+
const name = member['name'];
|
|
97
|
+
entries.push(typeof name === 'string'
|
|
98
|
+
? { id, name, inInsert: true }
|
|
99
|
+
: { id, inInsert: true });
|
|
75
100
|
}
|
|
76
101
|
continue;
|
|
77
102
|
}
|
|
78
103
|
const id = entryId(item);
|
|
79
|
-
if (id
|
|
104
|
+
if (id === null) continue;
|
|
105
|
+
const name = (item as Record<string, unknown>)['name'];
|
|
106
|
+
entries.push(typeof name === 'string'
|
|
107
|
+
? { id, name, inInsert: false }
|
|
108
|
+
: { id, inInsert: false });
|
|
109
|
+
}
|
|
110
|
+
return entries;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 读出文档里的 insert 成员 id 与顶层行 id(自检与测试共用;不判重、保持文档顺序)。 */
|
|
114
|
+
export function describePatchDocument(doc: unknown): { insertIds: string[]; topLevelIds: string[] } {
|
|
115
|
+
const insertIds: string[] = [];
|
|
116
|
+
const topLevelIds: string[] = [];
|
|
117
|
+
for (const entry of patchDocumentEntries(doc)) {
|
|
118
|
+
if (entry.inInsert) insertIds.push(entry.id);
|
|
119
|
+
else topLevelIds.push(entry.id);
|
|
80
120
|
}
|
|
81
121
|
return { insertIds, topLevelIds };
|
|
82
122
|
}
|
|
@@ -117,8 +157,11 @@ export function planPatchDocument(doc: unknown, changes: readonly PatchLineChang
|
|
|
117
157
|
continue;
|
|
118
158
|
}
|
|
119
159
|
const previous = state.get(change.lineId);
|
|
120
|
-
//
|
|
121
|
-
|
|
160
|
+
// 归属默认由**原文档**决定:更新一条既有 insert 成员不会把它搬到顶层;新增才按动作分流。
|
|
161
|
+
// forceTopLevel 是唯一例外(#144 存量:本层旧 insert 成员 + 别层也 insert 同一 id)。
|
|
162
|
+
const inInsert = change.forceTopLevel === true
|
|
163
|
+
? false
|
|
164
|
+
: previous !== undefined ? previous.inInsert : change.action === 'insert';
|
|
122
165
|
state.set(change.lineId, { raw: change.raw, inInsert });
|
|
123
166
|
}
|
|
124
167
|
|
|
@@ -182,13 +225,21 @@ export function describePatchLayoutDrift(
|
|
|
182
225
|
+ '; got ' + fmt('insert', observed.insertIds) + ' ' + fmt('top-level', observed.topLevelIds);
|
|
183
226
|
}
|
|
184
227
|
/**
|
|
185
|
-
*
|
|
228
|
+
* 覆盖行孤儿检查(issue #133 起、issue #144 改判到「整条生效链」口径)。
|
|
186
229
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
230
|
+
* 宿主对顶层行只做**覆盖**:`entryMap` 查不到该 id ⇒ `patch: entry %C not found` 整行丢弃。
|
|
231
|
+
* 所以真正值得拒绝的只有一种:**任何一层都没有提供这个 id**。旧判据反过来拒绝「别的层用
|
|
232
|
+
* `- insert:` 提供过它」—— 那恰恰是条目已经存在、覆盖**合法**的情形,#144 里 bundle 层提供的
|
|
233
|
+
* 6 个 id 正是被这条旧判据误拒的(写进去就是重复条目)。
|
|
234
|
+
*
|
|
235
|
+
* `docs` = 判定依据的层文档(生效链 + 本文件写入前的文档;读不出来的层由调用方自行丢弃 ——
|
|
236
|
+
* 守卫只做加强,绝不因为兄弟层损坏而永久阻塞写入)。
|
|
189
237
|
*/
|
|
190
|
-
export function
|
|
238
|
+
export function unprovidedTopLevelIds(docs: readonly unknown[], topLevelIds: readonly string[]): string[] {
|
|
191
239
|
if (topLevelIds.length === 0) return [];
|
|
192
|
-
const
|
|
193
|
-
|
|
240
|
+
const provided = new Set<string>();
|
|
241
|
+
for (const doc of docs) {
|
|
242
|
+
for (const entry of patchDocumentEntries(doc)) provided.add(entry.id);
|
|
243
|
+
}
|
|
244
|
+
return topLevelIds.filter((id) => !provided.has(id));
|
|
194
245
|
}
|
|
@@ -62,7 +62,7 @@ test('readEffectivePatchLines:单层读失败不阻塞另一层,失败如实
|
|
|
62
62
|
if (file === USER_PATCH_FILE) return [{ lineId: 'a', raw: { id: 'a' } }];
|
|
63
63
|
throw new Error('读取失败示例');
|
|
64
64
|
},
|
|
65
|
-
async applyPatchChanges() {},
|
|
65
|
+
async applyPatchChanges() { return { downgraded: [] } },
|
|
66
66
|
};
|
|
67
67
|
const read = await readEffectivePatchLines(patchFile, 'tauri');
|
|
68
68
|
assert.equal(read.lines.length, 1, '坏的那层不能拖垮好的一层');
|