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:
+28
-1
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user