|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { mkdtempSync, rmSync, writeFileSync, chmodSync, readFileSync } from 'node:fs'; |
| 3 | +import { tmpdir } from 'node:os'; |
| 4 | +import { join, resolve } from 'node:path'; |
| 5 | +import { spawnSync } from 'node:child_process'; |
| 6 | +import { test } from 'node:test'; |
| 7 | + |
| 8 | +const repoRoot = resolve(import.meta.dirname, '../../..'); |
| 9 | +const installScript = join(repoRoot, 'apps/landing-page/public/install.sh'); |
| 10 | + |
| 11 | +function runInstall(args: string[], pathDir: string) { |
| 12 | + return spawnSync('sh', [installScript, ...args], { |
| 13 | + encoding: 'utf8', |
| 14 | + env: { |
| 15 | + ...process.env, |
| 16 | + PATH: `${pathDir}${process.platform === 'win32' ? ';' : ':'}${process.env.PATH ?? ''}`, |
| 17 | + }, |
| 18 | + }); |
| 19 | +} |
| 20 | + |
| 21 | +test('landing page serves install.sh as a shell script, not the HTML app fallback', () => { |
| 22 | + const body = readFileSync(installScript, 'utf8'); |
| 23 | + |
| 24 | + assert.match(body, /^#!\/usr\/bin\/env sh\n/); |
| 25 | + assert.match(body, /od mcp install/); |
| 26 | + assert.doesNotMatch(body, /<!doctype html/i); |
| 27 | + assert.doesNotMatch(body, /<html/i); |
| 28 | +}); |
| 29 | + |
| 30 | +test('install.sh delegates to the Open Design CLI installer with the requested agent', () => { |
| 31 | + const tmp = mkdtempSync(join(tmpdir(), 'od-install-sh-')); |
| 32 | + const argvOut = join(tmp, 'argv.txt'); |
| 33 | + const fakeOd = join(tmp, 'od'); |
| 34 | + writeFileSync( |
| 35 | + fakeOd, |
| 36 | + `#!/bin/sh |
| 37 | +if [ "$1" = "mcp" ] && [ "$2" = "install" ] && [ "$3" = "--help" ]; then |
| 38 | + printf '%s\\n' 'Usage text intentionally does not define CLI identity.' |
| 39 | + exit 0 |
| 40 | +fi |
| 41 | +if [ "$1" = "mcp" ] && [ "$2" = "install" ] && [ "$3" = "--open-design-cli-probe" ]; then |
| 42 | + printf '%s\\n' 'open-design-cli:mcp-install:v1' |
| 43 | + exit 0 |
| 44 | +fi |
| 45 | +printf '%s\\n' "$@" > "${argvOut}" |
| 46 | +`, |
| 47 | + 'utf8', |
| 48 | + ); |
| 49 | + chmodSync(fakeOd, 0o755); |
| 50 | + |
| 51 | + try { |
| 52 | + const result = runInstall(['codex', '--print'], tmp); |
| 53 | + |
| 54 | + assert.equal(result.status, 0, result.stderr); |
| 55 | + assert.equal(readFileSync(argvOut, 'utf8'), 'mcp\ninstall\ncodex\n--print\n'); |
| 56 | + } finally { |
| 57 | + rmSync(tmp, { recursive: true, force: true }); |
| 58 | + } |
| 59 | +}); |
| 60 | + |
| 61 | +test('install.sh rejects a shadowed od binary even when its help exits successfully', () => { |
| 62 | + const tmp = mkdtempSync(join(tmpdir(), 'od-install-sh-shadow-success-')); |
| 63 | + const argvOut = join(tmp, 'argv.txt'); |
| 64 | + const fakeOd = join(tmp, 'od'); |
| 65 | + writeFileSync( |
| 66 | + fakeOd, |
| 67 | + `#!/bin/sh |
| 68 | +if [ "$3" = "--help" ]; then |
| 69 | + printf '%s\\n' 'Usage: od [OPTION]... [FILE]...' |
| 70 | + exit 0 |
| 71 | +fi |
| 72 | +if [ "$3" = "--open-design-cli-probe" ]; then |
| 73 | + printf '%s\\n' 'Usage: od [OPTION]... [FILE]...' |
| 74 | + exit 0 |
| 75 | +fi |
| 76 | +printf '%s\\n' "$@" > "${argvOut}" |
| 77 | +exit 0 |
| 78 | +`, |
| 79 | + 'utf8', |
| 80 | + ); |
| 81 | + chmodSync(fakeOd, 0o755); |
| 82 | + |
| 83 | + try { |
| 84 | + const result = runInstall(['cursor'], tmp); |
| 85 | + |
| 86 | + assert.equal(result.status, 1); |
| 87 | + assert.match(result.stderr, /does not look like the Open Design CLI/); |
| 88 | + assert.throws(() => readFileSync(argvOut, 'utf8'), /ENOENT/); |
| 89 | + } finally { |
| 90 | + rmSync(tmp, { recursive: true, force: true }); |
| 91 | + } |
| 92 | +}); |
| 93 | + |
| 94 | +test('install.sh rejects a non-Open-Design od binary instead of calling coreutils od', () => { |
| 95 | + const tmp = mkdtempSync(join(tmpdir(), 'od-install-sh-shadow-')); |
| 96 | + const fakeOd = join(tmp, 'od'); |
| 97 | + writeFileSync( |
| 98 | + fakeOd, |
| 99 | + `#!/bin/sh |
| 100 | +exit 1 |
| 101 | +`, |
| 102 | + 'utf8', |
| 103 | + ); |
| 104 | + chmodSync(fakeOd, 0o755); |
| 105 | + |
| 106 | + try { |
| 107 | + const result = runInstall(['cursor'], tmp); |
| 108 | + |
| 109 | + assert.equal(result.status, 1); |
| 110 | + assert.match(result.stderr, /does not look like the Open Design CLI/); |
| 111 | + } finally { |
| 112 | + rmSync(tmp, { recursive: true, force: true }); |
| 113 | + } |
| 114 | +}); |
0 commit comments