mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
Main push jobs occupied hosted runners during 94% of the sampled critical-path queue time. Limit simultaneous post-merge API and browser shards while retaining the full test inventory and the normal pull request and release workflow widths.
76 lines
3.8 KiB
Python
76 lines
3.8 KiB
Python
"""Check the dependency graph and audit verdicts used in frontend CI."""
|
|
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
import yaml
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
BUILD = ROOT / ".github/workflows/build-and-test.yml"
|
|
SECURITY = ROOT / ".github/workflows/security-scan.yml"
|
|
|
|
|
|
class FrontendDependencyAuditTest(unittest.TestCase):
|
|
def test_pull_request_audits_the_locked_frontend_graph(self):
|
|
jobs = yaml.safe_load(BUILD.read_text())["jobs"]
|
|
self.assertEqual(jobs["changes"]["outputs"]["frontend_deps"],
|
|
"${{ steps.filter.outputs.frontend_deps }}")
|
|
producer = jobs["frontend-build"]
|
|
self.assertEqual(producer["timeout-minutes"], 30)
|
|
steps = {step["name"]: step for step in producer["steps"]}
|
|
self.assertIn("Check Solid serialization dependency edges", steps)
|
|
self.assertEqual(steps["Install frontend dependencies"]["run"], "npm ci --no-audit")
|
|
audit = steps["Audit complete frontend dependency graph"]
|
|
self.assertEqual(audit["id"], "audit-complete")
|
|
self.assertIs(audit["continue-on-error"], True)
|
|
self.assertEqual(audit["env"]["NPM_AUDIT_REQUIRE_RESULT"],
|
|
"${{ needs.changes.outputs.frontend_deps }}")
|
|
self.assertEqual(audit["run"], 'bash "$GITHUB_WORKSPACE/scripts/npm-audit-retry.sh" all')
|
|
verdict = steps["Require frontend dependency audit"]
|
|
self.assertEqual(verdict["if"], "${{ !cancelled() }}")
|
|
self.assertEqual(verdict["env"]["COMPLETE_AUDIT_RESULT"], "${{ steps.audit-complete.outcome }}")
|
|
|
|
def test_unit_runner_uses_the_locked_graph(self):
|
|
jobs = yaml.safe_load(BUILD.read_text())["jobs"]
|
|
steps = {step["name"]: step for step in jobs["frontend-unit"]["steps"]}
|
|
self.assertEqual(steps["Install frontend dependencies"]["run"], "npm ci --no-audit")
|
|
self.assertTrue(steps["Frontend unit tests"]["run"].startswith("npm run test -- "))
|
|
|
|
def test_scheduled_audit_requires_both_reports(self):
|
|
jobs = yaml.safe_load(SECURITY.read_text())["jobs"]
|
|
steps = {step["name"]: step for step in jobs["npm-audit"]["steps"]}
|
|
production = steps["Audit production dependencies"]
|
|
self.assertEqual(production["id"], "audit-production")
|
|
self.assertEqual(production["run"],
|
|
'bash "$GITHUB_WORKSPACE/scripts/npm-audit-retry.sh" production --package-lock-only')
|
|
self.assertEqual(steps["Require dependency audits"]["env"], {
|
|
"COMPLETE_AUDIT_RESULT": "${{ steps.audit-complete.outcome }}",
|
|
"PRODUCTION_AUDIT_RESULT": "${{ steps.audit-production.outcome }}",
|
|
})
|
|
|
|
def test_runner_keeps_strict_findings_and_wall_clock_bounds(self):
|
|
runner = (ROOT / "scripts/npm-audit-retry.sh").read_text()
|
|
self.assertNotIn("--audit-level", runner)
|
|
for expression in (
|
|
"NPM_AUDIT_REQUIRE_RESULT:-true",
|
|
'AUDIT_ARGS=(audit --json "$@")',
|
|
"AUDIT_ARGS+=(--omit=dev)",
|
|
"if type(value) is int and value >= 0:",
|
|
"has_findings = isinstance(findings, dict) and bool(findings)",
|
|
"if has_findings or any(count > 0 for count in counts.values()):",
|
|
'print("vulnerable")',
|
|
'isinstance(report, dict) and not report.get("error")',
|
|
"len(counts) == len(count_names) and all(count == 0 for count in counts.values())",
|
|
'and ("vulnerabilities" not in report or isinstance(findings, dict))',
|
|
'if [ "${REQUIRE_RESULT}" = "false" ]; then',
|
|
"NPM_AUDIT_MAX_SECONDS", "NPM_AUDIT_ATTEMPT_TIMEOUT",
|
|
"export npm_config_fetch_retries=0", "DEADLINE=",
|
|
):
|
|
with self.subTest(expression=expression):
|
|
self.assertIn(expression, runner)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|