dsh-delete-session 0.3.0 → 0.3.2

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.
@@ -233,6 +233,12 @@ let bundleFactory = null
233
233
  // next one can drop the leftovers.
234
234
  const rafQueues = []
235
235
 
236
+ // Timers started by a plugin instance outlive the test that started them. The
237
+ // batch path schedules a 2.5 s settle, and its callback decorates whatever
238
+ // `globalThis.document` is when it fires - the next test's DOM. Track and
239
+ // clear them so one test cannot reach into another.
240
+ const pendingTimers = []
241
+
236
242
  /**
237
243
  * The bundle registers through `window.__ModuleLoader__` once per process and ESM
238
244
  * caching means a second `import()` never re-runs it. Caching the factory is also
@@ -251,6 +257,8 @@ async function loadPlugin(options = {}) {
251
257
  const document = {
252
258
  body: new StubElement('body'),
253
259
  head: new StubElement('head'),
260
+ // Read when the host provides no locale service at all.
261
+ documentElement: new StubElement('html'),
254
262
  createElement: (tag) => new StubElement(tag),
255
263
  addEventListener(type, handler) {
256
264
  const list = documentListeners.get(type) ?? []
@@ -317,6 +325,13 @@ async function loadPlugin(options = {}) {
317
325
  // very regression this file exists to catch.
318
326
  // Drop anything an earlier instance queued: it would run against THIS dom.
319
327
  for (const stale of rafQueues) stale.clear()
328
+ while (pendingTimers.length > 0) clearTimeout(pendingTimers.pop())
329
+ const realSetTimeout = globalThis.setTimeout
330
+ globalThis.setTimeout = (fn, ms) => {
331
+ const id = realSetTimeout(fn, ms)
332
+ pendingTimers.push(id)
333
+ return id
334
+ }
320
335
  let rafId = 0
321
336
  const rafQueue = new Map()
322
337
  rafQueues.push(rafQueue)
@@ -386,6 +401,11 @@ async function loadPlugin(options = {}) {
386
401
  const locales = {}
387
402
  const localeStub = {
388
403
  register: (namespace, dictionaries) => { locales[namespace] = dictionaries },
404
+ // `dsh-client-locale` exposes `getSnapshot() -> { active }`. The plugin follows
405
+ // it instead of `navigator.language`, so an English OS with DSH in Chinese no
406
+ // longer renders an English plugin (issue #3).
407
+ getSnapshot: () => ({ active: options.activeLocale ?? 'zh', locales: [], revision: 0 }),
408
+ subscribe: () => () => {},
389
409
  // Mirrors dsh-client-locale: a non-string entry is handed back untouched, and
390
410
  // only string templates interpolate `{name}` from a params object. Returning
391
411
  // a function as-is is exactly what makes the plugin fall back to its own
@@ -436,11 +456,14 @@ async function loadPlugin(options = {}) {
436
456
  if (name === 'slots') return slotsStub
437
457
  // `lateLocale` models a host where the locale service is only reachable
438
458
  // through ctx.inject, which is the path that used to skip registration.
439
- if (name === 'locale') return options.lateLocale ? null : localeStub
459
+ if (name === 'locale') return (options.lateLocale || options.noLocale) ? null : localeStub
440
460
  return null
441
461
  },
442
462
  inject: (names, cb) => {
443
- if (typeof cb === 'function') cb(options.lateLocale ? { slots: slotsStub, locale: localeStub } : { slots: slotsStub })
463
+ if (typeof cb === 'function') {
464
+ const late = options.lateLocale && !options.noLocale
465
+ cb(late ? { slots: slotsStub, locale: localeStub } : { slots: slotsStub })
466
+ }
444
467
  },
445
468
  effect: (fn) => { const dispose = fn(); return () => { if (typeof dispose === 'function') dispose() } },
446
469
  })
@@ -593,13 +616,13 @@ const clickBar = (node) => node.props.onClick({ stopPropagation() {} })
593
616
  const tick = () => new Promise((resolve) => setTimeout(resolve, 0))
594
617
 
595
618
  /** Let the queued rAF decorate passes drain. */
596
- const flush = async () => { await tick() }
597
-
598
- /**
599
- * Drain until nothing is left. `flush()` is one tick, and a decorate pass can
600
- * queue another callback while it runs; a test that snapshots a counter right
601
- * after a single flush occasionally catches a straggler.
602
- */
619
+ const flush = async () => { await tick() }
620
+
621
+ /**
622
+ * Drain until nothing is left. `flush()` is one tick, and a decorate pass can
623
+ * queue another callback while it runs; a test that snapshots a counter right
624
+ * after a single flush occasionally catches a straggler.
625
+ */
603
626
  const settle = async () => { for (let i = 0; i < 20; i += 1) await flush() }
604
627
 
605
628
  /**
@@ -710,8 +733,69 @@ test('the Russian dictionary ships with every key the other dictionaries carry',
710
733
  assert.deepEqual(keys(en), keys(zh), 'en still covers the zh key set')
711
734
  })
712
735
 
713
- test('a Russian browser gets Russian labels from the built-in dictionary', async () => {
714
- const harness = await loadPlugin()
736
+ test('an English OS with DSH in Chinese renders Chinese (issue #3)', async () => {
737
+ const harness = await loadPlugin({ activeLocale: 'zh' })
738
+ const previous = globalThis.navigator
739
+ Object.defineProperty(globalThis, 'navigator', {
740
+ value: { language: 'en-US', languages: ['en-US'] },
741
+ configurable: true,
742
+ writable: true,
743
+ })
744
+ try {
745
+ // The reported bug: the OS is English, the user set DSH to 中文, and the plugin
746
+ // still answered in English because it read `navigator.language`. The host is
747
+ // the authority now, so the browser language must not win.
748
+ assert.equal(deleteRow(harness).element.props.children, '删除会话')
749
+ assert.equal(selectRow(harness).element.props.children, '多选')
750
+ } finally {
751
+ Object.defineProperty(globalThis, 'navigator', {
752
+ value: previous,
753
+ configurable: true,
754
+ writable: true,
755
+ })
756
+ }
757
+ })
758
+
759
+ test('a Chinese OS with DSH in English renders English', async () => {
760
+ const harness = await loadPlugin({ activeLocale: 'en' })
761
+ const previous = globalThis.navigator
762
+ Object.defineProperty(globalThis, 'navigator', {
763
+ value: { language: 'zh-CN', languages: ['zh-CN'] },
764
+ configurable: true,
765
+ writable: true,
766
+ })
767
+ try {
768
+ assert.equal(deleteRow(harness).element.props.children, 'Delete session')
769
+ assert.equal(selectRow(harness).element.props.children, 'Select multiple')
770
+ } finally {
771
+ Object.defineProperty(globalThis, 'navigator', {
772
+ value: previous,
773
+ configurable: true,
774
+ writable: true,
775
+ })
776
+ }
777
+ })
778
+
779
+ test('a host language we do not ship falls back to English', async () => {
780
+ const harness = await loadPlugin({ activeLocale: 'ja' })
781
+
782
+ // DSH knows ja/es/fr/de/pt as well. Those have no dictionary here, and the host
783
+ // would answer in English for them, so the plugin does too instead of silently
784
+ // dropping to Chinese (which is what the old browser-based fallback did).
785
+ assert.equal(deleteRow(harness).element.props.children, 'Delete session')
786
+ })
787
+
788
+ test('with no locale service the document hint decides', async () => {
789
+ const harness = await loadPlugin({ lateLocale: true, noLocale: true })
790
+ harness.document.documentElement.lang = 'ru'
791
+
792
+ // `dsh-client-locale` mirrors its choice onto `<html lang>`. A host that never
793
+ // hands over the service still leaves that behind, so it is read next.
794
+ assert.equal(deleteRow(harness).element.props.children, 'Удалить сессию')
795
+ })
796
+
797
+ test('with neither hint the browser language is the last resort', async () => {
798
+ const harness = await loadPlugin({ noLocale: true })
715
799
  const previous = globalThis.navigator
716
800
  Object.defineProperty(globalThis, 'navigator', {
717
801
  value: { language: 'ru-RU', languages: ['ru-RU'] },
@@ -719,10 +803,9 @@ test('a Russian browser gets Russian labels from the built-in dictionary', async
719
803
  writable: true,
720
804
  })
721
805
  try {
722
- // The host translator in this harness answers in zh; the rows must prefer the
723
- // plugin's own Russian dictionary instead of following it.
806
+ // Pre-#3 behaviour, kept as the floor: something has to answer when the host
807
+ // provides nothing at all.
724
808
  assert.equal(deleteRow(harness).element.props.children, 'Удалить сессию')
725
- assert.equal(selectRow(harness).element.props.children, 'Выбрать несколько')
726
809
  } finally {
727
810
  Object.defineProperty(globalThis, 'navigator', {
728
811
  value: previous,
@@ -731,6 +814,14 @@ test('a Russian browser gets Russian labels from the built-in dictionary', async
731
814
  })
732
815
  }
733
816
  })
817
+ test('a Russian DSH gets Russian labels from the built-in dictionary', async () => {
818
+ const harness = await loadPlugin({ activeLocale: 'ru' })
819
+
820
+ // The host translator in this harness answers in zh; the rows must prefer the
821
+ // plugin's own Russian dictionary instead of following it.
822
+ assert.equal(deleteRow(harness).element.props.children, 'Удалить сессию')
823
+ assert.equal(selectRow(harness).element.props.children, 'Выбрать несколько')
824
+ })
734
825
 
735
826
  test('the delete row asks the host for its danger styling', async () => {
736
827
  const harness = await loadPlugin()
@@ -2878,704 +2969,773 @@ test('a button-shaped footer entry steps aside without hiding the bar itself', a
2878
2969
  /\[data-slot="sidebar\.footer\.action"\] > button\{display:none\}/,
2879
2970
  'never hide every button unconditionally',
2880
2971
  )
2881
- })
2882
-
2883
- test('the drop label names the conversation instead of printing the placeholder', async () => {
2884
- const harness = await loadPlugin()
2885
- const row = mountRow(harness, SESSION_A)
2886
-
2887
- startRowDrag(harness, row)
2888
- await flush()
2889
- bar(harness).props.onDragOver(dropEvent())
2890
- await flush()
2891
-
2892
- const node = bar(harness)
2893
- const text = JSON.stringify(node.props.children)
2894
-
2895
- // The dictionary entry is `松手删除「{name}」`, but the interpolation map carries
2896
- // `n`/`done`/`total`/`ok`/`fail`/`path` — not `name`. Passing the title as a bare
2897
- // string therefore left the braces in the label.
2898
- assert.doesNotMatch(text, /\{name\}/, 'no unsubstituted placeholder in the label')
2899
- assert.match(text, /松手删除/, 'the sentence is still there')
2900
- })
2901
-
2902
- test('the drop label carries the dragged conversation title', async () => {
2903
- const harness = await loadPlugin()
2904
- const row = mountRow(harness, SESSION_A)
2905
- row.textContent = 'BiliLearn-AI 仓库'
2906
-
2907
- startRowDrag(harness, row)
2908
- await flush()
2909
- bar(harness).props.onDragOver(dropEvent())
2910
- await flush()
2911
-
2912
- const text = JSON.stringify(bar(harness).props.children)
2913
- assert.match(text, /BiliLearn-AI 仓库/, 'the title reaches the sentence')
2914
- })
2915
- test('a workspace header offers a select-all box', async () => {
2916
- const harness = await loadPlugin()
2917
- const section = harness.document.createElement('div')
2918
- section.setAttribute('role', 'group')
2919
-
2920
- const header = harness.document.createElement('div')
2921
- header.setAttribute('role', 'treeitem')
2922
- header.setAttribute('data-row-key', 'workspace:ws-a')
2923
- section.appendChild(header)
2924
-
2925
- mountRow(harness, SESSION_A, section)
2926
- mountRow(harness, SESSION_B, section)
2927
- harness.document.body.appendChild(section)
2928
-
2929
- await enterMulti(harness)
2930
- observerPass(harness)
2931
- await flush()
2932
-
2933
- const box = header.querySelector('.dsdel-select-all')
2934
- assert.ok(box, 'the header carries one')
2935
- assert.equal(box.getAttribute('role'), 'checkbox')
2936
- assert.equal(box.getAttribute('aria-checked'), 'false', 'nothing picked yet')
2937
- })
2938
-
2939
- test('the workspace box selects only its own sessions', async () => {
2940
- const harness = await loadPlugin()
2941
- const sectionA = harness.document.createElement('div')
2942
- sectionA.setAttribute('role', 'group')
2943
- const headA = harness.document.createElement('div')
2944
- headA.setAttribute('role', 'treeitem')
2945
- headA.setAttribute('data-row-key', 'workspace:ws-a')
2946
- sectionA.appendChild(headA)
2947
- mountRow(harness, SESSION_A, sectionA)
2948
- harness.document.body.appendChild(sectionA)
2949
-
2950
- const sectionB = harness.document.createElement('div')
2951
- sectionB.setAttribute('role', 'group')
2952
- const headB = harness.document.createElement('div')
2953
- headB.setAttribute('role', 'treeitem')
2954
- headB.setAttribute('data-row-key', 'workspace:ws-b')
2955
- sectionB.appendChild(headB)
2956
- mountRow(harness, SESSION_B, sectionB)
2957
- harness.document.body.appendChild(sectionB)
2958
-
2959
- await enterMulti(harness)
2960
- observerPass(harness)
2961
- await flush()
2962
-
2963
- headA.querySelector('.dsdel-select-all').fire('click')
2964
- await flush()
2965
-
2966
- assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true', 'A turned on')
2967
- const boxB = headB.querySelector('.dsdel-select-all')
2968
- assert.equal(boxB.getAttribute('aria-checked'), 'false', 'B untouched')
2969
- })
2970
-
2971
- test('a second press clears the workspace again', async () => {
2972
- const harness = await loadPlugin()
2973
- const section = harness.document.createElement('div')
2974
- section.setAttribute('role', 'group')
2975
- const header = harness.document.createElement('div')
2976
- header.setAttribute('role', 'treeitem')
2977
- header.setAttribute('data-row-key', 'workspace:ws-a')
2978
- section.appendChild(header)
2979
- mountRow(harness, SESSION_A, section)
2980
- harness.document.body.appendChild(section)
2981
-
2982
- await enterMulti(harness)
2983
- observerPass(harness)
2984
- await flush()
2985
-
2986
- const box = header.querySelector('.dsdel-select-all')
2987
- box.fire('click')
2988
- await flush()
2989
- assert.equal(box.getAttribute('aria-checked'), 'true')
2990
-
2991
- box.fire('click')
2992
- await flush()
2993
- assert.equal(box.getAttribute('aria-checked'), 'false')
2994
- })
2995
-
2996
- test('the box reports a partly picked workspace as mixed', async () => {
2997
- const harness = await loadPlugin()
2998
- const section = harness.document.createElement('div')
2999
- section.setAttribute('role', 'group')
3000
- const header = harness.document.createElement('div')
3001
- header.setAttribute('role', 'treeitem')
3002
- header.setAttribute('data-row-key', 'workspace:ws-a')
3003
- section.appendChild(header)
3004
- const rowA = mountRow(harness, SESSION_A, section)
3005
- mountRow(harness, SESSION_B, section)
3006
- harness.document.body.appendChild(section)
3007
-
3008
- await enterMulti(harness)
3009
- observerPass(harness)
3010
- await flush()
3011
-
3012
- clickRowIn(harness, rowA)
3013
- observerPass(harness)
3014
- await flush()
3015
-
3016
- assert.equal(header.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'mixed')
3017
- })
3018
-
3019
- test('the heading row selects every workspace at once', async () => {
3020
- const harness = await loadPlugin()
3021
- const heading = harness.document.createElement('div')
3022
- heading.setAttribute('data-sidebar-workspace-header', '')
3023
- harness.document.body.appendChild(heading)
3024
-
3025
- const sectionA = harness.document.createElement('div')
3026
- sectionA.setAttribute('role', 'group')
3027
- const headA = harness.document.createElement('div')
3028
- headA.setAttribute('role', 'treeitem')
3029
- headA.setAttribute('data-row-key', 'workspace:ws-a')
3030
- sectionA.appendChild(headA)
3031
- mountRow(harness, SESSION_A, sectionA)
3032
- harness.document.body.appendChild(sectionA)
3033
-
3034
- const sectionB = harness.document.createElement('div')
3035
- sectionB.setAttribute('role', 'group')
3036
- const headB = harness.document.createElement('div')
3037
- headB.setAttribute('role', 'treeitem')
3038
- headB.setAttribute('data-row-key', 'workspace:ws-b')
3039
- sectionB.appendChild(headB)
3040
- mountRow(harness, SESSION_B, sectionB)
3041
- harness.document.body.appendChild(sectionB)
3042
-
3043
- await enterMulti(harness)
3044
- observerPass(harness)
3045
- await flush()
3046
-
3047
- const all = heading.querySelector('.dsdel-select-all-workspaces')
3048
- assert.ok(all, 'the heading carries the global box')
3049
- all.fire('click')
3050
- await flush()
3051
-
3052
- assert.equal(all.getAttribute('aria-checked'), 'true', 'everything picked')
3053
- assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
3054
- assert.equal(headB.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
3055
- })
3056
-
3057
- test('both boxes go away when the mode ends', async () => {
3058
- const harness = await loadPlugin()
3059
- const heading = harness.document.createElement('div')
3060
- heading.setAttribute('data-sidebar-workspace-header', '')
3061
- harness.document.body.appendChild(heading)
3062
-
3063
- const section = harness.document.createElement('div')
3064
- section.setAttribute('role', 'group')
3065
- const header = harness.document.createElement('div')
3066
- header.setAttribute('role', 'treeitem')
3067
- header.setAttribute('data-row-key', 'workspace:ws-a')
3068
- section.appendChild(header)
3069
- mountRow(harness, SESSION_A, section)
3070
- harness.document.body.appendChild(section)
3071
-
3072
- await enterMulti(harness)
3073
- observerPass(harness)
3074
- await flush()
3075
- assert.ok(header.querySelector('.dsdel-select-all'), 'present during the mode')
3076
- assert.ok(heading.querySelector('.dsdel-select-all-workspaces'))
3077
-
3078
- harness.document.dispatchToDocument('keydown', { key: 'Escape', stopPropagation() {} })
3079
- observerPass(harness)
3080
- await flush()
3081
-
3082
- assert.equal(header.querySelector('.dsdel-select-all'), null, 'removed with the mode')
3083
- assert.equal(heading.querySelector('.dsdel-select-all-workspaces'), null)
3084
- })
3085
-
3086
- test('the select-all boxes do not lean on the page token scope', async () => {
3087
- const harness = await loadPlugin()
3088
- const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3089
-
3090
- // The boxes render inside the SIDEBAR. The `--dsdel-*` tokens are declared on
3091
- // `.dsdel-page`, `.dsdel-modal` and `.dsdel-bar` only, so any rule outside those
3092
- // scopes that reads them gets an invalid value and loses the whole declaration.
3093
- // That is how the first version shipped an invisible button: `border` was
3094
- // dropped, leaving no box and nothing to click.
3095
- const rules = [...css.matchAll(/(?:^|\})\s*\.dsdel-select-all[^{]*\{([^}]*)\}/g)]
3096
- assert.ok(rules.length > 0, 'the rules are in the stylesheet')
3097
- for (const match of rules) {
3098
- assert.equal(match[1].includes('--dsdel-'), false,
3099
- 'a sidebar rule must not read the page tokens: ' + match[0].slice(0, 60))
3100
- }
3101
-
3102
- // Every host alias carries a literal fallback, so the box still draws when the
3103
- // host renames its palette.
3104
- assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-border-l2,[^)]*\)/, 'border has a fallback')
3105
- assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-brand-primary,[^)]*\)/, 'brand has a fallback')
3106
- })
3107
-
3108
- test('a box always keeps a visible 15px square', async () => {
3109
- const harness = await loadPlugin()
3110
- const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3111
-
3112
- // A flex child with no width collapses to its content, and the empty state has
3113
- // no content: `width` plus `min-width` plus content-box sizing is what makes the
3114
- // square exist before anything is ticked.
3115
- assert.match(css, /\.dsdel-select-all[^}]*width:15px/, 'a fixed width')
3116
- assert.match(css, /\.dsdel-select-all[^}]*height:15px/, 'and a fixed height')
3117
- assert.match(css, /\.dsdel-select-all[^}]*min-width:15px/, 'that flex cannot shrink away')
3118
- assert.match(css, /\.dsdel-select-all[^}]*box-sizing:border-box/, 'with the border inside it')
3119
- })
3120
-
3121
- test('the workspace box sits beside the name, not at the row edge', async () => {
3122
- const harness = await loadPlugin()
3123
- const section = harness.document.createElement('div')
3124
- section.setAttribute('role', 'group')
3125
-
3126
- const header = harness.document.createElement('div')
3127
- header.setAttribute('role', 'treeitem')
3128
- header.setAttribute('data-row-key', 'workspace:ws-a')
3129
-
3130
- // The host row: label block, then the action cluster (which carries margin-left:auto).
3131
- const label = harness.document.createElement('span')
3132
- label.className = 'YDXeBa_projectText'
3133
- header.appendChild(label)
3134
- const actions = harness.document.createElement('span')
3135
- actions.className = 'YDXeBa_rowActions'
3136
- header.appendChild(actions)
3137
-
3138
- section.appendChild(header)
3139
- mountRow(harness, SESSION_A, section)
3140
- harness.document.body.appendChild(section)
3141
-
3142
- await enterMulti(harness)
3143
- observerPass(harness)
3144
- await flush()
3145
-
3146
- const box = header.querySelector('.dsdel-select-all')
3147
- assert.ok(box, 'the box exists')
3148
-
3149
- // Appending put it after the action cluster, whose auto margin pushes it into the
3150
- // far right of the row — that is the "靠右" the screenshot showed. It has to be
3151
- // inserted before the actions instead.
3152
- const index = header.children.indexOf(box)
3153
- const actionsIndex = header.children.indexOf(actions)
3154
- assert.equal(index < actionsIndex, true, 'the box comes before the action cluster')
3155
- assert.equal(header.children[index - 1].className, 'YDXeBa_projectText', 'and right after the label')
3156
- })
3157
-
3158
- test('the global box sits after the heading label, before the search slot', async () => {
3159
- const harness = await loadPlugin()
3160
-
3161
- const heading = harness.document.createElement('div')
3162
- heading.setAttribute('data-sidebar-workspace-header', '')
3163
-
3164
- const label = harness.document.createElement('span')
3165
- label.className = 'bhn1Oq_sectionLabel'
3166
- heading.appendChild(label)
3167
- const search = harness.document.createElement('div')
3168
- search.className = 'bhn1Oq_searchSlot'
3169
- heading.appendChild(search)
3170
-
3171
- harness.document.body.appendChild(heading)
3172
-
3173
- const section = harness.document.createElement('div')
3174
- section.setAttribute('role', 'group')
3175
- const header = harness.document.createElement('div')
3176
- header.setAttribute('role', 'treeitem')
3177
- header.setAttribute('data-row-key', 'workspace:ws-a')
3178
- section.appendChild(header)
3179
- mountRow(harness, SESSION_A, section)
3180
- harness.document.body.appendChild(section)
3181
-
3182
- await enterMulti(harness)
3183
- observerPass(harness)
3184
- await flush()
3185
-
3186
- const box = heading.querySelector('.dsdel-select-all-workspaces')
3187
- assert.ok(box, 'the global box exists')
3188
- const index = heading.children.indexOf(box)
3189
- assert.equal(index < heading.children.indexOf(search), true, 'before the search slot')
3190
- assert.equal(heading.children[index - 1].className, 'bhn1Oq_sectionLabel', 'and after the label')
3191
- })
3192
-
3193
- test('a box left at the wrong edge is moved on the next pass', async () => {
3194
- const harness = await loadPlugin()
3195
- const section = harness.document.createElement('div')
3196
- section.setAttribute('role', 'group')
3197
-
3198
- const header = harness.document.createElement('div')
3199
- header.setAttribute('role', 'treeitem')
3200
- header.setAttribute('data-row-key', 'workspace:ws-a')
3201
-
3202
- const label = harness.document.createElement('span')
3203
- label.className = 'wnFoaW_projectText'
3204
- header.appendChild(label)
3205
- const actions = harness.document.createElement('span')
3206
- actions.className = 'wnFoaW_rowActions'
3207
- header.appendChild(actions)
3208
-
3209
- // An earlier build left its box AFTER the actions: the far edge.
3210
- const stale = harness.document.createElement('button')
3211
- stale.className = 'dsdel-select-all'
3212
- header.appendChild(stale)
3213
-
3214
- section.appendChild(header)
3215
- mountRow(harness, SESSION_A, section)
3216
- harness.document.body.appendChild(section)
3217
-
3218
- await enterMulti(harness)
3219
- observerPass(harness)
3220
- await flush()
3221
-
3222
- // The insert used to live inside the "created" branch, so an existing box was
3223
- // never repositioned: the heading box moved and the workspace box stayed put.
3224
- const index = header.children.indexOf(stale)
3225
- assert.equal(index < header.children.indexOf(actions), true, 'moved before the actions')
3226
- assert.equal(header.children[index - 1].className, 'wnFoaW_projectText', 'and beside the label')
3227
- })
3228
-
3229
- test('the workspace name stops absorbing the row while the mode runs', async () => {
3230
- const harness = await loadPlugin()
3231
- const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3232
-
3233
- // `.projectText` carries `flex:1`, so it fills whatever the actions do not take.
3234
- // A box inserted after it therefore lands at the row's far edge even though it
3235
- // is early in the child list — that is why the workspace box stayed right while
3236
- // the header box (whose label is not flexed) moved. The rule only applies while
3237
- // the mode runs, so the host keeps its normal layout otherwise.
3238
- assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*flex:0 1 auto/,
3239
- 'the name sizes to its text during the mode')
3240
- assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*min-width:0/,
3241
- 'and can still truncate a long name')
3242
- })
3243
-
3244
- test('a spacer keeps the right-hand cluster in place', async () => {
3245
- const harness = await loadPlugin()
3246
- const section = harness.document.createElement('div')
3247
- section.setAttribute('role', 'group')
3248
-
3249
- const header = harness.document.createElement('div')
3250
- header.setAttribute('role', 'treeitem')
3251
- header.setAttribute('data-row-key', 'workspace:ws-a')
3252
-
3253
- const label = harness.document.createElement('span')
3254
- label.className = 'wnFoaW_projectText'
3255
- header.appendChild(label)
3256
- // The cluster that must NOT move: count, menu, new-session.
3257
- const actions = harness.document.createElement('span')
3258
- actions.className = 'wnFoaW_rowActions'
3259
- header.appendChild(actions)
3260
-
3261
- section.appendChild(header)
3262
- mountRow(harness, SESSION_A, section)
3263
- harness.document.body.appendChild(section)
3264
-
3265
- await enterMulti(harness)
3266
- observerPass(harness)
3267
- await flush()
3268
-
3269
- // Order has to be: label, box, spacer, actions. With the spacer growing, the
3270
- // name keeps its natural width and the cluster stays at the row's end; without
3271
- // it, every flex child simply packs left and the count/menu/new buttons slid
3272
- // over with the box.
3273
- const kids = header.children
3274
- const box = header.querySelector('.dsdel-select-all')
3275
- const spacer = header.querySelector('.dsdel-flex-spacer')
3276
- assert.ok(box, 'the box exists')
3277
- assert.ok(spacer, 'the spacer exists')
3278
-
3279
- assert.equal(kids.indexOf(box) < kids.indexOf(spacer), true, 'box before spacer')
3280
- assert.equal(kids.indexOf(spacer) < kids.indexOf(actions), true, 'spacer before the cluster')
3281
- assert.equal(kids.indexOf(label) < kids.indexOf(box), true, 'label first')
3282
- })
3283
-
3284
- test('the spacer is removed with the mode', async () => {
3285
- const harness = await loadPlugin()
3286
- const section = harness.document.createElement('div')
3287
- section.setAttribute('role', 'group')
3288
- const header = harness.document.createElement('div')
3289
- header.setAttribute('role', 'treeitem')
3290
- header.setAttribute('data-row-key', 'workspace:ws-a')
3291
- const label = harness.document.createElement('span')
3292
- label.className = 'wnFoaW_projectText'
3293
- header.appendChild(label)
3294
- const actions = harness.document.createElement('span')
3295
- actions.className = 'wnFoaW_rowActions'
3296
- header.appendChild(actions)
3297
- section.appendChild(header)
3298
- mountRow(harness, SESSION_A, section)
3299
- harness.document.body.appendChild(section)
3300
-
3301
- await enterMulti(harness)
3302
- observerPass(harness)
3303
- await flush()
3304
- assert.ok(header.querySelector('.dsdel-flex-spacer'), 'spacer present during the mode')
3305
-
3306
- // The bar's Cancel is the mode's own exit route. Escape would also reach
3307
- // handlers left behind by earlier tests: the stub never unregisters one.
3308
- clickBar(barCancel(harness))
3309
- observerPass(harness)
3310
- await flush()
3311
- assert.equal(header.querySelector('.dsdel-flex-spacer'), null, 'gone with the mode')
3312
- assert.equal(header.querySelector('.dsdel-select-all'), null, 'and so is the box')
3313
- })
3314
-
3315
- test('PROBE exit removes spacer', async () => {
3316
- const harness = await loadPlugin()
3317
- const section = harness.document.createElement('div')
3318
- section.setAttribute('role', 'group')
3319
- const header = harness.document.createElement('div')
3320
- header.setAttribute('role', 'treeitem')
3321
- header.setAttribute('data-row-key', 'workspace:ws-a')
3322
- const actions = harness.document.createElement('span')
3323
- actions.className = 'wnFoaW_rowActions'
3324
- header.appendChild(actions)
3325
- section.appendChild(header)
3326
- mountRow(harness, SESSION_A, section)
3327
- harness.document.body.appendChild(section)
3328
-
3329
- await enterMulti(harness)
3330
- observerPass(harness)
3331
- await flush()
3332
-
3333
- const before = harness.document.querySelectorAll('.dsdel-flex-spacer').length
3334
- console.log('PROBE 装饰后 spacer 数:', before)
3335
- for (const el of harness.document.querySelectorAll('.dsdel-flex-spacer')) {
3336
- console.log('PROBE spacer parent:', el.parentElement && el.parentElement.getAttribute('data-row-key'), 'idx:', el.parentElement ? el.parentElement.children.indexOf(el) : -1)
3337
- }
3338
- const cancel = barCancel(harness)
3339
- console.log('PROBE cancel 节点:', cancel && cancel.props && cancel.props.className)
3340
- clickBar(cancel)
3341
- await flush()
3342
- console.log('PROBE 退出后 spacer 数:', harness.document.querySelectorAll('.dsdel-flex-spacer').length)
3343
- assert.ok(true)
3344
- })
3345
-
3346
- test('the spacer is the growing child, so the cluster keeps its seat', async () => {
3347
- const harness = await loadPlugin()
3348
- const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3349
-
3350
- // Without a growing child the flex row simply packs left, which drags the count
3351
- // and the action buttons along with the box. The spacer is what holds them at
3352
- // the row's end while the box sits beside the name.
3353
- assert.match(css, /\.dsdel-flex-spacer\{[^}]*flex:1/, 'the spacer grows')
3354
- assert.match(css, /\.dsdel-flex-spacer\{[^}]*min-width:0/, 'and can collapse when space is tight')
3355
- assert.match(css, /\.dsdel-select-all[^}]*flex:0 0 auto/, 'the box itself does not grow')
3356
- })
3357
-
3358
- test('a document click on a plugin-drawn element leaves the session alone', async () => {
3359
- const harness = await loadPlugin()
3360
- const row = mountRow(harness, SESSION_A)
3361
- await enterMulti(harness)
3362
- observerPass(harness)
3363
- await flush()
3364
- assert.equal(harness.document.body.className.includes('dsdel-selecting'), true)
3365
-
3366
- // The document capture listener runs before any element handler. It must ignore
3367
- // elements this plugin drew — a box inside a workspace row is the everyday case,
3368
- // and inside a session row it would otherwise toggle that session.
3369
- const box = harness.document.createElement('button')
3370
- box.className = 'dsdel-select-all'
3371
- box.setAttribute('data-dsh-delete-session', 'select-all')
3372
- row.appendChild(box)
3373
-
3374
- clickRowIn(harness, box)
3375
- observerPass(harness)
3376
- await flush()
3377
-
3378
- const check = row.querySelector('.dsdel-check')
3379
- assert.equal(check.classList.contains('dsdel-check-on'), false, 'no session was toggled')
3380
- })
3381
-
3382
- test('the row handler still works for a real session row', async () => {
3383
- const harness = await loadPlugin()
3384
- const row = mountRow(harness, SESSION_A)
3385
- await enterMulti(harness)
3386
- observerPass(harness)
3387
- await flush()
3388
-
3389
- clickRowIn(harness, row)
3390
- await flush()
3391
-
3392
- const check = row.querySelector('.dsdel-check')
3393
- assert.equal(check.classList.contains('dsdel-check-on'), true, 'a plain row still toggles')
3394
- })
3395
-
3396
- test('a decorate pass with nothing to move keeps the box where it is', async () => {
3397
- const harness = await loadPlugin()
3398
- const section = harness.document.createElement('div')
3399
- section.setAttribute('role', 'group')
3400
- const header = harness.document.createElement('div')
3401
- header.setAttribute('role', 'treeitem')
3402
- header.setAttribute('data-row-key', 'workspace:ws-a')
3403
- const label = harness.document.createElement('span')
3404
- label.className = 'wnFoaW_projectText'
3405
- header.appendChild(label)
3406
- const actions = harness.document.createElement('span')
3407
- actions.className = 'wnFoaW_rowActions'
3408
- header.appendChild(actions)
3409
- section.appendChild(header)
3410
- mountRow(harness, SESSION_A, section)
3411
- harness.document.body.appendChild(section)
3412
-
3413
- await enterMulti(harness)
3414
- observerPass(harness)
3415
- await flush()
3416
-
3417
- // Every insertBefore is a mutation, and the list observer counted it as a
3418
- // reason to scan again: each pass scheduled the next one, forever, and the box
3419
- // was detached and re-attached under the pointer. Nothing may move here — the
3420
- // box and its spacer are already in the right place.
3421
- const box = header.querySelector('.dsdel-select-all')
3422
- const spacer = header.querySelector('.dsdel-flex-spacer')
3423
- const index = header.children.indexOf(box)
3424
-
3425
- // Re-inserting a node where it already sits leaves its index unchanged, so the
3426
- // index alone cannot prove the pass was quiet. Count the calls instead: a real
3427
- // insertBefore produces a MutationRecord, and the observer used to feed on them.
3428
- const realInsert = header.insertBefore.bind(header)
3429
- let inserts = 0
3430
- header.insertBefore = (child, ref) => { inserts += 1; return realInsert(child, ref) }
3431
-
3432
- observerPass(harness)
3433
- observerPass(harness)
3434
- await flush()
3435
-
3436
- assert.equal(inserts, 0, 'a settled row is left untouched')
3437
-
3438
- assert.equal(header.children.indexOf(box), index, 'the box did not move')
3439
- assert.equal(header.children.indexOf(spacer), index + 1, 'nor did the spacer')
3440
- assert.equal(header.children.filter((el) => el === box).length, 1, 'and there is only one')
3441
- })
3442
-
3443
- test('a mutation naming only our own nodes schedules no pass', async () => {
3444
- const harness = await loadPlugin()
3445
-
3446
- // Drive the frame queue by hand: a timer-based flush made this test flaky,
3447
- // because a pass can queue another callback while it runs.
3448
- //
3449
- // Note the drain: emptying the queue without running its callbacks leaves the
3450
- // plugin's `decorateRaf` handle truthy, and every later `scheduleDecorate`
3451
- // silently returns. That is a harness trap, not a product bug.
3452
- const queued = []
3453
- const realRaf = globalThis.requestAnimationFrame
3454
- const realCancel = globalThis.cancelAnimationFrame
3455
- globalThis.requestAnimationFrame = (fn) => { queued.push(fn); return queued.length }
3456
- globalThis.cancelAnimationFrame = () => {}
3457
- const drain = () => { let guard = 0; while (queued.length > 0 && guard < 50) { guard += 1; queued.shift()() } }
3458
-
3459
- try {
3460
- await enterMulti(harness)
3461
- drain()
3462
-
3463
- // A row that arrives after the last pass carries no checkbox, so whether a
3464
- // pass runs is readable straight off the DOM.
3465
- const section = harness.document.createElement('div')
3466
- section.setAttribute('role', 'group')
3467
- const hostRow = harness.document.createElement('div')
3468
- hostRow.setAttribute('role', 'treeitem')
3469
- hostRow.setAttribute('data-row-key', 'session:session-cccc1111-2222-4333-8444-555555555555')
3470
- section.appendChild(hostRow)
3471
- harness.document.body.appendChild(section)
3472
- assert.equal(hostRow.querySelector('.dsdel-check'), null, 'the row is undecorated')
3473
-
3474
- // Decorate inserts checkboxes, and the list observer reports them right back.
3475
- // Every such record used to schedule another pass, so the loop never settled:
3476
- // the box was re-inserted under the pointer and a click often missed.
3477
- const own = harness.document.createElement('span')
3478
- own.setAttribute('data-dsh-delete-session', 'check')
3479
- harness.observers[0].callback([{ addedNodes: [own], removedNodes: [] }])
3480
- assert.equal(queued.length, 0, 'our own node schedules nothing')
3481
-
3482
- // A host change must still get through.
3483
- harness.observers[0].callback([{ addedNodes: [hostRow], removedNodes: [] }])
3484
- assert.equal(queued.length, 1, 'a real host row schedules one pass')
3485
- drain()
3486
- assert.ok(hostRow.querySelector('.dsdel-check'), 'and that pass decorates it')
3487
- } finally {
3488
- globalThis.requestAnimationFrame = realRaf
3489
- globalThis.cancelAnimationFrame = realCancel
3490
- }
3491
- })
3492
-
3493
- test('the plugin never calls array methods on a live child list', async () => {
3494
- const source = await readFile(new URL('../src/client.js', import.meta.url), 'utf8')
3495
-
3496
- // In a browser `element.children` is an HTMLCollection: it has `length` and
3497
- // indexing, and none of the Array methods. The test stub uses a plain array, so
3498
- // `children.indexOf(...)` passed here and threw a TypeError in the real host —
3499
- // the decorate pass died before inserting anything, and the select-all box never
3500
- // appeared. Index it by hand (`childIndex`) or spread it first.
3501
- const offenders = []
3502
- for (const match of source.matchAll(/\.children\.([A-Za-z]+)\s*\(/g)) {
3503
- offenders.push(match[0])
3504
- }
3505
- assert.deepEqual(offenders, [], 'no Array methods on `children`')
3506
- })
3507
-
3508
- test('the workspace box reaches past a wrapping element', async () => {
3509
- const harness = await loadPlugin()
3510
- const section = harness.document.createElement('div')
3511
- section.setAttribute('role', 'group')
3512
-
3513
- // The real host wraps the workspace row in HoverCard's <span>, so the row's
3514
- // parentElement is that span, not the section. A subtree query from the span
3515
- // returns only the workspace row itself and the box ends up with no ids —
3516
- // `toggleGroup` then returns without doing anything, which is exactly the
3517
- // "single-workspace select-all does nothing" report.
3518
- const wrapper = harness.document.createElement('span')
3519
- wrapper.className = 'HoverCard_root'
3520
- const header = harness.document.createElement('div')
3521
- header.setAttribute('role', 'treeitem')
3522
- header.setAttribute('data-row-key', 'workspace:ws-a')
3523
- const label = harness.document.createElement('span')
3524
- label.className = 'wnFoaW_projectText'
3525
- header.appendChild(label)
3526
- const actions = harness.document.createElement('span')
3527
- actions.className = 'wnFoaW_rowActions'
3528
- header.appendChild(actions)
3529
- wrapper.appendChild(header)
3530
- section.appendChild(wrapper)
3531
-
3532
- mountRow(harness, SESSION_A, section)
3533
- mountRow(harness, SESSION_B, section)
3534
- harness.document.body.appendChild(section)
3535
-
3536
- await enterMulti(harness)
3537
- observerPass(harness)
3538
- await flush()
3539
-
3540
- const box = header.querySelector('.dsdel-select-all')
3541
- assert.ok(box, 'the box exists')
3542
- assert.deepEqual(box.__dsdelIds, [SESSION_A.id, SESSION_B.id], 'both sessions were found')
3543
-
3544
- box.fire('click')
3545
- await flush()
3546
- assert.equal(box.getAttribute('aria-checked'), 'true', 'and pressing it selects them')
3547
- })
3548
-
3549
- test('a workspace box never reaches into a nested workspace', async () => {
3550
- const harness = await loadPlugin()
3551
- const section = harness.document.createElement('div')
3552
- section.setAttribute('role', 'group')
3553
-
3554
- const header = harness.document.createElement('div')
3555
- header.setAttribute('role', 'treeitem')
3556
- header.setAttribute('data-row-key', 'workspace:outer')
3557
- const actions = harness.document.createElement('span')
3558
- actions.className = 'wnFoaW_rowActions'
3559
- header.appendChild(actions)
3560
- section.appendChild(header)
3561
- mountRow(harness, SESSION_A, section)
3562
-
3563
- // A nested workspace is a `div[role="group"]` holding its own rows.
3564
- const nested = harness.document.createElement('div')
3565
- nested.setAttribute('role', 'group')
3566
- const nestedHeader = harness.document.createElement('div')
3567
- nestedHeader.setAttribute('role', 'treeitem')
3568
- nestedHeader.setAttribute('data-row-key', 'workspace:inner')
3569
- nested.appendChild(nestedHeader)
3570
- mountRow(harness, SESSION_B, nested)
3571
- section.appendChild(nested)
3572
-
3573
- harness.document.body.appendChild(section)
3574
-
3575
- await enterMulti(harness)
3576
- observerPass(harness)
3577
- await flush()
3578
-
3579
- const box = header.querySelector('.dsdel-select-all')
3580
- assert.deepEqual(box.__dsdelIds, [SESSION_A.id], 'only the outer group\'s own session')
3581
- })
2972
+ })
2973
+
2974
+ test('the drop label names the conversation instead of printing the placeholder', async () => {
2975
+ const harness = await loadPlugin()
2976
+ const row = mountRow(harness, SESSION_A)
2977
+
2978
+ startRowDrag(harness, row)
2979
+ await flush()
2980
+ bar(harness).props.onDragOver(dropEvent())
2981
+ await flush()
2982
+
2983
+ const node = bar(harness)
2984
+ const text = JSON.stringify(node.props.children)
2985
+
2986
+ // The dictionary entry is `松手删除「{name}」`, but the interpolation map carries
2987
+ // `n`/`done`/`total`/`ok`/`fail`/`path` — not `name`. Passing the title as a bare
2988
+ // string therefore left the braces in the label.
2989
+ assert.doesNotMatch(text, /\{name\}/, 'no unsubstituted placeholder in the label')
2990
+ assert.match(text, /松手删除/, 'the sentence is still there')
2991
+ })
2992
+
2993
+ test('the drop label carries the dragged conversation title', async () => {
2994
+ const harness = await loadPlugin()
2995
+ const row = mountRow(harness, SESSION_A)
2996
+ row.textContent = 'BiliLearn-AI 仓库'
2997
+
2998
+ startRowDrag(harness, row)
2999
+ await flush()
3000
+ bar(harness).props.onDragOver(dropEvent())
3001
+ await flush()
3002
+
3003
+ const text = JSON.stringify(bar(harness).props.children)
3004
+ assert.match(text, /BiliLearn-AI 仓库/, 'the title reaches the sentence')
3005
+ })
3006
+ test('a workspace header offers a select-all box', async () => {
3007
+ const harness = await loadPlugin()
3008
+ const section = harness.document.createElement('div')
3009
+ section.setAttribute('role', 'group')
3010
+
3011
+ const header = harness.document.createElement('div')
3012
+ header.setAttribute('role', 'treeitem')
3013
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3014
+ section.appendChild(header)
3015
+
3016
+ mountRow(harness, SESSION_A, section)
3017
+ mountRow(harness, SESSION_B, section)
3018
+ harness.document.body.appendChild(section)
3019
+
3020
+ await enterMulti(harness)
3021
+ observerPass(harness)
3022
+ await flush()
3023
+
3024
+ const box = header.querySelector('.dsdel-select-all')
3025
+ assert.ok(box, 'the header carries one')
3026
+ assert.equal(box.getAttribute('role'), 'checkbox')
3027
+ assert.equal(box.getAttribute('aria-checked'), 'false', 'nothing picked yet')
3028
+ })
3029
+
3030
+ test('the workspace box selects only its own sessions', async () => {
3031
+ const harness = await loadPlugin()
3032
+ const sectionA = harness.document.createElement('div')
3033
+ sectionA.setAttribute('role', 'group')
3034
+ const headA = harness.document.createElement('div')
3035
+ headA.setAttribute('role', 'treeitem')
3036
+ headA.setAttribute('data-row-key', 'workspace:ws-a')
3037
+ sectionA.appendChild(headA)
3038
+ mountRow(harness, SESSION_A, sectionA)
3039
+ harness.document.body.appendChild(sectionA)
3040
+
3041
+ const sectionB = harness.document.createElement('div')
3042
+ sectionB.setAttribute('role', 'group')
3043
+ const headB = harness.document.createElement('div')
3044
+ headB.setAttribute('role', 'treeitem')
3045
+ headB.setAttribute('data-row-key', 'workspace:ws-b')
3046
+ sectionB.appendChild(headB)
3047
+ mountRow(harness, SESSION_B, sectionB)
3048
+ harness.document.body.appendChild(sectionB)
3049
+
3050
+ await enterMulti(harness)
3051
+ observerPass(harness)
3052
+ await flush()
3053
+
3054
+ headA.querySelector('.dsdel-select-all').fire('click')
3055
+ await flush()
3056
+
3057
+ assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true', 'A turned on')
3058
+ const boxB = headB.querySelector('.dsdel-select-all')
3059
+ assert.equal(boxB.getAttribute('aria-checked'), 'false', 'B untouched')
3060
+ })
3061
+
3062
+ test('a second press clears the workspace again', async () => {
3063
+ const harness = await loadPlugin()
3064
+ const section = harness.document.createElement('div')
3065
+ section.setAttribute('role', 'group')
3066
+ const header = harness.document.createElement('div')
3067
+ header.setAttribute('role', 'treeitem')
3068
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3069
+ section.appendChild(header)
3070
+ mountRow(harness, SESSION_A, section)
3071
+ harness.document.body.appendChild(section)
3072
+
3073
+ await enterMulti(harness)
3074
+ observerPass(harness)
3075
+ await flush()
3076
+
3077
+ const box = header.querySelector('.dsdel-select-all')
3078
+ box.fire('click')
3079
+ await flush()
3080
+ assert.equal(box.getAttribute('aria-checked'), 'true')
3081
+
3082
+ box.fire('click')
3083
+ await flush()
3084
+ assert.equal(box.getAttribute('aria-checked'), 'false')
3085
+ })
3086
+
3087
+ test('the box reports a partly picked workspace as mixed', async () => {
3088
+ const harness = await loadPlugin()
3089
+ const section = harness.document.createElement('div')
3090
+ section.setAttribute('role', 'group')
3091
+ const header = harness.document.createElement('div')
3092
+ header.setAttribute('role', 'treeitem')
3093
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3094
+ section.appendChild(header)
3095
+ const rowA = mountRow(harness, SESSION_A, section)
3096
+ mountRow(harness, SESSION_B, section)
3097
+ harness.document.body.appendChild(section)
3098
+
3099
+ await enterMulti(harness)
3100
+ observerPass(harness)
3101
+ await flush()
3102
+
3103
+ clickRowIn(harness, rowA)
3104
+ observerPass(harness)
3105
+ await flush()
3106
+
3107
+ assert.equal(header.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'mixed')
3108
+ })
3109
+
3110
+ test('the heading row selects every workspace at once', async () => {
3111
+ const harness = await loadPlugin()
3112
+ const heading = harness.document.createElement('div')
3113
+ heading.setAttribute('data-sidebar-workspace-header', '')
3114
+ harness.document.body.appendChild(heading)
3115
+
3116
+ const sectionA = harness.document.createElement('div')
3117
+ sectionA.setAttribute('role', 'group')
3118
+ const headA = harness.document.createElement('div')
3119
+ headA.setAttribute('role', 'treeitem')
3120
+ headA.setAttribute('data-row-key', 'workspace:ws-a')
3121
+ sectionA.appendChild(headA)
3122
+ mountRow(harness, SESSION_A, sectionA)
3123
+ harness.document.body.appendChild(sectionA)
3124
+
3125
+ const sectionB = harness.document.createElement('div')
3126
+ sectionB.setAttribute('role', 'group')
3127
+ const headB = harness.document.createElement('div')
3128
+ headB.setAttribute('role', 'treeitem')
3129
+ headB.setAttribute('data-row-key', 'workspace:ws-b')
3130
+ sectionB.appendChild(headB)
3131
+ mountRow(harness, SESSION_B, sectionB)
3132
+ harness.document.body.appendChild(sectionB)
3133
+
3134
+ await enterMulti(harness)
3135
+ observerPass(harness)
3136
+ await flush()
3137
+
3138
+ const all = heading.querySelector('.dsdel-select-all-workspaces')
3139
+ assert.ok(all, 'the heading carries the global box')
3140
+ all.fire('click')
3141
+ await flush()
3142
+
3143
+ assert.equal(all.getAttribute('aria-checked'), 'true', 'everything picked')
3144
+ assert.equal(headA.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
3145
+ assert.equal(headB.querySelector('.dsdel-select-all').getAttribute('aria-checked'), 'true')
3146
+ })
3147
+
3148
+ test('both boxes go away when the mode ends', async () => {
3149
+ const harness = await loadPlugin()
3150
+ const heading = harness.document.createElement('div')
3151
+ heading.setAttribute('data-sidebar-workspace-header', '')
3152
+ harness.document.body.appendChild(heading)
3153
+
3154
+ const section = harness.document.createElement('div')
3155
+ section.setAttribute('role', 'group')
3156
+ const header = harness.document.createElement('div')
3157
+ header.setAttribute('role', 'treeitem')
3158
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3159
+ section.appendChild(header)
3160
+ mountRow(harness, SESSION_A, section)
3161
+ harness.document.body.appendChild(section)
3162
+
3163
+ await enterMulti(harness)
3164
+ observerPass(harness)
3165
+ await flush()
3166
+ assert.ok(header.querySelector('.dsdel-select-all'), 'present during the mode')
3167
+ assert.ok(heading.querySelector('.dsdel-select-all-workspaces'))
3168
+
3169
+ harness.document.dispatchToDocument('keydown', { key: 'Escape', stopPropagation() {} })
3170
+ observerPass(harness)
3171
+ await flush()
3172
+
3173
+ assert.equal(header.querySelector('.dsdel-select-all'), null, 'removed with the mode')
3174
+ assert.equal(heading.querySelector('.dsdel-select-all-workspaces'), null)
3175
+ })
3176
+
3177
+ test('the select-all boxes do not lean on the page token scope', async () => {
3178
+ const harness = await loadPlugin()
3179
+ const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3180
+
3181
+ // The boxes render inside the SIDEBAR. The `--dsdel-*` tokens are declared on
3182
+ // `.dsdel-page`, `.dsdel-modal` and `.dsdel-bar` only, so any rule outside those
3183
+ // scopes that reads them gets an invalid value and loses the whole declaration.
3184
+ // That is how the first version shipped an invisible button: `border` was
3185
+ // dropped, leaving no box and nothing to click.
3186
+ const rules = [...css.matchAll(/(?:^|\})\s*\.dsdel-select-all[^{]*\{([^}]*)\}/g)]
3187
+ assert.ok(rules.length > 0, 'the rules are in the stylesheet')
3188
+ for (const match of rules) {
3189
+ assert.equal(match[1].includes('--dsdel-'), false,
3190
+ 'a sidebar rule must not read the page tokens: ' + match[0].slice(0, 60))
3191
+ }
3192
+
3193
+ // Every host alias carries a literal fallback, so the box still draws when the
3194
+ // host renames its palette.
3195
+ assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-border-l2,[^)]*\)/, 'border has a fallback')
3196
+ assert.match(css, /\.dsdel-select-all[^}]*var\(--dsw-alias-brand-primary,[^)]*\)/, 'brand has a fallback')
3197
+ })
3198
+
3199
+ test('a box always keeps a visible 15px square', async () => {
3200
+ const harness = await loadPlugin()
3201
+ const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3202
+
3203
+ // A flex child with no width collapses to its content, and the empty state has
3204
+ // no content: `width` plus `min-width` plus content-box sizing is what makes the
3205
+ // square exist before anything is ticked.
3206
+ assert.match(css, /\.dsdel-select-all[^}]*width:15px/, 'a fixed width')
3207
+ assert.match(css, /\.dsdel-select-all[^}]*height:15px/, 'and a fixed height')
3208
+ assert.match(css, /\.dsdel-select-all[^}]*min-width:15px/, 'that flex cannot shrink away')
3209
+ assert.match(css, /\.dsdel-select-all[^}]*box-sizing:border-box/, 'with the border inside it')
3210
+ })
3211
+
3212
+ test('the workspace box sits beside the name, not at the row edge', async () => {
3213
+ const harness = await loadPlugin()
3214
+ const section = harness.document.createElement('div')
3215
+ section.setAttribute('role', 'group')
3216
+
3217
+ const header = harness.document.createElement('div')
3218
+ header.setAttribute('role', 'treeitem')
3219
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3220
+
3221
+ // The host row: label block, then the action cluster (which carries margin-left:auto).
3222
+ const label = harness.document.createElement('span')
3223
+ label.className = 'YDXeBa_projectText'
3224
+ header.appendChild(label)
3225
+ const actions = harness.document.createElement('span')
3226
+ actions.className = 'YDXeBa_rowActions'
3227
+ header.appendChild(actions)
3228
+
3229
+ section.appendChild(header)
3230
+ mountRow(harness, SESSION_A, section)
3231
+ harness.document.body.appendChild(section)
3232
+
3233
+ await enterMulti(harness)
3234
+ observerPass(harness)
3235
+ await flush()
3236
+
3237
+ const box = header.querySelector('.dsdel-select-all')
3238
+ assert.ok(box, 'the box exists')
3239
+
3240
+ // Appending put it after the action cluster, whose auto margin pushes it into the
3241
+ // far right of the row — that is the "靠右" the screenshot showed. It has to be
3242
+ // inserted before the actions instead.
3243
+ const index = header.children.indexOf(box)
3244
+ const actionsIndex = header.children.indexOf(actions)
3245
+ assert.equal(index < actionsIndex, true, 'the box comes before the action cluster')
3246
+ assert.equal(header.children[index - 1].className, 'YDXeBa_projectText', 'and right after the label')
3247
+ })
3248
+
3249
+ test('the global box sits after the heading label, before the search slot', async () => {
3250
+ const harness = await loadPlugin()
3251
+
3252
+ const heading = harness.document.createElement('div')
3253
+ heading.setAttribute('data-sidebar-workspace-header', '')
3254
+
3255
+ const label = harness.document.createElement('span')
3256
+ label.className = 'bhn1Oq_sectionLabel'
3257
+ heading.appendChild(label)
3258
+ const search = harness.document.createElement('div')
3259
+ search.className = 'bhn1Oq_searchSlot'
3260
+ heading.appendChild(search)
3261
+
3262
+ harness.document.body.appendChild(heading)
3263
+
3264
+ const section = harness.document.createElement('div')
3265
+ section.setAttribute('role', 'group')
3266
+ const header = harness.document.createElement('div')
3267
+ header.setAttribute('role', 'treeitem')
3268
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3269
+ section.appendChild(header)
3270
+ mountRow(harness, SESSION_A, section)
3271
+ harness.document.body.appendChild(section)
3272
+
3273
+ await enterMulti(harness)
3274
+ observerPass(harness)
3275
+ await flush()
3276
+
3277
+ const box = heading.querySelector('.dsdel-select-all-workspaces')
3278
+ assert.ok(box, 'the global box exists')
3279
+ const index = heading.children.indexOf(box)
3280
+ assert.equal(index < heading.children.indexOf(search), true, 'before the search slot')
3281
+ assert.equal(heading.children[index - 1].className, 'bhn1Oq_sectionLabel', 'and after the label')
3282
+ })
3283
+
3284
+ test('a box left at the wrong edge is moved on the next pass', async () => {
3285
+ const harness = await loadPlugin()
3286
+ const section = harness.document.createElement('div')
3287
+ section.setAttribute('role', 'group')
3288
+
3289
+ const header = harness.document.createElement('div')
3290
+ header.setAttribute('role', 'treeitem')
3291
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3292
+
3293
+ const label = harness.document.createElement('span')
3294
+ label.className = 'wnFoaW_projectText'
3295
+ header.appendChild(label)
3296
+ const actions = harness.document.createElement('span')
3297
+ actions.className = 'wnFoaW_rowActions'
3298
+ header.appendChild(actions)
3299
+
3300
+ // An earlier build left its box AFTER the actions: the far edge.
3301
+ const stale = harness.document.createElement('button')
3302
+ stale.className = 'dsdel-select-all'
3303
+ header.appendChild(stale)
3304
+
3305
+ section.appendChild(header)
3306
+ mountRow(harness, SESSION_A, section)
3307
+ harness.document.body.appendChild(section)
3308
+
3309
+ await enterMulti(harness)
3310
+ observerPass(harness)
3311
+ await flush()
3312
+
3313
+ // The insert used to live inside the "created" branch, so an existing box was
3314
+ // never repositioned: the heading box moved and the workspace box stayed put.
3315
+ const index = header.children.indexOf(stale)
3316
+ assert.equal(index < header.children.indexOf(actions), true, 'moved before the actions')
3317
+ assert.equal(header.children[index - 1].className, 'wnFoaW_projectText', 'and beside the label')
3318
+ })
3319
+
3320
+ test('the workspace name stops absorbing the row while the mode runs', async () => {
3321
+ const harness = await loadPlugin()
3322
+ const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3323
+
3324
+ // `.projectText` carries `flex:1`, so it fills whatever the actions do not take.
3325
+ // A box inserted after it therefore lands at the row's far edge even though it
3326
+ // is early in the child list — that is why the workspace box stayed right while
3327
+ // the header box (whose label is not flexed) moved. The rule only applies while
3328
+ // the mode runs, so the host keeps its normal layout otherwise.
3329
+ assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*flex:0 1 auto/,
3330
+ 'the name sizes to its text during the mode')
3331
+ assert.match(css, /body\.dsdel-selecting \[class\*="_projectText"\]\{[^}]*min-width:0/,
3332
+ 'and can still truncate a long name')
3333
+ })
3334
+
3335
+ test('a spacer keeps the right-hand cluster in place', async () => {
3336
+ const harness = await loadPlugin()
3337
+ const section = harness.document.createElement('div')
3338
+ section.setAttribute('role', 'group')
3339
+
3340
+ const header = harness.document.createElement('div')
3341
+ header.setAttribute('role', 'treeitem')
3342
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3343
+
3344
+ const label = harness.document.createElement('span')
3345
+ label.className = 'wnFoaW_projectText'
3346
+ header.appendChild(label)
3347
+ // The cluster that must NOT move: count, menu, new-session.
3348
+ const actions = harness.document.createElement('span')
3349
+ actions.className = 'wnFoaW_rowActions'
3350
+ header.appendChild(actions)
3351
+
3352
+ section.appendChild(header)
3353
+ mountRow(harness, SESSION_A, section)
3354
+ harness.document.body.appendChild(section)
3355
+
3356
+ await enterMulti(harness)
3357
+ observerPass(harness)
3358
+ await flush()
3359
+
3360
+ // Order has to be: label, box, spacer, actions. With the spacer growing, the
3361
+ // name keeps its natural width and the cluster stays at the row's end; without
3362
+ // it, every flex child simply packs left and the count/menu/new buttons slid
3363
+ // over with the box.
3364
+ const kids = header.children
3365
+ const box = header.querySelector('.dsdel-select-all')
3366
+ const spacer = header.querySelector('.dsdel-flex-spacer')
3367
+ assert.ok(box, 'the box exists')
3368
+ assert.ok(spacer, 'the spacer exists')
3369
+
3370
+ assert.equal(kids.indexOf(box) < kids.indexOf(spacer), true, 'box before spacer')
3371
+ assert.equal(kids.indexOf(spacer) < kids.indexOf(actions), true, 'spacer before the cluster')
3372
+ assert.equal(kids.indexOf(label) < kids.indexOf(box), true, 'label first')
3373
+ })
3374
+
3375
+ test('the spacer is removed with the mode', async () => {
3376
+ const harness = await loadPlugin()
3377
+ const section = harness.document.createElement('div')
3378
+ section.setAttribute('role', 'group')
3379
+ const header = harness.document.createElement('div')
3380
+ header.setAttribute('role', 'treeitem')
3381
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3382
+ const label = harness.document.createElement('span')
3383
+ label.className = 'wnFoaW_projectText'
3384
+ header.appendChild(label)
3385
+ const actions = harness.document.createElement('span')
3386
+ actions.className = 'wnFoaW_rowActions'
3387
+ header.appendChild(actions)
3388
+ section.appendChild(header)
3389
+ mountRow(harness, SESSION_A, section)
3390
+ harness.document.body.appendChild(section)
3391
+
3392
+ await enterMulti(harness)
3393
+ observerPass(harness)
3394
+ await flush()
3395
+ assert.ok(header.querySelector('.dsdel-flex-spacer'), 'spacer present during the mode')
3396
+
3397
+ // The bar's Cancel is the mode's own exit route. Escape would also reach
3398
+ // handlers left behind by earlier tests: the stub never unregisters one.
3399
+ clickBar(barCancel(harness))
3400
+ observerPass(harness)
3401
+ await flush()
3402
+ assert.equal(header.querySelector('.dsdel-flex-spacer'), null, 'gone with the mode')
3403
+ assert.equal(header.querySelector('.dsdel-select-all'), null, 'and so is the box')
3404
+ })
3405
+
3406
+ test('PROBE exit removes spacer', async () => {
3407
+ const harness = await loadPlugin()
3408
+ const section = harness.document.createElement('div')
3409
+ section.setAttribute('role', 'group')
3410
+ const header = harness.document.createElement('div')
3411
+ header.setAttribute('role', 'treeitem')
3412
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3413
+ const actions = harness.document.createElement('span')
3414
+ actions.className = 'wnFoaW_rowActions'
3415
+ header.appendChild(actions)
3416
+ section.appendChild(header)
3417
+ mountRow(harness, SESSION_A, section)
3418
+ harness.document.body.appendChild(section)
3419
+
3420
+ await enterMulti(harness)
3421
+ observerPass(harness)
3422
+ await flush()
3423
+
3424
+ const before = harness.document.querySelectorAll('.dsdel-flex-spacer').length
3425
+ console.log('PROBE 装饰后 spacer 数:', before)
3426
+ for (const el of harness.document.querySelectorAll('.dsdel-flex-spacer')) {
3427
+ console.log('PROBE spacer parent:', el.parentElement && el.parentElement.getAttribute('data-row-key'), 'idx:', el.parentElement ? el.parentElement.children.indexOf(el) : -1)
3428
+ }
3429
+ const cancel = barCancel(harness)
3430
+ console.log('PROBE cancel 节点:', cancel && cancel.props && cancel.props.className)
3431
+ clickBar(cancel)
3432
+ await flush()
3433
+ console.log('PROBE 退出后 spacer 数:', harness.document.querySelectorAll('.dsdel-flex-spacer').length)
3434
+ assert.ok(true)
3435
+ })
3436
+
3437
+ test('the spacer is the growing child, so the cluster keeps its seat', async () => {
3438
+ const harness = await loadPlugin()
3439
+ const css = String(harness.document.head.querySelector('[data-dsh-delete-session="1"]')._text ?? '')
3440
+
3441
+ // Without a growing child the flex row simply packs left, which drags the count
3442
+ // and the action buttons along with the box. The spacer is what holds them at
3443
+ // the row's end while the box sits beside the name.
3444
+ assert.match(css, /\.dsdel-flex-spacer\{[^}]*flex:1/, 'the spacer grows')
3445
+ assert.match(css, /\.dsdel-flex-spacer\{[^}]*min-width:0/, 'and can collapse when space is tight')
3446
+ assert.match(css, /\.dsdel-select-all[^}]*flex:0 0 auto/, 'the box itself does not grow')
3447
+ })
3448
+
3449
+ test('a document click on a plugin-drawn element leaves the session alone', async () => {
3450
+ const harness = await loadPlugin()
3451
+ const row = mountRow(harness, SESSION_A)
3452
+ await enterMulti(harness)
3453
+ observerPass(harness)
3454
+ await flush()
3455
+ assert.equal(harness.document.body.className.includes('dsdel-selecting'), true)
3456
+
3457
+ // The document capture listener runs before any element handler. It must ignore
3458
+ // elements this plugin drew — a box inside a workspace row is the everyday case,
3459
+ // and inside a session row it would otherwise toggle that session.
3460
+ const box = harness.document.createElement('button')
3461
+ box.className = 'dsdel-select-all'
3462
+ box.setAttribute('data-dsh-delete-session', 'select-all')
3463
+ row.appendChild(box)
3464
+
3465
+ clickRowIn(harness, box)
3466
+ observerPass(harness)
3467
+ await flush()
3468
+
3469
+ const check = row.querySelector('.dsdel-check')
3470
+ assert.equal(check.classList.contains('dsdel-check-on'), false, 'no session was toggled')
3471
+ })
3472
+
3473
+ test('the row handler still works for a real session row', async () => {
3474
+ const harness = await loadPlugin()
3475
+ const row = mountRow(harness, SESSION_A)
3476
+ await enterMulti(harness)
3477
+ observerPass(harness)
3478
+ await flush()
3479
+
3480
+ clickRowIn(harness, row)
3481
+ await flush()
3482
+
3483
+ const check = row.querySelector('.dsdel-check')
3484
+ assert.equal(check.classList.contains('dsdel-check-on'), true, 'a plain row still toggles')
3485
+ })
3486
+
3487
+ test('a decorate pass with nothing to move keeps the box where it is', async () => {
3488
+ const harness = await loadPlugin()
3489
+ const section = harness.document.createElement('div')
3490
+ section.setAttribute('role', 'group')
3491
+ const header = harness.document.createElement('div')
3492
+ header.setAttribute('role', 'treeitem')
3493
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3494
+ const label = harness.document.createElement('span')
3495
+ label.className = 'wnFoaW_projectText'
3496
+ header.appendChild(label)
3497
+ const actions = harness.document.createElement('span')
3498
+ actions.className = 'wnFoaW_rowActions'
3499
+ header.appendChild(actions)
3500
+ section.appendChild(header)
3501
+ mountRow(harness, SESSION_A, section)
3502
+ harness.document.body.appendChild(section)
3503
+
3504
+ await enterMulti(harness)
3505
+ observerPass(harness)
3506
+ await flush()
3507
+
3508
+ // Every insertBefore is a mutation, and the list observer counted it as a
3509
+ // reason to scan again: each pass scheduled the next one, forever, and the box
3510
+ // was detached and re-attached under the pointer. Nothing may move here — the
3511
+ // box and its spacer are already in the right place.
3512
+ const box = header.querySelector('.dsdel-select-all')
3513
+ const spacer = header.querySelector('.dsdel-flex-spacer')
3514
+ const index = header.children.indexOf(box)
3515
+
3516
+ // Re-inserting a node where it already sits leaves its index unchanged, so the
3517
+ // index alone cannot prove the pass was quiet. Count the calls instead: a real
3518
+ // insertBefore produces a MutationRecord, and the observer used to feed on them.
3519
+ const realInsert = header.insertBefore.bind(header)
3520
+ let inserts = 0
3521
+ header.insertBefore = (child, ref) => { inserts += 1; return realInsert(child, ref) }
3522
+
3523
+ observerPass(harness)
3524
+ observerPass(harness)
3525
+ await flush()
3526
+
3527
+ assert.equal(inserts, 0, 'a settled row is left untouched')
3528
+
3529
+ assert.equal(header.children.indexOf(box), index, 'the box did not move')
3530
+ assert.equal(header.children.indexOf(spacer), index + 1, 'nor did the spacer')
3531
+ assert.equal(header.children.filter((el) => el === box).length, 1, 'and there is only one')
3532
+ })
3533
+
3534
+ test('a mutation naming only our own nodes schedules no pass', async () => {
3535
+ const harness = await loadPlugin()
3536
+
3537
+ // Drive the frame queue by hand: a timer-based flush made this test flaky,
3538
+ // because a pass can queue another callback while it runs.
3539
+ //
3540
+ // Note the drain: emptying the queue without running its callbacks leaves the
3541
+ // plugin's `decorateRaf` handle truthy, and every later `scheduleDecorate`
3542
+ // silently returns. That is a harness trap, not a product bug.
3543
+ const queued = []
3544
+ const realRaf = globalThis.requestAnimationFrame
3545
+ const realCancel = globalThis.cancelAnimationFrame
3546
+ globalThis.requestAnimationFrame = (fn) => { queued.push(fn); return queued.length }
3547
+ globalThis.cancelAnimationFrame = () => {}
3548
+ const drain = () => { let guard = 0; while (queued.length > 0 && guard < 50) { guard += 1; queued.shift()() } }
3549
+
3550
+ try {
3551
+ await enterMulti(harness)
3552
+ drain()
3553
+
3554
+ // A row that arrives after the last pass carries no checkbox, so whether a
3555
+ // pass runs is readable straight off the DOM.
3556
+ const section = harness.document.createElement('div')
3557
+ section.setAttribute('role', 'group')
3558
+ const hostRow = harness.document.createElement('div')
3559
+ hostRow.setAttribute('role', 'treeitem')
3560
+ hostRow.setAttribute('data-row-key', 'session:session-cccc1111-2222-4333-8444-555555555555')
3561
+ section.appendChild(hostRow)
3562
+ harness.document.body.appendChild(section)
3563
+ assert.equal(hostRow.querySelector('.dsdel-check'), null, 'the row is undecorated')
3564
+
3565
+ // Decorate inserts checkboxes, and the list observer reports them right back.
3566
+ // Every such record used to schedule another pass, so the loop never settled:
3567
+ // the box was re-inserted under the pointer and a click often missed.
3568
+ const own = harness.document.createElement('span')
3569
+ own.setAttribute('data-dsh-delete-session', 'check')
3570
+ harness.observers[0].callback([{ addedNodes: [own], removedNodes: [] }])
3571
+ assert.equal(queued.length, 0, 'our own node schedules nothing')
3572
+
3573
+ // A host change must still get through.
3574
+ harness.observers[0].callback([{ addedNodes: [hostRow], removedNodes: [] }])
3575
+ assert.equal(queued.length, 1, 'a real host row schedules one pass')
3576
+ drain()
3577
+ assert.ok(hostRow.querySelector('.dsdel-check'), 'and that pass decorates it')
3578
+ } finally {
3579
+ globalThis.requestAnimationFrame = realRaf
3580
+ globalThis.cancelAnimationFrame = realCancel
3581
+ }
3582
+ })
3583
+
3584
+ test('the plugin never calls array methods on a live child list', async () => {
3585
+ const source = await readFile(new URL('../src/client.js', import.meta.url), 'utf8')
3586
+
3587
+ // In a browser `element.children` is an HTMLCollection: it has `length` and
3588
+ // indexing, and none of the Array methods. The test stub uses a plain array, so
3589
+ // `children.indexOf(...)` passed here and threw a TypeError in the real host —
3590
+ // the decorate pass died before inserting anything, and the select-all box never
3591
+ // appeared. Index it by hand (`childIndex`) or spread it first.
3592
+ const offenders = []
3593
+ for (const match of source.matchAll(/\.children\.([A-Za-z]+)\s*\(/g)) {
3594
+ offenders.push(match[0])
3595
+ }
3596
+ assert.deepEqual(offenders, [], 'no Array methods on `children`')
3597
+ })
3598
+
3599
+ test('the workspace box reaches past a wrapping element', async () => {
3600
+ const harness = await loadPlugin()
3601
+ const section = harness.document.createElement('div')
3602
+ section.setAttribute('role', 'group')
3603
+
3604
+ // The real host wraps the workspace row in HoverCard's <span>, so the row's
3605
+ // parentElement is that span, not the section. A subtree query from the span
3606
+ // returns only the workspace row itself and the box ends up with no ids —
3607
+ // `toggleGroup` then returns without doing anything, which is exactly the
3608
+ // "single-workspace select-all does nothing" report.
3609
+ const wrapper = harness.document.createElement('span')
3610
+ wrapper.className = 'HoverCard_root'
3611
+ const header = harness.document.createElement('div')
3612
+ header.setAttribute('role', 'treeitem')
3613
+ header.setAttribute('data-row-key', 'workspace:ws-a')
3614
+ const label = harness.document.createElement('span')
3615
+ label.className = 'wnFoaW_projectText'
3616
+ header.appendChild(label)
3617
+ const actions = harness.document.createElement('span')
3618
+ actions.className = 'wnFoaW_rowActions'
3619
+ header.appendChild(actions)
3620
+ wrapper.appendChild(header)
3621
+ section.appendChild(wrapper)
3622
+
3623
+ mountRow(harness, SESSION_A, section)
3624
+ mountRow(harness, SESSION_B, section)
3625
+ harness.document.body.appendChild(section)
3626
+
3627
+ await enterMulti(harness)
3628
+ observerPass(harness)
3629
+ await flush()
3630
+
3631
+ const box = header.querySelector('.dsdel-select-all')
3632
+ assert.ok(box, 'the box exists')
3633
+ assert.deepEqual(box.__dsdelIds, [SESSION_A.id, SESSION_B.id], 'both sessions were found')
3634
+
3635
+ box.fire('click')
3636
+ await flush()
3637
+ assert.equal(box.getAttribute('aria-checked'), 'true', 'and pressing it selects them')
3638
+ })
3639
+
3640
+ test('a workspace box never reaches into a nested workspace', async () => {
3641
+ const harness = await loadPlugin()
3642
+ const section = harness.document.createElement('div')
3643
+ section.setAttribute('role', 'group')
3644
+
3645
+ const header = harness.document.createElement('div')
3646
+ header.setAttribute('role', 'treeitem')
3647
+ header.setAttribute('data-row-key', 'workspace:outer')
3648
+ const actions = harness.document.createElement('span')
3649
+ actions.className = 'wnFoaW_rowActions'
3650
+ header.appendChild(actions)
3651
+ section.appendChild(header)
3652
+ mountRow(harness, SESSION_A, section)
3653
+
3654
+ // A nested workspace is a `div[role="group"]` holding its own rows.
3655
+ const nested = harness.document.createElement('div')
3656
+ nested.setAttribute('role', 'group')
3657
+ const nestedHeader = harness.document.createElement('div')
3658
+ nestedHeader.setAttribute('role', 'treeitem')
3659
+ nestedHeader.setAttribute('data-row-key', 'workspace:inner')
3660
+ nested.appendChild(nestedHeader)
3661
+ mountRow(harness, SESSION_B, nested)
3662
+ section.appendChild(nested)
3663
+
3664
+ harness.document.body.appendChild(section)
3665
+
3666
+ await enterMulti(harness)
3667
+ observerPass(harness)
3668
+ await flush()
3669
+
3670
+ const box = header.querySelector('.dsdel-select-all')
3671
+ assert.deepEqual(box.__dsdelIds, [SESSION_A.id], 'only the outer group\'s own session')
3672
+ })
3673
+
3674
+ test('multi-select delete carries the artifact switch to every request', async () => {
3675
+ const harness = await loadPlugin({ plan: PLAN })
3676
+ localStorage.setItem(OFF_KEY, '0')
3677
+ localStorage.setItem(AUTO_KEY, '1')
3678
+ localStorage.setItem(SKIP_KEY, '1')
3679
+ const first = mountRow(harness, SESSION_A)
3680
+ const second = mountRow(harness, SESSION_B)
3681
+ await enterMulti(harness)
3682
+ clickRowIn(harness, first)
3683
+ clickRowIn(harness, second)
3684
+ await flush()
3685
+
3686
+ clickBar(barDelete(harness))
3687
+ // The batch runs several workers and settles asynchronously; waiting only one
3688
+ // tick left them running into the NEXT test, whose harness swapped the document
3689
+ // out from under them. Drain until the bar is gone.
3690
+ await settle()
3691
+ for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
3692
+
3693
+ // The single-delete path sends `quarantine`; batch used to call postDelete(id)
3694
+ // with nothing, so "quarantine the produced files" was silently skipped while
3695
+ // that same switch stayed on. Every request here has to carry it.
3696
+ const bodies = harness.requests
3697
+ .filter((call) => call.url === '/dsh-delete-session/delete')
3698
+ .map((call) => JSON.parse(call.init.body))
3699
+ assert.equal(bodies.length, 2, 'one request per selected session')
3700
+ for (const body of bodies) {
3701
+ assert.deepEqual(body.quarantine, { scope: 'created' }, 'the produced files follow the switch')
3702
+ }
3703
+ })
3704
+
3705
+ test('multi-select delete leaves the files alone when the switch is off', async () => {
3706
+ const harness = await loadPlugin()
3707
+ const first = mountRow(harness, SESSION_A)
3708
+ await enterMulti(harness)
3709
+ clickRowIn(harness, first)
3710
+ await flush()
3711
+
3712
+ clickBar(barDelete(harness))
3713
+ await settle()
3714
+ for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
3715
+
3716
+ const bodies = harness.requests
3717
+ .filter((call) => call.url === '/dsh-delete-session/delete')
3718
+ .map((call) => JSON.parse(call.init.body))
3719
+ assert.equal(bodies.length, 1, 'the delete went out')
3720
+ assert.equal('quarantine' in bodies[0], false, 'and does not move any file')
3721
+ })
3722
+
3723
+ test('a batch in asking mode says the files were left alone', async () => {
3724
+ const harness = await loadPlugin()
3725
+ localStorage.setItem(OFF_KEY, '0')
3726
+ localStorage.setItem(AUTO_KEY, '0')
3727
+ const first = mountRow(harness, SESSION_A)
3728
+ await enterMulti(harness)
3729
+ clickRowIn(harness, first)
3730
+ await flush()
3731
+
3732
+ clickBar(barDelete(harness))
3733
+ await settle()
3734
+ for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
3735
+
3736
+ // Asking means a per-file checklist, which a batch has nowhere to show. Silence
3737
+ // would look like the files had been handled.
3738
+ const said = toasts(harness).join(' | ')
3739
+ assert.equal(said.includes('产出文件没有处理'), true, 'the user is told: ' + said)
3740
+ assert.equal('quarantine' in deleteBody(harness), false, 'and nothing was moved')
3741
+ })