dsh-delete-session 0.2.3 → 0.2.5
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/README.md +5 -0
- package/package.json +1 -1
- package/src/client.js +396 -37
- package/src/index.js +199 -276
- package/test/artifacts.host.test.js +238 -0
- package/test/checkbox.dom.test.js +587 -11
|
@@ -282,9 +282,14 @@ async function loadPlugin(options = {}) {
|
|
|
282
282
|
writable: true,
|
|
283
283
|
})
|
|
284
284
|
globalThis.MutationObserver = class {
|
|
285
|
-
constructor(callback) {
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
constructor(callback) {
|
|
286
|
+
this.callback = callback
|
|
287
|
+
this.target = null
|
|
288
|
+
this.options = null
|
|
289
|
+
observers.push(this)
|
|
290
|
+
}
|
|
291
|
+
observe(target, options) { this.target = target === undefined ? null : target; this.options = options === undefined ? null : options }
|
|
292
|
+
disconnect() { this.target = null }
|
|
288
293
|
}
|
|
289
294
|
// The plugin coalesces decorate passes through rAF. Run the callback on a real
|
|
290
295
|
// microtask-free tick rather than synchronously: `scheduleDecorate` assigns the
|
|
@@ -328,10 +333,18 @@ async function loadPlugin(options = {}) {
|
|
|
328
333
|
}
|
|
329
334
|
// The native dialog route. `unsupported` models a platform without one, which
|
|
330
335
|
// is what makes the client fall back to the in-page picker.
|
|
336
|
+
if (href.endsWith('/dsh-delete-session/delete-file')) {
|
|
337
|
+
return { ok: true, status: 200, json: async () => ({ ok: true, recycled: true }) }
|
|
338
|
+
}
|
|
331
339
|
if (href.endsWith('/dsh-delete-session/pick')) {
|
|
332
340
|
const pick = options.pick ?? { cancelled: true, path: null }
|
|
333
341
|
if (pick.unsupported === true) {
|
|
334
|
-
return { ok: false, status:
|
|
342
|
+
return { ok: false, status: 200, json: async () => ({ ok: false, code: 'unsupported', error: '宿主没有 directoryPicker 服务' }) }
|
|
343
|
+
}
|
|
344
|
+
// A browse deployment: the host has no OS chooser to raise, so it tells the
|
|
345
|
+
// page to draw its own picker. Normal for a remote client.
|
|
346
|
+
if (pick.browse === true) {
|
|
347
|
+
return { ok: false, status: 200, json: async () => ({ ok: false, code: 'browse', error: '浏览式宿主' }) }
|
|
335
348
|
}
|
|
336
349
|
return { ok: true, status: 200, json: async () => ({ ok: true, ...pick }) }
|
|
337
350
|
}
|
|
@@ -442,12 +455,20 @@ function makeStorage() {
|
|
|
442
455
|
* from `data-row-key`, not from a React fiber; without this the plugin finds no
|
|
443
456
|
* id and skips the row, which would make every assertion below pass vacuously.
|
|
444
457
|
*/
|
|
445
|
-
|
|
458
|
+
/** The host wraps the session rows in this container; the plugin watches it. */
|
|
459
|
+
function mountList(harness) {
|
|
460
|
+
const list = harness.document.createElement('div')
|
|
461
|
+
list.className = 'hHd-Xa_regionArea'
|
|
462
|
+
harness.document.body.appendChild(list)
|
|
463
|
+
return list
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function mountRow(harness, session = SESSION_A, parent = null) {
|
|
446
467
|
const row = harness.document.createElement('div')
|
|
447
468
|
row.className = 'session_row'
|
|
448
469
|
row.setAttribute('role', 'treeitem')
|
|
449
470
|
row.setAttribute('data-row-key', `session:${session.id}`)
|
|
450
|
-
harness.document.body.appendChild(row)
|
|
471
|
+
;(parent ?? harness.document.body).appendChild(row)
|
|
451
472
|
harness.rows.push(row)
|
|
452
473
|
return row
|
|
453
474
|
}
|
|
@@ -1050,14 +1071,16 @@ const artifactSection = (harness) => {
|
|
|
1050
1071
|
return kids.find((node) => node && node.props && node.props.key === 'artifacts') ?? null
|
|
1051
1072
|
}
|
|
1052
1073
|
|
|
1053
|
-
/** One rendered
|
|
1074
|
+
/** One rendered row block per listed artifact. */
|
|
1054
1075
|
const artifactRows = (harness) => {
|
|
1055
1076
|
const section = artifactSection(harness)
|
|
1056
1077
|
if (section === null) return []
|
|
1057
|
-
return (section.props.children || []).filter((node) => node && node.
|
|
1078
|
+
return (section.props.children || []).filter((node) => node && node.props && node.props['data-file-row'] !== undefined)
|
|
1058
1079
|
}
|
|
1059
1080
|
|
|
1060
|
-
|
|
1081
|
+
/** The tick box of one row lives inside that row's label. */
|
|
1082
|
+
const rowLabel = (row) => (row.props.children || []).find((child) => child && child.type === 'label')
|
|
1083
|
+
const artifactInputs = (harness) => artifactRows(harness).map((row) => rowLabel(row).props.children[0])
|
|
1061
1084
|
|
|
1062
1085
|
/** Open the dialog through the real menu row and let the scan settle. */
|
|
1063
1086
|
async function openArtifactDialog(harness, session = SESSION_A) {
|
|
@@ -1906,12 +1929,12 @@ const childChecks = (harness) => {
|
|
|
1906
1929
|
return section === undefined ? [] : collectChecks([section], harness)
|
|
1907
1930
|
}
|
|
1908
1931
|
|
|
1909
|
-
test('the page offers to take child sessions with their parent,
|
|
1932
|
+
test('the page offers to take child sessions with their parent, on by default', async () => {
|
|
1910
1933
|
const harness = await loadPlugin()
|
|
1911
1934
|
const box = pageCheck(harness, 'syncChildren')
|
|
1912
1935
|
|
|
1913
1936
|
assert.ok(box, 'the switch renders with the other delete controls')
|
|
1914
|
-
assert.equal(box.props.checked,
|
|
1937
|
+
assert.equal(box.props.checked, true, 'taking them along is the default')
|
|
1915
1938
|
assert.equal(box.props.label, '同时删除子会话')
|
|
1916
1939
|
|
|
1917
1940
|
box.props.onChange(true)
|
|
@@ -1920,6 +1943,7 @@ test('the page offers to take child sessions with their parent, off by default',
|
|
|
1920
1943
|
|
|
1921
1944
|
test('with the switch off the dialog lists the children, ticked, for you to narrow', async () => {
|
|
1922
1945
|
const harness = await loadPlugin({ children: CHILDREN })
|
|
1946
|
+
localStorage.setItem(SYNC_CHILDREN_KEY, '0')
|
|
1923
1947
|
mountRow(harness, SESSION_A)
|
|
1924
1948
|
|
|
1925
1949
|
const { element } = deleteRow(harness, SESSION_A)
|
|
@@ -1933,6 +1957,7 @@ test('with the switch off the dialog lists the children, ticked, for you to narr
|
|
|
1933
1957
|
|
|
1934
1958
|
test('unticking a child keeps it out of the delete', async () => {
|
|
1935
1959
|
const harness = await loadPlugin({ children: CHILDREN })
|
|
1960
|
+
localStorage.setItem(SYNC_CHILDREN_KEY, '0')
|
|
1936
1961
|
mountRow(harness, SESSION_A)
|
|
1937
1962
|
|
|
1938
1963
|
const { element } = deleteRow(harness, SESSION_A)
|
|
@@ -2176,6 +2201,7 @@ test('an interpolating host translator never receives our function entries', asy
|
|
|
2176
2201
|
|
|
2177
2202
|
test('a placeholder string is interpolated locally, not by the host', async () => {
|
|
2178
2203
|
const harness = await loadPlugin({ children: CHILDREN })
|
|
2204
|
+
localStorage.setItem(SYNC_CHILDREN_KEY, '0')
|
|
2179
2205
|
const dict = harness.locales[NS].zh
|
|
2180
2206
|
const strict = (key, params) => {
|
|
2181
2207
|
const value = dict[key]
|
|
@@ -2213,3 +2239,553 @@ test('the bar buttons keep their width instead of wrapping', async () => {
|
|
|
2213
2239
|
assert.match(css, /\.dsdel-bar-btn\{[^}]*white-space:nowrap/, 'and never wrap their label')
|
|
2214
2240
|
assert.match(css, /\.dsdel-bar-count\{[^}]*text-overflow:ellipsis/, 'the count gives way instead')
|
|
2215
2241
|
})
|
|
2242
|
+
|
|
2243
|
+
// --- drag a session onto the footer bar to delete it ------------------------
|
|
2244
|
+
|
|
2245
|
+
/** Drag one mounted row the way the host starts a session drag. */
|
|
2246
|
+
const startRowDrag = (harness, row) => harness.document.dispatchToDocument('dragstart', {
|
|
2247
|
+
target: row,
|
|
2248
|
+
preventDefault() {},
|
|
2249
|
+
stopPropagation() {},
|
|
2250
|
+
})
|
|
2251
|
+
|
|
2252
|
+
const dropEvent = () => ({ preventDefault() {}, stopPropagation() {}, dataTransfer: { dropEffect: '' } })
|
|
2253
|
+
|
|
2254
|
+
test('dragging a session row turns the footer into a drop target', async () => {
|
|
2255
|
+
const harness = await loadPlugin()
|
|
2256
|
+
const row = mountRow(harness, SESSION_A)
|
|
2257
|
+
|
|
2258
|
+
assert.equal(bar(harness), null, 'the footer is untouched before the drag')
|
|
2259
|
+
|
|
2260
|
+
startRowDrag(harness, row)
|
|
2261
|
+
await flush()
|
|
2262
|
+
|
|
2263
|
+
const node = bar(harness)
|
|
2264
|
+
assert.ok(node, 'the bar appears while a session is being dragged')
|
|
2265
|
+
assert.match(String(node.props.className), /\bdsdel-drop\b/, 'as a drop target, not the selection bar')
|
|
2266
|
+
assert.equal(harness.document.body._classes.has('dsdel-selecting'), true, 'and the account row steps aside')
|
|
2267
|
+
})
|
|
2268
|
+
|
|
2269
|
+
test('hovering the bar shows that releasing will delete', async () => {
|
|
2270
|
+
const harness = await loadPlugin()
|
|
2271
|
+
const row = mountRow(harness, SESSION_A)
|
|
2272
|
+
|
|
2273
|
+
startRowDrag(harness, row)
|
|
2274
|
+
await flush()
|
|
2275
|
+
assert.doesNotMatch(String(bar(harness).props.className), /dsdel-drop-over/, 'not armed yet')
|
|
2276
|
+
|
|
2277
|
+
bar(harness).props.onDragOver(dropEvent())
|
|
2278
|
+
await flush()
|
|
2279
|
+
|
|
2280
|
+
const node = bar(harness)
|
|
2281
|
+
assert.match(String(node.props.className), /dsdel-drop-over/, 'armed once the pointer is over it')
|
|
2282
|
+
const text = JSON.stringify(node.props.children)
|
|
2283
|
+
assert.match(text, /松手删除/, 'and the line says so')
|
|
2284
|
+
})
|
|
2285
|
+
|
|
2286
|
+
test('leaving the bar disarms it again', async () => {
|
|
2287
|
+
const harness = await loadPlugin()
|
|
2288
|
+
const row = mountRow(harness, SESSION_A)
|
|
2289
|
+
|
|
2290
|
+
startRowDrag(harness, row)
|
|
2291
|
+
await flush()
|
|
2292
|
+
bar(harness).props.onDragOver(dropEvent())
|
|
2293
|
+
await flush()
|
|
2294
|
+
bar(harness).props.onDragLeave(dropEvent())
|
|
2295
|
+
await flush()
|
|
2296
|
+
|
|
2297
|
+
assert.doesNotMatch(String(bar(harness).props.className), /dsdel-drop-over/)
|
|
2298
|
+
})
|
|
2299
|
+
|
|
2300
|
+
test('dropping asks first unless the user turned asking off', async () => {
|
|
2301
|
+
const harness = await loadPlugin()
|
|
2302
|
+
const row = mountRow(harness, SESSION_A)
|
|
2303
|
+
|
|
2304
|
+
startRowDrag(harness, row)
|
|
2305
|
+
await flush()
|
|
2306
|
+
bar(harness).props.onDrop(dropEvent())
|
|
2307
|
+
await flush()
|
|
2308
|
+
|
|
2309
|
+
assert.ok(dialogParts(harness), 'the confirmation dialog opens — the same rule as the menu row')
|
|
2310
|
+
assert.equal(deleteCalls(harness), 0, 'and nothing is deleted yet')
|
|
2311
|
+
})
|
|
2312
|
+
|
|
2313
|
+
test('dropping deletes straight away when asking is off', async () => {
|
|
2314
|
+
const harness = await loadPlugin()
|
|
2315
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
2316
|
+
const row = mountRow(harness, SESSION_A)
|
|
2317
|
+
|
|
2318
|
+
startRowDrag(harness, row)
|
|
2319
|
+
await flush()
|
|
2320
|
+
bar(harness).props.onDrop(dropEvent())
|
|
2321
|
+
await flush()
|
|
2322
|
+
|
|
2323
|
+
assert.equal(deleteCalls(harness), 1, 'one delete goes out')
|
|
2324
|
+
assert.equal(dialogParts(harness), null, 'with no dialog')
|
|
2325
|
+
})
|
|
2326
|
+
|
|
2327
|
+
test('ending the drag without dropping puts the footer back', async () => {
|
|
2328
|
+
const harness = await loadPlugin()
|
|
2329
|
+
const row = mountRow(harness, SESSION_A)
|
|
2330
|
+
|
|
2331
|
+
startRowDrag(harness, row)
|
|
2332
|
+
await flush()
|
|
2333
|
+
harness.document.dispatchToDocument('dragend', { target: row, preventDefault() {}, stopPropagation() {} })
|
|
2334
|
+
await flush()
|
|
2335
|
+
|
|
2336
|
+
assert.equal(bar(harness), null, 'the footer is empty again')
|
|
2337
|
+
assert.equal(harness.document.body._classes.has('dsdel-selecting'), false, 'and the account row is back')
|
|
2338
|
+
})
|
|
2339
|
+
|
|
2340
|
+
test('a drag started during multi-select is left alone', async () => {
|
|
2341
|
+
const harness = await loadPlugin()
|
|
2342
|
+
mountRow(harness, SESSION_A)
|
|
2343
|
+
selectRow(harness).element.props.onSelect()
|
|
2344
|
+
await flush()
|
|
2345
|
+
|
|
2346
|
+
const barBefore = bar(harness)
|
|
2347
|
+
assert.match(String(barBefore.props.className), /\bdsdel-bar\b/)
|
|
2348
|
+
|
|
2349
|
+
startRowDrag(harness, harness.rows[0])
|
|
2350
|
+
await flush()
|
|
2351
|
+
|
|
2352
|
+
assert.doesNotMatch(String(bar(harness).props.className), /\bdsdel-drop\b/, 'reordering inside the mode is not a delete')
|
|
2353
|
+
})
|
|
2354
|
+
|
|
2355
|
+
// --- performance: the decorate pass must stay cheap --------------------------
|
|
2356
|
+
|
|
2357
|
+
test('the row observer watches the session list, not the whole document', async () => {
|
|
2358
|
+
const harness = await loadPlugin()
|
|
2359
|
+
const list = mountList(harness)
|
|
2360
|
+
mountRow(harness, SESSION_A, list)
|
|
2361
|
+
selectRow(harness).element.props.onSelect()
|
|
2362
|
+
await flush()
|
|
2363
|
+
|
|
2364
|
+
const observer = harness.observers[0]
|
|
2365
|
+
assert.ok(observer, 'multi-select installs one observer')
|
|
2366
|
+
// Observing `document.body` means every streamed token in the transcript wakes
|
|
2367
|
+
// this callback. The list is the only subtree that can gain or lose rows.
|
|
2368
|
+
assert.equal(
|
|
2369
|
+
observer.target,
|
|
2370
|
+
list,
|
|
2371
|
+
'the list container is the observation root',
|
|
2372
|
+
)
|
|
2373
|
+
})
|
|
2374
|
+
|
|
2375
|
+
test('a mutation with no added or removed nodes schedules no pass', async () => {
|
|
2376
|
+
const harness = await loadPlugin()
|
|
2377
|
+
mountRow(harness, SESSION_A)
|
|
2378
|
+
selectRow(harness).element.props.onSelect()
|
|
2379
|
+
await flush()
|
|
2380
|
+
|
|
2381
|
+
const observer = harness.observers[0]
|
|
2382
|
+
let scanned = 0
|
|
2383
|
+
const realQuery = harness.document.querySelectorAll.bind(harness.document)
|
|
2384
|
+
harness.document.querySelectorAll = (selector) => {
|
|
2385
|
+
if (selector === '[role="treeitem"]') scanned += 1
|
|
2386
|
+
return realQuery(selector)
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
// A character-data mutation: text streaming, nothing structural.
|
|
2390
|
+
observer.callback([{ type: 'characterData', addedNodes: [], removedNodes: [] }])
|
|
2391
|
+
await flush()
|
|
2392
|
+
assert.equal(scanned, 0, 'no row scan for a text-only mutation')
|
|
2393
|
+
|
|
2394
|
+
// A structural one still has to run.
|
|
2395
|
+
observer.callback([{ type: 'childList', addedNodes: [harness.rows[0]], removedNodes: [] }])
|
|
2396
|
+
await flush()
|
|
2397
|
+
assert.equal(scanned, 1, 'one scan when a row arrives')
|
|
2398
|
+
})
|
|
2399
|
+
|
|
2400
|
+
test('the decorate pass does not run a selector engine over every row', async () => {
|
|
2401
|
+
const harness = await loadPlugin()
|
|
2402
|
+
mountRow(harness, SESSION_A)
|
|
2403
|
+
selectRow(harness).element.props.onSelect()
|
|
2404
|
+
await flush()
|
|
2405
|
+
|
|
2406
|
+
const row = harness.rows[0]
|
|
2407
|
+
let rowSelectors = 0
|
|
2408
|
+
const realQuery = row.querySelector.bind(row)
|
|
2409
|
+
row.querySelector = (selector) => { rowSelectors += 1; return realQuery(selector) }
|
|
2410
|
+
|
|
2411
|
+
harness.observers[0].callback([{ type: 'childList', addedNodes: [row], removedNodes: [] }])
|
|
2412
|
+
await flush()
|
|
2413
|
+
|
|
2414
|
+
// The checkbox is always the first element child; a per-row selector call per
|
|
2415
|
+
// frame is the pass's dominant cost with a long list.
|
|
2416
|
+
assert.equal(rowSelectors, 0, 'the checkbox is found without querying')
|
|
2417
|
+
})
|
|
2418
|
+
|
|
2419
|
+
test('a browse-only host falls back to the in-page picker too', async () => {
|
|
2420
|
+
// The host answered `browse`: it has a listing API but no OS chooser to raise.
|
|
2421
|
+
// That is the normal shape for a remote client, so it must not read as an error.
|
|
2422
|
+
const listing = { path: 'C:/ws', parent: 'C:/', entries: [], roots: ['C:/'], truncated: false, defaultRoot: 'C:/home' }
|
|
2423
|
+
const harness = await loadPlugin({ browse: listing, pick: { browse: true } })
|
|
2424
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2425
|
+
localStorage.setItem(ROOT_KEY, 'C:/ws')
|
|
2426
|
+
|
|
2427
|
+
pageRootBrowse(harness).props.onClick()
|
|
2428
|
+
await tick()
|
|
2429
|
+
await tick()
|
|
2430
|
+
|
|
2431
|
+
assert.ok(pickerElement(harness), 'the in-page picker opened')
|
|
2432
|
+
assert.ok(browseRequests(harness).length > 0, 'and it asked the host for a listing')
|
|
2433
|
+
})
|
|
2434
|
+
|
|
2435
|
+
test('a failing folder dialog says so instead of blaming the delete', async () => {
|
|
2436
|
+
const harness = await loadPlugin()
|
|
2437
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2438
|
+
const originalFetch = globalThis.fetch
|
|
2439
|
+
globalThis.fetch = async (url, init) => {
|
|
2440
|
+
if (String(url).endsWith('/dsh-delete-session/pick')) {
|
|
2441
|
+
harness.requests.push({ url: String(url), init })
|
|
2442
|
+
return {
|
|
2443
|
+
ok: false,
|
|
2444
|
+
status: 500,
|
|
2445
|
+
json: async () => ({ ok: false, code: 'shell', error: "Cannot read properties of undefined (reading 'aborted')" }),
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
return originalFetch(url, init)
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2451
|
+
pageRootBrowse(harness).props.onClick()
|
|
2452
|
+
await tick()
|
|
2453
|
+
await tick()
|
|
2454
|
+
|
|
2455
|
+
const last = toasts(harness).at(-1)
|
|
2456
|
+
assert.match(last, /选择文件夹失败/, 'the picker is named')
|
|
2457
|
+
assert.doesNotMatch(last, /删除失败/, 'and deleting is not blamed for it')
|
|
2458
|
+
assert.match(last, /aborted/, 'the host message is still carried through')
|
|
2459
|
+
})
|
|
2460
|
+
|
|
2461
|
+
// --- first install: the four defaults --------------------------------------
|
|
2462
|
+
|
|
2463
|
+
test('a fresh install ticks all four delete switches', async () => {
|
|
2464
|
+
// No storage at all: this is what a new user sees on the plugin page.
|
|
2465
|
+
const harness = await loadPlugin()
|
|
2466
|
+
|
|
2467
|
+
const expected = [
|
|
2468
|
+
['ask', '删除时询问', 'ask first'],
|
|
2469
|
+
['recycle', '删除至回收站', 'recycle bin'],
|
|
2470
|
+
['syncChildren', '同时删除子会话', 'take the subagent sessions along'],
|
|
2471
|
+
['off', '不处理产出文件(保持当前行为)', 'leave produced files alone'],
|
|
2472
|
+
]
|
|
2473
|
+
|
|
2474
|
+
for (const [key, label, why] of expected) {
|
|
2475
|
+
const box = pageCheck(harness, key)
|
|
2476
|
+
assert.ok(box, key + ' renders')
|
|
2477
|
+
assert.equal(box.props.label, label)
|
|
2478
|
+
assert.equal(box.props.checked, true, why)
|
|
2479
|
+
}
|
|
2480
|
+
})
|
|
2481
|
+
|
|
2482
|
+
test('unticking "take the child sessions along" is remembered', async () => {
|
|
2483
|
+
const harness = await loadPlugin()
|
|
2484
|
+
const box = pageCheck(harness, 'syncChildren')
|
|
2485
|
+
assert.equal(box.props.checked, true, 'on by default')
|
|
2486
|
+
|
|
2487
|
+
box.props.onChange(false)
|
|
2488
|
+
// The default is now "on", so the off choice has to be written explicitly:
|
|
2489
|
+
// deleting the key would read back as on again.
|
|
2490
|
+
assert.equal(localStorage.getItem(SYNC_CHILDREN_KEY), '0', 'off is written, not cleared')
|
|
2491
|
+
})
|
|
2492
|
+
|
|
2493
|
+
test('a fresh install deletes the children without listing them', async () => {
|
|
2494
|
+
const harness = await loadPlugin({ children: CHILDREN })
|
|
2495
|
+
mountRow(harness, SESSION_A)
|
|
2496
|
+
|
|
2497
|
+
const { element } = deleteRow(harness, SESSION_A)
|
|
2498
|
+
element.props.onSelect({ shiftKey: false })
|
|
2499
|
+
await flush()
|
|
2500
|
+
|
|
2501
|
+
assert.deepEqual(childChecks(harness), [], 'no per-child ticks to narrow, because they all go')
|
|
2502
|
+
dialogParts(harness).confirm.props.onClick()
|
|
2503
|
+
await flush()
|
|
2504
|
+
|
|
2505
|
+
assert.deepEqual(
|
|
2506
|
+
deleteBody(harness).childSessionIds,
|
|
2507
|
+
['session-child-one', 'session-child-two'],
|
|
2508
|
+
'and the delete carries them',
|
|
2509
|
+
)
|
|
2510
|
+
})
|
|
2511
|
+
// --- visual layer: tokens, grouped fields, theme-true toast ----------------
|
|
2512
|
+
|
|
2513
|
+
test('the page card groups each switch with its hint in one field block', async () => {
|
|
2514
|
+
const harness = await loadPlugin()
|
|
2515
|
+
const card = pageCard(harness)
|
|
2516
|
+
const fields = (card.props.children ?? []).filter(
|
|
2517
|
+
(node) => node && node.props && node.props.className === 'dsdel-field',
|
|
2518
|
+
)
|
|
2519
|
+
|
|
2520
|
+
// Four switches at minimum: ask / recycle / syncChildren / artifacts-off.
|
|
2521
|
+
assert.ok(fields.length >= 4, 'each control became its own block, saw ' + fields.length)
|
|
2522
|
+
for (const field of fields) {
|
|
2523
|
+
const inner = (field.props.children ?? []).filter(Boolean)
|
|
2524
|
+
assert.ok(inner.length >= 1, 'the block holds the control')
|
|
2525
|
+
}
|
|
2526
|
+
})
|
|
2527
|
+
|
|
2528
|
+
test('the shared tokens are declared once and used by the blocks', async () => {
|
|
2529
|
+
const harness = await loadPlugin()
|
|
2530
|
+
const style = harness.document.head.querySelector('[data-dsh-delete-session="1"]')
|
|
2531
|
+
const css = String(style._text ?? '')
|
|
2532
|
+
|
|
2533
|
+
assert.match(css, /--dsdel-bg:/, 'a background token')
|
|
2534
|
+
assert.match(css, /--dsdel-border:/, 'a border token')
|
|
2535
|
+
assert.match(css, /--dsdel-ring:/, 'a focus ring token')
|
|
2536
|
+
assert.match(css, /\.dsdel-field\{[^}]*border-radius/, 'the block is rounded')
|
|
2537
|
+
assert.match(css, /\.dsdel-field:focus-within\{[^}]*outline/, 'and shows a focus ring')
|
|
2538
|
+
})
|
|
2539
|
+
|
|
2540
|
+
test('the toast follows the theme instead of the OS colour keywords', async () => {
|
|
2541
|
+
const harness = await loadPlugin()
|
|
2542
|
+
const style = harness.document.head.querySelector('[data-dsh-delete-session="1"]')
|
|
2543
|
+
const css = String(style._text ?? '')
|
|
2544
|
+
|
|
2545
|
+
// `Canvas`/`CanvasText` ignore the DSH theme entirely: in a dark app the toast
|
|
2546
|
+
// stayed a light system rectangle.
|
|
2547
|
+
assert.doesNotMatch(css, /background:Canvas/, 'no system background')
|
|
2548
|
+
assert.doesNotMatch(css, /color:CanvasText/, 'no system text colour')
|
|
2549
|
+
assert.match(css, /\.dsdel-toast\{[^}]*var\(--dsw-alias/, 'it reads the host theme tokens')
|
|
2550
|
+
})
|
|
2551
|
+
test('the card is registered on the package page, so its URL has one segment', async () => {
|
|
2552
|
+
const harness = await loadPlugin()
|
|
2553
|
+
const bundleEntry = harness.slotRegistrations.find(
|
|
2554
|
+
(entry) => entry.spec.name === 'plugins.bundle.config',
|
|
2555
|
+
)
|
|
2556
|
+
|
|
2557
|
+
// `plugins.row.config` renders on the row page, whose URL is
|
|
2558
|
+
// `#/panel/plugins/<package>/<rowId>` — with the row id equal to the package
|
|
2559
|
+
// name here, the address doubled. `plugins.bundle.config` renders on the
|
|
2560
|
+
// package page itself: `#/panel/plugins/<package>`.
|
|
2561
|
+
assert.ok(bundleEntry, 'the bundle-level slot is registered')
|
|
2562
|
+
assert.equal(bundleEntry.spec.key, NS, 'keyed by the package name')
|
|
2563
|
+
|
|
2564
|
+
const rendered = bundleEntry.Component({ view: 'page' })
|
|
2565
|
+
const fields = (rendered.props.children ?? []).filter(
|
|
2566
|
+
(node) => node && node.props && node.props.className === 'dsdel-field',
|
|
2567
|
+
)
|
|
2568
|
+
assert.ok(fields.length >= 4, 'and it carries the same switches')
|
|
2569
|
+
})
|
|
2570
|
+
|
|
2571
|
+
test('the row page keeps its one-line summary', async () => {
|
|
2572
|
+
const harness = await loadPlugin()
|
|
2573
|
+
const rowEntry = harness.slotRegistrations.find(
|
|
2574
|
+
(entry) => entry.spec.name === 'plugins.row.config',
|
|
2575
|
+
)
|
|
2576
|
+
assert.ok(rowEntry, 'the row summary is still registered')
|
|
2577
|
+
|
|
2578
|
+
const summary = rowEntry.Component({ view: 'summary' })
|
|
2579
|
+
assert.equal(typeof summary, 'string', 'the row list gets a sentence, not a card')
|
|
2580
|
+
})
|
|
2581
|
+
// --- each produced file can be opened where it lives ------------------------
|
|
2582
|
+
|
|
2583
|
+
/** The row block for one produced file inside the dialog. */
|
|
2584
|
+
function fileRow(harness, path) {
|
|
2585
|
+
const modal = dialogElement(harness)
|
|
2586
|
+
if (modal === null) return null
|
|
2587
|
+
const stack = [modal]
|
|
2588
|
+
while (stack.length > 0) {
|
|
2589
|
+
const node = stack.pop()
|
|
2590
|
+
if (node === null || node === undefined || typeof node !== 'object') continue
|
|
2591
|
+
if (node.props && node.props['data-file-row'] === path) return node
|
|
2592
|
+
const kids = node.props && node.props.children
|
|
2593
|
+
if (Array.isArray(kids)) stack.push(...kids)
|
|
2594
|
+
else if (kids) stack.push(kids)
|
|
2595
|
+
}
|
|
2596
|
+
return null
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
test('every produced file offers a button that opens its folder', async () => {
|
|
2600
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2601
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2602
|
+
mountRow(harness, SESSION_A)
|
|
2603
|
+
await openArtifactDialog(harness)
|
|
2604
|
+
|
|
2605
|
+
const target = PLAN.created[0].path
|
|
2606
|
+
const row = fileRow(harness, target)
|
|
2607
|
+
assert.ok(row, 'the file has its own row block')
|
|
2608
|
+
|
|
2609
|
+
|
|
2610
|
+
const button = findByKey(row.props.children ?? [], 'open')[0]
|
|
2611
|
+
assert.ok(button, 'the row carries an open button')
|
|
2612
|
+
|
|
2613
|
+
const before = harness.requests.filter((request) => request.url.endsWith('/dsh-delete-session/reveal')).length
|
|
2614
|
+
button.props.onClick({ preventDefault() {}, stopPropagation() {} })
|
|
2615
|
+
await tick()
|
|
2616
|
+
await tick()
|
|
2617
|
+
|
|
2618
|
+
const reveals = harness.requests.filter((request) => request.url.endsWith('/dsh-delete-session/reveal'))
|
|
2619
|
+
assert.equal(reveals.length, before + 1, 'the host is asked to reveal a folder')
|
|
2620
|
+
// The folder, not the file: the OS file manager highlights a file in its parent.
|
|
2621
|
+
assert.equal(JSON.parse(reveals.at(-1).init.body).path, 'C:/ws', 'the parent directory is passed')
|
|
2622
|
+
})
|
|
2623
|
+
|
|
2624
|
+
test('the open button does not disturb the selection', async () => {
|
|
2625
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2626
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2627
|
+
mountRow(harness, SESSION_A)
|
|
2628
|
+
await openArtifactDialog(harness)
|
|
2629
|
+
|
|
2630
|
+
const target = PLAN.created[0].path
|
|
2631
|
+
const checkbox = rowLabel(fileRow(harness, target)).props.children[0]
|
|
2632
|
+
assert.equal(checkbox.props.checked, true, 'ticked by default')
|
|
2633
|
+
|
|
2634
|
+
const button = findByKey(fileRow(harness, target).props.children ?? [], 'open')[0]
|
|
2635
|
+
button.props.onClick({ preventDefault() {}, stopPropagation() {} })
|
|
2636
|
+
await tick()
|
|
2637
|
+
|
|
2638
|
+
const after = rowLabel(fileRow(harness, target)).props.children[0]
|
|
2639
|
+
assert.equal(after.props.checked, true, 'still ticked: opening a folder is not a toggle')
|
|
2640
|
+
})
|
|
2641
|
+
// --- the per-file delete button follows the recycle switch -----------------
|
|
2642
|
+
|
|
2643
|
+
const removeButton = (harness, target) =>
|
|
2644
|
+
findByKey(fileRow(harness, target).props.children ?? [], 'remove')[0]
|
|
2645
|
+
|
|
2646
|
+
const deleteFileCalls = (harness) =>
|
|
2647
|
+
harness.requests.filter((request) => request.url.endsWith('/dsh-delete-session/delete-file'))
|
|
2648
|
+
|
|
2649
|
+
test('deleting one file honours the recycle switch', async () => {
|
|
2650
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2651
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2652
|
+
mountRow(harness, SESSION_A)
|
|
2653
|
+
await openArtifactDialog(harness)
|
|
2654
|
+
|
|
2655
|
+
const target = PLAN.created[0].path
|
|
2656
|
+
removeButton(harness, target).props.onClick({ preventDefault() {}, stopPropagation() {} })
|
|
2657
|
+
await tick()
|
|
2658
|
+
await tick()
|
|
2659
|
+
|
|
2660
|
+
const calls = deleteFileCalls(harness)
|
|
2661
|
+
assert.equal(calls.length, 1, 'one request')
|
|
2662
|
+
const body = JSON.parse(calls[0].init.body)
|
|
2663
|
+
assert.equal(body.path, target)
|
|
2664
|
+
assert.equal(body.recycle, true, 'recycling is on by default, same as a conversation')
|
|
2665
|
+
})
|
|
2666
|
+
|
|
2667
|
+
test('with recycling off the file is deleted outright', async () => {
|
|
2668
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2669
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2670
|
+
localStorage.setItem(RECYCLE_KEY, '0')
|
|
2671
|
+
mountRow(harness, SESSION_A)
|
|
2672
|
+
await openArtifactDialog(harness)
|
|
2673
|
+
|
|
2674
|
+
const target = PLAN.created[0].path
|
|
2675
|
+
removeButton(harness, target).props.onClick({ preventDefault() {}, stopPropagation() {} })
|
|
2676
|
+
await tick()
|
|
2677
|
+
await tick()
|
|
2678
|
+
|
|
2679
|
+
const body = JSON.parse(deleteFileCalls(harness)[0].init.body)
|
|
2680
|
+
assert.equal(body.recycle, false, 'the switch decides, not the button')
|
|
2681
|
+
})
|
|
2682
|
+
|
|
2683
|
+
test('a deleted file leaves the list and the selection', async () => {
|
|
2684
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2685
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2686
|
+
mountRow(harness, SESSION_A)
|
|
2687
|
+
await openArtifactDialog(harness)
|
|
2688
|
+
|
|
2689
|
+
const target = PLAN.created[0].path
|
|
2690
|
+
assert.ok(fileRow(harness, target), 'the row starts out there')
|
|
2691
|
+
|
|
2692
|
+
removeButton(harness, target).props.onClick({ preventDefault() {}, stopPropagation() {} })
|
|
2693
|
+
await tick()
|
|
2694
|
+
await tick()
|
|
2695
|
+
|
|
2696
|
+
assert.equal(fileRow(harness, target), null, 'the row is gone')
|
|
2697
|
+
assert.equal(artifactRows(harness).length, 1, 'the other file stays')
|
|
2698
|
+
})
|
|
2699
|
+
// --- only the file list earns the wide dialog ------------------------------
|
|
2700
|
+
|
|
2701
|
+
test('a plain confirmation keeps the host compact size', async () => {
|
|
2702
|
+
// No produced files here: the everyday "delete this conversation?" box. A
|
|
2703
|
+
// forced ratio would make it a screen-sized empty rectangle, because a
|
|
2704
|
+
// percentage of a wide monitor is simply a wide box.
|
|
2705
|
+
const harness = await loadPlugin()
|
|
2706
|
+
mountRow(harness, SESSION_A)
|
|
2707
|
+
const { element } = deleteRow(harness, SESSION_A)
|
|
2708
|
+
element.props.onSelect({ shiftKey: false })
|
|
2709
|
+
await flush()
|
|
2710
|
+
|
|
2711
|
+
const modal = dialogElement(harness)
|
|
2712
|
+
assert.ok(modal, 'the dialog opened')
|
|
2713
|
+
assert.equal(modal.props.className, undefined, 'no frame class')
|
|
2714
|
+
assert.equal(modal.props.style, undefined, 'and no forced size')
|
|
2715
|
+
})
|
|
2716
|
+
|
|
2717
|
+
test('the dialog widens when it actually lists files', async () => {
|
|
2718
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2719
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2720
|
+
mountRow(harness, SESSION_A)
|
|
2721
|
+
await openArtifactDialog(harness)
|
|
2722
|
+
|
|
2723
|
+
const modal = dialogElement(harness)
|
|
2724
|
+
assert.equal(modal.props.className, 'dsdel-dialog-wide', 'the list needs the room')
|
|
2725
|
+
})
|
|
2726
|
+
|
|
2727
|
+
test('the stylesheet keys the wide rule on the file rows, not on any meta line', async () => {
|
|
2728
|
+
const harness = await loadPlugin()
|
|
2729
|
+
const style = harness.document.head.querySelector('[data-dsh-delete-session="1"]')
|
|
2730
|
+
const css = String(style._text ?? '')
|
|
2731
|
+
|
|
2732
|
+
// `:has(.dsdel-modal-meta)` matched every dialog this plugin draws — the meta
|
|
2733
|
+
// line is just "title · id" — and widened all of them.
|
|
2734
|
+
assert.doesNotMatch(css, /:has\(\.dsdel-modal-meta\)/, 'no widening on a meta line')
|
|
2735
|
+
assert.match(css, /:has\(\.dsdel-file-row\)/, 'the file rows are what earns the width')
|
|
2736
|
+
})
|
|
2737
|
+
|
|
2738
|
+
test('the dialog is a 16:9 landscape card', async () => {
|
|
2739
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2740
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2741
|
+
mountRow(harness, SESSION_A)
|
|
2742
|
+
await openArtifactDialog(harness)
|
|
2743
|
+
|
|
2744
|
+
const modal = dialogElement(harness)
|
|
2745
|
+
const style = modal.props.style
|
|
2746
|
+
assert.match(String(style.width), /46vw/, 'the width budget is a share of the viewport')
|
|
2747
|
+
assert.match(String(style.width), /860px/, 'and it has a pixel ceiling for large monitors')
|
|
2748
|
+
assert.equal(style.maxHeight, '88vh', 'and never runs past the viewport')
|
|
2749
|
+
|
|
2750
|
+
// The list is the only part that grows, so it is the part that scrolls.
|
|
2751
|
+
const section = artifactSection(harness)
|
|
2752
|
+
assert.equal(section.props.className, 'dsdel-artifacts', 'the column is a scroll container')
|
|
2753
|
+
})
|
|
2754
|
+
|
|
2755
|
+
test('the stylesheet carries the same 16:9 geometry', async () => {
|
|
2756
|
+
const harness = await loadPlugin()
|
|
2757
|
+
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
2758
|
+
|
|
2759
|
+
assert.match(css, /\.dsdel-dialog-wide\{[^}]*max-width/, 'the class rule bounds the width')
|
|
2760
|
+
assert.match(css, /\.dsdel-artifacts\{[^}]*overflow:auto/, 'the column scrolls')
|
|
2761
|
+
})
|
|
2762
|
+
|
|
2763
|
+
test('the fixed-height frame keeps its buttons at the bottom', async () => {
|
|
2764
|
+
const harness = await loadPlugin()
|
|
2765
|
+
const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
|
|
2766
|
+
|
|
2767
|
+
// The host renders the dialog as a flex column of [content, footer]. Keying on
|
|
2768
|
+
// OUR class plus first/last child survives a host restyle, which the hashed
|
|
2769
|
+
// module class names (`_content_14mp3_63`) would not.
|
|
2770
|
+
assert.match(css, /\.dsdel-dialog-wide\{[^}]*display:flex/, 'the frame is a flex column')
|
|
2771
|
+
assert.match(css, /\.dsdel-dialog-wide\{[^}]*flex-direction:column/, 'with the host\'s own direction')
|
|
2772
|
+
assert.match(css, /\.dsdel-dialog-wide > :first-child\{[^}]*flex:1/, 'the content takes the slack')
|
|
2773
|
+
assert.match(css, /\.dsdel-dialog-wide > :first-child\{[^}]*overflow:auto/, 'and scrolls instead of growing')
|
|
2774
|
+
assert.match(css, /\.dsdel-dialog-wide > :last-child\{[^}]*margin-top:auto/, 'the footer is pushed down')
|
|
2775
|
+
})
|
|
2776
|
+
|
|
2777
|
+
test('the frame sizes itself to the list', async () => {
|
|
2778
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
2779
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
2780
|
+
mountRow(harness, SESSION_A)
|
|
2781
|
+
await openArtifactDialog(harness)
|
|
2782
|
+
|
|
2783
|
+
const style = dialogElement(harness).props.style
|
|
2784
|
+
// A ratio pins the height, which is what produced the empty band in the first
|
|
2785
|
+
// place: the box would keep a screen-ish height no matter how few rows it had.
|
|
2786
|
+
assert.equal(style.aspectRatio, undefined, 'no forced ratio')
|
|
2787
|
+
assert.equal(style.height, undefined, 'and no forced height')
|
|
2788
|
+
assert.equal(style.height, undefined, 'the height follows the list, not a ratio')
|
|
2789
|
+
assert.equal(style.maxHeight, '88vh', 'capped by the viewport')
|
|
2790
|
+
assert.match(String(style.minHeight), /240px/, 'and it never collapses')
|
|
2791
|
+
})
|