Skip to content
Myr

movers.test.ts

This file

Path

packages/project/test/movers.test.ts

149 lines · 4.2 KiB · TypeScript

Last changed by

Merge build/comments-project into mainoscabrielbefore adoption49efd2a

History of this file

Take it

Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097

lines 1–9why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";3import type { LandingView } from "@repo/protocol/domain/landing";4import {5 AskId,6 Handle,7 LandedSha,8 ProjectName,9 RepoName,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 10why, one step back
10 keyOf,

Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097

lines 11–19why, one step back
11 RepoPath,
12} from "@repo/protocol/ids";13import type { CommitSha } from "@repo/protocol/ids";14import { DateTime, Effect, Ref } from "effect";1516import { movedBy } from "../src/answer-runs/movers.ts";17import { Content, writer } from "./code-fixtures.ts";18import type { Tree } from "./code-fixtures.ts";19

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 20why, one step back
20const project = ProjectName.make("alice/movekit");

Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097

line 21why, one step back
21

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 22why, one step back
22const repo = RepoName.make(keyOf(project));

Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097

lines 23–149why, one step back
23
24const pathOf = (name: string) => RepoPath.make(`src/${name}.ts`);2526const [a, b, c, d, e] = [27 pathOf("a"),28 pathOf("b"),29 pathOf("c"),30 pathOf("d"),31 pathOf("e"),32] as const;3334const alice = Handle.make("alice");3536const dora = Handle.make("dora");3738type Versions = readonly [number, number, number, number, number];3940const files = (versions: Versions): Tree =>41 [a, b, c, d, e].map((path, at) => [42 path,43 Content.Text({ text: `export const v = ${versions[at] ?? 0};\n` }),44 ]);4546const landingOf = (47 sha: CommitSha,48 author: Handle,49 ask: Partial<Pick<LandingView, "ask" | "opened">>50): LandingView => ({51 ...ask,52 assisted: [],53 author,54 credits: [],55 landedAt: DateTime.makeUnsafe("2026-10-07T12:00:00Z"),56 project,57 sha: LandedSha.make(sha),58});5960const history = Effect.gen(function* () {61 const { commit, push } = yield* writer;6263 const on = (64 parent: CommitSha,65 message: string,66 versions: Versions,67 at: number68 ) => commit(message, files(versions), [parent], at);6970 const root = yield* commit("Start", files([0, 0, 0, 0, 0]), [], 0);71 const base = yield* on(root, "Change c", [0, 0, 1, 0, 0], 1);72 const fixA = yield* on(base, "Fix a", [1, 0, 1, 0, 0], 2);73 const own = yield* on(fixA, "Change d", [1, 0, 1, 1, 0], 3);74 const stray = yield* on(own, "Change b", [1, 1, 1, 1, 0], 4);75 const opening = yield* on(stray, "Open add-e", [1, 1, 1, 1, 1], 5);76 const fixAgain = yield* on(opening, "Fix a again", [2, 1, 1, 1, 1], 6);7778 yield* push(repo, [["refs/heads/main", fixAgain]]);7980 const record = [81 landingOf(fixA, alice, { ask: AskId.make("fix-a") }),82 landingOf(own, dora, {}),83 landingOf(opening, dora, { opened: AskId.make("add-e") }),84 landingOf(fixAgain, alice, { ask: AskId.make("fix-a-again") }),85 ];8687 return { base, fixAgain, opening, own, record };88});8990describe(movedBy, () => {91 it.effect(92 "names the newest landing since the base that changed each path, and no one else",93 () =>94 Effect.gen(function* () {95 const { base, fixAgain, opening, own, record } = yield* history;96 const asked = yield* Ref.make<readonly CommitSha[]>([]);9798 const moved = yield* movedBy(99 {100 base,101 conflicts: [a, b, c, d, e],102 main: LandedSha.make(fixAgain),103 repo,104 },105 (shas) =>106 Effect.as(107 Ref.update(asked, (all) => [...all, ...shas]),108 record.filter(({ sha }) => shas.includes(sha))109 )110 );111112 expect(moved).toStrictEqual([113 {114 ask: AskId.make("fix-a-again"),115 author: alice,116 landing: LandedSha.make(fixAgain),117 path: a,118 },119 { author: dora, landing: LandedSha.make(own), path: d },120 {121 ask: AskId.make("add-e"),122 author: dora,123 landing: LandedSha.make(opening),124 path: e,125 },126 ]);127 // The base changed c, so nothing at or before it is asked about.128 expect(yield* Ref.get(asked)).not.toContain(base);129 }).pipe(Effect.provide(RepoHostMemory))130 );131132 it.effect("names nobody when the repo cannot be read", () =>133 Effect.gen(function* () {134 const { base, fixAgain, record } = yield* history;135136 const moved = yield* movedBy(137 {138 base,139 conflicts: [a],140 main: LandedSha.make(fixAgain),141 repo: RepoName.make("no-such-repo"),142 },143 () => Effect.succeed(record)144 );145146 expect(moved).toStrictEqual([]);147 }).pipe(Effect.provide(RepoHostMemory))148 );149});