mirror of
https://github.com/yuangyaa/openclaw.git
synced 2026-07-14 11:07:29 +08:00
test: share runtime group policy fallback cases
This commit is contained in:
@@ -1,21 +1,14 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { installProviderRuntimeGroupPolicyFallbackSuite } from "../../test-utils/runtime-group-policy-contract.js";
|
||||||
import { __testing } from "./provider.js";
|
import { __testing } from "./provider.js";
|
||||||
|
|
||||||
describe("resolveDiscordRuntimeGroupPolicy", () => {
|
describe("resolveDiscordRuntimeGroupPolicy", () => {
|
||||||
it("fails closed when channels.discord is missing and no defaults are set", () => {
|
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||||
const resolved = __testing.resolveDiscordRuntimeGroupPolicy({
|
resolve: __testing.resolveDiscordRuntimeGroupPolicy,
|
||||||
providerConfigPresent: false,
|
configuredLabel: "keeps open default when channels.discord is configured",
|
||||||
});
|
defaultGroupPolicyUnderTest: "open",
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
missingConfigLabel: "fails closed when channels.discord is missing and no defaults are set",
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
missingDefaultLabel: "ignores explicit global defaults when provider config is missing",
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps open default when channels.discord is configured", () => {
|
|
||||||
const resolved = __testing.resolveDiscordRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: true,
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("open");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("respects explicit provider policy", () => {
|
it("respects explicit provider policy", () => {
|
||||||
@@ -26,13 +19,4 @@ describe("resolveDiscordRuntimeGroupPolicy", () => {
|
|||||||
expect(resolved.groupPolicy).toBe("disabled");
|
expect(resolved.groupPolicy).toBe("disabled");
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("ignores explicit global defaults when provider config is missing", () => {
|
|
||||||
const resolved = __testing.resolveDiscordRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: false,
|
|
||||||
defaultGroupPolicy: "open",
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,29 +1,13 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe } from "vitest";
|
||||||
|
import { installProviderRuntimeGroupPolicyFallbackSuite } from "../../test-utils/runtime-group-policy-contract.js";
|
||||||
import { __testing } from "./monitor-provider.js";
|
import { __testing } from "./monitor-provider.js";
|
||||||
|
|
||||||
describe("resolveIMessageRuntimeGroupPolicy", () => {
|
describe("resolveIMessageRuntimeGroupPolicy", () => {
|
||||||
it("fails closed when channels.imessage is missing and no defaults are set", () => {
|
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||||
const resolved = __testing.resolveIMessageRuntimeGroupPolicy({
|
resolve: __testing.resolveIMessageRuntimeGroupPolicy,
|
||||||
providerConfigPresent: false,
|
configuredLabel: "keeps open fallback when channels.imessage is configured",
|
||||||
});
|
defaultGroupPolicyUnderTest: "disabled",
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
missingConfigLabel: "fails closed when channels.imessage is missing and no defaults are set",
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
missingDefaultLabel: "ignores explicit global defaults when provider config is missing",
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps open fallback when channels.imessage is configured", () => {
|
|
||||||
const resolved = __testing.resolveIMessageRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: true,
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("open");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("ignores explicit global defaults when provider config is missing", () => {
|
|
||||||
const resolved = __testing.resolveIMessageRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: false,
|
|
||||||
defaultGroupPolicy: "disabled",
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,29 +1,13 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe } from "vitest";
|
||||||
|
import { installProviderRuntimeGroupPolicyFallbackSuite } from "../../test-utils/runtime-group-policy-contract.js";
|
||||||
import { __testing } from "./provider.js";
|
import { __testing } from "./provider.js";
|
||||||
|
|
||||||
describe("resolveSlackRuntimeGroupPolicy", () => {
|
describe("resolveSlackRuntimeGroupPolicy", () => {
|
||||||
it("fails closed when channels.slack is missing and no defaults are set", () => {
|
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||||
const resolved = __testing.resolveSlackRuntimeGroupPolicy({
|
resolve: __testing.resolveSlackRuntimeGroupPolicy,
|
||||||
providerConfigPresent: false,
|
configuredLabel: "keeps open default when channels.slack is configured",
|
||||||
});
|
defaultGroupPolicyUnderTest: "open",
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
missingConfigLabel: "fails closed when channels.slack is missing and no defaults are set",
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
missingDefaultLabel: "ignores explicit global defaults when provider config is missing",
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps open default when channels.slack is configured", () => {
|
|
||||||
const resolved = __testing.resolveSlackRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: true,
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("open");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("ignores explicit global defaults when provider config is missing", () => {
|
|
||||||
const resolved = __testing.resolveSlackRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: false,
|
|
||||||
defaultGroupPolicy: "open",
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,29 +1,13 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe } from "vitest";
|
||||||
|
import { installProviderRuntimeGroupPolicyFallbackSuite } from "../test-utils/runtime-group-policy-contract.js";
|
||||||
import { resolveTelegramRuntimeGroupPolicy } from "./group-access.js";
|
import { resolveTelegramRuntimeGroupPolicy } from "./group-access.js";
|
||||||
|
|
||||||
describe("resolveTelegramRuntimeGroupPolicy", () => {
|
describe("resolveTelegramRuntimeGroupPolicy", () => {
|
||||||
it("fails closed when channels.telegram is missing and no defaults are set", () => {
|
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||||
const resolved = resolveTelegramRuntimeGroupPolicy({
|
resolve: resolveTelegramRuntimeGroupPolicy,
|
||||||
providerConfigPresent: false,
|
configuredLabel: "keeps open fallback when channels.telegram is configured",
|
||||||
});
|
defaultGroupPolicyUnderTest: "disabled",
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
missingConfigLabel: "fails closed when channels.telegram is missing and no defaults are set",
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
missingDefaultLabel: "ignores explicit defaults when provider config is missing",
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps open fallback when channels.telegram is configured", () => {
|
|
||||||
const resolved = resolveTelegramRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: true,
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("open");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("ignores explicit defaults when provider config is missing", () => {
|
|
||||||
const resolved = resolveTelegramRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: false,
|
|
||||||
defaultGroupPolicy: "disabled",
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
43
src/test-utils/runtime-group-policy-contract.ts
Normal file
43
src/test-utils/runtime-group-policy-contract.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { expect, it } from "vitest";
|
||||||
|
import type {
|
||||||
|
ResolveProviderRuntimeGroupPolicyParams,
|
||||||
|
RuntimeGroupPolicyResolution,
|
||||||
|
} from "../config/runtime-group-policy.js";
|
||||||
|
import type { GroupPolicy } from "../config/types.base.js";
|
||||||
|
|
||||||
|
type RuntimeGroupPolicyResolver = (
|
||||||
|
params: ResolveProviderRuntimeGroupPolicyParams,
|
||||||
|
) => RuntimeGroupPolicyResolution;
|
||||||
|
|
||||||
|
export function installProviderRuntimeGroupPolicyFallbackSuite(params: {
|
||||||
|
configuredLabel: string;
|
||||||
|
defaultGroupPolicyUnderTest: GroupPolicy;
|
||||||
|
missingConfigLabel: string;
|
||||||
|
missingDefaultLabel: string;
|
||||||
|
resolve: RuntimeGroupPolicyResolver;
|
||||||
|
}) {
|
||||||
|
it(params.missingConfigLabel, () => {
|
||||||
|
const resolved = params.resolve({
|
||||||
|
providerConfigPresent: false,
|
||||||
|
});
|
||||||
|
expect(resolved.groupPolicy).toBe("allowlist");
|
||||||
|
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(params.configuredLabel, () => {
|
||||||
|
const resolved = params.resolve({
|
||||||
|
providerConfigPresent: true,
|
||||||
|
});
|
||||||
|
expect(resolved.groupPolicy).toBe("open");
|
||||||
|
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(params.missingDefaultLabel, () => {
|
||||||
|
const resolved = params.resolve({
|
||||||
|
providerConfigPresent: false,
|
||||||
|
defaultGroupPolicy: params.defaultGroupPolicyUnderTest,
|
||||||
|
});
|
||||||
|
expect(resolved.groupPolicy).toBe("allowlist");
|
||||||
|
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,29 +1,13 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe } from "vitest";
|
||||||
|
import { installProviderRuntimeGroupPolicyFallbackSuite } from "../../test-utils/runtime-group-policy-contract.js";
|
||||||
import { __testing } from "./access-control.js";
|
import { __testing } from "./access-control.js";
|
||||||
|
|
||||||
describe("resolveWhatsAppRuntimeGroupPolicy", () => {
|
describe("resolveWhatsAppRuntimeGroupPolicy", () => {
|
||||||
it("fails closed when channels.whatsapp is missing and no defaults are set", () => {
|
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||||
const resolved = __testing.resolveWhatsAppRuntimeGroupPolicy({
|
resolve: __testing.resolveWhatsAppRuntimeGroupPolicy,
|
||||||
providerConfigPresent: false,
|
configuredLabel: "keeps open fallback when channels.whatsapp is configured",
|
||||||
});
|
defaultGroupPolicyUnderTest: "disabled",
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
missingConfigLabel: "fails closed when channels.whatsapp is missing and no defaults are set",
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
missingDefaultLabel: "ignores explicit default policy when provider config is missing",
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps open fallback when channels.whatsapp is configured", () => {
|
|
||||||
const resolved = __testing.resolveWhatsAppRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: true,
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("open");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("ignores explicit default policy when provider config is missing", () => {
|
|
||||||
const resolved = __testing.resolveWhatsAppRuntimeGroupPolicy({
|
|
||||||
providerConfigPresent: false,
|
|
||||||
defaultGroupPolicy: "disabled",
|
|
||||||
});
|
|
||||||
expect(resolved.groupPolicy).toBe("allowlist");
|
|
||||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user