const test = require("node:test"); const assert = require("node:assert"); const { selectedChoice } = require("../../tht-gate.js"); // The frontend's reviewer widgets (SelectWidget, ArtifactGateWidget) always send the // picked option in a `choices` ARRAY: { id, kind, choices: [optionId] }. The gate's // select / artifact-gate handlers must read that array — reading a singular `choice` // yields undefined, so the gate answers "no choice received" and re-presents forever. test("selectedChoice reads the frontend's choices[] array (select widget)", () => { assert.equal(selectedChoice({ id: "u1", kind: "select", choices: ["old75_frozen"] }), "old75_frozen"); }); test("selectedChoice reads choices[] for the artifact-gate reject", () => { assert.equal(selectedChoice({ id: "u1", kind: "artifact-gate", choices: ["reject"] }), "reject"); }); test("selectedChoice falls back to the legacy singular choice", () => { assert.equal(selectedChoice({ id: "u1", choice: "a" }), "a"); }); test("selectedChoice returns undefined when nothing is selected", () => { assert.equal(selectedChoice({ id: "u1", choices: [] }), undefined); assert.equal(selectedChoice({ id: "u1" }), undefined); });