mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Nominal string types via a unique-symbol brand (zero runtime cost): an AgentId can no longer be passed where a CallId is expected. Each core package brands the IDs it owns — CallId in dsh-llm (tool-call correlation across blocks, chunks, session events, and execution results), SessionId in dsh-session, AgentId in dsh-agent. Construction goes through same-named factory functions; public string-in APIs (sessions.create, agentLoop.create) keep accepting plain strings and brand internally. Policy note in the brand module: brand IDs that cross package boundaries, not every string.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { Context } from 'cordis'
|
|
import { Session, SessionId } from '@deepseek-ai/dsh-session'
|
|
import AgentRegistry, { Agent, AgentId } from '@deepseek-ai/dsh-agent'
|
|
|
|
function stubAgent(rawId: string): Agent {
|
|
const id = AgentId(rawId)
|
|
return {
|
|
id,
|
|
options: {},
|
|
session: new Session(SessionId(`${id}-session`)),
|
|
status: 'idle',
|
|
send() {},
|
|
steer() {},
|
|
inject() {},
|
|
abort() {},
|
|
}
|
|
}
|
|
|
|
describe('AgentRegistry', () => {
|
|
it('registers agents and emits created/disposed events', async () => {
|
|
const ctx = new Context()
|
|
await ctx.plugin(AgentRegistry)
|
|
|
|
const created: string[] = []
|
|
const disposed: string[] = []
|
|
ctx.on('agent/created', agent => void created.push(agent.id))
|
|
ctx.on('agent/disposed', agent => void disposed.push(agent.id))
|
|
|
|
const agent = stubAgent('a1')
|
|
const dispose = ctx.agents.register(agent)
|
|
expect(created).toEqual(['a1'])
|
|
expect(ctx.agents.get('a1')).toBe(agent)
|
|
expect(ctx.agents.list()).toEqual([agent])
|
|
|
|
dispose()
|
|
expect(disposed).toEqual(['a1'])
|
|
expect(ctx.agents.get('a1')).toBeUndefined()
|
|
})
|
|
|
|
it('rejects duplicate ids and unregisters on fiber dispose (HMR safety)', async () => {
|
|
const ctx = new Context()
|
|
await ctx.plugin(AgentRegistry)
|
|
ctx.agents.register(stubAgent('main'))
|
|
expect(() => ctx.agents.register(stubAgent('main'))).toThrow('already registered')
|
|
|
|
const fiber = await ctx.plugin(Object.assign((inner: Context) => {
|
|
inner.agents.register(stubAgent('scoped'))
|
|
}, { inject: ['agents'] }))
|
|
expect(ctx.agents.list().map(a => a.id)).toEqual(['main', 'scoped'])
|
|
|
|
await fiber.dispose()
|
|
expect(ctx.agents.list().map(a => a.id)).toEqual(['main'])
|
|
})
|
|
})
|