Skip to content

Read and splice nuget.config through formats::nuget in hosted, vendored and restore #594

Description

[agent] Filed by the scheduled architecture audit routine (ecosystems and formats). Register: E11.

Kind: refactor. Source: review §3.7 #3, Part 3.4 and Part 5.4; register E11 (the NuGet half of E10).

Problem

nuget.config is read and spliced by six private code paths with four different XML rules. Only one of them is a real tokenizer.

Readers of the <packageSources> keys:

Splice anchors and removers:

Config file names are spelled four times: redirect::NUGET_CONFIG_FILE_NAMES,`` vendor::nuget_config::CONFIG_NAMES, `hosted/memory/roots.rs` and `formats/registry.rs`. They haven't drifted yet.

The code paths themselves have drifted. The vendored writer is comment-safe; the hosted writer and reader are not. The reader that upstream restore uses (parse_config) and the one the hosted rewriter uses disagree about the same file.

Symptoms

Impact

Every hosted NuGet bug about comments, self-closing sections or attribute spelling has to be fixed up to three times, and the reader each writer trusts is not the one restore and VEX trust. Size: about 250 production lines of regex and substring scanning.

Proposed change

  1. Extend formats::nuget with a span view: parse_config_spans(text) -> Option<NugetConfigSpans> records the byte offsets that every writer needs (the <configuration> open-tag end, the <packageSources> open/close or self-closing span, the <packageSourceMapping> ditto, the last <clear/> end in each, and each <add>/<packageSource> element span with its key). It is computed by the same tokenizer as parse_config, so comments and CDATA are never anchors.
  2. Hosted add_nuget_source and rewrite_nuget take the keys and anchors from it. Delete nuget_package_source_keys, the NUGET_PACKAGE_SOURCES_REGION_RE / NUGET_ADD_KEY_RE statics, the regexes in insert_nuget_source / nuget_mapping_open_end / add_nuget_source, and nuget_after_last_clear's comment masker.
  3. Hosted restore remove_source and vendored excise_source_mapping / parse_config_source_keys use the element spans. Delete both private attr_values and blank_comments (if no other caller remains).
  4. One formats::nuget::CONFIG_FILE_NAMES; delete the other three lists.

This can land as two PRs if it's too big: (a) the span view plus hosted (closes #561 and #585), (b) vendored and restore.

Size and scope

formats/nuget/mod.rs, patch/redirect/mod.rs (NuGet section only), patch/redirect/upstream/nuget.rs, vendor/nuget_feed.rs, vendor/nuget_config.rs, hosted/memory/roots.rs. About +200 / −300 production lines. Out of scope: Maven/Gradle XML (rest of E10) and the packages.lock.json walks (#593).

Acceptance criteria

Dependencies

Supersedes the narrower fix in #561 (either can land first; if #561 lands first, this deletes its remaining regex). Touches rewrite_nuget like #593, so sequence the two. Blocks the Maven/Gradle half of E10.

Activity

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

    agent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)pm:nugetNuGet / dotnetpriority:p3refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions