Refactor local memory and role-fixed runtime routing

This commit is contained in:
Eyejoker
2026-04-04 03:50:28 +09:00
parent ca58e8c8eb
commit 3dd772c229
47 changed files with 6158 additions and 669 deletions

View File

@@ -18,8 +18,11 @@ vi.mock('./platform.js', () => ({
import {
checkLaunchdService,
checkLaunchdServiceArtifact,
checkNohupService,
checkNohupServiceArtifact,
checkSystemdService,
checkSystemdServiceInScope,
getServiceChecks,
} from './verify-services.js';
import type { ServiceDef } from './service-defs.js';
@@ -54,6 +57,43 @@ describe('verify service checks', () => {
});
});
it('checks systemd services in both explicit scopes', () => {
execSyncMock.mockImplementation((cmd: string) => {
if (cmd === 'systemctl is-active ejclaw-codex') {
return undefined;
}
if (cmd === 'systemctl --user is-active ejclaw-codex') {
throw new Error('inactive');
}
if (cmd === 'systemctl --user list-unit-files') {
return '';
}
throw new Error(`unexpected command: ${cmd}`);
});
expect(checkSystemdServiceInScope('ejclaw-codex', 'system')).toBe('running');
expect(checkSystemdServiceInScope('ejclaw-codex', 'user')).toBe('not_found');
});
it('treats an unloaded launchd plist as stopped when artifact detection is enabled', () => {
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-launchd-'));
const plistPath = path.join(
tempHome,
'Library',
'LaunchAgents',
'com.ejclaw-codex.plist',
);
fs.mkdirSync(path.dirname(plistPath), { recursive: true });
fs.writeFileSync(plistPath, '<plist />');
execSyncMock.mockReturnValue('');
expect(
checkLaunchdServiceArtifact('com.ejclaw-codex', plistPath),
).toBe('stopped');
fs.rmSync(tempHome, { recursive: true, force: true });
});
it('treats known but inactive systemd services as stopped', () => {
execSyncMock
.mockImplementationOnce(() => {
@@ -79,6 +119,15 @@ describe('verify service checks', () => {
fs.rmSync(tempRoot, { recursive: true, force: true });
});
it('treats a legacy nohup wrapper without a live pid as stopped when artifact detection is enabled', () => {
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-verify-'));
fs.writeFileSync(path.join(tempRoot, 'start-ejclaw-codex.sh'), '#!/bin/bash\n');
expect(checkNohupServiceArtifact(tempRoot, 'ejclaw-codex')).toBe('stopped');
fs.rmSync(tempRoot, { recursive: true, force: true });
});
it('builds per-service status checks from service definitions', () => {
const defs: ServiceDef[] = [
{
@@ -89,18 +138,18 @@ describe('verify service checks', () => {
logName: 'ejclaw',
},
{
kind: 'codex',
name: 'ejclaw-codex',
description: 'Codex',
launchdLabel: 'com.ejclaw.codex',
logName: 'ejclaw-codex',
kind: 'primary',
name: 'ejclaw-secondary',
description: 'Secondary',
launchdLabel: 'com.ejclaw.secondary',
logName: 'ejclaw-secondary',
},
];
execSyncMock.mockReturnValue('123\t0\tcom.ejclaw\n');
expect(getServiceChecks(defs, '/tmp/ejclaw', 'launchd')).toEqual([
{ name: 'ejclaw', status: 'running' },
{ name: 'ejclaw-codex', status: 'not_found' },
{ name: 'ejclaw-secondary', status: 'not_found' },
]);
});
});