mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
test: speed up setup and core extension tests
This commit is contained in:
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { validateJsonSchemaValue } from "../../../src/plugins/schema-validator.js";
|
||||
import { qqbotPlugin } from "./channel.js";
|
||||
import { qqbotSetupAdapterShared } from "./channel-config-shared.js";
|
||||
import { qqbotSetupPlugin } from "./channel.setup.js";
|
||||
import { QQBotConfigSchema } from "./config-schema.js";
|
||||
import { DEFAULT_ACCOUNT_ID, resolveDefaultQQBotAccountId, resolveQQBotAccount } from "./config.js";
|
||||
@@ -264,7 +264,7 @@ describe("qqbot config", () => {
|
||||
});
|
||||
|
||||
it("rejects malformed --token consistently across setup paths", () => {
|
||||
const runtimeSetup = qqbotPlugin.setup;
|
||||
const runtimeSetup = qqbotSetupAdapterShared;
|
||||
const lightweightSetup = qqbotSetupPlugin.setup;
|
||||
expect(runtimeSetup).toBeDefined();
|
||||
expect(lightweightSetup).toBeDefined();
|
||||
@@ -272,7 +272,7 @@ describe("qqbot config", () => {
|
||||
const input = { token: "broken", name: "Bad" };
|
||||
|
||||
expect(
|
||||
runtimeSetup!.validateInput?.({
|
||||
runtimeSetup.validateInput?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
input,
|
||||
@@ -286,7 +286,7 @@ describe("qqbot config", () => {
|
||||
}),
|
||||
).toBe("QQBot --token must be in appId:clientSecret format");
|
||||
expect(
|
||||
runtimeSetup!.applyAccountConfig?.({
|
||||
runtimeSetup.applyAccountConfig?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
input,
|
||||
@@ -302,7 +302,7 @@ describe("qqbot config", () => {
|
||||
});
|
||||
|
||||
it("preserves the --use-env add flow across setup paths", () => {
|
||||
const runtimeSetup = qqbotPlugin.setup;
|
||||
const runtimeSetup = qqbotSetupAdapterShared;
|
||||
const lightweightSetup = qqbotSetupPlugin.setup;
|
||||
expect(runtimeSetup).toBeDefined();
|
||||
expect(lightweightSetup).toBeDefined();
|
||||
@@ -310,7 +310,7 @@ describe("qqbot config", () => {
|
||||
const input = { useEnv: true, name: "Env Bot" };
|
||||
|
||||
expect(
|
||||
runtimeSetup!.applyAccountConfig?.({
|
||||
runtimeSetup.applyAccountConfig?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
accountId: DEFAULT_ACCOUNT_ID,
|
||||
input,
|
||||
@@ -342,11 +342,11 @@ describe("qqbot config", () => {
|
||||
});
|
||||
|
||||
it("uses configured defaultAccount when runtime setup accountId is omitted", () => {
|
||||
const runtimeSetup = qqbotPlugin.setup;
|
||||
const runtimeSetup = qqbotSetupAdapterShared;
|
||||
expect(runtimeSetup).toBeDefined();
|
||||
|
||||
expect(
|
||||
runtimeSetup!.resolveAccountId?.({
|
||||
runtimeSetup.resolveAccountId?.({
|
||||
cfg: {
|
||||
channels: {
|
||||
qqbot: {
|
||||
@@ -363,7 +363,7 @@ describe("qqbot config", () => {
|
||||
});
|
||||
|
||||
it("rejects --use-env for named accounts across setup paths", () => {
|
||||
const runtimeSetup = qqbotPlugin.setup;
|
||||
const runtimeSetup = qqbotSetupAdapterShared;
|
||||
const lightweightSetup = qqbotSetupPlugin.setup;
|
||||
expect(runtimeSetup).toBeDefined();
|
||||
expect(lightweightSetup).toBeDefined();
|
||||
@@ -371,7 +371,7 @@ describe("qqbot config", () => {
|
||||
const input = { useEnv: true, name: "Env Bot" };
|
||||
|
||||
expect(
|
||||
runtimeSetup!.validateInput?.({
|
||||
runtimeSetup.validateInput?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
accountId: "bot2",
|
||||
input,
|
||||
@@ -385,7 +385,7 @@ describe("qqbot config", () => {
|
||||
}),
|
||||
).toBe("QQBot --use-env only supports the default account");
|
||||
expect(
|
||||
runtimeSetup!.applyAccountConfig?.({
|
||||
runtimeSetup.applyAccountConfig?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
accountId: "bot2",
|
||||
input,
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
type WizardPrompter,
|
||||
} from "../../../test/helpers/plugins/setup-wizard.js";
|
||||
import { listAccountIds, resolveAccount } from "./accounts.js";
|
||||
import { synologyChatPlugin } from "./channel.js";
|
||||
import { SynologyChatChannelConfigSchema } from "./config-schema.js";
|
||||
import {
|
||||
authorizeUserForDm,
|
||||
@@ -17,8 +16,21 @@ import {
|
||||
validateToken,
|
||||
} from "./security.js";
|
||||
import { buildSynologyChatInboundSessionKey } from "./session-key.js";
|
||||
import { synologyChatSetupWizard } from "./setup-surface.js";
|
||||
|
||||
const synologyChatConfigure = createPluginSetupWizardConfigure(synologyChatPlugin);
|
||||
const synologyChatSetupPlugin = {
|
||||
id: "synology-chat",
|
||||
meta: { label: "Synology Chat" },
|
||||
setupWizard: synologyChatSetupWizard,
|
||||
config: {
|
||||
listAccountIds,
|
||||
defaultAccountId: () => "default",
|
||||
resolveAllowFrom: ({ cfg, accountId }: { cfg: OpenClawConfig; accountId?: string }) =>
|
||||
resolveAccount(cfg, accountId).allowedUserIds,
|
||||
},
|
||||
};
|
||||
|
||||
const synologyChatConfigure = createPluginSetupWizardConfigure(synologyChatSetupPlugin);
|
||||
const originalEnv = { ...process.env };
|
||||
|
||||
describe("synology-chat core", () => {
|
||||
|
||||
@@ -7,27 +7,58 @@ import {
|
||||
type WizardPrompter,
|
||||
} from "../../../test/helpers/plugins/setup-wizard.js";
|
||||
import type { OpenClawConfig } from "../api.js";
|
||||
import { tlonPlugin } from "./channel.js";
|
||||
import { TlonAuthorizationSchema, TlonConfigSchema } from "./config-schema.js";
|
||||
import { resolveTlonOutboundTarget } from "./targets.js";
|
||||
import { tlonSetupWizard } from "./setup-surface.js";
|
||||
import { normalizeShip, resolveTlonOutboundTarget } from "./targets.js";
|
||||
import { listTlonAccountIds, resolveTlonAccount } from "./types.js";
|
||||
|
||||
const tlonConfigure = createPluginSetupWizardConfigure(tlonPlugin);
|
||||
const tlonStatus = createPluginSetupWizardStatus(tlonPlugin);
|
||||
const tlonTestPlugin = {
|
||||
id: "tlon",
|
||||
meta: { label: "Tlon" },
|
||||
setupWizard: tlonSetupWizard,
|
||||
config: {
|
||||
listAccountIds: listTlonAccountIds,
|
||||
defaultAccountId: () => "default",
|
||||
resolveAllowFrom: ({ cfg, accountId }: { cfg: OpenClawConfig; accountId?: string | null }) =>
|
||||
resolveTlonAccount(cfg, accountId).dmAllowlist,
|
||||
formatAllowFrom: ({
|
||||
allowFrom,
|
||||
}: {
|
||||
cfg: OpenClawConfig;
|
||||
allowFrom: Array<string | number> | undefined | null;
|
||||
}) => (allowFrom ?? []).map((entry) => normalizeShip(String(entry))).filter(Boolean),
|
||||
},
|
||||
setup: {
|
||||
resolveAccountId: ({ accountId }: { cfg: OpenClawConfig; accountId?: string | null }) =>
|
||||
accountId ?? "default",
|
||||
},
|
||||
};
|
||||
|
||||
const tlonConfigure = createPluginSetupWizardConfigure(tlonTestPlugin);
|
||||
const tlonStatus = createPluginSetupWizardStatus(tlonTestPlugin);
|
||||
|
||||
describe("tlon core", () => {
|
||||
it("formats dm allowlist entries through the shared hybrid adapter", () => {
|
||||
expect(
|
||||
tlonPlugin.config.formatAllowFrom?.({
|
||||
tlonTestPlugin.config.formatAllowFrom?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
allowFrom: ["zod", " ~nec "],
|
||||
}),
|
||||
).toEqual(["~zod", "~nec"]);
|
||||
});
|
||||
|
||||
it("returns an empty dm allowlist when the default account is unconfigured", () => {
|
||||
expect(
|
||||
tlonTestPlugin.config.resolveAllowFrom?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
accountId: "default",
|
||||
}),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("resolves dm allowlist from the default account", () => {
|
||||
expect(
|
||||
tlonPlugin.config.resolveAllowFrom?.({
|
||||
tlonTestPlugin.config.resolveAllowFrom?.({
|
||||
cfg: {
|
||||
channels: {
|
||||
tlon: {
|
||||
|
||||
Reference in New Issue
Block a user