37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import {
|
|
GenerationReceiptError,
|
|
parseGenerationPurpose,
|
|
parseGenerationReceiptId,
|
|
} from './generation-receipt.ts'
|
|
|
|
function assert(condition: boolean, message: string): void {
|
|
if (!condition) throw new Error(message)
|
|
}
|
|
|
|
Deno.test('generation receipt purpose is explicit and fail closed', () => {
|
|
assert(parseGenerationPurpose(null) === null, 'missing purpose should preserve generic LLM calls')
|
|
assert(parseGenerationPurpose('talk_response') === 'talk_response', 'Talk purpose should be accepted')
|
|
assert(parseGenerationPurpose('command_response') === 'command_response', 'Command purpose should be accepted')
|
|
assert(parseGenerationPurpose('action_response') === 'action_response', 'Action purpose should be accepted')
|
|
let rejected = false
|
|
try {
|
|
parseGenerationPurpose('meeting_document')
|
|
} catch (error) {
|
|
rejected = error instanceof GenerationReceiptError
|
|
}
|
|
assert(rejected, 'unknown purpose should be rejected')
|
|
})
|
|
|
|
Deno.test('generation receipt RPC result requires a UUID', () => {
|
|
const id = '29100000-0000-4000-8000-000000000001'
|
|
assert(parseGenerationReceiptId({ generationId: id.toUpperCase() }) === id, 'UUID should normalize')
|
|
for (const value of [null, {}, { generationId: 'bad' }]) {
|
|
let rejected = false
|
|
try {
|
|
parseGenerationReceiptId(value)
|
|
} catch (error) {
|
|
rejected = error instanceof GenerationReceiptError
|
|
}
|
|
assert(rejected, 'invalid receipt should be rejected')
|
|
}
|
|
})
|