Files
openclaw-zero-token/auto-reply/tokens.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
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
2026-03-30 17:58:12 +08:00

105 lines
3.9 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { isSilentReplyPrefixText, isSilentReplyText, stripSilentToken } from "./tokens.js";
describe("isSilentReplyText", () => {
it("returns true for exact token", () => {
expect(isSilentReplyText("NO_REPLY")).toBe(true);
});
it("returns true for token with surrounding whitespace", () => {
expect(isSilentReplyText(" NO_REPLY ")).toBe(true);
expect(isSilentReplyText("\nNO_REPLY\n")).toBe(true);
});
it("returns false for undefined/empty", () => {
expect(isSilentReplyText(undefined)).toBe(false);
expect(isSilentReplyText("")).toBe(false);
});
it("returns false for substantive text ending with token (#19537)", () => {
const text = "Here is a helpful response.\n\nNO_REPLY";
expect(isSilentReplyText(text)).toBe(false);
});
it("returns false for substantive text starting with token", () => {
const text = "NO_REPLY but here is more content";
expect(isSilentReplyText(text)).toBe(false);
});
it("returns false for token embedded in text", () => {
expect(isSilentReplyText("Please NO_REPLY to this")).toBe(false);
});
it("works with custom token", () => {
expect(isSilentReplyText("HEARTBEAT_OK", "HEARTBEAT_OK")).toBe(true);
expect(isSilentReplyText("Checked inbox. HEARTBEAT_OK", "HEARTBEAT_OK")).toBe(false);
});
});
describe("stripSilentToken", () => {
it("strips token from end of text", () => {
expect(stripSilentToken("Done.\n\nNO_REPLY")).toBe("Done.");
});
it("does not strip token from start of text", () => {
expect(stripSilentToken("NO_REPLY 👍")).toBe("NO_REPLY 👍");
});
it("strips token with emoji (#30916)", () => {
expect(stripSilentToken("😄 NO_REPLY")).toBe("😄");
});
it("does not strip embedded token suffix without whitespace delimiter", () => {
expect(stripSilentToken("interject.NO_REPLY")).toBe("interject.NO_REPLY");
});
it("strips only trailing occurrence", () => {
expect(stripSilentToken("NO_REPLY ok NO_REPLY")).toBe("NO_REPLY ok");
});
it("returns empty string when only token remains", () => {
expect(stripSilentToken("NO_REPLY")).toBe("");
expect(stripSilentToken(" NO_REPLY ")).toBe("");
});
it("strips token preceded by bold markdown formatting", () => {
expect(stripSilentToken("**NO_REPLY")).toBe("");
expect(stripSilentToken("some text **NO_REPLY")).toBe("some text");
expect(stripSilentToken("reasoning**NO_REPLY")).toBe("reasoning");
});
it("works with custom token", () => {
expect(stripSilentToken("done HEARTBEAT_OK", "HEARTBEAT_OK")).toBe("done");
});
});
describe("isSilentReplyPrefixText", () => {
it("matches uppercase token lead fragments", () => {
expect(isSilentReplyPrefixText("NO")).toBe(true);
expect(isSilentReplyPrefixText("NO_")).toBe(true);
expect(isSilentReplyPrefixText("NO_RE")).toBe(true);
expect(isSilentReplyPrefixText("NO_REPLY")).toBe(true);
expect(isSilentReplyPrefixText(" HEARTBEAT_", "HEARTBEAT_OK")).toBe(true);
});
it("rejects ambiguous natural-language prefixes", () => {
expect(isSilentReplyPrefixText("N")).toBe(false);
expect(isSilentReplyPrefixText("No")).toBe(false);
expect(isSilentReplyPrefixText("no")).toBe(false);
expect(isSilentReplyPrefixText("Hello")).toBe(false);
});
it("keeps underscore guard for non-NO_REPLY tokens", () => {
expect(isSilentReplyPrefixText("HE", "HEARTBEAT_OK")).toBe(false);
expect(isSilentReplyPrefixText("HEART", "HEARTBEAT_OK")).toBe(false);
expect(isSilentReplyPrefixText("HEARTBEAT", "HEARTBEAT_OK")).toBe(false);
expect(isSilentReplyPrefixText("HEARTBEAT_", "HEARTBEAT_OK")).toBe(true);
});
it("rejects non-prefixes and mixed characters", () => {
expect(isSilentReplyPrefixText("NO_X")).toBe(false);
expect(isSilentReplyPrefixText("NO_REPLY more")).toBe(false);
expect(isSilentReplyPrefixText("NO-")).toBe(false);
});
});