singularity-forge/packages/coding-agent/src/core/compaction-utils.test.ts
Mikael Hugo 6725a55591 feat(web): add error boundaries, expand test coverage, add README
- Add class-based ErrorBoundary component wrapping all 7 main views
  inside WorkspaceChrome; fallback shows view name, error, reload button
- Add 30 new unit tests (boot null-project path × 9, onboarding
  pure-function logic × 21); all 43 web/lib tests pass
- Add web/README.md: architecture, auth flow, 7 views, dev setup,
  API route pattern, test instructions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-10 11:24:40 +02:00

75 lines
2 KiB
TypeScript

import assert from "node:assert/strict";
import type { Message } from "@singularity-forge/ai";
import { test } from "vitest";
import { serializeConversation } from "./compaction/index.js";
test("serializeConversation uses narrative role markers instead of chat-style delimiters (#4054)", () => {
const messages: Message[] = [
{ role: "user", content: "Please refactor the parser." } as Message,
{
role: "assistant",
content: [
{
type: "thinking",
thinking: "I should inspect the parser entry points first.",
},
{ type: "text", text: "I'll start with the parser entry points." },
{
type: "toolCall",
id: "tool-1",
name: "Read",
arguments: { path: "src/parser.ts" },
},
],
api: "anthropic-messages",
provider: "anthropic",
model: "claude-sonnet-4-6",
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
},
stopReason: "stop",
timestamp: Date.now(),
} as Message,
{
role: "toolResult",
content: [{ type: "text", text: "parser contents" }],
toolName: "Read",
toolCallId: "tool-1",
} as Message,
];
const serialized = serializeConversation(messages);
assert.match(serialized, /\*\*User said:\*\* Please refactor the parser\./);
assert.match(
serialized,
/\*\*Assistant thinking:\*\* I should inspect the parser entry points first\./,
);
assert.match(
serialized,
/\*\*Assistant responded:\*\* I'll start with the parser entry points\./,
);
assert.match(
serialized,
/\*\*Assistant tool calls:\*\* Read\(path="src\/parser\.ts"\)/,
);
assert.match(serialized, /\*\*Tool result:\*\* parser contents/);
assert.ok(
!serialized.includes("[User]:"),
"chat-style [User]: markers should not remain",
);
assert.ok(
!serialized.includes("[Assistant]:"),
"chat-style [Assistant]: markers should not remain",
);
assert.ok(
!serialized.includes("[Tool result]:"),
"chat-style [Tool result]: markers should not remain",
);
});