import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const output = fs.mkdtempSync(path.join(os.tmpdir(), "assembly-response-state-")); try { execFileSync(path.join(root, "web/node_modules/.bin/tsc"), [ "-p", path.join(root, "web/tsconfig.json"), "--noEmit", "false", "--outDir", output, ], { stdio: "inherit" }); const { applyAssemblyResponse, prepareAssemblyCommand } = await import( pathToFileURL(path.join(output, "assembly-desktop-adapter.js"))); const documentId = "CurrentDocument"; for (const command of ["Assembly_CreateAssembly", "Assembly_ActivateAssembly"]) { const record = { command, id: `Assembly:desktop:${command}`, module: "Assembly" }; const active = new Map([[documentId, "OriginalAssembly"]]); let selections = 0; const response = selection => ({ kind: "result", result: { records: [{ apiId: record.id, status: "exposed", result: { documentId, assembly: "NextAssembly", object: "NextAssembly", activeAssembly: "NextAssembly", selection, }, }] } }); const rejected = applyAssemblyResponse(record, response([{ documentId, object: "" }]), record.id, documentId, active, () => selections++); assert.notEqual(rejected.kind, "result"); assert.equal(active.get(documentId), "OriginalAssembly"); assert.equal(selections, 0); const joint = prepareAssemblyCommand({ command: "Assembly_CreateJointFixed", id: "Assembly:desktop:Assembly_CreateJointFixed", module: "Assembly" }, { references: [{ object: "First", subelements: [""] }, { object: "Second", subelements: [""] }] }, documentId, active); assert.equal(joint.args.assembly, "OriginalAssembly"); const accepted = applyAssemblyResponse(record, response([{ documentId, object: "NextAssembly" }]), record.id, documentId, active, () => selections++); assert.equal(accepted.kind, "result"); assert.equal(active.get(documentId), "NextAssembly"); assert.equal(selections, 1); } console.log("Assembly response state: rejected activation preserves joint target; valid activation commits (2 routes passed)"); } finally { fs.rmSync(output, { recursive: true, force: true }); }