load-path.e2e.ts 2.6 KB

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