dsh-knit 0.4.0 → 0.5.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.
@@ -0,0 +1,119 @@
1
+ /**
2
+ * 宿主 HTTP 端到端:在真实回环端口上跑 apply() 注册的路由。
3
+ *
4
+ * 纯函数单测覆盖不到的部分在这里验证:/raw 整文件 200、HTTP Range 206 与
5
+ * Content-Range/字节数、安全响应头、路径越界 / 扩展名白名单 / 方法限制。
6
+ *
7
+ * 跑法:node --test test/host-http.test.mjs
8
+ */
9
+ import test from 'node:test'
10
+ import assert from 'node:assert/strict'
11
+ import http from 'node:http'
12
+ import { fileURLToPath } from 'node:url'
13
+ import { stat } from 'node:fs/promises'
14
+
15
+ import { apply } from '../src/host/index.js'
16
+ import { makeWorkspace } from './fixture.mjs'
17
+
18
+ /** 测试自带样本工作区(临时目录),里面有 docs/screenshot.png 当媒体样本。 */
19
+ const PROJECT_ROOT = makeWorkspace()
20
+
21
+ /**
22
+ * 起一个挂着 Knit 路由的回环 server(伪造 cordis 的 webServer / sessions / effect)。
23
+ * @returns {Promise<{base:string, close:Function}>} 地址根与关闭函数
24
+ */
25
+ async function startKnitServer() {
26
+ let handler = null
27
+ apply({
28
+ inject(_deps, cb) {
29
+ cb({
30
+ webServer: {
31
+ register({ handler: h }) { handler = h; return () => {} },
32
+ },
33
+ sessions: { get: () => ({ header: { cwd: PROJECT_ROOT } }) },
34
+ effect(fn) { fn() },
35
+ })
36
+ },
37
+ })
38
+ assert.ok(handler, 'apply 应注册路由 handler')
39
+
40
+ const server = http.createServer((req, res) => handler(req, res))
41
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
42
+ const base = `http://127.0.0.1:${server.address().port}/knit`
43
+ const close = () => new Promise((resolve) => server.close(resolve))
44
+ return { base, close }
45
+ }
46
+
47
+ test('HTTP 端到端:媒体列表、/raw 整文件、Range 206、安全拒绝', async () => {
48
+ const { base, close } = await startKnitServer()
49
+ try {
50
+ // kind=media:只回图片/视频,且扫到仓库自带截图
51
+ let r = await fetch(`${base}/api/recent?sessionId=s&kind=media&sort=time`)
52
+ let body = await r.json()
53
+ assert.equal(r.status, 200)
54
+ assert.equal(body.kind, 'media')
55
+ assert.ok(body.docs.some((d) => d.name === 'screenshot.png'))
56
+ assert.ok(body.docs.every((d) => d.kind === 'image' || d.kind === 'video'))
57
+ assert.ok(body.docs.every((d) => !('haystack' in d)), '不泄漏内部 haystack')
58
+
59
+ // kind=all:文档与媒体混合
60
+ r = await fetch(`${base}/api/recent?sessionId=s&kind=all&sort=time`)
61
+ body = await r.json()
62
+ assert.equal(body.kind, 'all')
63
+ assert.ok(body.docs.some((d) => d.kind === 'md'))
64
+ assert.ok(body.docs.some((d) => d.kind === 'image'))
65
+
66
+ // 缺省 kind 回落 doc
67
+ r = await fetch(`${base}/api/recent?sessionId=s`)
68
+ body = await r.json()
69
+ assert.equal(body.kind, 'doc')
70
+ assert.ok(body.docs.every((d) => d.kind === 'md'))
71
+
72
+ // /raw 整文件:200、字节一致、安全头齐全
73
+ const rel = 'docs/screenshot.png'
74
+ const realSize = (await stat(`${PROJECT_ROOT}/${rel}`)).size
75
+ r = await fetch(`${base}/api/raw?sessionId=s&rel=${encodeURIComponent(rel)}`)
76
+ assert.equal(r.status, 200)
77
+ assert.match(r.headers.get('content-type'), /image\/png/)
78
+ assert.equal(r.headers.get('accept-ranges'), 'bytes')
79
+ assert.equal(r.headers.get('x-content-type-options'), 'nosniff')
80
+ assert.match(r.headers.get('content-security-policy') || '', /default-src 'none'/)
81
+ assert.equal(Number(r.headers.get('content-length')), realSize)
82
+ assert.equal((await r.arrayBuffer()).byteLength, realSize)
83
+
84
+ // Range 闭区间:206 + Content-Range + 100 字节
85
+ r = await fetch(`${base}/api/raw?sessionId=s&rel=${encodeURIComponent(rel)}`, {
86
+ headers: { Range: 'bytes=0-99' },
87
+ })
88
+ assert.equal(r.status, 206)
89
+ assert.equal(r.headers.get('content-range'), `bytes 0-99/${realSize}`)
90
+ assert.equal(Number(r.headers.get('content-length')), 100)
91
+ assert.equal((await r.arrayBuffer()).byteLength, 100)
92
+
93
+ // Range 后缀 bytes=-1000
94
+ r = await fetch(`${base}/api/raw?sessionId=s&rel=${encodeURIComponent(rel)}`, {
95
+ headers: { Range: 'bytes=-1000' },
96
+ })
97
+ assert.equal(r.status, 206)
98
+ assert.equal(r.headers.get('content-range'), `bytes ${realSize - 1000}-${realSize - 1}/${realSize}`)
99
+ assert.equal((await r.arrayBuffer()).byteLength, 1000)
100
+
101
+ // 路径越界:404 + outside-workspace
102
+ r = await fetch(`${base}/api/raw?sessionId=s&rel=${encodeURIComponent('../../../../etc/passwd')}`)
103
+ body = await r.json()
104
+ assert.equal(r.status, 404)
105
+ assert.equal(body.code, 'knit/outside-workspace')
106
+
107
+ // 非白名单扩展名:404 + media-only
108
+ r = await fetch(`${base}/api/raw?sessionId=s&rel=${encodeURIComponent('package.json')}`)
109
+ body = await r.json()
110
+ assert.equal(r.status, 404)
111
+ assert.equal(body.code, 'knit/media-only')
112
+
113
+ // 非 GET:405
114
+ r = await fetch(`${base}/api/recent?sessionId=s`, { method: 'POST' })
115
+ assert.equal(r.status, 405)
116
+ } finally {
117
+ await close()
118
+ }
119
+ })
@@ -6,18 +6,24 @@
6
6
  import test from 'node:test'
7
7
  import assert from 'node:assert/strict'
8
8
  import { fileURLToPath } from 'node:url'
9
+ import { mkdtemp, writeFile, rm } from 'node:fs/promises'
10
+ import { tmpdir } from 'node:os'
11
+ import { join } from 'node:path'
9
12
 
10
13
  import {
11
14
  parseMarkdown,
12
15
  scan,
13
16
  readDocument,
14
17
  collectDocs,
18
+ mediaInfo,
19
+ parseRange,
15
20
  ERROR_CODES,
16
21
  } from '../src/host/index.js'
17
22
  import { extractKeywords, rankByRelevance, topicLabel } from '../src/host/relevance.js'
23
+ import { makeWorkspace } from './fixture.mjs'
18
24
 
19
- /** 本仓库根(08_Knit),里面有真实 Markdown 可当样本。 */
20
- const PROJECT_ROOT = fileURLToPath(new URL('../../', import.meta.url))
25
+ /** 测试自带样本工作区(临时目录),不依赖仓库/包的目录布局。 */
26
+ const PROJECT_ROOT = makeWorkspace()
21
27
 
22
28
  /**
23
29
  * 造一个假的宿主会话对象。
@@ -130,7 +136,7 @@ test('readDocument: 拒绝绝对路径逃逸', async () => {
130
136
  })
131
137
 
132
138
  test('readDocument: 拒绝非 Markdown', async () => {
133
- const r = await readDocument(PROJECT_ROOT, 'knit/package.json')
139
+ const r = await readDocument(PROJECT_ROOT, 'package.json')
134
140
  assert.equal(r.ok, false)
135
141
  assert.equal(r.code, ERROR_CODES.markdownOnly)
136
142
  })
@@ -247,3 +253,135 @@ test('scan: limit 生效', async () => {
247
253
  assert.ok(r.docs.length <= 2)
248
254
  assert.ok(r.total >= r.docs.length)
249
255
  })
256
+
257
+ /* ── 图片与视频:扫描、类型过滤、Range、安全边界 ──────── */
258
+
259
+ /** 建一个临时工作区并写入若干文件,跑完自动清理。 */
260
+ async function withTempFiles(files, fn) {
261
+ const dir = await mkdtemp(join(tmpdir(), 'knit-media-'))
262
+ try {
263
+ for (const [name, content] of Object.entries(files)) {
264
+ await writeFile(join(dir, name), content)
265
+ }
266
+ await fn(dir)
267
+ } finally {
268
+ await rm(dir, { recursive: true, force: true })
269
+ }
270
+ }
271
+
272
+ test('collectDocs: 同时扫出 Markdown 与媒体,媒体带 kind/size 且不读正文', async () => {
273
+ const { docs, media } = await collectDocs(PROJECT_ROOT)
274
+ assert.ok(docs.length > 0)
275
+ assert.ok(docs.every((d) => d.kind === 'md'), '文档池 kind 全为 md')
276
+ assert.ok(docs.every((d) => typeof d.size === 'number'))
277
+
278
+ const shot = media.find((m) => m.rel.split('/').pop() === 'screenshot.png')
279
+ assert.ok(shot, '应扫到样本里的 screenshot.png')
280
+ assert.equal(shot.kind, 'image')
281
+ assert.ok(shot.size > 0)
282
+ assert.equal(shot.summary, '', '媒体没有正文摘要')
283
+ assert.equal(shot.haystack.body, '')
284
+ assert.match(shot.haystack.title, /screenshot\.png/)
285
+ })
286
+
287
+ test('scan: 默认(doc)只回 Markdown 并回显 kind=doc', async () => {
288
+ const r = await scan(PROJECT_ROOT, 400, { sessionId: 's', sort: 'time' })
289
+ assert.equal(r.kind, 'doc')
290
+ assert.ok(r.docs.length > 0)
291
+ assert.ok(r.docs.every((d) => d.kind === 'md'))
292
+ })
293
+
294
+ test('scan: kind=media 只回图片/视频,公开载荷不带 haystack', async () => {
295
+ const r = await scan(PROJECT_ROOT, 400, { sessionId: 's', sort: 'time', kind: 'media' })
296
+ assert.equal(r.kind, 'media')
297
+ assert.ok(r.docs.some((d) => d.name === 'screenshot.png'))
298
+ assert.ok(r.docs.every((d) => d.kind === 'image' || d.kind === 'video'))
299
+ assert.ok(r.docs.every((d) => !('haystack' in d)), '媒体公开载荷也不得泄漏 haystack')
300
+ })
301
+
302
+ test('scan: kind=all 文档与媒体混排,并整体按 mtime 倒序', async () => {
303
+ const r = await scan(PROJECT_ROOT, 400, { sessionId: 's', sort: 'time', kind: 'all' })
304
+ assert.equal(r.kind, 'all')
305
+ assert.ok(r.docs.some((d) => d.kind === 'md'))
306
+ assert.ok(r.docs.some((d) => d.kind === 'image'))
307
+ const mt = r.docs.map((d) => d.mtimeMs)
308
+ assert.ok(mt.every((v, i) => i === 0 || mt[i - 1] >= v), '应整体按 mtime 倒序')
309
+ })
310
+
311
+ test('scan: 非法 kind 老实回落 doc', async () => {
312
+ const r = await scan(PROJECT_ROOT, 50, { sessionId: 's', sort: 'time', kind: 'wat' })
313
+ assert.equal(r.kind, 'doc')
314
+ assert.ok(r.docs.every((d) => d.kind === 'md'))
315
+ })
316
+
317
+ test('parseRange: 无 Range 头或空文件回 null(交给整文件响应)', () => {
318
+ assert.equal(parseRange(undefined, 1000), null)
319
+ assert.equal(parseRange('', 1000), null)
320
+ assert.equal(parseRange('bytes=0-99', 0), null)
321
+ })
322
+
323
+ test('parseRange: 解析起止区间与开放结尾', () => {
324
+ assert.deepEqual(parseRange('bytes=0-99', 1000), { start: 0, end: 99 })
325
+ assert.deepEqual(parseRange('bytes=0-', 1000), { start: 0, end: 999 })
326
+ assert.deepEqual(parseRange('bytes=500-', 1000), { start: 500, end: 999 })
327
+ })
328
+
329
+ test('parseRange: bytes=-N 取最后 N 字节,超过总长则从 0 开始', () => {
330
+ assert.deepEqual(parseRange('bytes=-500', 1000), { start: 500, end: 999 })
331
+ assert.deepEqual(parseRange('bytes=-2000', 1000), { start: 0, end: 999 })
332
+ })
333
+
334
+ test('parseRange: end 越界截断、end 小于 start 回落整段、start 越界拒绝', () => {
335
+ assert.deepEqual(parseRange('bytes=0-99999', 1000), { start: 0, end: 999 })
336
+ assert.deepEqual(parseRange('bytes=500-100', 1000), { start: 500, end: 999 })
337
+ assert.equal(parseRange('bytes=1000-', 1000), null)
338
+ })
339
+
340
+ test('parseRange: 多区间与怪异语法一律回 null', () => {
341
+ assert.equal(parseRange('bytes=0-9,20-29', 1000), null)
342
+ assert.equal(parseRange('bytes=-', 1000), null)
343
+ assert.equal(parseRange('items=0-9', 1000), null)
344
+ })
345
+
346
+ test('mediaInfo: 放行白名单图片并给出类型与大小', async () => {
347
+ await withTempFiles({ 'shot.png': Buffer.from([0x89, 0x50, 0x4e, 0x47]) }, async (dir) => {
348
+ const r = await mediaInfo(dir, 'shot.png')
349
+ assert.equal(r.ok, true)
350
+ assert.equal(r.kind, 'image')
351
+ assert.equal(r.type, 'image/png')
352
+ assert.equal(r.size, 4)
353
+ })
354
+ })
355
+
356
+ test('mediaInfo: 放行视频扩展名并判为 video', async () => {
357
+ await withTempFiles({ 'clip.mp4': Buffer.from([0, 0, 0, 20]) }, async (dir) => {
358
+ const r = await mediaInfo(dir, 'clip.mp4')
359
+ assert.equal(r.ok, true)
360
+ assert.equal(r.kind, 'video')
361
+ assert.equal(r.type, 'video/mp4')
362
+ })
363
+ })
364
+
365
+ test('mediaInfo: 拒绝非白名单扩展名(只准图片/视频)', async () => {
366
+ await withTempFiles({ 'secret.txt': 'x' }, async (dir) => {
367
+ const r = await mediaInfo(dir, 'secret.txt')
368
+ assert.equal(r.ok, false)
369
+ assert.equal(r.code, ERROR_CODES.mediaOnly)
370
+ })
371
+ })
372
+
373
+ test('mediaInfo: 拒绝目录穿越', async () => {
374
+ await withTempFiles({ 'a.png': Buffer.from([1]) }, async (dir) => {
375
+ const r = await mediaInfo(dir, '../../../../etc/passwd')
376
+ assert.equal(r.ok, false)
377
+ assert.equal(r.code, ERROR_CODES.outsideWorkspace)
378
+ })
379
+ })
380
+
381
+ test('mediaInfo: 文件不存在回 notFound', async () => {
382
+ await withTempFiles({ 'a.png': Buffer.from([1]) }, async (dir) => {
383
+ const r = await mediaInfo(dir, 'missing.png')
384
+ assert.equal(r.ok, false)
385
+ assert.equal(r.code, ERROR_CODES.notFound)
386
+ })
387
+ })
@@ -0,0 +1,208 @@
1
+ /**
2
+ * 「打开本地文件夹」测试:点头部那行工作区路径 → 用系统文件管理器打开它。
3
+ *
4
+ * 走官方 Remote:`ctx.remote.session.openWorkspacePath({ path })`,
5
+ * 返回值是一个信封(`{ ok, value } | { ok: false, error }`)。
6
+ *
7
+ * 跑法:node --test test/
8
+ */
9
+ import test from 'node:test'
10
+ import assert from 'node:assert/strict'
11
+
12
+ import { loadClientModule, createHarness, byClass, textOf, makeLocale } from './harness.mjs'
13
+
14
+ const harness = createHarness()
15
+ const React = globalThis.__knitReact
16
+ const h = React.createElement
17
+
18
+ /* ── 脚手架 ─────────────────────────────────────────── */
19
+
20
+ /**
21
+ * 装载模块并 apply 到一个带 remote.session 的假上下文。
22
+ *
23
+ * @param {object} [options] - `openWorkspacePath` 的实现,省略表示没有该服务
24
+ * @returns {{exports: object, calls: object[], log: object}} 结果与调用记录
25
+ */
26
+ function boot(options = {}) {
27
+ const loaded = loadClientModule()
28
+ const log = { effects: [] }
29
+ const { locale } = makeLocale({ active: 'zh' })
30
+
31
+ const services = { slots: { inject(n, cb) { cb(); return () => {} }, register() { return () => {} } } }
32
+ if (options.openWorkspacePath) {
33
+ services['remote.session'] = { openWorkspacePath: options.openWorkspacePath }
34
+ }
35
+
36
+ const ctx = {
37
+ slots: services.slots,
38
+ locale,
39
+ effect(fn, label) { log.effects.push(label); return fn() },
40
+ get: (name) => services[name],
41
+ inject(deps, cb) {
42
+ for (const d of deps) if (!services[d]) return
43
+ cb({ ...services, effect: (fn) => fn() })
44
+ },
45
+ }
46
+
47
+ loaded.exports.apply(ctx)
48
+ return { exports: loaded.exports, log }
49
+ }
50
+
51
+ /**
52
+ * 造一份列表载荷。
53
+ * @param {object} [overrides] - 覆盖字段
54
+ * @returns {object} 载荷
55
+ */
56
+ function listPayload(overrides = {}) {
57
+ return {
58
+ ok: true,
59
+ root: '/Users/me/proj',
60
+ total: 1,
61
+ mode: 'time',
62
+ topic: '',
63
+ docs: [{ path: '/Users/me/proj/a.md', rel: 'a.md', name: 'a.md', title: 'A', summary: 's', mtimeMs: Date.now(), score: null }],
64
+ ...overrides,
65
+ }
66
+ }
67
+
68
+ /**
69
+ * 渲染到列表加载完成,返回扁平节点。
70
+ * @returns {Promise<object[]>} 节点
71
+ */
72
+ async function render() {
73
+ globalThis.fetch = async () => ({ json: async () => listPayload() })
74
+ const { KnitBody } = boot({ openWorkspacePath: async () => ({ ok: true, value: { opened: true } }) }).exports.__test
75
+ harness.reset()
76
+ let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
77
+ await harness.flush()
78
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
79
+ return nodes
80
+ }
81
+
82
+ /* ── 渲染 ───────────────────────────────────────────── */
83
+
84
+ test('路径:渲染成一个可点的 button,带手型与提示', async () => {
85
+ const nodes = await render()
86
+ const path = byClass(nodes, 'knit-root-path')[0]
87
+
88
+ assert.ok(path, '应有工作区路径')
89
+ assert.equal(path.type, 'button', '必须是 button(才能点击 + 无障碍)')
90
+ assert.equal(path.props.type, 'button')
91
+ assert.equal(path.props.disabled, false)
92
+ assert.equal(path.props.title, '在文件管理器中打开')
93
+ assert.match(textOf(path), /08_Knit|proj/, '显示的就是工作区路径')
94
+ })
95
+
96
+ test('路径:没有工作目录时按钮禁用,且没有提示文案', async () => {
97
+ globalThis.fetch = async () => ({ json: async () => listPayload({ root: '', docs: [] }) })
98
+ const { KnitBody } = boot({ openWorkspacePath: async () => ({ ok: true, value: { opened: true } }) }).exports.__test
99
+ harness.reset()
100
+ let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
101
+ await harness.flush()
102
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
103
+
104
+ const path = byClass(nodes, 'knit-root-path')[0]
105
+ assert.equal(path.props.disabled, true)
106
+ assert.equal(path.props.title, '')
107
+ assert.doesNotThrow(() => path.props.onClick())
108
+ })
109
+
110
+ /* ── 行为 ───────────────────────────────────────────── */
111
+
112
+ test('路径:点击调 openWorkspacePath,参数是当前工作区绝对路径', async () => {
113
+ const calls = []
114
+ globalThis.fetch = async () => ({ json: async () => listPayload() })
115
+ const { KnitBody } = boot({
116
+ openWorkspacePath: async (request) => { calls.push(request); return { ok: true, value: { opened: true } } },
117
+ }).exports.__test
118
+
119
+ harness.reset()
120
+ let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
121
+ await harness.flush()
122
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
123
+
124
+ byClass(nodes, 'knit-root-path')[0].props.onClick()
125
+ await harness.flush()
126
+
127
+ assert.equal(calls.length, 1, '应调用一次')
128
+ assert.deepEqual(calls[0], { path: '/Users/me/proj' }, '参数是绝对路径')
129
+ })
130
+
131
+ test('路径:信封 ok:false 时把原因显示出来,不静默失败', async () => {
132
+ globalThis.fetch = async () => ({ json: async () => listPayload() })
133
+ const { KnitBody } = boot({
134
+ openWorkspacePath: async () => ({ ok: false, error: { code: 'boom', message: 'no opener' } }),
135
+ }).exports.__test
136
+
137
+ harness.reset()
138
+ let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
139
+ await harness.flush()
140
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
141
+
142
+ byClass(nodes, 'knit-root-path')[0].props.onClick()
143
+ await harness.flush()
144
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
145
+
146
+ const notice = byClass(nodes, 'knit-notice').map(textOf).join('')
147
+ assert.match(notice, /打开失败/, '应给出可见提示')
148
+ assert.match(notice, /no opener/, '应带上具体原因')
149
+ })
150
+
151
+ test('路径:remote 抛异常时不崩,转成提示', async () => {
152
+ globalThis.fetch = async () => ({ json: async () => listPayload() })
153
+ const { KnitBody } = boot({
154
+ openWorkspacePath: async () => { throw new Error('transport down') },
155
+ }).exports.__test
156
+
157
+ harness.reset()
158
+ let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
159
+ await harness.flush()
160
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
161
+
162
+ await assert.doesNotReject(async () => {
163
+ byClass(nodes, 'knit-root-path')[0].props.onClick()
164
+ await harness.flush()
165
+ })
166
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
167
+ assert.match(byClass(nodes, 'knit-notice').map(textOf).join(''), /transport down/)
168
+ })
169
+
170
+ test('路径:没有 remote.session 服务时给出提示而不是白点一下', async () => {
171
+ globalThis.fetch = async () => ({ json: async () => listPayload() })
172
+ const { KnitBody } = boot({}).exports.__test // 不提供 remote.session
173
+
174
+ harness.reset()
175
+ let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
176
+ await harness.flush()
177
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
178
+
179
+ byClass(nodes, 'knit-root-path')[0].props.onClick()
180
+ await harness.flush()
181
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
182
+
183
+ assert.ok(byClass(nodes, 'knit-notice').length >= 1, '应给出可见提示')
184
+ })
185
+
186
+ test('路径:成功时不残留上一次的错误提示', async () => {
187
+ globalThis.fetch = async () => ({ json: async () => listPayload() })
188
+ let fail = true
189
+ const { KnitBody } = boot({
190
+ openWorkspacePath: async () => (fail ? { ok: false, error: { message: 'nope' } } : { ok: true, value: { opened: true } }),
191
+ }).exports.__test
192
+
193
+ harness.reset()
194
+ let nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
195
+ await harness.flush()
196
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
197
+
198
+ byClass(nodes, 'knit-root-path')[0].props.onClick()
199
+ await harness.flush()
200
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
201
+ assert.equal(byClass(nodes, 'knit-notice').length, 1, '先失败,有提示')
202
+
203
+ fail = false
204
+ byClass(nodes, 'knit-root-path')[0].props.onClick()
205
+ await harness.flush()
206
+ nodes = harness.render(h(KnitBody, { sessionId: 's1' }))
207
+ assert.equal(byClass(nodes, 'knit-notice').length, 0, '再成功,提示应清掉')
208
+ })