plugin-shape.spec.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132
  1. import { describe, expect, it } from 'vitest'
  2. import Loader from '@cordisjs/plugin-loader'
  3. import * as jsonrpc from '../src/index.ts'
  4. /**
  5. * REAL-export-path guard for the @deepseek-ai/dsh-jsonrpc namespace plugin
  6. * (the packages/AGENTS.md red line: a plugin shipped via `cordis.yml` needs a
  7. * test through the real Loader/export path). A hand-built `ctx.plugin({...})`
  8. * mount bypasses `unwrapExports` — the exact path that once collapsed a
  9. * namespace plugin with a stray `export default` and silently dropped its
  10. * `inject` (docs/postmortem/0001) — so this spec drives the REAL
  11. * `Loader.unwrapExports` over the module namespace and asserts the
  12. * `name`/`inject`/`Config`/`apply` shape survives it intact.
  13. */
  14. describe('dsh-jsonrpc plugin export shape', () => {
  15. it('has the namespace-plugin export shape (no stray default) so the Loader keeps name/inject/Config/apply', () => {
  16. // A stray `export default` would make `unwrapExports` (`exports.default ??
  17. // exports`) collapse the module to the bare default, dropping `inject` —
  18. // the plugin would then throw "cannot get property … without inject" at
  19. // its first `ctx.agents` read. Adding `export default` fails this test.
  20. expect('default' in jsonrpc).toBe(false)
  21. expect(typeof jsonrpc.apply).toBe('function')
  22. const loader = Object.create(Loader.prototype) as Loader
  23. const unwrapped = loader.unwrapExports(jsonrpc) as Record<string, unknown>
  24. expect(unwrapped).toBe(jsonrpc)
  25. expect(unwrapped.name).toBe('jsonrpc')
  26. expect(unwrapped.inject).toEqual(['agents'])
  27. expect(unwrapped.Config).toBeDefined()
  28. expect(typeof unwrapped.apply).toBe('function')
  29. })
  30. })