Repository navigation
site-compare: the last review's nits (canonical check, site address spellings, redirect scripts, warning numbers) - #131
Merged
Merged
Conversation
- canonical is its own check, never lag: a site's configuration sets a page's canonical link, never a lecture. - A site's own address in any spelling: host case, a default port, a protocol-relative URL, a double slash after the prefix (which resolved outside the build). A directory-style canonical (.../sub/) gives the site's address too. On a site under a path, a root-absolute path outside it names no file of the build. - A script is a redirect stub's only if it redirects to the variable it sets: plotly's bundle sets target="_blank" and reads location.href. - In a warning's message, numbers are set aside only as whole tokens, so float64, log10 or h5py are part of the message. - 19 tests, each checked against a mutation of its guard (all 17 fail a test); 94 tool tests; the intermediate calibration is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
…d its unpinned guards - Warnings: a number may be followed by a full stop or a unit again, so a run-to-run value that ends a sentence (error = 3.2e-05.) or carries a unit (512MB) is set aside, as the owner's rule says; digits inside a name (float64, h5py) still block, and a version (1.2.3) is kept whole. - Tests for guards no test pinned: a normalise entry on canonical; the canonical reported under canonical alone; a double slash after a site's path in a root-absolute link; each form of a redirect script; values before a full stop and with units; a version's middle digit. - Nits: index pages matched exactly (not genindex.html); a port is a default only for its own scheme; root-absolute figures resolve under a site's path; dead branches gone. - 108 tool tests; every mutation of the review's list fails one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
… and two of its nits - Warnings: a number is matched whole or not at all, so a version keeps every part (1.10.0 against 1.20.0, numpy 1.26.4 against 2.16.4 block). Only a size or factor unit goes with a number (512MB, 2.5x), so a word that starts with digits (2D, 64bit) stays in the message; and digits after a hyphen in a name (utf-8, x86-64) stay too. - The value tests now differ in their last digit (600 against 601), which a pattern that stops early would not set aside. - figures leaves a figure at an absolute address to targets, which compares with the reference, so one missing from both builds is no difference. - 115 tool tests; each mutation of the new pattern fails one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
mmcky
added a commit
that referenced
this pull request
Dec 3, 2026
Two checks that QuantEcon/project-monorepo#26 asks of `tools/site-compare` and that it lacked: the PDF book, and a GPU site's CPU fallback. This PR also takes in the nits left from #131's review. **`pdf`: the PDF book** (`_pdf/*.pdf`, when both builds have one), a port of the hand validation's `pdf-compare.py`. - **The outline, in order.** The book is read by its outline's top two levels: parts and lectures. A section lost, added, typeset twice or moved blocks. A title that comes again (two "Notes") is matched by its occurrence. Keys keep digits, so advanced's "How to Pay for a War: Part 1/2/3" stay three sections. A book with no outline is compared whole, as one section, from its first page. - **Each section's text, by its letters.** Letters of any script count, maths italic and Greek included. Digits, spacing, line breaks and hyphenation are set aside, since pypdf's extraction drops some spaces. - **What is set aside, in pypdf's real shapes:** - each page's running header (the first line most pages share: the book's title); - its footer, the page's last line ("82 Chapter5. Title" on an even page, "5.9. Section 83" on an odd one), or the same footer glued onto the last line of text, as pypdf can give it (`init).block_until_ready()46 Chapter4. Title`), only straight after a character that is neither a space nor a digit; - code blocks' continuation notes; - timing lines, memory addresses and environment paths; - a line that is a date and time and nothing else, as `nvidia-smi`'s first line is ("Mon Nov 9 03:15:37 2026"); a date inside prose is still prose; - every line of the lecture's executed output, as its HTML pages show it, unless the pages' prose has it too; - a chunk moved by a page break, such as a float's caption, each move paired once. - **Lag.** A section's difference is on page `_pdf/<book>.pdf#<slug>`: the lecture whose `h1`, less its chapter number, the section's title names. So it can be lag, and an entry can name it. A section with no lecture page, such as LaTeX's own Bibliography, is keyed by its title. - **Page count.** Reported only. - **pypdf.** The PDFs are read with pypdf 7.2.0, which is in the script's header (Python 3.10 or later, pypdf's floor) and in `tests.yml`. If two PDF books are present and pypdf is missing, the run fails (exit 3) rather than skipping the check. **`gpu`, with `--gpu`.** For a site that builds on a GPU, these block, and are never lag: - **A page whose outputs show a CPU fallback:** - JAX's "falling back to cpu", "No GPU/TPU found", a CUDA-enabled jaxlib missing, or a backend that failed to initialise; - NVML failing; - `nvidia-smi` failed or not found, in bash's or zsh's words; - "No devices were found". - **A page whose reference outputs show the GPU while its own show none.** The GPU markers are a JAX GPU device in its current or older names, `cuda:0`, the `nvidia-smi` table, and "JAX backend: gpu", which back_prop and the status pages print. A fallback blocks even when the reference fell back too. The shadow workflow (QuantEcon/project-monorepo#80) is to pass `--gpu` for the matrix's `gpu` leg. **The shared list** gains one entry. The PDF's Bibliography is the merged bibliography typeset by LaTeX, so its months are dropped and its entries corrected there too, as on `zreferences.html`. **From #131's review:** - A malformed figure address (`http://[`) no longer fails the run (exit 3). - An address (`0x…`) must start a token, and a size (`1000x800`) counts as two values. - In a warning's message, these are now values: glued units (`kB`, `GHz`, `h`, `μs`, `s`, `it/s`, `512M`) and fractional seconds. - The unit pattern's alternatives are pinned by tests. - Left for the owner: whether a hyphenated range (`1-2`) is a value. **From Copilot's review** (requested by the maintainer, at `fba4703`; fixed in `9ff14a6`). Copilot made three points, each now fixed with a test: - **A size ending a sentence in a warning** ("figure is 1000x800.") is now values, as a number already was. A dot followed by digits still doesn't end it. - **The PDF's address rule no longer starts an address straight after a digit**, so a size's x ("1000x800") stays text. Copilot proposed WARN_NOISE's token-start guard, but that would keep the addresses pypdf glues to a word ("at0x7f3a2b"). So the guard is a digit, and a full address (8 hex digits or more) glued to a number still goes. - **Output lines are set aside before difflib aligns a section's lines**, so one can't anchor the alignment and split the same prose into a change. The letters are then compared again. **Calibration on intermediate.** I compared release `publish-2026nov30b` with the monorepo's build at `9728988` (site-build run 47031722447), with `--gpu` and `--lag newton_method`: - **The two PDFs:** 4012 pages and 186 sections each. - **Sections that differ:** - `newton_method`, which changed upstream: lag. - The Bibliography: expected. - Finite Markov Chains and Job Search IX differ only in executed output, which is set aside. - **GPU:** no fallback on any page. - **Totals:** 2 defects, 11 expected, 6 lag, 48 reported. The 2 defects are #45's two notebooks in that build, which predates #136. - **Time:** reading the two PDFs adds about 75 s. **jax** (release `publish-2026nov11` against the monorepo's build in the same run). This was not a matched pair, so most of its PDF rows are lag. `nvidia-smi`'s date line had raised 11 false defects there and put dates into 5 more sections. With the date rule there are none, and nothing new appears. One more false row came from a footer glued onto a page's last line (newtons_method, whose page break moved); stripping a glued footer removes it, and changes nothing else on jax, intermediate or dp. Intermediate's calibration had missed it only because both its builds ran on a Thursday in November. **dp** builds no PDF, and its comparison is unchanged: 0 defects with #137's lists. **Tests.** `tools/tests/test_site_compare.py` has 113 new tests (45 functions, the rest parametrised cases), on PDFs a small writer in the test file makes in pypdf's real shapes: - **The outline:** a section lost, added, typeset twice or moved; a title that comes twice, compared by occurrence (a change in the second is found); only the top two levels as sections; two sections starting on one page; no outline at all, read from its first page. - **The text:** - changed prose on its lecture's page, as lag too; - a paragraph lost or added; - non-ASCII, maths italic and Greek letters; - same-titled numbered sections; - a lecture typeset twice, or titled with a year, keeping its lecture page. - **What is set aside:** - digits and line breaks, however difflib aligns the lines; - timings (and `it/s`), addresses, paths under each environment prefix, and run-date lines (every weekday and month, spaceless, without seconds); - footers glued to a page's last line, even and odd; - a page break more, with its header, footer and both continuation notes; - a moved chunk, paired once each way, and a replaced one that is not a move. - **What isn't set aside:** - prose that looks like noise ("Chapter 6 of the book", "has elapsed", "Wall time:", "continued from previous page", a date inside a sentence); - a page's last line not in a footer's shape, including "3 Chapter 5 …", "1.2. We use Python 3.10" and prose ending in a number after a space; - a glued footer's shape inside a page; - a footer-shaped heading inside a page; - the book's title as prose, or as the start of a first line; - a first line shared by fewer than half the pages; - letters glued to a memory address. - **Executed output:** - set aside, including a line inside a longer output; - but not when either build's page has it as prose, or when it has fewer than eight letters (seven is too few). - **Also:** the page count, the Bibliography's entry, and no pypdf. - **GPU:** each fallback shape and each marker, blocking and never lag; each fallback line reported on its own, and one printed in several cells giving one line. - **Also in the text:** a change of case alone is a change. - **#131's nits.** - **Copilot's three points:** a size ending a warning's sentence; a size in a PDF line, spaced and glued; a full address glued to a number; an output line that would anchor the alignment. **Mutations,** run with `PYTHONDONTWRITEBYTECODE=1`, each mutant first checked to parse. The last round ran 113 across five sets (mine and the reviews'; two appear in two sets), and 107 fail a test. The other six: - two let the `JAX backend` marker match more widely, which on real outputs changes nothing; - two change which build's h1 names a lecture's page for lag, or which of two same-titled pages is used; - two are the same equivalent mutant: reading the footer from the page's last line rather than the body's. For Copilot's fixes, the delta review ran 10 mutations and caught 8 (mine ran 7 and caught 5). Two survive: - **The size's lookahead without its dot-digit clause.** It is more lenient only on a token like "2x3.5", which no warning prints. - **The second early return in `section_changes`.** `9ff14a6`'s message calls it a shortcut that gives the same empty result, but that is wrong. With the output lines gone, a repeated prose line can anchor the alignment. For example, `["wage", "iswage"]` against `["wageis", "wage", <an output line>]` gives no change with the return, and a change without it. No test covers it yet; it is the first item below. The full suite, with CI's packages and pypdf, on the branch with main merged in, gives 864 passed, 1 skipped (the skip is a case-insensitive file-system test on macOS). **Left for a follow-up** (the last reviews' nits; none changes a letter read from the four real PDFs): - A test for `section_changes`' second early return (the case above). - A PDF test for an address glued to a word with fewer than 8 hex digits ("at0x7f3a2b"), the reason the address guard is a digit. - The address rule's 8-hex branch also strips a word starting with a–f letters glued straight after a size whose first dimension ends in 0 ("1000x800faded"), while "1024x768faded" keeps its x. matplotlib writes "with" after a size, so this is recorded, not fixed. - The glued-footer rule's limits have no test: its digit exclusion, the odd and even shapes' exact parts, and its `$` anchor. The same goes for the date rule's weekday, month and year shapes. - A footer glued straight after a whole number with a space before it (`x = 45` + `46 Chapter4. Title`) isn't stripped. It would block, never hide. - A page's last line with a three-part version number ending in a dot (`Python 3.10.1. Then it said 5`) loses its tail. None occurs in the real PDFs. Requiring a glued footer's page number to be the page's own printed number would close both gaps. - The Bibliography and Index pages' own running footers aren't stripped (their section is on the shared list). - Two tests could be clearer: the case-only test's expected lines, and the glued-footer test's reference lines. **Not compared.** - The title page and contents, before the first section: the title page carries the build's date. (A book with no outline is read whole, so its date shows and it blocks; Sphinx always writes an outline.) - A number or punctuation that changes only in the PDF (the HTML text check compares numbers in prose). - A PDF line that matches the lecture's executed output in either build, unless it is also prose. - A traceback that shows only in a lagging lecture's PDF section would be lag, though a strict PDF build (`-W`) mostly prevents one. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The last review of #129 (Opus, at
3bb3e97) found nothing blocking: "ready with nits". This pull request carries those nits, for QuantEcon/project-monorepo#26.What changes in
tools/site-compare:canonicalis its own check, and never lag. A page's canonical link comes from the site's configuration, never from a lecture, so a change on a lag page is still a defect. It was a line oflinksin tools/site-compare: a monorepo site build against a series' own build, every difference classified #129.:443), a protocol-relative URL (//host/…), and a double slash after the site's path, which resolved outside the build. A directory-style canonical (…/sub/) gives the site's address too.quantecon.github.io/lecture-dp/), a root-absolute path outside that path names no file of the build. Live, it would point at another site on the same host.location.replace(target),location = target). plotly's bundle setst.target="_blank"and readslocation.href, so an inlined plotly gave a falseredirectsdefect.float64,log10,utf-8,2D) and a version (1.10.0) are part of the message, and a different one blocks.After this PR's review (
3e64c1b). The review found one should-fix: the token boundary refused a number before a full stop, so a value ending a sentence (error = 3.2e-05.) blocked again, against the owner's rule. It also found guards no test pinned.512MB,2.5x), which goes with it. Thenb2c4eee, after the delta review: a number is matched whole or not at all, so a version keeps every part (1.10.0against1.20.0blocks). Only listed units go with a number, so2Dor64bitstays in the message, and so do the digits of a hyphenated name (utf-8). The value tests now differ in their last digit.targets, which compares with the reference, so one missing from both builds is no difference.genindex.html.Tests: 40 new, 115 in
tools/tests/test_site_compare.py. Each pins a guard the reviews found untested, or one added here. Each was checked against a mutation of its guard. The last review (atb2c4eee, ready with nits) found six mutations of the number pattern that no test catches yet: dropping thexor bareBunit or theiofGiB, narrowing the size prefixes, dropping the sign, and a letters-only hyphen guard. They go, with its other nits, into the next change to the tool: an unguardedurlspliton a malformed figure address,0xmatching inside1000x800, and a few glued units not on the list (kB,GHz,1.2h,μs). The full suite gives 652 passed, 1 skipped.Calibration: the intermediate comparison of #129 is unchanged, item for item: 6 defect, 6 expected, 5 lag, 48 reported.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG