dsh-config-manager 0.8.2 → 0.9.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 +42 -13
- 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 +147 -4
- 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/index.js +14 -0
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +104 -49
- package/lib/client.js +12536 -12006
- 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 +7 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +14 -2
- 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 +22 -0
- 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 +1 -1
- package/lib/index.js +1 -1
- 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 +13 -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 +34 -1
- package/lib/sync/autosync-scheduler.js +151 -43
- 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/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/pending-merge.d.ts +34 -0
- package/lib/sync/pending-merge.js +53 -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 +23 -40
- package/lib/sync/sync-engine.js +115 -132
- 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/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/i18n.d.ts +2 -1
- package/lib/ui/i18n.js +4 -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 +8 -0
- package/lib/ui/selection-model.js +16 -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 +2 -1
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +43 -12
- 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 +288 -0
- package/src/adapters/plugins.ts +141 -4
- 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/index.ts +18 -0
- package/src/cli/web/web.test.ts +27 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/about/AboutPanel.tsx +7 -6
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- 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 +13 -12
- 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 +188 -3
- 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 +1507 -272
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +20 -21
- package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
- 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 +35 -30
- package/src/client/home/HomePanel.tsx +45 -10
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +7 -6
- package/src/client/import/ImportWizardView.tsx +2 -3
- package/src/client/import/PathMappingForm.tsx +4 -4
- package/src/client/import/PathPickerDialog.tsx +2 -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 +19 -15
- package/src/client/library/LibraryActions.tsx +56 -16
- package/src/client/library/LibraryPanel.tsx +7 -7
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +10 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +2 -2
- package/src/client/locales/import.ts +3 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +0 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketPanel.tsx +38 -20
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +5 -5
- 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 +31 -16
- package/src/client/recovery/RollbackCard.tsx +58 -16
- 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/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 +182 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +3 -5
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +3 -3
- package/src/client/sync/SyncLogList.tsx +16 -5
- package/src/client/sync/SyncPanel.tsx +153 -159
- 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 +304 -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 +3 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +12 -0
- package/src/client/sync/sync-locales.ts +87 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +42 -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 +14 -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 +16 -4
- 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/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 +27 -1
- 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.ts +1 -1
- 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 +13 -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/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +417 -0
- package/src/sync/autosync-scheduler.ts +154 -41
- 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/merge-apply-plan.ts +117 -0
- package/src/sync/messages.ts +2 -0
- package/src/sync/pending-merge.ts +77 -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 +130 -135
- 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/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/i18n.ts +4 -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 +15 -1
- package/src/ui/selection-model.ts +18 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-yaml.test.ts +207 -1
- 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
|
@@ -170,10 +170,12 @@ const RENDER_POINTS: RenderPoint[] = [
|
|
|
170
170
|
{
|
|
171
171
|
id: 'snapshot-inspect-description',
|
|
172
172
|
// UI v2:该视图搬到 library/ 供产物库与备份页共用(同一次提交里改登记表,绝不漏)
|
|
173
|
+
// W7(D-05 #1):条目拆成「圆点 + 等宽 adapter + 描述」三段,前导 {' '} 随之消失 ——
|
|
174
|
+
// 锚点改成描述那一段自己的容差位(安全边界不变:仍是同一个 redact 包住宿主文本)。
|
|
173
175
|
file: 'src/client/library/BackupInspectView.tsx',
|
|
174
|
-
redacted: R(
|
|
175
|
-
bare: R(
|
|
176
|
-
why: '
|
|
176
|
+
redacted: R('<span className={css.inspectDesc}>{redact(item.description)}</span>'),
|
|
177
|
+
bare: R('<span className={css.inspectDesc}>{item.description}</span>'),
|
|
178
|
+
why: '备份差异查看的计划项描述(D-05 三段条目的描述段)',
|
|
177
179
|
},
|
|
178
180
|
/* ---------------- 同步差异确认 ---------------- */
|
|
179
181
|
{
|
|
@@ -318,6 +320,63 @@ const RENDER_POINTS: RenderPoint[] = [
|
|
|
318
320
|
bare: /const redactErrorText = \(err: unknown\): string => err instanceof Error \? err\.message : String\(err\)/,
|
|
319
321
|
why: '运行中心错误文本(2 处,同文件其它 3 处已脱敏)',
|
|
320
322
|
},
|
|
323
|
+
/* ---------------- 审计 P9-2(error state → 自绘 Banner / 列表)登记 ---------------- */
|
|
324
|
+
{
|
|
325
|
+
id: 'lib-restore-plan-error-state',
|
|
326
|
+
file: 'src/client/library/LibraryActions.tsx',
|
|
327
|
+
redacted: R('planFingerprint: undefined, error: redactErrorText(err)'),
|
|
328
|
+
bare: R('planFingerprint: undefined, error: err instanceof Error ? err.message : String(err)'),
|
|
329
|
+
why: '恢复计划失败原因存进 plan.error 后由 <Banner kind="error">{plan.error}</Banner> 直接渲染(宿主 message 可能含路径/token/env 片段)',
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
id: 'lib-inspect-backup-error-state',
|
|
333
|
+
file: 'src/client/library/LibraryActions.tsx',
|
|
334
|
+
redacted: R('error: redactErrorText(err), result: null'),
|
|
335
|
+
bare: R('error: err instanceof Error ? err.message : String(err), result: null'),
|
|
336
|
+
why: '「查看与对比」失败原因存进 inspect.error 后由 Banner 直接渲染',
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
id: 'export-inventory-error-state',
|
|
340
|
+
file: 'src/client/export/ExportView.tsx',
|
|
341
|
+
redacted: R('setInvError(redactErrorText(err))'),
|
|
342
|
+
bare: R('setInvError(err instanceof Error ? err.message : String(err))'),
|
|
343
|
+
why: '分区清单读取失败文本(宿主异常 / 网络中断原文)由 Banner 直接渲染',
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
id: 'path-picker-browse-error-state',
|
|
347
|
+
file: 'src/client/import/PathPickerDialog.tsx',
|
|
348
|
+
redacted: R('detail: redact(error instanceof Error ? error.message : String(error))'),
|
|
349
|
+
bare: R('detail: error instanceof Error ? error.message : String(error)'),
|
|
350
|
+
why: '目录列举失败文本(含请求的绝对路径)由 Banner 直接渲染',
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
id: 'sync-confirm-apply-error-state',
|
|
354
|
+
file: 'src/client/sync/SyncConfirmView.tsx',
|
|
355
|
+
redacted: R(" } catch (err) {\n setPhase('failed');\n setError(redact(err instanceof Error ? err.message : String(err)));\n }\n };\n\n const runCancel"),
|
|
356
|
+
bare: R(" } catch (err) {\n setPhase('failed');\n setError(err instanceof Error ? err.message : String(err));\n }\n };\n\n const runCancel"),
|
|
357
|
+
why: '一致性应用失败原因(api.applyItems 抛出的宿主文本)由 Banner 直接渲染',
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
id: 'sync-confirm-rollback-error-state',
|
|
361
|
+
file: 'src/client/sync/SyncConfirmView.tsx',
|
|
362
|
+
redacted: R(" } catch (err) {\n setPhase('failed');\n setError(redact(err instanceof Error ? err.message : String(err)));\n }\n };\n\n const busy"),
|
|
363
|
+
bare: R(" } catch (err) {\n setPhase('failed');\n setError(err instanceof Error ? err.message : String(err));\n }\n };\n\n const busy"),
|
|
364
|
+
why: '回滚失败原因(api.rollback 抛出的宿主文本)由 Banner 直接渲染',
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
id: 'sync-confirm-result-warnings',
|
|
368
|
+
file: 'src/client/sync/SyncConfirmView.tsx',
|
|
369
|
+
redacted: R('result.warnings.map((w, i) => <li key={i}>{redact(w)}</li>)'),
|
|
370
|
+
bare: R('result.warnings.map((w, i) => <li key={i}>{w}</li>)'),
|
|
371
|
+
why: '应用结果 warnings(宿主按分区拼装,可能回显本地配置值/路径)逐条渲染',
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
id: 'sync-panel-push-warnings',
|
|
375
|
+
file: 'src/client/sync/SyncPanel.tsx',
|
|
376
|
+
redacted: R('pushView.warnings.map((w, i) => <li key={i}>{redact(w)}</li>)'),
|
|
377
|
+
bare: R('pushView.warnings.map((w, i) => <li key={i}>{w}</li>)'),
|
|
378
|
+
why: '推送结果 warnings 逐条渲染(同一类宿主文本)',
|
|
379
|
+
},
|
|
321
380
|
/* ---------------- 「工作区 + 会话回滚」卡(t12:新组件登记) ---------------- */
|
|
322
381
|
{
|
|
323
382
|
id: 'rollback-card-error-text',
|
|
@@ -500,3 +559,129 @@ test('安全守卫(按渲染点):NAKED_TOAST_CALL 的两处边界(t56:
|
|
|
500
559
|
// R3:可选链已纳入扫描
|
|
501
560
|
assert.ok(naked('toast?.error(String(problem))'), 'R3:toast?.error 已纳入')
|
|
502
561
|
})
|
|
562
|
+
|
|
563
|
+
/* ============================================================================
|
|
564
|
+
* 反向守卫(P9-9):**未登记的 Banner 裸渲染必须红灯**。
|
|
565
|
+
*
|
|
566
|
+
* 上面的「按渲染点」守卫是白名单式的:RENDER_POINTS 里没登记的新渲染点天然全绿
|
|
567
|
+
* (审计实测:给任意组件加一处裸 Banner 也能过)。这里补反方向判据 —— 主动扫描
|
|
568
|
+
* src/client 下全部 「<Banner kind="error">」 / 「<Banner kind="warn">」 渲染点,
|
|
569
|
+
* 命中「裸宿主错误文本」形态而**未登记**即失败。
|
|
570
|
+
*
|
|
571
|
+
* 扫描面(「明确形态」,故意窄,理由如下):
|
|
572
|
+
* - 只看 「<Banner kind="error|warn">{EXPR}</Banner>」 且 EXPR 内不含花括号
|
|
573
|
+
* (对象字面量 / 箭头函数体 / 嵌套 JSX 在纯字符串层判断不可靠,一律不扫);
|
|
574
|
+
* [^{}] 允许换行,所以跨行的简单表达式仍被扫到。
|
|
575
|
+
* - 命中形态:EXPR 直接取 .message / .detail,或 String(...) 强转 —— 这是宿主文本
|
|
576
|
+
* 进入 JSX 的明确裸形态(本仓最常见的泄漏写法)。
|
|
577
|
+
* - 表达式内已脱敏即放行:出现 redact( / redactErrorText((直接包住),或 t(
|
|
578
|
+
* (整段是字典文案,不含宿主值)。
|
|
579
|
+
* - 纯 state 字段形态({state.error} 这类)**不扫**:它们在写入侧脱敏(对应登记点
|
|
580
|
+
* 在 RENDER_POINTS 里),渲染处无法从字符串判断;强行扫描只能逼出全量白名单噪音,
|
|
581
|
+
* 与 P9-9「只扫明确形态、不许把白名单全塞进去」的边界冲突。宁可窄而真。
|
|
582
|
+
* - <ErrorBanner error={...}> 不扫:组件自身就是脱敏边界(下方单测钉住内部仍在 redact)。
|
|
583
|
+
*
|
|
584
|
+
* 豁免机制:BANNER_EXEMPTIONS 逐条给「文件 + 表达式 + 理由 + 前提正则」;
|
|
585
|
+
* 每条必须恰好命中 1 次,且前提正则在源码里仍命中 —— 脱敏被挪走即红灯(不留死条目)。
|
|
586
|
+
* 阈值:扫描面 >= 40 个渲染点(当前扫描到 62 个),扫描器被改坏 / 遍历失效会立刻红。
|
|
587
|
+
*/
|
|
588
|
+
const BANNER_ERROR_RENDER = /<Banner kind="(?:error|warn)">\{([^{}]+)\}<\/Banner>/g
|
|
589
|
+
const RAW_ERROR_EXPR = /\.message\b|\.detail\b|String\s*\(/
|
|
590
|
+
const REDACTING_EXPR = /\bredact(?:ErrorText)?\s*\(|\bt\s*\(/
|
|
591
|
+
|
|
592
|
+
interface BannerExemption {
|
|
593
|
+
file: string
|
|
594
|
+
expr: string
|
|
595
|
+
/** 豁免前提:该文件里仍存在的脱敏写入(挪走即失效) */
|
|
596
|
+
premise: RegExp
|
|
597
|
+
why: string
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const BANNER_EXEMPTIONS: readonly BannerExemption[] = [
|
|
601
|
+
{
|
|
602
|
+
file: 'src/client/import/PathPickerDialog.tsx',
|
|
603
|
+
expr: 'state.detail',
|
|
604
|
+
premise: /detail: redact\(error instanceof Error \? error\.message : String\(error\)\)/,
|
|
605
|
+
why: '目录浏览失败原因在写 state 时已 redact(登记点 path-picker-browse-error-state),渲染处拿到的是脱敏后的字符串',
|
|
606
|
+
},
|
|
607
|
+
]
|
|
608
|
+
|
|
609
|
+
/** 递归列出 src/client 下的非测试 .tsx(相对仓库根、正斜杠) */
|
|
610
|
+
function listClientTsx(dir: string, out: string[] = []): string[] {
|
|
611
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
612
|
+
const abs = path.join(dir, entry.name)
|
|
613
|
+
if (entry.isDirectory()) listClientTsx(abs, out)
|
|
614
|
+
else if (entry.name.endsWith('.tsx') && !entry.name.endsWith('.test.tsx')) {
|
|
615
|
+
out.push(path.relative(ROOT, abs).split(path.sep).join('/'))
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return out
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** 扫描到的全部 Banner error/warn 渲染点(表达式已 trim,便于登记比对) */
|
|
622
|
+
function scanBannerRenders(): { file: string; expr: string }[] {
|
|
623
|
+
const hits: { file: string; expr: string }[] = []
|
|
624
|
+
for (const file of listClientTsx(path.join(ROOT, 'src/client'))) {
|
|
625
|
+
for (const m of read(file).matchAll(BANNER_ERROR_RENDER)) hits.push({ file, expr: (m[1] ?? '').trim() })
|
|
626
|
+
}
|
|
627
|
+
return hits
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** 裸宿主错误文本 = 命中裸形态,且表达式内没有直接脱敏 */
|
|
631
|
+
function isNakedErrorExpr(expr: string): boolean {
|
|
632
|
+
return RAW_ERROR_EXPR.test(expr) && !REDACTING_EXPR.test(expr)
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
test('反向守卫(P9-9):src/client 的 Banner 错误渲染点不得出现未登记的裸宿主文本', () => {
|
|
636
|
+
const hits = scanBannerRenders()
|
|
637
|
+
assert.ok(
|
|
638
|
+
hits.length >= 40,
|
|
639
|
+
'扫描面异常:应识别 >= 40 个 <Banner kind="error|warn"> 渲染点(实际 ' + hits.length + ')',
|
|
640
|
+
)
|
|
641
|
+
const unregistered = hits
|
|
642
|
+
.filter((h) => isNakedErrorExpr(h.expr))
|
|
643
|
+
.filter((h) => !BANNER_EXEMPTIONS.some((e) => e.file === h.file && e.expr === h.expr))
|
|
644
|
+
.map((h) => h.file + ' -> {' + h.expr + '}')
|
|
645
|
+
assert.deepEqual(
|
|
646
|
+
unregistered,
|
|
647
|
+
[],
|
|
648
|
+
'Banner 直接渲染宿主错误原文:包 redact()/redactErrorText(),或按表达式登记 BANNER_EXEMPTIONS(含前提正则)',
|
|
649
|
+
)
|
|
650
|
+
})
|
|
651
|
+
|
|
652
|
+
test('反向守卫(P9-9):豁免项不得是死条目(恰好命中 1 次,且脱敏前提仍成立)', () => {
|
|
653
|
+
const hits = scanBannerRenders()
|
|
654
|
+
for (const e of BANNER_EXEMPTIONS) {
|
|
655
|
+
const n = hits.filter((h) => h.file === e.file && h.expr === e.expr).length
|
|
656
|
+
assert.equal(n, 1, '[' + e.file + ' {' + e.expr + '}] 豁免应恰好命中 1 次(实际 ' + n + ')—— 渲染点被删/被改就删掉本豁免')
|
|
657
|
+
assert.match(
|
|
658
|
+
read(e.file),
|
|
659
|
+
e.premise,
|
|
660
|
+
'[' + e.file + '] 豁免前提已失效:该处的脱敏写入不见了 —— ' + e.why,
|
|
661
|
+
)
|
|
662
|
+
}
|
|
663
|
+
})
|
|
664
|
+
|
|
665
|
+
test('反向守卫(P9-9):判别式对裸形态必须命中(注入自检,防守卫写成死代码)', () => {
|
|
666
|
+
const detect = (snippet: string): string[] =>
|
|
667
|
+
[...snippet.matchAll(BANNER_ERROR_RENDER)].map((m) => (m[1] ?? '').trim()).filter(isNakedErrorExpr)
|
|
668
|
+
assert.deepEqual(detect('<Banner kind="error">{err.message}</Banner>'), ['err.message'], 'err.message 必须判裸')
|
|
669
|
+
assert.deepEqual(detect('<Banner kind="warn">{String(cause)}</Banner>'), ['String(cause)'], 'String(cause) 必须判裸')
|
|
670
|
+
assert.deepEqual(detect('<Banner kind="error">{state.detail}</Banner>'), ['state.detail'], '.detail 必须判裸')
|
|
671
|
+
// 跨行简单表达式同样在扫描面内
|
|
672
|
+
assert.deepEqual(detect('<Banner kind="error">{\n err.message\n}</Banner>'), ['err.message'], '跨行表达式仍须命中')
|
|
673
|
+
// 已脱敏 / 字典文案放行
|
|
674
|
+
assert.deepEqual(detect('<Banner kind="error">{redact(err.message)}</Banner>'), [], 'redact 包住合法')
|
|
675
|
+
assert.deepEqual(detect("<Banner kind=\"error\">{t('syncflow.importFailed')}</Banner>"), [], '纯字典文案合法')
|
|
676
|
+
// 三元等无花括号形态也在扫描面内(比预期更宽,是好事)
|
|
677
|
+
assert.deepEqual(detect('<Banner kind="error">{cond ? err.message : null}</Banner>'), ['cond ? err.message : null'], '三元形态仍须命中')
|
|
678
|
+
// 边界如实锁定:含花括号的表达式不在扫描面(对象字面量 / 箭头函数体,纯字符串层判不准)
|
|
679
|
+
assert.deepEqual(detect('<Banner kind="error">{({ m: err.message }).m}</Banner>'), [], '含花括号形态不扫')
|
|
680
|
+
})
|
|
681
|
+
|
|
682
|
+
test('反向守卫(P9-9):ErrorBanner 自身仍是脱敏边界', () => {
|
|
683
|
+
const src = read('src/client/common/ErrorBanner.tsx')
|
|
684
|
+
assert.match(src, /const reason = redact\(actionable\.reason\)/, 'ErrorBanner 必须继续 redact 原因文本')
|
|
685
|
+
assert.match(src, /\{redact\(actionable\.title\)\}/, 'ErrorBanner 必须继续 redact 标题')
|
|
686
|
+
assert.match(src, /redact\(line\)/, 'ErrorList 必须继续 redact 每一行')
|
|
687
|
+
})
|
|
@@ -42,3 +42,63 @@ test('L-04 终止等待状态必须在卡片上可见(等多久 + 超阈值给
|
|
|
42
42
|
assert.ok(source.includes("t('runs.cancelStuck')"), '超过阈值必须给出「先跳过 / 否则重启」的出路文案');
|
|
43
43
|
assert.ok(source.includes('runs.cancelWaiting'), '必须显示已等待时长');
|
|
44
44
|
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* P9-6(时序)守卫:轮询重叠 + 决策框自己弹回来。
|
|
48
|
+
* 断言一律钉在**调用表达式**上:删掉实现(或把调用挪走)必红,改注释不会误绿。
|
|
49
|
+
*/
|
|
50
|
+
test('S-01 轮询必须有请求序号守卫(旧响应不得覆盖新数据)', () => {
|
|
51
|
+
assert.ok(source.includes('const seq = seqRef.current + 1'), '每次 refresh 必须领一个新的请求序号');
|
|
52
|
+
assert.ok(source.includes("from './runs-center-view.ts'"), '判定必须来自纯函数模块(可单测)');
|
|
53
|
+
assert.ok(
|
|
54
|
+
(source.match(/if \(!isStaleResponse\(runsSeqRef\.current, seq\)\) \{/g) ?? []).length >= 2,
|
|
55
|
+
'runs 通道的成功/失败两条落地路径都必须先判陈旧(否则旧进度会写回去)',
|
|
56
|
+
);
|
|
57
|
+
assert.ok(
|
|
58
|
+
(source.match(/if \(!isStaleResponse\(lockSeqRef\.current, seq\)\) \{/g) ?? []).length >= 2,
|
|
59
|
+
'lock 通道同样要判(否则旧锁状态会盖掉新的)',
|
|
60
|
+
);
|
|
61
|
+
assert.equal(
|
|
62
|
+
(source.match(/if \(isStaleResponse\(\w+SeqRef\.current, seq\)\) return/g) ?? []).length, 0,
|
|
63
|
+
'判陈旧不得 return:下一个请求(锁状态)与 runs 是两条独立通道,连带跳过会让锁刷新跟着停摆',
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('S-05 提交决策后必须同样登记「已忽略」,否则框会用陈旧快照把已结案的 run 重新弹开', () => {
|
|
68
|
+
assert.ok(
|
|
69
|
+
source.includes('dismissedRef.current.add(dialogKeyOf(run))'),
|
|
70
|
+
'确认出口在 setDialogRun(null) 之前必须登记 key(此刻 refresh 还没回来,runs 里那条 run 仍在等决定)',
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('S-06 框里那条 run 结案后必须自动关闭(否则一个过时的提问会挡住后面所有等待)', () => {
|
|
75
|
+
assert.ok(source.includes('isDialogStillWaiting(dialogRun, runs)'), '必须用纯函数判定「还在等吗」');
|
|
76
|
+
assert.ok(
|
|
77
|
+
/if \(dialogRun !== null\) \{[\s\S]{0,400}?isDialogStillWaiting\(dialogRun, runs\)\) setDialogRun\(null\)/.test(source),
|
|
78
|
+
'判定为已结案时必须真的关框,而不是只判不用',
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('S-02 关闭决策框必须登记「已忽略」,否则 1.5s 后同一个等待事件又弹回来', () => {
|
|
83
|
+
assert.ok(source.includes('dismissedRef.current.add(dialogKeyOf(dialogRun))'), 'onCancel 必须按稳定 key 记住这次忽略');
|
|
84
|
+
assert.ok(source.includes('onCancel={dismissDialog}'), '对话框的取消出口必须走登记函数');
|
|
85
|
+
assert.ok(
|
|
86
|
+
!source.includes('onCancel={() => { setDialogRun(null) }}'),
|
|
87
|
+
'旧的「只清 dialogRun」写法必须拆掉 —— 它就是框自己弹回来的原因',
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('S-03 自动弹框必须走 pickWaitingRun,且每轮裁剪忽略集合(有界)', () => {
|
|
92
|
+
assert.ok(source.includes('pickWaitingRun(runs, dismissedRef.current)'), '选择逻辑必须在纯函数里,且真的把忽略集合传进去');
|
|
93
|
+
assert.ok(
|
|
94
|
+
source.includes('dismissedRef.current = pruneDismissed(dismissedRef.current, runs)'),
|
|
95
|
+
'每轮必须裁剪已不在等待的键,否则集合无界增长',
|
|
96
|
+
);
|
|
97
|
+
assert.ok(source.includes('const waiting = pickWaitingRun('), '弹框条件不得内联回 effect(内联即绕过忽略集合)');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('S-04 忽略集合必须是每实例状态,不得是模块级单例', () => {
|
|
101
|
+
assert.ok(source.includes('useRef<Set<DialogKey>>(new Set())'), '必须是组件内 useRef(多实例各一份)');
|
|
102
|
+
const moduleLevel = /^(?:export\s+)?(?:const|let|var)\s+\w*[Dd]ismissed\w*\s*(?::[^=\n]*)?=/m;
|
|
103
|
+
assert.equal(moduleLevel.test(source), false, '模块级 dismissed 单例会让多个面板/页面互相串味');
|
|
104
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runs-center-view 单测:运行中心的时序判定(纯函数,node 可测)。
|
|
3
|
+
*
|
|
4
|
+
* 覆盖 P9-6 的两个现场:
|
|
5
|
+
* - 慢响应重叠:旧响应晚到不得覆盖新数据(isStaleResponse);
|
|
6
|
+
* - 关不掉的决策框:同一个等待事件跨轮询 key 必须不变(dialogKeyOf / pickWaitingRun),
|
|
7
|
+
* 且忽略集合必须随等待事件结束释放(pruneDismissed,有界)。
|
|
8
|
+
*/
|
|
9
|
+
import test from 'node:test'
|
|
10
|
+
import assert from 'node:assert/strict'
|
|
11
|
+
|
|
12
|
+
import { dialogKeyOf, isDialogStillWaiting, isStaleResponse, pickWaitingRun, pruneDismissed } from './runs-center-view.ts'
|
|
13
|
+
import type { RunState } from '../../core/run-registry.ts'
|
|
14
|
+
|
|
15
|
+
/** 造一条 run(只写测试关心的字段,其余给稳定默认值)。 */
|
|
16
|
+
function run(over: Partial<RunState> = {}): RunState {
|
|
17
|
+
return {
|
|
18
|
+
runId: 'r1',
|
|
19
|
+
kind: 'import',
|
|
20
|
+
status: 'running',
|
|
21
|
+
section: null,
|
|
22
|
+
sectionTotal: null,
|
|
23
|
+
item: 0,
|
|
24
|
+
itemTotal: 10,
|
|
25
|
+
detail: null,
|
|
26
|
+
log: [],
|
|
27
|
+
createdAt: 1_000,
|
|
28
|
+
updatedAt: 1_000,
|
|
29
|
+
...over,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
test('T-01 dialogKeyOf: 同一个等待事件跨轮询不变(updatedAt / log / 计数都在变)', () => {
|
|
34
|
+
const first = run({ pendingDecision: 'cancel', cancelRequestedAt: 1_100, updatedAt: 1_100, item: 3 })
|
|
35
|
+
const second = run({ pendingDecision: 'cancel', cancelRequestedAt: 1_100, updatedAt: 1_600, item: 7 })
|
|
36
|
+
assert.equal(dialogKeyOf(first), dialogKeyOf(second), '轮询回来的新对象必须是同一个 key,否则忽略失效')
|
|
37
|
+
assert.equal(dialogKeyOf(first), 'r1:cancel')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('T-02 dialogKeyOf: 换 run 或换决定种类 → 不同 key', () => {
|
|
41
|
+
assert.notEqual(dialogKeyOf(run({ runId: 'r1', pendingDecision: 'cancel' })), dialogKeyOf(run({ runId: 'r2', pendingDecision: 'cancel' })))
|
|
42
|
+
assert.notEqual(dialogKeyOf(run({ pendingDecision: 'cancel' })), dialogKeyOf(run({ pendingDecision: null })))
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('T-03 pickWaitingRun: 只选「running + 等 cancel 决定」的第一条', () => {
|
|
46
|
+
const done = run({ runId: 'done', status: 'done', pendingDecision: 'cancel' })
|
|
47
|
+
const plain = run({ runId: 'plain' })
|
|
48
|
+
const waiting = run({ runId: 'waiting', pendingDecision: 'cancel' })
|
|
49
|
+
assert.equal(pickWaitingRun([done, plain, waiting], new Set()), waiting)
|
|
50
|
+
assert.equal(pickWaitingRun([done, plain], new Set()), null)
|
|
51
|
+
assert.equal(pickWaitingRun(null, new Set()), null)
|
|
52
|
+
assert.equal(pickWaitingRun([], new Set()), null)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('T-04 pickWaitingRun: 被忽略的跳过;全部忽略 → 不弹', () => {
|
|
56
|
+
const waiting = run({ runId: 'waiting', pendingDecision: 'cancel' })
|
|
57
|
+
const dismissed = new Set([dialogKeyOf(waiting)])
|
|
58
|
+
assert.equal(pickWaitingRun([waiting], dismissed), null)
|
|
59
|
+
// 另一条新的等待事件仍然要弹(忽略只对同一个 key 生效)
|
|
60
|
+
const other = run({ runId: 'other', pendingDecision: 'cancel' })
|
|
61
|
+
assert.equal(pickWaitingRun([waiting, other], dismissed), other)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('T-05 现场复现: 关掉后连续三轮轮询(每次都是新对象、新 updatedAt)都不再自动弹', () => {
|
|
65
|
+
const dismissed: Set<string> = new Set()
|
|
66
|
+
let source = run({ pendingDecision: 'cancel', updatedAt: 1_000 })
|
|
67
|
+
dismissed.add(dialogKeyOf(source)) // 用户点了「取消」
|
|
68
|
+
for (const updatedAt of [1_500, 3_000, 4_500]) {
|
|
69
|
+
source = run({ pendingDecision: 'cancel', updatedAt, item: updatedAt / 1_500 })
|
|
70
|
+
// 每轮都按组件里的顺序:先裁剪,再挑
|
|
71
|
+
const pruned = pruneDismissed(dismissed, [source])
|
|
72
|
+
assert.equal(pruned.size, 1, 'run 还在等,忽略键必须保留')
|
|
73
|
+
dismissed.clear()
|
|
74
|
+
for (const key of pruned) dismissed.add(key)
|
|
75
|
+
assert.equal(pickWaitingRun([source], dismissed), null, '同一个等待事件不得再弹回来')
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('T-06 pruneDismissed: 等待结束后释放键(集合有界),runs 未知时保留', () => {
|
|
80
|
+
const a = run({ runId: 'a', pendingDecision: 'cancel' })
|
|
81
|
+
const b = run({ runId: 'b', pendingDecision: 'cancel' })
|
|
82
|
+
const dismissed = new Set([dialogKeyOf(a), dialogKeyOf(b)])
|
|
83
|
+
|
|
84
|
+
const afterAFinished = pruneDismissed(dismissed, [run({ runId: 'a', status: 'done' }), b])
|
|
85
|
+
assert.deepEqual([...afterAFinished], [dialogKeyOf(b)], '已结束的 run 不再占键')
|
|
86
|
+
|
|
87
|
+
assert.deepEqual([...pruneDismissed(dismissed, null)], [...dismissed], '首次加载未落地时不得清空(否则瞬时失败后弹框复现)')
|
|
88
|
+
assert.equal(pruneDismissed(new Set(), [a]).size, 0)
|
|
89
|
+
|
|
90
|
+
// 有界性:100 条 run 依次等待并结束,键集合不随之增长
|
|
91
|
+
let live = new Set<string>()
|
|
92
|
+
for (let i = 1; i <= 100; i += 1) {
|
|
93
|
+
const current = run({ runId: `r${i}`, pendingDecision: 'cancel' })
|
|
94
|
+
live.add(dialogKeyOf(current))
|
|
95
|
+
live = pruneDismissed(live, [current])
|
|
96
|
+
assert.equal(live.size, 1)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('T-07 isStaleResponse: 只有比已落地序号更新才允许落地', () => {
|
|
101
|
+
assert.equal(isStaleResponse(0, 1), false, '首条响应必须能落地')
|
|
102
|
+
assert.equal(isStaleResponse(2, 3), false)
|
|
103
|
+
assert.equal(isStaleResponse(2, 2), true, '同序号已写过,重复写会把更新的值压回去')
|
|
104
|
+
assert.equal(isStaleResponse(2, 1), true, '旧响应晚到必须丢弃')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('T-09 isDialogStillWaiting: 已结案的等待必须关框,快照未知不得关', () => {
|
|
108
|
+
const waiting = run({ pendingDecision: 'cancel' })
|
|
109
|
+
const settled = run({ status: 'done', pendingDecision: null })
|
|
110
|
+
assert.equal(isDialogStillWaiting(waiting, [waiting]), true, '仍在等决定时必须保留框')
|
|
111
|
+
assert.equal(isDialogStillWaiting(waiting, [settled]), false, '宿主超时自动裁决后必须关框')
|
|
112
|
+
assert.equal(isDialogStillWaiting(waiting, []), false, 'run 已从最近列表消失也算结案')
|
|
113
|
+
assert.equal(isDialogStillWaiting(waiting, null), true, '快照还没落地时关框等于把问题藏起来')
|
|
114
|
+
assert.equal(isDialogStillWaiting(waiting, [run({ runId: 'r2', pendingDecision: 'cancel' })]), false, '别的 run 在等不算这条还在等')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('T-08 现场复现: 旧响应后到不得覆盖新数据(进度回退)', () => {
|
|
118
|
+
let applied = 0
|
|
119
|
+
let shown = 0
|
|
120
|
+
const land = (seq: number, item: number): void => {
|
|
121
|
+
if (isStaleResponse(applied, seq)) return
|
|
122
|
+
applied = seq
|
|
123
|
+
shown = item
|
|
124
|
+
}
|
|
125
|
+
land(2, 9) // 新一轮先到
|
|
126
|
+
land(1, 3) // 旧一轮后到
|
|
127
|
+
assert.equal(shown, 9, '进度条不得回退')
|
|
128
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行中心(Run Center)的时序纯逻辑:轮询序号守卫 + 「待决策」弹框的忽略记忆。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一层:这两件事都是**时序判定**(谁的数据能落地、哪个框该弹),出错时表现为
|
|
5
|
+
* 「进度无故回退」「决策框关不掉」——都必须可单测,React 壳只装配(与 ui/runs-view.ts 同一分层理由)。
|
|
6
|
+
*
|
|
7
|
+
* 两条判据(读码得出,不是偏好):
|
|
8
|
+
* 1. **旧响应不得覆盖新数据**:/runs 与 /recovery/status 是两次独立请求,1.5s 轮询在慢响应时
|
|
9
|
+
* 必然重叠;没有序号守卫时,先发的旧响应后落地会把进度条/状态改回旧值。
|
|
10
|
+
* 2. **「忽略」只对同一个等待事件生效**:用户关掉决策框后,1.5s 后轮询回来的同一条 waiting run
|
|
11
|
+
* 又满足弹框条件。按对象引用或 updatedAt 记「已忽略」必然失效(每轮都是新对象、新时间戳),
|
|
12
|
+
* 框就会自己弹回来 —— 所以 key 只能由「run 身份 + 它等的那个决定」构成。
|
|
13
|
+
*/
|
|
14
|
+
import type { RunState } from '../../core/run-registry.ts'
|
|
15
|
+
|
|
16
|
+
/** 一次「等待用户决定」事件的稳定身份:同一 run 的同一等待状态跨轮询不变,忽略按它生效。 */
|
|
17
|
+
export type DialogKey = string
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 一条 run 的等待事件键。
|
|
21
|
+
*
|
|
22
|
+
* 只取 runId 与 pendingDecision:`updatedAt` 每轮都可能变(任何进度更新都会重写它),
|
|
23
|
+
* 用时间戳当 key 等于「每轮都是新事件」,用户永远关不掉弹框;`cancelRequestedAt` 虽然
|
|
24
|
+
* 幂等(宿主保留首个时刻),但一个 run 只会进入一次 cancel 等待,带上它不增加区分度。
|
|
25
|
+
*/
|
|
26
|
+
export function dialogKeyOf(run: RunState): DialogKey {
|
|
27
|
+
return `${run.runId}:${run.pendingDecision ?? 'none'}`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 框里那条 run 是否仍在等决定。
|
|
32
|
+
*
|
|
33
|
+
* 用途是**关掉过时的提问**:宿主对「等决定」有 5 分钟超时(超时按默认策略自动裁决),
|
|
34
|
+
* 期间界面若一直把框开着,它问的就是一个已经被回答的问题;更糟的是 dialogRun !== null
|
|
35
|
+
* 会让自动弹框 effect 永久早退 —— 后面任何 run 的等待都不会再弹出来。
|
|
36
|
+
* runs === null(快照还没落地)时返回 true:那一刻没有「已结案」的证据,关掉等于把问题藏起来。
|
|
37
|
+
*/
|
|
38
|
+
export function isDialogStillWaiting(dialogRun: RunState, runs: readonly RunState[] | null): boolean {
|
|
39
|
+
if (runs === null) return true
|
|
40
|
+
return runs.some((run) => run.runId === dialogRun.runId && isAwaitingCancelDecision(run))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 正在等「回滚 / 保留」决定的 run(沿用组件里原自动弹框的筛选语义,一字不改地搬进纯函数)。 */
|
|
44
|
+
function isAwaitingCancelDecision(run: RunState): boolean {
|
|
45
|
+
return run.status === 'running' && run.pendingDecision === 'cancel'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 序号守卫:incomingSeq ≤ 已落地序号 ⇒ 这条响应已过时,调用方整份丢弃(连 setError 都不覆盖)。
|
|
50
|
+
*
|
|
51
|
+
* 为什么是「≤」而不是「<」:同一次 refresh 的两个通道(runs / lock)各记一个已落地序号,
|
|
52
|
+
* 同序号再次落地说明这个通道已经写过,重复写只会把更新的值压回去(比如把 lockError 重新抹成旧值)。
|
|
53
|
+
*/
|
|
54
|
+
export function isStaleResponse(appliedSeq: number, incomingSeq: number): boolean {
|
|
55
|
+
return incomingSeq <= appliedSeq
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 自动弹框该弹哪一条:第一条「在等决定」且未被忽略的 run;null = 不该弹。
|
|
60
|
+
* 顺序确定(数组首条;宿主按 updatedAt 倒序给,= 最近更新的那条),不依赖 Set 迭代顺序。
|
|
61
|
+
*/
|
|
62
|
+
export function pickWaitingRun(
|
|
63
|
+
runs: readonly RunState[] | null,
|
|
64
|
+
dismissed: ReadonlySet<DialogKey>,
|
|
65
|
+
): RunState | null {
|
|
66
|
+
if (runs === null) return null
|
|
67
|
+
for (const run of runs) {
|
|
68
|
+
if (!isAwaitingCancelDecision(run)) continue
|
|
69
|
+
if (dismissed.has(dialogKeyOf(run))) continue
|
|
70
|
+
return run
|
|
71
|
+
}
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 裁掉「已经不在等待」的键:忽略集合必须随等待事件结束释放,否则一次会话里出现过的每条 run
|
|
77
|
+
* 都会留一个键(无界增长 —— 这是资源有界性要求,不是审美)。
|
|
78
|
+
*
|
|
79
|
+
* runs === null(首次加载还没落地)时**原样保留**:那一刻没有「谁还在等」的信息,
|
|
80
|
+
* 拿空集裁剪等于把用户刚关掉的框在一次瞬时失败后又放回来。
|
|
81
|
+
*/
|
|
82
|
+
export function pruneDismissed(
|
|
83
|
+
dismissed: ReadonlySet<DialogKey>,
|
|
84
|
+
runs: readonly RunState[] | null,
|
|
85
|
+
): Set<DialogKey> {
|
|
86
|
+
if (runs === null) return new Set(dismissed)
|
|
87
|
+
const waiting = new Set<DialogKey>()
|
|
88
|
+
for (const run of runs) {
|
|
89
|
+
if (isAwaitingCancelDecision(run)) waiting.add(dialogKeyOf(run))
|
|
90
|
+
}
|
|
91
|
+
const kept = new Set<DialogKey>()
|
|
92
|
+
for (const key of dismissed) {
|
|
93
|
+
if (waiting.has(key)) kept.add(key)
|
|
94
|
+
}
|
|
95
|
+
return kept
|
|
96
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SectionTitle 的 `action` 槽守卫(W5,2026-11-14)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要这条:卡头要「标题 + 右侧动作」时,最省事的写法是调用方自己再拼一行
|
|
5
|
+
* (历史上叫过 .recoveryHead 之类),于是同一页出现两套标题行 —— 字号、间距、图标基线各一套,
|
|
6
|
+
* 下次改标题样式时只改到一半。口径固定为:需要标题行右侧动作时**只传 `action`**,
|
|
7
|
+
* 由 SectionTitle 复用 .sectionTitleRow 的 flex 与 .statusSpacer 推尾,不新造容器类。
|
|
8
|
+
*
|
|
9
|
+
* 第二条判据是**纯增量**:不传 `action` 时 DOM 必须与旧版逐字一致(21 处既有调用点不受影响),
|
|
10
|
+
* 所以分支必须是 `action !== undefined && …` 的条件渲染,不能无条件插一个空 `<span>`/占位节点。
|
|
11
|
+
*
|
|
12
|
+
* 第三条是需求级:恢复页(P-05)唯一的重新拉取入口就挂在这个槽上 —— 它要是被顺手删掉,
|
|
13
|
+
* 面板就退回「只能切页/刷新浏览器才能更新」,而那次改动的 diff 看起来很干净。
|
|
14
|
+
*/
|
|
15
|
+
import test from 'node:test';
|
|
16
|
+
import assert from 'node:assert/strict';
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
|
|
19
|
+
const UI_PATH = 'src/client/common/ui.tsx';
|
|
20
|
+
const RECOVERY_PATH = 'src/client/recovery/RecoveryPanel.tsx';
|
|
21
|
+
|
|
22
|
+
/** 截出 SectionTitle 的函数体(到下一个顶层 `function` / `export function` 为止)。 */
|
|
23
|
+
function sectionTitleBody(): string {
|
|
24
|
+
const src = readFileSync(UI_PATH, 'utf8');
|
|
25
|
+
const at = src.indexOf('export function SectionTitle(');
|
|
26
|
+
assert.ok(at >= 0, UI_PATH + ' 里找不到 SectionTitle');
|
|
27
|
+
const next = src.slice(at + 1).search(/\n(export )?function /);
|
|
28
|
+
return next < 0 ? src.slice(at) : src.slice(at, at + 1 + next);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test('action 槽:props 可选、条件渲染、用共享 statusSpacer 推尾(不新造容器类)', () => {
|
|
32
|
+
const src = readFileSync(UI_PATH, 'utf8')
|
|
33
|
+
const body = sectionTitleBody();
|
|
34
|
+
|
|
35
|
+
// 属性声明在 SectionTitleProps(函数体外),所以对整文件断言类型;渲染分支对函数体断言。
|
|
36
|
+
assert.match(src, /\n action\?: ReactNode\n/,
|
|
37
|
+
'SectionTitleProps 必须声明可选的 action(不传即旧行为)')
|
|
38
|
+
|
|
39
|
+
assert.match(body, /\{action !== undefined && \(\s*<>\s*<span className=\{css\.statusSpacer\} \/>\s*\{action\}\s*<\/>\s*\)\}/,
|
|
40
|
+
'action 必须是条件渲染,且先渲共享的 statusSpacer 再渲 action(纯增量:不传时 DOM 逐字不变)')
|
|
41
|
+
|
|
42
|
+
// 位置:动作必须在 .sectionTitleRow 内、标题 <h3> 之后 —— 放 subtitle 之后会另起一行
|
|
43
|
+
// (视觉上回到两套标题行)。2026-11-14 起没有 info 槽(ⓘ 下线),标题行里只有标题与动作。
|
|
44
|
+
const rowAt = body.indexOf('css.sectionTitleRow')
|
|
45
|
+
const titleAt = body.indexOf('<h3')
|
|
46
|
+
const actionAt = body.indexOf('{action !== undefined')
|
|
47
|
+
const subtitleAt = body.indexOf('{subtitle !== undefined')
|
|
48
|
+
assert.ok(rowAt >= 0 && titleAt > rowAt && actionAt > titleAt && subtitleAt > actionAt,
|
|
49
|
+
'action 必须渲染在 .sectionTitleRow 内、<h3> 之后、subtitle 之前(不得另起一行)')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('恢复页(P-05)把「刷新」挂在 SectionTitle 的 action 槽上,而不是自建卡头', () => {
|
|
53
|
+
const src = readFileSync(RECOVERY_PATH, 'utf8')
|
|
54
|
+
const at = src.indexOf('<SectionTitle')
|
|
55
|
+
assert.ok(at >= 0, RECOVERY_PATH + ' 里找不到 SectionTitle')
|
|
56
|
+
// 到与 <SectionTitle 同缩进的收尾 '/>' 为止(action 里还有自闭合标签,不能截到第一个 '/>')
|
|
57
|
+
const end = src.indexOf('\n />', at)
|
|
58
|
+
assert.ok(end > at, RECOVERY_PATH + ' 里 SectionTitle 没有收尾')
|
|
59
|
+
const block = src.slice(at, end)
|
|
60
|
+
|
|
61
|
+
assert.match(block, /action=\{/, '恢复页标题行必须传 action(唯一重新拉取入口)')
|
|
62
|
+
assert.match(block, /t\(\s*'recovery\.refresh'\s*\)/, 'action 槽里必须是「刷新」,文案走字典键 recovery.refresh')
|
|
63
|
+
assert.match(block, /onClick=\{load\}/, '刷新按钮必须真的重新加载(onClick={load})')
|
|
64
|
+
assert.doesNotMatch(src, /className=\{css\.recoveryHead\}/,
|
|
65
|
+
'不得另建 .recoveryHead 之类的第二套标题行容器(走 SectionTitle 的 action 槽)')
|
|
66
|
+
})
|