Skip to content

Commit e103278

Browse files
committed
test: add tests for REQUIRED_FRONTMATTER_FIELDS constant validation
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent 9ddad50 commit e103278

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

tests/paths.test.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,108 @@ describe("paths.mjs exports", () => {
434434
expect(REQUIRED_FRONTMATTER_FIELDS).toContain("requires")
435435
})
436436

437+
describe("REQUIRED_FRONTMATTER_FIELDS", () => {
438+
it("should contain exactly 'version' and 'requires' fields", () => {
439+
expect(REQUIRED_FRONTMATTER_FIELDS).toEqual(["version", "requires"])
440+
})
441+
442+
it("should have exactly 2 required fields", () => {
443+
expect(REQUIRED_FRONTMATTER_FIELDS).toHaveLength(2)
444+
})
445+
446+
it("should have 'version' as the first required field", () => {
447+
expect(REQUIRED_FRONTMATTER_FIELDS[0]).toBe("version")
448+
})
449+
450+
it("should have 'requires' as the second required field", () => {
451+
expect(REQUIRED_FRONTMATTER_FIELDS[1]).toBe("requires")
452+
})
453+
454+
it("should be exported and accessible from the module", () => {
455+
// Verify the constant is defined and has the expected type
456+
expect(REQUIRED_FRONTMATTER_FIELDS).toBeDefined()
457+
expect(typeof REQUIRED_FRONTMATTER_FIELDS).toBe("object")
458+
expect(Array.isArray(REQUIRED_FRONTMATTER_FIELDS)).toBe(true)
459+
})
460+
461+
it("should contain string values only", () => {
462+
for (const field of REQUIRED_FRONTMATTER_FIELDS) {
463+
expect(typeof field).toBe("string")
464+
}
465+
})
466+
467+
it("should not contain empty strings", () => {
468+
for (const field of REQUIRED_FRONTMATTER_FIELDS) {
469+
expect(field.length).toBeGreaterThan(0)
470+
expect(field.trim()).toBe(field)
471+
}
472+
})
473+
474+
it("should be usable in validateAgentContent for field validation", () => {
475+
// Content missing 'version' field
476+
const missingVersion = `---
477+
requires: opencode
478+
---
479+
# Test Agent
480+
481+
This is a test agent that handles various tasks for you.
482+
`.padEnd(MIN_CONTENT_LENGTH + 50, " ")
483+
484+
const result1 = validateAgentContent(missingVersion)
485+
expect(result1.valid).toBe(false)
486+
expect(result1.error).toContain("version")
487+
expect(result1.error).toContain("missing required fields")
488+
489+
// Content missing 'requires' field
490+
const missingRequires = `---
491+
version: 1.0
492+
---
493+
# Test Agent
494+
495+
This is a test agent that handles various tasks for you.
496+
`.padEnd(MIN_CONTENT_LENGTH + 50, " ")
497+
498+
const result2 = validateAgentContent(missingRequires)
499+
expect(result2.valid).toBe(false)
500+
expect(result2.error).toContain("requires")
501+
expect(result2.error).toContain("missing required fields")
502+
})
503+
504+
it("should validate all fields from the constant are present in content", () => {
505+
// Content with all required fields present
506+
const validContent = `---
507+
version: 1.0
508+
requires: opencode
509+
---
510+
# Test Agent
511+
512+
This is a test agent that handles various tasks for you.
513+
`.padEnd(MIN_CONTENT_LENGTH + 50, " ")
514+
515+
const result = validateAgentContent(validContent)
516+
expect(result.valid).toBe(true)
517+
expect(result.error).toBeUndefined()
518+
})
519+
520+
it("should report all missing fields when multiple are absent", () => {
521+
// Content missing both 'version' and 'requires' fields
522+
const missingBoth = `---
523+
name: test
524+
---
525+
# Test Agent
526+
527+
This is a test agent that handles various tasks for you.
528+
`.padEnd(MIN_CONTENT_LENGTH + 50, " ")
529+
530+
const result = validateAgentContent(missingBoth)
531+
expect(result.valid).toBe(false)
532+
expect(result.error).toContain("missing required fields")
533+
// Both fields should be mentioned
534+
expect(result.error).toContain("version")
535+
expect(result.error).toContain("requires")
536+
})
537+
})
538+
437539
it("should export TRANSIENT_ERROR_CODES as an array", () => {
438540
expect(Array.isArray(TRANSIENT_ERROR_CODES)).toBe(true)
439541
expect(TRANSIENT_ERROR_CODES).toContain("EAGAIN")

0 commit comments

Comments
 (0)