The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { fromYaml } from "./schemaYaml.ts"; |
| 5 | |
| 6 | describe("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 | }); |