import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { generateEd25519, generateX25519, signJob } from "@crosscode/contracts/signing"; import type { AgentConfig } from "../src/config"; export const hubKeys = generateEd25519(); export const serverKeys = { ed25519: generateEd25519(), x25519: generateX25519() }; export const config: AgentConfig = { hubUrl: "https://hub.test", serverId: "srv_test00001", mode: "church", hubJobKey: hubKeys.publicKey, pollSeconds: 30, statsSeconds: 60, joinedAt: "2026-11-20T00:00:00.000Z", }; export const NOW = new Date("2026-11-20T12:05:00.000Z"); let n = 0; export function job(over: Record = {}, key = hubKeys.privateKeyPem) { n++; return signJob({ schema: "crosscode.agent-job/1", id: `job_test${String(n).padStart(6, "0")}`, serverId: config.serverId, type: "deploy", args: { church: "hope", products: ["events"], versions: ["events@2.4.1"] }, config: null, notBefore: "2026-11-20T12:00:00.000Z", expiresAt: "2026-11-20T12:15:00.000Z", ...over, }, key); } /** A temporary state folder per test file. */ export function tempState(): string { const dir = fs.mkdtempSync(path.join(os.tmpdir(), "agent-test-")); process.env.CROSSCODE_AGENT_STATE_DIR = dir; process.env.CROSSCODE_AGENT_RUN_DIR = path.join(dir, "run"); return dir; }