Skip to content
Myr

dev-fixtures.test.ts

This file

Path

apps/web/test/dev-fixtures.test.ts

884 lines · 27.8 KiB · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

1import { describe, expect, it } from "@effect/vitest";2import { Client, Contracts } from "@repo/protocol/contracts";3import { forkRev } from "@repo/protocol/domain/code";4import { DecisionSubject } from "@repo/protocol/domain/decision";5import type { Decision } from "@repo/protocol/domain/decision";6import { ProjectEvent } from "@repo/protocol/domain/event";7import { Outcome } from "@repo/protocol/domain/outcome";8import { LedgerEntry } from "@repo/protocol/domain/visibility";9import {10  AskId,11  DecisionId,12  Handle,13  ProjectName,14  ProposalId,15} from "@repo/protocol/ids";16import {17  Context,18  DateTime,19  Duration,20  Effect,21  Exit,22  Layer,23  Stream,24} from "effect";25import type { Scope } from "effect";26import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";27import { RpcClient, RpcSerialization } from "effect/rpc";2829import { askStates, familyMarks } from "../src/client/events.ts";30import type { FixtureMode } from "../src/dev/fixtures.ts";31import { fixturesNow } from "../src/dev/fixtures/vellum.ts";32import { seedEnd } from "../src/dev/seed.ts";33import type { DevWorldOptions } from "../src/dev/server.ts";34import { devServer } from "../src/dev/server.ts";35import { devToken } from "../src/dev/sessions.ts";3637const vellum = ProjectName.make("oscabriel/vellum");3839const ask = (id: string) => AskId.make(id);4041const signedIn = (handle: string) => devToken(Handle.make(handle));4243const connect = (44  handler: (request: Request) => Promise<Response>,45  token?: string46) =>47  Effect.map(48    Layer.build(49      Layer.effect(Client)(RpcClient.make(Contracts)).pipe(50        Layer.provide(51          RpcClient.layerProtocolHttp({52            transformClient: HttpClient.mapRequest((request) =>53              token === undefined54                ? request55                : HttpClientRequest.bearerToken(request, token)56            ),57            url: "http://localhost/rpc",58          })59        ),60        Layer.provide([FetchHttpClient.layer, RpcSerialization.layerJson]),61        Layer.provide(62          Layer.succeed(FetchHttpClient.Fetch, (input, init) =>63            handler(new Request(input, init))64          )65        )66      )67    ),68    Context.get(Client)69  );7071type Reader = Effect.Success<ReturnType<typeof connect>>;7273const inWorld = <A, E>(74  options: DevWorldOptions,75  read: (76    as: (token?: string) => Effect.Effect<Reader, never, Scope.Scope>77  ) => Effect.Effect<A, E, Scope.Scope>78) =>79  Effect.scoped(80    Effect.gen(function* () {81      const { dispose, handler } = devServer(options);8283      yield* Effect.addFinalizer(() => Effect.promise(dispose));8485      return yield* read((token) => connect(handler, token));86    })87  );8889const withFixtures: DevWorldOptions = { fixtures: "on" };9091const eventsOf = (client: Reader) =>92  Effect.map(93    Stream.runCollect(client.watch({ project: vellum })),94    (events): readonly ProjectEvent[] => events95  );9697const closedIn = (events: readonly ProjectEvent[]) =>98  events.filter(ProjectEvent.guards.AskClosed);99100const ANSWERS = {101  "carry-footnotes-to-epub": "Landed",102  "cli-version-flag": "Landed",103  "escape-attribute-quotes": "AwaitingDecision",104  "footnote-backrefs": "WaitingOnParent",105  "render-code-blocks": "Landed",106  "render-nested-lists": "Refused",107  "retire-old-tokenizer-vellum-lint": "Checking",108  "retire-old-tokenizer-vellum-parser": "Refused",109  "trim-trailing-spaces": "Refused",110  "wrap-long-table-cells": "AwaitingFinish",111} as const;112113const answersRead = inWorld(withFixtures, (as) =>114  Effect.gen(function* () {115    const anyone = yield* as();116117    const verdicts = yield* Effect.forEach(Object.keys(ANSWERS), (id) =>118      Effect.map(119        anyone.verdict({ ask: ask(id), project: vellum }),120        ({ verdict }) => [id, verdict] as const121      )122    );123124    const byAsk = new Map(verdicts);125126    const landingOf = (id: string) => {127      const outcome = byAsk.get(id)?.outcome;128129      return outcome !== undefined && Outcome.guards.Landed(outcome)130        ? Effect.map(131            anyone.landing({ project: vellum, sha: outcome.sha }),132            ({ landing }) => landing133          )134        : Effect.die(`${id} did not land`);135    };136137    return {138      byAsk,139      decided: yield* landingOf("carry-footnotes-to-epub"),140      events: yield* eventsOf(anyone),141      plain: yield* landingOf("cli-version-flag"),142    };143  })144);145146const refusalsOf = (outcome: Outcome | undefined) =>147  outcome !== undefined && Outcome.guards.Refused(outcome)148    ? outcome.refusals149    : [];150151const hunksOf = (patch: string) => {152  const hunks: { declared: string; counted: string }[] = [];153  let old = 0;154  let fresh = 0;155  let declared: string | undefined;156157  const close = () => {158    if (declared !== undefined) {159      hunks.push({ counted: `${old}/${fresh}`, declared });160    }161  };162163  for (const line of patch.split("\n")) {164    const header =165      /^@@ -\d+(?:,(?<old>\d+))? \+\d+(?:,(?<fresh>\d+))? @@/u.exec(line);166167    if (header !== null) {168      close();169      declared = `${header.groups?.old ?? "1"}/${header.groups?.fresh ?? "1"}`;170      old = 0;171      fresh = 0;172    } else if (line.startsWith("diff --git ")) {173      close();174      declared = undefined;175    } else if (declared !== undefined && line !== "") {176      old += line.startsWith("+") ? 0 : 1;177      fresh += line.startsWith("-") ? 0 : 1;178    }179  }180181  close();182183  return hunks;184};185186// Each test seeds a whole world while turbo runs every package's tests at once.187const seededWorlds = { timeout: 30_000 };188189describe("the dev world's fixtures", seededWorlds, () => {190  it.live(191    "list more than eight projects, vellum and one with no open asks among them",192    () =>193      inWorld(withFixtures, (as) =>194        Effect.gen(function* () {195          const { projects } = yield* (yield* as()).listProjects({});196          const names = new Set(projects.map(({ project }) => project));197198          expect(projects.length).toBeGreaterThan(8);199          expect(200            [201              "oscabriel/burrow",202              "oscabriel/datekit",203              "oscabriel/vellum",204            ].filter((name) => !names.has(ProjectName.make(name)))205          ).toStrictEqual([]);206          expect(207            projects.find(({ project }) => project === "lin-h/mossgate")208              ?.openAsks209          ).toBe(0);210        })211      )212  );213214  it.live("give every answer state its verdict", () =>215    Effect.gen(function* () {216      const { byAsk } = yield* answersRead;217218      expect(219        Object.fromEntries(220          [...byAsk].map(([id, verdict]) => [id, verdict?.outcome._tag])221        )222      ).toStrictEqual(ANSWERS);223      expect({224        checking: byAsk.get("retire-old-tokenizer-vellum-lint")?.outcome,225        decision: byAsk.get("escape-attribute-quotes")?.outcome,226        finish: byAsk.get("wrap-long-table-cells")?.outcome,227        parent: byAsk.get("footnote-backrefs")?.outcome,228      }).toStrictEqual({229        checking: Outcome.cases.Checking.make({ stage: "checks" }),230        decision: Outcome.cases.AwaitingDecision.make({231          decision: DecisionId.make("dec-000002"),232        }),233        finish: Outcome.cases.AwaitingFinish.make({234          decider: Handle.make("ines-v"),235        }),236        parent: Outcome.cases.WaitingOnParent.make({237          ask: ask("number-footnotes"),238        }),239      });240    })241  );242243  it.live(244    "refuse at Shape with a place, at the held-back stage by area, and at the checks with a failed lane's log",245    () =>246      Effect.gen(function* () {247        const { byAsk } = yield* answersRead;248        const scope = byAsk.get("trim-trailing-spaces");249        const held = byAsk.get("retire-old-tokenizer-vellum-parser");250        const checks = byAsk.get("render-nested-lists");251252        const [outside] = refusalsOf(scope?.outcome);253        const [sealed] = refusalsOf(held?.outcome);254        const [failed] = refusalsOf(checks?.outcome);255256        expect([scope?.stage, outside?._tag, outside?.at]).toStrictEqual([257          "shape",258          "OutOfScope",259          { line: 3, path: "packages/cli/src/args.ts" },260        ]);261        expect([held?.stage, sealed?._tag, held?.heldBack]).toMatchObject([262          "heldBack",263          "HeldBackFailed",264          [{ area: "parser", passed: 3, total: 4 }],265        ]);266        expect([checks?.stage, failed?._tag]).toStrictEqual([267          "checks",268          "ChecksFailed",269        ]);270        expect(271          checks?.lanes272            .filter(({ result }) => result === "failed")273            .map(({ lane, logRef }) => [lane, logRef !== undefined])274        ).toStrictEqual([["unit", true]]);275      })276  );277278  it.live(279    "give a failed lane's log to its claimant, and the same NotDecider to anyone else whether or not a log is kept",280    () =>281      inWorld(withFixtures, (as) =>282        Effect.gen(function* () {283          const anyone = yield* as();284          const nested = ask("render-nested-lists");285286          const { verdict } = yield* anyone.verdict({287            ask: nested,288            project: vellum,289          });290291          const ref = verdict?.lanes.find(292            ({ logRef }) => logRef !== undefined293          )?.logRef;294295          const claimant = askStates(yield* eventsOf(anyone)).get(296            nested297          )?.claimant;298299          const read = (client: Reader, logRef: string) =>300            Effect.match(client.evidence({ project: vellum, ref: logRef }), {301              onFailure: ({ _tag }): string => _tag,302              onSuccess: ({ lane }): string => lane,303            });304305          const owner = yield* as(signedIn(claimant ?? "nobody"));306          const stranger = yield* as(signedIn("wren"));307308          expect(claimant).toBeDefined();309          expect([310            yield* read(owner, ref ?? ""),311            yield* read(stranger, ref ?? ""),312            yield* read(313              stranger,314              "push-0000000000000000000000000000000000000000-wren/unit"315            ),316          ]).toStrictEqual(["unit", "NotDecider", "NotDecider"]);317        })318      )319  );320321  it.live(322    "land one answer with a decision and the Held-back trailer, and one with neither",323    () =>324      Effect.gen(function* () {325        const { byAsk, decided, plain } = yield* answersRead;326327        expect(decided.heldBackTrailer).toMatch(328          /^export 7\/7 @ sha256:[0-9a-f]{64}; parser 4\/4 @ sha256:[0-9a-f]{64}$/u329        );330        expect(decided.credits.map(({ role }) => role)).toContain("Decided-by");331        expect({332          attended: plain.credits.filter(333            ({ role }) => role === "Decided-by" || role === "Finished-by"334          ),335          heldBack: byAsk.get("cli-version-flag")?.heldBack,336          trailer: plain.heldBackTrailer,337        }).toStrictEqual({ attended: [], heldBack: [], trailer: undefined });338      })339  );340341  it.live("replay an answer's three rounds: refused twice, then landed", () =>342    Effect.gen(function* () {343      const { events } = yield* answersRead;344      const progress = askStates(events).get(ask("render-code-blocks"));345346      expect(progress?.rounds.map(({ outcome }) => outcome._tag)).toStrictEqual(347        ["Refused", "Refused", "Checking"]348      );349      expect(progress?.landed).toBeDefined();350    })351  );352353  it.live(354    "fold the first family's events into one child in every mark, its delete child waiting",355    () =>356      inWorld(withFixtures, (as) =>357        Effect.gen(function* () {358          const anyone = yield* as();359          const parent = ask("retire-old-tokenizer");360          const shown = yield* anyone.showAsk({ ask: parent, project: vellum });361          const states = askStates(yield* eventsOf(anyone));362          const family = familyMarks(shown.ask, states);363          const { asks } = yield* anyone.listAsks({ project: vellum });364365          // The parent stores its six children, then the delete child.366          expect(shown.ask.blockedBy).toHaveLength(7);367          expect(shown.ask.blockedBy.at(-1)).toBe(368            "retire-old-tokenizer-delete"369          );370          expect(371            family.children.slice(0, 6).map(({ mark }) => mark)372          ).toStrictEqual([373            "landed",374            "landed",375            "checking",376            "refused",377            "claimed",378            "open",379          ]);380          expect(381            asks.find(({ ask: id }) => id === "retire-old-tokenizer-delete")382          ).toBeDefined();383        })384      )385  );386387  it.live(388    "land the second family's children and open its delete child to take",389    () =>390      inWorld(withFixtures, (as) =>391        Effect.gen(function* () {392          const anyone = yield* as();393          const parent = ask("rename-page-size");394          const shown = yield* anyone.showAsk({ ask: parent, project: vellum });395          const states = askStates(yield* eventsOf(anyone));396          const { entries } = yield* anyone.frontPage({});397398          const children = shown.ask.blockedBy.filter(399            (child) => child !== "rename-page-size-delete"400          );401402          expect(children.length).toBeGreaterThanOrEqual(2);403          expect(404            children.filter((child) => states.get(child)?.landed === undefined)405          ).toStrictEqual([]);406          expect(407            entries.find(408              (entry) =>409                entry.project === vellum &&410                entry.ask.ask === "rename-page-size-delete"411            )?.takeable412          ).toBeTruthy();413        })414      )415  );416417  it.live(418    "hold asks open, held for newcomers, claimed with and without a push, and one with a long want",419    () =>420      inWorld(withFixtures, (as) =>421        Effect.gen(function* () {422          const anyone = yield* as();423          const { asks } = yield* anyone.listAsks({ project: vellum });424          const states = askStates(yield* eventsOf(anyone));425          const held = asks.find(({ reserve }) => reserve === "newcomers");426427          const mentored = yield* anyone.showAsk({428            ask: held?.ask ?? ask("missing"),429            project: vellum,430          });431432          const render = states.get(ask("retire-old-tokenizer-vellum-render"));433434          expect(mentored.ask.mentor).toBe("okonkwo");435          expect(asks.some(({ want }) => want.length > 80)).toBeTruthy();436          expect([render?.claimant, render?.lastPush]).toStrictEqual([437            "sefa",438            undefined,439          ]);440          expect(states.get(ask("number-footnotes"))?.lastPush).toBeDefined();441        })442      )443  );444445  it.live(446    "put every kind of decision on a maintainer's Today, one due within the day and two of five taken",447    () =>448      inWorld(withFixtures, (as) =>449        Effect.gen(function* () {450          const project = vellum;451          const ines = yield* as(signedIn("ines-v"));452          const mine = yield* ines.today({ project });453          const merged = yield* ines.today({});454455          const others = yield* Effect.forEach(["okonkwo", "lin-h"], (handle) =>456            Effect.flatMap(as(signedIn(handle)), (client) =>457              client.today({ project })458            )459          );460461          const kinds = new Set(462            [mine, ...others].flatMap(({ decisions }) =>463              decisions.map(({ subject }) => subject._tag)464            )465          );466467          expect({468            budget: [mine.budget.used, mine.budget.total],469            dueToday: mine.expiringSoon.length,470            overflow: mine.overflow,471            shown: mine.decisions.some(({ id }) => id === mine.expiringSoon[0]),472          }).toStrictEqual({473            budget: [2, 5],474            dueToday: 1,475            overflow: 3,476            shown: true,477          });478          expect([479            mine.newcomers.length > 0,480            mine.unattended.length > 0,481            merged.overflow >= 3,482          ]).toStrictEqual([true, true, true]);483          expect([...kinds].toSorted()).toStrictEqual(484            Object.keys(DecisionSubject.cases).toSorted()485          );486        })487      )488  );489490  it.live(491    "show a Finish decision with its diff, a refusal's place inside it, and the fork to finish from",492    () =>493      inWorld(withFixtures, (as) =>494        Effect.gen(function* () {495          const ines = yield* as(signedIn("ines-v"));496          const { decisions } = yield* ines.today({ project: vellum });497498          const finish = decisions.find(({ subject }) =>499            DecisionSubject.guards.Finish(subject)500          );501502          const patch = finish?.evidence.find(503            ({ label }) => label === "patch"504          )?.value;505506          const rounds =507            askStates(yield* eventsOf(ines)).get(ask("wrap-long-table-cells"))508              ?.rounds ?? [];509510          const placed = rounds511            .flatMap(({ outcome }) => refusalsOf(outcome))512            .flatMap(({ at }) => (at === undefined ? [] : [at]));513514          expect(finish?.evidence.map(({ label }) => label)).toContain("fork");515          expect(placed).toHaveLength(1);516          expect(patch).toContain(`+++ b/${placed[0]?.path}`);517518          // Every hunk holds the lines its header declares, or the diff view refuses it.519          const hunks = hunksOf(patch ?? "");520521          expect(hunks.length).toBeGreaterThan(0);522          expect(hunks.map(({ counted }) => counted)).toStrictEqual(523            hunks.map(({ declared }) => declared)524          );525        })526      )527  );528529  it.live(530    "keep a ledger of sealed evidence: a layer, two areas, and history of every kind",531    () =>532      inWorld(withFixtures, (as) =>533        Effect.gen(function* () {534          const anyone = yield* as();535          const ledger = yield* anyone.ledger({ project: vellum });536          const { projects } = yield* anyone.listProjects({});537538          expect([539            ledger.posture,540            projects.find(({ project }) => project === vellum)?.posture,541          ]).toStrictEqual([542            "openWithSealedEvidence",543            "openWithSealedEvidence",544          ]);545          expect(546            ledger.layers.map(({ name, reason }) => [name, reason.length > 0])547          ).toStrictEqual([["maintainers", true]]);548          expect(549            ledger.entries.flatMap((entry) =>550              LedgerEntry.guards.CommitmentPublished(entry)551                ? [[entry.area, entry.checks, entry.authors]]552                : []553            )554          ).toStrictEqual([555            ["export", 7, 3],556            ["parser", 4, 3],557          ]);558          expect(new Set(ledger.entries.map(({ _tag }) => _tag))).toStrictEqual(559            new Set([560              "Admitted",561              "CommitmentPublished",562              "CountChanged",563              "LayerDeclared",564              "PostureChanged",565              "Released",566              "ValueSet",567            ])568          );569        })570      )571  );572573  it.live(574    "declare an env schema with a write-only item someone set, and never a value",575    () =>576      inWorld(withFixtures, (as) =>577        Effect.gen(function* () {578          const declared = yield* (yield* as()).envShape({ project: vellum });579580          const token = declared.items.find(581            ({ key }) => key === "SENTRY_AUTH_TOKEN"582          );583584          expect(declared.items).toHaveLength(4);585          expect({586            proxy: token?.proxy,587            sensitive: token?.sensitive,588            setBy: token?.value?.setBy,589          }).toStrictEqual({590            proxy: { domains: ["sentry.io"], path: "/api/**" },591            sensitive: true,592            setBy: "ines-v",593          });594          expect(595            declared.items.some(({ deprecated }) => deprecated === true)596          ).toBeTruthy();597          expect(598            declared.items.filter(599              ({ placeholder }) => placeholder !== undefined600            )601          ).toStrictEqual([]);602        })603      )604  );605606  it.live(607    "state a policy with maintainers by path and a denounced person",608    () =>609      inWorld(withFixtures, (as) =>610        Effect.gen(function* () {611          const { policy } = yield* (yield* as()).projectPolicy({612            project: vellum,613          });614615          expect(616            new Set(policy?.deciders.map(({ paths }) => paths)).size617          ).toBeGreaterThan(2);618          expect(619            policy?.vouches620              .filter(({ denounced }) => denounced)621              .map(({ handle }) => handle)622          ).toStrictEqual(["wren"]);623        })624      )625  );626627  it.live("give every answer fork vellum lists a tree at its address", () =>628    inWorld(withFixtures, (as) =>629      Effect.gen(function* () {630        const anyone = yield* as();631        const { forks } = yield* anyone.listRefs({ project: vellum });632633        const answers = forks.flatMap((fork) =>634          fork.kind === "claim" && fork.ask !== undefined635            ? [forkRev({ ask: fork.ask, handle: fork.handle })]636            : []637        );638639        const read = yield* Effect.forEach(answers, (at) =>640          Effect.map(641            Effect.exit(anyone.readTree({ at, project: vellum })),642            (exit) => [at, Exit.isSuccess(exit)] as const643          )644        );645646        expect(answers.length).toBeGreaterThan(3);647        expect(read.filter(([, listed]) => !listed)).toStrictEqual([]);648      })649    )650  );651652  it.live("draft proposals into every state a draft settles in", () =>653    inWorld(withFixtures, (as) =>654      Effect.gen(function* () {655        const anyone = yield* as();656657        const shown = yield* Effect.forEach(658          ["prop-000002", "prop-000003", "prop-000004", "prop-000005"],659          (id) =>660            anyone.showProposal({661              project: vellum,662              proposal: ProposalId.make(id),663            })664        );665666        expect(667          shown.map(({ files, proposal }) => [668            proposal.draft?._tag,669            files.length,670          ])671        ).toStrictEqual([672          ["Ready", 3],673          ["Failed", 0],674          ["Failed", 3],675          ["Drafting", 0],676        ]);677      })678    )679  );680681  it.live(682    "list landings across three days, tags, and claim forks in every state",683    () =>684      inWorld(withFixtures, (as) =>685        Effect.gen(function* () {686          const anyone = yield* as();687          const refs = yield* anyone.listRefs({ project: vellum });688          const { commits } = yield* anyone.log({ project: vellum });689690          const landings = commits.flatMap(({ landing }) =>691            landing === undefined ? [] : [landing]692          );693694          expect(refs.tags.length).toBeGreaterThan(0);695          expect(696            new Set(refs.forks.map(({ kind, state }) => state ?? kind))697          ).toStrictEqual(698            new Set([699              "answered",700              "lapsed",701              "live",702              "released",703              "warned",704              "working",705            ])706          );707          expect(708            new Set(709              landings.map(({ landedAt }) =>710                DateTime.formatIsoDateUtc(landedAt)711              )712            ).size713          ).toBeGreaterThanOrEqual(3);714          expect([715            landings.some(({ opened }) => opened !== undefined),716            landings.some(717              ({ heldBackTrailer }) => heldBackTrailer !== undefined718            ),719          ]).toStrictEqual([true, true]);720        })721      )722  );723});724725describe("the dev world's live landing", seededWorlds, () => {726  it.live(727    "lands one more child of the first family after the project's watch is first read",728    () =>729      inWorld({ fixtures: "live", liveAfter: Duration.zero }, (as) =>730        Effect.gen(function* () {731          const anyone = yield* as();732          const first = yield* eventsOf(anyone);733          const second = yield* eventsOf(anyone);734735          const landed = closedIn(second).find(736            (event) => !closedIn(first).some(({ seq }) => seq === event.seq)737          );738739          expect(closedIn(second)).toHaveLength(closedIn(first).length + 1);740          expect(landed?.ask).toBe("retire-old-tokenizer-vellum-lint");741          expect(landed?.seq).toBeGreaterThan(742            Math.max(...first.map(({ seq }) => seq))743          );744        })745      )746  );747});748749const millisFrom = (from: DateTime.DateTime, at: DateTime.DateTime) =>750  Duration.toMillis(DateTime.distance(from, at));751752const timesIn = (options: DevWorldOptions) =>753  inWorld(options, (as) =>754    Effect.gen(function* () {755      const ines = yield* as(signedIn("ines-v"));756      const { decisions, overflow } = yield* ines.today({});757758      const proposedAt = (handle: string, want: string) =>759        Effect.flatMap(as(signedIn(handle)), (client) =>760          Effect.map(761            client.proposeAsk({762              project: ProjectName.make("oscabriel/datekit"),763              want,764            }),765            ({ proposal }) => proposal.openedAt766          )767        );768769      const first = yield* proposedAt("tove", "datekit prints ISO weeks.");770771      yield* Effect.sleep(Duration.millis(20));772773      const second = yield* proposedAt("sefa", "datekit reads RFC 2822 dates.");774775      return { decisions, first, overflow, second };776    })777  );778779const keyOf = ({ id, project }: Decision) => `${project}/${id}`;780781// Today's budget counts a UTC day, so which taken decisions fall on the present day moves with the time of day782// the world is built at: the two worlds are held to the same open count, and shared decisions to one shift.783const placedAtThePresent = (fixtures: FixtureMode, end: DateTime.Utc) =>784  Effect.gen(function* () {785    const fixed = yield* timesIn({ fixtures });786787    expect([fixed.first, fixed.second]).toStrictEqual([end, end]);788789    const before = DateTime.startOf(yield* DateTime.now, "minute");790    const present = yield* timesIn({ fixtures, time: "present" });791    const after = yield* DateTime.now;792793    const fixedByKey = new Map(794      fixed.decisions.map((decision) => [keyOf(decision), decision])795    );796797    const shared = present.decisions.filter((decision) =>798      fixedByKey.has(keyOf(decision))799    );800801    const [first] = shared;802803    expect(first).toBeDefined();804805    const shift = millisFrom(806      (first === undefined ? undefined : fixedByKey.get(keyOf(first)))807        ?.openedAt ?? end,808      first?.openedAt ?? end809    );810811    const unshifted = (at: DateTime.Utc) =>812      DateTime.subtractDuration(at, Duration.millis(shift));813814    expect(815      shared.map((decision) => [816        keyOf(decision),817        unshifted(decision.openedAt),818        unshifted(decision.expiresAt),819      ])820    ).toStrictEqual(821      shared.map((decision) => {822        const was = fixedByKey.get(keyOf(decision));823824        return [keyOf(decision), was?.openedAt, was?.expiresAt];825      })826    );827    expect(shift % Duration.toMillis(Duration.minutes(1))).toBe(0);828829    const anchor = DateTime.addDuration(end, Duration.millis(shift));830831    expect([832      millisFrom(before, anchor) >= 0,833      millisFrom(anchor, DateTime.startOf(after, "minute")) >= 0,834      millisFrom(anchor, present.first) >= 0,835      millisFrom(present.first, present.second) > 0,836      millisFrom(present.second, after) >= 0,837      present.decisions.every(838        ({ expiresAt }) => millisFrom(present.second, expiresAt) > 0839      ),840      present.decisions.length + present.overflow ===841        fixed.decisions.length + fixed.overflow,842    ]).toStrictEqual([true, true, true, true, true, true, true]);843  });844845describe("the dev world's time", seededWorlds, () => {846  it.live(847    "ends the default seed at the present minute and runs on from it",848    () => placedAtThePresent("off", seedEnd)849  );850851  it.live(852    "ends the fixtures' story at the present minute and runs on from it",853    () => placedAtThePresent("on", fixturesNow)854  );855856  it.live("lands the live child at the present on a running clock", () =>857    Effect.gen(function* () {858      const before = yield* DateTime.now;859860      const landed = yield* inWorld(861        { fixtures: "live", liveAfter: Duration.zero, time: "present" },862        (as) =>863          Effect.gen(function* () {864            const anyone = yield* as();865866            yield* eventsOf(anyone);867868            return closedIn(yield* eventsOf(anyone)).find(869              (event) => event.ask === "retire-old-tokenizer-vellum-lint"870            );871          })872      );873874      const after = yield* DateTime.now;875876      expect(landed).toBeDefined();877      expect([878        millisFrom(DateTime.startOf(before, "minute"), landed?.at ?? before) >=879          0,880        millisFrom(landed?.at ?? after, after) >= 0,881      ]).toStrictEqual([true, true]);882    })883  );884});