Remove Komodo backend in favor of native hosts
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import * as fs from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { vi } from 'vitest';
|
||||
|
||||
/** Read-only agent transport backed by fixture files. Mutations still fail. */
|
||||
export async function mockAgentFiles() {
|
||||
const backend = await import('../../src/lib/server/backends/native.js');
|
||||
const { serverDir } = await import('../../src/lib/server/config.js');
|
||||
return vi.spyOn(backend, 'nativeRequest').mockImplementation(async (instance, kind, payload = {}) => {
|
||||
const path = join(serverDir(instance.server), String(payload.path ?? '.'));
|
||||
let result: unknown;
|
||||
if (kind === 'files.read') {
|
||||
const content = await fs.readFile(path).catch((error: NodeJS.ErrnoException) => { if (error.code === 'ENOENT') return null; throw error; });
|
||||
result = { contentBase64: content?.toString('base64') ?? null };
|
||||
} else if (kind === 'files.stat') {
|
||||
const stat = await fs.stat(path).catch((error: NodeJS.ErrnoException) => { if (error.code === 'ENOENT') return null; throw error; });
|
||||
result = stat ? { exists: true, size: stat.size, mtime: stat.mtime.toISOString(), isDirectory: stat.isDirectory(), isFile: stat.isFile() } : null;
|
||||
} else if (kind === 'files.list') {
|
||||
result = { entries: (await fs.readdir(path, { withFileTypes: true })).map(entry => ({ name: entry.name, isDirectory: entry.isDirectory(), isFile: entry.isFile() })) };
|
||||
} else throw new Error(`Unexpected agent command: ${kind}`);
|
||||
return result as never;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { createHash, randomUUID } from 'node:crypto';
|
||||
|
||||
/** Seed verified host inventory without copying a complete game distribution. */
|
||||
export async function prepareNativeHost(servers: string[] = []) {
|
||||
const { config } = await import('../../src/lib/server/config.js');
|
||||
const hosts = await import('../../src/lib/server/hosts/index.js');
|
||||
const libraries = await import('../../src/lib/server/game-files/index.js');
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const host = hosts.createHost({ name: 'Fixture host', portMin: 28960, portMax: 29060 });
|
||||
const inventory = { protocolVersion: 1, cpuCount: 64, cpuUsagePercent: 0,
|
||||
memoryTotal: 128 * 1024 ** 3, memoryAvailable: 120 * 1024 ** 3,
|
||||
dockerRunning: true, directoriesWritable: true, storageAvailable: 100_000_000_000,
|
||||
runtimeImages: [config.defaultRuntimeImage] };
|
||||
hosts.enrollHost(hosts.createEnrollment(host.id).token, inventory);
|
||||
const versions = new Map<string, string>();
|
||||
for (const game of ['t5', 't6'] as const) {
|
||||
const version = libraries.createLibraryImport({ hostId: host.id, game });
|
||||
const manifest = JSON.stringify([{ path: 'zone/base.ff', size: 4, sha256: createHash('sha256').update('game').digest('hex') }]);
|
||||
const hash = createHash('sha256').update(manifest).digest('hex');
|
||||
db().prepare("UPDATE game_file_versions SET state='ready',manifest=?,manifest_sha256=?,size_bytes=4,published_at=? WHERE id=?")
|
||||
.run(manifest, hash, new Date().toISOString(), version.id);
|
||||
libraries.updateHostLibraryCaches(host.id, [{ libraryVersionId: version.id, status: 'ready', manifestSha256: hash }]);
|
||||
versions.set(game, version.id);
|
||||
}
|
||||
const heartbeat = () => hosts.heartbeat(host.id, { ...inventory, libraries: [...versions.values()].map(id => ({ id, state: 'ready' as const })) });
|
||||
heartbeat();
|
||||
for (const [index, server] of servers.entries()) {
|
||||
db().prepare(`INSERT INTO native_instances(id,server,host_id,library_id,image,port,created_at)
|
||||
VALUES(?,?,?,?,?,?,?)`).run(randomUUID(), server, host.id, versions.get(server.startsWith('t6_') ? 't6' : 't5'),
|
||||
config.defaultRuntimeImage, 28960 + index, new Date().toISOString());
|
||||
}
|
||||
return { host, versions, heartbeat };
|
||||
}
|
||||
Reference in New Issue
Block a user