#!/usr/bin/env node /** * Validate one workflow catalog YAML with the plugin's own restricted parser, * strict schema and static validation (schema/static review per PRD A2 ยง11). * * Usage: node scripts/validate-catalog.mjs [workflowId] */ import { readFileSync } from 'node:fs' import { parseCatalogConfig } from '../src/catalog/parse.ts' import { validateAndNormalize, computeDefinitionHash } from '../src/catalog/validate.ts' const file = process.argv[2] if (file === undefined) { console.error('usage: node scripts/validate-catalog.mjs [workflowId]') process.exit(2) } const workflowId = process.argv[3] ?? 'milestone-delivery' try { const text = readFileSync(file, 'utf8') const parsed = parseCatalogConfig(text) const warnings = [] const normalized = validateAndNormalize(structuredClone(parsed), { workflowId, warnings }) const hash = computeDefinitionHash(normalized) const root = normalized.workflow const countNodes = def => Object.keys(def.nodes).length console.log(`OK ${file}`) console.log(`workflowId=${workflowId} definitionHash=${hash}`) console.log(`root: startNode=${root.startNode}, ${countNodes(root)} nodes`) for (const [id, def] of Object.entries(normalized.childWorkflows ?? {})) { console.log(`child ${id}: startNode=${def.startNode}, ${countNodes(def)} nodes`) } // #59: non-blocking warnings still keep the file OK. for (const warning of warnings) console.warn(`WARN ${file}: ${warning}`) } catch (error) { console.error(`INVALID ${file}: ${String(error)}`) process.exit(1) }