test: speed up default test env
This commit is contained in:
@@ -28,6 +28,7 @@ export async function getReplyFromConfig(
|
|||||||
opts?: GetReplyOptions,
|
opts?: GetReplyOptions,
|
||||||
configOverride?: ClawdbotConfig,
|
configOverride?: ClawdbotConfig,
|
||||||
): Promise<ReplyPayload | ReplyPayload[] | undefined> {
|
): Promise<ReplyPayload | ReplyPayload[] | undefined> {
|
||||||
|
const isFastTestEnv = process.env.CLAWDBOT_TEST_FAST === "1";
|
||||||
const cfg = configOverride ?? loadConfig();
|
const cfg = configOverride ?? loadConfig();
|
||||||
const targetSessionKey =
|
const targetSessionKey =
|
||||||
ctx.CommandSource === "native" ? ctx.CommandTargetSessionKey?.trim() : undefined;
|
ctx.CommandSource === "native" ? ctx.CommandTargetSessionKey?.trim() : undefined;
|
||||||
@@ -62,7 +63,7 @@ export async function getReplyFromConfig(
|
|||||||
const workspaceDirRaw = resolveAgentWorkspaceDir(cfg, agentId) ?? DEFAULT_AGENT_WORKSPACE_DIR;
|
const workspaceDirRaw = resolveAgentWorkspaceDir(cfg, agentId) ?? DEFAULT_AGENT_WORKSPACE_DIR;
|
||||||
const workspace = await ensureAgentWorkspace({
|
const workspace = await ensureAgentWorkspace({
|
||||||
dir: workspaceDirRaw,
|
dir: workspaceDirRaw,
|
||||||
ensureBootstrapFiles: !agentCfg?.skipBootstrap,
|
ensureBootstrapFiles: !agentCfg?.skipBootstrap && !isFastTestEnv,
|
||||||
});
|
});
|
||||||
const workspaceDir = workspace.dir;
|
const workspaceDir = workspace.dir;
|
||||||
const agentDir = resolveAgentDir(cfg, agentId);
|
const agentDir = resolveAgentDir(cfg, agentId);
|
||||||
@@ -81,12 +82,14 @@ export async function getReplyFromConfig(
|
|||||||
|
|
||||||
const finalized = finalizeInboundContext(ctx);
|
const finalized = finalizeInboundContext(ctx);
|
||||||
|
|
||||||
await applyMediaUnderstanding({
|
if (!isFastTestEnv) {
|
||||||
ctx: finalized,
|
await applyMediaUnderstanding({
|
||||||
cfg,
|
ctx: finalized,
|
||||||
agentDir,
|
cfg,
|
||||||
activeModel: { provider, model },
|
agentDir,
|
||||||
});
|
activeModel: { provider, model },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const commandAuthorized = finalized.CommandAuthorized;
|
const commandAuthorized = finalized.CommandAuthorized;
|
||||||
resolveCommandAuthorization({
|
resolveCommandAuthorization({
|
||||||
|
|||||||
6
test/global-setup.ts
Normal file
6
test/global-setup.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { installTestEnv } from "./test-env";
|
||||||
|
|
||||||
|
export default async () => {
|
||||||
|
const { cleanup } = installTestEnv();
|
||||||
|
return () => cleanup();
|
||||||
|
};
|
||||||
@@ -9,11 +9,6 @@ import type { ClawdbotConfig } from "../src/config/config.js";
|
|||||||
import type { OutboundSendDeps } from "../src/infra/outbound/deliver.js";
|
import type { OutboundSendDeps } from "../src/infra/outbound/deliver.js";
|
||||||
import { setActivePluginRegistry } from "../src/plugins/runtime.js";
|
import { setActivePluginRegistry } from "../src/plugins/runtime.js";
|
||||||
import { createTestRegistry } from "../src/test-utils/channel-plugins.js";
|
import { createTestRegistry } from "../src/test-utils/channel-plugins.js";
|
||||||
import { installTestEnv } from "./test-env";
|
|
||||||
|
|
||||||
const { cleanup } = installTestEnv();
|
|
||||||
process.on("exit", cleanup);
|
|
||||||
|
|
||||||
const pickSendFn = (id: ChannelId, deps?: OutboundSendDeps) => {
|
const pickSendFn = (id: ChannelId, deps?: OutboundSendDeps) => {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case "discord":
|
case "discord":
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export function installTestEnv(): { cleanup: () => void; tempHome: string } {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const restore: RestoreEntry[] = [
|
const restore: RestoreEntry[] = [
|
||||||
|
{ key: "CLAWDBOT_TEST_FAST", value: process.env.CLAWDBOT_TEST_FAST },
|
||||||
{ key: "HOME", value: process.env.HOME },
|
{ key: "HOME", value: process.env.HOME },
|
||||||
{ key: "USERPROFILE", value: process.env.USERPROFILE },
|
{ key: "USERPROFILE", value: process.env.USERPROFILE },
|
||||||
{ key: "XDG_CONFIG_HOME", value: process.env.XDG_CONFIG_HOME },
|
{ key: "XDG_CONFIG_HOME", value: process.env.XDG_CONFIG_HOME },
|
||||||
@@ -84,6 +85,7 @@ export function installTestEnv(): { cleanup: () => void; tempHome: string } {
|
|||||||
process.env.HOME = tempHome;
|
process.env.HOME = tempHome;
|
||||||
process.env.USERPROFILE = tempHome;
|
process.env.USERPROFILE = tempHome;
|
||||||
process.env.CLAWDBOT_TEST_HOME = tempHome;
|
process.env.CLAWDBOT_TEST_HOME = tempHome;
|
||||||
|
process.env.CLAWDBOT_TEST_FAST = "1";
|
||||||
|
|
||||||
// Ensure test runs never touch the developer's real config/state, even if they have overrides set.
|
// Ensure test runs never touch the developer's real config/state, even if they have overrides set.
|
||||||
delete process.env.CLAWDBOT_CONFIG_PATH;
|
delete process.env.CLAWDBOT_CONFIG_PATH;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export default defineConfig({
|
|||||||
"test/format-error.test.ts",
|
"test/format-error.test.ts",
|
||||||
],
|
],
|
||||||
setupFiles: ["test/setup.ts"],
|
setupFiles: ["test/setup.ts"],
|
||||||
|
globalSetup: ["test/global-setup.ts"],
|
||||||
exclude: [
|
exclude: [
|
||||||
"dist/**",
|
"dist/**",
|
||||||
"apps/macos/**",
|
"apps/macos/**",
|
||||||
@@ -34,6 +35,7 @@ export default defineConfig({
|
|||||||
"**/vendor/**",
|
"**/vendor/**",
|
||||||
"dist/Clawdbot.app/**",
|
"dist/Clawdbot.app/**",
|
||||||
"**/*.live.test.ts",
|
"**/*.live.test.ts",
|
||||||
|
"**/*.e2e.test.ts",
|
||||||
],
|
],
|
||||||
coverage: {
|
coverage: {
|
||||||
provider: "v8",
|
provider: "v8",
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ export default defineConfig({
|
|||||||
test: {
|
test: {
|
||||||
pool: "forks",
|
pool: "forks",
|
||||||
maxWorkers: e2eWorkers,
|
maxWorkers: e2eWorkers,
|
||||||
include: ["test/**/*.e2e.test.ts"],
|
include: ["test/**/*.e2e.test.ts", "src/**/*.e2e.test.ts"],
|
||||||
setupFiles: ["test/setup.ts"],
|
setupFiles: ["test/setup.ts"],
|
||||||
|
globalSetup: ["test/global-setup.ts"],
|
||||||
exclude: [
|
exclude: [
|
||||||
"dist/**",
|
"dist/**",
|
||||||
"apps/macos/**",
|
"apps/macos/**",
|
||||||
|
|||||||
Reference in New Issue
Block a user