36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { mkdtemp, readFile, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { resolve } from "node:path";
|
|
import { parseEnvFile, writeEnvFileUpdates } from "../src/ui/env-store.js";
|
|
|
|
test("parseEnvFile handles missing files", async () => {
|
|
const root = await mkdtemp(resolve(tmpdir(), "ai-ops-env-store-"));
|
|
const envPath = resolve(root, ".env");
|
|
|
|
const parsed = await parseEnvFile(envPath);
|
|
assert.deepEqual(parsed.values, {});
|
|
assert.deepEqual(parsed.lines, []);
|
|
});
|
|
|
|
test("writeEnvFileUpdates merges and appends keys", async () => {
|
|
const root = await mkdtemp(resolve(tmpdir(), "ai-ops-env-store-"));
|
|
const envPath = resolve(root, ".env");
|
|
|
|
await writeFile(envPath, "FOO=bar\nAGENT_MAX_CONCURRENT=4\n", "utf8");
|
|
|
|
const updated = await writeEnvFileUpdates(envPath, {
|
|
AGENT_MAX_CONCURRENT: "9",
|
|
AGENT_RUNTIME_DISCORD_MIN_SEVERITY: "warning",
|
|
});
|
|
|
|
assert.equal(updated.values.FOO, "bar");
|
|
assert.equal(updated.values.AGENT_MAX_CONCURRENT, "9");
|
|
assert.equal(updated.values.AGENT_RUNTIME_DISCORD_MIN_SEVERITY, "warning");
|
|
|
|
const rendered = await readFile(envPath, "utf8");
|
|
assert.match(rendered, /AGENT_MAX_CONCURRENT=9/);
|
|
assert.match(rendered, /AGENT_RUNTIME_DISCORD_MIN_SEVERITY=warning/);
|
|
});
|