diff --git a/test/helpers/onboard-machine-runtime-fixture.test.ts b/test/helpers/onboard-machine-runtime-fixture.test.ts new file mode 100644 index 00000000000..0954f96ad91 --- /dev/null +++ b/test/helpers/onboard-machine-runtime-fixture.test.ts @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it } from "vitest"; +import { cloneSession, createSession } from "./onboard-machine-runtime-fixture"; + +describe("cloneSession", () => { + it("isolates invalid session state when normalization rejects the copy", () => { + const session = createSession(); + session.version = 0; + + const copy = cloneSession(session); + + expect(copy).not.toBe(session); + expect(copy.steps).not.toBe(session.steps); + + copy.status = "failed"; + copy.steps.preflight.status = "failed"; + + expect(session.status).toBe("in_progress"); + expect(session.steps.preflight.status).toBe("pending"); + }); +}); diff --git a/test/helpers/onboard-machine-runtime-fixture.ts b/test/helpers/onboard-machine-runtime-fixture.ts index 58b88d01a95..78287c67be8 100644 --- a/test/helpers/onboard-machine-runtime-fixture.ts +++ b/test/helpers/onboard-machine-runtime-fixture.ts @@ -27,7 +27,8 @@ export type { Session, SessionUpdates } from "../../src/lib/state/onboard-sessio /** A deep session copy that survives independent mutation. */ export function cloneSession(session: Session): Session { - return normalizeSession(JSON.parse(JSON.stringify(session))) ?? session; + const copy = JSON.parse(JSON.stringify(session)) as Session; + return normalizeSession(copy) ?? copy; } /** Behavior options for createTestRuntime. */