import { SUPPORTED_CONTRACT_VERSIONS } from '../../manifest/contracts'; import type { Check } from './types'; interface ManifestWithContract { celilo_contract?: string; } /** * Compares the manifest's declared `celilo_contract` against the framework's * supported set: * * - `ok` — claim equals the latest supported contract. * - `warn` — claim is older but still supported. The manifest works, but * new contract features won't be available. * - `fail` — claim is unknown to the framework (typo, future version * from a newer celilo, etc.). Manifest schema validation * already catches this case more loudly; we still report it * so a `module check` against a manifest with a bad contract * highlights it as a contract-level problem. * * Today the framework only ships contract "1.0", so the warn branch is * forward-looking; once "1.1" lands, modules still on "1.0" will see a * minor-bump suggestion. */ export function checkContractVersion(manifest: ManifestWithContract): Check { const claimed = manifest.celilo_contract; const supported = SUPPORTED_CONTRACT_VERSIONS; const latest = supported[supported.length - 1]; if (!claimed) { return { category: 'contract_version', name: 'celilo_contract', status: 'fail', message: 'manifest is missing the celilo_contract field', suggestedValue: latest, }; } if (claimed === latest) { return { category: 'contract_version', name: 'celilo_contract', status: 'ok', message: `manifest declares celilo_contract: ${claimed} (latest)`, currentValue: claimed, }; } if ((supported as readonly string[]).includes(claimed)) { return { category: 'contract_version', name: 'celilo_contract', status: 'warn', message: `manifest declares celilo_contract: ${claimed} (still supported, but ${latest} is available)`, currentValue: claimed, suggestedValue: latest, }; } return { category: 'contract_version', name: 'celilo_contract', status: 'fail', message: `manifest declares celilo_contract: ${claimed} (unknown to this framework — supported: ${supported.join(', ')})`, currentValue: claimed, suggestedValue: latest, }; }