t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Git/pushwire.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

44 lines
1.5 KiB
TypeScript

import { decodeStagedBatch, encodeStagedBatch } from "@/Git/PushWire.ts";
import { ObjectType } from "@/Git/Protocol/ObjectCodec.ts";
import { describe, expect, test } from "alchemy-test";
describe("push batch codec", { tags: ["unit", "local"] }, () => {
test("inline and promoted rows round-trip", () => {
const rows = [
{
oid: "a".repeat(40),
type: ObjectType.blob,
size: 10,
zdata: new Uint8Array([1, 2, 3]),
zsize: 3,
},
{
oid: "b".repeat(40),
type: ObjectType.blob,
size: 4096,
zdata: new Uint8Array(0),
zsize: 900,
pack: { packId: "wire-01H", offset: 12345 },
},
{
oid: "c".repeat(40),
type: ObjectType.tree,
size: 60,
zdata: new Uint8Array([9, 9, 9, 9]),
zsize: undefined,
},
];
const decoded = decodeStagedBatch(encodeStagedBatch(rows));
expect(decoded.length).toBe(3);
expect(decoded.map((r) => r.oid)).toEqual(rows.map((r) => r.oid));
expect(Array.from(decoded[0]!.zdata)).toEqual([1, 2, 3]);
expect(decoded[1]!.zdata.byteLength).toBe(0);
expect(decoded[1]!.pack).toEqual({ packId: "wire-01H", offset: 12345 });
expect(decoded[1]!.zsize).toBe(900);
expect(Array.from(decoded[2]!.zdata)).toEqual([9, 9, 9, 9]);
expect(decoded[2]!.type).toBe(ObjectType.tree);
});
test("an empty batch encodes to a header only", () => {
expect(decodeStagedBatch(encodeStagedBatch([])).length).toBe(0);
});
});