2026-03-17 16:31:04 +09:00
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
|
|
import { ZodError } from "zod/v4"
|
|
|
|
|
import { BackgroundTaskConfigSchema } from "./background-task"
|
|
|
|
|
|
|
|
|
|
describe("BackgroundTaskConfigSchema.circuitBreaker", () => {
|
|
|
|
|
describe("#given valid circuit breaker settings", () => {
|
|
|
|
|
test("#when parsed #then returns nested config", () => {
|
|
|
|
|
const result = BackgroundTaskConfigSchema.parse({
|
|
|
|
|
circuitBreaker: {
|
|
|
|
|
maxToolCalls: 150,
|
2026-03-18 14:32:27 +09:00
|
|
|
consecutiveThreshold: 10,
|
2026-03-17 16:31:04 +09:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
expect(result.circuitBreaker).toEqual({
|
|
|
|
|
maxToolCalls: 150,
|
2026-03-18 14:32:27 +09:00
|
|
|
consecutiveThreshold: 10,
|
2026-03-17 16:31:04 +09:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-18 14:32:27 +09:00
|
|
|
describe("#given consecutiveThreshold below minimum", () => {
|
2026-03-17 16:31:04 +09:00
|
|
|
test("#when parsed #then throws ZodError", () => {
|
|
|
|
|
let thrownError: unknown
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
BackgroundTaskConfigSchema.parse({
|
|
|
|
|
circuitBreaker: {
|
2026-03-18 14:32:27 +09:00
|
|
|
consecutiveThreshold: 4,
|
2026-03-17 16:31:04 +09:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
thrownError = error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(thrownError).toBeInstanceOf(ZodError)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-18 14:32:27 +09:00
|
|
|
describe("#given consecutiveThreshold is zero", () => {
|
2026-03-17 16:31:04 +09:00
|
|
|
test("#when parsed #then throws ZodError", () => {
|
|
|
|
|
let thrownError: unknown
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
BackgroundTaskConfigSchema.parse({
|
|
|
|
|
circuitBreaker: {
|
2026-03-18 14:32:27 +09:00
|
|
|
consecutiveThreshold: 0,
|
2026-03-17 16:31:04 +09:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
thrownError = error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(thrownError).toBeInstanceOf(ZodError)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|