Skip to content
Source
Sign inSign up

schemaYaml.test.ts

48 lines1.4 KB

1import * as Schema from "effect/Schema";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { fromYaml } from "./schemaYaml.ts";
5​
6describe("schemaYaml helpers", () => {
7 it("reports malformed YAML with safe structural diagnostics", () => {
8 const decodeYaml = Schema.decodeUnknownSync(fromYaml(Schema.Unknown));
9 const secret = "credential=secret-value";
10 let error: unknown;
11​
12 try {
13 decodeYaml(`name: ${secret}\n bad-indent: nope\n`);
14 } catch (cause) {
15 error = cause;
16 }
17​
18 expect(Schema.isSchemaError(error)).toBe(true);
19 if (!Schema.isSchemaError(error)) {
20 throw new Error("Expected a schema error");
21 }
22 expect(error.message).toBe("Invalid YAML (code=BLOCK_AS_IMPLICIT_KEY, line=1, column=7).");
23 expect(error.message).not.toContain(secret);
24 });
25​
26 it("does not expose stringify failure details", () => {
27 const encodeYaml = Schema.encodeSync(fromYaml(Schema.Unknown));
28 const secret = "credential=secret-value";
29 let error: unknown;
30​
31 try {
32 encodeYaml({
33 toJSON() {
34 throw new Error(secret);
35 },
36 });
37 } catch (cause) {
38 error = cause;
39 }
40​
41 expect(Schema.isSchemaError(error)).toBe(true);
42 if (!Schema.isSchemaError(error)) {
43 throw new Error("Expected a schema error");
44 }
45 expect(error.message).toBe("Failed to stringify YAML.");
46 expect(error.message).not.toContain(secret);
47 });
48});