mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 07:26:30 +00:00
3c3a228737
- agent loop and decisions without await in loops: steps as recursion, calls and applied changes in order through one promise chain, the independent reads and claims in parallel; part mapping in its own helpers - place card, header and weather strip without refs or components created in render; long hooks and components split; state reset during render - trip notes only in a turn's tool session, never an undo's; map view reported only while the assistant can run - place strip scrolls through the strip's own smooth scroll, no physical side - tests follow the raised limits and the new card fields; toasts read through a mocked useToast instead of a window global; baselines lowered where the counts fell
58 lines
2.8 KiB
TypeScript
58 lines
2.8 KiB
TypeScript
/**
|
|
* The trip notes the assistant keeps: a note goes below what is there, the
|
|
* same note is not added twice, notes that would run past the limit are
|
|
* refused whole, and other trips' notes stay as they are.
|
|
*/
|
|
import { noteOf, REMEMBER_SPEC, rememberForTrip } from '../../../../src/nest/assistant/assistant-memory';
|
|
import type { SettingsService } from '../../../../src/nest/settings/settings.service';
|
|
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
function settingsWith(prefs: Record<string, unknown>) {
|
|
const upsertSetting = vi.fn(async () => undefined);
|
|
const settings = { getUserSettings: vi.fn(async () => prefs), upsertSetting } as unknown as SettingsService;
|
|
return { settings, upsertSetting };
|
|
}
|
|
|
|
describe('the trip notes', () => {
|
|
it('ASTMEM-001: a note goes below the trip notes there are, and other trips keep theirs', async () => {
|
|
const { settings, upsertSetting } = settingsWith({ assistant_memory: { '4': 'Vegetarian', '9': 'Other trip' } });
|
|
const run = await rememberForTrip(settings, 1, 4, { note: ' We travel as two. ' });
|
|
expect(run).toEqual({ ok: true, value: { notes: 'Vegetarian\nWe travel as two.' } });
|
|
expect(upsertSetting).toHaveBeenCalledWith(1, 'assistant_memory', {
|
|
'4': 'Vegetarian\nWe travel as two.',
|
|
'9': 'Other trip',
|
|
});
|
|
});
|
|
|
|
it('ASTMEM-002: the first note starts them, and a note kept already is not added again', async () => {
|
|
const first = settingsWith({});
|
|
expect(await rememberForTrip(first.settings, 1, 4, { note: 'No museums' })).toEqual({
|
|
ok: true,
|
|
value: { notes: 'No museums' },
|
|
});
|
|
expect(first.upsertSetting).toHaveBeenCalledWith(1, 'assistant_memory', { '4': 'No museums' });
|
|
|
|
const again = settingsWith({ assistant_memory: { '4': 'No museums' } });
|
|
expect((await rememberForTrip(again.settings, 1, 4, { note: 'No museums' })).ok).toBe(true);
|
|
expect(again.upsertSetting).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('ASTMEM-003: nothing to keep, or no room left, is refused and writes nothing', async () => {
|
|
const empty = settingsWith({});
|
|
expect(await rememberForTrip(empty.settings, 1, 4, { note: ' ' })).toMatchObject({ ok: false });
|
|
const full = settingsWith({ assistant_memory: { '4': 'x'.repeat(1_990) } });
|
|
expect(await rememberForTrip(full.settings, 1, 4, { note: 'One more thing to keep' })).toMatchObject({
|
|
ok: false,
|
|
});
|
|
expect(empty.upsertSetting).not.toHaveBeenCalled();
|
|
expect(full.upsertSetting).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('ASTMEM-004: the note is read trimmed and capped, and the model is offered one short sentence', () => {
|
|
expect(noteOf({ note: 42 })).toBeNull();
|
|
expect(noteOf({ note: 'y'.repeat(600) })).toHaveLength(500);
|
|
expect(REMEMBER_SPEC.parameters).toMatchObject({ required: ['note'], additionalProperties: false });
|
|
});
|
|
});
|