// SPDX-License-Identifier: Apache-2.0
; specs/widgets/hive-gate.t27 -- The merge gate: when an approved pull request may merge
; Source of truth for public/widgets/hive-gate/ (gHashTag/trinity): scripts/widget-pages-from-spec.mjs
; compiles this file, checks its constants, evaluates the tests below and writes the page; the page
; hands every constant to tool.js as window.T27_WIDGET. tool.js holds no English and NO RULE of its
; own: every column, verdict and number it shows comes from public/widgets/hive-gate/logic.js -- the fn
; bodies of gHashTag/t27 specs/queen/merger_gate.t27 compiled to wasm, beside its copy logic.t27.
; Lesson 12 of the course queen-and-hive. ASCII only (L3), English only (LANG-EN).
; A K_ constant is an input, a preset, a range or a constant of the logic spec (widget-logic.mjs holds
; a K_ whose name the logic spec also has equal to it); never the result of a spec fn.

; WHAT IT DOES:  the reader sets how many checks posted, whether the ruleset is readable, and per
; check required, concluded, green and discounted. Each check is check_passes of its flags; the gate
; is gate_open(posted, running, blocking), the host counting the not concluded and the failing.

; WHAT IT DOES NOT CLAIM:  it does not read GitHub: the checks are what the reader taps. The merger
; itself is a workflow that meets this spec through a selftest.
; phi^2 + 1/phi^2 = 3 | TRINITY

module widget_hive_gate;

pub const KIND : str = "widget-tool";
pub const ID : str = "hive-gate";
pub const TITLE : str = "The merge gate: when an approved pull request may merge";
pub const DESCRIPTION : str = "Four checks on a pull request the reviewer bee approved. Tap what each one is: check_passes judges it, and gate_open opens only when one has posted, none runs and none blocks.";
pub const IMAGE_ALT : str = "Merge gate card: three checks posted. A required green check passes, an advisory red check that the bee discounted passes, and a required check still running blocks. The gate is shut, red: 1 running, 0 blocking.";
pub const HOOK : str = "Zero checks is not zero failures: a pull request with no posted check does not merge. And a red check counts as required whenever the ruleset cannot be read.";
pub const CATEGORY : str = "game";
pub const DATA_SOURCES : [2]str = ["gHashTag/t27 specs/queen/merger_gate.t27 (t27 master c42f8fb40): every value on the page is check_passes and gate_open, its fn bodies compiled to wasm (logic.js)", "Course 11 of t27.ai, queen-and-hive (gHashTag/trinity#1698): lesson 12 opens this widget"];
pub const READS_LOCAL_FILES : bool = false;
pub const SENDS_NOTHING : bool = true;

pub const K_CARD_WIDTH : u16 = 1200;
pub const K_CARD_HEIGHT : u16 = 630;

; --- Numbers: ranges, presets, and constants the logic spec holds ----------------------------
pub const K_CHECKS : u8 = 4;
pub const K_FLAG_BITS : [4]u8 = [1, 2, 4, 8];
pub const K_PRESET_POSTED : [4]u8 = [3, 2, 0, 2];
pub const K_PRESET_RULESET : [4]u8 = [1, 1, 1, 0];
pub const K_PRESET_C0 : [4]u8 = [7, 7, 0, 7];
pub const K_PRESET_C1 : [4]u8 = [10, 10, 0, 10];
pub const K_PRESET_C2 : [4]u8 = [1, 0, 0, 0];
pub const K_PRESET_C3 : [4]u8 = [0, 0, 0, 0];
pub const K_START_PRESET : u8 = 0;

; --- Words on screen ------------------------------------------------------------------------
pub const SAY_PRESETS_LABEL : str = "Start from";
pub const SAY_PRESET_NAMES : [4]str = ["One check still running", "All concluded", "No check posted", "Ruleset unreadable"];
pub const SAY_ASK : str = "When may the merger merge a pull request the reviewer bee approved?";
pub const SAY_POSTED : str = "checks posted";
pub const SAY_RULESET : str = "ruleset readable";
pub const SAY_CHECK_NAMES : [4]str = ["build", "corpus ratchet", "website gate", "typecheck"];
pub const SAY_FLAGS : [4]str = ["required", "concluded", "green", "discounted"];
pub const SAY_PASSES : str = "passes";
pub const SAY_BLOCKS : str = "blocks";
pub const SAY_RUNNING : str = "running";
pub const SAY_OPEN : str = "The gate opens: merge";
pub const SAY_SHUT : str = "The gate stays shut";
pub const SAY_COUNTS : str = "{0} posted, {1} running, {2} blocking";
pub const SAY_NOTE : str = "A red check passes only when it is not required, has concluded and the bee named it as discounted. With the ruleset unreadable, every check counts as required, so no red one is discountable.";
pub const SAY_SOURCE : str = "Logic: t27 spec queen/merger_gate.t27, compiled";

test the_card_is_the_share_size {
    assert K_CARD_WIDTH == 1200;
    assert K_CARD_HEIGHT == 630;
    assert K_CARD_WIDTH * 21 == K_CARD_HEIGHT * 40;
}

test four_checks_four_flags {
    assert K_CHECKS == 4;
    assert K_FLAG_BITS[3] == 8;
}

test the_start_has_a_running_required_check {
    assert K_PRESET_POSTED[0] == 3;
    assert K_PRESET_C2[0] == 1;
    assert K_PRESET_POSTED[2] == 0;
}
