diff --git a/.github/workflows/reusable-defensible-vertical-slice.yml b/.github/workflows/reusable-defensible-vertical-slice.yml index 33dbc8f..8fb2230 100644 --- a/.github/workflows/reusable-defensible-vertical-slice.yml +++ b/.github/workflows/reusable-defensible-vertical-slice.yml @@ -50,7 +50,31 @@ jobs: const missing = required.filter(k => !(k in p)); if (missing.length) throw new Error(`Missing profile keys: ${missing.join(', ')}`); if (p.schema_version !== 1) throw new Error('Unsupported profile schema_version'); - if (p.repository !== process.env.GITHUB_REPOSITORY) throw new Error(`Profile repository ${p.repository} does not match ${process.env.GITHUB_REPOSITORY}`); + const idPresent = p.repository_id !== undefined && process.env.GITHUB_REPOSITORY_ID !== undefined; + const idMatch = idPresent && String(p.repository_id) === String(process.env.GITHUB_REPOSITORY_ID); + const formerNames = Array.isArray(p.former_repository_names) ? p.former_repository_names : []; + const nameMatch = p.repository === process.env.GITHUB_REPOSITORY || formerNames.includes(process.env.GITHUB_REPOSITORY); + // Stable IDs are authoritative when both sides expose one. A name match must not + // rescue a profile whose explicit repository_id disagrees with the runtime ID. + const identityMatch = idPresent ? idMatch : nameMatch; + if (!identityMatch) throw new Error(`Profile identity mismatch: profile repository=${p.repository} former_repository_names=${JSON.stringify(formerNames)} repository_id=${p.repository_id ?? 'unset'}; runtime GITHUB_REPOSITORY=${process.env.GITHUB_REPOSITORY} GITHUB_REPOSITORY_ID=${process.env.GITHUB_REPOSITORY_ID}`); + if (idPresent && idMatch && nameMatch === false) console.log('Repository identity verified by stable ID; name is historical or renamed.'); + // Deterministic precedence tests: ID-only, former-name-only, legacy current-name, + // neither, and wrong-ID/name-match must remain distinguishable. + const cases = [ + { profileId: process.env.GITHUB_REPOSITORY_ID, profileName: '__no_match__', former: [], expected: true }, + { profileId: undefined, profileName: '__no_match__', former: [process.env.GITHUB_REPOSITORY], expected: true }, + { profileId: undefined, profileName: process.env.GITHUB_REPOSITORY, former: [], expected: true }, + { profileId: undefined, profileName: '__no_match__', former: [], expected: false }, + { profileId: '0', profileName: process.env.GITHUB_REPOSITORY, former: [], expected: false }, + ]; + for (const c of cases) { + const present = c.profileId !== undefined && process.env.GITHUB_REPOSITORY_ID !== undefined; + const match = present + ? String(c.profileId) === String(process.env.GITHUB_REPOSITORY_ID) + : c.profileName === process.env.GITHUB_REPOSITORY || c.former.includes(process.env.GITHUB_REPOSITORY); + if (match !== c.expected) throw new Error(`Identity precedence test failed: ${JSON.stringify(c)}`); + } if (!Array.isArray(p.promotion.required_gates) || !p.promotion.required_gates.length) throw new Error('At least one promotion gate is required'); console.log(JSON.stringify(p, null, 2)); NODE diff --git a/.github/workflows/reusable-node-verify-v2.yml b/.github/workflows/reusable-node-verify-v2.yml index 86bf78f..ae6663a 100644 --- a/.github/workflows/reusable-node-verify-v2.yml +++ b/.github/workflows/reusable-node-verify-v2.yml @@ -98,8 +98,28 @@ jobs: const required = ['schema_version', 'repository', 'classification', 'runtime', 'commands', 'surfaces', 'promotion', 'evidence']; const missing = required.filter((key) => !(key in profile)); if (missing.length) throw new Error(`Missing profile keys: ${missing.join(', ')}`); - if (profile.repository !== process.env.GITHUB_REPOSITORY) { - throw new Error(`Profile repository ${profile.repository} does not match ${process.env.GITHUB_REPOSITORY}`); + const idPresent = profile.repository_id !== undefined && process.env.GITHUB_REPOSITORY_ID !== undefined; + const idMatch = idPresent && String(profile.repository_id) === String(process.env.GITHUB_REPOSITORY_ID); + const formerNames = Array.isArray(profile.former_repository_names) ? profile.former_repository_names : []; + const nameMatch = profile.repository === process.env.GITHUB_REPOSITORY || formerNames.includes(process.env.GITHUB_REPOSITORY); + // Stable IDs are authoritative when both sides expose one. A name match must not + // rescue a profile whose explicit repository_id disagrees with the runtime ID. + const identityMatch = idPresent ? idMatch : nameMatch; + if (!identityMatch) throw new Error(`Profile identity mismatch: profile repository=${profile.repository} former_repository_names=${JSON.stringify(formerNames)} repository_id=${profile.repository_id ?? 'unset'}; runtime GITHUB_REPOSITORY=${process.env.GITHUB_REPOSITORY} GITHUB_REPOSITORY_ID=${process.env.GITHUB_REPOSITORY_ID}`); + if (idPresent && idMatch && nameMatch === false) console.log('Repository identity verified by stable ID; name is historical or renamed.'); + const cases = [ + { profileId: process.env.GITHUB_REPOSITORY_ID, profileName: '__no_match__', former: [], expected: true }, + { profileId: undefined, profileName: '__no_match__', former: [process.env.GITHUB_REPOSITORY], expected: true }, + { profileId: undefined, profileName: process.env.GITHUB_REPOSITORY, former: [], expected: true }, + { profileId: undefined, profileName: '__no_match__', former: [], expected: false }, + { profileId: '0', profileName: process.env.GITHUB_REPOSITORY, former: [], expected: false }, + ]; + for (const c of cases) { + const present = c.profileId !== undefined && process.env.GITHUB_REPOSITORY_ID !== undefined; + const match = present + ? String(c.profileId) === String(process.env.GITHUB_REPOSITORY_ID) + : c.profileName === process.env.GITHUB_REPOSITORY || c.former.includes(process.env.GITHUB_REPOSITORY); + if (match !== c.expected) throw new Error(`Identity precedence test failed: ${JSON.stringify(c)}`); } if (!Array.isArray(profile.promotion?.required_gates) || profile.promotion.required_gates.length === 0) { throw new Error('promotion.required_gates must contain at least one gate'); diff --git a/schemas/repository-verification-profile.schema.json b/schemas/repository-verification-profile.schema.json index 3d0e481..e31b018 100644 --- a/schemas/repository-verification-profile.schema.json +++ b/schemas/repository-verification-profile.schema.json @@ -8,6 +8,8 @@ "properties": { "schema_version": { "const": 1 }, "repository": { "type": "string", "pattern": "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$" }, + "repository_id": { "type": "integer", "minimum": 1, "description": "Stable GitHub numeric repository id; survives transfers and renames." }, + "former_repository_names": { "type": "array", "items": { "type": "string", "pattern": "^[^/]+/[^/]+$" }, "uniqueItems": true, "description": "Historical owner/name values (e.g. pre-transfer); preserved so historical receipts remain attributable." }, "classification": { "type": "object", "additionalProperties": false,