test: verify published stdio entry behavior

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Jax
2026-03-13 18:37:42 +08:00
parent 94a041d502
commit 37d94c669a
3 changed files with 159 additions and 3 deletions
+28 -1
View File
@@ -12,8 +12,11 @@ const stdioEntryPath = resolve(projectRoot, "src/stdio.ts");
const packageJsonPath = resolve(projectRoot, "package.json");
type StdioCommandConfig = {
name?: string;
bin?: Record<string, string>;
mcp?: {
stdio?: {
developmentOnly?: boolean;
command?: string;
args?: string[];
};
@@ -101,10 +104,11 @@ describe("stdio entrypoint", () => {
await transport.close();
});
it("publishes a non-npm stdio launch command for MCP clients", async () => {
it("publishes a development-only non-npm stdio launch command for workspace MCP clients", async () => {
const packageJsonRaw = await readFile(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonRaw) as StdioCommandConfig;
expect(packageJson.mcp?.stdio?.developmentOnly).toBe(true);
expect(packageJson.mcp?.stdio?.command).not.toMatch(/^npm|^npx/);
expect(packageJson.scripts?.["start:stdio"]).toBeUndefined();
expect(packageJson.mcp?.stdio?.command).toBe("node");
@@ -114,10 +118,33 @@ describe("stdio entrypoint", () => {
]);
});
it("publishes a bin entry for npx-based stdio startup", async () => {
const packageJsonRaw = await readFile(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonRaw) as StdioCommandConfig;
expect(packageJson.name).toBeDefined();
expect(packageJson.bin).toEqual({
[packageJson.name as string]: "./dist/stdio.js",
});
});
it("does not write non-protocol logs to stdout from source entry", async () => {
const source = await readFile(stdioEntryPath, "utf8");
expect(source).not.toMatch(/console\.log\(/);
expect(source).not.toMatch(/process\.stdout\.write\(/);
});
it("keeps the published stdio entry executable", async () => {
const source = await readFile(stdioEntryPath, "utf8");
expect(source).toMatch(/^#!\/usr\/bin\/env node/m);
});
it("publishes a dedicated package-level verification script for the bin entry", async () => {
const packageJsonRaw = await readFile(packageJsonPath, "utf8");
const packageJson = JSON.parse(packageJsonRaw) as StdioCommandConfig;
expect(packageJson.scripts?.["test:publish"]).toBe("node ./scripts/verify-publish-bin.mjs");
});
});