load-path.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Real-load-path guard for @deepseek-ai/dsh-mcp-client. `mcp-client` is a
  3. * NAMESPACE plugin with `inject` — so a stray `export default apply` would
  4. * make the cordis Loader's `unwrapExports` (`exports.default ?? exports`)
  5. * collapse the module to the bare `apply` function, DROPPING `inject`. The
  6. * plugin would then read `ctx.tools` without having injected it and throw
  7. * `cannot get property … without inject` the moment it loads (postmortem 0001).
  8. *
  9. * This test unwraps the module through the REAL `Loader.prototype.unwrapExports`
  10. * and verifies the namespace shape is preserved.
  11. */
  12. import { describe, expect, it } from 'vitest'
  13. import Loader from '@cordisjs/plugin-loader'
  14. import * as mcpClient from '@deepseek-ai/dsh-mcp-client'
  15. describe('dsh-mcp-client real-load-path guard', () => {
  16. it('has no default export and keeps name/inject/Config through unwrapExports', () => {
  17. expect('default' in mcpClient).toBe(false)
  18. const loader = Object.create(Loader.prototype) as Loader
  19. const unwrapped = loader.unwrapExports(mcpClient) as Record<string, unknown>
  20. expect(unwrapped).toBe(mcpClient)
  21. expect(unwrapped.name).toBe('mcp-client')
  22. expect(unwrapped.inject).toEqual(['tools'])
  23. expect(typeof unwrapped.apply).toBe('function')
  24. expect(unwrapped.Config).toBeDefined()
  25. })
  26. })