Expand description
Ordered policy execution for one lifecycle point. What: Run shipped policies in registry order for one lifecycle point and settle the outcome: which events were produced and whether the command may proceed. Why: Every lifecycle shares one execution contract: a policy runs only for the triggers it declares, at the configured severity, unless it is filtered out, escaped or off; the first error finding stops the pass unless the caller asked to keep going; and a policy or lifecycle this executable cannot evaluate is reported as unavailable, never as clean.
In TS you’d write (pseudocode):
// const stage = await runPolicyStage({ policies, context, trigger, severities, selectedPolicyIds, escapedPolicyIds, keepGoing });Structs§
- Policy
Finding - What:
One thing a policy reports.
A
structis a record with named fields;Stringis owned UTF-8 text;Option<T>is “a value or nothing”;&'static stris text baked into the program. Why: A policy describes what it found; the engine adds the trigger, the policy name and the configured severity when it turns the finding into an event. - Stage
Request - What:
The settings of one stage.
A
structthat owns its values:PolicyConfig,ControlsandVec<PolicyId>are copies made once per invocation. Why: Owning small copies keeps the record free of borrowing rules, so it can be handed to every stage of an invocation as one plain value. - Stage
Result - What:
The events of one stage and how it ended.
Vec<PolicyEvent>is an owned list. Why: Events gathered before a stop are still reported.
Enums§
- Policy
Outcome - What:
What one policy check returned.
An
enumis a closed set of named alternatives;Failed { code, message }carries named fields. Why: “Nothing found”, “cannot be evaluated here” and “could not finish” are three different answers; folding the last two into an empty finding list would let an unchecked command through. A policy that could not finish names its cause:content-unavailablewhen candidate bytes or a repository fact could not be read,policy-incompletewhen its own machinery failed. - Stage
End - What:
How a stage ended.
Why:
The caller continues only after
Completed; each other ending has its own exit code. - Unavailable
- What: Why a pass could not be evaluated by this executable. Why: The refusal names either a whole lifecycle or one policy and what it needs.
Constants§
- BLOCKED_
EXIT_ CODE - What:
Exit code when a pass ends with an error finding or a fixed-transform rejection.
i32is a signed 32-bit integer, the type of process exit codes. Why: Callers branch on 1 for “policy said no” and on 2 for “could not decide”.
Traits§
- Policy
Checks - What:
The policies behind the stage.
A
traitis a named set of methods a type promises to provide, like a TSinterface;&mut selflends the provider for writing, because a check may cache repository facts. Why: The stage owns order, severity and stopping; this seam owns what each policy reads. Tests drive the stage with a scripted provider, the executable with real Git.
Functions§
- any_
policy_ applies - What:
Whether any of
policieswould be evaluated for this request. Why: A lifecycle that only exists for its policies (manual push) is not applicable when none is enabled, and the caller must know that before asking the stage. - pass_
exit_ code - What:
The exit code of a pass that did not reach Git,
from its events and its ending.
&[PolicyEvent]borrows the events of every stage of the pass. Why: 0 means clean or warnings only, 1 means an error finding, a fixed-transform rejection or a pending correction, and 2 means the pass could not decide. - run_
policy_ stage - What:
Run
policiesin the given order.&mut dyn PolicyCheckslends “any provider of checks” for writing (dynmeans the concrete type is chosen at run time, like a TS interface value). Why: One policy at a time, in registry order, so findings and their numbers are reproducible. A trigger whose lifecycle is not ported ends the stage before any policy runs.