feat: add devflow doctor cli
This commit is contained in:
74
packages/core/src/config.test.ts
Normal file
74
packages/core/src/config.test.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { mkdirSync, mkdtempSync, realpathSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { loadConfigFromSources } from "./config.js";
|
||||
|
||||
describe("config loader", () => {
|
||||
it("loads .env, .env.local, then process env in descending precedence", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "devflow-config-"));
|
||||
const workspace = join(root, "workspace");
|
||||
mkdirSync(workspace);
|
||||
writeFileSync(
|
||||
join(root, ".env"),
|
||||
[
|
||||
"DATABASE_URL=postgres://env:env@localhost:5432/env",
|
||||
"WORKSPACE_ROOT=workspace",
|
||||
"LOG_LEVEL=warn",
|
||||
].join("\n"),
|
||||
);
|
||||
writeFileSync(join(root, ".env.local"), "LOG_LEVEL=debug\n");
|
||||
|
||||
const config = loadConfigFromSources({
|
||||
cwd: root,
|
||||
env: {
|
||||
DATABASE_URL: "postgres://process:process@localhost:5432/process",
|
||||
},
|
||||
});
|
||||
|
||||
expect(config.DATABASE_URL).toBe("postgres://process:process@localhost:5432/process");
|
||||
expect(config.LOG_LEVEL).toBe("debug");
|
||||
expect(config.WORKSPACE_ROOT).toBe(realpathSync(workspace));
|
||||
});
|
||||
|
||||
it("always exposes the fake backend as enabled", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "devflow-config-"));
|
||||
const workspace = join(root, "workspace");
|
||||
mkdirSync(workspace);
|
||||
|
||||
const config = loadConfigFromSources({
|
||||
cwd: root,
|
||||
env: {
|
||||
DATABASE_URL: "postgres://devflow:devflow@localhost:5432/devflow",
|
||||
WORKSPACE_ROOT: workspace,
|
||||
LOG_LEVEL: "info",
|
||||
},
|
||||
});
|
||||
|
||||
expect(config.backends).toContainEqual({ id: "fake", enabled: true });
|
||||
});
|
||||
|
||||
it("parses backend registration from DEVFLOW_BACKENDS_JSON", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "devflow-config-"));
|
||||
const workspace = join(root, "workspace");
|
||||
mkdirSync(workspace);
|
||||
|
||||
const config = loadConfigFromSources({
|
||||
cwd: root,
|
||||
env: {
|
||||
DATABASE_URL: "postgres://devflow:devflow@localhost:5432/devflow",
|
||||
WORKSPACE_ROOT: workspace,
|
||||
LOG_LEVEL: "info",
|
||||
DEVFLOW_BACKENDS_JSON: JSON.stringify([
|
||||
{ id: "codex", enabled: true, binaryPath: "/usr/local/bin/codex" },
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
expect(config.backends).toEqual([
|
||||
{ id: "fake", enabled: true },
|
||||
{ id: "codex", enabled: true, binaryPath: "/usr/local/bin/codex" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user