diff --git a/CHANGELOG.md b/CHANGELOG.md index e194217..282fa88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ All notable changes to ReleaseCheck will be documented here. ## Unreleased +- Added four pinned public npm/PyPI corpus records, a six-case offline adversarial matrix, and independent report-contract tests. +- Documented explicit attestation interoperability states and audited the Action/docs companion repository boundaries. - Documented Sigstore, SLSA, and GitHub artifact-attestation interoperability boundaries. - Added v0.1.2 package-manager metadata and a pinned real npm/PyPI corpus record. - Added an opt-in bounded corpus verifier that checks pinned artifact URLs, sizes, and SHA-256 digests without installing or executing packages. diff --git a/FINAL_AUDIT.md b/FINAL_AUDIT.md index 6dc93da..81dbeae 100644 --- a/FINAL_AUDIT.md +++ b/FINAL_AUDIT.md @@ -1,6 +1,6 @@ # ReleaseCheck Security and Release Audit -> **Current status (2026-10-18):** Public `v0.1.2` was released successfully. Its tag workflow and post-release Action E2E run passed. Remaining readiness work is owner-controlled Drips project claiming/configuration and genuine external impact evidence. +> **Current status (2026-11-03):** Public `v0.1.2` was released successfully. Its tag workflow and post-release Action E2E run passed. The evidence-quality follow-up added a pinned public corpus, offline adversarial cases, report-contract tests, explicit attestation interoperability semantics, and an independent companion-repository review. Remaining readiness work is owner-controlled Drips project claiming/configuration and genuine external impact evidence. Older pre-release findings in this document are retained as audit history; they do not describe the current release state. @@ -8,6 +8,8 @@ Audit date: 2026-10-18 (status addendum; original Phase 15 review dated 2026-10- Audit scope: current `main` after the Phase 15 remediation changes and the v0.1.2 release evidence. This document supersedes the stale Phase 14 checkpoint wording. Older conditional release-gate language is retained as historical audit context, not current release state. +Evidence-quality follow-up date: 2026-11-03. The follow-up is additive to the v0.1.2 audit and does not upgrade ReleaseCheck into a malware detector, cryptographic provenance verifier, or source-equivalence proof system. + ## Executive result **Recommendation: CONDITIONAL for v0.1.2 stabilization.** The public release and Action E2E gates passed; remaining limitations are explicitly accepted for v0.1.2 and must not be described as package-safety or cryptographic-provenance guarantees. @@ -24,6 +26,10 @@ The non-execution boundary remains credible, and the remediation adds bounded ma 6. Seven- or otherwise abbreviated hexadecimal references are no longer treated as immutable commits; only full 40-character Git object IDs receive immutable classification. 7. Comparison, provenance parsing, reports, exit codes, fixtures, and deterministic ordering remain covered by offline tests. 8. CI action references are pinned to full commit SHAs and workflows use least privilege. +9. The expanded public corpus verifier confirmed six pinned npm/PyPI artifacts by HTTPS, size, and SHA-256 without installing, extracting, importing, or executing package contents. +10. Offline adversarial cases cover artifact-only, source-only, modified, unsafe-path, install-metadata, and provenance-subject-mismatch evidence. +11. Independent report-contract tests confirm that human, JSON, and SARIF outputs preserve MATCH, REVIEW, and INCOMPLETE semantics and stable exit behavior. +12. The Action and docs repositories were independently checked for thin integration boundaries, cross-platform support, attestation wording, and stale claims. ## Finding status @@ -74,6 +80,7 @@ The workstation does not provide every security analysis tool. `go vet` and the - No stable public SDK compatibility promise. - Local/private mirror use requires explicit controlled configuration and is not a hosted isolation boundary. - The release workflow does not publish Sigstore, SLSA, or GitHub artifact attestations in v0.1.2; consumers must treat the published SHA256SUMS as checksum evidence only. +- The public corpus is a reproducibility and evidence-boundary corpus, not a catalog of malicious packages. Its adversarial cases target verifier behavior and do not establish intent. ## Historical release gate diff --git a/PROJECT_CONTEXT.md b/PROJECT_CONTEXT.md index 4bc3f68..894fed0 100644 --- a/PROJECT_CONTEXT.md +++ b/PROJECT_CONTEXT.md @@ -37,7 +37,7 @@ Out of scope: crates.io, Go modules, generic vulnerability scanning, SBOM genera ## Current implementation -The repository currently contains a Go CLI with npm and PyPI verification paths; bounded HTTPS acquisition; SHA-256 and supported npm integrity handling; safe ZIP/TAR.GZ inventory; source and artifact file comparison; deterministic structural security observations; provenance structure parsing and artifact binding; human, JSON, and SARIF reports with stable reason and next-action fields; stable exit codes; offline fixtures; contributor documentation; CI and release workflows; independent audit reports; pinned Go/Homebrew/Scoop installation metadata; and a metadata-only real npm/PyPI compatibility corpus with an opt-in bounded verifier. Public v0.1.2 release and Action E2E validation are complete. The product remains deliberately narrower than provenance infrastructure, reproducibility builders, vulnerability scanners, and repository-health tools. +The repository currently contains a Go CLI with npm and PyPI verification paths; bounded HTTPS acquisition; SHA-256 and supported npm integrity handling; safe ZIP/TAR.GZ inventory; source and artifact file comparison; deterministic structural security observations; provenance structure parsing and artifact binding; human, JSON, and SARIF reports with stable reason and next-action fields; stable exit codes; offline fixtures; contributor documentation; CI and release workflows; independent audit reports; pinned Go/Homebrew/Scoop installation metadata; and a metadata-only real npm/PyPI compatibility corpus with an opt-in bounded verifier. The corpus now includes four public release records and a checked-in adversarial evidence matrix. Independent report-contract tests confirm the meaning of MATCH, REVIEW, and INCOMPLETE across human, JSON, and SARIF renderers. Public v0.1.2 release, Action E2E validation, and companion repository audit are complete. The product remains deliberately narrower than provenance infrastructure, reproducibility builders, vulnerability scanners, and repository-health tools. The current CLI is: @@ -75,6 +75,7 @@ The dependency relationship is one-way: the core releases versioned binaries; th - Sigstore, SLSA, GitHub artifact attestations, npm provenance, and PyPI attestations are interoperability evidence sources, not reimplemented trust roots. v0.1.2 documents how to verify them with their ecosystem tooling and reports the remaining boundary. - Package-manager publication is staged conservatively: `go install` is documented for the public module, while Homebrew and Scoop metadata are prepared but no official tap or bucket is claimed. - Real-release compatibility records store URLs, sizes, and digests only. They are validated offline for schema/HTTPS/digest shape; package bytes are not committed, installed, or executed. +- The public corpus is adversarial to the evidence model rather than a malware dataset: it exercises source-bound npm releases, generated distributions, PyPI sdists/wheels, and missing exact source commits. Offline adversarial cases cover artifact-only, source-only, modified, unsafe-path, install-metadata, and provenance-subject-mismatch states. - Phase 2 domain model: one internal data-oriented package with small `RegistryAdapter` and `Cache` interfaces; standard `context.Context`; validation only for cross-ecosystem invariants. - Phase 3 acquisition: `internal/acquire` is HTTPS-only, bounded, SHA-256-aware, temporary-file based, and archive-inspection-only; it never extracts or executes package content. - Phase 4 npm path: the adapter consumes packument `dist`, `repository`, and `gitHead` metadata, verifies npm SRI when present, supports GitHub source snapshots, and reports unsupported/missing source data as limitations. @@ -128,6 +129,7 @@ Registry-native mechanisms already provide important pieces: npm metadata, integ - Phase 12: COMPLETE. Evidence: pinned cross-platform CI, race job, tag-driven release workflow, scripts/build-release.sh, VERSION, docs/RELEASE.md, and the local Phase 12 checkpoint checks. - Phase 13: COMPLETE. Evidence: README.md, docs/USAGE.md, docs/REPORTS.md, docs/CI.md, docs/REGISTRY_ADAPTERS.md, docs/GOOD_FIRST_ISSUES.md, updated SECURITY.md/CONTRIBUTING.md, feature-request template, and the documentation checkpoint review. - Phase 14: AUDIT REQUIRED as the historical audit checkpoint. Phase 15 records the remediation evidence; Phase 16 supersedes this historical gate. +- Evidence-quality follow-up (2026-11-03): COMPLETE. Added four pinned public npm/PyPI release records, a six-case offline adversarial matrix, independent human/JSON/SARIF report-contract tests, explicit attestation interoperability semantics, and a companion repository audit. Live corpus verification passed for six artifacts without installation or execution. Action/docs stale Ubuntu-only guidance was corrected. - Phase 15: COMPLETE. Evidence: `.gitattributes`, bounded archive-member reads, live manifest observations, default-deny artifact network policy, full-commit classification, focused adversarial tests, updated FINAL_AUDIT.md, and hosted CI runs `37852987328` and `37853277292` passing Ubuntu, Windows, macOS, and race jobs. - Phase 16: COMPLETE. Evidence: `AUDIT_REPORT.md` records the independent review, the Action checksum fix and core release-gate fix are merged in public PRs, and hosted CI runs pass. Residual limitations and the missing public release rehearsal remain explicit. - Organization milestone M0: COMPLETE. Evidence: public repositories `ReleaseCheck/releasecheck`, `ReleaseCheck/releasecheck-action`, and `ReleaseCheck/releasecheck-docs`; matching checkpoint commit IDs are recorded in ROADMAP.md. The core repository retains its existing history; the Action and docs repositories have bounded root commits. diff --git a/README.md b/README.md index 1001c4e..d9e9fde 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Apache-2.0 license

-[Core](https://github.com/ReleaseCheck/releasecheck) · [GitHub Action](https://github.com/ReleaseCheck/releasecheck-action) · [User documentation](https://github.com/ReleaseCheck/releasecheck-docs) · [Security policy](SECURITY.md) · [Roadmap](ROADMAP.md) +[Core](https://github.com/ReleaseCheck/releasecheck) · [GitHub Action](https://github.com/ReleaseCheck/releasecheck-action) · [User documentation](https://github.com/ReleaseCheck/releasecheck-docs) · [Security policy](SECURITY.md) · [Roadmap](ROADMAP.md) · [Companion repository audit](docs/COMPANION_REPOSITORY_AUDIT.md) **Project status:** v0.1.2 released · post-release validation passed. The released core binary and GitHub Action E2E path are verified together. diff --git a/ROADMAP.md b/ROADMAP.md index e88d123..fbdd453 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -7,7 +7,7 @@ This is an executable plan. A phase is complete only when its acceptance criteri | Item | Current truth | | --- | --- | | Product version | Public `v0.1.2` released | -| Current milestone | v0.1 post-release validation complete; Drips operational setup remains | +| Current milestone | v0.1 post-release evidence-quality follow-up complete; Drips operational setup remains | | Current active phase | Phase 19 - Release and stabilization (`COMPLETE`) | | Next executable phase | Drips project claim/configuration; no GitHub issues are required | | Release decision | v0.1.2 published and Action E2E verified | @@ -71,9 +71,11 @@ This is the single status overview for the whole roadmap. The detailed sections | Release-state and license truth pass | COMPLETE | Current v0.1.2 state in `PROJECT_CONTEXT.md`, `README.md`, `AUDIT_REPORT.md`, `FINAL_AUDIT.md`, Action README, and docs README; Apache-2.0 remains the canonical license in all three repositories | Historical audit checkpoints remain labeled as history; no false release or license claim is retained | | Sigstore/SLSA/GitHub attestation interoperability | COMPLETE | `docs/ATTESTATIONS.md`, `docs/DESIGN.md`, and docs repository `docs/attestations.md` | v0.1.2 consumes/reports evidence boundaries; it does not implement trust-root verification or publish GitHub attestations | | Package-manager installation metadata | PARTIAL | Pinned `go install` is usable; Homebrew/Scoop manifests are prepared metadata only | Official Homebrew tap and Scoop bucket publication remain owner/repository work | -| Real npm/PyPI compatibility corpus | COMPLETE | `fixtures/corpus/real-releases.json`, `cmd/corpuscheck`, corpus README, offline schema test; live verification confirmed three artifacts on 2026-10-20 | Package bytes are downloaded only to an ignored output directory and are never installed or executed | -| Cross-platform GitHub Action acquisition | IN PROGRESS | Platform dispatch and Windows PowerShell verifier added in `releasecheck-action` review branch | Hosted matrix must pass before completion; Action remains limited to published release targets | -| GitHub license classifier | IN PROGRESS | Canonical Apache-2.0 text normalized in all three repositories | GitHub must re-index the files; `NOASSERTION` is not considered fixed until the API reports Apache-2.0 | +| Real npm/PyPI compatibility corpus | COMPLETE | `fixtures/corpus/real-releases.json`, `fixtures/corpus/adversarial-cases.json`, `cmd/corpuscheck`, corpus README, offline schema/report tests; live verification confirmed six artifacts on 2026-11-03 | Package bytes are downloaded only to an ignored output directory and are never installed or executed | +| Cross-platform GitHub Action acquisition | COMPLETE | Merged Action PR #5; hosted Ubuntu, Windows, and macOS matrix passed; companion audit in `docs/COMPANION_REPOSITORY_AUDIT.md` | Action remains limited to published release targets | +| GitHub license classifier | COMPLETE | GitHub API reports Apache-2.0 for core, Action, and docs after canonical license normalization | External classifier state verified on 2026-10-20 | +| Adversarial corpus and report-contract proof | COMPLETE | Offline adversarial matrix plus independent human/JSON/SARIF contract tests; expanded public corpus live check passed on 2026-11-03 | Cases identify review signals and evidence limits; they do not claim maliciousness | +| Companion repository audit | COMPLETE | Action/docs responsibilities, platform support, attestation boundaries, and claim limits recorded in `docs/COMPANION_REPOSITORY_AUDIT.md` | This is a repository/documentation audit, not a cryptographic audit of external trust systems | ## Current Repository Architecture diff --git a/docs/ATTESTATIONS.md b/docs/ATTESTATIONS.md index 5a7625d..6828ed9 100644 --- a/docs/ATTESTATIONS.md +++ b/docs/ATTESTATIONS.md @@ -22,6 +22,17 @@ gh attestation verify ./releasecheck -R ReleaseCheck/releasecheck For Sigstore artifacts, use the official Cosign verification flow appropriate to the artifact type and signature format. For SLSA provenance, verify the envelope/signature, trusted builder identity, expected build type, subject digest, and policy expectations. These commands are external verification steps; ReleaseCheck never executes package code or arbitrary build commands to obtain them. +## Interoperability contract + +| Input state | Report meaning | Stronger conclusion allowed? | +| --- | --- | --- | +| No attestation returned | `absent` or `unavailable`, depending on the registry response | No provenance conclusion | +| Attestation is malformed or its subject does not match the selected artifact | `invalid` | No; the mismatch is a review signal | +| Subject and digest bind to the artifact, but signature/trust policy is outside ReleaseCheck | `insufficient` | No cryptographic trust conclusion | +| A supported external verifier has succeeded and its result is supplied as evidence | external evidence is recorded with its boundary | Only the external verifier's documented claim, not source equivalence or package safety | + +ReleaseCheck v0.1.2 does not call `npm audit signatures`, `gh attestation verify`, Cosign, or a PyPI attestation verifier internally. This is deliberate: those tools own ecosystem trust roots and policy. ReleaseCheck reports the relationship between the selected registry artifact and claimed source evidence without silently substituting its own trust policy. + ## Current release limitation ReleaseCheck v0.1.2 publishes signed-by-checksum GitHub release archives but does not publish GitHub artifact attestations or claim Sigstore verification. The release asset SHA-256 manifest proves only the downloaded asset's digest matches the published manifest; it is not a signature, provenance statement, or source-equivalence proof. diff --git a/docs/COMPANION_REPOSITORY_AUDIT.md b/docs/COMPANION_REPOSITORY_AUDIT.md new file mode 100644 index 0000000..4f60cf2 --- /dev/null +++ b/docs/COMPANION_REPOSITORY_AUDIT.md @@ -0,0 +1,24 @@ +# Companion Repository Audit + +This document records the independent review boundary for the three public ReleaseCheck repositories. It prevents the core audit from treating companion repositories as assumed evidence. + +## Responsibilities + +| Repository | Reviewed responsibility | Boundary confirmed | +| --- | --- | --- | +| `ReleaseCheck/releasecheck` | Core Go CLI, verification engine, reports, fixtures, security policy, and release workflow | Source of implementation truth | +| `ReleaseCheck/releasecheck-action` | Thin GitHub Actions wrapper that downloads a selected core release, verifies its checksum, and propagates the result | No second verification engine; package code is never executed | +| `ReleaseCheck/releasecheck-docs` | Curated user guides, CI examples, attestation guidance, and limitations | Links to core semantics; does not redefine them | + +## Review checks + +- README scope and limitations agree with the core evidence model. +- Action acquisition is platform-aware for Ubuntu, macOS, and Windows and verifies the selected release archive before execution. +- Action CI covers its validation gate and all three declared runner platforms. +- Documentation describes external attestation verification as interoperable evidence, not as native ReleaseCheck trust verification. +- Documentation does not claim package safety, source equivalence, universal provenance support, adoption, or novelty. +- Repository-local PR templates require Summary, Verification, Security, and documentation/limitation sections. + +## Evidence policy + +This is a repository-structure and documentation review, not an independent cryptographic audit of GitHub, npm, PyPI, Sigstore, or SLSA. Hosted CI results and exact commit IDs must be recorded at each release checkpoint. A passing companion-repository check does not upgrade a package verdict or prove that a published artifact is safe. diff --git a/fixtures/corpus/README.md b/fixtures/corpus/README.md index c4fb4b1..8d9f665 100644 --- a/fixtures/corpus/README.md +++ b/fixtures/corpus/README.md @@ -20,4 +20,6 @@ Each record includes: - the expected evidence state and comparison limitation; - the observation date and primary metadata URL. -The corpus intentionally includes both a strong npm source reference and PyPI distributions where the source repository is visible but an exact release commit is not supplied. That distinction is a product behavior, not a test failure. +The real corpus intentionally includes npm packages with and without exact source commits, plus PyPI sdists and wheels. The package selection is adversarial to the verifier's evidence model: it exercises generated distribution files, multiple release-file kinds, missing exact source references, and source-bound releases. It does not make a maliciousness claim about any package. + +`adversarial-cases.json` is the offline companion matrix. It names the controlled fixtures for artifact-only, source-only, modified, unsafe-path, install-metadata, and provenance-subject-mismatch evidence. These cases are deterministic and run in default CI; the public release records are opt-in because registries and source hosts are external dependencies. diff --git a/fixtures/corpus/adversarial-cases.json b/fixtures/corpus/adversarial-cases.json new file mode 100644 index 0000000..ec3b297 --- /dev/null +++ b/fixtures/corpus/adversarial-cases.json @@ -0,0 +1,48 @@ +{ + "schema_version": "1.0", + "purpose": "Offline adversarial verifier cases. These cases exercise evidence boundaries and do not label a package malicious.", + "cases": [ + { + "id": "artifact-only-file", + "fixture": "tests/fixture_matrix_test.go", + "signal": "comparison.artifact_only", + "expected_verdict": "REVIEW", + "interpretation": "An artifact contains a file absent from the source inventory; this requires review but is not proof of maliciousness." + }, + { + "id": "source-only-file", + "fixture": "tests/fixture_matrix_test.go", + "signal": "comparison.source_only", + "expected_verdict": "REVIEW", + "interpretation": "A source file is absent from the selected artifact; packaging rules or build transformation may explain it." + }, + { + "id": "modified-file", + "fixture": "tests/fixture_matrix_test.go", + "signal": "comparison.modified", + "expected_verdict": "REVIEW", + "interpretation": "The same path has different hashes; the report records evidence without assigning intent." + }, + { + "id": "unsafe-archive-path", + "fixture": "tests/fixture_matrix_test.go", + "signal": "archive.path_unsafe", + "expected_verdict": "INCOMPLETE", + "interpretation": "Archive inspection stops at a path traversal attempt; no extraction or execution occurs." + }, + { + "id": "install-script-metadata", + "fixture": "tests/fixture_matrix_test.go", + "signal": "security.npm.install_script", + "expected_verdict": "REVIEW", + "interpretation": "Install-time metadata is observed without running the script." + }, + { + "id": "provenance-subject-mismatch", + "fixture": "internal/provenance/provenance_test.go", + "signal": "provenance.invalid", + "expected_verdict": "REVIEW", + "interpretation": "The attestation subject does not bind to the selected artifact." + } + ] +} diff --git a/fixtures/corpus/real-releases.json b/fixtures/corpus/real-releases.json index 94067f1..8d0c993 100644 --- a/fixtures/corpus/real-releases.json +++ b/fixtures/corpus/real-releases.json @@ -1,6 +1,6 @@ { "schema_version": "1.0", - "observed_at": "2026-10-20", + "observed_at": "2026-11-03", "purpose": "Pinned metadata for reproducible, opt-in live release checks; package bytes are not committed or executed.", "records": [ { @@ -41,6 +41,47 @@ "source_repository": "https://github.com/pypa/sampleproject", "git_commit": null, "expected_state": "source-reference-without-published-commit" + }, + { + "ecosystem": "npm", + "package": "left-pad", + "version": "1.3.0", + "metadata_url": "https://registry.npmjs.org/left-pad/1.3.0", + "artifact_filename": "left-pad-1.3.0.tgz", + "artifact_url": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", + "artifact_size": 3619, + "artifact_sha256": "870c0fe1096223a58d4f8832d08a7e651ea2fcadb8e6877b2fdc26b662d481dd", + "registry_integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==", + "source_repository": "https://github.com/stevemao/left-pad", + "git_commit": "ff8e7ba8b4122829cf66125ca8445cac7f073bce", + "expected_state": "reviewable-source-bound", + "comparison_note": "Public package selected because generated distribution contents must be compared with its published source reference; no maliciousness is inferred from any difference." + }, + { + "ecosystem": "pypi", + "package": "requests", + "version": "2.32.3", + "metadata_url": "https://pypi.org/pypi/requests/2.32.3/json", + "artifacts": [ + { + "artifact_filename": "requests-2.32.3.tar.gz", + "artifact_url": "https://files.pythonhosted.org/packages/63/70/2bf7780ad2d390a8d301ad0b550f1581eadbd9a20f896afe06353c2a2913/requests-2.32.3.tar.gz", + "artifact_size": 131218, + "artifact_sha256": "55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760", + "kind": "sdist" + }, + { + "artifact_filename": "requests-2.32.3-py3-none-any.whl", + "artifact_url": "https://files.pythonhosted.org/packages/f9/9b/335f9764261e915ed497fcdeb11df5dfd6f7bf257d4a6a2a686d80da4d54/requests-2.32.3-py3-none-any.whl", + "artifact_size": 64928, + "artifact_sha256": "70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6", + "kind": "wheel" + } + ], + "source_repository": "https://github.com/psf/requests", + "git_commit": null, + "expected_state": "source-reference-without-published-commit", + "comparison_note": "The sdist and wheel are intentionally separate artifacts; a wheel is not expected to be byte-for-byte equal to a source snapshot." } ] } diff --git a/tests/corpus_test.go b/tests/corpus_test.go index 695a53d..de34612 100644 --- a/tests/corpus_test.go +++ b/tests/corpus_test.go @@ -42,7 +42,7 @@ func TestRealReleaseCorpusIsPinnedAndWellFormed(t *testing.T) { if err := json.Unmarshal(data, &got); err != nil { t.Fatalf("corpus JSON: %v", err) } - if got.SchemaVersion != "1.0" || got.ObservedAt == "" || len(got.Records) != 2 { + if got.SchemaVersion != "1.0" || got.ObservedAt == "" || len(got.Records) != 4 { t.Fatalf("unexpected corpus header: %#v", got) } for _, item := range got.Records { @@ -64,6 +64,38 @@ func TestRealReleaseCorpusIsPinnedAndWellFormed(t *testing.T) { } } +func TestAdversarialCorpusDocumentsEvidenceBoundaries(t *testing.T) { + data, err := os.ReadFile(filepath.Join("..", "fixtures", "corpus", "adversarial-cases.json")) + if err != nil { + t.Fatal(err) + } + var got struct { + SchemaVersion string `json:"schema_version"` + Purpose string `json:"purpose"` + Cases []struct { + ID string `json:"id"` + Fixture string `json:"fixture"` + Signal string `json:"signal"` + ExpectedVerdict string `json:"expected_verdict"` + Interpretation string `json:"interpretation"` + } `json:"cases"` + } + if err := json.Unmarshal(data, &got); err != nil { + t.Fatalf("adversarial corpus JSON: %v", err) + } + if got.SchemaVersion != "1.0" || got.Purpose == "" || len(got.Cases) < 6 { + t.Fatalf("unexpected adversarial corpus: %#v", got) + } + for _, item := range got.Cases { + if item.ID == "" || item.Fixture == "" || item.Signal == "" || item.Interpretation == "" { + t.Fatalf("incomplete adversarial case: %#v", item) + } + if item.ExpectedVerdict != "REVIEW" && item.ExpectedVerdict != "INCOMPLETE" { + t.Fatalf("unexpected verdict in adversarial case: %#v", item) + } + } +} + func assertDigestURL(t *testing.T, rawURL, digest string) { t.Helper() u, err := url.Parse(rawURL) diff --git a/tests/report_contract_test.go b/tests/report_contract_test.go new file mode 100644 index 0000000..a403a75 --- /dev/null +++ b/tests/report_contract_test.go @@ -0,0 +1,101 @@ +package tests + +import ( + "encoding/json" + "strings" + "testing" + + "github.com/releasecheck/releasecheck/internal/domain" + "github.com/releasecheck/releasecheck/internal/report" +) + +// TestReportContractSemantics checks the public meaning of each report mode +// through the renderers, independently of registry and archive acquisition. +func TestReportContractSemantics(t *testing.T) { + cases := []struct { + name string + mutate func(*domain.Report) + verdict domain.Verdict + exitCode domain.ExitCode + humanContains string + jsonContains string + sarifContains string + }{ + { + name: "match is bounded evidence", + verdict: domain.VerdictMatch, + exitCode: domain.ExitSuccess, + humanContains: "Verdict: MATCH", + jsonContains: `"reason_code": "comparison.identical"`, + }, + { + name: "difference is review, not malware verdict", + mutate: func(value *domain.Report) { + value.Comparisons[0].Kind = domain.ComparisonModified + }, + verdict: domain.VerdictReview, + exitCode: domain.ExitReview, + humanContains: "Verdict: REVIEW", + jsonContains: `"reason_code": "evidence.requires_review"`, + sarifContains: `"comparison.modified"`, + }, + { + name: "missing source is incomplete", + mutate: func(value *domain.Report) { + value.Source = nil + }, + verdict: domain.VerdictIncomplete, + exitCode: domain.ExitReview, + humanContains: "Verdict: INCOMPLETE", + jsonContains: `"reason_code": "evidence.incomplete"`, + }, + } + + for _, testCase := range cases { + t.Run(testCase.name, func(t *testing.T) { + value := contractReport() + if testCase.mutate != nil { + testCase.mutate(&value) + } + normalized, err := report.Normalize(value) + if err != nil { + t.Fatal(err) + } + if normalized.Verdict != testCase.verdict || report.ExitCode(normalized) != testCase.exitCode { + t.Fatalf("policy: got verdict=%s exit=%d, want verdict=%s exit=%d", normalized.Verdict, report.ExitCode(normalized), testCase.verdict, testCase.exitCode) + } + human, err := report.Human(value) + if err != nil || !strings.Contains(human, testCase.humanContains) { + t.Fatalf("human report: %v\n%s", err, human) + } + jsonData, err := report.JSON(value) + if err != nil || !strings.Contains(string(jsonData), testCase.jsonContains) { + t.Fatalf("JSON report: %v\n%s", err, jsonData) + } + if testCase.sarifContains != "" { + sarifData, err := report.SARIF(value) + if err != nil || !strings.Contains(string(sarifData), testCase.sarifContains) { + t.Fatalf("SARIF report: %v\n%s", err, sarifData) + } + } + var decoded map[string]any + if err := json.Unmarshal(jsonData, &decoded); err != nil { + t.Fatalf("report JSON remains parseable: %v", err) + } + }) + } +} + +func contractReport() domain.Report { + identity := domain.PackageIdentity{Registry: domain.RegistryNPM, Name: "contract-fixture", Version: "1.0.0"} + return domain.Report{ + Identity: identity, + Artifact: domain.Artifact{Identity: identity, Filename: "contract-fixture.tgz", URL: "https://registry.example/contract-fixture.tgz", SHA256: strings.Repeat("a", 64)}, + Source: &domain.SourceReference{URL: "https://github.com/example/contract-fixture"}, + Git: &domain.GitReference{Ref: strings.Repeat("b", 40), Commit: strings.Repeat("b", 40), Immutable: true}, + Comparisons: []domain.FileComparison{{ + Path: "index.js", + Kind: domain.ComparisonIdentical, + }}, + } +}