feat(web): merge compact status and summary cards
This commit is contained in:
@@ -320,6 +320,25 @@ describe('CommandService', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('preserves an earlier authoritative domain-event reference on successful settlement', async () => {
|
||||
const ctx = await mount()
|
||||
const { agent } = await mintAgentScope(ctx, 'a')
|
||||
const source = agent.session.append('turn/start', { turn: 1 })
|
||||
ctx.commands.register({
|
||||
name: 'linked',
|
||||
description: 'Link outcome',
|
||||
handler: () => ({ kind: 'success', text: 'linked', sourceEventSeq: source.seq }),
|
||||
})
|
||||
|
||||
const execution = await ctx.commands.execute(agent, '/linked', new AbortController().signal)
|
||||
|
||||
expect(execution?.result).toEqual({ kind: 'success', text: 'linked', sourceEventSeq: source.seq })
|
||||
expect(lifecycleOf(agent)).toMatchObject([
|
||||
{ type: 'command/run', data: { name: 'linked' } },
|
||||
{ type: 'command/done', data: { kind: 'success', text: 'linked', sourceEventSeq: source.seq } },
|
||||
])
|
||||
})
|
||||
|
||||
it('omits raw input from command/run when an authoritative domain event owns it', async () => {
|
||||
const ctx = await mount()
|
||||
const { agent } = await mintAgentScope(ctx, 'a')
|
||||
@@ -427,6 +446,9 @@ describe('CommandService', () => {
|
||||
[null, /CommandResult/],
|
||||
[{}, /CommandResult/],
|
||||
[{ kind: 'success', text: 1 }, /success text/],
|
||||
[{ kind: 'success', sourceEventSeq: -1 }, /sourceEventSeq/],
|
||||
[{ kind: 'success', sourceEventSeq: 1.5 }, /sourceEventSeq/],
|
||||
[{ kind: 'success', sourceEventSeq: '1' }, /sourceEventSeq/],
|
||||
[{ kind: 'error', text: '' }, /error text/],
|
||||
[{ kind: 'error', text: 1 }, /error text/],
|
||||
[{ kind: 'future', text: 'x' }, /unknown result kind/],
|
||||
|
||||
89
packages/ui/commands/tests/invariant.spec.ts
Normal file
89
packages/ui/commands/tests/invariant.spec.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
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 command-owned 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',
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user