Skip to content

Read Cargo.toml [package] identity through formats::cargo::manifest (#693) - #1110

Merged
Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
arch-refactor/693-cargo-manifest-reader
Oct 8, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
arch-refactor/693-cargo-manifest-reader

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-opus-5-5

Fixes #693 (slice 1 of 2)

Summary

Three parsers read a Cargo.toml's [package] name and version: the cargo crawler's hand-rolled line scanner, VEX product detection's scan_toml_section, and cargo_tag's own toml_edit lookup. This PR adds one toml_edit reader, formats::cargo::manifest, moves all three onto it, and deletes the crawler's scanner.

Why

What changed

  • New formats/cargo/manifest.rs:
    • package_table(&Table) returns [package], else legacy [project];
    • package_name_version(&str) returns the literal name and version, or None for invalid TOML, a missing or empty field, or a non-literal field such as version.workspace = true. It is pure, so it passes the formats architecture guard.
  • crawlers/cargo_crawler.rs (and its test oracle) calls package_name_version. Deleted: parse_cargo_toml_name_version, parse_table_header, extract_string_value and the scanner-specific unit tests. The tests that pin crawler behavior (comments, quotes, subtables, workspace inheritance) stay and now run through the shared reader.
  • vex/product.rs parse_cargo_toml calls package_name_version. scan_toml_section stays for pyproject.toml (E38's).
  • vendor/cargo_tag.rs version_literal finds its table through package_table and keeps only the span and quote logic.
  • tests/crawler_cargo_e2e.rs imports the reader from formats::cargo::manifest.

Left for slice 2: vendor/cargo.rs (path_crate_version, declared_cargo_minor, and #651's rust-version inheritance). Open PRs #1026, #1039, #1041, #1043 and #1050 change that file.

Diff

7 files, +250 / −247: production about +45 / −115, the rest tests.

Behavior

Lockfiles, JSON output, exit codes and the CLI contract don't change. Cargo-style parsing changes the reader in these cases:

  • Crawler: now reads a manifest with a BOM, [project], dotted keys or an inline package = { … }. It no longer reads invalid TOML ([package] junk, a stray [oops line); those fall back to the directory name, as version.workspace = true already did.
  • VEX product: now reads [project], dotted keys and the inline table.
  • cargo_tag: unchanged.

Normalized crates.io manifests (plain [package]) take none of these paths. On all 208 real registry manifests in ~/.cargo/registry/src, the old scanner and the new reader agree on every file.

Cost on the crawl path

A full toml_edit parse is slower than the line scanner, which stopped early. Release build, 208 real registry manifests × 20 iterations:

  • old scanner: 0.5 µs per manifest;
  • new reader: 81 µs per manifest.

crawl_all reads each crate's Cargo.toml on the walk pool, so 1,000 cached crates cost about 80 ms of extra CPU spread across the pool's threads. This is the price of agreeing with cargo, and #693 asks for toml_edit explicitly. S = 0 (no speed-up claimed).

Tests

  • New: vex::product::tests::cargo_manifest_readers_agree. It runs the issue's drift rows (plain, BOM, [project], dotted, inline, workspace, invalid, no package) through the crawler's reader, VEX parse_cargo_toml and cargo_tag::tag_manifest_text, and asserts they agree.
  • New: formats::cargo::manifest::tests, covering every spelling, [package] over [project], and the inputs it can't read.
  • New: find_by_purls_vendor_layout_reads_every_manifest_spelling (crawler e2e): vendored crates with a BOM, [project] or dotted-key manifest are found. It fails on main, where the scanner returns None and the version-less dir name can't stand in.
  • cargo clippy --workspace --all-features -- -D warnings: clean.
  • cargo test -p socket-patch-core --lib: 5711 passed, 4 failed. The 4 are the known root-only sandbox failures that also fail on main (copy_tree::relax_loop_must_not_traverse_symlinked_root, vlt_heal::an_unremovable_hidden_lock_keeps_every_store_entry, pypi_poetry::wire_write_failure_maps_error_and_leaves_lock_untouched, pypi_requirements::wire_failure_rolls_back_already_written_files).
  • cargo test -p socket-patch-core --test crawler_cargo_e2e: 34 passed.
  • cargo test -p socket-patch-cli --all-features with --test in_process_cargo_apply, mode_migration_cargo, e2e_cargo, covgap_commands_vex, e2e_vex_redirect and e2e_vex_vendor: all green.

Risk

Low. The changes are the documented reader cases above, and the extra parse CPU on the cargo crawl path.

🤖 Generated with Claude Code


Note

Medium Risk
Changes crate discovery and VEX product PURLs for non-standard but cargo-valid manifests; crawl path is slower per manifest though normal registry layouts are unchanged.

Overview
Unifies Cargo.toml package identity behind a single toml_edit reader in formats::cargo::manifest (package_name_version / package_table), replacing three divergent parsers (cargo crawler line scanner, VEX scan_toml_section, and duplicated table lookup in cargo_tag).

The cargo crawler and its test oracle now call package_name_version; the hand-rolled parser and most of its unit tests are deleted. VEX parse_cargo_toml and cargo_tag::version_literal route through the same module. Behavior shifts for edge manifests cargo accepts: UTF-8 BOM, legacy [project], dotted keys, and inline package = { … } are read consistently (fixing vendored crates whose dir name has no version). Invalid TOML is no longer partially parsed by the crawler scanner—it returns None and may fall back to directory-name parsing. Crawl path pays a full toml_edit parse per manifest.

Tests add manifest unit coverage, cargo_manifest_readers_agree, and vendor-layout e2e for alternate spellings.

Reviewed by Cursor Bugbot for commit 3f4b741. Configure here.


Generated by Claude Code

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko Mikola Lysenko (mikolalysenko) added refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code arch-refactor PR opened by the scheduled architecture refactor routine labels Oct 8, 2026
The cargo crawler, VEX product detection and cargo_tag each read a
Cargo.toml [package] table their own way, and they disagreed: the
crawler's line scanner missed a manifest with a BOM, the legacy
[project] table or dotted keys, so such a vendored crate could not be
found at all, while it accepted text cargo rejects as invalid TOML.

formats::cargo::manifest now parses with toml_edit for all three, and
the crawler's hand-rolled scanner is deleted.

Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review October 8, 2026 06:21
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 8, 2026
Assisted-by: Claude Code:claude-opus-5-5

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3f4b741. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Ready for review (burn-down agent).

  • Head: 3f4b7417ccabb9577718e53ecaa97893cffc4a7e
  • CI: 503/503 check runs green (success/skipped/neutral) on this head, mergeable, no conflicts.
  • Bugbot: reviewed this head (Cursor Bugbot check: success), no unresolved review threads.
  • Changelog: untouched.

Nothing specific flagged for the reviewer beyond the PR description.


Generated by Claude Code

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit d52a67b Oct 8, 2026
504 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the arch-refactor/693-cargo-manifest-reader branch October 8, 2026 17:29
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 8, 2026
Assisted-by: Claude Code:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read Cargo.toml package name and version through one shared toml_edit reader

3 participants