src/lightspeed@ops@transport_expansion_harness.erl

-module(lightspeed@ops@transport_expansion_harness).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lightspeed/ops/transport_expansion_harness.gleam").
-export([pass_fail_label/1, run_scenario/1, run_matrix/0, negotiation_contract_version_label/0, scenario_label/1, signature/1, scenario/1, deterministic/1, outcomes/1, failed_scenarios/1, nondeterministic_failures/1, report_signature/1, snapshot_signature/0, snapshot_report_markdown/0]).
-export_type([scenario/0, scenario_outcome/0, report/0]).

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

?MODULEDOC(" Deterministic transport compatibility and progressive enhancement harness (M56).\n").

-type scenario() :: capability_negotiation_and_mode_transitions |
    degraded_workflow_parity_across_modes |
    proxy_and_protocol_guidance_hardening |
    cross_transport_reconnect_invariant_parity |
    regression_gate_determinism.

-type scenario_outcome() :: {scenario_outcome,
        scenario(),
        boolean(),
        boolean(),
        binary()}.

-type report() :: {report, list(scenario_outcome()), integer(), integer()}.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 597).
-spec count_nondeterministic(list(scenario_outcome())) -> integer().
count_nondeterministic(Outcomes) ->
    _pipe = Outcomes,
    _pipe@1 = gleam@list:filter(
        _pipe,
        fun(Outcome) -> not erlang:element(4, Outcome) end
    ),
    erlang:length(_pipe@1).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 591).
-spec count_failed(list(scenario_outcome())) -> integer().
count_failed(Outcomes) ->
    _pipe = Outcomes,
    _pipe@1 = gleam@list:filter(
        _pipe,
        fun(Outcome) -> not erlang:element(3, Outcome) end
    ),
    erlang:length(_pipe@1).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 97).
?DOC(" Stable pass/fail label.\n").
-spec pass_fail_label(scenario_outcome()) -> binary().
pass_fail_label(Outcome) ->
    case erlang:element(3, Outcome) of
        true ->
            <<"pass"/utf8>>;

        false ->
            <<"fail"/utf8>>
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 603).
-spec bool_label(boolean()) -> binary().
bool_label(Value) ->
    case Value of
        true ->
            <<"true"/utf8>>;

        false ->
            <<"false"/utf8>>
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 573).
-spec auth_hook() -> lightspeed@transport@contract:auth_hook().
auth_hook() ->
    lightspeed@transport@contract:allow_all(<<"proc-a"/utf8>>).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 581).
-spec connect_request(integer()) -> lightspeed@transport@matrix:connect_request().
connect_request(Now_ms) ->
    {connect_request,
        <<"/counter"/utf8>>,
        <<"csrf"/utf8>>,
        <<"https://example.test"/utf8>>,
        Now_ms,
        false}.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 577).
-spec session_state(binary()) -> lightspeed@agent@session:session().
session_state(Id) ->
    lightspeed@agent@session:start(Id, <<"proc-a"/utf8>>, rehydrate, 0, 100).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 552).
-spec connect_state(
    lightspeed@transport@matrix:profile(),
    lightspeed@transport@progressive_enhancement:negotiation_policy(),
    lightspeed@transport@progressive_enhancement:proxy_headers(),
    lightspeed@transport@matrix:connect_request()
) -> {ok, lightspeed@transport@progressive_enhancement:negotiated_state()} |
    {error, binary()}.
connect_state(Profile, Policy, Proxy_headers, Request) ->
    case lightspeed@transport@progressive_enhancement:connect(
        session_state(
            <<"m56-"/utf8,
                (lightspeed@transport@matrix:profile_label(Profile))/binary>>
        ),
        Request,
        Profile,
        auth_hook(),
        Policy,
        Proxy_headers
    ) of
        {rejected, Error} ->
            {error, lightspeed@transport@contract:error_to_string(Error)};

        {connected, State, _} ->
            {ok, State}
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 457).
-spec run_reconnect_script(
    lightspeed@transport@matrix:profile(),
    lightspeed@transport@progressive_enhancement:negotiation_policy()
) -> {boolean(), binary(), binary()}.
run_reconnect_script(Profile, Policy) ->
    case connect_state(
        Profile,
        Policy,
        lightspeed@transport@progressive_enhancement:default_proxy_headers(),
        connect_request(0)
    ) of
        {error, Reason} ->
            {false,
                <<"connect_error:"/utf8, Reason/binary>>,
                <<"connect_error"/utf8>>};

        {ok, State0} ->
            First = lightspeed@transport@progressive_enhancement:apply_increment(
                State0,
                10
            ),
            Upgraded = lightspeed@transport@progressive_enhancement:upgrade(
                erlang:element(2, First),
                connect_request(11),
                auth_hook()
            ),
            case Upgraded of
                {rejected, Error} ->
                    {false,
                        <<"upgrade_error:"/utf8,
                            (lightspeed@transport@contract:error_to_string(
                                Error
                            ))/binary>>,
                        <<"upgrade_error"/utf8>>};

                {connected, State1, _} ->
                    Second = lightspeed@transport@progressive_enhancement:apply_increment(
                        State1,
                        12
                    ),
                    Canonical = <<<<<<<<<<<<<<"first="/utf8,
                                                (erlang:element(3, First))/binary>>/binary,
                                            ":counter="/utf8>>/binary,
                                        (erlang:integer_to_binary(
                                            erlang:element(4, First)
                                        ))/binary>>/binary,
                                    "|second="/utf8>>/binary,
                                (erlang:element(3, Second))/binary>>/binary,
                            ":counter="/utf8>>/binary,
                        (erlang:integer_to_binary(erlang:element(4, Second)))/binary>>,
                    Signature = <<<<<<<<<<<<<<<<<<"mode_start="/utf8,
                                                        (lightspeed@transport@progressive_enhancement:mode_label(
                                                            State0
                                                        ))/binary>>/binary,
                                                    ":mode_after_upgrade="/utf8>>/binary,
                                                (lightspeed@transport@progressive_enhancement:mode_label(
                                                    State1
                                                ))/binary>>/binary,
                                            ":mode_after_second="/utf8>>/binary,
                                        (erlang:element(5, Second))/binary>>/binary,
                                    ":transitions="/utf8>>/binary,
                                (lightspeed@transport@progressive_enhancement:transition_signature(
                                    erlang:element(2, Second)
                                ))/binary>>/binary,
                            "|"/utf8>>/binary,
                        Canonical/binary>>,
                    Passed = (((erlang:element(3, First) =:= <<"diff"/utf8>>)
                    andalso (erlang:element(3, Second) =:= <<"diff"/utf8>>))
                    andalso (erlang:element(4, First) =:= 1))
                    andalso (erlang:element(4, Second) =:= 2),
                    {Passed, Canonical, Signature}
            end
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 427).
-spec evaluate_cross_transport_reconnect_invariant_parity() -> {boolean(),
    binary()}.
evaluate_cross_transport_reconnect_invariant_parity() ->
    {Ws_passed, Ws_canonical, Ws_signature} = run_reconnect_script(
        web_socket_only,
        lightspeed@transport@progressive_enhancement:default_policy()
    ),
    {Sse_passed, Sse_canonical, Sse_signature} = run_reconnect_script(
        web_socket_with_server_sent_events_fallback,
        lightspeed@transport@progressive_enhancement:fallback_first_policy()
    ),
    {Lp_passed, Lp_canonical, Lp_signature} = run_reconnect_script(
        web_socket_with_long_polling_fallback,
        lightspeed@transport@progressive_enhancement:fallback_first_policy()
    ),
    Canonical_match = (Ws_canonical =:= Sse_canonical) andalso (Sse_canonical
    =:= Lp_canonical),
    Passed = ((Ws_passed andalso Sse_passed) andalso Lp_passed) andalso Canonical_match,
    {Passed,
        <<<<<<<<<<<<<<"ws="/utf8, Ws_signature/binary>>/binary, "|sse="/utf8>>/binary,
                            Sse_signature/binary>>/binary,
                        "|lp="/utf8>>/binary,
                    Lp_signature/binary>>/binary,
                "|canonical_match="/utf8>>/binary,
            (bool_label(Canonical_match))/binary>>}.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 363).
-spec evaluate_proxy_and_protocol_guidance_hardening() -> {boolean(), binary()}.
evaluate_proxy_and_protocol_guidance_hardening() ->
    Policy = lightspeed@transport@progressive_enhancement:default_policy(),
    Good_headers = lightspeed@transport@progressive_enhancement:default_proxy_headers(
        
    ),
    Bad_headers = {proxy_headers,
        <<"ftp"/utf8>>,
        <<"close"/utf8>>,
        <<""/utf8>>,
        <<""/utf8>>,
        <<""/utf8>>},
    Good_assessment = lightspeed@transport@progressive_enhancement:assess_proxy_headers(
        Good_headers,
        Policy
    ),
    Bad_assessment = lightspeed@transport@progressive_enhancement:assess_proxy_headers(
        Bad_headers,
        Policy
    ),
    Bad_rejected = case lightspeed@transport@progressive_enhancement:connect(
        session_state(<<"m56-proxy-bad"/utf8>>),
        connect_request(0),
        web_socket_only,
        auth_hook(),
        Policy,
        Bad_headers
    ) of
        {rejected, Error} ->
            gleam_stdlib:contains_string(
                lightspeed@transport@contract:error_to_string(Error),
                <<"proxy_guidance_rejected"/utf8>>
            );

        {connected, _, _} ->
            false
    end,
    case connect_state(
        web_socket_only,
        Policy,
        Good_headers,
        connect_request(0)
    ) of
        {error, Reason} ->
            {false, <<"good_connect_error:"/utf8, Reason/binary>>};

        {ok, State} ->
            Protocol_signature = lightspeed@transport@progressive_enhancement:protocol_invariant_signature(
                State
            ),
            Passed = (((erlang:element(2, Good_assessment) andalso not erlang:element(
                2,
                Bad_assessment
            ))
            andalso Bad_rejected)
            andalso gleam_stdlib:contains_string(
                Protocol_signature,
                <<"protocol=lightspeed"/utf8>>
            ))
            andalso gleam_stdlib:contains_string(
                Protocol_signature,
                <<"version=1"/utf8>>
            ),
            {Passed,
                <<<<<<<<<<<<<<"good="/utf8,
                                            (lightspeed@transport@progressive_enhancement:proxy_assessment_signature(
                                                Good_assessment
                                            ))/binary>>/binary,
                                        "|bad="/utf8>>/binary,
                                    (lightspeed@transport@progressive_enhancement:proxy_assessment_signature(
                                        Bad_assessment
                                    ))/binary>>/binary,
                                "|protocol="/utf8>>/binary,
                            Protocol_signature/binary>>/binary,
                        "|bad_rejected="/utf8>>/binary,
                    (bool_label(Bad_rejected))/binary>>}
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 277).
-spec evaluate_degraded_workflow_parity_across_modes() -> {boolean(), binary()}.
evaluate_degraded_workflow_parity_across_modes() ->
    Request = connect_request(0),
    Proxy = lightspeed@transport@progressive_enhancement:default_proxy_headers(),
    case connect_state(
        web_socket_only,
        lightspeed@transport@progressive_enhancement:default_policy(),
        Proxy,
        Request
    ) of
        {error, Reason} ->
            {false, <<"ws_connect_error:"/utf8, Reason/binary>>};

        {ok, Primary} ->
            {Primary_state, Primary_report} = lightspeed@transport@progressive_enhancement:run_degraded_workflows(
                Primary,
                20
            ),
            Primary_equivalence = lightspeed@transport@progressive_enhancement:workflow_equivalence_signature(
                Primary_report
            ),
            case connect_state(
                web_socket_with_server_sent_events_fallback,
                lightspeed@transport@progressive_enhancement:fallback_first_policy(
                    
                ),
                Proxy,
                Request
            ) of
                {error, Reason@1} ->
                    {false, <<"sse_connect_error:"/utf8, Reason@1/binary>>};

                {ok, Sse_fallback} ->
                    {_, Sse_report} = lightspeed@transport@progressive_enhancement:run_degraded_workflows(
                        Sse_fallback,
                        20
                    ),
                    Sse_equivalence = lightspeed@transport@progressive_enhancement:workflow_equivalence_signature(
                        Sse_report
                    ),
                    case connect_state(
                        web_socket_with_long_polling_fallback,
                        lightspeed@transport@progressive_enhancement:fallback_first_policy(
                            
                        ),
                        Proxy,
                        Request
                    ) of
                        {error, Reason@2} ->
                            {false,
                                <<"lp_connect_error:"/utf8, Reason@2/binary>>};

                        {ok, Lp_fallback} ->
                            {_, Lp_report} = lightspeed@transport@progressive_enhancement:run_degraded_workflows(
                                Lp_fallback,
                                20
                            ),
                            Lp_equivalence = lightspeed@transport@progressive_enhancement:workflow_equivalence_signature(
                                Lp_report
                            ),
                            Workflows_match = (Primary_equivalence =:= Sse_equivalence)
                            andalso (Sse_equivalence =:= Lp_equivalence),
                            Passed = (((Workflows_match andalso gleam_stdlib:contains_string(
                                lightspeed@transport@progressive_enhancement:workflow_signature(
                                    Primary_report
                                ),
                                <<"counter=1"/utf8>>
                            ))
                            andalso gleam_stdlib:contains_string(
                                lightspeed@transport@progressive_enhancement:workflow_signature(
                                    Sse_report
                                ),
                                <<"counter=1"/utf8>>
                            ))
                            andalso gleam_stdlib:contains_string(
                                lightspeed@transport@progressive_enhancement:workflow_signature(
                                    Lp_report
                                ),
                                <<"counter=1"/utf8>>
                            ))
                            andalso (lightspeed@transport@progressive_enhancement:mode_label(
                                Primary_state
                            )
                            =:= <<"primary_realtime"/utf8>>),
                            {Passed,
                                <<<<<<<<<<<<<<"ws="/utf8,
                                                            (lightspeed@transport@progressive_enhancement:workflow_signature(
                                                                Primary_report
                                                            ))/binary>>/binary,
                                                        "|sse="/utf8>>/binary,
                                                    (lightspeed@transport@progressive_enhancement:workflow_signature(
                                                        Sse_report
                                                    ))/binary>>/binary,
                                                "|lp="/utf8>>/binary,
                                            (lightspeed@transport@progressive_enhancement:workflow_signature(
                                                Lp_report
                                            ))/binary>>/binary,
                                        "|equivalent="/utf8>>/binary,
                                    (bool_label(Workflows_match))/binary>>}
                    end
            end
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 206).
-spec evaluate_capability_negotiation_and_mode_transitions() -> {boolean(),
    binary()}.
evaluate_capability_negotiation_and_mode_transitions() ->
    Policy = lightspeed@transport@progressive_enhancement:default_policy(),
    Request = connect_request(0),
    case connect_state(
        web_socket_with_long_polling_fallback,
        Policy,
        lightspeed@transport@progressive_enhancement:default_proxy_headers(),
        Request
    ) of
        {error, Reason} ->
            {false, Reason};

        {ok, State} ->
            Mode_connected = lightspeed@transport@progressive_enhancement:mode_label(
                State
            ),
            Connected_capabilities = lightspeed@transport@progressive_enhancement:capability_signature(
                State
            ),
            Downgraded = lightspeed@transport@progressive_enhancement:downgrade(
                State,
                connect_request(1),
                auth_hook()
            ),
            case Downgraded of
                {rejected, Error} ->
                    {false,
                        <<"downgrade_rejected:"/utf8,
                            (lightspeed@transport@contract:error_to_string(
                                Error
                            ))/binary>>};

                {connected, Down_state, _} ->
                    Mode_downgraded = lightspeed@transport@progressive_enhancement:mode_label(
                        Down_state
                    ),
                    Fallback_capabilities = lightspeed@transport@progressive_enhancement:capability_signature(
                        Down_state
                    ),
                    Upgraded = lightspeed@transport@progressive_enhancement:upgrade(
                        Down_state,
                        connect_request(2),
                        auth_hook()
                    ),
                    case Upgraded of
                        {rejected, Error@1} ->
                            {false,
                                <<"upgrade_rejected:"/utf8,
                                    (lightspeed@transport@contract:error_to_string(
                                        Error@1
                                    ))/binary>>};

                        {connected, Up_state, _} ->
                            Mode_upgraded = lightspeed@transport@progressive_enhancement:mode_label(
                                Up_state
                            ),
                            Upgraded_capabilities = lightspeed@transport@progressive_enhancement:capability_signature(
                                Up_state
                            ),
                            Transitions = lightspeed@transport@progressive_enhancement:transition_signature(
                                Up_state
                            ),
                            Passed = ((((((Mode_connected =:= <<"primary_realtime"/utf8>>)
                            andalso (Mode_downgraded =:= <<"fallback_polling"/utf8>>))
                            andalso (Mode_upgraded =:= <<"primary_realtime"/utf8>>))
                            andalso gleam_stdlib:contains_string(
                                Fallback_capabilities,
                                <<"bidirectional=false"/utf8>>
                            ))
                            andalso gleam_stdlib:contains_string(
                                Upgraded_capabilities,
                                <<"bidirectional=true"/utf8>>
                            ))
                            andalso gleam_stdlib:contains_string(
                                Transitions,
                                <<"downgrade:fallback_polling"/utf8>>
                            ))
                            andalso gleam_stdlib:contains_string(
                                Transitions,
                                <<"upgrade:primary_realtime"/utf8>>
                            ),
                            {Passed,
                                <<<<<<<<<<<<<<"connected="/utf8,
                                                            Connected_capabilities/binary>>/binary,
                                                        "|fallback="/utf8>>/binary,
                                                    Fallback_capabilities/binary>>/binary,
                                                "|upgraded="/utf8>>/binary,
                                            Upgraded_capabilities/binary>>/binary,
                                        "|transitions="/utf8>>/binary,
                                    Transitions/binary>>}
                    end
            end
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 517).
-spec evaluate_regression_gate_determinism() -> {boolean(), binary()}.
evaluate_regression_gate_determinism() ->
    Negotiation = run_scenario(capability_negotiation_and_mode_transitions),
    Workflows = run_scenario(degraded_workflow_parity_across_modes),
    Proxy = run_scenario(proxy_and_protocol_guidance_hardening),
    Reconnect = run_scenario(cross_transport_reconnect_invariant_parity),
    Passed = ((((((erlang:element(3, Negotiation) andalso erlang:element(
        3,
        Workflows
    ))
    andalso erlang:element(3, Proxy))
    andalso erlang:element(3, Reconnect))
    andalso erlang:element(4, Negotiation))
    andalso erlang:element(4, Workflows))
    andalso erlang:element(4, Proxy))
    andalso erlang:element(4, Reconnect),
    Signature = <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"negotiation="/utf8,
                                                                (pass_fail_label(
                                                                    Negotiation
                                                                ))/binary>>/binary,
                                                            ":"/utf8>>/binary,
                                                        (erlang:element(
                                                            5,
                                                            Negotiation
                                                        ))/binary>>/binary,
                                                    "|workflows="/utf8>>/binary,
                                                (pass_fail_label(Workflows))/binary>>/binary,
                                            ":"/utf8>>/binary,
                                        (erlang:element(5, Workflows))/binary>>/binary,
                                    "|proxy="/utf8>>/binary,
                                (pass_fail_label(Proxy))/binary>>/binary,
                            ":"/utf8>>/binary,
                        (erlang:element(5, Proxy))/binary>>/binary,
                    "|reconnect="/utf8>>/binary,
                (pass_fail_label(Reconnect))/binary>>/binary,
            ":"/utf8>>/binary,
        (erlang:element(5, Reconnect))/binary>>,
    {Passed, Signature}.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 192).
-spec evaluate(scenario()) -> {boolean(), binary()}.
evaluate(Scenario) ->
    case Scenario of
        capability_negotiation_and_mode_transitions ->
            evaluate_capability_negotiation_and_mode_transitions();

        degraded_workflow_parity_across_modes ->
            evaluate_degraded_workflow_parity_across_modes();

        proxy_and_protocol_guidance_hardening ->
            evaluate_proxy_and_protocol_guidance_hardening();

        cross_transport_reconnect_invariant_parity ->
            evaluate_cross_transport_reconnect_invariant_parity();

        regression_gate_determinism ->
            evaluate_regression_gate_determinism()
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 63).
?DOC(" Run one scenario twice and require deterministic parity.\n").
-spec run_scenario(scenario()) -> scenario_outcome().
run_scenario(Scenario) ->
    {First_passed, First_signature} = evaluate(Scenario),
    {Second_passed, Second_signature} = evaluate(Scenario),
    Deterministic = (First_passed =:= Second_passed) andalso (First_signature
    =:= Second_signature),
    Passed = (First_passed andalso Second_passed) andalso Deterministic,
    {scenario_outcome, Scenario, Passed, Deterministic, First_signature}.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 44).
?DOC(" Run all M56 scenarios.\n").
-spec run_matrix() -> report().
run_matrix() ->
    Outcomes = begin
        _pipe = [capability_negotiation_and_mode_transitions,
            degraded_workflow_parity_across_modes,
            proxy_and_protocol_guidance_hardening,
            cross_transport_reconnect_invariant_parity,
            regression_gate_determinism],
        gleam@list:map(_pipe, fun run_scenario/1)
    end,
    {report, Outcomes, count_failed(Outcomes), count_nondeterministic(Outcomes)}.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 79).
?DOC(" M56 negotiation contract version label.\n").
-spec negotiation_contract_version_label() -> binary().
negotiation_contract_version_label() ->
    <<"m56.negotiation.v"/utf8, (erlang:integer_to_binary(1))/binary>>.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 84).
?DOC(" Scenario label.\n").
-spec scenario_label(scenario()) -> binary().
scenario_label(Scenario) ->
    case Scenario of
        capability_negotiation_and_mode_transitions ->
            <<"capability_negotiation_and_mode_transitions"/utf8>>;

        degraded_workflow_parity_across_modes ->
            <<"degraded_workflow_parity_across_modes"/utf8>>;

        proxy_and_protocol_guidance_hardening ->
            <<"proxy_and_protocol_guidance_hardening"/utf8>>;

        cross_transport_reconnect_invariant_parity ->
            <<"cross_transport_reconnect_invariant_parity"/utf8>>;

        regression_gate_determinism ->
            <<"regression_gate_determinism"/utf8>>
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 105).
?DOC(" Scenario signature accessor.\n").
-spec signature(scenario_outcome()) -> binary().
signature(Outcome) ->
    erlang:element(5, Outcome).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 110).
?DOC(" Scenario accessor.\n").
-spec scenario(scenario_outcome()) -> scenario().
scenario(Outcome) ->
    erlang:element(2, Outcome).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 115).
?DOC(" Scenario determinism accessor.\n").
-spec deterministic(scenario_outcome()) -> boolean().
deterministic(Outcome) ->
    erlang:element(4, Outcome).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 120).
?DOC(" Report outcomes accessor.\n").
-spec outcomes(report()) -> list(scenario_outcome()).
outcomes(Report) ->
    erlang:element(2, Report).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 125).
?DOC(" Failed scenario count.\n").
-spec failed_scenarios(report()) -> integer().
failed_scenarios(Report) ->
    erlang:element(3, Report).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 130).
?DOC(" Nondeterministic scenario count.\n").
-spec nondeterministic_failures(report()) -> integer().
nondeterministic_failures(Report) ->
    erlang:element(4, Report).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 610).
-spec join_with(binary(), list(binary())) -> binary().
join_with(Separator, Values) ->
    case Values of
        [] ->
            <<""/utf8>>;

        [First | Rest] ->
            gleam@list:fold(
                Rest,
                First,
                fun(Accumulator, Value) ->
                    <<<<Accumulator/binary, Separator/binary>>/binary,
                        Value/binary>>
                end
            )
    end.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 135).
?DOC(" Stable report signature.\n").
-spec report_signature(report()) -> binary().
report_signature(Report) ->
    Entries = gleam@list:map(
        erlang:element(2, Report),
        fun(Outcome) ->
            <<<<<<<<<<<<(scenario_label(erlang:element(2, Outcome)))/binary,
                                    "="/utf8>>/binary,
                                (pass_fail_label(Outcome))/binary>>/binary,
                            ":deterministic="/utf8>>/binary,
                        (bool_label(erlang:element(4, Outcome)))/binary>>/binary,
                    ":"/utf8>>/binary,
                (erlang:element(5, Outcome))/binary>>
        end
    ),
    join_with(<<";"/utf8>>, Entries).

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 151).
?DOC(" Deterministic snapshot signature for M56 fixture drift gates.\n").
-spec snapshot_signature() -> binary().
snapshot_signature() ->
    <<<<<<"m56.snapshot.v"/utf8, (erlang:integer_to_binary(1))/binary>>/binary,
            "|"/utf8>>/binary,
        (report_signature(run_matrix()))/binary>>.

-file("src/lightspeed/ops/transport_expansion_harness.gleam", 159).
?DOC(" Deterministic markdown report for M56 fixture scripts.\n").
-spec snapshot_report_markdown() -> binary().
snapshot_report_markdown() ->
    Report = run_matrix(),
    Failed = failed_scenarios(Report),
    Nondeterministic = nondeterministic_failures(Report),
    Status = case (Failed =:= 0) andalso (Nondeterministic =:= 0) of
        true ->
            <<"OK"/utf8>>;

        false ->
            <<"FAIL"/utf8>>
    end,
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"# Transport Expansion Fixture Report\n\n"/utf8,
                                                                                        "snapshot_version: "/utf8>>/binary,
                                                                                    (erlang:integer_to_binary(
                                                                                        1
                                                                                    ))/binary>>/binary,
                                                                                "\n"/utf8>>/binary,
                                                                            "negotiation_contract_version: "/utf8>>/binary,
                                                                        (negotiation_contract_version_label(
                                                                            
                                                                        ))/binary>>/binary,
                                                                    "\n"/utf8>>/binary,
                                                                "status: "/utf8>>/binary,
                                                            Status/binary>>/binary,
                                                        "\n"/utf8>>/binary,
                                                    "failed_scenarios: "/utf8>>/binary,
                                                (erlang:integer_to_binary(
                                                    Failed
                                                ))/binary>>/binary,
                                            "\n"/utf8>>/binary,
                                        "nondeterministic_failures: "/utf8>>/binary,
                                    (erlang:integer_to_binary(Nondeterministic))/binary>>/binary,
                                "\n\n"/utf8>>/binary,
                            "snapshot_signature: "/utf8>>/binary,
                        (snapshot_signature())/binary>>/binary,
                    "\n\n"/utf8>>/binary,
                "report_signature: "/utf8>>/binary,
            (report_signature(Report))/binary>>/binary,
        "\n"/utf8>>.