AkurAI Build
Menu

popagent

public

Latest change 87892c407de7c8d7b5c93e23f81356985d4f6b97 - fix: replace channel activity spam by AkurAI Build

import { describe, expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import type { ChannelMessage } from "../api-types";
import { ChannelMessageCard, visibleChannelMessages } from "./ChannelPage";

const communication: ChannelMessage = {
  id: "message-2",
  channelId: "general",
  workspaceId: "default",
  authorId: "reviewer",
  authorName: "Reviewer",
  content: "The boundary is contained.",
  taskId: null,
  task: null,
  agentCommunication: {
    taskId: "task-1",
    fromAgentId: "reviewer",
    toAgentId: "researcher",
    toAgentName: "Researcher",
    replyToMessageId: "message-1",
  },
  createdAt: "2026-08-16T12:00:00.000Z",
};

const taskActivity: ChannelMessage = {
  ...communication,
  id: "activity-1",
  authorId: "task:task-1",
  authorName: "Orchistrator",
  content: "Using mastra_workspace_read_file, agentCommunication",
  agentCommunication: null,
};

const taskStart: ChannelMessage = {
  ...communication,
  id: "task-start",
  authorId: "orchistrator",
  authorName: "Orchistrator",
  content: "Started task: Inspect the entire repository and emit a very long internal prompt",
  taskId: "task-1",
  task: {
    id: "task-1",
    sessionId: null,
    scheduleId: null,
    source: "user",
    workspaceId: "default",
    prompt: "Find one high-confidence improvement",
    model: "codex/gpt-5.6-luna-medium",
    status: "running",
    output: null,
    error: null,
    stepsCompleted: 5,
    progress: "Inspecting task execution",
    recoveryCount: 0,
    attemptCount: 1,
    maxAttempts: 3,
    nextAttemptAt: null,
    lastErrorClass: null,
    deadLetteredAt: null,
    createdAt: "2026-08-16T12:00:00.000Z",
    startedAt: "2026-08-16T12:00:01.000Z",
    completedAt: null,
  },
  agentCommunication: null,
};

describe("ChannelMessageCard", () => {
  test("renders agent and company identities with an accessible reply relation", () => {
    const html = renderToStaticMarkup(
      <ChannelMessageCard
        message={communication}
        agentName="Orchistrator"
        mode="timeline"
        onCancel={() => undefined}
      />,
    );
    expect(html).toContain("Freyja");
    expect(html).toContain("Reviewer");
    expect(html).toContain("Researcher");
    expect(html).toContain("Salka");
    expect(html).toContain("Reply to message message-1");
    expect(html).toContain('aria-label="Message from Reviewer to Researcher"');
    expect(html.match(/<img/g)).toHaveLength(2);
  });

  test("replaces raw task activity spam with one informative work card", () => {
    const html = renderToStaticMarkup(
      <ChannelMessageCard
        message={taskStart}
        agentName="Orchistrator"
        mode="timeline"
        onCancel={() => undefined}
      />,
    );
    expect(html).toContain("Find one high-confidence improvement");
    expect(html).toContain("Inspecting task execution");
    expect(html).toContain("codex/gpt-5.6-luna-medium");
    expect(html).not.toContain("Started task:");
    expect(html).not.toContain("very long internal prompt");
  });

  test("removes low-level task activity rows from the channel transcript", () => {
    expect(visibleChannelMessages([communication, taskActivity, taskStart]).map((message) => message.id))
      .toEqual(["message-2", "task-start"]);
  });
});