Skip to content
Myr

outcome.test.tsx

This file

Path

apps/web/test/outcome.test.tsx

283 lines · 8.2 KiB · TypeScript

Last changed by

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

History of this file

Take it

Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726

lines 1–97why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Brand } from "@repo/brand";3import { Outcome } from "@repo/protocol/domain/outcome";4import type { StageName } from "@repo/protocol/domain/outcome";5import {6 AskId,7 DecisionId,8 Handle,9 LandedSha,10 RepoPath,11} from "@repo/protocol/ids";12import { OutOfScope, Weakened } from "@repo/protocol/refusal";13import { explain } from "@repo/protocol/render";14import { Schema } from "effect";15import type { ReactElement } from "react";1617import {18 OutcomeView,19 StageStrip,20 stageStates,21} from "../src/features/shared/outcome.tsx";22import { RefusalView } from "../src/features/shared/refusal.tsx";23import { allInOrder, markupOf, textOf } from "./markup.ts";2425const stagesOf = (element: ReactElement) =>26 [...markupOf(element).matchAll(/<li\b[^>]*>/gu)].flatMap(([tag]) => {27 const stage = /data-stage="(?<value>[^"]+)"/u.exec(tag)?.groups?.value;28 const state = /data-state="(?<value>[^"]+)"/u.exec(tag)?.groups?.value;2930 return stage === undefined || state === undefined ? [] : [[stage, state]];31 });3233const handle = Schema.decodeSync(Handle);3435const repoPath = Schema.decodeSync(RepoPath);3637const outOfScope = new OutOfScope({38 paths: [repoPath("packages/format/src/format.ts"), repoPath("README.md")],39});4041const weakened = new Weakened({42 at: { line: 12, path: repoPath("packages/parse/test/parse.test.ts") },43 weakening: { marker: ".skip(" },44});4546const refusals = [outOfScope, weakened] as const;4748const sha = Schema.decodeSync(LandedSha)(49 "9b1c3e5d7f9a1b3c5d7e9f1a3b5c7d9e1f3a5b7c"50);5152const landed = Outcome.cases.Landed.make({ sha });5354describe(RefusalView, () => {55 it("shows every line explain gives, in order, each refusal's tag, and then its next command", () => {56 const text = textOf(<RefusalView refusals={refusals} />);5758 const expected = refusals.flatMap((refusal) => [59 ...explain([refusal]).map((line) => line.trim()),60 refusal.next,61 ]);6263 expect(allInOrder(text, expected)).toBeTruthy();64 expect(text).toContain("OutOfScope");65 expect(text).toContain("Weakened");6667 for (const refusal of refusals) {68 expect(refusal.next.startsWith(`${Brand.cli} `)).toBeTruthy();69 }70 });7172 it("points at the path and line of a refusal that has one", () => {73 const text = textOf(<RefusalView refusals={[weakened]} />);7475 expect(text).toContain("packages/parse/test/parse.test.ts:12");76 });7778 it("says whether retrying can help, without rewording the refusal", () => {79 const markup = markupOf(<RefusalView refusals={refusals} />);8081 expect(markup).toContain('data-refusal="OutOfScope"');82 expect(markup).toContain('data-retryable="false"');83 });84});8586describe(OutcomeView, () => {87 const waiting = [88 [Outcome.cases.Checking.make({ stage: "checks" }), "Checking", "checks"],89 [90 Outcome.cases.AwaitingDecision.make({91 decision: Schema.decodeSync(DecisionId)("dec-000001"),92 }),93 "Waiting on decision",94 "dec-000001",95 ],96 [97 Outcome.cases.AwaitingFinish.make({ decider: handle("okonkwo") }),

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 98why, one step back
98 "waiting for a maintainer's finish",

Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726

lines 99–225why, one step back
99 "okonkwo",
100 ],101 [102 Outcome.cases.WaitingOnParent.make({103 ask: Schema.decodeSync(AskId)("split-format"),104 }),105 "waiting for",106 "split-format",107 ],108 ] as const;109110 it.each(waiting)(111 "reads %o as waiting, never as a refusal",112 (outcome, wording, names) => {113 const element = <OutcomeView outcome={outcome} />;114115 expect(markupOf(element)).toContain(`data-outcome="${outcome._tag}"`);116 expect(markupOf(element)).toContain('data-state="waiting"');117 expect(markupOf(element)).not.toContain("text-refused");118 expect(textOf(element)).toContain(wording);119 expect(textOf(element)).toContain(names);120 }121 );122123 it("reads a landing as final, with its short sha", () => {124 const element = <OutcomeView outcome={landed} />;125126 expect(markupOf(element)).toContain('data-state="final"');127 expect(textOf(element)).toContain("Landed as 9b1c3e5");128 });129130 it("shows a refusal through RefusalView", () => {131 const element = (132 <OutcomeView outcome={Outcome.cases.Refused.make({ refusals })} />133 );134135 expect(markupOf(element)).toContain('data-state="final"');136 expect(markupOf(element)).toContain(137 markupOf(<RefusalView refusals={refusals} />)138 );139 });140});141142const strip = (stage: StageName, outcome: Outcome) =>143 stagesOf(<StageStrip outcome={outcome} stage={stage} />);144145describe(StageStrip, () => {146 it("marks the stages before the current one passed, and the rest pending", () => {147 expect(148 strip("checks", Outcome.cases.Checking.make({ stage: "checks" }))149 ).toStrictEqual([150 ["parse", "passed"],151 ["shape", "passed"],152 ["merge", "passed"],153 ["cheap", "passed"],154 ["checks", "current"],155 ["heldBack", "pending"],156 ["human", "pending"],157 ]);158 });159160 it("marks the stage that refused, and leaves the rest unreached", () => {161 expect(162 strip("shape", Outcome.cases.Refused.make({ refusals }))163 ).toStrictEqual([164 ["parse", "passed"],165 ["shape", "refused"],166 ["merge", "pending"],167 ["cheap", "pending"],168 ["checks", "pending"],169 ["heldBack", "pending"],170 ["human", "pending"],171 ]);172 });173174 it("marks a landed answer's later stages as not needed", () => {175 expect(strip("checks", landed)).toStrictEqual([176 ["parse", "passed"],177 ["shape", "passed"],178 ["merge", "passed"],179 ["cheap", "passed"],180 ["checks", "passed"],181 ["heldBack", "skipped"],182 ["human", "skipped"],183 ]);184 });185186 it("marks the stage the gate is at as the current step, and gives each state a word at the floor size", () => {187 const markup = markupOf(188 <StageStrip189 outcome={Outcome.cases.Checking.make({ stage: "checks" })}190 stage="checks"191 />192 );193194 expect(markup).toMatch(195 /<li\b[^>]*aria-current="step"[^>]*data-stage="checks"/u196 );197 expect(markup.match(/aria-current=/gu)).toHaveLength(1);198 expect(textOf(<StageStrip outcome={landed} stage="checks" />)).toContain(199 "not needed"200 );201 expect(markup).not.toContain("text-xs");202 });203204 it("draws a stage the answer never needed as not needed, given what the verdict holds", () => {205 expect(206 stagesOf(207 <StageStrip208 holds={{ decided: false, heldBack: false }}209 outcome={landed}210 stage="human"211 />212 )213 ).toStrictEqual([214 ["parse", "passed"],215 ["shape", "passed"],216 ["merge", "passed"],217 ["cheap", "passed"],218 ["checks", "passed"],219 ["heldBack", "skipped"],220 ["human", "skipped"],221 ]);222 });223});224225describe("each stage's state", () => {

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 226why, one step back
226 it("marks the maintainer and held-back stages of a landing that needed neither as not needed", () => {

Draw every list and subject from one row, one status line, one family fan and one set of fact blocksoscabrielbefore adoption886b726

lines 227–283why, one step back
227 expect(
228 stageStates("human", landed, { decided: false, heldBack: false })229 ).toStrictEqual([230 ["parse", "passed"],231 ["shape", "passed"],232 ["merge", "passed"],233 ["cheap", "passed"],234 ["checks", "passed"],235 ["heldBack", "skipped"],236 ["human", "skipped"],237 ]);238 });239240 it("marks them passed when the verdict holds a decision and held-back results", () => {241 expect(242 stageStates("human", landed, { decided: true, heldBack: true })243 ).toStrictEqual([244 ["parse", "passed"],245 ["shape", "passed"],246 ["merge", "passed"],247 ["cheap", "passed"],248 ["checks", "passed"],249 ["heldBack", "passed"],250 ["human", "passed"],251 ]);252 });253254 it("keeps a stage the answer still waits at current, whatever the verdict holds", () => {255 expect(256 stageStates(257 "human",258 Outcome.cases.AwaitingFinish.make({ decider: handle("okonkwo") }),259 { decided: false, heldBack: false }260 )261 ).toStrictEqual([262 ["parse", "passed"],263 ["shape", "passed"],264 ["merge", "passed"],265 ["cheap", "passed"],266 ["checks", "passed"],267 ["heldBack", "skipped"],268 ["human", "current"],269 ]);270 });271272 it("reads as before when it is not told what the verdict holds", () => {273 expect(stageStates("human", landed)).toStrictEqual([274 ["parse", "passed"],275 ["shape", "passed"],276 ["merge", "passed"],277 ["cheap", "passed"],278 ["checks", "passed"],279 ["heldBack", "passed"],280 ["human", "passed"],281 ]);282 });283});