perf: speed local checks and warm builds

This commit is contained in:
Peter Steinberger
2026-04-20 15:07:47 +01:00
parent 4e907f78ca
commit 3ecb713b00
15 changed files with 411 additions and 48 deletions

View File

@@ -1,5 +1,5 @@
import type { ChannelOutboundAdapter } from "openclaw/plugin-sdk/channel-contract";
import type { ChannelPlugin } from "openclaw/plugin-sdk/core";
import type { ChannelPlugin } from "openclaw/plugin-sdk/channel-plugin-common";
import { loadBundledPluginTestApiSync } from "../../../src/test-utils/bundled-plugin-public-surface.js";
type CreateIMessageTestPlugin = (params?: { outbound?: ChannelOutboundAdapter }) => ChannelPlugin;

View File

@@ -1,4 +1,3 @@
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "openclaw/plugin-sdk/agent-runtime";
import { vi } from "vitest";
import {
removeAckReactionAfterReply,
@@ -10,6 +9,9 @@ import {
} from "../../../src/channels/mention-gating.js";
import type { PluginRuntime } from "../../../src/plugins/runtime/types.js";
const DEFAULT_PROVIDER = "openai";
const DEFAULT_MODEL = "gpt-5.4";
type DeepPartial<T> = {
[K in keyof T]?: T[K] extends (...args: never[]) => unknown
? T[K]

View File

@@ -1,9 +1,15 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
BUILD_ALL_PROFILES,
BUILD_ALL_STEPS,
resolveBuildAllStepCacheState,
resolveBuildAllStep,
resolveBuildAllSteps,
restoreBuildAllStepCacheOutputs,
writeBuildAllStepCacheStamp,
} from "../../scripts/build-all.mjs";
describe("resolveBuildAllStep", () => {
@@ -102,3 +108,100 @@ describe("resolveBuildAllSteps", () => {
expect(() => resolveBuildAllSteps("wat")).toThrow("Unknown build profile: wat");
});
});
describe("resolveBuildAllStepCacheState", () => {
it("marks cacheable steps fresh when the input signature matches", () => {
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-build-cache-"));
try {
const inputPath = path.join(rootDir, "src/input.ts");
const outputPath = path.join(rootDir, "dist/output.js");
fs.mkdirSync(path.dirname(inputPath), { recursive: true });
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
fs.writeFileSync(inputPath, "input");
fs.writeFileSync(outputPath, "output");
const step = {
label: "cached",
cache: {
inputs: ["src"],
outputs: ["dist"],
},
};
const cacheState = resolveBuildAllStepCacheState(step, { rootDir });
writeBuildAllStepCacheStamp(step, cacheState, { rootDir });
expect(resolveBuildAllStepCacheState(step, { rootDir })).toMatchObject({
cacheable: true,
fresh: true,
reason: "fresh",
inputFiles: 1,
outputFiles: 1,
});
} finally {
fs.rmSync(rootDir, { force: true, recursive: true });
}
});
it("marks cacheable steps stale when an input changes", () => {
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-build-cache-"));
try {
const inputPath = path.join(rootDir, "src/input.ts");
const outputPath = path.join(rootDir, "dist/output.js");
fs.mkdirSync(path.dirname(inputPath), { recursive: true });
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
fs.writeFileSync(inputPath, "input");
fs.writeFileSync(outputPath, "output");
const step = {
label: "cached",
cache: {
inputs: ["src"],
outputs: ["dist"],
},
};
const cacheState = resolveBuildAllStepCacheState(step, { rootDir });
writeBuildAllStepCacheStamp(step, cacheState, { rootDir });
fs.writeFileSync(inputPath, "changed");
expect(resolveBuildAllStepCacheState(step, { rootDir })).toMatchObject({
cacheable: true,
fresh: false,
reason: "stale",
});
} finally {
fs.rmSync(rootDir, { force: true, recursive: true });
}
});
it("restores cached outputs when generated files were removed", () => {
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-build-cache-"));
try {
const inputPath = path.join(rootDir, "src/input.ts");
const outputPath = path.join(rootDir, "dist/output.js");
fs.mkdirSync(path.dirname(inputPath), { recursive: true });
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
fs.writeFileSync(inputPath, "input");
fs.writeFileSync(outputPath, "output");
const step = {
label: "cached",
cache: {
inputs: ["src"],
outputs: ["dist"],
},
};
const cacheState = resolveBuildAllStepCacheState(step, { rootDir });
writeBuildAllStepCacheStamp(step, cacheState, { rootDir });
fs.rmSync(path.join(rootDir, "dist"), { force: true, recursive: true });
const restorable = resolveBuildAllStepCacheState(step, { rootDir });
expect(restorable).toMatchObject({
cacheable: true,
fresh: true,
reason: "fresh-cache",
restorable: true,
});
expect(restoreBuildAllStepCacheOutputs(restorable, { rootDir })).toBe(true);
expect(fs.readFileSync(outputPath, "utf8")).toBe("output");
} finally {
fs.rmSync(rootDir, { force: true, recursive: true });
}
});
});