mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
All agent/* and agent-loop/config-start-failed events take one payload object carrying the agent subject; waterfall/serial payloads require a signal and keep next as the final argument. PreStepContext and RequestFailureContext are unfolded into payloads and retired. goal/changed follows the same shape so agentEvents keeps its listener error containment. ReactLoopAgent builds its scope carrier once in the constructor. Regenerates scope resolvers, tool-cordis api catalog, and docs catalogs; updates all affected listeners, tests, and the core-data-structures docs (en + zh).
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { Context } from 'cordis'
|
|
import type { Agent } from '@deepseek-ai/dsh-agent'
|
|
import * as AgentInvariant from '@deepseek-ai/dsh-agent/invariant'
|
|
import { scopeTarget } from '@deepseek-ai/dsh-scope'
|
|
import InvariantService from '@deepseek-ai/dsh-invariants'
|
|
|
|
async function setup(): Promise<Context> {
|
|
const ctx = new Context()
|
|
await ctx.plugin(InvariantService)
|
|
await ctx.plugin(AgentInvariant)
|
|
return ctx
|
|
}
|
|
|
|
function mockAgent(id: string): Agent {
|
|
return { id } as unknown as Agent
|
|
}
|
|
|
|
describe('agent status invariants', () => {
|
|
it('accepts lifecycle transitions between idle and running', async () => {
|
|
const ctx = await setup()
|
|
const agent = mockAgent('a1')
|
|
expect(() => {
|
|
ctx.emit(scopeTarget(agent, agent), 'agent/status', { agent, status: 'idle' })
|
|
ctx.emit(scopeTarget(agent, agent), 'agent/status', { agent, status: 'running' })
|
|
ctx.emit(scopeTarget(agent, agent), 'agent/status', { agent, status: 'idle' })
|
|
}).not.toThrow()
|
|
})
|
|
|
|
it('rejects a no-op transition', async () => {
|
|
const ctx = await setup()
|
|
const agent = mockAgent('a3')
|
|
ctx.emit(scopeTarget(agent, agent), 'agent/status', { agent, status: 'running' })
|
|
expect(() => { ctx.emit(scopeTarget(agent, agent), 'agent/status', { agent, status: 'running' }) })
|
|
.toThrow(/no-op transition/)
|
|
})
|
|
|
|
it('tracks agents independently', async () => {
|
|
const ctx = await setup()
|
|
const a = mockAgent('a5')
|
|
const b = mockAgent('b5')
|
|
ctx.emit(scopeTarget(a, a), 'agent/status', { agent: a, status: 'running' })
|
|
expect(() => { ctx.emit(scopeTarget(b, b), 'agent/status', { agent: b, status: 'running' }) }).not.toThrow()
|
|
})
|
|
})
|