Skip to content
Myr

main.test.ts

This file

Path

apps/cli/test/main.test.ts

87 lines · 2.5 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–87why, one step back
1import { NodeServices } from "@effect/platform-node";
2import { describe, expect, it } from "@effect/vitest";3import { Brand } from "@repo/brand";4import { Client } from "@repo/protocol/contracts";5import { Effect, Layer } from "effect";6import { CliOutput, Command } from "effect/cli";7import { TestConsole } from "effect/testing";89import { Credentials } from "../src/credentials.ts";10import { root } from "../src/main.ts";11import { OutputPlain } from "../src/output.ts";1213const printed = Effect.map(TestConsole.logLines, (all) =>14 all.flatMap((chunk) => String(chunk).split("\n"))15);1617const services = Layer.mergeAll(18 TestConsole.layer,19 CliOutput.layer(CliOutput.defaultFormatter({ colors: false })),20 Layer.mock(Client)({}),21 Layer.mock(Credentials)({}),22 OutputPlain23).pipe(Layer.provideMerge(NodeServices.layer));2425const help = Effect.gen(function* () {26 yield* Command.runWith(root, { version: "0.0.0" })(["--help"]);2728 return yield* printed;29}).pipe(Effect.provide(services));3031const section = (lines: readonly string[], from: string) => {32 const start = lines.indexOf(from) + 1;3334 const end = lines.findIndex(35 (line, at) => at >= start && /^[A-Z][A-Z ]+$/u.test(line)36 );3738 return lines.slice(start, end === -1 ? lines.length : end).flatMap((line) => {39 const trimmed = line.trim();4041 return trimmed.length > 0 ? [trimmed] : [];42 });43};4445describe(`${Brand.cli} --help`, () => {46 it.effect("opens with the start-here banner, before the command list", () =>47 Effect.gen(function* () {48 const lines = yield* help;4950 expect(section(lines, "DESCRIPTION")).toStrictEqual([51 "Start here:",52 `${Brand.cli} asks list the open asks you could take`,53 `${Brand.cli} claim take one; you get a fork to push your answer to`,54 `${Brand.cli} check run the gate's checks locally before you push`,55 ]);56 expect(lines.indexOf("DESCRIPTION")).toBeLessThan(57 lines.indexOf("SUBCOMMANDS")58 );59 })60 );6162 it.effect(63 "lists the commands that read asks, take one, and every local command",64 () =>65 Effect.gen(function* () {66 const listed = section(yield* help, "SUBCOMMANDS").map(67 (line) => line.split(" ")[0]68 );6970 expect(listed).toStrictEqual(71 expect.arrayContaining([72 "asks",73 "claim",74 "login",75 "logout",76 "init",77 "check",78 "why",79 "env",80 "hook",81 "credential",82 "mcp",83 ])84 );85 })86 );87});