|
| 1 | +/** |
| 2 | + * Tests for plugin manifests: |
| 3 | + * - .claude-plugin/plugin.json (Claude Code plugin) |
| 4 | + * - .codex-plugin/plugin.json (Codex native plugin) |
| 5 | + * - .mcp.json (MCP server config at plugin root) |
| 6 | + * - .agents/plugins/marketplace.json (Codex marketplace discovery) |
| 7 | + * |
| 8 | + * Enforces rules from: |
| 9 | + * - .claude-plugin/PLUGIN_SCHEMA_NOTES.md (Claude Code validator rules) |
| 10 | + * - https://platform.openai.com/docs/codex/plugins (Codex official docs) |
| 11 | + * |
| 12 | + * Run with: node tests/plugin-manifest.test.js |
| 13 | + */ |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +const assert = require('assert'); |
| 18 | +const fs = require('fs'); |
| 19 | +const path = require('path'); |
| 20 | + |
| 21 | +const repoRoot = path.join(__dirname, '..'); |
| 22 | + |
| 23 | +let passed = 0; |
| 24 | +let failed = 0; |
| 25 | + |
| 26 | +function test(name, fn) { |
| 27 | + try { |
| 28 | + fn(); |
| 29 | + console.log(` ✓ ${name}`); |
| 30 | + passed++; |
| 31 | + } catch (err) { |
| 32 | + console.log(` ✗ ${name}`); |
| 33 | + console.log(` Error: ${err.message}`); |
| 34 | + failed++; |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// ── Claude plugin manifest ──────────────────────────────────────────────────── |
| 39 | +console.log('\n=== .claude-plugin/plugin.json ===\n'); |
| 40 | + |
| 41 | +const claudePluginPath = path.join(repoRoot, '.claude-plugin', 'plugin.json'); |
| 42 | + |
| 43 | +test('claude plugin.json exists', () => { |
| 44 | + assert.ok(fs.existsSync(claudePluginPath), 'Expected .claude-plugin/plugin.json to exist'); |
| 45 | +}); |
| 46 | + |
| 47 | +const claudePlugin = JSON.parse(fs.readFileSync(claudePluginPath, 'utf8')); |
| 48 | + |
| 49 | +test('claude plugin.json has version field', () => { |
| 50 | + assert.ok(claudePlugin.version, 'Expected version field'); |
| 51 | +}); |
| 52 | + |
| 53 | +test('claude plugin.json agents is an array', () => { |
| 54 | + assert.ok(Array.isArray(claudePlugin.agents), 'Expected agents to be an array (not a string/directory)'); |
| 55 | +}); |
| 56 | + |
| 57 | +test('claude plugin.json agents uses explicit file paths (not directories)', () => { |
| 58 | + for (const agentPath of claudePlugin.agents) { |
| 59 | + assert.ok( |
| 60 | + agentPath.endsWith('.md'), |
| 61 | + `Expected explicit .md file path, got: ${agentPath}`, |
| 62 | + ); |
| 63 | + assert.ok( |
| 64 | + !agentPath.endsWith('/'), |
| 65 | + `Expected explicit file path, not directory, got: ${agentPath}`, |
| 66 | + ); |
| 67 | + } |
| 68 | +}); |
| 69 | + |
| 70 | +test('claude plugin.json all agent files exist', () => { |
| 71 | + for (const agentRelPath of claudePlugin.agents) { |
| 72 | + const absolute = path.join(repoRoot, agentRelPath.replace(/^\.\//, '')); |
| 73 | + assert.ok( |
| 74 | + fs.existsSync(absolute), |
| 75 | + `Agent file missing: ${agentRelPath}`, |
| 76 | + ); |
| 77 | + } |
| 78 | +}); |
| 79 | + |
| 80 | +test('claude plugin.json skills is an array', () => { |
| 81 | + assert.ok(Array.isArray(claudePlugin.skills), 'Expected skills to be an array'); |
| 82 | +}); |
| 83 | + |
| 84 | +test('claude plugin.json commands is an array', () => { |
| 85 | + assert.ok(Array.isArray(claudePlugin.commands), 'Expected commands to be an array'); |
| 86 | +}); |
| 87 | + |
| 88 | +test('claude plugin.json does NOT have explicit hooks declaration', () => { |
| 89 | + assert.ok( |
| 90 | + !('hooks' in claudePlugin), |
| 91 | + 'hooks field must NOT be declared — Claude Code v2.1+ auto-loads hooks/hooks.json by convention', |
| 92 | + ); |
| 93 | +}); |
| 94 | + |
| 95 | +// ── Codex plugin manifest ───────────────────────────────────────────────────── |
| 96 | +// Per official docs: https://platform.openai.com/docs/codex/plugins |
| 97 | +// - .codex-plugin/plugin.json is the required manifest |
| 98 | +// - skills, mcpServers, apps are STRING paths relative to plugin root (not arrays) |
| 99 | +// - .mcp.json must be at plugin root (NOT inside .codex-plugin/) |
| 100 | +console.log('\n=== .codex-plugin/plugin.json ===\n'); |
| 101 | + |
| 102 | +const codexPluginPath = path.join(repoRoot, '.codex-plugin', 'plugin.json'); |
| 103 | + |
| 104 | +test('codex plugin.json exists', () => { |
| 105 | + assert.ok(fs.existsSync(codexPluginPath), 'Expected .codex-plugin/plugin.json to exist'); |
| 106 | +}); |
| 107 | + |
| 108 | +const codexPlugin = JSON.parse(fs.readFileSync(codexPluginPath, 'utf8')); |
| 109 | + |
| 110 | +test('codex plugin.json has name field', () => { |
| 111 | + assert.ok(codexPlugin.name, 'Expected name field'); |
| 112 | +}); |
| 113 | + |
| 114 | +test('codex plugin.json has version field', () => { |
| 115 | + assert.ok(codexPlugin.version, 'Expected version field'); |
| 116 | +}); |
| 117 | + |
| 118 | +test('codex plugin.json skills is a string (not array) per official spec', () => { |
| 119 | + assert.strictEqual( |
| 120 | + typeof codexPlugin.skills, |
| 121 | + 'string', |
| 122 | + 'skills must be a string path per Codex official docs, not an array', |
| 123 | + ); |
| 124 | +}); |
| 125 | + |
| 126 | +test('codex plugin.json mcpServers is a string path (not array) per official spec', () => { |
| 127 | + assert.strictEqual( |
| 128 | + typeof codexPlugin.mcpServers, |
| 129 | + 'string', |
| 130 | + 'mcpServers must be a string path per Codex official docs', |
| 131 | + ); |
| 132 | +}); |
| 133 | + |
| 134 | +test('codex plugin.json mcpServers exactly matches "./.mcp.json"', () => { |
| 135 | + assert.strictEqual( |
| 136 | + codexPlugin.mcpServers, |
| 137 | + './.mcp.json', |
| 138 | + 'mcpServers must point exactly to "./.mcp.json" per official docs', |
| 139 | + ); |
| 140 | + const mcpPath = path.join(repoRoot, codexPlugin.mcpServers.replace(/^\.\//, '')); |
| 141 | + assert.ok( |
| 142 | + fs.existsSync(mcpPath), |
| 143 | + `mcpServers file missing at plugin root: ${codexPlugin.mcpServers}`, |
| 144 | + ); |
| 145 | +}); |
| 146 | + |
| 147 | +test('codex plugin.json has interface.displayName', () => { |
| 148 | + assert.ok( |
| 149 | + codexPlugin.interface && codexPlugin.interface.displayName, |
| 150 | + 'Expected interface.displayName for plugin directory presentation', |
| 151 | + ); |
| 152 | +}); |
| 153 | + |
| 154 | +// ── .mcp.json at plugin root ────────────────────────────────────────────────── |
| 155 | +// Per official docs: keep .mcp.json at plugin root, NOT inside .codex-plugin/ |
| 156 | +console.log('\n=== .mcp.json (plugin root) ===\n'); |
| 157 | + |
| 158 | +const mcpJsonPath = path.join(repoRoot, '.mcp.json'); |
| 159 | + |
| 160 | +test('.mcp.json exists at plugin root (not inside .codex-plugin/)', () => { |
| 161 | + assert.ok(fs.existsSync(mcpJsonPath), 'Expected .mcp.json at repo root (plugin root)'); |
| 162 | + assert.ok( |
| 163 | + !fs.existsSync(path.join(repoRoot, '.codex-plugin', '.mcp.json')), |
| 164 | + '.mcp.json must NOT be inside .codex-plugin/ — only plugin.json belongs there', |
| 165 | + ); |
| 166 | +}); |
| 167 | + |
| 168 | +const mcpConfig = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf8')); |
| 169 | + |
| 170 | +test('.mcp.json has mcpServers object', () => { |
| 171 | + assert.ok( |
| 172 | + mcpConfig.mcpServers && typeof mcpConfig.mcpServers === 'object', |
| 173 | + 'Expected mcpServers object', |
| 174 | + ); |
| 175 | +}); |
| 176 | + |
| 177 | +test('.mcp.json includes at least github, context7, and exa servers', () => { |
| 178 | + const servers = Object.keys(mcpConfig.mcpServers); |
| 179 | + assert.ok(servers.includes('github'), 'Expected github MCP server'); |
| 180 | + assert.ok(servers.includes('context7'), 'Expected context7 MCP server'); |
| 181 | + assert.ok(servers.includes('exa'), 'Expected exa MCP server'); |
| 182 | +}); |
| 183 | + |
| 184 | +// ── Codex marketplace file ──────────────────────────────────────────────────── |
| 185 | +// Per official docs: repo marketplace lives at $REPO_ROOT/.agents/plugins/marketplace.json |
| 186 | +console.log('\n=== .agents/plugins/marketplace.json ===\n'); |
| 187 | + |
| 188 | +const marketplacePath = path.join(repoRoot, '.agents', 'plugins', 'marketplace.json'); |
| 189 | + |
| 190 | +test('marketplace.json exists at .agents/plugins/', () => { |
| 191 | + assert.ok( |
| 192 | + fs.existsSync(marketplacePath), |
| 193 | + 'Expected .agents/plugins/marketplace.json for Codex repo marketplace discovery', |
| 194 | + ); |
| 195 | +}); |
| 196 | + |
| 197 | +const marketplace = JSON.parse(fs.readFileSync(marketplacePath, 'utf8')); |
| 198 | + |
| 199 | +test('marketplace.json has name field', () => { |
| 200 | + assert.ok(marketplace.name, 'Expected name field'); |
| 201 | +}); |
| 202 | + |
| 203 | +test('marketplace.json has plugins array with at least one entry', () => { |
| 204 | + assert.ok(Array.isArray(marketplace.plugins) && marketplace.plugins.length > 0, 'Expected plugins array'); |
| 205 | +}); |
| 206 | + |
| 207 | +test('marketplace.json plugin entries have required fields', () => { |
| 208 | + for (const plugin of marketplace.plugins) { |
| 209 | + assert.ok(plugin.name, `Plugin entry missing name`); |
| 210 | + assert.ok(plugin.source && plugin.source.source, `Plugin "${plugin.name}" missing source.source`); |
| 211 | + assert.ok(plugin.policy && plugin.policy.installation, `Plugin "${plugin.name}" missing policy.installation`); |
| 212 | + assert.ok(plugin.category, `Plugin "${plugin.name}" missing category`); |
| 213 | + } |
| 214 | +}); |
| 215 | + |
| 216 | +// ── Summary ─────────────────────────────────────────────────────────────────── |
| 217 | +console.log(`\nPassed: ${passed}`); |
| 218 | +console.log(`Failed: ${failed}`); |
| 219 | +process.exit(failed > 0 ? 1 : 0); |
0 commit comments