@itphx/synth-backend 0.8.2 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +0 -1
- package/dist/app.js +2 -1
- package/dist/auth/middleware.d.ts +0 -1
- package/dist/auth/middleware.js +0 -1
- package/dist/auth/oidc.d.ts +0 -1
- package/dist/auth/oidc.js +0 -1
- package/dist/events/hub.d.ts +0 -1
- package/dist/events/hub.js +0 -1
- package/dist/lib/app-config.d.ts +0 -1
- package/dist/lib/app-config.js +0 -1
- package/dist/lib/defaults-store.d.ts +0 -1
- package/dist/lib/defaults-store.js +0 -1
- package/dist/lib/i18n-config.d.ts +0 -1
- package/dist/lib/i18n-config.js +0 -1
- package/dist/lib/i18n.d.ts +0 -1
- package/dist/lib/i18n.js +0 -1
- package/dist/lib/recalc-can-summarize.d.ts +0 -1
- package/dist/lib/recalc-can-summarize.js +0 -1
- package/dist/main.d.ts +0 -1
- package/dist/main.js +0 -1
- package/dist/middleware/rate-limiter.d.ts +0 -1
- package/dist/middleware/rate-limiter.js +0 -1
- package/dist/routes/agents.d.ts +0 -1
- package/dist/routes/agents.js +0 -1
- package/dist/routes/audit.d.ts +0 -1
- package/dist/routes/audit.js +0 -1
- package/dist/routes/auth.d.ts +0 -1
- package/dist/routes/auth.js +0 -1
- package/dist/routes/context.d.ts +0 -1
- package/dist/routes/context.js +0 -1
- package/dist/routes/debug.d.ts +0 -1
- package/dist/routes/debug.js +0 -1
- package/dist/routes/gateway-patterns.d.ts +0 -1
- package/dist/routes/gateway-patterns.js +0 -1
- package/dist/routes/llm.d.ts +0 -1
- package/dist/routes/llm.js +0 -1
- package/dist/routes/logs.d.ts +0 -1
- package/dist/routes/logs.js +0 -1
- package/dist/routes/mcp-registry.d.ts +0 -1
- package/dist/routes/mcp-registry.js +0 -1
- package/dist/routes/mcp.d.ts +0 -1
- package/dist/routes/mcp.js +0 -1
- package/dist/routes/messages.d.ts +0 -1
- package/dist/routes/messages.js +0 -1
- package/dist/routes/models.d.ts +0 -1
- package/dist/routes/models.js +0 -1
- package/dist/routes/projects.d.ts +0 -1
- package/dist/routes/projects.js +0 -1
- package/dist/routes/providers.d.ts +0 -1
- package/dist/routes/providers.js +0 -1
- package/dist/routes/queue.d.ts +0 -1
- package/dist/routes/queue.js +0 -1
- package/dist/routes/sessions.d.ts +0 -1
- package/dist/routes/sessions.js +0 -1
- package/dist/routes/users.d.ts +0 -1
- package/dist/routes/users.js +0 -1
- package/package.json +4 -4
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js.map +0 -1
- package/dist/auth/middleware.d.ts.map +0 -1
- package/dist/auth/middleware.js.map +0 -1
- package/dist/auth/oidc.d.ts.map +0 -1
- package/dist/auth/oidc.js.map +0 -1
- package/dist/auth/oidc.test.d.ts +0 -2
- package/dist/auth/oidc.test.d.ts.map +0 -1
- package/dist/auth/oidc.test.js +0 -39
- package/dist/auth/oidc.test.js.map +0 -1
- package/dist/events/hub.d.ts.map +0 -1
- package/dist/events/hub.js.map +0 -1
- package/dist/events/hub.test.d.ts +0 -2
- package/dist/events/hub.test.d.ts.map +0 -1
- package/dist/events/hub.test.js +0 -74
- package/dist/events/hub.test.js.map +0 -1
- package/dist/integration/hybrid.integration.test.d.ts +0 -2
- package/dist/integration/hybrid.integration.test.d.ts.map +0 -1
- package/dist/integration/hybrid.integration.test.js +0 -289
- package/dist/integration/hybrid.integration.test.js.map +0 -1
- package/dist/lib/app-config.d.ts.map +0 -1
- package/dist/lib/app-config.js.map +0 -1
- package/dist/lib/defaults-store.d.ts.map +0 -1
- package/dist/lib/defaults-store.js.map +0 -1
- package/dist/lib/defaults-store.test.d.ts +0 -2
- package/dist/lib/defaults-store.test.d.ts.map +0 -1
- package/dist/lib/defaults-store.test.js +0 -168
- package/dist/lib/defaults-store.test.js.map +0 -1
- package/dist/lib/i18n-config.d.ts.map +0 -1
- package/dist/lib/i18n-config.js.map +0 -1
- package/dist/lib/i18n.d.ts.map +0 -1
- package/dist/lib/i18n.js.map +0 -1
- package/dist/lib/orchestrator-workspace.test.d.ts +0 -2
- package/dist/lib/orchestrator-workspace.test.d.ts.map +0 -1
- package/dist/lib/orchestrator-workspace.test.js +0 -112
- package/dist/lib/orchestrator-workspace.test.js.map +0 -1
- package/dist/lib/recalc-can-summarize.d.ts.map +0 -1
- package/dist/lib/recalc-can-summarize.js.map +0 -1
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/middleware/rate-limiter.d.ts.map +0 -1
- package/dist/middleware/rate-limiter.js.map +0 -1
- package/dist/routes/agents.d.ts.map +0 -1
- package/dist/routes/agents.js.map +0 -1
- package/dist/routes/agents.test.d.ts +0 -2
- package/dist/routes/agents.test.d.ts.map +0 -1
- package/dist/routes/agents.test.js +0 -211
- package/dist/routes/agents.test.js.map +0 -1
- package/dist/routes/audit.d.ts.map +0 -1
- package/dist/routes/audit.js.map +0 -1
- package/dist/routes/audit.test.d.ts +0 -2
- package/dist/routes/audit.test.d.ts.map +0 -1
- package/dist/routes/audit.test.js +0 -285
- package/dist/routes/audit.test.js.map +0 -1
- package/dist/routes/auth.d.ts.map +0 -1
- package/dist/routes/auth.js.map +0 -1
- package/dist/routes/auth.test.d.ts +0 -2
- package/dist/routes/auth.test.d.ts.map +0 -1
- package/dist/routes/auth.test.js +0 -63
- package/dist/routes/auth.test.js.map +0 -1
- package/dist/routes/context.d.ts.map +0 -1
- package/dist/routes/context.js.map +0 -1
- package/dist/routes/debug.d.ts.map +0 -1
- package/dist/routes/debug.js.map +0 -1
- package/dist/routes/debug.test.d.ts +0 -2
- package/dist/routes/debug.test.d.ts.map +0 -1
- package/dist/routes/debug.test.js +0 -102
- package/dist/routes/debug.test.js.map +0 -1
- package/dist/routes/gateway-patterns.d.ts.map +0 -1
- package/dist/routes/gateway-patterns.js.map +0 -1
- package/dist/routes/gateway-patterns.test.d.ts +0 -2
- package/dist/routes/gateway-patterns.test.d.ts.map +0 -1
- package/dist/routes/gateway-patterns.test.js +0 -176
- package/dist/routes/gateway-patterns.test.js.map +0 -1
- package/dist/routes/git.test.d.ts +0 -2
- package/dist/routes/git.test.d.ts.map +0 -1
- package/dist/routes/git.test.js +0 -168
- package/dist/routes/git.test.js.map +0 -1
- package/dist/routes/llm.d.ts.map +0 -1
- package/dist/routes/llm.js.map +0 -1
- package/dist/routes/llm.test.d.ts +0 -2
- package/dist/routes/llm.test.d.ts.map +0 -1
- package/dist/routes/llm.test.js +0 -629
- package/dist/routes/llm.test.js.map +0 -1
- package/dist/routes/logs.d.ts.map +0 -1
- package/dist/routes/logs.js.map +0 -1
- package/dist/routes/logs.test.d.ts +0 -2
- package/dist/routes/logs.test.d.ts.map +0 -1
- package/dist/routes/logs.test.js +0 -269
- package/dist/routes/logs.test.js.map +0 -1
- package/dist/routes/mcp-network-policy.integration.test.d.ts +0 -2
- package/dist/routes/mcp-network-policy.integration.test.d.ts.map +0 -1
- package/dist/routes/mcp-network-policy.integration.test.js +0 -44
- package/dist/routes/mcp-network-policy.integration.test.js.map +0 -1
- package/dist/routes/mcp-registry.d.ts.map +0 -1
- package/dist/routes/mcp-registry.js.map +0 -1
- package/dist/routes/mcp-registry.test.d.ts +0 -2
- package/dist/routes/mcp-registry.test.d.ts.map +0 -1
- package/dist/routes/mcp-registry.test.js +0 -248
- package/dist/routes/mcp-registry.test.js.map +0 -1
- package/dist/routes/mcp.d.ts.map +0 -1
- package/dist/routes/mcp.js.map +0 -1
- package/dist/routes/mcp.test.d.ts +0 -2
- package/dist/routes/mcp.test.d.ts.map +0 -1
- package/dist/routes/mcp.test.js +0 -389
- package/dist/routes/mcp.test.js.map +0 -1
- package/dist/routes/messages.d.ts.map +0 -1
- package/dist/routes/messages.js.map +0 -1
- package/dist/routes/messages.test.d.ts +0 -2
- package/dist/routes/messages.test.d.ts.map +0 -1
- package/dist/routes/messages.test.js +0 -85
- package/dist/routes/messages.test.js.map +0 -1
- package/dist/routes/models.d.ts.map +0 -1
- package/dist/routes/models.js.map +0 -1
- package/dist/routes/models.test.d.ts +0 -2
- package/dist/routes/models.test.d.ts.map +0 -1
- package/dist/routes/models.test.js +0 -449
- package/dist/routes/models.test.js.map +0 -1
- package/dist/routes/projects-mcp.test.d.ts +0 -6
- package/dist/routes/projects-mcp.test.d.ts.map +0 -1
- package/dist/routes/projects-mcp.test.js +0 -160
- package/dist/routes/projects-mcp.test.js.map +0 -1
- package/dist/routes/projects-skills.integration.test.d.ts +0 -2
- package/dist/routes/projects-skills.integration.test.d.ts.map +0 -1
- package/dist/routes/projects-skills.integration.test.js +0 -60
- package/dist/routes/projects-skills.integration.test.js.map +0 -1
- package/dist/routes/projects.d.ts.map +0 -1
- package/dist/routes/projects.js.map +0 -1
- package/dist/routes/projects.test.d.ts +0 -2
- package/dist/routes/projects.test.d.ts.map +0 -1
- package/dist/routes/projects.test.js +0 -549
- package/dist/routes/projects.test.js.map +0 -1
- package/dist/routes/providers.d.ts.map +0 -1
- package/dist/routes/providers.js.map +0 -1
- package/dist/routes/providers.test.d.ts +0 -2
- package/dist/routes/providers.test.d.ts.map +0 -1
- package/dist/routes/providers.test.js +0 -211
- package/dist/routes/providers.test.js.map +0 -1
- package/dist/routes/queue.d.ts.map +0 -1
- package/dist/routes/queue.js.map +0 -1
- package/dist/routes/queue.test.d.ts +0 -2
- package/dist/routes/queue.test.d.ts.map +0 -1
- package/dist/routes/queue.test.js +0 -224
- package/dist/routes/queue.test.js.map +0 -1
- package/dist/routes/sessions-mcp.test.d.ts +0 -6
- package/dist/routes/sessions-mcp.test.d.ts.map +0 -1
- package/dist/routes/sessions-mcp.test.js +0 -182
- package/dist/routes/sessions-mcp.test.js.map +0 -1
- package/dist/routes/sessions.d.ts.map +0 -1
- package/dist/routes/sessions.js.map +0 -1
- package/dist/routes/sessions.test.d.ts +0 -2
- package/dist/routes/sessions.test.d.ts.map +0 -1
- package/dist/routes/sessions.test.js +0 -602
- package/dist/routes/sessions.test.js.map +0 -1
- package/dist/routes/settings.test.d.ts +0 -2
- package/dist/routes/settings.test.d.ts.map +0 -1
- package/dist/routes/settings.test.js +0 -184
- package/dist/routes/settings.test.js.map +0 -1
- package/dist/routes/ssh-keys.test.d.ts +0 -2
- package/dist/routes/ssh-keys.test.d.ts.map +0 -1
- package/dist/routes/ssh-keys.test.js +0 -129
- package/dist/routes/ssh-keys.test.js.map +0 -1
- package/dist/routes/users.d.ts.map +0 -1
- package/dist/routes/users.js.map +0 -1
|
@@ -1,602 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { Hono } from 'hono';
|
|
3
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { createSessionRoutes } from './sessions.js';
|
|
7
|
-
import { SessionManager, EventBus, FileStore, FileProfileStore } from '@itphx/synth-core';
|
|
8
|
-
import { ProjectStore } from '@itphx/synth-core';
|
|
9
|
-
import { MessageRole, generateId, makeTextPart, nowISO } from '@itphx/synth-shared';
|
|
10
|
-
const testUser = {
|
|
11
|
-
id: 'test-user',
|
|
12
|
-
username: 'test-user',
|
|
13
|
-
roles: ['USER'],
|
|
14
|
-
preferredLanguage: 'ru',
|
|
15
|
-
createdAt: '',
|
|
16
|
-
teamRole: 'USER',
|
|
17
|
-
notes: '',
|
|
18
|
-
interviewCompleted: false,
|
|
19
|
-
};
|
|
20
|
-
function createMockKit() {
|
|
21
|
-
return {
|
|
22
|
-
requireAuth: async (_c, next) => { await next(); },
|
|
23
|
-
requirePermission: () => async (_c, next) => { await next(); },
|
|
24
|
-
getCurrentUser: () => testUser,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function createMockQueueManager() {
|
|
28
|
-
return {
|
|
29
|
-
isRunning: vi.fn().mockReturnValue(false),
|
|
30
|
-
stop: vi.fn(),
|
|
31
|
-
createProcessor: vi.fn(),
|
|
32
|
-
stopAll: vi.fn(),
|
|
33
|
-
getRingBuffer: vi.fn(),
|
|
34
|
-
setContextOptimizer: vi.fn(),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function createMockOrchestrator() {
|
|
38
|
-
const processMessage = vi.fn().mockResolvedValue({});
|
|
39
|
-
return {
|
|
40
|
-
createProcessMessage: () => processMessage,
|
|
41
|
-
cancel: vi.fn(),
|
|
42
|
-
getPromptInfo: vi.fn().mockResolvedValue({
|
|
43
|
-
manifest: { totalChars: 10, estTokens: 3, staticPrefixChars: 5, entries: [] },
|
|
44
|
-
history: {
|
|
45
|
-
messages: { count: 2, chars: 20, estTokens: 5 },
|
|
46
|
-
stateMessages: [{ type: 'mode_change', count: 1, chars: 40, estTokens: 10 }],
|
|
47
|
-
excluded: { disabled: 0, hidden: 0, info: 1 },
|
|
48
|
-
attachments: { count: 0, chars: 0 },
|
|
49
|
-
secretPlaceholders: 0,
|
|
50
|
-
},
|
|
51
|
-
promptState: null,
|
|
52
|
-
lastPromptMeta: null,
|
|
53
|
-
}),
|
|
54
|
-
getModelPricing: vi.fn().mockReturnValue(null),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function createMockEventHub() {
|
|
58
|
-
return {
|
|
59
|
-
subscribeToSession: vi.fn().mockResolvedValue(undefined),
|
|
60
|
-
unsubscribeFromSession: vi.fn(),
|
|
61
|
-
registerClient: vi.fn().mockResolvedValue(undefined),
|
|
62
|
-
unregisterClient: vi.fn(),
|
|
63
|
-
shutdown: vi.fn(),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function createTestApp(tmpDir, profilesStore) {
|
|
67
|
-
const app = new Hono();
|
|
68
|
-
const kit = createMockKit();
|
|
69
|
-
const fileStore = new FileStore({ dataDir: tmpDir });
|
|
70
|
-
const sessionManager = new SessionManager(fileStore);
|
|
71
|
-
const projectStore = new ProjectStore({ dataDir: tmpDir });
|
|
72
|
-
const eventBus = new EventBus();
|
|
73
|
-
const queueManager = createMockQueueManager();
|
|
74
|
-
const orchestrator = createMockOrchestrator();
|
|
75
|
-
const eventHub = createMockEventHub();
|
|
76
|
-
const sessionRoutes = createSessionRoutes(kit, sessionManager, eventBus, queueManager, orchestrator.createProcessMessage(), orchestrator, eventHub, undefined, projectStore, profilesStore);
|
|
77
|
-
app.route('/api/v2/sessions', sessionRoutes);
|
|
78
|
-
return { app, sessionManager, projectStore, eventBus, queueManager, orchestrator, eventHub, fileStore };
|
|
79
|
-
}
|
|
80
|
-
describe('Session API Routes', () => {
|
|
81
|
-
let tmpDir;
|
|
82
|
-
beforeEach(async () => {
|
|
83
|
-
tmpDir = await mkdtemp(join(tmpdir(), 'synth-test-'));
|
|
84
|
-
});
|
|
85
|
-
afterEach(async () => {
|
|
86
|
-
await rm(tmpDir, { recursive: true, force: true });
|
|
87
|
-
});
|
|
88
|
-
describe('GET /api/v2/sessions', () => {
|
|
89
|
-
it('возвращает пустой список', async () => {
|
|
90
|
-
const { app } = createTestApp(tmpDir);
|
|
91
|
-
const res = await app.request('/api/v2/sessions');
|
|
92
|
-
expect(res.status).toBe(200);
|
|
93
|
-
const body = await res.json();
|
|
94
|
-
expect(body).toEqual([]);
|
|
95
|
-
});
|
|
96
|
-
it('возвращает список сессий', async () => {
|
|
97
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
98
|
-
await sessionManager.createSession({ title: 'S1', userId: 'test-user' });
|
|
99
|
-
await sessionManager.createSession({ title: 'S2', userId: 'test-user' });
|
|
100
|
-
const res = await app.request('/api/v2/sessions');
|
|
101
|
-
expect(res.status).toBe(200);
|
|
102
|
-
const body = await res.json();
|
|
103
|
-
expect(body).toHaveLength(2);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe('POST /api/v2/sessions', () => {
|
|
107
|
-
it('создаёт сессию и возвращает 201', async () => {
|
|
108
|
-
const { app } = createTestApp(tmpDir);
|
|
109
|
-
const res = await app.request('/api/v2/sessions', {
|
|
110
|
-
method: 'POST',
|
|
111
|
-
headers: { 'Content-Type': 'application/json' },
|
|
112
|
-
body: JSON.stringify({ name: 'Test Session' }),
|
|
113
|
-
});
|
|
114
|
-
expect(res.status).toBe(201);
|
|
115
|
-
const body = await res.json();
|
|
116
|
-
expect(body.id).toBeTruthy();
|
|
117
|
-
expect(body.name).toBe('Test Session');
|
|
118
|
-
});
|
|
119
|
-
it('создаёт сессию с project_id', async () => {
|
|
120
|
-
const { app } = createTestApp(tmpDir);
|
|
121
|
-
const res = await app.request('/api/v2/sessions', {
|
|
122
|
-
method: 'POST',
|
|
123
|
-
headers: { 'Content-Type': 'application/json' },
|
|
124
|
-
body: JSON.stringify({ name: 'P', project_id: 'proj-1' }),
|
|
125
|
-
});
|
|
126
|
-
expect(res.status).toBe(201);
|
|
127
|
-
const body = await res.json();
|
|
128
|
-
expect(body.project_id).toBe('proj-1');
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe('GET /api/v2/sessions/:id', () => {
|
|
132
|
-
it('возвращает сессию по id', async () => {
|
|
133
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
134
|
-
const session = await sessionManager.createSession({ title: 'GetMe', userId: 'test-user' });
|
|
135
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`);
|
|
136
|
-
expect(res.status).toBe(200);
|
|
137
|
-
const body = await res.json();
|
|
138
|
-
expect(body.id).toBe(session.id);
|
|
139
|
-
expect(body.name).toBe('GetMe');
|
|
140
|
-
});
|
|
141
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
142
|
-
const { app } = createTestApp(tmpDir);
|
|
143
|
-
const res = await app.request('/api/v2/sessions/non-existent');
|
|
144
|
-
expect(res.status).toBe(404);
|
|
145
|
-
const body = await res.json();
|
|
146
|
-
expect(body.error.code).toBe('NOT_FOUND');
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe('PATCH /api/v2/sessions/:id', () => {
|
|
150
|
-
it('обновляет заголовок сессии', async () => {
|
|
151
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
152
|
-
const session = await sessionManager.createSession({ title: 'Old', userId: 'test-user' });
|
|
153
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
154
|
-
method: 'PATCH',
|
|
155
|
-
headers: { 'Content-Type': 'application/json' },
|
|
156
|
-
body: JSON.stringify({ name: 'New Title' }),
|
|
157
|
-
});
|
|
158
|
-
expect(res.status).toBe(200);
|
|
159
|
-
const body = await res.json();
|
|
160
|
-
expect(body.name).toBe('New Title');
|
|
161
|
-
});
|
|
162
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
163
|
-
const { app } = createTestApp(tmpDir);
|
|
164
|
-
const res = await app.request('/api/v2/sessions/non-existent', {
|
|
165
|
-
method: 'PATCH',
|
|
166
|
-
headers: { 'Content-Type': 'application/json' },
|
|
167
|
-
body: JSON.stringify({ name: 'Updated' }),
|
|
168
|
-
});
|
|
169
|
-
expect(res.status).toBe(404);
|
|
170
|
-
});
|
|
171
|
-
it('переключает mode в plan и возвращает его в сериализованной сессии', async () => {
|
|
172
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
173
|
-
const session = await sessionManager.createSession({ title: 'Mode', userId: 'test-user' });
|
|
174
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
175
|
-
method: 'PATCH',
|
|
176
|
-
headers: { 'Content-Type': 'application/json' },
|
|
177
|
-
body: JSON.stringify({ mode: 'plan' }),
|
|
178
|
-
});
|
|
179
|
-
expect(res.status).toBe(200);
|
|
180
|
-
const body = await res.json();
|
|
181
|
-
expect(body.mode).toBe('plan');
|
|
182
|
-
const persisted = await sessionManager.getSession(session.id);
|
|
183
|
-
expect(persisted?.mode).toBe('plan');
|
|
184
|
-
});
|
|
185
|
-
it('переключает mode в act', async () => {
|
|
186
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
187
|
-
const session = await sessionManager.createSession({ title: 'Mode', userId: 'test-user' });
|
|
188
|
-
await sessionManager.updateSession({ ...session, mode: 'plan' });
|
|
189
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
190
|
-
method: 'PATCH',
|
|
191
|
-
headers: { 'Content-Type': 'application/json' },
|
|
192
|
-
body: JSON.stringify({ mode: 'act' }),
|
|
193
|
-
});
|
|
194
|
-
expect(res.status).toBe(200);
|
|
195
|
-
const body = await res.json();
|
|
196
|
-
expect(body.mode).toBe('act');
|
|
197
|
-
});
|
|
198
|
-
it('возвращает 400 VALIDATION_ERROR для невалидного mode', async () => {
|
|
199
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
200
|
-
const session = await sessionManager.createSession({ title: 'Mode', userId: 'test-user' });
|
|
201
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
202
|
-
method: 'PATCH',
|
|
203
|
-
headers: { 'Content-Type': 'application/json' },
|
|
204
|
-
body: JSON.stringify({ mode: 'review' }),
|
|
205
|
-
});
|
|
206
|
-
expect(res.status).toBe(400);
|
|
207
|
-
const body = await res.json();
|
|
208
|
-
expect(body.error.code).toBe('VALIDATION_ERROR');
|
|
209
|
-
const persisted = await sessionManager.getSession(session.id);
|
|
210
|
-
expect(persisted?.mode).toBeUndefined();
|
|
211
|
-
});
|
|
212
|
-
it('возвращает 400 VALIDATION_ERROR для невалидного settings.reasoningLevel', async () => {
|
|
213
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
214
|
-
const session = await sessionManager.createSession({ title: 'Mode', userId: 'test-user' });
|
|
215
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
216
|
-
method: 'PATCH',
|
|
217
|
-
headers: { 'Content-Type': 'application/json' },
|
|
218
|
-
body: JSON.stringify({ settings: { reasoningLevel: 'bogus' } }),
|
|
219
|
-
});
|
|
220
|
-
expect(res.status).toBe(400);
|
|
221
|
-
const body = await res.json();
|
|
222
|
-
expect(body.error.code).toBe('VALIDATION_ERROR');
|
|
223
|
-
expect(body.error.message).toContain('reasoningLevel');
|
|
224
|
-
const persisted = await sessionManager.getSession(session.id);
|
|
225
|
-
expect(persisted?.settings.reasoningLevel).toBeUndefined();
|
|
226
|
-
});
|
|
227
|
-
it('обновляет валидные settings и сохраняет их', async () => {
|
|
228
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
229
|
-
const session = await sessionManager.createSession({ title: 'Mode', userId: 'test-user' });
|
|
230
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
231
|
-
method: 'PATCH',
|
|
232
|
-
headers: { 'Content-Type': 'application/json' },
|
|
233
|
-
body: JSON.stringify({ settings: { reasoningLevel: 'high' } }),
|
|
234
|
-
});
|
|
235
|
-
expect(res.status).toBe(200);
|
|
236
|
-
const persisted = await sessionManager.getSession(session.id);
|
|
237
|
-
expect(persisted?.settings.reasoningLevel).toBe('high');
|
|
238
|
-
});
|
|
239
|
-
it('привязывает сессию к существующему проекту', async () => {
|
|
240
|
-
const { app, sessionManager, projectStore } = createTestApp(tmpDir);
|
|
241
|
-
const project = projectStore.create('Proj', 'test-user');
|
|
242
|
-
await projectStore.save(project);
|
|
243
|
-
const session = await sessionManager.createSession({ title: 'S', userId: 'test-user' });
|
|
244
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
245
|
-
method: 'PATCH',
|
|
246
|
-
headers: { 'Content-Type': 'application/json' },
|
|
247
|
-
body: JSON.stringify({ project_id: project.id }),
|
|
248
|
-
});
|
|
249
|
-
expect(res.status).toBe(200);
|
|
250
|
-
const body = await res.json();
|
|
251
|
-
expect(body.project_id).toBe(project.id);
|
|
252
|
-
});
|
|
253
|
-
it('валидирует несуществующий проект и возвращает 400 PROJECT_NOT_FOUND', async () => {
|
|
254
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
255
|
-
const session = await sessionManager.createSession({ title: 'S', userId: 'test-user' });
|
|
256
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
257
|
-
method: 'PATCH',
|
|
258
|
-
headers: { 'Content-Type': 'application/json' },
|
|
259
|
-
body: JSON.stringify({ project_id: 'missing' }),
|
|
260
|
-
});
|
|
261
|
-
expect(res.status).toBe(400);
|
|
262
|
-
const body = await res.json();
|
|
263
|
-
expect(body.error.code).toBe('PROJECT_NOT_FOUND');
|
|
264
|
-
});
|
|
265
|
-
it('смена проекта сбрасывает planApproved', async () => {
|
|
266
|
-
const { app, sessionManager, projectStore } = createTestApp(tmpDir);
|
|
267
|
-
const p1 = projectStore.create('P1', 'test-user');
|
|
268
|
-
const p2 = projectStore.create('P2', 'test-user');
|
|
269
|
-
await projectStore.save(p1);
|
|
270
|
-
await projectStore.save(p2);
|
|
271
|
-
const session = await sessionManager.createSession({ title: 'S', userId: 'test-user', projectId: p1.id });
|
|
272
|
-
await sessionManager.updateSession({ ...session, planApproved: true });
|
|
273
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
274
|
-
method: 'PATCH',
|
|
275
|
-
headers: { 'Content-Type': 'application/json' },
|
|
276
|
-
body: JSON.stringify({ project_id: p2.id }),
|
|
277
|
-
});
|
|
278
|
-
expect(res.status).toBe(200);
|
|
279
|
-
const persisted = await sessionManager.getSession(session.id);
|
|
280
|
-
expect(persisted?.projectId).toBe(p2.id);
|
|
281
|
-
expect(persisted?.planApproved).toBe(false);
|
|
282
|
-
});
|
|
283
|
-
it('публикует session.moved при смене проекта', async () => {
|
|
284
|
-
const { app, sessionManager, projectStore, eventBus } = createTestApp(tmpDir);
|
|
285
|
-
const p1 = projectStore.create('P1', 'test-user');
|
|
286
|
-
const p2 = projectStore.create('P2', 'test-user');
|
|
287
|
-
await projectStore.save(p1);
|
|
288
|
-
await projectStore.save(p2);
|
|
289
|
-
const session = await sessionManager.createSession({ title: 'S', userId: 'test-user', projectId: p1.id });
|
|
290
|
-
let moved;
|
|
291
|
-
eventBus.subscribe(session.id, (e) => {
|
|
292
|
-
if (e.type === 'session.moved')
|
|
293
|
-
moved = e.data;
|
|
294
|
-
});
|
|
295
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, {
|
|
296
|
-
method: 'PATCH',
|
|
297
|
-
headers: { 'Content-Type': 'application/json' },
|
|
298
|
-
body: JSON.stringify({ project_id: p2.id }),
|
|
299
|
-
});
|
|
300
|
-
expect(res.status).toBe(200);
|
|
301
|
-
expect(moved).toBeTruthy();
|
|
302
|
-
expect(moved?.project_id).toBe(p2.id);
|
|
303
|
-
expect(moved?.prev_project_id).toBe(p1.id);
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
describe('DELETE /api/v2/sessions/:id', () => {
|
|
307
|
-
it('удаляет сессию и возвращает 204', async () => {
|
|
308
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
309
|
-
const session = await sessionManager.createSession({ title: 'Del', userId: 'test-user' });
|
|
310
|
-
const res = await app.request(`/api/v2/sessions/${session.id}`, { method: 'DELETE' });
|
|
311
|
-
expect(res.status).toBe(204);
|
|
312
|
-
expect(await sessionManager.getSession(session.id)).toBeNull();
|
|
313
|
-
});
|
|
314
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
315
|
-
const { app } = createTestApp(tmpDir);
|
|
316
|
-
const res = await app.request('/api/v2/sessions/non-existent', { method: 'DELETE' });
|
|
317
|
-
expect(res.status).toBe(404);
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
describe('POST /api/v2/sessions/:id/fork', () => {
|
|
321
|
-
it('создаёт ответвление сессии', async () => {
|
|
322
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
323
|
-
const source = await sessionManager.createSession({ title: 'Source', userId: 'test-user' });
|
|
324
|
-
const res = await app.request(`/api/v2/sessions/${source.id}/fork`, {
|
|
325
|
-
method: 'POST',
|
|
326
|
-
headers: { 'Content-Type': 'application/json' },
|
|
327
|
-
body: JSON.stringify({}),
|
|
328
|
-
});
|
|
329
|
-
expect(res.status).toBe(201);
|
|
330
|
-
const body = await res.json();
|
|
331
|
-
expect(body.id).toBeTruthy();
|
|
332
|
-
expect(body.parent_id).toBe(source.id);
|
|
333
|
-
expect(body.name).toContain('Source');
|
|
334
|
-
});
|
|
335
|
-
it('создаёт форк с указанием title', async () => {
|
|
336
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
337
|
-
const source = await sessionManager.createSession({ title: 'Source', userId: 'test-user' });
|
|
338
|
-
const res = await app.request(`/api/v2/sessions/${source.id}/fork`, {
|
|
339
|
-
method: 'POST',
|
|
340
|
-
headers: { 'Content-Type': 'application/json' },
|
|
341
|
-
body: JSON.stringify({ title: 'Forked Session' }),
|
|
342
|
-
});
|
|
343
|
-
expect(res.status).toBe(201);
|
|
344
|
-
const body = await res.json();
|
|
345
|
-
expect(body.name).toBe('Forked Session');
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
describe('GET /api/v2/sessions/:id/children', () => {
|
|
349
|
-
it('возвращает дочерние сессии', async () => {
|
|
350
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
351
|
-
const parent = await sessionManager.createSession({ title: 'Parent', userId: 'test-user' });
|
|
352
|
-
const child = await sessionManager.forkSession(parent.id, { title: 'Child', userId: 'test-user' });
|
|
353
|
-
const res = await app.request(`/api/v2/sessions/${parent.id}/children`);
|
|
354
|
-
expect(res.status).toBe(200);
|
|
355
|
-
const body = await res.json();
|
|
356
|
-
expect(body).toHaveLength(1);
|
|
357
|
-
expect(body[0].id).toBe(child.id);
|
|
358
|
-
});
|
|
359
|
-
it('возвращает пустой массив когда нет детей', async () => {
|
|
360
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
361
|
-
const session = await sessionManager.createSession({ title: 'Leaf', userId: 'test-user' });
|
|
362
|
-
const res = await app.request(`/api/v2/sessions/${session.id}/children`);
|
|
363
|
-
expect(res.status).toBe(200);
|
|
364
|
-
const body = await res.json();
|
|
365
|
-
expect(body).toEqual([]);
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
describe('GET /api/v2/sessions/:id/status', () => {
|
|
369
|
-
it('возвращает статус сессии', async () => {
|
|
370
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
371
|
-
const session = await sessionManager.createSession({ title: 'Status', userId: 'test-user' });
|
|
372
|
-
const res = await app.request(`/api/v2/sessions/${session.id}/status`);
|
|
373
|
-
expect(res.status).toBe(200);
|
|
374
|
-
const body = await res.json();
|
|
375
|
-
expect(body).toHaveProperty('blocked');
|
|
376
|
-
expect(body).toHaveProperty('pending_count');
|
|
377
|
-
expect(body).toHaveProperty('processor_running');
|
|
378
|
-
expect(body.blocked).toBe(false);
|
|
379
|
-
expect(body.pending_count).toBe(0);
|
|
380
|
-
});
|
|
381
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
382
|
-
const { app } = createTestApp(tmpDir);
|
|
383
|
-
const res = await app.request('/api/v2/sessions/non-existent/status');
|
|
384
|
-
expect(res.status).toBe(404);
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
describe('GET /api/v2/sessions/:id/tree', () => {
|
|
388
|
-
it('возвращает дерево сессий', async () => {
|
|
389
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
390
|
-
const parent = await sessionManager.createSession({ title: 'Root', userId: 'test-user' });
|
|
391
|
-
const child = await sessionManager.forkSession(parent.id, { title: 'Child', userId: 'test-user' });
|
|
392
|
-
const res = await app.request(`/api/v2/sessions/${parent.id}/tree`);
|
|
393
|
-
expect(res.status).toBe(200);
|
|
394
|
-
const body = await res.json();
|
|
395
|
-
expect(body.session.id).toBe(parent.id);
|
|
396
|
-
expect(body.children).toHaveLength(1);
|
|
397
|
-
expect(body.children[0].session.id).toBe(child.id);
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
describe('POST /api/v2/sessions/:id/clear', () => {
|
|
401
|
-
it('очищает сообщения сессии', async () => {
|
|
402
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
403
|
-
const session = await sessionManager.createSession({ title: 'Clear', userId: 'test-user' });
|
|
404
|
-
const res = await app.request(`/api/v2/sessions/${session.id}/clear`, { method: 'POST' });
|
|
405
|
-
expect(res.status).toBe(200);
|
|
406
|
-
const body = await res.json();
|
|
407
|
-
expect(body.id).toBe(session.id);
|
|
408
|
-
});
|
|
409
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
410
|
-
const { app } = createTestApp(tmpDir);
|
|
411
|
-
const res = await app.request('/api/v2/sessions/non-existent/clear', { method: 'POST' });
|
|
412
|
-
expect(res.status).toBe(404);
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
describe('GET /api/v2/sessions/:id/export', () => {
|
|
416
|
-
it('возвращает полный объект сессии с историей, todos и настройками', async () => {
|
|
417
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
418
|
-
const session = await sessionManager.createSession({ title: 'Exp', userId: 'test-user' });
|
|
419
|
-
session.todos = [{ id: 't1', content: 'task', status: 'pending', priority: 'medium' }];
|
|
420
|
-
await sessionManager.updateSession(session);
|
|
421
|
-
await sessionManager.addMessage(session.id, {
|
|
422
|
-
id: 'm1', role: MessageRole.USER, seq: 1, origin: 'local',
|
|
423
|
-
parts: [{ id: 'p1', type: 'text', data: 'hello' }],
|
|
424
|
-
content: 'hello', createdAt: new Date().toISOString(),
|
|
425
|
-
disabled: false, pinned: false, hidden: false,
|
|
426
|
-
});
|
|
427
|
-
const res = await app.request(`/api/v2/sessions/${session.id}/export`);
|
|
428
|
-
expect(res.status).toBe(200);
|
|
429
|
-
const body = await res.json();
|
|
430
|
-
expect(body.id).toBe(session.id);
|
|
431
|
-
expect(body.title).toBe('Exp');
|
|
432
|
-
expect(body.messages).toHaveLength(1);
|
|
433
|
-
expect(body.messages[0].content).toBe('hello');
|
|
434
|
-
expect(body.todos).toEqual([{ id: 't1', content: 'task', status: 'pending', priority: 'medium' }]);
|
|
435
|
-
expect(body.settings).toBeTruthy();
|
|
436
|
-
expect(body.engine).toBe('synth');
|
|
437
|
-
});
|
|
438
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
439
|
-
const { app } = createTestApp(tmpDir);
|
|
440
|
-
const res = await app.request('/api/v2/sessions/non-existent/export');
|
|
441
|
-
expect(res.status).toBe(404);
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
describe('POST /api/v2/sessions/import', () => {
|
|
445
|
-
it('создаёт сессию с историей сообщений из экспорта', async () => {
|
|
446
|
-
const { app, sessionManager, projectStore } = createTestApp(tmpDir);
|
|
447
|
-
const proj = projectStore.create('Proj1', 'test-user');
|
|
448
|
-
await projectStore.save(proj);
|
|
449
|
-
const source = await sessionManager.createSession({ title: 'Src', userId: 'test-user' });
|
|
450
|
-
await sessionManager.addMessage(source.id, {
|
|
451
|
-
id: 'm1', role: MessageRole.USER, seq: 1, origin: 'local',
|
|
452
|
-
parts: [{ id: 'p1', type: 'text', data: 'привет' }],
|
|
453
|
-
content: 'привет', createdAt: '2026-01-01T00:00:00.000Z',
|
|
454
|
-
disabled: false, pinned: false, hidden: false,
|
|
455
|
-
});
|
|
456
|
-
await sessionManager.addMessage(source.id, {
|
|
457
|
-
id: 'm2', role: MessageRole.ASSISTANT, seq: 2, origin: 'local',
|
|
458
|
-
parts: [{ id: 'p2', type: 'text', data: 'ответ' }],
|
|
459
|
-
content: 'ответ', createdAt: '2026-01-01T00:00:01.000Z',
|
|
460
|
-
disabled: false, pinned: false, hidden: false,
|
|
461
|
-
});
|
|
462
|
-
const exported = await sessionManager.getSession(source.id);
|
|
463
|
-
const res = await app.request('/api/v2/sessions/import', {
|
|
464
|
-
method: 'POST',
|
|
465
|
-
headers: { 'Content-Type': 'application/json' },
|
|
466
|
-
body: JSON.stringify({ ...exported, import: { project_id: proj.id } }),
|
|
467
|
-
});
|
|
468
|
-
expect(res.status).toBe(201);
|
|
469
|
-
const body = await res.json();
|
|
470
|
-
expect(body.id).not.toBe(source.id);
|
|
471
|
-
expect(body.name).toBe('Src');
|
|
472
|
-
expect(body.project_id).toBe(proj.id);
|
|
473
|
-
const created = await sessionManager.getSession(body.id);
|
|
474
|
-
expect(created?.messages).toHaveLength(2);
|
|
475
|
-
expect(created?.messages[0]?.content).toBe('привет');
|
|
476
|
-
expect(created?.messages[1]?.content).toBe('ответ');
|
|
477
|
-
expect(created?.messages[1]?.seq).toBe(2);
|
|
478
|
-
});
|
|
479
|
-
it('принимает тело в snake_case формате', async () => {
|
|
480
|
-
const { app, projectStore } = createTestApp(tmpDir);
|
|
481
|
-
const proj = projectStore.create('Proj2', 'test-user');
|
|
482
|
-
await projectStore.save(proj);
|
|
483
|
-
const res = await app.request('/api/v2/sessions/import', {
|
|
484
|
-
method: 'POST',
|
|
485
|
-
headers: { 'Content-Type': 'application/json' },
|
|
486
|
-
body: JSON.stringify({
|
|
487
|
-
title: 'Snake',
|
|
488
|
-
engine: 'synth',
|
|
489
|
-
session_origin: 'user',
|
|
490
|
-
project_id: proj.id,
|
|
491
|
-
messages: [{
|
|
492
|
-
id: 'm1', role: MessageRole.USER, seq: 1, origin: 'local',
|
|
493
|
-
parts: [{ id: 'p1', type: 'text', data: 'x' }],
|
|
494
|
-
content: 'x', created_at: '2026-01-01T00:00:00.000Z',
|
|
495
|
-
disabled: false, pinned: false, hidden: false,
|
|
496
|
-
}],
|
|
497
|
-
todos: [{ id: 't1', content: 'task', status: 'pending', priority: 'high' }],
|
|
498
|
-
}),
|
|
499
|
-
});
|
|
500
|
-
expect(res.status).toBe(201);
|
|
501
|
-
const body = await res.json();
|
|
502
|
-
expect(body.name).toBe('Snake');
|
|
503
|
-
expect(body.project_id).toBe(proj.id);
|
|
504
|
-
});
|
|
505
|
-
it('сохраняет parentId из экспорта (publish переписывает его на remote-id)', async () => {
|
|
506
|
-
const { app, sessionManager, projectStore } = createTestApp(tmpDir);
|
|
507
|
-
const proj = projectStore.create('Proj3', 'test-user');
|
|
508
|
-
await projectStore.save(proj);
|
|
509
|
-
const parent = await sessionManager.createSession({ title: 'Parent', userId: 'test-user' });
|
|
510
|
-
const source = await sessionManager.createSession({ title: 'Child', userId: 'test-user', parentId: parent.id });
|
|
511
|
-
const exported = await sessionManager.getSession(source.id);
|
|
512
|
-
const res = await app.request('/api/v2/sessions/import', {
|
|
513
|
-
method: 'POST',
|
|
514
|
-
headers: { 'Content-Type': 'application/json' },
|
|
515
|
-
body: JSON.stringify({ ...exported, import: { project_id: proj.id } }),
|
|
516
|
-
});
|
|
517
|
-
expect(res.status).toBe(201);
|
|
518
|
-
const body = await res.json();
|
|
519
|
-
expect(body.id).not.toBe(source.id);
|
|
520
|
-
// parentId — как в экспорте (переписанный publish-ом remote-id).
|
|
521
|
-
expect(body.parent_id).toBe(parent.id);
|
|
522
|
-
const created = await sessionManager.getSession(body.id);
|
|
523
|
-
expect(created?.parentId).toBe(parent.id);
|
|
524
|
-
});
|
|
525
|
-
it('возвращает 400 PROJECT_NOT_FOUND для несуществующего проекта', async () => {
|
|
526
|
-
const { app } = createTestApp(tmpDir);
|
|
527
|
-
const res = await app.request('/api/v2/sessions/import', {
|
|
528
|
-
method: 'POST',
|
|
529
|
-
headers: { 'Content-Type': 'application/json' },
|
|
530
|
-
body: JSON.stringify({ title: 'X', import: { project_id: 'no-such-project' } }),
|
|
531
|
-
});
|
|
532
|
-
expect(res.status).toBe(400);
|
|
533
|
-
const body = await res.json();
|
|
534
|
-
expect(body.error.code).toBe('PROJECT_NOT_FOUND');
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
describe('GET /api/v2/sessions/:id/prompt (AD-070 §2.5)', () => {
|
|
538
|
-
it('возвращает манифест для существующей сессии', async () => {
|
|
539
|
-
const { app, sessionManager } = createTestApp(tmpDir);
|
|
540
|
-
const session = await sessionManager.createSession({ title: 'S', userId: testUser.id });
|
|
541
|
-
const res = await app.request(`/api/v2/sessions/${session.id}/prompt`);
|
|
542
|
-
expect(res.status).toBe(200);
|
|
543
|
-
const body = await res.json();
|
|
544
|
-
expect(body.manifest).toBeTruthy();
|
|
545
|
-
expect(body.manifest.totalChars).toBe(10);
|
|
546
|
-
expect(body.history).toBeTruthy();
|
|
547
|
-
expect(body.history.messages.count).toBe(2);
|
|
548
|
-
expect(body.history.stateMessages[0].type).toBe('mode_change');
|
|
549
|
-
expect(body.history.excluded.info).toBe(1);
|
|
550
|
-
expect(body.promptState).toBeNull();
|
|
551
|
-
expect(body.lastPromptMeta).toBeNull();
|
|
552
|
-
});
|
|
553
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
554
|
-
const { app } = createTestApp(tmpDir);
|
|
555
|
-
const res = await app.request('/api/v2/sessions/non-existent/prompt');
|
|
556
|
-
expect(res.status).toBe(404);
|
|
557
|
-
const body = await res.json();
|
|
558
|
-
expect(body.error.code).toBe('NOT_FOUND');
|
|
559
|
-
});
|
|
560
|
-
});
|
|
561
|
-
describe('GET /api/v2/sessions/:id/stats (AD-070 §2.6)', () => {
|
|
562
|
-
it('возвращает агрегацию по агентам и пользователям', async () => {
|
|
563
|
-
const profilesStore = new FileProfileStore({ dataDir: tmpDir });
|
|
564
|
-
await profilesStore.getOrCreateProfile({ username: testUser.username });
|
|
565
|
-
const profile = (await profilesStore.getProfileByUsername(testUser.username));
|
|
566
|
-
await profilesStore.saveProfile({ ...profile, displayName: 'Test User' });
|
|
567
|
-
const { app, sessionManager } = createTestApp(tmpDir, profilesStore);
|
|
568
|
-
const session = await sessionManager.createSession({ title: 'S', userId: testUser.id });
|
|
569
|
-
await sessionManager.addMessage(session.id, {
|
|
570
|
-
id: generateId(), role: MessageRole.USER, seq: 0, origin: 'local',
|
|
571
|
-
parts: [makeTextPart('hi')], content: 'hi', createdAt: nowISO(),
|
|
572
|
-
disabled: false, pinned: false, hidden: false, author: testUser.username,
|
|
573
|
-
});
|
|
574
|
-
await sessionManager.addMessage(session.id, {
|
|
575
|
-
id: generateId(), role: MessageRole.ASSISTANT, seq: 0, origin: 'local',
|
|
576
|
-
parts: [makeTextPart('ok')], content: 'ok', createdAt: nowISO(),
|
|
577
|
-
disabled: false, pinned: false, hidden: false, agentRole: 'developer',
|
|
578
|
-
model: 'm', usage: { inputTokens: 100, outputTokens: 10, totalTokens: 110 },
|
|
579
|
-
metadata: { duration_ms: 1000 },
|
|
580
|
-
});
|
|
581
|
-
const res = await app.request(`/api/v2/sessions/${session.id}/stats`);
|
|
582
|
-
expect(res.status).toBe(200);
|
|
583
|
-
const body = await res.json();
|
|
584
|
-
expect(body.session_id).toBe(session.id);
|
|
585
|
-
const dev = body.agents.find((a) => a.agent_role === 'developer');
|
|
586
|
-
expect(dev).toBeTruthy();
|
|
587
|
-
expect(dev.input_tokens).toBe(100);
|
|
588
|
-
const user = body.users.find((u) => u.author === testUser.username);
|
|
589
|
-
expect(user).toBeTruthy();
|
|
590
|
-
expect(user.messages).toBe(1);
|
|
591
|
-
expect(user.display_name).toBe('Test User');
|
|
592
|
-
});
|
|
593
|
-
it('возвращает 404 для отсутствующей сессии', async () => {
|
|
594
|
-
const { app } = createTestApp(tmpDir);
|
|
595
|
-
const res = await app.request('/api/v2/sessions/non-existent/stats');
|
|
596
|
-
expect(res.status).toBe(404);
|
|
597
|
-
const body = await res.json();
|
|
598
|
-
expect(body.error.code).toBe('NOT_FOUND');
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
});
|
|
602
|
-
//# sourceMappingURL=sessions.test.js.map
|