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:
lintianle
2026-07-08 16:51:42 +08:00
parent ace0760927
commit 2d5918e158
2 changed files with 29 additions and 3 deletions

View File

@@ -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

View 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()
})
})