Files
ruflo/tests/plugins/codex-plugin-hook-manifests.test.mjs
T
rUvandr a12e204de3 fix(plugins): Codex hook manifests for every function-hook plugin (#3688) (#5206)
* fix(plugins): give every function-hook plugin a Codex hook manifest

Codex 0.172 rejects a hooks/hooks.json that carries Claude Code's
function-hook `modules` key ("unknown field `modules`, expected
`description` or `hooks`") and drops that plugin's hooks, printing the
warning on every start (#3688). Only ruflo-adr, ruflo-ddd, ruflo-sparc
and ruflo-swarm had the fix.

Apply the ruflo-swarm pattern to the other 39 plugins whose installed
root declares `modules`: a .codex-plugin/plugin.json (name, description,
version, author, homepage, license, as in the existing four) pointing at
hooks/codex-hooks.json. That file keeps the classic command hooks and
drops only `modules`; ruflo-metaharness keeps its SessionStart secret
bridge, all others get an explicit no-op whose description says the mod
part does not run on this host. ruflo-ai-team and ruflo-x-gateway are
untouched: their marketplace roots (directory/) ship no hooks.

Codex caches plugins by <name>/<version>/, and
audit-plugin-version-bump requires it, so each of the 39 gets a patch
bump, with the smoke.sh pins, ruflo-console's CONSOLE_VERSION, the
protector README and the console/mods/protector changelogs updated.

The swarm-only test is generalized into
tests/plugins/codex-plugin-hook-manifests.test.mjs, which covers every
plugin whose installed root has a `modules` key and now runs in
all-plugins-smoke.yml.

Co-Authored-By: RuFlo <ruv@ruv.net>

* fix(ruflo-metaharness): no SessionStart hook on Codex

The hook writes OPENROUTER_API_KEY through CLAUDE_ENV_FILE, which Codex
does not provide, so on Codex it does nothing. Shipping it would add a
new hook Codex asks the user to review, which stops a phone-started
Codex tab at a review screen.

Co-Authored-By: RuFlo <ruv@ruv.net>

---------

Co-authored-by: r <r@x>
2026-11-30 16:48:51 -05:00

70 lines
4.0 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// Codex's plugin hook-manifest loader accepts only `description` and `hooks` at the top level. A
// hooks/hooks.json that declares Claude Code function-hook `modules` makes Codex print
// `unknown field 'modules'` on every start and drop that plugin's hooks (#3688). Each such plugin
// ships a `.codex-plugin/plugin.json` (Codex prefers it over `.claude-plugin/plugin.json`) that points
// at hooks/codex-hooks.json: the plugin's classic command hooks without `modules`, or an explicit
// no-op. adr, ddd and sparc carry real Codex ports of their guards (tests/plugins/codex-mod-hooks.test.mjs).
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
const read = (file) => JSON.parse(fs.readFileSync(file, 'utf8'));
const marketplace = read(path.join(root, '.claude-plugin/marketplace.json'));
// Command hooks that only do anything under Claude Code. Shipping them to Codex adds a hook Codex
// asks the user to review on every new install or update, which stops a phone-started Codex tab at a
// review screen, for no effect: ruflo-metaharness writes the key through CLAUDE_ENV_FILE, which
// Codex does not provide.
const CLAUDE_ONLY_HOOKS = new Set(['ruflo-metaharness']);
const PORTED = new Set(['ruflo-adr', 'ruflo-ddd', 'ruflo-sparc']);
// The root a host installs: the marketplace `source` when it is local, else plugins/<name> itself.
// ruflo-ai-team and ruflo-x-gateway publish a `directory/` sub-root that has no hooks at all.
function installedRoot(name) {
const entry = marketplace.plugins.find((p) => p.name === name);
const source = typeof entry?.source === 'string' ? entry.source : `./plugins/${name}`;
return path.join(root, source);
}
const roots = fs
.readdirSync(path.join(root, 'plugins'), { withFileTypes: true })
.filter((d) => d.isDirectory() && fs.existsSync(path.join(root, 'plugins', d.name, '.claude-plugin/plugin.json')))
.map((d) => ({ name: d.name, dir: installedRoot(d.name) }))
.filter(({ dir }) => fs.existsSync(path.join(dir, 'hooks/hooks.json')))
.filter(({ dir }) => Object.hasOwn(read(path.join(dir, 'hooks/hooks.json')), 'modules'));
test('the scan finds plugins with function-hook modules (an empty scan would prove nothing)', () => {
assert.ok(roots.length >= 40, `expected at least 40 plugins with a modules key, found ${roots.length}`);
});
for (const { name, dir } of roots) {
test(`${name}: Codex gets a manifest whose hooks file has no modules key`, () => {
const codexPath = path.join(dir, '.codex-plugin/plugin.json');
assert.ok(fs.existsSync(codexPath), `${path.relative(root, codexPath)} must exist (#3688)`);
const codex = read(codexPath);
const claude = read(path.join(dir, '.claude-plugin/plugin.json'));
assert.equal(codex.name, claude.name);
assert.equal(codex.version, claude.version, 'Codex caches by <plugin>/<version>; the two manifests must agree');
assert.equal(codex.hooks, './hooks/codex-hooks.json');
for (const key of ['skills', 'mcpServers', 'commands', 'agents']) {
assert.equal(codex[key], claude[key], `${key} must not differ from the Claude manifest`);
}
const hooks = read(path.join(dir, 'hooks/codex-hooks.json'));
assert.deepEqual(Object.keys(hooks).filter((k) => k !== 'description' && k !== 'hooks'), []);
assert.equal(typeof hooks.description, 'string');
assert.ok(hooks.hooks && typeof hooks.hooks === 'object' && !Array.isArray(hooks.hooks));
assert.doesNotMatch(JSON.stringify(hooks.hooks), /modules|register\.ts/);
const claudeHooks = read(path.join(dir, 'hooks/hooks.json'));
if (CLAUDE_ONLY_HOOKS.has(name)) {
assert.deepEqual(hooks.hooks, {}, `${name}: its command hook only works under Claude Code, so Codex gets none`);
} else if (!PORTED.has(name)) {
assert.deepEqual(hooks.hooks, claudeHooks.hooks ?? {}, 'classic command hooks are kept as-is; modules alone become a no-op');
}
});
}