| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { rejectedPushReport } |
| 4 | |
| 5 | /** Splits pkt-lines, keeping a flush as an empty payload. */ |
| 6 | function packets(data: |
| 7 | const lines: |
| 8 | for (let offset |
| 9 | const length = |
| 10 | data.toString('ascii |
| 11 | 16, |
| 12 | ); |
| 13 | lines.push(data |
| 14 | offset += Math. |
| 15 | } |
| 16 | return lines; |
| 17 | } |
| 18 | |
| 19 | describe('rejectedPushReport', () |
| 20 | it('refuses every ref on one line each when the client takes no side band', |
| 21 | const report = |
| 22 | refs: ['refs/heads/main', |
| 23 | capabilities: ['report-status'], |
| 24 | reason: 'Storage quota exceeded:\n1 KB of 1 KB used', |
| 25 | })!; |
| 26 | |
| 27 | expect(packets(report |
| 28 | 'unpack ok\n', |
| 29 | 'ng refs/heads/main Storage quota exceeded: 1 KB of 1 KB used\n', |
| 30 | 'ng refs/tags/v1 Storage quota exceeded: 1 KB of 1 KB used\n', |
| 31 | '', |
| 32 | ]); |
| 33 | }); |
| 34 | |
| 35 | it('wraps the report in side-band packets git can carry', |
| 36 | const refs = |
| 37 | const plain = |
| 38 | refs, |
| 39 | capabilities: ['report-status-v2'], |
| 40 | reason: 'no', |
| 41 | })!; |
| 42 | const banded = |
| 43 | refs, |
| 44 | capabilities: ['report-status', |
| 45 | reason: 'no', |
| 46 | })!; |
| 47 | |
| 48 | const outer = |
| 49 | expect(outer.at |
| 50 | const data = |
| 51 | expect(data.length) |
| 52 | for (const packet |
| 53 | expect(packet[0]) |
| 54 | expect(packet.length |
| 55 | } |
| 56 | expect(Buffer.concat |
| 57 | plain, |
| 58 | ); |
| 59 | }); |
| 60 | |
| 61 | it('fits a whole report in one side-band-64k packet', |
| 62 | const report = |
| 63 | refs: ['refs/heads/main'], |
| 64 | capabilities: ['report-status', |
| 65 | reason: 'no', |
| 66 | })!; |
| 67 | |
| 68 | expect(packets(report |
| 69 | }); |
| 70 | |
| 71 | it('has nothing to say to a client that asked for no report', |
| 72 | expect( |
| 73 | rejectedPushReport({ |
| 74 | refs: ['refs/heads/main'], |
| 75 | capabilities: ['side-band-64k'], |
| 76 | reason: 'no', |
| 77 | }), |
| 78 | ).toBeNull(); |
| 79 | }); |
| 80 | }); |