Files
PaperClipAI/tests/runner-e2e/server-config.ts
T
DottaandPaperclip bb118e2fd0 test(history): qualify indexed continuation with stock Codex
Part 6 of the opt-in indexed history draft series. Validated at the integrated tip; activation remains disabled by default.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-09-29 16:20:50 -05:00

74 lines
2.5 KiB
TypeScript

import { prepareDockerTestDatabase } from "./docker-database.js";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { paperclipConfigSchema } from "../../packages/shared/src/config-schema.js";
import { reserveRunnerE2EDatabasePort } from "./ports.js";
/** Seed only the disposable fixture. Onboarding preserves this validated config
* and still creates the normal secrets and database. Restarts keep the same DB.
*/
export async function prepareRunnerE2EServerConfig(input: {
temporaryRoot: string;
configPath: string;
serverPort: number;
}) {
try {
await readFile(input.configPath, "utf8");
return null;
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
}
const useDocker = process.env.PAPERCLIP_RUNNER_E2E_DATABASE === "docker";
const databaseReservation = useDocker ? null : await reserveRunnerE2EDatabasePort(input.serverPort);
const dockerConnection = useDocker ? await prepareDockerTestDatabase(input.temporaryRoot) : null;
try {
const instanceRoot = path.dirname(input.configPath);
const config = paperclipConfigSchema.parse({
$meta: {
version: 1,
updatedAt: new Date().toISOString(),
source: "onboard",
},
database: {
mode: useDocker ? "postgres" : "embedded-postgres",
...(dockerConnection ? { connectionString: dockerConnection } : {}),
embeddedPostgresDataDir: path.join(instanceRoot, "db"),
embeddedPostgresPort: databaseReservation?.port ?? 54329,
backup: {
enabled: false,
dir: path.join(input.temporaryRoot, "backups"),
},
},
logging: { mode: "file", logDir: path.join(instanceRoot, "logs") },
server: {
deploymentMode: "local_trusted",
exposure: "private",
bind: "loopback",
host: "127.0.0.1",
port: input.serverPort,
serveUi: true,
},
storage: {
provider: "local_disk",
localDisk: { baseDir: path.join(input.temporaryRoot, "storage") },
},
secrets: {
provider: "local_encrypted",
strictMode: true,
localEncrypted: {
keyFilePath: path.join(instanceRoot, "secrets", "master.key"),
},
},
});
await mkdir(instanceRoot, { recursive: true, mode: 0o700 });
await writeFile(input.configPath, `${JSON.stringify(config, null, 2)}\n`, {
flag: "wx",
mode: 0o600,
});
return databaseReservation;
} catch (error) {
await databaseReservation?.close();
throw error;
}
}