fix(runner): Dev-Neustart bei geänderten Variablen, Liveness-Prüfung, npm-ci-Fallback

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-09-30 21:54:01 +00:00
1 parent cd9a6e0cf1
commit 96c26fb9b8
8 files changed
+139 -10

No files matched your search

+54 -1
View File
@@ -5,7 +5,7 @@ import { createDev } from '../src/dev.js';
const MIN = 60e3;
const GB = 1024 ** 3;
function setup({ mem = 10 * GB, connect, detected, prep, rmImpl } = {}) {
function setup({ mem = 10 * GB, connect, detected, prep, rmImpl, alive } = {}) {
const config = { workRoot: '/w/work', cacheRoot: '/w/cache', baseHost: 'project.webklar.com', minFreeBytes: 1.5 * GB, devIdleMs: 20 * MIN, devMax: 3, devReadyMs: 180e3, giteaToken: 'tok_GEHEIM' };
const clock = { t: 1_000_000 };
const rmDirs = []; const runs = []; const removed = []; const held = new Map(); const prepared = [];
@@ -14,6 +14,7 @@ function setup({ mem = 10 * GB, connect, detected, prep, rmImpl } = {}) {
run: async (args, opts) => { if (args[0] === 'run') runs.push({ args, opts }); else opts?.onLine?.('container-log-zeile', 'out'); return { code: 0 }; },
rm: async (n) => { removed.push(n); if (rmImpl) await rmImpl(n); return { code: 0, lines: [] }; },
ps: async () => psResult,
...(alive ? { running: async (n) => alive(n) } : {}),
};
const jobs = {
prepareWorkspace: async (job, o) => { prepared.push({ job, o }); if (prep) return prep(job, o); o.onLine?.('npm install ok'); return { workDir: o.workDir, detected: detected ?? { pm: 'npm', devCmd: ['npm', 'run', 'dev', '--', '--host', '0.0.0.0', '--port', '5173'], devPort: 5173 } }; },
@@ -291,3 +292,55 @@ test('register: schlafender sub mit neuem sha startet nicht, wake nutzt das neue
assert.equal(s.runs.length, 2);
assert.equal(s.prepared[1].job.sha, '7654321');
});
test('I2: gleicher sha, geänderte Variablen ⇒ register/ensure starten neu', async () => {
const s = setup();
await s.dev.ensure('a', job('a')); await s.dev.idle();
assert.equal(s.runs.length, 1);
// gleiche Variablen (auch andere Reihenfolge): kein Neustart
assert.equal((await s.dev.register('a', job('a', { env: { API_KEY: 'geheim-wert' } }))).state, 'online');
assert.equal(s.runs.length, 1);
assert.equal((await s.dev.register('a', job('a', { env: { API_KEY: 'neuer-wert' } }))).state, 'starting');
await s.dev.idle();
assert.equal(s.runs.length, 2);
assert.ok(s.removed.includes('preview-dev-a'));
assert.equal(s.runs[1].opts.env.API_KEY, 'neuer-wert');
// Branch-Wechsel ebenfalls
await s.dev.ensure('a', job('a', { env: { API_KEY: 'neuer-wert' }, branch: 'dev' })); await s.dev.idle();
assert.equal(s.runs.length, 3);
});
test('I7: beendeter Container ⇒ sleeping, entfernt und per wake neu gestartet', async () => {
let up = true;
const s = setup({ alive: () => up });
await s.dev.wake('a').catch(() => {}); // unbekannt
await s.dev.register('a', job('a'));
await s.dev.wake('a'); await s.dev.idle();
assert.equal(s.runs.length, 1);
up = false;
s.clock.t += 11e3;
assert.deepEqual(await s.dev.wake('a'), { state: 'starting' });
await s.dev.idle();
assert.ok(s.removed.includes('preview-dev-a'));
assert.equal(s.runs.length, 2);
});
test('I7: Lebendigkeitsprüfung höchstens alle 10 s', async () => {
let checks = 0;
const s = setup({ alive: () => { checks++; return true; } });
await s.dev.ensure('a', job('a')); await s.dev.idle();
for (let i = 0; i < 5; i++) await s.dev.ensure('a', job('a'));
assert.equal(checks, 0);
s.clock.t += 11e3;
await s.dev.ensure('a', job('a')); await s.dev.ensure('a', job('a'));
assert.equal(checks, 1);
});
test('I7: markDead entfernt den Container und setzt sleeping', async () => {
const s = setup();
await s.dev.ensure('a', job('a')); await s.dev.idle();
await s.dev.markDead('a');
assert.ok(s.removed.includes('preview-dev-a'));
assert.equal(s.dev.list().find((e) => e.sub === 'a').state, 'sleeping');
assert.equal((await s.dev.wake('a')).state, 'starting');
});