import { test, expect } from "vitest"; import { selectDaemonTarget, describeDaemonTarget } from "./daemon-target.js"; test("explicit selectors win over both environment selectors", () => { const env = { PASEO_HOME: "/tmp/a", PASEO_HOST: "unused:12345" }; expect(selectDaemonTarget({ home: "/tmp/b" }, env)).toEqual({ kind: "instance", home: "/tmp/b" }); expect(selectDaemonTarget({ host: "chosen:23456" }, env)).toEqual({ kind: "endpoint", host: "chosen:23456", }); expect(() => selectDaemonTarget({}, env)).toThrow(); expect(() => selectDaemonTarget({ home: "/tmp/b", host: "chosen:23456" }, {})).toThrow(); }); test("local operations ignore routing environment but reject an explicit endpoint", () => { expect( selectDaemonTarget({}, { PASEO_HOME: "/tmp/b", PASEO_HOST: "unused:12345" }, true), ).toEqual({ kind: "instance", home: "/tmp/b" }); expect(() => selectDaemonTarget({ host: "chosen:23456" }, {}, true)).toThrow(); }); test("endpoint descriptions redact pairing material and credentials", () => { expect( describeDaemonTarget({ kind: "endpoint", host: "tcp://user:private@example.test:23456?password=secret", }), ).not.toMatch(/private|secret/); expect( describeDaemonTarget({ kind: "endpoint", host: "https://app.paseo.sh/#offer=private" }), ).not.toContain("private"); });