dsh-knit 0.23.0 → 0.23.1
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 +92 -0
- package/README.en.md +38 -37
- package/README.md +27 -28
- package/SECURITY.md +5 -2
- package/package.json +4 -2
- package/src/client/client.js +153 -133
- package/test/client.test.mjs +364 -328
package/test/client.test.mjs
CHANGED
|
@@ -635,11 +635,11 @@ function mediaPayload(overrides = {}) {
|
|
|
635
635
|
}
|
|
636
636
|
}
|
|
637
637
|
|
|
638
|
-
/** 造一份文档 + 图片 +
|
|
638
|
+
/** 造一份文档 + 图片 + 视频混排载荷(媒体档用;那个 `kind` 字段只是载荷回声)。 */
|
|
639
639
|
function mixedPayload(overrides = {}) {
|
|
640
640
|
const now = Date.now()
|
|
641
641
|
return {
|
|
642
|
-
ok: true, root: '/p', total: 3, mode: 'time', topic: '', kind: '
|
|
642
|
+
ok: true, root: '/p', total: 3, mode: 'time', topic: '', kind: 'media',
|
|
643
643
|
docs: [
|
|
644
644
|
{ path: '/p/方案.md', rel: '方案.md', name: '方案.md', title: '方案', kind: 'md', summary: '文档摘要', size: 500, mtimeMs: now - 30000, score: null },
|
|
645
645
|
{ path: '/p/a.png', rel: 'a.png', name: 'a.png', title: 'a', kind: 'image', summary: '', size: 1024, mtimeMs: now - 60000, score: null },
|
|
@@ -660,33 +660,6 @@ function kindResponder(map) {
|
|
|
660
660
|
}
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
-
/** 造一份超出「全部」两个分区上限的载荷:7 篇文档 + 5 图 + 4 视频 = 16 项。 */
|
|
664
|
-
function bigMixedPayload() {
|
|
665
|
-
const now = Date.now()
|
|
666
|
-
const docs = []
|
|
667
|
-
for (let i = 1; i <= 7; i += 1) {
|
|
668
|
-
docs.push({
|
|
669
|
-
path: `/p/d${i}.md`, rel: `d${i}.md`, name: `d${i}.md`, title: `文档${i}`,
|
|
670
|
-
kind: 'md', summary: '摘要', size: 500, mtimeMs: now - i * 1000, score: null,
|
|
671
|
-
})
|
|
672
|
-
}
|
|
673
|
-
for (let i = 1; i <= 5; i += 1) {
|
|
674
|
-
docs.push({
|
|
675
|
-
path: `/p/i${i}.png`, rel: `i${i}.png`, name: `i${i}.png`, title: `图${i}`,
|
|
676
|
-
kind: 'image', summary: '', size: 1024, mtimeMs: now - i * 1000, score: null,
|
|
677
|
-
})
|
|
678
|
-
}
|
|
679
|
-
for (let i = 1; i <= 4; i += 1) {
|
|
680
|
-
docs.push({
|
|
681
|
-
path: `/p/v${i}.mp4`, rel: `v${i}.mp4`, name: `v${i}.mp4`, title: `视频${i}`,
|
|
682
|
-
kind: 'video', summary: '', size: 99999, mtimeMs: now - i * 1000, score: null,
|
|
683
|
-
})
|
|
684
|
-
}
|
|
685
|
-
return {
|
|
686
|
-
ok: true, root: '/p', total: docs.length, mode: 'time', topic: '', kind: 'all', docs,
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
|
|
690
663
|
/**
|
|
691
664
|
* 按 class **词**取节点。
|
|
692
665
|
*
|
|
@@ -726,18 +699,22 @@ test('媒体:isMedia 只认 image/video', () => {
|
|
|
726
699
|
assert.equal(isMedia(null), false)
|
|
727
700
|
})
|
|
728
701
|
|
|
729
|
-
test('媒体:类型偏好默认 doc
|
|
702
|
+
test('媒体:类型偏好默认 doc,合法值保留,老值 all 回落到 doc', () => {
|
|
730
703
|
const { readKindPref } = loadClientModule().exports.__test
|
|
731
704
|
assert.equal(readKindPref(), 'doc')
|
|
732
705
|
globalThis.window.localStorage.setItem('dsh-knit:kind', 'media')
|
|
733
706
|
assert.equal(readKindPref(), 'media')
|
|
707
|
+
globalThis.window.localStorage.setItem('dsh-knit:kind', 'code')
|
|
708
|
+
assert.equal(readKindPref(), 'code')
|
|
709
|
+
// v0.23.1(2026-10-12 用户裁决):「全部」档整体删除 ⇒ 老用户 localStorage 里存着
|
|
710
|
+
// `'all'` 时必须**回落到文档**(不空白、不抛)。证伪:把白名单里的 'all' 加回去,这行立刻红。
|
|
734
711
|
globalThis.window.localStorage.setItem('dsh-knit:kind', 'all')
|
|
735
|
-
assert.equal(readKindPref(), '
|
|
712
|
+
assert.equal(readKindPref(), 'doc')
|
|
736
713
|
globalThis.window.localStorage.setItem('dsh-knit:kind', 'garbage')
|
|
737
714
|
assert.equal(readKindPref(), 'doc')
|
|
738
715
|
})
|
|
739
716
|
|
|
740
|
-
test('
|
|
717
|
+
test('媒体:默认文档视图有**三个**类型按钮(文档/代码/媒体),但不出现媒体网格,计数仍按文档', async () => {
|
|
741
718
|
installFetch(kindResponder({ doc: listPayload() }))
|
|
742
719
|
const { KnitBody } = loadClientModule().exports.__test
|
|
743
720
|
harness.reset()
|
|
@@ -747,10 +724,11 @@ test('媒体:默认文档视图有四个类型按钮(文档/代码/媒体/
|
|
|
747
724
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
748
725
|
|
|
749
726
|
const btns = byClass(nodes, 'knit-type-btn')
|
|
750
|
-
// v0.
|
|
751
|
-
//
|
|
752
|
-
assert.equal(btns.length,
|
|
753
|
-
assert.deepEqual(btns.map(textOf), ['文档', '代码', '媒体'
|
|
727
|
+
// v0.23.1(2026-10-12 用户裁决):**三档**「文档 / 代码 / 媒体」——「全部」整体删除。
|
|
728
|
+
// 三档等距、下划线页签样式不变,**不留空位**(出现四个按钮或「全部」即红)。
|
|
729
|
+
assert.equal(btns.length, 3)
|
|
730
|
+
assert.deepEqual(btns.map(textOf), ['文档', '代码', '媒体'])
|
|
731
|
+
assert.ok(!btns.some((btn) => textOf(btn) === '全部'), '界面上不许再有「全部」这一档')
|
|
754
732
|
assert.equal(btns.find((b) => textOf(b) === '文档').props['aria-selected'], true)
|
|
755
733
|
assert.equal(byClass(nodes, 'knit-media-grid').length, 0)
|
|
756
734
|
assert.equal(byClass(nodes, 'knit-doc').length, 2)
|
|
@@ -851,218 +829,41 @@ test('媒体:点视频卡片就地预览,播放器 controls 且静音自动
|
|
|
851
829
|
assert.ok(!calls.some((u) => u.includes('/api/doc')), '视频不应触发正文请求')
|
|
852
830
|
})
|
|
853
831
|
|
|
854
|
-
/* ── v0.23
|
|
855
|
-
2026-10-12
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
`文档 / 代码 / 媒体` = 把同一个包(或同一批语料)过滤到某类。 */
|
|
860
|
-
|
|
861
|
-
/** 「全部」档的时间序载荷:7 文档 + 3 代码 + 5 图 + 4 视频 = 19 项。 */
|
|
862
|
-
function allKindsPayload() {
|
|
863
|
-
const now = Date.now()
|
|
864
|
-
const row = (i, rel, title, kind, size) => ({
|
|
865
|
-
path: `/p/${rel}`, rel, name: rel, title, kind,
|
|
866
|
-
summary: kind === 'md' || kind === 'code' ? '摘要' : '',
|
|
867
|
-
size, mtimeMs: now - i * 1000, score: null,
|
|
868
|
-
})
|
|
869
|
-
const docs = []
|
|
870
|
-
for (let i = 1; i <= 7; i += 1) docs.push(row(i, `d${i}.md`, `文档${i}`, 'md', 500))
|
|
871
|
-
for (let i = 1; i <= 3; i += 1) docs.push(row(i, `c${i}.ts`, `c${i}.ts`, 'code', 300))
|
|
872
|
-
for (let i = 1; i <= 5; i += 1) docs.push(row(i, `i${i}.png`, `图${i}`, 'image', 1024))
|
|
873
|
-
for (let i = 1; i <= 4; i += 1) docs.push(row(i, `v${i}.mp4`, `视频${i}`, 'video', 99999))
|
|
874
|
-
return { ok: true, root: '/p', total: docs.length, mode: 'time', topic: '', kind: 'all', docs }
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
/** 造一个「全部」档的包条目。 */
|
|
878
|
-
function allItem(rel, title, kind, reason) {
|
|
879
|
-
return {
|
|
880
|
-
rel,
|
|
881
|
-
path: `/p/${rel}`,
|
|
882
|
-
name: rel.split('/').pop(),
|
|
883
|
-
title,
|
|
884
|
-
summary: `摘要 ${title}`,
|
|
885
|
-
mtimeMs: Date.now(),
|
|
886
|
-
kind,
|
|
887
|
-
source: kind === 'code' ? 'impl' : 'doc',
|
|
888
|
-
reason,
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
/** 「全部」档的相关序载荷:包里**文档与代码在同一层**,媒体只在载荷里(不在包里)。 */
|
|
893
|
-
function allContextPayload(overrides = {}) {
|
|
894
|
-
const at = Date.now()
|
|
895
|
-
const row = (rel, title, kind, score) => ({
|
|
896
|
-
path: `/p/${rel}`, rel, name: rel.split('/').pop(), title, kind,
|
|
897
|
-
summary: '摘要', size: 500, mtimeMs: at, score,
|
|
898
|
-
})
|
|
899
|
-
return {
|
|
900
|
-
ok: true, root: '/p', total: 5, mode: 'relevance', topic: '排序', keywords: ['排序'],
|
|
901
|
-
kind: 'all',
|
|
902
|
-
docs: [
|
|
903
|
-
row('docs/algo.md', '排序算法', 'md', 90),
|
|
904
|
-
row('src/sort.ts', 'sort.ts', 'code', null),
|
|
905
|
-
row('README.md', 'Knit', 'md', 10),
|
|
906
|
-
row('docs/other.md', '其他', 'md', 0),
|
|
907
|
-
{
|
|
908
|
-
path: '/p/a.png', rel: 'a.png', name: 'a.png', title: '图', kind: 'image',
|
|
909
|
-
summary: '', size: 1024, mtimeMs: at, score: null,
|
|
910
|
-
},
|
|
911
|
-
],
|
|
912
|
-
context: {
|
|
913
|
-
mode: 'relevance', topic: '排序', task: '',
|
|
914
|
-
primary: [
|
|
915
|
-
allItem('docs/algo.md', '排序算法', 'md', { code: 'titleMatch', terms: ['排序'], fields: 2 }),
|
|
916
|
-
allItem('src/sort.ts', 'sort.ts', 'code', { code: 'filenameMatch', terms: ['sort'], fields: 1 }),
|
|
917
|
-
],
|
|
918
|
-
supporting: [
|
|
919
|
-
allItem('README.md', 'Knit', 'md', { code: 'bodyMatch', terms: ['排序'], fields: 1 }),
|
|
920
|
-
],
|
|
921
|
-
related: [
|
|
922
|
-
allItem('docs/other.md', '其他', 'md', { code: 'related', terms: [], fields: 0 }),
|
|
923
|
-
],
|
|
924
|
-
totals: { primary: 2, supporting: 1, related: 1, matched: 3, total: 5 },
|
|
925
|
-
summary: { primary: 2, supporting: 1, related: 1, shown: 4, matched: 3, total: 5 },
|
|
926
|
-
},
|
|
927
|
-
...overrides,
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
test('v0.23「全部」(时间序):平铺的文档 + 代码 + 末尾**不截断**的媒体网格,分区一个都没有', async () => {
|
|
932
|
-
installFetch(kindResponder({ all: allKindsPayload() }))
|
|
933
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
934
|
-
harness.reset()
|
|
935
|
-
harness.seed(['', 'time', 'all'])
|
|
936
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
937
|
-
await harness.flush()
|
|
938
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
939
|
-
|
|
940
|
-
// ① 成行的是文档 + 代码:7 + 3 = 10 条(旧实现只给 4 条文档 + 0 条代码)
|
|
941
|
-
assert.equal(byToken(nodes, 'knit-doc').length, 10, '文档与代码都在行里,一条都不截断')
|
|
942
|
-
// ② 媒体一格不隐藏,而且网格只有一种形态(不再是「分区里的网格」)
|
|
943
|
-
assert.equal(byToken(nodes, 'knit-media-card').length, 9, '9 个媒体全出')
|
|
944
|
-
const grids = byExactClass(nodes, 'knit-media-grid')
|
|
945
|
-
assert.equal(grids.length, 1, '只有一个媒体网格')
|
|
946
|
-
assert.equal(grids[0].props.style.maxHeight, undefined,
|
|
947
|
-
'网格不许设 maxHeight —— 纵向有多少行就铺多少行,滚动交给 .knit-list')
|
|
948
|
-
assert.equal(byClass(nodes, 'knit-media-grid in-section').length, 0, '分区形态的网格已删')
|
|
949
|
-
// ③ 分区那套**整体不在**
|
|
950
|
-
assert.equal(byExactClass(nodes, 'knit-section').length, 0)
|
|
951
|
-
assert.equal(byExactClass(nodes, 'knit-section-title').length, 0)
|
|
952
|
-
assert.equal(byExactClass(nodes, 'knit-section-more').length, 0, '没有「查看全部 →」了')
|
|
953
|
-
// ④ 媒体排在**所有行之后** —— 它是整份阅读顺序的尾巴,不与行穿插
|
|
954
|
-
const gridAt = nodes.indexOf(grids[0])
|
|
955
|
-
const lastRowAt = nodes.reduce((max, node, i) => (
|
|
956
|
-
String((node.props && node.props.className) || '').split(/\s+/).includes('knit-doc') ? i : max), -1)
|
|
957
|
-
assert.ok(lastRowAt >= 0 && gridAt > lastRowAt,
|
|
958
|
-
`媒体网格必须在最后一条行之后(grid=${gridAt},最后一行=${lastRowAt})`)
|
|
959
|
-
assert.match(byClass(nodes, 'knit-count').map(textOf).join(''), /^19$/, '顶行仍报总数')
|
|
960
|
-
})
|
|
961
|
-
|
|
962
|
-
test('v0.23「全部」(相关序):与「文档」档**同一套三层**,代码进层、媒体不进', async () => {
|
|
963
|
-
const { nodes } = await mountWithPayload(allContextPayload(), 'all')
|
|
964
|
-
// ① 三层标题与提示语与「文档」档逐字一致(不再有「文档 / 代码 / 媒体」三个分区标题)
|
|
965
|
-
assert.deepEqual(
|
|
966
|
-
byExactClass(nodes, 'knit-tiername').map(textOf),
|
|
967
|
-
['主要上下文', '辅助上下文', '相关上下文'],
|
|
968
|
-
)
|
|
969
|
-
assert.ok(
|
|
970
|
-
byExactClass(nodes, 'knit-tierhint').map(textOf).join(' ').includes('先看'),
|
|
971
|
-
'主要上下文照样有「先看」那句提示',
|
|
972
|
-
)
|
|
973
|
-
// ② 代码与文档**在同一层里**混排;媒体不进任何层
|
|
974
|
-
const tiers = byExactClass(nodes, 'knit-tier')
|
|
975
|
-
const inTier = (rel) => tiers.some((tier) => flattenUnder(tier)
|
|
976
|
-
.some((n) => n.props && n.props['data-knit-rel'] === rel))
|
|
977
|
-
assert.ok(inTier('docs/algo.md'))
|
|
978
|
-
assert.ok(inTier('src/sort.ts'), '代码进层(旧实现里它在一个单独的「代码」区里)')
|
|
979
|
-
assert.ok(!inTier('a.png'), '媒体不进层')
|
|
980
|
-
// ③ 媒体仍然渲染 —— 在三层之后的那个网格里
|
|
981
|
-
assert.equal(byToken(nodes, 'knit-media-card').length, 1)
|
|
982
|
-
})
|
|
983
|
-
|
|
984
|
-
test('v0.23「全部」↔「文档」:文档档的层 = 全部档的层**去掉代码与媒体**(同一份包)', async () => {
|
|
985
|
-
const pack = allContextPayload()
|
|
986
|
-
const all = await mountWithPayload({ ...pack, kind: 'all' }, 'all')
|
|
987
|
-
// 文档档的载荷里本来就不该有代码与媒体(宿主按 kind 过滤语料)
|
|
988
|
-
const doc = await mountWithPayload(
|
|
989
|
-
{ ...pack, kind: 'doc', docs: pack.docs.filter((d) => d.kind === 'md') },
|
|
990
|
-
'doc',
|
|
991
|
-
)
|
|
992
|
-
const relsInTiers = (nodes) => byExactClass(nodes, 'knit-tier').flatMap((tier) => flattenUnder(tier)
|
|
993
|
-
.map((n) => n.props && n.props['data-knit-rel'])
|
|
994
|
-
.filter(Boolean))
|
|
995
|
-
const allRels = relsInTiers(all.nodes)
|
|
996
|
-
const docRels = relsInTiers(doc.nodes)
|
|
997
|
-
assert.deepEqual(
|
|
998
|
-
docRels,
|
|
999
|
-
allRels.filter((rel) => rel.endsWith('.md')),
|
|
1000
|
-
'文档档 = 全部档里去掉代码与媒体(顺序也一致)',
|
|
1001
|
-
)
|
|
1002
|
-
assert.ok(allRels.includes('src/sort.ts'), '代码只出现在「全部」档')
|
|
1003
|
-
assert.ok(!allRels.includes('a.png') && !docRels.includes('a.png'), '媒体两档都不进层')
|
|
1004
|
-
})
|
|
1005
|
-
|
|
1006
|
-
test('v0.23「全部」:媒体**永远不进层**(第二道防线 —— 哪怕宿主把它塞进包里)', async () => {
|
|
1007
|
-
const hostile = allContextPayload()
|
|
1008
|
-
// 模拟「宿主把靠文件名命中的媒体塞进了层」:客户端必须自己把它挡在外面
|
|
1009
|
-
hostile.context.supporting = hostile.context.supporting.concat([
|
|
1010
|
-
allItem('a.png', '图', 'image', { code: 'semantic', terms: [], fields: 0, term: '' }),
|
|
1011
|
-
])
|
|
1012
|
-
const { nodes } = await mountWithPayload(hostile, 'all')
|
|
1013
|
-
const tiers = byExactClass(nodes, 'knit-tier')
|
|
1014
|
-
assert.ok(
|
|
1015
|
-
!tiers.some((tier) => flattenUnder(tier).some((n) => n.props && n.props['data-knit-rel'] === 'a.png')),
|
|
1016
|
-
'媒体绝不许被当成上下文条目渲染',
|
|
1017
|
-
)
|
|
1018
|
-
assert.equal(byToken(nodes, 'knit-media-card').length, 1, '它照旧在末尾的网格里(不消失)')
|
|
1019
|
-
})
|
|
1020
|
-
|
|
1021
|
-
test('v0.23「全部」:键盘能走到**每一个**条目(没有任何上限截断)', async () => {
|
|
1022
|
-
installFetch(kindResponder({ all: allKindsPayload() }))
|
|
1023
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
1024
|
-
harness.reset()
|
|
1025
|
-
harness.seed(['', 'time', 'all'])
|
|
1026
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1027
|
-
await harness.flush()
|
|
1028
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1029
|
-
|
|
1030
|
-
const visited = new Set()
|
|
1031
|
-
for (let i = 0; i < 30; i += 1) {
|
|
1032
|
-
// ⚠️ 每轮都要取**最新渲染**里的 list:`onKeyDown` 闭包捕获的是那一轮的 cursor,
|
|
1033
|
-
// 拿第一次的节点反复按,永远只能从第一条走到第二条(写完实测踩到)。
|
|
1034
|
-
byExactClass(nodes, 'knit-list')[0].props.onKeyDown({ key: 'ArrowDown', preventDefault() {} })
|
|
1035
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1036
|
-
await harness.flush()
|
|
1037
|
-
const current = byToken(nodes, 'cursor')[0]
|
|
1038
|
-
if (current) visited.add(String(current.props['data-knit-rel'] || ''))
|
|
1039
|
-
}
|
|
1040
|
-
// 旧实现里 d5–d7.md 与全部媒体都到不了(被每区 4 条与分区上限截断)
|
|
1041
|
-
assert.ok(visited.has('d7.md'), `被旧上限截断的文档现在必须可达:${[...visited].join(', ')}`)
|
|
1042
|
-
assert.ok(visited.has('i1.png'), '媒体格子同样可达(它们在末尾的网格里)')
|
|
1043
|
-
})
|
|
832
|
+
/* ── v0.23.1:「全部」档整体删除 ─────────────────────────────────────
|
|
833
|
+
2026-10-12 用户裁决:类型档只留三档,界面上不再有「全部」及其混合浏览视图
|
|
834
|
+
(「三层混排文档 + 代码 + 末尾媒体网格」那套整块消失)。
|
|
835
|
+
⇒ 这一组守卫查的是**源码里那些名字真的没了** —— 不是关掉、不是 display:none。
|
|
836
|
+
证伪方式:把任意一个名字放回源码,下面这条守卫立刻红(写完实测过一次)。 */
|
|
1044
837
|
|
|
1045
|
-
test('v0.23
|
|
838
|
+
test('v0.23.1:「全部」档在**源码里整体删除**(KIND_ALL / allRows / allMedia / 它的 i18n 键 / 分区特例)', async () => {
|
|
1046
839
|
const { readFileSync } = await import('node:fs')
|
|
1047
840
|
const { fileURLToPath } = await import('node:url')
|
|
1048
841
|
const source = readFileSync(
|
|
1049
842
|
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
1050
843
|
'utf8',
|
|
1051
844
|
)
|
|
1052
|
-
for (const dead of [
|
|
1053
|
-
|
|
845
|
+
for (const dead of [
|
|
846
|
+
'KIND_ALL', 'allRows', 'allMedia', 'flatRows',
|
|
847
|
+
"'kind.all'", "'count.all'", "'count.all.filtered'",
|
|
848
|
+
'knit-section', 'ALL_DOC_CAP', 'ALL_CODE_CAP', 'MOTION_TIER_ALL',
|
|
849
|
+
]) {
|
|
850
|
+
assert.ok(!source.includes(dead), `「全部」必须整体删除,源码里不该再有 ${dead}`)
|
|
1054
851
|
}
|
|
1055
|
-
//
|
|
852
|
+
// 类型档只剩三个值 —— 一行写得清清楚楚(多一档就会红)
|
|
853
|
+
assert.ok(
|
|
854
|
+
source.includes("[[KIND_DOC, 'kind.doc'], [KIND_CODE, 'kind.code'], [KIND_MEDIA, 'kind.media']]"),
|
|
855
|
+
'类型档就是三档',
|
|
856
|
+
)
|
|
1056
857
|
})
|
|
1057
858
|
|
|
1058
859
|
test('媒体:条目不多时卡片正常带文件名与时间,不让文字让位', async () => {
|
|
1059
860
|
// 1 篇文档 + 5 媒体(正好一屏内)
|
|
1060
861
|
const pool = mixedPayload().docs
|
|
1061
862
|
const docs = pool.slice(0, 1).concat(pool.filter((d) => d.kind !== 'md').slice(0, 4))
|
|
1062
|
-
installFetch(kindResponder({
|
|
863
|
+
installFetch(kindResponder({ media: mixedPayload({ total: docs.length, docs }) }))
|
|
1063
864
|
const { KnitBody } = loadClientModule().exports.__test
|
|
1064
865
|
harness.reset()
|
|
1065
|
-
harness.seed(['', 'time', '
|
|
866
|
+
harness.seed(['', 'time', 'media'])
|
|
1066
867
|
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1067
868
|
await harness.flush()
|
|
1068
869
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
@@ -3960,43 +3761,6 @@ test('v0.19 网页预览:只有 HTML 给这个入口,点了走官方标签
|
|
|
3960
3761
|
assert.ok(byExactClass(nodes, 'knit-codepane').length === 1, '它照旧走就地代码预览')
|
|
3961
3762
|
})
|
|
3962
3763
|
|
|
3963
|
-
test('v0.19 代码/v0.23「全部」:文档与代码混排在一条平铺列表里,媒体在末尾(不再有分区顺序)', async () => {
|
|
3964
|
-
const now = Date.now()
|
|
3965
|
-
const docs = []
|
|
3966
|
-
for (let i = 1; i <= 7; i += 1) {
|
|
3967
|
-
docs.push({
|
|
3968
|
-
path: `/p/d${i}.md`, rel: `d${i}.md`, name: `d${i}.md`, title: `文档${i}`,
|
|
3969
|
-
kind: 'md', summary: '摘要', size: 500, mtimeMs: now - i * 1000, score: null,
|
|
3970
|
-
})
|
|
3971
|
-
}
|
|
3972
|
-
for (let i = 1; i <= 3; i += 1) {
|
|
3973
|
-
docs.push({
|
|
3974
|
-
path: `/p/c${i}.ts`, rel: `c${i}.ts`, name: `c${i}.ts`, title: `c${i}.ts`,
|
|
3975
|
-
kind: 'code', summary: '实现', size: 300, mtimeMs: now - i * 1000, score: null,
|
|
3976
|
-
})
|
|
3977
|
-
}
|
|
3978
|
-
for (let i = 1; i <= 3; i += 1) {
|
|
3979
|
-
docs.push({
|
|
3980
|
-
path: `/p/i${i}.png`, rel: `i${i}.png`, name: `i${i}.png`, title: `图${i}`,
|
|
3981
|
-
kind: 'image', summary: '', size: 1024, mtimeMs: now - i * 1000, score: null,
|
|
3982
|
-
})
|
|
3983
|
-
}
|
|
3984
|
-
installFetch(kindResponder({ all: { ok: true, root: '/p', total: docs.length, mode: 'time', topic: '', kind: 'all', docs } }))
|
|
3985
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
3986
|
-
harness.reset()
|
|
3987
|
-
harness.seed(['', 'time', 'all'])
|
|
3988
|
-
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3989
|
-
let nodes = render()
|
|
3990
|
-
await harness.flush()
|
|
3991
|
-
nodes = render()
|
|
3992
|
-
|
|
3993
|
-
// v0.23(方案 A):**没有分区标题**,文档与代码在同一个平铺列表里,一条都不截断
|
|
3994
|
-
assert.equal(byExactClass(nodes, 'knit-section-title').length, 0, '分区标题已整体删除')
|
|
3995
|
-
assert.equal(byToken(nodes, 'knit-doc').length, 10, '文档 7 + 代码 3 全在行里')
|
|
3996
|
-
assert.equal(byExactClass(nodes, 'knit-lang').length, 3, '语言徽章跟着代码那几行')
|
|
3997
|
-
assert.equal(byToken(nodes, 'knit-media-card').length, 3, '媒体一格不隐藏')
|
|
3998
|
-
assert.match(byClass(nodes, 'knit-count').map(textOf).join(''), /^13$/, '顶行仍报总数')
|
|
3999
|
-
})
|
|
4000
3764
|
test('v0.19 代码:Usage Lens 里的代码路径照常显示(读的是一份事实、不是两套)', async () => {
|
|
4001
3765
|
installFetch(() => contextPayload({
|
|
4002
3766
|
usage: {
|
|
@@ -4926,10 +4690,11 @@ test('v0.21.x 检索状态摘要:单行三组、竖线分隔、组内中点,
|
|
|
4926
4690
|
assert.equal(pipe.length, 1)
|
|
4927
4691
|
|
|
4928
4692
|
// ① 逐个格子的**原文**,以及分隔符的种类与位置 —— 顺序就是这条设计要传达的信息
|
|
4929
|
-
|
|
4693
|
+
// 用**直接子节点**(flattenUnder 会把状态格内部的按钮/箭头也压平 ⇒ 同一格数三次)
|
|
4694
|
+
const seq = (pipe[0].children || []).map(textOf)
|
|
4930
4695
|
assert.deepEqual(seq, [
|
|
4931
4696
|
'收集 4', '·', '排除 1', '·', '候选 3', '|',
|
|
4932
|
-
'BM25
|
|
4697
|
+
'BM25 检索›', '·', '关系 1 条', '·', '固定 1', '|',
|
|
4933
4698
|
'入包 1',
|
|
4934
4699
|
], `三组 = 工作区候选 | 检索与调整 | 最终结果:${textOf(pipe[0])}`)
|
|
4935
4700
|
|
|
@@ -4937,7 +4702,7 @@ test('v0.21.x 检索状态摘要:单行三组、竖线分隔、组内中点,
|
|
|
4937
4702
|
assert.match(seq[0], /收集 4/, '收集 = 候选 + 本批真被排掉的(3 + 1)')
|
|
4938
4703
|
assert.match(seq[2], /排除 1/, '排除 = 宿主按候选集算的 skipped,不是 excluded 表的长度')
|
|
4939
4704
|
assert.match(seq[4], /候选 3/, '候选 = 排除之后进入检索的篇数(原来的光数字)')
|
|
4940
|
-
assert.match(seq[6], /BM25
|
|
4705
|
+
assert.match(seq[6], /BM25 检索/, '零模型这条路要说出来')
|
|
4941
4706
|
assert.match(seq[8], /关系 1 条/, '关系 = 这一份包里带了几条关系证据')
|
|
4942
4707
|
assert.match(seq[10], /固定 1/, '固定 = 被固定、从三层移出进了固定区的篇数')
|
|
4943
4708
|
assert.match(seq[12], /入包 1/, '入包 = 三层条目数(固定区不算)')
|
|
@@ -4956,16 +4721,15 @@ test('v0.21.x 检索状态摘要:单行三组、竖线分隔、组内中点,
|
|
|
4956
4721
|
}
|
|
4957
4722
|
})
|
|
4958
4723
|
|
|
4959
|
-
test('v0.21.x 工具栏:排序 | 竖线 |
|
|
4960
|
-
/* 2026-10-09
|
|
4961
|
-
|
|
4724
|
+
test('v0.21.x/v0.23.1 工具栏:排序 | 竖线 | 三档类型 | [检索模式 + 搜索框] 右对齐容器', async () => {
|
|
4725
|
+
/* 2026-10-09 用户规格 + 2026-10-12(v0.23.1 用户裁决):左侧「相关 / 最新」负责排序;
|
|
4726
|
+
中间「文档 / 代码 / 媒体」负责内容类型(**三档**);右侧是一个右对齐容器
|
|
4727
|
+
`.knit-bar-right`,里面是**检索模式小下拉(在左)+ 搜索框(在右)**。四条要守住:
|
|
4962
4728
|
① 各条件**不做成一个整体** —— 排序 / 类型 / 检索模式是三个条件,中间的浅灰竖线就是边界;
|
|
4963
|
-
②
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
所以竖线又从 2 根**回到 1 根**:左端只有「排序 | 类型」两组。
|
|
4968
|
-
它仍在工具栏里(只是嵌在搜索框里),而且**未配 provider 也在**(菜单里如实说状态)。 */
|
|
4729
|
+
② 右对齐容器里**只有搜索框**是可伸缩项(`flex:1 1 180px` + `max-width:240px` + `min-width:0`)
|
|
4730
|
+
⇒ 窄屏先缩搜索框,排序 / 类型 / 检索模式都是 `flex:none`;
|
|
4731
|
+
③ 条件彼此独立:选「代码」再选「最新」= 最新的代码,搜索词两边都不重置;
|
|
4732
|
+
④ 检索模式「最新」档不出现、但**不重置**偏好(v0.23 既有裁决)。 */
|
|
4969
4733
|
const { nodes: first, renderAgain } = await mountWithPayload(v021Payload())
|
|
4970
4734
|
let nodes = first
|
|
4971
4735
|
|
|
@@ -4989,32 +4753,36 @@ test('v0.21.x 工具栏:排序 | 竖线 | 类型 | 搜索一行,两组
|
|
|
4989
4753
|
const cls = under.map((n) => String(n.props.className || ''))
|
|
4990
4754
|
const at = (name) => cls.findIndex((c) => c === name)
|
|
4991
4755
|
|
|
4992
|
-
// ① 顺序:排序 →
|
|
4993
|
-
|
|
4756
|
+
// ① 顺序:排序 → 类型 → 右对齐容器(容器里:检索模式在左、搜索框在右)
|
|
4757
|
+
// ⚠️ 2026-10-12 用户裁决:排序与类型之间**那根竖线删掉了**,两组靠 .knit-bar 的 gap 分界。
|
|
4758
|
+
for (const name of ['knit-seg', 'knit-types', 'knit-bar-right', 'knit-searchwrap']) {
|
|
4994
4759
|
assert.ok(at(name) >= 0, `工具栏里必须有 ${name}:${cls.join(' / ')}`)
|
|
4995
4760
|
}
|
|
4996
|
-
assert.ok(at('knit-seg') < at('knit-
|
|
4997
|
-
assert.ok(at('knit-
|
|
4998
|
-
assert.
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
//
|
|
5002
|
-
assert.equal(byClass(nodes, 'knit-bar-sep').length,
|
|
5003
|
-
//
|
|
5004
|
-
const
|
|
5005
|
-
|
|
5006
|
-
|
|
4761
|
+
assert.ok(at('knit-seg') < at('knit-types'), '排序组在类型组左边,而且紧邻(中间没有竖线)')
|
|
4762
|
+
assert.ok(at('knit-types') < at('knit-bar-right'), '右对齐容器排在类型组右边')
|
|
4763
|
+
assert.equal(directOf(bar[0]).at(-1), 'knit-bar-right',
|
|
4764
|
+
'右对齐容器是工具栏里最后一个直接子节点(工具栏尾部)')
|
|
4765
|
+
// 2026-10-12 用户裁决:**竖线一根都不留**(排序 / 类型之间靠 gap 分界)。
|
|
4766
|
+
// 这条是可证伪的:把任何一个 .knit-bar-sep 节点加回工具栏就会红。
|
|
4767
|
+
assert.equal(byClass(nodes, 'knit-bar-sep').length, 0, '工具栏里没有任何竖线了')
|
|
4768
|
+
// v0.24(2026-10-12 用户裁决):右对齐容器里**只剩搜索框** —— 检索方式搬去状态行了。
|
|
4769
|
+
const rightBox = byExactClass(nodes, 'knit-bar-right')[0]
|
|
4770
|
+
const inRight = flattenUnder(rightBox)
|
|
4771
|
+
assert.equal(byClass(inRight, 'knit-searchwrap').length, 1, '搜索框仍在右对齐容器里(靠右)')
|
|
4772
|
+
assert.equal(byClass(inRight, 'knit-retmode-btn').length, 0,
|
|
4773
|
+
'第二行里**没有**检索方式控件了(连旧类名都不许出现)')
|
|
4774
|
+
assert.equal(byClass(inRight, 'knit-pipe-method').length, 0,
|
|
4775
|
+
'状态行那个可点状态格也不许混进工具栏第二行')
|
|
5007
4776
|
assert.equal(byClass(under, 'knit-retseg').length, 0,
|
|
5008
4777
|
'左端不再有检索模式那一组(.knit-retseg 只剩配置区在用)')
|
|
5009
|
-
|
|
5010
|
-
assert.equal(sep.props['aria-hidden'], 'true', '分隔线是装饰,不进可达性树')
|
|
5011
|
-
}
|
|
4778
|
+
assert.equal(byExactClass(nodes, 'knit-bar-sep').length, 0, '连装饰用的竖线节点也不存在')
|
|
5012
4779
|
|
|
5013
4780
|
// ② 各条件都在,而且各用各的控件(不是把条件连排成一串按钮)
|
|
5014
4781
|
assert.deepEqual(byClass(under, 'knit-seg-btn').map(textOf), ['相关', '最新'])
|
|
5015
|
-
assert.deepEqual(byClass(under, 'knit-type-btn').map(textOf), ['文档', '代码', '媒体',
|
|
5016
|
-
|
|
5017
|
-
|
|
4782
|
+
assert.deepEqual(byClass(under, 'knit-type-btn').map(textOf), ['文档', '代码', '媒体'],
|
|
4783
|
+
'v0.23.1(2026-10-12):「全部」整体删除 ⇒ 三档')
|
|
4784
|
+
assert.equal(byClass(under, 'knit-retmode-btn').length + byClass(under, 'knit-pipe-method').length, 0,
|
|
4785
|
+
'v0.24:第二行只有排序 / 类型 / 搜索三样,检索方式不在这里')
|
|
5018
4786
|
for (const node of under) {
|
|
5019
4787
|
assert.ok(!/^(svg|path|use|img|i)$/.test(String(node.type)), `不许加图标:${String(node.type)}`)
|
|
5020
4788
|
}
|
|
@@ -5045,21 +4813,245 @@ test('v0.21.x 工具栏:排序 | 竖线 | 类型 | 搜索一行,两组
|
|
|
5045
4813
|
assert.ok(m, `必须有 .${sel} 这条规则`)
|
|
5046
4814
|
return m[1]
|
|
5047
4815
|
}
|
|
4816
|
+
// 伪类 / 多选择器那类规则(`.a:hover,.a:focus-visible{…}`)—— 取规则体,取不到就红。
|
|
4817
|
+
// ⚠️ 不能用 rule():它的正则要求 `.sel` 后面紧跟 `{`,多选择器会漏。
|
|
4818
|
+
const rule2 = (sel) => {
|
|
4819
|
+
const m = source.match(new RegExp(`\\.${sel}[^{]*\\{([^}]*)\\}`))
|
|
4820
|
+
assert.ok(m, `必须有 .${sel} 这条规则`)
|
|
4821
|
+
return m[1]
|
|
4822
|
+
}
|
|
5048
4823
|
// v0.23(2026-10-11):这几条量的是**搜索框容器**(描边与宽度都在容器上,输入框只管输入)
|
|
5049
4824
|
const wrapCss = rule('knit-searchwrap')
|
|
5050
4825
|
assert.match(wrapCss, /flex:1 1 180px/, '搜索框:基础宽 180px,可长可缩')
|
|
5051
4826
|
assert.match(wrapCss, /max-width:240px/, '搜索框封顶 240px(常规面板 180–240px)')
|
|
5052
|
-
assert.match(wrapCss, /margin-left:auto/, '封顶后剩下的空间留在左边 ⇒ 搜索框贴住右端')
|
|
5053
4827
|
assert.match(wrapCss, /min-width:0/, '面板窄了先缩搜索框')
|
|
4828
|
+
assert.ok(!/margin-left:auto/.test(wrapCss),
|
|
4829
|
+
'v0.23.1:margin-left:auto 已移交右对齐容器 —— 搜索框自己不再贴右')
|
|
4830
|
+
const rightCss = rule('knit-bar-right')
|
|
4831
|
+
assert.match(rightCss, /margin-left:auto/, '右对齐容器承担 margin-left:auto')
|
|
4832
|
+
assert.match(rightCss, /min-width:0/, '容器也要能缩,否则里面那项缩不动')
|
|
4833
|
+
const wrapCss2 = rule('knit-pipe-method-wrap')
|
|
4834
|
+
assert.match(wrapCss2, /position:relative/, '状态格自己的定位上下文(菜单相对它弹)')
|
|
4835
|
+
assert.match(wrapCss2, /flex:none/, '状态格不参与伸缩')
|
|
5054
4836
|
const filter = rule('knit-filter')
|
|
5055
|
-
assert.match(filter, /flex:1 1 auto/, '
|
|
4837
|
+
assert.match(filter, /flex:1 1 auto/, '输入框吃掉搜索框容器里剩下的宽度')
|
|
5056
4838
|
assert.match(filter, /min-width:0/, '输入框也要能缩')
|
|
5057
4839
|
assert.match(rule('knit-seg'), /flex:none/, '排序组不被挤')
|
|
5058
4840
|
assert.match(rule('knit-types'), /flex:none/, '类型组不被挤')
|
|
5059
4841
|
assert.ok(!/\.knit-types\{[^}]*padding/.test(source), '类型组不再自带左右内边距(.knit-bar 统一给)')
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
4842
|
+
assert.ok(!/\.knit-bar-sep\{/.test(source), '竖线的 CSS 规则也整体删除了(不是留着不用)')
|
|
4843
|
+
const methodCss = rule('knit-pipe-method')
|
|
4844
|
+
// 2026-10-12 第三次裁决:这一格的视觉**照命中段(.knit-hit)那套**来 —— 同一份视觉语言复用,
|
|
4845
|
+
// 不是新造一个控件。所以这里不只钉数值,还**逐值比对 .knit-hit**:两边必须同源,
|
|
4846
|
+
// 将来谁改了命中段而没改这一格,这条就会红。
|
|
4847
|
+
const hitCss = rule('knit-hit')
|
|
4848
|
+
for (const [label, re] of [
|
|
4849
|
+
['底 = --knit-chip-bg(三档灰底最深那档,命中段同源)', /background:var\(--knit-chip-bg/],
|
|
4850
|
+
['圆角 6px(命中段同值)', /border-radius:6px/],
|
|
4851
|
+
['内边距 1px 6px(命中段同值)', /padding:1px 6px/],
|
|
4852
|
+
]) {
|
|
4853
|
+
assert.match(methodCss, re, `状态格:${label}`)
|
|
4854
|
+
assert.match(hitCss, re, `命中段自己也必须是这个值,否则「参考命中段」就名不副实:${label}`)
|
|
4855
|
+
}
|
|
4856
|
+
assert.match(methodCss, /color:var\(--dsw-alias-label-secondary/,
|
|
4857
|
+
'字色 = 次级灰(命中段的静止态同款)')
|
|
4858
|
+
assert.ok(!/border-bottom|border:0\.5px/.test(methodCss), '描边一根都没有(命中段也是)')
|
|
4859
|
+
// 2026-10-13 用户裁决:「› 悬停时不用带下划线」⇒ 下划线从按钮挪到**包文字的那一层**。
|
|
4860
|
+
// 结构上必须分家:父级的 text-decoration 传播到全部子节点、子级又取消不掉。
|
|
4861
|
+
const hoverCss = rule2('knit-pipe-method:hover')
|
|
4862
|
+
assert.ok(!/text-decoration/.test(hoverCss),
|
|
4863
|
+
'按钮自己的 hover 不许带下划线 —— 那会连右边那个箭头 › 一起划上')
|
|
4864
|
+
assert.match(rule2('knit-pipe-method:hover .knit-pipe-method-label'),
|
|
4865
|
+
/text-decoration:underline/, '下划线只划文字那一层')
|
|
4866
|
+
// 字号 / 行高 / 字重:2026-10-13 用户裁决「字号与背景胶囊修改成命中段一样」⇒ 也逐值比对命中段。
|
|
4867
|
+
const fontOf = (css) => (css.match(/font-size:([\d.]+px)/) || [])[1]
|
|
4868
|
+
const lhOf = (css) => (css.match(/line-height:([\d.]+px)/) || [])[1]
|
|
4869
|
+
assert.equal(fontOf(methodCss), fontOf(hitCss),
|
|
4870
|
+
`字号必须与命中段同值(命中段 ${fontOf(hitCss)},状态格 ${fontOf(methodCss)})`)
|
|
4871
|
+
assert.equal(lhOf(methodCss), lhOf(hitCss),
|
|
4872
|
+
`行高必须与命中段同值(命中段 ${lhOf(hitCss)},状态格 ${lhOf(methodCss)})`)
|
|
4873
|
+
assert.match(methodCss, /font:inherit/, '字体族与字重跟随所在行(命中段同款写法:font:inherit)')
|
|
4874
|
+
assert.ok(!/font-weight/.test(methodCss) && !/font-weight/.test(hitCss),
|
|
4875
|
+
'两边都不自己定字重 —— 都跟随所在行,才不会一边 500 一边 400')
|
|
4876
|
+
assert.ok(!/--knit-accent/.test(methodCss), '不用品牌色(状态格不是主操作)')
|
|
4877
|
+
|
|
4878
|
+
// 菜单里那两个可选项也要跟命中段同源(用户:「对,就这样修改」)——
|
|
4879
|
+
// 圆角 6px 同值;**选中态**底换成命中段那档 --knit-chip-bg(原来是行选中那档)。
|
|
4880
|
+
const itemCss = rule('knit-retmenu-item')
|
|
4881
|
+
const radiusOf = (css) => (css.match(/border-radius:(\d+)px/) || [])[1]
|
|
4882
|
+
assert.equal(radiusOf(itemCss), radiusOf(hitCss),
|
|
4883
|
+
`菜单选项圆角必须与命中段同值(命中段 ${radiusOf(hitCss)}px)`)
|
|
4884
|
+
const bgOf = (css) => (css.match(/background:var\((--knit-[a-z-]+)/) || [])[1]
|
|
4885
|
+
assert.equal(bgOf(rule2('knit-retmenu-item.active')), bgOf(hitCss),
|
|
4886
|
+
`菜单选中态底必须与命中段同一档(命中段 ${bgOf(hitCss)})`)
|
|
4887
|
+
assert.match(rule('knit-retmenu-cfg'), /border-radius:6px/, '就地配置入口同一套圆角')
|
|
4888
|
+
// ⚠️ 但菜单**面板**仍是浮层:底/描边/阴影一个都不许少(压成灰胶囊就没有层级了)
|
|
4889
|
+
const menuPanel = rule('knit-retmenu')
|
|
4890
|
+
assert.match(menuPanel, /background:var\(--dsw-alias-bg-base/,
|
|
4891
|
+
'面板保持阅读底色 —— 浮层必须读起来像浮层')
|
|
4892
|
+
assert.match(menuPanel, /border:0\.5px solid var\(--dsw-alias-border-l3/, '面板保留 l3 描边')
|
|
4893
|
+
assert.match(menuPanel, /box-shadow/, '面板保留阴影(与状态格区分层级)')
|
|
4894
|
+
const goCss = rule('knit-pipe-method-go')
|
|
4895
|
+
assert.match(goCss, /transform:rotate\(90deg\)/, '关闭态:› 旋转 90° ⇒ 朝下')
|
|
4896
|
+
// ── 箭头的**几何**守卫(2026-10-13):光盯 CSS 文本会漏掉「看起来没变」的写法。
|
|
4897
|
+
// 上一版写的是 `rotate(90deg) scaleY(-1)` —— 文本上「有翻转」,实际是**空操作**:
|
|
4898
|
+
// › 本来就沿水平轴对称,上下镜像后还是它自己,算出来仍朝下。用户当场抓到。
|
|
4899
|
+
// 所以这里把 transform 真算成 2×2 矩阵、作用在「右箭头」的方向向量 (1,0) 上:
|
|
4900
|
+
// 关闭态必须 = (0,1) 朝下;展开态必须 = (0,-1) 朝上。
|
|
4901
|
+
const openArrow = source.match(/\.knit-pipe-method\[aria-expanded="true"\] \.knit-pipe-method-go\{([^}]*)\}/)
|
|
4902
|
+
assert.ok(openArrow, '必须有展开态的箭头规则')
|
|
4903
|
+
const fnsOf = (css) => (css.match(/transform:([^;}]+)/) || [])[1].trim().split(/\s+(?=[a-zA-Z])/)
|
|
4904
|
+
const matOf = (fn) => {
|
|
4905
|
+
const rot = fn.match(/^rotate\((-?[\d.]+)deg\)$/)
|
|
4906
|
+
if (rot) { const a = Number(rot[1]) * Math.PI / 180; return [Math.cos(a), -Math.sin(a), Math.sin(a), Math.cos(a)] }
|
|
4907
|
+
if (fn === 'scaleX(-1)') return [-1, 0, 0, 1]
|
|
4908
|
+
if (fn === 'scaleY(-1)') return [1, 0, 0, -1]
|
|
4909
|
+
if (/^scale\(1\)$/.test(fn)) return [1, 0, 0, 1]
|
|
4910
|
+
throw new Error(`几何守卫不认识的 transform 函数:${fn}`)
|
|
4911
|
+
}
|
|
4912
|
+
const mul = (A, B) => [A[0] * B[0] + A[1] * B[2], A[0] * B[1] + A[1] * B[3],
|
|
4913
|
+
A[2] * B[0] + A[3] * B[2], A[2] * B[1] + A[3] * B[3]]
|
|
4914
|
+
/** CSS 的 transform 列表是「最右边的先作用在点上」⇒ M = f1·f2·…,从右往左乘。 */
|
|
4915
|
+
const dirOf = (css) => {
|
|
4916
|
+
let M = [1, 0, 0, 1]
|
|
4917
|
+
for (const fn of fnsOf(css).reverse()) M = mul(matOf(fn), M)
|
|
4918
|
+
// `|| 0` 把 -0 归一成 0:assert/strict 的 deepEqual 用 Object.is,-0 与 0 不相等
|
|
4919
|
+
return [Math.round(M[0]) || 0, Math.round(M[2]) || 0] // 基础字形 › 指向 (1,0)
|
|
4920
|
+
}
|
|
4921
|
+
assert.deepEqual(dirOf(goCss), [0, 1], '关闭态:箭头朝下')
|
|
4922
|
+
assert.deepEqual(dirOf(openArrow[1]), [0, -1], '展开态:箭头朝上(横向翻转,不是空操作)')
|
|
4923
|
+
assert.match(openArrow[1], /scaleX\(-1\)/,
|
|
4924
|
+
'展开态是**横向翻转** scaleX(-1)(scaleY(-1) 对 › 是空操作)')
|
|
4925
|
+
assert.ok(!/rotate\(-90deg\)/.test(openArrow[1]),
|
|
4926
|
+
'不许用 rotate(-90deg) 对调角度:那是原地转 180°(风车),交互不对')
|
|
4927
|
+
assert.match(goCss, /transition:transform/, '翻转要有过渡(0.14s)——它是动画,不是瞬变')
|
|
4928
|
+
const menuCss = rule('knit-retmenu')
|
|
4929
|
+
assert.match(menuCss, /left:0/, 'v0.24:菜单相对状态格定位(left:0)')
|
|
4930
|
+
assert.match(menuCss, /top:22px/, '紧贴状态格下方')
|
|
4931
|
+
assert.ok(!/right:0/.test(menuCss), '不再沿用工具栏那套 right:0 / top:32px')
|
|
4932
|
+
// 词典里不许再留着 ⌄(它曾经是「文案的一部分」,读屏会把箭头念出来)——现在盯的是**活的**标签键:
|
|
4933
|
+
// 状态格可见文案 = pipe.rank / pipe.rankHybrid,两本词典各一遍,所以每次必须正好命中 2 条。
|
|
4934
|
+
for (const key of ['pipe.rank', 'pipe.rankHybrid']) {
|
|
4935
|
+
const values = [...source.matchAll(new RegExp(`'${key.replace('.', '\\.')}': '([^']*)'`, 'g'))].map((m) => m[1])
|
|
4936
|
+
assert.equal(values.length, 2, `${key} 在 ZH / EN 里各一遍,实际 ${values.length} 条`)
|
|
4937
|
+
for (const value of values) {
|
|
4938
|
+
assert.ok(value.length > 0 && !value.includes('⌄'), `${key} 不许再带 ⌄ 字形:${value}`)
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
// 旧的两个短标签键必须**整个删掉**,不是留着不用(2026-10-13 死键清理):
|
|
4942
|
+
// 它们曾经是工具栏下拉的按钮文案,控件搬进状态行后就没有任何渲染路径了。
|
|
4943
|
+
for (const dead of ['sem.mode.lexicalShort', 'sem.mode.hybridShort']) {
|
|
4944
|
+
assert.equal(source.includes(`'${dead}'`), false, `${dead} 是死键,应已删除`)
|
|
4945
|
+
}
|
|
4946
|
+
})
|
|
4947
|
+
|
|
4948
|
+
/* ── v0.23.1:三档各自的过滤 + 四项状态独立性 ─────────────────────────
|
|
4949
|
+
用户要求 7/8:类型档只留三档,且**排序 / 类型 / 搜索 / 检索模式**四项互不重置。 */
|
|
4950
|
+
|
|
4951
|
+
/** 一份 md + code + image 混排载荷,并按 kind 分桶回给客户端。 */
|
|
4952
|
+
function threeKindsResponder() {
|
|
4953
|
+
const now = Date.now()
|
|
4954
|
+
const doc = (rel, kind, extra = {}) => ({
|
|
4955
|
+
path: `/p/${rel}`, rel, name: rel, title: rel, kind,
|
|
4956
|
+
summary: kind === 'image' ? '' : '摘要', size: 500, mtimeMs: now, score: null, ...extra,
|
|
4957
|
+
})
|
|
4958
|
+
const md = [doc('a.md', 'md'), doc('b.md', 'md')]
|
|
4959
|
+
const code = [doc('s.ts', 'code', { language: 'typescript' })]
|
|
4960
|
+
const media = [doc('i.png', 'image')]
|
|
4961
|
+
const all = md.concat(code, media)
|
|
4962
|
+
const listPayload = (docs) => ({ ok: true, root: '/p', total: docs.length, mode: 'time', topic: '', kind: 'all', docs })
|
|
4963
|
+
return kindResponder({ doc: listPayload(md), code: listPayload(code), media: listPayload(media), all: listPayload(all) })
|
|
4964
|
+
}
|
|
4965
|
+
|
|
4966
|
+
test('v0.23.1 类型档:三档各自的过滤 —— 文档档只出文档、代码档只出代码、媒体档只出媒体网格', async () => {
|
|
4967
|
+
installFetch(threeKindsResponder())
|
|
4968
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
4969
|
+
harness.reset()
|
|
4970
|
+
harness.seed(['', 'time']) // 默认文档档
|
|
4971
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
4972
|
+
let nodes = render()
|
|
4973
|
+
await harness.flush()
|
|
4974
|
+
nodes = render()
|
|
4975
|
+
|
|
4976
|
+
const tab = (label) => byClass(nodes, 'knit-type-btn').find((b) => textOf(b) === label)
|
|
4977
|
+
const rows = () => byToken(nodes, 'knit-doc').map((n) => n.props['data-knit-rel'])
|
|
4978
|
+
const media = () => byToken(nodes, 'knit-media-card')
|
|
4979
|
+
// 切档会触发一次新的取数 ⇒ 必须「先渲染(登记 effect)→ flush(跑 effect)→ 再渲染」
|
|
4980
|
+
const step = async () => { nodes = render(); await harness.flush(); nodes = render() }
|
|
4981
|
+
|
|
4982
|
+
// ① 文档档:只有那两篇 .md,没有网格
|
|
4983
|
+
assert.deepEqual(rows().sort(), ['a.md', 'b.md'], '文档档只出文档')
|
|
4984
|
+
assert.equal(media().length, 0, '文档档不出媒体网格')
|
|
4985
|
+
|
|
4986
|
+
// ② 代码档:只有那个 .ts(语言徽章跟着它),没有媒体网格
|
|
4987
|
+
tab('代码').props.onClick()
|
|
4988
|
+
await step()
|
|
4989
|
+
assert.deepEqual(rows(), ['s.ts'], '代码档只出代码')
|
|
4990
|
+
assert.equal(byExactClass(nodes, 'knit-lang').length, 1, '代码行带语言徽章')
|
|
4991
|
+
assert.equal(media().length, 0, '代码档不出媒体网格')
|
|
4992
|
+
|
|
4993
|
+
// ③ 媒体档:一个文档行都不渲染,只有方形网格
|
|
4994
|
+
tab('媒体').props.onClick()
|
|
4995
|
+
await step()
|
|
4996
|
+
assert.equal(rows().length, 0, '媒体档不渲染任何文档行')
|
|
4997
|
+
assert.equal(media().length, 1, '媒体档渲染媒体网格')
|
|
4998
|
+
assert.equal(byExactClass(nodes, 'knit-media-grid').length, 1, '网格在')
|
|
4999
|
+
})
|
|
5000
|
+
|
|
5001
|
+
test('v0.23.1 状态独立性:排序 / 类型 / 搜索 / 检索模式 四项互不重置(含「最新→相关」后 hybrid 仍在)', async () => {
|
|
5002
|
+
const payload = v021Payload()
|
|
5003
|
+
installSemanticFetch(payload)
|
|
5004
|
+
// 预置「混合」:偏好必须在 harness.reset() 之后写(mountV023 内部就是这么做的)
|
|
5005
|
+
const { nodes: first, renderAgain } = await mountV023(payload, 'hybrid')
|
|
5006
|
+
let nodes = first
|
|
5007
|
+
|
|
5008
|
+
const activeKind = () => textOf(byClass(nodes, 'knit-type-btn').find((n) => String(n.props.className).includes('active')))
|
|
5009
|
+
const activeSort = () => textOf(byClass(nodes, 'knit-seg-btn').find((n) => String(n.props.className).includes('active')))
|
|
5010
|
+
const queryValue = () => byClass(nodes, 'knit-filter')[0].props.value
|
|
5011
|
+
const modeLabel = () => (byExactClass(nodes, 'knit-pipe-method')[0] ? textOf(byExactClass(nodes, 'knit-pipe-method')[0]) : null)
|
|
5012
|
+
|
|
5013
|
+
// ⚠️ 状态格写的是**实际生效**的模式(`semantic.mode`),不是「你点了什么」:
|
|
5014
|
+
// 载荷没报 hybrid 生效时,它就必须还写「BM25 检索」。所以这里先记下初值,
|
|
5015
|
+
// 后面用「切来切去它不变 + 盘上偏好仍是 hybrid」来证「没有被重置」。
|
|
5016
|
+
const modeAtStart = modeLabel()
|
|
5017
|
+
assert.ok(modeAtStart && modeAtStart.startsWith('BM25'), `状态格要有文案:${modeAtStart}`)
|
|
5018
|
+
assert.equal(globalThis.window.localStorage.getItem('dsh-knit:retrieval'), 'hybrid', '预置偏好已落盘')
|
|
5019
|
+
|
|
5020
|
+
// ① 先写一个搜索词 + 切到代码档
|
|
5021
|
+
byClass(nodes, 'knit-filter')[0].props.onChange({ target: { value: '排序' } })
|
|
5022
|
+
nodes = await renderAgain()
|
|
5023
|
+
byClass(nodes, 'knit-type-btn').find((b) => textOf(b) === '代码').props.onClick()
|
|
5024
|
+
nodes = await renderAgain()
|
|
5025
|
+
assert.equal(activeKind(), '代码', '类型切到代码')
|
|
5026
|
+
assert.equal(queryValue(), '排序', '切类型不重置搜索词')
|
|
5027
|
+
assert.equal(activeSort(), '相关', '切类型不重置排序')
|
|
5028
|
+
assert.equal(modeLabel(), modeAtStart, '切类型不重置检索模式')
|
|
5029
|
+
|
|
5030
|
+
// ② 切「最新」:类型与搜索词都不变;状态行那一格**整行不出现**但偏好不重置
|
|
5031
|
+
byClass(nodes, 'knit-seg-btn').find((b) => textOf(b) === '最新').props.onClick()
|
|
5032
|
+
nodes = await renderAgain()
|
|
5033
|
+
assert.equal(activeSort(), '最新', '排序切到最新')
|
|
5034
|
+
assert.equal(activeKind(), '代码', '切排序不重置类型')
|
|
5035
|
+
assert.equal(queryValue(), '排序', '切排序不重置搜索词')
|
|
5036
|
+
assert.equal(globalThis.window.localStorage.getItem('dsh-knit:retrieval'), 'hybrid',
|
|
5037
|
+
'只隐藏、不重置:偏好仍在盘上')
|
|
5038
|
+
|
|
5039
|
+
// ③ 切回「相关」:状态格自己长回来,而且仍写着混合(这是要求 8 的核心)
|
|
5040
|
+
byClass(nodes, 'knit-seg-btn').find((b) => textOf(b) === '相关').props.onClick()
|
|
5041
|
+
nodes = await renderAgain()
|
|
5042
|
+
assert.equal(modeLabel(), modeAtStart, '「最新 → 相关」之后词法/混合偏好仍在(格子写的东西没变)')
|
|
5043
|
+
assert.equal(activeKind(), '代码', '来回切排序,类型仍是代码')
|
|
5044
|
+
assert.equal(queryValue(), '排序', '来回切排序,搜索词仍在')
|
|
5045
|
+
|
|
5046
|
+
// ④ 切检索模式:前三项一个都不许被重置
|
|
5047
|
+
byExactClass(nodes, 'knit-pipe-method')[0].props.onClick()
|
|
5048
|
+
nodes = await renderAgain()
|
|
5049
|
+
byClass(nodes, 'knit-retmenu-item')[0].props.onClick() // 选「词法检索」
|
|
5050
|
+
nodes = await renderAgain()
|
|
5051
|
+
assert.equal(modeLabel(), modeAtStart, '切检索模式不重置其它三项;格子仍如实写实际生效的模式')
|
|
5052
|
+
assert.equal(activeSort(), '相关', '切检索模式不重置排序')
|
|
5053
|
+
assert.equal(activeKind(), '代码', '切检索模式不重置类型')
|
|
5054
|
+
assert.equal(queryValue(), '排序', '切检索模式不重置搜索词')
|
|
5063
5055
|
})
|
|
5064
5056
|
|
|
5065
5057
|
test('v0.21.x 开关「使用情况」不许把检索状态摘要顶下去(摘要紧贴工具栏,观察层在它下面)', async () => {
|
|
@@ -5263,11 +5255,13 @@ function allText(nodes) {
|
|
|
5263
5255
|
return flattenUnder(root).map(textOf).join(' | ')
|
|
5264
5256
|
}
|
|
5265
5257
|
|
|
5266
|
-
test('v0.
|
|
5258
|
+
test('v0.24:默认词法 —— 状态行那格可点(BM25 检索 + ›),未配 provider 也在', async () => {
|
|
5267
5259
|
const { nodes } = await mountWithPayload(v021Payload())
|
|
5268
|
-
const btns =
|
|
5269
|
-
assert.equal(btns.length, 1, '未配 provider
|
|
5270
|
-
assert.equal(textOf(btns[0]), '
|
|
5260
|
+
const btns = byExactClass(nodes, 'knit-pipe-method')
|
|
5261
|
+
assert.equal(btns.length, 1, '未配 provider 时这一格**也在**(没有设置页 ⇒ 藏起来就永远打不开)')
|
|
5262
|
+
assert.equal(textOf(btns[0]), 'BM25 检索›', '状态文案 + 一个装饰箭头 ›')
|
|
5263
|
+
assert.equal(byExactClass(flattenUnder(byExactClass(nodes, 'knit-pipe')[0]), 'knit-pipe-method').length, 1,
|
|
5264
|
+
'它必须**长在状态行里**(不是工具栏第二行)')
|
|
5271
5265
|
assert.equal(btns[0].props['aria-haspopup'], 'true')
|
|
5272
5266
|
assert.equal(btns[0].props['aria-expanded'], false, '默认收起')
|
|
5273
5267
|
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, '收起时菜单一个节点都不产生(不是 display:none)')
|
|
@@ -5275,7 +5269,39 @@ test('v0.23(2026-10-11):默认词法 —— 下拉在搜索框右端、标
|
|
|
5275
5269
|
assert.equal(byExactClass(nodes, 'knit-semcfg').length, 0, '词法模式:配置区不出现')
|
|
5276
5270
|
const text = allText(nodes)
|
|
5277
5271
|
assert.ok(!text.includes('语义候选'), `词法模式不许出现语义候选的计数:${text}`)
|
|
5278
|
-
assert.ok(text.includes('BM25
|
|
5272
|
+
assert.ok(text.includes('BM25 检索'), '摘要里那格仍然如实写着词法检索')
|
|
5273
|
+
})
|
|
5274
|
+
|
|
5275
|
+
test('v0.24:状态行那格是**真 button**,菜单相对它弹出(不在工具栏那套定位上)', async () => {
|
|
5276
|
+
const { nodes: first, render } = await mountV023(v021Payload())
|
|
5277
|
+
let nodes = first
|
|
5278
|
+
const cell = byExactClass(nodes, 'knit-pipe-method')[0]
|
|
5279
|
+
assert.equal(String(cell.type), 'button', '是真 button,不是可点的 span')
|
|
5280
|
+
// 文字 / 箭头分属两层:下划线划不到箭头(上一条 CSS 守卫的结构面)
|
|
5281
|
+
const labelNode = byExactClass(flattenUnder(cell), 'knit-pipe-method-label')[0]
|
|
5282
|
+
const arrowNode = byExactClass(flattenUnder(cell), 'knit-pipe-method-go')[0]
|
|
5283
|
+
assert.ok(labelNode && arrowNode, '文字那一层与箭头都在')
|
|
5284
|
+
assert.equal(textOf(labelNode), 'BM25 检索', '文字层只包文字(不含箭头)')
|
|
5285
|
+
assert.ok(!(labelNode.children || []).includes(arrowNode),
|
|
5286
|
+
'箭头**不在**文字层里 —— 否则悬停下划线会把它也划上')
|
|
5287
|
+
assert.equal(arrowNode.props['aria-hidden'], 'true',
|
|
5288
|
+
'箭头是装饰:必须 aria-hidden(否则读屏会单独念出一个 ›)')
|
|
5289
|
+
assert.ok(String(cell.props['aria-haspopup'] || '').length > 0,
|
|
5290
|
+
'按钮要声明 aria-haspopup(这个格子的可见名之外,还得说明它开的是菜单)')
|
|
5291
|
+
assert.equal(cell.props['aria-haspopup'], 'true')
|
|
5292
|
+
assert.equal(cell.props['aria-expanded'], false, '默认收起')
|
|
5293
|
+
assert.ok(String(cell.props.title || '').length > 0, '可访问名(整句话)由 title 承担')
|
|
5294
|
+
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, '收起时菜单一个节点都不产生')
|
|
5295
|
+
|
|
5296
|
+
cell.props.onClick()
|
|
5297
|
+
nodes = render()
|
|
5298
|
+
const wrap = byExactClass(nodes, 'knit-pipe-method-wrap')[0]
|
|
5299
|
+
assert.equal(byExactClass(flattenUnder(wrap), 'knit-retmenu').length, 1,
|
|
5300
|
+
'菜单挂在**状态格自己的容器**里(这样菜单才相对它定位,而不是工具栏的 right:0/top:32px)')
|
|
5301
|
+
assert.equal(byExactClass(flattenUnder(byExactClass(nodes, 'knit-bar')[0]), 'knit-retmenu').length, 0,
|
|
5302
|
+
'工具栏第二行里不许有菜单')
|
|
5303
|
+
assert.equal(byExactClass(nodes, 'knit-pipe-method')[0].props['aria-expanded'], true, '展开态跟着走')
|
|
5304
|
+
assert.equal(byClass(nodes, 'knit-retmenu-item').length, 2, '两个选项照旧')
|
|
5279
5305
|
})
|
|
5280
5306
|
|
|
5281
5307
|
test('v0.23 Phase A:切到「混合」—— 偏好落盘,且下一次取数带上 retrieval=hybrid', async () => {
|
|
@@ -5288,8 +5314,8 @@ test('v0.23 Phase A:切到「混合」—— 偏好落盘,且下一次取数
|
|
|
5288
5314
|
assert.ok(calls.some((url) => url.includes('retrieval=lexical')),
|
|
5289
5315
|
`默认取数要把词法**显式**带上(宿主据此完全不碰 provider):${calls.join(' | ')}`)
|
|
5290
5316
|
|
|
5291
|
-
//
|
|
5292
|
-
|
|
5317
|
+
// 点开状态行那一格 → 两个选项的文案与选中态先核一遍 → 点「混合检索 · 实验」
|
|
5318
|
+
byExactClass(nodes, 'knit-pipe-method')[0].props.onClick()
|
|
5293
5319
|
nodes = render()
|
|
5294
5320
|
const items = byClass(nodes, 'knit-retmenu-item')
|
|
5295
5321
|
assert.equal(items.length, 2, '菜单里两个选项')
|
|
@@ -5319,8 +5345,8 @@ test('v0.23 Phase A:混合真的在跑时 —— 摘要那一格改口径并
|
|
|
5319
5345
|
const pipe = byExactClass(nodes, 'knit-pipe')
|
|
5320
5346
|
assert.equal(pipe.length, 1)
|
|
5321
5347
|
const seq = flattenUnder(pipe[0]).slice(1).map(textOf)
|
|
5322
|
-
assert.ok(seq.includes('BM25 +
|
|
5323
|
-
assert.ok(!seq.includes('BM25
|
|
5348
|
+
assert.ok(seq.includes('BM25 + 语义补充›'), `实际生效的是混合,摘要就必须这么说:${seq.join(' / ')}`)
|
|
5349
|
+
assert.ok(!seq.includes('BM25 检索›'), '不许在混合真的在跑时还写「词法检索」')
|
|
5324
5350
|
assert.ok(seq.includes('语义候选 3 条'), `可用时要如实给候选数:${seq.join(' / ')}`)
|
|
5325
5351
|
assert.equal(seq.filter((t) => t === '·').length, 5, '语义那一格进第二组 ⇒ 组内中点从 4 变 5')
|
|
5326
5352
|
assert.equal(byExactClass(nodes, 'knit-retnote').length, 0, '混合在跑:没有「不可用」说明')
|
|
@@ -5338,11 +5364,11 @@ test('v0.23 Phase A:选了混合但宿主回词法(no-provider)—— 如
|
|
|
5338
5364
|
const note = byExactClass(nodes, 'knit-retnote')
|
|
5339
5365
|
assert.equal(note.length, 1, '不可用时必须有一行事实说明(不是每条结果里的噪声)')
|
|
5340
5366
|
assert.match(textOf(note[0]), /还没有配置 provider/, `原因要来自宿主的码:${textOf(note[0])}`)
|
|
5341
|
-
// ⚠️ 摘要仍然写「BM25
|
|
5342
|
-
assert.ok(allText(nodes).includes('BM25
|
|
5367
|
+
// ⚠️ 摘要仍然写「BM25 检索」:**实际生效**的模式是词法,不是用户点了什么
|
|
5368
|
+
assert.ok(allText(nodes).includes('BM25 检索'), '没生效就还写词法')
|
|
5343
5369
|
|
|
5344
5370
|
// 菜单:状态行如实说「未配置 provider」,并给一条就地配置入口
|
|
5345
|
-
|
|
5371
|
+
byExactClass(nodes, 'knit-pipe-method')[0].props.onClick()
|
|
5346
5372
|
nodes = await renderAgain()
|
|
5347
5373
|
assert.equal(textOf(byClass(nodes, 'knit-retmenu-note')[0]), '未配置 provider —— 混合还没生效。',
|
|
5348
5374
|
'状态行如实写(不美化、不说成可用)')
|
|
@@ -5422,7 +5448,7 @@ test('v0.23 Phase A:宿主缺 semantic 字段时不崩、也不改变默认词
|
|
|
5422
5448
|
const { nodes } = await mountWithPayload(v023Payload(undefined))
|
|
5423
5449
|
assert.equal(byExactClass(nodes, 'knit-retnote').length, 0, '词法模式:老宿主也不产生说明行')
|
|
5424
5450
|
assert.equal(byExactClass(nodes, 'knit-pipe').length, 1, '状态摘要照旧')
|
|
5425
|
-
assert.ok(allText(nodes).includes('BM25
|
|
5451
|
+
assert.ok(allText(nodes).includes('BM25 检索'), '默认词法的呈现一个字不变')
|
|
5426
5452
|
})
|
|
5427
5453
|
|
|
5428
5454
|
test('v0.23(2026-10-11):切到「最新」—— 搜索框右端那个下拉**整块不存在**(不是禁用、也不是 display:none)', async () => {
|
|
@@ -5433,12 +5459,15 @@ test('v0.23(2026-10-11):切到「最新」—— 搜索框右端那个下
|
|
|
5433
5459
|
const payload = v023Payload({
|
|
5434
5460
|
mode: 'lexical', requested: 'lexical', available: null, reason: null, candidates: 0, provider: null,
|
|
5435
5461
|
})
|
|
5436
|
-
|
|
5437
|
-
|
|
5462
|
+
// ⚠️ 客户端是按**载荷里的 `mode`** 决定渲不渲染状态行的(`payload.mode !== 'relevance'` ⇒ 整行不画),
|
|
5463
|
+
// 所以喂给 fetch 替身的必须**就是**那份时间序载荷(只改 mount 的参数没用 —— 替身认的是安装时那份)。
|
|
5464
|
+
const timePayload = { ...payload, mode: 'time' }
|
|
5465
|
+
const { calls } = installSemanticFetch(timePayload)
|
|
5466
|
+
const { nodes: first, renderAgain } = await mountV023(timePayload, 'hybrid', 'time')
|
|
5438
5467
|
let nodes = first
|
|
5439
5468
|
|
|
5440
|
-
assert.equal(
|
|
5441
|
-
assert.equal(
|
|
5469
|
+
assert.equal(byExactClass(nodes, 'knit-pipe-method-wrap').length, 0, '时间序 ⇒ 状态行整行不出现,那一格自然也没有')
|
|
5470
|
+
assert.equal(byExactClass(nodes, 'knit-pipe-method').length, 0, '「不存在」要真不存在(拿 display:none 冒充是空转的绿灯)')
|
|
5442
5471
|
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, '菜单更不该有')
|
|
5443
5472
|
assert.equal(byExactClass(nodes, 'knit-searchwrap').length, 1, '搜索框还在(它自己占满,不留空位)')
|
|
5444
5473
|
assert.equal(byClass(nodes, 'knit-filter').length, 1)
|
|
@@ -5446,10 +5475,17 @@ test('v0.23(2026-10-11):切到「最新」—— 搜索框右端那个下
|
|
|
5446
5475
|
assert.ok(calls.every((url) => !url.includes('retrieval=hybrid')), `最新档不许白问混合:${calls.join(' | ')}`)
|
|
5447
5476
|
assert.ok(calls.every((url) => url.includes('retrieval=lexical')), `最新档带的是词法:${calls.join(' | ')}`)
|
|
5448
5477
|
|
|
5449
|
-
//
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5478
|
+
// 「只隐藏、不重置」:这一档过了之后,盘上那个偏好必须还在
|
|
5479
|
+
assert.equal(globalThis.window.localStorage.getItem('dsh-knit:retrieval'), 'hybrid',
|
|
5480
|
+
'切到「最新」只隐藏控件,已存偏好不许被重置')
|
|
5481
|
+
|
|
5482
|
+
// 切回「相关」⇒ 它自己长出来(**不做禁用态**:直接出现)。
|
|
5483
|
+
// ⚠️ 替身认的是**安装时那份**载荷,所以这里重新装一份相关序的(真实宿主这时会回 `mode:'relevance'`)。
|
|
5484
|
+
const relevancePayload = { ...payload, mode: 'relevance' }
|
|
5485
|
+
installSemanticFetch(relevancePayload)
|
|
5486
|
+
const back = await mountV023(relevancePayload, 'hybrid', 'relevance')
|
|
5487
|
+
assert.equal(byExactClass(back.nodes, 'knit-pipe-method').length, 1, '回到相关档,那一格自己出现')
|
|
5488
|
+
assert.equal(byExactClass(back.nodes, 'knit-searchwrap').length, 1, '搜索框还在第二行')
|
|
5453
5489
|
})
|
|
5454
5490
|
|
|
5455
5491
|
test('v0.23(2026-10-11):宿主回一个客户端不认识的 reason 码 —— 降级成「原因未知」,不许漏出裸键名', async () => {
|
|
@@ -5461,7 +5497,7 @@ test('v0.23(2026-10-11):宿主回一个客户端不认识的 reason 码
|
|
|
5461
5497
|
installSemanticFetch(payload)
|
|
5462
5498
|
const { nodes: first, renderAgain } = await mountV023(payload, 'hybrid')
|
|
5463
5499
|
let nodes = first
|
|
5464
|
-
|
|
5500
|
+
byExactClass(nodes, 'knit-pipe-method')[0].props.onClick()
|
|
5465
5501
|
nodes = await renderAgain()
|
|
5466
5502
|
|
|
5467
5503
|
const note = textOf(byClass(nodes, 'knit-retmenu-note')[0])
|
|
@@ -5480,7 +5516,7 @@ test('v0.23(2026-10-11):菜单的键盘关闭 —— Esc 收起菜单、
|
|
|
5480
5516
|
installSemanticFetch(payload)
|
|
5481
5517
|
const { nodes: first, renderAgain } = await mountV023(payload, 'lexical')
|
|
5482
5518
|
let nodes = first
|
|
5483
|
-
const btn = () =>
|
|
5519
|
+
const btn = () => byExactClass(nodes, 'knit-pipe-method')[0]
|
|
5484
5520
|
assert.equal(btn().props['aria-expanded'], false, '收起时 aria-expanded=false')
|
|
5485
5521
|
btn().props.onClick()
|
|
5486
5522
|
nodes = await renderAgain()
|