dsh-knit 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +166 -0
- package/README.en.md +155 -9
- package/README.md +148 -14
- package/package.json +5 -2
- package/src/client/client.js +501 -197
- package/src/host/context.js +568 -0
- package/src/host/index.js +305 -20
- package/src/host/relevance.js +44 -6
- package/src/host/tool.js +274 -58
- package/test/client.test.mjs +488 -92
- package/test/context/fixture.mjs +553 -0
- package/test/context-eval.test.mjs +576 -0
- package/test/context.test.mjs +542 -0
- package/test/harness.mjs +33 -7
- package/test/host-http.test.mjs +71 -0
- package/test/host.test.mjs +105 -0
- package/test/i18n.test.mjs +46 -3
- package/test/tool.test.mjs +328 -96
- package/tools/json-schema-subset.mjs +89 -0
package/test/client.test.mjs
CHANGED
|
@@ -179,8 +179,13 @@ test('渲染:relevance 模式不做任何相关度可视化,只解释排序
|
|
|
179
179
|
|
|
180
180
|
assert.equal(byClass(nodes, 'knit-time').length, 2, '时间对所有行都一样显示')
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
// 2026-09-29 用户要求**弱化关键词**:可见文本只剩一句中性的「相关性排序」,
|
|
183
|
+
// 命中了哪几个词退到 title 里当低层 metadata(关键词是系统依据,不是主角)。
|
|
184
|
+
const topicNode = byClass(nodes, 'knit-topic')[0]
|
|
185
|
+
assert.equal(textOf(topicNode), '相关性排序', '可见文本里不许再出现关键词')
|
|
186
|
+
assert.ok(!textOf(topicNode).includes('sidebar'), '关键词不进可见文本')
|
|
187
|
+
assert.match(String(topicNode.props.title), /命中的关键词:相关性、sidebar/,
|
|
188
|
+
'关键词退到 title 里,悬停才给')
|
|
184
189
|
})
|
|
185
190
|
|
|
186
191
|
test('渲染:相关度分数只影响顺序,不影响任何一行的渲染', async () => {
|
|
@@ -1036,79 +1041,114 @@ test('媒体:mediaLayoutFor —— 列数只跟可用宽度走,格子基准
|
|
|
1036
1041
|
assert.ok(!('maxHeight' in mediaLayoutFor(632)), '连这个键都不该存在')
|
|
1037
1042
|
})
|
|
1038
1043
|
|
|
1039
|
-
test('
|
|
1044
|
+
test('文档:列表永远单列 —— 多列那套(docLayoutFor / .knit-multicol)已整体删除', () => {
|
|
1040
1045
|
const client = loadClientModule().exports.__test
|
|
1041
|
-
const { docLayoutFor, DOC_TRACK_PX, DOC_GRID_MAX_COLS, DOC_SUMMARY_MIN_PX, MEDIA_GAP_PX } = client
|
|
1042
1046
|
|
|
1043
|
-
assert.equal(DOC_TRACK_PX, 205, '格子下限由「2–3 列时摘要还放得下」反推(150px 会让 632px 排到 4 列)')
|
|
1044
1047
|
// 演进:4 列 → 3 列(「视觉跳动信息过载」)→ 2 列(交互评审:3 列摘要每行只剩 16 字)
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
//
|
|
1049
|
-
assert.
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
assert.equal(docLayoutFor(w).compact, false, `${w}px:1 列不是多列态`)
|
|
1055
|
-
}
|
|
1048
|
+
// → **1 列(2026-09-29 用户拍板:「文档列表最多一个就行,现在一行两个有点太多了」)**。
|
|
1049
|
+
// ⚠️ 最后一版是**删除**,不是「把上限从 2 改成 1」:留着一套永远算不出 2 列的代码
|
|
1050
|
+
// (`docLayoutFor` 本身、`DOC_TRACK_PX` / `DOC_SUMMARY_MIN_PX` 这类只为多列存在的常量),
|
|
1051
|
+
// 下一个人只会以为它还在生效。所以这四条守的是「它真的没了」。
|
|
1052
|
+
assert.equal(client.docLayoutFor, undefined, 'docLayoutFor 该删掉,不是留着不用')
|
|
1053
|
+
assert.equal(client.DOC_TRACK_PX, undefined, 'DOC_TRACK_PX 该删掉(只为算格子宽而存在)')
|
|
1054
|
+
assert.equal(client.DOC_GRID_MAX_COLS, undefined, 'DOC_GRID_MAX_COLS 该删掉')
|
|
1055
|
+
assert.equal(client.DOC_SUMMARY_MIN_PX, undefined, 'DOC_SUMMARY_MIN_PX 该删掉')
|
|
1056
|
+
})
|
|
1056
1057
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1058
|
+
test('文档:序号是最左边一列,行一=「点 + 标题 + 时间」(时间靠右)', async () => {
|
|
1059
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1060
|
+
|
|
1061
|
+
// ⚠️ 2026-09-29 用户追加要求:「文档列表序号放在独立最左边,其他数据放在右边」。
|
|
1062
|
+
// 所以序号**从行一里搬了出去**,成为 .knit-doc 这条两列 grid 的第一列 ——
|
|
1063
|
+
// 一条行的直接子节点恰好两个:左边那一列序号 + 右边那一列全部数据(.knit-body)。
|
|
1064
|
+
const docs = byClass(nodes, 'knit-doc')
|
|
1065
|
+
assert.ok(docs.length > 0, '要有文档行')
|
|
1066
|
+
const numbered = docs.filter((d) => classesUnder(d).includes('knit-num'))
|
|
1067
|
+
assert.ok(numbered.length > 0, '这个包里得有带序号的行')
|
|
1068
|
+
for (const doc of numbered) {
|
|
1069
|
+
assert.deepEqual(
|
|
1070
|
+
doc.children.slice(0, 2).map((c) => String((c && c.props && c.props.className) || '')),
|
|
1071
|
+
['knit-num', 'knit-body'],
|
|
1072
|
+
'一行=最左边一列序号 + 右边一列其余数据',
|
|
1073
|
+
)
|
|
1064
1074
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
assert.
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
// ⚠️ 核心约束:**compact 与列数同源**(不能出现「排了 2 列但还是 1 列的样子」)
|
|
1073
|
-
for (let w = 100; w <= 2000; w += 25) {
|
|
1074
|
-
const { columns, compact } = docLayoutFor(w)
|
|
1075
|
-
assert.equal(compact, columns > 1, `${w}px:compact 必须 == (columns > 1)`)
|
|
1075
|
+
// 没有序号的行(时间序 / 筛选结果 /「其他相关文档」)**不渲染序号节点**,但它们
|
|
1076
|
+
// 也**不许掉进第一列** —— 靠 .knit-body 的 grid-column 定死位置(用自动排布就会掉)。
|
|
1077
|
+
const unnumbered = docs.filter((d) => !classesUnder(d).includes('knit-num'))
|
|
1078
|
+
assert.ok(unnumbered.length > 0, '这个 payload 里有不编号的条目')
|
|
1079
|
+
for (const doc of unnumbered) {
|
|
1080
|
+
assert.equal(String((doc.children[0] && doc.children[0].props.className) || ''), 'knit-body',
|
|
1081
|
+
'没有序号时正文也要落在第二列,和有条目的行左边缘对齐')
|
|
1076
1082
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
+
|
|
1084
|
+
const rows = byExactClass(nodes, 'knit-row1')
|
|
1085
|
+
assert.ok(rows.length > 0, '要有行一')
|
|
1086
|
+
for (const row of rows) {
|
|
1087
|
+
const cls = classesUnder(row)
|
|
1088
|
+
// 2026-09-29 这一天里这一行改了三次,最后落在:**点 + 标题 + 时间(时间靠右)**。
|
|
1089
|
+
// 用户最后一条原话:「将时间放到标题同行,时间放在右边,然后标题跟时间就可以
|
|
1090
|
+
// 以序号平行,居中平行」⇒ 标题**回到行一**(先前那条「标题独占一行」作废)。
|
|
1091
|
+
assert.ok(cls.some((c) => c.includes('knit-title')), '标题就在行一里')
|
|
1092
|
+
assert.ok(cls.some((c) => c.includes('knit-time')), '时间也在行一里(靠右)')
|
|
1093
|
+
assert.equal(cls.some((c) => c.includes('knit-sum')), false, '摘要不在行一里')
|
|
1094
|
+
// **顺序**也是这一行的一部分:标题必须在时间前面,反了时间就跑到标题左边。
|
|
1095
|
+
const kids = (row.children || []).map((c) => String((c && c.props && c.props.className) || ''))
|
|
1096
|
+
assert.equal(kids.filter((c) => c === 'knit-title').length, 1, '行一里恰好一个标题')
|
|
1097
|
+
assert.equal(kids.filter((c) => c === 'knit-time').length, 1, '行一里恰好一个时间')
|
|
1098
|
+
assert.ok(kids.indexOf('knit-title') < kids.indexOf('knit-time'), '标题在时间左边')
|
|
1083
1099
|
}
|
|
1084
1100
|
|
|
1085
|
-
// ⚠️
|
|
1086
|
-
//
|
|
1087
|
-
//
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1101
|
+
// ⚠️ 2026-09-29:**列表行里不再有路径**。用户原话:「文档列表中的文档路径,我觉得不需要
|
|
1102
|
+
// 出现了,因为点开查看文档详情的时候已经有了,所以这里是重复的,隐藏掉」。
|
|
1103
|
+
// 守的是「那个节点真的没了」,**不是**「它被 display:none 藏了」—— 两者看代码的人
|
|
1104
|
+
// 会得出完全不同的结论(后者会让人以为样式一改就回来)。
|
|
1105
|
+
assert.equal(byClass(nodes, 'knit-meta').length, 0, '列表里不该再有路径节点')
|
|
1106
|
+
assert.equal(nodes.every((n) => !String(n.className || '').includes('knit-meta')), true,
|
|
1107
|
+
'knit-meta 这个类名应该整体消失,不是留在某处隐藏')
|
|
1108
|
+
// 反证:行的定位**不靠可见路径** —— data-knit-rel 仍在(键盘 / 预览映射靠它)。
|
|
1109
|
+
assert.equal(byClass(nodes, 'knit-doc').every((d) => typeof d.props['data-knit-rel'] === 'string'), true,
|
|
1110
|
+
'每行仍要带 data-knit-rel')
|
|
1111
|
+
|
|
1112
|
+
// 标题仍然挨着自己的那一行(现在它就在行一里):每条文档恰好一个标题。
|
|
1113
|
+
for (const doc of docs) {
|
|
1114
|
+
assert.equal(classesUnder(doc).filter((c) => c === 'knit-title').length, 1, '恰好一个标题')
|
|
1094
1115
|
}
|
|
1095
|
-
// 兜底分支本身必须能用:格子真的窄到放不下时,摘要让位
|
|
1096
|
-
assert.equal(docLayoutFor(420).summary, true, '2 列 205px 格:摘要保留')
|
|
1097
|
-
assert.equal(docLayoutFor(400).summary, true, '1 列时摘要永远在')
|
|
1098
1116
|
})
|
|
1099
1117
|
|
|
1100
|
-
test('
|
|
1118
|
+
test('样式:类型切换是下划线式页签,选中态不用品牌色也不用灰底', async () => {
|
|
1101
1119
|
const { readFileSync } = await import('node:fs')
|
|
1102
1120
|
const { fileURLToPath } = await import('node:url')
|
|
1103
1121
|
const source = readFileSync(fileURLToPath(new URL('../src/client/client.js', import.meta.url)), 'utf8')
|
|
1104
1122
|
|
|
1105
|
-
//
|
|
1123
|
+
// v0.14(Design §20):三个并排的灰底按钮改成下划线式页签。
|
|
1124
|
+
// ⚠️ 2026-09-29 用户裁决:这条**覆盖**了更早那条「选中填充背景灰就可以」。
|
|
1125
|
+
// 早先那句的诉求是「别加绿色、蓝色的描边」,现在连灰底也不要了。
|
|
1106
1126
|
const rule = source.match(/\.knit-type-btn\.active\{([^}]*)\}/)
|
|
1107
1127
|
assert.ok(rule, '必须还有 .knit-type-btn.active 这条规则')
|
|
1108
1128
|
assert.ok(!rule[1].includes('--knit-accent'), `选中态不许再出现品牌色:${rule[1]}`)
|
|
1109
|
-
|
|
1129
|
+
assert.match(rule[1], /border-bottom-color:/, '选中态靠下划线表达层级')
|
|
1130
|
+
assert.ok(!rule[1].includes('background:var(--knit-active-bg'),
|
|
1131
|
+
'下划线式页签不许再退回灰底按钮——两者叠加会同时占用两种「选中」表达')
|
|
1132
|
+
// 页签条本身要有那条 hairline,否则下划线悬空
|
|
1133
|
+
assert.match(source, /\.knit-types\{[^}]*border-bottom:1px solid/, '页签条要有底边')
|
|
1134
|
+
})
|
|
1135
|
+
|
|
1136
|
+
test('样式:列表行的「正在预览」是中性描边,不再是品牌色描边', async () => {
|
|
1137
|
+
const { readFileSync } = await import('node:fs')
|
|
1138
|
+
const { fileURLToPath } = await import('node:url')
|
|
1139
|
+
const source = readFileSync(fileURLToPath(new URL('../src/client/client.js', import.meta.url)), 'utf8')
|
|
1140
|
+
|
|
1141
|
+
// v0.14(Design §12 / §8):用户 2026-09-29 裁决改成 neutral border。
|
|
1142
|
+
// ⚠️ 这条**覆盖**了 AGENTS.md §4.1.2 里那句「列表行『正在预览』的品牌色描边是故意留的」。
|
|
1143
|
+
// 理由是 Design §8「用灰阶建立层级,而不是用颜色建立层级」。
|
|
1144
|
+
const rule = source.match(/\.knit-doc\.active\{([^}]*)\}/)
|
|
1145
|
+
assert.ok(rule, '必须还有 .knit-doc.active 这条规则')
|
|
1146
|
+
assert.ok(!rule[1].includes('--knit-accent'),
|
|
1147
|
+
`列表行选中态不许再出现品牌色:${rule[1]}`)
|
|
1148
|
+
assert.match(rule[1], /border-color:var\(--dsw-alias-border-l4/,
|
|
1149
|
+
'选中态用中性描边(与键盘光标同一档工具色)')
|
|
1110
1150
|
assert.match(rule[1], /background:var\(--knit-active-bg/,
|
|
1111
|
-
'
|
|
1151
|
+
'选中态仍然保留灰底——描边只说明「在哪儿」,填充才说明「选中了」')
|
|
1112
1152
|
})
|
|
1113
1153
|
|
|
1114
1154
|
test('样式:悬停 / 选中的灰底各降一档(悬停 −60% / 选中 −40%),两个主题都给了值', async () => {
|
|
@@ -1133,52 +1173,84 @@ test('样式:悬停 / 选中的灰底各降一档(悬停 −60% / 选中 −
|
|
|
1133
1173
|
assert.match(css, /\.knit-media-thumbbox\{[^}]*background:var\(--dsw-alias-interactive-bg-hover/)
|
|
1134
1174
|
})
|
|
1135
1175
|
|
|
1136
|
-
test('
|
|
1176
|
+
test('样式:文档列表没有网格 —— 多列那套已整体删除,容器类名不与 knit-doc 撞前缀', async () => {
|
|
1137
1177
|
const { readFileSync } = await import('node:fs')
|
|
1138
1178
|
const { fileURLToPath } = await import('node:url')
|
|
1139
1179
|
const source = readFileSync(fileURLToPath(new URL('../src/client/client.js', import.meta.url)), 'utf8')
|
|
1140
1180
|
const start = source.indexOf('const CSS = `') + 'const CSS = `'.length
|
|
1141
1181
|
const css = source.slice(start, source.indexOf('`', start)).replace(/\/\*[\s\S]*?\*\//g, '')
|
|
1182
|
+
// JS 侧扫的是**剥掉注释**的源码:注释里会有意保留「这里曾经有什么」的说明
|
|
1183
|
+
// (那是有价值的历史),所以「标识符不许再出现」只能在代码上判。
|
|
1184
|
+
const code = source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '')
|
|
1142
1185
|
|
|
1143
|
-
//
|
|
1144
|
-
//
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
//
|
|
1148
|
-
assert.ok(
|
|
1149
|
-
assert.ok(
|
|
1150
|
-
assert.ok(
|
|
1186
|
+
// 2026-09-29 用户拍板「最多一个」⇒ 上限由 2 列改成 1 列,做法是**删除**:
|
|
1187
|
+
// 容器规则、列数类、卡片样式、摘要让位、`transform:none` 兜底,全没了。
|
|
1188
|
+
// ⚠️ 这几条在删之前都是「必须存在」;现在反过来守「必须不存在」——
|
|
1189
|
+
// 只删一半(CSS 留着 .knit-multicol.cols-2、而 JS 不再加类)才是最坏的状态:
|
|
1190
|
+
// 读代码的人会以为它还生效。
|
|
1191
|
+
assert.ok(!css.includes('knit-multicol'), '文档多列的容器规则该删干净')
|
|
1192
|
+
assert.ok(!/cols-[234]\b/.test(css), '列数类(cols-2 / cols-3 / cols-4)该删干净')
|
|
1193
|
+
assert.ok(!css.includes('auto-fit') || css.includes('.knit-media-grid'),
|
|
1194
|
+
'auto-fit 只许留给媒体网格')
|
|
1151
1195
|
// ⚠️ 容器类名里**不能含 `knit-doc`**:byClass 是子串匹配,会把它当成一个文档行
|
|
1152
1196
|
// (§6.5 那个坑的第三次;旧名 knit-doc-grid 就是踩了这个)。
|
|
1153
|
-
assert.ok(
|
|
1197
|
+
assert.ok(!code.includes('knit-doc-grid'), '容器类名不许是 knit-doc* 前缀(会被 byClass 误命中)')
|
|
1154
1198
|
assert.ok(!/\.knit-list\.cols-/.test(css),
|
|
1155
1199
|
'列数类只许加在文档容器上 —— .knit-list 是唯一滚动容器,媒体档与「全部」都在它里面')
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
assert.ok(!/\.knit-
|
|
1164
|
-
|
|
1165
|
-
//
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
//
|
|
1170
|
-
assert.
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
}
|
|
1200
|
+
// JS 侧也一并没了。「布局函数不许吃条目数」那条守卫跟着退休 —— 函数都不在了。
|
|
1201
|
+
assert.ok(!code.includes('docLayoutFor'), '源码里不该再有 docLayoutFor')
|
|
1202
|
+
assert.ok(!/DOC_TRACK_PX|DOC_SUMMARY_MIN_PX|DOC_GRID_(MIN|MAX)_COLS/.test(code),
|
|
1203
|
+
'只为多列存在的常量该删干净')
|
|
1204
|
+
|
|
1205
|
+
// 数据一个不砍(这一条从「多列不砍数据」升级成「永远不砍数据」):
|
|
1206
|
+
// 摘要不该再有 display:none 这条路(第一版的错就是「只剩标题 + 时间」)。
|
|
1207
|
+
assert.ok(!/\.knit-sum[^{]*\{[^}]*display:none/.test(css), '摘要不再有「让位」这条路')
|
|
1208
|
+
// ⚠️ **路径(knit-meta)在 2026-09-29 被用户要求整体删掉**,理由见上面那条测试:
|
|
1209
|
+
// 它和预览头的面包屑重复。所以断言要**反过来写** —— 不再是「路径任何情况下都保留」,
|
|
1210
|
+
// 而是「这个类名真的没了」;写成旧的 `!…display:none` 会变成一盏空转的绿灯
|
|
1211
|
+
// (类名不存在时它也通过,但什么也没守住)。
|
|
1212
|
+
// 仍然不许 display:none 的只有**摘要**:那条守的是「不许因为排版窄就静默少给信息」,
|
|
1213
|
+
// 而路径是**重复信息**,删它不违反那条教训。
|
|
1214
|
+
assert.ok(!code.includes('knit-meta'), '路径那一行应该整体消失,不是换个方式藏起来')
|
|
1215
|
+
// 反证:路径仍然有地方显示 —— 预览头的面包屑(目录浅 + 文件名亮,还可点)。
|
|
1216
|
+
assert.match(code, /className: 'knit-preview-path'/, '预览头必须还有路径面包屑')
|
|
1217
|
+
assert.match(code, /className: 'knit-preview-name'/, '面包屑里要有文件名')
|
|
1218
|
+
// 标题不再折行(折行是为窄格子写的,现在「格子」这个概念都不存在了)
|
|
1219
|
+
assert.ok(!/\.knit-title\{[^}]*-webkit-line-clamp/.test(css), '标题不再折两行')
|
|
1220
|
+
|
|
1221
|
+
// ⚠️ 行一=**标题行**:Primary 点 + 标题 + 时间(时间靠右)。2026-09-29 用户最后一条要求是
|
|
1222
|
+
// 「将时间放到标题同行,时间放在右边,然后标题跟时间就可以以序号平行,居中平行」——
|
|
1223
|
+
// 它**推翻了同一天早先的「标题独占一行」**,所以下面这两条断言是反过来的。
|
|
1224
|
+
// 间距也从标题挪到了行一(行一 margin-bottom:5px,标题不再留 margin)。
|
|
1225
|
+
assert.match(css, /\.knit-row1\{display:flex;align-items:center;gap:8px;margin-bottom:5px\}/)
|
|
1226
|
+
assert.ok(!/\.knit-title\{[^}]*margin-bottom/.test(css), '间距归行一,不在标题上')
|
|
1227
|
+
// 标题 flex:1 1 auto + min-width:0 是「时间被推到行尾 + 长标题在时间之前省略」的前提;
|
|
1228
|
+
// 这里也钉住 .knit-num 的行高 = .knit-title 的 14px × 1.4 = 19.6px —— 序号与标题第一行
|
|
1229
|
+
// **垂直居中**靠的正是这两个数字对齐,改一处必须改另一处
|
|
1230
|
+
// (v0.14 规格 §15 把文档标题提到 14px,所以这一对数字一起变了)。
|
|
1231
|
+
assert.match(css, /\.knit-title\{flex:1 1 auto;min-width:0;font-weight:600;font-size:14px;line-height:1\.4;/)
|
|
1232
|
+
assert.match(css, /\.knit-num\{grid-column:1;font-size:10\.5px;line-height:19\.6px;/)
|
|
1233
|
+
|
|
1234
|
+
// ⚠️ 行的**静止态没有底色**(2026-09-29 用户看了暗色主题之后要求:
|
|
1235
|
+
// 「深色模式下,文档列表没有选中,鼠标没有悬停,不需要有背景。或者是说,跟深色模式的最底下的
|
|
1236
|
+
// 背景一样」)。这条断言是有来历的:以前写 bg-layer-1,**浅色主题下它和 .knit-pack 的
|
|
1237
|
+
// bg-base 都是 #fff**(根本看不出来),**暗色主题下它比底色亮一档** ⇒ 每一行都像一张浮起来的
|
|
1238
|
+
// 小卡片,哪怕没选中、没悬停。现在静止态 transparent,露出 .knit-pack 的底色。
|
|
1239
|
+
// hover / .active 各自有令牌,**不该**跟着变 transparent —— 那样一屏灰里就认不出选中态了。
|
|
1240
|
+
assert.match(css, /\.knit-doc\{[^}]*background:transparent/,
|
|
1241
|
+
'行的静止态要露出面板底色(暗色下 bg-layer-1 比底色亮,每行都会像卡片)')
|
|
1242
|
+
assert.ok(!/\.knit-doc\{[^}]*background:var\(--dsw-alias-bg-layer-1/.test(css),
|
|
1243
|
+
'静止态别再走 bg-layer-1')
|
|
1244
|
+
assert.match(css, /\.knit-doc\.active\{[^}]*background:var\(--knit-active-bg/,
|
|
1245
|
+
'选中态必须仍然有底色 —— 它是一屏灰里唯一的分层信号')
|
|
1246
|
+
|
|
1247
|
+
// ⚠️ 2026-09-29:列表行改成**两列 grid** —— 序号占最左边一列,其余数据全在第二列
|
|
1248
|
+
// (用户原话:「文档列表序号放在独立最左边,其他数据放在右边」)。
|
|
1249
|
+
// 第二列必须是 minmax(0,1fr):不然长标题会把行撑宽,省略号失效。
|
|
1250
|
+
assert.match(css, /\.knit-doc\{display:grid;grid-template-columns:22px minmax\(0,1fr\)/)
|
|
1251
|
+
assert.match(css, /\.knit-num\{grid-column:1;/)
|
|
1252
|
+
assert.match(css, /\.knit-body\{grid-column:2;min-width:0\}/,
|
|
1253
|
+
'第二列的位置与 min-width:0 都要写死 —— 少一个长标题就会把行撑宽')
|
|
1182
1254
|
})
|
|
1183
1255
|
|
|
1184
1256
|
test('样式:媒体网格靠 auto-fill 连续加列,格子基准与 JS 常量同源', async () => {
|
|
@@ -1531,3 +1603,327 @@ test('引用条:图片/视频不请求 /api/links(图里只有 .md,请求
|
|
|
1531
1603
|
assert.ok(!calls.some((u) => u.includes('/api/links')), '媒体不该请求引用关系')
|
|
1532
1604
|
assert.equal(byClass(nodes, 'knit-links').length, 0, '媒体不显示引用条')
|
|
1533
1605
|
})
|
|
1606
|
+
|
|
1607
|
+
/* ── v0.14 当前任务上下文(Context Pack)─────────────────
|
|
1608
|
+
面板这一层的职责是**纯投影**:分组、顺序、理由全部来自宿主,
|
|
1609
|
+
客户端一个分组规则都不许重写(否则就会出现两套排序逻辑)。 */
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* 造一份带 Context Pack 的相关模式载荷。
|
|
1613
|
+
* @param {object} [overrides] - 覆盖字段
|
|
1614
|
+
* @returns {object} 载荷
|
|
1615
|
+
*/
|
|
1616
|
+
function contextPayload(overrides = {}) {
|
|
1617
|
+
const at = Date.now()
|
|
1618
|
+
const item = (rel, title, reason) => ({
|
|
1619
|
+
rel,
|
|
1620
|
+
path: `/p/${rel}`,
|
|
1621
|
+
name: rel.split('/').pop(),
|
|
1622
|
+
title,
|
|
1623
|
+
summary: `摘要 ${title}`,
|
|
1624
|
+
mtimeMs: at,
|
|
1625
|
+
kind: 'md',
|
|
1626
|
+
source: 'doc',
|
|
1627
|
+
reason,
|
|
1628
|
+
})
|
|
1629
|
+
return {
|
|
1630
|
+
ok: true,
|
|
1631
|
+
root: '/p',
|
|
1632
|
+
total: 5,
|
|
1633
|
+
mode: 'relevance',
|
|
1634
|
+
topic: 'BM25、排序',
|
|
1635
|
+
keywords: ['bm25', '排序'],
|
|
1636
|
+
docs: [
|
|
1637
|
+
{ path: '/p/docs/algo.md', rel: 'docs/algo.md', name: 'algo.md', title: '排序算法', summary: '摘要', mtimeMs: at, score: 100 },
|
|
1638
|
+
{ path: '/p/docs/eval.md', rel: 'docs/eval.md', name: 'eval.md', title: '排序评测', summary: '摘要', mtimeMs: at, score: 40 },
|
|
1639
|
+
{ path: '/p/CHANGELOG.md', rel: 'CHANGELOG.md', name: 'CHANGELOG.md', title: '变更记录', summary: '摘要', mtimeMs: at, score: 12 },
|
|
1640
|
+
{ path: '/p/README.md', rel: 'README.md', name: 'README.md', title: 'Knit', summary: '摘要', mtimeMs: at, score: 0 },
|
|
1641
|
+
{ path: '/p/docs/other.md', rel: 'docs/other.md', name: 'other.md', title: '无关文档', summary: '摘要', mtimeMs: at, score: 0 },
|
|
1642
|
+
],
|
|
1643
|
+
context: {
|
|
1644
|
+
mode: 'relevance',
|
|
1645
|
+
topic: 'BM25、排序',
|
|
1646
|
+
task: '',
|
|
1647
|
+
primary: [item('docs/algo.md', '排序算法', { code: 'titleMatch', terms: ['排序'], fields: 2 })],
|
|
1648
|
+
supporting: [
|
|
1649
|
+
item('docs/eval.md', '排序评测', { code: 'bodyMatch', terms: ['bm25'], fields: 1 }),
|
|
1650
|
+
item('CHANGELOG.md', '变更记录', { code: 'linkSource', terms: [], fields: 0 }),
|
|
1651
|
+
],
|
|
1652
|
+
related: [item('README.md', 'Knit', { code: 'related', terms: [], fields: 0 })],
|
|
1653
|
+
totals: { primary: 1, supporting: 2, related: 1, matched: 3, total: 5 },
|
|
1654
|
+
summary: { primary: 1, supporting: 2, related: 1, shown: 4, matched: 3, total: 5 },
|
|
1655
|
+
},
|
|
1656
|
+
...overrides,
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
/**
|
|
1661
|
+
* 挂上 KnitBody 并等首帧数据到位。
|
|
1662
|
+
*
|
|
1663
|
+
* 返回的 `renderAgain()` 用**同一份 hook 状态**重渲染 —— 断言跨帧状态
|
|
1664
|
+
* (cursor / preview)时必须用它,另起一次 `KnitBody` 会是全新状态(AGENTS.md §6.2)。
|
|
1665
|
+
*
|
|
1666
|
+
* @param {object} payload - `fetch` 的载荷
|
|
1667
|
+
* @returns {Promise<{nodes:object[], render:s Function}>} 首帧节点与重渲染函数
|
|
1668
|
+
*/
|
|
1669
|
+
async function mountWithPayload(payload) {
|
|
1670
|
+
installFetch((url) => (url.includes('/api/links')
|
|
1671
|
+
? { ok: true, rel: 'x', incoming: [], outgoing: [], incomingTotal: 0, outgoingTotal: 0 }
|
|
1672
|
+
: payload))
|
|
1673
|
+
const { KnitBody } = loadClientModule().exports.__test
|
|
1674
|
+
harness.reset()
|
|
1675
|
+
// 前两个 hook 槽位是 notice / sort —— 预置成相关序,面板才会去用 Context Pack
|
|
1676
|
+
harness.seed(['', 'relevance'])
|
|
1677
|
+
const render = () => harness.render(h(KnitBody, { sessionId: 's1' }))
|
|
1678
|
+
// ⚠️ 数据到位后要再走一轮 render → flush → render:cursor 是在**数据到达之后**
|
|
1679
|
+
// 那一轮 effect 里落位的(AGENTS.md §6.2:断言前少一轮就会停在初值)。
|
|
1680
|
+
let nodes = render()
|
|
1681
|
+
await harness.flush()
|
|
1682
|
+
nodes = render()
|
|
1683
|
+
await harness.flush()
|
|
1684
|
+
nodes = render()
|
|
1685
|
+
return { nodes, render, renderAgain: async () => { nodes = render(); await harness.flush(); return render() } }
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
test('上下文:分层视图渲染三档 + 极短提示(右栏那块标题 / 计数已删)', async () => {
|
|
1689
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1690
|
+
// ⚠️ 必须 byExactClass:`knit-tier` 是 `knit-tierline` / `knit-tiername` 的子串
|
|
1691
|
+
const tiers = byExactClass(nodes, 'knit-tier')
|
|
1692
|
+
assert.equal(tiers.length, 4, '三层 + 「其他相关文档」')
|
|
1693
|
+
const titles = byExactClass(nodes, 'knit-tiername').map(textOf)
|
|
1694
|
+
assert.deepEqual(titles, ['主要上下文', '辅助上下文', '相关上下文', '其他相关文档'])
|
|
1695
|
+
// 提示语是中性说明,不是「AI 推荐」这类话术
|
|
1696
|
+
assert.ok(
|
|
1697
|
+
byExactClass(nodes, 'knit-tierhint').map(textOf).join(' ').includes('先看'),
|
|
1698
|
+
'主要上下文要有一句「先看」的提示',
|
|
1699
|
+
)
|
|
1700
|
+
// 提示语**必须极短**(2026-09-29 用户要求):它是「先看 / 辅助 / 背景」这一档,
|
|
1701
|
+
// 不许再长成「先看这几篇 / 证据与实现支撑」那样的说明句。
|
|
1702
|
+
assert.deepEqual(
|
|
1703
|
+
byExactClass(nodes, 'knit-tierhint').map(textOf),
|
|
1704
|
+
['先看', '辅助', '背景'],
|
|
1705
|
+
'组后面的解释只能两三个字',
|
|
1706
|
+
)
|
|
1707
|
+
// 右栏那一整块(包标题 / 命中计数)已经删除,断言也一起删 —— 见下面的「单栏」守卫
|
|
1708
|
+
assert.equal(byClass(nodes, 'knit-pack-title').length, 0)
|
|
1709
|
+
})
|
|
1710
|
+
|
|
1711
|
+
test('上下文:分组顺序就是宿主给的顺序,客户端不重排', async () => {
|
|
1712
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1713
|
+
// DOM 顺序:primary 的条目 → supporting → related → 其他
|
|
1714
|
+
const rels = byClass(nodes, 'knit-doc').map((n) => n.props['data-knit-rel'])
|
|
1715
|
+
assert.deepEqual(rels, [
|
|
1716
|
+
'docs/algo.md',
|
|
1717
|
+
'docs/eval.md',
|
|
1718
|
+
'CHANGELOG.md',
|
|
1719
|
+
'README.md',
|
|
1720
|
+
'docs/other.md',
|
|
1721
|
+
])
|
|
1722
|
+
// 「其他相关文档」里是宿主没有放进任何一层的那篇
|
|
1723
|
+
const sections = byExactClass(nodes, 'knit-tier')
|
|
1724
|
+
const last = sections[sections.length - 1]
|
|
1725
|
+
assert.match(textOf(last), /其他相关文档/)
|
|
1726
|
+
assert.match(textOf(last), /无关文档/)
|
|
1727
|
+
})
|
|
1728
|
+
|
|
1729
|
+
test('上下文:每一条都带「为什么在这里」,且理由来自宿主给的码', async () => {
|
|
1730
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1731
|
+
const why = byClass(nodes, 'knit-why').map(textOf)
|
|
1732
|
+
assert.equal(why.length, 4, 'Context Pack 的四个条目各一行;「其他」区那篇没有理由')
|
|
1733
|
+
assert.match(why[0], /标题命中:排序/)
|
|
1734
|
+
assert.match(why[1], /正文命中:bm25/)
|
|
1735
|
+
assert.match(why[2], /引用了主要上下文/)
|
|
1736
|
+
assert.match(why[3], /与当前任务相关/)
|
|
1737
|
+
// ⚠️ 不许出现任何无法验证的话术
|
|
1738
|
+
const all = why.join(' ')
|
|
1739
|
+
assert.ok(!all.includes('当前话题'), '「命中当前话题」那套调试口吻已删')
|
|
1740
|
+
for (const banned of ['AI', '智能', '推荐', '置信', '%']) {
|
|
1741
|
+
assert.ok(!all.includes(banned), `理由里不该出现「${banned}」:${all}`)
|
|
1742
|
+
}
|
|
1743
|
+
})
|
|
1744
|
+
|
|
1745
|
+
test('上下文:没有 reason 的条目不出「为什么在这里」这一行', async () => {
|
|
1746
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1747
|
+
const other = byClass(nodes, 'knit-doc').find((n) => n.props['data-knit-rel'] === 'docs/other.md')
|
|
1748
|
+
assert.ok(other, '「其他相关文档」里应当有 docs/other.md')
|
|
1749
|
+
// 它的 reason 是宿主给的 related —— 那也是理由,所以有 why 行;
|
|
1750
|
+
// 真正没有理由的是**平铺列表**里的条目,见下一条用例。
|
|
1751
|
+
assert.ok(byClass(nodes, 'knit-why').length >= 4)
|
|
1752
|
+
})
|
|
1753
|
+
|
|
1754
|
+
test('上下文:宿主没给 context 时退回平铺列表(与 v0.13 逐字一致)', async () => {
|
|
1755
|
+
const flat = contextPayload()
|
|
1756
|
+
delete flat.context
|
|
1757
|
+
const { nodes } = await mountWithPayload(flat)
|
|
1758
|
+
assert.equal(byExactClass(nodes, 'knit-tier').length, 0, '不该有空的分区')
|
|
1759
|
+
assert.equal(byClass(nodes, 'knit-why').length, 0, '平铺列表不编造理由')
|
|
1760
|
+
assert.equal(byClass(nodes, 'knit-doc').length, 5, '五篇照常列出')
|
|
1761
|
+
})
|
|
1762
|
+
|
|
1763
|
+
test('上下文:时间序 / 媒体档即使给了 context 也不分层', async () => {
|
|
1764
|
+
const { nodes } = await mountWithPayload(contextPayload({ mode: 'time' }))
|
|
1765
|
+
assert.equal(byExactClass(nodes, 'knit-tier').length, 0, '时间序不假装分了层')
|
|
1766
|
+
})
|
|
1767
|
+
|
|
1768
|
+
test('上下文:过滤框在当前上下文里做子集化,不会把非命中项漏掉', async () => {
|
|
1769
|
+
const mounted = await mountWithPayload(contextPayload())
|
|
1770
|
+
// 过滤到「无关」—— 它在「其他相关文档」里,不在前三层
|
|
1771
|
+
byClass(mounted.nodes, 'knit-filter')[0].props.onChange({ target: { value: '无关' } })
|
|
1772
|
+
const after = mounted.render()
|
|
1773
|
+
const rels = byClass(after, 'knit-doc').map((n) => n.props['data-knit-rel'])
|
|
1774
|
+
assert.deepEqual(rels, ['docs/other.md'], `过滤后应当只剩那一篇,实际 ${JSON.stringify(rels)}`)
|
|
1775
|
+
})
|
|
1776
|
+
|
|
1777
|
+
test('上下文:过滤到前三层里的某一篇时,只留它所在的那一档', async () => {
|
|
1778
|
+
const mounted = await mountWithPayload(contextPayload())
|
|
1779
|
+
byClass(mounted.nodes, 'knit-filter')[0].props.onChange({ target: { value: '排序评测' } })
|
|
1780
|
+
const after = mounted.render()
|
|
1781
|
+
const rels = byClass(after, 'knit-doc').map((n) => n.props['data-knit-rel'])
|
|
1782
|
+
assert.deepEqual(rels, ['docs/eval.md'])
|
|
1783
|
+
const titles = byExactClass(after, 'knit-tiername').map(textOf)
|
|
1784
|
+
assert.deepEqual(titles, ['辅助上下文'], '只剩有命中的那一档')
|
|
1785
|
+
})
|
|
1786
|
+
|
|
1787
|
+
test('上下文:键盘按屏幕顺序穿过三档(↓ 跨区不断链)', async () => {
|
|
1788
|
+
const mounted = await mountWithPayload(contextPayload())
|
|
1789
|
+
const first = byClass(mounted.nodes, 'knit-doc')[0]
|
|
1790
|
+
assert.ok(String(first.props.className).includes('cursor'), 'cursor 初始在第一项')
|
|
1791
|
+
byClass(mounted.nodes, 'knit-list')[0].props.onKeyDown({ key: 'ArrowDown', preventDefault() {} })
|
|
1792
|
+
const after = await mounted.renderAgain()
|
|
1793
|
+
const second = byClass(after, 'knit-doc')[1]
|
|
1794
|
+
assert.ok(String(second.props.className).includes('cursor'), '↓ 走到第二条(跨层也不断链)')
|
|
1795
|
+
})
|
|
1796
|
+
|
|
1797
|
+
/* ── v0.14 单栏(2026-09-29 用户裁定)────────────────────────────────
|
|
1798
|
+
这里曾经是「左=文档列表,右=当前任务上下文的解释」的双栏。用户否掉了它:
|
|
1799
|
+
Context Pack 是**数据层**结构(Primary / Supporting / Related),不是一个
|
|
1800
|
+
要单独显示的 UI 卡片 —— 分组直接落在文档列表里就够了。
|
|
1801
|
+
|
|
1802
|
+
⚠️ 下面那条守卫是反向的:就算宿主照旧给了 Context Pack,DOM 里也不许再出现
|
|
1803
|
+
任何右栏骨架。留着一套渲染不出来的样式,下一个人只会以为它还在生效。 */
|
|
1804
|
+
|
|
1805
|
+
/**
|
|
1806
|
+
* 收集一棵子树里所有元素节点的 className(展开函数组件)。
|
|
1807
|
+
*
|
|
1808
|
+
* `byClass` 只看扁平列表,答不了「谁在谁里面」;右栏必须在 listbox **外面**
|
|
1809
|
+
* 这条断言需要真正的包含关系。
|
|
1810
|
+
*
|
|
1811
|
+
* @param {object} node - 节点
|
|
1812
|
+
* @returns {string[]} className 列表
|
|
1813
|
+
*/
|
|
1814
|
+
function classesUnder(node) {
|
|
1815
|
+
const acc = []
|
|
1816
|
+
const walk = (n) => {
|
|
1817
|
+
if (!n || typeof n !== 'object') return
|
|
1818
|
+
if (Array.isArray(n)) { n.forEach(walk); return }
|
|
1819
|
+
const type = n.type
|
|
1820
|
+
if (type && typeof type === 'object' && typeof type.type === 'function') { walk(type.type(n.props)); return }
|
|
1821
|
+
if (typeof type === 'function') { walk(type(n.props)); return }
|
|
1822
|
+
if (n.props && n.props.className) acc.push(String(n.props.className))
|
|
1823
|
+
;(n.children || []).forEach(walk)
|
|
1824
|
+
}
|
|
1825
|
+
walk(node)
|
|
1826
|
+
return acc
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
test('单栏:即使给了 Context Pack,DOM 里也没有任何右栏骨架', async () => {
|
|
1830
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1831
|
+
for (const dead of ['knit-context-layout', 'knit-col-list', 'knit-context-column',
|
|
1832
|
+
'knit-pack', 'knit-pack-title', 'knit-grip', 'knit-evrow', 'knit-ev-hint']) {
|
|
1833
|
+
assert.equal(byClass(nodes, dead).length, 0, `${dead} 不该再出现(右栏已整体删除)`)
|
|
1834
|
+
}
|
|
1835
|
+
// 删掉的是「单独一栏」,不是分层:三档 +「其他相关文档」照旧
|
|
1836
|
+
assert.equal(byExactClass(nodes, 'knit-tier').length, 4)
|
|
1837
|
+
assert.equal(byClass(nodes, 'knit-doc').length, 5)
|
|
1838
|
+
// 列表就是那个滚动容器本身,不再有网格包装
|
|
1839
|
+
assert.equal(byExactClass(nodes, 'knit-list').length, 1)
|
|
1840
|
+
})
|
|
1841
|
+
|
|
1842
|
+
test('单栏:过滤后分组随之收窄,只剩有命中的那一档', async () => {
|
|
1843
|
+
const mounted = await mountWithPayload(contextPayload())
|
|
1844
|
+
byClass(mounted.nodes, 'knit-filter')[0].props.onChange({ target: { value: '排序评测' } })
|
|
1845
|
+
const after = mounted.render()
|
|
1846
|
+
assert.deepEqual(byClass(after, 'knit-doc').map((n) => n.props['data-knit-rel']), ['docs/eval.md'])
|
|
1847
|
+
// 这一档以前也顺便验「右栏计数跟着左栏动」——右栏没了,左侧的分区本身就是答案
|
|
1848
|
+
assert.deepEqual(byExactClass(after, 'knit-tiername').map(textOf), ['辅助上下文'])
|
|
1849
|
+
})
|
|
1850
|
+
|
|
1851
|
+
test('上下文:行首序号跨三档连续,且「其他相关文档」不编号', async () => {
|
|
1852
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1853
|
+
assert.deepEqual(byExactClass(nodes, 'knit-num').map(textOf), ['01', '02', '03', '04'])
|
|
1854
|
+
const docs = byClass(nodes, 'knit-doc')
|
|
1855
|
+
assert.equal(docs.length, 5)
|
|
1856
|
+
assert.equal(docs[4].props['data-knit-rel'], 'docs/other.md', '最后一档是「其他相关文档」')
|
|
1857
|
+
assert.equal(byExactClass(nodes, 'knit-num').length, 4, '它不在这个包里,所以不编号')
|
|
1858
|
+
})
|
|
1859
|
+
|
|
1860
|
+
test('上下文:Primary 那颗点是位置信号,只有主上下文那一行有', async () => {
|
|
1861
|
+
const { nodes } = await mountWithPayload(contextPayload())
|
|
1862
|
+
assert.equal(byExactClass(nodes, 'knit-dot').length, 1, 'Primary 只有一篇 ⇒ 点只有一个')
|
|
1863
|
+
const dots = classesUnder(byClass(nodes, 'knit-doc')[0])
|
|
1864
|
+
assert.ok(dots.includes('knit-dot'), '点落在第一条(主上下文)上')
|
|
1865
|
+
assert.ok(
|
|
1866
|
+
classesUnder(byClass(nodes, 'knit-doc')[1]).includes('knit-dot') === false,
|
|
1867
|
+
'辅助那一档不许出现点',
|
|
1868
|
+
)
|
|
1869
|
+
})
|
|
1870
|
+
|
|
1871
|
+
test('上下文:时间序不分层,行首也不编号(平铺列表照旧)', async () => {
|
|
1872
|
+
const { nodes } = await mountWithPayload(contextPayload({ mode: 'time' }))
|
|
1873
|
+
assert.equal(byExactClass(nodes, 'knit-tier').length, 0, '时间序不分层')
|
|
1874
|
+
assert.equal(byExactClass(nodes, 'knit-num').length, 0, '平铺列表不编号')
|
|
1875
|
+
assert.equal(byExactClass(nodes, 'knit-dot').length, 0, '平铺列表没有主上下文点')
|
|
1876
|
+
assert.equal(byClass(nodes, 'knit-doc').length, 5, '文档本身照常列全')
|
|
1877
|
+
})
|
|
1878
|
+
|
|
1879
|
+
/* ── 右栏形态(拖宽 / 浮动 / 右缘吸附)已整体删除(2026-09-29)───────
|
|
1880
|
+
那一套几何交互只服务于右侧的 Context Pack 面板:面板本身被用户否掉之后
|
|
1881
|
+
(理由见上面「单栏」那段),宽度 / 浮动 / 吸附、把手的 separator 键盘模型、
|
|
1882
|
+
clampPackW / clampFloatPos / nearRightEdge 三个纯函数、以及 capturePointers
|
|
1883
|
+
这个只为驱动一次拖拽而存在的替身,**全部一起删掉** —— 留着一套永远调用不到的
|
|
1884
|
+
代码,下一个人只会以为它还在生效。
|
|
1885
|
+
|
|
1886
|
+
仍然成立的那条原则(当时是为几何状态写的,现在适用于所有界面状态):
|
|
1887
|
+
readPref / writePref 只用于排序 / 类型 / 预览高度这类**语义偏好**,
|
|
1888
|
+
界面几何状态不落盘。 */
|
|
1889
|
+
|
|
1890
|
+
test('单栏:源码里不再有任何右栏 CSS 规则 / 函数 / 常量', async () => {
|
|
1891
|
+
const { readFileSync } = await import('node:fs')
|
|
1892
|
+
const { fileURLToPath } = await import('node:url')
|
|
1893
|
+
const source = readFileSync(
|
|
1894
|
+
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
1895
|
+
'utf8',
|
|
1896
|
+
)
|
|
1897
|
+
// ⚠️ 断言的是**规则与调用**,不是名字:文件里留着墓碑注释(说明这块为什么删了),
|
|
1898
|
+
// 那些注释会原样提到这些名字 —— 用 includes 会把墓碑本身当成残留。
|
|
1899
|
+
for (const rule of ['.knit-context-layout', '.knit-col-list', '.knit-context-column',
|
|
1900
|
+
'.knit-pack', '.knit-grip', '.knit-evrow', '.knit-pack-btn', '.knit-undocked']) {
|
|
1901
|
+
assert.ok(!new RegExp(`\\${rule}\\s*[{,:]`).test(source), `${rule} 的规则必须删干净`)
|
|
1902
|
+
}
|
|
1903
|
+
assert.ok(!/--knit-pack-w/.test(source), '右栏宽度变量必须删干净')
|
|
1904
|
+
for (const call of ['clampPackW', 'clampFloatPos', 'nearRightEdge', 'setPackWidth']) {
|
|
1905
|
+
assert.ok(!new RegExp(`${call}\\s*\\(`).test(source), `${call} 不该再被调用`)
|
|
1906
|
+
}
|
|
1907
|
+
assert.ok(!/const PACK_W_DEFAULT/.test(source), 'PACK_W_DEFAULT 已删')
|
|
1908
|
+
assert.ok(!/const PACK_SNAP_PX/.test(source), 'PACK_SNAP_PX 已删')
|
|
1909
|
+
assert.ok(!source.includes('dsh-knit:pack'), '几何不落盘:没有 pack 的 localStorage 键')
|
|
1910
|
+
})
|
|
1911
|
+
|
|
1912
|
+
test('样式:组与组之间只靠 16px 空间(不再画横线),序号与标题行等高', async () => {
|
|
1913
|
+
const { readFileSync } = await import('node:fs')
|
|
1914
|
+
const { fileURLToPath } = await import('node:url')
|
|
1915
|
+
const source = readFileSync(
|
|
1916
|
+
fileURLToPath(new URL('../src/client/client.js', import.meta.url)),
|
|
1917
|
+
'utf8',
|
|
1918
|
+
)
|
|
1919
|
+
// 用户要求「减少横向分割线」:组间距靠空间,不靠 border-top
|
|
1920
|
+
assert.match(source, /\.knit-tier \+ \.knit-tier\{margin-top:16px\}/)
|
|
1921
|
+
assert.ok(!/\.knit-tier \+ \.knit-tier\{[^}]*border-top/.test(source), '组之间不该再有横线')
|
|
1922
|
+
// 顶部那行排序依据也不再带全宽下划线
|
|
1923
|
+
assert.ok(!/\.knit-topic\{[^}]*border-bottom/.test(source), '排序依据那一行不画线')
|
|
1924
|
+
// 字号:标题 14px / 行高 1.4 = 19.6px;序号的 line-height 必须与它同步,
|
|
1925
|
+
// 这是「序号与标题第一行垂直居中」的唯一手段(改一处必须改两处)
|
|
1926
|
+
assert.match(source, /\.knit-title\{flex:1 1 auto;min-width:0;font-weight:600;font-size:14px;line-height:1\.4;/)
|
|
1927
|
+
assert.match(source, /\.knit-num\{grid-column:1;font-size:10\.5px;line-height:19\.6px;/)
|
|
1928
|
+
assert.match(source, /\.knit-sum\{font-size:12px;line-height:19px;/)
|
|
1929
|
+
})
|