Skip to content
Myr

output.test.ts

This file

Path

apps/cli/test/output.test.ts

108 lines · 3.1 KiB · TypeScript

Last changed by

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

History of this file

Take 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–108why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Envelope } from "@repo/protocol/envelope";3import { CommitSha, RepoPath } from "@repo/protocol/ids";4import { StaleBase } from "@repo/protocol/refusal";5import { Effect, Schema } from "effect";6import { TestConsole } from "effect/testing";78import { Output, OutputPlain } from "../src/output.ts";910const refusal = new StaleBase({11 base: CommitSha.make("1111111111111111111111111111111111111111"),12 conflicts: [RepoPath.make("src/a.ts")],13 main: CommitSha.make("2222222222222222222222222222222222222222"),14});1516const view = { markdown: "**2** open asks", text: "2 open asks" };1718const printedBy = (use: (output: Output["Service"]) => Effect.Effect<void>) =>19 Effect.gen(function* () {20 yield* Effect.flatMap(Effect.service(Output), use);2122 return {23 err: (yield* TestConsole.errorLines).map(String),24 out: (yield* TestConsole.logLines).map(String),25 };26 }).pipe(Effect.provide([OutputPlain, TestConsole.layer]));2728const decodeEnvelope = Schema.decodeEffect(29 Schema.fromJsonString(Envelope(Schema.Unknown))30);3132describe("plain output", () => {33 it.effect("prints a result as text for a person", () =>34 Effect.gen(function* () {35 const printed = yield* printedBy((output) =>36 output.success({37 command: "asks",38 data: { asks: [] },39 json: false,40 view,41 })42 );4344 expect(printed).toStrictEqual({ err: [], out: ["2 open asks"] });45 })46 );4748 it.effect("prints --json as exactly one envelope on stdout", () =>49 Effect.gen(function* () {50 const printed = yield* printedBy((output) =>51 Effect.andThen(52 output.note("asking the platform"),53 output.success({54 command: "asks",55 data: { asks: [] },56 json: true,57 view,58 })59 )60 );6162 expect(printed.err).toStrictEqual(["asking the platform"]);63 expect(printed.out).toHaveLength(1);64 expect(yield* decodeEnvelope(printed.out[0] ?? "")).toStrictEqual({65 command: "asks",66 data: { asks: [] },67 ok: true,68 v: 1,69 });70 })71 );7273 it.effect(74 "prints refusals in the envelope under --json, and nowhere else",75 () =>76 Effect.gen(function* () {77 const printed = yield* printedBy((output) =>78 output.refused({ command: "submit", json: true, refusals: [refusal] })79 );8081 expect(printed.err).toStrictEqual([]);82 expect(printed.out).toHaveLength(1);83 expect(yield* decodeEnvelope(printed.out[0] ?? "")).toStrictEqual({84 command: "submit",85 ok: false,86 refusals: [refusal],87 v: 1,88 });89 })90 );9192 it.effect(93 "prints refusals on stderr for a person, with what to run next",94 () =>95 Effect.gen(function* () {96 const printed = yield* printedBy((output) =>97 output.refused({98 command: "submit",99 json: false,100 refusals: [refusal],101 })102 );103104 expect(printed.out).toStrictEqual([]);105 expect(printed.err.join("\n")).toContain("git pull --rebase");106 })107 );108});