| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { |
| 4 | decodeEntryHeader, |
| 5 | decodeIndex, |
| 6 | encodeEntryHeader, |
| 7 | encodeIndex, |
| 8 | } from './wal-codec.js'; |
| 9 | import { createUlid } |
| 10 | import { WalCorruptError } |
| 11 | import { emptyIndex, type |
| 12 | |
| 13 | const oid = ( |
| 14 | const packSha = ( |
| 15 | |
| 16 | describe('wal-codec', () |
| 17 | it('round-trips an index', |
| 18 | const ulid = |
| 19 | const index: |
| 20 | seq: 42, |
| 21 | compactedThroughSeq: 7, |
| 22 | refs: new Map |
| 23 | ['refs/heads/main', oid |
| 24 | ['refs/tags/v1.0.0', oid |
| 25 | ]), |
| 26 | layers: [{ ulid |
| 27 | deleted: false, |
| 28 | }; |
| 29 | |
| 30 | const decoded = |
| 31 | |
| 32 | expect(decoded.seq |
| 33 | expect(decoded.compactedThroughSeq |
| 34 | expect(decoded.refs |
| 35 | expect(decoded.layers |
| 36 | expect(decoded.deleted |
| 37 | }); |
| 38 | |
| 39 | it('round-trips a tombstone', |
| 40 | const decoded = |
| 41 | encodeIndex({ ...emptyIndex |
| 42 | ); |
| 43 | |
| 44 | expect(decoded.deleted |
| 45 | expect(decoded.seq |
| 46 | }); |
| 47 | |
| 48 | it('round-trips an empty index', |
| 49 | const decoded = |
| 50 | encodeIndex({ |
| 51 | seq: 0, |
| 52 | compactedThroughSeq: 0, |
| 53 | refs: new Map |
| 54 | layers: [], |
| 55 | deleted: false, |
| 56 | }), |
| 57 | ); |
| 58 | |
| 59 | expect(decoded.seq |
| 60 | expect(decoded.refs |
| 61 | expect(decoded.layers |
| 62 | }); |
| 63 | |
| 64 | it('rejects a foreign buffer', |
| 65 | expect(() => |
| 66 | }); |
| 67 | |
| 68 | it('reports where the pack begins so headers can be read with a ranged GET', |
| 69 | const ulid = |
| 70 | const header = |
| 71 | ulid, |
| 72 | createdAt: 1_700_000_000_000, |
| 73 | pushedBy: 'phantomknight287', |
| 74 | transitions: [ |
| 75 | { ref: 'refs/heads/main', |
| 76 | ], |
| 77 | }); |
| 78 | const pack = |
| 79 | |
| 80 | const decoded = |
| 81 | |
| 82 | expect(decoded.packOffset |
| 83 | expect(decoded.header |
| 84 | expect(decoded.header |
| 85 | expect(decoded.header |
| 86 | }); |
| 87 | |
| 88 | it('stores oids as raw bytes rather than hex', |
| 89 | const encoded = |
| 90 | seq: 1, |
| 91 | compactedThroughSeq: 0, |
| 92 | refs: new Map |
| 93 | layers: [], |
| 94 | deleted: false, |
| 95 | }); |
| 96 | |
| 97 | expect(encoded.includes |
| 98 | }); |
| 99 | }); |