Files
deepseek-harness/packages/interaction/commands/tests/invariant.spec.ts
Tianyi Cui 3fc35c91ff refactor(packages): dissolve ui/ and rename sdk/ to scaffold/
git mv per the regrouping RFC: the five human-collaboration seams and
tui join packages/interaction/, app-boot becomes packages/boot/, and
jsonrpc joins the renamed scaffold/ (formerly sdk/) as its server half
beside client/protocol/create-sdk/helper/scripts/telemetry, whose
folders drop the legacy sdk- prefix. Three new group README triplets
replace the ui/ and sdk/ ones; tsconfig references/paths/globs,
knip keys, vitest globs, gate scripts, catalogs, docs, and the
lockfile follow. Adds the four settled FIXME rename markers
(dsh-sdk-server, dsh-sdk-telemetry, dsh-sdk-helper, dsh-sdk-scripts).

The scaffold folders diverge from their npm names until those renames
land, so tsconfig.base.json maps the three affected names explicitly
beside the group wildcard. Also repairs two pre-existing stale-path
classes the strengthened sweep surfaced: docs/web-styling.md's retired
web-ui host package and type-model spec fixture-literal joins.

app-boot's three Loader-composition specs time out at the default 5s
under full-suite parallel load on this filesystem (pre-existing;
pass isolated with --testTimeout=30000); interaction/scaffold/boot
suites otherwise green (687 passed).
2026-08-09 01:21:12 +08:00

90 lines
2.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { Context } from 'cordis'
import * as CommandInvariant from '@deepseek-ai/dsh-commands/invariant'
import InvariantService, { InvariantError } from '@deepseek-ai/dsh-invariants'
import SessionStore, { SessionId, type Session } from '@deepseek-ai/dsh-session'
import { CommandId } from '@deepseek-ai/dsh-commands'
async function mount(installCompanion = true): Promise<{ ctx: Context; session: Session }> {
const ctx = new Context()
await ctx.plugin(SessionStore)
const session = ctx.sessions.create(SessionId('commands-invariant'))
await ctx.plugin(InvariantService, { enabled: true })
if (installCompanion) await ctx.plugin(CommandInvariant)
return { ctx, session }
}
function appendRun(session: Session, id: string): void {
session.append('command/run', {
commandId: CommandId(id),
name: 'linked',
args: '',
source: { kind: 'user' },
})
}
describe('command lifecycle invariants', () => {
it('accepts a success outcome linked to an earlier non-command domain event', async () => {
const { session } = await mount()
const source = session.append('turn/start', { turn: 1 })
appendRun(session, 'cmd-valid')
expect(() => {
session.append('command/done', {
commandId: CommandId('cmd-valid'),
kind: 'success',
sourceEventSeq: source.seq,
})
}).not.toThrow()
})
it.each([-1, 1.5, 1])('rejects invalid or non-prior sourceEventSeq %s', async (sourceEventSeq) => {
const { session } = await mount()
appendRun(session, 'cmd-invalid')
expect(() => {
session.append('command/done', {
commandId: CommandId('cmd-invalid'),
kind: 'success',
sourceEventSeq,
})
}).toThrow(expect.objectContaining<Partial<InvariantError>>({
code: 'INVARIANT',
packageName: '@deepseek-ai/dsh-commands',
}))
})
it('rejects an error settlement carrying a success-only source reference', async () => {
const { session } = await mount()
const source = session.append('turn/start', { turn: 1 })
appendRun(session, 'cmd-error-source')
expect(() => {
session.append('command/done', {
commandId: CommandId('cmd-error-source'),
kind: 'error',
text: 'failed',
sourceEventSeq: source.seq,
})
}).toThrow(expect.objectContaining<Partial<InvariantError>>({
code: 'INVARIANT',
packageName: '@deepseek-ai/dsh-commands',
}))
})
it('attributes an invalid durable prefix during late companion loading', async () => {
const { ctx, session } = await mount(false)
appendRun(session, 'cmd-late')
session.append('command/done', {
commandId: CommandId('cmd-late'),
kind: 'success',
sourceEventSeq: 0,
})
await expect(ctx.plugin(CommandInvariant)).rejects.toMatchObject({
code: 'INVARIANT',
packageName: '@deepseek-ai/dsh-commands',
})
})
})