fix(assistant): improve trip proposals and approvals

This commit is contained in:
Maurice
2026-12-02 22:03:28 +01:00
parent 01ad13623c
commit 62a3e63f3f
144 changed files with 4093 additions and 1336 deletions
@@ -4,10 +4,11 @@
* The error line: one sentence, at most one thing to do, and that thing
* does what it says.
*/
import type { AiStatusResponse, AssistantErrorCode } from '@trek/shared';
import type { AiStatusResponse, AssistantErrorCode, AssistantMessage } from '@trek/shared';
import { Route, Routes } from 'react-router';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { HIKE } from '../../../tests/helpers/assistantTour';
import { fireEvent, render, screen } from '../../../tests/helpers/render';
import { chatOf, useAssistantStore } from '../../store/assistantStore';
import { setForcedOffline } from '../../sync/networkMode';
@@ -33,13 +34,17 @@ const retry = vi.fn(async () => {});
const continueHere = vi.fn(async () => {});
const send = vi.fn(async () => {});
function withError(error: AssistantErrorCode | null, status: AiStatusResponse = STATUS) {
function withError(
error: AssistantErrorCode | null,
status: AiStatusResponse = STATUS,
messages: AssistantMessage[] = []
) {
useAssistantStore.setState({
status,
retry,
continueHere,
send,
byTrip: { [TRIP]: { ...chatOf(useAssistantStore.getState(), TRIP), error } },
byTrip: { [TRIP]: { ...chatOf(useAssistantStore.getState(), TRIP), error, messages } },
});
}
@@ -119,6 +124,25 @@ describe('AssistantError', () => {
expect(screen.queryByRole('button')).toBeNull();
});
it('keeps a calculated route distinct from the rate-limited reply', () => {
const when = '2026-10-21T08:00:00.000Z';
const question: AssistantMessage = { id: 'm1', role: 'user', status: 'complete', parts: [], createdAt: when };
const answer: AssistantMessage = {
id: 'm2',
role: 'assistant',
status: 'error',
createdAt: when,
parts: [{ type: 'data-trek-card', data: { toolCallId: 'hike', card: HIKE } }],
};
withError('rate_limited', STATUS, [question, answer]);
const { unmount } = renderLine();
expect(screen.getByRole('status')).toHaveTextContent('The route preview is still available.');
unmount();
withError('rate_limited', STATUS, [question, answer, { ...question, id: 'm3' }]);
renderLine();
expect(screen.getByRole('status')).toHaveTextContent('Limit reached at Anthropic. Try again later.');
});
it('FE-AI-ERR-008: waiting changes ask for a decision before a place can be suggested', () => {
withError('decide_first');
renderLine();