|
| 1 | +/** |
| 2 | + * The acceptance criterion #1432 states in one sentence — "a wire-type change |
| 3 | + * without an RPC version bump fails" — proved from fixtures. |
| 4 | + * |
| 5 | + * It cannot be proved end-to-end yet: no released tag carries a wire ledger |
| 6 | + * until this lands and ships, so `run.ts` has nothing to diff against. These |
| 7 | + * cases pin the rule now, and `run.ts` becomes a thin git reader over them. |
| 8 | + */ |
| 9 | + |
| 10 | +import assert from 'node:assert/strict'; |
| 11 | +import test from 'node:test'; |
| 12 | +import type { WireLedger } from '../../test/wire-compat/ledger.ts'; |
| 13 | +import { compareWireLedgers } from './model.ts'; |
| 14 | + |
| 15 | +const RESPONSE = 'packages/kernel/src/contracts.ts#DaemonResponse'; |
| 16 | +const META = 'packages/kernel/src/contracts.ts#DaemonRequestMeta'; |
| 17 | + |
| 18 | +function ledger(overrides: Partial<WireLedger> = {}): WireLedger { |
| 19 | + return { |
| 20 | + protocolVersion: 2, |
| 21 | + declarations: { [RESPONSE]: 'sha256:aaa', [META]: 'sha256:bbb' }, |
| 22 | + compatibleChanges: [], |
| 23 | + ...overrides, |
| 24 | + }; |
| 25 | +} |
| 26 | + |
| 27 | +function compare(current: WireLedger, digests: Record<string, string>) { |
| 28 | + return compareWireLedgers({ |
| 29 | + baselineTag: 'v0.20.6', |
| 30 | + released: ledger(), |
| 31 | + current, |
| 32 | + digests: new Map(Object.entries(digests)), |
| 33 | + }); |
| 34 | +} |
| 35 | + |
| 36 | +test('an unchanged wire surface passes', () => { |
| 37 | + const result = compare(ledger(), { [RESPONSE]: 'sha256:aaa', [META]: 'sha256:bbb' }); |
| 38 | + assert.deepEqual(result.failures, []); |
| 39 | + assert.deepEqual(result.changed, []); |
| 40 | +}); |
| 41 | + |
| 42 | +test('a changed wire declaration without a bump or ack fails, naming the symbol', () => { |
| 43 | + const current = ledger({ declarations: { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' } }); |
| 44 | + const result = compare(current, { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' }); |
| 45 | + assert.deepEqual(result.changed, [RESPONSE]); |
| 46 | + assert.equal(result.failures.length, 1); |
| 47 | + assert.match(result.failures[0]!, /DaemonResponse/); |
| 48 | + assert.match(result.failures[0]!, /without bumping DAEMON_RPC_PROTOCOL_VERSION \(still 2\)/); |
| 49 | +}); |
| 50 | + |
| 51 | +test('the same change passes once the protocol version is bumped', () => { |
| 52 | + const current = ledger({ |
| 53 | + protocolVersion: 3, |
| 54 | + declarations: { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' }, |
| 55 | + }); |
| 56 | + const result = compare(current, { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' }); |
| 57 | + assert.equal(result.bumped, true); |
| 58 | + assert.deepEqual(result.failures, []); |
| 59 | +}); |
| 60 | + |
| 61 | +test('the same change passes with a compatible-change ack at the new digest', () => { |
| 62 | + const current = ledger({ |
| 63 | + declarations: { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' }, |
| 64 | + compatibleChanges: [ |
| 65 | + { declaration: RESPONSE, digest: 'sha256:zzz', rationale: 'Added an optional field.' }, |
| 66 | + ], |
| 67 | + }); |
| 68 | + const result = compare(current, { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' }); |
| 69 | + assert.deepEqual(result.failures, []); |
| 70 | +}); |
| 71 | + |
| 72 | +// The ack is keyed by the digest it covers precisely so it expires. Without |
| 73 | +// this, one "added an optional field" ack would launder every later change to |
| 74 | +// the same declaration. |
| 75 | +test('an ack pinned to a superseded digest does not cover the next change', () => { |
| 76 | + const current = ledger({ |
| 77 | + declarations: { [RESPONSE]: 'sha256:yyy', [META]: 'sha256:bbb' }, |
| 78 | + compatibleChanges: [ |
| 79 | + { declaration: RESPONSE, digest: 'sha256:zzz', rationale: 'Covered the previous change.' }, |
| 80 | + ], |
| 81 | + }); |
| 82 | + const result = compare(current, { [RESPONSE]: 'sha256:yyy', [META]: 'sha256:bbb' }); |
| 83 | + assert.equal(result.failures.length, 1); |
| 84 | + assert.match(result.failures[0]!, /DaemonResponse/); |
| 85 | +}); |
| 86 | + |
| 87 | +test('an ack with an empty rationale does not count as an ack', () => { |
| 88 | + const current = ledger({ |
| 89 | + declarations: { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' }, |
| 90 | + compatibleChanges: [{ declaration: RESPONSE, digest: 'sha256:zzz', rationale: ' ' }], |
| 91 | + }); |
| 92 | + const result = compare(current, { [RESPONSE]: 'sha256:zzz', [META]: 'sha256:bbb' }); |
| 93 | + assert.equal(result.failures.length, 1); |
| 94 | +}); |
| 95 | + |
| 96 | +test('a removed wire declaration fails even when acked, because only a bump covers it', () => { |
| 97 | + const current = ledger({ |
| 98 | + declarations: { [META]: 'sha256:bbb' }, |
| 99 | + compatibleChanges: [ |
| 100 | + { declaration: RESPONSE, digest: 'sha256:aaa', rationale: 'Nobody used it.' }, |
| 101 | + ], |
| 102 | + }); |
| 103 | + const result = compare(current, { [META]: 'sha256:bbb' }); |
| 104 | + assert.deepEqual(result.removed, [RESPONSE]); |
| 105 | + assert.equal(result.failures.length, 1); |
| 106 | + assert.match(result.failures[0]!, /an ack cannot cover it/); |
| 107 | +}); |
| 108 | + |
| 109 | +test('a removed wire declaration passes with a bump', () => { |
| 110 | + const current = ledger({ protocolVersion: 3, declarations: { [META]: 'sha256:bbb' } }); |
| 111 | + const result = compare(current, { [META]: 'sha256:bbb' }); |
| 112 | + assert.deepEqual(result.failures, []); |
| 113 | +}); |
| 114 | + |
| 115 | +test('a newly added wire declaration is additive and needs nothing', () => { |
| 116 | + const added = 'packages/kernel/src/contracts.ts#NewEnvelope'; |
| 117 | + const current = ledger({ |
| 118 | + declarations: { [RESPONSE]: 'sha256:aaa', [META]: 'sha256:bbb', [added]: 'sha256:ccc' }, |
| 119 | + }); |
| 120 | + const result = compare(current, { |
| 121 | + [RESPONSE]: 'sha256:aaa', |
| 122 | + [META]: 'sha256:bbb', |
| 123 | + [added]: 'sha256:ccc', |
| 124 | + }); |
| 125 | + assert.deepEqual(result.added, [added]); |
| 126 | + assert.deepEqual(result.failures, []); |
| 127 | +}); |
0 commit comments