dsh-delete-session 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +11 -0
- package/cordis.patch.yml +7 -7
- package/package.json +1 -1
- package/src/client.js +217 -25
- package/src/index.js +2168 -2037
- package/test/artifacts.host.test.js +165 -3
- package/test/checkbox.dom.test.js +289 -3
|
@@ -50,7 +50,12 @@ process.env.DSH_HOME = HOME_ROOT
|
|
|
50
50
|
// hand the next test the real home.
|
|
51
51
|
beforeEach(() => {
|
|
52
52
|
assert.equal(process.env.DSH_HOME, HOME_ROOT, 'every test must run against the scratch home')
|
|
53
|
-
|
|
53
|
+
// Compare through realpath: on macOS `os.tmpdir()` is /var/folders/... while
|
|
54
|
+
// the same directory resolves to /private/var/folders/..., and a plain prefix
|
|
55
|
+
// test failed every single test in this file on this machine.
|
|
56
|
+
const tmp = fs.realpathSync(os.tmpdir())
|
|
57
|
+
const root = fs.realpathSync(HOME_ROOT)
|
|
58
|
+
assert.ok(root.startsWith(tmp), 'the scratch home must live under tmp, got ' + HOME_ROOT)
|
|
54
59
|
})
|
|
55
60
|
|
|
56
61
|
function writeAt(root, relative, content = 'x') {
|
|
@@ -1165,10 +1170,24 @@ test('the delete reports which children failed', async () => {
|
|
|
1165
1170
|
|
|
1166
1171
|
const result = await internals.deleteSession(serviceFree, PARENT_ID, {
|
|
1167
1172
|
recycle: false,
|
|
1168
|
-
|
|
1173
|
+
// Not "not-a-session-id": a dashed name is a LEGAL DSH id (the GUI creates
|
|
1174
|
+
// named sessions). What must never become a child delete is an id that
|
|
1175
|
+
// could leave the session store.
|
|
1176
|
+
childSessionIds: ['../etc/passwd'],
|
|
1169
1177
|
})
|
|
1170
1178
|
|
|
1171
|
-
assert.equal(result.children.length, 0, 'an
|
|
1179
|
+
assert.equal(result.children.length, 0, 'an id that could leave a path never becomes a child delete')
|
|
1180
|
+
})
|
|
1181
|
+
|
|
1182
|
+
test('a NAMED session is taken with its parent, like any other id', async () => {
|
|
1183
|
+
const parent = plantSession(PARENT_ID)
|
|
1184
|
+
const named = plantSession('bili-whale')
|
|
1185
|
+
|
|
1186
|
+
await internals.deleteSession(serviceFree, PARENT_ID, { recycle: false, childSessionIds: ['bili-whale'] })
|
|
1187
|
+
|
|
1188
|
+
assert.equal(fs.existsSync(parent.dir), false, 'the parent is gone')
|
|
1189
|
+
assert.equal(fs.existsSync(named.dir), false, 'the named child went with it')
|
|
1190
|
+
assert.equal(fs.existsSync(named.cache), false, 'and so did its cache row')
|
|
1172
1191
|
})
|
|
1173
1192
|
|
|
1174
1193
|
test('a child is probed for a live writer before its files go', async () => {
|
|
@@ -1310,3 +1329,146 @@ test('the native chooser is given a live abort signal', async () => {
|
|
|
1310
1329
|
assert.equal(typeof seen.aborted, 'boolean', 'and it is an AbortSignal')
|
|
1311
1330
|
assert.equal(seen.aborted, false, 'not already aborted')
|
|
1312
1331
|
})
|
|
1332
|
+
|
|
1333
|
+
// --- both subagent creation modes are deletable, and only they -------------
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* A subagent started in "fork" mode: it inherits a seeded prefix of the parent
|
|
1337
|
+
* log, so the header carries `isSeeded: true` — but `origin` is still `subagent`,
|
|
1338
|
+
* and the host writes it for both creation modes
|
|
1339
|
+
* (`childSessionMeta` in dsh-subagent sets `origin: "subagent"` unconditionally,
|
|
1340
|
+
* with `isSeeded` recording which mode was used).
|
|
1341
|
+
*/
|
|
1342
|
+
const forkedSubagent = (id, parentSession) => ({
|
|
1343
|
+
id,
|
|
1344
|
+
parentSession,
|
|
1345
|
+
origin: 'subagent',
|
|
1346
|
+
isSeeded: true,
|
|
1347
|
+
delegationDepth: 1,
|
|
1348
|
+
})
|
|
1349
|
+
|
|
1350
|
+
test('a subagent started by fork is still a child of its parent', () => {
|
|
1351
|
+
const headers = [
|
|
1352
|
+
header('session-parent'),
|
|
1353
|
+
child('session-child-new', 'session-parent'),
|
|
1354
|
+
forkedSubagent('session-child-fork', 'session-parent'),
|
|
1355
|
+
]
|
|
1356
|
+
|
|
1357
|
+
const found = internals.collectDescendants(headers, 'session-parent')
|
|
1358
|
+
|
|
1359
|
+
assert.deepEqual(
|
|
1360
|
+
found.map((h) => h.id),
|
|
1361
|
+
['session-child-new', 'session-child-fork'],
|
|
1362
|
+
'both creation modes are picked up',
|
|
1363
|
+
)
|
|
1364
|
+
})
|
|
1365
|
+
|
|
1366
|
+
test('a forked subagent can be deleted on its own', () => {
|
|
1367
|
+
const headers = [header('session-parent'), forkedSubagent('session-child-fork', 'session-parent')]
|
|
1368
|
+
|
|
1369
|
+
const picked = internals.selectChildDeletes(headers, 'session-parent', ['session-child-fork'])
|
|
1370
|
+
|
|
1371
|
+
assert.deepEqual(picked, ['session-child-fork'], 'deleting the parent may take the fork-mode child')
|
|
1372
|
+
})
|
|
1373
|
+
|
|
1374
|
+
test('the two modes are told apart from a user fork, which stays untouched', () => {
|
|
1375
|
+
const headers = [
|
|
1376
|
+
header('session-parent'),
|
|
1377
|
+
child('session-child-new', 'session-parent'),
|
|
1378
|
+
forkedSubagent('session-child-fork', 'session-parent'),
|
|
1379
|
+
fork('session-user-fork', 'session-parent'),
|
|
1380
|
+
]
|
|
1381
|
+
|
|
1382
|
+
const found = internals.collectDescendants(headers, 'session-parent').map((h) => h.id)
|
|
1383
|
+
|
|
1384
|
+
assert.deepEqual(found, ['session-child-new', 'session-child-fork'], 'subagents only')
|
|
1385
|
+
assert.equal(found.includes('session-user-fork'), false, 'a conversation the user branched is not dragged along')
|
|
1386
|
+
})
|
|
1387
|
+
// --- deleting one produced file, with the same recycle choice ----------------
|
|
1388
|
+
|
|
1389
|
+
test('only the files the dialog listed may be deleted one by one', () => {
|
|
1390
|
+
const plan = {
|
|
1391
|
+
created: [{ path: 'C:/ws/new-a.md', ops: 1 }],
|
|
1392
|
+
modified: [{ path: 'C:/ws/old-c.md', ops: 2 }],
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
const candidates = internals.artifactCandidates(plan)
|
|
1396
|
+
|
|
1397
|
+
assert.deepEqual(candidates.sort(), ['C:/ws/new-a.md', 'C:/ws/old-c.md'])
|
|
1398
|
+
// A path the plan never offered is refused by the route; this is the list it
|
|
1399
|
+
// checks against, so it has to cover both groups.
|
|
1400
|
+
assert.equal(candidates.includes('C:/ws/secret.md'), false)
|
|
1401
|
+
})
|
|
1402
|
+
|
|
1403
|
+
test('a permanent single-file delete really removes the file', async () => {
|
|
1404
|
+
const file = path.join(os.tmpdir(), `dsdel-one-${Date.now()}.md`)
|
|
1405
|
+
fs.writeFileSync(file, 'x')
|
|
1406
|
+
|
|
1407
|
+
const result = await internals.removeOneFile(file, false)
|
|
1408
|
+
|
|
1409
|
+
assert.equal(result.recycled, false)
|
|
1410
|
+
assert.equal(fs.existsSync(file), false, 'gone')
|
|
1411
|
+
})
|
|
1412
|
+
|
|
1413
|
+
test('a missing file is reported instead of throwing raw', async () => {
|
|
1414
|
+
const file = path.join(os.tmpdir(), `dsdel-one-missing-${Date.now()}.md`)
|
|
1415
|
+
|
|
1416
|
+
await assert.rejects(
|
|
1417
|
+
() => internals.removeOneFile(file, false),
|
|
1418
|
+
(error) => error instanceof Error,
|
|
1419
|
+
)
|
|
1420
|
+
})
|
|
1421
|
+
|
|
1422
|
+
test('a directory is refused: this button deletes files, not folders', async () => {
|
|
1423
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dsdel-one-dir-'))
|
|
1424
|
+
try {
|
|
1425
|
+
await assert.rejects(
|
|
1426
|
+
() => internals.removeOneFile(dir, false),
|
|
1427
|
+
(error) => error && error.code === 'not-a-file',
|
|
1428
|
+
)
|
|
1429
|
+
} finally {
|
|
1430
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
1431
|
+
}
|
|
1432
|
+
})
|
|
1433
|
+
|
|
1434
|
+
test('a path the plan never listed is refused', () => {
|
|
1435
|
+
const plan = { created: [{ path: 'C:/ws/listed.md' }], modified: [] }
|
|
1436
|
+
|
|
1437
|
+
assert.equal(internals.assertListedPath(plan, 'C:/ws/listed.md'), path.resolve('C:/ws/listed.md'))
|
|
1438
|
+
assert.throws(
|
|
1439
|
+
() => internals.assertListedPath(plan, 'C:/ws/secret.md'),
|
|
1440
|
+
(error) => error && error.code === 'not-listed',
|
|
1441
|
+
)
|
|
1442
|
+
})
|
|
1443
|
+
test('a session that names thousands of files is scanned up to a limit, not forever', async () => {
|
|
1444
|
+
// Every distinct path the log names costs a realpath. A runaway session (an
|
|
1445
|
+
// agent that walked a large tree) can name tens of thousands, and the dialog
|
|
1446
|
+
// would sit on "正在扫描…" while all of them are resolved. The cap bounds that
|
|
1447
|
+
// work; the plan reports `truncated`, which the dialog already shows.
|
|
1448
|
+
const events = []
|
|
1449
|
+
for (let i = 0; i < internals.MAX_SCANNED + 50; i += 1) {
|
|
1450
|
+
events.push({
|
|
1451
|
+
type: 'tool/call',
|
|
1452
|
+
data: {
|
|
1453
|
+
name: 'write',
|
|
1454
|
+
arguments: JSON.stringify({ path: `C:/ws/file-${i}.md` }),
|
|
1455
|
+
},
|
|
1456
|
+
})
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
const result = await internals.collectSessionPaths(events, 'C:/ws', new Map())
|
|
1460
|
+
|
|
1461
|
+
assert.equal(result.overflow, true, 'the scan says it stopped early')
|
|
1462
|
+
assert.equal(result.named <= internals.MAX_SCANNED, true, 'and resolved no more than the cap')
|
|
1463
|
+
})
|
|
1464
|
+
|
|
1465
|
+
test('a small session is not flagged as truncated', async () => {
|
|
1466
|
+
const events = [
|
|
1467
|
+
{ type: 'tool/call', data: { name: 'write', arguments: JSON.stringify({ path: 'C:/ws/a.md' }) } },
|
|
1468
|
+
{ type: 'tool/call', data: { name: 'write', arguments: JSON.stringify({ path: 'C:/ws/b.md' }) } },
|
|
1469
|
+
]
|
|
1470
|
+
|
|
1471
|
+
const result = await internals.collectSessionPaths(events, 'C:/ws', new Map())
|
|
1472
|
+
|
|
1473
|
+
assert.equal(result.overflow, false)
|
|
1474
|
+
})
|
|
@@ -333,6 +333,9 @@ async function loadPlugin(options = {}) {
|
|
|
333
333
|
}
|
|
334
334
|
// The native dialog route. `unsupported` models a platform without one, which
|
|
335
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
|
+
}
|
|
336
339
|
if (href.endsWith('/dsh-delete-session/pick')) {
|
|
337
340
|
const pick = options.pick ?? { cancelled: true, path: null }
|
|
338
341
|
if (pick.unsupported === true) {
|
|
@@ -1068,14 +1071,16 @@ const artifactSection = (harness) => {
|
|
|
1068
1071
|
return kids.find((node) => node && node.props && node.props.key === 'artifacts') ?? null
|
|
1069
1072
|
}
|
|
1070
1073
|
|
|
1071
|
-
/** One rendered
|
|
1074
|
+
/** One rendered row block per listed artifact. */
|
|
1072
1075
|
const artifactRows = (harness) => {
|
|
1073
1076
|
const section = artifactSection(harness)
|
|
1074
1077
|
if (section === null) return []
|
|
1075
|
-
return (section.props.children || []).filter((node) => node && node.
|
|
1078
|
+
return (section.props.children || []).filter((node) => node && node.props && node.props['data-file-row'] !== undefined)
|
|
1076
1079
|
}
|
|
1077
1080
|
|
|
1078
|
-
|
|
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])
|
|
1079
1084
|
|
|
1080
1085
|
/** Open the dialog through the real menu row and let the scan settle. */
|
|
1081
1086
|
async function openArtifactDialog(harness, session = SESSION_A) {
|
|
@@ -2503,3 +2508,284 @@ test('a fresh install deletes the children without listing them', async () => {
|
|
|
2503
2508
|
'and the delete carries them',
|
|
2504
2509
|
)
|
|
2505
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
|
+
})
|