| 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 type { WalIndex |
| 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 | }; |
| 28 | |
| 29 | const decoded = |
| 30 | |
| 31 | expect(decoded.seq |
| 32 | expect(decoded.compactedThroughSeq |
| 33 | expect(decoded.refs |
| 34 | expect(decoded.layers |
| 35 | }); |
| 36 | |
| 37 | it('round-trips an empty index', |
| 38 | const decoded = |
| 39 | encodeIndex({ |
| 40 | seq: 0, |
| 41 | compactedThroughSeq: 0, |
| 42 | refs: new Map |
| 43 | layers: [], |
| 44 | }), |
| 45 | ); |
| 46 | |
| 47 | expect(decoded.seq |
| 48 | expect(decoded.refs |
| 49 | expect(decoded.layers |
| 50 | }); |
| 51 | |
| 52 | it('rejects a foreign buffer', |
| 53 | expect(() => |
| 54 | }); |
| 55 | |
| 56 | it('reports where the pack begins so headers can be read with a ranged GET', |
| 57 | const ulid = |
| 58 | const header = |
| 59 | ulid, |
| 60 | createdAt: 1_700_000_000_000, |
| 61 | pushedBy: 'phantomknight287', |
| 62 | transitions: [ |
| 63 | { ref: 'refs/heads/main', |
| 64 | ], |
| 65 | }); |
| 66 | const pack = |
| 67 | |
| 68 | const decoded = |
| 69 | |
| 70 | expect(decoded.packOffset |
| 71 | expect(decoded.header |
| 72 | expect(decoded.header |
| 73 | expect(decoded.header |
| 74 | }); |
| 75 | |
| 76 | it('stores oids as raw bytes rather than hex', |
| 77 | const encoded = |
| 78 | seq: 1, |
| 79 | compactedThroughSeq: 0, |
| 80 | refs: new Map |
| 81 | layers: [], |
| 82 | }); |
| 83 | |
| 84 | expect(encoded.includes |
| 85 | }); |
| 86 | }); |