fix(core): coerce unknown material.preset to 'custom' (Sentry MONOREPO-EDITOR-DB) (#400)

Co-authored-by: openclaw-agent <agent@pascal.app>
This commit is contained in:
Anton
2026-06-24 15:52:22 -04:00
committed by GitHub
co-authored by openclaw-agent
parent a71de82ccb
commit 05771270e3
2 changed files with 51 additions and 1 deletions
+49
View File
@@ -0,0 +1,49 @@
import { describe, expect, test } from 'bun:test'
import { MaterialSchema } from './material'
describe('MaterialSchema', () => {
describe('preset', () => {
test('valid preset passes through unchanged', () => {
const result = MaterialSchema.parse({ preset: 'brick' })
expect(result.preset).toBe('brick')
})
test('every enum preset is accepted', () => {
const presets = [
'white',
'brick',
'concrete',
'wood',
'glass',
'metal',
'plaster',
'tile',
'marble',
'custom',
] as const
for (const preset of presets) {
expect(MaterialSchema.parse({ preset }).preset).toBe(preset)
}
})
test("unknown preset coerces to 'custom' instead of throwing (Sentry MONOREPO-EDITOR-DB)", () => {
const result = MaterialSchema.parse({ preset: 'stone' })
expect(result.preset).toBe('custom')
})
test("non-string preset coerces to 'custom'", () => {
const result = MaterialSchema.parse({ preset: 42 })
expect(result.preset).toBe('custom')
})
test('missing preset stays undefined', () => {
const result = MaterialSchema.parse({})
expect(result.preset).toBeUndefined()
})
test('explicit undefined preset stays undefined', () => {
const result = MaterialSchema.parse({ preset: undefined })
expect(result.preset).toBeUndefined()
})
})
})
+2 -1
View File
@@ -27,7 +27,8 @@ export type MaterialProperties = z.infer<typeof MaterialProperties>
export const MaterialSchema = z.object({
id: z.string().optional(),
preset: MaterialPreset.optional(),
// Coerce unknown presets (legacy/AI-generated data) to 'custom' instead of throwing.
preset: MaterialPreset.catch('custom').optional(),
properties: MaterialProperties.optional(),
texture: z
.object({