fix: Stop the automatic upgrade from discarding valid configuration (#2692)

- Closes #2689
This commit is contained in:
Dermot Duffy
2026-08-19 17:02:46 -07:00
committed by GitHub
parent 84b90bcc7e
commit 1e03e6a3d9
7 changed files with 749 additions and 89 deletions
@@ -0,0 +1,30 @@
import { describe, expect, it } from 'vitest';
import { z } from 'zod';
import { preprocessToArray } from '../../../../src/config/schema/common/preprocess-to-array';
const schema = z.object({
items: preprocessToArray(z.object({ name: z.string() }).array()).optional(),
});
describe('preprocessToArray', () => {
it('should keep a list as it is', () => {
expect(schema.parse({ items: [{ name: 'office' }] })).toEqual({
items: [{ name: 'office' }],
});
});
it('should normalise a single item to a list', () => {
expect(schema.parse({ items: { name: 'office' } })).toEqual({
items: [{ name: 'office' }],
});
});
it('should read a key written with no value as a list of nothing', () => {
expect(schema.parse({ items: null })).toEqual({ items: [] });
});
it('should leave an absent optional field absent', () => {
expect(schema.parse({})).toEqual({});
});
});