dsh-codearts-dock 1.0.0 → 1.0.1
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/DISCLAIMER.md +2 -2
- package/README.md +14 -17
- package/SECURITY.md +2 -4
- package/client.js +422 -450
- package/docs/DETAIL.md +4 -5
- package/docs/DETAIL.zh.md +4 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -2
- package/src/adapter.js +0 -27
- package/src/checkin.js +5 -5
- package/src/features.js +4 -4
- package/src/health.js +0 -3
- package/src/index.js +22 -101
- package/src/preferences.js +9 -12
- package/test/accounts.test.mjs +22 -0
- package/test/features.test.mjs +59 -76
- package/test/registration.test.mjs +3 -1
- package/test/ui.test.mjs +425 -63
- package/test/visual.test.mjs +16 -34
- package/src/usage.js +0 -55
package/test/ui.test.mjs
CHANGED
|
@@ -12,13 +12,14 @@ const initialModels = {
|
|
|
12
12
|
],
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function harness() {
|
|
15
|
+
function harness(surface = 'settings', rootProps = {}) {
|
|
16
16
|
const postResponses = new Map()
|
|
17
17
|
const confirmations = []
|
|
18
|
-
const controls = { confirmAnswer: true }
|
|
18
|
+
const controls = { confirmAnswer: true, now: Date.now() }
|
|
19
19
|
let active
|
|
20
20
|
let cursor = 0
|
|
21
21
|
let SettingsPage
|
|
22
|
+
let ComposerChip
|
|
22
23
|
let currentTree
|
|
23
24
|
const instances = new Map()
|
|
24
25
|
const effects = []
|
|
@@ -26,6 +27,8 @@ function harness() {
|
|
|
26
27
|
const pending = []
|
|
27
28
|
const writes = []
|
|
28
29
|
const copied = []
|
|
30
|
+
const downloads = []
|
|
31
|
+
const blobs = new Map()
|
|
29
32
|
const state = () => {
|
|
30
33
|
const index = cursor++
|
|
31
34
|
return [active, index]
|
|
@@ -68,7 +71,20 @@ function harness() {
|
|
|
68
71
|
}
|
|
69
72
|
const context = vm.createContext({
|
|
70
73
|
console, AbortController,
|
|
71
|
-
|
|
74
|
+
Date: class extends Date { static now() { return controls.now } },
|
|
75
|
+
Blob,
|
|
76
|
+
URL: {
|
|
77
|
+
createObjectURL: (blob) => { const url = `blob:offline-${blobs.size}`; blobs.set(url, blob); return url },
|
|
78
|
+
revokeObjectURL: (url) => blobs.delete(url),
|
|
79
|
+
},
|
|
80
|
+
document: {
|
|
81
|
+
documentElement: { lang: 'zh-CN' }, body: { appendChild() {} },
|
|
82
|
+
addEventListener() {}, removeEventListener() {},
|
|
83
|
+
createElement: (tag) => {
|
|
84
|
+
assert.equal(tag, 'a')
|
|
85
|
+
return { click() { downloads.push({ name: this.download, blob: blobs.get(this.href) }) }, remove() {} }
|
|
86
|
+
},
|
|
87
|
+
},
|
|
72
88
|
navigator: { language: 'zh-CN', clipboard: { writeText: async (text) => copied.push(text) } },
|
|
73
89
|
setInterval: (fn) => { intervals.push(fn); return intervals.length }, clearInterval() {},
|
|
74
90
|
fetch: async (url, options = {}) => {
|
|
@@ -77,19 +93,20 @@ function harness() {
|
|
|
77
93
|
const body = JSON.parse(options.body)
|
|
78
94
|
writes.push({ path, body })
|
|
79
95
|
const reply = postResponses.get(path)
|
|
80
|
-
const result = typeof reply === 'function' ? reply(body) : reply ?? { ok: true, enabled: 1 }
|
|
96
|
+
const result = await (typeof reply === 'function' ? reply(body) : reply ?? { ok: true, enabled: 1 })
|
|
81
97
|
return { ok: true, text: async () => JSON.stringify(result) }
|
|
82
98
|
}
|
|
83
99
|
return new Promise((resolve, reject) => {
|
|
84
100
|
pending.push({ path, options, resolve: (body) => resolve({ ok: true, text: async () => JSON.stringify(body) }), reject })
|
|
85
101
|
})
|
|
86
102
|
},
|
|
87
|
-
window: { confirm: (text) => { confirmations.push(text); return controls.confirmAnswer }, __ModuleLoader__: { load: (definition) => {
|
|
103
|
+
window: { setTimeout: (fn) => fn(), confirm: (text) => { confirmations.push(text); return controls.confirmAnswer }, __ModuleLoader__: { load: (definition) => {
|
|
88
104
|
const module = definition.factory(() => React)
|
|
89
105
|
module.apply({ effect() {}, slots: {
|
|
90
106
|
inject: (_, fn) => fn(),
|
|
91
107
|
register: (seat, component) => {
|
|
92
108
|
if (seat.name === 'settings.section') SettingsPage = component
|
|
109
|
+
if (seat.name === 'conversation.input.right') ComposerChip = component
|
|
93
110
|
return () => {}
|
|
94
111
|
},
|
|
95
112
|
} })
|
|
@@ -116,7 +133,7 @@ function harness() {
|
|
|
116
133
|
const result = { ...element, props: { ...element.props, children: element.props.children.map((child, i) => resolve(child, `${path}/${child?.props?.key ?? i}`)) } }
|
|
117
134
|
return result
|
|
118
135
|
}
|
|
119
|
-
currentTree = resolve(React.createElement(SettingsPage), 'root')
|
|
136
|
+
currentTree = resolve(React.createElement(surface === 'settings' ? SettingsPage : ComposerChip, rootProps), 'root')
|
|
120
137
|
for (const [key, instance] of instances) {
|
|
121
138
|
if (!live.has(key)) {
|
|
122
139
|
instance.hooks.forEach((hook) => hook?.cleanup?.())
|
|
@@ -143,11 +160,19 @@ function harness() {
|
|
|
143
160
|
await new Promise(setImmediate)
|
|
144
161
|
render()
|
|
145
162
|
}
|
|
163
|
+
async function fail(path) {
|
|
164
|
+
const index = pending.findIndex((request) => request.path === path)
|
|
165
|
+
assert.notEqual(index, -1, `Missing request ${path}`)
|
|
166
|
+
pending.splice(index, 1)[0].reject(new Error('Offline refresh failure'))
|
|
167
|
+
await new Promise(setImmediate)
|
|
168
|
+
render()
|
|
169
|
+
}
|
|
146
170
|
render()
|
|
147
|
-
return { render, findAll, one, text, settle, pending, writes, intervals, copied, postResponses, confirmations, controls }
|
|
171
|
+
return { render, findAll, one, text, settle, fail, pending, writes, intervals, copied, postResponses, confirmations, controls, downloads }
|
|
148
172
|
}
|
|
149
173
|
|
|
150
174
|
const app = harness()
|
|
175
|
+
assert.deepEqual(app.pending.map((request) => request.path).sort(), ['/account', '/accounts', '/models', '/status'])
|
|
151
176
|
const tab = (id) => app.one((node) => node.props.role === 'tab' && node.props.id.endsWith(`-tab-${id}`))
|
|
152
177
|
const panel = (id) => app.one((node) => node.props.role === 'tabpanel' && node.props.id.endsWith(`-panel-${id}`))
|
|
153
178
|
const button = (label) => app.one((node) => node.type === 'button' && app.text(node) === label)
|
|
@@ -160,11 +185,11 @@ app.render()
|
|
|
160
185
|
assert.equal(panel('models').props.hidden, false)
|
|
161
186
|
assert.match(app.text(panel('models')), /本地缓存/)
|
|
162
187
|
let focused = false
|
|
163
|
-
tab('
|
|
188
|
+
tab('diagnostics').props.ref({ focus: () => { focused = true } })
|
|
164
189
|
tab('models').props.onKeyDown({ key: 'ArrowRight', preventDefault() {} })
|
|
165
190
|
app.render()
|
|
166
191
|
assert.equal(focused, true)
|
|
167
|
-
assert.equal(panel('
|
|
192
|
+
assert.equal(panel('diagnostics').props.hidden, false)
|
|
168
193
|
assert.match(app.text(panel('diagnostics')), /加载中/)
|
|
169
194
|
console.log('✓ fast model reads render before account probes; tab arrows move focus')
|
|
170
195
|
|
|
@@ -179,7 +204,7 @@ assert.equal(reasoner().props.checked, false)
|
|
|
179
204
|
assert.match(app.text(panel('models')), /未保存/)
|
|
180
205
|
console.log('✓ switching panels preserves the model draft')
|
|
181
206
|
|
|
182
|
-
const savePromise = button('
|
|
207
|
+
const savePromise = button('保存模型配置').props.onClick()
|
|
183
208
|
await new Promise(setImmediate)
|
|
184
209
|
assert.equal(app.writes[0].path, '/models/select')
|
|
185
210
|
assert.deepEqual(app.writes[0].body.enabledIds, ['coder'])
|
|
@@ -189,7 +214,7 @@ assert.equal(app.pending.filter((entry) => entry.path === '/account').length, 1)
|
|
|
189
214
|
await app.settle('/models', { ...initialModels, enabledIds: ['coder'] })
|
|
190
215
|
await savePromise
|
|
191
216
|
app.render()
|
|
192
|
-
assert.equal(button('
|
|
217
|
+
assert.equal(button('保存模型配置').props.disabled, true)
|
|
193
218
|
assert.match(app.text(panel('models')), /已保存/)
|
|
194
219
|
console.log('✓ save preserves existing overrides and completes without waiting for account probes')
|
|
195
220
|
|
|
@@ -232,13 +257,7 @@ const fixtures = {
|
|
|
232
257
|
] },
|
|
233
258
|
'/status': status,
|
|
234
259
|
'/account': { ok: true, credit: { total: 1000, remain: 99 } },
|
|
235
|
-
'/accounts': { ok: true, activeId: 'account-1', accounts: [{ id: 'account-1', label: 'Example', ak: 'TEST…MASK', isActive: true, health: { state: 'credentials', checkedAt:
|
|
236
|
-
'/preferences': { ok: true, preferences: { lowBalanceEnabled: true, lowBalanceThreshold: 500, usageEnabled: true } },
|
|
237
|
-
'/usage': { ok: true, enabled: true, records: [
|
|
238
|
-
{ id: 'one', at: Date.now(), model: 'reasoner', durationMs: 1000, inputTokens: 8, outputTokens: 2, status: 'success' },
|
|
239
|
-
{ id: 'two', at: Date.now(), model: 'coder', durationMs: 20, inputTokens: null, outputTokens: null, status: 'error' },
|
|
240
|
-
{ id: 'three', at: Date.now(), model: 'reasoner', durationMs: 20, status: 'aborted' },
|
|
241
|
-
] },
|
|
260
|
+
'/accounts': { ok: true, activeId: 'account-1', accounts: [{ id: 'account-1', label: 'Example', ak: 'TEST…MASK', isActive: true, health: { state: 'credentials', checkedAt: features.controls.now - 300000 }, error: 'RAW_GATEWAY_ERROR_FOR_DETAILS', credit: null, checkin: null }] },
|
|
242
261
|
}
|
|
243
262
|
const ft = (id) => features.one((node) => node.props.role === 'tab' && node.props.id.endsWith(`-tab-${id}`))
|
|
244
263
|
const fp = (id) => features.one((node) => node.props.role === 'tabpanel' && node.props.id.endsWith(`-panel-${id}`))
|
|
@@ -268,22 +287,23 @@ async function act(fn) {
|
|
|
268
287
|
}
|
|
269
288
|
await drain()
|
|
270
289
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
features.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
290
|
+
assert.equal(features.findAll((node) => node.props.role === 'tab').length, 3)
|
|
291
|
+
assert.doesNotMatch(features.text(fp('account')), /余额提醒|自动签到/)
|
|
292
|
+
assert.ok(!features.pending.some((request) => ['/usage', '/preferences'].includes(request.path)))
|
|
293
|
+
console.log('✓ settings retain three tabs and never request retired alert or history data')
|
|
294
|
+
const checkTime = () => features.one((node) => node.type === 'time')
|
|
295
|
+
assert.equal(features.text(checkTime()), '5 分钟前')
|
|
296
|
+
assert.match(checkTime().props.title, /最近检查/)
|
|
297
|
+
assert.equal(checkTime().props.dateTime, new Date(features.controls.now - 300000).toISOString())
|
|
298
|
+
features.controls.now += 60000
|
|
299
|
+
features.intervals[1]()
|
|
277
300
|
features.render()
|
|
278
|
-
features.
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
assert.deepEqual(features.writes.at(-1), { path: '/preferences/save', body: { lowBalanceEnabled: true, lowBalanceThreshold: 250 } })
|
|
285
|
-
assert.equal(labelled('提醒阈值(积分)').props.value, '250')
|
|
286
|
-
console.log('✓ balance alerts reject invalid thresholds and persist the edited preferences')
|
|
301
|
+
assert.equal(features.text(checkTime()), '6 分钟前')
|
|
302
|
+
const accountError = features.one((node) => node.type === 'details' && node.props.className === 'dca-details dca-account-error')
|
|
303
|
+
assert.notEqual(accountError.props.open, true)
|
|
304
|
+
assert.match(features.text(accountError), /RAW_GATEWAY_ERROR_FOR_DETAILS/)
|
|
305
|
+
console.log('✓ account check times advance without fetching; raw errors stay in collapsed details')
|
|
306
|
+
|
|
287
307
|
|
|
288
308
|
fb('更新凭证').props.onClick()
|
|
289
309
|
features.render(); features.render()
|
|
@@ -292,6 +312,14 @@ features.postResponses.set('/accounts/check', { ok: true, account: { label: 'Exa
|
|
|
292
312
|
await act(() => fb('重新检查').props.onClick())
|
|
293
313
|
assert.ok(features.writes.some((entry) => entry.path === '/accounts/check' && entry.body.id === 'account-1'))
|
|
294
314
|
console.log('✓ unhealthy accounts expose credential repair and account-specific rechecks')
|
|
315
|
+
assert.ok(!features.writes.some((entry) => entry.path.startsWith('/checkin')), 'loading and rechecking accounts never claims benefits')
|
|
316
|
+
features.postResponses.set('/checkin/claim-all', { ok: true, summary: { claimed: 1, failures: [] } })
|
|
317
|
+
await act(() => fb('一键签到').props.onClick())
|
|
318
|
+
const manualClaims = features.writes.filter((entry) => entry.path.startsWith('/checkin'))
|
|
319
|
+
assert.equal(manualClaims.length, 1)
|
|
320
|
+
assert.deepEqual(manualClaims[0], { path: '/checkin/claim-all', body: {} })
|
|
321
|
+
console.log('✓ check-in only runs on an explicit click and never sends automation preferences')
|
|
322
|
+
|
|
295
323
|
|
|
296
324
|
ft('models').props.onClick(); features.render()
|
|
297
325
|
const capability = (label, value) => { labelled(label).props.onChange({ target: { checked: value } }); features.render() }
|
|
@@ -302,10 +330,10 @@ capability('支持图片', false)
|
|
|
302
330
|
capability('支持推理', true)
|
|
303
331
|
assert.equal(features.findAll((node) => node.type === 'input' && node.props['aria-label'] === 'Free').length, 0)
|
|
304
332
|
capability('支持推理', false)
|
|
333
|
+
assert.equal(features.findAll((node) => node.type === 'input' && node.props.maxLength === 48).length, 0)
|
|
305
334
|
const presetSelect = () => features.one((node) => node.type === 'select' && node.props['aria-label'] === '模型配置预设')
|
|
306
335
|
presetSelect().props.onChange({ target: { value: 'builtin:daily' } }); features.render()
|
|
307
336
|
const writesBeforePreview = features.writes.length
|
|
308
|
-
fb('预览配置').props.onClick(); features.render()
|
|
309
337
|
const previewList = features.one((node) => node.type === 'ul' && node.props.className === 'dca-preset-preview')
|
|
310
338
|
assert.match(features.text(previewList), /Free/)
|
|
311
339
|
assert.doesNotMatch(features.text(previewList), /Expensive/)
|
|
@@ -314,57 +342,391 @@ fb('应用到草稿').props.onClick(); features.render()
|
|
|
314
342
|
assert.equal(features.writes.length, writesBeforePreview)
|
|
315
343
|
assert.equal(features.one((node) => node.type === 'input' && node.props['aria-label'] === 'Expensive').props.checked, false)
|
|
316
344
|
assert.match(features.text(fp('models')), /未保存/)
|
|
345
|
+
fb('保存为预设').props.onClick(); features.render()
|
|
317
346
|
const presetName = features.one((node) => node.type === 'input' && node.props.maxLength === 48)
|
|
318
347
|
presetName.props.onChange({ target: { value: 'My draft' } }); features.render()
|
|
319
348
|
features.postResponses.set('/presets', (body) => ({ ok: true, presets: [{ ...body, id: 'custom-1' }] }))
|
|
320
|
-
await act(() =>
|
|
349
|
+
await act(() => features.one((node) => node.type === 'form' && features.findAll((child) => child.type === 'input' && child.props.maxLength === 48, node).length === 1).props.onSubmit({ preventDefault() {} }))
|
|
321
350
|
assert.equal(features.writes.at(-1).path, '/presets')
|
|
322
351
|
assert.equal(features.writes.at(-1).body.modelOverrides.reasoner.allowOff, false)
|
|
323
352
|
assert.ok(!features.writes.slice(writesBeforePreview).some((entry) => entry.path === '/models/select'))
|
|
324
353
|
console.log('✓ capability filters and presets preserve drafts, include zero-cost models, and never auto-save the live selection')
|
|
325
354
|
|
|
326
|
-
ft('usage').props.onClick(); features.render()
|
|
327
|
-
const usageRows = () => features.findAll((node) => node.type === 'tbody', fp('usage'))[0].props.children.filter(Boolean)
|
|
328
|
-
assert.equal(usageRows().length, 3)
|
|
329
|
-
features.one((node) => node.type === 'input' && node.props['aria-label'] === '按模型搜索记录').props.onChange({ target: { value: 'reasoner' } }); features.render()
|
|
330
|
-
assert.equal(usageRows().length, 2)
|
|
331
|
-
features.one((node) => node.type === 'select' && node.props['aria-label'] === '结果').props.onChange({ target: { value: 'success' } }); features.render()
|
|
332
|
-
assert.equal(usageRows().length, 1)
|
|
333
|
-
await act(() => labelled('记录最近 200 次请求').props.onChange())
|
|
334
|
-
assert.equal(labelled('记录最近 200 次请求').props.checked, false)
|
|
335
|
-
features.controls.confirmAnswer = false
|
|
336
|
-
const beforeCancel = features.writes.length
|
|
337
|
-
await act(() => fb('清空记录').props.onClick())
|
|
338
|
-
assert.equal(features.writes.length, beforeCancel)
|
|
339
|
-
features.controls.confirmAnswer = true
|
|
340
|
-
features.postResponses.set('/usage/clear', () => { fixtures['/usage'].records = []; return { ok: true } })
|
|
341
|
-
await act(() => fb('清空记录').props.onClick())
|
|
342
|
-
assert.equal(usageRows().length, 0)
|
|
343
|
-
assert.match(features.text(fp('usage')), /暂无符合条件的记录/)
|
|
344
|
-
console.log('✓ usage filters, opt-out, clear confirmation, and empty states behave correctly')
|
|
345
|
-
|
|
346
355
|
ft('account').props.onClick(); features.render()
|
|
347
|
-
|
|
356
|
+
const backupRoot = () => features.one((node) => node.type === 'details' && node.props.className === 'dca-card dca-details' && features.findAll((child) => child.type === 'summary' && features.text(child) === '配置备份与迁移', node).length === 1)
|
|
357
|
+
assert.equal(features.findAll((node) => node.type === 'input' && node.props.type === 'password' && node.props.autoComplete === 'new-password').length, 0)
|
|
358
|
+
assert.equal(features.findAll((node) => node.type === 'textarea' && node.props.rows === 4).length, 0, 'restore controls are absent in export mode')
|
|
359
|
+
assert.equal(fb('下载备份').props.disabled, false, 'config-only export needs no password by default')
|
|
360
|
+
labelled('加密备份').props.onChange({ target: { checked: true } }); features.render()
|
|
348
361
|
assert.equal(fb('下载备份').props.disabled, true)
|
|
349
|
-
labelled('
|
|
362
|
+
labelled('加密密码').props.onChange({ target: { value: 'password-123' } })
|
|
350
363
|
labelled('确认加密密码').props.onChange({ target: { value: 'different' } }); features.render()
|
|
351
364
|
assert.equal(fb('下载备份').props.disabled, true)
|
|
352
365
|
labelled('确认加密密码').props.onChange({ target: { value: 'password-123' } }); features.render()
|
|
366
|
+
labelled('加密备份').props.onChange({ target: { checked: false } }); features.render()
|
|
367
|
+
assert.equal(features.findAll((node) => node.type === 'input' && node.props.autoComplete === 'new-password').length, 0)
|
|
368
|
+
labelled('包含账号凭证(AK/SK)').props.onChange({ target: { checked: true } }); features.render()
|
|
369
|
+
assert.equal(fb('下载备份').props.disabled, true)
|
|
370
|
+
assert.equal(labelled('加密密码').props.value, '', 'turning off encryption clears its password')
|
|
371
|
+
labelled('加密密码').props.onChange({ target: { value: 'password-123' } })
|
|
372
|
+
labelled('确认加密密码').props.onChange({ target: { value: 'password-123' } }); features.render()
|
|
353
373
|
assert.equal(fb('下载备份').props.disabled, false)
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
features.postResponses.set('/backup/
|
|
374
|
+
const backupForm = () => features.one((node) => node.type === 'form' && features.findAll((child) => child.type === 'button' && features.text(child) === '下载备份', node).length === 1)
|
|
375
|
+
const exportedEnvelope = { format: 'dsh-connect-codearts-encrypted', version: 1, data: 'fake-test-ciphertext' }
|
|
376
|
+
features.postResponses.set('/backup/export', { ok: true, backup: exportedEnvelope })
|
|
377
|
+
await act(() => backupForm().props.onSubmit({ preventDefault() {} }))
|
|
378
|
+
assert.equal(features.writes.at(-1).body.includeCredentials, true)
|
|
379
|
+
assert.equal(features.writes.at(-1).body.password, 'password-123')
|
|
380
|
+
assert.equal(features.downloads.length, 1)
|
|
381
|
+
assert.match(features.downloads[0].name, /^codearts-backup-\d{4}-\d{2}-\d{2}\.json$/)
|
|
382
|
+
assert.deepEqual(JSON.parse(await features.downloads[0].blob.text()), exportedEnvelope)
|
|
383
|
+
assert.equal(labelled('加密密码').props.value, '')
|
|
384
|
+
assert.equal(labelled('确认加密密码').props.value, '')
|
|
385
|
+
fb('恢复配置').props.onClick(); features.render()
|
|
386
|
+
assert.equal(features.findAll((node) => node.type === 'button' && features.text(node) === '下载备份').length, 0)
|
|
387
|
+
assert.equal(features.findAll((node) => node.type === 'input' && node.props.autoComplete === 'off' && node.props.type === 'password', backupRoot()).length, 0)
|
|
388
|
+
const advancedPaste = features.one((node) => node.type === 'details' && features.findAll((child) => child.type === 'summary' && features.text(child) === '粘贴 JSON(高级)', node).length === 1 && features.findAll((child) => child.type === 'textarea', node).length === 1 && node.props.className === 'dca-details')
|
|
389
|
+
assert.notEqual(advancedPaste.props.open, true)
|
|
390
|
+
const backupText = JSON.stringify(exportedEnvelope)
|
|
391
|
+
const inputFile = () => features.one((node) => node.type === 'input' && node.props.type === 'file' && node.props.accept === '.json,application/json')
|
|
392
|
+
await act(() => inputFile().props.onChange({ target: { value: 'file.json', files: [{ name: 'my-backup.json', size: backupText.length, text: async () => backupText }] } }))
|
|
393
|
+
assert.match(features.text(fp('account')), /已选择:my-backup.json/)
|
|
394
|
+
assert.equal(fb('读取并预览').props.disabled, true, 'encrypted files require a password')
|
|
395
|
+
labelled('解密密码').props.onChange({ target: { value: 'password-123' } }); features.render()
|
|
396
|
+
features.postResponses.set('/backup/preview', { ok: true, changes: ['composerChip'], preferences: { composerChip: false }, accounts: { added: 1, updated: 0 } })
|
|
357
397
|
await act(() => fb('读取并预览').props.onClick())
|
|
358
398
|
assert.equal(features.writes.at(-1).path, '/backup/preview')
|
|
359
399
|
assert.ok(!features.writes.some((entry) => entry.path === '/backup/restore'))
|
|
360
|
-
labelled('
|
|
400
|
+
labelled('解密密码').props.onChange({ target: { value: 'new-password' } }); features.render()
|
|
361
401
|
assert.equal(features.findAll((node) => node.type === 'button' && features.text(node) === '确认恢复').length, 0)
|
|
362
402
|
await act(() => fb('读取并预览').props.onClick())
|
|
363
403
|
features.postResponses.set('/backup/restore', { ok: true, added: 1, updated: 0 })
|
|
364
404
|
await act(() => fb('确认恢复').props.onClick())
|
|
365
405
|
assert.equal(features.writes.at(-1).path, '/backup/restore')
|
|
366
406
|
assert.equal(features.writes.at(-1).body.text, backupText)
|
|
407
|
+
assert.equal(features.writes.at(-1).body.password, 'new-password')
|
|
408
|
+
assert.equal(labelled('备份内容(也可粘贴 JSON)', 'textarea').props.value, '')
|
|
409
|
+
assert.equal(features.findAll((node) => node.type === 'input' && node.props.autoComplete === 'off' && node.props.type === 'password', backupRoot()).length, 0)
|
|
410
|
+
console.log('✓ backup modes reveal only relevant forms; encryption, file selection, restore preview and input clearing work')
|
|
411
|
+
|
|
412
|
+
// Failed reads preserve input; selecting an invalid replacement never leaves a stale backup ready to restore.
|
|
413
|
+
labelled('备份内容(也可粘贴 JSON)', 'textarea').props.onChange({ target: { value: backupText } }); features.render()
|
|
414
|
+
labelled('解密密码').props.onChange({ target: { value: 'wrong-password' } }); features.render()
|
|
415
|
+
features.postResponses.set('/backup/preview', { ok: false, error: '密码错误,或备份文件已损坏' })
|
|
416
|
+
const restoreCount = features.writes.filter((entry) => entry.path === '/backup/restore').length
|
|
417
|
+
await act(() => fb('读取并预览').props.onClick())
|
|
418
|
+
assert.match(features.text(fp('account')), /密码错误/)
|
|
419
|
+
assert.equal(labelled('备份内容(也可粘贴 JSON)', 'textarea').props.value, backupText)
|
|
420
|
+
assert.equal(labelled('解密密码').props.value, 'wrong-password')
|
|
421
|
+
assert.equal(features.findAll((node) => node.type === 'button' && features.text(node) === '确认恢复').length, 0)
|
|
422
|
+
assert.equal(features.writes.filter((entry) => entry.path === '/backup/restore').length, restoreCount)
|
|
423
|
+
await act(() => inputFile().props.onChange({ target: { value: 'too-big.json', files: [{ name: 'too-big.json', size: 800000 }] } }))
|
|
424
|
+
assert.match(features.text(fp('account')), /备份文件过大/)
|
|
367
425
|
assert.equal(labelled('备份内容(也可粘贴 JSON)', 'textarea').props.value, '')
|
|
368
|
-
assert.equal(
|
|
369
|
-
|
|
426
|
+
assert.equal(fb('读取并预览').props.disabled, true)
|
|
427
|
+
const plainBackup = '{"format":"dsh-connect-codearts-backup","version":1,"preferences":{}}'
|
|
428
|
+
labelled('备份内容(也可粘贴 JSON)', 'textarea').props.onChange({ target: { value: plainBackup } }); features.render()
|
|
429
|
+
assert.equal(features.findAll((node) => node.type === 'input' && node.props.autoComplete === 'off' && node.props.type === 'password', backupRoot()).length, 0)
|
|
430
|
+
features.postResponses.set('/backup/preview', { ok: true, changes: [], preferences: {}, accounts: { added: 0, updated: 0 } })
|
|
431
|
+
await act(() => fb('读取并预览').props.onClick())
|
|
432
|
+
assert.equal(features.writes.at(-1).body.password, '')
|
|
433
|
+
fb('导出配置').props.onClick(); features.render()
|
|
434
|
+
fb('恢复配置').props.onClick(); features.render()
|
|
435
|
+
assert.equal(features.findAll((node) => node.type === 'button' && features.text(node) === '确认恢复').length, 0, 'changing modes invalidates the preview')
|
|
436
|
+
console.log('✓ malformed replacements cannot restore stale contents; plain backups skip password inputs; mode changes invalidate previews')
|
|
437
|
+
|
|
438
|
+
// The composer is a compact account picker, not a second diagnostics page.
|
|
439
|
+
let openedSettings = 0
|
|
440
|
+
const chip = harness('composer', {
|
|
441
|
+
useProjection: () => ({ next: { provider: 'codearts' } }),
|
|
442
|
+
openSettings: () => { openedSettings += 1 },
|
|
443
|
+
})
|
|
444
|
+
const chipPool = { ok: true, accounts: [
|
|
445
|
+
{ id: 'primary', label: 'Primary', active: true, credit: { remain: 42 }, health: { state: 'available' } },
|
|
446
|
+
{ id: 'backup', label: 'Backup', credit: { remain: 13.25 }, health: { state: 'available' } },
|
|
447
|
+
{ id: 'network', label: 'Network', error: 'RAW_NETWORK_ERROR', health: { state: 'network' } },
|
|
448
|
+
] }
|
|
449
|
+
await chip.settle('/account', { ok: true, credit: { remain: 42 } })
|
|
450
|
+
await chip.settle('/accounts', chipPool)
|
|
451
|
+
chip.one((node) => node.props['aria-haspopup'] === 'dialog').props.onClick()
|
|
452
|
+
chip.render()
|
|
453
|
+
const dialog = () => chip.one((node) => node.props.role === 'dialog')
|
|
454
|
+
const chipRow = (name) => chip.one((node) => node.props['aria-label'] === `切换到 ${name}`)
|
|
455
|
+
assert.equal(chipRow('Primary').props.disabled, true)
|
|
456
|
+
assert.equal(chip.text(chipRow('Primary')), 'Primary当前选用')
|
|
457
|
+
assert.equal(chip.text(chipRow('Backup')), 'Backup')
|
|
458
|
+
assert.equal(chip.text(chipRow('Network')), 'Network网络异常')
|
|
459
|
+
assert.equal(chip.findAll((node) => node.props.title === 'RAW_NETWORK_ERROR', dialog()).length, 1)
|
|
460
|
+
assert.doesNotMatch(chip.text(dialog()), /RAW_NETWORK_ERROR/)
|
|
461
|
+
chipRow('Backup').props.onClick()
|
|
462
|
+
await new Promise(setImmediate)
|
|
463
|
+
assert.deepEqual(chip.writes.at(-1), { path: '/accounts/activate', body: { id: 'backup' } })
|
|
464
|
+
chip.render()
|
|
465
|
+
assert.match(chip.text(chipRow('Backup')), /正在切换/)
|
|
466
|
+
assert.doesNotMatch(chip.text(chipRow('Primary')), /正在切换/)
|
|
467
|
+
assert.equal(chipRow('Backup').props['aria-busy'], true)
|
|
468
|
+
assert.equal(chipRow('Network').props.disabled, true)
|
|
469
|
+
assert.equal(chip.findAll((node) => node.type === 'svg' && node.props.className?.includes('dca-pop-refresh-icon-spin')).length, 0, 'switching must not look like a refresh')
|
|
470
|
+
await chip.settle('/account', { ok: true, credit: { remain: 13.25 } })
|
|
471
|
+
await chip.settle('/accounts', { ok: true, accounts: chipPool.accounts.map((account) => ({ ...account, active: account.id === 'backup' })) })
|
|
472
|
+
assert.equal(chip.text(chipRow('Backup')), 'Backup当前选用')
|
|
473
|
+
assert.equal(chipRow('Backup').props['aria-busy'], false)
|
|
474
|
+
assert.match(chip.text(dialog()), /已切换到「Backup」/)
|
|
475
|
+
chip.postResponses.set('/accounts/activate', { ok: false, error: 'Switch refused' })
|
|
476
|
+
chipRow('Primary').props.onClick()
|
|
477
|
+
await new Promise(setImmediate); chip.render()
|
|
478
|
+
assert.equal(chipRow('Primary').props.disabled, false, 'failed account switches can be retried')
|
|
479
|
+
assert.equal(chip.text(chipRow('Backup')), 'Backup当前选用', 'failed switches keep the current account')
|
|
480
|
+
assert.match(chip.text(dialog()), /切换到「Primary」失败:Switch refused/)
|
|
481
|
+
assert.doesNotMatch(chip.text(dialog()), /已切换到「Backup」/)
|
|
482
|
+
chip.one((node) => node.props.className === 'dca-pop-settings').props.onClick()
|
|
483
|
+
chip.render()
|
|
484
|
+
assert.equal(openedSettings, 1)
|
|
485
|
+
assert.equal(chip.findAll((node) => node.props.role === 'dialog').length, 0)
|
|
486
|
+
const otherProvider = harness('composer', { useProjection: () => ({ next: { provider: 'another' } }) })
|
|
487
|
+
assert.equal(otherProvider.render(), null)
|
|
488
|
+
assert.equal(otherProvider.pending.length, 0)
|
|
489
|
+
console.log('✓ composer shows concise health states, keeps raw errors out of row text, and supports account switching')
|
|
490
|
+
|
|
491
|
+
// Pinned ordering is a preference independent of the unsaved model draft.
|
|
492
|
+
async function flushSettings(instance, responses) {
|
|
493
|
+
await new Promise(setImmediate)
|
|
494
|
+
let turns = 0
|
|
495
|
+
while (instance.pending.length && turns++ < 20) {
|
|
496
|
+
const path = instance.pending[0].path
|
|
497
|
+
assert.ok(path in responses, `Unexpected request ${path}`)
|
|
498
|
+
await instance.settle(path, responses[path])
|
|
499
|
+
}
|
|
500
|
+
assert.equal(instance.pending.length, 0)
|
|
501
|
+
instance.render()
|
|
502
|
+
}
|
|
503
|
+
const pins = harness()
|
|
504
|
+
const pinResponses = { ...fixtures, '/models': { ...fixtures['/models'], favoriteModelIds: ['coder'] } }
|
|
505
|
+
await flushSettings(pins, pinResponses)
|
|
506
|
+
pins.one((node) => node.props.role === 'tab' && node.props.id.endsWith('-tab-models')).props.onClick(); pins.render()
|
|
507
|
+
const modelOrder = () => pins.findAll((node) => node.type === 'div' && /^dca-model(?: |$)/.test(node.props.className ?? '')).map((node) => node.props.key)
|
|
508
|
+
const star = (label) => pins.one((node) => node.type === 'button' && node.props['aria-label'] === label)
|
|
509
|
+
assert.equal(modelOrder()[0], 'coder')
|
|
510
|
+
pins.one((node) => node.type === 'input' && node.props['aria-label'] === 'Reasoner').props.onChange({ target: { checked: false } }); pins.render()
|
|
511
|
+
pins.postResponses.set('/preferences/save', (body) => {
|
|
512
|
+
pinResponses['/models'] = { ...pinResponses['/models'], favoriteModelIds: body.favoriteModelIds }
|
|
513
|
+
return { ok: true, preferences: { favoriteModelIds: body.favoriteModelIds } }
|
|
514
|
+
})
|
|
515
|
+
star('置顶 Expensive').props.onClick()
|
|
516
|
+
await flushSettings(pins, pinResponses)
|
|
517
|
+
assert.deepEqual(pins.writes.at(-1), { path: '/preferences/save', body: { favoriteModelIds: ['coder', 'expensive'] } })
|
|
518
|
+
assert.deepEqual(modelOrder(), ['coder', 'expensive', 'reasoner', 'free'])
|
|
519
|
+
assert.equal(pins.one((node) => node.type === 'input' && node.props['aria-label'] === 'Reasoner').props.checked, false)
|
|
520
|
+
assert.ok(!pins.writes.some((entry) => entry.path === '/models/select'), 'pinning must not save the live selection')
|
|
521
|
+
const modelSaveStatus = () => pins.one((node) => node.props.className === 'dca-save-status')
|
|
522
|
+
assert.equal(pins.text(modelSaveStatus()), '有未保存的模型配置', 'pin success must not hide the unsaved settings status')
|
|
523
|
+
assert.match(pins.text(pins.render()), /常用置顶已保存/)
|
|
524
|
+
assert.match(pins.text(pins.render()), /置顶即时保存/)
|
|
525
|
+
assert.equal(pins.one((node) => node.type === 'button' && pins.text(node) === '保存模型配置').props.disabled, false)
|
|
526
|
+
pins.one((node) => node.type === 'select' && node.props['aria-label'] === '模型排序').props.onChange({ target: { value: 'ratio' } }); pins.render()
|
|
527
|
+
assert.deepEqual(modelOrder(), ['coder', 'expensive', 'free', 'reasoner'])
|
|
528
|
+
pins.one((node) => node.type === 'input' && node.props.type === 'search').props.onChange({ target: { value: 'Reasoner' } }); pins.render()
|
|
529
|
+
assert.deepEqual(modelOrder(), ['reasoner'], 'pinned models still obey search filters')
|
|
530
|
+
pins.one((node) => node.type === 'input' && node.props.type === 'search').props.onChange({ target: { value: '' } }); pins.render()
|
|
531
|
+
star('取消置顶 Coder').props.onClick()
|
|
532
|
+
await flushSettings(pins, pinResponses)
|
|
533
|
+
assert.deepEqual(modelOrder(), ['expensive', 'free', 'reasoner', 'coder'])
|
|
534
|
+
pins.postResponses.set('/preferences/save', { ok: false, error: 'Cannot save pinned models' })
|
|
535
|
+
star('置顶 Free').props.onClick()
|
|
536
|
+
await flushSettings(pins, pinResponses)
|
|
537
|
+
assert.equal(star('置顶 Free').props['aria-pressed'], false, 'failed writes must not appear persisted')
|
|
538
|
+
assert.match(pins.text(pins.render()), /Cannot save pinned models/)
|
|
539
|
+
assert.equal(pins.text(modelSaveStatus()), '有未保存的模型配置', 'pin errors must remain separate from the model draft status')
|
|
540
|
+
pins.one((node) => node.type === 'input' && node.props['aria-label'] === 'Coder').props.onChange({ target: { checked: false } })
|
|
541
|
+
pins.one((node) => node.type === 'input' && node.props['aria-label'] === 'Expensive').props.onChange({ target: { checked: false } })
|
|
542
|
+
pins.one((node) => node.type === 'input' && node.props['aria-label'] === 'Free').props.onChange({ target: { checked: false } })
|
|
543
|
+
pins.render()
|
|
544
|
+
star('置顶 Free').props.onClick()
|
|
545
|
+
await flushSettings(pins, pinResponses)
|
|
546
|
+
assert.equal(pins.text(modelSaveStatus()), '请至少启用一个模型后保存', 'favorite errors must not hide the empty-selection guidance')
|
|
547
|
+
assert.equal(pins.one((node) => node.type === 'button' && pins.text(node) === '保存模型配置').props.disabled, true)
|
|
548
|
+
console.log('✓ pinned models lead each sort, obey filters, persist separately, and preserve unsaved drafts on success and failure')
|
|
549
|
+
|
|
550
|
+
// Deferred writes expose progress before acknowledgement and before the subsequent reload.
|
|
551
|
+
const switching = harness()
|
|
552
|
+
const switchResponses = { ...fixtures, '/accounts': { ok: true, accounts: [
|
|
553
|
+
{ id: 'personal', label: '个人', active: true, health: { state: 'available' } },
|
|
554
|
+
{ id: 'work', label: '工作', active: false, health: { state: 'available' } },
|
|
555
|
+
] } }
|
|
556
|
+
await flushSettings(switching, switchResponses)
|
|
557
|
+
const accountRow = (id) => switching.one((node) => node.type === 'div' && node.props.key === id && node.props.className?.startsWith('dca-pool-row'))
|
|
558
|
+
const accountButton = (id, label) => {
|
|
559
|
+
const matches = switching.findAll((node) => node.type === 'button' && switching.text(node) === label, accountRow(id))
|
|
560
|
+
assert.equal(matches.length, 1)
|
|
561
|
+
return matches[0]
|
|
562
|
+
}
|
|
563
|
+
let finishSwitch
|
|
564
|
+
switching.postResponses.set('/accounts/activate', () => new Promise((resolve) => { finishSwitch = resolve }))
|
|
565
|
+
const pendingSwitch = accountButton('work', '切换').props.onClick()
|
|
566
|
+
switching.render()
|
|
567
|
+
assert.equal(accountButton('work', '正在切换…').props.disabled, true)
|
|
568
|
+
assert.equal(accountButton('work', '正在切换…').props['aria-busy'], true)
|
|
569
|
+
assert.equal(accountButton('work', '重新检查').props.disabled, true)
|
|
570
|
+
assert.equal(accountButton('personal', '重新检查').props.disabled, true)
|
|
571
|
+
assert.doesNotMatch(switching.text(accountRow('personal')), /正在切换/)
|
|
572
|
+
assert.equal(switching.findAll((node) => node.type === 'button' && switching.text(node) === '加载中…').length, 0)
|
|
573
|
+
assert.equal(switching.pending.length, 0, 'reload waits for activation acknowledgement')
|
|
574
|
+
finishSwitch({ ok: true })
|
|
575
|
+
await new Promise(setImmediate); switching.render()
|
|
576
|
+
assert.match(switching.text(accountRow('work')), /正在切换/)
|
|
577
|
+
switchResponses['/accounts'] = { ok: true, accounts: switchResponses['/accounts'].accounts.map((account) => ({ ...account, active: account.id === 'work' })) }
|
|
578
|
+
await flushSettings(switching, switchResponses)
|
|
579
|
+
await pendingSwitch; switching.render()
|
|
580
|
+
assert.match(switching.text(accountRow('work')), /已切换到「工作」/)
|
|
581
|
+
assert.doesNotMatch(switching.text(accountRow('personal')), /已切换到/)
|
|
582
|
+
assert.equal(accountRow('work').props['aria-busy'], false)
|
|
583
|
+
assert.equal(accountButton('personal', '切换').props.disabled, false)
|
|
584
|
+
switching.postResponses.set('/accounts/activate', { ok: false, error: 'Switch refused' })
|
|
585
|
+
await accountButton('personal', '切换').props.onClick(); switching.render()
|
|
586
|
+
assert.match(switching.text(accountRow('personal')), /切换到「个人」失败:Switch refused/)
|
|
587
|
+
assert.equal(switching.findAll((node) => node.props.role === 'alert', accountRow('personal')).length, 1)
|
|
588
|
+
assert.equal(accountButton('personal', '切换').props.disabled, false)
|
|
589
|
+
assert.match(accountRow('work').props.className, /dca-pool-row-current/)
|
|
590
|
+
assert.doesNotMatch(switching.text(accountRow('work')), /Switch refused|已切换到/)
|
|
591
|
+
switching.postResponses.set('/accounts/activate', () => { throw new Error('Offline switch') })
|
|
592
|
+
await accountButton('personal', '切换').props.onClick(); switching.render()
|
|
593
|
+
assert.match(switching.text(accountRow('personal')), /切换到「个人」失败:Offline switch/)
|
|
594
|
+
assert.equal(accountButton('personal', '切换').props.disabled, false)
|
|
595
|
+
console.log('✓ account switches show progress and outcomes on the target row, preserve current state on failure, and allow retry')
|
|
596
|
+
|
|
597
|
+
// Account import is a read-only preview of the entire confirmed batch.
|
|
598
|
+
const imports = harness()
|
|
599
|
+
await flushSettings(imports, fixtures)
|
|
600
|
+
const importFile = () => imports.one((node) => node.type === 'input' && node.props.type === 'file' && node.props.accept.includes('.csv'))
|
|
601
|
+
const importDialog = () => imports.one((node) => node.props.role === 'dialog' && node.props.className === 'dca-transfer-dialog')
|
|
602
|
+
const importButton = (label) => {
|
|
603
|
+
const matches = imports.findAll((node) => node.type === 'button' && imports.text(node) === label, importDialog())
|
|
604
|
+
assert.equal(matches.length, 1)
|
|
605
|
+
return matches[0]
|
|
606
|
+
}
|
|
607
|
+
const importText = 'OFFLINE_AK_1,OFFLINE_SK_1\nOFFLINE_AK_2,OFFLINE_SK_2'
|
|
608
|
+
imports.postResponses.set('/accounts/preview', { ok: true, total: 2, accounts: [
|
|
609
|
+
{ index: 0, label: '个人', akMasked: 'OFF…ONE' },
|
|
610
|
+
{ index: 1, akMasked: 'OFF…TWO' },
|
|
611
|
+
] })
|
|
612
|
+
const chooseImport = async () => {
|
|
613
|
+
importFile().props.onChange({ target: { value: 'credentials.csv', files: [{ text: async () => importText }] } })
|
|
614
|
+
await flushSettings(imports, fixtures)
|
|
615
|
+
}
|
|
616
|
+
await chooseImport()
|
|
617
|
+
assert.match(imports.text(importDialog()), /将导入以下 2 个账号/)
|
|
618
|
+
assert.equal(imports.findAll((node) => node.type === 'li', importDialog()).length, 2)
|
|
619
|
+
assert.equal(imports.findAll((node) => node.type === 'input' || node.type === 'label', importDialog()).length, 0, 'the preview must not imply per-account selection')
|
|
620
|
+
assert.match(imports.text(importDialog()), /个人OFF…TWO/)
|
|
621
|
+
assert.doesNotMatch(imports.text(importDialog()), /OFFLINE_SK|OFFLINE_AK/)
|
|
622
|
+
assert.ok(!imports.writes.some((write) => write.path === '/accounts/import'))
|
|
623
|
+
importButton('取消').props.onClick(); imports.render()
|
|
624
|
+
assert.equal(imports.findAll((node) => node.props.className === 'dca-transfer-dialog').length, 0)
|
|
625
|
+
assert.ok(!imports.writes.some((write) => write.path === '/accounts/import'), 'cancel does not write any accounts')
|
|
626
|
+
await chooseImport()
|
|
627
|
+
imports.postResponses.set('/accounts/import', { ok: true, added: 2, updated: 0, skipped: 0 })
|
|
628
|
+
const importing = importButton('导入 2 个').props.onClick()
|
|
629
|
+
await flushSettings(imports, fixtures)
|
|
630
|
+
await importing; imports.render()
|
|
631
|
+
assert.deepEqual(imports.writes.at(-1), { path: '/accounts/import', body: { text: importText } })
|
|
632
|
+
assert.equal(imports.findAll((node) => node.props.className === 'dca-transfer-dialog').length, 0)
|
|
633
|
+
console.log('✓ account import previews a plain list with the confirmed batch count and only writes after confirmation')
|
|
634
|
+
|
|
635
|
+
const balances = harness()
|
|
636
|
+
const checkedAt = balances.controls.now - 300000
|
|
637
|
+
const balanceResponses = { ...fixtures,
|
|
638
|
+
'/account': { ok: true, accountId: 'primary', creditIdentity: 'primary-key', credit: { remain: 20 }, creditCheckedAt: checkedAt },
|
|
639
|
+
'/accounts': { ok: true, accounts: [
|
|
640
|
+
{ id: 'primary', creditIdentity: 'primary-key', label: 'Primary', credit: { remain: 20 }, creditCheckedAt: checkedAt },
|
|
641
|
+
{ id: 'backup', creditIdentity: 'backup-key', label: 'Backup', credit: { remain: 0 }, creditCheckedAt: checkedAt },
|
|
642
|
+
] },
|
|
643
|
+
}
|
|
644
|
+
await flushSettings(balances, balanceResponses)
|
|
645
|
+
const balanceCell = (name) => {
|
|
646
|
+
const row = balances.one((node) => node.type === 'div' && /^dca-pool-row(?: dca-pool-row-current)?$/.test(node.props.className ?? '') && balances.text(node).includes(name))
|
|
647
|
+
return balances.findAll((node) => node.props.className === 'dca-pool-credits-row', row)[0]
|
|
648
|
+
}
|
|
649
|
+
balanceResponses['/accounts'] = { ok: true, accounts: balanceResponses['/accounts'].accounts.map((account) => ({ ...account, credit: null, creditCheckedAt: null, health: { state: 'network' } })) }
|
|
650
|
+
balances.intervals[0]()
|
|
651
|
+
await flushSettings(balances, balanceResponses)
|
|
652
|
+
assert.match(balances.text(balanceCell('Primary')), /20.*上次结果.*5 分钟前/)
|
|
653
|
+
assert.match(balances.text(balanceCell('Backup')), /0.*上次结果.*5 分钟前/, 'zero is a successful balance too')
|
|
654
|
+
balances.controls.now += 120000
|
|
655
|
+
balances.intervals[1]()
|
|
656
|
+
balances.intervals[0]()
|
|
657
|
+
await balances.fail('/accounts')
|
|
658
|
+
await flushSettings(balances, balanceResponses)
|
|
659
|
+
assert.match(balances.text(balanceCell('Primary')), /20.*上次结果.*7 分钟前/, 'failed reads must not move the success timestamp')
|
|
660
|
+
balanceResponses['/accounts'] = { ok: true, accounts: [{ id: 'primary', creditIdentity: 'primary-key', label: 'Primary', credit: { remain: 0 }, creditCheckedAt: balances.controls.now }] }
|
|
661
|
+
balances.intervals[0]()
|
|
662
|
+
await flushSettings(balances, balanceResponses)
|
|
663
|
+
assert.equal(balances.text(balanceCell('Primary')), '0')
|
|
664
|
+
balanceResponses['/accounts'] = { ok: true, accounts: [{ id: 'primary', creditIdentity: 'replaced-key', label: 'Primary', credit: null }] }
|
|
665
|
+
balances.intervals[0]()
|
|
666
|
+
await flushSettings(balances, balanceResponses)
|
|
667
|
+
assert.equal(balances.text(balanceCell('Primary')), '—', 'new credentials must not inherit an old credential snapshot')
|
|
668
|
+
console.log('✓ settings retain successful balances and timestamps on gateway and route failures, recover zero balances, and isolate credential identities')
|
|
669
|
+
|
|
670
|
+
const staleChip = harness('composer', { useProjection: () => ({ next: { provider: 'codearts' } }) })
|
|
671
|
+
const chipCheckedAt = staleChip.controls.now - 300000
|
|
672
|
+
const currentAccount = { ok: true, accountId: 'primary', creditIdentity: 'primary-key', credit: { remain: 20 }, creditCheckedAt: chipCheckedAt }
|
|
673
|
+
const currentPool = { ok: true, accounts: [
|
|
674
|
+
{ id: 'primary', creditIdentity: 'primary-key', active: true, label: 'Primary', credit: { remain: 20 }, creditCheckedAt: chipCheckedAt },
|
|
675
|
+
{ id: 'backup', creditIdentity: 'backup-key', active: false, label: 'Backup', credit: { remain: 0 }, creditCheckedAt: chipCheckedAt },
|
|
676
|
+
] }
|
|
677
|
+
await staleChip.settle('/account', currentAccount)
|
|
678
|
+
await staleChip.settle('/accounts', currentPool)
|
|
679
|
+
const chipTrigger = () => staleChip.one((node) => node.props['aria-haspopup'] === 'dialog')
|
|
680
|
+
const chipRefresh = () => staleChip.one((node) => node.props.className === 'dca-pop-refresh')
|
|
681
|
+
chipTrigger().props.onClick(); staleChip.render()
|
|
682
|
+
const failedRefresh = chipRefresh().props.onClick()
|
|
683
|
+
await staleChip.fail('/account')
|
|
684
|
+
await staleChip.fail('/accounts')
|
|
685
|
+
await failedRefresh; staleChip.render()
|
|
686
|
+
assert.equal(staleChip.text(chipTrigger()), '◈上次积分 20')
|
|
687
|
+
assert.match(staleChip.text(staleChip.render()), /积分刷新失败,显示上次结果/)
|
|
688
|
+
assert.match(staleChip.text(staleChip.render()), /5 分钟前/)
|
|
689
|
+
assert.equal(staleChip.text(chipRefresh()).includes('重试'), true)
|
|
690
|
+
const nullRefresh = chipRefresh().props.onClick()
|
|
691
|
+
await staleChip.settle('/account', { ...currentAccount, credit: null, creditCheckedAt: null })
|
|
692
|
+
await staleChip.settle('/accounts', { ok: true, accounts: currentPool.accounts.map((account) => ({ ...account, credit: null, creditCheckedAt: null })) })
|
|
693
|
+
await nullRefresh; staleChip.render()
|
|
694
|
+
assert.equal(staleChip.text(chipTrigger()), '◈上次积分 20', 'an HTTP success without credit data is still a failed credit read')
|
|
695
|
+
const gatewayError = chipRefresh().props.onClick()
|
|
696
|
+
await staleChip.settle('/account', { ok: false, stage: 'gateway', error: 'offline gateway error' })
|
|
697
|
+
await staleChip.settle('/accounts', { ok: false, error: 'offline gateway error' })
|
|
698
|
+
await gatewayError; staleChip.render()
|
|
699
|
+
assert.equal(staleChip.text(chipTrigger()), '◈上次积分 20', 'HTTP-200 error payloads must retain last successful values too')
|
|
700
|
+
const recovery = chipRefresh().props.onClick()
|
|
701
|
+
await staleChip.settle('/account', { ...currentAccount, credit: { remain: 7 }, creditCheckedAt: staleChip.controls.now })
|
|
702
|
+
await staleChip.settle('/accounts', { ok: true, accounts: currentPool.accounts.map((account) => ({ ...account, credit: { remain: account.id === 'primary' ? 7 : 0 } })) })
|
|
703
|
+
await recovery; staleChip.render()
|
|
704
|
+
assert.equal(staleChip.text(chipTrigger()), '◈积分 7')
|
|
705
|
+
assert.equal(staleChip.findAll((node) => node.props.className === 'dca-credit-status').length, 0)
|
|
706
|
+
// An older background response must not overwrite a newer manual refresh.
|
|
707
|
+
staleChip.intervals[0]()
|
|
708
|
+
const olderReads = staleChip.pending.splice(0)
|
|
709
|
+
const newestRefresh = chipRefresh().props.onClick()
|
|
710
|
+
await staleChip.settle('/account', { ...currentAccount, credit: { remain: 9 }, creditCheckedAt: staleChip.controls.now })
|
|
711
|
+
await staleChip.settle('/accounts', currentPool)
|
|
712
|
+
await newestRefresh
|
|
713
|
+
for (const request of olderReads) request.resolve(request.path === '/account' ? { ...currentAccount, credit: { remain: 999 } } : currentPool)
|
|
714
|
+
await new Promise(setImmediate); staleChip.render()
|
|
715
|
+
assert.equal(staleChip.text(chipTrigger()), '◈积分 9', 'late background responses cannot restore an older value')
|
|
716
|
+
staleChip.one((node) => node.props['aria-label'] === '切换到 Backup').props.onClick()
|
|
717
|
+
await new Promise(setImmediate); staleChip.render()
|
|
718
|
+
assert.doesNotMatch(staleChip.text(chipTrigger()), /9/, 'switching clears the previous account headline immediately')
|
|
719
|
+
await staleChip.settle('/account', { ok: true, accountId: 'backup', creditIdentity: 'backup-key', credit: null })
|
|
720
|
+
await staleChip.settle('/accounts', { ok: true, accounts: currentPool.accounts.map((account) => ({ ...account, active: account.id === 'backup' })) })
|
|
721
|
+
assert.doesNotMatch(staleChip.text(chipTrigger()), /9/, 'failed reads for the new account cannot reuse the previous account balance')
|
|
722
|
+
console.log('✓ composer retains last values on refresh failures, exposes retry and timestamps, clears stale markers on recovery, and isolates account switches')
|
|
723
|
+
|
|
724
|
+
const unreadChip = harness('composer', { useProjection: () => ({ next: { provider: 'codearts' } }) })
|
|
725
|
+
await unreadChip.fail('/account')
|
|
726
|
+
await unreadChip.fail('/accounts')
|
|
727
|
+
unreadChip.one((node) => node.props['aria-haspopup'] === 'dialog').props.onClick(); unreadChip.render()
|
|
728
|
+
assert.match(unreadChip.text(unreadChip.render()), /积分暂时无法读取,请重试/)
|
|
729
|
+
assert.doesNotMatch(unreadChip.text(unreadChip.render()), /上次积分|积分 0/)
|
|
730
|
+
console.log('✓ first-time credit failures show an actionable state without inventing a cached balance')
|
|
731
|
+
|
|
370
732
|
console.log('\nui: all checks passed')
|