|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { describe, it, expect } from "vitest"; |
| 5 | +import { resolveOpenshell } from "../../dist/lib/resolve-openshell"; |
| 6 | + |
| 7 | +describe("lib/resolve-openshell", () => { |
| 8 | + it("returns command -v result when absolute path", () => { |
| 9 | + expect(resolveOpenshell({ commandVResult: "/usr/bin/openshell" })).toBe("/usr/bin/openshell"); |
| 10 | + }); |
| 11 | + |
| 12 | + it("rejects non-absolute command -v result (alias)", () => { |
| 13 | + expect( |
| 14 | + resolveOpenshell({ commandVResult: "openshell", checkExecutable: () => false }), |
| 15 | + ).toBeNull(); |
| 16 | + }); |
| 17 | + |
| 18 | + it("rejects alias definition from command -v", () => { |
| 19 | + expect( |
| 20 | + resolveOpenshell({ |
| 21 | + commandVResult: "alias openshell='echo pwned'", |
| 22 | + checkExecutable: () => false, |
| 23 | + }), |
| 24 | + ).toBeNull(); |
| 25 | + }); |
| 26 | + |
| 27 | + it("falls back to ~/.local/bin when command -v fails", () => { |
| 28 | + expect( |
| 29 | + resolveOpenshell({ |
| 30 | + commandVResult: null, |
| 31 | + checkExecutable: (p) => p === "/fakehome/.local/bin/openshell", |
| 32 | + home: "/fakehome", |
| 33 | + }), |
| 34 | + ).toBe("/fakehome/.local/bin/openshell"); |
| 35 | + }); |
| 36 | + |
| 37 | + it("falls back to /usr/local/bin", () => { |
| 38 | + expect( |
| 39 | + resolveOpenshell({ |
| 40 | + commandVResult: null, |
| 41 | + checkExecutable: (p) => p === "/usr/local/bin/openshell", |
| 42 | + }), |
| 43 | + ).toBe("/usr/local/bin/openshell"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("falls back to /usr/bin", () => { |
| 47 | + expect( |
| 48 | + resolveOpenshell({ |
| 49 | + commandVResult: null, |
| 50 | + checkExecutable: (p) => p === "/usr/bin/openshell", |
| 51 | + }), |
| 52 | + ).toBe("/usr/bin/openshell"); |
| 53 | + }); |
| 54 | + |
| 55 | + it("prefers ~/.local/bin over /usr/local/bin", () => { |
| 56 | + expect( |
| 57 | + resolveOpenshell({ |
| 58 | + commandVResult: null, |
| 59 | + checkExecutable: (p) => |
| 60 | + p === "/fakehome/.local/bin/openshell" || p === "/usr/local/bin/openshell", |
| 61 | + home: "/fakehome", |
| 62 | + }), |
| 63 | + ).toBe("/fakehome/.local/bin/openshell"); |
| 64 | + }); |
| 65 | + |
| 66 | + it("returns null when openshell not found anywhere", () => { |
| 67 | + expect( |
| 68 | + resolveOpenshell({ |
| 69 | + commandVResult: null, |
| 70 | + checkExecutable: () => false, |
| 71 | + }), |
| 72 | + ).toBeNull(); |
| 73 | + }); |
| 74 | + |
| 75 | + it("skips home candidate when home is not absolute", () => { |
| 76 | + expect( |
| 77 | + resolveOpenshell({ |
| 78 | + commandVResult: null, |
| 79 | + checkExecutable: () => false, |
| 80 | + home: "relative/path", |
| 81 | + }), |
| 82 | + ).toBeNull(); |
| 83 | + }); |
| 84 | + |
| 85 | +}); |
0 commit comments