Skip to content

Guard against a package.json change without a matching package-lock.json, so npm ci cannot fail late #332

Closed

Description

@scttfrdmn

What changed

#327 committed sdks/javascript/package-lock.json and switched the sdk-metrics job from npm install to npm ci. Both were deliberate: npm ci installs the locked tree, so what CI resolves is what a developer resolves, and a vulnerability alert then describes a copy that is actually in the tree rather than whatever a manifest range happens to pick up that day. (That second point is not hypothetical — an npm alert on this SDK previously closed without a fix, because with no lockfile the alert tracked the manifest range instead of the nested copy actually installed.)

The consequence, which I did not flag at the time: npm ci refuses to run when package.json and package-lock.json disagree. Dependabot's open PRs against this directory predate the lockfile and edit the manifest only, so they now fail before installing anything:

npm error `npm ci` can only install packages when your package.json and package-lock.json are in sync.
npm error Invalid: lock file's @types/[email protected] does not satisfy @types/[email protected]
npm error Invalid: lock file's [email protected] does not satisfy [email protected]

Reproduced with #310's manifest against main's lockfile.

The trap: their green checks are stale, and look authoritative

#310 and #309 both show passing checks. Those runs happened before #327 merged, against the old workflow — #310's sdk-metrics completed in 34 seconds and its log still shows npm install --no-audit --no-fund under the comment "No lockfile is committed". That job never ran npm ci, never ran tsc, and never ran npm run lint.

So a reviewer glancing at either PR sees green on a PR that would fail on main. This is the same shape as the defect class #327 was about — a check that does not run is indistinguishable from one that passes — arriving this time as a check that ran under different rules than the ones now in force.

What to do

Going forward Dependabot regenerates the lockfile alongside the manifest, because one is now committed; that is its normal behaviour and it is the reason committing the lockfile was worth doing. The open PRs need a rebase to pick it up.

The last item is the durable fix. The rest is one-time cleanup of a queue that predates the gate.

Not affected

The Python, Java and C SDKs. Python's CI step installs from requirements.txt, Java's resolves through Maven with its own lockfile-equivalent semantics, and the C SDK's make test builds from the Go module, which already has go.sum.

Activity

  1. added
    type: ci-cd
    priority: medium
    effort: small
    area: sdk
    area: ci-cd
    on Aug 3, 2026
  2. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    The one-time cleanup resolved itself; the durable item is what's left.

    Merging #327 triggered Dependabot to rebase its open npm PRs, and because a package-lock.json is now committed, it regenerated the lockfile alongside each manifest — the normal behaviour this issue predicted. #310 is now at 7d0b91e touching both files, and its re-run executed the full post-#327 sdk-metrics job (install / build / tests / lint, plus Java and C) and passed. So:

    Only the last one is still worth building, and it is the only one that prevents recurrence rather than cleaning up after it. Note the failure mode it guards against is not the one I originally described: Dependabot handles the lockfile correctly now, so the realistic case is a human editing package.json by hand and pushing without running npm install. That fails npm ci with Invalid: lock file's X does not satisfy Y, which is a clear message but arrives after a full job setup, and the fix is non-obvious to anyone who has not met npm ci before.

    Keeping this open for that item alone. Retitling accordingly.

  3. changed the title [-]npm Dependabot PRs opened before the package-lock.json landed now fail npm ci, and their green checks are stale[/-] [+]Guard against a package.json change without a matching package-lock.json, so npm ci cannot fail late[/+] on Aug 3, 2026
  4. scttfrdmn commented on Aug 4, 2026

    @scttfrdmn
    OwnerAuthor

    Its three cleanup items are done, and #345 implements the fourth — the one this issue calls the durable fix.

    The gate is TestNPMLockfilesAgreeWithTheirManifests, in the test job rather than as a workflow step, comparing each manifest against the lockfile's packages[""] entry — npm's own copy of what the manifest said when the lock was generated. That answers this issue's question from one checkout, where a changed-files diff would need a base ref, would not run on a push to main, and would pass a hand edit that touched both files without regenerating the tree.

    One correction to this issue's "Not affected" section, because it named sdks/python as fine and it is not. The claim was "Python's CI step installs from requirements.txt" — there is no requirements.txt in sdks/python, and no pyproject.toml either. ci.yml:292 runs pip install --quiet pytest ., which resolves 16 unbounded >= floors from setup.py fresh on every run. Worse, nothing scans them: trivy fs --scanners vuln . reports exactly four targets — go.mod, sdks/java/pom.xml, and the two package-lock.json files — because Trivy detects Python from requirements.txt / poetry.lock / Pipfile.lock / pyproject.toml, and a bare setup.py is on none of those lists. Filed as #343.

    The Java and C claims hold as written. Java resolves through Maven, and the C SDK builds from the Go module with go.sum.

    Coverage of the new gate is both npm directories: /sdks/javascript (#201) and /docs-platform (#214). And Dependabot is now doing the right thing unprompted — #339, #340 and #341 each change the manifest and the lockfile together, which is the behaviour committing the lockfile was supposed to buy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: ci-cdarea: sdkeffort: smallpriority: mediumtype: ci-cd

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions