diff --git a/scripts/deposit.py b/scripts/deposit.py index d000634..b745598 100644 --- a/scripts/deposit.py +++ b/scripts/deposit.py @@ -647,6 +647,19 @@ def run(slug, provider, live, publish, new_version, delete_draft, set_field(slug, "archived_version", meta.get("version") or "0.0.0") steps.append("stamped archived_at %s (version %s)" % (stamp, meta.get("version"))) + # The DOI has to reach the ARTICLE's front matter too, not only + # metadata.yml: that is where the PDF's title page takes it from, + # and `pixi run test` asserts the two agree. Run here, the request + # carries both files and the publish needs nothing further. Run at + # publish instead, it would land on the runner and have to be + # written back -- the step this flow exists to remove. + import subprocess + if subprocess.call([sys.executable, "scripts/sync_archival.py"], + cwd=ROOT) != 0: + raise DepositError( + "could not write the reserved DOI into the article's " + "front matter; nothing else was changed") + steps.append("wrote the DOI into the article front matter") print("\n".join(" " + s for s in steps)) print("\nReserved and stopped. The identifiers are in " "metadata.yml; commit them, and the deposit runs when they " diff --git a/tests/test_migration.py b/tests/test_migration.py index 952035d..efea3c2 100644 --- a/tests/test_migration.py +++ b/tests/test_migration.py @@ -2374,6 +2374,24 @@ def test_an_open_request_is_not_asked_for_twice(): "and it must subtract them from what it asks about" +def test_the_reserve_writes_the_doi_into_the_article_too(): + """A deposit request has to carry BOTH files. + + `metadata.yml` holds the record for the guard; the article's own front + matter is where the PDF's title page takes the DOI from, and + `test_the_pdf_carries_the_archival_doi_once_a_note_is_deposited` asserts + the two agree. The first live reserve wrote only the metadata and that + test failed on the request it opened -- correctly, because a publish from + that state would have produced a PDF with no DOI on it. + """ + src = (ROOT / "scripts" / "deposit.py").read_text(encoding="utf-8") + reserve = src.split("if not rebuild:")[1].split("return")[0] + assert "sync_archival.py" in reserve, \ + "the reserve must write the DOI into the article front matter" + for field in ("archived_at", "archived_version"): + assert field in reserve, "%s must be stamped by the reserve" % field + + def test_the_deposit_reminder_asks_on_a_schedule_as_well_as_on_a_push(): """The push trigger fires on a metadata CHANGE; the condition it cares about is a STATE — archival, published, and holding no record.