






























11import { describe, expect, it } from "vitest";
2+import type { OpenClawConfig } from "../config/types.openclaw.js";
23import {
34createCommandTurnContext,
45isAuthorizedTextSlashCommandTurn,
@@ -7,6 +8,9 @@ import {
78resolveCommandTurnContext,
89resolveCommandTurnTargetSessionKey,
910} from "./command-turn-context.js";
11+import { isExplicitCommandTurnContext } from "./command-turn-detection.js";
12+13+const emptyConfig = {} as const satisfies OpenClawConfig;
10141115describe("resolveCommandTurnContext", () => {
1216it("derives native command turns from legacy context fields", () => {
@@ -53,6 +57,88 @@ describe("resolveCommandTurnContext", () => {
5357expect(isExplicitCommandTurn(commandTurn)).toBe(false);
5458});
555960+it("treats authorized control command bodies as explicit without legacy source tags", () => {
61+expect(
62+isExplicitCommandTurnContext(
63+{
64+CommandAuthorized: true,
65+CommandBody: "/reset",
66+},
67+emptyConfig,
68+),
69+).toBe(true);
70+expect(
71+isExplicitCommandTurnContext(
72+{
73+CommandAuthorized: true,
74+CommandBody: "hey can you /status please",
75+},
76+emptyConfig,
77+),
78+).toBe(false);
79+});
80+81+it("keeps structured normal command turns non-explicit", () => {
82+expect(
83+isExplicitCommandTurnContext(
84+{
85+CommandTurn: {
86+kind: "normal",
87+source: "message",
88+authorized: false,
89+body: "/think high through this",
90+},
91+CommandAuthorized: true,
92+Body: "through this",
93+RawBody: "through this",
94+CommandBody: "/think high through this",
95+},
96+emptyConfig,
97+),
98+).toBe(false);
99+});
100+101+it("uses cleaned command bodies for command-shaped structured normal turns", () => {
102+expect(
103+isExplicitCommandTurnContext(
104+{
105+CommandTurn: {
106+kind: "normal",
107+source: "message",
108+authorized: false,
109+body: "/reset",
110+},
111+CommandAuthorized: true,
112+Body: "/reset@openclaw",
113+RawBody: "/reset@openclaw",
114+CommandBody: "/reset",
115+},
116+emptyConfig,
117+),
118+).toBe(true);
119+});
120+121+it("normalizes bot-mentioned command bodies for structured normal turns", () => {
122+expect(
123+isExplicitCommandTurnContext(
124+{
125+CommandTurn: {
126+kind: "normal",
127+source: "message",
128+authorized: false,
129+body: "/reset@openclaw",
130+},
131+CommandAuthorized: true,
132+Body: "/reset@openclaw",
133+RawBody: "/reset@openclaw",
134+CommandBody: "/reset@openclaw",
135+BotUsername: "openclaw",
136+},
137+emptyConfig,
138+),
139+).toBe(true);
140+});
141+56142it("lets structured command turns override legacy command fields", () => {
57143expect(
58144resolveCommandTurnContext({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。