Skip to content

fix(dashboard): build the image from the lockfile and compare it in CI - #498

Closed
Alajmah wants to merge 1 commit into
masterfrom
fix/dashboard-image-lockfile-v3
Closed

Alajmah wants to merge 1 commit into
masterfrom
fix/dashboard-image-lockfile-v3

Conversation

@Alajmah

@Alajmah Alajmah commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Status

Create only. Merge and deploy are on hold until the diff and the build test are reviewed.

This supersedes #495. It is the same change with one addition: the answer to a review finding on #495, which was correct and needed a code change. A branch cannot be updated here, so the fix is in a new branch.

What this changes

The dashboard image was not built from the lockfile. packages/web-dashboard/Dockerfile copied only package.json into its build context and ran npm install, which resolves dependency ranges on the day of the build. This PR makes the image install from package-lock.json, the way the app image does, and adds a CI check that compares the packages inside the built image with the lockfile.

What the current build holds

I listed every package in the running production dashboard container (read-only) and checked each against the lockfile on master. The container holds 16 packages. Three versions are in no lockfile entry:

Package In the production container In the lockfile on master
@next/env 16.4.6 16.3.3 only
semver (top level) 6.3.2 not present
semver (under sharp) 7.8.6 not present

The Dockerfile as it is on master reproduces this: a local rebuild of it, compared with the master lockfile by the new check, reports the same three.

Root cause of the @next/env difference

The lockfile entry for the dashboard's next 16.4.6 recorded the dependency ranges of 16.3.3, and the @next/env entry beside it was still 16.3.3. npm ci and npm ls accept that, because they compare the recorded ranges with the lockfile and not with the registry.

Lockfile change

Two entries repaired from npm's own resolution of the same versions, on a scratch copy:

  • packages/web-dashboard/node_modules/next: @next/env and the eight @next/swc-* ranges move from 16.3.3 to 16.4.6, and sharp from ^0.35.3 to ^0.35.5.
  • packages/web-dashboard/node_modules/@next/env: 16.3.3 to 16.4.6 (version, resolved, integrity).

The lockfile keeps its 1018 entries. Nothing is added or removed. One installed version changes: @next/env for the dashboard, from 16.3.3 to 16.4.6, which is the version next 16.4.6 declares.

Recorded ranges against the published manifests (registry audit of the dashboard's production tree, 76 entries compared): 10 ranges differ from the published manifest on master, 0 after this PR.

Why not a full regeneration

Approach Entries Changed Added / removed
A. npm install --package-lock-only on the master lockfile 1018 → 1018 0 in the dashboard, 1 elsewhere (packages/demo-dashboard) 0 / 0
B. The same, after removing the stale dashboard entries 1018 → 1017 1 elsewhere 11 / 12
C. This PR 1018 → 1018 2, both under packages/web-dashboard 0 / 0

A repairs nothing: npm trusts the lockfile. B relocates the whole Next family from the dashboard's node_modules to the repository root, which changes the tree shape for every workspace, so it is wider than this unit. C changes only the two stale entries.

Build change

  • Build context is the repository root, because the dashboard's dependencies are locked in the root package-lock.json.
  • Install: npm ci --workspace=packages/web-dashboard --ignore-scripts. One workspace is installed and no lifecycle script runs. The lockfile is satisfied with only the root manifests and the dashboard manifest present, so the other workspaces are not copied into the builder.
  • Dockerfile.dockerignore (new, next to the Dockerfile): an allowlist that admits only what the Dockerfile copies. With the context at the repository root, the repository's .dockerignore would otherwise apply; it excludes *.svg, the public assets the image serves.
  • Three checks run before the install and fail the build when the ignore file is not honoured: no node_modules and no .next from a local checkout, and the svg assets present.
  • next.config.ts: outputFileTracingRoot is the repository root. Next drops every traced file outside that root, and the dependencies now come from the repository root's node_modules.
  • docker-compose.build.yml and the dashboard README describe the same build context.

What changes inside the image

On master With this PR
Entry point /app/server.js /app/packages/web-dashboard/server.js
Build output and public assets /app/.next, /app/public /app/packages/web-dashboard/.next, /app/packages/web-dashboard/public
Packages with a package.json (Linux) 16 20
React versions listed 19.2.4 19.2.4 and 19.2.8

Nothing outside the image depends on those paths: the production compose service sets no command or working directory, and the deploy script checks the dashboard over HTTP.

The second React version comes from the root lockfile and predates this PR: demo-dashboard resolves react to 19.2.8 at the repository root, while the dashboard pins 19.2.4 in its own node_modules. Next's standalone output copies fragments of both. In a local build the root react has 3 files and the root react-dom only its manifest. The only package in the output at the root that requires react is styled-jsx, a dependency of next that this dashboard does not use.

Next loads one React instance. Its build maps every react import to the copy inside the next package for the browser, and the server output reaches React only through one module of its own. I checked this at runtime on a local build: all 25 static pages render server-side with status 200 and no hook error, and two pages hydrate in a browser with no React error.

CI change

  • The three dashboard builds (docker-build-dashboard, release-tooling-validation, publish-release-images) use the repository root as context.
  • The image is compared with the lockfile in all three jobs. In publish-release-images the comparison runs before the image is pushed.
  • scripts/compare-image-deps.mjs lists every package.json under node_modules in the image and fails when a version is in no lockfile entry. A version the lockfile pins only for another workspace is a warning. A package.json that is there and cannot be read as a JSON object stops the check with exit 2; its package is never left out without a word. A directory without a package.json is not a package and is passed over.
  • packages/core/tests/compare-image-deps.test.js holds 23 tests for the script.

What is different from #495

One review finding on #495 was correct: the script skipped a package whose package.json it could not read, so a broken manifest inside the image would have made its package invisible to the check. This PR reports such a file and exits 2. The six new tests for it fail on the script of #495 and pass here. The diff from the #495 commit is the script (35 lines added, 13 removed) and its tests (52 lines added). The Dockerfile, the lockfile, the workflow and the ignore file are byte for byte those of #495.

Review record of #495

Finding of the automated review on #495 Answer
The lockfile repair is not among the changed files, so the image would still get the old @next/env Not so. package-lock.json is one of the nine changed files (13 lines added, 13 removed), and the comparison run on the built image in CI lists @next/env@16.4.6 as pinned
The script skips a package whose package.json cannot be read Correct. Fixed here
Native optional dependencies may be missing from the lockfile Not so. The lockfile holds the Linux binaries: @next/swc-linux-x64-musl 16.4.6 for the dashboard, @img/sharp-linuxmusl-x64 0.35.5 and lightningcss-linux-x64-musl 1.32.0. The Linux build log has no message about a WebAssembly fallback, and the build took 13 s
Installing from the root lockfile pulls every workspace into the image Not so. One workspace is installed, lifecycle scripts do not run, and the runner stage copies only the standalone output, the static files and public. The comparison lists 20 packages in the image
The new gate ships without tests Not so. The tests are in the PR, and the core-tests job ran them

The first review attempt on #495 ended without a review ("could not parse response"). The second gave the five findings above at low confidence. A separate code review by the Codex connector on #495 reported no findings.

Verification

Manual CI run on this branch, commit d1d684c: https://github.com/Octo-Lex/GitWire/actions/runs/45068276144. All 16 jobs passed; publish-release-images is skipped on a manual run by design.

docker-build-dashboard:

Step Result
Build context 1.01 MB (the manifests and the dashboard without its tests: 1,024,088 bytes)
Three checks pass
npm ci 664 packages, 49.8 s
next build 15.8 s
Packages listed in the image 20
Pinned by the lockfile and in the dashboard tree 19
Warning semver@6.3.1 at the root: pinned by the lockfile for another workspace; a lone package.json with no code, which Next's standalone output also wrote into the old image (as 6.3.2)
Boot /dashboard responded

core-tests ran 84 tests on Linux, 23 of them for the comparison script and none skipped.

docker-build-dashboard works on a clean checkout, so its checks show that the ignore file is honoured and nothing more. release-tooling-validation runs npm ci at the repository root before building, which leaves the dashboard's installed dependencies in the checkout. The checks pass there as well, so those dependencies stay out of the build context.

The validator image is not touched by this PR.

Earlier attempts

Branch Commit Run Outcome
fix/dashboard-image-lockfile 0365a92 45062066337 Failed at a check of mine that I had placed after npm ci, which creates the directory the check looks for. Everything before it passed
fix/dashboard-image-lockfile-v2 (#495) 8def80f 45063731937 Passed. Superseded for the review finding fixed here

Both branches are left in place until this PR is merged.

Not verified

  • The image was built on Linux only in CI. I did not run Docker locally.
  • The production dashboard's pages behind the login were exercised against no API backend, so they rendered their empty and error states.
  • publish-release-images does not run on a manual CI run. Its dashboard build and comparison first run after the merge.

Found while working, outside this PR

  • packages/demo-dashboard has the same kind of stale entry: next 15.5.28 with the ranges of 15.5.24. Its 10 recorded ranges differ from the published manifest, unchanged by this PR. Its image also installs with npm install.
  • The bot, docs and plugin-sandbox images install with npm install as well. Of the three images the release pipeline publishes, the app image was already lock-pinned and the executor image has no dependencies.
  • In release-tooling-validation the app image's build context transfers 596 MB, also on master (run 45047105326). The job installs dependencies at the repository root before building. I did not check whether the rehearsal image differs from the published one because of it.

The dashboard image ran `npm install` inside packages/web-dashboard with
only that package.json in the build context. It resolved dependency
ranges on build day and ignored package-lock.json. The image now in
production holds three package versions that appear in no lockfile
entry: @next/env 16.4.6, semver 6.3.2 and semver 7.8.6.

Why @next/env differed: the lockfile entry for the dashboard's next
16.4.6 recorded the dependency ranges of 16.3.3, and the @next/env entry
beside it was still 16.3.3. `npm ci` and `npm ls` accept that, because
they compare the recorded ranges with the lockfile, not with the
registry.

package-lock.json: two entries repaired from npm's own resolution of
the same versions. In the next 16.4.6 entry, @next/env and the eight
@next/swc-* ranges go from 16.3.3 to 16.4.6 and sharp from ^0.35.3 to
^0.35.5. The @next/env entry goes from 16.3.3 to 16.4.6. The lockfile
keeps its 1018 entries; nothing is added or removed. A full
regeneration was not used: with the stale entries removed, npm moves the
whole Next family from the dashboard's node_modules to the repository
root (11 entries added, 12 removed).

packages/web-dashboard/Dockerfile: the build context is the repository
root and the dependencies are installed with
`npm ci --workspace=packages/web-dashboard --ignore-scripts`. The source
is copied before the install, and three checks that run in between fail
the build when the ignore file is not honoured: the repository's
.dockerignore drops the svg public assets and keeps a local checkout's
node_modules and .next in. The standalone output is read from the
workspace directory.

packages/web-dashboard/Dockerfile.dockerignore: an allowlist holding
only what the Dockerfile copies. It replaces the root .dockerignore,
which excludes the svg files under public that the image serves.

packages/web-dashboard/next.config.ts: outputFileTracingRoot is the
repository root. Next drops every traced file outside that root, and
the dashboard's dependencies are installed from the repository root's
node_modules.

scripts/compare-image-deps.mjs and its tests: list every package.json
under node_modules in the built image and fail when a version is in no
lockfile entry. A version the lockfile pins only for another workspace
is reported as a warning. A package.json that is there and cannot be
read as a JSON object stops the check; its package is never left out in
silence.

.github/workflows/ci.yml: the three dashboard builds use the root
context. The image is compared with the lockfile in
docker-build-dashboard, in release-tooling-validation, and in
publish-release-images before the image is pushed.

docker-compose.build.yml and the dashboard README describe the same
build context.

Signed-off-by: Alajmah <55954113+Alajmah@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T20:55:09.554138Z d1d684c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@gitwire-hq gitwire-hq Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review — 💬 Needs discussion

Confidence: medium · Findings: 2
AI judgment: NEEDS DISCUSSION · Evidence: COMPLETE · Authority: advisory
Evidence complete · 9/9 changed files accounted for

Key issues

  • [HIGH] Described lockfile repair is missing from the diff; npm ci ships next@16.4.6 with @next/env@16.3.3 and the new check passes anyway 🔮 ⚠️ unverified

Other findings (1)

  • [medium] Containment-only dependency check cannot detect tree-shape mismatches, only version existence ⚠️ unverified

🔮 Devil's Advocate (2 turns): 1 missed risk found · 1 upheld


GitWire AI Review Gate (bundle-driven v2) · Structured schema · Scope-validated · Devil's Advocate · AI recommendation — maintainers and repository policy retain authority

Finding details (not annotatable inline)

  • [HIGH] Described lockfile repair is missing from the diff; npm ci ships next@16.4.6 with @next/env@16.3.3 and the new check passes anyway

    The PR description contains a 'Lockfile change' section stating two entries were repaired: packages/web-dashboard/node_modules/next (its @next/env and @next/swc-* ranges moved 16.3.3 -> 16.4.6, sharp ^0.35.3 -> ^0.35.5) and packages/web-dashboard/node_modules/@next/env (16.3.3 -> 16.4.6). None of the 8 changed files modifies package-lock.json. Per the description's own root-cause analysis, npm ci accepts that stale lockfile because it compares recorded ranges against the lockfile, not the registry. So the new Dockerfile will install @next/env@16.3.3 beside next@16.4.6 (and sharp 0.35.3 under range ^0.35.3) — the exact version skew this PR documents as the bug, now in the opposite direction. The new gate cannot catch it: scripts/compare-image-deps.mjs only verifies that each image package's name@version exists somewhere in the lockfile and never validates recorded dependency ranges against resolved versions, so next@16.4.6 + @next/env@16.3.3 reports status 'ok' and CI goes green. Fix: commit the lockfile entry repairs described in the PR (include package-lock.json in this PR, derived from npm's own resolution of the same versions), and optionally extend the checker to verify that resolved versions satisfy the recorded dependency ranges of tree entries so intra-lockfile skew becomes a failure instead of a silent pass.

  • [MEDIUM] Containment-only dependency check cannot detect tree-shape mismatches, only version existence

    Per the finding, compare-image-deps.mjs passes if each image package's name@version exists 'somewhere' in the lockfile. Lockfiles routinely contain multiple copies of the same package at different versions (a hoisted root entry plus nested per-workspace entries). An image could therefore ship a version that only exists under an unrelated workspace's subtree — a version npm ci would never install for web-dashboard — and still report status 'ok'. The gate verifies lockfile membership, not correspondence between the image's resolved tree and the lockfile's resolved tree for the relevant install path. This is a broader weakness of the new gate than the specific next/@next/env skew and holds even if the lockfile repair is committed.

@Alajmah

Alajmah commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The automated review on this pull request has two findings. Both were checked against the pull request and the build log.

The lockfile repair is in the pull request. The review counted 8 changed files and no package-lock.json. The pull request has 9 changed files, and package-lock.json is one of them, with 13 lines added and 13 removed: @next/env 16.3.3 → 16.4.6, the eight @next/swc-* ranges 16.3.3 → 16.4.6, and sharp ^0.35.3 → ^0.35.5.

The image built from this pull request's lockfile holds the repaired versions. The comparison step of run 45068276144 lists, from the built image:

Package Version in the image
next 16.4.6
@next/env 16.4.6
sharp 0.35.5

A review that reports 8 changed files for this pull request is probably not shown lockfiles. That is a guess of mine about the review tool, not something I checked.

The check compares name and version, not placement. That is its stated limit, and it is correct. The script's header says so: the comparison is by package name and version as declared in each package.json. It does not compare where in the tree a package sits, and it does not compare the lockfile with the registry. Two things cover what it leaves out:

  • Placement: a version the lockfile pins only outside the workspace's tree is reported as a warning, and the run on this pull request shows exactly one, the lone semver@6.3.1 manifest.
  • Staleness of the lockfile against the registry: checked separately for this pull request and described under "Lockfile change". Of the 76 entries in the dashboard's production tree, 10 recorded ranges differ from the published manifest on master and 0 after this pull request.

No code change follows from these two findings, so the branch stays as it is.

@Alajmah

Alajmah commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The maintainer's review of this pull request asked for one correction before a merge: scripts/compare-image-deps.mjs treated a directory it could not list as an empty one, so the check could pass without having seen the packages under it. A branch cannot be updated here, so the correction is on a new branch.

This pull request is closed as superseded, unmerged. Its branch and its record stay. The successor carries the same change plus:

  • an explicit failure when a directory that must be examined cannot be listed, read or resolved: the walk stops and the check exits 2 with the path and the error code;
  • tests that bring the failure about through a failing fs method on every platform, and through real permission bits on POSIX;
  • the proof that those tests fail on the script of this pull request and pass on the corrected one, and the Linux image run of the corrected branch, with the results of this pull request unchanged.

@Alajmah Alajmah closed this Nov 22, 2026
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