Handle Windows line-endings
This commit is contained in:
parent
4bd43ec8b9
commit
d0ef58b421
|
|
@ -38,7 +38,7 @@ function assert(condition, testName, detail) {
|
||||||
* Validates the output is well-formed YAML that parses back correctly.
|
* Validates the output is well-formed YAML that parses back correctly.
|
||||||
*/
|
*/
|
||||||
function parseOutputDescription(output) {
|
function parseOutputDescription(output) {
|
||||||
const match = output.match(/^---\n([\s\S]*?)\n---/);
|
const match = output.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
const parsed = yaml.parse(match[1]);
|
const parsed = yaml.parse(match[1]);
|
||||||
return parsed?.description;
|
return parsed?.description;
|
||||||
|
|
@ -103,6 +103,15 @@ console.log(`\n${colors.cyan}CodexSetup.transformToSkillFormat tests${colors.res
|
||||||
assert(result.includes('Just some content without frontmatter.'), 'body preserved when no frontmatter');
|
assert(result.includes('Just some content without frontmatter.'), 'body preserved when no frontmatter');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- CRLF frontmatter is parsed correctly (Windows line endings) ---
|
||||||
|
{
|
||||||
|
const input = '---\r\ndescription: windows line endings\r\n---\r\n\r\nBody.';
|
||||||
|
const result = setup.transformToSkillFormat(input, 'crlf-skill');
|
||||||
|
const desc = parseOutputDescription(result);
|
||||||
|
assert(desc === 'windows line endings', 'CRLF frontmatter parses correctly', `got description: ${JSON.stringify(desc)}`);
|
||||||
|
assert(result.includes('Body.'), 'body preserved for CRLF input');
|
||||||
|
}
|
||||||
|
|
||||||
// --- Summary ---
|
// --- Summary ---
|
||||||
console.log(`\n${passed} passed, ${failed} failed\n`);
|
console.log(`\n${passed} passed, ${failed} failed\n`);
|
||||||
process.exit(failed > 0 ? 1 : 0);
|
process.exit(failed > 0 ? 1 : 0);
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ class CodexSetup extends BaseIdeSetup {
|
||||||
*/
|
*/
|
||||||
transformToSkillFormat(content, skillName) {
|
transformToSkillFormat(content, skillName) {
|
||||||
// Parse frontmatter
|
// Parse frontmatter
|
||||||
const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
|
||||||
if (!fmMatch) {
|
if (!fmMatch) {
|
||||||
// No frontmatter -- wrap with minimal frontmatter
|
// No frontmatter -- wrap with minimal frontmatter
|
||||||
return `---\nname: ${skillName}\ndescription: '${skillName}'\n---\n\n${content}`;
|
return `---\nname: ${skillName}\ndescription: '${skillName}'\n---\n\n${content}`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue