mirror of
https://fastgit.cc/github.com/openclaw/openclaw
synced 2026-05-01 06:36:23 +08:00
test(secrets): share inactive channel fixtures
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { vi } from "vitest";
|
||||
import { loadBundledChannelSecretContractApi } from "./channel-contract-api.js";
|
||||
|
||||
const googleChatSecrets = loadBundledChannelSecretContractApi("googlechat");
|
||||
const ircSecrets = loadBundledChannelSecretContractApi("irc");
|
||||
const slackSecrets = loadBundledChannelSecretContractApi("slack");
|
||||
|
||||
if (
|
||||
!googleChatSecrets?.collectRuntimeConfigAssignments ||
|
||||
!ircSecrets?.collectRuntimeConfigAssignments ||
|
||||
!slackSecrets?.collectRuntimeConfigAssignments
|
||||
) {
|
||||
throw new Error("Missing channel secret contract api");
|
||||
}
|
||||
|
||||
function resolveAssignments(id: string) {
|
||||
if (id === "irc") {
|
||||
return ircSecrets.collectRuntimeConfigAssignments;
|
||||
}
|
||||
if (id === "slack") {
|
||||
return slackSecrets.collectRuntimeConfigAssignments;
|
||||
}
|
||||
if (id === "googlechat") {
|
||||
return googleChatSecrets.collectRuntimeConfigAssignments;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
vi.mock("../channels/plugins/bootstrap-registry.js", () => ({
|
||||
getBootstrapChannelPlugin: (id: string) => {
|
||||
const collectRuntimeConfigAssignments = resolveAssignments(id);
|
||||
return collectRuntimeConfigAssignments
|
||||
? {
|
||||
secrets: { collectRuntimeConfigAssignments },
|
||||
}
|
||||
: undefined;
|
||||
},
|
||||
getBootstrapChannelSecrets: (id: string) => {
|
||||
const collectRuntimeConfigAssignments = resolveAssignments(id);
|
||||
return collectRuntimeConfigAssignments ? { collectRuntimeConfigAssignments } : undefined;
|
||||
},
|
||||
}));
|
||||
@@ -1,97 +1,14 @@
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import type { AuthProfileStore } from "../agents/auth-profiles.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createEmptyPluginRegistry } from "../plugins/registry.js";
|
||||
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import { loadBundledChannelSecretContractApi } from "./channel-contract-api.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import "./runtime-channel-inactive-variants.test-support.ts";
|
||||
import {
|
||||
asConfig,
|
||||
loadAuthStoreWithProfiles,
|
||||
setupSecretsRuntimeSnapshotTestHooks,
|
||||
} from "./runtime.test-support.ts";
|
||||
|
||||
const googleChatSecrets = loadBundledChannelSecretContractApi("googlechat");
|
||||
const ircSecrets = loadBundledChannelSecretContractApi("irc");
|
||||
const slackSecrets = loadBundledChannelSecretContractApi("slack");
|
||||
if (
|
||||
!googleChatSecrets?.collectRuntimeConfigAssignments ||
|
||||
!ircSecrets?.collectRuntimeConfigAssignments ||
|
||||
!slackSecrets?.collectRuntimeConfigAssignments
|
||||
) {
|
||||
throw new Error("Missing channel secret contract api");
|
||||
}
|
||||
|
||||
vi.mock("../channels/plugins/bootstrap-registry.js", () => {
|
||||
return {
|
||||
getBootstrapChannelPlugin: (id: string) => {
|
||||
if (id === "irc") {
|
||||
return {
|
||||
secrets: {
|
||||
collectRuntimeConfigAssignments: ircSecrets.collectRuntimeConfigAssignments,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (id === "slack") {
|
||||
return {
|
||||
secrets: {
|
||||
collectRuntimeConfigAssignments: slackSecrets.collectRuntimeConfigAssignments,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (id === "googlechat") {
|
||||
return {
|
||||
secrets: {
|
||||
collectRuntimeConfigAssignments: googleChatSecrets.collectRuntimeConfigAssignments,
|
||||
},
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
getBootstrapChannelSecrets: (id: string) => {
|
||||
if (id === "irc") {
|
||||
return {
|
||||
collectRuntimeConfigAssignments: ircSecrets.collectRuntimeConfigAssignments,
|
||||
};
|
||||
}
|
||||
if (id === "slack") {
|
||||
return {
|
||||
collectRuntimeConfigAssignments: slackSecrets.collectRuntimeConfigAssignments,
|
||||
};
|
||||
}
|
||||
if (id === "googlechat") {
|
||||
return {
|
||||
collectRuntimeConfigAssignments: googleChatSecrets.collectRuntimeConfigAssignments,
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
function asConfig(value: unknown): OpenClawConfig {
|
||||
return value as OpenClawConfig;
|
||||
}
|
||||
|
||||
let clearConfigCache: typeof import("../config/config.js").clearConfigCache;
|
||||
let clearRuntimeConfigSnapshot: typeof import("../config/config.js").clearRuntimeConfigSnapshot;
|
||||
let clearSecretsRuntimeSnapshot: typeof import("./runtime.js").clearSecretsRuntimeSnapshot;
|
||||
let prepareSecretsRuntimeSnapshot: typeof import("./runtime.js").prepareSecretsRuntimeSnapshot;
|
||||
|
||||
function loadAuthStoreWithProfiles(profiles: AuthProfileStore["profiles"]): AuthProfileStore {
|
||||
return {
|
||||
version: 1,
|
||||
profiles,
|
||||
};
|
||||
}
|
||||
const { prepareSecretsRuntimeSnapshot } = setupSecretsRuntimeSnapshotTestHooks();
|
||||
|
||||
describe("secrets runtime snapshot channel inactive variants", () => {
|
||||
beforeAll(async () => {
|
||||
({ clearConfigCache, clearRuntimeConfigSnapshot } = await import("../config/config.js"));
|
||||
({ clearSecretsRuntimeSnapshot, prepareSecretsRuntimeSnapshot } = await import("./runtime.js"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setActivePluginRegistry(createEmptyPluginRegistry());
|
||||
clearSecretsRuntimeSnapshot();
|
||||
clearRuntimeConfigSnapshot();
|
||||
clearConfigCache();
|
||||
});
|
||||
|
||||
it("treats IRC account nickserv password refs as inactive when nickserv is disabled", async () => {
|
||||
const snapshot = await prepareSecretsRuntimeSnapshot({
|
||||
config: asConfig({
|
||||
|
||||
Reference in New Issue
Block a user