load-path.e2e.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Keyless real-Loader-path smoke for the combined SQLite session-query service.
  3. *
  4. * @module @deepseek-ai/dsh-session-query-sqlite/tests/load-path
  5. */
  6. import { afterEach, describe, expect, it } from 'vitest'
  7. import { Context } from 'cordis'
  8. import Loader from '@cordisjs/plugin-loader'
  9. import { SESSION_FORMAT_VERSION, SessionId } from '@deepseek-ai/dsh-session'
  10. import SessionStore from '@deepseek-ai/dsh-session'
  11. import SessionPersistenceSqlite from '@deepseek-ai/dsh-session-persistence-sqlite'
  12. import SessionQuerySqlite, * as queryModule from '@deepseek-ai/dsh-session-query-sqlite'
  13. import { mkdtemp, rm } from 'node:fs/promises'
  14. import { tmpdir } from 'node:os'
  15. import { join } from 'node:path'
  16. const temporaryDirectories: string[] = []
  17. afterEach(async () => {
  18. for (const directory of temporaryDirectories.splice(0)) {
  19. await rm(directory, { recursive: true, force: true })
  20. }
  21. })
  22. async function temporaryPath(name: string): Promise<string> {
  23. const directory = await mkdtemp(join(tmpdir(), 'dsh-session-search-loader-'))
  24. temporaryDirectories.push(directory)
  25. return join(directory, name)
  26. }
  27. describe('dsh-session-query-sqlite real Loader path', () => {
  28. it('unwraps, mounts, and searches the real persistence backend', async () => {
  29. const persistencePath = await temporaryPath('canonical.db')
  30. const searchPath = await temporaryPath('derived.db')
  31. const ctx = new Context()
  32. await ctx.plugin(SessionStore)
  33. const persistence = await ctx.plugin(SessionPersistenceSqlite, { path: persistencePath })
  34. const loader = Object.create(Loader.prototype) as Loader
  35. const unwrapped = loader.unwrapExports(queryModule) as Parameters<Context['plugin']>[0]
  36. expect(unwrapped).toBe(SessionQuerySqlite)
  37. const query = await ctx.plugin(unwrapped, { path: searchPath })
  38. const id = SessionId('loader-path')
  39. await ctx.sessionPersistence.create({ version: SESSION_FORMAT_VERSION, id, createdAt: 10 })
  40. await ctx.sessionPersistence.append(id, [{
  41. type: 'user/message',
  42. seq: 0,
  43. time: 10,
  44. data: { content: [{ type: 'text', text: 'real Loader needle' }], source: { kind: 'user' } },
  45. surfaceOp: 'append',
  46. }])
  47. await expect(ctx.sessionQuery.searchSessions({ query: 'Loader needle' }))
  48. .resolves.toMatchObject({ items: [{ header: { id }, persisted: true, live: false }] })
  49. await expect(ctx.sessionQuery.listSessions())
  50. .resolves.toMatchObject([{ header: { id }, persisted: true, live: false }])
  51. await query.dispose()
  52. await persistence.dispose()
  53. })
  54. })