diff --git a/scripts/consumer-freshness.mjs b/scripts/consumer-freshness.mjs index 41bf956..ea0b95c 100644 --- a/scripts/consumer-freshness.mjs +++ b/scripts/consumer-freshness.mjs @@ -43,18 +43,26 @@ export async function readPinnedManifest(lock, fetchBytes = get) { export async function auditConsumers(expected, fetchBytes = get) { const targets = [ - ['cli', 'https://raw.githubusercontent.com/stack-sh/cli/main/skills/docs-source.json'], - ['web', 'https://raw.githubusercontent.com/stack-sh/web/main/scripts/docs-source.json'], + ['cli', 'skills/docs-source.json'], + ['web', 'scripts/docs-source.json'], ['production', 'https://stack-diagram.com/docs-source.json'], ]; const errors = []; - for (const [kind, url] of targets) { + for (const [kind, resource] of targets) { try { + let base; + if (kind !== 'production') { + const ref = JSON.parse((await fetchBytes(`https://api.github.com/repos/stack-sh/${kind}/git/ref/heads/main`)).toString('utf8')); + assert.equal(ref.object.type, 'commit'); + assert.match(ref.object.sha, /^[a-f0-9]{40}$/); + base = `https://raw.githubusercontent.com/stack-sh/${kind}/${ref.object.sha}/`; + } + const url = kind === 'production' ? resource : base + resource; const lock = JSON.parse((await fetchBytes(url)).toString('utf8')); const actual = await readPinnedManifest(lock, fetchBytes); compareConsumer(expected, actual, kind); if (kind === 'cli') { - const skill = await fetchBytes('https://raw.githubusercontent.com/stack-sh/cli/main/skills/stack-diagrams/SKILL.md'); + const skill = await fetchBytes(base + 'skills/stack-diagrams/SKILL.md'); assert.equal(digest(skill), expected.files.find(file => file.path === skillPath).sha256, 'CLI skill differs from the canonical generated bytes'); } console.log(`${kind}: canonical generated content is current (${lock.revision}).`); diff --git a/scripts/consumer-freshness.test.mjs b/scripts/consumer-freshness.test.mjs index e815370..75b9073 100644 --- a/scripts/consumer-freshness.test.mjs +++ b/scripts/consumer-freshness.test.mjs @@ -37,7 +37,7 @@ test('verifies pinned manifest integrity and rejects mutable revisions', async ( test('checks actual installed skill bytes and reports stale production separately', async () => { const bytes = Buffer.from(JSON.stringify(manifest)); const lock = Buffer.from(JSON.stringify({ repository: 'stack-sh/docs', revision: 'a'.repeat(40), manifestSha256: hash(bytes) })); - const fetchBytes = async url => url.endsWith('/generated/manifest.json') ? bytes : url.endsWith('/SKILL.md') ? Buffer.from(skill) : lock; + const fetchBytes = async url => url.includes('/git/ref/heads/main') ? Buffer.from(JSON.stringify({ object: { type: 'commit', sha: 'b'.repeat(40) } })) : url.endsWith('/generated/manifest.json') ? bytes : url.endsWith('/SKILL.md') ? Buffer.from(skill) : lock; await auditConsumers(manifest, fetchBytes); await assert.rejects(auditConsumers(manifest, async url => url.endsWith('/SKILL.md') ? Buffer.from('hand edited') : fetchBytes(url)), /CLI skill differs/); await assert.rejects(auditConsumers(manifest, async url => {