The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(theme): reject an import whose colors are null, an array, or empty
M3gA-Mind88bc7f6c1d92
diff --git a/app/src/components/settings/panels/ThemeStudioPanel.test.tsx b/app/src/components/settings/panels/ThemeStudioPanel.test.tsxindex 9bf5074fd2..46a84719a3 100644--- a/app/src/components/settings/panels/ThemeStudioPanel.test.tsx+++ b/app/src/components/settings/panels/ThemeStudioPanel.test.tsx@@ -79,4 +79,50 @@ describe('<ThemeStudioPanel />', () => {backdrop: { kind: 'image', imageUrl: 'https://example.com/bg.jpg' },});});++ // #5901: `typeof null === 'object'` and `typeof [] === 'object'`, so the old+ // shape check let both through; `{ ...null }` and `{ ...[] }` each yield `{}`,+ // and a zero-token theme was stored and could be activated from the gallery.+ // `{}` is refused for the same reason — `applyTheme` writes one custom+ // property per token, so a colourless theme applies nothing at all.+ it.each([+ ['null colors', null],+ ['an array of colors', []],+ ['an empty colors object', {}],+ ['a string colors value', 'surface'],+ ['a numeric colors value', 42],+ ])('refuses to import a theme with %s', (_label, colors) => {+ const { store } = renderWithProviders(<ThemeStudioPanel />, {+ preloadedState: { theme: themeState },+ initialEntries: ['/settings/theme'],+ });++ fireEvent.change(screen.getByLabelText('Import theme'), {+ target: { value: JSON.stringify({ name: 'Colourless', isDark: false, colors }) },+ });+ fireEvent.click(screen.getByRole('button', { name: 'Import' }));++ expect(screen.getByText('Could not parse that theme JSON.')).toBeInTheDocument();+ expect(store.getState().theme.customThemes).toHaveLength(0);+ });++ it('still imports a theme carrying a single colour token', () => {+ const { store } = renderWithProviders(<ThemeStudioPanel />, {+ preloadedState: { theme: themeState },+ initialEntries: ['/settings/theme'],+ });++ fireEvent.change(screen.getByLabelText('Import theme'), {+ target: {+ value: JSON.stringify({ name: 'Minimal', isDark: false, colors: { surface: '1 2 3' } }),+ },+ });+ fireEvent.click(screen.getByRole('button', { name: 'Import' }));++ expect(store.getState().theme.customThemes).toHaveLength(1);+ expect(store.getState().theme.customThemes[0]).toMatchObject({+ name: 'Minimal',+ colors: { surface: '1 2 3' },+ });+ });});diff --git a/app/src/components/settings/panels/ThemeStudioPanel.tsx b/app/src/components/settings/panels/ThemeStudioPanel.tsxindex 9404dc3837..bd1b64c757 100644--- a/app/src/components/settings/panels/ThemeStudioPanel.tsx+++ b/app/src/components/settings/panels/ThemeStudioPanel.tsx@@ -88,6 +88,37 @@ function tileCanvas(theme: Theme): string {return theme.gradient?.canvas ?? channelsToCss(swatchChannels(theme, 'surface-canvas'));}+/**+ * Does this value carry at least one colour token?+ *+ * The old check was `typeof parsed.colors !== 'object'`, which passes for+ * `null` and for an array — `typeof null` and `typeof []` are both `'object'`.+ * Execution then reached `colors: { ...(parsed.colors) }`, and spreading either+ * yields `{}`, so a theme with ZERO colour tokens was written to the store and+ * could be activated from the gallery (#5901).+ *+ * An empty object is refused for the same reason, not merely for tidiness: its+ * user-visible outcome is identical to `null`. `applyTheme` writes one custom+ * property per token and `withDerivedChrome` derives only FROM existing tokens+ * (`lib/theme/chrome.ts:67-79`), so a zero-token theme applies nothing at all —+ * a named entry in the gallery that silently does nothing when clicked.+ * Accepting `{}` while rejecting `null` would fix the shape and leave the+ * defect.+ *+ * The cost, stated plainly: a fonts-or-backdrop-only theme can no longer be+ * imported without at least one colour. That was never really supported —+ * `colors` has always been a required field here — and it is the narrower+ * trade against shipping a theme that does nothing.+ */+function hasColorTokens(colors: unknown): colors is Record<string, string> {+ return (+ typeof colors === 'object' &&+ colors !== null &&+ !Array.isArray(colors) &&+ Object.keys(colors).length > 0+ );+}+function importedGradient(parsed: Partial<Theme>): Theme['gradient'] {if (!parsed.gradient || typeof parsed.gradient !== 'object') return undefined;return typeof parsed.gradient.canvas === 'string' ? { canvas: parsed.gradient.canvas } : {};@@ -148,7 +179,7 @@ const ThemeStudioPanel = ({ embedded = false }: ThemeStudioPanelProps = {}) => {setImportError('');try {const parsed = JSON.parse(importText) as Partial<Theme>;- if (!parsed || typeof parsed !== 'object' || typeof parsed.colors !== 'object') {+ if (!parsed || typeof parsed !== 'object' || !hasColorTokens(parsed.colors)) {throw new Error('shape');}const theme: Theme = {