Rework as scripts-centric, upload-only, gated beta lifecycle

Scripts become first-class: named, versioned, uploaded via the UI, optionally
scoped to a game or map. Any change that would land on scope-matched servers
(marking-required or new version of a scoped script) must first pass a beta.
The beta runs a per-server state machine — deploy -beta.gsc → wait empty →
Komodo restart → wait healthy → optionally wait for a real match end
(games_sp.log 'ExitLevel: executed') — before it's eligible for promotion.
Rollback is always available and restores from .OLD.

The shared/scripts mirror and its betas/ staging folder are gone. Every
server now has a tracked script inventory (server_scripts table), populated
only by explicit upload flows.

New: /scripts, /scripts/[id], /betas/[id] UI; /api/scripts + /api/betas +
/api/servers/[name]/scripts endpoints; scripts.ts, inventory.ts, beta.ts
(rewritten), beta-runner.ts, match-log.ts, komodoInspectHealthy().
Removed: push.ts, /api/push, BetaPanel, legacy importer.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-09-12 13:25:06 -04:00
co-authored by Claude Opus 4.7
parent 47051dc79a
commit 93d5a8e2e5
52 changed files with 2605 additions and 1689 deletions
+83
View File
@@ -0,0 +1,83 @@
import { json } from '@sveltejs/kit';
import {
createScript,
listScripts,
listVersions,
serversMatchingScope,
ScriptError,
type ScopeType
} from '$lib/server/fleet/scripts.js';
import { findRunningBetaForScript } from '$lib/server/fleet/beta.js';
function scopeTypeOrNull(v: FormDataEntryValue | null): ScopeType | null {
if (v === null) return null;
const s = String(v);
if (s === '' || s === 'none') return null;
if (s === 'game' || s === 'map') return s;
throw new ScriptError(`invalid scope_type: ${s}`, 'invalid-scope');
}
export async function GET() {
const scripts = listScripts().map((s) => {
const versions = listVersions(s.id);
const matched = s.scope_type && s.scope_value
? serversMatchingScope(s.scope_type as ScopeType, s.scope_value)
: [];
const runningBeta = findRunningBetaForScript(s.id);
return {
...s,
latestVersion: versions[0]
? {
id: versions[0].id,
version: versions[0].version,
sha256: versions[0].sha256,
size: versions[0].size,
uploaded_at: versions[0].uploaded_at
}
: null,
versionCount: versions.length,
servers: matched,
runningBetaId: runningBeta?.id ?? null
};
});
return json({ scripts });
}
// Multipart POST — creates a script + version 1 from a single file upload.
// Fields: name (text), targetRelPath (text), scopeType (optional: 'game'|'map'),
// scopeValue (optional string), notes (optional), content (file).
export async function POST({ request }: { request: Request }) {
const form = await request.formData();
const name = String(form.get('name') ?? '').trim();
const targetRelPath = String(form.get('targetRelPath') ?? '').trim();
const notes = form.get('notes') ? String(form.get('notes')) : undefined;
let scopeType: ScopeType | null;
try {
scopeType = scopeTypeOrNull(form.get('scopeType'));
} catch (err) {
return json({ ok: false, error: (err as Error).message }, { status: 400 });
}
const scopeValueRaw = form.get('scopeValue');
const scopeValue = scopeValueRaw ? String(scopeValueRaw).trim() : null;
const file = form.get('content');
if (!(file instanceof File)) return json({ ok: false, error: 'content file is required' }, { status: 400 });
const content = Buffer.from(await file.arrayBuffer());
try {
const { script, version } = createScript({
name,
targetRelPath,
scopeType,
scopeValue,
content,
notes
});
return json({ ok: true, script, versionId: version.id });
} catch (err) {
if (err instanceof ScriptError) {
return json({ ok: false, error: err.message, kind: err.kind }, { status: 409 });
}
throw err;
}
}