dsh-knit 0.18.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 +193 -7
- package/README.en.md +73 -26
- package/README.md +97 -21
- package/SECURITY.md +4 -3
- package/package.json +6 -4
- package/src/client/client.js +451 -47
- 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 +431 -3
- package/test/code-context.test.mjs +567 -0
- package/test/eval/fixture.mjs +309 -6
- package/test/eval.test.mjs +117 -1
- package/test/host.test.mjs +63 -3
- 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)
|
|
@@ -1436,6 +1438,57 @@ test('样式:预览面板底色恒为纯阅读底色,不靠底色分层;
|
|
|
1436
1438
|
assert.ok(!css.includes('transition:background-color'))
|
|
1437
1439
|
})
|
|
1438
1440
|
|
|
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
|
+
|
|
1439
1492
|
test('媒体:点类型按钮切到「媒体」会带 kind=media 重拉并记住偏好', async () => {
|
|
1440
1493
|
const { calls } = installFetch(kindResponder({ doc: listPayload(), media: mediaPayload() }))
|
|
1441
1494
|
const { KnitBody } = loadClientModule().exports.__test
|
|
@@ -3276,3 +3329,378 @@ test('v0.17 交互审:列表只在光标真的换了(且焦点在列表上
|
|
|
3276
3329
|
assert.match(code, /scrollIntoView\(\{ block: 'nearest' \}\)/, '滚的是最小距离,不是把行顶到最上面')
|
|
3277
3330
|
})
|
|
3278
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
|
+
})
|