Files
aryx/tests/shared/session.test.ts
T
David KayaandCopilot 4a229a1f88 feat: add session library backend APIs
Add persisted session and pattern metadata for pinning, archiving, manual titles, and favorite patterns. Expose backend query and mutation APIs for session library features, and cover the shared helpers with tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-22 19:33:20 +01:00

121 lines
3.2 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import type { PatternDefinition } from '@shared/domain/pattern';
import {
applyScratchpadSessionConfig,
createScratchpadSessionConfig,
resolveSessionTitle,
resolveScratchpadSessionConfig,
type SessionRecord,
} from '@shared/domain/session';
function createPattern(): PatternDefinition {
return {
id: 'pattern-single',
name: '1-on-1 Copilot Chat',
description: 'Single agent chat',
mode: 'single',
availability: 'available',
maxIterations: 1,
agents: [
{
id: 'agent-primary',
name: 'Primary Agent',
description: 'Helpful assistant',
instructions: 'Help the user.',
model: 'gpt-5.4',
reasoningEffort: 'high',
},
{
id: 'agent-secondary',
name: 'Secondary Agent',
description: 'Unused here',
instructions: 'Review.',
model: 'claude-sonnet-4.5',
reasoningEffort: 'medium',
},
],
createdAt: '2026-03-23T00:00:00.000Z',
updatedAt: '2026-03-23T00:00:00.000Z',
};
}
function createSession(overrides?: Partial<SessionRecord>): SessionRecord {
return {
id: 'session-1',
projectId: 'project-scratchpad',
patternId: 'pattern-single',
title: 'Scratchpad',
createdAt: '2026-03-23T00:00:00.000Z',
updatedAt: '2026-03-23T00:00:00.000Z',
status: 'idle',
messages: [],
...overrides,
};
}
describe('scratchpad session config helpers', () => {
test('captures the initial scratchpad model settings from the primary agent', () => {
expect(createScratchpadSessionConfig(createPattern())).toEqual({
model: 'gpt-5.4',
reasoningEffort: 'high',
});
});
test('resolves persisted scratchpad overrides over the pattern defaults', () => {
const config = resolveScratchpadSessionConfig(
createSession({
scratchpadConfig: {
model: 'claude-opus-4.5',
reasoningEffort: 'medium',
},
}),
createPattern(),
);
expect(config).toEqual({
model: 'claude-opus-4.5',
reasoningEffort: 'medium',
});
});
test('applies scratchpad settings only to the primary agent', () => {
const pattern = createPattern();
const updated = applyScratchpadSessionConfig(
pattern,
createSession({
scratchpadConfig: {
model: 'gpt-5.4-mini',
reasoningEffort: 'low',
},
}),
);
expect(updated.agents[0].model).toBe('gpt-5.4-mini');
expect(updated.agents[0].reasoningEffort).toBe('low');
expect(updated.agents[1]).toEqual(pattern.agents[1]);
});
});
describe('session title helpers', () => {
test('keeps a manual title instead of recomputing it from the first user message', () => {
const pattern = createPattern();
const session = createSession({
title: 'Release readiness review',
titleSource: 'manual',
});
expect(
resolveSessionTitle(session, pattern, [
{
id: 'msg-1',
role: 'user',
authorName: 'You',
content: 'Investigate why the version badge keeps saying unknown after refresh.',
createdAt: '2026-03-23T00:00:00.000Z',
},
]),
).toBe('Release readiness review');
});
});