From 77cb6251a1e4e6ad19b16db5bfabda5bc0c522c9 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 27 Sep 2026 22:54:30 +0200 Subject: [PATCH] fix(web-app-docs): stop serving a deployed build the run did not stage The site answers 202 while it builds a version, and 200 once a build exists. Whether that build matches what the version currently names was never asked at the serving gate: servable() only checks that an index.html is on disk. So the first request after a new snapshot got the previous build with 200, and the rebuild it triggered finished into a directory nobody was waiting for. For a release tag that cannot happen, and for latest it is a reasonable trade, since a visitor would rather read the previous page than a spinner. For deployed it is wrong by definition: the name means the working tree this run staged, so an earlier snapshot is not a stale answer but a different question's answer. The post-deploy test that reads the published page therefore validated the round before it, and reported a role broken whose page had already been fixed. The comparison already existed. _current() weighs built_ref against _wanted_ref, which resolves deployed to the snapshot digest, and the builder consults it to decide whether to rebuild. Only the server did not. outdated() exposes it for deployed alone and the serving branch now treats a mismatch as not yet servable, so the poll waits for the build it asked for. Measured on the stack while the previous round was live: the served page was written 16:44:41 from the older snapshot, its own source carried the newer content, and the correct build landed at 17:10:56, twenty-six minutes after the test had already read the stale one and failed. Co-Authored-By: Claude Opus 5 (1M context) --- .../files/python/infinito_docs/library.py | 16 +++++++++ .../files/python/infinito_docs/server.py | 2 +- .../files/infinito_docs/test_library.py | 33 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/roles/web-app-docs/files/python/infinito_docs/library.py b/roles/web-app-docs/files/python/infinito_docs/library.py index 88c32b0a34..64256934f8 100644 --- a/roles/web-app-docs/files/python/infinito_docs/library.py +++ b/roles/web-app-docs/files/python/infinito_docs/library.py @@ -126,6 +126,22 @@ class Library(Sites, Queue, Builder): and self._language_index_is_current(version) ) + def outdated(self, version) -> bool: + """Whether a built site answers for a snapshot it was not built from. + + ``deployed`` names the working tree a run just staged, so serving an + earlier build under it is a wrong answer rather than a stale one. A + released tag cannot move, and ``latest`` is allowed to serve its + previous build while the next one is still being made. + + Args: + version: ``latest``, ``deployed`` or a release tag. + """ + if version != DEPLOYED: + return False + head, _ = self.refs() + return not self._current(version, head) + def _translation_current(self, version, code, head): return self.translation_servable(version, code) and self.translation_ref( version, code diff --git a/roles/web-app-docs/files/python/infinito_docs/server.py b/roles/web-app-docs/files/python/infinito_docs/server.py index f97b4136b1..34433e14f2 100644 --- a/roles/web-app-docs/files/python/infinito_docs/server.py +++ b/roles/web-app-docs/files/python/infinito_docs/server.py @@ -124,7 +124,7 @@ class DocsHandler(SimpleHTTPRequestHandler): self.send_error(HTTPStatus.NOT_FOUND) elif not slash: self._redirect(f"/{version}/") - elif not self.library.servable(version): + elif not self.library.servable(version) or self.library.outdated(version): self.library.request(version) body = BUILDING.format(version=html.escape(version)) self._page(HTTPStatus.ACCEPTED, f"Building {version}", body, head) diff --git a/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_library.py b/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_library.py index ccb204248e..d24e75a6a3 100644 --- a/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_library.py +++ b/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_library.py @@ -276,5 +276,38 @@ class TestBeforeTheFirstFetch(unittest.TestCase): self.assertIsNone(shelf.next_queued()) +class TestOutdated(unittest.TestCase): + BUILT = "a" * 64 + STAGED = "b" * 64 + + def _shelf(self, td, built, staged): + shelf = library.Library("unused", Path(td), 1, Path(td), Path(td) / "snapshot") + patch.object(shelf, "refs", lambda: ("head", ())).start() + patch.object(shelf, "servable", lambda version: True).start() + patch.object(shelf, "built_ref", lambda version: built).start() + patch.object(shelf, "snapshot_ref", lambda: staged).start() + patch.object(shelf, "_language_index_is_current", lambda version: True).start() + self.addCleanup(patch.stopall) + return shelf + + def test_a_deployed_build_of_an_older_snapshot_is_outdated(self) -> None: + with TemporaryDirectory() as td: + shelf = self._shelf(td, self.BUILT, self.STAGED) + + self.assertTrue(shelf.outdated("deployed")) + + def test_a_deployed_build_of_the_staged_snapshot_is_not(self) -> None: + with TemporaryDirectory() as td: + shelf = self._shelf(td, self.BUILT, self.BUILT) + + self.assertFalse(shelf.outdated("deployed")) + + def test_latest_may_serve_its_previous_build_while_rebuilding(self) -> None: + with TemporaryDirectory() as td: + shelf = self._shelf(td, self.BUILT, self.STAGED) + + self.assertFalse(shelf.outdated("latest")) + + if __name__ == "__main__": unittest.main()