From 52641393d648d20bd8c2c055dd558330523a23f9 Mon Sep 17 00:00:00 2001 From: nyctophile Date: Tue, 3 Nov 2026 23:42:53 -0300 Subject: [PATCH] fix: keep dependency prompts when lockfiles are deleted Co-authored-by: nyctophile --- README.md | 2 +- src/engine.js | 9 +++++++-- tests/engine.test.js | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e26eaad..51dcf68 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ The bundled example has **4 changed files and 5 review prompts**. Also try the s | Skipped or exclusive test markers | Check which tests actually run | | Known TLS verification bypass patterns | Restore certificate verification | | Dynamic `eval` / `exec` calls | Trace input and execution context | -| Dependency manifest without a lockfile in the patch | Check the project’s dependency policy | +| Dependency manifest without a kept or added lockfile in the patch | Check the project’s dependency policy | | Source changes without changed tests | Confirm existing coverage or add a regression test | | Binary changes or large file changes | Make space for a separate review | diff --git a/src/engine.js b/src/engine.js index e71690d..3e99ea9 100644 --- a/src/engine.js +++ b/src/engine.js @@ -329,14 +329,19 @@ export function analyzeDiff(input) { const manifests = parsed.files.filter( (file) => isManifest(file.path) && file.additions + file.deletions, ); - if (manifests.length && !parsed.files.some((file) => isLock(file.path))) + if ( + manifests.length && + !parsed.files.some( + (file) => isLock(file.path) && file.status !== "deleted", + ) + ) emit( "lockfile", "medium", manifests[0], null, "Check dependency reproducibility", - "A dependency manifest changed, but no recognized lockfile is present in this patch. Some ecosystems do not require one.", + "A dependency manifest changed, but this patch contains no recognized lockfile that is kept or added. Some ecosystems do not require one.", "Confirm the project’s dependency policy and regenerate the lockfile if applicable.", ); const runtime = parsed.files.filter( diff --git a/tests/engine.test.js b/tests/engine.test.js index 1d2a16f..b30725a 100644 --- a/tests/engine.test.js +++ b/tests/engine.test.js @@ -115,6 +115,31 @@ test("lockfile in patch suppresses dependency reproducibility prompt", () => { ); assert.ok(!report.findings.some((f) => f.rule === "lockfile")); }); +test("deleted lockfiles do not suppress dependency reproducibility prompts", () => { + const manifest = patch( + "package.json", + '@@ -1 +1 @@\n-{"x":"1"}\n+{"x":"2"}', + ); + for (const lockfile of [ + "diff --git a/package-lock.json b/package-lock.json\ndeleted file mode 100644\n--- a/package-lock.json\n+++ /dev/null\n@@ -1 +0,0 @@\n-old-lock", + "--- a/package-lock.json\n+++ /dev/null\n@@ -1 +0,0 @@\n-old-lock", + "diff --git a/package-lock.json b/old-lock.txt\nsimilarity index 100%\nrename from package-lock.json\nrename to old-lock.txt", + ]) { + const report = analyzeDiff(`${manifest}\n${lockfile}`); + const finding = report.findings.find((f) => f.rule === "lockfile"); + assert.ok(finding); + assert.equal(finding.path, "package.json"); + assert.equal(finding.severity, "medium"); + } +}); +test("a replacement lockfile still suppresses the dependency prompt", () => { + const report = analyzeDiff( + patch("package.json", '@@ -1 +1 @@\n-{"x":"1"}\n+{"x":"2"}') + + "\ndiff --git a/package-lock.json b/package-lock.json\ndeleted file mode 100644\n--- a/package-lock.json\n+++ /dev/null\n@@ -1 +0,0 @@\n-old-lock\n" + + "diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml\nnew file mode 100644\n--- /dev/null\n+++ b/pnpm-lock.yaml\n@@ -0,0 +1 @@\n+lockfileVersion: '9.0'", + ); + assert.ok(!report.findings.some((f) => f.rule === "lockfile")); +}); test("unsupported or empty input fails clearly and size limits are enforced", () => { for (const input of ["", "hello", "x".repeat(limits.bytes + 1)]) assert.throws(() => analyzeDiff(input));