|
| 1 | +import { execFileSync } from 'node:child_process'; |
| 2 | +import type { ExecFileSyncOptionsWithStringEncoding } from 'node:child_process'; |
| 3 | +import { chmodSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; |
| 4 | +import { tmpdir } from 'node:os'; |
| 5 | +import { join } from 'node:path'; |
| 6 | +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; |
| 7 | + |
| 8 | +const verifyScriptPath = join(process.cwd(), 'scripts', 'verify-portable-install.sh'); |
| 9 | +const execOptions = { |
| 10 | + encoding: 'utf8', |
| 11 | + stdio: 'pipe', |
| 12 | +} satisfies ExecFileSyncOptionsWithStringEncoding; |
| 13 | + |
| 14 | +function createExecutable(path: string) { |
| 15 | + writeFileSync(path, '#!/usr/bin/env bash\nexit 0\n'); |
| 16 | + chmodSync(path, 0o755); |
| 17 | +} |
| 18 | + |
| 19 | +function createPortableRoot(root: string) { |
| 20 | + mkdirSync(join(root, 'bin'), { recursive: true }); |
| 21 | + mkdirSync(join(root, 'libexec', 'manifests'), { recursive: true }); |
| 22 | + mkdirSync(join(root, 'libexec', 'bundled', 'Frameworks'), { recursive: true }); |
| 23 | + mkdirSync(join(root, 'libexec', 'skills'), { recursive: true }); |
| 24 | + mkdirSync(join(root, 'libexec', 'schemas', 'structured-output', '_defs'), { recursive: true }); |
| 25 | + mkdirSync( |
| 26 | + join(root, 'libexec', 'schemas', 'structured-output', 'xcodebuildmcp.output.session-defaults'), |
| 27 | + { recursive: true }, |
| 28 | + ); |
| 29 | + |
| 30 | + createExecutable(join(root, 'bin', 'xcodebuildmcp')); |
| 31 | + createExecutable(join(root, 'bin', 'xcodebuildmcp-doctor')); |
| 32 | + createExecutable(join(root, 'libexec', 'xcodebuildmcp')); |
| 33 | + createExecutable(join(root, 'libexec', 'node-runtime')); |
| 34 | + createExecutable(join(root, 'libexec', 'bundled', 'axe')); |
| 35 | + writeFileSync( |
| 36 | + join(root, 'libexec', 'schemas', 'structured-output', '_defs', 'common.schema.json'), |
| 37 | + '{}', |
| 38 | + ); |
| 39 | + writeFileSync( |
| 40 | + join( |
| 41 | + root, |
| 42 | + 'libexec', |
| 43 | + 'schemas', |
| 44 | + 'structured-output', |
| 45 | + 'xcodebuildmcp.output.session-defaults', |
| 46 | + '1.schema.json', |
| 47 | + ), |
| 48 | + '{}', |
| 49 | + ); |
| 50 | +} |
| 51 | + |
| 52 | +describe('verify-portable-install.sh', () => { |
| 53 | + let tempDir: string; |
| 54 | + |
| 55 | + beforeEach(() => { |
| 56 | + tempDir = join(tmpdir(), `xbmcp-portable-verify-${process.pid}-${Date.now()}`); |
| 57 | + mkdirSync(tempDir, { recursive: true }); |
| 58 | + }); |
| 59 | + |
| 60 | + afterEach(() => { |
| 61 | + rmSync(tempDir, { recursive: true, force: true }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('accepts a portable root containing structured output schemas', () => { |
| 65 | + const root = join(tempDir, 'portable-root'); |
| 66 | + createPortableRoot(root); |
| 67 | + |
| 68 | + expect(() => execFileSync(verifyScriptPath, ['--root', root], execOptions)).not.toThrow(); |
| 69 | + }); |
| 70 | + |
| 71 | + it('rejects a portable root missing structured output schemas', () => { |
| 72 | + const root = join(tempDir, 'portable-root'); |
| 73 | + createPortableRoot(root); |
| 74 | + rmSync(join(root, 'libexec', 'schemas'), { recursive: true, force: true }); |
| 75 | + |
| 76 | + try { |
| 77 | + execFileSync(verifyScriptPath, ['--root', root], execOptions); |
| 78 | + throw new Error('Expected verify-portable-install.sh to fail'); |
| 79 | + } catch (error) { |
| 80 | + expect(error).toMatchObject({ |
| 81 | + stdout: expect.stringContaining('Missing structured output common schema'), |
| 82 | + }); |
| 83 | + } |
| 84 | + }); |
| 85 | +}); |
0 commit comments