From 00c12febbeef829e144a8d301ba77e2bb8097e52 Mon Sep 17 00:00:00 2001 From: e0425bed061809c5ce17450fe47dc970090a0938 Date: Fri, 2 Oct 2026 06:52:45 +0000 Subject: [PATCH] Solution 0x2a7b6a284a867d4e10849050698c3956c5f7840a3bc29190fc7798287e6da0b9 T2T-Item: 0x2a7b6a284a867d4e10849050698c3956c5f7840a3bc29190fc7798287e6da0b9 T2T-Issue: 0xce1f03063035e40185e7b2778dce2cf95081649b1257ecb171218cf78a9dda3c --- tests/acceptance/5/CRITERIA.json | 24 ++++++++++++++++++++++++ tests/acceptance/5/criteria.test.js | 20 ++++++++++++++++++++ web/js/skills.js | 5 +++-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 tests/acceptance/5/CRITERIA.json create mode 100644 tests/acceptance/5/criteria.test.js diff --git a/tests/acceptance/5/CRITERIA.json b/tests/acceptance/5/CRITERIA.json new file mode 100644 index 0000000..e9eba52 --- /dev/null +++ b/tests/acceptance/5/CRITERIA.json @@ -0,0 +1,24 @@ +{ + "schema": "elffuss-t2t/criteria@2", + "issue": 5, + "criteria": [ + { + "index": 1, + "tests": [ + "tests/acceptance/5/criteria.test.js::criterion 1" + ] + }, + { + "index": 2, + "tests": [ + "tests/acceptance/5/criteria.test.js::criterion 2" + ] + }, + { + "index": 3, + "tests": [ + "tests/acceptance/5/criteria.test.js::criterion 3" + ] + } + ] +} diff --git a/tests/acceptance/5/criteria.test.js b/tests/acceptance/5/criteria.test.js new file mode 100644 index 0000000..5794ff4 --- /dev/null +++ b/tests/acceptance/5/criteria.test.js @@ -0,0 +1,20 @@ +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import * as mod from '../../../web/js/skills.js' // the code under test: call it as mod.(...) +const source = readFileSync(new URL('../../../web/js/skills.js', import.meta.url), 'utf8') // the text of web/js/skills.js, for a criterion about how the file is written + +test('criterion 1', () => { + // `parseSkill("---\r\nname: demo\r\ndescription: x\r\n---\r\nBody")` returns `{ name: "demo", description: "x", content: "Body" }`. + assert.deepEqual(mod.parseSkill("---\r\nname: demo\r\ndescription: x\r\n---\r\nBody"), { name: "demo", description: "x", content: "Body" }) +}) + +test('criterion 2', () => { + // `parseSkill("---\nname: demo\ndescription: x\n---\nBody")` returns `{ name: "demo", description: "x", content: "Body" }`. + assert.deepEqual(mod.parseSkill("---\nname: demo\ndescription: x\n---\nBody"), { name: "demo", description: "x", content: "Body" }) +}) + +test('criterion 3', () => { + // `parseSkill("Body only", "fallback")` returns `{ name: "fallback", description: "", content: "Body only" }`. + assert.deepEqual(mod.parseSkill("Body only", "fallback"), { name: "fallback", description: "", content: "Body only" }) +}) diff --git a/web/js/skills.js b/web/js/skills.js index 6effe6b..45d80c2 100644 --- a/web/js/skills.js +++ b/web/js/skills.js @@ -131,11 +131,12 @@ export async function installFromRepo(entry) { // SKILL.md → { name, description, content } export function parseSkill(md, fallbackName = 'skill') { - const fm = md.match(/^---\n([\s\S]*?)\n---/); + const normalizedMd = md.replace(/\r\n/g, '\n'); + const fm = normalizedMd.match(/^---\n([\s\S]*?)\n---/); const meta = fm?.[1] || ''; const name = meta.match(/^name:\s*(.+)$/m)?.[1]?.trim() || fallbackName; const description = (meta.match(/^description:\s*([\s\S]+?)(?:\n\w+:|$)/m)?.[1] || '').replace(/\s+/g, ' ').trim(); - const content = md.replace(/^---\n[\s\S]*?\n---\n?/, '').trim(); + const content = normalizedMd.replace(/^---\n[\s\S]*?\n---\n?/, '').trim(); return { name, description, content }; }