Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260/** Tests for OS specification parsing and container command building. @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { buildContainerCommand, parseOs,} from './container.ts';
await describe({ name: 'container', children: [ //region parseOs
describe({ name: parseOs.name, children: [ it({ name: 'parses container:ubuntu', fn: async () => { const result = parseOs('container:ubuntu',); expect(result.protocol,).toBe('container',); expect(result.distro,).toBe('ubuntu',); }, },),
it({ name: 'parses container:fedora:39 preserving tag in distro', fn: async () => { const result = parseOs('container:fedora:39',); expect(result.protocol,).toBe('container',); expect(result.distro,).toBe('fedora:39',); }, },),
it({ name: 'parses host: with empty distro', fn: async () => { const result = parseOs('host:',); expect(result.protocol,).toBe('host',); expect(result.distro,).toBe('',); }, },),
it({ name: 'parses vm: protocol', fn: async () => { const result = parseOs('vm:fedora',); expect(result.protocol,).toBe('vm',); expect(result.distro,).toBe('fedora',); }, },),
it({ name: 'throws on missing protocol prefix', fn: async () => { expect(function noProtocol() { parseOs('ubuntu',); },) .toThrow('must have a protocol prefix',); }, },),
it({ name: 'throws on unknown protocol', fn: async () => { expect(function unknownProtocol() { parseOs('docker:ubuntu',); },) .toThrow('Unknown protocol "docker"',); }, },), ], },),
//endregion parseOs
//region buildContainerCommand
describe({ name: buildContainerCommand.name, children: [ it({ name: 'root user builds a direct command chain', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/home/user/Mono/packages/foo/test.ts', os: 'container:ubuntu', user: 'root', runtime: 'bun', }, monorepoRoot: '/home/user/Mono', },);
/** Should be a && chain without sudo -u or heredoc. */ expect(cmd,).toContain('apt-get',); expect(cmd,).toContain('curl',); expect(cmd,).toContain('.bun/bin/bun',); expect(cmd,).toContain('/workspace/packages/foo/test.ts',); expect(cmd,).not.toContain('sudo -u',); expect(cmd,).not.toContain('run-test.sh',); }, },),
it({ name: 'non-root user writes heredoc script and uses sudo -u', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/home/user/Mono/packages/foo/test.ts', os: 'container:ubuntu', user: 'user', runtime: 'bun', }, monorepoRoot: '/home/user/Mono', },);
expect(cmd,).toContain('sudo -u testuser',); expect(cmd,).toContain('run-test.sh',); expect(cmd,).toContain('useradd',); expect(cmd,).toContain('NOPASSWD',); }, },),
it({ name: 'converts host path to /workspace container path', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/repo/root/packages/bar/src/test.ts', os: 'container:fedora', user: 'root', runtime: 'bun', }, monorepoRoot: '/repo/root', },);
expect(cmd,).toContain('/workspace/packages/bar/src/test.ts',); expect(cmd,).not.toContain('/repo/root',); }, },),
it({ name: 'uses dnf for fedora', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/repo/test.ts', os: 'container:fedora', user: 'root', runtime: 'bun', }, monorepoRoot: '/repo', },);
expect(cmd,).toContain('dnf install',); }, },),
it({ name: 'uses apk for alpine', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/repo/test.ts', os: 'container:alpine', user: 'root', runtime: 'deno', }, monorepoRoot: '/repo', },);
expect(cmd,).toContain('apk add',); expect(cmd,).toContain('.deno/bin/deno',); }, },),
it({ name: 'alpine non-root uses adduser -D instead of useradd', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/repo/test.ts', os: 'container:alpine', user: 'user', runtime: 'bun', }, monorepoRoot: '/repo', },);
expect(cmd,).toContain('adduser -D testuser',); expect(cmd,).not.toContain('useradd',); }, },),
it({ name: 'deno exec includes --allow-all flag', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/repo/test.ts', os: 'container:ubuntu', user: 'root', runtime: 'deno', }, monorepoRoot: '/repo', },);
expect(cmd,).toContain('--allow-all',); }, },),
it({ name: 'non-root heredoc includes cd /workspace', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/repo/test.ts', os: 'container:ubuntu', user: 'user', runtime: 'bun', }, monorepoRoot: '/repo', },);
expect(cmd,).toContain('cd /workspace',); }, },),
it({ name: 'root command includes cd /workspace', fn: async () => { const cmd = buildContainerCommand({ combination: { file: '/repo/test.ts', os: 'container:ubuntu', user: 'root', runtime: 'bun', }, monorepoRoot: '/repo', },);
expect(cmd,).toContain('cd /workspace',); }, },), ], },), //endregion buildContainerCommand ],},);