mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-05-08 16:17:54 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
112 lines
3.4 KiB
TypeScript
112 lines
3.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
resolveCommandAuthorizedFromAuthorizers,
|
|
resolveControlCommandGate,
|
|
resolveDualTextControlCommandGate,
|
|
} from "./command-gating.js";
|
|
|
|
describe("resolveCommandAuthorizedFromAuthorizers", () => {
|
|
it("denies when useAccessGroups is enabled and no authorizer is configured", () => {
|
|
expect(
|
|
resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: true,
|
|
authorizers: [{ configured: false, allowed: true }],
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("allows when useAccessGroups is enabled and any configured authorizer allows", () => {
|
|
expect(
|
|
resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: true,
|
|
authorizers: [
|
|
{ configured: true, allowed: false },
|
|
{ configured: true, allowed: true },
|
|
],
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("allows when useAccessGroups is disabled (default)", () => {
|
|
expect(
|
|
resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: false,
|
|
authorizers: [{ configured: true, allowed: false }],
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("honors modeWhenAccessGroupsOff=deny", () => {
|
|
expect(
|
|
resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: false,
|
|
authorizers: [{ configured: false, allowed: true }],
|
|
modeWhenAccessGroupsOff: "deny",
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("honors modeWhenAccessGroupsOff=configured (allow when none configured)", () => {
|
|
expect(
|
|
resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: false,
|
|
authorizers: [{ configured: false, allowed: false }],
|
|
modeWhenAccessGroupsOff: "configured",
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("honors modeWhenAccessGroupsOff=configured (enforce when configured)", () => {
|
|
expect(
|
|
resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: false,
|
|
authorizers: [{ configured: true, allowed: false }],
|
|
modeWhenAccessGroupsOff: "configured",
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
resolveCommandAuthorizedFromAuthorizers({
|
|
useAccessGroups: false,
|
|
authorizers: [{ configured: true, allowed: true }],
|
|
modeWhenAccessGroupsOff: "configured",
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("resolveControlCommandGate", () => {
|
|
it("blocks control commands when unauthorized", () => {
|
|
const result = resolveControlCommandGate({
|
|
useAccessGroups: true,
|
|
authorizers: [{ configured: true, allowed: false }],
|
|
allowTextCommands: true,
|
|
hasControlCommand: true,
|
|
});
|
|
expect(result.commandAuthorized).toBe(false);
|
|
expect(result.shouldBlock).toBe(true);
|
|
});
|
|
|
|
it("does not block when control commands are disabled", () => {
|
|
const result = resolveControlCommandGate({
|
|
useAccessGroups: true,
|
|
authorizers: [{ configured: true, allowed: false }],
|
|
allowTextCommands: false,
|
|
hasControlCommand: true,
|
|
});
|
|
expect(result.shouldBlock).toBe(false);
|
|
});
|
|
|
|
it("supports the dual-authorizer text gate helper", () => {
|
|
const result = resolveDualTextControlCommandGate({
|
|
useAccessGroups: true,
|
|
primaryConfigured: true,
|
|
primaryAllowed: false,
|
|
secondaryConfigured: true,
|
|
secondaryAllowed: true,
|
|
hasControlCommand: true,
|
|
});
|
|
expect(result.commandAuthorized).toBe(true);
|
|
expect(result.shouldBlock).toBe(false);
|
|
});
|
|
});
|