forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-guards-edge-cases.test.ts
More file actions
60 lines (53 loc) · 1.92 KB
/
Copy pathruntime-guards-edge-cases.test.ts
File metadata and controls
60 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { describe, it, expect } from "vitest";
import { assertNonEmptyValue } from "../../src/guards/runtime-guards.js";
import { RuntimeError } from "../../src/errors/runtime-errors.js";
describe("assertNonEmptyValue edge cases (Issue #152)", () => {
it("rejects whitespace-only string with INVALID_TASK", () => {
try {
assertNonEmptyValue(" \t\n ", "field");
expect.fail("should have thrown");
} catch (e) {
const err = e as RuntimeError;
expect(err.code).toBe("INVALID_TASK");
expect(err.details?.fieldName).toBe("field");
}
});
it("accepts string with leading/trailing whitespace but non-empty content", () => {
expect(() => assertNonEmptyValue(" valid ", "field")).not.toThrow();
});
it("uses default INVALID_TASK code when not overridden", () => {
try {
assertNonEmptyValue("", "taskId");
expect.fail("should have thrown");
} catch (e) {
const err = e as RuntimeError;
expect(err.code).toBe("INVALID_TASK");
}
});
it("respects overridden EXECUTION_FAILED code", () => {
try {
assertNonEmptyValue("", "taskRef", "EXECUTION_FAILED");
expect.fail("should have thrown");
} catch (e) {
const err = e as RuntimeError;
expect(err.code).toBe("EXECUTION_FAILED");
expect(err.details?.fieldName).toBe("taskRef");
}
});
it("includes fieldName in details matching input parameter", () => {
try {
assertNonEmptyValue("\n\r\t", "customField");
expect.fail("should have thrown");
} catch (e) {
const err = e as RuntimeError;
expect(err.details?.fieldName).toBe("customField");
expect(err.message).toContain("customField");
}
});
it("rejects single space character", () => {
expect(() => assertNonEmptyValue(" ", "x")).toThrow(RuntimeError);
});
it("accepts single non-whitespace character", () => {
expect(() => assertNonEmptyValue("a", "x")).not.toThrow();
});
});