import { describe, expect, it } from "vitest";

import { generationErrorRegistry } from "../../apps/worker/src/generation-error-registry.js";

describe("TASK-WP2-06 fixed generation error registry", () => {
  it("contains exactly the nine frozen categories and no supplier-facing text", () => {
    expect(Object.keys(generationErrorRegistry).toSorted()).toEqual([
      "gateway_balance_insufficient", "gateway_contract_invalid", "model_disabled", "reference_invalid",
      "safety_rejected", "unknown_non_retryable", "unknown_retryable", "upstream_failed", "upstream_timeout",
    ]);
    expect(generationErrorRegistry).toMatchObject({
      gateway_balance_insufficient: { creditBehavior: "release_if_reserved", taskOutcome: "failed_or_not_created", userAction: "choose_model_or_contact_admin" },
      gateway_contract_invalid: { creditBehavior: "release_if_reserved", taskOutcome: "failed_or_not_created", userAction: "choose_model_or_contact_admin" },
      model_disabled: { creditBehavior: "no_reserve", taskOutcome: "not_created", userAction: "choose_model_or_contact_admin" },
      reference_invalid: { creditBehavior: "release_if_reserved", taskOutcome: "failed_or_not_created", userAction: "edit_input" },
      safety_rejected: { creditBehavior: "release_if_reserved", taskOutcome: "rejected", userAction: "edit_input" },
      unknown_non_retryable: { creditBehavior: "release_if_reserved", retryPolicy: "none", taskOutcome: "failed", userAction: "contact_admin" },
      unknown_retryable: { creditBehavior: "release_if_reserved", retryPolicy: "after_wait", taskOutcome: "failed", userAction: "wait_and_retry" },
      upstream_failed: { creditBehavior: "release_if_reserved", retryPolicy: "after_wait", taskOutcome: "failed", userAction: "wait_and_retry" },
      upstream_timeout: { creditBehavior: "release_if_reserved", retryPolicy: "immediate", taskOutcome: "failed", userAction: "retry_same_input" },
    });
    expect(JSON.stringify(generationErrorRegistry)).not.toMatch(/supplier|stack|https?:\/\//i);
    expect(Object.isFrozen(generationErrorRegistry)).toBe(true);
  });
});
