shell-env.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect, test } from "bun:test"
  2. import { isNushell, mergeShellEnv, parseShellEnv } from "./shell-env"
  3. describe("shell env", () => {
  4. test("parseShellEnv supports null-delimited pairs", () => {
  5. const env = parseShellEnv(Buffer.from("PATH=/usr/bin:/bin\0FOO=bar=baz\0\0"))
  6. expect(env.PATH).toBe("/usr/bin:/bin")
  7. expect(env.FOO).toBe("bar=baz")
  8. })
  9. test("parseShellEnv ignores invalid entries", () => {
  10. const env = parseShellEnv(Buffer.from("INVALID\0=empty\0OK=1\0"))
  11. expect(Object.keys(env).length).toBe(1)
  12. expect(env.OK).toBe("1")
  13. })
  14. test("mergeShellEnv keeps explicit overrides", () => {
  15. const env = mergeShellEnv(
  16. {
  17. PATH: "/shell/path",
  18. HOME: "/tmp/home",
  19. },
  20. {
  21. PATH: "/desktop/path",
  22. OPENCODE_CLIENT: "desktop",
  23. },
  24. )
  25. expect(env.PATH).toBe("/desktop/path")
  26. expect(env.HOME).toBe("/tmp/home")
  27. expect(env.OPENCODE_CLIENT).toBe("desktop")
  28. })
  29. test("isNushell handles path and binary name", () => {
  30. expect(isNushell("nu")).toBe(true)
  31. expect(isNushell("/opt/homebrew/bin/nu")).toBe(true)
  32. expect(isNushell("C:\\Program Files\\nu.exe")).toBe(true)
  33. expect(isNushell("/bin/zsh")).toBe(false)
  34. })
  35. })