Skip to content

fix(dedupe): sort check snapshot changes - #13451

Merged
zkochan merged 4 commits into
mainfrom
test-novu
Jul 27, 2026
Merged

zkochan merged 4 commits into
mainfrom
test-novu

Conversation

@zkochan

@zkochan zkochan commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Sort snapshot additions, removals, and updates in the TypeScript pnpm dedupe --check diff. The Rust CLI already emits canonical lockfile-key order, so this makes the two implementations report the same deterministic result on large workspaces such as novuhq/novu.

Related to #13305.

The Novu lockfiles written by the available TypeScript baseline and the branch-built Rust CLI were byte-identical. A full branch-built TypeScript Novu run remains blocked because the workspace references the private @taskforcesh/bullmq-pro package and the registry returns 404 without project credentials.

Squash Commit Body

Sort dedupe check snapshot changes before rendering them so output does not depend on resolver insertion order. This aligns the TypeScript report with Rust pnpm, which already reports canonical lockfile-key order.

Related to pnpm/pnpm#13305.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Codex, GPT-5.6).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Improved pnpm dedupe --check snapshot diff consistency by producing deterministic results regardless of lockfile ordering.
  • Tests
    • Added Jest coverage to verify dedupe check issue reporting remains correctly structured and stably sorted across input variations.
  • Releases
    • Prepared patch releases for the deduplication checking package and pnpm.

Copilot AI review requested due to automatic review settings July 27, 2026 22:52

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@zkochan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 70a3e649-43f3-43f4-9c6a-e9ac75914bac

📥 Commits

Reviewing files that changed from the base of the PR and between 8090403 and c8c945f.

📒 Files selected for processing (4)
  • .changeset/calm-dedupes-report.md
  • pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts
  • pnpm11/installing/dedupe/issues-renderer/src/index.ts
  • pnpm11/installing/dedupe/issues-renderer/test/index.ts
📝 Walkthrough

Walkthrough

diffSnapshots now returns deterministically ordered snapshot changes. A regression test verifies stable dedupe issue ordering, and a changeset records patch releases for the affected packages.

Changes

Dedupe snapshot sorting

Layer / File(s) Summary
Sort dedupe diff results
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts
diffSnapshots sorts added, removed, and updated entries using a key-sorting helper.
Validate sorted snapshot issues
pnpm11/installing/dedupe/check/test/dedupeDiffCheck.ts, .changeset/calm-dedupes-report.md
Tests verify stable package issue ordering across resolution order changes, and the changeset records patch releases for @pnpm/installing.dedupe.check and pnpm.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: product: pnpm@11

Suggested reviewers: copilot

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-novu

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.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Sort pnpm dedupe --check snapshot diff output deterministically

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Sort added/removed/updated snapshot changes so dedupe --check output is deterministic.
• Add a regression test to prove ordering is independent of resolver insertion order.
• Publish a patch changeset describing the stabilized output behavior.
Diagram

graph TD
  A["dedupeDiffCheck.ts"] --> B["diffSnapshots()"] --> C["Sort changes"] --> D["Dedupe check report"]
  E["dedupeDiffCheck.test.ts"] --> F["calcDedupeCheckIssues()"] --> B
Loading
High-Level Assessment

Sorting added, removed, and the updated map keys at the diff boundary is the simplest way to guarantee deterministic output and keep behavior aligned with the Rust implementation. Alternatives like sorting only at render-time or relying on insertion order are more fragile and risk reintroducing nondeterminism in other consumers.

Files changed (3) +81 / -2

Bug fix (1) +7 / -1
dedupeDiffCheck.tsSort snapshot diff results before returning +7/-1

Sort snapshot diff results before returning

• Ensures 'diffSnapshots()' returns deterministically ordered results by sorting the 'added' and 'removed' dep-path arrays. Also sorts 'updated' entries by key before returning to make the diff stable regardless of resolver insertion order.

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts

Tests (1) +68 / -1
dedupeDiffCheck.tsAdd regression test for snapshot-change ordering +68/-1

Add regression test for snapshot-change ordering

• Extends tests to cover ordering stability by constructing before/after lockfiles with intentionally non-canonical key order. Asserts that 'calcDedupeCheckIssues()' reports 'added' and 'updated' in sorted, deterministic order.

pnpm11/installing/dedupe/check/test/dedupeDiffCheck.ts

Documentation (1) +6 / -0
calm-dedupes-report.mdAdd changeset for deterministic 'dedupe --check' output +6/-0

Add changeset for deterministic 'dedupe --check' output

• Adds a patch changeset for both '@pnpm/installing.dedupe.check' and 'pnpm'. The note explains that snapshot changes are now sorted for stable output across implementations.

.changeset/calm-dedupes-report.md

@greptile-apps

greptile-apps Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the renderer now sorts both snapshot IDs and nested aliases lexically, including integer-like keys.

Reviews (4): Last reviewed commit: "fix(dedupe): sort rendered snapshot chan..." | Re-trigger Greptile

@qodo-code-review

qodo-code-review Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Action required

1. Nested updates not canonical ✓ Resolved 🐞 Bug ≡ Correctness
Description
getResolutionUpdates() sorts each per-field change record, but diffSnapshots() merges multiple
fields into one updates map via Object.assign(), which can leave the final per-snapshot alias
iteration order non-sorted (grouped by field). Because rendering iterates Object.entries(issue)
without sorting, pnpm dedupe --check output can still differ from a true canonical key order when
changes come from different dependency fields.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[R135-141]

+  return sortRecord(updates)
+}
+
+function sortRecord<T> (record: Record<string, T>): Record<string, T> {
+  return Object.fromEntries(
+    Object.entries(record).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
+  )
Relevance

⭐⭐⭐ High

Repo repeatedly accepts fixes for deterministic/canonical ordering and output stability.

PR-#13074
PR-#12953

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The code sorts per-field updates (via return sortRecord(updates)), but then merges multiple fields
into a single updates map with Object.assign(), which preserves insertion order by merge
sequence rather than global key order. The renderer uses Object.entries(issue) with no sorting, so
that insertion order controls displayed order.

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[115-136]
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[138-141]
pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`getResolutionUpdates()` now returns a sorted record, but `diffSnapshots()` merges multiple per-field results into a single `updates` object with `Object.assign()`. If field A yields key `z` and field B yields key `a`, the merged insertion order becomes `z` then `a` (even though each source record was sorted), so the nested per-snapshot output is not globally sorted.

## Issue Context
The renderer relies on object insertion order (`Object.entries(issue)`) and does not sort at render time, so the merged alias map order directly affects user-visible output.

## Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[115-141]
- pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]
- pnpm11/installing/dedupe/check/test/dedupeDiffCheck.ts[119-183]

## What to change
1. Have `getResolutionUpdates()` return the plain `updates` object (no sorting).
2. After the per-field merge loop in `diffSnapshots()`, sort the *combined* `updates` once (e.g. `const sorted = Object.keys(updates).length > 1 ? sortRecord(updates) : updates`) before assigning to `updated[id]`.
3. Keep the outer `sortRecord(updated)` for deterministic snapshot ordering.
4. Add a test where two different dependency fields contribute different aliases (e.g. one alias change in `dependencies`, another in `optionalDependencies` or importer fields) and assert the nested `updated[id]` alias order is globally sorted.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Redundant list sorting 🐞 Bug ➹ Performance ⭐ New
Description
renderDedupeCheckIssues() now clones and sorts the added/removed lists even though the common
producer (diffSnapshots) already sorts them before returning, adding extra allocation and O(n log n)
work proportional to the number of added/removed entries. This is a low-severity performance
regression in dry-run and dedupe-check reporting paths when change lists are large.
Code

pnpm11/installing/dedupe/issues-renderer/src/index.ts[R35-36]

+    ...[...snapshotChanges.added].sort().map((id) => `${chalk.green('+')} ${id}`),
+    ...[...snapshotChanges.removed].sort().map((id) => `${chalk.red('-')} ${id}`),
Relevance

⭐⭐⭐ High

Team often accepts removing redundant allocations/work when behavior is preserved; similar “avoid
redundant” fixes accepted.

PR-#12762
PR-#12491

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The renderer now sorts/clones added/removed, but the upstream diff function already sorts these
arrays before returning SnapshotsChanges, and the dry-run path feeds calcDedupeCheckIssues() output
directly into renderDedupeCheckIssues(), making the renderer’s added/removed sorting redundant in
the common flow.

pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-37]
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[84-112]
pnpm11/installing/commands/src/install.ts[476-485]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`renderDedupeCheckIssues()` defensively sorts `snapshotChanges.added` and `snapshotChanges.removed` by cloning and sorting them again. In the common path, these arrays are already sorted by the diffing code, so this adds avoidable CPU and memory work.

## Issue Context
- The renderer is used for dry-run reporting and dedupe check issue reporting.
- Upstream diffing already sorts the `added` and `removed` arrays before returning `SnapshotsChanges`.

## Fix Focus Areas
- pnpm11/installing/dedupe/issues-renderer/src/index.ts[34-36]

### Suggested approach
Keep deterministic output while avoiding extra work when inputs are already sorted:
- Add a small helper like `sortedIfNeeded(list: readonly string[]): readonly string[] | string[]` that does a linear `isSorted` check.
- If already sorted, return the original list (no clone, no sort).
- Otherwise, return a cloned sorted copy.

This preserves renderer defensiveness for non-standard callers while removing the redundant sort/clone in the main `calcDedupeCheckIssues()`-produced path.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. sortRecord() duplicates key-sorting ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new sortRecord() helper reimplements record key sorting even though the repo already provides
a shared, canonical key-sorting module. This increases maintenance burden and risks inconsistent
ordering semantics across packages.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[R138-141]

+function sortRecord<T> (record: Record<string, T>): Record<string, T> {
+  return Object.fromEntries(
+    Object.entries(record).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
+  )
Relevance

⭐⭐⭐ High

They often accept deduping utilities into shared canon to avoid drift.

PR-#13124
PR-#11609

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 713439 requires avoiding duplicate implementations when a shared module already exists. The PR
adds a bespoke sortRecord() implementation, while the codebase already provides
@pnpm/object.key-sorting for sorting object keys.

Rule 713439: Avoid reimplementing existing functionality; extract and reuse shared modules
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[138-141]
pnpm11/object/key-sorting/src/index.ts[1-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new local helper `sortRecord()` was added to sort object keys, duplicating functionality that already exists in the repo (`@pnpm/object.key-sorting`).

## Issue Context
The repo already has a shared key-sorting implementation that centralizes ordering semantics (and avoids repeated bespoke comparators). Reusing it reduces divergence and maintenance overhead.

## Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[138-141]
- pnpm11/object/key-sorting/src/index.ts[1-12]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

4. Extra per-snapshot sorting ✓ Resolved 🐞 Bug ➹ Performance
Description
diffSnapshots() now sorts and re-materializes the per-snapshot alias-change record via
sortRecord(updates) for every changed snapshot, adding extra allocations and O(k log k) work beyond
what’s required to compute the diff. This cost shows up in check/reporting flows (e.g. `pnpm dedupe
--check and pnpm install --dry-run`) where ordering could instead be enforced at render time.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[102]

+      updated[id] = sortRecord(updates)
Relevance

⭐⭐ Medium

Performance vs determinism tradeoff; no close precedent on moving sorting from diff to renderer.

PR-#12449

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new line sorts/copies every per-snapshot updates map; the dry-run install path calls
calcDedupeCheckIssues() and renders the report; and the renderer relies on insertion order via
Object.entries(...), so ordering could be applied there instead of during diff construction.

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
pnpm11/installing/commands/src/install.ts[476-485]
pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`diffSnapshots()` now sorts and copies `updates` into a new object for every updated snapshot (`updated[id] = sortRecord(updates)`). This introduces extra allocations/sorting work even though stable ordering is only required when rendering the report (the renderer currently iterates `Object.entries(...)` without sorting).

### Issue Context
This code runs in reporting/checking paths such as `pnpm dedupe --check` and `pnpm install --dry-run`, so the added work only matters when many snapshots have changes.

### Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
- pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]

### Suggested approach
- Keep `updates` as-is in `diffSnapshots()` (avoid per-snapshot `sortRecord(updates)`), and instead sort at render time:
 - In `report()`: iterate `Object.keys(snapshotChanges.updated).sort()`.
 - In `toArchy()`: iterate `Object.keys(issue).sort()`.
- If you still want deterministic ordering in non-render consumers, consider sorting keys arrays (not rebuilding objects) or guarding sorting behind a flag used only by report paths.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Missing trailing comma in fromEntries() ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The multi-line Object.fromEntries(...) call omits a trailing comma after its last argument,
violating the repo’s TypeScript trailing-comma requirement and causing noisier diffs.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[R110-112]

+  const sortedUpdated = Object.fromEntries(
+    Object.entries(updated).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
+  )
Relevance

⭐ Low

Team repeatedly rejected adding trailing commas in multi-line TS call/params despite rule 713434.

PR-#12872
PR-#12833
PR-#13133

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas in TypeScript multi-line constructs. In
dedupeDiffCheck.ts, the Object.fromEntries( call spans multiple lines with its single argument
on its own line but does not end that argument with a trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[108-114]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A multi-line function call argument list is missing a trailing comma on the last argument.

## Issue Context
The repo compliance rule requires trailing commas in TypeScript multi-line constructs (including argument lists) to keep formatting consistent and diffs stable.

## Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[110-112]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit c8c945f

Results up to commit 7523493 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Informational
1. Missing trailing comma in fromEntries() ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The multi-line Object.fromEntries(...) call omits a trailing comma after its last argument,
violating the repo’s TypeScript trailing-comma requirement and causing noisier diffs.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[R110-112]

+  const sortedUpdated = Object.fromEntries(
+    Object.entries(updated).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
+  )
Relevance

⭐ Low

Team repeatedly rejected adding trailing commas in multi-line TS call/params despite rule 713434.

PR-#12872
PR-#12833
PR-#13133

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas in TypeScript multi-line constructs. In
dedupeDiffCheck.ts, the Object.fromEntries( call spans multiple lines with its single argument
on its own line but does not end that argument with a trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[108-114]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A multi-line function call argument list is missing a trailing comma on the last argument.

## Issue Context
The repo compliance rule requires trailing commas in TypeScript multi-line constructs (including argument lists) to keep formatting consistent and diffs stable.

## Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[110-112]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit 254190d ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Nested updates not canonical ✓ Resolved 🐞 Bug ≡ Correctness
Description
getResolutionUpdates() sorts each per-field change record, but diffSnapshots() merges multiple
fields into one updates map via Object.assign(), which can leave the final per-snapshot alias
iteration order non-sorted (grouped by field). Because rendering iterates Object.entries(issue)
without sorting, pnpm dedupe --check output can still differ from a true canonical key order when
changes come from different dependency fields.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[R135-141]

+  return sortRecord(updates)
+}
+
+function sortRecord<T> (record: Record<string, T>): Record<string, T> {
+  return Object.fromEntries(
+    Object.entries(record).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
+  )
Relevance

⭐⭐⭐ High

Repo repeatedly accepts fixes for deterministic/canonical ordering and output stability.

PR-#13074
PR-#12953

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The code sorts per-field updates (via return sortRecord(updates)), but then merges multiple fields
into a single updates map with Object.assign(), which preserves insertion order by merge
sequence rather than global key order. The renderer uses Object.entries(issue) with no sorting, so
that insertion order controls displayed order.

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[115-136]
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[138-141]
pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`getResolutionUpdates()` now returns a sorted record, but `diffSnapshots()` merges multiple per-field results into a single `updates` object with `Object.assign()`. If field A yields key `z` and field B yields key `a`, the merged insertion order becomes `z` then `a` (even though each source record was sorted), so the nested per-snapshot output is not globally sorted.

## Issue Context
The renderer relies on object insertion order (`Object.entries(issue)`) and does not sort at render time, so the merged alias map order directly affects user-visible output.

## Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[115-141]
- pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]
- pnpm11/installing/dedupe/check/test/dedupeDiffCheck.ts[119-183]

## What to change
1. Have `getResolutionUpdates()` return the plain `updates` object (no sorting).
2. After the per-field merge loop in `diffSnapshots()`, sort the *combined* `updates` once (e.g. `const sorted = Object.keys(updates).length > 1 ? sortRecord(updates) : updates`) before assigning to `updated[id]`.
3. Keep the outer `sortRecord(updated)` for deterministic snapshot ordering.
4. Add a test where two different dependency fields contribute different aliases (e.g. one alias change in `dependencies`, another in `optionalDependencies` or importer fields) and assert the nested `updated[id]` alias order is globally sorted.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. sortRecord() duplicates key-sorting ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new sortRecord() helper reimplements record key sorting even though the repo already provides
a shared, canonical key-sorting module. This increases maintenance burden and risks inconsistent
ordering semantics across packages.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[R138-141]

+function sortRecord<T> (record: Record<string, T>): Record<string, T> {
+  return Object.fromEntries(
+    Object.entries(record).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
+  )
Relevance

⭐⭐⭐ High

They often accept deduping utilities into shared canon to avoid drift.

PR-#13124
PR-#11609

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 713439 requires avoiding duplicate implementations when a shared module already exists. The PR
adds a bespoke sortRecord() implementation, while the codebase already provides
@pnpm/object.key-sorting for sorting object keys.

Rule 713439: Avoid reimplementing existing functionality; extract and reuse shared modules
pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[138-141]
pnpm11/object/key-sorting/src/index.ts[1-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new local helper `sortRecord()` was added to sort object keys, duplicating functionality that already exists in the repo (`@pnpm/object.key-sorting`).

## Issue Context
The repo already has a shared key-sorting implementation that centralizes ordering semantics (and avoids repeated bespoke comparators). Reusing it reduces divergence and maintenance overhead.

## Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[138-141]
- pnpm11/object/key-sorting/src/index.ts[1-12]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit 8090403 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Informational
1. Extra per-snapshot sorting ✓ Resolved 🐞 Bug ➹ Performance
Description
diffSnapshots() now sorts and re-materializes the per-snapshot alias-change record via
sortRecord(updates) for every changed snapshot, adding extra allocations and O(k log k) work beyond
what’s required to compute the diff. This cost shows up in check/reporting flows (e.g. `pnpm dedupe
--check and pnpm install --dry-run`) where ordering could instead be enforced at render time.
Code

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[102]

+      updated[id] = sortRecord(updates)
Relevance

⭐⭐ Medium

Performance vs determinism tradeoff; no close precedent on moving sorting from diff to renderer.

PR-#12449

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new line sorts/copies every per-snapshot updates map; the dry-run install path calls
calcDedupeCheckIssues() and renders the report; and the renderer relies on insertion order via
Object.entries(...), so ordering could be applied there instead of during diff construction.

pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
pnpm11/installing/commands/src/install.ts[476-485]
pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`diffSnapshots()` now sorts and copies `updates` into a new object for every updated snapshot (`updated[id] = sortRecord(updates)`). This introduces extra allocations/sorting work even though stable ordering is only required when rendering the report (the renderer currently iterates `Object.entries(...)` without sorting).

### Issue Context
This code runs in reporting/checking paths such as `pnpm dedupe --check` and `pnpm install --dry-run`, so the added work only matters when many snapshots have changes.

### Fix Focus Areas
- pnpm11/installing/dedupe/check/src/dedupeDiffCheck.ts[96-103]
- pnpm11/installing/dedupe/issues-renderer/src/index.ts[32-44]

### Suggested approach
- Keep `updates` as-is in `diffSnapshots()` (avoid per-snapshot `sortRecord(updates)`), and instead sort at render time:
 - In `report()`: iterate `Object.keys(snapshotChanges.updated).sort()`.
 - In `toArchy()`: iterate `Object.keys(issue).sort()`.
- If you still want deterministic ordering in non-render consumers, consider sorting keys arrays (not rebuilding objects) or guarding sorting behind a flag used only by report paths.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Copilot AI review requested due to automatic review settings July 27, 2026 22:55

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 254190d

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Copilot AI review requested due to automatic review settings July 27, 2026 23:19

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8090403

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Copilot AI review requested due to automatic review settings July 27, 2026 23:27

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit c8c945f

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit 9df134b into main Jul 27, 2026
28 checks passed
@zkochan
zkochan deleted the test-novu branch July 27, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants