From cbca27f8b296efe9b03fd6740eb822a739d592ae Mon Sep 17 00:00:00 2001 From: Dimitrie Hoekstra Date: Mon, 7 Sep 2026 18:03:31 +0200 Subject: [PATCH] test: pick the newest handbook commit by author date, not by traversal order The handbook recent-changes test asked git for `log -1` and asserted that weeks[0] was that commit's week. Those are two different commits whenever a change is authored before, but lands after, another one. git ranks traversal by COMMIT date. getHandbookChanges buckets weeks by AUTHOR date and sorts on it, which the module already documents and does deliberately. So the two agree only while author dates happen to be monotonic with merge order: any rebase breaks it, and so does an ordinary PR that sat open while a later-authored one merged ahead of it. Caught while rebasing another branch: the tip was authored 2026-09-03 while the newest handbook change was authored 2026-09-07, putting the test's "latest" and the module's weeks[0] in different weeks. Nothing was wrong with the module. The test now parses the full log and takes the maximum author date, which is what weeks[0] is built from. Ties on a date are harmless, since same-date commits share a week. Worth knowing: this never failed CI. git is not on the PATH in that job, so getHandbookChanges takes its documented git-unavailable path and the assertions never run. The failure is only reachable locally, which is where it was found. --- nuxt/server/lib/handbookChanges.test.mjs | 43 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/nuxt/server/lib/handbookChanges.test.mjs b/nuxt/server/lib/handbookChanges.test.mjs index 57b8599663..623eca8793 100644 --- a/nuxt/server/lib/handbookChanges.test.mjs +++ b/nuxt/server/lib/handbookChanges.test.mjs @@ -147,18 +147,39 @@ test('getHandbookChanges produces well-formed, newest-first weekly data', () => }) test('the actual latest handbook commit appears in the most recent week', () => { - // Ask git directly (independent of handbookChanges.mjs) for the single most - // recent commit that touched a tracked handbook file, and confirm it shows - // up in weeks[0]. Asserting against a hardcoded PR number here would rot the - // moment anyone else edits the handbook, since "most recent" keeps moving. - const latest = execFileSync('git', [ - 'log', '--no-merges', '-M', '-1', '--name-status', '--date=short', - '--pretty=format:%H%x1f%ad%x1f%s', + // Ask git directly (independent of handbookChanges.mjs) for the handbook commit + // with the newest AUTHOR date, and confirm it shows up in weeks[0]. Asserting + // against a hardcoded PR number here would rot the moment anyone else edits the + // handbook, since "most recent" keeps moving. + // + // Not `git log -1`. That returns the newest commit in traversal order, which git + // ranks by COMMIT date, while getHandbookChanges buckets weeks by author date and + // sorts them on that. The two diverge whenever a commit is authored before, but + // landed after, another one - so after any rebase, and after any PR that sat open + // while a later-authored one merged ahead of it. Using -1 here made this test fail + // for a reason that had nothing to do with the module: the branch tip was authored + // 2026-09-03 while the newest handbook change was authored 2026-09-07, two + // different weeks. Pick the maximum author date, which is what weeks[0] is built + // from. + const RECORD = '\x1e' + const log = execFileSync('git', [ + 'log', '--no-merges', '-M', '--name-status', '--date=short', + `--pretty=format:${RECORD}%H%x1f%ad%x1f%s`, '--', 'nuxt/content/handbook', 'src/handbook' - ], { cwd: process.cwd() }).toString() - - const [header, ...fileLines] = latest.split('\n').filter(Boolean) - const [sha, date, subject] = header.split('\x1f') + ], { cwd: process.cwd(), maxBuffer: 64 * 1024 * 1024 }).toString() + + const parsed = log.split(RECORD).filter(chunk => chunk.trim()).map(chunk => { + const [header, ...files] = chunk.split('\n').filter(Boolean) + const [sha, date, subject] = header.split('\x1f') + return { sha, date, subject, files } + }) + assert.ok(parsed.length > 0, 'git reports at least one handbook commit') + + // Ties on the same date are fine: any commit from that date lands in the same week, + // and the per-page assertions below only need one of them. + const newest = parsed.reduce((a, b) => (b.date > a.date ? b : a)) + const { sha, date, subject } = newest + const fileLines = newest.files const prMatch = subject.match(/\(#(\d+)\)\s*$/) const files = fileLines.map(line => line.split('\t')).map(parts => parts[0].startsWith('R') || parts[0].startsWith('C') ? parts[2] : parts[1]