Sweep active code, tests, identity files, public docs, CMS seed content, and stale handoffs so old assistant-name fixtures no longer leak into current Clawdie/system-namespace behavior. Keep the skills-memory SQL artifact unchanged per regeneration policy. --- Build: pass Tests: pass — 2197 passed (164 files) --- Build: pass | Tests: pass — 2197 passed (650 files)
142 lines
3.8 KiB
TypeScript
142 lines
3.8 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
|
|
import {
|
|
SYSTEM_ENV_SCHEMA_VERSION,
|
|
loadSystemEnv,
|
|
resolveSystemEnv,
|
|
} from './system-env.js';
|
|
|
|
function makeProjectRoot(): string {
|
|
const base = path.join(process.cwd(), 'tmp', 'tests');
|
|
fs.mkdirSync(base, { recursive: true });
|
|
return fs.mkdtempSync(path.join(base, 'clawdie-system-env-'));
|
|
}
|
|
|
|
function removeDir(dirPath: string): void {
|
|
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
}
|
|
|
|
describe('system env', () => {
|
|
const roots: string[] = [];
|
|
|
|
afterEach(() => {
|
|
while (roots.length > 0) {
|
|
removeDir(roots.pop()!);
|
|
}
|
|
});
|
|
|
|
it('loads blank defaults when system.env is absent', () => {
|
|
const root = makeProjectRoot();
|
|
roots.push(root);
|
|
|
|
expect(loadSystemEnv(root)).toEqual({
|
|
systemSchemaVersion: SYSTEM_ENV_SCHEMA_VERSION,
|
|
networkExternalIf: null,
|
|
networkInternalIf: null,
|
|
tailscaleIf: null,
|
|
zfsPool: null,
|
|
zfsLayout: null,
|
|
zfsDataDisks: null,
|
|
zfsHotSpares: null,
|
|
zfsDisks: [],
|
|
zfsSpareDisks: [],
|
|
zfsPrefix: null,
|
|
gpuDevice: null,
|
|
sndDevice: null,
|
|
});
|
|
});
|
|
|
|
it('parses explicit system.env values', () => {
|
|
const root = makeProjectRoot();
|
|
roots.push(root);
|
|
fs.writeFileSync(
|
|
path.join(root, 'system.env'),
|
|
[
|
|
'SYSTEM_SCHEMA_VERSION=1',
|
|
'NETWORK_EXTERNAL_IF=em0',
|
|
'NETWORK_INTERNAL_IF=warden0',
|
|
'TAILSCALE_IF=tailscale0',
|
|
'ZFS_POOL=tank',
|
|
'ZFS_LAYOUT=raidz1',
|
|
'ZFS_DATA_DISKS=3',
|
|
'ZFS_HOT_SPARES=1',
|
|
'ZFS_DISKS=ada0,ada1,ada2',
|
|
'ZFS_SPARE_DISKS=ada3',
|
|
'ZFS_PREFIX=alpha data',
|
|
'GPU_DEVICE=drm0',
|
|
'SND_DEVICE=pcm0',
|
|
'',
|
|
].join('\n'),
|
|
);
|
|
|
|
expect(loadSystemEnv(root)).toEqual({
|
|
systemSchemaVersion: 1,
|
|
networkExternalIf: 'em0',
|
|
networkInternalIf: 'warden0',
|
|
tailscaleIf: 'tailscale0',
|
|
zfsPool: 'tank',
|
|
zfsLayout: 'raidz1',
|
|
zfsDataDisks: 3,
|
|
zfsHotSpares: 1,
|
|
zfsDisks: ['ada0', 'ada1', 'ada2'],
|
|
zfsSpareDisks: ['ada3'],
|
|
zfsPrefix: 'alpha-data',
|
|
gpuDevice: 'drm0',
|
|
sndDevice: 'pcm0',
|
|
});
|
|
});
|
|
|
|
it('rejects unsupported system.env schema versions', () => {
|
|
const root = makeProjectRoot();
|
|
roots.push(root);
|
|
fs.writeFileSync(
|
|
path.join(root, 'system.env'),
|
|
['SYSTEM_SCHEMA_VERSION=2', ''].join('\n'),
|
|
);
|
|
|
|
expect(() => loadSystemEnv(root)).toThrow(/SYSTEM_SCHEMA_VERSION=2/);
|
|
});
|
|
|
|
it('resolves autodetected values only for blanks', () => {
|
|
const root = makeProjectRoot();
|
|
roots.push(root);
|
|
fs.writeFileSync(
|
|
path.join(root, 'system.env'),
|
|
[
|
|
'NETWORK_EXTERNAL_IF=',
|
|
'NETWORK_INTERNAL_IF=bridge2',
|
|
'GPU_DEVICE=',
|
|
'',
|
|
].join('\n'),
|
|
);
|
|
|
|
const resolved = resolveSystemEnv(root, {
|
|
commandExists: (name) => name === 'route' || name === 'ifconfig',
|
|
existsSync: (filePath) =>
|
|
filePath === '/dev/drm0' ||
|
|
filePath === '/dev/pcm0' ||
|
|
fs.existsSync(filePath),
|
|
execFileSync: ((cmd: string, args: string[]) => {
|
|
if (cmd === 'route') return 'interface: vtnet0\n';
|
|
if (cmd === 'ifconfig') return 'lo0 warden0 tailscale0';
|
|
throw new Error(`unexpected command ${cmd} ${args.join(' ')}`);
|
|
}) as typeof import('child_process').execFileSync,
|
|
});
|
|
|
|
expect(resolved.networkExternalIf).toBe('vtnet0');
|
|
expect(resolved.networkInternalIf).toBe('bridge2');
|
|
expect(resolved.tailscaleIf).toBe('tailscale0');
|
|
expect(resolved.gpuDevice).toBe('drm0');
|
|
expect(resolved.sndDevice).toBe('pcm0');
|
|
expect(resolved.detected).toEqual({
|
|
networkExternalIf: true,
|
|
networkInternalIf: false,
|
|
tailscaleIf: true,
|
|
gpuDevice: true,
|
|
sndDevice: true,
|
|
});
|
|
});
|
|
});
|