browser-plugin.client.spec.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /**
  2. * Web reference source coverage: Remote-backed file/session discovery,
  3. * deterministic ordering and labels, quoted-path suppression, pick projections, codec
  4. * round-trip, and registration lifecycle.
  5. */
  6. import { Context, Service } from '@deepseek-ai/cordis'
  7. import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
  8. import { LocaleRuntime } from '@deepseek-ai/dsh-client-locale/client'
  9. import type { SessionId } from '@deepseek-ai/dsh-session/types'
  10. import { RemoteError } from '@deepseek-ai/dsh-client-test-runtime'
  11. import type {
  12. CandidateRequest, ClientSessionContext, InputTriggerCandidate, InputTriggerSource,
  13. } from '@deepseek-ai/dsh-client-ui-input-trigger/client'
  14. import type { FileReferenceCandidate } from '@deepseek-ai/dsh-file-reference/types'
  15. import type { SessionReferenceMentionCandidate } from '@deepseek-ai/dsh-session-reference/types'
  16. import { apply, inject } from '../src/client/index.ts'
  17. import { apply as nodeApply } from '../src/index.ts'
  18. const sid = (value: string): SessionId => value as SessionId
  19. const session: ClientSessionContext = { sessionId: sid('target') }
  20. /** The target session's own workspace: candidates in it are the `sameWorkspace` rows. */
  21. const HOME = '/Users/dev'
  22. const CREATED_AT = 1_700_000_000_000
  23. /** Three days after every fixture's createdAt, so age copy is one fixed bucket. */
  24. const NOW = CREATED_AT + 3 * 86_400_000
  25. /** The Host session list dates a row; only a session missing from it falls back to createdAt. */
  26. const UPDATED_AT = NOW - 3_600_000
  27. beforeEach(() => {
  28. vi.useFakeTimers({ toFake: ['Date'] })
  29. vi.setSystemTime(NOW)
  30. })
  31. afterEach(() => { vi.useRealTimers() })
  32. type RemoteEnvelope<T> =
  33. | { ok: true; value: T }
  34. | { ok: false; error: { code: string; message: string; details: object } }
  35. type RemoteLookup<T> = (
  36. agentId: SessionId,
  37. query: string,
  38. signal?: AbortSignal,
  39. ) => Promise<RemoteEnvelope<T[]>>
  40. function request(
  41. query: string,
  42. options: { quoted?: boolean; signal?: AbortSignal } = {},
  43. ): CandidateRequest {
  44. return {
  45. query,
  46. quoted: options.quoted ?? false,
  47. position: 'inline',
  48. drilled: false,
  49. signal: options.signal ?? new AbortController().signal,
  50. }
  51. }
  52. async function bench(
  53. files: RemoteLookup<FileReferenceCandidate> = vi.fn(() => Promise.resolve({
  54. ok: true as const,
  55. value: [
  56. { path: 'src', kind: 'directory' as const },
  57. { path: 'docs/a b.md', kind: 'file' as const },
  58. ],
  59. })),
  60. sessions: RemoteLookup<SessionReferenceMentionCandidate> = vi.fn(() => Promise.resolve({
  61. ok: true as const,
  62. value: [{
  63. sessionId: sid('source'),
  64. label: 'Research',
  65. cwd: `${HOME}/project`,
  66. sameWorkspace: false,
  67. createdAt: CREATED_AT,
  68. mention: '@[Research](dsh-session:InNvdXJjZSI)',
  69. }],
  70. })),
  71. listed: Record<string, {
  72. updatedAt: number
  73. origin?: 'subagent'
  74. parentId?: SessionId
  75. projectionValues?: { title?: string | null }
  76. }> = {},
  77. ): Promise<{ ctx: Context; fiber: ReturnType<Context['plugin']>; source: InputTriggerSource }> {
  78. const ctx = new Context()
  79. ctx.provide('sidebarRight', { openResource: vi.fn() })
  80. let source: InputTriggerSource | undefined
  81. ctx.provide('inputTriggers', {
  82. registerSource(candidate: InputTriggerSource) {
  83. source = candidate
  84. return () => { source = undefined }
  85. },
  86. })
  87. class RemoteService extends Service {
  88. readonly $host = { home: HOME, isLoopback: true }
  89. constructor(serviceCtx: Context) {
  90. super(serviceCtx, 'remote')
  91. }
  92. }
  93. new RemoteService(ctx)
  94. ctx.provide('remote.fileReferences', { list: files })
  95. ctx.provide('remote.sessionReferenceResolver', { candidates: sessions })
  96. ctx.provide('locale', new LocaleRuntime(ctx))
  97. ctx.provide('sessions', { list: { getSnapshot: () => ({ byId: listed }) } })
  98. const fiber = ctx.plugin({ inject: [...inject], apply })
  99. await fiber.await()
  100. if (source === undefined) throw new Error('reference source was not registered')
  101. return { ctx, fiber, source }
  102. }
  103. describe('apply', () => {
  104. it('declares its services and releases the @ reference registration on disposal', async () => {
  105. expect(inject).toEqual([
  106. 'inputTriggers', 'locale', 'sessions', 'remote', 'remote.fileReferences',
  107. 'remote.sessionReferenceResolver', 'sidebarRight',
  108. ])
  109. const { fiber } = await bench()
  110. let registered: InputTriggerSource | undefined
  111. const ctx = new Context()
  112. ctx.provide('sidebarRight', { openResource: vi.fn() })
  113. ctx.provide('inputTriggers', {
  114. registerSource(source: InputTriggerSource) {
  115. registered = source
  116. return () => { registered = undefined }
  117. },
  118. })
  119. class RemoteService extends Service {
  120. readonly $host = { home: undefined, isLoopback: false }
  121. constructor(serviceCtx: Context) {
  122. super(serviceCtx, 'remote')
  123. }
  124. }
  125. new RemoteService(ctx)
  126. ctx.provide('remote.fileReferences', { list: () => Promise.resolve({ ok: true, value: [] }) })
  127. ctx.provide('remote.sessionReferenceResolver', { candidates: () => Promise.resolve({ ok: true, value: [] }) })
  128. ctx.provide('locale', new LocaleRuntime(ctx))
  129. ctx.provide('sessions', { list: { getSnapshot: () => ({ byId: {} }) } })
  130. const ownFiber = ctx.plugin({ inject: [...inject], apply })
  131. await ownFiber.await()
  132. expect(registered).toMatchObject({ trigger: '@', name: 'reference', showGroupTitle: false })
  133. await ownFiber.dispose()
  134. expect(registered).toBeUndefined()
  135. await fiber.dispose()
  136. })
  137. it('the node half applies without host-side behavior', () => {
  138. expect(() => { nodeApply() }).not.toThrow()
  139. })
  140. })
  141. describe('candidates', () => {
  142. it('starts both Remote lookups together and renders files before sessions with stable labels', async () => {
  143. let releaseFiles!: () => void
  144. let releaseSessions!: () => void
  145. const files = vi.fn(() => new Promise<{
  146. ok: true
  147. value: { path: string; kind: 'file' | 'directory' }[]
  148. }>((resolve) => {
  149. releaseFiles = () => {
  150. resolve({
  151. ok: true,
  152. value: [
  153. { path: 'src', kind: 'directory' },
  154. { path: 'docs/a b.md', kind: 'file' },
  155. ],
  156. })
  157. }
  158. }))
  159. const sessions = vi.fn(() => new Promise<{
  160. ok: true
  161. value: {
  162. sessionId: SessionId
  163. label: string
  164. cwd: string
  165. sameWorkspace: boolean
  166. createdAt: number
  167. mention: string
  168. }[]
  169. }>((resolve) => {
  170. releaseSessions = () => {
  171. resolve({
  172. ok: true,
  173. value: [{
  174. sessionId: sid('source'),
  175. label: 'Research',
  176. cwd: `${HOME}/project`,
  177. sameWorkspace: false,
  178. createdAt: CREATED_AT,
  179. mention: '@[Research](dsh-session:InNvdXJjZSI)',
  180. }],
  181. })
  182. }
  183. }))
  184. const { source } = await bench(files, sessions, { source: { updatedAt: UPDATED_AT } })
  185. const pending = source.candidates(session, request('re'))
  186. expect(files).toHaveBeenCalledTimes(1)
  187. expect(sessions).toHaveBeenCalledTimes(1)
  188. releaseSessions()
  189. releaseFiles()
  190. await expect(pending).resolves.toEqual([
  191. {
  192. name: 'src/',
  193. icon: 'folder',
  194. section: 'Files & folders',
  195. value: JSON.stringify({ kind: 'file', fileKind: 'directory', label: 'src', mention: '@src/' }),
  196. drill: true,
  197. },
  198. expect.objectContaining({
  199. name: 'a b.md',
  200. description: 'docs',
  201. icon: 'file',
  202. section: 'Files & folders',
  203. }),
  204. expect.objectContaining({
  205. name: 'Research',
  206. description: '~/project · 1h',
  207. icon: 'session',
  208. section: 'Sessions',
  209. }),
  210. ])
  211. })
  212. it('suppresses sessions for an open quoted path and degrades each failed domain independently', async () => {
  213. const files = vi.fn()
  214. .mockResolvedValueOnce({
  215. ok: true as const,
  216. value: [{ path: 'README.md', kind: 'file' as const }],
  217. })
  218. .mockResolvedValueOnce({
  219. ok: false as const,
  220. error: new RemoteError('gateway/internal', 'file scan failed', {}),
  221. })
  222. const sessions = vi.fn(() => Promise.resolve({
  223. ok: true as const,
  224. value: [{
  225. sessionId: sid('source'),
  226. label: 'Research',
  227. cwd: `${HOME}/project`,
  228. sameWorkspace: false,
  229. createdAt: CREATED_AT,
  230. mention: '@[Research](dsh-session:InNvdXJjZSI)',
  231. }],
  232. }))
  233. const { source } = await bench(files, sessions)
  234. const quoted = await source.candidates(session, request('READ', { quoted: true }))
  235. expect(quoted).toEqual([expect.objectContaining({ name: 'README.md', icon: 'file' })])
  236. expect(source.onPick({
  237. candidate: quoted[0]!,
  238. session,
  239. position: 'inline',
  240. via: 'menu',
  241. action: 'pick',
  242. span: { start: 0, end: 6, draftRev: 1 },
  243. })).toEqual({
  244. insert: {
  245. source: 'reference',
  246. ref: '@"README.md"',
  247. label: 'README.md',
  248. appearance: 'file',
  249. clipboardText: '@"README.md"',
  250. },
  251. })
  252. expect(sessions).not.toHaveBeenCalled()
  253. await expect(source.candidates(session, request('research'))).resolves.toEqual([
  254. expect.objectContaining({ name: 'Research', icon: 'session' }),
  255. ])
  256. })
  257. it('drops a completed result when the query signal was superseded', async () => {
  258. const controller = new AbortController()
  259. const { source } = await bench()
  260. const pending = source.candidates(session, request('', { signal: controller.signal }))
  261. controller.abort()
  262. await expect(pending).resolves.toEqual([])
  263. })
  264. it('treats Remote failures as empty domains and filters paths that cannot be mentioned', async () => {
  265. const files = vi.fn(() => Promise.resolve({
  266. ok: true as const,
  267. value: [{ path: 'bad\nname', kind: 'file' as const }],
  268. }))
  269. const sessions = vi.fn(() => Promise.resolve({
  270. ok: false as const,
  271. error: new RemoteError('gateway/internal', 'session lookup failed', {}),
  272. }))
  273. const { source } = await bench(files, sessions)
  274. await expect(source.candidates(session, request('bad'))).resolves.toEqual([])
  275. files.mockResolvedValueOnce({
  276. ok: false as const,
  277. error: new RemoteError('gateway/internal', 'file lookup failed', {}),
  278. } as never)
  279. await expect(source.candidates(session, request('bad'))).resolves.toEqual([])
  280. })
  281. it('labels a session without a cwd and still dates it', async () => {
  282. const files = vi.fn(() => Promise.resolve({ ok: true as const, value: [] }))
  283. const sessions = vi.fn(() => Promise.resolve({
  284. ok: true as const,
  285. value: [{
  286. sessionId: sid('same'),
  287. label: 'same',
  288. sameWorkspace: false,
  289. createdAt: CREATED_AT,
  290. mention: '@[same](dsh-session:InNhbWUi)',
  291. }],
  292. }))
  293. const { source } = await bench(files, sessions)
  294. await expect(source.candidates(session, request('same'))).resolves.toEqual([
  295. expect.objectContaining({
  296. name: 'same',
  297. description: '(no cwd) · 3d',
  298. }),
  299. ])
  300. })
  301. it('falls back to the candidate createdAt for a session the Host list does not carry', async () => {
  302. const files = vi.fn(() => Promise.resolve({ ok: true as const, value: [] }))
  303. const sessions = vi.fn(() => Promise.resolve({
  304. ok: true as const,
  305. value: [{
  306. sessionId: sid('unlisted'),
  307. label: 'Unlisted run',
  308. cwd: `${HOME}/project`,
  309. sameWorkspace: true,
  310. createdAt: CREATED_AT,
  311. mention: '@[Unlisted run](dsh-session:InVubGlzdGVkIg)',
  312. }],
  313. }))
  314. // A row absent from the list has no durable activity time to read.
  315. const { source } = await bench(files, sessions, { other: { updatedAt: UPDATED_AT } })
  316. await expect(source.candidates(session, request('unlisted'))).resolves.toEqual([
  317. expect.objectContaining({ name: 'Unlisted run', description: '3d' }),
  318. ])
  319. })
  320. it('uses current Session titles and groups direct subagents above ordinary Sessions', async () => {
  321. const files = vi.fn(() => Promise.resolve({ ok: true as const, value: [] }))
  322. const sessions = vi.fn(() => Promise.resolve({
  323. ok: true as const,
  324. value: [
  325. {
  326. sessionId: sid('ordinary'),
  327. label: 'Ordinary title',
  328. displayTitle: 'Ordinary title',
  329. cwd: `${HOME}/project`,
  330. sameWorkspace: true,
  331. createdAt: CREATED_AT,
  332. mention: '@[Ordinary title](dsh-session:Im9yZGluYXJ5Ig)',
  333. },
  334. {
  335. sessionId: sid('worker'),
  336. label: 'Investigate startup',
  337. displayTitle: 'researcher',
  338. cwd: `${HOME}/project`,
  339. sameWorkspace: true,
  340. createdAt: CREATED_AT,
  341. mention: '@[researcher](dsh-session:IndvcmtlciI)',
  342. },
  343. ],
  344. }))
  345. const { source } = await bench(files, sessions, {
  346. worker: {
  347. updatedAt: UPDATED_AT,
  348. origin: 'subagent', parentId: session.sessionId,
  349. projectionValues: { title: 'Investigate startup' },
  350. },
  351. ordinary: { updatedAt: UPDATED_AT, projectionValues: { title: 'Ordinary title' } },
  352. })
  353. const candidates = await source.candidates(session, request('worker'))
  354. expect(candidates.map(candidate => ({ name: candidate.name, section: candidate.section }))).toEqual([
  355. { name: 'researcher', section: 'Subagents' },
  356. { name: 'Ordinary title', section: 'Sessions' },
  357. ])
  358. const [candidate] = candidates
  359. expect(source.onPick({
  360. candidate: candidate!,
  361. session,
  362. position: 'inline',
  363. via: 'menu',
  364. action: 'pick',
  365. span: { start: 0, end: 7, draftRev: 1 },
  366. })).toEqual({
  367. insert: {
  368. source: 'reference',
  369. ref: '@[researcher](dsh-session:IndvcmtlciI)',
  370. label: 'researcher',
  371. appearance: 'session',
  372. clipboardText: '@[researcher](dsh-session:IndvcmtlciI)',
  373. },
  374. })
  375. })
  376. it('reads a session opened moments ago as the present, not a zero distance', async () => {
  377. const files = vi.fn(() => Promise.resolve({ ok: true as const, value: [] }))
  378. const sessions = vi.fn(() => Promise.resolve({
  379. ok: true as const,
  380. value: [{
  381. sessionId: sid('just-now'),
  382. label: 'Just now',
  383. cwd: `${HOME}/project`,
  384. sameWorkspace: true,
  385. createdAt: NOW - 1_000,
  386. mention: '@[Just now](dsh-session:Imp1c3Qtbm93Ig)',
  387. }],
  388. }))
  389. const { source } = await bench(files, sessions, { 'just-now': { updatedAt: NOW - 1_000 } })
  390. await expect(source.candidates(session, request('just'))).resolves.toEqual([
  391. expect.objectContaining({ name: 'Just now', description: 'now' }),
  392. ])
  393. })
  394. it('dates a session in the current workspace without repeating that workspace', async () => {
  395. const files = vi.fn(() => Promise.resolve({ ok: true as const, value: [] }))
  396. const sessions = vi.fn(() => Promise.resolve({
  397. ok: true as const,
  398. value: [{
  399. sessionId: sid('sibling'),
  400. label: 'Sibling run',
  401. cwd: `${HOME}/project`,
  402. sameWorkspace: true,
  403. createdAt: CREATED_AT,
  404. mention: '@[Sibling run](dsh-session:InNpYmxpbmdyIg)',
  405. }],
  406. }))
  407. const { source } = await bench(files, sessions)
  408. await expect(source.candidates(session, request('sib'))).resolves.toEqual([
  409. expect.objectContaining({ name: 'Sibling run', description: '3d' }),
  410. ])
  411. })
  412. })
  413. describe('directory header', () => {
  414. const drilledRequest = (query: string, quoted = false): CandidateRequest => ({
  415. query,
  416. quoted,
  417. position: 'inline',
  418. drilled: true,
  419. signal: new AbortController().signal,
  420. })
  421. it('publishes no header for a query the user typed', async () => {
  422. const { source } = await bench()
  423. expect(source.header?.(session, { query: 'src/module1/', drilled: false })).toBeUndefined()
  424. })
  425. it('publishes no header until a drilled query names a directory', async () => {
  426. const { source } = await bench()
  427. expect(source.header?.(session, { query: 'src', drilled: true })).toBeUndefined()
  428. })
  429. it('trails the workspace root down to the directory being listed', async () => {
  430. const { source } = await bench()
  431. expect(source.header?.(session, { query: 'src/module1/ind', drilled: true })).toEqual([
  432. { label: 'Workspace', value: JSON.stringify({ kind: 'file', fileKind: 'directory', label: 'Workspace', mention: '@' }) },
  433. { label: 'src', value: JSON.stringify({ kind: 'file', fileKind: 'directory', label: 'src', mention: '@src/' }) },
  434. {
  435. label: 'module1',
  436. value: JSON.stringify({ kind: 'file', fileKind: 'directory', label: 'module1', mention: '@src/module1/' }),
  437. current: true,
  438. },
  439. ])
  440. })
  441. it('keeps an open quote across every crumb of a quoted descent', async () => {
  442. const { source } = await bench()
  443. const crumbs = source.header?.(session, { query: 'my dir/sub/', quoted: true, drilled: true })
  444. expect(crumbs?.map(crumb => JSON.parse(crumb.value) as { mention: string }).map(value => value.mention))
  445. .toEqual(['@"', '@"my dir/', '@"my dir/sub/'])
  446. })
  447. it('publishes no header when a segment cannot be written back as mention text', async () => {
  448. const { source } = await bench()
  449. expect(source.header?.(session, { query: 'ok/we\u0001ird/', drilled: true })).toBeUndefined()
  450. })
  451. it('returns to a crumb through the same drill outcome a folder row uses', async () => {
  452. const { source } = await bench()
  453. const crumbs = source.header?.(session, { query: 'src/module1/', drilled: true })
  454. expect(source.onPick({
  455. candidate: { name: 'src', value: crumbs?.[1]?.value ?? '' },
  456. session,
  457. position: 'inline',
  458. via: 'menu',
  459. action: 'drill',
  460. span: { start: 0, end: 13, draftRev: 1 },
  461. })).toEqual({ text: '@src/', continue: true })
  462. })
  463. it('drops the row location a drilled listing already shows in its header', async () => {
  464. const files = vi.fn(() => Promise.resolve({
  465. ok: true as const,
  466. value: [{ path: 'src/module1/index.html', kind: 'file' as const }],
  467. }))
  468. const sessions = vi.fn(() => Promise.resolve({ ok: true as const, value: [] }))
  469. const { source } = await bench(files, sessions)
  470. await expect(source.candidates(session, drilledRequest('src/module1/'))).resolves.toEqual([
  471. expect.objectContaining({ name: 'index.html', icon: 'file' }),
  472. ])
  473. const [row] = await source.candidates(session, drilledRequest('src/module1/'))
  474. expect(row).not.toHaveProperty('description')
  475. })
  476. })
  477. describe('pick and codec', () => {
  478. const pickAs = (action: 'pick' | 'drill') =>
  479. (source: InputTriggerSource, candidate: InputTriggerCandidate) => source.onPick({
  480. candidate,
  481. session,
  482. position: 'inline',
  483. via: 'menu',
  484. action,
  485. span: { start: 0, end: 1, draftRev: 1 },
  486. })
  487. const pick = pickAs('pick')
  488. const drill = pickAs('drill')
  489. it('settles files and directories as atomic icon labels; drill keeps directory completion open', async () => {
  490. const { source } = await bench()
  491. const [directory, file] = await source.candidates(session, request(''))
  492. expect(directory?.drill).toBe(true)
  493. expect(file?.drill).toBeUndefined()
  494. expect(pick(source, directory!)).toEqual({
  495. insert: {
  496. source: 'reference',
  497. ref: '@src/',
  498. label: 'src/',
  499. appearance: 'folder',
  500. clipboardText: '@src/',
  501. },
  502. })
  503. expect(drill(source, directory!)).toEqual({ text: '@src/', continue: true })
  504. expect(pick(source, file!)).toEqual({
  505. insert: {
  506. source: 'reference',
  507. ref: '@"docs/a b.md"',
  508. label: 'a b.md',
  509. appearance: 'file',
  510. clipboardText: '@"docs/a b.md"',
  511. },
  512. })
  513. const [quotedDirectory] = await source.candidates(session, request('', { quoted: true }))
  514. expect(drill(source, quotedDirectory!)).toEqual({ text: '@"src/', continue: true })
  515. })
  516. it('inserts sessions as atomic chips whose clipboard and model forms are canonical mentions', async () => {
  517. const { source } = await bench()
  518. const candidates = await source.candidates(session, request(''))
  519. const candidate = candidates.find(item => item.name === 'Research')!
  520. const mention = '@[Research](dsh-session:InNvdXJjZSI)'
  521. expect(pick(source, candidate)).toEqual({
  522. insert: {
  523. source: 'reference',
  524. ref: mention,
  525. label: 'Research',
  526. appearance: 'session',
  527. clipboardText: mention,
  528. },
  529. })
  530. expect(source.codec?.clipboardText(mention)).toBe(mention)
  531. await expect(source.codec?.serialize(mention, new AbortController().signal)).resolves.toBe(mention)
  532. })
  533. it('ignores candidates that do not carry a source-owned value', async () => {
  534. const { source } = await bench()
  535. expect(pick(source, { name: 'foreign candidate' })).toBeUndefined()
  536. })
  537. })
  538. describe('reference preview', () => {
  539. it('opens plain and quoted file references without treating folders or sessions as files', async () => {
  540. const { ctx, source, fiber } = await bench()
  541. const openResource = vi.spyOn(ctx.sidebarRight, 'openResource')
  542. expect(source.openReference?.(session, { ref: '@notes/readme.md', appearance: 'file' })).toBe(true)
  543. expect(source.openReference?.(session, { ref: '@"docs/a b.md"', appearance: 'file' })).toBe(true)
  544. expect(openResource).toHaveBeenNthCalledWith(1, 'dsh-resource://file/session/target/notes/readme.md')
  545. expect(openResource).toHaveBeenNthCalledWith(2, 'dsh-resource://file/session/target/docs/a%20b.md')
  546. expect(source.openReference?.(session, { ref: '@docs/', appearance: 'folder' })).toBe(false)
  547. expect(source.openReference?.(session, { ref: '@[Research](dsh-session:abc)', appearance: 'session' })).toBe(false)
  548. expect(openResource).toHaveBeenCalledTimes(2)
  549. await fiber.dispose()
  550. })
  551. })