Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Training pipeline reads outcomes/*.jsonl for ESN (confidence time series) and pa
| `Retraction.idr` | Quarantine as retraction (HYP-01): a token survives iff its support thins into what remains; a finding survives through one of its tokens. Transcribed from residual-evidence-types `Revision.agda` @ 97244f5 |
| `Egress.idr` | RE001's decision on egress declarations (standards ADR-009): `Clean` is decidable (`decClean`); an audit hardener never passes a block claim; a declaration lists exactly the secrets read; a run-time key is never declared. Mirror: `test/egress_decision_mirror_test.exs` |
| `SecretAlerts.idr` | The `hypatia secret-alerts` line contract read by the bash/jq secret-scanning sweep: exit 0 iff ok, 3 iff error; an error line is never "clean"; `total` = number of findings; no finding is "sound". Gate: `scripts/check-verdicts.sh` (`tests/accept/SecretAlertsLines.idr`, `tests/reject/SecretAlerts*.idr`) |
| `RsrProfile.idr` | RSR capability-profile resolution (engineering model of `lib/rules/rsr_conformance.ex`): deed precedence, fail-closed duplicate/list-less clauses, a2ml fallback, and when criterion 3.2.2 agrees with the scorecard's `profile_present` (and the one case it does not). Gate: `scripts/check-verdicts.sh` (+ `tests/reject/`, `tests/accept/`) |
| `RsrProfile.idr` | RSR capability-profile resolution (engineering model of `lib/rules/rsr_conformance.ex`): deed precedence, fail-closed duplicate/list-less clauses, a2ml fallback, and that criterion 3.2.2 agrees with the scorecard's `profile_present` for every source (3.2.2 is the verdict of the same capability reader). Gate: `scripts/check-verdicts.sh` (+ `tests/reject/`, `tests/accept/`) |

**Build system:** `src/abi/hypatia-abi.ipkg` (compile), `verify/hypatia-verify.ipkg` (proofs), `pack.toml` (Pack package manager).
The ipkg sets `sourcedir = ".."`, so **`src/Hypatia/ABI/` is what compiles** — that is the
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ https://semver.org/[Semantic Versioning].

=== Changed

==== RSR 3.2.2 is the verdict of the capability reader (2026-11-16)

Criterion 3.2.2 (profile present) now passes exactly when
`declared_capabilities/1` finds a profile, the same reader behind the
scorecard's `profile_present`. Before, a repository with no deed
`(rsr-profile …)` clause passed 3.2.2 whenever
`<machine tree>/rsr-profile.a2ml` existed, even when that file did not parse
or carried no `capabilities` list. In that case the scorecard reported no
profile. The Idris2 model (`src/Hypatia/ABI/RsrProfile.idr`, from #1033)
proved that this was the only case where the two disagreed. With the fix it
proves they agree for every source (`profilePresentAgrees`), and
`tests/reject/EmptyA2mlPassesProfileCriterion.idr` guards against the old
behaviour returning.

Effect on scores: a deedless repository whose `rsr-profile.a2ml` declares no
capabilities now fails 3.2.2. It was already scored as having no profile, so
gated criteria were already `:na` for it.

==== WH013 reads the canonical workflow model; `Hypatia.WorkflowYaml` is gone (2026-11-16)

WH013 now reads `Hypatia.Workflow`, as RE001, RE002 and WH014 do. With that,
Expand Down
31 changes: 16 additions & 15 deletions lib/rules/rsr_conformance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ defmodule Hypatia.Rules.RsrConformance do
# then to :unverified.
case delegated_verdict(c.id, delegated) do
:skip ->
# A detector of arity 2 also takes the capability set `score/2` read
# once, so it judges the same profile the scorecard reports.
case Map.fetch(detectors(), c.id) do
{:ok, fun} when is_function(fun, 2) -> fun.(repo, caps)
{:ok, fun} -> fun.(repo)
:error -> :unverified
end
Expand Down Expand Up @@ -606,22 +609,20 @@ defmodule Hypatia.Rules.RsrConformance do
end
end

# 3.2.2: the repo declares a profile. Either carrier counts, with the same
# precedence and validation as the capability reader above: when the repo
# deed carries a top-level (rsr-profile …) clause it decides, and it passes
# only if the reader accepts it (exactly one clause, with a `:capabilities`
# list). A duplicated or list-less clause fails, as it declares nothing.
# With no such clause, the legacy <machine tree>/rsr-profile.a2ml counts.
# 3.2.2: the repo declares a profile. It passes exactly when the capability
# set `score/2` read (once, via the reader above) is not `:none`, so 3.2.2
# and the scorecard's `profile_present` (`caps != :none`) judge the same
# value and agree by construction, even if the profile changes mid-scan
# (src/Hypatia/ABI/RsrProfile.idr, `profilePresentAgrees`, which models
# that single read). The deed's top-level (rsr-profile …) clause
# decides when present: a duplicated or list-less clause fails, as it
# declares nothing. With no such clause, the legacy
# <machine tree>/rsr-profile.a2ml counts only if it yields a capabilities
# list; a file that exists but does not parse, or has none, no longer
# passes on its presence alone (that case once passed 3.2.2 while the
# scorecard reported no profile).
defp profile_present do
a2ml = present_mr("rsr-profile.a2ml")

fn repo ->
case deed_profile_capabilities(repo) do
:absent -> a2ml.(repo)
:none -> :fail
_caps -> :pass
end
end
fn _repo, caps -> if caps == :none, do: :fail, else: :pass end
end

# 3.1.8: the anchor. The legacy ANCHOR.a2ml still counts; its successor is
Expand Down
131 changes: 41 additions & 90 deletions src/Hypatia/ABI/RsrProfile.idr
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
-- `clause_capabilities/1` ~ `readClause` (with `capLists`,
-- `keepCaps`)
-- `a2ml_capabilities/1` ~ `a2mlCapabilities`
-- `profile_present/0` (3.2.2) ~ `criterion322`
-- `present_mr("rsr-profile.a2ml")` ~ `a2mlFileVerdict`
-- `profile_present/0` (3.2.2) ~ `criterion322` (= `verdictOf` of
-- `declaredCapabilities`)
-- `deed_clause?/2` ~ not used by 3.2.2 since bffd76a; before
-- it, 3.2.2 passed on any clause, which is
-- the defect `deedDecidedAgrees` excludes
Expand All @@ -42,13 +42,14 @@
-- `duplicateFailsCriterion`, `listlessFailsCriterion`);
-- * fallback: with no clause the result is the a2ml reading
-- (`fallbackNoDeed`, `fallbackNoClause`, `fallbackCriterionNoClause`);
-- * consistency: 3.2.2 passes iff the scorecard says `profile_present`
-- whenever the deed decides (`deedDecidedAgrees`, the bffd76a fix) and
-- whenever the a2ml is not "present but declaring nothing"
-- (`a2mlDecidedAgrees`); they disagree in exactly that one case
-- (`disagreementIsExactly`), and it is inhabited (`residualDivergence`):
-- with no deed clause, 3.2.2 checks only that rsr-profile.a2ml exists,
-- while the scorecard needs it to yield a capabilities list.
-- * consistency: 3.2.2 passes iff the scorecard says `profile_present`,
-- for every source (`profilePresentAgrees`). It holds by construction:
-- 3.2.2 is the verdict of the same capability reader. The bffd76a fix
-- is the deed-decided instance (`deedDecidedAgrees`). The case that
-- diverged before the 3.2.2 fix (no deed clause; an rsr-profile.a2ml
-- that exists but yields no capabilities list, which passed 3.2.2 on its
-- presence while the scorecard reported no profile) now fails
-- (`emptyA2mlFails`).
--
-- What is NOT proved here: that the Elixir behaves as this model. The
-- Elixir is not extracted from this module; the correspondence is by review
Expand Down Expand Up @@ -202,24 +203,17 @@ passes : CriterionVerdict -> Bool
passes Pass = True
passes Fail = False

||| `present_mr("rsr-profile.a2ml")`: the file exists.
||| The verdict of `profile_present/0`: pass exactly when the capability
||| reader declares a profile (`declared_capabilities(repo) == :none` fails).
public export
a2mlFileVerdict : A2mlState -> CriterionVerdict
a2mlFileVerdict A2mlMissing = Fail
a2mlFileVerdict A2mlDeclaresNothing = Pass
a2mlFileVerdict (A2mlDeclares _) = Pass

||| The `case` of `profile_present/0`.
public export
check322 : Resolution -> A2mlState -> CriterionVerdict
check322 Absent a = a2mlFileVerdict a
check322 DeclaresNothing _ = Fail
check322 (Declared _) _ = Pass
verdictOf : Caps -> CriterionVerdict
verdictOf CapsNone = Fail
verdictOf (CapsList _) = Pass

||| Criterion 3.2.2, `profile_present/0`.
public export
criterion322 : ProfileSource -> CriterionVerdict
criterion322 src = check322 (resolve (deed src)) (a2ml src)
criterion322 src = verdictOf (declaredCapabilities src)

------------------------------------------------------------------------
-- Section 4: Lemmas on the reading steps
Expand All @@ -240,16 +234,6 @@ fromAbsent : (a : A2mlState) -> (r : Resolution)
-> r = Absent -> fromResolution r a = a2mlCapabilities a
fromAbsent _ _ Refl = Refl

public export
checkNothing : (a : A2mlState) -> (r : Resolution)
-> r = DeclaresNothing -> check322 r a = Fail
checkNothing _ _ Refl = Refl

public export
checkAbsent : (a : A2mlState) -> (r : Resolution)
-> r = Absent -> check322 r a = a2mlFileVerdict a
checkAbsent _ _ Refl = Refl

||| One clause: the reading is that clause's.
public export
oneClause : (bs : List (List BodyItem)) -> (body : List BodyItem)
Expand Down Expand Up @@ -350,9 +334,7 @@ duplicateFailsCriterion : (items : List TopItem) -> (a : A2mlState)
-> {b1, b2 : List BodyItem} -> {rest : List (List BodyItem)}
-> profileBodies items = b1 :: b2 :: rest
-> criterion322 (MkProfileSource (Just items) a) = Fail
duplicateFailsCriterion items a dup =
checkNothing a (readBodies (profileBodies items))
(twoClauses (profileBodies items) dup)
duplicateFailsCriterion items a dup = cong verdictOf (duplicateDeclaresNothing items a dup)

||| One clause without a capabilities list fails 3.2.2, for every a2ml
||| state.
Expand All @@ -362,9 +344,7 @@ listlessFailsCriterion : (items : List TopItem) -> (a : A2mlState)
-> capLists body = []
-> criterion322 (MkProfileSource (Just items) a) = Fail
listlessFailsCriterion items a body one listless =
checkNothing a (readBodies (profileBodies items))
(trans (oneClause (profileBodies items) body one)
(listlessClause body listless))
cong verdictOf (listlessDeclaresNothing items a body one listless)

------------------------------------------------------------------------
-- Section 7: Fallback to the a2ml
Expand All @@ -384,74 +364,45 @@ fallbackNoClause : (items : List TopItem) -> (a : A2mlState)
fallbackNoClause items a none =
fromAbsent a (readBodies (profileBodies items)) (noClause (profileBodies items) none)

||| A deed without a top-level clause: 3.2.2 is the a2ml file check.
||| A deed without a top-level clause: 3.2.2 is the verdict of the a2ml
||| reading, so an .a2ml that exists but yields no list fails.
public export
fallbackCriterionNoClause : (items : List TopItem) -> (a : A2mlState)
-> profileBodies items = []
-> criterion322 (MkProfileSource (Just items) a) = a2mlFileVerdict a
fallbackCriterionNoClause items a none =
checkAbsent a (readBodies (profileBodies items)) (noClause (profileBodies items) none)
-> criterion322 (MkProfileSource (Just items) a) = verdictOf (a2mlCapabilities a)
fallbackCriterionNoClause items a none = cong verdictOf (fallbackNoClause items a none)

------------------------------------------------------------------------
-- Section 8: 3.2.2 and the scorecard agree
------------------------------------------------------------------------

||| The verdict passes exactly when the scorecard field is true.
public export
agreeWhenDecided : (r : Resolution) -> (a : A2mlState) -> Not (r = Absent)
-> passes (check322 r a) = scorecardProfilePresent (fromResolution r a)
agreeWhenDecided Absent _ notAbsent = void (notAbsent Refl)
agreeWhenDecided (Declared _) _ _ = Refl
agreeWhenDecided DeclaresNothing _ _ = Refl

public export
agreeUnlessEmptyA2ml : (r : Resolution) -> (a : A2mlState)
-> Not (a = A2mlDeclaresNothing)
-> passes (check322 r a) = scorecardProfilePresent (fromResolution r a)
agreeUnlessEmptyA2ml Absent A2mlMissing _ = Refl
agreeUnlessEmptyA2ml Absent A2mlDeclaresNothing notEmpty = void (notEmpty Refl)
agreeUnlessEmptyA2ml Absent (A2mlDeclares _) _ = Refl
agreeUnlessEmptyA2ml (Declared _) _ _ = Refl
agreeUnlessEmptyA2ml DeclaresNothing _ _ = Refl
verdictAgrees : (c : Caps) -> passes (verdictOf c) = scorecardProfilePresent c
verdictAgrees CapsNone = Refl
verdictAgrees (CapsList _) = Refl

||| 3.2.2 passes iff the scorecard says the profile is present, for every
||| source: both read the same capability set.
public export
disagreeReading : (r : Resolution) -> (a : A2mlState)
-> Not (passes (check322 r a) = scorecardProfilePresent (fromResolution r a))
-> (r = Absent, a = A2mlDeclaresNothing)
disagreeReading Absent A2mlMissing differ = void (differ Refl)
disagreeReading Absent A2mlDeclaresNothing _ = (Refl, Refl)
disagreeReading Absent (A2mlDeclares _) differ = void (differ Refl)
disagreeReading (Declared _) _ differ = void (differ Refl)
disagreeReading DeclaresNothing _ differ = void (differ Refl)
profilePresentAgrees : (src : ProfileSource)
-> passes (criterion322 src) = scorecardProfilePresent (declaredCapabilities src)
profilePresentAgrees src = verdictAgrees (declaredCapabilities src)

||| When the deed decides, 3.2.2 passes iff the scorecard says the profile
||| is present. This is the property bffd76a restored: a duplicated or
||| list-less clause neither passes 3.2.2 nor counts as a profile.
||| list-less clause neither passes 3.2.2 nor counts as a profile. It is
||| now an instance of `profilePresentAgrees`.
public export
deedDecidedAgrees : (src : ProfileSource) -> Not (resolve (deed src) = Absent)
-> passes (criterion322 src) = scorecardProfilePresent (declaredCapabilities src)
deedDecidedAgrees src notAbsent = agreeWhenDecided (resolve (deed src)) (a2ml src) notAbsent

||| Unless the a2ml is present but declares no capabilities list, 3.2.2
||| passes iff the scorecard says the profile is present.
public export
a2mlDecidedAgrees : (src : ProfileSource) -> Not (a2ml src = A2mlDeclaresNothing)
-> passes (criterion322 src) = scorecardProfilePresent (declaredCapabilities src)
a2mlDecidedAgrees src notEmpty = agreeUnlessEmptyA2ml (resolve (deed src)) (a2ml src) notEmpty

||| The two readers disagree only when there is no deed clause and the a2ml
||| is present but declares no capabilities list.
public export
disagreementIsExactly : (src : ProfileSource)
-> Not (passes (criterion322 src) = scorecardProfilePresent (declaredCapabilities src))
-> (resolve (deed src) = Absent, a2ml src = A2mlDeclaresNothing)
disagreementIsExactly src differ = disagreeReading (resolve (deed src)) (a2ml src) differ
deedDecidedAgrees src _ = profilePresentAgrees src

||| And that case occurs: no deed, and an rsr-profile.a2ml that exists but
||| yields no capabilities list, passes 3.2.2 while the scorecard reports no
||| profile.
||| The case that diverged before the 3.2.2 fix: no deed, and an
||| rsr-profile.a2ml that exists but yields no capabilities list. It used
||| to pass 3.2.2 on the file's presence while the scorecard reported no
||| profile; it now fails 3.2.2 (tests/reject/EmptyA2mlPassesProfileCriterion
||| is the regression guard).
public export
residualDivergence : ( criterion322 (MkProfileSource Nothing A2mlDeclaresNothing) = Pass
, scorecardProfilePresent
(declaredCapabilities (MkProfileSource Nothing A2mlDeclaresNothing))
= False )
residualDivergence = (Refl, Refl)
emptyA2mlFails : criterion322 (MkProfileSource Nothing A2mlDeclaresNothing) = Fail
emptyA2mlFails = Refl
23 changes: 23 additions & 0 deletions test/rules/rsr_conformance_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,29 @@ defmodule Hypatia.Rules.RsrConformanceTest do
end
end

# With no deed clause, the legacy .a2ml counts only if the reader gets a
# capabilities list from it. This case used to pass 3.2.2 on the file's
# presence while the scorecard reported no profile (RsrProfile.idr: the
# former `residualDivergence`; now `emptyA2mlFails`).
test "3.2.2 agrees with profile_present on an rsr-profile.a2ml with no list", %{
tmp_dir: tmp
} do
{:ok, catalogue} = RsrCriteria.load(@ssot)
path = ".machine_readable/rsr-profile.a2ml"

for {text, want} <- [
{"[rsr-profile]\ncapabilities = [\"bash\"]\n", {:pass, true}},
{"[rsr-profile]\nversion = \"1.0.0\"\n", {:fail, false}},
{"[unrelated]\ncapabilities = [\"bash\"]\n", {:fail, false}},
{"this is not a record [[[\n", {:fail, false}}
] do
mk!(tmp, path, text)
{:ok, sc} = RsrConformance.score(catalogue, tmp)
verdict = Enum.find(sc.results, &(&1.id == "3.2.2")).verdict
assert {verdict, sc.profile_present} == want, "for #{inspect(text)}"
end
end

test "a malformed descriptile fails 3.2.1 (parse gate, not just presence)", %{
tmp_dir: tmp
} do
Expand Down
26 changes: 17 additions & 9 deletions tests/accept/RsrProfileResolution.idr
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,20 @@ dupAgrees : passes (criterion322 (MkProfileSource (Just RsrProfileResolution.dup
(declaredCapabilities (MkProfileSource (Just RsrProfileResolution.dupDeed) (A2mlDeclares ["bash"])))
dupAgrees = deedDecidedAgrees (MkProfileSource (Just dupDeed) (A2mlDeclares ["bash"])) nothingIsNotAbsent

-- The residual case: no deed clause and an .a2ml that exists but yields no
-- capabilities list. 3.2.2 passes on the file's presence; the scorecard
-- reports no profile.
residualPasses : criterion322 (MkProfileSource Nothing A2mlDeclaresNothing) = Pass
residualPasses = fst residualDivergence

residualNotPresent : scorecardProfilePresent (declaredCapabilities (MkProfileSource Nothing A2mlDeclaresNothing))
= False
residualNotPresent = snd residualDivergence
-- The case that diverged before the 3.2.2 fix: no deed clause and an .a2ml
-- that exists but yields no capabilities list. 3.2.2 now fails, and agrees
-- with the scorecard, which reports no profile.
emptyA2mlFailsHere : criterion322 (MkProfileSource Nothing A2mlDeclaresNothing) = Fail
emptyA2mlFailsHere = emptyA2mlFails

emptyA2mlNotPresent : scorecardProfilePresent (declaredCapabilities (MkProfileSource Nothing A2mlDeclaresNothing))
= False
emptyA2mlNotPresent = Refl

emptyA2mlAgrees : passes (criterion322 (MkProfileSource Nothing A2mlDeclaresNothing))
= scorecardProfilePresent (declaredCapabilities (MkProfileSource Nothing A2mlDeclaresNothing))
emptyA2mlAgrees = profilePresentAgrees (MkProfileSource Nothing A2mlDeclaresNothing)

-- A2ML with a list and no deed: 3.2.2 passes.
a2mlListPasses : criterion322 (MkProfileSource Nothing (A2mlDeclares ["bash"])) = Pass
a2mlListPasses = Refl
28 changes: 28 additions & 0 deletions tests/reject/EmptyA2mlPassesProfileCriterion.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- SPDX-License-Identifier: MPL-2.0
-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
--
-- EXPECTED REJECTION (RSR capability-profile resolution).
-- scripts/check-verdicts.sh passes only if Idris2 refuses this module, and
-- only at the declaration `invalid`. Every other declaration must
-- typecheck, so that the refusal is for the stated reason and not for a
-- missing import or a typo.
--
-- Must fail: criterion 3.2.2 with no deed and an rsr-profile.a2ml that
-- exists but yields no capabilities list. Before the 3.2.2 fix the
-- detector passed on the file's presence while the scorecard reported no
-- profile; 3.2.2 is now the verdict of the capability reader, so it fails.
--
-- EXPECT: Mismatch between: Pass and Fail.

module EmptyA2mlPassesProfileCriterion

import Hypatia.ABI.RsrProfile

%default total
%unbound_implicits off

source : ProfileSource
source = MkProfileSource Nothing A2mlDeclaresNothing

invalid : criterion322 EmptyA2mlPassesProfileCriterion.source = Pass
invalid = Refl
Loading
Loading