Files
goodbuddy/src/main/assistant/subagent-scheduler.test.ts
T
mesalogo b36d688900
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build Linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build Linux x64 Agent (push) Canceled after 0s
feat: add direct model programming agents
Direct model conversations can now execute bounded platform-native processes and delegate one level of programming work without duplicating tools in Agent Runtimes. Process and Subagent activity follows existing workspace, mode, approval, cancellation, and lifecycle boundaries, with chat attribution and complete feature documentation.

Remove the static Renderer bundle baseline gate and its build-only manifests; production builds continue to compile all processes and verify the control-plane installer. Also include the pending documentation link normalization.

Release note: 直连模型现在可在 Execute 模式运行本机命令,并可委派编程 Subagent 完成修改、测试和复核;构建流程不再因静态 Renderer 包体基线阻塞。
2026-09-02 00:50:54 +08:00

101 lines
3.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { vi } from 'vitest'
import { SubagentScheduler } from './subagent-scheduler'
describe('SubagentScheduler', () => {
it('enforces concurrency and starts queued work in FIFO order', async () => {
const scheduler = new SubagentScheduler({
concurrency: 2,
queueLimit: 3,
timeoutMs: 1_000
})
const started: number[] = []
let releaseInitial!: () => void
const initialGate = new Promise<void>((resolve) => {
releaseInitial = resolve
})
const jobs = [0, 1, 2, 3].map((value) =>
scheduler.schedule(async () => {
started.push(value)
if (value < 2) {
await initialGate
}
return value
})
)
await Promise.resolve()
expect(started).toEqual([0, 1])
releaseInitial()
await expect(Promise.all(jobs)).resolves.toEqual([0, 1, 2, 3])
expect(started).toEqual([0, 1, 2, 3])
scheduler.dispose()
})
it('rejects overflow, queued cancellation, and timed out work', async () => {
const scheduler = new SubagentScheduler({
concurrency: 1,
queueLimit: 1,
timeoutMs: 20
})
const blocker = scheduler.schedule(
(signal) => new Promise((_resolve, reject) => {
signal.addEventListener('abort', () => reject(signal.reason))
})
)
const controller = new AbortController()
const queued = scheduler.schedule(async () => 'queued', controller.signal)
await expect(
scheduler.schedule(async () => 'overflow')
).rejects.toThrow('队列已满')
controller.abort(new Error('cancelled'))
await expect(queued).rejects.toThrow('cancelled')
await expect(blocker).rejects.toThrow('1 秒')
scheduler.dispose()
})
it('holds its concurrency slot until aborted work finishes cleanup', async () => {
const scheduler = new SubagentScheduler({
concurrency: 1,
queueLimit: 1,
timeoutMs: 1_000
})
const controller = new AbortController()
let finishCleanup!: () => void
const cleanupGate = new Promise<void>((resolve) => {
finishCleanup = resolve
})
const started: string[] = []
const first = scheduler.schedule(async (signal) => {
started.push('first')
await new Promise<void>((resolve) => {
signal.addEventListener('abort', () => resolve(), { once: true })
})
await cleanupGate
return 'first'
}, controller.signal)
const second = scheduler.schedule(async () => {
started.push('second')
return 'second'
})
await vi.waitFor(() => expect(started).toEqual(['first']))
controller.abort(new Error('cancelled'))
await expect(first).rejects.toThrow('cancelled')
await Promise.resolve()
expect(started).toEqual(['first'])
let idle = false
const idlePromise = scheduler.waitForIdle().then(() => {
idle = true
})
await Promise.resolve()
expect(idle).toBe(false)
finishCleanup()
await expect(second).resolves.toBe('second')
await idlePromise
expect(started).toEqual(['first', 'second'])
scheduler.dispose()
})
})