mirror of
https://github.com/nexu-io/open-design.git
synced 2026-09-20 06:15:06 +08:00
6ac5528ab3
* fix(landing): correct Codex plugin install page * fix(landing): address Codex plugin review * fix(landing): harden Codex plugin install protocol * fix(landing): secure plugin preflight and MCP checks * fix(landing): complete safe packaged install flow * fix(landing): harden Codex plugin verification * fix(landing): verify Codex install metadata * fix(landing): expose MCP launch spec for verification --------- Co-authored-by: Joey <236967869+joeylee12629-star@users.noreply.github.com>
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import { execFile } from 'node:child_process';
|
|
import { createServer } from 'node:http';
|
|
import { dirname, resolve as pathResolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { promisify } from 'node:util';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const execFileP = promisify(execFile);
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const DAEMON_ROOT = pathResolve(__dirname, '..');
|
|
const REPO_ROOT = pathResolve(__dirname, '../../..');
|
|
const CLI_SRC = pathResolve(__dirname, '../src/cli.ts');
|
|
const TSX_CLI = pathResolve(REPO_ROOT, 'node_modules/tsx/dist/cli.mjs');
|
|
|
|
async function runCli(args: string[]): Promise<{ stdout: string; stderr: string; code: number | null }> {
|
|
const env: NodeJS.ProcessEnv = { ...process.env };
|
|
delete env.NODE_OPTIONS;
|
|
try {
|
|
const { stdout, stderr } = await execFileP(process.execPath, [TSX_CLI, CLI_SRC, ...args], {
|
|
cwd: DAEMON_ROOT,
|
|
env,
|
|
timeout: 15_000,
|
|
maxBuffer: 4 * 1024 * 1024,
|
|
});
|
|
return { stdout, stderr, code: 0 };
|
|
} catch (err) {
|
|
const failed = err as { stdout?: string; stderr?: string; code?: number | null };
|
|
return {
|
|
stdout: failed.stdout ?? '',
|
|
stderr: failed.stderr ?? '',
|
|
code: failed.code ?? 1,
|
|
};
|
|
}
|
|
}
|
|
|
|
describe('od mcp install CLI identity probe', () => {
|
|
it('emits a stable identity token without requiring an agent slug', async () => {
|
|
const result = await runCli(['mcp', 'install', '--open-design-cli-probe']);
|
|
|
|
expect(result.code).toBe(0);
|
|
expect(result.stderr).toBe('');
|
|
expect(result.stdout).toBe('open-design-cli:mcp-install:v1\n');
|
|
});
|
|
|
|
it('includes the resolved launch spec in JSON dry-run output', async () => {
|
|
const launchSpec = {
|
|
command: '/opt/open-design/runtime',
|
|
args: ['/opt/open-design/daemon-cli.mjs', 'mcp'],
|
|
env: { OD_DATA_DIR: '/tmp/open-design-data' },
|
|
};
|
|
const server = createServer((_req, res) => {
|
|
res.setHeader('content-type', 'application/json');
|
|
res.end(JSON.stringify(launchSpec));
|
|
});
|
|
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
try {
|
|
const address = server.address();
|
|
if (!address || typeof address === 'string') throw new Error('missing test server address');
|
|
const result = await runCli([
|
|
'mcp',
|
|
'install',
|
|
'codex',
|
|
'--print',
|
|
'--json',
|
|
'--daemon-url',
|
|
`http://127.0.0.1:${address.port}`,
|
|
]);
|
|
|
|
expect(result.code).toBe(0);
|
|
expect(result.stderr).toBe('');
|
|
expect(JSON.parse(result.stdout)).toMatchObject({
|
|
ok: true,
|
|
agent: 'codex',
|
|
kind: 'cli',
|
|
launchSpec,
|
|
});
|
|
} finally {
|
|
await new Promise<void>((resolve, reject) => {
|
|
server.close((error) => (error ? reject(error) : resolve()));
|
|
});
|
|
}
|
|
});
|
|
});
|