Repository navigation
Conversation
|
Important Approval pendingCodeRabbit is reviewing the latest commit. It will check approval again when the review finishes. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
PR Summary by QodoFix Rust workspace manifest writer to edit single-line flow YAML blocks in place
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Confidence Score: 4/5The PR is not yet safe to merge because pruning an unsupported multi-line The destructive replacement from the previous thread is prevented, but the replacement branch now returns a no-op signal and the prune caller lacks the preflight needed to turn that condition into the documented unsupported-inline error. Files Needing Attention: pnpm/crates/workspace-manifest-writer/src/edit.rs, pnpm/crates/workspace-manifest-writer/src/lib.rs Reviews (2): Last reviewed commit: "fix(workspace-manifest-writer): span a m..." | Re-trigger Greptile |
Code Review by Qodo
1. Wrong-kind flow bypass
|
| pub(crate) fn has_unsupported_inline_value(text: &str, path: &[&str]) -> bool { | ||
| document_root_is_inline(text) | ||
| || (matches!(locate_mapping(text, path), Inline::Unsupported) | ||
| && matches!(locate_sequence(text, path), Inline::Unsupported)) | ||
| } |
There was a problem hiding this comment.
2. Wrong-kind flow bypass 🐞 Bug ≡ Correctness
has_unsupported_inline_value() returns false when a key’s inline value is a single-line flow collection of the *wrong kind* (e.g. allowBuilds: [ ... ]), so callers don’t refuse the write. The subsequent mapping writers fall back to block-style splicing and can append key: value lines after an inline value, producing an invalid/unparsable YAML document.
Agent Prompt
### Issue description
`edit::has_unsupported_inline_value()` currently treats an inline value as “unsupported” only if *both* `locate_mapping()` and `locate_sequence()` return `Inline::Unsupported`. This means a single-line flow **sequence** at a path where callers expect a **mapping** (or vice versa) is treated as supported, so the write proceeds and block-style splicing can corrupt the YAML.
### Issue Context
Callers use `unsupported_inline_key()` (in `lib.rs`) to refuse writes before mutating text. Because the guard is not kind-aware, a wrong-kind flow value can slip through, and functions like `write_rendered_entry_at()` will then take the non-flow branch and splice block-style entries into a line that already contains an inline value.
### Fix Focus Areas
- pnpm/crates/workspace-manifest-writer/src/edit.rs[50-67]
- pnpm/crates/workspace-manifest-writer/src/lib.rs[122-131]
- pnpm/crates/workspace-manifest-writer/src/edit.rs[1029-1036]
### Suggested fix
- Replace `has_unsupported_inline_value(text, path)` with a kind-aware API, e.g.:
- `has_unsupported_inline_mapping(text, path)` (uses `locate_mapping` only)
- `has_unsupported_inline_sequence(text, path)` (uses `locate_sequence` only)
- or `has_unsupported_inline_value(text, path, expected_kind)`.
- Update each caller to pass the expected kind for that path:
- `catalog`, `catalogs`, `configDependencies`, `allowBuilds`, `patchedDependencies`, `overrides` => mapping
- `minimumReleaseAgeExclude`, `auditConfig.ignoreGhsas` => sequence
- Add regression tests for wrong-kind single-line flow values (e.g. `allowBuilds: [ foo ]` and a write attempt) to assert the writer refuses rather than corrupting the document.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
This one isn't reachable: a wrong-kind value never gets past Manifest::parse. Every block these writers touch is typed (allowBuilds, overrides, catalog, catalogs, configDependencies, patchedDependencies are IndexMaps; auditConfig.ignoreGhsas and minimumReleaseAgeExclude are Vec<String>), so the manifest is rejected before any guard runs:
$ # allowBuilds: [ foo ] + set_allow_builds([("bar", true)])
Failed to parse "…/pnpm-workspace.yaml" as YAML: error: line 1 column 14:
unexpected event: expected mapping start
Same for overrides: [ foo ] and auditConfig: { ignoreGhsas: { a: b } }. The file is left untouched in each case.
That's the real guarantee, so rather than add a kind-aware API whose extra branch no input can reach, I pinned the guarantee with a test — flow_style::a_flow_collection_of_the_wrong_kind_fails_to_parse (493b739) — which fails if a block ever loses its typed decode.
Kind-awareness does exist one level down, where it can bite: locate_mapping / locate_sequence classify a flow collection of the wrong kind as Unsupported, so no writer can splice a mapping entry into a sequence or the reverse.
Written by an agent (Claude Code, claude-opus-5[1m]).
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14112 +/- ##
==========================================
+ Coverage 88.44% 88.46% +0.02%
==========================================
Files 673 674 +1
Lines 113365 113563 +198
==========================================
+ Hits 100270 100468 +198
Misses 13095 13095 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Found 12 test failures on Blacksmith runners: Failures
...and 2 more test failures. View all on Blacksmith
|
The workspace-manifest writer's splices are line-oriented, so a block a
user wrote inline — `catalog: { foo: ^1.0.0 }`, `overrides: { foo: 1.0.0 }`,
`minimumReleaseAgeExclude: [[email protected]]` — had no entry lines to splice.
`overrides:` and `auditConfig:` refused the write; every other block spliced
a block-style line in after the inline value and left an unparsable
document behind:
catalog: { foo: ^1.0.0 }
bar: ^2.0.0
The TypeScript writer round-trips the document through the yaml library and
edits such a block in place, keeping its flow style, its other entries and
their quoting, and any trailing comment. pacquet now does the same: a new
`flow` module parses a single-line flow collection into entry spans and
rebuilds it with one entry upserted, replaced, or dropped, and the entry
splices, the removal splices, the catalog/allowBuilds/patchedDependencies
writers, and the cleanup passes all route through it. The rendering matches
what the yaml library emits (`{ a: 1, b: 2 }`, `[ a, b ]`), so both stacks
now produce the same bytes for the same edit — pinned by the new
`flow_style` suite here and its mirror in
pnpm11/workspace/workspace-manifest-writer/test/flowStyle.test.ts.
A flow collection spanning several lines can carry comments between its
entries that a one-line rebuild would drop, so those — along with aliases
and scalars standing where a collection belongs — are still refused with
ERR_PNPM_WORKSPACE_MANIFEST_WRITER_UNSUPPORTED_INLINE_BLOCK, now on every
writer rather than only two.
Closes #14108
The mirrored TypeScript suite typechecks against the current `AuditConfig` and `Project` types: build the pruning fixture with `prepare` + `findPackages` rather than a hand-rolled project literal, and drop the `auditConfig` sibling key that does not exist on this branch. The Rust `ignore_ghsas_are_added_to_a_flow_audit_config` case moves to the same input so the two suites stay a mirror.
A pnpm-workspace.yaml written as a single flow mapping
(`{ overrides: { foo: 1.0.0 } }`) has no top-level key lines, so the
writers found no block to edit and appended a fresh block-style one after
it, leaving an unparsable document. Every writer now reports
ERR_PNPM_WORKSPACE_MANIFEST_WRITER_UNSUPPORTED_INLINE_BLOCK for that shape
instead, `pnpm config set` included.
A flow collection written across several lines closes at column zero, which
`top_level_span` read as the next top-level key. Replacing or removing such
a block left its closing bracket behind:
minimumReleaseAgeExclude:
- [email protected]
]
The span now runs to the bracket that closes the value, so a removal takes
the whole block and `pnpm config set`/`delete` no longer strand one. The
list writers refuse a multi-line inline value outright rather than
re-rendering it in block style, which would drop the comments between its
entries — the stance the mapping writers already take.
Reported by Greptile on #14112.
| // Rendering the whole block afresh would drop the comments an | ||
| // inline value this writer cannot edit may hold, so leave it be; | ||
| // the public writer refuses such a manifest outright. | ||
| Inline::Unsupported => return false, |
There was a problem hiding this comment.
Unsupported prune silently succeeds
When minimumReleaseAgeExcludePrune changes a multi-line flow sequence, this branch returns false without the unsupported-inline preflight used by the public setter. The workspace update therefore succeeds without applying the prune, leaving stale minimumReleaseAgeExclude entries in the manifest instead of reporting ERR_PNPM_WORKSPACE_MANIFEST_WRITER_UNSUPPORTED_INLINE_BLOCK.
There was a problem hiding this comment.
That one is deliberate, for two reasons.
Erroring here would diverge from the TypeScript writer more than skipping does. TS never fails on this shape — it prunes and re-emits:
# in
minimumReleaseAgeExclude: [
[email protected], # pinned
[email protected],
]
# out (TS, minimumReleaseAgeExcludePrune)
minimumReleaseAgeExclude:
[
[email protected] # pinned
]So the options are "prune silently" (TS) versus "prune silently, or skip" (pacquet). Raising ERR_PNPM_WORKSPACE_MANIFEST_WRITER_UNSUPPORTED_INLINE_BLOCK would make pnpm install fail over a manifest formatting choice, in a stack whose counterpart succeeds — a worse parity break than postponing a cleanup.
It matches every other cleanup pass in this crate. catalogPrune (remove_unused_default_catalog, remove_unused_named_catalogs) and prune_allow_builds already return false for a block they cannot edit entry by entry, and always have. These passes are housekeeping that runs on every install; refusing to install is not on their menu. The user-initiated writers are the ones that must speak up, which is why set_minimum_release_age_excludes grew the preflight in 493b739.
Nothing is lost by skipping: the entries stay exactly as written, and the prune runs on the next install once the block is block style.
The gap worth closing eventually is a surgical entry delete inside a multi-line flow collection (drop the entry's span plus its comma, leave the surrounding comments), which would let both the prune and the setter handle this shape without flattening. That is a larger change than this PR, and I would rather not grow the flow parser under a bug fix.
Written by an agent (Claude Code, claude-opus-5[1m]).
|
Code review by qodo was updated up to the latest commit 493b739 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…rite refusal pnpm#14112 taught the shared workspace-manifest writer to edit flow-style YAML blocks in place, matching the TypeScript writer. Update both stacks' cleanupUnusedIgnoredGhsas coverage of a flow-style auditConfig to assert the successful in-place edit instead of the now-obsolete write refusal, and add the mirrored TypeScript test that was previously impossible because of that divergence. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MgTb23fbaanpxBTp9p4WPe
…rite refusal pnpm#14112 taught the shared workspace-manifest writer to edit flow-style YAML blocks in place, matching the TypeScript writer. Update both stacks' cleanupUnusedIgnoredGhsas coverage of a flow-style auditConfig to assert the successful in-place edit instead of the now-obsolete write refusal, and add the mirrored TypeScript test that was previously impossible because of that divergence. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MgTb23fbaanpxBTp9p4WPe
![Fix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/fix-with-codesmith-light.png)
Summary
Closes #14108.
The issue reports that the two stacks disagree on writing to a flow-style
block in
pnpm-workspace.yaml: the TypeScript writer edits it in place, theRust one refuses. Probing the Rust writer while scoping the fix turned up
something worse than the refusal — only
overrides:andauditConfig:hadthe inline guard. Every other block spliced a block-style line in after the
inline value and left an unparsable document behind:
Same for
configDependencies,allowBuilds, andpatchedDependencies.The direction taken is the one the issue lists first: pacquet learns to
edit flow-style nodes in place, matching TS. The TypeScript writer keeps
today's behavior (refusing there would break
audit --fix,link, andcatalog writes for anyone whose manifest uses flow style, and it already
handles the case well — flow style, entry quoting, and trailing comments all
survive).
pacquet side (
pnpm/crates/workspace-manifest-writer):flowmodule: parses a single-line flow collection into entry spansand rebuilds it with one entry upserted, replaced, or dropped. Untouched
entries keep their exact text, and everything outside the brackets stays
verbatim.
edit.rsclassifies each key path as block / editable-flow / unsupported,and the entry splices, the removal splices, the catalog,
allowBuilds,patchedDependenciesandconfigDependencieswriters, and thecatalogPrune/allowBuildscleanup passes all route through it.yamllibrary emits ({ a: 1, b: 2 },[ a, b ]), including where a new key sorts in, so both stacks now writethe same bytes for the same edit.
ERR_PNPM_WORKSPACE_MANIFEST_WRITER_UNSUPPORTED_INLINE_BLOCKnow guardsevery writer instead of two, and fires only for shapes a splice really
cannot edit: a multi-line flow collection (whose interleaved comments a
one-line rebuild would drop), an alias, or a scalar where a collection
belongs. Removing a block never triggers it, so
patchedDependencies: nullstill clears cleanly.
Every expectation in the new
flow_stylesuite was taken from running theTypeScript writer on the same input; the mirrored suite lives in
pnpm11/workspace/workspace-manifest-writer/test/flowStyle.test.tsso thetwo stay pinned together.
Known remaining divergences, all in shapes pacquet now refuses with an
actionable error rather than corrupting: TS reformats a multi-line flow
collection (re-indenting the whole block), resolves aliases by unwrapping
them into the value, and edits a manifest written as one whole-document
flow mapping (
{ overrides: { foo: 1.0.0 } }) in place. Matching the firstwould mean reproducing the yaml emitter's flow-wrapping algorithm; the other
two are exotic enough that a clear error beats the machinery. All three
corrupted the file before this PR.
Note for #11384: its
audit_fix_cleanup_reports_the_write_error_for_an_inline_audit_configassertsthe old refusal for a flow
auditConfig. Once this lands, that test shouldassert the successful in-place edit instead — and the TS mirror CodeRabbit
asked for there becomes writable.
Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.(TypeScript already behaved this way; it gains the mirrored tests that pin
the contract.)
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5[1m]).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
New Features
Bug Fixes
Tests