schema.test.ts
This file
Path
apps/cli/test/schema.test.ts
94 lines · 2.9 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–94why, one step back1import { describe, expect, it } from "@effect/vitest";2import { Envelope } from "@repo/protocol/envelope";3import { unanswered } from "@repo/protocol/testing";4import { Effect, Schema } from "effect";56import { runProgram } from "./remote-server.ts";78const PayloadSchema = Schema.fromJsonString(9 Schema.Struct({10 $schema: Schema.String,11 properties: Schema.Record(12 Schema.String,13 Schema.Struct({14 description: Schema.optionalKey(Schema.String),15 type: Schema.optionalKey(Schema.String),16 writeOnly: Schema.optionalKey(Schema.Boolean),17 })18 ),19 required: Schema.Array(Schema.String),20 type: Schema.Literal("object"),21 })22);2324const decodePayloadSchema = Schema.decodeEffect(PayloadSchema);2526const schemaOf = (words: readonly string[], env = {}) =>27 runProgram(["schema", ...words], { env, handlers: unanswered });2829describe("schema <command>", () => {30 it.effect("prints claim's payload: project and ask, both required", () =>31 Effect.gen(function* () {32 const run = yield* schemaOf(["claim"]);33 const printed = yield* decodePayloadSchema(run.out.join("\n"));3435 expect(run.code).toBe(0);36 expect(Object.keys(printed.properties)).toStrictEqual(37 expect.arrayContaining(["project", "ask"])38 );39 expect(printed.required).toStrictEqual(40 expect.arrayContaining(["project", "ask"])41 );42 })43 );4445 it.effect("prints it as one document even for an agent", () =>46 Effect.gen(function* () {47 const run = yield* schemaOf(["ask", "open"], { CLAUDECODE: "1" });48 const printed = yield* decodePayloadSchema(run.out.join("\n"));4950 expect(printed.required).toStrictEqual(51 expect.arrayContaining(["project", "ask", "files"])52 );53 })54 );5556 it.effect("describes env set's value as write-only", () =>57 Effect.gen(function* () {58 const run = yield* schemaOf(["env", "set"]);59 const printed = yield* decodePayloadSchema(run.out.join("\n"));6061 const { key, value } = printed.properties;6263 expect([value?.type, value?.writeOnly]).toStrictEqual(["string", true]);64 expect(value?.description).toContain("Write-only");65 expect(key?.writeOnly).toBeUndefined();66 })67 );6869 it.effect("prints one envelope under --json", () =>70 Effect.gen(function* () {71 const run = yield* schemaOf(["claim", "--json"]);7273 const envelope = yield* Schema.decodeEffect(74 Schema.fromJsonString(Envelope(Schema.Unknown))75 )(run.out.join("\n"));7677 expect(envelope).toStrictEqual(78 expect.objectContaining({ command: "schema", ok: true, v: 1 })79 );80 })81 );8283 it.effect.each([["no-such-command"], ["check"], ["ask", "close"]])(84 "exits 2 for a command with no payload: %j",85 (words) =>86 Effect.gen(function* () {87 const run = yield* schemaOf(words);8889 expect(run.code).toBe(2);90 expect(run.out).toStrictEqual([]);91 expect(run.err).toHaveLength(1);92 })93 );94});