Scope kanban and usage profile reads
This commit is contained in:
@@ -135,7 +135,7 @@ describe('kanban controller', () => {
|
||||
expect(mockListTasks).toHaveBeenLastCalledWith({ board: 'default', status: 'ready', assignee: undefined, tenant: undefined, includeArchived: false })
|
||||
})
|
||||
|
||||
it('filters kanban tasks, stats, and assignees to the requested profile', async () => {
|
||||
it('filters kanban tasks, stats, and assignees to the user-bound profiles', async () => {
|
||||
const tasks = [
|
||||
{ id: 'task-1', assignee: 'research', status: 'todo' },
|
||||
{ id: 'task-2', assignee: 'travel', status: 'done' },
|
||||
@@ -162,6 +162,43 @@ describe('kanban controller', () => {
|
||||
expect(assigneesCtx.body).toEqual({ assignees: [{ name: 'research', on_disk: true, counts: { todo: 1 } }] })
|
||||
})
|
||||
|
||||
it('loads kanban data for every profile bound to the user instead of only the active header profile', async () => {
|
||||
mockListUserProfiles.mockReturnValue([{ profile_name: 'research' }, { profile_name: 'travel' }])
|
||||
const tasks = [
|
||||
{ id: 'task-1', assignee: 'research', status: 'todo' },
|
||||
{ id: 'task-2', assignee: 'travel', status: 'done' },
|
||||
{ id: 'task-3', assignee: 'default', status: 'blocked' },
|
||||
]
|
||||
mockListTasks.mockResolvedValue(tasks)
|
||||
mockGetAssignees.mockResolvedValue([
|
||||
{ name: 'research', on_disk: true, counts: { todo: 1 } },
|
||||
])
|
||||
|
||||
const state = { user: { id: 7, role: 'admin' }, profile: { name: 'research' } }
|
||||
const listCtx = ctx({ state, query: { board: 'default', includeArchived: 'true' } })
|
||||
await ctrl.list(listCtx)
|
||||
expect(listCtx.body).toEqual({ tasks: [tasks[0], tasks[1]] })
|
||||
|
||||
const statsCtx = ctx({ state, query: { board: 'default' } })
|
||||
await ctrl.stats(statsCtx)
|
||||
expect(statsCtx.body).toEqual({
|
||||
stats: {
|
||||
by_status: { todo: 1, done: 1 },
|
||||
by_assignee: { research: 1, travel: 1 },
|
||||
total: 2,
|
||||
},
|
||||
})
|
||||
|
||||
const assigneesCtx = ctx({ state, query: { board: 'default' } })
|
||||
await ctrl.assignees(assigneesCtx)
|
||||
expect(assigneesCtx.body).toEqual({
|
||||
assignees: [
|
||||
{ name: 'research', on_disk: true, counts: { todo: 1 } },
|
||||
{ name: 'travel', on_disk: true, counts: null },
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it('defaults created kanban tasks to the requested profile and rejects unauthorized assignees', async () => {
|
||||
mockCreateTask.mockResolvedValue({ id: 'task-1', assignee: 'research' })
|
||||
const state = { user: { id: 7, role: 'admin' }, profile: { name: 'research' } }
|
||||
|
||||
@@ -374,6 +374,39 @@ describe('session conversations controller', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('loads usage analytics from the request-scoped profile state database', async () => {
|
||||
getUsageStatsFromDbMock.mockResolvedValue({
|
||||
input_tokens: 12,
|
||||
output_tokens: 6,
|
||||
cache_read_tokens: 3,
|
||||
cache_write_tokens: 1,
|
||||
reasoning_tokens: 2,
|
||||
sessions: 1,
|
||||
cost: 0.01,
|
||||
total_api_calls: 4,
|
||||
by_model: [
|
||||
{ model: 'research-model', input_tokens: 12, output_tokens: 6, cache_read_tokens: 3, cache_write_tokens: 1, reasoning_tokens: 2, sessions: 1 },
|
||||
],
|
||||
by_day: [],
|
||||
})
|
||||
|
||||
const mod = await import('../../packages/server/src/controllers/hermes/sessions')
|
||||
const ctx: any = { query: { days: '2' }, state: { profile: { name: 'research' } }, body: null }
|
||||
await mod.usageStats(ctx)
|
||||
|
||||
expect(getUsageStatsFromDbMock).toHaveBeenCalledWith(2, undefined, 'research')
|
||||
expect(ctx.body).toMatchObject({
|
||||
total_input_tokens: 12,
|
||||
total_output_tokens: 6,
|
||||
total_sessions: 1,
|
||||
total_cost: 0.01,
|
||||
total_api_calls: 4,
|
||||
})
|
||||
expect(ctx.body.model_usage).toEqual([
|
||||
{ model: 'research-model', input_tokens: 12, output_tokens: 6, cache_read_tokens: 3, cache_write_tokens: 1, reasoning_tokens: 2, sessions: 1 },
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps blank model usage as returned by state.db analytics', async () => {
|
||||
getLocalUsageStatsMock.mockReturnValue({
|
||||
input_tokens: 3,
|
||||
|
||||
Reference in New Issue
Block a user