Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Result from "effect/Result";
4
5import { checkOutput, outputRequestProblem } from "./runOutput.ts";
6
7const open = { type: "object", properties: { verdict: { type: "string" } }, required: ["verdict"] };
8const closed = { ...open, additionalProperties: false };
9
10it.effect("a closed schema turns down a key it does not name, and an open one keeps it", () =>
11 Effect.gen(function* () {
12 const extra = '{"verdict":"merge","note":"kept"}';
13 assert.deepStrictEqual(yield* checkOutput(open, extra), Result.succeed(JSON.parse(extra)));
14 const rejected = yield* checkOutput(closed, extra);
15 assert.isTrue(Result.isFailure(rejected));
16 assert.isTrue(Result.isSuccess(yield* checkOutput(closed, '{"verdict":"merge"}')));
17 }),
18);
19
20it("a command its provider runs itself cannot be asked for a result", () => {
21 for (const text of ["/compact", "/goal Review the changes"]) {
22 assert.include(outputRequestProblem(open, { text }) ?? "", "command");
23 }
24 assert.isNull(outputRequestProblem(open, { text: "Review the changes" }));
25});