clawdie-ai/setup/platform.test.ts
Sam & Claude 11fbc7f3e0 refactor(phase-2.1): AGENT_NAME namespace — jail-config + platform + jails step
- src/jail-config.ts: full rewrite — drop WARDEN_*/controlplane, introduce
  AGENT_BRIDGE_NAME=clawdie0, AGENT_JAIL_PROFILES, AGENT_SUBNET_*, AGENT_GATEWAY_IP,
  getWorkerBastillePlan(), getDefaultJailConfigForProfile(); all jail names
  derive from process.env.AGENT_NAME (default: clawdie)
- src/jail-config.test.ts: rewrite tests to match new AGENT_* API
- setup/jails.ts: new step replacing jail.ts; creates {AGENT_NAME}-worker jail
  via Bastille using shared clawdie0 bridge
- setup/jail.ts: deleted (replaced by jails.ts)
- setup/index.ts: replace 'jail' step with 'jails', add 'pi-config',
  remove 'network'/'setup-wizard'/'telegram-auth' steps
- setup/platform.ts: add isDesktop() and hasBrowser()
- setup/platform.test.ts: add tests for new functions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 13:47:22 +00:00

107 lines
2.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import {
getPlatform,
isRoot,
isHeadless,
isDesktop,
hasBrowser,
getServiceManager,
commandExists,
getNodeVersion,
getNodeMajorVersion,
} from './platform.js';
// --- getPlatform ---
describe('getPlatform', () => {
it('returns a valid platform string', () => {
const result = getPlatform();
expect(['freebsd', 'unknown']).toContain(result);
});
});
// --- isRoot ---
describe('isRoot', () => {
it('returns a boolean', () => {
expect(typeof isRoot()).toBe('boolean');
});
});
// --- isHeadless ---
describe('isHeadless', () => {
it('returns a boolean', () => {
expect(typeof isHeadless()).toBe('boolean');
});
});
describe('getServiceManager', () => {
it('returns a valid service manager', () => {
const result = getServiceManager();
expect(['freebsd-rc', 'none']).toContain(result);
});
it('matches the detected platform', () => {
const platform = getPlatform();
const result = getServiceManager();
if (platform === 'freebsd') {
expect(result).toBe('freebsd-rc');
} else {
expect(result).toBe('none');
}
});
});
// --- commandExists ---
describe('commandExists', () => {
it('returns true for node', () => {
expect(commandExists('node')).toBe(true);
});
it('returns false for nonexistent command', () => {
expect(commandExists('this_command_does_not_exist_xyz_123')).toBe(false);
});
});
// --- getNodeVersion ---
describe('getNodeVersion', () => {
it('returns a version string', () => {
const version = getNodeVersion();
expect(version).not.toBeNull();
expect(version).toMatch(/^\d+\.\d+\.\d+/);
});
});
// --- getNodeMajorVersion ---
describe('getNodeMajorVersion', () => {
it('returns at least 20', () => {
const major = getNodeMajorVersion();
expect(major).not.toBeNull();
expect(major!).toBeGreaterThanOrEqual(20);
});
});
// --- isDesktop ---
describe('isDesktop', () => {
it('returns a boolean', () => {
expect(typeof isDesktop()).toBe('boolean');
});
it('is inverse of isHeadless', () => {
expect(isDesktop()).toBe(!isHeadless());
});
});
// --- hasBrowser ---
describe('hasBrowser', () => {
it('returns a boolean', () => {
expect(typeof hasBrowser()).toBe('boolean');
});
});