Skip to content

fix: flush cache writes before tap removes the fixture dir [ci full-matrix] - #1897

Merged
ruyadorno merged 1 commit into
mainfrom
fix/flush-cache-before-fixture-cleanup
Sep 24, 2026
Merged

ruyadorno merged 1 commit into
mainfrom
fix/flush-cache-before-fixture-cleanup

Conversation

@ruy-bot

@ruy-bot ruy-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What

Test - macOS - 22.x has been red on every release PR run since Sep 23 (#1894 is the fifth in a row) and on 2 of the last 5 pushes to main, always with the same shape:

# error thrown in teardown
not ok N - ENOTEMPTY: directory not empty, rmdir '…/.tap/fixtures/<subtest>/registry-client'

A different subtest loses the race each time — 7 distinct ones so far across package-info/test/{index,capabilities}.ts and registry-client/test/{index,revalidate-entry}.ts, once on Ubuntu too. It is not a macOS regression and not the release bump: release is main + version strings, and the passing main run and the failing #1894 run had the same runner image (macos-26-arm64 20260907.0351.1), Node 22.23.3, vlt and lockfile.

Why

RegistryClient.request() hands the response to cache.set(), which writes to disk in the background (mkdir → writeFile tmp → rename, tracked in Cache#pending; cache.promise() awaits it). The subtest returns without flushing, @tapjs/fixture's cleanup runs rimraf(dir) — native fs.rm with maxRetries: 0 — and when a write lands between its readdir and the final rmdir, the rmdir throws ENOTEMPTY. tap rethrows EOF-hook errors onto the parent test, which is where the duplicated subtests and off-by-N movingRequests assertions further down the log come from. The slow disks on the arm64 macOS runners just make the interleaving common.

#1593 fixed the same thing in the integrity tests in April. #1876 added ~10 subtests that each client(t) → fetch → return without flushing, and never ran on macOS before merging (macOS is excluded from the matrix on ordinary PRs).

The non-obvious part

Checked against the repo's tap (@tapjs/core 4.5.9, @tapjs/fixture / @tapjs/after / @tapjs/after-each 4.3.11): both t.testdir() and t.teardown() wrap t.onEOF by calling the previous hook first, so hooks run in registration order. A t.teardown() added after t.testdir() runs after the dir is already gone, and so does a parent t.afterEach(). That is why registry-client/test/index.ts's afterEach flush ("always wait for the cache to resolve before trying to clean up") was not protecting anything — its forceRevalidate bypasses fresh cache entries hit the same ENOTEMPTY on the v1.1.1 release PR on Sep 20.

Changes

  • package-info/test/index.ts — the ?stable block's client(t) helper hooks the flush before t.testdir(), covering all of its subtests at once.
  • package-info/test/capabilities.ts — same helper shape; client() now takes the test. The shared-cache test flushes its second client explicitly.
  • registry-client/test/index.ts — the afterEach flush moves into a t.teardown() hooked before t.testdir() in beforeEach, so it actually runs first.
  • registry-client/test/revalidate-entry.ts — explicit await rc.cache.promise() in the one test there that didn't have it.

[ci full-matrix] in the title so macOS runs on this PR.

Verified

  • tap for package-info (291/291) and registry-client (843/843), tsc --noEmit, eslint and prettier on the touched files — on Linux.
  • Hook ordering, with a 3-case tap test against the same tap version: teardown after testdir() → dir already removed; teardown before testdir() → dir still present; parent afterEach → dir already removed.
  • Not reproduced on macOS locally (this was investigated from a Linux box); the macOS job on this PR is the real check.

Evidence — macOS job on code that includes #1876

run branch subtest that hit ENOTEMPTY
35929530891 release stable › an exact version asks for it too
35934073950 main (#1881) registry-client revalidate-entry.ts › re-requests the representation it was given
35934257337 release stable › selectors a prerelease can answer… › a dist tag
36025411630 main (#1879) stable › asks optimistically before the document lands
36025652117 release stable › selectors… › the any range — and Ubuntu: capabilities.ts › reset clears the settled document too
36043038907 release stable › an exact version asks for it too; stable › selectors… › a bare name
36054844431 release (#1894) stable › packument() answers with every version

macOS: main 3 ✓ / 2 ✗, release 0 ✓ / 5 ✗. Unblocks #1894 — release.yml re-cuts the release branch on the next push to main.

…atrix]

RegistryClient.request() hands each response to cache.set(), which
writes to disk in the background. Subtests that fetch and return without
awaiting cache.promise() race @tapjs/fixture's cleanup: rimraf (native
fs.rm, no retries) readdirs the dir, a write lands, and the final rmdir
throws ENOTEMPTY. tap reports it as "error thrown in teardown" and
rethrows onto the parent test, which is where the duplicated subtests
further down the log come from. The slow disks on the arm64 macOS
runners make the interleaving common: Test - macOS has failed every
release PR run since #1876 landed, 2 of the last 5 pushes to main, and
Ubuntu once, each time on a different subtest.

tap runs EOF hooks in registration order, so a flush only runs before
the cleanup if it is hooked before t.testdir(). A t.teardown() added
after t.testdir(), and a parent t.afterEach(), both run once the dir is
already gone; registry-client's afterEach flush was not protecting
anything.

- package-info: the ?stable block's client(t) helper and capabilities'
  client() hook the flush before t.testdir(), covering every subtest
- registry-client: the afterEach flush moves into a teardown hooked
  before t.testdir() in beforeEach; revalidate-entry gets the explicit
  await the neighbouring tests already have

Co-authored-by: Ruy Adorno <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01W7bVD3WnCopm6LTiLqQMff
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Sep 24, 2026 9:26pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4bc8c973-0606-40fa-af93-4c4cb01421dd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🐰 Bencher Report

Projectvltpkg
Branchfix/flush-cache-before-fixture-cleanup
Testbedubuntu-latest

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
vlt install: vue & lockfileLatency
seconds (s)
📈 plot
🚷 threshold
🚨 alert (🔔)
4.17 s
(+12.32%)Baseline: 3.72 s
4.09 s
(102.11%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
vlt install: vue & cache-lockfile📈 view plot
🚷 view threshold
1,221.38 ms
(-10.39%)Baseline: 1,362.99 ms
1,499.29 ms
(81.46%)
vlt install: vue & cache-lockfile-node-modules📈 view plot
🚷 view threshold
302.55 ms
(-13.41%)Baseline: 349.41 ms
384.35 ms
(78.72%)
vlt install: vue & clean📈 view plot
🚷 view threshold
11,293.10 ms
(+5.14%)Baseline: 10,741.21 ms
11,815.33 ms
(95.58%)
vlt install: vue & lockfile📈 view plot
🚷 view threshold
🚨 view alert (🔔)
4,172.80 ms
(+12.32%)Baseline: 3,715.13 ms
4,086.64 ms
(102.11%)

🐰 View full continuous benchmarking report in Bencher

@ruyadorno
ruyadorno merged commit c802826 into main Sep 24, 2026
20 checks passed
@ruyadorno
ruyadorno deleted the fix/flush-cache-before-fixture-cleanup branch September 24, 2026 21:37

This branch was successfully deployed

1 active deployment
Preview — 7bcbcd1b Deployed Sep 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant