Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
281 lines
9.6 KiB
TypeScript
281 lines
9.6 KiB
TypeScript
// Test environment tests validate shared env setup helpers.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { deleteTestEnvValue, setTestEnvValue } from "../src/test-utils/env.js";
|
|
import { cleanupTempDirs, makeTempDir } from "./helpers/temp-dir.js";
|
|
import { installTestEnv } from "./test-env.js";
|
|
|
|
const ORIGINAL_ENV = { ...process.env };
|
|
|
|
const tempDirs = new Set<string>();
|
|
const cleanupFns: Array<() => void> = [];
|
|
|
|
function restoreProcessEnv(): void {
|
|
for (const key of Object.keys(process.env)) {
|
|
if (!(key in ORIGINAL_ENV)) {
|
|
deleteTestEnvValue(key);
|
|
}
|
|
}
|
|
for (const [key, value] of Object.entries(ORIGINAL_ENV)) {
|
|
if (value === undefined) {
|
|
deleteTestEnvValue(key);
|
|
} else {
|
|
setTestEnvValue(key, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
function writeFile(targetPath: string, content: string): void {
|
|
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
fs.writeFileSync(targetPath, content, "utf8");
|
|
}
|
|
|
|
function createTempHome(): string {
|
|
return makeTempDir(tempDirs, "openclaw-test-env-real-home-");
|
|
}
|
|
|
|
function requireRecord(
|
|
value: Record<string, unknown> | undefined,
|
|
label: string,
|
|
): Record<string, unknown> {
|
|
if (!value) {
|
|
throw new Error(`expected copied ${label} config`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function requireTelegramStreaming(
|
|
value:
|
|
| {
|
|
mode?: string;
|
|
chunkMode?: string;
|
|
block?: { enabled?: boolean };
|
|
preview?: { chunk?: { minChars?: number } };
|
|
}
|
|
| undefined,
|
|
) {
|
|
if (!value) {
|
|
throw new Error("expected copied telegram streaming config");
|
|
}
|
|
return value;
|
|
}
|
|
|
|
afterEach(() => {
|
|
while (cleanupFns.length > 0) {
|
|
cleanupFns.pop()?.();
|
|
}
|
|
restoreProcessEnv();
|
|
cleanupTempDirs(tempDirs);
|
|
});
|
|
|
|
describe("installTestEnv", () => {
|
|
it("keeps live tests on a temp HOME while copying config and auth state", () => {
|
|
const realHome = createTempHome();
|
|
const priorIsolatedHome = createTempHome();
|
|
writeFile(path.join(realHome, ".profile"), "export TEST_PROFILE_ONLY=from-profile\n");
|
|
writeFile(
|
|
path.join(realHome, "custom-openclaw.json5"),
|
|
`{
|
|
// Preserve provider config, strip host-bound paths.
|
|
agents: {
|
|
defaults: {
|
|
workspace: "/Users/peter/Projects",
|
|
agentDir: "/Users/peter/.openclaw/agents/main/agent",
|
|
},
|
|
list: [
|
|
{
|
|
id: "dev",
|
|
workspace: "/Users/peter/dev-workspace",
|
|
agentDir: "/Users/peter/.openclaw/agents/dev/agent",
|
|
},
|
|
],
|
|
},
|
|
models: {
|
|
providers: {
|
|
custom: { baseUrl: "https://example.test/v1" },
|
|
},
|
|
},
|
|
channels: {
|
|
telegram: {
|
|
streaming: {
|
|
mode: "block",
|
|
chunkMode: "newline",
|
|
block: {
|
|
enabled: true,
|
|
},
|
|
preview: {
|
|
chunk: {
|
|
minChars: 120,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}`,
|
|
);
|
|
writeFile(path.join(realHome, ".openclaw", "credentials", "token.txt"), "secret\n");
|
|
writeFile(
|
|
path.join(realHome, ".openclaw", "external-plugins", "glueclaw", "openclaw.plugin.json"),
|
|
'{"id":"glueclaw"}\n',
|
|
);
|
|
writeFile(
|
|
path.join(realHome, ".openclaw", "agents", "main", "agent", "auth-profiles.json"),
|
|
JSON.stringify({ version: 1, profiles: { default: { provider: "openai" } } }, null, 2),
|
|
);
|
|
writeFile(path.join(realHome, ".claude", ".credentials.json"), '{"accessToken":"token"}\n');
|
|
writeFile(path.join(realHome, ".claude", "projects", "old-session.jsonl"), "session\n");
|
|
fs.mkdirSync(path.join(realHome, ".claude", "settings.local.json"), { recursive: true });
|
|
writeFile(path.join(realHome, ".codex", "auth.json"), '{"OPENAI_API_KEY":"token"}\n');
|
|
writeFile(path.join(realHome, ".codex", "config.toml"), 'model = "gpt-5.4"\n');
|
|
writeFile(
|
|
path.join(realHome, ".codex", "sessions", "2026", "02", "26", "rollout.jsonl"),
|
|
"session\n",
|
|
);
|
|
|
|
setTestEnvValue("HOME", realHome);
|
|
setTestEnvValue("USERPROFILE", realHome);
|
|
setTestEnvValue("OPENCLAW_LIVE_TEST", "1");
|
|
setTestEnvValue("OPENCLAW_LIVE_TEST_QUIET", "1");
|
|
setTestEnvValue("OPENCLAW_CONFIG_PATH", "~/custom-openclaw.json5");
|
|
setTestEnvValue("OPENCLAW_TEST_HOME", priorIsolatedHome);
|
|
setTestEnvValue("OPENCLAW_STATE_DIR", path.join(priorIsolatedHome, ".openclaw"));
|
|
|
|
const testEnv = installTestEnv();
|
|
cleanupFns.push(testEnv.cleanup);
|
|
|
|
expect(testEnv.tempHome).not.toBe(realHome);
|
|
expect(process.env.HOME).toBe(testEnv.tempHome);
|
|
expect(process.env.OPENCLAW_TEST_HOME).toBe(testEnv.tempHome);
|
|
expect(process.env.TEST_PROFILE_ONLY).toBe("from-profile");
|
|
|
|
const copiedConfigPath = path.join(testEnv.tempHome, ".openclaw", "openclaw.json");
|
|
const copiedConfig = JSON.parse(fs.readFileSync(copiedConfigPath, "utf8")) as {
|
|
agents?: {
|
|
defaults?: Record<string, unknown>;
|
|
list?: Array<Record<string, unknown>>;
|
|
};
|
|
models?: { providers?: Record<string, unknown> };
|
|
channels?: {
|
|
telegram?: {
|
|
streaming?: {
|
|
mode?: string;
|
|
chunkMode?: string;
|
|
block?: { enabled?: boolean };
|
|
preview?: { chunk?: { minChars?: number } };
|
|
};
|
|
};
|
|
};
|
|
};
|
|
const providers = copiedConfig.models?.providers;
|
|
requireRecord(providers, "model providers");
|
|
expect(providers.custom).toEqual({ baseUrl: "https://example.test/v1" });
|
|
|
|
const agentDefaults = requireRecord(copiedConfig.agents?.defaults, "agent defaults");
|
|
const agentConfig = requireRecord(copiedConfig.agents?.list?.[0], "agent");
|
|
expect(agentDefaults.workspace).toBeUndefined();
|
|
expect(agentDefaults.agentDir).toBeUndefined();
|
|
expect(agentConfig.workspace).toBeUndefined();
|
|
expect(agentConfig.agentDir).toBeUndefined();
|
|
|
|
const telegramStreaming = requireTelegramStreaming(copiedConfig.channels?.telegram?.streaming);
|
|
expect(telegramStreaming).toEqual({
|
|
mode: "block",
|
|
chunkMode: "newline",
|
|
block: { enabled: true },
|
|
preview: { chunk: { minChars: 120 } },
|
|
});
|
|
|
|
expect(
|
|
fs.existsSync(path.join(testEnv.tempHome, ".openclaw", "credentials", "token.txt")),
|
|
).toBe(true);
|
|
expect(
|
|
fs.existsSync(
|
|
path.join(
|
|
testEnv.tempHome,
|
|
".openclaw",
|
|
"external-plugins",
|
|
"glueclaw",
|
|
"openclaw.plugin.json",
|
|
),
|
|
),
|
|
).toBe(true);
|
|
expect(
|
|
fs.existsSync(
|
|
path.join(testEnv.tempHome, ".openclaw", "agents", "main", "agent", "auth-profiles.json"),
|
|
),
|
|
).toBe(true);
|
|
expect(fs.existsSync(path.join(testEnv.tempHome, ".claude", ".credentials.json"))).toBe(true);
|
|
expect(fs.existsSync(path.join(testEnv.tempHome, ".claude", "projects"))).toBe(false);
|
|
expect(fs.existsSync(path.join(testEnv.tempHome, ".claude", "settings.local.json"))).toBe(
|
|
false,
|
|
);
|
|
expect(fs.existsSync(path.join(testEnv.tempHome, ".codex", "auth.json"))).toBe(true);
|
|
expect(fs.existsSync(path.join(testEnv.tempHome, ".codex", "config.toml"))).toBe(true);
|
|
expect(fs.existsSync(path.join(testEnv.tempHome, ".codex", "sessions"))).toBe(false);
|
|
});
|
|
|
|
it("allows explicit live runs against the real HOME", () => {
|
|
const realHome = createTempHome();
|
|
writeFile(path.join(realHome, ".profile"), "export TEST_PROFILE_ONLY=from-profile\n");
|
|
|
|
setTestEnvValue("HOME", realHome);
|
|
setTestEnvValue("USERPROFILE", realHome);
|
|
setTestEnvValue("OPENCLAW_LIVE_TEST", "1");
|
|
setTestEnvValue("OPENCLAW_LIVE_USE_REAL_HOME", "1");
|
|
setTestEnvValue("OPENCLAW_LIVE_TEST_QUIET", "1");
|
|
|
|
const testEnv = installTestEnv();
|
|
|
|
expect(testEnv.tempHome).toBe(realHome);
|
|
expect(process.env.HOME).toBe(realHome);
|
|
expect(process.env.TEST_PROFILE_ONLY).toBe("from-profile");
|
|
});
|
|
|
|
it("does not load ~/.profile for normal isolated test runs", () => {
|
|
const realHome = createTempHome();
|
|
writeFile(path.join(realHome, ".profile"), "export TEST_PROFILE_ONLY=from-profile\n");
|
|
|
|
setTestEnvValue("HOME", realHome);
|
|
setTestEnvValue("USERPROFILE", realHome);
|
|
deleteTestEnvValue("LIVE");
|
|
deleteTestEnvValue("OPENCLAW_LIVE_TEST");
|
|
deleteTestEnvValue("OPENCLAW_LIVE_GATEWAY");
|
|
deleteTestEnvValue("OPENCLAW_LIVE_USE_REAL_HOME");
|
|
deleteTestEnvValue("OPENCLAW_LIVE_TEST_QUIET");
|
|
|
|
const testEnv = installTestEnv();
|
|
cleanupFns.push(testEnv.cleanup);
|
|
|
|
expect(testEnv.tempHome).not.toBe(realHome);
|
|
expect(process.env.TEST_PROFILE_ONLY).toBeUndefined();
|
|
});
|
|
|
|
it("falls back to parsing ~/.profile when bash is unavailable", async () => {
|
|
const realHome = createTempHome();
|
|
writeFile(path.join(realHome, ".profile"), "export TEST_PROFILE_ONLY=from-profile\n");
|
|
|
|
setTestEnvValue("HOME", realHome);
|
|
setTestEnvValue("USERPROFILE", realHome);
|
|
setTestEnvValue("OPENCLAW_LIVE_TEST", "1");
|
|
setTestEnvValue("OPENCLAW_LIVE_USE_REAL_HOME", "1");
|
|
setTestEnvValue("OPENCLAW_LIVE_TEST_QUIET", "1");
|
|
|
|
vi.doMock("node:child_process", () => ({
|
|
execFileSync: () => {
|
|
throw Object.assign(new Error("bash missing"), { code: "ENOENT" });
|
|
},
|
|
}));
|
|
|
|
const { installTestEnv: installFreshTestEnv } = await importFreshModule<
|
|
typeof import("./test-env.js")
|
|
>(import.meta.url, "./test-env.js?scope=profile-fallback");
|
|
|
|
const testEnv = installFreshTestEnv();
|
|
|
|
expect(testEnv.tempHome).toBe(realHome);
|
|
expect(process.env.TEST_PROFILE_ONLY).toBe("from-profile");
|
|
});
|
|
});
|