dsh-delete-session 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/package.json +1 -1
- package/src/client.js +114 -11
- package/test/checkbox.dom.test.js +244 -77
package/README.md
CHANGED
|
@@ -162,6 +162,19 @@ MIT
|
|
|
162
162
|
|
|
163
163
|
## 修复记录
|
|
164
164
|
|
|
165
|
+
**(v0.3.3)** —— 删除当前会话不再顺手新建一个会话。
|
|
166
|
+
|
|
167
|
+
- **问题**:删掉正在看的那个会话之后,`leaveIfCurrent()` 会去侧边栏点「新建会话」按钮,好让主视图别停在那个禁用的合成器上。可那个按钮是**用户**新建会话的入口,凡是拦截「新建会话」的插件(命名弹窗、模板选择、预设工作区)都会跟着触发 —— 结果是「删了一个会话」被做成了「新建一个会话」([#5](https://github.com/DDDMUC/dsh-delete-session/issues/5))。
|
|
168
|
+
- **改用宿主的 `uiWorkspace.clearMain()`**:放掉主引用、释放 retain、把持久化的 `dsh.sessions.current` 一并复位、清空面板。宿主自己就用它表达「没有当前会话」—— 归档当前会话走它,`startSession` 拿不到工作区也走它。
|
|
169
|
+
- **顺带去掉两个副作用**:不再需要 `localStorage.removeItem('dsh.sessions.current')`(`clearMain` 已经复位),也不再需要 `location.reload()`。
|
|
170
|
+
- **旧宿主仍有兜底**:`uiWorkspace` 拿不到(或没有 `clearMain`)时才退回原来的按钮点击 + 重置指针 + reload,保证视图不会停在已删的会话上。服务本身经 `ctx.get` 查一次、拿不到再 `ctx.inject` 补挂。
|
|
171
|
+
**(v0.3.2)** —— 语言跟随 DSH 的界面语言,而不是操作系统。
|
|
172
|
+
|
|
173
|
+
- **问题**:插件的语言只认 `navigator.language`。OS 是英文、DSH 设成中文的用户,看到的是全英文界面,而且没有任何办法改([#3](https://github.com/DDDMUC/dsh-delete-session/issues/3))。
|
|
174
|
+
- **现在跟随宿主**:先读 `locale` 服务的 `getSnapshot().active`(`dsh-client-locale` 就是这么暴露当前语言的);服务取不到就读 `document.documentElement.lang`(宿主每次切换都会把选择同步到这里);两者都没有才退回浏览器语言。
|
|
175
|
+
- **宿主语言我们没收录时的落点**:DSH 自己还认识 ja/es/fr/de/pt。这些没有对应字典,宿主对它们也只会答英文,所以插件答英文 —— 而不是像原来那样直接从浏览器猜,猜不到就掉回中文。
|
|
176
|
+
- **菜单和底栏不能再分裂**:原来会话菜单对 zh/en 一律交给宿主翻译,只有俄语才用插件字典。跟随宿主语言之后这条规则会让同一种语言出现两个来源 —— DSH 设成英文时菜单英文、底栏和弹窗中文。现在统一先查插件字典,未收录的键才交给宿主。
|
|
177
|
+
- **切换语言即时生效**:订阅 `locale.subscribe()`,宿主改语言时底栏和弹窗跟着重渲染,不需要刷新页面。
|
|
165
178
|
**(v0.3.1)** —— 批量删除也会处理产出文件了。
|
|
166
179
|
|
|
167
180
|
- **批量删除原来完全不碰产出文件**:单删会带上 `quarantine`,批量那条却调 `postDelete(id)` 什么都不传,宿主按缺省当「不动文件」。于是用户明明开着「产出文件默认全部进隔离夹」,批量删时文件**原地留着**,而且没有任何提示——看起来像做了,其实没做。现在两条路径共用 `quarantinePlan()`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-delete-session",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Delete sessions from the DSH Web sidebar: adds a Delete action to the session row menu with a risk-consent dialog, sends the session log, workspace accounting and live session state to the system trash (or removes them outright), and, when opted in, quarantines the files the conversation produced.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/client.js
CHANGED
|
@@ -358,12 +358,57 @@ window.__ModuleLoader__.load({
|
|
|
358
358
|
|
|
359
359
|
let sessionsSvc = null
|
|
360
360
|
let localeSvc = null
|
|
361
|
+
/** `uiWorkspace`: the host's own "this conversation is closed" face. */
|
|
362
|
+
let navigationSvc = null
|
|
363
|
+
/** Kept so the navigation service can be looked up lazily, outside apply(). */
|
|
364
|
+
let hostCtx = null
|
|
361
365
|
|
|
366
|
+
/** Languages this plugin ships dictionaries for. */
|
|
367
|
+
const SHIPPED = ['zh', 'en', 'ru']
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* The language DSH itself is showing, or null when the host offers none.
|
|
371
|
+
*
|
|
372
|
+
* `dsh-client-locale` provides a `locale` service: `getSnapshot()` returns
|
|
373
|
+
* `{ active }` and `subscribe()` fires on every change. It also mirrors the
|
|
374
|
+
* choice onto `document.documentElement.lang`, which covers the case where the
|
|
375
|
+
* service is not reachable but the page has already been localised.
|
|
376
|
+
*/
|
|
377
|
+
function hostLang() {
|
|
378
|
+
if (localeSvc !== null && typeof localeSvc.getSnapshot === 'function') {
|
|
379
|
+
try {
|
|
380
|
+
const snapshot = localeSvc.getSnapshot()
|
|
381
|
+
const active = snapshot && typeof snapshot.active === 'string' ? snapshot.active : null
|
|
382
|
+
if (active !== null) return active
|
|
383
|
+
} catch { /* fall through to the document hint */ }
|
|
384
|
+
}
|
|
385
|
+
if (typeof document !== 'undefined' && document.documentElement) {
|
|
386
|
+
const html = document.documentElement.lang
|
|
387
|
+
if (typeof html === 'string' && html !== '') return html
|
|
388
|
+
}
|
|
389
|
+
return null
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Which of our dictionaries to read.
|
|
394
|
+
*
|
|
395
|
+
* The host is authoritative and the browser is the fallback: following
|
|
396
|
+
* `navigator.language` alone meant an English OS rendered an English plugin
|
|
397
|
+
* even with DSH switched to 中文. A host language we do not ship (DSH knows
|
|
398
|
+
* ja/es/fr/de/pt as well) falls back to Russian for ru, English for the rest,
|
|
399
|
+
* because the host would also answer in one of those two.
|
|
400
|
+
*/
|
|
362
401
|
function browserLang() {
|
|
402
|
+
const host = hostLang()
|
|
403
|
+
if (host !== null) {
|
|
404
|
+
const primary = String(host).toLowerCase().split('-')[0]
|
|
405
|
+
if (primary === 'zh' || primary === 'en' || primary === 'ru') return primary
|
|
406
|
+
return primary === 'ru' ? 'ru' : 'en'
|
|
407
|
+
}
|
|
363
408
|
if (typeof navigator === 'undefined') return 'zh'
|
|
364
409
|
for (const tag of (navigator.languages || []).concat([navigator.language])) {
|
|
365
410
|
const primary = String(tag || '').toLowerCase().split('-')[0]
|
|
366
|
-
if (primary
|
|
411
|
+
if (SHIPPED.indexOf(primary) !== -1) return primary
|
|
367
412
|
}
|
|
368
413
|
return 'zh'
|
|
369
414
|
}
|
|
@@ -444,17 +489,18 @@ window.__ModuleLoader__.load({
|
|
|
444
489
|
}
|
|
445
490
|
|
|
446
491
|
/**
|
|
447
|
-
*
|
|
492
|
+
* The translator every slot component renders through.
|
|
448
493
|
*
|
|
449
|
-
* The
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
494
|
+
* The plugin ships its own dictionaries and follows the host's language
|
|
495
|
+
* (issue #3), so its dictionary is asked first for every language it carries,
|
|
496
|
+
* not just Russian. Deferring to the injected `t` for zh/en would split one
|
|
497
|
+
* language across two authorities: with DSH set to English the menu would say
|
|
498
|
+
* "Delete session" while the bar and the dialog stayed Chinese. Keys this
|
|
499
|
+
* plugin does not ship still go to the host.
|
|
454
500
|
*/
|
|
455
501
|
function slotTranslator(injected) {
|
|
456
502
|
const raw = typeof injected === 'function' ? injected : t
|
|
457
|
-
return
|
|
503
|
+
return localizedTranslator(raw)
|
|
458
504
|
}
|
|
459
505
|
|
|
460
506
|
// --- state -----------------------------------------------------------------
|
|
@@ -878,13 +924,34 @@ window.__ModuleLoader__.load({
|
|
|
878
924
|
try { window.location.reload() } catch { /* ignore */ }
|
|
879
925
|
}
|
|
880
926
|
|
|
881
|
-
// Deleting the session the main view is showing
|
|
882
|
-
//
|
|
883
|
-
// which
|
|
927
|
+
// Deleting the session the main view is showing has to leave the app with no
|
|
928
|
+
// current conversation. It used to click the sidebar's "new session" button,
|
|
929
|
+
// which is wrong twice over: that button is the USER entry point, so every
|
|
930
|
+
// plugin that intercepts a new session (a naming dialog, a template picker,
|
|
931
|
+
// a preset workspace) fires on a delete; and the visible result of a delete
|
|
932
|
+
// became "a new conversation was created".
|
|
933
|
+
//
|
|
934
|
+
// The host has a way to express exactly this: `uiWorkspace.clearMain()`
|
|
935
|
+
// drops the main reference, releases its retain, resets the persisted
|
|
936
|
+
// `dsh.sessions.current` pointer and clears the panel. Archiving the current
|
|
937
|
+
// conversation and a failed `startSession` both go through it, so it is the
|
|
938
|
+
// sanctioned "nothing is open" state rather than a side effect of ours.
|
|
884
939
|
function deletedVariants(id) {
|
|
885
940
|
return id.startsWith('session-') ? [id, id.slice('session-'.length)] : [id, `session-${id}`]
|
|
886
941
|
}
|
|
887
942
|
|
|
943
|
+
/** The navigation service, looked up lazily so a late one is still found. */
|
|
944
|
+
function navigationApi() {
|
|
945
|
+
if (navigationSvc !== null) return navigationSvc
|
|
946
|
+
const holder = hostCtx
|
|
947
|
+
if (holder === null || typeof holder.get !== 'function') return navigationSvc
|
|
948
|
+
try {
|
|
949
|
+
const svc = holder.get('uiWorkspace')
|
|
950
|
+
if (svc !== null && svc !== undefined) navigationSvc = svc
|
|
951
|
+
} catch { /* optional service */ }
|
|
952
|
+
return navigationSvc
|
|
953
|
+
}
|
|
954
|
+
|
|
888
955
|
function leaveIfCurrent(id) {
|
|
889
956
|
let current = null
|
|
890
957
|
try {
|
|
@@ -894,6 +961,18 @@ window.__ModuleLoader__.load({
|
|
|
894
961
|
return
|
|
895
962
|
}
|
|
896
963
|
if (!current || !deletedVariants(id).includes(current)) return
|
|
964
|
+
|
|
965
|
+
// Preferred: tell the host, which owns the pointer and the retain.
|
|
966
|
+
const api = navigationApi()
|
|
967
|
+
if (api !== null && typeof api.clearMain === 'function') {
|
|
968
|
+
try {
|
|
969
|
+
api.clearMain()
|
|
970
|
+
return
|
|
971
|
+
} catch { /* older build: fall through */ }
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// No such service (a host that predates it): the old route, kept so the
|
|
975
|
+
// view is never left pointing at a conversation that no longer exists.
|
|
897
976
|
const btn = document.querySelector(
|
|
898
977
|
'button[class*="newSession"], button[aria-label*="New session" i], button[aria-label*="新会话"]',
|
|
899
978
|
)
|
|
@@ -2728,11 +2807,23 @@ window.__ModuleLoader__.load({
|
|
|
2728
2807
|
}
|
|
2729
2808
|
}
|
|
2730
2809
|
|
|
2810
|
+
hostCtx = ctx
|
|
2731
2811
|
sessionsSvc = ctx.get('sessions') || null
|
|
2732
2812
|
if (!sessionsSvc) {
|
|
2733
2813
|
try { ctx.inject(['sessions'], (sub) => { sessionsSvc = sub.sessions }) } catch { /* optional */ }
|
|
2734
2814
|
}
|
|
2735
2815
|
localeSvc = ctx.get('locale') || null
|
|
2816
|
+
// `uiWorkspace` is a service, not a module: `ctx.get` is an optional lookup,
|
|
2817
|
+
// and a host that provides it later is covered by the inject below.
|
|
2818
|
+
try {
|
|
2819
|
+
const nav = ctx.get('uiWorkspace')
|
|
2820
|
+
if (nav !== null && nav !== undefined) navigationSvc = nav
|
|
2821
|
+
} catch { /* optional service */ }
|
|
2822
|
+
if (navigationSvc === null) {
|
|
2823
|
+
try {
|
|
2824
|
+
ctx.inject(['uiWorkspace'], (sub) => { navigationSvc = sub.uiWorkspace || null })
|
|
2825
|
+
} catch { /* optional service */ }
|
|
2826
|
+
}
|
|
2736
2827
|
|
|
2737
2828
|
// Slot components are handed a `t` bound to this namespace, so the
|
|
2738
2829
|
// dictionaries must reach the host - on BOTH arrival paths. If `locale`
|
|
@@ -2741,8 +2832,20 @@ window.__ModuleLoader__.load({
|
|
|
2741
2832
|
// printing raw keys ("multiSelect", "menu"). `ctx.effect` ties the
|
|
2742
2833
|
// registration's lifetime to the plugin, matching ui-workspace.
|
|
2743
2834
|
let localeRegistered = false
|
|
2835
|
+
let localeSubscribed = false
|
|
2744
2836
|
const adoptLocale = (svc) => {
|
|
2745
2837
|
localeSvc = svc || null
|
|
2838
|
+
// The bar, the dialog and the toasts are rendered by this plugin, so they
|
|
2839
|
+
// do not inherit the host's re-render when the language changes in the
|
|
2840
|
+
// settings. Piggy-backing on the service's own notification keeps them in
|
|
2841
|
+
// step with the menu rows, which the host and re-render itself.
|
|
2842
|
+
if (localeSvc !== null && typeof localeSvc.subscribe === 'function' && !localeSubscribed) {
|
|
2843
|
+
localeSubscribed = true
|
|
2844
|
+
try {
|
|
2845
|
+
const off = localeSvc.subscribe(() => { try { publish() } catch { /* not mounted yet */ } })
|
|
2846
|
+
if (typeof ctx.effect === 'function' && typeof off === 'function') ctx.effect(() => off, `${NS}: language changes`)
|
|
2847
|
+
} catch { /* a host without subscribe still renders on its own */ }
|
|
2848
|
+
}
|
|
2746
2849
|
if (localeRegistered || !localeSvc || typeof localeSvc.register !== 'function') return
|
|
2747
2850
|
localeRegistered = true
|
|
2748
2851
|
const register = () => localeSvc.register(NS, { zh, en, ru })
|
|
@@ -188,6 +188,12 @@ function walk(root) {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
function matches(node, selector) {
|
|
191
|
+
// A comma list is an OR in the DOM, and the plugin uses one to find the
|
|
192
|
+
// "new session" button. Without this the stub silently answered "no match"
|
|
193
|
+
// for every alternative, which hid the fallback path entirely.
|
|
194
|
+
if (selector.includes(',')) {
|
|
195
|
+
return selector.split(',').some((part) => matches(node, part.trim()))
|
|
196
|
+
}
|
|
191
197
|
// `:scope > .dsdel-check` - a DIRECT child. The plugin uses this to tell its
|
|
192
198
|
// own row checkbox apart from anything nested, so depth has to be respected.
|
|
193
199
|
const scoped = /^:scope > \.([\w-]+)$/.exec(selector)
|
|
@@ -201,6 +207,23 @@ function matches(node, selector) {
|
|
|
201
207
|
return node._classes.has(selector.slice(1))
|
|
202
208
|
}
|
|
203
209
|
|
|
210
|
+
// `button[class*="newSession"]` - tag-qualified, used by the fallback that
|
|
211
|
+
// finds the host's "new session" button after a delete.
|
|
212
|
+
const tagClassContains = /^([A-Za-z][\w-]*)\[class\*="([^"]*)"\]$/.exec(selector)
|
|
213
|
+
if (tagClassContains !== null) {
|
|
214
|
+
if (String(node.tagName || '').toLowerCase() !== tagClassContains[1].toLowerCase()) return false
|
|
215
|
+
return String(node.className ?? '').includes(tagClassContains[2])
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// `button[aria-label*="New session" i]` - a case-insensitive attribute match.
|
|
219
|
+
const tagAttrContains = /^([A-Za-z][\w-]*)\[([\w-]+)\*="([^"]*)"(?: i)?\]$/.exec(selector)
|
|
220
|
+
if (tagAttrContains !== null) {
|
|
221
|
+
if (String(node.tagName || '').toLowerCase() !== tagAttrContains[1].toLowerCase()) return false
|
|
222
|
+
const value = node.attributes[tagAttrContains[2]]
|
|
223
|
+
if (typeof value !== 'string') return false
|
|
224
|
+
return value.toLowerCase().includes(tagAttrContains[3].toLowerCase())
|
|
225
|
+
}
|
|
226
|
+
|
|
204
227
|
// `[class*="_footArea"]` - how the bar finds the host's sidebar footer.
|
|
205
228
|
const classContains = /^\[class\*="([^"]*)"\]$/.exec(selector)
|
|
206
229
|
if (classContains !== null) return node.className.includes(classContains[1])
|
|
@@ -257,6 +280,8 @@ async function loadPlugin(options = {}) {
|
|
|
257
280
|
const document = {
|
|
258
281
|
body: new StubElement('body'),
|
|
259
282
|
head: new StubElement('head'),
|
|
283
|
+
// Read when the host provides no locale service at all.
|
|
284
|
+
documentElement: new StubElement('html'),
|
|
260
285
|
createElement: (tag) => new StubElement(tag),
|
|
261
286
|
addEventListener(type, handler) {
|
|
262
287
|
const list = documentListeners.get(type) ?? []
|
|
@@ -399,6 +424,11 @@ async function loadPlugin(options = {}) {
|
|
|
399
424
|
const locales = {}
|
|
400
425
|
const localeStub = {
|
|
401
426
|
register: (namespace, dictionaries) => { locales[namespace] = dictionaries },
|
|
427
|
+
// `dsh-client-locale` exposes `getSnapshot() -> { active }`. The plugin follows
|
|
428
|
+
// it instead of `navigator.language`, so an English OS with DSH in Chinese no
|
|
429
|
+
// longer renders an English plugin (issue #3).
|
|
430
|
+
getSnapshot: () => ({ active: options.activeLocale ?? 'zh', locales: [], revision: 0 }),
|
|
431
|
+
subscribe: () => () => {},
|
|
402
432
|
// Mirrors dsh-client-locale: a non-string entry is handed back untouched, and
|
|
403
433
|
// only string templates interpolate `{name}` from a params object. Returning
|
|
404
434
|
// a function as-is is exactly what makes the plugin fall back to its own
|
|
@@ -449,11 +479,18 @@ async function loadPlugin(options = {}) {
|
|
|
449
479
|
if (name === 'slots') return slotsStub
|
|
450
480
|
// `lateLocale` models a host where the locale service is only reachable
|
|
451
481
|
// through ctx.inject, which is the path that used to skip registration.
|
|
452
|
-
if (name === 'locale') return options.lateLocale ? null : localeStub
|
|
482
|
+
if (name === 'locale') return (options.lateLocale || options.noLocale) ? null : localeStub
|
|
483
|
+
if (name === 'uiWorkspace') return options.noNavigation ? null : (options.navigation || null)
|
|
453
484
|
return null
|
|
454
485
|
},
|
|
455
486
|
inject: (names, cb) => {
|
|
456
|
-
if (typeof cb === 'function')
|
|
487
|
+
if (typeof cb === 'function') {
|
|
488
|
+
const late = options.lateLocale && !options.noLocale
|
|
489
|
+
const bag = { slots: slotsStub }
|
|
490
|
+
if (late) bag.locale = localeStub
|
|
491
|
+
if (options.navigation && !options.noNavigation) bag.uiWorkspace = options.navigation
|
|
492
|
+
cb(bag)
|
|
493
|
+
}
|
|
457
494
|
},
|
|
458
495
|
effect: (fn) => { const dispose = fn(); return () => { if (typeof dispose === 'function') dispose() } },
|
|
459
496
|
})
|
|
@@ -723,8 +760,69 @@ test('the Russian dictionary ships with every key the other dictionaries carry',
|
|
|
723
760
|
assert.deepEqual(keys(en), keys(zh), 'en still covers the zh key set')
|
|
724
761
|
})
|
|
725
762
|
|
|
726
|
-
test('
|
|
727
|
-
const harness = await loadPlugin()
|
|
763
|
+
test('an English OS with DSH in Chinese renders Chinese (issue #3)', async () => {
|
|
764
|
+
const harness = await loadPlugin({ activeLocale: 'zh' })
|
|
765
|
+
const previous = globalThis.navigator
|
|
766
|
+
Object.defineProperty(globalThis, 'navigator', {
|
|
767
|
+
value: { language: 'en-US', languages: ['en-US'] },
|
|
768
|
+
configurable: true,
|
|
769
|
+
writable: true,
|
|
770
|
+
})
|
|
771
|
+
try {
|
|
772
|
+
// The reported bug: the OS is English, the user set DSH to 中文, and the plugin
|
|
773
|
+
// still answered in English because it read `navigator.language`. The host is
|
|
774
|
+
// the authority now, so the browser language must not win.
|
|
775
|
+
assert.equal(deleteRow(harness).element.props.children, '删除会话')
|
|
776
|
+
assert.equal(selectRow(harness).element.props.children, '多选')
|
|
777
|
+
} finally {
|
|
778
|
+
Object.defineProperty(globalThis, 'navigator', {
|
|
779
|
+
value: previous,
|
|
780
|
+
configurable: true,
|
|
781
|
+
writable: true,
|
|
782
|
+
})
|
|
783
|
+
}
|
|
784
|
+
})
|
|
785
|
+
|
|
786
|
+
test('a Chinese OS with DSH in English renders English', async () => {
|
|
787
|
+
const harness = await loadPlugin({ activeLocale: 'en' })
|
|
788
|
+
const previous = globalThis.navigator
|
|
789
|
+
Object.defineProperty(globalThis, 'navigator', {
|
|
790
|
+
value: { language: 'zh-CN', languages: ['zh-CN'] },
|
|
791
|
+
configurable: true,
|
|
792
|
+
writable: true,
|
|
793
|
+
})
|
|
794
|
+
try {
|
|
795
|
+
assert.equal(deleteRow(harness).element.props.children, 'Delete session')
|
|
796
|
+
assert.equal(selectRow(harness).element.props.children, 'Select multiple')
|
|
797
|
+
} finally {
|
|
798
|
+
Object.defineProperty(globalThis, 'navigator', {
|
|
799
|
+
value: previous,
|
|
800
|
+
configurable: true,
|
|
801
|
+
writable: true,
|
|
802
|
+
})
|
|
803
|
+
}
|
|
804
|
+
})
|
|
805
|
+
|
|
806
|
+
test('a host language we do not ship falls back to English', async () => {
|
|
807
|
+
const harness = await loadPlugin({ activeLocale: 'ja' })
|
|
808
|
+
|
|
809
|
+
// DSH knows ja/es/fr/de/pt as well. Those have no dictionary here, and the host
|
|
810
|
+
// would answer in English for them, so the plugin does too instead of silently
|
|
811
|
+
// dropping to Chinese (which is what the old browser-based fallback did).
|
|
812
|
+
assert.equal(deleteRow(harness).element.props.children, 'Delete session')
|
|
813
|
+
})
|
|
814
|
+
|
|
815
|
+
test('with no locale service the document hint decides', async () => {
|
|
816
|
+
const harness = await loadPlugin({ lateLocale: true, noLocale: true })
|
|
817
|
+
harness.document.documentElement.lang = 'ru'
|
|
818
|
+
|
|
819
|
+
// `dsh-client-locale` mirrors its choice onto `<html lang>`. A host that never
|
|
820
|
+
// hands over the service still leaves that behind, so it is read next.
|
|
821
|
+
assert.equal(deleteRow(harness).element.props.children, 'Удалить сессию')
|
|
822
|
+
})
|
|
823
|
+
|
|
824
|
+
test('with neither hint the browser language is the last resort', async () => {
|
|
825
|
+
const harness = await loadPlugin({ noLocale: true })
|
|
728
826
|
const previous = globalThis.navigator
|
|
729
827
|
Object.defineProperty(globalThis, 'navigator', {
|
|
730
828
|
value: { language: 'ru-RU', languages: ['ru-RU'] },
|
|
@@ -732,10 +830,9 @@ test('a Russian browser gets Russian labels from the built-in dictionary', async
|
|
|
732
830
|
writable: true,
|
|
733
831
|
})
|
|
734
832
|
try {
|
|
735
|
-
//
|
|
736
|
-
//
|
|
833
|
+
// Pre-#3 behaviour, kept as the floor: something has to answer when the host
|
|
834
|
+
// provides nothing at all.
|
|
737
835
|
assert.equal(deleteRow(harness).element.props.children, 'Удалить сессию')
|
|
738
|
-
assert.equal(selectRow(harness).element.props.children, 'Выбрать несколько')
|
|
739
836
|
} finally {
|
|
740
837
|
Object.defineProperty(globalThis, 'navigator', {
|
|
741
838
|
value: previous,
|
|
@@ -744,6 +841,14 @@ test('a Russian browser gets Russian labels from the built-in dictionary', async
|
|
|
744
841
|
})
|
|
745
842
|
}
|
|
746
843
|
})
|
|
844
|
+
test('a Russian DSH gets Russian labels from the built-in dictionary', async () => {
|
|
845
|
+
const harness = await loadPlugin({ activeLocale: 'ru' })
|
|
846
|
+
|
|
847
|
+
// The host translator in this harness answers in zh; the rows must prefer the
|
|
848
|
+
// plugin's own Russian dictionary instead of following it.
|
|
849
|
+
assert.equal(deleteRow(harness).element.props.children, 'Удалить сессию')
|
|
850
|
+
assert.equal(selectRow(harness).element.props.children, 'Выбрать несколько')
|
|
851
|
+
})
|
|
747
852
|
|
|
748
853
|
test('the delete row asks the host for its danger styling', async () => {
|
|
749
854
|
const harness = await loadPlugin()
|
|
@@ -796,6 +901,68 @@ test('shift-click forces the dialog even after asking was turned off', async ()
|
|
|
796
901
|
|
|
797
902
|
// --- the regression ---------------------------------------------------------
|
|
798
903
|
|
|
904
|
+
test('deleting the current session clears the main view instead of opening a new one (issue #5)', async () => {
|
|
905
|
+
let cleared = 0
|
|
906
|
+
const harness = await loadPlugin({
|
|
907
|
+
navigation: { clearMain: () => { cleared += 1 } },
|
|
908
|
+
})
|
|
909
|
+
mountRow(harness, SESSION_A)
|
|
910
|
+
localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
|
|
911
|
+
|
|
912
|
+
// The host's own session menu row drives the delete; asking is off so it goes
|
|
913
|
+
// straight through, like the reporter did.
|
|
914
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
915
|
+
const { element } = deleteRow(harness)
|
|
916
|
+
element.props.onSelect({ shiftKey: false })
|
|
917
|
+
await tick()
|
|
918
|
+
await flush()
|
|
919
|
+
|
|
920
|
+
// Issue #5: this used to click the sidebar's "new session" button, which every
|
|
921
|
+
// plugin that intercepts session creation shares (a naming dialog, a template
|
|
922
|
+
// picker). Deleting a conversation must not create one.
|
|
923
|
+
assert.equal(cleared, 1, 'the host was told to drop the main reference')
|
|
924
|
+
assert.equal(harness.requests.filter((c) => c.url === '/dsh-delete-session/delete').length, 1, 'the delete still went out')
|
|
925
|
+
})
|
|
926
|
+
|
|
927
|
+
test('a delete that is not the current session leaves navigation alone', async () => {
|
|
928
|
+
let cleared = 0
|
|
929
|
+
const harness = await loadPlugin({
|
|
930
|
+
navigation: { clearMain: () => { cleared += 1 } },
|
|
931
|
+
})
|
|
932
|
+
mountRow(harness, SESSION_A)
|
|
933
|
+
localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_B.id }))
|
|
934
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
935
|
+
|
|
936
|
+
const { element } = deleteRow(harness)
|
|
937
|
+
element.props.onSelect({ shiftKey: false })
|
|
938
|
+
await tick()
|
|
939
|
+
await flush()
|
|
940
|
+
|
|
941
|
+
assert.equal(cleared, 0, 'nothing to clear: the deleted one was not on screen')
|
|
942
|
+
})
|
|
943
|
+
|
|
944
|
+
test('with no navigation service the sidebar button is the last resort', async () => {
|
|
945
|
+
const harness = await loadPlugin({ noNavigation: true })
|
|
946
|
+
mountRow(harness, SESSION_A)
|
|
947
|
+
localStorage.setItem('dsh.sessions.current', JSON.stringify({ sessionId: SESSION_A.id }))
|
|
948
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
949
|
+
|
|
950
|
+
// A host that predates `clearMain` still has to end up with no current
|
|
951
|
+
// conversation, so the old fallback stays. It is only reached when the service
|
|
952
|
+
// is genuinely absent.
|
|
953
|
+
let clicked = 0
|
|
954
|
+
const btn = harness.document.createElement('button')
|
|
955
|
+
btn.className = 'newSession'
|
|
956
|
+
btn.click = () => { clicked += 1 }
|
|
957
|
+
harness.document.body.appendChild(btn)
|
|
958
|
+
|
|
959
|
+
const { element } = deleteRow(harness)
|
|
960
|
+
element.props.onSelect({ shiftKey: false })
|
|
961
|
+
await tick()
|
|
962
|
+
await flush()
|
|
963
|
+
|
|
964
|
+
assert.equal(clicked, 1, 'the fallback still runs without the service')
|
|
965
|
+
})
|
|
799
966
|
test('a single delete plants no checkbox on any row (the v0.1.8 regression)', async () => {
|
|
800
967
|
const harness = await loadPlugin()
|
|
801
968
|
mountRow(harness, SESSION_A)
|
|
@@ -3591,73 +3758,73 @@ test('a workspace box never reaches into a nested workspace', async () => {
|
|
|
3591
3758
|
|
|
3592
3759
|
const box = header.querySelector('.dsdel-select-all')
|
|
3593
3760
|
assert.deepEqual(box.__dsdelIds, [SESSION_A.id], 'only the outer group\'s own session')
|
|
3594
|
-
})
|
|
3595
|
-
|
|
3596
|
-
test('multi-select delete carries the artifact switch to every request', async () => {
|
|
3597
|
-
const harness = await loadPlugin({ plan: PLAN })
|
|
3598
|
-
localStorage.setItem(OFF_KEY, '0')
|
|
3599
|
-
localStorage.setItem(AUTO_KEY, '1')
|
|
3600
|
-
localStorage.setItem(SKIP_KEY, '1')
|
|
3601
|
-
const first = mountRow(harness, SESSION_A)
|
|
3602
|
-
const second = mountRow(harness, SESSION_B)
|
|
3603
|
-
await enterMulti(harness)
|
|
3604
|
-
clickRowIn(harness, first)
|
|
3605
|
-
clickRowIn(harness, second)
|
|
3606
|
-
await flush()
|
|
3607
|
-
|
|
3608
|
-
clickBar(barDelete(harness))
|
|
3609
|
-
// The batch runs several workers and settles asynchronously; waiting only one
|
|
3610
|
-
// tick left them running into the NEXT test, whose harness swapped the document
|
|
3611
|
-
// out from under them. Drain until the bar is gone.
|
|
3612
|
-
await settle()
|
|
3613
|
-
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3614
|
-
|
|
3615
|
-
// The single-delete path sends `quarantine`; batch used to call postDelete(id)
|
|
3616
|
-
// with nothing, so "quarantine the produced files" was silently skipped while
|
|
3617
|
-
// that same switch stayed on. Every request here has to carry it.
|
|
3618
|
-
const bodies = harness.requests
|
|
3619
|
-
.filter((call) => call.url === '/dsh-delete-session/delete')
|
|
3620
|
-
.map((call) => JSON.parse(call.init.body))
|
|
3621
|
-
assert.equal(bodies.length, 2, 'one request per selected session')
|
|
3622
|
-
for (const body of bodies) {
|
|
3623
|
-
assert.deepEqual(body.quarantine, { scope: 'created' }, 'the produced files follow the switch')
|
|
3624
|
-
}
|
|
3625
|
-
})
|
|
3626
|
-
|
|
3627
|
-
test('multi-select delete leaves the files alone when the switch is off', async () => {
|
|
3628
|
-
const harness = await loadPlugin()
|
|
3629
|
-
const first = mountRow(harness, SESSION_A)
|
|
3630
|
-
await enterMulti(harness)
|
|
3631
|
-
clickRowIn(harness, first)
|
|
3632
|
-
await flush()
|
|
3633
|
-
|
|
3634
|
-
clickBar(barDelete(harness))
|
|
3635
|
-
await settle()
|
|
3636
|
-
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3637
|
-
|
|
3638
|
-
const bodies = harness.requests
|
|
3639
|
-
.filter((call) => call.url === '/dsh-delete-session/delete')
|
|
3640
|
-
.map((call) => JSON.parse(call.init.body))
|
|
3641
|
-
assert.equal(bodies.length, 1, 'the delete went out')
|
|
3642
|
-
assert.equal('quarantine' in bodies[0], false, 'and does not move any file')
|
|
3643
|
-
})
|
|
3644
|
-
|
|
3645
|
-
test('a batch in asking mode says the files were left alone', async () => {
|
|
3646
|
-
const harness = await loadPlugin()
|
|
3647
|
-
localStorage.setItem(OFF_KEY, '0')
|
|
3648
|
-
localStorage.setItem(AUTO_KEY, '0')
|
|
3649
|
-
const first = mountRow(harness, SESSION_A)
|
|
3650
|
-
await enterMulti(harness)
|
|
3651
|
-
clickRowIn(harness, first)
|
|
3652
|
-
await flush()
|
|
3653
|
-
|
|
3654
|
-
clickBar(barDelete(harness))
|
|
3655
|
-
await settle()
|
|
3656
|
-
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3657
|
-
|
|
3658
|
-
// Asking means a per-file checklist, which a batch has nowhere to show. Silence
|
|
3659
|
-
// would look like the files had been handled.
|
|
3660
|
-
const said = toasts(harness).join(' | ')
|
|
3661
|
-
assert.equal(said.includes('产出文件没有处理'), true, 'the user is told: ' + said)
|
|
3662
|
-
assert.equal('quarantine' in deleteBody(harness), false, 'and nothing was moved')
|
|
3663
|
-
})
|
|
3761
|
+
})
|
|
3762
|
+
|
|
3763
|
+
test('multi-select delete carries the artifact switch to every request', async () => {
|
|
3764
|
+
const harness = await loadPlugin({ plan: PLAN })
|
|
3765
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
3766
|
+
localStorage.setItem(AUTO_KEY, '1')
|
|
3767
|
+
localStorage.setItem(SKIP_KEY, '1')
|
|
3768
|
+
const first = mountRow(harness, SESSION_A)
|
|
3769
|
+
const second = mountRow(harness, SESSION_B)
|
|
3770
|
+
await enterMulti(harness)
|
|
3771
|
+
clickRowIn(harness, first)
|
|
3772
|
+
clickRowIn(harness, second)
|
|
3773
|
+
await flush()
|
|
3774
|
+
|
|
3775
|
+
clickBar(barDelete(harness))
|
|
3776
|
+
// The batch runs several workers and settles asynchronously; waiting only one
|
|
3777
|
+
// tick left them running into the NEXT test, whose harness swapped the document
|
|
3778
|
+
// out from under them. Drain until the bar is gone.
|
|
3779
|
+
await settle()
|
|
3780
|
+
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3781
|
+
|
|
3782
|
+
// The single-delete path sends `quarantine`; batch used to call postDelete(id)
|
|
3783
|
+
// with nothing, so "quarantine the produced files" was silently skipped while
|
|
3784
|
+
// that same switch stayed on. Every request here has to carry it.
|
|
3785
|
+
const bodies = harness.requests
|
|
3786
|
+
.filter((call) => call.url === '/dsh-delete-session/delete')
|
|
3787
|
+
.map((call) => JSON.parse(call.init.body))
|
|
3788
|
+
assert.equal(bodies.length, 2, 'one request per selected session')
|
|
3789
|
+
for (const body of bodies) {
|
|
3790
|
+
assert.deepEqual(body.quarantine, { scope: 'created' }, 'the produced files follow the switch')
|
|
3791
|
+
}
|
|
3792
|
+
})
|
|
3793
|
+
|
|
3794
|
+
test('multi-select delete leaves the files alone when the switch is off', async () => {
|
|
3795
|
+
const harness = await loadPlugin()
|
|
3796
|
+
const first = mountRow(harness, SESSION_A)
|
|
3797
|
+
await enterMulti(harness)
|
|
3798
|
+
clickRowIn(harness, first)
|
|
3799
|
+
await flush()
|
|
3800
|
+
|
|
3801
|
+
clickBar(barDelete(harness))
|
|
3802
|
+
await settle()
|
|
3803
|
+
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3804
|
+
|
|
3805
|
+
const bodies = harness.requests
|
|
3806
|
+
.filter((call) => call.url === '/dsh-delete-session/delete')
|
|
3807
|
+
.map((call) => JSON.parse(call.init.body))
|
|
3808
|
+
assert.equal(bodies.length, 1, 'the delete went out')
|
|
3809
|
+
assert.equal('quarantine' in bodies[0], false, 'and does not move any file')
|
|
3810
|
+
})
|
|
3811
|
+
|
|
3812
|
+
test('a batch in asking mode says the files were left alone', async () => {
|
|
3813
|
+
const harness = await loadPlugin()
|
|
3814
|
+
localStorage.setItem(OFF_KEY, '0')
|
|
3815
|
+
localStorage.setItem(AUTO_KEY, '0')
|
|
3816
|
+
const first = mountRow(harness, SESSION_A)
|
|
3817
|
+
await enterMulti(harness)
|
|
3818
|
+
clickRowIn(harness, first)
|
|
3819
|
+
await flush()
|
|
3820
|
+
|
|
3821
|
+
clickBar(barDelete(harness))
|
|
3822
|
+
await settle()
|
|
3823
|
+
for (let i = 0; i < 40 && bar(harness) !== null; i += 1) await flush()
|
|
3824
|
+
|
|
3825
|
+
// Asking means a per-file checklist, which a batch has nowhere to show. Silence
|
|
3826
|
+
// would look like the files had been handled.
|
|
3827
|
+
const said = toasts(harness).join(' | ')
|
|
3828
|
+
assert.equal(said.includes('产出文件没有处理'), true, 'the user is told: ' + said)
|
|
3829
|
+
assert.equal('quarantine' in deleteBody(harness), false, 'and nothing was moved')
|
|
3830
|
+
})
|