dsh-knit 0.22.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 +210 -3
- package/README.en.md +38 -37
- package/README.md +27 -28
- package/SECURITY.md +14 -5
- package/package.json +5 -3
- package/src/client/client.js +575 -132
- package/src/host/context.js +42 -3
- package/src/host/index.js +196 -7
- package/src/host/semantic.js +465 -0
- package/src/host/tool.js +44 -1
- package/test/client.test.mjs +767 -248
- package/test/harness.mjs +3 -1
- package/test/host-http.test.mjs +23 -0
- package/test/hybrid-eval.test.mjs +184 -0
- package/test/hybrid-retrieval.test.mjs +313 -0
- package/test/retrieval-corpus.mjs +379 -0
- package/test/retrieval-eval.mjs +231 -0
- package/test/semantic.test.mjs +257 -0
- package/test/tool.test.mjs +59 -4
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,160 +829,49 @@ test('媒体:点视频卡片就地预览,播放器 controls 且静音自动
|
|
|
851
829
|
assert.ok(!calls.some((u) => u.includes('/api/doc')), '视频不应触发正文请求')
|
|
852
830
|
})
|
|
853
831
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
860
|
-
await harness.flush()
|
|
861
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
832
|
+
/* ── v0.23.1:「全部」档整体删除 ─────────────────────────────────────
|
|
833
|
+
2026-10-12 用户裁决:类型档只留三档,界面上不再有「全部」及其混合浏览视图
|
|
834
|
+
(「三层混排文档 + 代码 + 末尾媒体网格」那套整块消失)。
|
|
835
|
+
⇒ 这一组守卫查的是**源码里那些名字真的没了** —— 不是关掉、不是 display:none。
|
|
836
|
+
证伪方式:把任意一个名字放回源码,下面这条守卫立刻红(写完实测过一次)。 */
|
|
862
837
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
838
|
+
test('v0.23.1:「全部」档在**源码里整体删除**(KIND_ALL / allRows / allMedia / 它的 i18n 键 / 分区特例)', async () => {
|
|
839
|
+
const { readFileSync } = await import('node:fs')
|
|
840
|
+
const { fileURLToPath } = await import('node:url')
|
|
841
|
+
const source = readFileSync(
|
|
842
|
+
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
843
|
+
'utf8',
|
|
844
|
+
)
|
|
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}`)
|
|
851
|
+
}
|
|
852
|
+
// 类型档只剩三个值 —— 一行写得清清楚楚(多一档就会红)
|
|
853
|
+
assert.ok(
|
|
854
|
+
source.includes("[[KIND_DOC, 'kind.doc'], [KIND_CODE, 'kind.code'], [KIND_MEDIA, 'kind.media']]"),
|
|
855
|
+
'类型档就是三档',
|
|
867
856
|
)
|
|
868
|
-
assert.equal(byToken(nodes, 'knit-doc').length, 4, '文档区最多 4 条')
|
|
869
|
-
// 载荷里 5 图 + 4 视频 = 9 个媒体:一格都不隐藏,纵向也**不封顶**(有多少行铺多少行)
|
|
870
|
-
assert.equal(byToken(nodes, 'knit-media-card').length, 9, '媒体区不截断,9 个全出')
|
|
871
|
-
assert.equal(byExactClass(nodes, 'knit-media-grid in-section').length, 1, '媒体区用分区网格')
|
|
872
|
-
assert.match(byClass(nodes, 'knit-count').map(textOf).join(''), /^16$/, '顶行仍报总数')
|
|
873
|
-
|
|
874
|
-
const grid = byExactClass(nodes, 'knit-media-grid in-section')[0]
|
|
875
|
-
// 测试环境没有 ResizeObserver → 量不到宽度 → 走默认面板几何(632px)
|
|
876
|
-
assert.equal(grid.props.style['--knit-media-cell'], '118px', '默认面板下 9 个媒体 → 118px 的格子')
|
|
877
|
-
// 列数**不再由 JS 下发** —— 交给 CSS 的 auto-fill,面板一变宽就自己多一列
|
|
878
|
-
assert.equal(grid.props.style['--knit-media-cols'], undefined, '不再下发列数')
|
|
879
|
-
assert.equal(grid.props.style['--knit-media-label'], undefined, '118px 还有地方写文件名/时间')
|
|
880
|
-
// ⚠️ 纵向不许封顶:2026-09-20 前两版设 maxHeight 封「两行」,真机上第三行只露一点点
|
|
881
|
-
assert.equal(grid.props.style.maxHeight, undefined,
|
|
882
|
-
'网格不许设 maxHeight —— 纵向有多少行就铺多少行,滚动交给 .knit-list')
|
|
883
857
|
})
|
|
884
858
|
|
|
885
859
|
test('媒体:条目不多时卡片正常带文件名与时间,不让文字让位', async () => {
|
|
886
860
|
// 1 篇文档 + 5 媒体(正好一屏内)
|
|
887
|
-
const
|
|
888
|
-
|
|
889
|
-
installFetch(kindResponder({
|
|
861
|
+
const pool = mixedPayload().docs
|
|
862
|
+
const docs = pool.slice(0, 1).concat(pool.filter((d) => d.kind !== 'md').slice(0, 4))
|
|
863
|
+
installFetch(kindResponder({ media: mixedPayload({ total: docs.length, docs }) }))
|
|
890
864
|
const { KnitBody } = loadClientModule().exports.__test
|
|
891
865
|
harness.reset()
|
|
892
|
-
harness.seed(['', 'time', '
|
|
866
|
+
harness.seed(['', 'time', 'media'])
|
|
893
867
|
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
894
868
|
await harness.flush()
|
|
895
869
|
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
896
870
|
|
|
897
|
-
const grid = byExactClass(nodes, 'knit-media-grid
|
|
871
|
+
const grid = byExactClass(nodes, 'knit-media-grid')[0]
|
|
898
872
|
assert.equal(grid.props.style['--knit-media-label'], undefined, '不缩小就保留文件名/时间')
|
|
899
|
-
assert.equal(byExactClass(nodes, 'knit-media-meta').length,
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
test('媒体:「全部」的文档区被截断时给「已显示 / 总数」与「查看全部」,媒体区不截断', async () => {
|
|
903
|
-
installFetch(kindResponder({ all: bigMixedPayload() }))
|
|
904
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
905
|
-
harness.reset()
|
|
906
|
-
harness.seed(['', 'time', 'all'])
|
|
907
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
908
|
-
await harness.flush()
|
|
909
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
910
|
-
|
|
911
|
-
// 7 篇文档里只显示 4 条;媒体 9 个全显示,所以媒体区没有「已显示 / 总数」
|
|
912
|
-
assert.deepEqual(byExactClass(nodes, 'knit-section-count').map(textOf), ['4 / 7', '9'])
|
|
913
|
-
assert.equal(byExactClass(nodes, 'knit-section-more').length, 1, '只有文档区被截断')
|
|
914
|
-
})
|
|
915
|
-
|
|
916
|
-
test('媒体:「全部」没被截断时不出现「查看全部」,空的一区整个不渲染', async () => {
|
|
917
|
-
// 1 篇文档 + 1 图:都低于上限
|
|
918
|
-
installFetch(kindResponder({ all: mixedPayload({ total: 2, docs: mixedPayload().docs.slice(0, 2) }) }))
|
|
919
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
920
|
-
harness.reset()
|
|
921
|
-
harness.seed(['', 'time', 'all'])
|
|
922
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
923
|
-
await harness.flush()
|
|
924
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
925
|
-
|
|
926
|
-
assert.equal(byExactClass(nodes, 'knit-section').length, 2)
|
|
927
|
-
assert.equal(byExactClass(nodes, 'knit-section-more').length, 0, '没截断就没有「查看全部」')
|
|
928
|
-
assert.deepEqual(byExactClass(nodes, 'knit-section-count').map(textOf), ['1 / 1', '1'])
|
|
929
|
-
})
|
|
930
|
-
|
|
931
|
-
test('媒体:只有文档时「全部」只出一区,不留空标题', async () => {
|
|
932
|
-
installFetch(kindResponder({ all: mixedPayload({ total: 1, docs: mixedPayload().docs.slice(0, 1) }) }))
|
|
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
|
-
assert.equal(byExactClass(nodes, 'knit-section').length, 1)
|
|
941
|
-
assert.deepEqual(byExactClass(nodes, 'knit-section-title').map(textOf), ['文档'])
|
|
942
|
-
assert.equal(byExactClass(nodes, 'knit-media-grid in-section').length, 0)
|
|
943
|
-
})
|
|
944
|
-
|
|
945
|
-
test('媒体:「全部」文档区的「查看全部」点了切到文档分类', async () => {
|
|
946
|
-
const { calls } = installFetch(kindResponder({
|
|
947
|
-
all: bigMixedPayload(), doc: listPayload(), media: mediaPayload(),
|
|
948
|
-
}))
|
|
949
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
950
|
-
harness.reset()
|
|
951
|
-
harness.seed(['', 'time', 'all'])
|
|
952
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
953
|
-
await harness.flush()
|
|
954
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
955
|
-
|
|
956
|
-
// 媒体区不截断,所以「全部」里只剩文档区那一个「查看全部」
|
|
957
|
-
byExactClass(nodes, 'knit-section-more')[0].props.onClick()
|
|
958
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
959
|
-
await harness.flush()
|
|
960
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
961
|
-
|
|
962
|
-
assert.ok(calls.some((u) => u.includes('kind=doc')), `实际: ${calls.join(', ')}`)
|
|
963
|
-
assert.equal(globalThis.window.localStorage.getItem('dsh-knit:kind'), 'doc')
|
|
964
|
-
assert.equal(byExactClass(nodes, 'knit-section').length, 0, '已离开「全部」,不再有分区')
|
|
965
|
-
assert.equal(byExactClass(nodes, 'knit-media-grid').length, 0, '文档视图里没有媒体网格')
|
|
966
|
-
})
|
|
967
|
-
|
|
968
|
-
test('媒体:只有媒体时「全部」的媒体区不截断、也不给「查看全部」', async () => {
|
|
969
|
-
const now = Date.now()
|
|
970
|
-
const docs = Array.from({ length: 9 }, (_, i) => ({
|
|
971
|
-
path: `/p/i${i}.png`, rel: `i${i}.png`, name: `i${i}.png`, title: `图${i}`,
|
|
972
|
-
kind: 'image', summary: '', size: 1024, mtimeMs: now - i * 1000, score: null,
|
|
973
|
-
}))
|
|
974
|
-
installFetch(kindResponder({ all: mixedPayload({ total: docs.length, docs }) }))
|
|
975
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
976
|
-
harness.reset()
|
|
977
|
-
harness.seed(['', 'time', 'all'])
|
|
978
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
979
|
-
await harness.flush()
|
|
980
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
981
|
-
|
|
982
|
-
assert.equal(byExactClass(nodes, 'knit-section').length, 1, '只有媒体区')
|
|
983
|
-
assert.deepEqual(byExactClass(nodes, 'knit-section-title').map(textOf), ['媒体'])
|
|
984
|
-
assert.equal(byExactClass(nodes, 'knit-section-more').length, 0, '媒体区不截断,没有「查看全部」')
|
|
985
|
-
assert.equal(byToken(nodes, 'knit-media-card').length, 9)
|
|
986
|
-
})
|
|
987
|
-
|
|
988
|
-
test('媒体:「全部」的键盘导航只走到分区上限内,不落到被截断的条目', async () => {
|
|
989
|
-
installFetch(kindResponder({ all: bigMixedPayload() }))
|
|
990
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
991
|
-
harness.reset()
|
|
992
|
-
harness.seed(['', 'time', 'all'])
|
|
993
|
-
let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
994
|
-
await harness.flush()
|
|
995
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
996
|
-
|
|
997
|
-
const list = byExactClass(nodes, 'knit-list')[0]
|
|
998
|
-
// 上限内共 4 + 6 = 10 条;连按 20 次也不能走到第 11 条
|
|
999
|
-
for (let i = 0; i < 20; i += 1) {
|
|
1000
|
-
list.props.onKeyDown({ key: 'ArrowDown', preventDefault() {} })
|
|
1001
|
-
nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1002
|
-
await harness.flush()
|
|
1003
|
-
}
|
|
1004
|
-
const withCursor = byToken(nodes, 'cursor')
|
|
1005
|
-
assert.equal(withCursor.length, 1, '任何时候只有一个条目是 cursor')
|
|
1006
|
-
const reached = String(withCursor[0].props['data-knit-rel'] || '')
|
|
1007
|
-
assert.ok(!/^d[5-7]\.md$/.test(reached), `不该落到被截断的文档:${reached}`)
|
|
873
|
+
assert.equal(byExactClass(nodes, 'knit-media-meta').length, docs.filter((d) => d.kind !== 'md').length,
|
|
874
|
+
'每个媒体都有文字区')
|
|
1008
875
|
})
|
|
1009
876
|
|
|
1010
877
|
test('媒体:mediaLayoutFor —— 列数只跟可用宽度走,格子基准固定、与条目数无关', () => {
|
|
@@ -1794,14 +1661,14 @@ function contextPayload(overrides = {}) {
|
|
|
1794
1661
|
* @param {object} payload - `fetch` 的载荷
|
|
1795
1662
|
* @returns {Promise<{nodes:object[], render:s Function}>} 首帧节点与重渲染函数
|
|
1796
1663
|
*/
|
|
1797
|
-
async function mountWithPayload(payload) {
|
|
1664
|
+
async function mountWithPayload(payload, kind = 'doc') {
|
|
1798
1665
|
installFetch((url) => (url.includes('/api/links')
|
|
1799
1666
|
? { ok: true, rel: 'x', incoming: [], outgoing: [], incomingTotal: 0, outgoingTotal: 0 }
|
|
1800
1667
|
: payload))
|
|
1801
1668
|
const { KnitBody } = loadClientModule().exports.__test
|
|
1802
1669
|
harness.reset()
|
|
1803
|
-
//
|
|
1804
|
-
harness.seed(['', 'relevance'])
|
|
1670
|
+
// 前三个 hook 槽位是 notice / sort / kind —— 预置成相关序,面板才会去用 Context Pack
|
|
1671
|
+
harness.seed(['', 'relevance', kind])
|
|
1805
1672
|
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1806
1673
|
// ⚠️ 数据到位后要再走一轮 render → flush → render:cursor 是在**数据到达之后**
|
|
1807
1674
|
// 那一轮 effect 里落位的(AGENTS.md §6.2:断言前少一轮就会停在初值)。
|
|
@@ -3049,9 +2916,11 @@ test('v0.18 定位手感:高亮时长与 CSS 同步;对比控件描边用官
|
|
|
3049
2916
|
assert.match(source,
|
|
3050
2917
|
/\.knit-seg-btn \+ \.knit-seg-btn\{border-left:0\.5px solid var\(--dsw-alias-border-l3/,
|
|
3051
2918
|
'「相关 / 最新」之间的分隔线也是同一档同粗(色或粗细差一点就会看得出来)')
|
|
3052
|
-
|
|
2919
|
+
// v0.23(2026-10-11 用户裁决):描边从输入框挪到**搜索框容器**(.knit-searchwrap)——
|
|
2920
|
+
// 检索模式那个小下拉贴在容器右端,两者共用一圈描边才像一个控件。色与粗细一字不变。
|
|
2921
|
+
assert.match(source, /\.knit-searchwrap\{[^}]*border:0\.5px solid var\(--dsw-alias-border-l3/,
|
|
3053
2922
|
'搜索框描边用 border-l3、0.5px')
|
|
3054
|
-
assert.ok(!/\.knit-(?:seg|
|
|
2923
|
+
assert.ok(!/\.knit-(?:seg|searchwrap)\{[^}]*border[^;]*--dsw-alias-border-l4/.test(source),
|
|
3055
2924
|
'这两个控件不许再退回 l4')
|
|
3056
2925
|
assert.ok(!/\.knit-seg(-btn \+ \.knit-seg-btn)?\{[^}]*border[^;]*:1px solid var\(--dsw-alias-border-l3/
|
|
3057
2926
|
.test(source), '这三个描边要么一起 0.5px,要么一起改 —— 不许只把其中一处写回 1px')
|
|
@@ -3892,45 +3761,6 @@ test('v0.19 网页预览:只有 HTML 给这个入口,点了走官方标签
|
|
|
3892
3761
|
assert.ok(byExactClass(nodes, 'knit-codepane').length === 1, '它照旧走就地代码预览')
|
|
3893
3762
|
})
|
|
3894
3763
|
|
|
3895
|
-
test('v0.19 代码:「全部」档是三区(文档 / 代码 / 媒体),代码区排在媒体区之前且限流', async () => {
|
|
3896
|
-
const now = Date.now()
|
|
3897
|
-
const docs = []
|
|
3898
|
-
for (let i = 1; i <= 7; i += 1) {
|
|
3899
|
-
docs.push({
|
|
3900
|
-
path: `/p/d${i}.md`, rel: `d${i}.md`, name: `d${i}.md`, title: `文档${i}`,
|
|
3901
|
-
kind: 'md', summary: '摘要', size: 500, mtimeMs: now - i * 1000, score: null,
|
|
3902
|
-
})
|
|
3903
|
-
}
|
|
3904
|
-
for (let i = 1; i <= 6; i += 1) {
|
|
3905
|
-
docs.push({
|
|
3906
|
-
path: `/p/src/c${i}.ts`, rel: `src/c${i}.ts`, name: `c${i}.ts`, title: `c${i}.ts`,
|
|
3907
|
-
kind: 'code', summary: 'src/', size: 900, mtimeMs: now - i * 1000, score: null,
|
|
3908
|
-
})
|
|
3909
|
-
}
|
|
3910
|
-
for (let i = 1; i <= 3; i += 1) {
|
|
3911
|
-
docs.push({
|
|
3912
|
-
path: `/p/i${i}.png`, rel: `i${i}.png`, name: `i${i}.png`, title: `图${i}`,
|
|
3913
|
-
kind: 'image', summary: '', size: 1024, mtimeMs: now - i * 1000, score: null,
|
|
3914
|
-
})
|
|
3915
|
-
}
|
|
3916
|
-
installFetch(kindResponder({ all: { ok: true, root: '/p', total: docs.length, mode: 'time', topic: '', kind: 'all', docs } }))
|
|
3917
|
-
const { KnitBody } = loadClientModule().exports.__test
|
|
3918
|
-
harness.reset()
|
|
3919
|
-
harness.seed(['', 'time', 'all'])
|
|
3920
|
-
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
3921
|
-
let nodes = render()
|
|
3922
|
-
await harness.flush()
|
|
3923
|
-
nodes = render()
|
|
3924
|
-
|
|
3925
|
-
assert.deepEqual(byExactClass(nodes, 'knit-section-title').map(textOf), ['文档', '代码', '媒体'],
|
|
3926
|
-
'三区的顺序是文档 → 代码 → 媒体')
|
|
3927
|
-
// 文档区 4 条 + 代码区 4 条 = 8 行文本行;媒体区是格子,不算行
|
|
3928
|
-
assert.equal(byToken(nodes, 'knit-doc').length, 8, '文档区与代码区各自限 4 条')
|
|
3929
|
-
assert.equal(byExactClass(nodes, 'knit-lang').length, 4, '语言徽章只跟着代码区那 4 行')
|
|
3930
|
-
assert.equal(byToken(nodes, 'knit-media-card').length, 3, '媒体一格不隐藏')
|
|
3931
|
-
assert.match(byClass(nodes, 'knit-count').map(textOf).join(''), /^16$/, '顶行仍报总数')
|
|
3932
|
-
})
|
|
3933
|
-
|
|
3934
3764
|
test('v0.19 代码:Usage Lens 里的代码路径照常显示(读的是一份事实、不是两套)', async () => {
|
|
3935
3765
|
installFetch(() => contextPayload({
|
|
3936
3766
|
usage: {
|
|
@@ -4609,6 +4439,94 @@ test('v0.21 来源:检索 / 关系 / 用户固定 三个中性词,不是分
|
|
|
4609
4439
|
}
|
|
4610
4440
|
})
|
|
4611
4441
|
|
|
4442
|
+
/* ── v0.23 可选混合检索:来源与理由各多一档(Phase B)──────────────
|
|
4443
|
+
宿主开始**真的把语义候选补进包**之后,契约里多两个值:
|
|
4444
|
+
· `provenance: 'semantic'` ⇒ 来源徽标「语义相关」(与前三档同一个中性词组);
|
|
4445
|
+
· `reason.code: 'semantic'` ⇒ 理由句(只陈述可复核的事实:标题 + 摘要的向量相似)。
|
|
4446
|
+
第三件事是**未知值**:客户端不认识的 provenance / reason.code 不许抛、
|
|
4447
|
+
不许把 `undefined` 或裸码渲染到界面上。 */
|
|
4448
|
+
|
|
4449
|
+
test('v0.23 来源:语义 是第四档中性词(徽标),与前三档同一组', async () => {
|
|
4450
|
+
const payload = v021Payload({ pinnedRels: ['docs/pin.md'] })
|
|
4451
|
+
payload.context.primary = [{ ...payload.context.primary[0], provenance: 'semantic' }]
|
|
4452
|
+
payload.context.supporting = [{ ...payload.context.primary[0], rel: 'docs/eval.md', provenance: 'relation' }]
|
|
4453
|
+
const { nodes } = await mountWithPayload(payload)
|
|
4454
|
+
const provs = byExactClass(nodes, 'knit-prov').map(textOf).sort()
|
|
4455
|
+
assert.deepEqual(provs, ['关系', '用户固定', '语义相关'].sort(), '四档来源共用一套中性词')
|
|
4456
|
+
// 来源**不是强弱**:不许带数字 / 百分比 / 颜色语义(与 v0.21 同一条纪律)
|
|
4457
|
+
for (const text of provs) {
|
|
4458
|
+
assert.ok(!/\d|%/.test(text), `来源词里不许出现数字或百分比:${text}`)
|
|
4459
|
+
}
|
|
4460
|
+
})
|
|
4461
|
+
|
|
4462
|
+
test('v0.23 理由:reason.code = semantic 渲染成「语义相关」,且只写可复核的事实', async () => {
|
|
4463
|
+
const payload = v021Payload()
|
|
4464
|
+
payload.context.primary = [{
|
|
4465
|
+
...payload.context.primary[0],
|
|
4466
|
+
// 只换理由码:这样这一行里的「语义相关」只可能来自理由,不会与来源徽标混在一起
|
|
4467
|
+
provenance: 'retrieval',
|
|
4468
|
+
reason: { code: 'semantic', terms: [], fields: 0, term: '' },
|
|
4469
|
+
}]
|
|
4470
|
+
const { nodes } = await mountWithPayload(payload)
|
|
4471
|
+
const row = byToken(nodes, 'knit-doc').find((r) => r.props['data-knit-rel'] === 'docs/algo.md')
|
|
4472
|
+
const text = textOf(row)
|
|
4473
|
+
assert.ok(text.includes('语义相关'), `理由要渲染出来:${text}`)
|
|
4474
|
+
assert.ok(!text.includes('why.semantic'), `不许把词典键漏到界面上:${text}`)
|
|
4475
|
+
assert.ok(!/模型|AI|置信|相似度/.test(text), `理由只陈述事实,不许出现模型 / 置信度这类说法:${text}`)
|
|
4476
|
+
})
|
|
4477
|
+
|
|
4478
|
+
test('v0.23 来源 / 理由:英文环境下是 semantic / semantic match', async () => {
|
|
4479
|
+
const payload = v021Payload()
|
|
4480
|
+
payload.context.primary = [{
|
|
4481
|
+
...payload.context.primary[0],
|
|
4482
|
+
provenance: 'semantic',
|
|
4483
|
+
reason: { code: 'semantic', terms: [], fields: 0, term: '' },
|
|
4484
|
+
}]
|
|
4485
|
+
installFetch((url) => (url.includes('/api/links')
|
|
4486
|
+
? { ok: true, rel: 'x', incoming: [], outgoing: [], incomingTotal: 0, outgoingTotal: 0 }
|
|
4487
|
+
: payload))
|
|
4488
|
+
const { exports } = loadClientModule()
|
|
4489
|
+
// 词典是模块级状态:apply 到 en 之后整块面板都说英文(与真机一致)
|
|
4490
|
+
exports.apply(fakeCtx({ sidebarRightTabs: true, locale: 'en' }).ctx)
|
|
4491
|
+
const { KnitBody } = exports.__test
|
|
4492
|
+
harness.reset()
|
|
4493
|
+
harness.seed(['', 'relevance'])
|
|
4494
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
4495
|
+
let nodes = render()
|
|
4496
|
+
await harness.flush()
|
|
4497
|
+
nodes = render()
|
|
4498
|
+
await harness.flush()
|
|
4499
|
+
nodes = render()
|
|
4500
|
+
|
|
4501
|
+
const provs = byExactClass(nodes, 'knit-prov').map(textOf)
|
|
4502
|
+
assert.ok(provs.includes('semantic'), `英文来源词是中性小写 semantic:${provs.join(' / ')}`)
|
|
4503
|
+
const row = byToken(nodes, 'knit-doc').find((r) => r.props['data-knit-rel'] === 'docs/algo.md')
|
|
4504
|
+
const text = textOf(row)
|
|
4505
|
+
assert.ok(text.includes('semantic match'), `英文理由句:${text}`)
|
|
4506
|
+
assert.ok(!text.includes('why.semantic'), `不许把词典键漏出来:${text}`)
|
|
4507
|
+
})
|
|
4508
|
+
|
|
4509
|
+
test('v0.23 未知值降级:不认识的 provenance / reason.code 不抛、不渲染 undefined', async () => {
|
|
4510
|
+
const payload = v021Payload()
|
|
4511
|
+
payload.context.primary = [{
|
|
4512
|
+
...payload.context.primary[0],
|
|
4513
|
+
provenance: 'mystery',
|
|
4514
|
+
reason: { code: 'mystery', terms: [], fields: 0, term: '' },
|
|
4515
|
+
}]
|
|
4516
|
+
// 「不抛」这一条由这次 await 自己守:渲染路径真的抛了,这条用例直接红。
|
|
4517
|
+
const { nodes } = await mountWithPayload(payload)
|
|
4518
|
+
assert.equal(byExactClass(nodes, 'knit-prov').length, 0, '不认识的来源 ⇒ 一个徽标都不给(不替它认领一档)')
|
|
4519
|
+
const flat = nodes.map((node) => textOf(node)).join('\n')
|
|
4520
|
+
assert.ok(!flat.includes('undefined'), '任何位置都不许渲染出 undefined')
|
|
4521
|
+
// ⚠️ 未知**理由码**会显示键名(下面那条),所以这里只守**来源**那一侧不许漏裸码。
|
|
4522
|
+
assert.ok(!flat.includes('prov.mystery'), '未知来源不许以 `prov.mystery` 这种裸码出现在界面上')
|
|
4523
|
+
const row = byToken(nodes, 'knit-doc').find((r) => r.props['data-knit-rel'] === 'docs/algo.md')
|
|
4524
|
+
assert.ok(
|
|
4525
|
+
textOf(row).includes('why.mystery'),
|
|
4526
|
+
'未知理由码显示键名(可见的异常,便于发现宿主加了码而客户端没跟上),而不是一条静默的空行',
|
|
4527
|
+
)
|
|
4528
|
+
})
|
|
4529
|
+
|
|
4612
4530
|
test('v0.21.x 布局:标题行只剩标题与时间,来源与固定 / 排除搬到证据行右端(固定 → 排除 → 来源词)', async () => {
|
|
4613
4531
|
/* 2026-10-08 用户规格(Context 列表操作布局优化):标题行右侧原来并排四样东西
|
|
4614
4532
|
(来源词 + 固定 + 排除 + 时间)=信息过载。来源与命中段、理由说的是**同一层证据**,
|
|
@@ -4772,10 +4690,11 @@ test('v0.21.x 检索状态摘要:单行三组、竖线分隔、组内中点,
|
|
|
4772
4690
|
assert.equal(pipe.length, 1)
|
|
4773
4691
|
|
|
4774
4692
|
// ① 逐个格子的**原文**,以及分隔符的种类与位置 —— 顺序就是这条设计要传达的信息
|
|
4775
|
-
|
|
4693
|
+
// 用**直接子节点**(flattenUnder 会把状态格内部的按钮/箭头也压平 ⇒ 同一格数三次)
|
|
4694
|
+
const seq = (pipe[0].children || []).map(textOf)
|
|
4776
4695
|
assert.deepEqual(seq, [
|
|
4777
4696
|
'收集 4', '·', '排除 1', '·', '候选 3', '|',
|
|
4778
|
-
'BM25
|
|
4697
|
+
'BM25 检索›', '·', '关系 1 条', '·', '固定 1', '|',
|
|
4779
4698
|
'入包 1',
|
|
4780
4699
|
], `三组 = 工作区候选 | 检索与调整 | 最终结果:${textOf(pipe[0])}`)
|
|
4781
4700
|
|
|
@@ -4783,7 +4702,7 @@ test('v0.21.x 检索状态摘要:单行三组、竖线分隔、组内中点,
|
|
|
4783
4702
|
assert.match(seq[0], /收集 4/, '收集 = 候选 + 本批真被排掉的(3 + 1)')
|
|
4784
4703
|
assert.match(seq[2], /排除 1/, '排除 = 宿主按候选集算的 skipped,不是 excluded 表的长度')
|
|
4785
4704
|
assert.match(seq[4], /候选 3/, '候选 = 排除之后进入检索的篇数(原来的光数字)')
|
|
4786
|
-
assert.match(seq[6], /BM25
|
|
4705
|
+
assert.match(seq[6], /BM25 检索/, '零模型这条路要说出来')
|
|
4787
4706
|
assert.match(seq[8], /关系 1 条/, '关系 = 这一份包里带了几条关系证据')
|
|
4788
4707
|
assert.match(seq[10], /固定 1/, '固定 = 被固定、从三层移出进了固定区的篇数')
|
|
4789
4708
|
assert.match(seq[12], /入包 1/, '入包 = 三层条目数(固定区不算)')
|
|
@@ -4802,35 +4721,68 @@ test('v0.21.x 检索状态摘要:单行三组、竖线分隔、组内中点,
|
|
|
4802
4721
|
}
|
|
4803
4722
|
})
|
|
4804
4723
|
|
|
4805
|
-
test('v0.21.x 工具栏:排序 | 竖线 |
|
|
4806
|
-
/* 2026-10-09
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4724
|
+
test('v0.21.x/v0.23.1 工具栏:排序 | 竖线 | 三档类型 | [检索模式 + 搜索框] 右对齐容器', async () => {
|
|
4725
|
+
/* 2026-10-09 用户规格 + 2026-10-12(v0.23.1 用户裁决):左侧「相关 / 最新」负责排序;
|
|
4726
|
+
中间「文档 / 代码 / 媒体」负责内容类型(**三档**);右侧是一个右对齐容器
|
|
4727
|
+
`.knit-bar-right`,里面是**检索模式小下拉(在左)+ 搜索框(在右)**。四条要守住:
|
|
4728
|
+
① 各条件**不做成一个整体** —— 排序 / 类型 / 检索模式是三个条件,中间的浅灰竖线就是边界;
|
|
4729
|
+
② 右对齐容器里**只有搜索框**是可伸缩项(`flex:1 1 180px` + `max-width:240px` + `min-width:0`)
|
|
4730
|
+
⇒ 窄屏先缩搜索框,排序 / 类型 / 检索模式都是 `flex:none`;
|
|
4731
|
+
③ 条件彼此独立:选「代码」再选「最新」= 最新的代码,搜索词两边都不重置;
|
|
4732
|
+
④ 检索模式「最新」档不出现、但**不重置**偏好(v0.23 既有裁决)。 */
|
|
4811
4733
|
const { nodes: first, renderAgain } = await mountWithPayload(v021Payload())
|
|
4812
4734
|
let nodes = first
|
|
4813
4735
|
|
|
4814
4736
|
const bar = byExactClass(nodes, 'knit-bar')
|
|
4815
4737
|
assert.equal(bar.length, 1, '工具栏恰好一个')
|
|
4738
|
+
// 直接子节点的类名(要判「谁是最后一个」必须看直接子节点,不能看 flatten 后的整棵子树)
|
|
4739
|
+
const directOf = (node) => {
|
|
4740
|
+
const out = []
|
|
4741
|
+
const push = (n) => {
|
|
4742
|
+
if (!n || typeof n !== 'object') return
|
|
4743
|
+
if (Array.isArray(n)) { n.forEach(push); return }
|
|
4744
|
+
const type = n.type
|
|
4745
|
+
if (type && typeof type === 'object' && typeof type.type === 'function') { push(type.type(n.props)); return }
|
|
4746
|
+
if (typeof type === 'function') { push(type(n.props)); return }
|
|
4747
|
+
out.push(String((n.props && n.props.className) || ''))
|
|
4748
|
+
}
|
|
4749
|
+
;(node.children || []).forEach(push)
|
|
4750
|
+
return out
|
|
4751
|
+
}
|
|
4816
4752
|
const under = flattenUnder(bar[0]).slice(1)
|
|
4817
4753
|
const cls = under.map((n) => String(n.props.className || ''))
|
|
4818
4754
|
const at = (name) => cls.findIndex((c) => c === name)
|
|
4819
4755
|
|
|
4820
|
-
// ① 顺序:排序 →
|
|
4821
|
-
|
|
4756
|
+
// ① 顺序:排序 → 类型 → 右对齐容器(容器里:检索模式在左、搜索框在右)
|
|
4757
|
+
// ⚠️ 2026-10-12 用户裁决:排序与类型之间**那根竖线删掉了**,两组靠 .knit-bar 的 gap 分界。
|
|
4758
|
+
for (const name of ['knit-seg', 'knit-types', 'knit-bar-right', 'knit-searchwrap']) {
|
|
4822
4759
|
assert.ok(at(name) >= 0, `工具栏里必须有 ${name}:${cls.join(' / ')}`)
|
|
4823
4760
|
}
|
|
4824
|
-
assert.ok(at('knit-seg') < at('knit-
|
|
4825
|
-
assert.ok(at('knit-
|
|
4826
|
-
assert.equal(
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
//
|
|
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
|
+
'状态行那个可点状态格也不许混进工具栏第二行')
|
|
4776
|
+
assert.equal(byClass(under, 'knit-retseg').length, 0,
|
|
4777
|
+
'左端不再有检索模式那一组(.knit-retseg 只剩配置区在用)')
|
|
4778
|
+
assert.equal(byExactClass(nodes, 'knit-bar-sep').length, 0, '连装饰用的竖线节点也不存在')
|
|
4779
|
+
|
|
4780
|
+
// ② 各条件都在,而且各用各的控件(不是把条件连排成一串按钮)
|
|
4832
4781
|
assert.deepEqual(byClass(under, 'knit-seg-btn').map(textOf), ['相关', '最新'])
|
|
4833
|
-
assert.deepEqual(byClass(under, 'knit-type-btn').map(textOf), ['文档', '代码', '媒体',
|
|
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:第二行只有排序 / 类型 / 搜索三样,检索方式不在这里')
|
|
4834
4786
|
for (const node of under) {
|
|
4835
4787
|
assert.ok(!/^(svg|path|use|img|i)$/.test(String(node.type)), `不许加图标:${String(node.type)}`)
|
|
4836
4788
|
}
|
|
@@ -4861,17 +4813,245 @@ test('v0.21.x 工具栏:排序 | 竖线 | 类型 | 搜索一行,两组
|
|
|
4861
4813
|
assert.ok(m, `必须有 .${sel} 这条规则`)
|
|
4862
4814
|
return m[1]
|
|
4863
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
|
+
}
|
|
4823
|
+
// v0.23(2026-10-11):这几条量的是**搜索框容器**(描边与宽度都在容器上,输入框只管输入)
|
|
4824
|
+
const wrapCss = rule('knit-searchwrap')
|
|
4825
|
+
assert.match(wrapCss, /flex:1 1 180px/, '搜索框:基础宽 180px,可长可缩')
|
|
4826
|
+
assert.match(wrapCss, /max-width:240px/, '搜索框封顶 240px(常规面板 180–240px)')
|
|
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/, '状态格不参与伸缩')
|
|
4864
4836
|
const filter = rule('knit-filter')
|
|
4865
|
-
assert.match(filter, /flex:1 1
|
|
4866
|
-
assert.match(filter, /
|
|
4867
|
-
assert.match(filter, /margin-left:auto/, '封顶后剩下的空间留在左边 ⇒ 搜索框贴住右端')
|
|
4868
|
-
assert.match(filter, /min-width:0/, '面板窄了先缩搜索框')
|
|
4837
|
+
assert.match(filter, /flex:1 1 auto/, '输入框吃掉搜索框容器里剩下的宽度')
|
|
4838
|
+
assert.match(filter, /min-width:0/, '输入框也要能缩')
|
|
4869
4839
|
assert.match(rule('knit-seg'), /flex:none/, '排序组不被挤')
|
|
4870
4840
|
assert.match(rule('knit-types'), /flex:none/, '类型组不被挤')
|
|
4871
4841
|
assert.ok(!/\.knit-types\{[^}]*padding/.test(source), '类型组不再自带左右内边距(.knit-bar 统一给)')
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
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(), '排序', '切检索模式不重置搜索词')
|
|
4875
5055
|
})
|
|
4876
5056
|
|
|
4877
5057
|
test('v0.21.x 开关「使用情况」不许把检索状态摘要顶下去(摘要紧贴工具栏,观察层在它下面)', async () => {
|
|
@@ -5013,3 +5193,342 @@ test('镜像常量:客户端的 REL_MAX 必须等于宿主的面板投影上
|
|
|
5013
5193
|
'客户端镜像必须与宿主一致 —— 否则「共 N 条关系」那句话会撒谎',
|
|
5014
5194
|
)
|
|
5015
5195
|
})
|
|
5196
|
+
|
|
5197
|
+
|
|
5198
|
+
/* ── v0.23(Phase A):检索模式选择器 + 语义 provider 最小配置区 ──────────
|
|
5199
|
+
这一版**只管呈现**:默认词法、语义默认关、没有 provider 时如实说不可用。
|
|
5200
|
+
Phase A **不动三层、不加 provenance 新值** —— 语义候选只计数(`semantic.candidates`)。
|
|
5201
|
+
契约(宿主由另一边实现,这里按冻结合同写):
|
|
5202
|
+
`/api/recent` 多一个 `semantic: { mode, requested, available, reason, candidates, provider }`;
|
|
5203
|
+
写只有 `POST /knit/api/semantic`;**没有** `GET`;`semantic` 字段可能整个不存在(老宿主)。 */
|
|
5204
|
+
|
|
5205
|
+
/** 把 v0.21 的载荷补上 v0.23 的 `semantic` 字段(不传 = 模拟**老宿主**:字段缺失)。 */
|
|
5206
|
+
function v023Payload(semantic, options = {}) {
|
|
5207
|
+
const base = v021Payload(options)
|
|
5208
|
+
return semantic === undefined ? base : { ...base, semantic }
|
|
5209
|
+
}
|
|
5210
|
+
|
|
5211
|
+
/** 装一个「记录 URL + 记录 POST body」的 fetch 替身(返回体按 url 决定)。 */
|
|
5212
|
+
function installSemanticFetch(payload, postReply = { ok: true, available: true, reason: null }) {
|
|
5213
|
+
const calls = []
|
|
5214
|
+
const posts = []
|
|
5215
|
+
globalThis.fetch = async (url, init = {}) => {
|
|
5216
|
+
const target = String(url)
|
|
5217
|
+
calls.push(target)
|
|
5218
|
+
if (target.includes('/api/semantic') && String(init.method || 'GET').toUpperCase() === 'POST') {
|
|
5219
|
+
posts.push(JSON.parse(init.body))
|
|
5220
|
+
return { json: async () => postReply }
|
|
5221
|
+
}
|
|
5222
|
+
if (target.includes('/api/links')) {
|
|
5223
|
+
return { json: async () => ({ ok: true, rel: 'x', incoming: [], outgoing: [], incomingTotal: 0, outgoingTotal: 0 }) }
|
|
5224
|
+
}
|
|
5225
|
+
return { json: async () => payload }
|
|
5226
|
+
}
|
|
5227
|
+
return { calls, posts }
|
|
5228
|
+
}
|
|
5229
|
+
|
|
5230
|
+
/**
|
|
5231
|
+
* 渲染一轮面板,可选先把检索模式偏好写进 localStorage。
|
|
5232
|
+
* ⚠️ 偏好**必须在 `harness.reset()` 之后**写:reset 会把 window / localStorage 换成新的替身,
|
|
5233
|
+
* 写在它前面等于没写(第一次跑这几条用例时正是在这里翻的车)。
|
|
5234
|
+
* @param {object} payload - fetch 载荷
|
|
5235
|
+
* @param {'lexical'|'hybrid'} [pref] - 要预置的检索模式
|
|
5236
|
+
* @returns {Promise<object>} 与 `mountWithPayload` 同形
|
|
5237
|
+
*/
|
|
5238
|
+
async function mountV023(payload, pref, sort = 'relevance') {
|
|
5239
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
5240
|
+
harness.reset()
|
|
5241
|
+
if (pref) globalThis.window.localStorage.setItem('dsh-knit:retrieval', pref)
|
|
5242
|
+
harness.seed(['', sort])
|
|
5243
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
5244
|
+
let nodes = render()
|
|
5245
|
+
await harness.flush()
|
|
5246
|
+
nodes = render()
|
|
5247
|
+
await harness.flush()
|
|
5248
|
+
nodes = render()
|
|
5249
|
+
return { nodes, render, renderAgain: async () => { nodes = render(); await harness.flush(); return render() } }
|
|
5250
|
+
}
|
|
5251
|
+
|
|
5252
|
+
/** 面板里所有可见文字(判断「有没有出现某句话」时用它)。 */
|
|
5253
|
+
function allText(nodes) {
|
|
5254
|
+
const root = byExactClass(nodes, 'knit-root')[0]
|
|
5255
|
+
return flattenUnder(root).map(textOf).join(' | ')
|
|
5256
|
+
}
|
|
5257
|
+
|
|
5258
|
+
test('v0.24:默认词法 —— 状态行那格可点(BM25 检索 + ›),未配 provider 也在', async () => {
|
|
5259
|
+
const { nodes } = await mountWithPayload(v021Payload())
|
|
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
|
+
'它必须**长在状态行里**(不是工具栏第二行)')
|
|
5265
|
+
assert.equal(btns[0].props['aria-haspopup'], 'true')
|
|
5266
|
+
assert.equal(btns[0].props['aria-expanded'], false, '默认收起')
|
|
5267
|
+
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, '收起时菜单一个节点都不产生(不是 display:none)')
|
|
5268
|
+
assert.equal(byExactClass(nodes, 'knit-retnote').length, 0, '词法模式:一句说明都不产生')
|
|
5269
|
+
assert.equal(byExactClass(nodes, 'knit-semcfg').length, 0, '词法模式:配置区不出现')
|
|
5270
|
+
const text = allText(nodes)
|
|
5271
|
+
assert.ok(!text.includes('语义候选'), `词法模式不许出现语义候选的计数:${text}`)
|
|
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, '两个选项照旧')
|
|
5305
|
+
})
|
|
5306
|
+
|
|
5307
|
+
test('v0.23 Phase A:切到「混合」—— 偏好落盘,且下一次取数带上 retrieval=hybrid', async () => {
|
|
5308
|
+
const payload = v021Payload()
|
|
5309
|
+
const { calls } = installSemanticFetch(payload)
|
|
5310
|
+
const { nodes: first, render, renderAgain } = await mountV023(payload)
|
|
5311
|
+
let nodes = first
|
|
5312
|
+
assert.ok(calls.every((url) => !url.includes('retrieval=hybrid')),
|
|
5313
|
+
`默认取数必须是词法:${calls.join(' | ')}`)
|
|
5314
|
+
assert.ok(calls.some((url) => url.includes('retrieval=lexical')),
|
|
5315
|
+
`默认取数要把词法**显式**带上(宿主据此完全不碰 provider):${calls.join(' | ')}`)
|
|
5316
|
+
|
|
5317
|
+
// 点开状态行那一格 → 两个选项的文案与选中态先核一遍 → 点「混合检索 · 实验」
|
|
5318
|
+
byExactClass(nodes, 'knit-pipe-method')[0].props.onClick()
|
|
5319
|
+
nodes = render()
|
|
5320
|
+
const items = byClass(nodes, 'knit-retmenu-item')
|
|
5321
|
+
assert.equal(items.length, 2, '菜单里两个选项')
|
|
5322
|
+
assert.deepEqual(items.map((b) => b.props['aria-checked']), [true, false], '选中态跟着当前模式走(默认词法)')
|
|
5323
|
+
const itemText = (node) => flattenUnder(node).map(textOf).join(' ')
|
|
5324
|
+
assert.ok(itemText(items[0]).includes('词法检索') && itemText(items[0]).includes('默认模式'),
|
|
5325
|
+
`选项一:词法检索 + 副文案:${itemText(items[0])}`)
|
|
5326
|
+
assert.ok(itemText(items[1]).includes('混合检索') && itemText(items[1]).includes('provider'),
|
|
5327
|
+
`选项二:混合检索 + 副文案:${itemText(items[1])}`)
|
|
5328
|
+
await items.find((b) => itemText(b).includes('混合检索')).props.onClick()
|
|
5329
|
+
nodes = await renderAgain()
|
|
5330
|
+
await harness.flush()
|
|
5331
|
+
nodes = render()
|
|
5332
|
+
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, '选完就收起菜单')
|
|
5333
|
+
assert.equal(globalThis.window.localStorage.getItem('dsh-knit:retrieval'), 'hybrid', '偏好应被记住')
|
|
5334
|
+
assert.ok(calls.some((url) => url.includes('retrieval=hybrid')),
|
|
5335
|
+
`切到混合后必须带上 retrieval=hybrid:${calls.join(' | ')}`)
|
|
5336
|
+
})
|
|
5337
|
+
|
|
5338
|
+
test('v0.23 Phase A:混合真的在跑时 —— 摘要那一格改口径并多一格「语义候选 N 条」', async () => {
|
|
5339
|
+
const payload = v023Payload({
|
|
5340
|
+
mode: 'hybrid', requested: 'hybrid', available: true, reason: null, candidates: 3,
|
|
5341
|
+
provider: { kind: 'ollama', base: 'http://127.0.0.1:11434', model: 'nomic-embed-text' },
|
|
5342
|
+
}, { relations: [{ type: 'references', dir: 'out', other: 'docs/b.md', line: 7 }] })
|
|
5343
|
+
installSemanticFetch(payload)
|
|
5344
|
+
const { nodes } = await mountV023(payload, 'hybrid')
|
|
5345
|
+
const pipe = byExactClass(nodes, 'knit-pipe')
|
|
5346
|
+
assert.equal(pipe.length, 1)
|
|
5347
|
+
const seq = flattenUnder(pipe[0]).slice(1).map(textOf)
|
|
5348
|
+
assert.ok(seq.includes('BM25 + 语义补充›'), `实际生效的是混合,摘要就必须这么说:${seq.join(' / ')}`)
|
|
5349
|
+
assert.ok(!seq.includes('BM25 检索›'), '不许在混合真的在跑时还写「词法检索」')
|
|
5350
|
+
assert.ok(seq.includes('语义候选 3 条'), `可用时要如实给候选数:${seq.join(' / ')}`)
|
|
5351
|
+
assert.equal(seq.filter((t) => t === '·').length, 5, '语义那一格进第二组 ⇒ 组内中点从 4 变 5')
|
|
5352
|
+
assert.equal(byExactClass(nodes, 'knit-retnote').length, 0, '混合在跑:没有「不可用」说明')
|
|
5353
|
+
assert.equal(byExactClass(nodes, 'knit-semcfg').length, 0, '混合在跑:不展开配置区')
|
|
5354
|
+
})
|
|
5355
|
+
|
|
5356
|
+
test('v0.23 Phase A:选了混合但宿主回词法(no-provider)—— 如实说原因 + 就地展开最小配置区', async () => {
|
|
5357
|
+
const payload = v023Payload({
|
|
5358
|
+
mode: 'lexical', requested: 'hybrid', available: false, reason: 'no-provider', candidates: 0, provider: null,
|
|
5359
|
+
})
|
|
5360
|
+
const { calls, posts } = installSemanticFetch(payload)
|
|
5361
|
+
const { nodes: first, renderAgain } = await mountV023(payload, 'hybrid')
|
|
5362
|
+
let nodes = first
|
|
5363
|
+
|
|
5364
|
+
const note = byExactClass(nodes, 'knit-retnote')
|
|
5365
|
+
assert.equal(note.length, 1, '不可用时必须有一行事实说明(不是每条结果里的噪声)')
|
|
5366
|
+
assert.match(textOf(note[0]), /还没有配置 provider/, `原因要来自宿主的码:${textOf(note[0])}`)
|
|
5367
|
+
// ⚠️ 摘要仍然写「BM25 检索」:**实际生效**的模式是词法,不是用户点了什么
|
|
5368
|
+
assert.ok(allText(nodes).includes('BM25 检索'), '没生效就还写词法')
|
|
5369
|
+
|
|
5370
|
+
// 菜单:状态行如实说「未配置 provider」,并给一条就地配置入口
|
|
5371
|
+
byExactClass(nodes, 'knit-pipe-method')[0].props.onClick()
|
|
5372
|
+
nodes = await renderAgain()
|
|
5373
|
+
assert.equal(textOf(byClass(nodes, 'knit-retmenu-note')[0]), '未配置 provider —— 混合还没生效。',
|
|
5374
|
+
'状态行如实写(不美化、不说成可用)')
|
|
5375
|
+
const entry = byClass(nodes, 'knit-retmenu-cfg')
|
|
5376
|
+
assert.equal(entry.length, 1, '未配 provider 时必须给「配置语义 provider…」入口')
|
|
5377
|
+
assert.match(textOf(entry[0]), /配置语义 provider/)
|
|
5378
|
+
// 点它:菜单收起、配置区就地展开,并且**第一个输入框拿到焦点**(键盘用户不用自己 Tab)
|
|
5379
|
+
// ⚠️ 假 React 的替身里**没有真 document**(`ensureStyle` 就是在 typeof 检查那里早退的),
|
|
5380
|
+
// 所以要临时给一个**够用的**:`getElementById` 回真值 ⇒ ensureStyle 直接早退,
|
|
5381
|
+
// 不会走到 createElement / head;`querySelector` 就是这一条要断言的那次聚焦。
|
|
5382
|
+
// 收尾必须把 document **整个还原/删掉** —— 第一版只删了 querySelector,
|
|
5383
|
+
// 留下的空对象把后面两条用例全打挂了(跨用例污染,单独跑却全绿)。
|
|
5384
|
+
const focused = []
|
|
5385
|
+
const hadDocument = 'document' in globalThis
|
|
5386
|
+
const prevDocument = globalThis.document
|
|
5387
|
+
globalThis.document = {
|
|
5388
|
+
getElementById: () => ({ id: 'knit-style' }),
|
|
5389
|
+
querySelector: (sel) => ({ focus: () => focused.push(sel) }),
|
|
5390
|
+
}
|
|
5391
|
+
try {
|
|
5392
|
+
entry[0].props.onClick()
|
|
5393
|
+
nodes = await renderAgain()
|
|
5394
|
+
} finally {
|
|
5395
|
+
if (hadDocument) globalThis.document = prevDocument
|
|
5396
|
+
else delete globalThis.document
|
|
5397
|
+
}
|
|
5398
|
+
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, '点入口会收起菜单')
|
|
5399
|
+
assert.deepEqual(focused, ['.knit-semcfg-input'], '配置区一展开就把焦点送进第一个输入框')
|
|
5400
|
+
|
|
5401
|
+
const cfg = byExactClass(nodes, 'knit-semcfg')
|
|
5402
|
+
assert.equal(cfg.length, 1, '点过入口后就地展开一行最小配置区')
|
|
5403
|
+
assert.deepEqual(byClass(flattenUnder(cfg[0]), 'knit-retseg-btn').map(textOf), ['Ollama(本地)', 'OpenAI 兼容'])
|
|
5404
|
+
const inputs = byClass(flattenUnder(cfg[0]), 'knit-semcfg-input')
|
|
5405
|
+
assert.equal(inputs.length, 2, 'base + model 两个输入框')
|
|
5406
|
+
assert.ok(byClass(flattenUnder(cfg[0]), 'knit-btn').map(textOf).includes('保存并测试'), '写路由只此一个按钮')
|
|
5407
|
+
assert.match(textOf(byClass(flattenUnder(cfg[0]), 'knit-semcfg-note')[0]), /填上服务地址后/,
|
|
5408
|
+
'空地址时给中性提示,不许说「不离开这台机器」也不许说「会发送到 —」')
|
|
5409
|
+
|
|
5410
|
+
// ① 回环地址 ⇒ 说「本地服务」
|
|
5411
|
+
inputs[0].props.onChange({ target: { value: 'http://127.0.0.1:11434' } })
|
|
5412
|
+
nodes = await renderAgain()
|
|
5413
|
+
let cfgNow = byExactClass(nodes, 'knit-semcfg')[0]
|
|
5414
|
+
assert.match(textOf(byClass(flattenUnder(cfgNow), 'knit-semcfg-note')[0]), /本地服务:内容不离开这台机器/,
|
|
5415
|
+
'回环地址才敢说不离开本机')
|
|
5416
|
+
|
|
5417
|
+
// ② 非回环 ⇒ 必须明写「内容会发送到你配置的服务 <base>」
|
|
5418
|
+
await byClass(flattenUnder(cfgNow), 'knit-retseg-btn').find((b) => textOf(b) === 'OpenAI 兼容').props.onClick()
|
|
5419
|
+
nodes = await renderAgain()
|
|
5420
|
+
cfgNow = byExactClass(nodes, 'knit-semcfg')[0]
|
|
5421
|
+
byClass(flattenUnder(cfgNow), 'knit-semcfg-input')[0].props.onChange({ target: { value: 'https://embed.example.com' } })
|
|
5422
|
+
nodes = await renderAgain()
|
|
5423
|
+
cfgNow = byExactClass(nodes, 'knit-semcfg')[0]
|
|
5424
|
+
assert.match(textOf(byClass(flattenUnder(cfgNow), 'knit-semcfg-note')[0]), /内容会发送到你配置的服务 https:\/\/embed\.example\.com/,
|
|
5425
|
+
'远程 provider 必须披露内容去向')
|
|
5426
|
+
|
|
5427
|
+
// ③ 「保存并测试」= 一次 POST,body 就是表单里的三格
|
|
5428
|
+
await byClass(flattenUnder(cfgNow), 'knit-btn').find((b) => textOf(b) === '保存并测试').props.onClick()
|
|
5429
|
+
await harness.flush()
|
|
5430
|
+
assert.equal(posts.length, 1, '保存只发一次 POST')
|
|
5431
|
+
assert.deepEqual(posts[0], { kind: 'openai-compatible', base: 'https://embed.example.com', model: '' })
|
|
5432
|
+
assert.ok(calls.some((url) => url.includes('/api/semantic')), '写路由是 /knit/api/semantic')
|
|
5433
|
+
})
|
|
5434
|
+
|
|
5435
|
+
test('v0.23 Phase A:老宿主(响应里没有 semantic 字段)—— 说清是宿主不支持,且不展开配置区', async () => {
|
|
5436
|
+
// ⚠️ 必须自己装 fetch:`mountV023` 不装(它要能被「装了记录型替身」的用例复用),
|
|
5437
|
+
// 不装就会沿用上一条用例留下的替身 —— 那会读到别的 payload(这里翻过一次车)。
|
|
5438
|
+
const payload = v023Payload(undefined)
|
|
5439
|
+
installSemanticFetch(payload)
|
|
5440
|
+
const { nodes } = await mountV023(payload, 'hybrid')
|
|
5441
|
+
const note = byExactClass(nodes, 'knit-retnote')
|
|
5442
|
+
assert.equal(note.length, 1)
|
|
5443
|
+
assert.match(textOf(note[0]), /当前宿主版本不支持/, '缺字段要说成宿主的问题,别让用户去配一个用不上的 provider')
|
|
5444
|
+
assert.equal(byExactClass(nodes, 'knit-semcfg').length, 0, '宿主不支持时不给配置区(配了也没用)')
|
|
5445
|
+
})
|
|
5446
|
+
|
|
5447
|
+
test('v0.23 Phase A:宿主缺 semantic 字段时不崩、也不改变默认词法的界面(静默降级)', async () => {
|
|
5448
|
+
const { nodes } = await mountWithPayload(v023Payload(undefined))
|
|
5449
|
+
assert.equal(byExactClass(nodes, 'knit-retnote').length, 0, '词法模式:老宿主也不产生说明行')
|
|
5450
|
+
assert.equal(byExactClass(nodes, 'knit-pipe').length, 1, '状态摘要照旧')
|
|
5451
|
+
assert.ok(allText(nodes).includes('BM25 检索'), '默认词法的呈现一个字不变')
|
|
5452
|
+
})
|
|
5453
|
+
|
|
5454
|
+
test('v0.23(2026-10-11):切到「最新」—— 搜索框右端那个下拉**整块不存在**(不是禁用、也不是 display:none)', async () => {
|
|
5455
|
+
/* 用户裁决 ①:检索模式只在「相关」档有意义。判据在代码里:时间序没有 Context Pack
|
|
5456
|
+
分层(宿主 `contextPayload()` 要求 `sort === 'relevance'`),语义候选无处可落。
|
|
5457
|
+
⇒ 这一档**一个节点都不产生**(不是置灰、不是隐藏),搜索框自己占满;
|
|
5458
|
+
顺便也不带 `retrieval=hybrid` 去白问宿主(宿主那侧已按 not-applicable 短路)。 */
|
|
5459
|
+
const payload = v023Payload({
|
|
5460
|
+
mode: 'lexical', requested: 'lexical', available: null, reason: null, candidates: 0, provider: null,
|
|
5461
|
+
})
|
|
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')
|
|
5467
|
+
let nodes = first
|
|
5468
|
+
|
|
5469
|
+
assert.equal(byExactClass(nodes, 'knit-pipe-method-wrap').length, 0, '时间序 ⇒ 状态行整行不出现,那一格自然也没有')
|
|
5470
|
+
assert.equal(byExactClass(nodes, 'knit-pipe-method').length, 0, '「不存在」要真不存在(拿 display:none 冒充是空转的绿灯)')
|
|
5471
|
+
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, '菜单更不该有')
|
|
5472
|
+
assert.equal(byExactClass(nodes, 'knit-searchwrap').length, 1, '搜索框还在(它自己占满,不留空位)')
|
|
5473
|
+
assert.equal(byClass(nodes, 'knit-filter').length, 1)
|
|
5474
|
+
assert.ok(calls.length > 0, '时间序也要取数')
|
|
5475
|
+
assert.ok(calls.every((url) => !url.includes('retrieval=hybrid')), `最新档不许白问混合:${calls.join(' | ')}`)
|
|
5476
|
+
assert.ok(calls.every((url) => url.includes('retrieval=lexical')), `最新档带的是词法:${calls.join(' | ')}`)
|
|
5477
|
+
|
|
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, '搜索框还在第二行')
|
|
5489
|
+
})
|
|
5490
|
+
|
|
5491
|
+
test('v0.23(2026-10-11):宿主回一个客户端不认识的 reason 码 —— 降级成「原因未知」,不许漏出裸键名', async () => {
|
|
5492
|
+
/* 判据 5 的界面面:宿主只给码,客户端查表。查不到时必须说「原因未知」,
|
|
5493
|
+
而不是把 `sem.reason.weird-code` 或者 `undefined` 渲染到界面上。 */
|
|
5494
|
+
const payload = v023Payload({
|
|
5495
|
+
mode: 'lexical', requested: 'hybrid', available: false, reason: 'weird-code', candidates: 0, provider: null,
|
|
5496
|
+
})
|
|
5497
|
+
installSemanticFetch(payload)
|
|
5498
|
+
const { nodes: first, renderAgain } = await mountV023(payload, 'hybrid')
|
|
5499
|
+
let nodes = first
|
|
5500
|
+
byExactClass(nodes, 'knit-pipe-method')[0].props.onClick()
|
|
5501
|
+
nodes = await renderAgain()
|
|
5502
|
+
|
|
5503
|
+
const note = textOf(byClass(nodes, 'knit-retmenu-note')[0])
|
|
5504
|
+
assert.match(note, /原因未知/, `未知码必须说「原因未知」:${note}`)
|
|
5505
|
+
assert.match(textOf(byExactClass(nodes, 'knit-retnote')[0]), /原因未知/, '事实行同一口径')
|
|
5506
|
+
const text = allText(nodes)
|
|
5507
|
+
for (const bad of ['sem.reason.', 'why.', 'undefined']) {
|
|
5508
|
+
assert.ok(!text.includes(bad), `不许把裸键名或空值渲染出来(${bad}):${text}`)
|
|
5509
|
+
}
|
|
5510
|
+
})
|
|
5511
|
+
|
|
5512
|
+
test('v0.23(2026-10-11):菜单的键盘关闭 —— Esc 收起菜单、不改当前模式,且 aria-expanded 跟着走', async () => {
|
|
5513
|
+
const payload = v023Payload({
|
|
5514
|
+
mode: 'lexical', requested: 'lexical', available: null, reason: null, candidates: 0, provider: null,
|
|
5515
|
+
})
|
|
5516
|
+
installSemanticFetch(payload)
|
|
5517
|
+
const { nodes: first, renderAgain } = await mountV023(payload, 'lexical')
|
|
5518
|
+
let nodes = first
|
|
5519
|
+
const btn = () => byExactClass(nodes, 'knit-pipe-method')[0]
|
|
5520
|
+
assert.equal(btn().props['aria-expanded'], false, '收起时 aria-expanded=false')
|
|
5521
|
+
btn().props.onClick()
|
|
5522
|
+
nodes = await renderAgain()
|
|
5523
|
+
assert.equal(btn().props['aria-expanded'], true, '开着时 aria-expanded=true(读屏据此播报)')
|
|
5524
|
+
// ⚠️ 容器要用 byExactClass:`byClass` 是**子串**匹配,`knit-retmenu` 会把
|
|
5525
|
+
// -item / -note / -cfg 一起数进来(这里 1 个容器 + 2 个选项 + 1 行状态 = 4)。
|
|
5526
|
+
assert.equal(byExactClass(nodes, 'knit-retmenu').length, 1)
|
|
5527
|
+
|
|
5528
|
+
btn().props.onKeyDown({ key: 'Escape', stopPropagation() {} })
|
|
5529
|
+
nodes = await renderAgain()
|
|
5530
|
+
assert.equal(byClass(nodes, 'knit-retmenu').length, 0, 'Esc 收起菜单')
|
|
5531
|
+
assert.equal(btn().props['aria-expanded'], false, 'aria-expanded 跟着回到 false')
|
|
5532
|
+
assert.equal(globalThis.window.localStorage.getItem('dsh-knit:retrieval') || 'lexical', 'lexical',
|
|
5533
|
+
'Esc 只关菜单,不改检索模式')
|
|
5534
|
+
})
|