import * as fs from "node:fs/promises";
import { expect } from "e2e";
import { T3_HOME } from "../e2e.config.ts";
import { test, WEB } from "./t3.ts";

test("A real Pi Haiku streaming reply has no extra Thinking row", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("math-demo");
  const path = `${T3_HOME}/userdata/settings.json`;
  const settings = JSON.parse(await fs.readFile(path, "utf8"));
  settings.providerInstances.pi = { driver: "pi", enabled: true, config: { binaryPath: "/usr/local/bin/pi" } };
  settings.defaultModelSelection = { instanceId: "pi", model: "anthropic/claude-haiku-5-5" };
  await fs.writeFile(path, JSON.stringify(settings));
  await t3.open();
  await expect(browser.locator('[data-chat-provider-model-picker-label]').first()).toHaveText(/Haiku/i, { timeout: 60000 });
  await screen.getByRole("textbox").fill("Do not use tools. Start your reply with STREAMING PROOF, then write a detailed 1200-word tutorial explaining pure functions with examples. Do not mention any environment or filesystem details.");
  await screen.getByRole("textbox").press("Enter");
  await browser.locator('[data-message-role="assistant"]').getByText("STREAMING PROOF", { exact: false }).first().waitFor();
  await app.screenshot("real-provider-visible-reply-streaming");
  await expect(screen.getByRole("region", "Conversation").getByText("Thinking", { exact: true }).first()).toBeHidden({ timeout: 500 });
});
