Skip to content
Open
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
74 changes: 74 additions & 0 deletions src/fixtures/review-validation-failed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"review": {
"reviewScore": 18
},
"validation": {
"checks": [
{
"name": "skill_md_line_count",
"status": "passed",
"message": "SKILL.md line count is 171 (<= 500)",
"details": {
"line_count": 171,
"max_lines": 500
}
},
{
"name": "frontmatter_valid",
"status": "passed",
"message": "YAML frontmatter is valid",
"details": {
"keys": ["name", "description"]
}
},
{
"name": "name_field",
"status": "passed",
"message": "'name' field is valid: 'legibility-review'",
"details": {
"value": "legibility-review",
"length": 17
}
},
{
"name": "description_field",
"status": "error",
"message": "'description' must not contain XML tags",
"details": {
"length": 915
}
},
{
"name": "body_present",
"status": "passed",
"message": "SKILL.md body is present",
"details": {
"body_chars": 17335
}
}
],
"overallPassed": false,
"errorCount": 1,
"warningCount": 0,
"skillName": "legibility-review",
"skillDescription": "How to review code so a reader without your context can understand each piece."
},
"contentJudge": {
"success": true,
"evaluation": {
"scores": {
"conciseness": {
"score": 0,
"reasoning": "Deterministic validation failed; LLM judge was not run."
}
},
"overall_assessment": "Skill failed deterministic validation. LLM judge evaluation was skipped.",
"suggestions": [
"Fix the deterministic validation errors before running LLM judge."
],
"validation_skipped": true
},
"weightedScore": 0,
"normalizedScore": 0
}
}
45 changes: 43 additions & 2 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,23 @@ describe('runSkillReview', () => {
normalizedScore: 0.85,
evaluation: 'Good skill definition.',
},
validation: { output: 'All checks passed.' },
validation: {
checks: [
{
name: 'frontmatter_valid',
status: 'passed',
message: 'YAML frontmatter is valid',
},
{
name: 'body_present',
status: 'passed',
message: 'SKILL.md body is present',
},
],
overallPassed: true,
errorCount: 0,
warningCount: 0,
},
});

// @ts-expect-error mock assignment
Expand All @@ -269,10 +285,35 @@ describe('runSkillReview', () => {
expect(result.score).toBe(85);
expect(result.passed).toBe(true);
expect(result.error).toBeUndefined();
expect(result.output).toContain('All checks passed.');
expect(result.output).toContain('### Validation Checks');
expect(result.output).toContain('Validation passed');
expect(result.output).toContain('YAML frontmatter is valid');
expect(result.output).toContain('SKILL.md body is present');
expect(result.output).toContain('Good skill definition.');
});

test('renders failing validation checks from golden fixture', async () => {
const fixture = await Bun.file(
new URL('./fixtures/review-validation-failed.json', import.meta.url),
).text();

// @ts-expect-error mock assignment
Bun.spawn = makeMockSpawn(fixture, '', 0);

const result = await runSkillReview('skills/legibility-review/SKILL.md', 0);
expect(result.output).toContain('### Validation Checks');
// Summary reflects the failing run.
expect(result.output).toContain('Validation failed');
expect(result.output).toContain('1 error(s)');
// The failing "error" check is rendered with its message and marker.
expect(result.output).toContain('description field');
expect(result.output).toContain("'description' must not contain XML tags");
expect(result.output).toContain('❌');
// A passing check is also rendered.
expect(result.output).toContain('YAML frontmatter is valid');
expect(result.output).toContain('✅');
});

test('CLI failure (non-zero exit)', async () => {
// @ts-expect-error mock assignment
Bun.spawn = makeMockSpawn('', 'Command not found', 1);
Expand Down
53 changes: 46 additions & 7 deletions src/skill-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,49 @@ function formatEvaluation(value: unknown): string {
return parts.length > 0 ? parts.join('\n') : JSON.stringify(value, null, 2);
}

/** Safely convert an unknown value to a readable string */
function stringify(value: unknown): string {
if (typeof value === 'string') return value;
return JSON.stringify(value, null, 2);
interface ValidationCheck {
name: string;
status: 'passed' | 'warning' | 'error';
message: string;
}

interface Validation {
checks?: ValidationCheck[];
overallPassed?: boolean;
errorCount?: number;
warningCount?: number;
}

/** Marker emoji for a validation check status */
function statusMarker(status: ValidationCheck['status']): string {
if (status === 'passed') return '✅';
if (status === 'warning') return '⚠️';
return '❌';
}

/** Render validation checks into a readable markdown table with a summary line. */
function formatValidation(validation: Validation): string {
const parts: string[] = [];

const passed = validation.overallPassed ? 'passed' : 'failed';
const errors = validation.errorCount ?? 0;
const warnings = validation.warningCount ?? 0;
parts.push(
`**Validation ${passed}** — ${errors} error(s), ${warnings} warning(s)`,
);

const checks = validation.checks ?? [];
if (checks.length > 0) {
parts.push('', '| | Check | Message |', '|--|-------|---------|');
for (const check of checks) {
const label = check.name.replace(/_/g, ' ');
parts.push(
`| ${statusMarker(check.status)} | **${label}** | ${check.message} |`,
);
}
}

return parts.join('\n');
}

/**
Expand Down Expand Up @@ -154,7 +193,7 @@ export async function runSkillReview(
}
let parsed: {
contentJudge?: { normalizedScore?: number; evaluation?: unknown };
validation?: { output?: unknown };
validation?: Validation;
};

try {
Expand All @@ -174,9 +213,9 @@ export async function runSkillReview(
const score = Math.round(normalizedScore * 100);

const outputParts: string[] = [];
if (parsed.validation?.output) {
if (parsed.validation?.checks && parsed.validation.checks.length > 0) {
outputParts.push(
'### Validation Checks\n\n' + stringify(parsed.validation.output),
'### Validation Checks\n\n' + formatValidation(parsed.validation),
);
}
if (parsed.contentJudge?.evaluation) {
Expand Down