mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
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.
119 lines
4.3 KiB
TypeScript
119 lines
4.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { Context } from '@deepseek-ai/cordis'
|
|
import SessionStore, { Session, SessionId } from '@deepseek-ai/dsh-session'
|
|
import * as HookInvariant from '@deepseek-ai/dsh-hook-protocol/invariant'
|
|
import InvariantService from '@deepseek-ai/dsh-invariants'
|
|
|
|
async function setup(): Promise<Context> {
|
|
const ctx = new Context()
|
|
await ctx.plugin(SessionStore)
|
|
await ctx.plugin(InvariantService)
|
|
await ctx.plugin(HookInvariant)
|
|
return ctx
|
|
}
|
|
|
|
const invoked = (overrides: Record<string, unknown> = {}) => ({
|
|
turn: 1,
|
|
point: 'PreToolUse',
|
|
dialect: 'claude' as const,
|
|
handlerId: 'hook-1',
|
|
...overrides,
|
|
})
|
|
|
|
const result = (overrides: Record<string, unknown> = {}) => ({
|
|
turn: 1,
|
|
point: 'PreToolUse',
|
|
handlerId: 'hook-1',
|
|
decision: 'pass',
|
|
durationMs: 3,
|
|
...overrides,
|
|
})
|
|
|
|
function startTurn(session: Session, turn = 1): void {
|
|
session.append('turn/start', { turn })
|
|
}
|
|
|
|
describe('hook-protocol invariants', () => {
|
|
it('pairs serial and repeated handler invocations', async () => {
|
|
const ctx = await setup()
|
|
const session = ctx.sessions.create()
|
|
startTurn(session)
|
|
session.append('hook/invoked', invoked())
|
|
session.append('hook/invoked', invoked())
|
|
session.append('step/start', { turn: 1, step: 1 })
|
|
session.append('hook/result', result())
|
|
session.append('hook/result', result())
|
|
})
|
|
|
|
it('rebuilds pending hook invocations from an existing session', async () => {
|
|
const ctx = new Context()
|
|
await ctx.plugin(SessionStore)
|
|
const session = ctx.sessions.create()
|
|
session.append('turn/start', { turn: 1 })
|
|
session.append('hook/invoked', invoked())
|
|
await ctx.plugin(InvariantService)
|
|
await ctx.plugin(HookInvariant)
|
|
expect(() => session.append('hook/result', result())).not.toThrow()
|
|
session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
|
})
|
|
|
|
it('adopts a bare session first observed through publication', async () => {
|
|
const ctx = await setup()
|
|
const session = Session.create(SessionId('bare-hook-session'))
|
|
expect(() => {
|
|
ctx.emit('session/event', session, {
|
|
type: 'turn/start', seq: 0, time: 0,
|
|
data: { turn: 1 },
|
|
})
|
|
ctx.emit('session/event', session, {
|
|
type: 'hook/invoked', seq: 1, time: 1, data: invoked(),
|
|
})
|
|
ctx.emit('session/event', session, {
|
|
type: 'hook/result', seq: 2, time: 2, data: result(),
|
|
})
|
|
}).not.toThrow()
|
|
})
|
|
|
|
it('rejects hook events outside or for a different open turn', async () => {
|
|
const ctx = await setup()
|
|
const session = ctx.sessions.create()
|
|
expect(() => session.append('hook/invoked', invoked())).toThrow(/outside any open turn/)
|
|
startTurn(session)
|
|
expect(() => session.append('hook/invoked', invoked({ turn: 2 }))).toThrow(/but open turn is 1/)
|
|
})
|
|
|
|
it('rejects an unenclosed hook event when replaying an existing session', async () => {
|
|
const ctx = new Context()
|
|
await ctx.plugin(SessionStore)
|
|
const session = ctx.sessions.create()
|
|
startTurn(session)
|
|
session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
|
session.append('hook/invoked', invoked())
|
|
await ctx.plugin(InvariantService)
|
|
await expect(ctx.plugin(HookInvariant).then(() => undefined)).rejects.toThrow(/outside any open turn/)
|
|
})
|
|
|
|
it.each([
|
|
[invoked({ point: '' }), /point and handlerId must be non-empty/],
|
|
[invoked({ handlerId: '' }), /point and handlerId must be non-empty/],
|
|
[invoked({ dialect: 'other' }), /unknown dialect/],
|
|
])('rejects malformed hook invocation %#', async (data, message) => {
|
|
const ctx = await setup()
|
|
const session = ctx.sessions.create()
|
|
startTurn(session)
|
|
expect(() => session.append('hook/invoked', data as never)).toThrow(message)
|
|
})
|
|
|
|
it('rejects unmatched and malformed results', async () => {
|
|
const ctx = await setup()
|
|
const session = ctx.sessions.create()
|
|
startTurn(session)
|
|
expect(() => session.append('hook/result', result())).toThrow(/no matching hook\/invoked/)
|
|
session.append('hook/invoked', invoked())
|
|
expect(() => session.append('hook/result', result({ durationMs: -1 })))
|
|
.toThrow(/durationMs must be a non-negative finite number/)
|
|
expect(() => session.append('hook/result', result({ point: 'Stop' })))
|
|
.toThrow(/no matching hook\/invoked/)
|
|
})
|
|
})
|