mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
test: speed up diffs browser tests
This commit is contained in:
@@ -1,54 +1,11 @@
|
||||
import path from "node:path";
|
||||
import {
|
||||
definePluginEntry,
|
||||
resolvePreferredOpenClawTmpDir,
|
||||
type OpenClawPluginApi,
|
||||
} from "./api.js";
|
||||
import {
|
||||
diffsPluginConfigSchema,
|
||||
resolveDiffsPluginDefaults,
|
||||
resolveDiffsPluginSecurity,
|
||||
resolveDiffsPluginViewerBaseUrl,
|
||||
} from "./src/config.js";
|
||||
import { createDiffsHttpHandler } from "./src/http.js";
|
||||
import { DIFFS_AGENT_GUIDANCE } from "./src/prompt-guidance.js";
|
||||
import { DiffArtifactStore } from "./src/store.js";
|
||||
import { createDiffsTool } from "./src/tool.js";
|
||||
import { definePluginEntry } from "./api.js";
|
||||
import { diffsPluginConfigSchema } from "./src/config.js";
|
||||
import { registerDiffsPlugin } from "./src/plugin.js";
|
||||
|
||||
export default definePluginEntry({
|
||||
id: "diffs",
|
||||
name: "Diffs",
|
||||
description: "Read-only diff viewer and PNG/PDF renderer for agents.",
|
||||
configSchema: diffsPluginConfigSchema,
|
||||
register(api: OpenClawPluginApi) {
|
||||
const defaults = resolveDiffsPluginDefaults(api.pluginConfig);
|
||||
const security = resolveDiffsPluginSecurity(api.pluginConfig);
|
||||
const viewerBaseUrl = resolveDiffsPluginViewerBaseUrl(api.pluginConfig);
|
||||
const store = new DiffArtifactStore({
|
||||
rootDir: path.join(resolvePreferredOpenClawTmpDir(), "openclaw-diffs"),
|
||||
logger: api.logger,
|
||||
});
|
||||
|
||||
api.registerTool(
|
||||
(ctx) => createDiffsTool({ api, store, defaults, viewerBaseUrl, context: ctx }),
|
||||
{
|
||||
name: "diffs",
|
||||
},
|
||||
);
|
||||
api.registerHttpRoute({
|
||||
path: "/plugins/diffs",
|
||||
auth: "plugin",
|
||||
match: "prefix",
|
||||
handler: createDiffsHttpHandler({
|
||||
store,
|
||||
logger: api.logger,
|
||||
allowRemoteViewer: security.allowRemoteViewer,
|
||||
trustedProxies: api.config.gateway?.trustedProxies,
|
||||
allowRealIpFallback: api.config.gateway?.allowRealIpFallback === true,
|
||||
}),
|
||||
});
|
||||
api.on("before_prompt_build", async () => ({
|
||||
prependSystemContext: DIFFS_AGENT_GUIDANCE,
|
||||
}));
|
||||
},
|
||||
register: registerDiffsPlugin,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { createMockServerResponse } from "../../../test/helpers/plugins/mock-htt
|
||||
import { createTestPluginApi } from "../../../test/helpers/plugins/plugin-api.js";
|
||||
import type { OpenClawConfig } from "../api.js";
|
||||
import type { OpenClawPluginApi, OpenClawPluginToolContext } from "../api.js";
|
||||
import plugin from "../index.js";
|
||||
import { registerDiffsPlugin } from "./plugin.js";
|
||||
import { createTempDiffRoot } from "./test-helpers.js";
|
||||
|
||||
const { launchMock } = vi.hoisted(() => ({
|
||||
@@ -239,7 +239,7 @@ describe("diffs plugin registration", () => {
|
||||
on,
|
||||
});
|
||||
|
||||
plugin.register?.(api as unknown as OpenClawPluginApi);
|
||||
registerDiffsPlugin(api as unknown as OpenClawPluginApi);
|
||||
|
||||
expect(on).toHaveBeenCalledTimes(1);
|
||||
expect(on.mock.calls[0]?.[0]).toBe("before_prompt_build");
|
||||
|
||||
43
extensions/diffs/src/plugin.ts
Normal file
43
extensions/diffs/src/plugin.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import path from "node:path";
|
||||
import { resolvePreferredOpenClawTmpDir, type OpenClawPluginApi } from "../api.js";
|
||||
import {
|
||||
resolveDiffsPluginDefaults,
|
||||
resolveDiffsPluginSecurity,
|
||||
resolveDiffsPluginViewerBaseUrl,
|
||||
} from "./config.js";
|
||||
import { createDiffsHttpHandler } from "./http.js";
|
||||
import { DIFFS_AGENT_GUIDANCE } from "./prompt-guidance.js";
|
||||
import { DiffArtifactStore } from "./store.js";
|
||||
import { createDiffsTool } from "./tool.js";
|
||||
|
||||
export function registerDiffsPlugin(api: OpenClawPluginApi): void {
|
||||
const defaults = resolveDiffsPluginDefaults(api.pluginConfig);
|
||||
const security = resolveDiffsPluginSecurity(api.pluginConfig);
|
||||
const viewerBaseUrl = resolveDiffsPluginViewerBaseUrl(api.pluginConfig);
|
||||
const store = new DiffArtifactStore({
|
||||
rootDir: path.join(resolvePreferredOpenClawTmpDir(), "openclaw-diffs"),
|
||||
logger: api.logger,
|
||||
});
|
||||
|
||||
api.registerTool(
|
||||
(ctx) => createDiffsTool({ api, store, defaults, viewerBaseUrl, context: ctx }),
|
||||
{
|
||||
name: "diffs",
|
||||
},
|
||||
);
|
||||
api.registerHttpRoute({
|
||||
path: "/plugins/diffs",
|
||||
auth: "plugin",
|
||||
match: "prefix",
|
||||
handler: createDiffsHttpHandler({
|
||||
store,
|
||||
logger: api.logger,
|
||||
allowRemoteViewer: security.allowRemoteViewer,
|
||||
trustedProxies: api.config.gateway?.trustedProxies,
|
||||
allowRealIpFallback: api.config.gateway?.allowRealIpFallback === true,
|
||||
}),
|
||||
});
|
||||
api.on("before_prompt_build", async () => ({
|
||||
prependSystemContext: DIFFS_AGENT_GUIDANCE,
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user