feat: add global exceptions

This commit is contained in:
Justin Lin committed 2025-04-21 11:41:07 +08:00
1 parent fb823814e0
commit cfce5ececa
6 files changed
+71 -5

No files matched your search

+30
View File
@@ -43,6 +43,24 @@ const quest: IQuest = {
response: { type: 'narrative', content: 'Narrative 2' },
},
],
exceptions: [
{
id: 'exception3',
condition: {
command: 'rm',
},
response: { type: 'narrative', content: 'Exception 3' },
requirements: [],
},
{
id: 'exception4',
condition: {
command: 'mv',
},
response: { type: 'narrative', content: 'Exception 4' },
requirements: ['stage1'],
},
],
}
describe('exceptions', () => {
@@ -57,4 +75,16 @@ describe('exceptions', () => {
console.log('completed', session.completedStages)
expect(await session.runCommand({ command: 'ls' })).toBe('stage2')
})
it('should return the global exception', async () => {
const session = new Session(
{ completedStages: [] },
quest,
new MockFileChecker()
)
expect(await session.runCommand({ command: 'rm' })).toBe('exception3')
expect(await session.runCommand({ command: 'mv' })).toBeNull()
session.complete('stage1')
expect(await session.runCommand({ command: 'mv' })).toBe('exception4')
})
})