mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: add global exceptions
This commit is contained in:
1 parent
fb823814e0
commit
cfce5ececa
6 files changed
+71
-5
No files matched your search
@@ -5,6 +5,7 @@ import { PwdMatcher } from '../src/condition/PwdMatcher'
|
||||
import { CommandMatcher } from '../src/condition/CommandMatcher'
|
||||
import { ErrorMatcher } from '../src/condition/ErrorMatcher.js'
|
||||
import { conditionSchema } from '../src/schema'
|
||||
import { MockFileChecker } from './asyncCondition.test'
|
||||
|
||||
test('command match', () => {
|
||||
const matcher = new CommandMatcher('^echo start$')
|
||||
@@ -92,3 +93,10 @@ it('should parse condition', () => {
|
||||
}
|
||||
expect(conditionSchema.safeParse(condition).error).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should not match empty condition', async () => {
|
||||
const condition = new Condition({})
|
||||
expect(
|
||||
await condition.satisfies({ command: 'echo start' }, new MockFileChecker())
|
||||
).toBe(false)
|
||||
})
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user