dsh-knit 0.17.0 → 0.19.0
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/CHANGELOG.md +333 -2
- package/README.en.md +128 -31
- package/README.md +142 -25
- package/SECURITY.md +4 -3
- package/package.json +6 -4
- package/src/client/client.js +1146 -194
- package/src/host/classification.js +250 -0
- package/src/host/context.js +31 -9
- package/src/host/index.js +336 -77
- package/src/host/tool.js +29 -13
- package/test/classification.test.mjs +237 -0
- package/test/client.test.mjs +982 -54
- package/test/code-context.test.mjs +567 -0
- package/test/eval/fixture.mjs +309 -6
- package/test/eval.test.mjs +117 -1
- package/test/harness.mjs +4 -1
- package/test/host.test.mjs +63 -3
- package/test/i18n.test.mjs +188 -5
- package/test/path.test.mjs +97 -5
- package/test/tool.test.mjs +23 -15
package/test/client.test.mjs
CHANGED
|
@@ -737,7 +737,7 @@ test('媒体:类型偏好默认 doc,合法值保留,非法值回落', () =
|
|
|
737
737
|
assert.equal(readKindPref(), 'doc')
|
|
738
738
|
})
|
|
739
739
|
|
|
740
|
-
test('
|
|
740
|
+
test('媒体:默认文档视图有四个类型按钮(文档/代码/媒体/全部),但不出现媒体网格,计数仍按文档', async () => {
|
|
741
741
|
installFetch(kindResponder({ doc: listPayload() }))
|
|
742
742
|
const { KnitBody } = loadClientModule().exports.__test
|
|
743
743
|
harness.reset()
|
|
@@ -747,8 +747,10 @@ test('媒体:默认文档视图有三个类型按钮,但不出现媒体网
|
|
|
747
747
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
748
748
|
|
|
749
749
|
const btns = byClass(nodes, 'knit-type-btn')
|
|
750
|
-
|
|
751
|
-
|
|
750
|
+
// v0.19:一级分类从「文档 / 媒体 / 全部」扩成「文档 / 代码 / 媒体 / 全部」。
|
|
751
|
+
// 刻意**只加一档** —— 不再给代码做第二层语言分类 UI(需求 §46)。
|
|
752
|
+
assert.equal(btns.length, 4)
|
|
753
|
+
assert.deepEqual(btns.map(textOf), ['文档', '代码', '媒体', '全部'])
|
|
752
754
|
assert.equal(btns.find((b) => textOf(b) === '文档').props['aria-selected'], true)
|
|
753
755
|
assert.equal(byClass(nodes, 'knit-media-grid').length, 0)
|
|
754
756
|
assert.equal(byClass(nodes, 'knit-doc').length, 2)
|
|
@@ -840,7 +842,7 @@ test('媒体:「全部」分上下两区,文档上限 4、媒体一格不隐
|
|
|
840
842
|
assert.equal(byExactClass(nodes, 'knit-section').length, 2, '文档区 + 媒体区,上下两区')
|
|
841
843
|
assert.deepEqual(
|
|
842
844
|
byExactClass(nodes, 'knit-section-title').map(textOf),
|
|
843
|
-
['文档', '
|
|
845
|
+
['文档', '媒体'],
|
|
844
846
|
)
|
|
845
847
|
assert.equal(byToken(nodes, 'knit-doc').length, 4, '文档区最多 4 条')
|
|
846
848
|
// 载荷里 5 图 + 4 视频 = 9 个媒体:一格都不隐藏,纵向也**不封顶**(有多少行铺多少行)
|
|
@@ -957,7 +959,7 @@ test('媒体:只有媒体时「全部」的媒体区不截断、也不给「
|
|
|
957
959
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
958
960
|
|
|
959
961
|
assert.equal(byExactClass(nodes, 'knit-section').length, 1, '只有媒体区')
|
|
960
|
-
assert.deepEqual(byExactClass(nodes, 'knit-section-title').map(textOf), ['
|
|
962
|
+
assert.deepEqual(byExactClass(nodes, 'knit-section-title').map(textOf), ['媒体'])
|
|
961
963
|
assert.equal(byExactClass(nodes, 'knit-section-more').length, 0, '媒体区不截断,没有「查看全部」')
|
|
962
964
|
assert.equal(byToken(nodes, 'knit-media-card').length, 9)
|
|
963
965
|
})
|
|
@@ -1270,7 +1272,7 @@ test('样式:文档列表没有网格 —— 多列那套已整体删除,容
|
|
|
1270
1272
|
assert.match(css, /\.knit-title\{flex:1 1 auto;min-width:0;font-weight:600;font-size:14px;line-height:1\.4;/)
|
|
1271
1273
|
// 2026-10-01:`.knit-gapmark`(没号时的中性占位标记)与序号**共用同一条选择器**,
|
|
1272
1274
|
// 所以「序号的行高必须等于标题行高」这条纪律自动覆盖它。
|
|
1273
|
-
assert.match(css, /\.knit-num,\.knit-gapmark\{grid-column:1;font-size:
|
|
1275
|
+
assert.match(css, /\.knit-num,\.knit-gapmark\{grid-column:1;font-size:11px;line-height:19\.6px;/)
|
|
1274
1276
|
|
|
1275
1277
|
// ⚠️ 行的**静止态没有底色**(2026-09-29 用户看了暗色主题之后要求:
|
|
1276
1278
|
// 「深色模式下,文档列表没有选中,鼠标没有悬停,不需要有背景。或者是说,跟深色模式的最底下的
|
|
@@ -1436,7 +1438,58 @@ test('样式:预览面板底色恒为纯阅读底色,不靠底色分层;
|
|
|
1436
1438
|
assert.ok(!css.includes('transition:background-color'))
|
|
1437
1439
|
})
|
|
1438
1440
|
|
|
1439
|
-
test('
|
|
1441
|
+
test('全屏:隐藏名单必须覆盖「列表之外还在正常流里」的每一块 —— 漏一块预览就被挤一次', async () => {
|
|
1442
|
+
const { readFileSync } = await import('node:fs')
|
|
1443
|
+
const { fileURLToPath } = await import('node:url')
|
|
1444
|
+
const source = readFileSync(fileURLToPath(new URL('../src/client/client.js', import.meta.url)), 'utf8')
|
|
1445
|
+
const start = source.indexOf('const CSS = `') + 'const CSS = `'.length
|
|
1446
|
+
const css = source.slice(start, source.indexOf('`', start)).replace(/\/\*[\s\S]*?\*\//g, '')
|
|
1447
|
+
|
|
1448
|
+
// 全屏的隐藏名单。它可以写成一条逗号列表,也可以按块拆成多条规则 ——
|
|
1449
|
+
// 这里把**所有**带 display:none 的 `.knit-root.fullscreen <sel>` 收进一个集合。
|
|
1450
|
+
const hidden = new Set()
|
|
1451
|
+
for (const rule of css.matchAll(/([^{}]*)\{([^{}]*)\}/g)) {
|
|
1452
|
+
if (!/display\s*:\s*none/.test(rule[2])) continue
|
|
1453
|
+
for (const sel of rule[1].matchAll(/\.knit-root\.fullscreen\s+(\.[\w-]+)/g)) hidden.add(sel[1])
|
|
1454
|
+
}
|
|
1455
|
+
assert.ok(hidden.size > 0, '全屏必须有一条 display:none 的隐藏名单')
|
|
1456
|
+
|
|
1457
|
+
// 这些都在**正常流**里(不是浮层),全屏时必须一起让位,否则预览被它们挤在下面。
|
|
1458
|
+
// ⚠️ 2026-10-07 用户反馈:开了「使用情况」再点全屏,Lens 仍占掉面板上方约三分之一,
|
|
1459
|
+
// 看起来就像「全屏没生效」—— `.knit-usage` 是 flex:none 的自然高度,漏了就抢不回来。
|
|
1460
|
+
for (const section of ['.knit-head', '.knit-bar', '.knit-types', '.knit-usage', '.knit-list']) {
|
|
1461
|
+
assert.ok(hidden.has(section), `全屏必须藏掉 ${section}(它是列表上方的正常流块,不藏就挤压预览)`)
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// 再把名单跟**真的渲染出来的**全屏树对一次账:改名 / 删块时这条要响。
|
|
1465
|
+
installFetch(kindResponder({ doc: listPayload() }))
|
|
1466
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
1467
|
+
harness.reset()
|
|
1468
|
+
// usageOn 在 hook 顺序里的下标是 **15**(useRef 也占槽位,与真实 React 一致):
|
|
1469
|
+
// notice/sort/kind/state/preview/tick/cursor/query/ratio/fullscreen = 0..9
|
|
1470
|
+
// listRef/rootRef = 10,11 → listWidth=12, links=13, linksExpandedTick=14, usageOn=15
|
|
1471
|
+
const seeded = ['', 'time']
|
|
1472
|
+
seeded[15] = true
|
|
1473
|
+
harness.seed(seeded)
|
|
1474
|
+
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1475
|
+
await harness.flush()
|
|
1476
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1477
|
+
byClass(nodes, 'knit-doc')[0].props.onClick()
|
|
1478
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1479
|
+
byToken(nodes, 'knit-btn').find((b) => textOf(b) === '全屏').props.onClick()
|
|
1480
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1481
|
+
|
|
1482
|
+
const root = nodes.find((n) => String(n.props.className || '').startsWith('knit-root'))
|
|
1483
|
+
assert.match(String(root.props.className), /fullscreen/, '点过全屏后根节点要带 fullscreen')
|
|
1484
|
+
const present = new Set(nodes.map((n) => '.' + String(n.props.className || '').split(/\s+/)[0]))
|
|
1485
|
+
for (const section of ['.knit-usage', '.knit-list', '.knit-preview']) {
|
|
1486
|
+
assert.ok(present.has(section), `${section} 应当出现在全屏树里(靠 CSS 藏,不是不渲染)`)
|
|
1487
|
+
}
|
|
1488
|
+
// 名单里只允许出现「顶栏 / 观察层 / 列表」这三类,别去藏预览本身
|
|
1489
|
+
assert.ok(!hidden.has('.knit-preview'), '全屏当然不能把预览自己藏掉')
|
|
1490
|
+
})
|
|
1491
|
+
|
|
1492
|
+
test('媒体:点类型按钮切到「媒体」会带 kind=media 重拉并记住偏好', async () => {
|
|
1440
1493
|
const { calls } = installFetch(kindResponder({ doc: listPayload(), media: mediaPayload() }))
|
|
1441
1494
|
const { KnitBody } = loadClientModule().exports.__test
|
|
1442
1495
|
harness.reset()
|
|
@@ -1445,7 +1498,7 @@ test('媒体:点类型按钮切到「图片与视频」会带 kind=media 重
|
|
|
1445
1498
|
await harness.flush()
|
|
1446
1499
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1447
1500
|
|
|
1448
|
-
byClass(nodes, 'knit-type-btn').find((b) => textOf(b) === '
|
|
1501
|
+
byClass(nodes, 'knit-type-btn').find((b) => textOf(b) === '媒体').props.onClick()
|
|
1449
1502
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1450
1503
|
await harness.flush()
|
|
1451
1504
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
@@ -1991,8 +2044,8 @@ test('样式:组与组之间只靠 16px 空间(不再画横线),序号
|
|
|
1991
2044
|
// 字号:标题 14px / 行高 1.4 = 19.6px;序号的 line-height 必须与它同步,
|
|
1992
2045
|
// 这是「序号与标题第一行垂直居中」的唯一手段(改一处必须改两处)
|
|
1993
2046
|
assert.match(source, /\.knit-title\{flex:1 1 auto;min-width:0;font-weight:600;font-size:14px;line-height:1\.4;/)
|
|
1994
|
-
assert.match(source, /\.knit-num,\.knit-gapmark\{grid-column:1;font-size:
|
|
1995
|
-
assert.match(source, /\.knit-sum\{font-size:12px;line-height:
|
|
2047
|
+
assert.match(source, /\.knit-num,\.knit-gapmark\{grid-column:1;font-size:11px;line-height:19\.6px;/)
|
|
2048
|
+
assert.match(source, /\.knit-sum\{font-size:12px;line-height:18px;/)
|
|
1996
2049
|
})
|
|
1997
2050
|
|
|
1998
2051
|
/* ── v0.15「使用情况」 ───────────────────────────────────────────────
|
|
@@ -2046,7 +2099,7 @@ test('使用情况:默认关 —— 请求里没有 usage=1,DOM 里也没有
|
|
|
2046
2099
|
assert.equal(byExactClass(nodes, 'knit-usage').length, 0, '默认关:不显示那一行')
|
|
2047
2100
|
})
|
|
2048
2101
|
|
|
2049
|
-
test('使用情况:打开后请求带 usage=1
|
|
2102
|
+
test('v0.18 使用情况:打开后请求带 usage=1,Lens 只报事实(没有分数 / 百分比)', async () => {
|
|
2050
2103
|
const { calls } = installFetch(() => usagePayload())
|
|
2051
2104
|
const { KnitBody } = loadClientModule().exports.__test
|
|
2052
2105
|
harness.reset()
|
|
@@ -2069,16 +2122,21 @@ test('使用情况:打开后请求带 usage=1,那一行只报事实(没有
|
|
|
2069
2122
|
|
|
2070
2123
|
assert.ok(calls.some((url) => url.includes('usage=1')), '打开后必须带 usage=1')
|
|
2071
2124
|
const line = byExactClass(nodes, 'knit-usage')[0]
|
|
2072
|
-
assert.ok(line, '
|
|
2125
|
+
assert.ok(line, '打开后必须出现 Usage Lens')
|
|
2073
2126
|
const text = textOf(line)
|
|
2074
|
-
assert.match(text,
|
|
2075
|
-
assert.match(text,
|
|
2076
|
-
|
|
2077
|
-
assert.match(text,
|
|
2078
|
-
assert.match(text,
|
|
2079
|
-
assert.match(text,
|
|
2127
|
+
assert.match(text, /使用情况/, 'Lens 标题')
|
|
2128
|
+
assert.match(text, /Epoch 4/, '当前上下文的编号要如实说出来')
|
|
2129
|
+
// 摘要行只留三件事实:读了几次 / 几篇包外 / 换过几次
|
|
2130
|
+
assert.match(text, /7 次读取/)
|
|
2131
|
+
assert.match(text, /2 篇包外/)
|
|
2132
|
+
assert.match(text, /上下文变化 2 次/)
|
|
2080
2133
|
assert.ok(!text.includes('%'), '不许有百分比')
|
|
2081
2134
|
assert.ok(!/评分|置信|分数/.test(text), '不许有评分 / 置信度这类词')
|
|
2135
|
+
// Coverage:三层各自的「已读 ÷ 本层总数」;v0.15 载荷没有 lifecycle ⇒ 全是未读
|
|
2136
|
+
assert.deepEqual(byExactClass(nodes, 'knit-cov-num').map(textOf), ['0 / 1', '0 / 2', '0 / 1'])
|
|
2137
|
+
const dots = dotsOf(nodes)
|
|
2138
|
+
assert.equal(dots.length, 4, '每一篇正文都要有一个状态点')
|
|
2139
|
+
assert.ok(dots.every((dot) => !String(dot.props.className).includes('on')), '没有记录就是未读')
|
|
2082
2140
|
})
|
|
2083
2141
|
|
|
2084
2142
|
test('样式:使用情况那一行是弱化文字 —— 没有卡片 / 进度条 / 品牌色', async () => {
|
|
@@ -2088,7 +2146,8 @@ test('样式:使用情况那一行是弱化文字 —— 没有卡片 / 进度
|
|
|
2088
2146
|
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
2089
2147
|
'utf8',
|
|
2090
2148
|
)
|
|
2091
|
-
|
|
2149
|
+
// v0.18 UI 迭代(md §四十七 的尺度表):这一块从 10.5px 提到 **12px**。
|
|
2150
|
+
assert.match(source, /\.knit-usage\{[^}]*font-size:12px/)
|
|
2092
2151
|
assert.ok(!/\.knit-usage\{[^}]*background/.test(source), '不画卡片底色')
|
|
2093
2152
|
assert.ok(!/\.knit-usage\{[^}]*knit-accent/.test(source), '不用品牌色')
|
|
2094
2153
|
assert.ok(!/\.knit-usage\{[^}]*width:\s*\d/.test(source), '不是进度条')
|
|
@@ -2234,7 +2293,9 @@ function lifecyclePayload(overrides = {}) {
|
|
|
2234
2293
|
rank: 2,
|
|
2235
2294
|
inside: true,
|
|
2236
2295
|
},
|
|
2237
|
-
|
|
2296
|
+
// 宿主回的是**阅读顺序**(seq = 首次读);面板要按「读得最多」重排 ——
|
|
2297
|
+
// 另一个用例会刻意把这里的顺序反过来,验证排序真的发生在客户端。
|
|
2298
|
+
outsideDocs: overrides.outsideDocs || [
|
|
2238
2299
|
{ rel: 'docs/old-plan.md', count: 3, lastReadAt: 1, seq: 10 },
|
|
2239
2300
|
{ rel: 'docs/test-case.md', count: 1, lastReadAt: 2, seq: 20 },
|
|
2240
2301
|
],
|
|
@@ -2250,8 +2311,28 @@ function lifecyclePayload(overrides = {}) {
|
|
|
2250
2311
|
})
|
|
2251
2312
|
}
|
|
2252
2313
|
|
|
2253
|
-
/** 分层视图里五行文档各自该显示的状态文字(顺序 = 屏幕顺序)。
|
|
2254
|
-
|
|
2314
|
+
/** 分层视图里五行文档各自该显示的状态文字(顺序 = 屏幕顺序)。
|
|
2315
|
+
* v0.18 起「已读」只说次数:圈点已经把「读过」说完了,文字里再写一遍是重复。 */
|
|
2316
|
+
const LIFE_EXPECTED = ['×3', '修改后已重新读取', '读后已更新', '未读', '未读']
|
|
2317
|
+
|
|
2318
|
+
/** 同一屏里五行各自该显示的**状态点**(v0.18 UI 迭代起是 CSS 圆点,不是字符)。
|
|
2319
|
+
* `data-mark` 四态 = read / reread / updated / unread;它与上面的文字**同时**存在:
|
|
2320
|
+
* 只给点读不出「读了几次」,只给文字看不出「哪几篇同档」。 */
|
|
2321
|
+
const GLYPH_EXPECTED = ['read', 'reread', 'updated', 'unread', 'unread']
|
|
2322
|
+
|
|
2323
|
+
/** 预览面板里正在显示哪一篇(只看文件名那一格)。 */
|
|
2324
|
+
function openNameOf(nodes) {
|
|
2325
|
+
const name = byExactClass(nodes, 'knit-preview-name')[0]
|
|
2326
|
+
return name ? textOf(name) : ''
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
/** Coverage 的状态点。className 可能是 `knit-cov-dot` 也可能是 `knit-cov-dot on`。
|
|
2330
|
+
* ⚠️ 不能用 `byClass`:它是**子串**匹配,会把容器 `.knit-cov-dots` 一起算进来。 */
|
|
2331
|
+
function dotsOf(nodes) {
|
|
2332
|
+
return nodes.filter((node) => node && node.props
|
|
2333
|
+
&& String(node.props.className || '').split(' ').includes('knit-cov-dot'))
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2255
2336
|
|
|
2256
2337
|
/**
|
|
2257
2338
|
* 挂上面板并**打开「使用情况」**(数据到位后再点,与真实用法一致)。
|
|
@@ -2296,21 +2377,43 @@ test('v0.17 生命周期:使用情况关着 —— 一个状态节点都不出
|
|
|
2296
2377
|
assert.ok(!/未读|已读|读后已更新|修改后已重新读取/.test(rowText), '关着时行里只有标题与时间')
|
|
2297
2378
|
})
|
|
2298
2379
|
|
|
2299
|
-
test('v0.
|
|
2380
|
+
test('v0.18 生命周期:四种状态都落在文档行里,且只是一枚 glyph + 一段极短文字', async () => {
|
|
2300
2381
|
const { nodes } = await mountUsage(lifecyclePayload())
|
|
2301
2382
|
|
|
2302
2383
|
const lives = byExactClass(nodes, 'knit-life')
|
|
2303
2384
|
assert.deepEqual(lives.map(textOf), LIFE_EXPECTED, '四档事实状态按屏幕顺序逐行显示')
|
|
2304
|
-
//
|
|
2385
|
+
// 状态文字是**弱化辅助信息**:没有图标、没有 aria、没有颜色、没有百分比
|
|
2305
2386
|
for (const node of lives) {
|
|
2306
|
-
assert.deepEqual(Object.keys(node.props).sort(), ['className'], '
|
|
2387
|
+
assert.deepEqual(Object.keys(node.props).sort(), ['className'], '状态文字只是一个 span')
|
|
2388
|
+
}
|
|
2389
|
+
// v0.18:状态**点**与状态**文字**同时存在(规格 §10 / §13)
|
|
2390
|
+
const glyphs = byExactClass(nodes, 'knit-glyph')
|
|
2391
|
+
// v0.18 UI 迭代:点从 `○ ● △ ↻` 字符改成 **CSS 圆点**(6px,与 Coverage 同一套语言),
|
|
2392
|
+
// 于是「哪一档」不再看字符、看 `data-mark`;只有「修改后已重新读取」仍留一个 ↻ 记号。
|
|
2393
|
+
const marks = byExactClass(nodes, 'knit-glyph-mark')
|
|
2394
|
+
assert.deepEqual(marks.map((node) => node.props['data-mark']), GLYPH_EXPECTED,
|
|
2395
|
+
'每一行正好一枚状态点,四档各归其位')
|
|
2396
|
+
assert.deepEqual(marks.map((node) => node.props['aria-hidden']), ['true', 'true', 'true', 'true', 'true'],
|
|
2397
|
+
'状态点本身是装饰 —— 「哪一档」由 aria-label 说出来,不让读屏念两遍')
|
|
2398
|
+
assert.deepEqual(glyphs.map(textOf), ['', '↻', '', '', ''],
|
|
2399
|
+
'CSS 圆之后只有 reread 还带字符')
|
|
2400
|
+
for (const node of glyphs) {
|
|
2401
|
+
assert.equal(node.props.type, 'button', '状态点可点 → 必须是真 button')
|
|
2402
|
+
assert.ok(node.props['aria-label'], '状态点必须有 aria-label')
|
|
2403
|
+
assert.ok(node.props.title, '状态点必须有 tooltip')
|
|
2404
|
+
assert.equal(node.props.style, undefined, '状态点不带内联颜色')
|
|
2307
2405
|
}
|
|
2406
|
+
assert.deepEqual(glyphs.map((node) => node.props['aria-label']), [
|
|
2407
|
+
'已读 ×3', '修改后已重新读取', '读后已更新', '未读', '未读',
|
|
2408
|
+
], 'tooltip / aria-label 把这一档状态解释清楚')
|
|
2308
2409
|
const allText = textOf(byExactClass(nodes, 'knit-usage')[0])
|
|
2309
2410
|
assert.ok(!allText.includes('%'), '不许有百分比')
|
|
2310
2411
|
assert.ok(!/评分|置信|分数|质量|命中率|漏召回/.test(allText), '不许把事实写成评分')
|
|
2412
|
+
// 圈点那一格原本是 Primary 的黑点:统计开着时让给状态点,一行只有一个标记
|
|
2413
|
+
assert.equal(byExactClass(nodes, 'knit-dot').length, 0, 'usage 开着时不再画 Primary 黑点')
|
|
2311
2414
|
})
|
|
2312
2415
|
|
|
2313
|
-
test('v0.
|
|
2416
|
+
test('v0.18 生命周期:状态点在标题之前,行结构不变', async () => {
|
|
2314
2417
|
const { nodes } = await mountUsage(lifecyclePayload())
|
|
2315
2418
|
|
|
2316
2419
|
const rows = byExactClass(nodes, 'knit-row1')
|
|
@@ -2319,11 +2422,13 @@ test('v0.17 生命周期:状态插在标题与时间之间,行结构不变',
|
|
|
2319
2422
|
assert.equal(kidsOf(row, 'knit-title').length, 1, '一行只有一个标题')
|
|
2320
2423
|
assert.equal(kidsOf(row, 'knit-time').length, 1, '一行只有一个时间')
|
|
2321
2424
|
assert.equal(kidsOf(row, 'knit-life').length, 1, '一行只有一个状态文字')
|
|
2425
|
+
assert.equal(kidsOf(row, 'knit-glyph').length, 1, '一行只有一个状态点')
|
|
2322
2426
|
const order = row.children.map((n) => String(n.props.className || ''))
|
|
2323
2427
|
assert.ok(
|
|
2324
|
-
order.indexOf('knit-
|
|
2428
|
+
order.indexOf('knit-glyph') < order.indexOf('knit-title')
|
|
2429
|
+
&& order.indexOf('knit-title') < order.indexOf('knit-life')
|
|
2325
2430
|
&& order.indexOf('knit-life') < order.indexOf('knit-time'),
|
|
2326
|
-
|
|
2431
|
+
`状态点 / 标题 / 状态 / 时间的顺序不能乱:${order.join(' / ')}`,
|
|
2327
2432
|
)
|
|
2328
2433
|
}
|
|
2329
2434
|
// 每行的前两个直接子节点仍然是「号 / 占位符 + 正文」(v0.15 起就钉住的形状)
|
|
@@ -2337,49 +2442,99 @@ test('v0.17 生命周期:状态插在标题与时间之间,行结构不变',
|
|
|
2337
2442
|
}
|
|
2338
2443
|
})
|
|
2339
2444
|
|
|
2340
|
-
test('v0.
|
|
2341
|
-
const { nodes } = await mountUsage(lifecyclePayload())
|
|
2445
|
+
test('v0.18 最近读取:一行可点的事实(谁 · 多久前 ›),不说「正在阅读」', async () => {
|
|
2446
|
+
const { nodes, render, calls } = await mountUsage(lifecyclePayload())
|
|
2342
2447
|
|
|
2343
|
-
const
|
|
2344
|
-
|
|
2345
|
-
|
|
2448
|
+
const rows = byExactClass(nodes, 'knit-read-row')
|
|
2449
|
+
assert.equal(rows.length, 1, '最近读取是**可点的一行**')
|
|
2450
|
+
const text = textOf(rows[0])
|
|
2451
|
+
assert.match(text, /docs\/eval\.md/, '最近一次**成功** read 的文件要如实说出来')
|
|
2452
|
+
assert.match(text, /12分钟前/, '多久前也要如实说')
|
|
2453
|
+
assert.equal(rows[0].props.type, 'button', '整行可点 → 真 button')
|
|
2346
2454
|
assert.ok(!/正在阅读|当前正在|正在读/.test(text), 'Knit 证明不了「此刻正在读」')
|
|
2347
|
-
//
|
|
2348
|
-
|
|
2349
|
-
assert.match(
|
|
2455
|
+
// 与摘要行并存,没有多出统计指标
|
|
2456
|
+
const allText = textOf(byExactClass(nodes, 'knit-usage')[0])
|
|
2457
|
+
assert.match(allText, /Epoch 4/)
|
|
2458
|
+
assert.match(allText, /7 次读取/)
|
|
2459
|
+
// 点它 = 直接打开那一篇:**点的那一下不敲宿主**(走已有的 requestPreview,
|
|
2460
|
+
// 而不是「先拉一次列表再打开」)。之后出现的请求是渲染 effect 自己的事。
|
|
2461
|
+
const before = calls.length
|
|
2462
|
+
rows[0].props.onClick()
|
|
2463
|
+
assert.equal(calls.length, before, '点它不直接请求列表')
|
|
2464
|
+
await harness.flush()
|
|
2465
|
+
const opened = render()
|
|
2466
|
+
assert.equal(openNameOf(opened), 'eval.md', '点最近读取就打开那一篇')
|
|
2350
2467
|
})
|
|
2351
2468
|
|
|
2352
|
-
test('v0.
|
|
2469
|
+
test('v0.18 上下文外读取:默认折叠,展开才逐篇列出(按读得最多的排)', async () => {
|
|
2353
2470
|
const { nodes, render } = await mountUsage(lifecyclePayload())
|
|
2354
2471
|
|
|
2355
2472
|
const buttons = byExactClass(nodes, 'knit-more-btn')
|
|
2356
|
-
const gapBtn = buttons.find((node) => textOf(node)
|
|
2473
|
+
const gapBtn = buttons.find((node) => textOf(node).includes('上下文外读取'))
|
|
2357
2474
|
assert.ok(gapBtn, '包外读取要有一行可展开的统计')
|
|
2475
|
+
// v0.18 UI 迭代(md §三十四):菜单行是「label ── 数量 ›」三段,
|
|
2476
|
+
// 数量单独成一个 `.knit-more-meta`(右对齐),不再挤在标题字符串里。
|
|
2477
|
+
assert.equal(textOf(kidsOf(gapBtn, 'knit-more-label')[0]), '上下文外读取')
|
|
2478
|
+
assert.equal(textOf(kidsOf(gapBtn, 'knit-more-meta')[0]), '2', '数量是事实,单独一列')
|
|
2358
2479
|
assert.equal(gapBtn.props['aria-expanded'], 'false', '默认折叠')
|
|
2359
2480
|
assert.equal(byExactClass(nodes, 'knit-gap-list').length, 0, '折叠时不渲染明细节点')
|
|
2360
|
-
assert.equal(byExactClass(nodes, 'knit-
|
|
2481
|
+
assert.equal(byExactClass(nodes, 'knit-out-row').length, 0, '折叠时一行明细都不许有')
|
|
2361
2482
|
|
|
2362
2483
|
gapBtn.props.onClick()
|
|
2363
2484
|
const open = render()
|
|
2364
2485
|
const list = byExactClass(open, 'knit-gap-list')
|
|
2365
2486
|
assert.equal(list.length, 1, '展开后出现明细区')
|
|
2366
|
-
const rows =
|
|
2487
|
+
const rows = byExactClass(open, 'knit-out-row')
|
|
2367
2488
|
assert.equal(rows.length, 2, '两篇包外文档各一行')
|
|
2489
|
+
assert.deepEqual(rows.map((row) => textOf(kidsOf(row, 'knit-out-rel')[0])),
|
|
2490
|
+
['docs/old-plan.md', 'docs/test-case.md'], '读得多的(×3)排前面')
|
|
2491
|
+
assert.deepEqual(rows.map((row) => textOf(kidsOf(row, 'knit-out-count')[0])), ['×3', '×1'])
|
|
2492
|
+
// v0.18 UI 迭代(md §三十六):行首补两位序号(位置,不是评分)。
|
|
2493
|
+
assert.deepEqual(rows.map((row) => textOf(kidsOf(row, 'knit-out-num')[0])), ['01', '02'],
|
|
2494
|
+
'行首序号从左到右两位补齐')
|
|
2495
|
+
// 每一行都带生命周期,而且复用**同一份** v0.17 数据(不是第二套)。
|
|
2496
|
+
// ⚠️ 状态用**词**(已读),不用短次数 —— 左边 `×N` 已经说了一遍,再来一遍就渲染成
|
|
2497
|
+
// `docs/old-plan.md ×3 ×3`(2026-10-05 用真实会话载荷渲染时抓到)。
|
|
2498
|
+
assert.deepEqual(rows.map((row) => textOf(kidsOf(row, 'knit-life')[0])), ['已读', '已读'])
|
|
2499
|
+
for (const row of rows) {
|
|
2500
|
+
const shown = textOf(row).match(/×\d+/g) || []
|
|
2501
|
+
assert.equal(new Set(shown).size, shown.length, `次数在同一行里不许说两遍:${textOf(row)}`)
|
|
2502
|
+
}
|
|
2503
|
+
for (const row of rows) assert.equal(row.props.type, 'button', '每一行都是可点对象 → 真 button')
|
|
2504
|
+
// 只陈述事实:不评价 Knit 推荐得对不对
|
|
2505
|
+
const openText = textOf(rows[0]) + textOf(byExactClass(open, 'knit-usage')[0])
|
|
2506
|
+
assert.ok(!/漏掉|推荐错|绕过|不认可|低质量|命中率/.test(openText), '包外读取不是「Knit 漏了」')
|
|
2507
|
+
})
|
|
2508
|
+
|
|
2509
|
+
test('v0.18 上下文外读取:排序在客户端(count DESC),不是宿主给的阅读顺序', async () => {
|
|
2510
|
+
// 宿主 `outsideDocsOf` 回的是**首次读**的顺序(seq);面板要回答「哪几篇被反复读」
|
|
2511
|
+
const payload = lifecyclePayload({
|
|
2512
|
+
outsideDocs: [
|
|
2513
|
+
{ rel: 'docs/test-case.md', count: 1, lastReadAt: 2, seq: 20 },
|
|
2514
|
+
{ rel: 'docs/old-plan.md', count: 3, lastReadAt: 1, seq: 10 },
|
|
2515
|
+
],
|
|
2516
|
+
})
|
|
2517
|
+
const { nodes, render } = await mountUsage(payload)
|
|
2518
|
+
byExactClass(nodes, 'knit-more-btn')
|
|
2519
|
+
.find((node) => textOf(node).includes('上下文外读取')).props.onClick()
|
|
2520
|
+
const open = render()
|
|
2368
2521
|
assert.deepEqual(
|
|
2369
|
-
|
|
2522
|
+
byExactClass(open, 'knit-out-row').map((row) => textOf(kidsOf(row, 'knit-out-rel')[0])),
|
|
2370
2523
|
['docs/old-plan.md', 'docs/test-case.md'],
|
|
2524
|
+
'读得多的排前面 —— 即使宿主把它放在后面',
|
|
2371
2525
|
)
|
|
2372
|
-
assert.deepEqual(rows.map((row) => textOf(kidsOf(row, 'knit-life')[0])), ['已读 ×3', '已读'])
|
|
2373
|
-
// 只陈述事实:不评价 Knit 推荐得对不对
|
|
2374
|
-
const openText = textOf(kidsOf(list[0], 'knit-gap-row')[0]) + textOf(byExactClass(open, 'knit-usage')[0])
|
|
2375
|
-
assert.ok(!/漏掉|推荐错|绕过|不认可|低质量|命中率/.test(openText), '包外读取不是「Knit 漏了」')
|
|
2376
2526
|
})
|
|
2377
2527
|
|
|
2378
|
-
test('v0.
|
|
2528
|
+
test('v0.18 Context Delta:只展示最近一次,符号只有 + / - / ↔', async () => {
|
|
2379
2529
|
const { nodes, render } = await mountUsage(lifecyclePayload())
|
|
2380
2530
|
|
|
2381
|
-
const deltaBtn = byExactClass(nodes, 'knit-more-btn')
|
|
2531
|
+
const deltaBtn = byExactClass(nodes, 'knit-more-btn')
|
|
2532
|
+
.find((node) => textOf(node).includes('上下文变化'))
|
|
2382
2533
|
assert.ok(deltaBtn, '有变化就要有一行摘要')
|
|
2534
|
+
// v0.18 UI 迭代(md §三十八):菜单行固定写「上下文变化 最近一次 ›」——
|
|
2535
|
+
// **按钮上不再写条数**(条数由展开后的行数与「还有 N 条」承担,见下面那条账目守卫)。
|
|
2536
|
+
assert.equal(textOf(kidsOf(deltaBtn, 'knit-more-label')[0]), '上下文变化')
|
|
2537
|
+
assert.equal(textOf(kidsOf(deltaBtn, 'knit-more-meta')[0]), '最近一次')
|
|
2383
2538
|
assert.equal(deltaBtn.props['aria-expanded'], 'false', '默认折叠')
|
|
2384
2539
|
const digest = byExactClass(nodes, 'knit-delta-row')
|
|
2385
2540
|
assert.deepEqual(digest.map(textOf), [
|
|
@@ -2394,6 +2549,12 @@ test('v0.17 Context Delta:只展示最近一次,符号只有 + / - / ↔', a
|
|
|
2394
2549
|
deltaBtn.props.onClick()
|
|
2395
2550
|
const open = render()
|
|
2396
2551
|
assert.deepEqual(byExactClass(open, 'knit-delta-head').map(textOf), ['进入', '离开', '换层'])
|
|
2552
|
+
// 展开后折叠摘要必须**让位**给分组:三行摘要 + 「还有 N 条」再叠上明细 = 同一件事讲两遍
|
|
2553
|
+
// (2026-10-05 用真实会话载荷渲染时抓到的重复)。
|
|
2554
|
+
const openRows = byExactClass(open, 'knit-delta-row').map(textOf)
|
|
2555
|
+
assert.deepEqual(openRows, ['+ docs/algo.md', '- README.md', '↔ docs/eval.md · 辅助 → 相关'])
|
|
2556
|
+
assert.equal(new Set(openRows).size, openRows.length, '展开后同一行不许出现两次')
|
|
2557
|
+
assert.ok(!openRows.some((row) => /还有/.test(row)), '展开后不再有折叠尾巴')
|
|
2397
2558
|
const openText = textOf(byExactClass(open, 'knit-usage')[0])
|
|
2398
2559
|
assert.ok(!/\d{2}:\d{2}/.test(openText), '不许出现时间线')
|
|
2399
2560
|
})
|
|
@@ -2414,12 +2575,74 @@ test('v0.17 Context Delta:超过三条折叠成「还有 N 条」,任务变
|
|
|
2414
2575
|
assert.deepEqual(byExactClass(folded.nodes, 'knit-delta-row').map(textOf), [
|
|
2415
2576
|
'+ a.md', '+ b.md', '+ c.md', '还有 1 条',
|
|
2416
2577
|
])
|
|
2578
|
+
// 展开 = 折叠摘要让位给分组明细(否则第 4 条既在「还有 1 条」里、又单独列一遍)
|
|
2579
|
+
byExactClass(folded.nodes, 'knit-more-btn')
|
|
2580
|
+
.find((node) => textOf(node).includes('上下文变化')).props.onClick()
|
|
2581
|
+
const opened = folded.render()
|
|
2582
|
+
assert.deepEqual(byExactClass(opened, 'knit-delta-row').map(textOf),
|
|
2583
|
+
['+ a.md', '+ b.md', '+ c.md', '+ d.md'], '展开后四条各出现一次,没有折叠尾巴')
|
|
2417
2584
|
|
|
2418
2585
|
const task = await mountUsage(lifecyclePayload({
|
|
2419
2586
|
delta: { appeared: [{ rel: 'docs/algo.md', tier: 'primary', rank: 1 }], disappeared: [], moved: [], taskChanged: true },
|
|
2420
2587
|
}))
|
|
2421
2588
|
const text = byExactClass(task.nodes, 'knit-delta-row').map(textOf)
|
|
2422
2589
|
assert.deepEqual(text, ['+ docs/algo.md', '任务上下文已更新'], '任务变化也是一句事实,不是时间线')
|
|
2590
|
+
// ⚠️ 展开后这一句**不许消失**:折叠摘要算上了它,只列 1 行就成了「说 2 条、列 1 行」
|
|
2591
|
+
// 的自相矛盾(2026-10-05 用真实载荷渲染时抓到)。
|
|
2592
|
+
const taskBtn = byExactClass(task.nodes, 'knit-more-btn')
|
|
2593
|
+
.find((node) => textOf(node).includes('上下文变化'))
|
|
2594
|
+
assert.equal(taskBtn.props['aria-expanded'], 'false', '默认折叠')
|
|
2595
|
+
taskBtn.props.onClick()
|
|
2596
|
+
assert.deepEqual(byExactClass(task.render(), 'knit-delta-row').map(textOf),
|
|
2597
|
+
['+ docs/algo.md', '任务上下文已更新'], '展开后任务变化仍在,还是只出现一次')
|
|
2598
|
+
})
|
|
2599
|
+
|
|
2600
|
+
test('v0.18 Context Delta:展开后的行 + 组内尾巴必须说清**全部**变化', async () => {
|
|
2601
|
+
// 通用账目关系(不是针对某个夹具的定点断言):展开后的明细必须把这次变化的**全部**条目
|
|
2602
|
+
// 说清楚 —— 列出的行(不含尾巴)+ 每条尾巴里的数字 = 变化总数。
|
|
2603
|
+
// ⚠️ 这正是一次真实载荷渲染抓到的 bug 的通用式:按钮说 N 条、展开后却少列一行
|
|
2604
|
+
// (`taskChanged` 那一句只出现在折叠摘要里,展开就没了)。
|
|
2605
|
+
// ⚠️ v0.18 UI 迭代后按钮上**不再写条数**(菜单行固定是「上下文变化 最近一次」),
|
|
2606
|
+
// 所以基准从**载荷自己**算出来,不再读按钮文字。
|
|
2607
|
+
// 组内上限 `MAX_DELTA_GROUP = 5` 让这条账目多了一个分支,所以这里刻意给 8 条换层。
|
|
2608
|
+
const moved = Array.from({ length: 8 }, (_, i) => ({
|
|
2609
|
+
rel: `docs/m${i + 1}.md`,
|
|
2610
|
+
from: { tier: 'related', rank: i + 2 },
|
|
2611
|
+
to: { tier: 'supporting', rank: i + 1 },
|
|
2612
|
+
}))
|
|
2613
|
+
const { nodes, render } = await mountUsage(lifecyclePayload({
|
|
2614
|
+
delta: {
|
|
2615
|
+
appeared: [
|
|
2616
|
+
{ rel: 'docs/algo.md', tier: 'primary', rank: 1 },
|
|
2617
|
+
{ rel: 'docs/new.md', tier: 'related', rank: 9 },
|
|
2618
|
+
],
|
|
2619
|
+
disappeared: [],
|
|
2620
|
+
moved,
|
|
2621
|
+
taskChanged: true,
|
|
2622
|
+
},
|
|
2623
|
+
}))
|
|
2624
|
+
const deltaBtn = byExactClass(nodes, 'knit-more-btn')
|
|
2625
|
+
.find((node) => textOf(node).includes('上下文变化'))
|
|
2626
|
+
assert.ok(!/\d/.test(textOf(deltaBtn)), '菜单行上不许再出现条数(数字)')
|
|
2627
|
+
// 2 篇进入 + 8 条换层 + 1 句任务变化 = 11
|
|
2628
|
+
const total = 2 + moved.length + 1
|
|
2629
|
+
|
|
2630
|
+
deltaBtn.props.onClick()
|
|
2631
|
+
const opened = render()
|
|
2632
|
+
const rows = byExactClass(opened, 'knit-delta-row').map(textOf)
|
|
2633
|
+
const tailOf = (row) => (row.match(/^还有 (\d+) 条$/) || [])[1]
|
|
2634
|
+
const tails = rows.map(tailOf).filter(Boolean).map(Number)
|
|
2635
|
+
const listed = rows.filter((row) => !tailOf(row))
|
|
2636
|
+
assert.deepEqual(byExactClass(opened, 'knit-delta-head').map(textOf), ['进入', '换层'],
|
|
2637
|
+
'这份夹具没有「离开」,所以不画空的「离开」标题')
|
|
2638
|
+
assert.deepEqual(tails, [3], '换层 8 条、组内只列 5 条 ⇒ 尾巴写「还有 3 条」')
|
|
2639
|
+
assert.ok(listed.some((row) => /任务上下文已更新/.test(row)),
|
|
2640
|
+
'任务变化没有分组标题可挂,但必须真的列出来')
|
|
2641
|
+
assert.equal(
|
|
2642
|
+
listed.length + tails.reduce((sum, n) => sum + n, 0),
|
|
2643
|
+
total,
|
|
2644
|
+
`列出的行 + 尾巴里的数字必须等于变化总数(实际列出 ${JSON.stringify(listed)})`,
|
|
2645
|
+
)
|
|
2423
2646
|
})
|
|
2424
2647
|
|
|
2425
2648
|
test('v0.17 样式:状态与折叠区只用语义 token —— 没有卡片 / 固定色 / 边框', async () => {
|
|
@@ -2465,24 +2688,354 @@ test('v0.17 生命周期:英文环境下状态与折叠文案都是英文', as
|
|
|
2465
2688
|
|
|
2466
2689
|
assert.deepEqual(
|
|
2467
2690
|
byExactClass(nodes, 'knit-life').map(textOf),
|
|
2468
|
-
['
|
|
2469
|
-
'
|
|
2691
|
+
['×3', 'Re-read after update', 'Updated after read', 'Unread', 'Unread'],
|
|
2692
|
+
'四档状态文字在英文下也是英文',
|
|
2470
2693
|
)
|
|
2471
|
-
assert.
|
|
2472
|
-
byExactClass(nodes, 'knit-
|
|
2473
|
-
'
|
|
2694
|
+
assert.deepEqual(
|
|
2695
|
+
byExactClass(nodes, 'knit-glyph').map((node) => node.props['aria-label']),
|
|
2696
|
+
['Read ×3', 'Re-read after update', 'Updated after read', 'Unread', 'Unread'],
|
|
2697
|
+
'状态点的 tooltip 也要翻译',
|
|
2474
2698
|
)
|
|
2475
|
-
|
|
2699
|
+
// v0.18 UI 迭代:菜单行是「label ── 数量 ›」三段,英文下 label 也必须是英文。
|
|
2700
|
+
const gapBtn = byExactClass(nodes, 'knit-more-btn')
|
|
2701
|
+
.find((node) => textOf(kidsOf(node, 'knit-more-label')[0]).includes('Reads outside context'))
|
|
2702
|
+
assert.ok(gapBtn, '包外明细的按钮文案也要翻译')
|
|
2703
|
+
assert.equal(textOf(kidsOf(gapBtn, 'knit-more-meta')[0]), '2', '数量与文案分开两段')
|
|
2704
|
+
const deltaBtn = byExactClass(nodes, 'knit-more-btn').find((node) => textOf(node).includes('Context changes'))
|
|
2476
2705
|
assert.ok(deltaBtn, '变化摘要的按钮文案也要翻译')
|
|
2477
2706
|
deltaBtn.props.onClick()
|
|
2478
2707
|
const open = render()
|
|
2479
2708
|
assert.deepEqual(byExactClass(open, 'knit-delta-head').map(textOf), ['Entered', 'Left', 'Moved tier'])
|
|
2480
2709
|
|
|
2481
2710
|
const allText = byExactClass(open, 'knit-usage').map(textOf).join(' ')
|
|
2482
|
-
assert.match(allText, /
|
|
2711
|
+
assert.match(allText, /docs\/eval\.md/)
|
|
2712
|
+
assert.match(allText, /12 min ago/)
|
|
2483
2713
|
assert.ok(!/[\u4e00-\u9fff]/.test(allText), '英文环境里一个汉字都不许有')
|
|
2484
2714
|
})
|
|
2485
2715
|
|
|
2716
|
+
/* ── v0.18:Context Usage Lens(2026-10-05 规格 §46–§49 的守卫)─────────
|
|
2717
|
+
这一节的判据来自规格本身:信息架构(§47)、动画(§48)、回归保护(§49)。
|
|
2718
|
+
⚠️ 全部只读现有事实:不新增采集、不新增持久化、不新增第二个滚动容器。 */
|
|
2719
|
+
|
|
2720
|
+
test('v0.18 纯函数:Coverage 派生、包外排序、Delta 分组', () => {
|
|
2721
|
+
const { coverageOf, groupOutsideDocs, groupDelta, lifeStatusOf, LIFE_GLYPH } =
|
|
2722
|
+
loadClientModule().exports.__test
|
|
2723
|
+
|
|
2724
|
+
// Coverage 的分母是**这一层真实有几篇**,不是 Context Pack 的 matched/total
|
|
2725
|
+
const cov = coverageOf(
|
|
2726
|
+
{ primary: [{ rel: 'a.md' }], supporting: ['b.md', 'c.md'], related: [] },
|
|
2727
|
+
{ 'a.md': { status: 'read', count: 3 } },
|
|
2728
|
+
)
|
|
2729
|
+
assert.deepEqual(cov.primary, { total: 1, read: 1, rels: [{ rel: 'a.md', read: true }] })
|
|
2730
|
+
assert.deepEqual(cov.supporting, {
|
|
2731
|
+
total: 2,
|
|
2732
|
+
read: 0,
|
|
2733
|
+
rels: [{ rel: 'b.md', read: false }, { rel: 'c.md', read: false }],
|
|
2734
|
+
})
|
|
2735
|
+
assert.deepEqual(cov.related, { total: 0, read: 0, rels: [] }, '没有那一层就是 0 / 0,不编')
|
|
2736
|
+
assert.equal(lifeStatusOf(null, 'a.md'), 'unread', '没有记录就是未读')
|
|
2737
|
+
assert.equal(lifeStatusOf({ 'a.md': { status: '天外飞仙' } }, 'a.md'), 'unread', '认不出的状态退回未读')
|
|
2738
|
+
assert.deepEqual(Object.keys(LIFE_GLYPH).sort(),
|
|
2739
|
+
['read', 'reread_after_update', 'unread', 'updated_after_read'])
|
|
2740
|
+
|
|
2741
|
+
// 包外:读得最多的在前;同计数按最后读的时间(载荷里没有 lastRead.seq)
|
|
2742
|
+
assert.deepEqual(groupOutsideDocs([
|
|
2743
|
+
{ rel: 'x.md', count: 1, lastReadAt: 100, seq: 1 },
|
|
2744
|
+
{ rel: 'y.md', count: 3, lastReadAt: 50, seq: 2 },
|
|
2745
|
+
{ rel: 'z.md', count: 1, lastReadAt: 200, seq: 3 },
|
|
2746
|
+
]).map((row) => row.rel), ['y.md', 'z.md', 'x.md'])
|
|
2747
|
+
assert.deepEqual(groupOutsideDocs(null), [], '没有数据就是空列表')
|
|
2748
|
+
|
|
2749
|
+
// Delta:只拆「进 / 出 / 换层」,两种载荷(字符串 / 对象)都认
|
|
2750
|
+
const grouped = groupDelta({ appeared: ['a.md'], disappeared: [{ rel: 'b.md' }], moved: [] })
|
|
2751
|
+
assert.deepEqual(grouped.enter, [{ rel: 'a.md' }])
|
|
2752
|
+
assert.deepEqual(grouped.leave, [{ rel: 'b.md' }])
|
|
2753
|
+
assert.deepEqual(grouped.move, [])
|
|
2754
|
+
assert.deepEqual(groupDelta(null), { enter: [], leave: [], move: [] })
|
|
2755
|
+
})
|
|
2756
|
+
|
|
2757
|
+
test('v0.18 Coverage:三层各自的「已读 ÷ 本层总数」,点它定位到那一层', async () => {
|
|
2758
|
+
const { nodes, render } = await mountUsage(lifecyclePayload())
|
|
2759
|
+
|
|
2760
|
+
const cols = byExactClass(nodes, 'knit-cov-col')
|
|
2761
|
+
assert.deepEqual(cols.map((node) => textOf(kidsOf(node, 'knit-cov-name')[0])), ['主要', '辅助', '相关'])
|
|
2762
|
+
// 文本与视觉**同时**存在:只给点读不出「读了几篇」;没有百分比、没有进度条
|
|
2763
|
+
assert.deepEqual(cols.map((node) => textOf(kidsOf(node, 'knit-cov-num')[0])), ['1 / 1', '2 / 2', '0 / 1'])
|
|
2764
|
+
// v0.18 UI 迭代(md §十五 / §十六):状态点改成**真 CSS 圆**(6px,与文档行同一套语言),
|
|
2765
|
+
// 于是断言从「`○ ●` 字符」改成「有几个点是 on(=这一层读过)」。字符版已不存在。
|
|
2766
|
+
const dotStates = cols.map((node) => kidsOf(node, 'knit-cov-dots')[0].children
|
|
2767
|
+
.filter((dot) => dot && dot.props)
|
|
2768
|
+
.map((dot) => String(dot.props.className).includes(' on')))
|
|
2769
|
+
assert.deepEqual(dotStates, [[true], [true, true], [false]],
|
|
2770
|
+
'实心 = 这一篇读过、空心 = 没读过')
|
|
2771
|
+
assert.deepEqual(dotStates.map((flags) => flags.length), [1, 2, 1], '每层圆点数 = 本层篇数')
|
|
2772
|
+
assert.deepEqual(dotStates.map((flags) => flags.filter(Boolean).length), [1, 2, 0], '……其中实心几个')
|
|
2773
|
+
assert.deepEqual(cols.map((node) => node.props['aria-label']),
|
|
2774
|
+
['主要上下文:1 / 1 篇已读', '辅助上下文:2 / 2 篇已读', '相关上下文:0 / 1 篇已读'],
|
|
2775
|
+
'读屏听到完整一句(md §六十三),但屏幕上不显示这句话')
|
|
2776
|
+
assert.ok(!textOf(byExactClass(nodes, 'knit-usage')[0]).includes('篇已读'),
|
|
2777
|
+
'无障碍文案不许出现在视觉里')
|
|
2778
|
+
for (const node of cols) assert.equal(node.props.type, 'button', '可点就必须是真 button')
|
|
2779
|
+
|
|
2780
|
+
// 点「辅助」→ 只点亮「辅助」那一层(替身里没有 DOM,定位落在 data-knit-tier 上)
|
|
2781
|
+
cols[1].props.onClick()
|
|
2782
|
+
const flashed = byClass(render(), 'knit-tier')
|
|
2783
|
+
.filter((node) => String(node.props.className).includes('flash'))
|
|
2784
|
+
assert.equal(flashed.length, 1, '点一层只点亮那一层')
|
|
2785
|
+
assert.equal(flashed[0].props['data-knit-tier'], 'supporting', '点的哪一层就亮哪一层')
|
|
2786
|
+
|
|
2787
|
+
// 高亮只是一下提示,自己会收掉(不靠 hover、不靠点别处)
|
|
2788
|
+
harness.tick()
|
|
2789
|
+
assert.equal(
|
|
2790
|
+
byClass(render(), 'knit-tier').filter((n) => String(n.props.className).includes('flash')).length,
|
|
2791
|
+
0,
|
|
2792
|
+
)
|
|
2793
|
+
})
|
|
2794
|
+
|
|
2795
|
+
test('v0.18 Coverage:一份包可以没有 Primary —— 不画「0 / 0」的假层', async () => {
|
|
2796
|
+
const base = lifecyclePayload()
|
|
2797
|
+
const { nodes } = await mountUsage({ ...base, context: { ...base.context, primary: [] } })
|
|
2798
|
+
assert.deepEqual(
|
|
2799
|
+
byExactClass(nodes, 'knit-cov-col').map((node) => textOf(kidsOf(node, 'knit-cov-name')[0])),
|
|
2800
|
+
['辅助', '相关'],
|
|
2801
|
+
'Primary 缺席就整列不显示,而不是画一个 0 / 0 的假层',
|
|
2802
|
+
)
|
|
2803
|
+
})
|
|
2804
|
+
|
|
2805
|
+
test('v0.18 Lens 展开 / 收起:收起只收起细节,统计照样开着', async () => {
|
|
2806
|
+
const { nodes, render } = await mountUsage(lifecyclePayload())
|
|
2807
|
+
|
|
2808
|
+
const head = byExactClass(nodes, 'knit-lens-head')
|
|
2809
|
+
assert.equal(head.length, 1, 'Lens 有一行可点的标题')
|
|
2810
|
+
assert.equal(head[0].props.type, 'button', '标题行是真 button')
|
|
2811
|
+
assert.equal(head[0].props['aria-expanded'], 'true', '默认展开')
|
|
2812
|
+
assert.equal(byExactClass(nodes, 'knit-lens-body').length, 1)
|
|
2813
|
+
|
|
2814
|
+
head[0].props.onClick()
|
|
2815
|
+
const closed = render()
|
|
2816
|
+
assert.equal(byExactClass(closed, 'knit-lens-head')[0].props['aria-expanded'], 'false')
|
|
2817
|
+
assert.equal(byExactClass(closed, 'knit-lens-body').length, 0, '收起后不渲染细节')
|
|
2818
|
+
const text = textOf(byExactClass(closed, 'knit-usage')[0])
|
|
2819
|
+
assert.match(text, /使用情况/, '标题还在')
|
|
2820
|
+
assert.match(text, /Epoch 4/, 'Epoch 还在')
|
|
2821
|
+
assert.match(text, /7 次读取/, '摘要行还在 —— 收起的是细节,不是统计')
|
|
2822
|
+
assert.equal(byExactClass(closed, 'knit-cov-col').length, 0, '细节收起来了')
|
|
2823
|
+
})
|
|
2824
|
+
|
|
2825
|
+
test('v0.18 空使用情况:不画「0%」大卡,只报事实', async () => {
|
|
2826
|
+
const payload = lifecyclePayload()
|
|
2827
|
+
const empty = {
|
|
2828
|
+
...payload,
|
|
2829
|
+
usage: {
|
|
2830
|
+
at: 1,
|
|
2831
|
+
epochId: 1,
|
|
2832
|
+
stats: {
|
|
2833
|
+
reads: 0,
|
|
2834
|
+
distinct: 0,
|
|
2835
|
+
outside: 0,
|
|
2836
|
+
outsideReads: [],
|
|
2837
|
+
firstReadTier: 'outside',
|
|
2838
|
+
firstReadRel: null,
|
|
2839
|
+
firstReadAt: null,
|
|
2840
|
+
primaryRel: null,
|
|
2841
|
+
primaryFollowThrough: false,
|
|
2842
|
+
byTier: { primary: { total: 1, read: 0 }, supporting: { total: 2, read: 0 }, related: { total: 1, read: 0 } },
|
|
2843
|
+
supportingCoverage: 0,
|
|
2844
|
+
churn: { snapshots: 0, deltas: 0, retained: 0, appeared: 0, disappeared: 0, moved: 0, taskChanged: 0 },
|
|
2845
|
+
},
|
|
2846
|
+
delta: null,
|
|
2847
|
+
latestDelta: null,
|
|
2848
|
+
recentRead: null,
|
|
2849
|
+
outsideDocs: [],
|
|
2850
|
+
lifecycle: {},
|
|
2851
|
+
},
|
|
2852
|
+
}
|
|
2853
|
+
const { nodes } = await mountUsage(empty)
|
|
2854
|
+
const text = textOf(byExactClass(nodes, 'knit-usage')[0])
|
|
2855
|
+
assert.match(text, /0 次读取/, '零就写零')
|
|
2856
|
+
assert.ok(!text.includes('%'), '不许有百分比')
|
|
2857
|
+
assert.match(text, /暂无记录/, '没有读取记录 = 一句「暂无记录」,不是一块空状态卡')
|
|
2858
|
+
assert.deepEqual(byExactClass(nodes, 'knit-cov-num').map(textOf), ['0 / 1', '0 / 2', '0 / 1'])
|
|
2859
|
+
assert.equal(byExactClass(nodes, 'knit-more-btn').length, 0, '没有包外、没有变化:一个折叠区都不出现')
|
|
2860
|
+
})
|
|
2861
|
+
|
|
2862
|
+
test('v0.18 小高度面板:矮下来不铺细节,滚动仍然只交给列表', async () => {
|
|
2863
|
+
const { readFileSync } = await import('node:fs')
|
|
2864
|
+
const { fileURLToPath } = await import('node:url')
|
|
2865
|
+
const source = readFileSync(
|
|
2866
|
+
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
2867
|
+
'utf8',
|
|
2868
|
+
)
|
|
2869
|
+
// 规格 §31 / §46-E:面板矮时降级成 Summary + Coverage + 最近读取,变化摘要不铺开,
|
|
2870
|
+
// Outside / Delta 收成标题(点得开)。
|
|
2871
|
+
// ⚠️ 测试替身里拿不到 DOM ref,量不到高度 —— 这一条只能守**代码形状**,
|
|
2872
|
+
// 真机手感由 §46-E(面板拉到很矮)人眼确认。
|
|
2873
|
+
const { COMPACT_PANEL_PX } = loadClientModule().exports.__test
|
|
2874
|
+
assert.equal(COMPACT_PANEL_PX, 420, '降级阈值是 420px')
|
|
2875
|
+
const compactAt = source.indexOf('const compact = panelH > 0 && panelH < COMPACT_PANEL_PX')
|
|
2876
|
+
const linesAt = source.indexOf('const previewLines = compact ? [] :')
|
|
2877
|
+
assert.ok(compactAt > 0, '矮面板必须有明确的降级判据')
|
|
2878
|
+
assert.ok(linesAt > compactAt, 'compact 必须先算出来再用(TDZ + 先判后用)')
|
|
2879
|
+
// 量不到高度(0)时按「不矮」处理:首帧与替身里都照常展开,不是默认收起
|
|
2880
|
+
assert.match(source, /const COMPACT_PANEL_PX = 420/)
|
|
2881
|
+
})
|
|
2882
|
+
|
|
2883
|
+
test('v0.18 点状态点 / 包外行:打开那一篇,不重新请求列表', async () => {
|
|
2884
|
+
const { nodes, render, calls } = await mountUsage(lifecyclePayload())
|
|
2885
|
+
|
|
2886
|
+
// 状态点:点它 = 打开 / 选中这一篇(点的那一下不敲宿主)
|
|
2887
|
+
const before = calls.length
|
|
2888
|
+
byExactClass(nodes, 'knit-glyph')[0].props.onClick()
|
|
2889
|
+
assert.equal(calls.length, before, '点状态点不直接请求列表')
|
|
2890
|
+
await harness.flush()
|
|
2891
|
+
const opened = render()
|
|
2892
|
+
assert.equal(openNameOf(opened), 'algo.md', '点哪一篇的状态点就打开哪一篇')
|
|
2893
|
+
// **已经打开则保持原预览**:不重开、不重拉
|
|
2894
|
+
byExactClass(opened, 'knit-glyph')[0].props.onClick()
|
|
2895
|
+
await harness.flush()
|
|
2896
|
+
const again = render()
|
|
2897
|
+
assert.equal(openNameOf(again), 'algo.md')
|
|
2898
|
+
assert.equal(byExactClass(again, 'knit-preview').length, 1, '预览没有被关掉也没有重开')
|
|
2899
|
+
|
|
2900
|
+
// 包外行:展开只是显示(不敲宿主),点那一行同样只是换预览
|
|
2901
|
+
byExactClass(again, 'knit-more-btn')
|
|
2902
|
+
.find((node) => textOf(node).includes('上下文外读取')).props.onClick()
|
|
2903
|
+
const expanded = render()
|
|
2904
|
+
const beforeRow = calls.length
|
|
2905
|
+
byExactClass(expanded, 'knit-out-row')[0].props.onClick()
|
|
2906
|
+
assert.equal(calls.length, beforeRow, '点包外行不直接请求列表')
|
|
2907
|
+
await harness.flush()
|
|
2908
|
+
const outside = render()
|
|
2909
|
+
assert.equal(openNameOf(outside), 'old-plan.md', '点包外行就打开那一篇')
|
|
2910
|
+
})
|
|
2911
|
+
|
|
2912
|
+
test('v0.18 动效:数据没变,轮询不许让 Lens 重播任何动画', async () => {
|
|
2913
|
+
const { nodes, render } = await mountUsage(lifecyclePayload())
|
|
2914
|
+
const dots = (list) => dotsOf(list).map((node) => String(node.props.className))
|
|
2915
|
+
const before = dots(nodes)
|
|
2916
|
+
// 只是轮询 / 计时器走了一轮,数据一个字没变
|
|
2917
|
+
harness.tick()
|
|
2918
|
+
await harness.flush()
|
|
2919
|
+
harness.tick()
|
|
2920
|
+
await harness.flush()
|
|
2921
|
+
assert.deepEqual(dots(render()), before, '同样的数据 → 同样的 class → 补间不会被重播')
|
|
2922
|
+
})
|
|
2923
|
+
|
|
2924
|
+
test('v0.18 样式:Lens 只用语义 token、自己不滚动、减弱动效时不动', async () => {
|
|
2925
|
+
const { readFileSync } = await import('node:fs')
|
|
2926
|
+
const { fileURLToPath } = await import('node:url')
|
|
2927
|
+
const source = readFileSync(
|
|
2928
|
+
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
2929
|
+
'utf8',
|
|
2930
|
+
)
|
|
2931
|
+
// v0.18 UI 迭代(md §十五 / §二十九):状态点**只是一枚中性圆点** ——
|
|
2932
|
+
// 真圆、空心(未读 border,已读 background)、只有中性 token。
|
|
2933
|
+
// ⚠️ Coverage 的圆点与文档行的 glyph 圆点必须是**同一套状态语言**:同一个直径、
|
|
2934
|
+
// 同一对 token。下面这条守卫就是防两处各画各的(人眼很难发现 1px 的差异)。
|
|
2935
|
+
// 直径不写死在守卫里,而是**比对两处**,再钉住当前定的那个值。
|
|
2936
|
+
const covDotSize = source.match(/\.knit-cov-dot\{[^}]*width:(\d+)px;height:(\d+)px;border-radius:50%/)
|
|
2937
|
+
const glyphMarkSize = source.match(/\.knit-glyph-mark\{[^}]*width:(\d+)px;height:(\d+)px;border-radius:50%/)
|
|
2938
|
+
assert.ok(covDotSize, 'Coverage 的状态点必须是真圆(有宽高 + 50% 圆角)')
|
|
2939
|
+
assert.ok(glyphMarkSize, '文档行的状态点必须是真圆(有宽高 + 50% 圆角)')
|
|
2940
|
+
assert.deepEqual([glyphMarkSize[1], glyphMarkSize[2]], [covDotSize[1], covDotSize[2]],
|
|
2941
|
+
'两处状态点必须是同一个直径(两处各画各的时候,1px 的差异人眼很难发现)')
|
|
2942
|
+
assert.equal(covDotSize[1], '6', '圆点直径是 6px(2026-10-06 用户定:9px 改成 6px)')
|
|
2943
|
+
assert.match(source, /\.knit-cov-dot\{[^}]*border:1px solid var\(--dsw-alias-label-caption/)
|
|
2944
|
+
assert.match(source, /\.knit-cov-dot\.on\{[^}]*background:var\(--dsw-alias-label-caption/)
|
|
2945
|
+
assert.match(source, /\.knit-glyph-mark\{[^}]*border:1px solid var\(--dsw-alias-label-caption/)
|
|
2946
|
+
assert.match(source, /\[data-mark="read"\]\{[^}]*background:var\(--dsw-alias-label-caption/,
|
|
2947
|
+
'「已读」在文档行里也是实心')
|
|
2948
|
+
assert.ok(!/\.knit-cov-dot\{[^}]*opacity/.test(source), '不再靠透明度表达状态')
|
|
2949
|
+
assert.ok(!/\.knit-cov-dot\{[^}]*transform/.test(source), '不再靠缩放表达状态')
|
|
2950
|
+
assert.ok(!/#(?:0f9d58|34a853|ea4335|db4437|f9ab00|fbbc04|4285f4|1a73e8)/i.test(source),
|
|
2951
|
+
'四态不许用绿 / 红 / 黄 / 蓝强调(读没读过不是好 / 坏)')
|
|
2952
|
+
assert.ok(!/\.knit-cov[^{]*\{[^}]*color:\s*#[0-9a-fA-F]{3,6}/.test(source), '不许写死颜色')
|
|
2953
|
+
assert.ok(!/\.knit-out-row[^{]*\{[^}]*color:\s*#[0-9a-fA-F]{3,6}/.test(source), '不许写死颜色')
|
|
2954
|
+
assert.match(source, /\.knit-glyph\{[^}]*color:var\(--dsw-alias-label-caption/, '状态点也是中性灰')
|
|
2955
|
+
assert.ok(!/\.knit-glyph\{[^}]*background:(?!none)/.test(source), '状态点不画底色 / 不加徽章')
|
|
2956
|
+
// **不新增第二个滚动容器**(窄侧栏里滚轮套滚轮很难用)
|
|
2957
|
+
assert.ok(!/\.knit-usage[^{]*\{[^}]*overflow-y:\s*(auto|scroll)/.test(source), 'Lens 自己不滚动')
|
|
2958
|
+
assert.ok(!/\.knit-lens[^{]*\{[^}]*overflow-y:\s*(auto|scroll)/.test(source), '细节区也不自己滚动')
|
|
2959
|
+
// 展开 / 收起走条件渲染,不用会自己重播的 animation
|
|
2960
|
+
assert.ok(!/\.knit-lens-body\{[^}]*animation/.test(source))
|
|
2961
|
+
// 「减弱动态效果」:状态点与高亮都不动(终态照常出现)
|
|
2962
|
+
assert.match(source, /prefers-reduced-motion: reduce\)\{[\s\S]*?\.knit-cov-dot\{transition:none/)
|
|
2963
|
+
assert.match(source, /prefers-reduced-motion: reduce\)\{[\s\S]*?\.knit-tier\.flash\{transition:none/)
|
|
2964
|
+
})
|
|
2965
|
+
|
|
2966
|
+
test('v0.18 定位手感:高亮时长与 CSS 同步;对比控件描边用官方分割线那一档', async () => {
|
|
2967
|
+
const { readFileSync } = await import('node:fs')
|
|
2968
|
+
const { fileURLToPath } = await import('node:url')
|
|
2969
|
+
const source = readFileSync(
|
|
2970
|
+
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
2971
|
+
'utf8',
|
|
2972
|
+
)
|
|
2973
|
+
// ① 点 Coverage 层名之后的高亮:JS 常量与 CSS transition **必须是同一个数**。
|
|
2974
|
+
// 两者不同步时不会报任何错,只会看见「高亮已经取消、背景还在慢慢褪」的错帧。
|
|
2975
|
+
const flash = source.match(/const FLASH_MS = (\d+)/)
|
|
2976
|
+
assert.ok(flash, 'FLASH_MS 必须还在(高亮时长是它的唯一出处)')
|
|
2977
|
+
assert.equal(flash[1], '1200', '高亮 1200ms(2026-10-06 用户定:原 650ms 改成 1200ms)')
|
|
2978
|
+
const tierTransition = source.match(/\.knit-tier\{transition:background ([\d.]+)s/)
|
|
2979
|
+
assert.ok(tierTransition, '高亮背景必须有 transition(否则是硬闪一下)')
|
|
2980
|
+
assert.equal(Math.round(Number(tierTransition[1]) * 1000), Number(flash[1]),
|
|
2981
|
+
'CSS transition 的秒数必须等于 FLASH_MS —— 改一个忘另一个只在真机上看得见')
|
|
2982
|
+
// ② 「相关 / 最新」与搜索框的描边:色用 --dsw-alias-border-l3、粗细用 0.5px,
|
|
2983
|
+
// 即 DSH 主区「对话」页签下面那条横线的同一档(官方 .wSkVaW_header 的
|
|
2984
|
+
// border-bottom: .5px solid rgba(0,0,0,.12),浅色下就是 border-l3)。
|
|
2985
|
+
// 退回 l4 会重一档(像两个输入框把内容框住);粗细写回 1px 则高分屏上比官方粗一倍
|
|
2986
|
+
// —— 色对上了粗细没对上,只看得见「比旁边那条横重」,看不出是哪里不对。
|
|
2987
|
+
// 两处都是 2026-10-06 用户看真机后提的。
|
|
2988
|
+
assert.match(source, /\.knit-seg\{[^}]*border:0\.5px solid var\(--dsw-alias-border-l3/,
|
|
2989
|
+
'「相关 / 最新」的外框用 border-l3、0.5px')
|
|
2990
|
+
assert.match(source,
|
|
2991
|
+
/\.knit-seg-btn \+ \.knit-seg-btn\{border-left:0\.5px solid var\(--dsw-alias-border-l3/,
|
|
2992
|
+
'「相关 / 最新」之间的分隔线也是同一档同粗(色或粗细差一点就会看得出来)')
|
|
2993
|
+
assert.match(source, /\.knit-filter\{[^}]*border:0\.5px solid var\(--dsw-alias-border-l3/,
|
|
2994
|
+
'搜索框描边用 border-l3、0.5px')
|
|
2995
|
+
assert.ok(!/\.knit-(?:seg|filter)\{[^}]*border[^;]*--dsw-alias-border-l4/.test(source),
|
|
2996
|
+
'这两个控件不许再退回 l4')
|
|
2997
|
+
assert.ok(!/\.knit-seg(-btn \+ \.knit-seg-btn)?\{[^}]*border[^;]*:1px solid var\(--dsw-alias-border-l3/
|
|
2998
|
+
.test(source), '这三个描边要么一起 0.5px,要么一起改 —— 不许只把其中一处写回 1px')
|
|
2999
|
+
})
|
|
3000
|
+
|
|
3001
|
+
test('v0.18 键盘与 aria:Lens 里每个可点元素都是真 button,且各自都有焦点环', async () => {
|
|
3002
|
+
// 规格 §59 第 13 步(keyboard & aria)。三件事各自会静默坏掉:
|
|
3003
|
+
// ① 写成 `div` + `onClick` ⇒ 键盘 Tab 到不了(鼠标能用、键盘不能用,人眼审最容易漏);
|
|
3004
|
+
// ② 没有 `type:'button'` ⇒ 拿到隐式 submit 语义;
|
|
3005
|
+
// ③ 没有 `:focus-visible` ⇒ 能 Tab 到但看不见焦点在哪(这一版新增的六处都得有)。
|
|
3006
|
+
const { readFileSync } = await import('node:fs')
|
|
3007
|
+
const { fileURLToPath } = await import('node:url')
|
|
3008
|
+
const source = readFileSync(
|
|
3009
|
+
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
3010
|
+
'utf8',
|
|
3011
|
+
)
|
|
3012
|
+
const clickable = ['knit-lens-head', 'knit-cov-col', 'knit-read-row', 'knit-out-row', 'knit-more-btn', 'knit-glyph']
|
|
3013
|
+
for (const cls of clickable) {
|
|
3014
|
+
const at = source.indexOf(`className: '${cls}'`)
|
|
3015
|
+
assert.ok(at > 0, `${cls} 没渲染出来(改过类名?)`)
|
|
3016
|
+
// 紧邻它前面的那一次 h(...) 必须是 button —— 不是 div、不是 span
|
|
3017
|
+
const before = source.slice(Math.max(0, at - 160), at)
|
|
3018
|
+
const call = before.slice(before.lastIndexOf("h('"))
|
|
3019
|
+
assert.ok(call.startsWith("h('button'"), `${cls} 不是真 button(键盘到不了):${JSON.stringify(call.slice(0, 24))}`)
|
|
3020
|
+
assert.match(source.slice(at, at + 90), /type: 'button'/, `${cls} 缺少 type:'button'`)
|
|
3021
|
+
assert.match(
|
|
3022
|
+
source,
|
|
3023
|
+
new RegExp(`\\.${cls}:focus-visible\\{[^}]*outline:`),
|
|
3024
|
+
`${cls} 能 Tab 到却没有焦点环(看不见焦点在哪)`,
|
|
3025
|
+
)
|
|
3026
|
+
}
|
|
3027
|
+
// 三个折叠开关必须把展开态报出来(读屏靠 aria-expanded,不靠 › / ↑ 这两个字形)
|
|
3028
|
+
for (const flag of ['lensOpen', 'gapOpen', 'deltaOpen']) {
|
|
3029
|
+
assert.match(
|
|
3030
|
+
source,
|
|
3031
|
+
new RegExp(`'aria-expanded': ${flag} \\? 'true' : 'false'`),
|
|
3032
|
+
`${flag} 的折叠开关没有报 aria-expanded`,
|
|
3033
|
+
)
|
|
3034
|
+
}
|
|
3035
|
+
// 行内 glyph 有 title 就也要有 aria-label(只有 title 时读屏不一定念得出来)
|
|
3036
|
+
assert.match(source, /className: 'knit-glyph'[\s\S]{0,220}?'aria-label': glyph\.title/)
|
|
3037
|
+
})
|
|
3038
|
+
|
|
2486
3039
|
/* ── v0.17:列表的进出动效(2026-10-03 用户拍板的那套手感)──────────────
|
|
2487
3040
|
用户原话:「新读取跟挤掉旧的未读的,这里的交互可能要优化,因为现在是一闪一闪的…
|
|
2488
3041
|
从当前的、如辅助上下文中新增,它应该是从低向上的…消失的时候从上到下,渐隐掉」。
|
|
@@ -2776,3 +3329,378 @@ test('v0.17 交互审:列表只在光标真的换了(且焦点在列表上
|
|
|
2776
3329
|
assert.match(code, /scrollIntoView\(\{ block: 'nearest' \}\)/, '滚的是最小距离,不是把行顶到最上面')
|
|
2777
3330
|
})
|
|
2778
3331
|
|
|
3332
|
+
|
|
3333
|
+
/* ── v0.19 代码上下文 ───────────────────────────────────────────────
|
|
3334
|
+
这一组的职责:守住「代码这一档在**浏览器半边**长什么样」。
|
|
3335
|
+
宿主侧的规则(分类 / 排序 / 包 / 生命周期 / Epoch)在
|
|
3336
|
+
`test/classification.test.mjs` 与 `test/code-context.test.mjs` 里守,
|
|
3337
|
+
这里只管三件事:**它出现在哪个档、行上多了什么、点开怎么渲染**。
|
|
3338
|
+
贯穿约束:代码**不是**一个新的工具页 —— 它仍然受当前任务检索支配,
|
|
3339
|
+
所以这里从不假设「代码档 = 项目全部代码」。 */
|
|
3340
|
+
|
|
3341
|
+
/** 一份代码档载荷:一条带目录、一条在根。 */
|
|
3342
|
+
function codePayload(overrides = {}) {
|
|
3343
|
+
const now = Date.now()
|
|
3344
|
+
return {
|
|
3345
|
+
ok: true, root: '/p', total: 2, mode: 'time', topic: '', kind: 'code',
|
|
3346
|
+
docs: [
|
|
3347
|
+
{
|
|
3348
|
+
path: '/p/src/context-manager.ts', rel: 'src/context-manager.ts', name: 'context-manager.ts',
|
|
3349
|
+
title: 'context-manager.ts', kind: 'code', summary: 'src/', size: 2400,
|
|
3350
|
+
mtimeMs: now - 30000, score: null,
|
|
3351
|
+
},
|
|
3352
|
+
{
|
|
3353
|
+
path: '/p/plugin-loader.js', rel: 'plugin-loader.js', name: 'plugin-loader.js',
|
|
3354
|
+
title: 'plugin-loader.js', kind: 'code', summary: '', size: 900,
|
|
3355
|
+
mtimeMs: now - 60000, score: null,
|
|
3356
|
+
},
|
|
3357
|
+
],
|
|
3358
|
+
...overrides,
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
test('v0.19 代码:「代码」档请求 kind=code,代码行带语言徽章而文档行不带', async () => {
|
|
3363
|
+
const { calls } = installFetch(kindResponder({ code: codePayload() }))
|
|
3364
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
3365
|
+
harness.reset()
|
|
3366
|
+
harness.seed(['', 'time', 'code'])
|
|
3367
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3368
|
+
let nodes = render()
|
|
3369
|
+
await harness.flush()
|
|
3370
|
+
nodes = render()
|
|
3371
|
+
|
|
3372
|
+
assert.ok(calls.some((u) => u.includes('kind=code')), `实际 URL:${calls.join(' ')}`)
|
|
3373
|
+
assert.equal(byToken(nodes, 'knit-doc').length, 2, '两条代码候选各一行')
|
|
3374
|
+
// 徽章是**纯展示**:它把文件名后缀说给人看,不参与任何判定(判定在宿主分类层)。
|
|
3375
|
+
assert.deepEqual(byExactClass(nodes, 'knit-lang').map(textOf), ['TS', 'JS'])
|
|
3376
|
+
assert.equal(byExactClass(nodes, 'knit-media-grid').length, 0, '代码档没有媒体网格')
|
|
3377
|
+
assert.match(byClass(nodes, 'knit-count').map(textOf).join(''), /2 个代码文件/)
|
|
3378
|
+
})
|
|
3379
|
+
|
|
3380
|
+
test('v0.19 代码:文档行的语言徽章不出场 —— 整列都是 Markdown,挂 MD 是纯噪声', async () => {
|
|
3381
|
+
installFetch(kindResponder({ doc: listPayload() }))
|
|
3382
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
3383
|
+
harness.reset()
|
|
3384
|
+
harness.seed(['', 'time'])
|
|
3385
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3386
|
+
let nodes = render()
|
|
3387
|
+
await harness.flush()
|
|
3388
|
+
nodes = render()
|
|
3389
|
+
|
|
3390
|
+
assert.equal(byToken(nodes, 'knit-doc').length, 2)
|
|
3391
|
+
assert.equal(byExactClass(nodes, 'knit-lang').length, 0, '文档行一个徽章都不加')
|
|
3392
|
+
})
|
|
3393
|
+
|
|
3394
|
+
test('v0.19 代码:点代码行就地渲染行号 + 正文,绝不落到 Markdown 渲染', async () => {
|
|
3395
|
+
const { calls } = installFetch((url) => {
|
|
3396
|
+
if (url.includes('/api/doc')) {
|
|
3397
|
+
return {
|
|
3398
|
+
ok: true, rel: 'src/context-manager.ts', kind: 'code', language: 'typescript',
|
|
3399
|
+
title: 'context-manager.ts',
|
|
3400
|
+
// 故意用 Markdown 会吃掉的两行:`#` 开头 + `-` 开头。
|
|
3401
|
+
// 如果代码误落到 MarkdownText,这两行会变成标题和列表项 —— 那正是这条测试要钉的。
|
|
3402
|
+
text: '# not a heading\nexport class A {}\n',
|
|
3403
|
+
truncated: false,
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
return codePayload()
|
|
3407
|
+
})
|
|
3408
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
3409
|
+
harness.reset()
|
|
3410
|
+
harness.seed(['', 'time', 'code'])
|
|
3411
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3412
|
+
let nodes = render()
|
|
3413
|
+
await harness.flush()
|
|
3414
|
+
nodes = render()
|
|
3415
|
+
|
|
3416
|
+
byToken(nodes, 'knit-doc')[0].props.onClick()
|
|
3417
|
+
await harness.flush()
|
|
3418
|
+
nodes = render()
|
|
3419
|
+
await harness.flush()
|
|
3420
|
+
nodes = render()
|
|
3421
|
+
|
|
3422
|
+
assert.ok(calls.some((u) => u.includes('/api/doc')), '选中代码行必须读正文')
|
|
3423
|
+
assert.equal(byExactClass(nodes, 'knit-codepane').length, 1, '代码走 CodePane')
|
|
3424
|
+
assert.equal(byExactClass(nodes, 'knit-code-gutter').length, 1, '有独立行号列')
|
|
3425
|
+
assert.equal(byExactClass(nodes, 'knit-code-src').length, 1, '有正文列')
|
|
3426
|
+
// 行号与正文各是**一个**文本节点(靠 white-space:pre 换行)—— 不做逐行 DOM。
|
|
3427
|
+
assert.equal(textOf(byExactClass(nodes, 'knit-code-gutter')[0]), '1\n2')
|
|
3428
|
+
assert.equal(textOf(byExactClass(nodes, 'knit-code-src')[0]), '# not a heading\nexport class A {}')
|
|
3429
|
+
// 落到 Markdown 渲染的判据:降级分支那个 `pre.knit-raw` 一个都不许有
|
|
3430
|
+
assert.equal(byExactClass(nodes, 'knit-raw').length, 0, '代码不许走纯文本降级那条路')
|
|
3431
|
+
})
|
|
3432
|
+
|
|
3433
|
+
test('v0.19 代码:同名 source map 才给「Source map」入口,没有就不给', async () => {
|
|
3434
|
+
const docResponder = (mapRel) => (url) => {
|
|
3435
|
+
if (url.includes('/api/doc')) {
|
|
3436
|
+
return {
|
|
3437
|
+
ok: true, rel: 'plugin-loader.js', kind: 'code', language: 'javascript',
|
|
3438
|
+
title: 'plugin-loader.js', text: 'export const x = 1\n', truncated: false,
|
|
3439
|
+
...(mapRel ? { mapRel } : {}),
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
return codePayload()
|
|
3443
|
+
}
|
|
3444
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
3445
|
+
|
|
3446
|
+
// ① 有同名 `.map`:入口出现,且是**低权重**按钮(.knit-btn-quiet)
|
|
3447
|
+
installFetch(docResponder('plugin-loader.js.map'))
|
|
3448
|
+
harness.reset()
|
|
3449
|
+
harness.seed(['', 'time', 'code'])
|
|
3450
|
+
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3451
|
+
await harness.flush()
|
|
3452
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3453
|
+
byToken(nodes, 'knit-doc')[1].props.onClick()
|
|
3454
|
+
await harness.flush()
|
|
3455
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3456
|
+
await harness.flush()
|
|
3457
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3458
|
+
|
|
3459
|
+
const mapBtn = byToken(nodes, 'knit-btn-quiet').find((b) => textOf(b) === 'Source map')
|
|
3460
|
+
assert.ok(mapBtn, '有 .map 时必须给「Source map」入口')
|
|
3461
|
+
// 列表里**没有** .map 那一行 —— 它是生成产物,不进上下文(Context eligibility ≠ 文件可见性)
|
|
3462
|
+
assert.ok(!byToken(nodes, 'knit-doc').some((r) => String(r.props['data-knit-rel']).endsWith('.map')),
|
|
3463
|
+
'.map 不许作为独立行出现在代码列表里')
|
|
3464
|
+
mapBtn.props.onClick()
|
|
3465
|
+
await harness.flush()
|
|
3466
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3467
|
+
await harness.flush()
|
|
3468
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3469
|
+
assert.ok(byExactClass(nodes, 'knit-codepane').length === 1,
|
|
3470
|
+
'.map 也走同一个 CodePane(以纯文本 / JSON 看)')
|
|
3471
|
+
|
|
3472
|
+
// ② 没有同名 `.map`:一个入口都不给(不留空壳按钮)
|
|
3473
|
+
installFetch(docResponder(''))
|
|
3474
|
+
harness.reset()
|
|
3475
|
+
harness.seed(['', 'time', 'code'])
|
|
3476
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3477
|
+
await harness.flush()
|
|
3478
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3479
|
+
byToken(nodes, 'knit-doc')[1].props.onClick()
|
|
3480
|
+
await harness.flush()
|
|
3481
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3482
|
+
await harness.flush()
|
|
3483
|
+
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3484
|
+
assert.equal(byToken(nodes, 'knit-btn-quiet').filter((b) => textOf(b) === 'Source map').length, 0,
|
|
3485
|
+
'没有同名 .map 就不许画这个按钮')
|
|
3486
|
+
})
|
|
3487
|
+
|
|
3488
|
+
/**
|
|
3489
|
+
* v0.19 追加:HTML 的「网页预览」入口。
|
|
3490
|
+
*
|
|
3491
|
+
* 就地预览给的是**源码**;这个按钮开的是**官方文档预览标签页**(`actions.openResource`
|
|
3492
|
+
* → `dsh-resource://file/session/…`),那一侧有 DSH 自带的 HTML 渲染器,出来的是网页。
|
|
3493
|
+
* 这条测试钉三件事:
|
|
3494
|
+
* ① **只有 HTML 出场** —— 其余代码类型一个都不给,别把按钮变成常驻噪声;
|
|
3495
|
+
* ② 走的是**同一条** `openResource` 通道(不新开第二条打开路径),地址就是这个文件的
|
|
3496
|
+
* session 资源地址;
|
|
3497
|
+
* ③ **正文还没到手时按钮已经在了**(`language` 还空着,靠列表徽章那张表兜底)——
|
|
3498
|
+
* 否则头部会在读完正文后突然长出一个按钮,正是 v0.19 一直在避免的那种几何跳动。
|
|
3499
|
+
*/
|
|
3500
|
+
test('v0.19 网页预览:只有 HTML 给这个入口,点了走官方标签页,读正文前后都在', async () => {
|
|
3501
|
+
const opened = []
|
|
3502
|
+
const now = Date.now()
|
|
3503
|
+
const htmlRow = {
|
|
3504
|
+
path: '/p/02_方案与 Demo/knit-demo.html', rel: '02_方案与 Demo/knit-demo.html',
|
|
3505
|
+
name: 'knit-demo.html', title: 'knit-demo.html', kind: 'code',
|
|
3506
|
+
summary: '02_方案与 Demo/', size: 1200, mtimeMs: now - 30000, score: null,
|
|
3507
|
+
}
|
|
3508
|
+
const tsRow = {
|
|
3509
|
+
path: '/p/src/context-manager.ts', rel: 'src/context-manager.ts',
|
|
3510
|
+
name: 'context-manager.ts', title: 'context-manager.ts', kind: 'code',
|
|
3511
|
+
summary: 'src/', size: 2400, mtimeMs: now - 60000, score: null,
|
|
3512
|
+
}
|
|
3513
|
+
// 正文那边的 `language` 按「当前打开的是哪一行」给 —— 分类结论由宿主说了算(v0.19)。
|
|
3514
|
+
let language = 'html'
|
|
3515
|
+
installFetch((url) => {
|
|
3516
|
+
if (String(url).includes('/api/doc')) {
|
|
3517
|
+
return {
|
|
3518
|
+
ok: true, rel: htmlRow.rel, kind: 'code', language,
|
|
3519
|
+
title: 'knit-demo.html', text: '<!DOCTYPE html>\n<h1>hi</h1>\n', truncated: false,
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
return { ok: true, root: '/p', total: 2, mode: 'time', topic: '', kind: 'code', docs: [htmlRow, tsRow] }
|
|
3523
|
+
})
|
|
3524
|
+
|
|
3525
|
+
const { OfficialTabBody } = loadClientModule().exports.__test
|
|
3526
|
+
const props = {
|
|
3527
|
+
sessionId: 's-1',
|
|
3528
|
+
useTabInfo: () => ({
|
|
3529
|
+
tab: { id: 't', visible: true, actions: { openResource: (a) => opened.push(a) } },
|
|
3530
|
+
}),
|
|
3531
|
+
}
|
|
3532
|
+
const render = () => harness.render(h(OfficialTabBody, props))
|
|
3533
|
+
|
|
3534
|
+
// ① 打开 HTML 行:**不等正文**,按钮就得在
|
|
3535
|
+
harness.reset()
|
|
3536
|
+
let nodes = render()
|
|
3537
|
+
await harness.flush()
|
|
3538
|
+
nodes = render()
|
|
3539
|
+
language = 'html'
|
|
3540
|
+
byToken(nodes, 'knit-doc')[0].props.onClick()
|
|
3541
|
+
nodes = render()
|
|
3542
|
+
const beforeLoad = byToken(nodes, 'knit-btn').find((b) => textOf(b) === '网页预览')
|
|
3543
|
+
assert.ok(beforeLoad, '正文还没到手时「网页预览」就该在场(否则头会长高一下)')
|
|
3544
|
+
|
|
3545
|
+
// 正文到手后仍在,且带完整相对路径的 tooltip
|
|
3546
|
+
await harness.flush()
|
|
3547
|
+
nodes = render()
|
|
3548
|
+
const webBtn = byToken(nodes, 'knit-btn').find((b) => textOf(b) === '网页预览')
|
|
3549
|
+
assert.ok(webBtn, '读完正文后「网页预览」仍在')
|
|
3550
|
+
assert.notEqual(webBtn.props.disabled, true, '有 openResource 时不禁用')
|
|
3551
|
+
assert.match(String(webBtn.props.title), /knit-demo\.html/, 'tooltip 里带相对路径')
|
|
3552
|
+
|
|
3553
|
+
// ② 点了走官方标签页那条通道,地址就是这个文件的 session 资源地址
|
|
3554
|
+
webBtn.props.onClick()
|
|
3555
|
+
await harness.flush()
|
|
3556
|
+
assert.deepEqual(opened, ['dsh-resource://file/session/s-1/02_%E6%96%B9%E6%A1%88%E4%B8%8E%20Demo/knit-demo.html'],
|
|
3557
|
+
'「网页预览」必须与双击同一条 openResource 通道')
|
|
3558
|
+
|
|
3559
|
+
// ③ 换一个非 HTML 的代码行:这个入口一个都不许有
|
|
3560
|
+
language = 'typescript'
|
|
3561
|
+
harness.reset()
|
|
3562
|
+
nodes = render()
|
|
3563
|
+
await harness.flush()
|
|
3564
|
+
nodes = render()
|
|
3565
|
+
byToken(nodes, 'knit-doc')[1].props.onClick()
|
|
3566
|
+
await harness.flush()
|
|
3567
|
+
nodes = render()
|
|
3568
|
+
await harness.flush()
|
|
3569
|
+
nodes = render()
|
|
3570
|
+
assert.equal(byToken(nodes, 'knit-btn').filter((b) => textOf(b) === '网页预览').length, 0,
|
|
3571
|
+
'非 HTML 的代码不许出现「网页预览」')
|
|
3572
|
+
assert.ok(byExactClass(nodes, 'knit-codepane').length === 1, '它照旧走就地代码预览')
|
|
3573
|
+
})
|
|
3574
|
+
|
|
3575
|
+
test('v0.19 代码:「全部」档是三区(文档 / 代码 / 媒体),代码区排在媒体区之前且限流', async () => {
|
|
3576
|
+
const now = Date.now()
|
|
3577
|
+
const docs = []
|
|
3578
|
+
for (let i = 1; i <= 7; i += 1) {
|
|
3579
|
+
docs.push({
|
|
3580
|
+
path: `/p/d${i}.md`, rel: `d${i}.md`, name: `d${i}.md`, title: `文档${i}`,
|
|
3581
|
+
kind: 'md', summary: '摘要', size: 500, mtimeMs: now - i * 1000, score: null,
|
|
3582
|
+
})
|
|
3583
|
+
}
|
|
3584
|
+
for (let i = 1; i <= 6; i += 1) {
|
|
3585
|
+
docs.push({
|
|
3586
|
+
path: `/p/src/c${i}.ts`, rel: `src/c${i}.ts`, name: `c${i}.ts`, title: `c${i}.ts`,
|
|
3587
|
+
kind: 'code', summary: 'src/', size: 900, mtimeMs: now - i * 1000, score: null,
|
|
3588
|
+
})
|
|
3589
|
+
}
|
|
3590
|
+
for (let i = 1; i <= 3; i += 1) {
|
|
3591
|
+
docs.push({
|
|
3592
|
+
path: `/p/i${i}.png`, rel: `i${i}.png`, name: `i${i}.png`, title: `图${i}`,
|
|
3593
|
+
kind: 'image', summary: '', size: 1024, mtimeMs: now - i * 1000, score: null,
|
|
3594
|
+
})
|
|
3595
|
+
}
|
|
3596
|
+
installFetch(kindResponder({ all: { ok: true, root: '/p', total: docs.length, mode: 'time', topic: '', kind: 'all', docs } }))
|
|
3597
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
3598
|
+
harness.reset()
|
|
3599
|
+
harness.seed(['', 'time', 'all'])
|
|
3600
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3601
|
+
let nodes = render()
|
|
3602
|
+
await harness.flush()
|
|
3603
|
+
nodes = render()
|
|
3604
|
+
|
|
3605
|
+
assert.deepEqual(byExactClass(nodes, 'knit-section-title').map(textOf), ['文档', '代码', '媒体'],
|
|
3606
|
+
'三区的顺序是文档 → 代码 → 媒体')
|
|
3607
|
+
// 文档区 4 条 + 代码区 4 条 = 8 行文本行;媒体区是格子,不算行
|
|
3608
|
+
assert.equal(byToken(nodes, 'knit-doc').length, 8, '文档区与代码区各自限 4 条')
|
|
3609
|
+
assert.equal(byExactClass(nodes, 'knit-lang').length, 4, '语言徽章只跟着代码区那 4 行')
|
|
3610
|
+
assert.equal(byToken(nodes, 'knit-media-card').length, 3, '媒体一格不隐藏')
|
|
3611
|
+
assert.match(byClass(nodes, 'knit-count').map(textOf).join(''), /16 项/, '顶行仍报总数')
|
|
3612
|
+
})
|
|
3613
|
+
|
|
3614
|
+
test('v0.19 代码:Usage Lens 里的代码路径照常显示(读的是一份事实、不是两套)', async () => {
|
|
3615
|
+
installFetch(() => contextPayload({
|
|
3616
|
+
usage: {
|
|
3617
|
+
at: 1_700_000_000_000,
|
|
3618
|
+
epochId: 4,
|
|
3619
|
+
stats: {
|
|
3620
|
+
reads: 5,
|
|
3621
|
+
distinct: 2,
|
|
3622
|
+
outside: 1,
|
|
3623
|
+
outsideReads: ['src/util.ts'],
|
|
3624
|
+
firstReadTier: 'primary',
|
|
3625
|
+
firstReadRel: 'src/context-manager.ts',
|
|
3626
|
+
firstReadAt: 1,
|
|
3627
|
+
primaryRel: 'src/context-manager.ts',
|
|
3628
|
+
primaryFollowThrough: true,
|
|
3629
|
+
byTier: {
|
|
3630
|
+
primary: { total: 1, read: 1 },
|
|
3631
|
+
supporting: { total: 1, read: 1 },
|
|
3632
|
+
related: { total: 1, read: 0 },
|
|
3633
|
+
},
|
|
3634
|
+
supportingCoverage: 1,
|
|
3635
|
+
churn: { snapshots: 2, deltas: 1, retained: 2, appeared: 1, disappeared: 0, moved: 0, taskChanged: 0 },
|
|
3636
|
+
},
|
|
3637
|
+
delta: { appeared: ['src/context-manager.ts'], disappeared: [], moved: [], taskChanged: false },
|
|
3638
|
+
// 最近读取与包外读取都是**代码路径**:Lens 只按 rel 渲染,认不出这是不是 Markdown。
|
|
3639
|
+
recentRead: { rel: 'src/context-manager.ts', at: 1_700_000_000_000, status: 'updated_after_read' },
|
|
3640
|
+
outsideDocs: [{ rel: 'src/util.ts', count: 2, lastReadAt: 1_699_000_000_000 }],
|
|
3641
|
+
},
|
|
3642
|
+
}))
|
|
3643
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
3644
|
+
harness.reset()
|
|
3645
|
+
harness.seed(['', 'relevance'])
|
|
3646
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3647
|
+
let nodes = render()
|
|
3648
|
+
await harness.flush()
|
|
3649
|
+
nodes = render()
|
|
3650
|
+
await harness.flush()
|
|
3651
|
+
nodes = render()
|
|
3652
|
+
|
|
3653
|
+
const toggle = byExactClass(nodes, 'knit-btn').find((node) => textOf(node) === '使用情况')
|
|
3654
|
+
assert.ok(toggle, '头部必须有「使用情况」按钮')
|
|
3655
|
+
toggle.props.onClick()
|
|
3656
|
+
await harness.flush()
|
|
3657
|
+
nodes = render()
|
|
3658
|
+
await harness.flush()
|
|
3659
|
+
nodes = render()
|
|
3660
|
+
|
|
3661
|
+
const line = byExactClass(nodes, 'knit-usage')[0]
|
|
3662
|
+
assert.ok(line, '打开后必须出现 Usage Lens')
|
|
3663
|
+
// 代码与文档共用同一份 Lens:这里只是 rel 恰好是个 .ts —— 没有第二套展示
|
|
3664
|
+
assert.match(textOf(line), /src\/context-manager\.ts/, '最近读取的代码路径要出现')
|
|
3665
|
+
// 包外读取那一块是**可展开**的(默认收起),展开后才逐条列 rel
|
|
3666
|
+
const gapBtn = byToken(nodes, 'knit-more-btn').find((b) => textOf(b).includes('上下文外读取'))
|
|
3667
|
+
assert.ok(gapBtn, '必须有「上下文外读取」这一块')
|
|
3668
|
+
gapBtn.props.onClick()
|
|
3669
|
+
await harness.flush()
|
|
3670
|
+
nodes = render()
|
|
3671
|
+
const text = textOf(byExactClass(nodes, 'knit-usage')[0])
|
|
3672
|
+
assert.match(text, /src\/util\.ts/, '包外读取的代码路径也要出现')
|
|
3673
|
+
// 纪律没变:只有事实,没有分数 / 百分比 / 评分条
|
|
3674
|
+
assert.ok(!/分|%|score/i.test(text), `Usage Lens 里不许出现分数或百分比:${text}`)
|
|
3675
|
+
})
|
|
3676
|
+
|
|
3677
|
+
test('v0.19 代码:样式守卫 —— 行号/正文各归各的滚动,语言徽章不是胶囊', async () => {
|
|
3678
|
+
const { readFileSync } = await import('node:fs')
|
|
3679
|
+
const { fileURLToPath } = await import('node:url')
|
|
3680
|
+
const source = readFileSync(fileURLToPath(new URL('../src/client/client.js', import.meta.url)), 'utf8')
|
|
3681
|
+
const start = source.indexOf('const CSS = `') + 'const CSS = `'.length
|
|
3682
|
+
const css = source.slice(start, source.indexOf('`', start)).replace(/\/\*[\s\S]*?\*\//g, '')
|
|
3683
|
+
|
|
3684
|
+
// ① 横向滚动只属于正文列(min-width:0 才滚得动),纵向仍归 .knit-preview-body
|
|
3685
|
+
const pane = css.match(/\.knit-codepane\{([^}]*)\}/)
|
|
3686
|
+
const src = css.match(/\.knit-code-src\{([^}]*)\}/)
|
|
3687
|
+
assert.ok(pane && src, '必须有 .knit-codepane 与 .knit-code-src 两条规则')
|
|
3688
|
+
assert.ok(!/overflow-[xy]/.test(pane[1]), 'CodePane 自己不滚动 —— 别开第二个滚动容器')
|
|
3689
|
+
assert.match(src[1], /overflow-x:auto/, '正文列负责横向滚动')
|
|
3690
|
+
assert.match(src[1], /min-width:0/, 'flex 子项没有 min-width:0 就永远滚不动')
|
|
3691
|
+
assert.match(css.match(/\.knit-code-gutter\{([^}]*)\}/)[1], /white-space:pre/, '行号靠 pre 换行,不做逐行节点')
|
|
3692
|
+
|
|
3693
|
+
// ② 语言徽章是**一条弱注释**,不是标签:无底色、无边框、无圆角
|
|
3694
|
+
const lang = css.match(/\.knit-lang\{([\s\S]*?)\}/)[0]
|
|
3695
|
+
assert.ok(!/background/.test(lang), `徽章不许有底色:${lang}`)
|
|
3696
|
+
assert.ok(!/border/.test(lang), `徽章不许有边框:${lang}`)
|
|
3697
|
+
assert.ok(!/border-radius/.test(lang), `徽章不许有圆角:${lang}`)
|
|
3698
|
+
assert.match(lang, /flex:none/, '窄侧边栏里压缩的是标题,不是徽章')
|
|
3699
|
+
|
|
3700
|
+
// ③ 颜色全走 DSH 令牌(亮 / 暗两套主题各给各的值),失败时有中性回落
|
|
3701
|
+
for (const rule of [lang, css.match(/\.knit-code-gutter\{([^}]*)\}/)[0]]) {
|
|
3702
|
+
for (const token of rule.match(/var\(--dsw-[a-z0-9-]+[^)]*\)/g) || []) {
|
|
3703
|
+
assert.ok(token.includes(','), `DSH 令牌必须带回落值:${token}`)
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
})
|