|
| 1 | +import { Execution } from '@bitcode/execution-generics'; |
| 2 | +import { |
| 3 | + assertInterfaceDisclosureBoundarySourceSafe, |
| 4 | + buildInterfaceDisclosureBoundary, |
| 5 | + INTERFACE_DISCLOSURE_BOUNDARY_STAGES, |
| 6 | + INTERFACE_DISCLOSURE_BOUNDARY_SURFACES, |
| 7 | + persistInterfaceDisclosureBoundary, |
| 8 | + summarizeInterfaceDisclosureBoundary, |
| 9 | +} from '../interface-disclosure-boundary'; |
| 10 | + |
| 11 | +describe('Interface disclosure boundary', () => { |
| 12 | + it('covers every product, interface, teaching, and compatibility surface at every disclosure stage', () => { |
| 13 | + const boundary = buildInterfaceDisclosureBoundary(); |
| 14 | + |
| 15 | + expect(boundary).toMatchObject({ |
| 16 | + schema: 'bitcode.interface-disclosure-boundary', |
| 17 | + routeVocabulary: { |
| 18 | + currentProductRoutes: ['/deposit', '/read', '/packs'], |
| 19 | + compatibilityRedirects: { |
| 20 | + '/exchange': '/packs', |
| 21 | + }, |
| 22 | + canonicalTerms: { |
| 23 | + assetPackCommodity: 'AssetPack commodity', |
| 24 | + btdScalarVolumeAndRights: 'BTD scalar volume and rights', |
| 25 | + btcSettlementMoney: 'BTC settlement money', |
| 26 | + proofReadbackAuthority: 'proof readback authority', |
| 27 | + }, |
| 28 | + }, |
| 29 | + sourceSafety: { |
| 30 | + sourceSafeMetadataOnly: true, |
| 31 | + protectedSourceVisible: false, |
| 32 | + unpaidAssetPackSourceVisible: false, |
| 33 | + credentialsSerialized: false, |
| 34 | + }, |
| 35 | + }); |
| 36 | + expect(boundary.requiredSurfaces).toEqual([...INTERFACE_DISCLOSURE_BOUNDARY_SURFACES]); |
| 37 | + expect(boundary.requiredStages).toEqual([...INTERFACE_DISCLOSURE_BOUNDARY_STAGES]); |
| 38 | + expect(boundary.rowCount).toBe( |
| 39 | + INTERFACE_DISCLOSURE_BOUNDARY_SURFACES.length * |
| 40 | + INTERFACE_DISCLOSURE_BOUNDARY_STAGES.length, |
| 41 | + ); |
| 42 | + expect( |
| 43 | + boundary.rows.map((row) => `${row.surface}:${row.stage}`).sort(), |
| 44 | + ).toEqual( |
| 45 | + INTERFACE_DISCLOSURE_BOUNDARY_SURFACES.flatMap((surface) => |
| 46 | + INTERFACE_DISCLOSURE_BOUNDARY_STAGES.map((stage) => `${surface}:${stage}`), |
| 47 | + ).sort(), |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it('keeps collapsed and expanded interface states source-safe before repository delivery', () => { |
| 52 | + const boundary = buildInterfaceDisclosureBoundary(); |
| 53 | + |
| 54 | + for (const row of boundary.rows) { |
| 55 | + expect(row.collapsedStateSummary).toContain('source-safe status'); |
| 56 | + expect(row.expandedStateSummary).toContain( |
| 57 | + row.stage === 'after-repository-delivery' |
| 58 | + ? 'purchased AssetPack source' |
| 59 | + : 'withholds source-bearing AssetPack contents', |
| 60 | + ); |
| 61 | + expect(row.visibleFields.join(' ')).toMatch(/proof roots|repository delivery proof/u); |
| 62 | + expect(row.withheldFields.join(' ')).toMatch(/source|credentials/u); |
| 63 | + expect(row.sourceSafety).toMatchObject({ |
| 64 | + protectedSourcePayloadSerialized: false, |
| 65 | + rawProtectedPromptVisible: false, |
| 66 | + rawInterpolatedPromptVisible: false, |
| 67 | + rawProviderResponseVisible: false, |
| 68 | + walletPrivateMaterialVisible: false, |
| 69 | + }); |
| 70 | + if (row.stage !== 'after-repository-delivery') { |
| 71 | + expect(row.sourceBearingAssetPackVisibleToReader).toBe(false); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + assertInterfaceDisclosureBoundarySourceSafe(boundary); |
| 76 | + }); |
| 77 | + |
| 78 | + it('unlocks source-bearing delivery only after BTC finality, BTD rights transfer, and repository delivery', () => { |
| 79 | + const boundary = buildInterfaceDisclosureBoundary(); |
| 80 | + const deliveryRows = boundary.rows.filter( |
| 81 | + (row) => row.stage === 'after-repository-delivery', |
| 82 | + ); |
| 83 | + const earlyRows = boundary.rows.filter( |
| 84 | + (row) => row.stage !== 'after-repository-delivery', |
| 85 | + ); |
| 86 | + |
| 87 | + expect(deliveryRows.length).toBe(INTERFACE_DISCLOSURE_BOUNDARY_SURFACES.length); |
| 88 | + expect(earlyRows.every((row) => row.sourceBearingAssetPackVisibleToReader === false)).toBe(true); |
| 89 | + for (const row of deliveryRows) { |
| 90 | + expect(row).toMatchObject({ |
| 91 | + sourceBearingAssetPackVisibleToReader: true, |
| 92 | + btdRightsTransferred: true, |
| 93 | + btcFinalityRequired: true, |
| 94 | + repositoryDeliveryRequiredForSource: true, |
| 95 | + }); |
| 96 | + } |
| 97 | + }); |
| 98 | + |
| 99 | + it('treats /exchange as a compatibility redirect rather than a current product route', () => { |
| 100 | + const boundary = buildInterfaceDisclosureBoundary(); |
| 101 | + const redirectRows = boundary.rows.filter((row) => row.surface === 'exchange_redirect'); |
| 102 | + |
| 103 | + expect(redirectRows.length).toBe(INTERFACE_DISCLOSURE_BOUNDARY_STAGES.length); |
| 104 | + for (const row of redirectRows) { |
| 105 | + expect(row).toMatchObject({ |
| 106 | + surfaceKind: 'compatibility_redirect', |
| 107 | + routePath: '/exchange', |
| 108 | + compatibilityRedirectTarget: '/packs', |
| 109 | + }); |
| 110 | + } |
| 111 | + expect(boundary.routeVocabulary.currentProductRoutes).not.toContain('/exchange'); |
| 112 | + }); |
| 113 | + |
| 114 | + it('persists route vocabulary, rows, source safety, and proof roots on execution storage', () => { |
| 115 | + const execution = new Execution('interface-disclosure-boundary-test'); |
| 116 | + const boundary = buildInterfaceDisclosureBoundary(); |
| 117 | + |
| 118 | + persistInterfaceDisclosureBoundary(execution, boundary); |
| 119 | + |
| 120 | + expect(execution.get('interfaces/disclosure', 'boundary')).toMatchObject({ |
| 121 | + schema: 'bitcode.interface-disclosure-boundary', |
| 122 | + rowCount: boundary.rowCount, |
| 123 | + }); |
| 124 | + expect(execution.get('interfaces/disclosure', 'routeVocabulary')).toMatchObject({ |
| 125 | + currentProductRoutes: ['/deposit', '/read', '/packs'], |
| 126 | + }); |
| 127 | + expect(execution.get('interfaces/disclosure', 'proofRoots')).toMatchObject({ |
| 128 | + boundaryRoot: expect.stringMatching(/^sha256:/u), |
| 129 | + }); |
| 130 | + expect(summarizeInterfaceDisclosureBoundary(boundary)).toContain('BTD scalar volume and rights'); |
| 131 | + }); |
| 132 | + |
| 133 | + it('does not serialize protected source, secrets, or raw provider responses in boundary records', () => { |
| 134 | + const boundary = buildInterfaceDisclosureBoundary(); |
| 135 | + const serialized = JSON.stringify(boundary); |
| 136 | + |
| 137 | + expect(serialized).not.toContain('diff --git'); |
| 138 | + expect(serialized).not.toContain(`${['sk', 'proj'].join('-')}-`); |
| 139 | + expect(serialized).not.toContain(`${['sb', 'secret'].join('_')}__`); |
| 140 | + expect(serialized).not.toContain('protected source body'); |
| 141 | + expect(serialized).not.toContain('raw provider response body'); |
| 142 | + }); |
| 143 | +}); |
0 commit comments