Files
deepseek-harness/packages/subagent/subagent/tests/timing-projection.spec.ts
imccyu ec601ca13d build(vendor): rescope the vendored Cordis packages into @deepseek-ai
Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it
prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`,
`verify-translation-pairing --write` for the touched bilingual pairs,
`gen-doc-graphs`, and one typert snapshot whose ids embed character offsets.
`pnpm run rescope-vendor --check` verifies the result.

Renames nine vendored packages (cordis, cosmokit, schemastery and the six
@cordisjs plugins) and every reference that resolves them: manifest names and
dependency keys, module specifiers including declare-module merges, cordis.yml
plugin names, tsconfig paths, every Markdown fence, and `docs/` prose.
Directory names, upstream versions, and dependency ranges are unchanged, so
vendor/README.md still reads as an upstream snapshot; its manifest table gains
an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed
at each fork's origin.

The tutorial tier follows the rename end to end: its yaml fences named plugins
the Loader can no longer resolve, its `ts ignore-check` fences disagreed with
the compiled fences beside them, and its prose quoted both. The contracts that
told readers to keep upstream names — the root convention and the vendoring
cookbook's tree comment and manifest invariant — now say to rescope instead.

Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle
purity gate now names the vendored libraries a browser bundle inlines, and the
files where a bare `cordis` is an agent-preset id keep that product data.
2026-08-10 22:04:13 +08:00

85 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { Context } from '@deepseek-ai/cordis'
import SessionStore from '@deepseek-ai/dsh-session'
import type { SessionEvent } from '@deepseek-ai/dsh-session'
import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
import SubagentService from '../src/index.ts'
import { subagentTimingProjectionDefinition } from '../src/projection.ts'
function event(type: SessionEvent['type'], seq: number, time: number): SessionEvent {
return { type, seq, time, data: {} } as SessionEvent
}
function fold(events: SessionEvent[]) {
let state = subagentTimingProjectionDefinition.init()
for (const item of events) state = subagentTimingProjectionDefinition.apply(state, item)
return subagentTimingProjectionDefinition.view(state)
}
describe('subagent timing projection', () => {
it('registers with the optional session projection registry', async () => {
const ctx = new Context()
await ctx.plugin(SessionStore)
await ctx.plugin(SessionProjectionRegistry)
const serviceFiber = await ctx.plugin(SubagentService)
const before = ctx.sessionProjections.snapshot(ctx.sessions.create()).values
expect(before.subagentTiming).toEqual({ settledMs: 0 })
// The identity unit registers alongside timing; an empty log serves its
// serializable null sentinel.
expect(before.subagent).toBeNull()
await serviceFiber.dispose()
const after = ctx.sessionProjections.snapshot(ctx.sessions.create()).values
expect(after.subagentTiming).toBeUndefined()
expect(after.subagent).toBeUndefined()
})
it('resets inherited seed timing at the child descriptor and sums later completed turns', () => {
expect(fold([
event('turn/start', 0, 100),
event('subagent/descriptor', 1, 110),
event('turn/end', 2, 300),
event('turn/start', 3, 1_000),
event('subagent/descriptor', 4, 1_100),
event('turn/end', 5, 4_100),
event('turn/start', 6, 10_000),
event('turn/end', 7, 12_000),
])).toEqual({ settledMs: 5_100 })
})
it('exposes an open turn start and never subtracts time for reversed boundaries', () => {
expect(fold([
event('turn/start', 0, 1_000),
event('subagent/descriptor', 1, 1_100),
event('turn/end', 2, 900),
event('turn/start', 3, 2_000),
event('assistant/chunk', 4, 2_500),
])).toEqual({ settledMs: 0, active: { since: 2_000, through: 2_500 } })
})
it('ignores completed pre-descriptor turns and unrelated events', () => {
const initial = subagentTimingProjectionDefinition.init()
expect(subagentTimingProjectionDefinition.apply(
initial,
event('assistant/chunk', 0, 1),
)).toBe(initial)
expect(subagentTimingProjectionDefinition.apply(
initial,
event('turn/end', 1, 2),
)).toBe(initial)
const descriptor = subagentTimingProjectionDefinition.apply(
initial,
event('subagent/descriptor', 2, 3),
)
expect(subagentTimingProjectionDefinition.apply(
descriptor,
event('turn/end', 3, 4),
)).toBe(descriptor)
expect(fold([
event('turn/start', 0, 100),
event('turn/end', 1, 200),
event('subagent/descriptor', 2, 300),
])).toEqual({ settledMs: 0 })
})
})