Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openclaw/src/shared/   (KI Agentensystem Version 22©)  Datei vom 26.3.2026 mit Größe 2 kB image not shown  

Quelle  chat-content.test.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import { describe, expect, it } from "vitest";
import { extractTextFromChatContent } from "./chat-content.js";

describe("shared/chat-content", () => {
  it("normalizes plain string content", () => {
    expect(extractTextFromChatContent("  hello\nworld  ")).toBe("hello world");
  });

  it("extracts only text blocks from array content", () => {
    expect(
      extractTextFromChatContent([
        { type: "text", text: " hello " },
        { type: "image_url", image_url: "https://example.com" },
        { type: "text", text: "world" },
        { text: "ignored without type" },
        null,
      ]),
    ).toBe("hello world");
  });

  it("applies sanitizers and custom join/normalization hooks", () => {
    expect(
      extractTextFromChatContent("Here [Tool Call: foo (ID: 1)] ok", {
        sanitizeText: (text) => text.replace(/\[Tool Call:[^\]]+\]\s*/g, ""),
      }),
    ).toBe("Here ok");

    expect(
      extractTextFromChatContent(
        [
          { type: "text", text: " hello " },
          { type: "text", text: "world " },
        ],
        {
          sanitizeText: (text) => text.trim(),
          joinWith: "\n",
          normalizeText: (text) => text.trim(),
        },
      ),
    ).toBe("hello\nworld");

    expect(
      extractTextFromChatContent(
        [
          { type: "text", text: "keep" },
          { type: "text", text: "drop" },
        ],
        {
          sanitizeText: (text) => (text === "drop" ? "   " : text),
        },
      ),
    ).toBe("keep");
  });

  it("returns null for unsupported or empty content", () => {
    expect(extractTextFromChatContent(123)).toBeNull();
    expect(extractTextFromChatContent([{ type: "text", text: "   " }])).toBeNull();
    expect(
      extractTextFromChatContent("  ", {
        sanitizeText: () => "",
      }),
    ).toBeNull();
  });

  it("tolerates sanitize and normalize hooks that return non-string values", () => {
    expect(
      extractTextFromChatContent("hello", {
        sanitizeText: () => undefined as unknown as string,
      }),
    ).toBeNull();
    expect(
      extractTextFromChatContent([{ type: "text", text: "hello" }], {
        sanitizeText: () => 42 as unknown as string,
      }),
    ).toBe("42");
    expect(
      extractTextFromChatContent("hello", {
        normalizeText: () => undefined as unknown as string,
      }),
    ).toBeNull();
  });
});

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.