Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): silence dup headshot toast, cover async render path

[._.]/ Adam Eivy7566ff829bdf
diff --git a/client/src/pages/Authors.jsx b/client/src/pages/Authors.jsx
index 5ff97976d2..978fb5185d 100644
--- a/client/src/pages/Authors.jsx
+++ b/client/src/pages/Authors.jsx
@@ -106,13 +106,15 @@ export default function Authors() {
return;
}
setStartingGen(true);
+ // `silent: true` — this catch owns the error toast, so suppress the
+ // apiCore `request()` helper's default toast to avoid firing two.
const queued = await generateImage({
prompt: buildHeadshotPrompt(form),
// Shared base plus portrait-specific guards (people-only artifacts).
negativePrompt: `${DEFAULT_NEGATIVE_PROMPT}, extra limbs, nsfw, nude`,
width: 768,
height: 1024,
- }).catch((err) => {
+ }, { silent: true }).catch((err) => {
toast.error(err.message || 'Headshot generation failed');
return null;
});
diff --git a/client/src/pages/Authors.test.jsx b/client/src/pages/Authors.test.jsx
index d5d5c22f5b..6bde0b95f3 100644
--- a/client/src/pages/Authors.test.jsx
+++ b/client/src/pages/Authors.test.jsx
@@ -26,12 +26,18 @@ vi.mock('../components/ui/Toast', () => ({
default: { success: (...a) => toastSuccess(...a), error: (...a) => toastError(...a) },
}));
-// Gallery picker and headshot progress hook are exercised elsewhere; stub them
-// so this suite focuses on the generate flow.
+// Gallery picker is exercised elsewhere; stub it so this suite focuses on
+// the generate flow.
vi.mock('../components/imageGen/GalleryImagePicker', () => ({ default: () => null }));
-vi.mock('../hooks/useMediaJobProgress', () => ({
- default: () => ({ status: 'unknown', currentImage: null, step: 0, totalSteps: null, filename: null, path: null, error: null }),
-}));
+
+// Drive the headshot-progress hook from a mutable module-level value so a test
+// can transition an in-flight async render to 'completed' between renders. The
+// real hook subscribes to sockets; here the test owns the returned snapshot.
+const idleProgress = () => ({
+ status: 'unknown', currentImage: null, step: 0, totalSteps: null, filename: null, path: null, error: null,
+});
+let hookState = idleProgress();
+vi.mock('../hooks/useMediaJobProgress', () => ({ default: () => hookState }));
describe('Authors headshot generation', () => {
beforeEach(() => {
@@ -39,6 +45,7 @@ describe('Authors headshot generation', () => {
generateImage.mockReset();
toastSuccess.mockReset();
toastError.mockReset();
+ hookState = idleProgress();
});
const openCreateForm = async () => {
@@ -47,6 +54,12 @@ describe('Authors headshot generation', () => {
fireEvent.click(screen.getByRole('button', { name: /New Author/i }));
};
+ // Re-render the component without changing generation state, so a freshly
+ // mutated `hookState` is observed (mirrors a socket-driven hook update).
+ const nudgeRerender = () => fireEvent.change(
+ screen.getByPlaceholderText('Jane Doe'), { target: { value: `n${Math.random()}` } },
+ );
+
it('disables Generate until a description or style is provided', async () => {
await openCreateForm();
const genBtn = screen.getByRole('button', { name: /Generate/i });
@@ -74,18 +87,68 @@ describe('Authors headshot generation', () => {
const payload = generateImage.mock.calls[0][0];
expect(payload.prompt).toContain('Woman in her 40s, warm gaze');
expect(payload.prompt).toContain('Studio portrait, 85mm');
+ // The caller owns the error toast, so the API call must be silent.
+ expect(generateImage.mock.calls[0][1]).toMatchObject({ silent: true });
const img = await screen.findByAltText('Author headshot');
expect(img.getAttribute('src')).toBe('/data/images/headshot.png');
});
- it('toasts when generation fails', async () => {
+ it('tracks an async (jobId) render and lands the completed image', async () => {
+ generateImage.mockResolvedValue({ jobId: 'job-1', filename: 'job-1.png', path: '/data/images/job-1.png' });
+ await openCreateForm();
+ fireEvent.change(screen.getByPlaceholderText(/silver-streaked dark hair/i), {
+ target: { value: 'Woman in her 40s' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: /Generate/i }));
+ await waitFor(() => expect(generateImage).toHaveBeenCalledTimes(1));
+ // Still rendering — the async job hasn't completed, so no headshot yet.
+ expect(screen.queryByAltText('Author headshot')).toBeNull();
+
+ // Job completes; the hook reports the final filename/path.
+ hookState = { ...idleProgress(), status: 'completed', filename: 'final.png', path: '/data/images/final.png' };
+ nudgeRerender();
+
+ const img = await screen.findByAltText('Author headshot');
+ expect(img.getAttribute('src')).toBe('/data/images/final.png');
+ });
+
+ it('does not overwrite a different author when one is selected mid-render', async () => {
+ generateImage.mockResolvedValue({ jobId: 'job-2', filename: 'job-2.png', path: '/data/images/job-2.png' });
+ listAuthors.mockResolvedValue([
+ { id: 'a1', name: 'Alice', headshotImageUrl: '' },
+ { id: 'a2', name: 'Bob', headshotImageUrl: '' },
+ ]);
+ render(<Authors />);
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Alice' }));
+ fireEvent.change(screen.getByPlaceholderText(/silver-streaked dark hair/i), {
+ target: { value: 'Alice description' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: /Generate/i }));
+ await waitFor(() => expect(generateImage).toHaveBeenCalledTimes(1));
+
+ // Switch to Bob before the render finishes — this cancels the tracking.
+ fireEvent.click(screen.getByRole('button', { name: 'Bob' }));
+
+ // Alice's job now reports completion, but it must not write Bob's headshot.
+ hookState = { ...idleProgress(), status: 'completed', filename: 'alice.png', path: '/data/images/alice.png' };
+ nudgeRerender();
+
+ await waitFor(() => expect(toastSuccess).not.toHaveBeenCalledWith('Headshot generated'));
+ expect(screen.queryByAltText('Author headshot')).toBeNull();
+ });
+
+ it('toasts exactly once when generation fails', async () => {
generateImage.mockRejectedValue(new Error('backend down'));
await openCreateForm();
fireEvent.change(screen.getByPlaceholderText(/silver-streaked dark hair/i), {
target: { value: 'Woman in her 40s' },
});
fireEvent.click(screen.getByRole('button', { name: /Generate/i }));
+ // `silent: true` keeps the apiCore helper from adding a second toast — only
+ // this component's catch fires.
await waitFor(() => expect(toastError).toHaveBeenCalledWith('backend down'));
+ expect(toastError).toHaveBeenCalledTimes(1);
});
});