Skip to content

Commit a7c2ce0

Browse files
committed
fix(desktop): throw on unknown artifact type instead of silent html fallback
1 parent 7f63539 commit a7c2ce0

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { toSnapshotArtifactType } from './store';
3+
4+
describe('toSnapshotArtifactType', () => {
5+
it('folds html/slides/bundle/undefined into html', () => {
6+
expect(toSnapshotArtifactType(undefined)).toBe('html');
7+
expect(toSnapshotArtifactType('html')).toBe('html');
8+
expect(toSnapshotArtifactType('slides')).toBe('html');
9+
expect(toSnapshotArtifactType('bundle')).toBe('html');
10+
});
11+
12+
it('passes svg and react through', () => {
13+
expect(toSnapshotArtifactType('svg')).toBe('svg');
14+
expect(toSnapshotArtifactType('react')).toBe('react');
15+
});
16+
17+
it('throws on unknown coreType instead of silently returning html', () => {
18+
expect(() => toSnapshotArtifactType('mystery')).toThrow(
19+
/Unsupported artifact type for snapshot persistence: mystery/,
20+
);
21+
});
22+
});

apps/desktop/src/renderer/src/store.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,25 @@ function isDefaultDesignName(name: string): boolean {
283283
}
284284

285285
// Core emits 'html' | 'svg' | 'slides' | 'bundle' but the snapshots schema only
286-
// stores 'html' | 'react' | 'svg' (see DesignSnapshotV1). 'slides'/'bundle' fall
287-
// through to 'html' because their on-disk source is HTML — keeping the column
286+
// stores 'html' | 'react' | 'svg' (see DesignSnapshotV1). 'slides'/'bundle' fold
287+
// into 'html' because their on-disk source is HTML — keeping the column
288288
// constraint stable means we don't need a schema migration to persist them.
289-
function toSnapshotArtifactType(coreType: string | undefined): 'html' | 'react' | 'svg' {
290-
if (coreType === 'svg') return 'svg';
291-
if (coreType === 'react') return 'react';
292-
return 'html';
289+
// Unknown types throw so a new core ArtifactType doesn't silently round-trip
290+
// as the wrong renderer.
291+
export function toSnapshotArtifactType(coreType: string | undefined): 'html' | 'react' | 'svg' {
292+
switch (coreType) {
293+
case undefined:
294+
case 'html':
295+
case 'slides':
296+
case 'bundle':
297+
return 'html';
298+
case 'svg':
299+
return 'svg';
300+
case 'react':
301+
return 'react';
302+
default:
303+
throw new Error(`Unsupported artifact type for snapshot persistence: ${coreType}`);
304+
}
293305
}
294306

295307
interface PersistArtifact {

0 commit comments

Comments
 (0)