mirror of
https://github.com/mvschwarz/openrig.git
synced 2026-11-07 05:56:21 -10:00
Node test suites run inside an OpenRig seat no longer inherit that seat's instance. The daemon and TUI suites now use the same fixture-home and fetch-guard setup as the CLI suite (test/hermetic-env.setup.ts). OPENRIG_* and RIGGED_* instance selectors are cleared before product imports, so tests cannot reach the person's OpenRig home, database or daemon endpoint. Ordinary runs also redirect HOME and the XDG directories and clear CODEX_HOME. With OPENRIG_E2E_REAL_CODEX=1, the real HOME, CODEX_HOME and XDG directories are kept, so the opt-in real-Codex tests run as before. Explicit fixture overrides set after setup still apply. Test-only; no product code changes. Controls against disposable outer audit, SQLite and HTTP targets fail with the old setup and pass with the new one. Not covered: subprocess globals and hardcoded filesystem targets outside the fetch guard.
46 lines
2.1 KiB
TypeScript
46 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { tmpdir } from "node:os";
|
|
import { createDb } from "../src/db/connection.js";
|
|
import { ConfigStore } from "../../cli/src/config-store.js";
|
|
import { DaemonClient } from "../../cli/src/client.js";
|
|
|
|
describe("test instance environment", () => {
|
|
// scripts/test-instance-isolation.test.mjs supplies only a disposable outer
|
|
// home/database/HTTP server. Never run this discriminator against a real seat.
|
|
it.skipIf(!process.env.OPENRIG_TEST_OUTER_INSTANCE)("exercises default database and endpoint routing", async () => {
|
|
const file = new ConfigStore().resolve().db.path;
|
|
mkdirSync(dirname(file), { recursive: true });
|
|
const db = createDb(file);
|
|
try { db.exec("CREATE TABLE IF NOT EXISTS isolation_probe (value TEXT)"); }
|
|
finally { db.close(); }
|
|
try {
|
|
const response = await new DaemonClient().get("/api/test-isolation");
|
|
expect(response.status).toBe(200);
|
|
} catch (error) {
|
|
// The isolated default is not a fixture server; the existing fetch guard
|
|
// must reject it before any network request. The parent reaches the outer server.
|
|
expect(String(error)).toContain("FETCH GUARD");
|
|
}
|
|
});
|
|
|
|
it("preserves explicit fixture overrides made after setup", async () => {
|
|
const root = mkdtempSync(join(tmpdir(), "instance-override-"));
|
|
try {
|
|
vi.stubEnv("OPENRIG_HOME", root);
|
|
vi.stubEnv("OPENRIG_DB", join(root, "chosen.sqlite"));
|
|
vi.stubEnv("OPENRIG_URL", "http://fixture.invalid:12345");
|
|
expect(new ConfigStore().resolve().db.path).toBe(join(root, "chosen.sqlite"));
|
|
const fetchImpl = vi.fn(async () => new Response("{}", { status: 200 }));
|
|
const client = new DaemonClient(undefined, { fetchImpl });
|
|
expect(client.baseUrl).toBe("http://fixture.invalid:12345");
|
|
await client.get("/api/test-isolation");
|
|
expect(fetchImpl).toHaveBeenCalled();
|
|
} finally {
|
|
vi.unstubAllEnvs();
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|