mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test: share runtime group policy fallback cases
This commit is contained in:
@@ -1,21 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { installProviderRuntimeGroupPolicyFallbackSuite } from "../../test-utils/runtime-group-policy-contract.js";
|
||||
import { __testing } from "./provider.js";
|
||||
|
||||
describe("resolveDiscordRuntimeGroupPolicy", () => {
|
||||
it("fails closed when channels.discord is missing and no defaults are set", () => {
|
||||
const resolved = __testing.resolveDiscordRuntimeGroupPolicy({
|
||||
providerConfigPresent: false,
|
||||
});
|
||||
expect(resolved.groupPolicy).toBe("allowlist");
|
||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
||||
});
|
||||
|
||||
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);
|
||||
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||
resolve: __testing.resolveDiscordRuntimeGroupPolicy,
|
||||
configuredLabel: "keeps open default when channels.discord is configured",
|
||||
defaultGroupPolicyUnderTest: "open",
|
||||
missingConfigLabel: "fails closed when channels.discord is missing and no defaults are set",
|
||||
missingDefaultLabel: "ignores explicit global defaults when provider config is missing",
|
||||
});
|
||||
|
||||
it("respects explicit provider policy", () => {
|
||||
@@ -26,13 +19,4 @@ describe("resolveDiscordRuntimeGroupPolicy", () => {
|
||||
expect(resolved.groupPolicy).toBe("disabled");
|
||||
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";
|
||||
|
||||
describe("resolveIMessageRuntimeGroupPolicy", () => {
|
||||
it("fails closed when channels.imessage is missing and no defaults are set", () => {
|
||||
const resolved = __testing.resolveIMessageRuntimeGroupPolicy({
|
||||
providerConfigPresent: false,
|
||||
});
|
||||
expect(resolved.groupPolicy).toBe("allowlist");
|
||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
||||
});
|
||||
|
||||
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);
|
||||
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||
resolve: __testing.resolveIMessageRuntimeGroupPolicy,
|
||||
configuredLabel: "keeps open fallback when channels.imessage is configured",
|
||||
defaultGroupPolicyUnderTest: "disabled",
|
||||
missingConfigLabel: "fails closed when channels.imessage is missing and no defaults are set",
|
||||
missingDefaultLabel: "ignores explicit global defaults when provider config is missing",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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";
|
||||
|
||||
describe("resolveSlackRuntimeGroupPolicy", () => {
|
||||
it("fails closed when channels.slack is missing and no defaults are set", () => {
|
||||
const resolved = __testing.resolveSlackRuntimeGroupPolicy({
|
||||
providerConfigPresent: false,
|
||||
});
|
||||
expect(resolved.groupPolicy).toBe("allowlist");
|
||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
||||
});
|
||||
|
||||
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);
|
||||
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||
resolve: __testing.resolveSlackRuntimeGroupPolicy,
|
||||
configuredLabel: "keeps open default when channels.slack is configured",
|
||||
defaultGroupPolicyUnderTest: "open",
|
||||
missingConfigLabel: "fails closed when channels.slack is missing and no defaults are set",
|
||||
missingDefaultLabel: "ignores explicit global defaults when provider config is missing",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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";
|
||||
|
||||
describe("resolveTelegramRuntimeGroupPolicy", () => {
|
||||
it("fails closed when channels.telegram is missing and no defaults are set", () => {
|
||||
const resolved = resolveTelegramRuntimeGroupPolicy({
|
||||
providerConfigPresent: false,
|
||||
});
|
||||
expect(resolved.groupPolicy).toBe("allowlist");
|
||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
||||
});
|
||||
|
||||
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);
|
||||
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||
resolve: resolveTelegramRuntimeGroupPolicy,
|
||||
configuredLabel: "keeps open fallback when channels.telegram is configured",
|
||||
defaultGroupPolicyUnderTest: "disabled",
|
||||
missingConfigLabel: "fails closed when channels.telegram is missing and no defaults are set",
|
||||
missingDefaultLabel: "ignores explicit defaults when provider config is missing",
|
||||
});
|
||||
});
|
||||
|
||||
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";
|
||||
|
||||
describe("resolveWhatsAppRuntimeGroupPolicy", () => {
|
||||
it("fails closed when channels.whatsapp is missing and no defaults are set", () => {
|
||||
const resolved = __testing.resolveWhatsAppRuntimeGroupPolicy({
|
||||
providerConfigPresent: false,
|
||||
});
|
||||
expect(resolved.groupPolicy).toBe("allowlist");
|
||||
expect(resolved.providerMissingFallbackApplied).toBe(true);
|
||||
});
|
||||
|
||||
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);
|
||||
installProviderRuntimeGroupPolicyFallbackSuite({
|
||||
resolve: __testing.resolveWhatsAppRuntimeGroupPolicy,
|
||||
configuredLabel: "keeps open fallback when channels.whatsapp is configured",
|
||||
defaultGroupPolicyUnderTest: "disabled",
|
||||
missingConfigLabel: "fails closed when channels.whatsapp is missing and no defaults are set",
|
||||
missingDefaultLabel: "ignores explicit default policy when provider config is missing",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user