From 486782c576d3d8327108761ce0218687a17ad24f Mon Sep 17 00:00:00 2001 From: ggfevans Date: Fri, 20 Feb 2026 13:20:38 -0800 Subject: [PATCH 1/2] fix: preserve half-width slot placement in YAML Fixes #1248 --- src/lib/utils/yaml.ts | 7 ++++-- src/tests/yaml-roundtrip.test.ts | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/tests/yaml-roundtrip.test.ts diff --git a/src/lib/utils/yaml.ts b/src/lib/utils/yaml.ts index fc64afbd..0e4aa8c7 100644 --- a/src/lib/utils/yaml.ts +++ b/src/lib/utils/yaml.ts @@ -56,7 +56,7 @@ export async function parseYaml(yamlString: string): Promise { /** * Order DeviceType fields according to schema v1.0.0 - * Field order: slug, manufacturer, model, part_number, u_height, is_full_depth, is_powered, + * Field order: slug, manufacturer, model, part_number, u_height, slot_width, is_full_depth, is_powered, * weight, weight_unit, airflow, front_image, rear_image, colour, category, tags, * notes, serial_number, asset_tag, links, custom_fields, interfaces, power_ports, * power_outlets, device_bays, inventory_items, subdevice_role, va_rating @@ -72,6 +72,7 @@ function orderDeviceTypeFields(dt: DeviceType): Record { // --- Physical Properties --- ordered.u_height = dt.u_height; + if (dt.slot_width !== undefined) ordered.slot_width = dt.slot_width; if (dt.is_full_depth !== undefined) ordered.is_full_depth = dt.is_full_depth; if (dt.is_powered !== undefined) ordered.is_powered = dt.is_powered; if (dt.weight !== undefined) ordered.weight = dt.weight; @@ -118,7 +119,7 @@ function orderDeviceTypeFields(dt: DeviceType): Record { /** * Order PlacedDevice fields according to schema v1.0.0 - * Field order: id, device_type, name, position, face, front_image, rear_image, + * Field order: id, device_type, name, position, face, slot_position, front_image, rear_image, * parent_device, device_bay, notes, custom_fields */ function orderPlacedDeviceFields( @@ -132,6 +133,8 @@ function orderPlacedDeviceFields( if (device.name !== undefined) ordered.name = device.name; ordered.position = device.position; ordered.face = device.face; + if (device.slot_position !== undefined) + ordered.slot_position = device.slot_position; // --- Placement Image Override --- if (device.front_image !== undefined) diff --git a/src/tests/yaml-roundtrip.test.ts b/src/tests/yaml-roundtrip.test.ts new file mode 100644 index 00000000..9e17f771 --- /dev/null +++ b/src/tests/yaml-roundtrip.test.ts @@ -0,0 +1,42 @@ +import { describe, it, expect } from "vitest"; +import { serializeLayoutToYaml, parseLayoutYaml } from "$lib/utils/yaml"; +import { + createTestDevice, + createTestDeviceType, + createTestLayout, + createTestRack, +} from "./factories"; + +describe("YAML layout round-trip", () => { + it("preserves half-width slot width and slot position", async () => { + const halfWidth = createTestDeviceType({ + slug: "half-width-device", + u_height: 1, + slot_width: 1, + }); + + const layout = createTestLayout({ + racks: [ + createTestRack({ + id: "rack-1", + devices: [ + createTestDevice({ + id: "placed-1", + device_type: halfWidth.slug, + position: 10, + face: "front", + slot_position: "left", + }), + ], + }), + ], + device_types: [halfWidth], + }); + + const yaml = await serializeLayoutToYaml(layout); + const restored = await parseLayoutYaml(yaml); + + expect(restored.device_types[0]?.slot_width).toBe(1); + expect(restored.racks[0]?.devices[0]?.slot_position).toBe("left"); + }); +}); From 41ede6ff13c1b6f060924336ee9e41e4426578fb Mon Sep 17 00:00:00 2001 From: ggfevans Date: Wed, 25 Feb 2026 01:01:39 -0800 Subject: [PATCH 2/2] fix(test): remove redundant face property from test fixture The createTestDevice factory already defaults face to "front", so the explicit assignment was unnecessary. Addresses CodeRabbit review feedback. Co-Authored-By: Claude Opus 4.6 --- src/tests/yaml-roundtrip.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/yaml-roundtrip.test.ts b/src/tests/yaml-roundtrip.test.ts index 9e17f771..f6a93886 100644 --- a/src/tests/yaml-roundtrip.test.ts +++ b/src/tests/yaml-roundtrip.test.ts @@ -24,7 +24,6 @@ describe("YAML layout round-trip", () => { id: "placed-1", device_type: halfWidth.slug, position: 10, - face: "front", slot_position: "left", }), ],