File
Blob: test/pack-rewrite-plan.test.ts
| 1 | import { assert, test } from "vitest"; |
| 2 | |
| 3 | import { createLogger } from "@/worker/common"; |
| 4 | import { buildOutputOrder, compactDeadSlots } from "@/worker/git/pack/rewrite/plan"; |
| 5 | import { allocateSelectionTable } from "@/worker/git/pack/rewrite/shared"; |
| 6 | |
| 7 | test("compactDeadSlots preserves base slots for live rows that move", () => { |
| 8 | const table = allocateSelectionTable(4); |
| 9 | table.count = 4; |
| 10 | |
| 11 | // Row 1 is dead and redirects to row 0. Rows 2 and 3 are live and will move |
| 12 | // down one slot, so their dependency metadata must move with them. |
| 13 | table.packSlots[0] = 0; |
| 14 | table.entryIndices[0] = 0; |
| 15 | table.offsets[0] = 10; |
| 16 | table.oidsRaw[0] = 0x10; |
| 17 | table.typeCodes[0] = 3; |
| 18 | table.baseSlots[0] = -1; |
| 19 | |
| 20 | table.packSlots[1] = 0; |
| 21 | table.entryIndices[1] = 1; |
| 22 | table.offsets[1] = 20; |
| 23 | table.oidsRaw[20] = 0x20; |
| 24 | table.typeCodes[1] = 7; |
| 25 | table.baseSlots[1] = 0; |
| 26 | |
| 27 | table.packSlots[2] = 0; |
| 28 | table.entryIndices[2] = 2; |
| 29 | table.offsets[2] = 30; |
| 30 | table.oidsRaw[40] = 0x30; |
| 31 | table.typeCodes[2] = 3; |
| 32 | table.baseSlots[2] = -1; |
| 33 | |
| 34 | table.packSlots[3] = 0; |
| 35 | table.entryIndices[3] = 3; |
| 36 | table.offsets[3] = 40; |
| 37 | table.oidsRaw[60] = 0x40; |
| 38 | table.typeCodes[3] = 6; |
| 39 | table.baseSlots[3] = 2; |
| 40 | |
| 41 | compactDeadSlots(table, new Map([[1, 0]]), createLogger("error", { service: "test" })); |
| 42 | |
| 43 | assert.strictEqual(table.count, 3); |
| 44 | assert.deepEqual(Array.from(table.entryIndices.subarray(0, 3)), [0, 2, 3]); |
| 45 | assert.deepEqual(Array.from(table.baseSlots.subarray(0, 3)), [-1, -1, 1]); |
| 46 | assert.deepEqual([table.oidsRaw[0], table.oidsRaw[20], table.oidsRaw[40]], [0x10, 0x30, 0x40]); |
| 47 | |
| 48 | assert.isTrue(buildOutputOrder(table, createLogger("error", { service: "test" }))); |
| 49 | assert.deepEqual(Array.from(table.outputOrder.subarray(0, 3)), [0, 1, 2]); |
| 50 | }); |