Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 46 additions & 79 deletions sdk/typescript/tests-ts/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,49 @@ async function plugin(root: string, version = "1.2.3"): Promise<string> {
return path;
}

interface McpServerResponse {
id: number;
result: {
capabilities?: Record<string, unknown>;
tools?: Array<{
name: string;
inputSchema: {
properties: { userContext?: { maxLength?: number } };
};
}>;
};
}

async function inspectMcpServer(): Promise<McpServerResponse[]> {
const messages = [
{
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2025-11-25",
capabilities: {},
clientInfo: { name: "codex-security-test", version: "1.0.0" },
},
},
{ jsonrpc: "2.0", method: "notifications/initialized", params: {} },
{ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} },
];
const execution = promisify(execFile)(
"node",
[join(PLUGIN_ROOT, "mcp", "server.mjs"), "--stdio"],
{ encoding: "utf8", timeout: 10_000, windowsHide: true },
);
execution.child.stdin?.end(
`${messages.map((message) => JSON.stringify(message)).join("\n")}\n`,
);
const { stdout } = await execution;
return stdout
.trim()
.split("\n")
.map((line) => JSON.parse(line) as McpServerResponse);
}

describe("plugin runtime preparation", () => {
test("keeps installed-package plugin lookup inside the package", async () => {
const root = await temporaryDirectory();
Expand Down Expand Up @@ -461,48 +504,8 @@ describe("plugin runtime preparation", () => {
]);
});

test("accepts preserved context before starting a headless scan", () => {
const messages = [
{
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2025-11-25",
capabilities: {},
clientInfo: { name: "codex-security-test", version: "1.0.0" },
},
},
{ jsonrpc: "2.0", method: "notifications/initialized", params: {} },
{ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} },
];
const server = spawnSync(
process.execPath,
[join(PLUGIN_ROOT, "mcp", "server.mjs"), "--stdio"],
{
input: `${messages.map((message) => JSON.stringify(message)).join("\n")}\n`,
encoding: "utf8",
timeout: 10_000,
},
);
expect(server.status, server.stderr).toBe(0);
const responses = server.stdout
.trim()
.split("\n")
.map(
(line) =>
JSON.parse(line) as {
id: number;
result: {
tools?: Array<{
name: string;
inputSchema: {
properties: { userContext?: { maxLength?: number } };
};
}>;
};
},
);
test("accepts preserved context before starting a headless scan", async () => {
const responses = await inspectMcpServer();
const tool = responses
.find((response) => response.id === 2)
?.result.tools?.find(
Expand All @@ -521,43 +524,7 @@ describe("plugin runtime preparation", () => {
expect(contract.shippedExact).not.toContain("mcp/mcp-app.html.br");
expect(existsSync(join(PLUGIN_ROOT, "mcp", "mcp-app.html.br"))).toBe(false);

const messages = [
{
jsonrpc: "2.0",
id: 1,
method: "initialize",
params: {
protocolVersion: "2025-11-25",
capabilities: {},
clientInfo: { name: "codex-security-test", version: "1.0.0" },
},
},
{ jsonrpc: "2.0", method: "notifications/initialized", params: {} },
{ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} },
];
const server = spawnSync(
process.execPath,
[join(PLUGIN_ROOT, "mcp", "server.mjs"), "--stdio"],
{
input: `${messages.map((message) => JSON.stringify(message)).join("\n")}\n`,
encoding: "utf8",
timeout: 10_000,
},
);
expect(server.status, server.stderr).toBe(0);
const responses = server.stdout
.trim()
.split("\n")
.map(
(line) =>
JSON.parse(line) as {
id: number;
result: {
capabilities?: Record<string, unknown>;
tools?: Array<{ name: string }>;
};
},
);
const responses = await inspectMcpServer();
expect(
responses.find((response) => response.id === 1)?.result.capabilities,
).not.toHaveProperty("resources");
Expand Down
Loading