load-path.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Real Loader-path guard for an injected namespace plugin. A default export would make
  3. * `unwrapExports` collapse the namespace and drop `inject`, causing access to `ctx.web` to fail.
  4. * Hand-built mounting bypasses that path, so this test unwraps through the real Loader first; see
  5. * postmortem 0001.
  6. */
  7. import { describe, expect, it } from 'vitest'
  8. import { Context } from '@deepseek-ai/cordis'
  9. import Loader from '@deepseek-ai/cordis-plugin-loader'
  10. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  11. import ToolRuntime from '@deepseek-ai/dsh-tools'
  12. import WebRuntime from '@deepseek-ai/dsh-web'
  13. import * as toolWeb from '@deepseek-ai/dsh-tool-web'
  14. describe('dsh-tool-web real-load-path guard', () => {
  15. it('has no default export and keeps name/inject/Config through unwrapExports', () => {
  16. expect('default' in toolWeb).toBe(false)
  17. const loader = Object.create(Loader.prototype) as Loader
  18. const unwrapped = loader.unwrapExports(toolWeb) as Record<string, unknown>
  19. expect(unwrapped).toBe(toolWeb)
  20. expect(unwrapped.name).toBe('tool-web')
  21. expect(unwrapped.inject).toEqual(['tools', 'web', 'systemPrompt'])
  22. expect(typeof unwrapped.apply).toBe('function')
  23. })
  24. it('boots over ctx.web through the unwrapped module without an inject error', async () => {
  25. const ctx = new Context()
  26. await ctx.plugin(SystemPrompt)
  27. await ctx.plugin(ToolRuntime)
  28. await ctx.plugin(WebRuntime, {})
  29. const loader = Object.create(Loader.prototype) as Loader
  30. const unwrapped = loader.unwrapExports(toolWeb) as Parameters<Context['plugin']>[0]
  31. // Mounting the collapsed shape would throw for missing injection here.
  32. const fiber = await ctx.plugin(unwrapped)
  33. expect(ctx.tools.schemas().map(s => s.name)).toEqual(expect.arrayContaining(['web_search', 'web_fetch']))
  34. await fiber.dispose()
  35. })
  36. })