Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/helpers/onboard-machine-runtime-fixture.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
3 changes: 2 additions & 1 deletion test/helpers/onboard-machine-runtime-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Loading