feat(mystery): parseEncounterNarration — phase and transition prose

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 09:21:29 -05:00
parent e60844a937
commit bf8a693949
2 changed files with 65 additions and 2 deletions
+41 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { parseRoom, parseItem, parseEnding } from './loader'
import { parseRoom, parseItem, parseEnding, parseEncounterNarration } from './loader'
const FOYER_MD = `---
id: foyer
@@ -246,3 +246,43 @@ whenFlags: {}
expect(result.ending.narration).toBe('')
})
})
const RAT_MD = `---
id: rat
startsIn: "[[cellar-stair]]"
initialPhase: lurking
---
## lurking
A heavy rat watches you from the third step. Its eyes catch the light.
## attack-resolved
You stamp. The rat squeals and is gone into the dark.
## wait-stays
The rat does not move. Neither do you.
`
describe('parseEncounterNarration', () => {
it('parses frontmatter and narration sections', () => {
const doc = parseEncounterNarration(RAT_MD, 'encounters/rat.md')
expect(doc.id).toBe('rat')
expect(doc.startsIn).toBe('cellar-stair')
expect(doc.initialPhase).toBe('lurking')
expect(doc.narrations).toEqual({
lurking: 'A heavy rat watches you from the third step. Its eyes catch the light.',
'attack-resolved': 'You stamp. The rat squeals and is gone into the dark.',
'wait-stays': 'The rat does not move. Neither do you.',
})
})
it('throws when no sections are present', () => {
const md = `---
id: x
startsIn: room
initialPhase: p
---
`
expect(() => parseEncounterNarration(md, 'encounters/x.md')).toThrow(/no narration sections/i)
})
})