dsh-config-manager 0.5.0 → 0.7.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/client.d.ts +8 -0
- package/lib/client.js +748 -602
- package/lib/core/local-plugin-host.d.ts +9 -0
- package/lib/core/local-plugin-host.js +174 -1
- package/lib/core/messages.d.ts +7 -0
- package/lib/core/messages.js +16 -0
- package/lib/core/migration-history.d.ts +40 -0
- package/lib/core/migration-history.js +55 -0
- package/lib/core/plugin-cli.d.ts +5 -0
- package/lib/core/plugin-cli.js +11 -3
- package/lib/core/run-registry.d.ts +10 -0
- package/lib/core/run-registry.js +17 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.js +20 -19
- package/lib/profiles/dsh-profile-manager.d.ts +1 -1
- package/lib/profiles/dsh-profile-manager.js +26 -7
- package/lib/profiles/dsh-profile-shared.d.ts +3 -1
- package/lib/routes/import.js +6 -1
- package/lib/routes/route-support.d.ts +2 -1
- package/lib/routes/route-support.js +8 -3
- package/lib/routes/sync.js +5 -2
- package/lib/sync/autosync-config.d.ts +9 -1
- package/lib/sync/autosync-config.js +10 -2
- package/lib/sync/autosync-scheduler.js +18 -6
- package/lib/sync/git/git-transport.d.ts +31 -1
- package/lib/sync/git/git-transport.js +119 -23
- package/lib/sync/sync-config.d.ts +34 -3
- package/lib/sync/sync-config.js +38 -5
- package/lib/ui/sync-repository-picker.d.ts +21 -0
- package/lib/ui/sync-repository-picker.js +18 -0
- package/lib/ui/sync-settings-view.d.ts +4 -0
- package/lib/ui/sync-settings-view.js +3 -0
- package/lib/utils/remove-tree.d.ts +7 -0
- package/lib/utils/remove-tree.js +265 -0
- package/package.json +1 -1
- package/src/client/config-manager.module.css +21 -1
- package/src/client/environment/EnvironmentPanel.tsx +2 -2
- package/src/client/locales/profiles.ts +2 -0
- package/src/client/run-store.test.ts +1 -1
- package/src/client/run-store.ts +5 -0
- package/src/client/sync/ChannelConfigDialog.tsx +47 -2
- package/src/client/sync/SyncPanel.tsx +17 -30
- package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
- package/src/client/sync/SyncSettingsView.test.ts +32 -0
- package/src/client/sync/config-save-state.test.ts +99 -0
- package/src/client/sync/config-save-state.ts +69 -0
- package/src/client/sync/sync-api.ts +2 -0
- package/src/client/sync/sync-locales.ts +10 -0
- package/src/core/engine-locale.test.ts +4 -0
- package/src/core/local-plugin-host.test.ts +31 -2
- package/src/core/local-plugin-host.ts +175 -2
- package/src/core/messages.ts +16 -0
- package/src/core/migration-history.test.ts +65 -0
- package/src/core/migration-history.ts +70 -0
- package/src/core/plugin-cli.fs.test.ts +30 -3
- package/src/core/plugin-cli.ts +11 -3
- package/src/core/run-registry-runs.test.ts +26 -1
- package/src/core/run-registry.ts +18 -0
- package/src/index.sync.test.ts +27 -0
- package/src/index.ts +21 -21
- package/src/profiles/dsh-profile-manager.test.ts +20 -0
- package/src/profiles/dsh-profile-manager.ts +25 -7
- package/src/profiles/dsh-profile-shared.ts +2 -0
- package/src/routes/import.ts +6 -1
- package/src/routes/route-support.ts +7 -3
- package/src/routes/sync.ts +5 -2
- package/src/sync/autosync-config.ts +10 -2
- package/src/sync/autosync-scheduler.test.ts +61 -1
- package/src/sync/autosync-scheduler.ts +17 -5
- package/src/sync/git/git-transport.test.ts +117 -0
- package/src/sync/git/git-transport.ts +131 -23
- package/src/sync/sync-config.test.ts +59 -1
- package/src/sync/sync-config.ts +51 -5
- package/src/ui/sync-repository-picker.test.ts +34 -1
- package/src/ui/sync-repository-picker.ts +24 -0
- package/src/ui/sync-settings-view.test.ts +1 -0
- package/src/ui/sync-settings-view.ts +7 -0
- package/src/utils/remove-tree.test.ts +120 -0
- package/src/utils/remove-tree.ts +239 -0
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* - 失败**绝不静默,也绝不把拒绝抛出去**(调用点在 void 上下文里):错误同时进 toast 与内联红字
|
|
16
16
|
* (toast 会被后续提示挤掉,内联红字留在原地),宿主下发的文本一律先过 `redact()` 再渲染。
|
|
17
17
|
*/
|
|
18
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
18
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
19
19
|
import type { ChangeEvent } from 'react'
|
|
20
20
|
|
|
21
21
|
import type { TranslateNS } from '../client-types.ts'
|
|
@@ -27,7 +27,7 @@ import { toast } from '../common/toast-store.ts'
|
|
|
27
27
|
import type { SyncApi } from './sync-api.ts'
|
|
28
28
|
import {
|
|
29
29
|
formatRepoUpdatedAt, repoCreateBody, repoNameError, repoPickerOptions, repoPickerRepos,
|
|
30
|
-
repoPickerValueFor, REPO_PICKER_CREATE_VALUE, type RepoNameError, type RepoPickerRepo,
|
|
30
|
+
repoPickerValueFor, shouldAutoLoadRepos, REPO_PICKER_CREATE_VALUE, type RepoNameError, type RepoPickerRepo,
|
|
31
31
|
} from '../../ui/sync-repository-picker.ts'
|
|
32
32
|
import css from '../config-manager.module.css'
|
|
33
33
|
|
|
@@ -39,6 +39,11 @@ export interface SyncRepositoryPickerProps {
|
|
|
39
39
|
t: TranslateNS<'config-manager-sync'>
|
|
40
40
|
/** 表单里当前的仓库地址(用于回显「当前选中的是哪一个」) */
|
|
41
41
|
repoUrl: string
|
|
42
|
+
/**
|
|
43
|
+
* GitHub 登录态(null = 未知)。登录成功那一刻由父组件变 true ⇒ 本组件**自动**拉列表,
|
|
44
|
+
* 用户不必再点开下拉才知道列表出来了(2026-11-08 用户反馈)。
|
|
45
|
+
*/
|
|
46
|
+
signedIn: boolean | null
|
|
42
47
|
/** 表单繁忙(保存中 / 同步中)时禁用选择与新建 */
|
|
43
48
|
busy: boolean
|
|
44
49
|
/** 选中仓库(或新建成功)后把地址交回父组件 */
|
|
@@ -46,7 +51,7 @@ export interface SyncRepositoryPickerProps {
|
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/** 打开下拉时才拉列表(Select 的 onOpen)—— 弹窗一打开就请求会白跑一次网络。 */
|
|
49
|
-
export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: SyncRepositoryPickerProps) {
|
|
54
|
+
export function SyncRepositoryPicker({ open, api, t, repoUrl, signedIn, busy, onPick }: SyncRepositoryPickerProps) {
|
|
50
55
|
const [repos, setRepos] = useState<RepoPickerRepo[]>([])
|
|
51
56
|
const [loading, setLoading] = useState(false)
|
|
52
57
|
const [loaded, setLoaded] = useState(false)
|
|
@@ -58,20 +63,26 @@ export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: Sy
|
|
|
58
63
|
const [nameError, setNameError] = useState<RepoNameError>(null)
|
|
59
64
|
const [createError, setCreateError] = useState<string | null>(null)
|
|
60
65
|
|
|
61
|
-
/** 拉取仓库列表。**绝不抛出**(调用点在 void 上下文里,抛出的拒绝会变成 unhandled rejection)。
|
|
62
|
-
|
|
66
|
+
/** 拉取仓库列表。**绝不抛出**(调用点在 void 上下文里,抛出的拒绝会变成 unhandled rejection)。
|
|
67
|
+
* announce:手动点「刷新列表」为 true —— 列表就在眼前,但用户需要知道那一次点击真的跑了;
|
|
68
|
+
* 自动加载(打开弹窗 / 登录成功)保持静默,否则一进弹窗就弹一条没人要求的通知。
|
|
69
|
+
* 失败**始终**进 toast(内联红字会随滚动离开视野,密码/token 相关的 401 尤其要当刻可见)。 */
|
|
70
|
+
const load = useCallback(async (announce = false): Promise<void> => {
|
|
63
71
|
setLoading(true)
|
|
64
72
|
setLoadError(null)
|
|
65
73
|
try {
|
|
66
74
|
const res = await api.githubListRepositories()
|
|
67
75
|
setRepos(res.repos)
|
|
68
76
|
setLoaded(true)
|
|
77
|
+
if (announce) toast.ok(t('repoPicker.refreshed', { count: repoPickerRepos(res.repos).length }))
|
|
69
78
|
} catch (err) {
|
|
70
|
-
|
|
79
|
+
const detail = err instanceof Error ? err.message : String(err)
|
|
80
|
+
setLoadError(detail)
|
|
81
|
+
toast.error(t('repoPicker.loadFailed') + t('common.labelSeparator') + redact(detail))
|
|
71
82
|
} finally {
|
|
72
83
|
setLoading(false)
|
|
73
84
|
}
|
|
74
|
-
}, [api])
|
|
85
|
+
}, [api, t])
|
|
75
86
|
|
|
76
87
|
// 关闭时收起新建表单(下次打开从「选择」开始,不留上一次的半截输入)
|
|
77
88
|
useEffect(() => {
|
|
@@ -83,13 +94,23 @@ export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: Sy
|
|
|
83
94
|
setCreateError(null)
|
|
84
95
|
}, [open])
|
|
85
96
|
|
|
86
|
-
//
|
|
87
|
-
//
|
|
97
|
+
// 自动加载的三个触发(弹窗打开 / 登录成功瞬间 / 表单里已有地址)由 ui 层的 shouldAutoLoadRepos 判定:
|
|
98
|
+
// 父组件在轮询到 success 时把 signedIn 变 true,这里就会**自动**把列表拉出来 —— 用户不再需要
|
|
99
|
+
// 自己去点开下拉(2026-11-08 用户反馈:登录成功后界面没有任何提示,看不出到底成了没有)。
|
|
100
|
+
// 失败过不自动重试(避免每开一次弹窗打一次必然失败的请求),重试走「刷新列表」或登录态复位。
|
|
88
101
|
useEffect(() => {
|
|
89
|
-
if (!open
|
|
90
|
-
if (repoUrl.trim() === '') return
|
|
102
|
+
if (!shouldAutoLoadRepos({ open, signedIn, loaded, loading, failed: loadError !== null, repoUrl })) return
|
|
91
103
|
void load()
|
|
92
|
-
}, [open, loaded, loading, loadError, repoUrl, load])
|
|
104
|
+
}, [open, signedIn, loaded, loading, loadError, repoUrl, load])
|
|
105
|
+
|
|
106
|
+
// 登录状态由「未登录/未知」变「已登录」→ 清掉上一次的失败态(多半是未登录时的 401),让上面那条
|
|
107
|
+
// effect 立刻重试一次;否则用户登录完仍旧只看到「加载失败,可重试」。
|
|
108
|
+
const prevSignedInRef = useRef(signedIn)
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
const prev = prevSignedInRef.current
|
|
111
|
+
prevSignedInRef.current = signedIn
|
|
112
|
+
if (prev !== true && signedIn === true && loadError !== null) setLoadError(null)
|
|
113
|
+
}, [signedIn, loadError])
|
|
93
114
|
|
|
94
115
|
const pick = (value: string): void => {
|
|
95
116
|
if (value === REPO_PICKER_CREATE_VALUE) {
|
|
@@ -159,7 +180,7 @@ export function SyncRepositoryPicker({ open, api, t, repoUrl, busy, onPick }: Sy
|
|
|
159
180
|
onOpen={() => { if (!loaded && !loading) void load() }}
|
|
160
181
|
onChange={pick}
|
|
161
182
|
/>
|
|
162
|
-
<Button size="sm" loading={loading} disabled={busy} onClick={() => { void load() }}>
|
|
183
|
+
<Button size="sm" loading={loading} disabled={busy} onClick={() => { void load(true) }}>
|
|
163
184
|
{t('repoPicker.refresh')}
|
|
164
185
|
</Button>
|
|
165
186
|
</div>
|
|
@@ -170,3 +170,35 @@ test('t42: 未新增硬编码颜色(DESIGN.md:颜色/阴影走 --dsw-* token
|
|
|
170
170
|
assert.doesNotMatch(viewSource, /#[0-9a-fA-F]{3,8}\b/, '不得出现硬编码颜色值')
|
|
171
171
|
assert.doesNotMatch(viewSource, /rgba?\(/, '不得出现硬编码 rgb/rgba 颜色')
|
|
172
172
|
})
|
|
173
|
+
|
|
174
|
+
/* ------------------------------- 用户感知:登录回执 / 列表自动加载 / 自动保存回执 */
|
|
175
|
+
|
|
176
|
+
test('GitHub 登录成功必须立刻给出 toast(用户报告:成功后界面没有任何提示,只能靠猜)', () => {
|
|
177
|
+
// 成功分支原本只 patch 状态 + loadStatus:登录块在 githubSignedIn===true 时整块隐藏,
|
|
178
|
+
// 「成功」这件事在界面上完全消失,用户看不出到底成了没有。文案必须复用 githubPollMessage
|
|
179
|
+
// 的 success 分支(同一句话不在字典与 toast 里各写一遍)。
|
|
180
|
+
const start = viewSource.indexOf("if (poll.status === 'success')")
|
|
181
|
+
assert.ok(start > 0, 'success 分支必须存在')
|
|
182
|
+
const branch = viewSource.slice(start, start + 400)
|
|
183
|
+
assert.match(branch, /toast\.ok\(message\)/, '登录成功必须弹 toast(复用 githubPollMessage 的成功文案)')
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('仓库列表在登录成功那一刻自动加载,不必用户先点开下拉(2026-11-08 用户反馈)', () => {
|
|
187
|
+
// 判定收在 ui 纯逻辑里(可单测),组件只负责调用 —— 组件里不得再出现「地址为空就 return」这类内联规则。
|
|
188
|
+
const picker = readSource(fileURLToPath(new URL('./SyncRepositoryPicker.tsx', import.meta.url)))
|
|
189
|
+
assert.match(picker, /shouldAutoLoadRepos\(\{ open, signedIn, loaded, loading, failed: loadError !== null, repoUrl \}\)/, '自动加载必须经 ui/sync-repository-picker.ts 的 shouldAutoLoadRepos 判定')
|
|
190
|
+
assert.doesNotMatch(picker, /if \(repoUrl\.trim\(\) === ''\) return/, '旧的「地址为空就不加载」内联规则必须撤掉(登录成功也要能拉列表)')
|
|
191
|
+
assert.match(picker, /signedIn: boolean \| null/, '选择器必须接收登录态')
|
|
192
|
+
const dialog = readSource(fileURLToPath(new URL('./ChannelConfigDialog.tsx', import.meta.url)))
|
|
193
|
+
assert.match(dialog, /signedIn=\{githubSignedIn\}/, '弹窗必须把登录态传给仓库选择器(登录成功后翻 true ⇒ 自动加载)')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test('静默自动保存必须有可见回执(四通道共用:输入防抖保存此前成功后完全静默)', () => {
|
|
197
|
+
// 主文件:自动保存成功(announce=false)→ 计数 +1;弹窗据此闪一次「已保存」徽章。
|
|
198
|
+
assert.match(viewSource, /else setSaveTick\(\(n\) => n \+ 1\)/, '自动保存成功后必须递增 saveTick(不进 SyncUiState 契约)')
|
|
199
|
+
assert.match(viewSource, /<ChannelConfigDialog[\s\S]*?saveTick=\{saveTick\}/, 'saveTick 必须传给配置弹窗')
|
|
200
|
+
const dialog = readSource(fileURLToPath(new URL('./ChannelConfigDialog.tsx', import.meta.url)))
|
|
201
|
+
assert.match(dialog, /\{savedVisible && <span className=\{css\.savedTick\}>/, '弹窗必须渲染「已保存」回执')
|
|
202
|
+
assert.match(dialog, /t\('config\.savedTick'\)/, '回执文案必须走字典(i18n 禁硬编码)')
|
|
203
|
+
assert.match(dialog, /SAVED_TICK_MS = 2400/, '回执是瞬时提示(2.4s 后隐藏),不得常驻')
|
|
204
|
+
})
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「保存通道配置成功」的 state 演进(./config-save-state.ts)。
|
|
3
|
+
*
|
|
4
|
+
* 真机背景:四通道都有输入防抖自动保存,成功后此前完全静默;
|
|
5
|
+
* 而凭据清空与徽章合并原本内联在 SyncPanel,既挤占行数棘轮又不能单测。
|
|
6
|
+
* 这里钉住两条不可放宽的口径:
|
|
7
|
+
* ① 只清「本次确实写出去」的凭据(保存期间用户改过输入 → 保留新值);
|
|
8
|
+
* ② 响应只含布尔/非密视图,绝不把 secret 值写回 state。
|
|
9
|
+
*/
|
|
10
|
+
import test from 'node:test';
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
|
|
13
|
+
import { savedConfigState } from './config-save-state.ts';
|
|
14
|
+
import type { SavedConfigState } from './config-save-state.ts';
|
|
15
|
+
import type { SyncConfigSaveResponse, SyncStatusResponse } from './sync-api.ts';
|
|
16
|
+
|
|
17
|
+
const status = {
|
|
18
|
+
ok: true,
|
|
19
|
+
configured: false,
|
|
20
|
+
credentialConfigured: false,
|
|
21
|
+
credentialWritable: true,
|
|
22
|
+
sectionCount: 0,
|
|
23
|
+
} as SyncStatusResponse;
|
|
24
|
+
|
|
25
|
+
const base: SavedConfigState = {
|
|
26
|
+
savingConfig: true,
|
|
27
|
+
webdavPassword: '',
|
|
28
|
+
token: '',
|
|
29
|
+
s3Secret: '',
|
|
30
|
+
gistToken: '',
|
|
31
|
+
statusInfo: null,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function state(over: Partial<SavedConfigState> = {}): SavedConfigState {
|
|
35
|
+
return { ...base, ...over };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test('savingConfig 复位:无论成功与否,落库的 state 都不再处于保存中', () => {
|
|
39
|
+
const next = savedConfigState(state(), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, {});
|
|
40
|
+
assert.equal(next.savingConfig, false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('git:token 等于本次发出的值 → 清空(已写入 credentials)', () => {
|
|
44
|
+
const next = savedConfigState(state({ token: 'ghp_sent' }), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, { token: 'ghp_sent' });
|
|
45
|
+
assert.equal(next.token, '');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('git:保存期间用户改了输入(token ≠ 发出的值)→ 保留用户新输入', () => {
|
|
49
|
+
const next = savedConfigState(state({ token: 'ghp_new' }), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, { token: 'ghp_sent' });
|
|
50
|
+
assert.equal(next.token, 'ghp_new');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('webdav:password 走同一口径;未发出的空值不会被当成「清空依据」', () => {
|
|
54
|
+
const cleared = savedConfigState(state({ webdavPassword: 'pw' }), { ok: true, configured: true, transport: 'webdav', credentialConfigured: false }, { password: 'pw' });
|
|
55
|
+
assert.equal(cleared.webdavPassword, '');
|
|
56
|
+
const kept = savedConfigState(state({ webdavPassword: 'pw-other' }), { ok: true, configured: true, transport: 'webdav', credentialConfigured: false }, { password: 'pw' });
|
|
57
|
+
assert.equal(kept.webdavPassword, 'pw-other');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('s3 / gist:secret 槽位共用 → 各自按同一口径清空,互不影响别的通道', () => {
|
|
61
|
+
const next = savedConfigState(state({ s3Secret: 'sk', gistToken: 'gh' }), { ok: true, configured: true, transport: 's3', credentialConfigured: false }, { secret: 'sk' });
|
|
62
|
+
assert.equal(next.s3Secret, '', 's3 密钥已写入 → 清空');
|
|
63
|
+
assert.equal(next.gistToken, 'gh', 'gist token 不等于本次 secret → 保留');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('statusInfo 为 null(还没拉到 /sync/status)→ 不做徽章合并,留待 loadStatus', () => {
|
|
67
|
+
const next = savedConfigState(state(), { ok: true, configured: true, transport: 'git', credentialConfigured: true }, {});
|
|
68
|
+
assert.equal(next.statusInfo, null);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('徽章合并:configured / credentialConfigured 取响应;webdav 保留本机 url 与 username', () => {
|
|
72
|
+
const withWebdav = { ...status, webdav: { url: 'https://dav.example.com', username: 'me', usernameConfigured: true, passwordConfigured: false } } as SyncStatusResponse;
|
|
73
|
+
const saved: SyncConfigSaveResponse = {
|
|
74
|
+
ok: true,
|
|
75
|
+
configured: true,
|
|
76
|
+
transport: 'webdav',
|
|
77
|
+
credentialConfigured: false,
|
|
78
|
+
webdav: { usernameConfigured: true, passwordConfigured: true },
|
|
79
|
+
};
|
|
80
|
+
const next = savedConfigState(state({ statusInfo: withWebdav }), saved, {});
|
|
81
|
+
assert.equal(next.statusInfo?.configured, true);
|
|
82
|
+
assert.deepEqual(next.statusInfo?.webdav, {
|
|
83
|
+
url: 'https://dav.example.com',
|
|
84
|
+
username: 'me',
|
|
85
|
+
usernameConfigured: true,
|
|
86
|
+
passwordConfigured: true,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('徽章合并:s3 / gist 非密视图原样并入(响应里没有就不动旧值)', () => {
|
|
91
|
+
const cloudS3 = { secretStored: true } as unknown as NonNullable<SyncStatusResponse['s3']>;
|
|
92
|
+
const next = savedConfigState(
|
|
93
|
+
state({ statusInfo: status }),
|
|
94
|
+
{ ok: true, configured: true, transport: 's3', credentialConfigured: false, s3: cloudS3 },
|
|
95
|
+
{},
|
|
96
|
+
);
|
|
97
|
+
assert.equal(next.statusInfo?.s3, cloudS3);
|
|
98
|
+
assert.equal(next.statusInfo?.gist, undefined, '响应没带 gist 视图 → 不得凭空造出');
|
|
99
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「保存通道配置」成功后的本机状态合并(纯函数,node 可测)。
|
|
3
|
+
*
|
|
4
|
+
* 抽成独立文件的原因与 ./SyncRepositoryPicker.tsx 相同:SyncPanel 有行数棘轮,
|
|
5
|
+
* 而「清空已入库凭据 + 合并凭据徽章」是一段自包含的状态演算,
|
|
6
|
+
* 留在组件里既挤占行数,也无法脱离 React 单测。
|
|
7
|
+
*
|
|
8
|
+
* 口径(不得放宽):只清空**本次确实写出去**的 password / token / secret ——
|
|
9
|
+
* 保存期间用户又改了输入则保留新值;响应的凭据字段只有布尔,绝无 secret 值。
|
|
10
|
+
*/
|
|
11
|
+
import type { SyncConfigSaveResponse, SyncPushPayload, SyncStatusResponse } from './sync-api.ts'
|
|
12
|
+
|
|
13
|
+
/** 参与合并的 state 结构子集(不依赖 SyncUiState 全量定义,避免循环 import)。 */
|
|
14
|
+
export interface SavedConfigState {
|
|
15
|
+
savingConfig: boolean
|
|
16
|
+
webdavPassword: string
|
|
17
|
+
token: string
|
|
18
|
+
s3Secret: string
|
|
19
|
+
gistToken: string
|
|
20
|
+
statusInfo: SyncStatusResponse | null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 只清「本次已写入的」内存凭据:仍等于刚才发出去的值才清空,否则说明用户改过,保留。 */
|
|
24
|
+
function clearSent(value: string, sent: string | undefined): string {
|
|
25
|
+
return value !== '' && value !== sent ? value : ''
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 保存成功的 state 演进:savingConfig 复位 → 清空已写入的凭据 → 合并凭据徽章事实。
|
|
30
|
+
* @param s 保存发起时刻之后的权威 state(stateRef.current)
|
|
31
|
+
* @param saved POST /sync/config 响应(只含布尔,无 secret 值)
|
|
32
|
+
* @param sent 本次实际发出的请求体(判断「哪些值确实写出去了」)
|
|
33
|
+
*/
|
|
34
|
+
export function savedConfigState(
|
|
35
|
+
s: SavedConfigState,
|
|
36
|
+
saved: SyncConfigSaveResponse,
|
|
37
|
+
sent: SyncPushPayload,
|
|
38
|
+
): SavedConfigState {
|
|
39
|
+
const next: SavedConfigState = {
|
|
40
|
+
...s,
|
|
41
|
+
savingConfig: false,
|
|
42
|
+
webdavPassword: clearSent(s.webdavPassword, sent.password),
|
|
43
|
+
token: clearSent(s.token, sent.token),
|
|
44
|
+
// 云端点密钥同一口径:s3 与 gist 共用请求体的 secret 槽位
|
|
45
|
+
s3Secret: clearSent(s.s3Secret, sent.secret),
|
|
46
|
+
gistToken: clearSent(s.gistToken, sent.secret),
|
|
47
|
+
}
|
|
48
|
+
// 状态未知(还没拉到 /sync/status)时没有徽章可合并,等下一次 loadStatus 回填
|
|
49
|
+
if (s.statusInfo === null) return next
|
|
50
|
+
const info: SyncStatusResponse = {
|
|
51
|
+
...s.statusInfo,
|
|
52
|
+
configured: true,
|
|
53
|
+
credentialConfigured: saved.credentialConfigured,
|
|
54
|
+
}
|
|
55
|
+
// webdav 徽章:url / username 是可回显的非敏感事实,用本机已有的回填
|
|
56
|
+
if (saved.webdav !== undefined) {
|
|
57
|
+
info.webdav = {
|
|
58
|
+
url: s.statusInfo.webdav?.url,
|
|
59
|
+
username: s.statusInfo.webdav?.username,
|
|
60
|
+
usernameConfigured: saved.webdav.usernameConfigured,
|
|
61
|
+
passwordConfigured: saved.webdav.passwordConfigured,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// 云端点:响应只回非密视图 + secretStored 布尔(值永不回传),直接合并供徽章刷新
|
|
65
|
+
if (saved.s3 !== undefined) info.s3 = saved.s3
|
|
66
|
+
if (saved.gist !== undefined) info.gist = saved.gist
|
|
67
|
+
next.statusInfo = info
|
|
68
|
+
return next
|
|
69
|
+
}
|
|
@@ -68,6 +68,8 @@ export interface SyncStatusResponse {
|
|
|
68
68
|
configured: boolean;
|
|
69
69
|
/** git 通道:已配置的仓库地址(不含 token,可回显;与当前通道无关,配置过即返回) */
|
|
70
70
|
repoUrl?: string;
|
|
71
|
+
/** git 通道:仓库内子目录前缀('' / 缺省 = 仓库根;issue 131,供表单回填) */
|
|
72
|
+
subdir?: string;
|
|
71
73
|
/** git 通道:DSH credentials 中是否已存在 token(describe 只报状态,值永不返回) */
|
|
72
74
|
credentialConfigured: boolean;
|
|
73
75
|
credentialWritable: boolean;
|
|
@@ -14,6 +14,9 @@ export const zh = {
|
|
|
14
14
|
'config.title': '仓库配置',
|
|
15
15
|
'config.repoUrl': '仓库地址',
|
|
16
16
|
'config.repoUrlHint': 'Git 私有仓库地址(https / ssh / 本地路径)。认证 token 请使用下方凭据字段,不要拼入地址。',
|
|
17
|
+
'config.gitSubdir': '仓库内子目录',
|
|
18
|
+
'config.gitSubdirHint': '留空 = 直接用仓库根目录(旧行为)。填了就把同步内容放进该子目录(如「DSH备份」或「tools/dsh」):多个工具共用一个私有仓库时各自独立。切换子目录不会搬动已有快照 —— 换前缀前先重建工作副本。',
|
|
19
|
+
'config.gitSubdirPlaceholder': 'DSH备份(可选)',
|
|
17
20
|
'config.token': '认证 token',
|
|
18
21
|
'config.tokenHint': '将安全写入 DSH credentials(引用名 {ref}),不会写入同步文件或日志。留空表示沿用已保存的凭据。',
|
|
19
22
|
'config.tokenSaved': '凭据已配置',
|
|
@@ -22,6 +25,7 @@ export const zh = {
|
|
|
22
25
|
// 配置保存(自动保存 + 显式保存按钮)
|
|
23
26
|
'config.save': '立即保存',
|
|
24
27
|
'config.saveHint': '表单改动会自动保存:密码/token 安全写入 DSH credentials,不会写入同步文件或日志。',
|
|
28
|
+
'config.savedTick': '已保存',
|
|
25
29
|
// 通道选择器
|
|
26
30
|
'channel.title': '同步通道',
|
|
27
31
|
'channel.git': 'Git 私有仓库',
|
|
@@ -102,6 +106,7 @@ export const zh = {
|
|
|
102
106
|
'repoPicker.hint': '列出你 GitHub 账号下已有的私有仓库(按最近更新排序),选中即填入下方仓库地址;也可以直接在下方手填地址(ssh / 本地路径 / 不在列表里的仓库)。列表需要先登录 GitHub;新建的仓库一律为私有 —— 公开仓库会公开你的配置内容。',
|
|
103
107
|
'repoPicker.placeholder': '手动填写地址(或从上方选择)',
|
|
104
108
|
'repoPicker.refresh': '刷新列表',
|
|
109
|
+
'repoPicker.refreshed': '已刷新:{count} 个私有仓库',
|
|
105
110
|
'repoPicker.forkBadge': 'Fork',
|
|
106
111
|
'repoPicker.empty': '没有可用的私有仓库',
|
|
107
112
|
'repoPicker.loadFailed': '仓库列表加载失败,可重试或直接手填地址。',
|
|
@@ -474,6 +479,9 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
474
479
|
'config.title': 'Repository',
|
|
475
480
|
'config.repoUrl': 'Repository URL',
|
|
476
481
|
'config.repoUrlHint': 'Private Git repository URL (https / ssh / local path). Use the credential field below for the auth token; never embed it in the URL.',
|
|
482
|
+
'config.gitSubdir': 'Subdirectory in repo',
|
|
483
|
+
'config.gitSubdirHint': 'Blank = use the repository root (previous behavior). When set, sync content goes into that subdirectory (e.g. "DSH-backup" or "tools/dsh"), so several tools can share one private repo independently. Changing it does not move existing snapshots — rebuild the working copy before switching prefixes.',
|
|
484
|
+
'config.gitSubdirPlaceholder': 'DSH-backup (optional)',
|
|
477
485
|
'config.token': 'Auth token',
|
|
478
486
|
'config.tokenHint': 'Securely written into DSH credentials (ref {ref}); never written into sync files or logs. Leave blank to reuse the saved credential.',
|
|
479
487
|
'config.tokenSaved': 'Credential configured',
|
|
@@ -482,6 +490,7 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
482
490
|
// Config save (auto-save + explicit save button)
|
|
483
491
|
'config.save': 'Save now',
|
|
484
492
|
'config.saveHint': 'Form changes are saved automatically: password/token goes securely into DSH credentials, never into sync files or logs.',
|
|
493
|
+
'config.savedTick': 'Saved',
|
|
485
494
|
'channel.title': 'Sync Channel',
|
|
486
495
|
'channel.git': 'Git private repo',
|
|
487
496
|
'channel.webdav': 'WebDAV server',
|
|
@@ -559,6 +568,7 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
559
568
|
'repoPicker.hint': 'Lists the existing private repositories in your GitHub account (most recently updated first); picking one fills the repository URL below. You can still type an address by hand (ssh / local path / repositories not in the list). The list requires GitHub sign-in. Newly created repositories are always private — a public repository would expose your config contents.',
|
|
560
569
|
'repoPicker.placeholder': 'Type an address (or pick above)',
|
|
561
570
|
'repoPicker.refresh': 'Refresh list',
|
|
571
|
+
'repoPicker.refreshed': 'Refreshed: {count} private repositories',
|
|
562
572
|
'repoPicker.forkBadge': 'Fork',
|
|
563
573
|
'repoPicker.empty': 'No private repository available',
|
|
564
574
|
'repoPicker.loadFailed': 'Could not load the repository list — retry, or type the address below.',
|
|
@@ -173,6 +173,10 @@ test('t2 新增的 host.* 键:zh 逐字保留既有文案、en 非空且无 CJ
|
|
|
173
173
|
['host.snapshotPruneSummary', '自动保留清理删除 {count} 个旧快照'],
|
|
174
174
|
['host.autosyncSummary', '自动同步 {direction}{transportSuffix}'],
|
|
175
175
|
['host.autosyncTransportSuffix', '({transport})'],
|
|
176
|
+
['host.autosyncDirectionPush', '上传'],
|
|
177
|
+
['host.autosyncDirectionPull', '下载'],
|
|
178
|
+
['host.autosyncDirectionBoth', '双向'],
|
|
179
|
+
['host.autosyncDirectionNone', '检查'],
|
|
176
180
|
];
|
|
177
181
|
const zhDict = zh as Readonly<Record<string, string>>;
|
|
178
182
|
const enDict = en as Readonly<Record<string, string>>;
|
|
@@ -29,6 +29,8 @@ async function fixture(t: { after: (fn: () => Promise<void>) => void }, opts: {
|
|
|
29
29
|
tarballBytes?: number;
|
|
30
30
|
oversizeTtlMs?: number;
|
|
31
31
|
maxTarballBytes?: number;
|
|
32
|
+
/** 内容缓存上限(字节;0 = 关闭) */
|
|
33
|
+
packedCacheMaxBytes?: number;
|
|
32
34
|
} = {}): Promise<Fixture> {
|
|
33
35
|
const root = await fsp.mkdtemp(path.join(os.tmpdir(), 'dshcm-packhost-'));
|
|
34
36
|
t.after(async () => { await fsp.rm(root, { recursive: true, force: true }); });
|
|
@@ -54,6 +56,7 @@ async function fixture(t: { after: (fn: () => Promise<void>) => void }, opts: {
|
|
|
54
56
|
exec,
|
|
55
57
|
maxTarballBytes: opts.maxTarballBytes ?? 1024,
|
|
56
58
|
...(opts.oversizeTtlMs === undefined ? {} : { oversizeTtlMs: opts.oversizeTtlMs }),
|
|
59
|
+
...(opts.packedCacheMaxBytes === undefined ? {} : { packedCacheMaxBytes: opts.packedCacheMaxBytes }),
|
|
57
60
|
});
|
|
58
61
|
return {
|
|
59
62
|
hook,
|
|
@@ -115,14 +118,40 @@ test('oversizeTtlMs=0:关闭缓存,两轮都真打(测试与排障用)',
|
|
|
115
118
|
assert.equal(fx.calls(), 2);
|
|
116
119
|
});
|
|
117
120
|
|
|
118
|
-
test('未超限:正常产出 packed
|
|
121
|
+
test('未超限:正常产出 packed;源没变时第二轮走内容缓存,不再 npm pack', async (t) => {
|
|
119
122
|
const fx = await fixture(t, { tarballBytes: 256, maxTarballBytes: 1024 });
|
|
120
123
|
const first = await fx.hook(fx.plugins, ctx);
|
|
121
124
|
assert.equal(first.packed.length, 1);
|
|
122
125
|
assert.equal(first.oversize.length, 0);
|
|
123
126
|
assert.equal(first.warnings.length, 0);
|
|
127
|
+
|
|
128
|
+
// 2026-11-09:内容缓存上线后,源没变的第二轮直接复用 tarball 字节(此前是每轮都真打)。
|
|
129
|
+
const second = await fx.hook(fx.plugins, ctx);
|
|
130
|
+
assert.equal(fx.calls(), 1, '源没变 → 复用缓存,不再 spawn npm pack');
|
|
131
|
+
assert.equal(second.packed.length, 1, '缓存命中同样要产出 packed(备份缺它会把插件丢掉)');
|
|
132
|
+
assert.deepEqual(second.packed[0]?.data, first.packed[0]?.data, '复用的必须是同一份字节');
|
|
133
|
+
assert.equal(second.packed[0]?.rewrittenSpec, first.packed[0]?.rewrittenSpec);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('内容缓存:源目录里改一个文件(lib/ 里那种不改目录 mtime 的改动)→ 必须重新打包', async (t) => {
|
|
137
|
+
const fx = await fixture(t, { tarballBytes: 256, maxTarballBytes: 1024 });
|
|
138
|
+
await fsp.mkdir(path.join(fx.sourceDir, 'lib'), { recursive: true });
|
|
139
|
+
await fsp.writeFile(path.join(fx.sourceDir, 'lib', 'index.js'), 'export const a = 1\n');
|
|
124
140
|
await fx.hook(fx.plugins, ctx);
|
|
125
|
-
assert.equal(fx.calls(),
|
|
141
|
+
assert.equal(fx.calls(), 1);
|
|
142
|
+
|
|
143
|
+
const file = path.join(fx.sourceDir, 'lib', 'index.js');
|
|
144
|
+
const future = new Date(Date.now() + 5000);
|
|
145
|
+
await fsp.utimes(file, future, future);
|
|
146
|
+
await fx.hook(fx.plugins, ctx);
|
|
147
|
+
assert.equal(fx.calls(), 2, '内容指纹按文件级 rel/size/mtime 算,改文件必须重打包(不能把旧 tarball 当当前内容)');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('内容缓存:packedCacheMaxBytes=0 → 关闭,两轮都真打', async (t) => {
|
|
151
|
+
const fx = await fixture(t, { tarballBytes: 256, maxTarballBytes: 1024, packedCacheMaxBytes: 0 });
|
|
152
|
+
await fx.hook(fx.plugins, ctx);
|
|
153
|
+
await fx.hook(fx.plugins, ctx);
|
|
154
|
+
assert.equal(fx.calls(), 2, '关闭缓存时行为与改造前一致');
|
|
126
155
|
});
|
|
127
156
|
|
|
128
157
|
test('无本地源插件:零 spawn、零目录创建', async (t) => {
|