@logictan/dsh-config-manager 0.1.60
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/LICENSE +21 -0
- package/README.md +105 -0
- package/cordis.patch.yml +21 -0
- package/lib/adapters/agent-instructions.d.ts +13 -0
- package/lib/adapters/agent-instructions.js +46 -0
- package/lib/adapters/agent-presets.d.ts +13 -0
- package/lib/adapters/agent-presets.js +14 -0
- package/lib/adapters/credentials.d.ts +37 -0
- package/lib/adapters/credentials.js +122 -0
- package/lib/adapters/file-collection.d.ts +15 -0
- package/lib/adapters/file-collection.js +127 -0
- package/lib/adapters/index.d.ts +57 -0
- package/lib/adapters/index.js +55 -0
- package/lib/adapters/link-report.d.ts +16 -0
- package/lib/adapters/link-report.js +47 -0
- package/lib/adapters/mcp.d.ts +28 -0
- package/lib/adapters/mcp.js +178 -0
- package/lib/adapters/plugin-files.d.ts +18 -0
- package/lib/adapters/plugin-files.js +142 -0
- package/lib/adapters/plugins.d.ts +41 -0
- package/lib/adapters/plugins.js +603 -0
- package/lib/adapters/pnpm-workspace.d.ts +26 -0
- package/lib/adapters/pnpm-workspace.js +147 -0
- package/lib/adapters/prompts.d.ts +30 -0
- package/lib/adapters/prompts.js +231 -0
- package/lib/adapters/providers.d.ts +34 -0
- package/lib/adapters/providers.js +155 -0
- package/lib/adapters/self.d.ts +17 -0
- package/lib/adapters/self.js +71 -0
- package/lib/adapters/sessions.d.ts +14 -0
- package/lib/adapters/sessions.js +15 -0
- package/lib/adapters/settings.d.ts +28 -0
- package/lib/adapters/settings.js +165 -0
- package/lib/adapters/skills.d.ts +13 -0
- package/lib/adapters/skills.js +14 -0
- package/lib/adapters/test-helpers.d.ts +125 -0
- package/lib/adapters/test-helpers.js +236 -0
- package/lib/adapters/ui.d.ts +27 -0
- package/lib/adapters/ui.js +89 -0
- package/lib/adapters/workspaces.d.ts +13 -0
- package/lib/adapters/workspaces.js +106 -0
- package/lib/client.d.ts +1026 -0
- package/lib/client.js +10047 -0
- package/lib/core/analyzer.d.ts +99 -0
- package/lib/core/analyzer.js +934 -0
- package/lib/core/backup.d.ts +138 -0
- package/lib/core/backup.js +513 -0
- package/lib/core/boot-rescue.d.ts +146 -0
- package/lib/core/boot-rescue.js +618 -0
- package/lib/core/cache-cleaner.d.ts +31 -0
- package/lib/core/cache-cleaner.js +95 -0
- package/lib/core/config-lifecycle.d.ts +180 -0
- package/lib/core/config-lifecycle.js +481 -0
- package/lib/core/config-snapshot.d.ts +135 -0
- package/lib/core/config-snapshot.js +424 -0
- package/lib/core/config-state.d.ts +70 -0
- package/lib/core/config-state.js +177 -0
- package/lib/core/consult-source.d.ts +58 -0
- package/lib/core/consult-source.js +260 -0
- package/lib/core/crash-report.d.ts +84 -0
- package/lib/core/crash-report.js +317 -0
- package/lib/core/exporter.d.ts +68 -0
- package/lib/core/exporter.js +375 -0
- package/lib/core/ghost-sweep.d.ts +19 -0
- package/lib/core/ghost-sweep.js +52 -0
- package/lib/core/importer.d.ts +60 -0
- package/lib/core/importer.js +29 -0
- package/lib/core/index.d.ts +14 -0
- package/lib/core/index.js +14 -0
- package/lib/core/journal.d.ts +197 -0
- package/lib/core/journal.js +418 -0
- package/lib/core/local-plugin-host.d.ts +35 -0
- package/lib/core/local-plugin-host.js +120 -0
- package/lib/core/local-plugin-pack.d.ts +135 -0
- package/lib/core/local-plugin-pack.js +278 -0
- package/lib/core/messages.d.ts +310 -0
- package/lib/core/messages.js +621 -0
- package/lib/core/migration-consult.d.ts +117 -0
- package/lib/core/migration-consult.js +363 -0
- package/lib/core/migration-history.d.ts +153 -0
- package/lib/core/migration-history.js +411 -0
- package/lib/core/model-tools.d.ts +50 -0
- package/lib/core/model-tools.js +148 -0
- package/lib/core/msg-types.d.ts +8 -0
- package/lib/core/msg-types.js +6 -0
- package/lib/core/phase3-child-crash.d.ts +1 -0
- package/lib/core/phase3-child-crash.js +87 -0
- package/lib/core/phase3-host.d.ts +138 -0
- package/lib/core/phase3-host.js +359 -0
- package/lib/core/phase3-prod-child.d.ts +1 -0
- package/lib/core/phase3-prod-child.js +35 -0
- package/lib/core/phase4-crash-child.d.ts +1 -0
- package/lib/core/phase4-crash-child.js +103 -0
- package/lib/core/plugin-cli.d.ts +150 -0
- package/lib/core/plugin-cli.js +497 -0
- package/lib/core/reconcile.d.ts +120 -0
- package/lib/core/reconcile.js +389 -0
- package/lib/core/recovery-orchestrator.d.ts +94 -0
- package/lib/core/recovery-orchestrator.js +327 -0
- package/lib/core/restore.d.ts +162 -0
- package/lib/core/restore.js +703 -0
- package/lib/core/rollback.d.ts +12 -0
- package/lib/core/rollback.js +145 -0
- package/lib/core/run-registry.d.ts +85 -0
- package/lib/core/run-registry.js +157 -0
- package/lib/core/startup-barrier.d.ts +53 -0
- package/lib/core/startup-barrier.js +77 -0
- package/lib/core/types.d.ts +515 -0
- package/lib/core/types.js +27 -0
- package/lib/core/undo.d.ts +73 -0
- package/lib/core/undo.js +87 -0
- package/lib/core/validator.d.ts +18 -0
- package/lib/core/validator.js +77 -0
- package/lib/core/verify-recovery.d.ts +21 -0
- package/lib/core/verify-recovery.js +256 -0
- package/lib/core/watcher.d.ts +101 -0
- package/lib/core/watcher.js +219 -0
- package/lib/index.d.ts +238 -0
- package/lib/index.js +2764 -0
- package/lib/migrations/index.d.ts +29 -0
- package/lib/migrations/index.js +56 -0
- package/lib/migrations/v1-to-v2.d.ts +9 -0
- package/lib/migrations/v1-to-v2.js +10 -0
- package/lib/profiles/index.d.ts +4 -0
- package/lib/profiles/index.js +5 -0
- package/lib/profiles/profile-manager.d.ts +106 -0
- package/lib/profiles/profile-manager.js +543 -0
- package/lib/schema/config.d.ts +28 -0
- package/lib/schema/config.js +165 -0
- package/lib/schema/index.d.ts +24 -0
- package/lib/schema/index.js +26 -0
- package/lib/schema/manifest.d.ts +28 -0
- package/lib/schema/manifest.js +109 -0
- package/lib/schema/tombstones.d.ts +46 -0
- package/lib/schema/tombstones.js +64 -0
- package/lib/schema/types.d.ts +232 -0
- package/lib/schema/types.js +8 -0
- package/lib/schema/versions.d.ts +27 -0
- package/lib/schema/versions.js +50 -0
- package/lib/security/encryption.d.ts +85 -0
- package/lib/security/encryption.js +279 -0
- package/lib/security/index.d.ts +16 -0
- package/lib/security/index.js +17 -0
- package/lib/security/integrity.d.ts +30 -0
- package/lib/security/integrity.js +78 -0
- package/lib/security/redaction.d.ts +26 -0
- package/lib/security/redaction.js +95 -0
- package/lib/security/secret-scanner.d.ts +86 -0
- package/lib/security/secret-scanner.js +404 -0
- package/lib/security/vault.d.ts +59 -0
- package/lib/security/vault.js +151 -0
- package/lib/security/zip-security.d.ts +27 -0
- package/lib/security/zip-security.js +154 -0
- package/lib/sync/autosync-config.d.ts +39 -0
- package/lib/sync/autosync-config.js +151 -0
- package/lib/sync/autosync-scheduler.d.ts +139 -0
- package/lib/sync/autosync-scheduler.js +564 -0
- package/lib/sync/fs.d.ts +18 -0
- package/lib/sync/fs.js +49 -0
- package/lib/sync/git/git-transport.d.ts +100 -0
- package/lib/sync/git/git-transport.js +437 -0
- package/lib/sync/github-auth.d.ts +131 -0
- package/lib/sync/github-auth.js +264 -0
- package/lib/sync/layout.d.ts +43 -0
- package/lib/sync/layout.js +203 -0
- package/lib/sync/snapshot-json.d.ts +9 -0
- package/lib/sync/snapshot-json.js +107 -0
- package/lib/sync/sync-config.d.ts +81 -0
- package/lib/sync/sync-config.js +281 -0
- package/lib/sync/sync-engine.d.ts +269 -0
- package/lib/sync/sync-engine.js +591 -0
- package/lib/sync/sync-history.d.ts +42 -0
- package/lib/sync/sync-history.js +78 -0
- package/lib/sync/sync-selection.d.ts +29 -0
- package/lib/sync/sync-selection.js +127 -0
- package/lib/sync/sync-session.d.ts +40 -0
- package/lib/sync/sync-session.js +54 -0
- package/lib/sync/sync-state.d.ts +37 -0
- package/lib/sync/sync-state.js +108 -0
- package/lib/sync/transport.d.ts +75 -0
- package/lib/sync/transport.js +55 -0
- package/lib/sync/ui-prefs.d.ts +34 -0
- package/lib/sync/ui-prefs.js +109 -0
- package/lib/sync/webdav/webdav-transport.d.ts +77 -0
- package/lib/sync/webdav/webdav-transport.js +451 -0
- package/lib/ui/errors.d.ts +19 -0
- package/lib/ui/errors.js +81 -0
- package/lib/ui/export-flow.d.ts +82 -0
- package/lib/ui/export-flow.js +98 -0
- package/lib/ui/i18n.d.ts +289 -0
- package/lib/ui/i18n.js +581 -0
- package/lib/ui/migration-consult-view.d.ts +91 -0
- package/lib/ui/migration-consult-view.js +115 -0
- package/lib/ui/progress.d.ts +38 -0
- package/lib/ui/progress.js +87 -0
- package/lib/ui/report.d.ts +23 -0
- package/lib/ui/report.js +153 -0
- package/lib/ui/test-helpers.d.ts +69 -0
- package/lib/ui/test-helpers.js +154 -0
- package/lib/ui/types.d.ts +257 -0
- package/lib/ui/types.js +21 -0
- package/lib/utils/atomic-write.d.ts +88 -0
- package/lib/utils/atomic-write.js +399 -0
- package/lib/utils/env-lock.d.ts +393 -0
- package/lib/utils/env-lock.js +930 -0
- package/lib/utils/hashing.d.ts +17 -0
- package/lib/utils/hashing.js +41 -0
- package/lib/utils/json.d.ts +24 -0
- package/lib/utils/json.js +76 -0
- package/lib/utils/logger.d.ts +39 -0
- package/lib/utils/logger.js +82 -0
- package/lib/utils/paths.d.ts +42 -0
- package/lib/utils/paths.js +189 -0
- package/lib/utils/proxy.d.ts +69 -0
- package/lib/utils/proxy.js +455 -0
- package/lib/utils/recursive-walk.d.ts +24 -0
- package/lib/utils/recursive-walk.js +134 -0
- package/lib/utils/zip.d.ts +54 -0
- package/lib/utils/zip.js +285 -0
- package/package.json +188 -0
- package/src/adapters/agent-instructions.ts +48 -0
- package/src/adapters/agent-presets.ts +14 -0
- package/src/adapters/credentials.test.ts +90 -0
- package/src/adapters/credentials.ts +143 -0
- package/src/adapters/file-collection.ts +137 -0
- package/src/adapters/files.test.ts +353 -0
- package/src/adapters/index.ts +94 -0
- package/src/adapters/link-report.test.ts +65 -0
- package/src/adapters/link-report.ts +61 -0
- package/src/adapters/mcp.test.ts +96 -0
- package/src/adapters/mcp.ts +185 -0
- package/src/adapters/plugin-files.ts +146 -0
- package/src/adapters/plugins.test.ts +326 -0
- package/src/adapters/plugins.ts +615 -0
- package/src/adapters/pnpm-workspace.test.ts +87 -0
- package/src/adapters/pnpm-workspace.ts +150 -0
- package/src/adapters/prompts.test.ts +110 -0
- package/src/adapters/prompts.ts +230 -0
- package/src/adapters/providers.test.ts +126 -0
- package/src/adapters/providers.ts +173 -0
- package/src/adapters/roundtrip.test.ts +190 -0
- package/src/adapters/self.test.ts +92 -0
- package/src/adapters/self.ts +75 -0
- package/src/adapters/sessions.ts +15 -0
- package/src/adapters/settings.test.ts +100 -0
- package/src/adapters/settings.ts +187 -0
- package/src/adapters/skills.ts +14 -0
- package/src/adapters/test-helpers.ts +248 -0
- package/src/adapters/ui.test.ts +57 -0
- package/src/adapters/ui.ts +108 -0
- package/src/adapters/workspaces.test.ts +106 -0
- package/src/adapters/workspaces.ts +109 -0
- package/src/client/ConfigManagerSection.tsx +90 -0
- package/src/client/api.ts +66 -0
- package/src/client/client-types.ts +18 -0
- package/src/client/common/ErrorBanner.tsx +73 -0
- package/src/client/common/Icon.tsx +129 -0
- package/src/client/common/Modal.tsx +173 -0
- package/src/client/common/ToastViewport.tsx +73 -0
- package/src/client/common/toast-store.test.ts +192 -0
- package/src/client/common/toast-store.ts +181 -0
- package/src/client/common/toast-types.ts +7 -0
- package/src/client/common/ui.tsx +342 -0
- package/src/client/config-manager.module.css +2971 -0
- package/src/client/css-modules.d.ts +8 -0
- package/src/client/index.ts +65 -0
- package/src/client/locales.ts +56 -0
- package/src/client/lucide-icons.d.ts +38 -0
- package/src/client/run-store.test.ts +223 -0
- package/src/client/run-store.ts +372 -0
- package/src/client/sync/SyncConfirmView.tsx +379 -0
- package/src/client/sync/SyncHistoryView.test.ts +40 -0
- package/src/client/sync/SyncHistoryView.tsx +220 -0
- package/src/client/sync/SyncSettingsView.tsx +1535 -0
- package/src/client/sync/history-model.test.ts +194 -0
- package/src/client/sync/history-model.ts +195 -0
- package/src/client/sync/sync-api.test.ts +585 -0
- package/src/client/sync/sync-api.ts +543 -0
- package/src/client/sync/sync-locales.ts +416 -0
- package/src/client/sync/sync-push-preview.test.ts +52 -0
- package/src/client/sync/sync-view-v2.test.ts +213 -0
- package/src/client/sync/sync-view.test.ts +487 -0
- package/src/client/sync/sync-view.ts +759 -0
- package/src/core/analyzer.ts +1068 -0
- package/src/core/backup.ts +605 -0
- package/src/core/boot-rescue.test.ts +847 -0
- package/src/core/boot-rescue.ts +737 -0
- package/src/core/cache-cleaner.test.ts +169 -0
- package/src/core/cache-cleaner.ts +121 -0
- package/src/core/config-lifecycle.test.ts +727 -0
- package/src/core/config-lifecycle.ts +573 -0
- package/src/core/config-snapshot.test.ts +369 -0
- package/src/core/config-snapshot.ts +522 -0
- package/src/core/config-state.test.ts +381 -0
- package/src/core/config-state.ts +207 -0
- package/src/core/consult-source.test.ts +199 -0
- package/src/core/consult-source.ts +293 -0
- package/src/core/crash-report.test.ts +380 -0
- package/src/core/crash-report.ts +369 -0
- package/src/core/exporter.ts +417 -0
- package/src/core/ghost-sweep.test.ts +94 -0
- package/src/core/ghost-sweep.ts +67 -0
- package/src/core/importer.ts +83 -0
- package/src/core/index.ts +56 -0
- package/src/core/journal.test.ts +257 -0
- package/src/core/journal.ts +518 -0
- package/src/core/local-plugin-host.ts +152 -0
- package/src/core/local-plugin-pack.test.ts +359 -0
- package/src/core/local-plugin-pack.ts +363 -0
- package/src/core/messages.test.ts +54 -0
- package/src/core/messages.ts +664 -0
- package/src/core/migration-consult.test.ts +315 -0
- package/src/core/migration-consult.ts +494 -0
- package/src/core/migration-history.test.ts +319 -0
- package/src/core/migration-history.ts +484 -0
- package/src/core/model-tools.test.ts +190 -0
- package/src/core/model-tools.ts +208 -0
- package/src/core/msg-types.ts +10 -0
- package/src/core/phase3-child-crash.ts +95 -0
- package/src/core/phase3-host.ts +411 -0
- package/src/core/phase3-p1.test.ts +212 -0
- package/src/core/phase3-p2b-fingerprint.test.ts +189 -0
- package/src/core/phase3-prod-child.ts +36 -0
- package/src/core/phase3-production-integration.test.ts +286 -0
- package/src/core/phase4-crash-child.ts +101 -0
- package/src/core/phase4-crash-injection.test.ts +166 -0
- package/src/core/plugin-cli.fs.test.ts +184 -0
- package/src/core/plugin-cli.test.ts +137 -0
- package/src/core/plugin-cli.ts +563 -0
- package/src/core/reconcile.test.ts +392 -0
- package/src/core/reconcile.ts +498 -0
- package/src/core/recovery-orchestrator.test.ts +145 -0
- package/src/core/recovery-orchestrator.ts +366 -0
- package/src/core/restore-manage.test.ts +94 -0
- package/src/core/restore.ts +849 -0
- package/src/core/rollback.ts +151 -0
- package/src/core/run-progress.test.ts +237 -0
- package/src/core/run-registry.test.ts +232 -0
- package/src/core/run-registry.ts +209 -0
- package/src/core/smoke.test.ts +842 -0
- package/src/core/startup-barrier.ts +99 -0
- package/src/core/types.ts +542 -0
- package/src/core/undo.ts +116 -0
- package/src/core/validator.ts +84 -0
- package/src/core/verify-recovery.ts +265 -0
- package/src/core/watcher.test.ts +326 -0
- package/src/core/watcher.ts +263 -0
- package/src/index.facade.test.ts +265 -0
- package/src/index.sync.test.ts +217 -0
- package/src/index.ts +2975 -0
- package/src/migrations/index.ts +71 -0
- package/src/migrations/v1-to-v2.ts +17 -0
- package/src/profiles/index.ts +8 -0
- package/src/profiles/profile-manager.test.ts +282 -0
- package/src/profiles/profile-manager.ts +630 -0
- package/src/schema/config.ts +165 -0
- package/src/schema/index.ts +71 -0
- package/src/schema/manifest-schema.test.ts +519 -0
- package/src/schema/manifest.ts +124 -0
- package/src/schema/tombstones.test.ts +131 -0
- package/src/schema/tombstones.ts +89 -0
- package/src/schema/types.ts +245 -0
- package/src/schema/versions.ts +55 -0
- package/src/security/encryption.ts +335 -0
- package/src/security/index.ts +16 -0
- package/src/security/integrity.ts +102 -0
- package/src/security/redaction.ts +101 -0
- package/src/security/secret-scanner.ts +445 -0
- package/src/security/security.test.ts +1215 -0
- package/src/security/vault.test.ts +164 -0
- package/src/security/vault.ts +198 -0
- package/src/security/zip-security.ts +180 -0
- package/src/sync/autosync-config.test.ts +147 -0
- package/src/sync/autosync-config.ts +179 -0
- package/src/sync/autosync-scheduler.test.ts +490 -0
- package/src/sync/autosync-scheduler.ts +646 -0
- package/src/sync/fs.ts +48 -0
- package/src/sync/git/git-transport.test.ts +673 -0
- package/src/sync/git/git-transport.ts +491 -0
- package/src/sync/github-auth.test.ts +280 -0
- package/src/sync/github-auth.ts +356 -0
- package/src/sync/layout.test.ts +270 -0
- package/src/sync/layout.ts +222 -0
- package/src/sync/snapshot-json.test.ts +119 -0
- package/src/sync/snapshot-json.ts +128 -0
- package/src/sync/sync-config.test.ts +310 -0
- package/src/sync/sync-config.ts +299 -0
- package/src/sync/sync-engine.test.ts +1074 -0
- package/src/sync/sync-engine.ts +754 -0
- package/src/sync/sync-history.test.ts +116 -0
- package/src/sync/sync-history.ts +120 -0
- package/src/sync/sync-selection.test.ts +186 -0
- package/src/sync/sync-selection.ts +143 -0
- package/src/sync/sync-session.test.ts +143 -0
- package/src/sync/sync-session.ts +77 -0
- package/src/sync/sync-state.test.ts +164 -0
- package/src/sync/sync-state.ts +131 -0
- package/src/sync/transport.test.ts +111 -0
- package/src/sync/transport.ts +118 -0
- package/src/sync/ui-prefs.test.ts +152 -0
- package/src/sync/ui-prefs.ts +135 -0
- package/src/sync/webdav/webdav-transport.test.ts +871 -0
- package/src/sync/webdav/webdav-transport.ts +535 -0
- package/src/ui/errors.test.ts +47 -0
- package/src/ui/errors.ts +100 -0
- package/src/ui/export-flow.test.ts +87 -0
- package/src/ui/export-flow.ts +156 -0
- package/src/ui/i18n.ts +590 -0
- package/src/ui/migration-consult-view.test.ts +151 -0
- package/src/ui/migration-consult-view.ts +178 -0
- package/src/ui/progress.test.ts +47 -0
- package/src/ui/progress.ts +102 -0
- package/src/ui/report.test.ts +101 -0
- package/src/ui/report.ts +146 -0
- package/src/ui/test-helpers.ts +184 -0
- package/src/ui/types.ts +325 -0
- package/src/utils/atomic-write.test.ts +312 -0
- package/src/utils/atomic-write.ts +422 -0
- package/src/utils/env-lock.test.ts +999 -0
- package/src/utils/env-lock.ts +1086 -0
- package/src/utils/hashing.ts +53 -0
- package/src/utils/json.ts +77 -0
- package/src/utils/logger.ts +114 -0
- package/src/utils/paths.ts +176 -0
- package/src/utils/proxy.test.ts +465 -0
- package/src/utils/proxy.ts +493 -0
- package/src/utils/recursive-walk.test.ts +148 -0
- package/src/utils/recursive-walk.ts +145 -0
- package/src/utils/zip.ts +332 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 迁移前咨询 UI 纯渲染模型(Phase 7)单测。
|
|
3
|
+
*/
|
|
4
|
+
import { test } from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import { makeUiT } from './i18n.ts';
|
|
7
|
+
import {
|
|
8
|
+
consultView, consultVerdictBadgeKind, consultRecommendationBadgeKind,
|
|
9
|
+
consultDimensionLabel, consultRecommendationLabel,
|
|
10
|
+
dedupeConsultReasons, consultReasonGroups,
|
|
11
|
+
} from './migration-consult-view.ts';
|
|
12
|
+
import type { ConsultReport } from '../core/migration-consult.ts';
|
|
13
|
+
|
|
14
|
+
const t = makeUiT('zh');
|
|
15
|
+
|
|
16
|
+
function makeReport(over: Partial<ConsultReport> = {}): ConsultReport {
|
|
17
|
+
return {
|
|
18
|
+
source: { type: 'export-zip', id: '/tmp/x.zip' },
|
|
19
|
+
healthScore: 100,
|
|
20
|
+
verdict: 'healthy',
|
|
21
|
+
recommendation: 'proceed',
|
|
22
|
+
recommendationReasons: [],
|
|
23
|
+
dimensions: [
|
|
24
|
+
{ id: 'compatibility', score: 100, verdict: 'healthy', issues: [] },
|
|
25
|
+
{ id: 'integrity', score: 100, verdict: 'healthy', issues: [] },
|
|
26
|
+
{ id: 'sections', score: 100, verdict: 'healthy', issues: [] },
|
|
27
|
+
{ id: 'consistency', score: 100, verdict: 'healthy', issues: [] },
|
|
28
|
+
{ id: 'sensitive', score: 100, verdict: 'healthy', issues: [] },
|
|
29
|
+
{ id: 'migratability', score: 100, verdict: 'healthy', issues: [] },
|
|
30
|
+
],
|
|
31
|
+
willApply: { sections: ['settings'], itemCount: 3, conflicts: 0, risks: 0, overwritten: 0, dryRun: true },
|
|
32
|
+
bound: { sourceId: '/tmp/x.zip' },
|
|
33
|
+
generatedAt: '2026-08-25T00:00:00.000Z',
|
|
34
|
+
...over,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test('consult-view: 健康报告 → 视图数据完整', () => {
|
|
39
|
+
const view = consultView(makeReport(), t);
|
|
40
|
+
assert.equal(view.healthScore, 100);
|
|
41
|
+
assert.equal(view.verdict, 'healthy');
|
|
42
|
+
assert.equal(view.verdictBadgeKind, 'ok');
|
|
43
|
+
assert.equal(view.recommendation, 'proceed');
|
|
44
|
+
assert.equal(view.recommendationBadgeKind, 'ok');
|
|
45
|
+
assert.equal(view.dimensions.length, 6);
|
|
46
|
+
assert.equal(view.willApply.itemCount, 3);
|
|
47
|
+
assert.equal(view.willApply.dryRun, true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('consult-view: critical + block → 视图反映', () => {
|
|
51
|
+
const report = makeReport({
|
|
52
|
+
healthScore: 40,
|
|
53
|
+
verdict: 'critical',
|
|
54
|
+
recommendation: 'block',
|
|
55
|
+
recommendationReasons: ['不受支持:schema 超出范围'],
|
|
56
|
+
dimensions: [
|
|
57
|
+
{ id: 'compatibility', score: 0, verdict: 'critical', issues: [{ severity: 'error', code: 'x', message: '不受支持' }] },
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
const view = consultView(report, t);
|
|
61
|
+
assert.equal(view.verdictBadgeKind, 'error');
|
|
62
|
+
assert.equal(view.recommendationBadgeKind, 'error');
|
|
63
|
+
assert.equal(view.recommendationLabel, '建议:阻止执行');
|
|
64
|
+
assert.equal(view.reasons.length, 1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('consult-view: 维度 label 映射', () => {
|
|
68
|
+
assert.equal(consultDimensionLabel('compatibility', t), '版本/平台兼容性');
|
|
69
|
+
assert.equal(consultDimensionLabel('integrity', t), '结构完整性');
|
|
70
|
+
assert.equal(consultDimensionLabel('sensitive', t), '敏感暴露');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('consult-view: verdict/recommendation badge kind 映射', () => {
|
|
74
|
+
assert.equal(consultVerdictBadgeKind('healthy'), 'ok');
|
|
75
|
+
assert.equal(consultVerdictBadgeKind('needs-attention'), 'warn');
|
|
76
|
+
assert.equal(consultVerdictBadgeKind('critical'), 'error');
|
|
77
|
+
assert.equal(consultRecommendationBadgeKind('proceed'), 'ok');
|
|
78
|
+
assert.equal(consultRecommendationBadgeKind('review'), 'warn');
|
|
79
|
+
assert.equal(consultRecommendationBadgeKind('block'), 'error');
|
|
80
|
+
assert.equal(consultRecommendationLabel('proceed', t), '建议:可继续');
|
|
81
|
+
assert.equal(consultRecommendationLabel('review', t), '建议:需人工确认');
|
|
82
|
+
assert.equal(consultRecommendationLabel('block', t), '建议:阻止执行');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/* ---------------- 建议依据:去重与分组 ---------------- */
|
|
86
|
+
|
|
87
|
+
test('consult-reasons: dedupeConsultReasons 原文去重 + 保持首现顺序 + 丢弃空串/纯空白', () => {
|
|
88
|
+
const input = ['B', 'A', 'B', '', ' ', 'A', '\t', 'C'];
|
|
89
|
+
assert.deepEqual(dedupeConsultReasons(input), ['B', 'A', 'C']);
|
|
90
|
+
// 纯函数:不修改入参
|
|
91
|
+
assert.deepEqual(input, ['B', 'A', 'B', '', ' ', 'A', '\t', 'C']);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('consult-reasons: dedupeConsultReasons 不做 trim 合并(前后空格视为不同条目)', () => {
|
|
95
|
+
// 规则 1 明确:只按原文去重,'A' / ' A' / 'A ' 是三个不同条目
|
|
96
|
+
assert.deepEqual(dedupeConsultReasons(['A', ' A', 'A ', 'A']), ['A', ' A', 'A ']);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('consult-reasons: 空数组 / 全空白 → 空结果', () => {
|
|
100
|
+
assert.deepEqual(dedupeConsultReasons([]), []);
|
|
101
|
+
assert.deepEqual(dedupeConsultReasons(['', ' ', '\n']), []);
|
|
102
|
+
assert.deepEqual(consultReasonGroups([]), []);
|
|
103
|
+
assert.deepEqual(consultReasonGroups(['', ' ']), []);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('consult-reasons: consultReasonGroups 计数取原始数组,顺序 = 首次出现顺序', () => {
|
|
107
|
+
assert.deepEqual(consultReasonGroups(['B', 'A', 'B', 'C', 'B', 'A']), [
|
|
108
|
+
{ message: 'B', count: 3 },
|
|
109
|
+
{ message: 'A', count: 2 },
|
|
110
|
+
{ message: 'C', count: 1 },
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('consult-reasons: 真实场景 — 迁移项重复 3 次 + 敏感暴露重复 2 次', () => {
|
|
115
|
+
const reasons = [
|
|
116
|
+
'存在需注意的迁移项',
|
|
117
|
+
'存在需注意的迁移项',
|
|
118
|
+
'存在需注意的迁移项',
|
|
119
|
+
'检测到 2 处敏感字段暴露(已脱敏)',
|
|
120
|
+
'检测到 2 处敏感字段暴露(已脱敏)',
|
|
121
|
+
];
|
|
122
|
+
const groups = consultReasonGroups(reasons);
|
|
123
|
+
assert.equal(groups.length, 2);
|
|
124
|
+
assert.deepEqual(groups[0], { message: '存在需注意的迁移项', count: 3 });
|
|
125
|
+
assert.deepEqual(groups[1], { message: '检测到 2 处敏感字段暴露(已脱敏)', count: 2 });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('consult-reasons: 需求验收样例 → 2 组且第一组 count=2', () => {
|
|
129
|
+
const groups = consultReasonGroups([
|
|
130
|
+
'存在需注意的迁移项',
|
|
131
|
+
'存在需注意的迁移项',
|
|
132
|
+
'检测到 2 处敏感字段暴露(已脱敏)',
|
|
133
|
+
]);
|
|
134
|
+
assert.equal(groups.length, 2);
|
|
135
|
+
assert.equal(groups[0]?.count, 2);
|
|
136
|
+
assert.equal(groups[1]?.count, 1);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('consult-reasons: 与 consultView 串联(reasons 字段语义保持不变)', () => {
|
|
140
|
+
const view = consultView(makeReport({
|
|
141
|
+
verdict: 'needs-attention',
|
|
142
|
+
recommendation: 'review',
|
|
143
|
+
recommendationReasons: ['x', 'x', 'y'],
|
|
144
|
+
}), t);
|
|
145
|
+
// 既有字段语义不变:仍返回原始数组(含重复)
|
|
146
|
+
assert.deepEqual(view.reasons, ['x', 'x', 'y']);
|
|
147
|
+
assert.deepEqual(consultReasonGroups(view.reasons), [
|
|
148
|
+
{ message: 'x', count: 2 },
|
|
149
|
+
{ message: 'y', count: 1 },
|
|
150
|
+
]);
|
|
151
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 迁移前咨询的纯渲染模型(Phase 7,m6-ui)。
|
|
3
|
+
*
|
|
4
|
+
* 把 core 的 ConsultReport 转成 React 可直接绑定的视图数据:
|
|
5
|
+
* - 健康评分徽章(verdict → Badge kind)
|
|
6
|
+
* - 维度明细(每维度:label / score / verdict / issues)
|
|
7
|
+
* - 建议(proceed / review / block + 触发项)
|
|
8
|
+
* - 将应用摘要(willApply)
|
|
9
|
+
*
|
|
10
|
+
* 安全:所有展示文本渲染前由 UI 层 redact() 兜底;本模型只做结构转换,不引入敏感值。
|
|
11
|
+
* 文案走 UiT(zh 源 / en 镜像,见 src/ui/i18n.ts)。
|
|
12
|
+
*/
|
|
13
|
+
import type { UiT } from './i18n.ts';
|
|
14
|
+
import type {
|
|
15
|
+
ConsultReport, ConsultDimensionId, HealthVerdict, Recommendation,
|
|
16
|
+
} from '../core/migration-consult.ts';
|
|
17
|
+
|
|
18
|
+
/** Badge kind(与 DESIGN.md 四态语义一一对应) */
|
|
19
|
+
export type ConsultBadgeKind = 'ok' | 'info' | 'warn' | 'error';
|
|
20
|
+
|
|
21
|
+
/** 维度视图数据 */
|
|
22
|
+
export interface ConsultDimensionView {
|
|
23
|
+
id: ConsultDimensionId;
|
|
24
|
+
label: string;
|
|
25
|
+
score: number;
|
|
26
|
+
verdict: HealthVerdict;
|
|
27
|
+
badgeKind: ConsultBadgeKind;
|
|
28
|
+
issues: { severity: 'info' | 'warning' | 'error'; message: string }[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 咨询卡视图数据 */
|
|
32
|
+
export interface ConsultView {
|
|
33
|
+
healthScore: number;
|
|
34
|
+
verdict: HealthVerdict;
|
|
35
|
+
verdictBadgeKind: ConsultBadgeKind;
|
|
36
|
+
recommendation: Recommendation;
|
|
37
|
+
recommendationBadgeKind: ConsultBadgeKind;
|
|
38
|
+
recommendationLabel: string;
|
|
39
|
+
reasons: string[];
|
|
40
|
+
dimensions: ConsultDimensionView[];
|
|
41
|
+
willApply: {
|
|
42
|
+
sections: string[];
|
|
43
|
+
itemCount: number;
|
|
44
|
+
conflicts: number;
|
|
45
|
+
risks: number;
|
|
46
|
+
overwritten: number;
|
|
47
|
+
dryRun: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* ---------------- 建议依据(reasons)去重与分组 ---------------- */
|
|
52
|
+
|
|
53
|
+
/** 建议依据分组条目(去重后的 message + 在原始数组中的出现次数) */
|
|
54
|
+
export interface ConsultReasonGroup {
|
|
55
|
+
message: string;
|
|
56
|
+
/** 该 message 在原始 reasons 数组中的出现次数(≥1;仅用于 UI 展示「×N」) */
|
|
57
|
+
count: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 「建议依据」去重(纯函数)。
|
|
62
|
+
*
|
|
63
|
+
* 背景:core 的 `recommendationReasons` 是各维度 error/warning issue message 的
|
|
64
|
+
* 直接拼接,同一句话可能被 push 多次(如 migratability 维度按 `m.warnings` 逐条 push
|
|
65
|
+
* 「存在需注意的迁移项」),同一句也可能既出现在维度 issue 又出现在 reasons 中。
|
|
66
|
+
*
|
|
67
|
+
* 去重规则(严格按此实现,勿擅自放宽):
|
|
68
|
+
* 1. **按原文去重**:只有完全相同的字符串才算重复——不做 trim 后合并、不做大小写
|
|
69
|
+
* 折叠、不做前缀/子串归并。因此 `'A'`、`' A'`、`'A '` 是三个不同条目。
|
|
70
|
+
* 2. **保持首次出现顺序**:稳定去重,输出顺序 = 各条目在输入中首次出现的顺序。
|
|
71
|
+
* 3. **丢弃空串与纯空白字符串**(`trim() === ''`),它们不参与展示。
|
|
72
|
+
*
|
|
73
|
+
* 不修改入参,返回新数组。
|
|
74
|
+
*/
|
|
75
|
+
export function dedupeConsultReasons(reasons: string[]): string[] {
|
|
76
|
+
const seen = new Set<string>();
|
|
77
|
+
const out: string[] = [];
|
|
78
|
+
for (const reason of reasons) {
|
|
79
|
+
if (reason.trim() === '') continue; // 空串/纯空白:直接丢弃
|
|
80
|
+
if (seen.has(reason)) continue; // 原文去重:仅完全相同才视为重复
|
|
81
|
+
seen.add(reason);
|
|
82
|
+
out.push(reason);
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 「建议依据」分组(纯函数):去重后给出每个条目的重复次数,供 UI 渲染「×N」。
|
|
89
|
+
*
|
|
90
|
+
* 规则:
|
|
91
|
+
* 1. 先经 `dedupeConsultReasons` 去重(原文去重、丢弃空串/纯空白、保持首现顺序);
|
|
92
|
+
* 2. `count` = 该 message 在**原始数组**(未去重)中的出现次数,按原文精确匹配统计,
|
|
93
|
+
* 因此 count ≥ 1;count 仅用于展示「×N」,不代表任何业务优先级或权重;
|
|
94
|
+
* 3. 输出顺序 = 去重后的顺序(即各条目首次出现的顺序)。
|
|
95
|
+
*
|
|
96
|
+
* 不修改入参,返回新数组。
|
|
97
|
+
*/
|
|
98
|
+
export function consultReasonGroups(reasons: string[]): ConsultReasonGroup[] {
|
|
99
|
+
const counts = new Map<string, number>();
|
|
100
|
+
for (const reason of reasons) {
|
|
101
|
+
counts.set(reason, (counts.get(reason) ?? 0) + 1);
|
|
102
|
+
}
|
|
103
|
+
return dedupeConsultReasons(reasons).map((message) => ({
|
|
104
|
+
message,
|
|
105
|
+
// 去重结果必来自入参,故此处理论上不会取到兜底值
|
|
106
|
+
count: counts.get(message) ?? 0,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** verdict → Badge kind(语义映射) */
|
|
111
|
+
export function consultVerdictBadgeKind(v: HealthVerdict): ConsultBadgeKind {
|
|
112
|
+
switch (v) {
|
|
113
|
+
case 'healthy': return 'ok';
|
|
114
|
+
case 'needs-attention': return 'warn';
|
|
115
|
+
case 'critical': return 'error';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** recommendation → Badge kind */
|
|
120
|
+
export function consultRecommendationBadgeKind(r: Recommendation): ConsultBadgeKind {
|
|
121
|
+
switch (r) {
|
|
122
|
+
case 'proceed': return 'ok';
|
|
123
|
+
case 'review': return 'warn';
|
|
124
|
+
case 'block': return 'error';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 维度 label(i18n key 后缀) */
|
|
129
|
+
export function consultDimensionLabel(id: ConsultDimensionId, t: UiT): string {
|
|
130
|
+
switch (id) {
|
|
131
|
+
case 'compatibility': return t('consult.dim.compatibility');
|
|
132
|
+
case 'integrity': return t('consult.dim.integrity');
|
|
133
|
+
case 'sections': return t('consult.dim.sections');
|
|
134
|
+
case 'consistency': return t('consult.dim.consistency');
|
|
135
|
+
case 'sensitive': return t('consult.dim.sensitive');
|
|
136
|
+
case 'migratability': return t('consult.dim.migratability');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** 把 ConsultReport 转成视图数据(纯函数) */
|
|
141
|
+
export function consultView(report: ConsultReport, t: UiT): ConsultView {
|
|
142
|
+
const dimensions: ConsultDimensionView[] = report.dimensions.map((d) => ({
|
|
143
|
+
id: d.id,
|
|
144
|
+
label: consultDimensionLabel(d.id, t),
|
|
145
|
+
score: d.score,
|
|
146
|
+
verdict: d.verdict,
|
|
147
|
+
badgeKind: consultVerdictBadgeKind(d.verdict),
|
|
148
|
+
issues: d.issues.map((i) => ({ severity: i.severity, message: i.message })),
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
healthScore: report.healthScore,
|
|
153
|
+
verdict: report.verdict,
|
|
154
|
+
verdictBadgeKind: consultVerdictBadgeKind(report.verdict),
|
|
155
|
+
recommendation: report.recommendation,
|
|
156
|
+
recommendationBadgeKind: consultRecommendationBadgeKind(report.recommendation),
|
|
157
|
+
recommendationLabel: consultRecommendationLabel(report.recommendation, t),
|
|
158
|
+
reasons: report.recommendationReasons,
|
|
159
|
+
dimensions,
|
|
160
|
+
willApply: {
|
|
161
|
+
sections: report.willApply.sections,
|
|
162
|
+
itemCount: report.willApply.itemCount,
|
|
163
|
+
conflicts: report.willApply.conflicts,
|
|
164
|
+
risks: report.willApply.risks,
|
|
165
|
+
overwritten: report.willApply.overwritten,
|
|
166
|
+
dryRun: report.willApply.dryRun,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** recommendation 的可读标签 */
|
|
172
|
+
export function consultRecommendationLabel(r: Recommendation, t: UiT): string {
|
|
173
|
+
switch (r) {
|
|
174
|
+
case 'proceed': return t('consult.recommendation.proceed');
|
|
175
|
+
case 'review': return t('consult.recommendation.review');
|
|
176
|
+
case 'block': return t('consult.recommendation.block');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* progress 测试(m6-ui,规范 §29):阶段文案与进度追踪。
|
|
3
|
+
*/
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import { EXPORT_STAGES, IMPORT_STAGES, ProgressTracker, stageText } from './progress.ts';
|
|
7
|
+
import { makeUiT } from './i18n.ts';
|
|
8
|
+
|
|
9
|
+
const enT = makeUiT('en');
|
|
10
|
+
const zhT = makeUiT('zh');
|
|
11
|
+
|
|
12
|
+
test('progress: 阶段文案映射(导出/导入/回滚,en / zh)', () => {
|
|
13
|
+
assert.equal(stageText('analyzing', enT), 'Analyzing configuration...');
|
|
14
|
+
assert.equal(stageText('creating-snapshot', enT), 'Creating safety snapshot...');
|
|
15
|
+
assert.equal(stageText('rolling-back', enT), 'Rolling back...');
|
|
16
|
+
assert.equal(stageText('restoring-mcp', enT), 'Restoring MCP...');
|
|
17
|
+
assert.equal(stageText('done', enT), 'Done');
|
|
18
|
+
assert.equal(stageText('analyzing', zhT), '正在分析配置…');
|
|
19
|
+
// 未知阶段回退 id
|
|
20
|
+
assert.equal(stageText('unknown-phase', enT), 'unknown-phase');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('progress: 导出阶段序列完整', () => {
|
|
24
|
+
assert.deepEqual(EXPORT_STAGES, [
|
|
25
|
+
'analyzing', 'exporting-settings', 'scanning-secrets', 'exporting-plugins',
|
|
26
|
+
'creating-archive', 'calculating-checksums', 'done',
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('progress: 导入阶段序列含快照/回滚', () => {
|
|
31
|
+
assert.ok(IMPORT_STAGES.includes('creating-snapshot'));
|
|
32
|
+
assert.ok(IMPORT_STAGES.includes('rolling-back'));
|
|
33
|
+
assert.ok(IMPORT_STAGES.includes('restoring-settings'));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('progress: tracker 发出事件并带 step/total', () => {
|
|
37
|
+
const events: { stage: string; step?: number; total?: number }[] = [];
|
|
38
|
+
const t = new ProgressTracker(IMPORT_STAGES, (e) => events.push(e));
|
|
39
|
+
t.emit('validating');
|
|
40
|
+
t.emit('creating-snapshot');
|
|
41
|
+
t.emit('done');
|
|
42
|
+
assert.deepEqual(t.events, ['validating', 'creating-snapshot', 'done']);
|
|
43
|
+
assert.equal(events[0]!.step, 1);
|
|
44
|
+
assert.equal(events[0]!.total, IMPORT_STAGES.length);
|
|
45
|
+
assert.equal(events[1]!.step, 3);
|
|
46
|
+
assert.equal(events[2]!.step, IMPORT_STAGES.length);
|
|
47
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 进度阶段文案与进度追踪(规范 §29,m6-ui)。
|
|
3
|
+
*
|
|
4
|
+
* 纯文本层:每个阶段 id 有默认文案;未知阶段回退显示 id 本身。
|
|
5
|
+
* ProgressTracker 供导出/导入控制器在调用 core 前后发出阶段事件(UI 不冻结)。
|
|
6
|
+
*/
|
|
7
|
+
import type { ProgressEvent, ProgressListener } from './types.ts';
|
|
8
|
+
import { zhUiT, type UiT, type UiTextKey } from './i18n.ts';
|
|
9
|
+
|
|
10
|
+
/** 导出阶段文案(规范 §29 Export 示例) */
|
|
11
|
+
export const EXPORT_STAGES: readonly string[] = [
|
|
12
|
+
'analyzing', // Analyzing configuration...
|
|
13
|
+
'exporting-settings', // Exporting settings...
|
|
14
|
+
'scanning-secrets', // Scanning secrets...
|
|
15
|
+
'exporting-plugins', // Exporting plugins...
|
|
16
|
+
'creating-archive', // Creating archive...
|
|
17
|
+
'calculating-checksums', // Calculating checksums...
|
|
18
|
+
'done',
|
|
19
|
+
] as const;
|
|
20
|
+
|
|
21
|
+
/** 导入阶段文案(规范 §29 Import 示例 + 快照/回滚阶段) */
|
|
22
|
+
export const IMPORT_STAGES: readonly string[] = [
|
|
23
|
+
'validating', // Validating backup...
|
|
24
|
+
'checking-compatibility', // Checking compatibility...
|
|
25
|
+
'creating-snapshot', // Creating safety snapshot...
|
|
26
|
+
'restoring-settings', // Restoring settings...
|
|
27
|
+
'restoring-plugins', // Restoring plugins...
|
|
28
|
+
'restoring-mcp', // Restoring MCP...
|
|
29
|
+
'validating-config', // Validating configuration...
|
|
30
|
+
'rolling-back', // Rolling back...(仅失败回滚时)
|
|
31
|
+
'done',
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 真实执行阶段(不在 IMPORT_STAGES 序列里,因此 step/total 缺省 → 进度条渲染
|
|
36
|
+
* 为不定态动画而非伪造百分比)。execute 是一个单次 HTTP 请求,Host 端串行
|
|
37
|
+
* 跑完全部计划项(其中插件安装是 npm 串行,耗时最长);请求期间没有中间
|
|
38
|
+
* 进度事件可回传,旧实现把 restoring-settings / restoring-plugins /
|
|
39
|
+
* restoring-mcp / validating-config 在请求前全部预发,导致进度条瞬间跳到
|
|
40
|
+
* 78% 后长时间无变化——像卡死。现在统一在请求期间显示 'executing' 不定态,
|
|
41
|
+
* 让用户明确知道「仍在执行,请等待」。
|
|
42
|
+
*/
|
|
43
|
+
export const EXECUTING_STAGE = 'executing' as const;
|
|
44
|
+
|
|
45
|
+
const STAGE_KEYS: Record<string, UiTextKey> = {
|
|
46
|
+
analyzing: 'progress.analyzing',
|
|
47
|
+
'exporting-settings': 'progress.exportingSettings',
|
|
48
|
+
'scanning-secrets': 'progress.scanningSecrets',
|
|
49
|
+
'exporting-plugins': 'progress.exportingPlugins',
|
|
50
|
+
'creating-archive': 'progress.creatingArchive',
|
|
51
|
+
'calculating-checksums': 'progress.calculatingChecksums',
|
|
52
|
+
exporting: 'progress.exporting',
|
|
53
|
+
validating: 'progress.validating',
|
|
54
|
+
'checking-compatibility': 'progress.checkingCompatibility',
|
|
55
|
+
'creating-snapshot': 'progress.creatingSnapshot',
|
|
56
|
+
'restoring-settings': 'progress.restoringSettings',
|
|
57
|
+
'restoring-plugins': 'progress.restoringPlugins',
|
|
58
|
+
'restoring-mcp': 'progress.restoringMcp',
|
|
59
|
+
'validating-config': 'progress.validatingConfig',
|
|
60
|
+
'rolling-back': 'progress.rollingBack',
|
|
61
|
+
executing: 'progress.executing',
|
|
62
|
+
done: 'progress.done',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** 阶段 id → 用户可读文案(未知阶段回退 id) */
|
|
66
|
+
export function stageText(stage: string, t: UiT = zhUiT): string {
|
|
67
|
+
const key = STAGE_KEYS[stage];
|
|
68
|
+
return key !== undefined ? t(key) : stage;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 进度追踪器:按给定阶段序列在回调时附带 step/total 序号。
|
|
73
|
+
* 控制器调用 core 前后 emit(),UI 侧渲染进度条/阶段文字。
|
|
74
|
+
*/
|
|
75
|
+
export class ProgressTracker {
|
|
76
|
+
private readonly listener: ProgressListener | undefined;
|
|
77
|
+
private readonly stages: readonly string[];
|
|
78
|
+
private readonly emitted: string[] = [];
|
|
79
|
+
|
|
80
|
+
constructor(stages: readonly string[], listener?: ProgressListener) {
|
|
81
|
+
this.stages = stages;
|
|
82
|
+
this.listener = listener;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** 发出某阶段事件(可携带 detail);未在序列中的阶段 step/total 缺省 */
|
|
86
|
+
emit(stage: string, detail?: string): void {
|
|
87
|
+
const idx = this.stages.indexOf(stage);
|
|
88
|
+
const event: ProgressEvent = {
|
|
89
|
+
stage,
|
|
90
|
+
detail,
|
|
91
|
+
step: idx >= 0 ? idx + 1 : undefined,
|
|
92
|
+
total: idx >= 0 ? this.stages.length : undefined,
|
|
93
|
+
};
|
|
94
|
+
this.emitted.push(stage);
|
|
95
|
+
this.listener?.(event);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 已发出阶段的快照(测试与日志用) */
|
|
99
|
+
get events(): readonly string[] {
|
|
100
|
+
return [...this.emitted];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* report 测试(m6-ui):§21 导出报告 / §22 导入报告 / §17 回滚报告 / 动作按钮。
|
|
3
|
+
*/
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import {
|
|
7
|
+
formatBytes, importSectionStats, renderExportReport, renderImportReport,
|
|
8
|
+
renderRollbackReport, sectionFromItemId, suggestedActions,
|
|
9
|
+
} from './report.ts';
|
|
10
|
+
import { makeUiT } from './i18n.ts';
|
|
11
|
+
import { makeExportReport, makeImportResult, makeRollbackReport } from './test-helpers.ts';
|
|
12
|
+
|
|
13
|
+
const enT = makeUiT('en');
|
|
14
|
+
const zhT = makeUiT('zh');
|
|
15
|
+
|
|
16
|
+
test('report: sectionFromItemId 前缀推断', () => {
|
|
17
|
+
assert.equal(sectionFromItemId('settings:general'), 'settings');
|
|
18
|
+
assert.equal(sectionFromItemId('ui:theme'), 'ui');
|
|
19
|
+
assert.equal(sectionFromItemId('provider:pi-ai'), 'providers');
|
|
20
|
+
assert.equal(sectionFromItemId('plugin:x'), 'plugins');
|
|
21
|
+
assert.equal(sectionFromItemId('patch:line-1'), 'plugins');
|
|
22
|
+
assert.equal(sectionFromItemId('mcp:filesystem'), 'mcp');
|
|
23
|
+
assert.equal(sectionFromItemId('prompt:p1'), 'prompts');
|
|
24
|
+
assert.equal(sectionFromItemId('workspace:ws-1'), 'workspaces');
|
|
25
|
+
assert.equal(sectionFromItemId('secret:K1'), 'credentialsStatus');
|
|
26
|
+
assert.equal(sectionFromItemId('skills:my.md'), 'skills');
|
|
27
|
+
assert.equal(sectionFromItemId('sessions:s1'), 'sessions');
|
|
28
|
+
assert.equal(sectionFromItemId('unknown'), 'other');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('report: 导出报告含 Included/Excluded/Security/File(en / zh)', () => {
|
|
32
|
+
const enText = renderExportReport(makeExportReport(), enT);
|
|
33
|
+
assert.ok(enText.includes('Backup Created'));
|
|
34
|
+
assert.ok(enText.includes('✓ settings'));
|
|
35
|
+
assert.ok(enText.includes('8 plugins'));
|
|
36
|
+
assert.ok(enText.includes('○ sessions'));
|
|
37
|
+
assert.ok(enText.includes('API Keys excluded: yes'));
|
|
38
|
+
assert.ok(enText.includes('File: dsh-config-2026-08-14.zip'));
|
|
39
|
+
assert.ok(enText.includes('2 sensitive field(s) redacted'));
|
|
40
|
+
const zhText = renderExportReport(makeExportReport(), zhT);
|
|
41
|
+
assert.ok(zhText.includes('备份已创建'));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('report: 导入报告分节统计', () => {
|
|
45
|
+
const result = makeImportResult();
|
|
46
|
+
const stats = importSectionStats(result.executed);
|
|
47
|
+
const settings = stats.find((s) => s.section === 'settings')!;
|
|
48
|
+
assert.equal(settings.ok, 2);
|
|
49
|
+
const plugins = stats.find((s) => s.section === 'plugins')!;
|
|
50
|
+
assert.equal(plugins.ok, 1);
|
|
51
|
+
assert.equal(plugins.skipped, 1);
|
|
52
|
+
const secrets = stats.find((s) => s.section === 'credentialsStatus')!;
|
|
53
|
+
assert.equal(secrets.skipped, 1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('report: 导入报告渲染含分节/重启/缺失 secret(en)', () => {
|
|
57
|
+
const text = renderImportReport(makeImportResult(), enT);
|
|
58
|
+
assert.ok(text.includes('Import Complete'));
|
|
59
|
+
assert.ok(text.includes('settings: ✓ 2 imported/restored'));
|
|
60
|
+
assert.ok(text.includes('Secrets: ⚠ 1 credential(s) need to be entered'));
|
|
61
|
+
assert.ok(text.includes('Plugin / MCP changes take effect'));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('report: 失败导入渲染 Import Failed + 回滚报告(en)', () => {
|
|
65
|
+
const result = makeImportResult({
|
|
66
|
+
ok: false,
|
|
67
|
+
executed: [
|
|
68
|
+
{ itemId: 'settings:a', status: 'ok' },
|
|
69
|
+
{ itemId: 'mcp:m', status: 'failed', message: 'npx not found' },
|
|
70
|
+
],
|
|
71
|
+
rollback: makeRollbackReport(),
|
|
72
|
+
});
|
|
73
|
+
const text = renderImportReport(result, enT);
|
|
74
|
+
assert.ok(text.includes('Import Failed'));
|
|
75
|
+
assert.ok(text.includes('Rollback partially completed.'));
|
|
76
|
+
assert.ok(text.includes('manual recovery'));
|
|
77
|
+
assert.ok(text.includes('npx not found'));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('report: 回滚报告 full / partial(zh 缺省 + en)', () => {
|
|
81
|
+
assert.ok(renderRollbackReport({ full: true, restored: [], failed: [] }, zhT).includes('已完整恢复'));
|
|
82
|
+
const partial = renderRollbackReport(makeRollbackReport(), enT);
|
|
83
|
+
assert.ok(partial.includes('Rollback partially completed.'));
|
|
84
|
+
assert.ok(partial.includes('manual recovery'));
|
|
85
|
+
const partialZh = renderRollbackReport(makeRollbackReport(), zhT);
|
|
86
|
+
assert.ok(partialZh.includes('请手动'));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('report: suggestedActions 仅「完成」(报告已内联全部详情,无空操作按钮)', () => {
|
|
90
|
+
assert.deepEqual(suggestedActions(makeImportResult()), ['done']);
|
|
91
|
+
const failed = makeImportResult({
|
|
92
|
+
executed: [{ itemId: 'mcp:m', status: 'failed' }],
|
|
93
|
+
});
|
|
94
|
+
assert.deepEqual(suggestedActions(failed), ['done']);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('report: formatBytes', () => {
|
|
98
|
+
assert.equal(formatBytes(512), '512 B');
|
|
99
|
+
assert.equal(formatBytes(20480), '20.0 KB');
|
|
100
|
+
assert.equal(formatBytes(2 * 1024 * 1024), '2.0 MB');
|
|
101
|
+
});
|