import test from "node:test";
import assert from "node:assert/strict";
import { actionBlockedReason, projectSetupPrompt, setupErrorMessage } from "./setup-errors.js";

test("setup error messages are actionable and hide raw error text", () => {
  assert.equal(
    setupErrorMessage(new Error("workspace_not_found"), "chat_create_failed"),
    "Selected project is no longer available. Choose another project before starting a Chat."
  );
  assert.equal(
    setupErrorMessage(new Error("account_not_available_for_execution"), "chat_message_failed"),
    "This history source can only be read. Select a signed-in account before sending."
  );
  assert.equal(
    setupErrorMessage(new Error("C:\\Users\\private\\.codex\\auth.json"), "chat_create_failed"),
    "Could not start Chat. Check the selected account and project, then try again."
  );
  assert.equal(
    setupErrorMessage(new Error("workspace_mismatch"), "chat_message_failed"),
    "The Chat opened in a different project, so no message was sent. Select the project again."
  );
  assert.equal(
    setupErrorMessage(new Error("attachment_in_use"), "request_failed"),
    "That image is being used by running or queued work. Try again after it finishes."
  );
  assert.equal(
    setupErrorMessage(new Error("attachment_delete_failed"), "request_failed"),
    "The image was not deleted. Check PC storage and try again."
  );
  assert.equal(
    setupErrorMessage(new Error("turn_start_timeout"), "chat_message_failed"),
    "Codex did not start work within 30 seconds. The Chat was stopped; try again."
  );
  assert.equal(
    setupErrorMessage(new Error("internal_error"), "stop_failed"),
    "Could not confirm that work stopped. Refresh the Chat to check its actual state."
  );
  assert.equal(
    setupErrorMessage(new Error("turn_stop_unconfirmed"), "chat_message_failed"),
    "Could not confirm that work stopped. Refresh the Chat to check its actual state."
  );
});

test("new chat disables only when an account is missing", () => {
  assert.equal(actionBlockedReason({ hasAccount: false, hasWorkspace: false }), "Sign in to a Codex account to start a Chat.");
  assert.equal(actionBlockedReason({ hasAccount: true, hasWorkspace: false }), "");
  assert.equal(actionBlockedReason({ hasAccount: true, hasWorkspace: true }), "");
});

test("project setup prompt guides first-run project selection", () => {
  assert.equal(projectSetupPrompt({ hasAccount: false, hasWorkspace: false }), "");
  assert.equal(projectSetupPrompt({ hasAccount: true, hasWorkspace: false }), "Choose or create a project folder to start a Chat.");
  assert.equal(projectSetupPrompt({ hasAccount: true, hasWorkspace: true }), "");
});
