Skip to content

Commit 5c9e75c

Browse files
committed
addressing codex review
1 parent 5de82c4 commit 5c9e75c

4 files changed

Lines changed: 65 additions & 5 deletions

File tree

src/auto-reply/command-auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,15 @@ function resolveOwnerAuthorizationState(params: {
430430

431431
function resolveCommandSenderAuthorization(params: {
432432
commandAuthorized: boolean;
433+
enforceOwnerForCommands: boolean;
433434
nativeCommandAuthorized: boolean;
434435
isOwnerForCommands: boolean;
435436
senderCandidates: string[];
436437
commandsAllowFromList: string[] | null;
437438
providerResolutionError: boolean;
438439
commandsAllowFromConfigured: boolean;
439440
}): boolean {
440-
if (!params.isOwnerForCommands) {
441+
if (params.enforceOwnerForCommands && !params.isOwnerForCommands) {
441442
return false;
442443
}
443444
if (
@@ -713,6 +714,7 @@ export function resolveCommandAuthorization(params: {
713714
commandAuthorized && ctx.CommandSource === "native" && !requireOwner;
714715
const isAuthorizedSender = resolveCommandSenderAuthorization({
715716
commandAuthorized,
717+
enforceOwnerForCommands: enforceOwner,
716718
nativeCommandAuthorized,
717719
isOwnerForCommands,
718720
senderCandidates,

src/auto-reply/command-control.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,34 @@ describe("resolveCommandAuthorization", () => {
674674
expect(auth.isAuthorizedSender).toBe(false);
675675
});
676676

677+
it("keeps commands.allowFrom available to non-owner command users when an owner allowlist is configured", () => {
678+
const cfg = {
679+
commands: {
680+
ownerAllowFrom: ["discord:owner"],
681+
allowFrom: {
682+
discord: ["helper"],
683+
},
684+
},
685+
channels: { discord: { allowFrom: ["*"] } },
686+
} as OpenClawConfig;
687+
688+
const auth = resolveCommandAuthorization({
689+
ctx: {
690+
Provider: "discord",
691+
Surface: "discord",
692+
ChatType: "group",
693+
From: "discord:helper",
694+
SenderId: "helper",
695+
CommandSource: "native",
696+
} as MsgContext,
697+
cfg,
698+
commandAuthorized: true,
699+
});
700+
701+
expect(auth.senderIsOwner).toBe(false);
702+
expect(auth.isAuthorizedSender).toBe(true);
703+
});
704+
677705
it("does not treat conversation ids in From as sender identities", () => {
678706
const cfg = {
679707
commands: {

src/auto-reply/reply/commands-stop-target.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
import type { OpenClawConfig } from "../../config/config.js";
3-
import { setActivePluginRegistry } from "../../plugins/runtime.js";
3+
import {
4+
getActivePluginRegistry,
5+
resetPluginRuntimeStateForTest,
6+
setActivePluginRegistry,
7+
} from "../../plugins/runtime.js";
48
import { createOutboundTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js";
59
import { resolveCommandAuthorization } from "../command-auth.js";
610
import type { MsgContext } from "../templating.js";
@@ -55,6 +59,8 @@ vi.mock("./reply-run-registry.js", () => ({
5559
const formatAllowFrom = ({ allowFrom }: { allowFrom: Array<string | number> }) =>
5660
allowFrom.map((entry) => String(entry).trim()).filter(Boolean);
5761

62+
let previousPluginRegistry: ReturnType<typeof getActivePluginRegistry>;
63+
5864
function registerOwnerEnforcingTelegramPlugin() {
5965
setActivePluginRegistry(
6066
createTestRegistry([
@@ -116,10 +122,19 @@ function buildStopParams(): HandleCommandsParams {
116122

117123
describe("handleStopCommand target fallback", () => {
118124
beforeEach(() => {
125+
previousPluginRegistry = getActivePluginRegistry();
119126
vi.clearAllMocks();
120127
persistAbortTargetEntryMock.mockResolvedValue(true);
121128
});
122129

130+
afterEach(() => {
131+
if (previousPluginRegistry) {
132+
setActivePluginRegistry(previousPluginRegistry);
133+
} else {
134+
resetPluginRuntimeStateForTest();
135+
}
136+
});
137+
123138
it("does not fall back to the wrapper session when a distinct target session is missing from store", async () => {
124139
const params = buildStopParams();
125140

src/auto-reply/reply/commands-subagents-routing.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
import type { OpenClawConfig } from "../../config/config.js";
3-
import { setActivePluginRegistry } from "../../plugins/runtime.js";
3+
import {
4+
getActivePluginRegistry,
5+
resetPluginRuntimeStateForTest,
6+
setActivePluginRegistry,
7+
} from "../../plugins/runtime.js";
48
import { createOutboundTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js";
59
import { resolveCommandAuthorization } from "../command-auth.js";
610
import type { MsgContext } from "../templating.js";
@@ -31,6 +35,8 @@ vi.mock("./commands-subagents-control.runtime.js", () => ({
3135
const formatAllowFrom = ({ allowFrom }: { allowFrom: Array<string | number> }) =>
3236
allowFrom.map((entry) => String(entry).trim()).filter(Boolean);
3337

38+
let previousPluginRegistry: ReturnType<typeof getActivePluginRegistry>;
39+
3440
function registerOwnerEnforcingTelegramPlugin() {
3541
setActivePluginRegistry(
3642
createTestRegistry([
@@ -104,9 +110,18 @@ function buildParams(
104110

105111
describe("subagents command dispatch", () => {
106112
beforeEach(() => {
113+
previousPluginRegistry = getActivePluginRegistry();
107114
vi.clearAllMocks();
108115
});
109116

117+
afterEach(() => {
118+
if (previousPluginRegistry) {
119+
setActivePluginRegistry(previousPluginRegistry);
120+
} else {
121+
resetPluginRuntimeStateForTest();
122+
}
123+
});
124+
110125
it("prefers native command target session keys", () => {
111126
const params = buildParams("/subagents list", {
112127
CommandSource: "native",

0 commit comments

Comments
 (0)