47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import {
|
|
cancelPascalAgentJob,
|
|
finishPascalAgentJob,
|
|
isPascalAgentJobActive,
|
|
startPascalAgentJob,
|
|
} from './pascal-agent-jobs'
|
|
|
|
describe('Pascal agent background jobs', () => {
|
|
test('keeps one active job per owner and conversation', () => {
|
|
const input = {
|
|
conversationId: crypto.randomUUID(),
|
|
ownerId: 'owner-a',
|
|
sceneId: 'scene-a',
|
|
}
|
|
const job = startPascalAgentJob(input)
|
|
|
|
expect(job).not.toBeNull()
|
|
expect(startPascalAgentJob(input)).toBeNull()
|
|
expect(isPascalAgentJobActive(input)).toBe(true)
|
|
|
|
finishPascalAgentJob(job)
|
|
expect(isPascalAgentJobActive(input)).toBe(false)
|
|
})
|
|
|
|
test('cancels only the matching owner, conversation, and scene', () => {
|
|
const input = {
|
|
conversationId: crypto.randomUUID(),
|
|
ownerId: 'owner-b',
|
|
sceneId: 'scene-b',
|
|
}
|
|
const job = startPascalAgentJob(input)
|
|
|
|
expect(
|
|
cancelPascalAgentJob({
|
|
...input,
|
|
sceneId: 'other-scene',
|
|
}),
|
|
).toBe(false)
|
|
expect(cancelPascalAgentJob(input)).toBe(true)
|
|
expect(job?.controller.signal.aborted).toBe(true)
|
|
expect(isPascalAgentJobActive(input)).toBe(false)
|
|
|
|
finishPascalAgentJob(job)
|
|
})
|
|
})
|