fork-address.test.ts
This file
Path
packages/protocol/test/fork-address.test.ts
81 lines · 2.2 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 1–81why, one step back1import { describe, expect, it } from "@effect/vitest";2import { Option } from "effect";34import { forkAddressOf, ForkPoint, forkRev } from "../src/domain/code.ts";5import { AskId, BranchName, CommitSha, Handle } from "../src/ids.ts";67const bob = { ask: AskId.make("parse-iso"), handle: Handle.make("bob") };89const sha = CommitSha.make("a".repeat(40));1011describe("a fork address", () => {12 it("names a fork's main, a branch, or a commit by claimant and ask", () => {13 expect(14 [15 "@bob/parse-iso",16 "@bob/parse-iso:main",17 "@bob/parse-iso:fix/tz",18 `@bob/parse-iso:${sha}`,19 ].map(forkAddressOf)20 ).toStrictEqual([21 Option.some({22 ...bob,23 point: ForkPoint.Branch({ name: BranchName.make("main") }),24 }),25 Option.some({26 ...bob,27 point: ForkPoint.Branch({ name: BranchName.make("main") }),28 }),29 Option.some({30 ...bob,31 point: ForkPoint.Branch({ name: BranchName.make("fix/tz") }),32 }),33 Option.some({ ...bob, point: ForkPoint.Commit({ sha }) }),34 ]);35 });3637 it("is written back as the text it was read from", () => {38 const written = [39 forkRev(bob),40 forkRev(bob, "main"),41 forkRev(bob, "fix/tz"),42 forkRev(bob, sha),43 ];4445 expect(written).toStrictEqual([46 "@bob/parse-iso",47 "@bob/parse-iso",48 "@bob/parse-iso:fix/tz",49 `@bob/parse-iso:${sha}`,50 ]);51 expect(52 written.map((rev) => Option.isSome(forkAddressOf(rev)))53 ).toStrictEqual([true, true, true, true]);54 });5556 it("reads nothing else: a ref path, a repo's name, a tag, or a reserved ask", () => {57 const refused = [58 "main",59 "v1.0.0",60 "@datekit/core@2.0.0",61 "alice__datekit--parse-iso--bob",62 "alice__datekit--layer--secrets",63 "@bob/layer",64 "@bob/me",65 "@bob/Parse-ISO",66 "@-bob/parse-iso",67 "@bob/parse-iso/more",68 "@bob/parse-iso:",69 "@bob/parse-iso:refs/heads/main",70 "@bob/parse-iso:../main",71 "@bob/parse-iso:a//b",72 "@bob/parse-iso:main:main",73 "@bob",74 "bob/parse-iso",75 ];7677 expect(78 refused.filter((rev) => Option.isSome(forkAddressOf(rev)))79 ).toStrictEqual([]);80 });81});