|
| 1 | +import Test |
| 2 | +import TOML |
| 3 | + |
| 4 | +const CITATION_PACKAGE_ROOT = normpath(joinpath(@__DIR__, "..")) |
| 5 | + |
| 6 | +include(joinpath(CITATION_PACKAGE_ROOT, "scripts", "verify_zenodo_release.jl")) |
| 7 | + |
| 8 | +function _zenodo_record(; concept = "7812066", version = "v0.7.6") |
| 9 | + return Dict( |
| 10 | + "conceptrecid" => concept, |
| 11 | + "doi" => "10.5281/zenodo.21078136", |
| 12 | + "metadata" => Dict("version" => version), |
| 13 | + ) |
| 14 | +end |
| 15 | + |
| 16 | +Test.@testset "Citation metadata is consistent" begin |
| 17 | + read_text(path) = replace(read(path, String), "\r\n" => "\n") |
| 18 | + |
| 19 | + project = TOML.parsefile(joinpath(CITATION_PACKAGE_ROOT, "Project.toml")) |
| 20 | + citation = read_text(joinpath(CITATION_PACKAGE_ROOT, "CITATION.cff")) |
| 21 | + readme = read_text(joinpath(CITATION_PACKAGE_ROOT, "README.md")) |
| 22 | + checklist = read_text(joinpath(CITATION_PACKAGE_ROOT, ".github", "RELEASE_CHECKLIST.md")) |
| 23 | + workflow = read_text(joinpath(CITATION_PACKAGE_ROOT, ".github", "workflows", "zenodo.yml")) |
| 24 | + |
| 25 | + concept_doi = "10.5281/zenodo.7812066" |
| 26 | + version_doi = "10.5281/zenodo.21078136" |
| 27 | + article_doi = "10.1080/10556788.2026.2702926" |
| 28 | + version = string(project["version"]) |
| 29 | + |
| 30 | + Test.@test occursin("doi: \"$concept_doi\"", citation) |
| 31 | + Test.@test occursin("version: \"$version\"", citation) |
| 32 | + Test.@test occursin(article_doi, citation) |
| 33 | + |
| 34 | + Test.@test occursin("badge/DOI/$concept_doi.svg", readme) |
| 35 | + Test.@test occursin("doi.org/$concept_doi", readme) |
| 36 | + Test.@test occursin("doi.org/$version_doi", readme) |
| 37 | + Test.@test occursin("doi.org/$article_doi", readme) |
| 38 | + |
| 39 | + Test.@test occursin(concept_doi, checklist) |
| 40 | + Test.@test occursin("Can manage", checklist) |
| 41 | + Test.@test occursin("Zenodo release verification", checklist) |
| 42 | + Test.@test occursin(r"(?m)^\s*release:\s*$", workflow) |
| 43 | + Test.@test occursin(r"(?m)^\s*-\s*published\s*$", workflow) |
| 44 | + Test.@test occursin("scripts/verify_zenodo_release.jl", workflow) |
| 45 | +end |
| 46 | + |
| 47 | +Test.@testset "Zenodo release comparison detects archive drift" begin |
| 48 | + current = ZenodoReleaseVerification.check_record(_zenodo_record(), "v0.7.6") |
| 49 | + stale = ZenodoReleaseVerification.check_record( |
| 50 | + _zenodo_record(; version = "v0.7.5"), |
| 51 | + "v0.7.6", |
| 52 | + ) |
| 53 | + wrong_concept = ZenodoReleaseVerification.check_record( |
| 54 | + _zenodo_record(; concept = "9999999"), |
| 55 | + "v0.7.6", |
| 56 | + ) |
| 57 | + |
| 58 | + Test.@test current.ok |
| 59 | + Test.@test current.doi == "10.5281/zenodo.21078136" |
| 60 | + Test.@test !stale.ok |
| 61 | + Test.@test occursin("v0.7.5", stale.message) |
| 62 | + Test.@test !wrong_concept.ok |
| 63 | + Test.@test occursin("9999999", wrong_concept.message) |
| 64 | + |
| 65 | + responses = Any[_zenodo_record(; version = "v0.7.5"), _zenodo_record()] |
| 66 | + result = ZenodoReleaseVerification.verify_release( |
| 67 | + "v0.7.6"; |
| 68 | + attempts = 2, |
| 69 | + delay_seconds = 0, |
| 70 | + record_fetcher = _ -> popfirst!(responses), |
| 71 | + ) |
| 72 | + |
| 73 | + Test.@test result.ok |
| 74 | + Test.@test isempty(responses) |
| 75 | + Test.@test_throws ErrorException ZenodoReleaseVerification.verify_release( |
| 76 | + "v0.7.6"; |
| 77 | + attempts = 1, |
| 78 | + delay_seconds = 0, |
| 79 | + record_fetcher = _ -> _zenodo_record(; version = "v0.7.5"), |
| 80 | + ) |
| 81 | + |
| 82 | + transport_error = try |
| 83 | + ZenodoReleaseVerification.verify_release( |
| 84 | + "v0.7.6"; |
| 85 | + attempts = 1, |
| 86 | + delay_seconds = 0, |
| 87 | + record_fetcher = _ -> error("network unavailable"), |
| 88 | + ) |
| 89 | + nothing |
| 90 | + catch error |
| 91 | + sprint(showerror, error) |
| 92 | + end |
| 93 | + |
| 94 | + Test.@test occursin("network unavailable", transport_error) |
| 95 | +end |
0 commit comments