Files
oh-my-pi/packages/coding-agent/test/streaming-render-debug.ts
T
can1357 e22d123009 refactor(fs): migrated remaining sync file operations to async
- Converted readdirSync, readFileSync, and statSync to async readdir, readFile, stat across skills and agent discovery.
- Made scanDirectoryForSkills async and refactored custom directory scanning to use Promise.all for concurrent processing.
- Updated agent discovery to use fs/promises for async file reading and refactored helper patterns.
- Added AgentParsingError exception class for better error handling during agent parsing.
- Added filesystem error type guards (isEnoent, isEacces, isPerm, etc.) to pi-utils for safe error checking.
- Added color manipulation utilities to pi-utils for accessibility features.
- Added color-blind mode setting to settings manager.
- Migrated plugins, settings, and config modules from sync to async file operations.
- Updated error handling to use new pi-utils type guards for type-safe checking.
2026-01-24 03:18:03 +01:00

90 lines
2.6 KiB
TypeScript

/**
* Debug script to reproduce streaming rendering issues.
* Uses real fixture data that caused the bug.
* Run with: npx tsx test/streaming-render-debug.ts
*/
import * as path from "node:path";
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
import { AssistantMessageComponent } from "@oh-my-pi/pi-coding-agent/modes/components/assistant-message";
import { initTheme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
import { ProcessTerminal, TUI } from "@oh-my-pi/pi-tui";
import { sleep } from "bun";
// Initialize dark theme with full color support
process.env.COLORTERM = "truecolor";
initTheme("dark");
async function main() {
// Load the real fixture that caused the bug
const fixtureMessage: AssistantMessage = JSON.parse(
await Bun.file(path.join(import.meta.dir, "fixtures/assistant-message-with-thinking-code.json")).text(),
);
// Extract thinking and text content
const thinkingContent = fixtureMessage.content.find((c) => c.type === "thinking");
const textContent = fixtureMessage.content.find((c) => c.type === "text");
if (!thinkingContent || thinkingContent.type !== "thinking") {
console.error("No thinking content in fixture");
process.exit(1);
}
const fullThinkingText = thinkingContent.thinking;
const fullTextContent = textContent && textContent.type === "text" ? textContent.text : "";
const terminal = new ProcessTerminal();
const tui = new TUI(terminal);
// Start with empty message
const message = {
role: "assistant",
content: [{ type: "thinking", thinking: "" }],
} as AssistantMessage;
const component = new AssistantMessageComponent(message, false);
tui.addChild(component);
tui.start();
// Simulate streaming thinking content
let thinkingBuffer = "";
const chunkSize = 10; // characters per "token"
for (let i = 0; i < fullThinkingText.length; i += chunkSize) {
thinkingBuffer += fullThinkingText.slice(i, i + chunkSize);
// Update message content
const updatedMessage = {
role: "assistant",
content: [{ type: "thinking", thinking: thinkingBuffer }],
} as AssistantMessage;
component.updateContent(updatedMessage);
tui.requestRender();
await sleep(15); // Simulate token delay
}
// Now add the text content
await sleep(500);
const finalMessage = {
role: "assistant",
content: [
{ type: "thinking", thinking: fullThinkingText },
{ type: "text", text: fullTextContent },
],
} as AssistantMessage;
component.updateContent(finalMessage);
tui.requestRender();
// Keep alive for a moment to see the result
await sleep(3000);
tui.stop();
process.exit(0);
}
main().catch(console.error);