Ports push_scripts.sh (1497 lines of bash) to a SvelteKit + SQLite web app that manages a fleet of T5 Plutonium servers running on Komodo. Same push and beta workflow as the shell script, with a live SSE pipeline view, a !rt-token-gated auth modal that hard-pauses deployments on stale tokens, per-file audit diffs, and a Komodo-container deployment target. - Push/beta engines port the exact filter, held-by-beta, conflict, and stale-backup rules from the shell script - SQLite (better-sqlite3) replaces script_metadata.json; a one-shot importer moves legacy state over on first boot - 16 vitest tests cover push add/update/skip, beta open→rollback, open→promote, conflict guards, sweep frozen/manual branches, and IW4M login/status parsing - docker/ + komodo/stack.toml deploy as a managed container on the same host as the game servers, /root/zombies bind-mounted at the same path the shell script used
96 lines
4.2 KiB
TypeScript
96 lines
4.2 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
import { existsSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { newFixture, type Fixture } from '../helpers/fixture.js';
|
|
|
|
let fixture: Fixture;
|
|
|
|
beforeEach(async () => {
|
|
vi.resetModules();
|
|
fixture = await newFixture(
|
|
{ 'hud.gsc': 'v1', 'zom.gsc': 'v1' },
|
|
['t5_kino_1', 't5_ascension_1']
|
|
);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await fixture.cleanup();
|
|
});
|
|
|
|
describe('beta lifecycle', () => {
|
|
it('open → rollback restores original state', async () => {
|
|
const { doPush } = await import('../../src/lib/server/fleet/push.js');
|
|
const { openBeta, rollbackBeta } = await import('../../src/lib/server/fleet/beta.js');
|
|
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
|
|
await seedServerRegistry();
|
|
|
|
// Populate servers with v1 first
|
|
await doPush({ patterns: ['*'] });
|
|
|
|
// Stage a new hud
|
|
await writeFile(join(fixture.staging, 'hud.gsc'), 'v2');
|
|
|
|
// Open beta on t5_kino_1 only
|
|
const opened = await openBeta({ name: 'test1', patterns: ['t5_kino_1'] });
|
|
expect(opened.slug).toBe('test1');
|
|
expect(opened.servers).toEqual(['t5_kino_1']);
|
|
|
|
// On kino: hud-beta.gsc = v2, hud.OLD = v1, hud.gsc gone
|
|
const kinoSp = join(fixture.t5, 't5_kino_1', 'runtime/plutonium/storage/t5/raw/scripts/sp');
|
|
expect(await readFile(join(kinoSp, 'hud-beta.gsc'), 'utf8')).toBe('v2');
|
|
expect(await readFile(join(kinoSp, 'hud.OLD'), 'utf8')).toBe('v1');
|
|
expect(existsSync(join(kinoSp, 'hud.gsc'))).toBe(false);
|
|
|
|
// ascension untouched
|
|
const ascSp = join(fixture.t5, 't5_ascension_1', 'runtime/plutonium/storage/t5/raw/scripts/sp');
|
|
expect(await readFile(join(ascSp, 'hud.gsc'), 'utf8')).toBe('v1');
|
|
|
|
// Rollback
|
|
const back = await rollbackBeta('test1');
|
|
expect(back.restored).toContain('hud.gsc');
|
|
expect(await readFile(join(kinoSp, 'hud.gsc'), 'utf8')).toBe('v1');
|
|
expect(existsSync(join(kinoSp, 'hud-beta.gsc'))).toBe(false);
|
|
expect(existsSync(join(kinoSp, 'hud.OLD'))).toBe(false);
|
|
});
|
|
|
|
it('open → promote lands the beta on shared/scripts and clears beta files', async () => {
|
|
const { doPush } = await import('../../src/lib/server/fleet/push.js');
|
|
const { openBeta, promoteBeta } = await import('../../src/lib/server/fleet/beta.js');
|
|
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
|
|
await seedServerRegistry();
|
|
|
|
await doPush({ patterns: ['*'] });
|
|
await writeFile(join(fixture.staging, 'hud.gsc'), 'v2');
|
|
await openBeta({ name: 'promote-me', patterns: ['t5_kino_1'] });
|
|
|
|
const kinoSp = join(fixture.t5, 't5_kino_1', 'runtime/plutonium/storage/t5/raw/scripts/sp');
|
|
expect(existsSync(join(kinoSp, 'hud-beta.gsc'))).toBe(true);
|
|
|
|
await promoteBeta('promote-me');
|
|
|
|
// shared has v2 now
|
|
expect(await readFile(join(fixture.shared, 'hud.gsc'), 'utf8')).toBe('v2');
|
|
// kino has plain hud.gsc = v2, no OLD, no -beta
|
|
expect(await readFile(join(kinoSp, 'hud.gsc'), 'utf8')).toBe('v2');
|
|
expect(existsSync(join(kinoSp, 'hud-beta.gsc'))).toBe(false);
|
|
expect(existsSync(join(kinoSp, 'hud.OLD'))).toBe(false);
|
|
});
|
|
|
|
it('refuses to open a beta whose staged file matches an already-owned target', async () => {
|
|
const { doPush } = await import('../../src/lib/server/fleet/push.js');
|
|
const { openBeta, BetaError } = await import('../../src/lib/server/fleet/beta.js');
|
|
const { seedServerRegistry } = await import('../../src/lib/server/fleet/servers.js');
|
|
await seedServerRegistry();
|
|
await doPush({ patterns: ['*'] });
|
|
|
|
// First beta claims hud on kino
|
|
await writeFile(join(fixture.staging, 'hud.gsc'), 'v2');
|
|
await openBeta({ name: 'first', patterns: ['t5_kino_1'] });
|
|
|
|
// Second attempt on kino should conflict
|
|
await writeFile(join(fixture.staging, 'hud.gsc'), 'v3');
|
|
await expect(openBeta({ name: 'second', patterns: ['t5_kino_1'] })).rejects.toThrow(BetaError);
|
|
});
|
|
});
|