|
| 1 | +import { |
| 2 | + estimateDepositorySettledDemand, |
| 3 | + groundOptionNeedinessFromSettledDepository, |
| 4 | + settledDemandEstimateToNeediness, |
| 5 | + settledDemandEstimateToSignals, |
| 6 | + type SettledDepositoryPackSummary, |
| 7 | +} from '../depository-settled-demand-estimate'; |
| 8 | + |
| 9 | +function pack( |
| 10 | + id: string, |
| 11 | + overrides: Partial<SettledDepositoryPackSummary> = {}, |
| 12 | +): SettledDepositoryPackSummary { |
| 13 | + return { |
| 14 | + id, |
| 15 | + title: overrides.title ?? `Settled pack ${id}`, |
| 16 | + summary: overrides.summary ?? 'Source-safe settled AssetPack summary for demand search.', |
| 17 | + kind: overrides.kind ?? 'capability-slice', |
| 18 | + repositoryFullName: overrides.repositoryFullName ?? 'acme/widgets', |
| 19 | + lifecycleState: overrides.lifecycleState ?? 'settled', |
| 20 | + topics: overrides.topics ?? ['auth', 'routing'], |
| 21 | + }; |
| 22 | +} |
| 23 | + |
| 24 | +describe('depository settled demand estimate', () => { |
| 25 | + it('returns unestimatable when the settled corpus is empty', () => { |
| 26 | + const estimate = estimateDepositorySettledDemand({ settledPacks: [] }); |
| 27 | + expect(estimate.estimatable).toBe(false); |
| 28 | + expect(estimate.state).toBe('unestimatable-demand'); |
| 29 | + expect(estimate.demand).toBeNull(); |
| 30 | + expect(estimate.needinessVolume).toBeNull(); |
| 31 | + expect(estimate.rationale).toMatch(/^Unestimatable:/); |
| 32 | + expect(settledDemandEstimateToSignals(estimate).depositoryDemandSignals).toEqual([]); |
| 33 | + expect(settledDemandEstimateToNeediness(estimate).estimatable).toBe(false); |
| 34 | + }); |
| 35 | + |
| 36 | + it('returns unestimatable when below the settled floor', () => { |
| 37 | + const estimate = estimateDepositorySettledDemand({ |
| 38 | + settledPacks: [pack('a'), pack('b')], |
| 39 | + minSettledPacks: 3, |
| 40 | + }); |
| 41 | + expect(estimate.estimatable).toBe(false); |
| 42 | + expect(estimate.settledPackCount).toBe(2); |
| 43 | + expect(estimate.rationale).toMatch(/need at least 3/); |
| 44 | + }); |
| 45 | + |
| 46 | + it('estimates aggregate demand from a settled corpus without inventing strong placeholders', () => { |
| 47 | + const settledPacks = [ |
| 48 | + pack('1', { title: 'Auth capability slice', summary: 'Reusable authentication capability' }), |
| 49 | + pack('2', { title: 'Routing pattern', summary: 'HTTP routing implementation pattern' }), |
| 50 | + pack('3', { title: 'Proof ops', summary: 'Operations proof for deposit route' }), |
| 51 | + pack('4', { title: 'Telemetry slice', summary: 'Telemetry collection capability' }), |
| 52 | + ]; |
| 53 | + const estimate = estimateDepositorySettledDemand({ settledPacks }); |
| 54 | + expect(estimate.estimatable).toBe(true); |
| 55 | + expect(estimate.demand).not.toBeNull(); |
| 56 | + expect(estimate.demand!).toBeGreaterThan(0); |
| 57 | + expect(estimate.demand!).toBeLessThanOrEqual(1); |
| 58 | + expect(estimate.saturation).not.toBeNull(); |
| 59 | + expect(estimate.needinessVolume).not.toBeNull(); |
| 60 | + expect(estimate.rationale).toMatch(/settled Depository AssetPack/i); |
| 61 | + const signals = settledDemandEstimateToSignals(estimate); |
| 62 | + expect(signals.depositoryDemandSignals[0]?.weight).toBe(estimate.demand); |
| 63 | + }); |
| 64 | + |
| 65 | + it('returns unestimatable for a focused topic with no matching settled packs', () => { |
| 66 | + const settledPacks = [ |
| 67 | + pack('1', { title: 'Auth capability', summary: 'login session tokens' }), |
| 68 | + pack('2', { title: 'Auth middleware', summary: 'session cookies' }), |
| 69 | + pack('3', { title: 'Identity bridge', summary: 'oauth providers' }), |
| 70 | + ]; |
| 71 | + const estimate = estimateDepositorySettledDemand({ |
| 72 | + settledPacks, |
| 73 | + focus: { |
| 74 | + title: 'Quantum ledger warp core', |
| 75 | + summary: 'Hyperdimensional quantum entanglement settlement primitives', |
| 76 | + kind: 'proof-operations-slice', |
| 77 | + repositoryFullName: 'other/org', |
| 78 | + }, |
| 79 | + }); |
| 80 | + expect(estimate.estimatable).toBe(false); |
| 81 | + expect(estimate.state).toBe('unestimatable-demand'); |
| 82 | + expect(estimate.rationale).toMatch(/no settled Depository AssetPacks match/i); |
| 83 | + }); |
| 84 | + |
| 85 | + it('raises demand for topic-aligned settled packs with low corpus coverage', () => { |
| 86 | + const settledPacks = [ |
| 87 | + pack('1', { |
| 88 | + title: 'Deposit route proof operations', |
| 89 | + summary: 'Source-safe deposit route proof and admission', |
| 90 | + kind: 'proof-operations-slice', |
| 91 | + repositoryFullName: 'engineeredsoftware/ENGI', |
| 92 | + topics: ['deposit', 'route', 'proof'], |
| 93 | + }), |
| 94 | + pack('2', { |
| 95 | + title: 'Deposit admission receipt', |
| 96 | + summary: 'Depository admission for deposit options', |
| 97 | + kind: 'proof-operations-slice', |
| 98 | + repositoryFullName: 'engineeredsoftware/ENGI', |
| 99 | + topics: ['deposit', 'admission'], |
| 100 | + }), |
| 101 | + pack('3', { |
| 102 | + title: 'Unrelated widget inventory', |
| 103 | + summary: 'Inventory of garden widgets and tools', |
| 104 | + kind: 'capability-slice', |
| 105 | + repositoryFullName: 'acme/widgets', |
| 106 | + topics: ['garden', 'widgets'], |
| 107 | + }), |
| 108 | + pack('4', { |
| 109 | + title: 'Widget shipping labels', |
| 110 | + summary: 'Shipping label generation for widgets', |
| 111 | + kind: 'implementation-pattern', |
| 112 | + repositoryFullName: 'acme/widgets', |
| 113 | + topics: ['shipping'], |
| 114 | + }), |
| 115 | + pack('5', { |
| 116 | + title: 'Widget color palette', |
| 117 | + summary: 'Color tokens for the widget catalog', |
| 118 | + kind: 'capability-slice', |
| 119 | + repositoryFullName: 'acme/widgets', |
| 120 | + topics: ['design'], |
| 121 | + }), |
| 122 | + ]; |
| 123 | + const estimate = estimateDepositorySettledDemand({ |
| 124 | + settledPacks, |
| 125 | + focus: { |
| 126 | + title: 'Deposit route proof operations slice', |
| 127 | + summary: 'Source-safe deposit route proof and Depository admission evidence', |
| 128 | + kind: 'proof-operations-slice', |
| 129 | + repositoryFullName: 'engineeredsoftware/ENGI', |
| 130 | + coveredSourcePaths: ['uapi/app/deposits/DepositPageClient.tsx'], |
| 131 | + }, |
| 132 | + }); |
| 133 | + expect(estimate.estimatable).toBe(true); |
| 134 | + expect(estimate.matchedPackCount).toBeGreaterThan(0); |
| 135 | + expect(estimate.demand).toBeGreaterThan(0); |
| 136 | + expect(settledDemandEstimateToNeediness(estimate).estimatable).toBe(true); |
| 137 | + }); |
| 138 | + |
| 139 | + it('grounds option neediness from settled packs or marks Unestimatable', () => { |
| 140 | + const options = [ |
| 141 | + { |
| 142 | + title: 'Auth capability slice', |
| 143 | + summary: 'Reusable authentication capability from the repository', |
| 144 | + kind: 'capability-slice', |
| 145 | + neediness: { volume: 0.86, demand: 0.9, saturation: 0.1, rationale: 'LLM invented' }, |
| 146 | + contents: { provenantSourcePaths: ['src/auth.ts'] }, |
| 147 | + sourceBinding: { repositoryFullName: 'acme/widgets' }, |
| 148 | + }, |
| 149 | + ]; |
| 150 | + |
| 151 | + const thin = groundOptionNeedinessFromSettledDepository(options, []); |
| 152 | + expect(thin[0].neediness?.rationale).toMatch(/^Unestimatable:/); |
| 153 | + expect(thin[0].neediness?.demand).toBe(0); |
| 154 | + |
| 155 | + const settledPacks = [ |
| 156 | + pack('1', { title: 'Auth capability', summary: 'authentication sessions' }), |
| 157 | + pack('2', { title: 'Auth middleware', summary: 'login authentication middleware' }), |
| 158 | + pack('3', { title: 'Session store', summary: 'authentication session store pattern' }), |
| 159 | + ]; |
| 160 | + const grounded = groundOptionNeedinessFromSettledDepository(options, settledPacks); |
| 161 | + expect(grounded[0].neediness?.rationale).not.toBe('LLM invented'); |
| 162 | + // Either estimatable from matches or honest Unestimatable — never silent invent. |
| 163 | + expect( |
| 164 | + grounded[0].neediness?.rationale?.includes('settled') || |
| 165 | + grounded[0].neediness?.rationale?.startsWith('Unestimatable'), |
| 166 | + ).toBe(true); |
| 167 | + }); |
| 168 | +}); |
0 commit comments