@240xu/dsh-message-ops 0.9.6 → 0.10.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.
@@ -3,15 +3,28 @@
3
3
  *
4
4
  * /undo 走官方斜杠管线 `ctx.inputTriggers.registerSource`,注册路径踩过四个坑,
5
5
  * 全部锁在这里(宿主侧的契约坑无法用单测覆盖,故此文件锁「我方判定」那一半)。
6
+ *
7
+ * 🔴🔴 文件里的 helper 分两类,**不许与其它测试的 helper 合并去重** 🔴🔴
8
+ *
9
+ * 1. `shouldHide(cands, fences, reverted)` —— **0.9.4 历史判据(已废弃)** 的
10
+ * 独立副本。client.js 0.9.6 起藏行判据已是 `idx.shadowed`(replace 区间),
11
+ * `fences` / `reverted` 两套都不再存在。本 helper 全绿只因测的是自己的副本;
12
+ * 它与 `test/transcript-visibility.test.js` 的 `decide()` 属同一批历史样本。
13
+ * ⛔ 合并 = 把过期契约焊死成现行契约。
14
+ * 2. `pickLastVisible(rows)` —— **仍与现行实现同源**:对齐 client.js 的
15
+ * `lastRevertable`(「可回滚目标」必须挑模型 surface 上的那一条,至今用
16
+ * `visible`)。那是另一套语义,与藏行判据无关,不要混淆。
6
17
  */
7
18
  import test from 'node:test'
8
19
  import assert from 'node:assert/strict'
20
+ import fs from 'node:fs'
9
21
 
10
22
  const bare = (id) => String(id || '').replace(/^session-/, '')
11
23
  const pickLastVisible = (rows) => {
12
24
  for (let i = rows.length - 1; i >= 0; i--) if (rows[i] && rows[i].seq != null && rows[i].visible) return rows[i]
13
25
  return null
14
26
  }
27
+ /** [0.9.4 判据(已废弃)] 历史副本 —— 现行判据是 client.js 的 idx.shadowed。 */
15
28
  const shouldHide = (cands, fences, reverted) =>
16
29
  fences.length ? cands.some((q) => fences.some((f) => q >= f)) : cands.some((q) => reverted.has(q))
17
30
 
@@ -27,6 +40,7 @@ test('回归:__currentSessionId 带前缀会让 API 请求静默失败', () =>
27
40
  })
28
41
 
29
42
  test('lastRevertable 必须挑 surface 上的那条', () => {
43
+ // [现行同源] 对齐 client.js 的 lastRevertable(visible = 模型 surface,仍在用)
30
44
  const rows = [
31
45
  { seq: 8, visible: true },
32
46
  { seq: 54, visible: true },
@@ -44,6 +58,7 @@ test('没有 surface 上的用户消息 → 返回 null,不发请求', () => {
44
58
  })
45
59
 
46
60
  test('fence 判定:边界及其后都藏', () => {
61
+ // [0.9.4 判据(已废弃)] fences 只存在于历史实现,client.js 已不发 revertFences。
47
62
  assert.equal(shouldHide([8], [8], new Set()), true)
48
63
  assert.equal(shouldHide([7], [8], new Set()), false)
49
64
  assert.equal(shouldHide([70], [70, 8], new Set()), true, '多个 fence 取并集')
@@ -52,10 +67,23 @@ test('fence 判定:边界及其后都藏', () => {
52
67
  })
53
68
 
54
69
  test('fence 为空时退回 reverted 集合', () => {
70
+ // [0.9.4 判据(已废弃)] reverted 集合已被 0.9.6 的 shadowed 取代。
55
71
  assert.equal(shouldHide([54], [], new Set([54, 63])), true)
56
72
  assert.equal(shouldHide([8], [], new Set([54, 63])), false)
57
73
  })
58
74
 
59
75
  test('空 fences + 空 reverted → 全部可见', () => {
76
+ // [0.9.4 判据(已废弃)]
60
77
  assert.equal(shouldHide([1, 2, 3], [], new Set()), false)
61
78
  })
79
+
80
+ // ── 对照:现行实现(0.9.6+)用的是 shadowed,不是上面那些历史副本 ────────────
81
+ test('[当前判据对照] client.js 藏行判据 = idx.shadowed,本文件 shouldHide 只是历史样本', () => {
82
+ const src = fs.readFileSync(new URL('../src/client.js', import.meta.url), 'utf8')
83
+ assert.ok(/shouldHide = idx\.shadowed\.has\(hit\.seq\)/.test(src),
84
+ '消息/工具类判据必须是 idx.shadowed(0.9.6)')
85
+ assert.ok(!/\bfences\b/.test(src.match(/var applySurfaceVisibility = [\s\S]*?\n {6}\};/)?.[0] ?? ''),
86
+ 'applySurfaceVisibility 内不得出现 fences(0.9.4 判据已废弃)')
87
+ assert.ok(/r\.seq != null && r\.visible/.test(src),
88
+ 'lastRevertable 仍须用 visible 挑「可回滚目标」(与藏行判据是两套语义)')
89
+ })