36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { ZodError } from "zod";
|
|
|
|
import { parseExecutionContext, executionContextSchema } from "./execution-context-schema";
|
|
|
|
describe("parseExecutionContext", () => {
|
|
it("parses valid executionContext with diachron_root", () => {
|
|
const env = { diachron_root: "/some/path" };
|
|
const result = parseExecutionContext(env);
|
|
assert.deepEqual(result, { diachron_root: "/some/path" });
|
|
});
|
|
|
|
it("throws ZodError when diachron_root is missing", () => {
|
|
const env = {};
|
|
assert.throws(() => parseExecutionContext(env), ZodError);
|
|
});
|
|
|
|
it("strips extra fields not in schema", () => {
|
|
const env = {
|
|
diachron_root: "/some/path",
|
|
EXTRA_VAR: "should be stripped",
|
|
};
|
|
const result = parseExecutionContext(env);
|
|
assert.deepEqual(result, { diachron_root: "/some/path" });
|
|
assert.equal("EXTRA_VAR" in result, false);
|
|
});
|
|
});
|
|
|
|
describe("executionContextSchema", () => {
|
|
it("requires diachron_root to be a string", () => {
|
|
const result = executionContextSchema.safeParse({ diachron_root: 123 });
|
|
assert.equal(result.success, false);
|
|
});
|
|
});
|