import assert from "node:assert/strict";
import test from "node:test";

import {
  WP4_07_PERFORMANCE_BUDGETS,
  WP4_07_RED_RESOURCE_VERSION,
  WP4_07_VISUAL_THRESHOLDS,
  assertWp407Fixture,
  createWp407CanvasFixture,
} from "./wp4-07-fixture.mjs";

test("FX-CANVAS-50 stays fixed at the normative composition and export size", () => {
  const contract = assertWp407Fixture();
  assert.deepEqual(contract.counts, {
    color_card: 4,
    dynamic_sticker: 10,
    static_sticker: 24,
    text_template: 12,
  });
  assert.match(contract.fixture_sha256, /^[0-9A-F]{64}$/);
});

test("visual and performance thresholds cannot be weakened by the harness", () => {
  assert.deepEqual(WP4_07_VISUAL_THRESHOLDS, {
    boundary_delta_px_max: 2,
    channel_delta_significant: 16,
    significant_pixel_ratio_max: 0.01,
  });
  assert.deepEqual(WP4_07_PERFORMANCE_BUDGETS, {
    autosave_serialization_p95_ms_max: 50,
    canvas_frame_p95_ms_max: 33,
    continuous_unresponsive_ms_max_exclusive: 500,
    editor_reopen_ms_max: 3_000,
    export_1080x1920_ms_max: 10_000,
    export_peak_additional_bytes_max: 1_073_741_824,
    interaction_duration_ms: 10_000,
    long_task_ms_max: 200,
    measured_runs: 5,
    pointer_to_frame_p95_ms_max: 50,
    warmup_runs: 1,
  });
});

test("the Red contract resource version is structurally barred from Green", () => {
  const canvas = createWp407CanvasFixture();
  assert.equal(new Set(canvas.elements.map((element) => element.resource_version)).size, 1);
  assert.equal(canvas.elements[0].resource_version, WP4_07_RED_RESOURCE_VERSION);
  assert.match(WP4_07_RED_RESOURCE_VERSION, /red-contract/);
});
