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 (codex): pin the avatar guard's resetKey at its call site (#4688)

[._.]/ Adam Eivyd259400d1160
diff --git a/client/src/components/cos/MiniCharacterCoSAvatar.test.jsx b/client/src/components/cos/MiniCharacterCoSAvatar.test.jsx
new file mode 100644
index 0000000000..f20e9343f7
--- /dev/null
+++ b/client/src/components/cos/MiniCharacterCoSAvatar.test.jsx
@@ -0,0 +1,51 @@
+import { render, screen, waitFor } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+// The guard is what this covers the WIRING of, so it is stubbed to record the
+// props it receives. Without this, `resetKey={url}` could be deleted at the
+// call site and CoSCanvasGuard's own tests would stay green while switching
+// characters after a failed model regressed in production.
+const guardProps = vi.hoisted(() => []);
+vi.mock('./CoSCanvasGuard', () => ({
+ default: (props) => {
+ guardProps.push(props);
+ return <div data-testid="canvas-guard" data-reset-key={props.resetKey}>{props.children}</div>;
+ },
+}));
+// jsdom has no WebGL context and none of the scene is under test here, so the
+// Canvas is stubbed CHILDLESS — rendering the subtree would run three.js object
+// code against r3f's HTMLElement stand-ins. Only which props reach the guard
+// matters, and the guard sits OUTSIDE the canvas.
+vi.mock('@react-three/fiber', () => ({
+ Canvas: () => <div data-testid="mini-canvas" />,
+ useFrame: vi.fn(),
+}));
+
+import MiniCharacterCoSAvatar from './MiniCharacterCoSAvatar';
+
+describe('MiniCharacterCoSAvatar', () => {
+ beforeEach(() => {
+ guardProps.length = 0;
+ // The component HEAD-probes the model before mounting the canvas.
+ vi.stubGlobal('fetch', vi.fn(() => Promise.resolve({ ok: true })));
+ });
+ afterEach(() => { vi.unstubAllGlobals(); });
+
+ // A single guard instance is reused across variants, so the guard needs to be
+ // told when the model changed — otherwise one character's dead GLB leaves the
+ // failure panel up for every character picked afterwards.
+ it('keys the canvas guard on the model url so switching characters clears a failure', async () => {
+ const { rerender } = render(<MiniCharacterCoSAvatar variant="mini-male-c" />);
+ await waitFor(() => expect(screen.getByTestId('canvas-guard')).toBeInTheDocument());
+ expect(screen.getByTestId('canvas-guard')).toHaveAttribute(
+ 'data-reset-key',
+ '/api/avatar/model.glb?variant=mini-male-c',
+ );
+
+ rerender(<MiniCharacterCoSAvatar variant="mini-female-d" />);
+ await waitFor(() => expect(screen.getByTestId('canvas-guard')).toHaveAttribute(
+ 'data-reset-key',
+ '/api/avatar/model.glb?variant=mini-female-d',
+ ));
+ });
+});