Repository navigation
Replace archiver with tar-fs and tar-stream - #1652
Open
cristianrgreco wants to merge 8 commits into
Open
cristianrgreco wants to merge 8 commits into
cristianrgreco wants to merge 8 commits into
Conversation
archiver 7 pulls in archiver-utils, whose glob and minimatch carry advisories, and archiver 8 is ESM-only. Build copy archives with tar-fs, already a runtime dependency, and tar-stream instead.
…rs-node into replace-archiver-with-tar-fs # Conflicts: # package-lock.json
…nd special files Copy a directory passed as a file as an empty directory, add content before directories so a directory entry wins over content with the same target, and skip FIFOs and sockets instead of failing.
…rs-node into replace-archiver-with-tar-fs # Conflicts: # package-lock.json # packages/testcontainers/package.json
cristianrgreco
marked this pull request as ready for review
November 19, 2026 13:42
zigordev
added a commit
to zigordev/toolkit
that referenced
this pull request
Nov 23, 2026
) ## What Step 4.1 of the build plan: the new package `@zigordev/test`, private for now. - `@zigordev/test/postgres`: one PostgreSQL 18 container per test run, started through Testcontainers. A global setup migrates a template database once, and `useTestDatabase()` gives each test file its own copy, dropped after the file. - `@zigordev/test/app`: the harness for API tests. `useApp()` builds an app once per file and closes it after. `captureLogs()` keeps the log lines and finds events. `expectProblem()` checks an error answer: the status, `application/problem+json`, the code, and exactly the fields of the platform's error format. - Tests that need a container live in `*.db.test.ts`, in a Vitest project named `<name>:db` from a `vitest.db.config.ts`. `pnpm check` runs them. `pnpm check:quick`, which the push hook runs, now leaves them out with `--project '!*:db'`. ## Why The test rules ask for API tests on a real PostgreSQL, and for every test file to get its own copy of the migrated database. Without one shared package, each service would write its own container start, copies and clean-up. Steps 4.2 and 4.3 build on it. ## The override, and the owner's exception Testcontainers 12.2.2, the newest release, brings `glob` 10.5.0 through `archiver` 7 and `archiver-utils`, with the flaw [GHSA-3g3m-2fjr-6pw4](GHSA-3g3m-2fjr-6pw4), medium, published 2026-10-30. Record 0033 was followed in its order: 1. **Update the package that brings it in.** Not possible yet. The maintainer's own fix, testcontainers/testcontainers-node#1652, replaces `archiver`. It was still open on 2026-11-23. 2. **Do without it.** Not possible. Testcontainers loads `archiver` when it starts: an override that removed it failed every test with `MODULE_NOT_FOUND`. `archiver` 8 drops `archiver-utils`, but brings `minimatch` 10.2.6, which has its own flaw, GHSA-g3hv-75wg-m249. 3. **Replace the flawed package.** `archiver-utils>glob: 14.0.6` under `overrides`. `pnpm audit` then finds nothing, and every test passes. **This is an exception to the one-month rule.** `glob` 14 is a new major version, first released on 2026-10-27, so the override would have waited until 2026-11-27. On 2026-11-23 the owner was asked "Let toolkit#64 wait until 2026-11-27, keeping the one-month rule?" and answered, in their words: "Merge it now". Why the risk is low: Testcontainers uses `archiver`, and through it `glob`, only to copy files into a container, which nothing here does. Every test of the package passes with `glob` 14, on this Mac and in CI. When the line goes: when a release of Testcontainers drops `archiver`. From 2026-11-27 it is no longer an exception. The README of `@zigordev/test` and the new table "The overrides in force" on the handbook page Dependency updates both say so. ## How it was tested - `pnpm check` passes: 665 tests, 99.3% of lines covered, in 29 seconds on this Mac with Docker Desktop. - The database tests ask the server for its version, and pass only on PostgreSQL 18. They prove that copies never see each other's rows, that five copies can be made at once, that a copy drops while a client still holds it, that the template refuses clients, that a client left open by `prepare` does not block a copy, and that a failing `prepare` stops its container. - `vitest list --project '!*:db'` lists 536 tests and none from a `*.db.test.ts` file. - The package was packed and installed into an empty folder outside the repo, with the README's settings. Its example ran there: a copy of the template, and `expectProblem` on an answer. That trial found that Testcontainers also needs `protobufjs: false` under `allowBuilds`, and the README now names all three. ## Observability Nothing runs in production. A test run starts one PostgreSQL container and Testcontainers' clean-up container, and both are removed when the run ends. ## Docs - `packages/test/README.md`, with the five headings. - A new handbook page, `docs/handbook/tests.md`, listed as page 14 of the reading order. - `CLAUDE.md`: the new folder, and what `check:quick` leaves out. - `docs/handbook/dependency-updates.md`: a table of the overrides in force, and when each goes. ## Follow-ups - Remove the override once Testcontainers drops `archiver`. - A repo that installs `@zigordev/test` needs three lines under `allowBuilds` and, until then, the override line. The README says so.
This branch has not been deployed
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.
Summary
Replaces
archiverwithtar-fs(already a runtime dependency, used for image builds) andtar-stream(already in the tree throughtar-fs) for copying files, directories and content into containers.archiver@7pulls inarchiver-utils, whoseglob@10andminimatch@9carry advisories that failnpm auditfor every consumer (#1641). There is no fix in range:archiver-utilshas had no commits since October 2024, andarchiver@8dropped it but is ESM-only, which breaks Jest users (#1365, #1366).tar-fsandtar-streamare CommonJS.createArchive(generic-container/create-archive.ts) builds one tar stream:tar-fs.pack, all writing into one sharedtar-streampack (pack,finalize: false)pack.entry. AReadableis buffered first, asarchiverdoes, since a tar header needs the size up fronttar-fsdoes the directory walking and header encoding. The helper sets a few options so archives match whatarchiverproduced:umask: 0tar-fsapplies the process umask,archiverdoes not; without it a666file is copied as644entriestar-fsotherwise adds an entry for the copied directory itself, which changes the target's permissions (copying into/tmpmade it700)dereference: truefor filesuid/gid0archiverwrote them\to/, drive letter and leading/removed,..and//resolvedarchiverdid. A Windows user building a target withpath.join("/app", "x")gets\app\x, which would otherwise be copied as a file literally named\app\x0755on Windowsarchiverdid, becausefs.staton Windows doesn't report usable directory permissionsignorechildren for fileswithCopyFilesToContaineris copied as an empty directory, asarchiverdid, instead of being walkedarchiveradded content synchronously and directory entries asynchronously, so a directory entry won over content with the same targetstrict: falsetar-fsalways skips sockets), which is whatarchiverintended (in practice it hung on them, see below). Checked in the scenario run rather than a test, since creating a FIFO needsmkfifoThis also removes
archiver,@types/archiver, their Dependabot ignore entries, and their subtree (archiver-utils,glob,minimatch,zip-stream,compress-commons,readdir-glob, …) from the runtime dependencies.npm audit --omit=devgoes from 5 moderate findings to 0.require("archiver")took about 60 ms against about 6 ms fortar-fs(#1577).Earlier attempts were closed over complexity: #1246 moved content to the filesystem, and #1370 owned the tar walking and headers. Here, content stays in memory and
tar-fsowns the walking.Closes #1641
Verification
npm run format,npm run lint,npm run knip,npm run check-compiles: passgeneric-container.test.ts -t "copy|Copy": 20 passed (13 existing copy and ownership tests, 7 new). The missing-directory test pins an intended behaviour change: it resolves onarchiverand rejects withENOENThereWindows-style targets (
path.win32.join("/tmp", "nested", "test.txt"),C:\tmp\drive\test.txt): the new test fails before the normalization (catexits1, the files don't exist) and passes with itFile and content targets ending in
/: the new test fails without the check (promise resolved "undefined" instead of rejecting, and Docker replaced the existing/tmp/dirwith the file) and passes with it, leaving the directory in placeNew tests cover a directory with hidden files, an empty directory, a symlink and a
666file; the target directory's permissions staying unchanged; andReadablecontent. Evidence that they pin the existing behaviour:main'sarchivercode: the directory, target-permission, Readable and ownership tests pass. The failing-Readable test hangs there, because that is an archiver bug (see the scenario table)umask: 0removed: fails,expected '644' to be '666'expected '755' to be '1777'Comparing archives built by
archiverand bycreateArchivefrom the same inputs (files, mode overrides, symlinked source, nested and empty directories, dotfiles, symlinks inside a directory including a broken one,600/666/755/777/setgid modes, string/Buffer/Readable content, relative symlinks): extracted trees identical in content, type, mode, size and link targetRan 20 user scenarios through both
archiver(main) andcreateArchiveagainst a real container and compared the resulting files, types, modes, owners, link targets and checksums:/0ENOENTarchiverhangs forever; now skippedarchiverhangs forever and raises an unhandled error; now rejects with the errorarchiversilently copies nothing; now rejects withENOENT, as a missing file already didJest 30 CommonJS runtime against the built package: copying files, directories, string and Readable content works. The build also loads with
requireand ESMimport.Archiving a 500 MB directory locally: 412 ms and 118 MB peak RSS, against 561 ms and 158 MB with
archiver. Both stream without holding file contents in memoryPublish dry run: https://github.com/testcontainers/testcontainers-node/actions/runs/43711875356
On Windows, libuv's
fs.statreports directories as0666, or0444when read-only, with no execute bit (src/win/fs.c).tar-fsonly checks the platform when extracting, so without the Windows line, directories copied from Windows would have no execute bit and couldn't be entered by a non-root user in the container.archiverforced0755, and Docker's own client also adds execute bits when packing on Windows (chmodTarEntry). The line is checked against those sources but hasn't been run on Windows: CI has no Windows runner with Linux containers.Not breaking
No public API changes, and the copy methods' types are unchanged. Behaviour matches
archiverexcept:archiverhung, or silently ignored a missing directory, now reject with the underlying error/(or empty) rejects withTarget "…" must be a file path.archiverhung on it for files and threw for content. Without the check, Docker replaces an existing directory at that path with the file. This also covers a directory passed as a file with such a target, whicharchivercopied as an empty directorymodeoncopyDirectoriesToContainerfor a started container is now applied, as it already was forwithCopyDirectoriesToContainer.archiverwas never passed it theredocker cpdoes.archiverrewrote them relative to the host directory, so a link to an absolute path inside the copied directory used to resolve in the container and now doesn't, while a link to a system path such as/etc/hostsno longer depends on how deep the host directory was. Relative symlinks, the usual case, are unchangedRuntime dependencies stay CommonJS.
tar-streambecomes a direct dependency oftestcontainersat the same range@testcontainers/k3salready uses.