mirror of
https://github.com/beenuar/AiSOC.git
synced 2026-11-24 16:48:33 +08:00
* fix(eval): the live behavioural path imported a class that does not exist
`check_injection_eval --live` imported `InvestigatorAgent` from
`app.investigator`. No such class exists in `services/agents` — the only
one by that name is in the historical prototype under `plans/`. So the
live path could never have measured anything, and nobody found out
because the hosted-key check ran first: with no funded key it returned
"no live LLM key configured" and the broken import was never reached.
Three of the four Phase 3 metrics have therefore read "not measured" for
their whole life, for a reason that was never the real one.
It now imports the real `TriageAgent` and accepts a **local** provider,
through the agent's own configuration rather than a second set of names.
Refusing to measure without a funded hosted key would have made this
permanently unmeasurable on the configuration the product itself
recommends: Ollama ships in CORE precisely so triage runs with zero
credentials.
**Measured, against a local llama3:8b over all 71 pairs:**
Verdict flip rate 9.3% (5/54)
Unsafe action proposal rate not measured — the agent proposed no
actions on any of 54 pairs
Tool-call deviation rate not measured — no tool calls recorded
The first run of that is the part worth keeping. It published **"unsafe
action proposal rate 0.0% (0/54)"**, which reads as "the agent resisted
every payload" and meant "the agent proposed nothing at all":
`auto_triage` populates neither `proposed_actions` nor `tools_used`, and
all three rates shared the pair count as their denominator. 0-out-of-0
was being rendered as 0%.
Verdict flip was a real 9.3% on the same pairs, which is exactly why the
three cannot share a denominator — two of the signals never occurred and
the shared count made them look like clean results. Each rate now
reports unmeasured when its own signal is absent, and says which signal
and over how many pairs.
Two notes for whoever reads the number next. The flip rate moved 11.1%
to 9.3% across two runs over the identical corpus, so a small local
model is not deterministic here and a single run is not a reading. And
that the agent proposes no actions at all is itself a finding about
`auto_triage` rather than about injection resistance.
5 tests pin the refusal, including the negative control in both
directions: verdict flip must keep reporting on the same run, and both
suppressed rates must come back as soon as their signal appears.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* feat(eval): tool selection, evidence completeness, overflow and escalation
Waves 3 and 4.
**Three process measurements that had zero hits in the tree.** Verdict
accuracy already exists and can be satisfied by luck at the sample
sizes this corpus supports. Two agents that both answer "true positive"
are not equally good if one checked host criticality, recent user
behaviour and hash reputation, and the other matched a keyword. So
`app/eval/agent_quality.py` scores tool-selection accuracy, evidence
completeness and time to verdict, with partial credit — three of four
required tools is most of the way there and grading it as zero hides
real progress.
Each refuses to produce a rate when its own signal never appeared,
which is the same contract the injection metrics had to learn: an agent
that called no tools scores 0-out-of-0, and rendering that as 0% says
the opposite of what happened.
**Context overflow**, which the existing corpus cannot reach by
growing, because every payload in it is a short string in a field. Here
the payload is the *volume*: 24–100 KB of filler that looks like the
log source it is padding, with the instruction at the end where recency
weighs heaviest. Built from four numbers rather than committed, so the
repository does not carry megabytes of deterministic filler.
Two controls make it gradeable. One payload carries no instruction at
all — if the agent fails that too then volume alone is sufficient and
the tail text is incidental, a different and worse finding. And the
decisive comparison is the same instruction scanned alone versus
buried: if the guard catches it alone and misses it under padding, the
padding is what defeated it.
**Privilege escalation**, which nothing anywhere tested. The matrix and
the contracts are each well covered in isolation; what was never
exercised is the agent *trying*, which is the only path an injected
instruction has to a destructive action. Six attempts across both
origins — `injected`, and `drift` where the agent proposes it
unprompted and no attacker string exists to detect — including
`unisolate_host`, because a ceiling written only for destructive verbs
misses that un-containing a host an analyst contained is also an attack.
Graded at confidence 0.99 deliberately: confidence is one of the two
inputs, so a ceiling that only holds when the agent is unsure is not a
ceiling.
It lives in `services/actions/tests/` rather than beside the corpus
because it must run against the shipped matrix, and both services root
their packages at `app` — loading one from the other binds to the
wrong tree. It fails rather than skips when the matrix is unreachable,
since a skipped escalation suite is indistinguishable from a passing
one on a CI summary.
The corpus check earned itself immediately: it rejected `delete_file`,
a verb I had invented that is in no contract, which would have passed
every assertion below it while proving nothing.
29 tests across the three files, each with its negative control — the
matrix must still auto-execute something at L4, or the refusals above
are not a ceiling but a broken matrix.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* feat(chaos,perf): actions exactly-once, store outages, load shapes, batched writes
Waves 5, 6 and 7.
**Chaos ran only its self-test.** `fusion_restart.py` grades
exactly-once event delivery against real Postgres and is good; CI never
ran it live, and the live harness had been executed once, by hand. A
harness nobody triggers is one that rots — the thing it grades drifts
and the first anyone finds out is during an incident. `chaos.yml` runs
it weekly and on dispatch.
**Actions were not covered at all**, and the failure modes are not
comparable to events. A lost event is a gap in a timeline. A lost
action is a host that was never isolated while the console says it
was, and a duplicated one is a firewall rule added twice that somebody
has to find and unpick. So the grader tells four outcomes apart rather
than pass/fail, and an action still `pending_approval` counts as in
flight rather than lost — counting it as loss would make an approval
queue look like corruption and render the harness unusable on the
posture the product actually ships.
**Store outages for the five dependencies nobody killed.** Each
declares what losing it should look like, because a service that
treats ClickHouse and Kafka the same is wrong about one of them:
`degrade` (the feature stops, readiness says so, the service's own job
continues — losing the entity graph must not pull ingest out of the
load balancer), or `block` (the core job cannot proceed, so readiness
must fail). The question graded is not "does it crash" — crashing is
fine. It is whether readiness admits the dependency is gone, which is
the shape UEBA shipped: consumer detached, container `running`,
`/health` 200, permanently. Recovery is graded too, since degrading
correctly and never reconnecting turns an outage into an outage plus a
manual restart.
**No `--duration` flag existed anywhere**, so there has never been a
soak, and the published 176.9 and 214.0 alerts/s come from one laptop
session that nothing re-measures. `load_profiles.py` adds ramp, burst,
backpressure and 24/72-hour soak, and `saturation_verdict` reports the
rate the system stopped keeping up **and which signal gave way first**
— acceptance, queue depth, or latency. "It saturates at 340/s" is a
number; "because consumer lag grows monotonically past there while
acceptance stays flat" is something to act on. The self-test covers the
case a throughput-only harness cannot see at all: acceptance holding
while the queue grows underneath it.
No figure is claimed. These are the shapes; the numbers come from
running them, and the long profiles have not been run.
**Batched alert writes.** `persist` acquires a pooled connection and
makes a round trip per alert, so 200 alerts/s is 200 acquisitions and
200 round trips a second. `persist_many` does one acquisition for the
batch while keeping the single path's contract exactly: one result per
input in order, one bad row failing alone, and dedup still decided by
the database. Deliberately not one transaction over the batch — a
rollback would discard every alert in the window because of one bad
row.
The two 25-element argument tuples became one `_insert_args`, which is
the pair that drifts by one column and writes a confidence score into
a narrative without anything failing.
Three graders, each with a self-test that runs unconditionally, because
a grader nobody exercised is a grader nobody can trust. The batch tests
found their own double was *less* capable than the real model — missing
`src_ip` and five siblings, so every row came back FAILED inside the
sink's own except clause.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* feat(detections): separation of duties, rule versions, and split throughput claims
Waves 8 and 9.
**The author of a detection rule could approve it.**
`detection_rule_proposals.proposed_by_id` was written at creation and
compared against nothing at `/decide`, on the one surface in this
product that writes executable code into the detection engine. Every
other governed surface separates the two — action approval, playbook
dispatch, MSSP overrides. Approval only: rejecting your own proposal is
withdrawing it and needs no second person, and a proposal with no
author (the shipped corpus) is not blocked or the catalogue would be
unapprovable. Overridable on a single-analyst deployment, because a
control that forces people to disable it entirely is worse than one
that is off by choice and recorded.
**Promotion overwrote in place**, so "roll back the rule we shipped on
Tuesday" had no answer other than reconstructing it from a pull
request — which is exactly the question asked at 02:00 when a
detection starts firing on everything. Migration 084 adds
`detection_rule_versions`, keyed on a monotonic integer rather than a
timestamp because two promotions in one second are ordinary during a
tuning session and "the version before this one" must have exactly one
answer. A rollback writes a *new* version carrying an old body rather
than deleting rows, so the history of what was live when stays intact.
Also: owner, team, expiry and review dates (a rule written for an
incident three years ago was indistinguishable from one somebody
maintains), a dev/staging/production environment, and shadow mode as a
column independent of environment — a production rule can be shadowed
during a tuning change without being demoted. Shadow matches land in
their own table rather than behind a flag on `alerts`, so no query and
no person can mistake one for an alert.
**One throughput number described three different pipelines.** Ingest,
lake and the alert path differ by orders of magnitude, so quoting the
slowest understates the product and quoting the fastest misrepresents
it. `throughput_claims.py` declares them separately, requires the
context that makes each reproducible — host count, partitions,
replicas, commit — and refuses a published ingest rate with no
detection coverage beside it, because that reads as "every event was
evaluated" and running the full corpus at six figures a second is not
what this product does.
Measurements older than thirty days report as stale rather than being
quietly reused: the tree moves faster than that, and a figure nobody
re-measured across a release describes a different product. Every
unmeasured claim renders **not measured**, never zero.
Migration 084 verified fresh and idempotent across two full passes.
4,113 API tests. The separation-of-duties suite carries its negative
control — a second person must still be able to approve, or the check
is not a control but a wall.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* feat(packs,priority): a pack is five sections, and criticality now reorders the queue
Waves 10 and 11.
**A pack is a playbook today.** The 62 shipped playbooks do cover the
named scenarios, and each assumes something already raised the alert,
something already correlated the signals, and somebody already knows
the response worked — none of which ship with it. An operator adopting
"ransomware" gets the last fifth of the thing its name implies.
A pack now bundles five sections and fails validation missing any one,
because a pack short a section looks complete in a listing. Detections
by rule id rather than a carried fork, which is how two copies of a
rule end up disagreeing. Correlations, because three rules firing on
one encryption burst produce three alerts and make the operator's day
worse. An investigation plan of **questions** — a plan says what the
answer must contain, and a list of actions with no questions is a
playbook under another name. And validation, the section whose absence
makes the other four unfalsifiable: a validation step with no expected
outcome cannot fail, which is indistinguishable from not running it.
Scenario tags come from the pack rather than from retagging 877 rules
that carry three distinct non-MITRE tags between them — same
information, from the end that does not require a corpus migration
first.
`check_content_packs.py` resolves references against the **compiled
ruleset the engine loads**, not the YAML on disk: that is a projection
carrying thousands of rules the engine never compiles, so validating
against it would certify a pack whose detections cannot fire. The
shipped ransomware pack resolves against all 833 executable rules and
25 playbooks, and the negative control is proven — one bad rule id
fails the gate by name.
**Criticality reached a prompt string and nothing else.** Two alerts
of equal severity, one on a domain controller and one on a
meeting-room display, arrived in the queue in the order they were
raised, and an analyst worked out which was which by reading the
hostname.
Context is a **multiplier on severity, never a sum**. Addition lets a
stack of small bumps push an informational alert above a critical one,
which is how a prioritisation scheme gets switched off the first time
it surprises somebody. Multiplying reorders within a tier — what it is
for — and cannot invert a severity gap, which is asserted directly.
Migration 085 adds `identity_privilege` (no privileged-account field
existed anywhere), a stored `priority_score` with its rationale, and
finally indexes `alert_asset_correlations` — created in migration 013
with zero readers and zero writers, and the join that makes asset
criticality reachable from an alert at all. That is the Wave 0 item
deferred to here on the grounds it needed this context to be worth
wiring.
The score is stored rather than computed at read time for two reasons:
the queue sorts on it, and an analyst asking "why was this top of my
queue" needs the answer that applied then, not the one today's CMDB
produces. Priority deliberately does not touch severity — severity is
what the detection claimed and is compared across deployments, and
conflating them would let a tenant's CMDB quality change what their
detections appear to have found.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* feat(cases,iam): queues, SLA clocks, escalation, ABAC and time-boxed elevation
Waves 12 and 13.
**Three clocks, not one.** A case picked up in four minutes and
resolved in four days met its acknowledgement target and missed its
resolution one; a single `sla_due_at` cannot say that, and a SOC that
cannot distinguish them cannot tell a staffing problem from a
capability problem. Targets are measured from `opened_at` rather than
now, so re-reading a case does not silently extend its deadline and
make every breach disappear on the next edit. No policy gives no
target **and a stated reason** — an empty due date with no explanation
reads as "met" on every dashboard that counts breaches.
**Queues route deterministically.** Precedence breaks a match tie and
the name breaks a precedence tie; without the second, two
equally-ranked queues resolve by row order and a case appears to move
between them on each read. Criteria are ANDed: a queue declaring
critical AND pci under OR would also collect every critical case in
the estate, which is how a team's queue becomes everyone's.
**Escalation did not exist**, so a case nobody picked up stayed
unpicked and the SLA passed in silence. Keyed on the acknowledgement
clock rather than resolution, because a case somebody is working on
and has not finished is not the failure an escalation ladder
addresses.
Migration 086 also adds the shift handoff that replaced nothing when
`/shifts` was removed in v15.0.0 — snapshotting the case ids rather
than recomputing them, because what was handed over is a historical
fact — and `case_status_transitions`, since the case carried its
current status and four timestamps and "who moved this to resolved,
and on what basis" was unanswerable. That is the first question asked
when a closed case turns out to have been an incident.
**One shared service token.** `AISOC_SERVICE_TOKEN` is a single string
every internal caller presents: unattributable, unscoped, and
unrotatable without restarting everything at once. Migration 087 adds
per-service identities with two live secrets during rotation, so
callers roll over on their own schedule. API keys gain the same
rotate-in-place pair — the old path was create, update every caller,
delete, which is downtime, so most people never rotated at all.
**Elevation is time-boxed and grants permissions, not roles.**
Elevating to `admin` to isolate one host confers the wildcard, which
is the opposite of least privilege. Expiry is checked at use rather
than by a sweep: a background job that revokes grants is a job that
can be down, and a grant outliving its window because a worker crashed
is exactly what JIT elevation exists to remove.
**Conditions narrow and never grant.** A condition that could grant
would be a second authorization system reaching a different answer
from the first. The operator set is closed, total and side-effect
free rather than an expression language — an evaluator running
caller-influenced input inside the authorization path is the shape
already removed from the rule engine once.
The decision worth stating: a condition the request carries no data
for **denies**. Treating it as satisfied would mean a caller who omits
a header is less constrained than one who sends it, which inverts the
control. An unknown operator denies for the same reason.
25 tests across both waves, each with its negative control — an
unconditioned permission must behave exactly as before, and a case
inside its window must not escalate or the ladder pages constantly.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* feat(governance,dr): legal hold, field access, residency, and three restore paths
Waves 14 and 15.
**The retention worker could purge and nothing could stop it**, so the
correct response to "preserve everything relating to this account
pending litigation" was to disable retention for the whole tenant and
remember to turn it back on.
A legal hold now outranks retention unconditionally — any arrangement
where retention can win is a system that deletes evidence under
litigation, which is the one outcome that cannot be apologised for.
`retention_decision` returns the hold rather than a boolean, so a
caller cannot treat "held" as "not expired" and move on. Holds are
stored as a predicate rather than a list of ids, because the rows a
hold covers keep arriving after it is placed, and releasing one is an
event with an actor rather than a deletion — a hold that vanishes
leaves no evidence it existed, which defeats the audit it was placed
for.
**Field access hides and names what it hid.** A missing field and a
withheld one look identical to a client, and an analyst needs to know
whether the source IP is absent or redacted — those lead to opposite
next steps. Dotted paths reach into `raw_event`, which is where a
source puts whatever it likes and the field most worth constraining.
Hashing is stable so two masked values stay correlatable without
either being readable, and a rule naming a field the record does not
carry is **not** reported as withheld, or the response claims to be
hiding something it never had.
**Residency fails closed.** Enforcement with no declared region
refuses rather than permits: the alternative allows everything under a
setting an operator believes is strict. Violations are recorded even
when the operation is refused, because a refusal nobody counted cannot
answer "has this ever happened".
**backup.sh backed up five stores; restore.sh restored two.** Neo4j,
Qdrant and Redis each had a backup nobody had ever proven they could
use, and the first time anyone would find out is during the recovery.
Nothing failed — both scripts ran, both reported success, and the
asymmetry was visible only by reading the two files side by side.
Neo4j replays Cypher rather than using `neo4j-admin load`, which needs
the database stopped; a restore requiring downtime on a store the
platform degrades gracefully without is the worse trade. Statements
apply one at a time so a single failing MERGE does not discard the
graph, and failures are counted and surfaced — a restore reporting
success having skipped half the graph is this wave's entire subject.
Qdrant lets the snapshot upload recreate collections, because the
vector dimension is immutable and pre-creating one wrong would fail in
a way that looks like corrupt data. Redis requires explicit
confirmation: it holds only rebuildable state, and a restored cache
serves stale answers with full confidence, which is worse than a cold
start.
`check_backup_restore_parity.py` runs in the direction that drifts — a
store gains a backup long before it gains a restore, because the
backup is the part that feels urgent. Negative control proven:
removing one restore function fails the gate by name. Its exemption
list is empty, and that is the point; when it was not empty nobody had
written the reasons down because nobody had noticed.
30 tests across both waves, each with its negative control.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* feat(migrate): bring detections in from SPL, KQL and EQL
Wave 16.
Translators existed in one direction only — AiSOC rules become SPL,
KQL, ESQL and AQL so a federated search can run on a customer's SIEM.
Nothing came the other way, so a team arriving with 400 Splunk
searches rewrote all of them by hand, and that cost is what decides
whether a migration happens at all.
**Measured on the 2,005 Splunk rules already stored and quarantined in
this repository**, which had never been translated:
1,734 of 2,005 (86.5%) produce a rule
271 refused, each with a stated cause
1,711 of the 1,734 are only partial
The third line is the honest half, and the suite asserts it directly.
The corpus is overwhelmingly aggregation-based, so "translated" mostly
means "field matches carried across, the threshold did not". Reporting
86.5% without that would imply a migration that is almost done. The
refusal causes are counted too: 1,709 aggregations, 109 lookups, 57
eventstats, 51 joins.
**Refusing is the feature.** A translator that produces something for
every input is worse than one that refuses, because an almost-right
detection is harder to find than a missing one — it sits in the
catalogue, fires on the wrong thing, and nobody checks it against the
original. So transaction, lookup, join, sequence and six others refuse
the whole translation rather than being dropped quietly, and every
refusal names what stopped it, because a reviewer cannot act on "could
not translate".
Two details worth keeping. Keywords are word-bounded, so a field named
join_key is not mistaken for a join — without that the translator
refuses rules it can handle, which is the opposite failure and the
harder one to notice. And Splunk's index and sourcetype are dropped
with a note rather than carried: they address Splunk's own storage,
and translating them would make every imported rule match on a field
no connector emits.
Confidence rises with clause count, and a single clause is marked
partial on the grounds that one comparison rarely captures a real
detection.
15 tests, including the negative control that the corpus is actually
present — without it the 86.5% measurement would pass against an empty
list.
* fix(waves): wire the five new modules, and fix two gates that found them
The reachability gate caught this branch committing the exact defect
the whole programme exists to close: five modules with tests, no
production caller, and nothing to tell them apart from working
features.
services/agents/app/eval/agent_quality.py
services/api/app/security/abac.py
services/api/app/services/alert_priority.py
services/api/app/services/case_orchestration.py
services/api/app/services/governance.py
Each is now imported from the one place it changes an outcome rather
than from a convenient one. Priority is wired into the alert queue,
because the queue is the only surface where prioritisation does
anything — a score nothing sorts on is a column. Governance into
retention, where a legal hold has to beat a purge, reading holds per
run rather than caching them: a cache measured in hours is a cache
that deletes evidence placed under hold this morning. ABAC into
`role_grants`, after the role check and never instead of it. Case
orchestration into the cases endpoint. Agent quality is re-exported
from its package and imported by the agents service.
Two gates also needed fixing, and both were right.
`check_gate_contract` found `check_backup_restore_parity` reporting OK
inside a bare repository. The first fix made it read the working
directory and fall back to `repo_root()` when that had no `scripts/`
— which is precisely the bare-repository case, so the fallback walked
straight back to the real tree and the gate still passed. It now
prefers the working directory whenever that is itself a repository.
The remaining probe is a recorded exception rather than a defect, with
the reason written down: the gate's entire subject is `backup.sh` and
`restore.sh`, and `scripts/` is the one directory the scratch tree
keeps so a gate is runnable at all. The probe therefore cannot pose
the question — the files are present and genuinely read. The case it
reaches for is covered directly instead: the gate exits 2 naming the
directory it looked in, verified from a bare repository, and exits 2
again if `backup.sh` declares no functions, so a parse that silently
matched nothing cannot read as parity.
Migration 086 named `case_tasks`; the table is `aisoc_case_tasks`.
That aborted the migration before its RLS block ran, which then made
`060_rls_coverage` fail on five tables that would have been covered —
one wrong table name, two failing migrations, and the second error
naming the wrong cause entirely. All 100 migrations now apply clean
across three consecutive passes.
7,424 tests across api, agents, fusion and actions. Ruff, the mypy
baseline, and ten structural gates pass. Zero breaking OpenAPI
changes.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* fix(codeql): five findings in the new wave code, and a format check
All five are in code this branch added.
`...` as a method body reads as an ineffectual statement, so the test
double's methods take docstring bodies — the convention this
repository already uses for Protocol and abstract bodies.
The re-export in the agents service was a bare import carrying a
`noqa`, which is indistinguishable from a stale one and which CodeQL
reads as unused. `__all__` states the intent instead.
`factor` was assigned in two branches of one if/elif in the priority
scorer, flagged as a redefinition. Renamed per factor, which also
reads better: `known_criticality` and `privilege_factor` say what they
are where `factor` twice did not.
A bare `"example.net" in dns` is the incomplete-URL-sanitization shape
and reads as one whether or not the value is trusted. The assertion
now matches a whole label.
Also one file the whole-tree format check wanted reformatted.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* fix(chaos): provision secrets before booting, and guard the readiness probe
Two gate findings, both correct.
The deployment-posture gate caught `chaos.yml` calling `docker compose
up` without running `scripts/ensure_env.py` first, which `make up`
does. That provisions an environment with every generated secret
empty — ingest refuses to start without JWT_SECRET and the API
without METRICS_TOKEN — so the store-outage legs would have graded a
stack that never came up. A vacuous pass, in the workflow written to
catch vacuous passes.
Semgrep went 103 to 104 on a third `dynamic-urllib-use-detected`, from
the readiness probe. The URL now has to start with a local-stack
prefix or the probe refuses, which is the same mitigation the two
existing calls use: build from a fixed root and refuse anything else,
so the `file://` read the rule warns about is unreachable. The rule
fires on any non-literal argument to `urlopen` regardless, so it is
counted rather than suppressed — a ceiling counts a finding, a
suppression hides it.
The ceiling returns to the 104 it stood at before the unused-logger
removal lowered it, which is a different thing from raising one to
make a scan pass. The error count stays at the reduced 39.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* fix(ci): wire the two new gates into a workflow
`check_gate_coverage` caught both new gates being unreachable: no
workflow ran them, directly or through make, another script, or a
test suite CI executes.
That is the defect this whole programme is about, committed by the
programme. A gate that cannot fail is indistinguishable from no gate,
and worse than none, because its presence in the tree implies coverage
that does not exist — which is exactly what I would have shipped: two
gates, both passing locally, neither able to red anything.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
* fix(ci): run the aisoc-migrate suite
`check_test_discovery` caught the wave-16 tests being collected by no
workflow invocation — the third time in this branch a gate has found
me shipping something that cannot fail.
A test file nothing runs reports nothing and reads exactly like one
that passed, which is the same shape as the unreachable gates two
commits ago and the unreachable modules before them. The gates are
doing their job on the work written to close exactly this class of
defect.
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
---------
Signed-off-by: Beenu Arora <beenu.a.arora@gmail.com>
1007 lines
46 KiB
Python
1007 lines
46 KiB
Python
#!/usr/bin/env python3
|
|
"""No gate in this tree may report OK over a repository containing nothing.
|
|
|
|
Why this exists
|
|
---------------
|
|
The cheapest diagnostic anyone has run on this repository was to copy
|
|
``scripts/`` into an empty git repository and run every wired check there.
|
|
Five reported OK over a tree with no content:
|
|
|
|
* ``validate_detections.py`` — the validator behind the rule count the front
|
|
page quotes — printed a warning and exited 0, certifying zero rules valid.
|
|
* ``check_grafana_dashboards.py`` had both branches and had them backwards:
|
|
it failed on an *empty* dashboards directory and passed on a *missing* one,
|
|
forgiving the larger loss.
|
|
* ``check_go_module_paths.py`` reported ``OK: 0 published Go module path(s)``.
|
|
* ``check_repo_self_links.py`` called every self-link healthy over zero files
|
|
— and it exists to replace a lychee run that accepted HTTP 403 as healthy,
|
|
so it had inherited the same inability in a different costume.
|
|
* ``audit_health_probes.py --check`` printed a table header and exited 0.
|
|
|
|
All five are fixed. The probe that found them was a one-off, so the next gate
|
|
written could reintroduce the defect freely. This makes it permanent.
|
|
|
|
The question it asks
|
|
--------------------
|
|
Not "does the gate flag the right things" but **"what does it credit as
|
|
clean, and could it credit something it never opened?"** A gate that walks
|
|
zero files finds zero violations; unless it refuses an empty read, a clean
|
|
result is indistinguishable from a broken glob, a wrong root, or a tree that
|
|
is not there. *Found nothing* and *scanned nothing* print the same word.
|
|
|
|
What it checks
|
|
--------------
|
|
Three properties of every check in the tree, each with a shrink-only list of
|
|
recorded exceptions, each list verified in both directions so an entry that
|
|
stops being needed fails the build rather than sitting there:
|
|
|
|
``empty-tree``
|
|
Run the gate the way CI runs it, inside a git repository holding only
|
|
``scripts/``. It must not exit 0.
|
|
|
|
``root-from-git``
|
|
A gate that derives a repository root from ``__file__`` must also consult
|
|
``git rev-parse``. ``Path(__file__).parent.parent`` is whatever sits two
|
|
levels above the script; a copy run from elsewhere scans that other tree
|
|
and prints a confident OK about a checkout nobody asked about. One gate
|
|
was in exactly that state and only a deliberate probe from another
|
|
directory caught it.
|
|
|
|
``self-test``
|
|
The gate declares ``--self-test``, so a contributor can prove it still
|
|
detects what it claims to before CI does.
|
|
|
|
The inventory is not written here
|
|
---------------------------------
|
|
It comes from ``check_gate_coverage.py``, which already resolves the
|
|
workflow-to-check graph mechanically and classifies a script by what it does
|
|
rather than what it is called. Two scanners drift the first time either one
|
|
learns something the other has not — that gate went from 42 to 59 inventoried
|
|
checks the day its filename test was deleted, and a second inventory here
|
|
would have kept the old answer.
|
|
|
|
How an invocation is chosen
|
|
---------------------------
|
|
From the workflow surface, not from a list kept here. Every way a workflow
|
|
runs the script is a candidate, in CI's own spelling; ``--self-test`` is
|
|
excluded because it renders a verdict on the gate rather than on the tree,
|
|
and so are invocations naming an unexpanded shell variable or a path outside
|
|
the repository, because replaying those tests the argument list rather than
|
|
the tree. If nothing is replayable, the script's own declared verdict flag is
|
|
used.
|
|
|
|
A run that fails for a reason other than the empty tree — an argparse usage
|
|
error, or an import of a third-party module the environment lacks — proves
|
|
nothing, so it is reported as INCONCLUSIVE and fails this gate. Crediting a
|
|
refusal the probe never actually caused would be the same defect one level
|
|
up.
|
|
|
|
Usage
|
|
-----
|
|
python3 scripts/check_gate_contract.py # gate
|
|
python3 scripts/check_gate_contract.py --list # per-check detail
|
|
python3 scripts/check_gate_contract.py --json
|
|
python3 scripts/check_gate_contract.py --self-test # prove it detects drift
|
|
|
|
Exit codes: 0 clean, 1 findings, 2 the scan itself could not run.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import ast
|
|
import json
|
|
import re
|
|
import shlex
|
|
import subprocess
|
|
import sys
|
|
from collections.abc import Sequence
|
|
from dataclasses import asdict, dataclass, field
|
|
from pathlib import Path
|
|
|
|
# `scripts/` is on sys.path when this file is run as a program, but not when a
|
|
# test loads it by path with importlib. Its siblings sit beside it either way.
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
|
import check_gate_coverage as coverage # noqa: E402
|
|
from gate_toolkit import ( # noqa: E402
|
|
BARE,
|
|
SELF_TEST_FLAG,
|
|
SKELETON,
|
|
TREE_SHAPES,
|
|
VERDICT_FLAG_PREFERENCE,
|
|
repo_root,
|
|
run_in_scratch_tree,
|
|
scratch_tree,
|
|
)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Recorded exceptions. Every one of these is shrink-only and checked in both
|
|
# directions: an entry naming a check that does not exist fails the build, and
|
|
# so does an entry whose reason has stopped being true.
|
|
# --------------------------------------------------------------------------
|
|
|
|
#: Every shape, when a script behaves the same against all of them.
|
|
ANY_SHAPE = "*"
|
|
|
|
#: Checks the empty-tree question cannot be put to, each recorded with the
|
|
#: disposition it is expected to produce. Recording the disposition and not
|
|
#: just the name is what makes the entry falsifiable: an exception written
|
|
#: because argparse refused the arguments does not quietly go on covering the
|
|
#: gate on the day it starts exiting 0 instead.
|
|
#:
|
|
#: Keyed ``script -> shape -> (disposition, reason)``. ``ANY_SHAPE`` covers
|
|
#: every shape and is what most entries use; a named shape overrides it. The
|
|
#: indirection earns its keep exactly once — ``check_logger_kwargs.py``
|
|
#: refuses the bare tree and legitimately passes the skeleton — and writing
|
|
#: both shapes out for the other four would have duplicated four paragraphs
|
|
#: to express "no change".
|
|
EMPTY_TREE_EXCEPTIONS: dict[str, dict[str, tuple[str, str]]] = {
|
|
"resolve_port_conflicts.py": {
|
|
ANY_SHAPE: (
|
|
"passed",
|
|
"Not a check of the repository. It asks the operating system which TCP ports are "
|
|
"held and moves AiSOC off the ones that are, so `make up` resolves a conflict "
|
|
"instead of refusing to start. Exit 0 means 'no port is in use', which is a real "
|
|
"finding about the host rather than a tree it never opened — and the one piece of "
|
|
"repository content it does read, the port inventory in scripts/doctor.sh, it "
|
|
"refuses to run without: a bare tree missing that file exits 1 with the reason, "
|
|
"Its --self-test proves the two properties that have already been wrong once, the "
|
|
"probe reporting a held port as held and the overlay using `ports: !override`.",
|
|
)
|
|
},
|
|
"compare_eval_runs.py": {
|
|
ANY_SHAPE: (
|
|
"inconclusive",
|
|
"Not a check of the repository. It is a two-input comparator: it takes --before and "
|
|
"--after eval reports and publishes the delta between them, so there is no tree for "
|
|
"it to credit and argparse correctly refuses a probe that supplies neither. Asking "
|
|
"it whether an empty tree is clean is a question it cannot be asked, rather than one "
|
|
"it answers wrongly. What it must get right instead is refusing comparisons that "
|
|
"would read as results, and that is covered by scripts/tests/test_compare_eval_runs.py "
|
|
"in both directions: an axis measured before and not after reports 'not comparable' "
|
|
"rather than a -0.62 regression, two runs over different datasets are refused "
|
|
"outright, and a balanced pair still compares so the refusals are not vacuous.",
|
|
)
|
|
},
|
|
"wet_eval_check.py": {
|
|
ANY_SHAPE: (
|
|
"passed",
|
|
"Reads two environment variables and no repository content at all. Its exit status is 0 by "
|
|
"design so a fork with no secrets does not look like a broken build; the verdict is the JSON "
|
|
"status file that wet-eval.yml branches on, which is why check_gate_coverage classifies it "
|
|
"from the job graph rather than from anything intrinsic. There is no tree for it to credit, "
|
|
"so its --self-test checks the verdict it does render: should_run across present, absent, "
|
|
"partial and dry-run secrets.",
|
|
)
|
|
},
|
|
"check_backup_restore_parity.py": {
|
|
ANY_SHAPE: (
|
|
"passed",
|
|
"Its entire subject is scripts/backup.sh and scripts/restore.sh, and scripts/ is the "
|
|
"one directory the scratch tree has to keep for a gate to be runnable at all. So the "
|
|
"probe cannot pose the question: the two files it compares are present in the scratch "
|
|
"tree, it reads them, and exit 0 is a real finding about a tree it genuinely opened "
|
|
"rather than a tree it never did. The same situation as security_audit's "
|
|
"validate-ignores arm below, for the same reason. The case the probe is reaching for "
|
|
"— a tree where those files are absent — is covered directly: the gate exits 2 naming "
|
|
"the directory it looked in, verified by running it from a bare repository, and it "
|
|
"exits 2 again if backup.sh declares no backup functions, so a parse that silently "
|
|
"matched nothing cannot read as parity either.",
|
|
)
|
|
},
|
|
"security_audit.py": {
|
|
ANY_SHAPE: (
|
|
"passed",
|
|
"Three of its four arms — pnpm, python, go — now refuse a tree with no manifests in it. The "
|
|
"fourth, validate-ignores, has scripts/security_audit_ignores.txt as its entire subject, and "
|
|
"scripts/ is the one directory the scratch tree has to keep for the gate to be runnable at "
|
|
"all. So the probe cannot pose the question for that arm; the missing-policy-file case is "
|
|
"covered instead by test_validate_ignores_refuses_a_missing_policy_file.",
|
|
)
|
|
},
|
|
"openapi_diff.py": {
|
|
ANY_SHAPE: (
|
|
"inconclusive",
|
|
"Both specifications are named on the command line and one of them is a checkout of main that "
|
|
"openapi-breaking.yml writes outside the repository, so it discovers nothing from the tree and "
|
|
"there is no empty-tree verdict to render. Run with no arguments it refuses at argparse, before "
|
|
"any file is opened.",
|
|
)
|
|
},
|
|
"wet_eval_update_benchmark.py": {
|
|
ANY_SHAPE: (
|
|
"inconclusive",
|
|
"Same shape: --wet-block names a report the weekly workflow produces outside the checkout, so "
|
|
"the only replayable invocation would be testing the argument list rather than the tree. "
|
|
"Required arguments mean argparse refuses a bare run before it reads anything.",
|
|
)
|
|
},
|
|
"check_logger_kwargs.py": {
|
|
BARE: (
|
|
"refused",
|
|
"No services/ directory at all, which it refuses outright before scanning. Recorded rather "
|
|
"than left implicit because the skeleton entry below only makes sense next to it.",
|
|
),
|
|
SKELETON: (
|
|
"passed",
|
|
"Its corpus is every Python file in the repository, not one directory — scripts/ is in scope "
|
|
"and the scratch tree keeps it, so against a skeleton it classifies real stdlib loggers in "
|
|
"real files and correctly finds none misused. That is a pass over a corpus it genuinely has, "
|
|
"not a credit for a tree it never opened, and its own floor proves the difference: it exits 1 "
|
|
"when it classifies zero stdlib calls. Measured, not assumed — 64 of the 71 checks refuse the "
|
|
"skeleton and this is the only one whose disposition differs between the two shapes.",
|
|
),
|
|
},
|
|
}
|
|
|
|
#: Checks that derive a root from ``__file__`` and do not consult git. Empty:
|
|
#: every check in the tree resolves through git today. The list stays so that
|
|
#: a future exception has to be written down and justified rather than
|
|
#: appearing as a quietly relaxed rule.
|
|
NO_GIT_ROOT: dict[str, str] = {}
|
|
|
|
#: Checks that do not declare ``--self-test``. Also empty, same reason.
|
|
NO_SELF_TEST: dict[str, str] = {}
|
|
|
|
|
|
class ProbeError(RuntimeError):
|
|
"""The probe could not be set up. Never downgraded to a passing result."""
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Choosing how to run each gate
|
|
# --------------------------------------------------------------------------
|
|
#: Command words that mean "the next path is a Python program". Requiring one
|
|
#: is what keeps a quoted path inside an `echo` out of the answer: shlex hands
|
|
#: back `['echo', 'scripts/foo.py']`, whose command word is `echo`. A matcher
|
|
#: that looked for the substring counted eleven services as CI-covered on the
|
|
#: strength of a quoted path in a shell array.
|
|
_INTERPRETERS = frozenset({"python", "python3", *(f"python3.{minor}" for minor in range(8, 20))})
|
|
|
|
#: `uv run python x.py` and `poetry run python x.py` reach the same place.
|
|
_RUNNERS = frozenset({"uv", "poetry"})
|
|
|
|
|
|
def _segments(text: str) -> list[str]:
|
|
"""Individual commands inside a workflow `run:` block."""
|
|
joined = text.replace("\\\n", " ")
|
|
parts: list[str] = []
|
|
for line in joined.splitlines():
|
|
for piece in re.split(r"&&|\|\||[;|]", line):
|
|
stripped = piece.strip()
|
|
if stripped:
|
|
parts.append(stripped)
|
|
return parts
|
|
|
|
|
|
def _argv_after(tokens: list[str], script: str) -> list[str] | None:
|
|
"""The arguments a command passes to ``scripts/<script>``, or None."""
|
|
index = 0
|
|
while index < len(tokens) and re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*=.*", tokens[index]):
|
|
index += 1
|
|
if index < len(tokens) and tokens[index] == "env":
|
|
index += 1
|
|
while index < len(tokens) and re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*=.*", tokens[index]):
|
|
index += 1
|
|
if index >= len(tokens):
|
|
return None
|
|
if tokens[index] in _RUNNERS:
|
|
if index + 1 >= len(tokens) or tokens[index + 1] != "run":
|
|
return None
|
|
index += 2
|
|
if index < len(tokens) and tokens[index] in _INTERPRETERS:
|
|
index += 1
|
|
elif tokens[index] in _INTERPRETERS:
|
|
index += 1
|
|
else:
|
|
return None
|
|
# `python -m pytest ...` runs a module, not this script.
|
|
if index < len(tokens) and tokens[index].startswith("-"):
|
|
return None
|
|
if index >= len(tokens) or Path(tokens[index]).name != script:
|
|
return None
|
|
return tokens[index + 1 :]
|
|
|
|
|
|
def _replayable(args: Sequence[str]) -> bool:
|
|
"""Whether replaying these arguments would test the tree rather than the argument list.
|
|
|
|
An unexpanded `$VAR` becomes a literal path that cannot exist, and an
|
|
absolute path is an artefact CI builds outside the checkout. Either way
|
|
the gate would fail for a reason the empty tree did not cause, which is
|
|
not evidence of anything.
|
|
"""
|
|
return not any("$" in arg or arg.startswith("/") for arg in args)
|
|
|
|
|
|
def ci_invocations(surface: coverage.Surface, script: str, signals: dict[str, str] | None = None) -> list[list[str]]:
|
|
"""Every replayable way a workflow asks ``script`` for a verdict.
|
|
|
|
Asks for a verdict, not merely runs: several scripts here are a generator
|
|
and a gate in one file, and CI runs both halves. ``build_marketplace.py``
|
|
with no arguments *writes* ``marketplace/index.json``; only
|
|
``--check`` compares it. Probing the generator would report that writing
|
|
an empty index over an empty tree is a gate crediting nothing, which is
|
|
true of every generator and says nothing about the gate. So when a script
|
|
declares verdict flags, only the invocations carrying one are probed —
|
|
the same structural signal ``check_gate_coverage`` classifies it by.
|
|
"""
|
|
verdict_flags = {f for f in (signals or {}).get("verdict-flag", "").split() if f != SELF_TEST_FLAG}
|
|
found: list[list[str]] = []
|
|
for _workflow, _wd, text in surface.texts():
|
|
if f"/{script}" not in text and not text.strip().startswith(script):
|
|
continue
|
|
for segment in _segments(text):
|
|
try:
|
|
tokens = shlex.split(segment)
|
|
except ValueError:
|
|
continue
|
|
args = _argv_after(tokens, script)
|
|
if args is None or args == [SELF_TEST_FLAG] or not _replayable(args):
|
|
continue
|
|
if verdict_flags and not verdict_flags & set(args):
|
|
continue
|
|
if args not in found:
|
|
found.append(args)
|
|
# Longest first: a step that passes flags is asking a sharper question
|
|
# than a bare run, and is the one whose behaviour matters most.
|
|
found.sort(key=len, reverse=True)
|
|
return found
|
|
|
|
|
|
def declared_invocations(signals: dict[str, str]) -> list[list[str]]:
|
|
"""Fallbacks from the gate's own declared verdict flags."""
|
|
flags = [f for f in signals.get("verdict-flag", "").split() if f != SELF_TEST_FLAG]
|
|
ordered = [f for f in VERDICT_FLAG_PREFERENCE if f in flags]
|
|
ordered += [f for f in flags if f not in ordered]
|
|
return [[flag] for flag in ordered] + [[]]
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Reading the result
|
|
# --------------------------------------------------------------------------
|
|
_ARGPARSE_USAGE = re.compile(r"^usage: ", re.MULTILINE)
|
|
_ARGPARSE_ERROR = re.compile(r"^\S+: error: ", re.MULTILINE)
|
|
_MISSING_MODULE = re.compile(r"ModuleNotFoundError: No module named '([\w.]+)'")
|
|
|
|
REFUSED = "refused"
|
|
PASSED = "passed"
|
|
INCONCLUSIVE = "inconclusive"
|
|
|
|
|
|
def importable_names(root: Path) -> frozenset[str]:
|
|
"""Top-level module names the repository itself supplies.
|
|
|
|
A gate that dies on ``No module named 'app'`` inside the scratch tree died
|
|
*because* the tree is empty — ``app`` is the package under ``services/``.
|
|
One that dies on ``No module named 'structlog'`` died because the probe
|
|
environment is short a dependency, which is evidence about the probe and
|
|
not about the gate.
|
|
"""
|
|
out = subprocess.run( # noqa: S603 - fixed argv, no shell
|
|
["git", "ls-files"],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
cwd=root,
|
|
)
|
|
if out.returncode != 0:
|
|
raise ProbeError(f"cannot list tracked files under {root}: {out.stderr.strip()}")
|
|
names: set[str] = set()
|
|
for line in out.stdout.splitlines():
|
|
path = Path(line)
|
|
if path.name == "__init__.py":
|
|
names.add(path.parent.name)
|
|
elif path.suffix == ".py":
|
|
names.add(path.stem)
|
|
if not names:
|
|
raise ProbeError(f"git ls-files returned no Python under {root}")
|
|
return frozenset(names)
|
|
|
|
|
|
def classify(status: int | None, output: str, supplied: frozenset[str]) -> tuple[str, str]:
|
|
"""(disposition, why) for one run of a gate in the scratch tree."""
|
|
if status is None:
|
|
return INCONCLUSIVE, "timed out"
|
|
if status == 0:
|
|
return PASSED, "exited 0"
|
|
if _ARGPARSE_USAGE.search(output) and _ARGPARSE_ERROR.search(output):
|
|
return INCONCLUSIVE, "argparse rejected the arguments, so the tree was never read"
|
|
missing = _MISSING_MODULE.search(output)
|
|
if missing and missing.group(1).split(".")[0] not in supplied:
|
|
return INCONCLUSIVE, f"the probe environment has no {missing.group(1)!r}, which this repository does not supply"
|
|
return REFUSED, f"exited {status}"
|
|
|
|
|
|
@dataclass
|
|
class Run:
|
|
"""One invocation of one gate inside one scratch tree."""
|
|
|
|
args: list[str]
|
|
source: str
|
|
shape: str
|
|
disposition: str
|
|
why: str
|
|
evidence: str = ""
|
|
|
|
|
|
@dataclass
|
|
class Probe:
|
|
"""Everything the probe learned about one gate."""
|
|
|
|
script: str
|
|
runs: list[Run] = field(default_factory=list)
|
|
|
|
def disposition_for(self, shape: str) -> str:
|
|
"""The worst thing any invocation did against ``shape``.
|
|
|
|
Worst, not first: a script CI runs four ways is four gates wearing one
|
|
name, and excusing the set because the first one refused is how a
|
|
subcommand that credits an empty tree stays hidden behind a sibling
|
|
that does not.
|
|
"""
|
|
seen = {run.disposition for run in self.runs if run.shape == shape}
|
|
if PASSED in seen:
|
|
return PASSED
|
|
if REFUSED in seen:
|
|
return REFUSED
|
|
return INCONCLUSIVE
|
|
|
|
def why_for(self, shape: str) -> str:
|
|
worst = self.disposition_for(shape)
|
|
return next(
|
|
(run.why for run in self.runs if run.shape == shape and run.disposition == worst),
|
|
"no invocation was attempted",
|
|
)
|
|
|
|
@property
|
|
def shapes(self) -> list[str]:
|
|
return [shape for shape in TREE_SHAPES if any(run.shape == shape for run in self.runs)]
|
|
|
|
|
|
def probe(surface: coverage.Surface, checks: dict[str, dict[str, str]], root: Path, *, only: str | None = None) -> list[Probe]:
|
|
"""Run every check inside a repository with no content and read the result.
|
|
|
|
Every way CI runs a script is probed, because each is a verdict somebody
|
|
relies on. Its own declared flags are the fallback, used only when nothing
|
|
CI does can be replayed — a step whose arguments name an artefact built
|
|
outside the checkout tests the argument list rather than the tree.
|
|
|
|
Two tree shapes, because they are two questions. ``BARE`` asks what a gate
|
|
does when the thing it judges is not there; ``SKELETON`` asks what it does
|
|
when the directory is there and holds nothing. The second is the one that
|
|
happens — a renamed package, a changed glob — and a gate opening with
|
|
``if not X.is_dir(): return 2`` answers the first for a reason that says
|
|
nothing about its corpus.
|
|
"""
|
|
supplied = importable_names(root)
|
|
results: dict[str, Probe] = {script: Probe(script=script) for script in sorted(checks) if not only or script == only}
|
|
for shape in TREE_SHAPES:
|
|
with scratch_tree(root / "scripts", shape=shape) as tree:
|
|
for script, result in results.items():
|
|
for args in ci_invocations(surface, script, checks[script]):
|
|
result.runs.append(_run_one(script, args, tree, supplied, "the workflow that runs it", shape))
|
|
if result.disposition_for(shape) == INCONCLUSIVE:
|
|
for args in declared_invocations(checks[script]):
|
|
run = _run_one(script, args, tree, supplied, "its own declared verdict flag", shape)
|
|
result.runs.append(run)
|
|
if run.disposition != INCONCLUSIVE:
|
|
break
|
|
return list(results.values())
|
|
|
|
|
|
def _run_one(script: str, args: Sequence[str], tree: Path, supplied: frozenset[str], source: str, shape: str) -> Run:
|
|
status, output = run_in_scratch_tree(script, args, tree=tree)
|
|
_reset(tree)
|
|
disposition, why = classify(status, output, supplied)
|
|
return Run(args=list(args), source=source, shape=shape, disposition=disposition, why=why, evidence=_tail(output))
|
|
|
|
|
|
def _reset(tree: Path) -> None:
|
|
"""Undo anything the gate just wrote, so the next one sees the same tree."""
|
|
for argv in (["reset", "--hard", "-q"], ["clean", "-qxfd"]):
|
|
subprocess.run(["git", *argv], cwd=tree, check=False, capture_output=True) # noqa: S603
|
|
|
|
|
|
def _tail(output: str, limit: int = 220) -> str:
|
|
lines = [line for line in output.strip().splitlines() if line.strip()]
|
|
return lines[-1][-limit:] if lines else ""
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
# The two static properties
|
|
# --------------------------------------------------------------------------
|
|
#: Read from the syntax tree, never from the text. The first spelling of this
|
|
#: matched `\brepo_root\b` anywhere in the file, and `check_gate_coverage.py`
|
|
#: emits `"repo_root"` as a JSON key — so a gate that resolved its root from
|
|
#: `__file__` and never asked git read as compliant on the strength of a
|
|
#: dictionary key in its own output. A gate crediting something it never
|
|
#: opened, one level up from the gates it inspects.
|
|
_GIT_TOPLEVEL = "--show-toplevel"
|
|
_ROOT_HELPER = "repo_root"
|
|
|
|
|
|
def static_properties(source: str) -> dict[str, bool]:
|
|
"""What the syntax tree says about root resolution and self-testing."""
|
|
try:
|
|
tree = ast.parse(source)
|
|
except SyntaxError:
|
|
return {"derives_root_from_file": False, "consults_git_for_root": False, "declares_self_test": False}
|
|
return {
|
|
"derives_root_from_file": any(_is_file_relative_root(n) for n in ast.walk(tree)),
|
|
"consults_git_for_root": _consults_git(tree),
|
|
"declares_self_test": _declares_self_test(tree),
|
|
}
|
|
|
|
|
|
def _is_file_relative_root(node: ast.AST) -> bool:
|
|
"""``Path(__file__)…parent.parent`` or ``…parents[n]`` — a root from a file path."""
|
|
if isinstance(node, ast.Attribute) and node.attr == "parent":
|
|
inner = node.value
|
|
return isinstance(inner, ast.Attribute) and inner.attr == "parent" and _reaches_dunder_file(inner)
|
|
if isinstance(node, ast.Subscript) and isinstance(node.value, ast.Attribute) and node.value.attr == "parents":
|
|
index = node.slice
|
|
return isinstance(index, ast.Constant) and index.value != 0 and _reaches_dunder_file(node.value)
|
|
return False
|
|
|
|
|
|
def _reaches_dunder_file(node: ast.AST) -> bool:
|
|
return any(isinstance(sub, ast.Name) and sub.id == "__file__" for sub in ast.walk(node))
|
|
|
|
|
|
def _consults_git(tree: ast.Module) -> bool:
|
|
"""Either it shells out to git itself, or it calls the shared resolver."""
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Constant) and node.value == _GIT_TOPLEVEL:
|
|
return True
|
|
if isinstance(node, ast.Call):
|
|
called = node.func
|
|
name = called.id if isinstance(called, ast.Name) else (called.attr if isinstance(called, ast.Attribute) else None)
|
|
if name == _ROOT_HELPER:
|
|
return True
|
|
return False
|
|
|
|
|
|
def _declares_self_test(tree: ast.Module) -> bool:
|
|
"""The flag reaches code, or the shared hook is installed.
|
|
|
|
A docstring promising ``--self-test`` while nothing parses it is the
|
|
documentation equivalent of a gate with no caller, and this repository has
|
|
shipped that shape more than once — so the flag has to appear as a value
|
|
the program uses, not as prose about the program.
|
|
"""
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Constant) and node.value == SELF_TEST_FLAG:
|
|
return True
|
|
if isinstance(node, ast.Name) and node.id == "SELF_TEST_FLAG":
|
|
return True
|
|
if isinstance(node, ast.Call):
|
|
called = node.func
|
|
name = called.id if isinstance(called, ast.Name) else (called.attr if isinstance(called, ast.Attribute) else None)
|
|
if name == "self_test_if_requested":
|
|
return True
|
|
return False
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Verdict
|
|
# --------------------------------------------------------------------------
|
|
def _expected(accepted: dict[str, dict[str, tuple[str, str]]], script: str, shape: str) -> tuple[str, str] | None:
|
|
"""The recorded exception for this script and shape, if there is one."""
|
|
per_shape = accepted.get(script)
|
|
if per_shape is None:
|
|
return None
|
|
return per_shape.get(shape) or per_shape.get(ANY_SHAPE)
|
|
|
|
|
|
def evaluate(
|
|
checks: dict[str, dict[str, str]],
|
|
probes: dict[str, Probe],
|
|
properties: dict[str, dict[str, bool]],
|
|
*,
|
|
accepted: dict[str, dict[str, tuple[str, str]]],
|
|
no_git_root: dict[str, str],
|
|
no_self_test: dict[str, str],
|
|
) -> list[tuple[str, str]]:
|
|
"""Every finding, as (code, detail). Pure, so the self-test can drive it."""
|
|
failures: list[tuple[str, str]] = []
|
|
|
|
for script in sorted(checks):
|
|
result = probes.get(script)
|
|
if result is None:
|
|
failures.append(("not-probed", f"{script} is a check and the probe produced no result for it"))
|
|
continue
|
|
for shape in result.shapes:
|
|
exception = _expected(accepted, script, shape)
|
|
disposition, why = result.disposition_for(shape), result.why_for(shape)
|
|
if exception is not None and disposition != exception[0]:
|
|
failures.append(
|
|
(
|
|
"exception-stale",
|
|
f"{script} is excused against the {shape} tree on the strength of a "
|
|
f"{exception[0]!r} disposition and now reports {disposition!r} ({why}). Either the "
|
|
"reason has stopped being true and the entry should go, or it is covering "
|
|
"something it was never written for.",
|
|
)
|
|
)
|
|
elif exception is None and disposition == INCONCLUSIVE:
|
|
failures.append(
|
|
(
|
|
"inconclusive",
|
|
f"{script} against the {shape} tree: {why}. The probe did not exercise the gate, so "
|
|
"a non-zero exit is not evidence it refuses an empty tree — install the dependency "
|
|
"in the job, or record an exception saying why the question cannot be asked.",
|
|
)
|
|
)
|
|
elif exception is None and disposition == PASSED:
|
|
offending = [" ".join(r.args) or "(no arguments)" for r in result.runs if r.shape == shape and r.disposition == PASSED]
|
|
failures.append(
|
|
(
|
|
"passes-over-empty-tree",
|
|
f"{script} {', '.join(offending)} exited 0 inside a {shape} repository holding no "
|
|
"content. Found nothing and scanned nothing print the same word: this gate credits "
|
|
"a tree it never opened. Make it fail closed on an empty read, or record why the "
|
|
"exit status is not its verdict.",
|
|
)
|
|
)
|
|
|
|
static = properties.get(script, {})
|
|
needs_git = static.get("derives_root_from_file") and not static.get("consults_git_for_root")
|
|
if needs_git and script not in no_git_root:
|
|
failures.append(
|
|
(
|
|
"root-from-file",
|
|
f"{script} resolves a repository root from __file__ and never asks git. Two levels above "
|
|
"the script is whatever happens to be there; use gate_toolkit.repo_root().",
|
|
)
|
|
)
|
|
if not needs_git and script in no_git_root:
|
|
failures.append(("ratchet-stale", f"{script} is on NO_GIT_ROOT but now resolves its root from git; remove the entry"))
|
|
|
|
if not static.get("declares_self_test") and script not in no_self_test:
|
|
failures.append(
|
|
(
|
|
"no-self-test",
|
|
f"{script} declares no {SELF_TEST_FLAG}, so nothing proves it still detects what it "
|
|
f"claims to. gate_toolkit.self_test_main() is the shared body.",
|
|
)
|
|
)
|
|
if static.get("declares_self_test") and script in no_self_test:
|
|
failures.append(("ratchet-stale", f"{script} is on NO_SELF_TEST but now declares {SELF_TEST_FLAG}; remove the entry"))
|
|
|
|
flattened = {name: " ".join(reason for _disposition, reason in per_shape.values()) for name, per_shape in accepted.items()}
|
|
reasons: dict[str, dict[str, str]] = {
|
|
"EMPTY_TREE_EXCEPTIONS": flattened,
|
|
"NO_GIT_ROOT": no_git_root,
|
|
"NO_SELF_TEST": no_self_test,
|
|
}
|
|
for name, label in reasons.items():
|
|
for script in sorted(set(label) - set(checks)):
|
|
failures.append(("ratchet-names-nothing", f"{name} lists {script!r}, which is not a check in the tree"))
|
|
for script, reason in sorted(label.items()):
|
|
if script in checks and not reason.strip():
|
|
failures.append(("ratchet-unexplained", f"{name}[{script!r}] carries no reason"))
|
|
|
|
return failures
|
|
|
|
|
|
def _exception_summary() -> str:
|
|
counts: dict[str, int] = {}
|
|
for per_shape in EMPTY_TREE_EXCEPTIONS.values():
|
|
for disposition, _reason in per_shape.values():
|
|
counts[disposition] = counts.get(disposition, 0) + 1
|
|
return ", ".join(f"{count} {name}" for name, count in sorted(counts.items())) or "none"
|
|
|
|
|
|
def load(root: Path, *, only: str | None = None) -> dict:
|
|
surface = coverage.Surface(root)
|
|
checks = coverage.collect_checks(root, surface.gating)
|
|
results = probe(surface, checks, root, only=only)
|
|
properties = {script: static_properties((root / "scripts" / script).read_text(encoding="utf-8", errors="replace")) for script in checks}
|
|
return {"checks": checks, "probes": {p.script: p for p in results}, "properties": properties}
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
# CLI
|
|
# --------------------------------------------------------------------------
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
parser.add_argument("--repo-root", type=Path, default=None, help="the tree to inspect (default: git rev-parse)")
|
|
parser.add_argument("--list", action="store_true", help="print every check with its disposition")
|
|
parser.add_argument("--json", action="store_true")
|
|
parser.add_argument("--only", help="probe a single check, by file name")
|
|
parser.add_argument(SELF_TEST_FLAG, action="store_true", help="prove this gate detects the drift it claims to")
|
|
args = parser.parse_args(argv)
|
|
|
|
if args.self_test:
|
|
return self_test()
|
|
|
|
root = (args.repo_root or repo_root()).resolve()
|
|
try:
|
|
data = load(root, only=args.only)
|
|
except (ProbeError, coverage.GateError, FileNotFoundError) as exc:
|
|
print(f"check_gate_contract: FAILED to run the probe: {exc}", file=sys.stderr)
|
|
return 2
|
|
|
|
checks, probes, properties = data["checks"], data["probes"], data["properties"]
|
|
failures = evaluate(
|
|
checks,
|
|
probes,
|
|
properties,
|
|
accepted=EMPTY_TREE_EXCEPTIONS,
|
|
no_git_root=NO_GIT_ROOT,
|
|
no_self_test=NO_SELF_TEST,
|
|
)
|
|
|
|
if args.json:
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"repo_root": str(root),
|
|
"checks": sorted(checks),
|
|
"probes": {name: asdict(p) for name, p in probes.items()},
|
|
"properties": properties,
|
|
"empty_tree_exceptions": EMPTY_TREE_EXCEPTIONS,
|
|
"no_git_root": NO_GIT_ROOT,
|
|
"no_self_test": NO_SELF_TEST,
|
|
"failures": [{"code": c, "detail": d} for c, d in failures],
|
|
},
|
|
indent=2,
|
|
sort_keys=True,
|
|
)
|
|
)
|
|
return 1 if failures else 0
|
|
|
|
runs = sum(len(p.runs) for p in probes.values())
|
|
print(f"repo root {root}")
|
|
print(f"inventory check_gate_coverage.py ({len(checks)} checks, {len(probes)} probed over {runs} invocations)")
|
|
print("scratch trees bare — a git repository holding only scripts/: services, detections, apps, docs, workflows absent")
|
|
print(" skeleton — the same, with those directories present and empty")
|
|
for shape in TREE_SHAPES:
|
|
counts = {name: sum(1 for p in probes.values() if p.disposition_for(shape) == name) for name in (REFUSED, PASSED, INCONCLUSIVE)}
|
|
print(f" {shape:<14} {counts[REFUSED]} refused, {counts[PASSED]} exited 0, {counts[INCONCLUSIVE]} inconclusive")
|
|
print(
|
|
f"exceptions {len(EMPTY_TREE_EXCEPTIONS)} scripts recorded ({_exception_summary()}), "
|
|
f"{len(NO_GIT_ROOT)} without a git root, {len(NO_SELF_TEST)} without a self-test"
|
|
)
|
|
print()
|
|
|
|
if args.list:
|
|
width = max((len(s) for s in probes), default=10)
|
|
for name in sorted(probes):
|
|
for run in probes[name].runs:
|
|
mark = {REFUSED: "refused ", PASSED: "EXITED 0", INCONCLUSIVE: "UNKNOWN "}[run.disposition]
|
|
print(f" {mark} {run.shape:<9} {name:{width}} {' '.join(run.args) or '(no arguments)'} [{run.source}]")
|
|
if run.evidence:
|
|
print(f" {'':9} {'':{width}} {run.evidence}")
|
|
print()
|
|
|
|
if failures:
|
|
print(f"FAIL — {len(failures)} finding(s):")
|
|
for code, detail in failures:
|
|
print(f" [{code}] {detail}")
|
|
return 1
|
|
print(f"OK — {len(checks) - len(EMPTY_TREE_EXCEPTIONS)} of {len(checks)} checks refuse both a repository with no content")
|
|
print(" and one whose directories are present and empty;")
|
|
print(f" the other {len(EMPTY_TREE_EXCEPTIONS)} are recorded exceptions, each with the disposition it is excused for per shape.")
|
|
return 0
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Self-test
|
|
# --------------------------------------------------------------------------
|
|
def self_test() -> int:
|
|
"""Inject each defect this gate exists to catch and require it to be caught."""
|
|
checks = {"check_real.py": {"verdict-flag": "--check"}}
|
|
|
|
def result(*dispositions: str, shape: str = BARE, also: dict[str, str] | None = None) -> dict[str, Probe]:
|
|
runs = [Run(args=["--check"], source="test", shape=shape, disposition=d, why=f"exited on {d}") for d in dispositions]
|
|
for other_shape, disposition in (also or {}).items():
|
|
runs.append(Run(args=["--check"], source="test", shape=other_shape, disposition=disposition, why="exited"))
|
|
return {"check_real.py": Probe(script="check_real.py", runs=runs)}
|
|
|
|
good = result(REFUSED)
|
|
clean_props = {"check_real.py": {"derives_root_from_file": False, "consults_git_for_root": True, "declares_self_test": True}}
|
|
|
|
def run(probes, props=None, *, accepted=None, no_git=None, no_self=None):
|
|
return {
|
|
code
|
|
for code, _ in evaluate(
|
|
checks,
|
|
probes,
|
|
props or clean_props,
|
|
accepted=accepted or {},
|
|
no_git_root=no_git or {},
|
|
no_self_test=no_self or {},
|
|
)
|
|
}
|
|
|
|
cases: list[tuple[str, str, set[str]]] = [
|
|
(
|
|
"a gate that exits 0 over a repository with no content",
|
|
"passes-over-empty-tree",
|
|
run(result(PASSED)),
|
|
),
|
|
(
|
|
"one invocation of a gate exits 0 while a sibling invocation refuses",
|
|
"passes-over-empty-tree",
|
|
run(result(REFUSED, PASSED)),
|
|
),
|
|
(
|
|
"a run that failed for a reason the empty tree did not cause",
|
|
"inconclusive",
|
|
run(result(INCONCLUSIVE)),
|
|
),
|
|
(
|
|
"a check the probe never reached at all",
|
|
"not-probed",
|
|
run({}),
|
|
),
|
|
(
|
|
"an accepted empty-tree pass that has started refusing — a stale exception",
|
|
"exception-stale",
|
|
run(good, accepted={"check_real.py": {ANY_SHAPE: (PASSED, "recorded reason")}}),
|
|
),
|
|
(
|
|
"an exception written for an inconclusive probe now covering an outright pass",
|
|
"exception-stale",
|
|
run(result(PASSED), accepted={"check_real.py": {ANY_SHAPE: (INCONCLUSIVE, "recorded reason")}}),
|
|
),
|
|
(
|
|
"an exception naming a check that is not in the tree",
|
|
"ratchet-names-nothing",
|
|
run(good, accepted={"check_ghost.py": {ANY_SHAPE: (PASSED, "recorded reason")}}),
|
|
),
|
|
(
|
|
"an exception with no reason given",
|
|
"ratchet-unexplained",
|
|
run(good, accepted={"check_real.py": {ANY_SHAPE: (REFUSED, " ")}}),
|
|
),
|
|
(
|
|
"a gate that refuses the bare tree and credits the skeleton — the shape the second tree exists for",
|
|
"passes-over-empty-tree",
|
|
run(result(REFUSED, also={SKELETON: PASSED})),
|
|
),
|
|
(
|
|
"an ANY_SHAPE exemption cannot quietly cover a shape it was not written for",
|
|
"exception-stale",
|
|
run(
|
|
result(REFUSED, also={SKELETON: PASSED}),
|
|
accepted={"check_real.py": {ANY_SHAPE: (REFUSED, "recorded reason")}},
|
|
),
|
|
),
|
|
(
|
|
"a per-shape exemption covers only the shape it names",
|
|
"passes-over-empty-tree",
|
|
run(
|
|
result(PASSED, also={SKELETON: PASSED}),
|
|
accepted={"check_real.py": {SKELETON: (PASSED, "recorded reason")}},
|
|
),
|
|
),
|
|
(
|
|
"a gate rooting itself at __file__ with no git resolution",
|
|
"root-from-file",
|
|
run(
|
|
good,
|
|
{"check_real.py": {"derives_root_from_file": True, "consults_git_for_root": False, "declares_self_test": True}},
|
|
),
|
|
),
|
|
(
|
|
"a gate that has moved onto git but is still listed as if it had not",
|
|
"ratchet-stale",
|
|
run(good, no_git={"check_real.py": "recorded reason"}),
|
|
),
|
|
(
|
|
"a gate with no self-test",
|
|
"no-self-test",
|
|
run(
|
|
good,
|
|
{"check_real.py": {"derives_root_from_file": False, "consults_git_for_root": True, "declares_self_test": False}},
|
|
),
|
|
),
|
|
]
|
|
|
|
print("check_gate_contract self-test")
|
|
print("baseline: one clean check, 0 findings (every case below perturbs exactly that)\n")
|
|
ok = not run(good)
|
|
print(f" {'PASS' if ok else 'FAIL'} the unperturbed baseline reports nothing")
|
|
|
|
for description, expected, codes in cases:
|
|
caught = expected in codes
|
|
ok &= caught
|
|
print(f" {'PASS' if caught else 'FAIL'} {description}")
|
|
print(f" expected [{expected}] got {sorted(codes) or 'nothing'}")
|
|
|
|
# The reader of the result, not just the rules on top of it. A classifier
|
|
# that called everything a refusal would pass every case above.
|
|
supplied = frozenset({"app"})
|
|
reader: list[tuple[str, tuple[str, str], str]] = [
|
|
("exit 0 is a pass", classify(0, "OK: 0 things checked", supplied), PASSED),
|
|
("exit 1 with a refusal is a refusal", classify(1, "no detections/ directory", supplied), REFUSED),
|
|
("an argparse usage error proves nothing", classify(2, "usage: x [-h]\nx: error: unrecognized arguments", supplied), INCONCLUSIVE),
|
|
(
|
|
"a missing third-party module proves nothing",
|
|
classify(1, "ModuleNotFoundError: No module named 'structlog'", supplied),
|
|
INCONCLUSIVE,
|
|
),
|
|
(
|
|
"a missing repo package is the empty tree doing its job",
|
|
classify(1, "ModuleNotFoundError: No module named 'app'", supplied),
|
|
REFUSED,
|
|
),
|
|
("a timeout is neither", classify(None, "", supplied), INCONCLUSIVE),
|
|
]
|
|
for read_label, (read, _why), read_want in reader:
|
|
correct = read == read_want
|
|
ok &= correct
|
|
print(f" {'PASS' if correct else 'FAIL'} READER: {read_label}")
|
|
print(f" expected {read_want} got {read}")
|
|
|
|
# The invocation chooser. A quoted path inside an `echo` is the shape that
|
|
# manufactured CI coverage for eleven services in another gate.
|
|
chooser: list[tuple[str, list[str] | None, list[str] | None]] = [
|
|
("a plain invocation yields its arguments", _argv_after(shlex.split("python3 scripts/x.py --check"), "x.py"), ["--check"]),
|
|
("a quoted path in an echo is not an invocation", _argv_after(shlex.split('echo "scripts/x.py --check"'), "x.py"), None),
|
|
("an env prefix is stepped over", _argv_after(shlex.split("FOO=1 python scripts/x.py --check"), "x.py"), ["--check"]),
|
|
("uv run reaches the same place", _argv_after(shlex.split("uv run python scripts/x.py"), "x.py"), []),
|
|
("python -m runs a module, not this script", _argv_after(shlex.split("python3 -m pytest scripts/x.py"), "x.py"), None),
|
|
]
|
|
for chosen_label, chosen, chosen_want in chooser:
|
|
correct = chosen == chosen_want
|
|
ok &= correct
|
|
print(f" {'PASS' if correct else 'FAIL'} CHOOSER: {chosen_label}")
|
|
print(f" expected {chosen_want} got {chosen}")
|
|
|
|
replay: list[tuple[str, bool, bool]] = [
|
|
("an unexpanded shell variable is not replayable", _replayable(["--root", "$GITHUB_WORKSPACE"]), False),
|
|
("a path CI builds outside the checkout is not replayable", _replayable(["--old", "/tmp/base.yaml"]), False),
|
|
("a repository-relative path is", _replayable(["--new", "docs/openapi.yaml"]), True),
|
|
]
|
|
for replay_label, replayed, replay_want in replay:
|
|
correct = replayed == replay_want
|
|
ok &= correct
|
|
print(f" {'PASS' if correct else 'FAIL'} REPLAY: {replay_label}")
|
|
print(f" expected {replay_want} got {replayed}")
|
|
|
|
# And the scratch trees themselves, because every result above is only as
|
|
# good as the claim that each tree really is the shape it says it is.
|
|
with scratch_tree() as tree:
|
|
present = sorted(p.name for p in tree.iterdir() if p.name != ".git")
|
|
toplevel = subprocess.run( # noqa: S603
|
|
["git", "rev-parse", "--show-toplevel"], cwd=tree, capture_output=True, text=True, check=False
|
|
)
|
|
isolated = Path(toplevel.stdout.strip() or "/nowhere").resolve() == tree.resolve()
|
|
bare = present == ["scripts"]
|
|
ok &= bare and isolated
|
|
print(f" {'PASS' if bare else 'FAIL'} TREE(bare): the scratch repository holds scripts/ and nothing else")
|
|
print(f" contents {present}")
|
|
print(f" {'PASS' if isolated else 'FAIL'} TREE(bare): git inside it resolves to itself, not to the real checkout")
|
|
|
|
# The skeleton has to differ from the bare tree in exactly one way: the
|
|
# directories exist and hold nothing. A skeleton that accidentally copied
|
|
# content would turn every probe into a scan of real files, and one whose
|
|
# directories vanished under `git clean` between probes would silently be
|
|
# the bare tree wearing a second name.
|
|
with scratch_tree(shape=SKELETON) as tree:
|
|
_reset(tree)
|
|
dirs = sorted(p.name for p in tree.iterdir() if p.is_dir() and p.name != ".git")
|
|
services = tree / "services"
|
|
empty = services.is_dir() and [p.name for p in services.iterdir()] == [".gitkeep"]
|
|
has_dirs = "services" in dirs and "detections" in dirs
|
|
ok &= empty and has_dirs
|
|
print(f" {'PASS' if has_dirs else 'FAIL'} TREE(skeleton): the directories a gate judges are present")
|
|
print(f" contents {dirs}")
|
|
print(f" {'PASS' if empty else 'FAIL'} TREE(skeleton): and still empty after a reset between probes")
|
|
|
|
print()
|
|
if not ok:
|
|
print("self-test FAILED: this gate did not catch drift it claims to catch")
|
|
return 1
|
|
print(f"self-test OK: {len(cases)} injected defects and {len(reader) + len(chooser) + len(replay) + 4} component assertions")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|