-
Notifications
You must be signed in to change notification settings - Fork 0
fix(readiness): separate canonical buyer gaps from capability maturity #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5f25fac
test(readiness): define canonical buyer-gap registry contract
seonghobae 1b33b3d
feat(readiness): evaluate canonical buyer-gap evidence
seonghobae cc29d03
feat(readiness): register canonical buyer-visible gaps
seonghobae 3378b83
feat(readiness): attach canonical buyer-gap evidence
seonghobae c52c9a7
feat(readiness): add live buyer-gap audit entrypoint
seonghobae 3976017
fix(readiness): render capability and buyer gaps separately
seonghobae d089b6b
build(readiness): verify buyer-gap audit modules
seonghobae c9d455e
ci(readiness): reconcile canonical buyer-gap state
seonghobae 4618273
test(readiness): cover bounded buyer-gap collection
seonghobae 5e8b0b4
test(readiness): verify separated buyer-gap reporting
seonghobae 788b02f
test(readiness): verify buyer-gap CLI boundary
seonghobae 757fdf3
test(readiness): harden buyer-gap snapshot validation
seonghobae fd9d046
test(readiness): preserve capability maturity under buyer-gap evidence
seonghobae f657adb
fix(readiness): bind audit evidence to exact PR head
seonghobae 197e4f0
test(readiness): require exact-head PR audit checkout
seonghobae a48f90b
style(readiness): format buyer-gap renderer
seonghobae ee620a5
test(readiness): assert canonical buyer-gap exhaustion failures
seonghobae a9b488d
test(readiness): reject coerced buyer-gap timestamps
seonghobae c1468c8
docs(readiness): explain capability and buyer-gap report contract
seonghobae 1b01adb
test(readiness): reject non-string buyer-gap timestamps
seonghobae 7d92de1
fix(readiness): require string buyer-gap timestamps
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/commercial-readiness/src/buyer-gap-audit.test.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { mkdtemp, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { describe, it } from 'node:test'; | ||
| import { evaluateCapabilities } from './audit.mjs'; | ||
|
|
||
| const manifest = { | ||
| capabilities: [ | ||
| { | ||
| id: 'planning.durable-data', | ||
| outcome: 'Durable planning works.', | ||
| target_maturity: 'production', | ||
| customer_impact: 5, | ||
| risk: 5, | ||
| acquisition_impact: 5, | ||
| effort: 1, | ||
| dependencies: [], | ||
| tracking_issue: 121, | ||
| evidence: [ | ||
| { | ||
| maturity: 'production', | ||
| mode: 'contains', | ||
| path: 'evidence.txt', | ||
| value: 'durable', | ||
| max_bytes: 1024, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| async function evaluate(rootDir, buyerGapEvidence) { | ||
| return await evaluateCapabilities(manifest, { | ||
| rootDir, | ||
| generatedAt: '2026-08-09T11:00:00.000Z', | ||
| commitSha: 'a'.repeat(40), | ||
| buyerGapEvidence, | ||
| }); | ||
| } | ||
|
|
||
| describe('evaluateCapabilities with canonical buyer-gap evidence', () => { | ||
| it('keeps the configured maturity result byte-for-byte equivalent while adding dimensions', async () => { | ||
| const rootDir = await mkdtemp(join(tmpdir(), 'life-os-buyer-gap-audit-')); | ||
| await writeFile(join(rootDir, 'evidence.txt'), 'durable', 'utf8'); | ||
|
|
||
| const legacy = await evaluate(rootDir, undefined); | ||
| const enriched = await evaluate(rootDir, { | ||
| unresolved: [ | ||
| { | ||
| gap_id: 'today.multi-device-sync', | ||
| issue_number: 121, | ||
| capability_ids: ['planning.durable-data'], | ||
| state: 'open', | ||
| resolution: null, | ||
| }, | ||
| ], | ||
| resolved: [], | ||
| unknown: [], | ||
| }); | ||
|
|
||
| assert.deepEqual(enriched.capabilities, legacy.capabilities); | ||
| assert.deepEqual(enriched.gaps, legacy.gaps); | ||
| assert.equal( | ||
| enriched.summary.weighted_maturity_percent, | ||
| legacy.summary.weighted_maturity_percent, | ||
| ); | ||
| assert.equal(enriched.summary.unresolved_gaps, legacy.summary.unresolved_gaps); | ||
| assert.equal(enriched.summary.capability_evidence_gaps, 0); | ||
| assert.equal(enriched.summary.unresolved_buyer_gaps, 1); | ||
| assert.equal(enriched.summary.unknown_buyer_gap_states, 0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #!/usr/bin/env node | ||
| import { lstat, mkdir, readFile, rename, writeFile } from 'node:fs/promises'; | ||
| import { dirname, resolve } from 'node:path'; | ||
| import { pathToFileURL } from 'node:url'; | ||
| import { randomUUID } from 'node:crypto'; | ||
| import { evaluateCapabilities } from './audit.mjs'; | ||
| import { | ||
| collectBuyerGapSnapshot, | ||
| evaluateBuyerGaps, | ||
| validateBuyerGapRegistry, | ||
| } from './buyer-gaps.mjs'; | ||
| import { GitHubApiClient } from './github-client.mjs'; | ||
| import { renderCommercialReadinessIssue } from './render.mjs'; | ||
| import { | ||
| validateCapabilityManifest, | ||
| validateCommercialReadinessPolicy, | ||
| validateGitHubSnapshot, | ||
| } from './schema.mjs'; | ||
|
|
||
| const FLAG_TO_KEY = Object.freeze({ | ||
| '--repository': 'repository', | ||
| '--manifest': 'manifest', | ||
| '--buyer-gaps': 'buyerGaps', | ||
| '--snapshot': 'snapshot', | ||
| '--policy': 'policy', | ||
| '--root': 'root', | ||
| '--output-json': 'outputJson', | ||
| '--output-markdown': 'outputMarkdown', | ||
| }); | ||
| const REQUIRED_KEYS = Object.freeze(Object.values(FLAG_TO_KEY)); | ||
|
|
||
| function invalidCommand() { | ||
| throw new Error('Invalid buyer gap audit command'); | ||
| } | ||
|
|
||
| /** Parses the fixed, non-shell commercial buyer-gap audit command surface. */ | ||
| export function parseBuyerGapArguments(argv) { | ||
| if (!Array.isArray(argv)) invalidCommand(); | ||
| const options = {}; | ||
| for (let index = 0; index < argv.length; index += 1) { | ||
| const key = FLAG_TO_KEY[argv[index]]; | ||
| if (!key || Object.hasOwn(options, key)) invalidCommand(); | ||
| const value = argv[index + 1]; | ||
| if ( | ||
| typeof value !== 'string' || | ||
| !value || | ||
| value.startsWith('--') || | ||
| value.length > 500 || | ||
| /[\u0000-\u001f\u007f]/u.test(value) | ||
| ) { | ||
| invalidCommand(); | ||
| } | ||
| options[key] = value; | ||
| index += 1; | ||
| } | ||
| if (REQUIRED_KEYS.some((key) => !Object.hasOwn(options, key))) invalidCommand(); | ||
| return options; | ||
| } | ||
|
|
||
| async function readJson(path, maxBytes = 1024 * 1024) { | ||
| const metadata = await lstat(path); | ||
| if (metadata.isSymbolicLink() || !metadata.isFile()) { | ||
| throw new Error('Buyer gap audit input must be a regular file'); | ||
| } | ||
| if (metadata.size > maxBytes) { | ||
| throw new Error('Buyer gap audit input exceeded the size limit'); | ||
| } | ||
| try { | ||
| return JSON.parse(await readFile(path, 'utf8')); | ||
| } catch (error) { | ||
| if (error instanceof SyntaxError) throw new Error('Buyer gap audit JSON was invalid'); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| async function writeAtomic(path, content) { | ||
| const target = resolve(path); | ||
| await mkdir(dirname(target), { recursive: true }); | ||
| const temporary = `${target}.${randomUUID()}.tmp`; | ||
| await writeFile(temporary, content, { encoding: 'utf8', mode: 0o600 }); | ||
| await rename(temporary, target); | ||
| } | ||
|
|
||
| /** Runs the capability audit and canonical buyer-gap reconciliation together. */ | ||
| export async function runBuyerGapAudit(options, environment = process.env) { | ||
| const [manifestValue, registryValue, snapshotValue, policyValue] = await Promise.all([ | ||
| readJson(options.manifest), | ||
| readJson(options.buyerGaps), | ||
| readJson(options.snapshot), | ||
| readJson(options.policy), | ||
| ]); | ||
| const manifest = validateCapabilityManifest(manifestValue); | ||
| const registry = validateBuyerGapRegistry(registryValue, manifest); | ||
| const snapshot = validateGitHubSnapshot(snapshotValue); | ||
| const policy = validateCommercialReadinessPolicy(policyValue); | ||
| const token = environment.GITHUB_TOKEN; | ||
| if (typeof token !== 'string' || !token.trim()) { | ||
| throw new Error('GitHub token is required'); | ||
| } | ||
| const client = new GitHubApiClient({ token }); | ||
| const gapSnapshot = await collectBuyerGapSnapshot( | ||
| client, | ||
| options.repository, | ||
| registry, | ||
| snapshot.generated_at, | ||
| ); | ||
| const buyerGapEvidence = evaluateBuyerGaps(registry, gapSnapshot); | ||
| const report = await evaluateCapabilities(manifest, { | ||
| rootDir: options.root, | ||
| generatedAt: snapshot.generated_at, | ||
| commitSha: snapshot.commit_sha, | ||
| buyerGapEvidence, | ||
| }); | ||
| const markdown = renderCommercialReadinessIssue(report, snapshot, { | ||
| marker: policy.readiness_issue_marker, | ||
| maxGaps: 20, | ||
| }); | ||
| await Promise.all([ | ||
| writeAtomic(options.outputJson, `${JSON.stringify(report, null, 2)}\n`), | ||
| writeAtomic(options.outputMarkdown, markdown), | ||
| ]); | ||
| return report; | ||
| } | ||
|
|
||
| async function main(argv = process.argv.slice(2)) { | ||
| const options = parseBuyerGapArguments(argv); | ||
| const report = await runBuyerGapAudit(options); | ||
| console.log( | ||
| `audit: ${report.summary.capability_evidence_gaps} capability evidence gap(s), ${report.summary.unresolved_buyer_gaps} canonical buyer gap(s), ${report.summary.unknown_buyer_gap_states} unknown buyer-gap state(s)`, | ||
| ); | ||
| } | ||
|
|
||
| const invokedPath = process.argv[1]; | ||
| if (invokedPath && import.meta.url === pathToFileURL(invokedPath).href) { | ||
| main().catch((error) => { | ||
| console.error( | ||
| error instanceof Error ? error.message : 'Buyer gap audit failed', | ||
| ); | ||
| process.exitCode = 1; | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
| import { parseBuyerGapArguments } from './buyer-gap-cli.mjs'; | ||
|
|
||
| const validArguments = [ | ||
| '--repository', | ||
| 'ContextualWisdomLab/life-os', | ||
| '--manifest', | ||
| 'product/capabilities.json', | ||
| '--buyer-gaps', | ||
| 'product/buyer-gaps.json', | ||
| '--snapshot', | ||
| 'evidence/github-snapshot.json', | ||
| '--policy', | ||
| 'product/commercial-readiness-policy.json', | ||
| '--root', | ||
| '.', | ||
| '--output-json', | ||
| 'evidence/commercial-readiness.json', | ||
| '--output-markdown', | ||
| 'evidence/commercial-readiness.md', | ||
| ]; | ||
|
|
||
| describe('parseBuyerGapArguments', () => { | ||
| it('accepts the fixed bounded workflow surface', () => { | ||
| assert.deepEqual(parseBuyerGapArguments(validArguments), { | ||
| repository: 'ContextualWisdomLab/life-os', | ||
| manifest: 'product/capabilities.json', | ||
| buyerGaps: 'product/buyer-gaps.json', | ||
| snapshot: 'evidence/github-snapshot.json', | ||
| policy: 'product/commercial-readiness-policy.json', | ||
| root: '.', | ||
| outputJson: 'evidence/commercial-readiness.json', | ||
| outputMarkdown: 'evidence/commercial-readiness.md', | ||
| }); | ||
| }); | ||
|
|
||
| it('rejects unknown, duplicate, missing, and control-character arguments', () => { | ||
| for (const argv of [ | ||
| validArguments.slice(0, -2), | ||
| [...validArguments, '--unknown', 'value'], | ||
| [...validArguments, '--root', '.'], | ||
| validArguments.map((value, index) => | ||
| index === 1 ? 'ContextualWisdomLab/life-os\nother' : value, | ||
| ), | ||
| ]) { | ||
| assert.throws( | ||
| () => parseBuyerGapArguments(argv), | ||
| /Invalid buyer gap audit command/, | ||
| ); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.