(filePath: string)
| 22 | } |
| 23 | |
| 24 | async validateSpec(filePath: string): Promise<ValidationReport> { |
| 25 | const issues: ValidationIssue[] = []; |
| 26 | const specName = this.extractNameFromPath(filePath); |
| 27 | try { |
| 28 | const content = readFileSync(filePath, 'utf-8'); |
| 29 | const parser = new MarkdownParser(content); |
| 30 | |
| 31 | const spec = parser.parseSpec(specName); |
| 32 | |
| 33 | const result = SpecSchema.safeParse(spec); |
| 34 | |
| 35 | if (!result.success) { |
| 36 | issues.push(...this.convertZodErrors(result.error)); |
| 37 | } |
| 38 | |
| 39 | issues.push(...this.applySpecRules(spec, content)); |
| 40 | |
| 41 | } catch (error) { |
| 42 | const baseMessage = error instanceof Error ? error.message : 'Unknown error'; |
| 43 | const enriched = this.enrichTopLevelError(specName, baseMessage); |
| 44 | issues.push({ |
| 45 | level: 'ERROR', |
| 46 | path: 'file', |
| 47 | message: enriched, |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | return this.createReport(issues); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Validate spec content from a string (used for pre-write validation of rebuilt specs) |
no test coverage detected