upload-pack.test.ts
This file
Path
packages/git/test/upload-pack.test.ts
121 lines · 2.9 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake 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–121why, one step back1import { describe, expect, it } from "@effect/vitest";2import { CommitSha } from "@repo/protocol/ids";3import { Option } from "effect";45import { concat, FLUSH, pkt, utf8 } from "../src/pkt-line.ts";6import { readUpload } from "../src/upload-pack.ts";7import type { UploadRequest } from "../src/upload-pack.ts";89const first = "1".repeat(40);1011const second = "2".repeat(40);1213const DELIM = utf8("0001");1415const request = (...parts: readonly (string | Uint8Array)[]) =>16 concat(17 parts.map((part) =>18 part instanceof Uint8Array ? part : pkt(utf8(`${part}\n`))19 )20 );2122const reads = (want?: string): UploadRequest => ({23 reads: true,24 want: want === undefined ? Option.none() : Option.some(CommitSha.make(want)),25});2627const rows: readonly {28 readonly name: string;29 readonly bytes: Uint8Array;30 readonly read: UploadRequest;31}[] = [32 {33 bytes: request(34 `want ${first} multi_ack_detailed side-band-64k ofs-delta agent=git/2.56.0`,35 `want ${second}`,36 FLUSH,37 "done"38 ),39 name: "a v0 clone reads, naming its first want, capabilities and all",40 read: reads(first),41 },42 {43 bytes: request(44 "command=fetch",45 "agent=git/2.56.0",46 "object-format=sha1",47 DELIM,48 "thin-pack",49 "ofs-delta",50 `want ${first}`,51 `want ${second}`,52 "done",53 FLUSH54 ),55 name: "a v2 fetch reads, naming its first want past the delimiter",56 read: reads(first),57 },58 {59 bytes: request(60 "command=ls-refs",61 "agent=git/2.56.0",62 DELIM,63 "peel",64 "symrefs",65 "ref-prefix HEAD",66 FLUSH67 ),68 name: "a v2 ls-refs lists refs and reads nothing",69 read: { reads: false, want: Option.none() },70 },71 {72 bytes: request(73 "command=fetch",74 DELIM,75 "want-ref refs/heads/main",76 "done",77 FLUSH78 ),79 name: "a fetch that wants a ref by name reads, naming no commit",80 read: reads(),81 },82 {83 bytes: request("want 1234abcd", "done"),84 name: "a want that is no full commit id names none",85 read: reads(),86 },87 {88 bytes: concat([utf8("zz07want"), request(`want ${first}`)]),89 name: "framing it can't read is still a read, naming nothing past the break",90 read: reads(),91 },92 {93 bytes: concat([94 request(`want ${first}`),95 utf8("zz07want"),96 request(`want ${second}`),97 ]),98 name: "lines before the framing breaks still count",99 read: reads(first),100 },101 {102 bytes: concat([103 request("command=fetch"),104 utf8("0003"),105 request(`want ${first}`),106 ]),107 name: "a length of 3 is no packet: nothing past it is read",108 read: reads(),109 },110 {111 bytes: new Uint8Array(),112 name: "an empty request is still a read",113 read: reads(),114 },115];116117describe("an upload-pack request, as the read log reads it", () => {118 it.each(rows)("$name", ({ bytes, read }) => {119 expect(readUpload(bytes)).toStrictEqual(read);120 });121});