feat(mystery): parseEnding — markdown to typed Ending

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 09:17:11 -05:00
parent e108ca16e0
commit e60844a937
2 changed files with 50 additions and 2 deletions
+33 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { parseRoom, parseItem } from './loader'
import { parseRoom, parseItem, parseEnding } from './loader'
const FOYER_MD = `---
id: foyer
@@ -214,3 +214,35 @@ takeable: false
expect(() => parseItem(md, 'items/x.md')).toThrow(/empty long description/i)
})
})
const TRUE_ENDING_MD = `---
id: true
whenFlags:
ratGone: true
---
You stand at the top of the stair. The thing below has settled.
The door behind you opens, and outside, finally, is morning.
`
describe('parseEnding', () => {
it('parses an ending with flags and prose', () => {
const result = parseEnding(TRUE_ENDING_MD, 'endings/true.md')
expect(result.id).toBe('true')
expect(result.ending.whenFlags).toEqual({ ratGone: true })
expect(result.ending.narration).toBe(
'You stand at the top of the stair. The thing below has settled.\n\nThe door behind you opens, and outside, finally, is morning.',
)
})
it('accepts an empty body (unreachable ending stub)', () => {
const md = `---
id: wrong
whenFlags: {}
---
`
const result = parseEnding(md, 'endings/wrong.md')
expect(result.ending.narration).toBe('')
})
})