fix: clean up Hermes-visible OpenClaw leftovers (#97)
* cleanup openclaw session leftovers - hermes can breathe now * fix: load hermes adapter env from .env * fix: redact secrets from hermes adapter error output * addressed review findings * address luke findings #2
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
describe("loadLocalGatewayDefaults with CLAW3D_GATEWAY_URL", () => {
|
||||
const originalEnv = { ...process.env };
|
||||
@@ -17,7 +20,14 @@ describe("loadLocalGatewayDefaults with CLAW3D_GATEWAY_URL", () => {
|
||||
"../../src/lib/studio/settings-store"
|
||||
);
|
||||
const result = loadLocalGatewayDefaults();
|
||||
expect(result).toEqual({ url: "ws://my-gateway:18789", token: "my-token" });
|
||||
expect(result).toEqual({
|
||||
url: "ws://my-gateway:18789",
|
||||
token: "my-token",
|
||||
adapterType: "openclaw",
|
||||
profiles: {
|
||||
openclaw: { url: "ws://my-gateway:18789", token: "my-token" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns env-based defaults with empty token when only URL is set", async () => {
|
||||
@@ -28,7 +38,14 @@ describe("loadLocalGatewayDefaults with CLAW3D_GATEWAY_URL", () => {
|
||||
"../../src/lib/studio/settings-store"
|
||||
);
|
||||
const result = loadLocalGatewayDefaults();
|
||||
expect(result).toEqual({ url: "ws://my-gateway:18789", token: "" });
|
||||
expect(result).toEqual({
|
||||
url: "ws://my-gateway:18789",
|
||||
token: "",
|
||||
adapterType: "openclaw",
|
||||
profiles: {
|
||||
openclaw: { url: "ws://my-gateway:18789", token: "" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null when no env var and no openclaw.json", async () => {
|
||||
@@ -57,4 +74,110 @@ describe("loadLocalGatewayDefaults with CLAW3D_GATEWAY_URL", () => {
|
||||
}
|
||||
// If no file exists in CI, it falls back to env — that's also correct
|
||||
});
|
||||
|
||||
it("uses CLAW3D_GATEWAY_ADAPTER_TYPE for Hermes env defaults", async () => {
|
||||
process.env.CLAW3D_GATEWAY_URL = "ws://my-hermes:18789";
|
||||
process.env.CLAW3D_GATEWAY_ADAPTER_TYPE = "hermes";
|
||||
delete process.env.CLAW3D_GATEWAY_TOKEN;
|
||||
process.env.OPENCLAW_STATE_DIR = "/tmp/claw3d-test-nonexistent-" + Date.now();
|
||||
const { loadLocalGatewayDefaults } = await import(
|
||||
"../../src/lib/studio/settings-store"
|
||||
);
|
||||
const result = loadLocalGatewayDefaults();
|
||||
expect(result).toEqual({
|
||||
url: "ws://my-hermes:18789",
|
||||
token: "",
|
||||
adapterType: "hermes",
|
||||
profiles: {
|
||||
hermes: { url: "ws://my-hermes:18789", token: "" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("exposes local Hermes adapter defaults when only HERMES_ADAPTER_PORT is set", async () => {
|
||||
delete process.env.CLAW3D_GATEWAY_URL;
|
||||
delete process.env.CLAW3D_GATEWAY_TOKEN;
|
||||
process.env.HERMES_ADAPTER_PORT = "19444";
|
||||
process.env.OPENCLAW_STATE_DIR = "/tmp/claw3d-test-nonexistent-" + Date.now();
|
||||
const { loadLocalGatewayDefaults } = await import(
|
||||
"../../src/lib/studio/settings-store"
|
||||
);
|
||||
const result = loadLocalGatewayDefaults();
|
||||
expect(result).toEqual({
|
||||
url: "ws://localhost:19444",
|
||||
token: "",
|
||||
adapterType: "hermes",
|
||||
profiles: {
|
||||
hermes: { url: "ws://localhost:19444", token: "" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("merges Hermes adapter defaults into file-backed OpenClaw defaults", async () => {
|
||||
delete process.env.CLAW3D_GATEWAY_URL;
|
||||
delete process.env.CLAW3D_GATEWAY_TOKEN;
|
||||
delete process.env.CLAW3D_GATEWAY_ADAPTER_TYPE;
|
||||
process.env.HERMES_ADAPTER_PORT = "19444";
|
||||
|
||||
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "claw3d-gateway-defaults-"));
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
fs.writeFileSync(
|
||||
path.join(stateDir, "openclaw.json"),
|
||||
JSON.stringify({
|
||||
gateway: {
|
||||
port: 18789,
|
||||
auth: { token: "file-token" },
|
||||
},
|
||||
}),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
const { loadLocalGatewayDefaults } = await import(
|
||||
"../../src/lib/studio/settings-store"
|
||||
);
|
||||
const result = loadLocalGatewayDefaults();
|
||||
|
||||
expect(result).toEqual({
|
||||
url: "ws://localhost:18789",
|
||||
token: "file-token",
|
||||
adapterType: "openclaw",
|
||||
profiles: {
|
||||
openclaw: { url: "ws://localhost:18789", token: "file-token" },
|
||||
hermes: { url: "ws://localhost:19444", token: "" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps file-backed openclaw profile when CLAW3D_GATEWAY_URL is also set", async () => {
|
||||
process.env.CLAW3D_GATEWAY_URL = "ws://env-gateway:19999";
|
||||
process.env.CLAW3D_GATEWAY_TOKEN = "env-token";
|
||||
delete process.env.CLAW3D_GATEWAY_ADAPTER_TYPE;
|
||||
|
||||
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "claw3d-gateway-defaults-"));
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
fs.writeFileSync(
|
||||
path.join(stateDir, "openclaw.json"),
|
||||
JSON.stringify({
|
||||
gateway: {
|
||||
port: 18789,
|
||||
auth: { token: "file-token" },
|
||||
},
|
||||
}),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
const { loadLocalGatewayDefaults } = await import(
|
||||
"../../src/lib/studio/settings-store"
|
||||
);
|
||||
const result = loadLocalGatewayDefaults();
|
||||
|
||||
expect(result).toEqual({
|
||||
url: "ws://localhost:18789",
|
||||
token: "file-token",
|
||||
adapterType: "openclaw",
|
||||
profiles: {
|
||||
openclaw: { url: "ws://localhost:18789", token: "file-token" },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user