Skip to content
Myr

patch-id.test.ts

This file

Path

packages/git/test/patch-id.test.ts

58 lines · 1.6 KiB · TypeScript

Last changed by

Not known.

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–58why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { BlobSha, RepoPath } from "@repo/protocol/ids";3import { Effect } from "effect";45import { patchId } from "../src/patch-id.ts";6import type { Change } from "../src/tree-diff.ts";78const blob = (digit: string) => BlobSha.make(digit.repeat(40));910const modified: Change = {11 after: blob("2"),12 before: blob("1"),13 path: RepoPath.make("src/a.ts"),14 status: "modified",15};1617const added: Change = {18 after: blob("3"),19 path: RepoPath.make("src/b.ts"),20 status: "added",21};2223const deleted: Change = {24 before: blob("4"),25 path: RepoPath.make("docs/x.md"),26 status: "deleted",27};2829describe("an answer's patch id", () => {30 it.effect("is SHA-256 over the sorted (path, before, after) lines", () =>31 Effect.gen(function* () {32 // `printf 'src/a.ts\0<1×40>\0<2×40>\nsrc/b.ts\0\0<3×40>\n' | sha256sum`33 expect(yield* patchId([added, modified])).toBe(34 "41cf8262f0d7d26011b85d7576fb81865b70e05c5f5d0668b6420045d3b1091d"35 );36 })37 );3839 it.effect("is the same for the same change set in any order", () =>40 Effect.gen(function* () {41 const one = yield* patchId([modified, added, deleted]);4243 expect(yield* patchId([deleted, modified, added])).toBe(one);44 expect(yield* patchId([added, deleted, modified])).toBe(one);45 expect(one).toMatch(/^[0-9a-f]{64}$/u);46 })47 );4849 it.effect("moves when one file's new blob moves", () =>50 Effect.gen(function* () {51 const one = yield* patchId([modified, added]);5253 expect(54 yield* patchId([{ ...modified, after: blob("5") }, added])55 ).not.toBe(one);56 })57 );58});