test: add Loader export-path guard for dsh-mcp-client
Verifies the namespace plugin has no default export and preserves name/inject/Config through Loader.unwrapExports — the same guard pattern as dsh-tool-web, per the packages/AGENTS.md convention.
This commit is contained in:
@@ -79,9 +79,6 @@ flowchart TD
|
||||
pkg_app_boot["app-boot"]
|
||||
pkg_stdio_agent["stdio-agent"]
|
||||
end
|
||||
subgraph group_mcp["packages/mcp"]
|
||||
pkg_mcp_client["mcp-client"]
|
||||
end
|
||||
subgraph group_code_runtime["packages/code-runtime"]
|
||||
pkg_code_runtime["code-runtime"]
|
||||
end
|
||||
|
||||
29
packages/mcp/mcp-client/tests/load-path.spec.ts
Normal file
29
packages/mcp/mcp-client/tests/load-path.spec.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Real-load-path guard for @deepseek-ai/dsh-mcp-client. `mcp-client` is a
|
||||
* NAMESPACE plugin with `inject` — so a stray `export default apply` would
|
||||
* make the cordis Loader's `unwrapExports` (`exports.default ?? exports`)
|
||||
* collapse the module to the bare `apply` function, DROPPING `inject`. The
|
||||
* plugin would then read `ctx.tools` without having injected it and throw
|
||||
* `cannot get property … without inject` the moment it loads (postmortem 0001).
|
||||
*
|
||||
* This test unwraps the module through the REAL `Loader.prototype.unwrapExports`
|
||||
* and verifies the namespace shape is preserved.
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import Loader from '@cordisjs/plugin-loader'
|
||||
import * as mcpClient from '@deepseek-ai/dsh-mcp-client'
|
||||
|
||||
describe('dsh-mcp-client real-load-path guard', () => {
|
||||
it('has no default export and keeps name/inject/Config through unwrapExports', () => {
|
||||
expect('default' in mcpClient).toBe(false)
|
||||
|
||||
const loader = Object.create(Loader.prototype) as Loader
|
||||
const unwrapped = loader.unwrapExports(mcpClient) as Record<string, unknown>
|
||||
expect(unwrapped).toBe(mcpClient)
|
||||
expect(unwrapped.name).toBe('mcp-client')
|
||||
expect(unwrapped.inject).toEqual(['tools'])
|
||||
expect(typeof unwrapped.apply).toBe('function')
|
||||
expect(unwrapped.Config).toBeDefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user