|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { readFileSync } from "node:fs"; |
| 3 | +import { join } from "node:path"; |
| 4 | + |
| 5 | +// Source-contract regressions for the final fixes that let devlog |
| 6 | +// 260702_windows-deploy-stability close: the ocx.cmd shell-less restart (A), F9 systemd no-DBUS |
| 7 | +// SSH detection (E), and the F4 explicit-localhost bind symmetry (D). These files run top-level or |
| 8 | +// platform-gated logic, so guard the invariants at the source level (repo convention — see |
| 9 | +// ocx-launcher-source.test.ts / service.test.ts). |
| 10 | +const read = (rel: string) => readFileSync(join(import.meta.dir, "..", rel), "utf8"); |
| 11 | + |
| 12 | +describe("update-job restart avoids the shell-less .cmd EINVAL (Windows, bun/source)", () => { |
| 13 | + const src = read("src/update-job.ts"); |
| 14 | + test("no ocx.cmd shim is spawned for restart", () => { |
| 15 | + expect(src).not.toContain('"ocx.cmd"'); |
| 16 | + expect(src).not.toMatch(/function ocxBin/); |
| 17 | + }); |
| 18 | + test("bun/source restart uses the runtime executable + launcher (a real .exe, no shell)", () => { |
| 19 | + // restartCommand's non-npm branch resolves to process.execPath + the package launcher. |
| 20 | + expect(src).toMatch(/const bin = process\.execPath;\s*\n\s*const args = serviceInstalled \? \[launcher, "service", "install"\] : \[launcher, "start"\];/); |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +describe("systemd detection tolerates a no-DBUS SSH session (F9)", () => { |
| 25 | + const src = read("src/service.ts"); |
| 26 | + test("isSystemd falls back to the per-user runtime dir when the user-bus probe fails", () => { |
| 27 | + expect(src).toContain("function userRuntimeDir()"); |
| 28 | + expect(src).toContain("function ensureUserBusEnv()"); |
| 29 | + // The version probe passing + a runtime dir existing is enough — not a hard fail on the --user probe. |
| 30 | + expect(src).toMatch(/catch \{ \/\* no user bus in this session \*\/ \}\s*\n\s*return userRuntimeDir\(\) !== null;/); |
| 31 | + }); |
| 32 | + test("install ensures the user-bus env before touching systemctl --user", () => { |
| 33 | + expect(src).toMatch(/function installSystemd\(\): void \{\s*\n\s*ensureUserBusEnv\(\);/); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe("server bind canonicalizes explicit localhost but preserves wildcards (F4 symmetry)", () => { |
| 38 | + const src = read("src/server.ts"); |
| 39 | + test("literal localhost binds to 127.0.0.1; 0.0.0.0/:: exposure is untouched", () => { |
| 40 | + expect(src).toContain('/^localhost$/i.test(config.hostname ?? "") ? "127.0.0.1"'); |
| 41 | + expect(src).toContain("hostname: bindHost,"); |
| 42 | + // Must not blanket-rewrite the bind host (that would break intentional 0.0.0.0 exposure). |
| 43 | + expect(src).not.toContain('hostname: "127.0.0.1",'); |
| 44 | + }); |
| 45 | +}); |
0 commit comments