Fix LaunchAgent missing TMPDIR causing SQLITE_CANTOPEN on macOS (#20512)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 25ba59765d
Co-authored-by: Clawborn <261310391+Clawborn@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Clawborn
2026-02-19 10:42:35 +08:00
committed by GitHub
parent c2b6f099c6
commit 2bb8ead187
4 changed files with 58 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { resolveGatewayStateDir } from "./paths.js";
@@ -282,6 +283,22 @@ describe("buildServiceEnvironment", () => {
}
});
it("forwards TMPDIR from the host environment", () => {
const env = buildServiceEnvironment({
env: { HOME: "/home/user", TMPDIR: "/var/folders/xw/abc123/T/" },
port: 18789,
});
expect(env.TMPDIR).toBe("/var/folders/xw/abc123/T/");
});
it("falls back to os.tmpdir when TMPDIR is not set", () => {
const env = buildServiceEnvironment({
env: { HOME: "/home/user" },
port: 18789,
});
expect(env.TMPDIR).toBe(os.tmpdir());
});
it("uses profile-specific unit and label", () => {
const env = buildServiceEnvironment({
env: { HOME: "/home/user", OPENCLAW_PROFILE: "work" },
@@ -301,6 +318,20 @@ describe("buildNodeServiceEnvironment", () => {
});
expect(env.HOME).toBe("/home/user");
});
it("forwards TMPDIR for node services", () => {
const env = buildNodeServiceEnvironment({
env: { HOME: "/home/user", TMPDIR: "/tmp/custom" },
});
expect(env.TMPDIR).toBe("/tmp/custom");
});
it("falls back to os.tmpdir for node services when TMPDIR is not set", () => {
const env = buildNodeServiceEnvironment({
env: { HOME: "/home/user" },
});
expect(env.TMPDIR).toBe(os.tmpdir());
});
});
describe("resolveGatewayStateDir", () => {