diff --git a/.github/nightly-signing-policy.json b/.github/nightly-signing-policy.json index fd5a203059..78aea04108 100644 --- a/.github/nightly-signing-policy.json +++ b/.github/nightly-signing-policy.json @@ -79,7 +79,14 @@ "issue_types": [ "VULNERABILITY" ], - "accepted_conditions": [], + "accepted_conditions": [ + { + "metric": "new_security_rating", + "comparator": "GT", + "error_threshold": "1", + "maximum": "5" + } + ], "required_conditions": [ { "metric": "new_reliability_rating", diff --git a/docs/nightly-release-preparation.md b/docs/nightly-release-preparation.md index 36cc4620e7..06cb396dce 100644 --- a/docs/nightly-release-preparation.md +++ b/docs/nightly-release-preparation.md @@ -101,7 +101,7 @@ Read on 2026-11-24; re-read anything that may have moved before `nightly-signer` - Manual actors match the reviewed release-managers list in both `nightly.yml` and `.github/nightly-signing-policy.json`, with `automatic_signer_actors` empty. - Both callers pin the same immutable `craft-common-actions` commit in `uses` and `tooling-revision`. - No nightly schedule is registered, no cache actions or secrets appear in the app callers, and `nightly-sign.yml` retains its literal root `concurrency` block (`group: vectorcraft-nightly-release`, `cancel-in-progress: false`, `queue: max`). -- Policy v3 schema, platform rows, bounds, required main-push CI workflow, and SonarCloud project identity match `sonar-project.properties`. +- Policy v3 schema, platform rows, bounds, required main-push CI workflow, and SonarCloud project identity match `sonar-project.properties`, and the Sonar gate shape keeps every live condition once with accepted failures inside the reviewed issue scope. - The signer guards `refs/heads/nightly-signer`, passes `app-name: vectorcraft`, and the policy's `release_branch` names it. - A trust-closure scan reads every workflow: nothing binds an `environment`, only `nightly-sign.yml` @@ -174,13 +174,14 @@ enabled, so no `app.ron` is written anywhere); if it is ever turned on, its stat installation on every platform, and `apps/vectorcraft/src/profile.rs` (`install_data_root`) is the one hook every data path follows. -## Activation prerequisite: the Sonar issue scope +## The Sonar issue scope The pinned candidate validator requires every entry in `candidate_policy.sonar.issue_types` to map from a reviewed `accepted_conditions` row, and it requires the gate condition set to equal -`accepted_conditions` plus `required_conditions`. The installed policy lists `VULNERABILITY` with no -accepted condition, so it fails that contract before SonarCloud is read. Correct the policy in this -app's activation review with Skylar, together with the live gate conditions, before the first run. -`producer_workflow_id` is now populated and the signer runs on `nightly-signer`, so this policy -correction - with the registry's Windows and macOS targets - is what still stands between this tree +`accepted_conditions` plus `required_conditions`. The installed policy lists `VULNERABILITY` with +`new_security_rating` accepted (max 5) and the other five gate conditions required - the same shape +PhotoCraft and WordCraft ship - so it satisfies that contract before SonarCloud is read. `debt` stays +empty, so any unresolved vulnerability on `main` is still refused, and the live gate is still compared +condition by condition against the policy. `producer_workflow_id` is now populated and the signer runs +on `nightly-signer`; the registry's Windows and macOS targets are what still stand between this tree and a first signed nightly. diff --git a/packaging/nightly-release-tests.py b/packaging/nightly-release-tests.py index d09b2d0624..e175a01c2b 100755 --- a/packaging/nightly-release-tests.py +++ b/packaging/nightly-release-tests.py @@ -429,6 +429,52 @@ class NightlyInstalledPolicy(unittest.TestCase): self.assertIn(item["type"], sonar["issue_types"]) self.assertRegex(item["hash"], r"^[0-9a-f]{32}$") + def test_sonar_policy_keeps_the_shared_candidate_contract(self): + """The Sonar shape craft-common-actions' candidate contract() admits, refused here first. + + An empty issue scope, an accepted condition outside the reviewed issue types, a metric in both + lists, a missing live gate condition or a widened security bound is refused at admission, so + this suite must catch it before a nightly run can. `debt` stays empty, so any unresolved + vulnerability on main is still refused; accepting the new-code rating only records the + reviewed A threshold instead of demanding a clean rating the live gate does not. + """ + sonar = self.policy["candidate_policy"]["sonar"] + accepted = {"bugs": "BUG", "vulnerabilities": "VULNERABILITY", "code_smells": "CODE_SMELL", + "security_rating": "VULNERABILITY", "new_security_rating": "VULNERABILITY"} + gate = {"new_reliability_rating", "new_security_rating", "new_maintainability_rating", + "new_coverage", "new_duplicated_lines_density", "new_security_hotspots_reviewed"} + self.assertTrue(sonar["issue_types"], "an empty issue scope is refused as unreviewed") + self.assertEqual(len(sonar["issue_types"]), len(set(sonar["issue_types"]))) + metrics = {} + for field in ("accepted_conditions", "required_conditions"): + for condition in sonar[field]: + with self.subTest(field=field, metric=condition.get("metric")): + expected = {"metric", "comparator", "error_threshold"} + if field == "accepted_conditions": + expected.add("maximum") + self.assertEqual(set(condition), expected) + self.assertNotIn(condition["metric"], metrics, "one condition per gate metric") + metrics[condition["metric"]] = condition + self.assertIn(condition["comparator"], ("GT", "LT")) + self.assertRegex(condition["error_threshold"], r"^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$") + if field != "accepted_conditions": + continue + self.assertIn(condition["metric"], accepted, "an accepted metric outside the reviewed map") + self.assertIn(accepted[condition["metric"]], sonar["issue_types"], + "an accepted failure must lie inside the reviewed issue scope") + self.assertEqual(condition["comparator"], "GT") + self.assertRegex(condition["maximum"], r"^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$") + maximum = float(condition["maximum"]) + if condition["metric"] in ("security_rating", "new_security_rating"): + self.assertEqual(int(maximum), maximum, "the A..E bound is a whole rating") + self.assertTrue(1 <= maximum <= 5, "the security bound stays A..E") + self.assertEqual(condition["error_threshold"], "1", "the reviewed A threshold stays") + else: + self.assertLessEqual(maximum, len(sonar["debt"]), "accepted failures exceed the reviewed debt") + self.assertEqual({accepted[c["metric"]] for c in sonar["accepted_conditions"]}, set(sonar["issue_types"]), + "accepted conditions and reviewed issue types must cover the same scope") + self.assertEqual(set(metrics), gate, "every live gate condition stays gated exactly once") + SIGNER_BRANCH = "nightly-signer" SHARED = "storytold/craft-common-actions/.github/workflows/"