fix(plugins): validate Codex companion launch metadata

This commit is contained in:
morluto
2026-10-14 01:23:15 +08:00
parent b7dabdbc4f
commit a85bfed8dc
15 changed files with 315 additions and 99 deletions
@@ -24,9 +24,24 @@ const pluginManifestPaths = [
".codex-plugin/plugin.json",
] as const;
const pluginManifest = (version: string, launch = `rea-agents@${version}`) => ({
const pluginManifest = (version: string, launch = version) => ({
version,
mcpServers: { rea: { args: ["-y", launch, "mcp"] } },
mcpServers: {
rea: {
command: "node",
args: ["${CLAUDE_PLUGIN_ROOT}/scripts/plugin-mcp-launcher.mjs", launch],
},
},
});
const codexServerConfig = (version: string, launch = version) => ({
mcpServers: {
rea: {
command: "node",
args: ["./scripts/plugin-mcp-launcher.mjs", launch],
startup_timeout_sec: 30,
},
},
});
async function metadata(
@@ -40,9 +55,12 @@ async function metadata(
for (const path of pluginManifestPaths)
await mkdir(join(directory, dirname(path)), { recursive: true });
const files = {
...Object.fromEntries(
pluginManifestPaths.map((path) => [path, pluginManifest(version)]),
),
".claude-plugin/plugin.json": pluginManifest(version),
".codex-plugin/plugin.json": {
version,
mcpServers: "./.mcp.json",
},
".mcp.json": codexServerConfig(version),
"package.json": { name: "rea-agents", version },
"package-lock.json": { version, packages: { "": { version } } },
".release-please-manifest.json": { ".": version },
@@ -581,27 +599,15 @@ it.each([
});
it.each(
pluginManifestPaths.flatMap((path) => [
{
path,
stale: "version",
manifest: pluginManifest("5.1.0", "rea-agents@6.0.0"),
failure: "declares 5.1.0; release branch requires 6.0.0",
},
{
path,
stale: "server launch",
manifest: pluginManifest("6.0.0", "rea-agents@5.1.0"),
failure:
"launches rea-agents@5.1.0; release branch requires rea-agents@6.0.0",
},
{
path,
stale: "server launch without the package name",
manifest: pluginManifest("6.0.0", "6.0.0"),
failure: "launches 6.0.0; release branch requires rea-agents@6.0.0",
},
]),
pluginManifestPaths.map((path) => ({
path,
stale: "version",
manifest:
path === ".codex-plugin/plugin.json"
? { version: "5.1.0", mcpServers: "./.mcp.json" }
: pluginManifest("5.1.0"),
failure: "declares 5.1.0; release branch requires 6.0.0",
})),
)("rejects a plugin $stale in $path", async ({ path, manifest, failure }) => {
const f = await fixture();
await candidate(f, "6.0.0");
@@ -614,6 +620,29 @@ it.each(
});
});
it.each([
{
path: ".claude-plugin/plugin.json",
manifest: pluginManifest("6.0.0", "5.1.0"),
},
{
path: ".mcp.json",
manifest: codexServerConfig("6.0.0", "5.1.0"),
},
])("reads the release pin from $path", async ({ path, manifest }) => {
const f = await fixture();
await candidate(f, "6.0.0");
await writeFile(join(f.directory, path), JSON.stringify(manifest));
await git(f.directory, ["add", "."]);
await git(f.directory, ["commit", "-m", "chore: stale plugin launch"]);
await expect(verify(f)).rejects.toMatchObject({
code: 1,
stderr: expect.stringContaining(
`launches version 5.1.0; release branch requires 6.0.0`,
),
});
});
it("checks a publish merge using its pre-release first parent baseline", async () => {
const f = await fixture();
const sourceSha = await candidate(f, "6.0.0");
+74 -17
View File
@@ -47,6 +47,7 @@ const pluginManifests = [
".claude-plugin/plugin.json",
".codex-plugin/plugin.json",
] as const;
const pluginServerConfig = ".mcp.json";
const pluginMarketplaces = [
".claude-plugin/marketplace.json",
@@ -58,15 +59,43 @@ const pluginMarketplace = (version: string, packageName = "rea-agents") => ({
],
});
const pluginServer = (version: string, command = "node") => ({
mcpServers: {
rea: {
command,
args: ["./scripts/plugin-mcp-launcher.mjs", version],
startup_timeout_sec: 30,
},
},
});
const pluginManifest = (
version: string,
{ skills = ["./skill"], packageName = "rea-agents" } = {},
{ skills = ["./skill"], command = "node" } = {},
) => ({
version,
skills,
mcpServers: { rea: { args: ["-y", `${packageName}@${version}`, "mcp"] } },
mcpServers: {
rea: {
command,
args: ["${CLAUDE_PLUGIN_ROOT}/scripts/plugin-mcp-launcher.mjs", version],
},
},
});
const pluginManifestFor = (
path: (typeof pluginManifests)[number],
version: string,
options: { skills?: string[]; command?: string } = {},
) =>
path === ".codex-plugin/plugin.json"
? {
version,
skills: options.skills ?? ["./skill"],
mcpServers: "./.mcp.json",
}
: pluginManifest(version, options);
beforeAll(async () => {
const workspace = await createTestWorkspace("rea-release-notes-seed-");
seedWorkspaceRoot = workspace.root;
@@ -86,9 +115,13 @@ beforeAll(async () => {
await mkdir(join(directory, dirname(path)), { recursive: true });
await writeFile(
join(directory, path),
JSON.stringify(pluginManifest("6.3.0")),
JSON.stringify(pluginManifestFor(path, "6.3.0")),
);
}
await writeFile(
join(directory, pluginServerConfig),
JSON.stringify(pluginServer("6.3.0")),
);
for (const path of pluginMarketplaces) {
await mkdir(join(directory, dirname(path)), { recursive: true });
await writeFile(
@@ -409,8 +442,12 @@ it("binds publication to complete recorded history and the reviewed base", async
for (const path of pluginManifests)
await writeFile(
join(f.directory, path),
JSON.stringify(pluginManifest("6.4.0")),
JSON.stringify(pluginManifestFor(path, "6.4.0")),
);
await writeFile(
join(f.directory, pluginServerConfig),
JSON.stringify(pluginServer("6.4.0")),
);
for (const path of pluginMarketplaces)
await writeFile(
join(f.directory, path),
@@ -420,6 +457,7 @@ it("binds publication to complete recorded history and the reviewed base", async
"add",
"CHANGELOG.md",
...pluginManifests,
pluginServerConfig,
...pluginMarketplaces,
]);
await git(f.directory, ["commit", "-m", "chore: release notes"]);
@@ -445,22 +483,15 @@ it("binds publication to complete recorded history and the reviewed base", async
});
});
it.each(
pluginManifests.flatMap((path) => [
{ path, change: "the skill path", edit: { skills: ["./another-skill"] } },
{
path,
change: "the launched package",
edit: { packageName: "another-package" },
},
]),
)(
"treats a release that changes $change in $path as a product change",
async ({ path, edit }) => {
it.each(pluginManifests)(
"treats a release that changes the skill path in %s as a product change",
async (path) => {
const f = await fixture();
await writeFile(
join(f.directory, path),
JSON.stringify(pluginManifest("6.4.0", edit)),
JSON.stringify(
pluginManifestFor(path, "6.4.0", { skills: ["./another-skill"] }),
),
);
await git(f.directory, ["add", "CHANGELOG.md", path]);
await git(f.directory, ["commit", "-m", "chore: release notes"]);
@@ -474,6 +505,32 @@ it.each(
},
);
it.each([
{
path: ".claude-plugin/plugin.json",
content: pluginManifest("6.4.0", { command: "other-launcher" }),
},
{
path: pluginServerConfig,
content: pluginServer("6.4.0", "other-launcher"),
},
])(
"keeps launcher behavior in $path outside version-only metadata",
async ({ path, content }) => {
const f = await fixture();
await writeFile(join(f.directory, path), JSON.stringify(content));
await git(f.directory, ["add", "CHANGELOG.md", path]);
await git(f.directory, ["commit", "-m", "chore: release notes"]);
await expect(
f.invoke(["check", "--manifest", f.manifest, "--source", "HEAD"]),
).rejects.toMatchObject({
stderr: expect.stringContaining(
`Product changed after notes target; regenerate inventory: ${path}`,
),
});
},
);
it("checks the live merged PR and exact Git snapshot before either publication route", async () => {
const f = await fixture();
await mkdir(join(f.directory, "docs/releases"), { recursive: true });
@@ -10,8 +10,8 @@ const launcher = fileURLToPath(
new URL("../../../scripts/plugin-mcp-launcher.mjs", import.meta.url),
);
const start = (path: string, packageSpecifier = "rea-agents@6.4.0-rc.1") => {
const child = spawn(process.execPath, [launcher, packageSpecifier], {
const start = (path: string, version = "6.4.0-rc.1") => {
const child = spawn(process.execPath, [launcher, version], {
env: {
...process.env,
PATH: `${path}${delimiter}${process.env.PATH ?? ""}`,
@@ -65,7 +65,7 @@ it.skipIf(process.platform === "win32")(
process.stdin.pipe(process.stdout);
process.stdin.on("end", () => { process.exitCode = 7; });
`);
const { child, closed } = start(bin, "rea-agents@6.4.0-rc.1");
const { child, closed } = start(bin, "6.4.0-rc.1");
child.stdin.end('{"jsonrpc":"2.0","id":1}\n');
expect(await closed).toEqual({
code: 7,
@@ -162,7 +162,7 @@ it.skipIf(process.platform === "win32")(
it("rejects a shell expression instead of treating it as the pinned package", async () => {
const root = await createTestTempDirectory("rea-plugin-invalid-pin-");
const { child, closed } = start(root, "rea-agents@6.4.0&echo wrong");
const { child, closed } = start(root, "6.4.0&echo wrong");
child.stdin.end();
expect(await closed).toMatchObject({
code: 1,
+14 -10
View File
@@ -195,7 +195,7 @@ describe("plugin manifests", () => {
});
});
it.each(pluginManifests)(
it.each([...pluginManifests, pluginServerConfig])(
"pins the plugin manifest %s and Codex's server config path",
async (path) => {
const packageJson = (await readJson("package.json")) as {
@@ -251,7 +251,12 @@ describe("plugin manifests", () => {
expect(updatedJson.get(".claude-plugin/plugin.json")).toMatchObject({
version: nextVersion,
mcpServers: {
rea: { args: ["-y", `rea-agents@${nextVersion}`, "mcp"] },
rea: {
args: [
"${CLAUDE_PLUGIN_ROOT}/scripts/plugin-mcp-launcher.mjs",
nextVersion,
],
},
},
});
expect(updatedJson.get(".codex-plugin/plugin.json")).toMatchObject({
@@ -259,7 +264,10 @@ describe("plugin manifests", () => {
});
expect(updatedJson.get(pluginServerConfig)).toMatchObject({
mcpServers: {
rea: { args: ["-y", `rea-agents@${nextVersion}`, "mcp"] },
rea: {
args: ["./scripts/plugin-mcp-launcher.mjs", nextVersion],
startup_timeout_sec: 30,
},
},
});
for (const path of [
@@ -281,7 +289,6 @@ describe("plugin manifests", () => {
it("pins the plugin server launch from the shared MCP declaration", async () => {
const packageJson = (await readJson("package.json")) as {
name: string;
version: string;
};
@@ -289,10 +296,7 @@ describe("plugin manifests", () => {
mcpServers: {
rea: {
command: "node",
args: [
"./scripts/plugin-mcp-launcher.mjs",
`${packageJson.name}@${packageJson.version}`,
],
args: ["./scripts/plugin-mcp-launcher.mjs", packageJson.version],
cwd: ".",
},
},
@@ -332,8 +336,8 @@ describe("plugin manifests", () => {
);
});
it("carries the owned Codex startup timeout in the Codex plugin server entry", async () => {
expect(await readJson(".codex-plugin/plugin.json")).toMatchObject({
it("carries the owned Codex startup timeout in the companion server entry", async () => {
expect(await readJson(pluginServerConfig)).toMatchObject({
mcpServers: {
rea: {
startup_timeout_sec: MCP_STARTUP_POLICY.codexStartupTimeoutSeconds,