Skip to content

Commit 58f43c7

Browse files
authored
test(auto-reply): consolidate command suites (#109342)
1 parent 786ad1d commit 58f43c7

12 files changed

Lines changed: 837 additions & 874 deletions

‎docs/refactor/database-first.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ without exceptions outside doctor/import/export/debug boundaries.
187187
Proof: no schema change in this pass; `pnpm db:kysely:check`;
188188
`pnpm lint:kysely`.
189189
- [x] Re-run focused tests for touched stores, commands, and scripts.
190-
Proof: `pnpm test src/cron/service/store.test.ts src/cron/store.test.ts src/cron/service.heartbeat-ok-summary-suppressed.test.ts src/cron/service.main-job-passes-heartbeat-target-last.test.ts src/cron/service.every-jobs-fire.test.ts src/cron/service.persists-delivered-status.test.ts src/cron/service.runs-one-shot-main-job-disables-it.test.ts src/cron/service/ops.test.ts src/cron/service/timer.regression.test.ts src/auto-reply/reply/commands-export-trajectory.test.ts extensions/telegram/src/thread-bindings.test.ts extensions/slack/src/monitor/message-handler/prepare.test.ts src/acp/translator.session-lineage-meta.test.ts`; `git diff --check`.
190+
Proof: `pnpm test src/cron/service/store.test.ts src/cron/store.test.ts src/cron/service.heartbeat-ok-summary-suppressed.test.ts src/cron/service.main-job-passes-heartbeat-target-last.test.ts src/cron/service.every-jobs-fire.test.ts src/cron/service.persists-delivered-status.test.ts src/cron/service.runs-one-shot-main-job-disables-it.test.ts src/cron/service/ops.test.ts src/cron/service/timer.regression.test.ts src/auto-reply/reply/commands-export-session.test.ts extensions/telegram/src/thread-bindings.test.ts extensions/slack/src/monitor/message-handler/prepare.test.ts src/acp/translator.session-lineage-meta.test.ts`; `git diff --check`.
191191
- [x] Before declaring `done`, run the changed gate or remote broad proof.
192192
Proof: `pnpm check:changed --timed -- <changed extension paths>` passed on
193193
Hetzner Crabbox run `run_3f1cabf6b25c` after temporary Node 24/pnpm setup and

‎src/auto-reply/reply/commands-context-report.test.ts‎

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
/** Tests context report command output and generated report files. */
1+
/** Tests context command behavior, token reporting, and generated report files. */
22
import { mkdtemp, readFile, rm, unlink, writeFile } from "node:fs/promises";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
55
import { describe, expect, it } from "vitest";
6+
import type { OpenClawConfig } from "../../config/config.js";
67
import type { SessionEntry } from "../../config/sessions.js";
78
import { buildContextReply } from "./commands-context-report.js";
9+
import { buildCommandContext } from "./commands-context.js";
810
import type { HandleCommandsParams } from "./commands-types.js";
11+
import { stripStructuralPrefixes } from "./mentions.js";
12+
import { buildTestCtx } from "./test-ctx.js";
13+
14+
/** Tests context report command output and generated report files. */
915

1016
function makeParams(
1117
commandBodyNormalized: string,
@@ -412,3 +418,106 @@ describe("buildContextReply", () => {
412418
expect(result.mediaUrl).toBeUndefined();
413419
});
414420
});
421+
422+
/** Tests context command behavior and token reporting. */
423+
424+
describe("buildCommandContext", () => {
425+
it("canonicalizes registered aliases like /id to their primary command", () => {
426+
const ctx = buildTestCtx({
427+
Provider: "webchat",
428+
Surface: "webchat",
429+
From: "user",
430+
To: "bot",
431+
Body: "/id",
432+
RawBody: "/id",
433+
CommandBody: "/id",
434+
BodyForCommands: "/id",
435+
});
436+
437+
const result = buildCommandContext({
438+
ctx,
439+
cfg: {} as OpenClawConfig,
440+
isGroup: false,
441+
triggerBodyNormalized: "/id",
442+
commandAuthorized: true,
443+
});
444+
445+
expect(result.commandBodyNormalized).toBe("/whoami");
446+
});
447+
448+
it("preserves multiline soft reset tails after structural normalization", () => {
449+
const ctx = buildTestCtx({
450+
Provider: "whatsapp",
451+
Surface: "whatsapp",
452+
From: "user",
453+
To: "bot",
454+
Body: "/reset soft\nre-read persona files",
455+
RawBody: "/reset soft\nre-read persona files",
456+
CommandBody: "/reset soft\nre-read persona files",
457+
BodyForCommands: "/reset soft\nre-read persona files",
458+
});
459+
460+
const result = buildCommandContext({
461+
ctx,
462+
cfg: {} as OpenClawConfig,
463+
isGroup: false,
464+
triggerBodyNormalized: stripStructuralPrefixes("/reset soft\nre-read persona files"),
465+
commandAuthorized: true,
466+
});
467+
468+
expect(result.commandBodyNormalized).toBe("/reset soft re-read persona files");
469+
});
470+
471+
it("preserves multiline slash skill payloads after structural normalization", () => {
472+
const body = "/skill demo_skill first line\nsecond line";
473+
const ctx = buildTestCtx({
474+
Provider: "whatsapp",
475+
Surface: "whatsapp",
476+
From: "user",
477+
To: "bot",
478+
Body: body,
479+
RawBody: body,
480+
CommandBody: body,
481+
BodyForCommands: body,
482+
});
483+
484+
const result = buildCommandContext({
485+
ctx,
486+
cfg: {} as OpenClawConfig,
487+
isGroup: false,
488+
triggerBodyNormalized: stripStructuralPrefixes(body),
489+
commandAuthorized: true,
490+
});
491+
492+
expect(result.commandBodyNormalized).toBe("/skill demo_skill first line\nsecond line");
493+
});
494+
495+
it("maps explicit gateway origin into command context", () => {
496+
const ctx = buildTestCtx({
497+
Provider: "internal",
498+
Surface: "internal",
499+
OriginatingChannel: "slack",
500+
OriginatingTo: "user:U123",
501+
SenderId: "gateway-client",
502+
From: undefined,
503+
To: undefined,
504+
Body: "/codex bind",
505+
RawBody: "/codex bind",
506+
CommandBody: "/codex bind",
507+
BodyForCommands: "/codex bind",
508+
});
509+
510+
const result = buildCommandContext({
511+
ctx,
512+
cfg: {} as OpenClawConfig,
513+
isGroup: false,
514+
triggerBodyNormalized: "/codex bind",
515+
commandAuthorized: true,
516+
});
517+
518+
expect(result.channel).toBe("slack");
519+
expect(result.channelId).toBe("slack");
520+
expect(result.from).toBe("gateway-client");
521+
expect(result.to).toBe("user:U123");
522+
});
523+
});

‎src/auto-reply/reply/commands-context.test.ts‎

Lines changed: 0 additions & 107 deletions
This file was deleted.

‎src/auto-reply/reply/commands-core.send-policy.test.ts‎

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)