import assert from "node:assert/strict"; import test from "node:test"; import { selectInstanceValue } from "./model.mjs"; test("indexed simulator identity selection uses explicit HWLAB_INSTANCE_INDEX", () => { assert.equal( selectInstanceValue("boxsimu_1,boxsimu_2", "fallback", { index: "1", hostname: "deployment-shaped-pod", requireIndexForMultiple: true, label: "HWLAB_BOX_ID" }), "boxsimu_2" ); }); test("indexed simulator identity selection uses StatefulSet hostname ordinal", () => { assert.equal( selectInstanceValue("res_boxsimu_1,res_boxsimu_2", "fallback", { index: "", hostname: "hwlab-box-simu-1", requireIndexForMultiple: true, label: "HWLAB_BOX_RESOURCE_ID" }), "res_boxsimu_2" ); }); test("multi-value simulator identities fail closed without an instance index", () => { assert.throws( () => selectInstanceValue("gwsimu_1,gwsimu_2", "fallback", { index: "", hostname: "hwlab-gateway-simu-random-suffix", requireIndexForMultiple: true, label: "HWLAB_GATEWAY_ID" }), /HWLAB_GATEWAY_ID declares 2 indexed values/u ); }); test("single simulator identity value still works without an index", () => { assert.equal( selectInstanceValue("boxsimu_1", "fallback", { index: "", hostname: "deployment-shaped-pod", requireIndexForMultiple: true, label: "HWLAB_BOX_ID" }), "boxsimu_1" ); });