Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions scripts/consumer-freshness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}).`);
Expand Down
2 changes: 1 addition & 1 deletion scripts/consumer-freshness.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down