|
1 | 1 | import { afterEach, describe, expect, spyOn, test } from "bun:test"; |
2 | 2 | import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
3 | 3 | import { tmpdir } from "node:os"; |
4 | | -import { join } from "node:path"; |
| 4 | +import { isAbsolute, join, posix, win32 } from "node:path"; |
5 | 5 | import * as serviceModule from "../src/service"; |
6 | 6 | import { saveConfig } from "../src/config"; |
7 | 7 | import { windowsEnvIndirectBatchValue } from "../src/lib/win-paths"; |
@@ -695,8 +695,24 @@ describe("launchd service plist", () => { |
695 | 695 | process.env.CODEX_SQLITE_HOME = "relative-sqlite-home"; |
696 | 696 | const plist = buildPlist(); |
697 | 697 |
|
698 | | - expect(plist).toContain("<key>CODEX_SQLITE_HOME</key>"); |
699 | | - expect(plist).not.toContain("<string>relative-sqlite-home</string>"); |
| 698 | + // Assert the emitted value is actually absolute. Rejecting only the raw string would |
| 699 | + // stay green for any other non-absolute transform, which is the whole thing this test |
| 700 | + // exists to catch. The two artifact formats differ, so each is extracted on its own |
| 701 | + // terms: launchd is XML, systemd is a quoted Environment= line. |
| 702 | + const plistValue = /<key>CODEX_SQLITE_HOME<\/key>\s*<string>([^<]*)<\/string>/.exec(plist)?.[1]; |
| 703 | + expect(plistValue).toBeDefined(); |
| 704 | + expect( |
| 705 | + isAbsolute(plistValue!) || posix.isAbsolute(plistValue!) || win32.isAbsolute(plistValue!), |
| 706 | + ).toBe(true); |
| 707 | + expect(plistValue!.endsWith("relative-sqlite-home")).toBe(true); |
| 708 | + |
| 709 | + const unit = buildUnit(); |
| 710 | + const unitValue = /Environment="CODEX_SQLITE_HOME=([^"]*)"/.exec(unit)?.[1]; |
| 711 | + expect(unitValue).toBeDefined(); |
| 712 | + expect( |
| 713 | + isAbsolute(unitValue!) || posix.isAbsolute(unitValue!) || win32.isAbsolute(unitValue!), |
| 714 | + ).toBe(true); |
| 715 | + expect(unitValue!.endsWith("relative-sqlite-home")).toBe(true); |
700 | 716 | } finally { |
701 | 717 | if (inherited === undefined) delete process.env.CODEX_SQLITE_HOME; |
702 | 718 | else process.env.CODEX_SQLITE_HOME = inherited; |
|
0 commit comments