mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 07:42:44 +00:00
test: dedupe channel and transport adapters
This commit is contained in:
@@ -3,40 +3,22 @@ import { markdownToSignalText } from "./format.js";
|
||||
|
||||
describe("markdownToSignalText", () => {
|
||||
describe("duplicate URL display", () => {
|
||||
it("does not duplicate URL when label matches URL without protocol", () => {
|
||||
// [selfh.st](http://selfh.st) should render as "selfh.st" not "selfh.st (http://selfh.st)"
|
||||
const res = markdownToSignalText("[selfh.st](http://selfh.st)");
|
||||
expect(res.text).toBe("selfh.st");
|
||||
});
|
||||
it("does not duplicate URL for normalized equivalent labels", () => {
|
||||
const equivalentCases = [
|
||||
{ input: "[selfh.st](http://selfh.st)", expected: "selfh.st" },
|
||||
{ input: "[example.com](https://example.com)", expected: "example.com" },
|
||||
{ input: "[www.example.com](https://example.com)", expected: "www.example.com" },
|
||||
{ input: "[example.com](https://example.com/)", expected: "example.com" },
|
||||
{ input: "[example.com](https://example.com///)", expected: "example.com" },
|
||||
{ input: "[example.com](https://www.example.com)", expected: "example.com" },
|
||||
{ input: "[EXAMPLE.COM](https://example.com)", expected: "EXAMPLE.COM" },
|
||||
{ input: "[example.com/page](https://example.com/page)", expected: "example.com/page" },
|
||||
] as const;
|
||||
|
||||
it("does not duplicate URL when label matches URL without https protocol", () => {
|
||||
const res = markdownToSignalText("[example.com](https://example.com)");
|
||||
expect(res.text).toBe("example.com");
|
||||
});
|
||||
|
||||
it("does not duplicate URL when label matches URL without www prefix", () => {
|
||||
const res = markdownToSignalText("[www.example.com](https://example.com)");
|
||||
expect(res.text).toBe("www.example.com");
|
||||
});
|
||||
|
||||
it("does not duplicate URL when label matches URL without trailing slash", () => {
|
||||
const res = markdownToSignalText("[example.com](https://example.com/)");
|
||||
expect(res.text).toBe("example.com");
|
||||
});
|
||||
|
||||
it("does not duplicate URL when label matches URL with multiple trailing slashes", () => {
|
||||
const res = markdownToSignalText("[example.com](https://example.com///)");
|
||||
expect(res.text).toBe("example.com");
|
||||
});
|
||||
|
||||
it("does not duplicate URL when label includes www but URL does not", () => {
|
||||
const res = markdownToSignalText("[example.com](https://www.example.com)");
|
||||
expect(res.text).toBe("example.com");
|
||||
});
|
||||
|
||||
it("handles case-insensitive domain comparison", () => {
|
||||
const res = markdownToSignalText("[EXAMPLE.COM](https://example.com)");
|
||||
expect(res.text).toBe("EXAMPLE.COM");
|
||||
for (const { input, expected } of equivalentCases) {
|
||||
const res = markdownToSignalText(input);
|
||||
expect(res.text).toBe(expected);
|
||||
}
|
||||
});
|
||||
|
||||
it("still shows URL when label is meaningfully different", () => {
|
||||
@@ -49,10 +31,5 @@ describe("markdownToSignalText", () => {
|
||||
const res = markdownToSignalText("[example.com](https://example.com/page)");
|
||||
expect(res.text).toBe("example.com (https://example.com/page)");
|
||||
});
|
||||
|
||||
it("does not duplicate when label matches full URL with path", () => {
|
||||
const res = markdownToSignalText("[example.com/page](https://example.com/page)");
|
||||
expect(res.text).toBe("example.com/page");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,10 +15,9 @@ const { monitorSignalProvider } = await import("./monitor.js");
|
||||
const { replyMock, sendMock, streamMock, upsertPairingRequestMock } =
|
||||
getSignalToolResultTestMocks();
|
||||
|
||||
async function runMonitorWithMocks(
|
||||
opts: Parameters<(typeof import("./monitor.js"))["monitorSignalProvider"]>[0],
|
||||
) {
|
||||
const { monitorSignalProvider } = await import("./monitor.js");
|
||||
type MonitorSignalProviderOptions = Parameters<typeof monitorSignalProvider>[0];
|
||||
|
||||
async function runMonitorWithMocks(opts: MonitorSignalProviderOptions) {
|
||||
return monitorSignalProvider(opts);
|
||||
}
|
||||
describe("monitorSignalProvider tool results", () => {
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
installSignalToolResultTestHooks();
|
||||
|
||||
// Import after the harness registers `vi.mock(...)` for Signal internals.
|
||||
await import("./monitor.js");
|
||||
const { monitorSignalProvider } = await import("./monitor.js");
|
||||
|
||||
const {
|
||||
replyMock,
|
||||
@@ -26,6 +26,7 @@ const {
|
||||
} = getSignalToolResultTestMocks();
|
||||
|
||||
const SIGNAL_BASE_URL = "http://127.0.0.1:8080";
|
||||
type MonitorSignalProviderOptions = Parameters<typeof monitorSignalProvider>[0];
|
||||
|
||||
function createMonitorRuntime() {
|
||||
return {
|
||||
@@ -69,16 +70,13 @@ function createAutoAbortController() {
|
||||
return abortController;
|
||||
}
|
||||
|
||||
async function runMonitorWithMocks(
|
||||
opts: Parameters<(typeof import("./monitor.js"))["monitorSignalProvider"]>[0],
|
||||
) {
|
||||
const { monitorSignalProvider } = await import("./monitor.js");
|
||||
async function runMonitorWithMocks(opts: MonitorSignalProviderOptions) {
|
||||
return monitorSignalProvider(opts);
|
||||
}
|
||||
|
||||
async function receiveSignalPayloads(params: {
|
||||
payloads: unknown[];
|
||||
opts?: Partial<Parameters<(typeof import("./monitor.js"))["monitorSignalProvider"]>[0]>;
|
||||
opts?: Partial<MonitorSignalProviderOptions>;
|
||||
}) {
|
||||
const abortController = new AbortController();
|
||||
streamMock.mockImplementation(async ({ onEvent }) => {
|
||||
@@ -122,7 +120,7 @@ function makeBaseEnvelope(overrides: Record<string, unknown> = {}) {
|
||||
|
||||
async function receiveSingleEnvelope(
|
||||
envelope: Record<string, unknown>,
|
||||
opts?: Partial<Parameters<(typeof import("./monitor.js"))["monitorSignalProvider"]>[0]>,
|
||||
opts?: Partial<MonitorSignalProviderOptions>,
|
||||
) {
|
||||
await receiveSignalPayloads({
|
||||
payloads: [{ envelope }],
|
||||
|
||||
Reference in New Issue
Block a user