fix(studio): the assistant column draws the page the server applied, and reads the user's role

A page preview draws the spread the server applied with the journey's photos,
texts and figures instead of applying the operations again without them. The
Studio's welcome, privacy banner and header fit a journey chat: a viewer is
told they can only look, the banner speaks of the book, and the trip notes
button stays in the trip chat. Escape closes the header menu before it stops a
reply, a single page renders at the full long edge, the status says a model
reads pages only while its provider has not refused an image, and pointing at
a page in a design card outlines it in the Studio.
This commit is contained in:
Maurice
2026-10-23 01:45:16 +00:00
parent 72c61f242e
commit 9e40092507
85 changed files with 857 additions and 144 deletions
@@ -1,22 +1,25 @@
/**
* FE-STUDIO-ASTPANEL-001 to FE-STUDIO-ASTPANEL-003
* FE-STUDIO-ASTPANEL-001 to FE-STUDIO-ASTPANEL-009
*
* The assistant's column in TREK Studio (journey-studio.md 3.4, 4.5): the
* journey's chat with its own question; the notice that images of a page
* leave only once the user agreed, for the connection on screen, and that
* "Not now" keeps it text for the visit; every key inside the column belongs
* to the chat, so Studio neither closes nor edits the page's selection, and
* Escape stops a running answer first.
* leave only once the user agreed, for the connection on screen, that "Not
* now" keeps it text for the visit, and that a model reading no images is
* never asked; every key inside the column belongs to the chat, so Studio
* neither closes nor edits the page's selection, and Escape stops a running
* answer first, while Escape in the header's menu only closes the menu; the
* journey's chat offers no trip notes, and its privacy banner speaks of the
* journey; the bar's switch and the column it opens.
*/
import type { AiStatusResponse } from '@trek/shared';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen, waitFor } from '../../../tests/helpers/render';
import { fireEvent, render, screen, waitFor, within } from '../../../tests/helpers/render';
import { aiConnectionsRepo } from '../../repo/aiConnectionsRepo';
import { assistantRepo } from '../../repo/assistantRepo';
import { assistantChatKey } from '../../store/assistantChatKey';
import { chatOf, useAssistantStore } from '../../store/assistantStore';
import StudioAssistantPanel from './StudioAssistantPanel';
import StudioAssistantPanel, { StudioAssistantColumn, StudioAssistantToggle } from './StudioAssistantPanel';
import type { StudioAssistant } from './useStudioAssistant';
const JOURNEY = 12;
@@ -32,13 +35,24 @@ const STATUS: AiStatusResponse = {
instance: { kind: 'anthropic', model: 'claude', host: 'api.anthropic.com' },
quota: null,
privacyAcked: true,
studioImages: true,
studioImagesAcked: false,
retention: { mode: 'days', days: 90 },
openrouterOAuth: false,
};
function assistant(): StudioAssistant {
return { chatKey: KEY, available: true, open: true, toggle: vi.fn(), jobs: [], drawn: vi.fn() };
function assistant(over: Partial<StudioAssistant> = {}): StudioAssistant {
return { chatKey: KEY, available: true, open: true, toggle: vi.fn(), jobs: [], drawn: vi.fn(), ...over };
}
/** A chat whose answer is still being written, with the store's cancel spied on. */
function running() {
const cancel = vi.fn();
useAssistantStore.setState({
cancel,
byTrip: { [KEY]: { ...chatOf(useAssistantStore.getState(), KEY), isRunning: true } },
});
return cancel;
}
beforeEach(() => {
@@ -83,11 +97,7 @@ describe('StudioAssistantPanel', () => {
});
it('FE-STUDIO-ASTPANEL-003: keys in the column stay there, Escape stops a running answer first', () => {
const cancel = vi.fn();
useAssistantStore.setState({
cancel,
byTrip: { [KEY]: { ...chatOf(useAssistantStore.getState(), KEY), isRunning: true } },
});
const cancel = running();
const studioKeys = vi.fn();
window.addEventListener('keydown', studioKeys);
const panel = assistant();
@@ -105,4 +115,94 @@ describe('StudioAssistantPanel', () => {
expect(panel.toggle).not.toHaveBeenCalled();
window.removeEventListener('keydown', studioKeys);
});
it("FE-STUDIO-ASTPANEL-004: Escape in the header's menu closes the menu, not the answer or Studio", async () => {
const cancel = running();
const studioKeys = vi.fn();
window.addEventListener('keydown', studioKeys);
const panel = assistant();
render(<StudioAssistantPanel assistant={panel} title="Lisbon" />);
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
const item = within(await screen.findByRole('menu')).getAllByRole('button')[0] as HTMLElement;
// The menu's own keys stay out of the Studio and leave the answer alone.
fireEvent.keyDown(item, { key: 'ArrowDown' });
fireEvent.keyDown(item, { key: 'Escape' });
await waitFor(() => expect(screen.queryByRole('menu')).toBeNull());
expect(cancel).not.toHaveBeenCalled();
expect(studioKeys).not.toHaveBeenCalled();
expect(panel.toggle).not.toHaveBeenCalled();
window.removeEventListener('keydown', studioKeys);
});
it('FE-STUDIO-ASTPANEL-005: the journey chat offers no trip notes, which only a trip turn reads', async () => {
render(<StudioAssistantPanel assistant={assistant()} title="Lisbon" />);
expect(await screen.findByText('What should the book look like?')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Recent chats' })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Trip notes' })).toBeNull();
});
it('FE-STUDIO-ASTPANEL-006: on the admin connection the privacy banner speaks of the journey', async () => {
useAssistantStore.setState({ status: { ...STATUS, privacyAcked: false } });
render(<StudioAssistantPanel assistant={assistant()} title="Lisbon" />);
expect(
await screen.findByText('Your messages and the journey data the assistant reads go to Anthropic.')
).toBeInTheDocument();
expect(screen.queryByText(/trip data/)).toBeNull();
fireEvent.click(screen.getByRole('button', { name: 'What gets shared?' }));
expect(
screen.getByText('Not your password or your other journeys. A picture of a page goes only once you allow it.')
).toBeInTheDocument();
expect(screen.getByText(/what the assistant reads of this journey/)).toBeInTheDocument();
expect(screen.queryByText('Not your password, your files or your other trips.')).toBeNull();
});
it('FE-STUDIO-ASTPANEL-007: a connection whose model reads no images is never asked to show pages', async () => {
useAssistantStore.setState({
status: {
...STATUS,
effective: { source: 'instance', kind: 'custom', model: 'llama3', host: 'ollama.lan', paidBy: 'instance' },
studioImages: false,
},
});
render(<StudioAssistantPanel assistant={assistant()} title="Lisbon" />);
expect(await screen.findByText('What should the book look like?')).toBeInTheDocument();
expect(screen.queryByRole('note')).toBeNull();
expect(screen.queryByRole('button', { name: 'Show it pages' })).toBeNull();
});
it('FE-STUDIO-ASTPANEL-008: the bar switch shows where the assistant runs, tells its state and toggles', () => {
const { unmount } = render(<StudioAssistantToggle assistant={assistant({ available: false })} />);
expect(screen.queryByRole('button', { name: 'Assistant' })).toBeNull();
unmount();
const closed = assistant({ open: false });
const second = render(<StudioAssistantToggle assistant={closed} />);
const toggle = screen.getByRole('button', { name: 'Assistant' });
expect(toggle).toHaveAttribute('aria-pressed', 'false');
expect(toggle).toHaveAttribute('title', 'Design the book together with the assistant');
expect(toggle).not.toHaveClass('is-on');
fireEvent.click(toggle);
expect(closed.toggle).toHaveBeenCalledTimes(1);
second.unmount();
render(<StudioAssistantToggle assistant={assistant()} />);
expect(screen.getByRole('button', { name: 'Assistant' })).toHaveAttribute('aria-pressed', 'true');
expect(screen.getByRole('button', { name: 'Assistant' })).toHaveClass('is-on');
});
it('FE-STUDIO-ASTPANEL-009: the column mounts only while it is open, named after the journey or as one', async () => {
const { unmount } = render(<StudioAssistantColumn assistant={assistant({ open: false })} title="Lisbon" />);
expect(screen.queryByRole('complementary', { name: 'Book assistant' })).toBeNull();
unmount();
render(<StudioAssistantColumn assistant={assistant()} />);
expect(screen.getByRole('complementary', { name: 'Book assistant' })).toBeInTheDocument();
expect(await screen.findByText('What should the book look like?')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Journey' })).toBeInTheDocument();
});
});