mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
* feat: Add Claude Code Agent Teams support - Add TeamState schemas and types for team collaboration - Extract team state from TeamCreate, SendMessage, Task tools - Add database migration V3→V4 for team_state storage - Add TeamPanel component to display team members, tasks, messages - Add team tool icons and presentation rules - Support vite proxy configuration via VITE_HUB_PROXY env var via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> * fix: Add timestamp protection for team_state updates Prevent old messages from overwriting newer team state by checking team_state_updated_at before updating. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> * fix: Extract team tasks from Task/TaskCreate/TaskUpdate tools - Enhance processTaskToolWithTeam to also generate task entries from the Task tool's description field when spawning teammates - Add processTaskCreate handler for TaskCreate tool calls - Add processTaskUpdate handler for TaskUpdate tool calls - Register both new tools in the extraction switch statement This fixes the gap where the Tasks section in TeamPanel could never populate because team task data was not being extracted from the message stream. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> * fix: Skip orphan TaskUpdate without title to prevent schema validation failure When TaskUpdate arrives before TaskCreate (message ordering), skip inserting incomplete tasks that lack required title field, preventing entire teamState from being dropped by schema validation. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> * test: Add unit tests for orphan TaskUpdate handling Verify that applyTeamStateDelta correctly skips inserting tasks without title field (orphan TaskUpdate) while still allowing normal task creation and updates to existing tasks. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> --------- Co-authored-by: tfq <tfq@gmail.com> Co-authored-by: HAPI <noreply@hapi.run>
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { describe, test, expect } from 'bun:test'
|
|
import { applyTeamStateDelta } from './teams'
|
|
import type { TeamState, TeamTask } from '@hapi/protocol/types'
|
|
|
|
const baseTeamState: TeamState = {
|
|
teamName: 'test-team',
|
|
members: [{ name: 'lead', status: 'active' }],
|
|
tasks: [],
|
|
messages: [],
|
|
updatedAt: 1000
|
|
}
|
|
|
|
function getTasks(result: TeamState | null | undefined): TeamTask[] {
|
|
expect(result).toBeTruthy()
|
|
return result!.tasks ?? []
|
|
}
|
|
|
|
describe('applyTeamStateDelta - orphan TaskUpdate', () => {
|
|
test('should skip inserting task without title (orphan TaskUpdate)', () => {
|
|
const result = applyTeamStateDelta(baseTeamState, {
|
|
tasks: [{ id: 'task-1', status: 'in_progress' } as any],
|
|
updatedAt: 2000
|
|
})
|
|
|
|
expect(getTasks(result)).toEqual([])
|
|
})
|
|
|
|
test('should insert task when title is present (normal TaskCreate)', () => {
|
|
const result = applyTeamStateDelta(baseTeamState, {
|
|
tasks: [{ id: 'task-1', title: 'Do something', status: 'pending' }],
|
|
updatedAt: 2000
|
|
})
|
|
|
|
const tasks = getTasks(result)
|
|
expect(tasks).toHaveLength(1)
|
|
expect(tasks[0]).toMatchObject({ title: 'Do something' })
|
|
})
|
|
|
|
test('should update existing task even without title (normal TaskUpdate)', () => {
|
|
const stateWithTask: TeamState = {
|
|
...baseTeamState,
|
|
tasks: [{ id: 'task-1', title: 'Do something', status: 'pending' }]
|
|
}
|
|
|
|
const result = applyTeamStateDelta(stateWithTask, {
|
|
tasks: [{ id: 'task-1', status: 'completed' } as any],
|
|
updatedAt: 2000
|
|
})
|
|
|
|
const tasks = getTasks(result)
|
|
expect(tasks).toHaveLength(1)
|
|
expect(tasks[0]).toMatchObject({ title: 'Do something', status: 'completed' })
|
|
})
|
|
|
|
test('should handle mixed: existing task update + orphan new task', () => {
|
|
const stateWithTask: TeamState = {
|
|
...baseTeamState,
|
|
tasks: [{ id: 'task-1', title: 'Existing task', status: 'pending' }]
|
|
}
|
|
|
|
const result = applyTeamStateDelta(stateWithTask, {
|
|
tasks: [
|
|
{ id: 'task-1', status: 'in_progress' } as any,
|
|
{ id: 'task-2', status: 'completed' } as any,
|
|
],
|
|
updatedAt: 2000
|
|
})
|
|
|
|
const tasks = getTasks(result)
|
|
expect(tasks).toHaveLength(1)
|
|
expect(tasks[0]).toMatchObject({ id: 'task-1', status: 'in_progress' })
|
|
})
|
|
})
|