Skip to content

Locate hosted Maven pom edits and their upstream restore through the formats::maven element scanner #717

Not planned

Description

[agent] Filed by the scheduled architecture audit routine (ecosystems and formats). Register: discussion #560 register.

Kind: refactor (it fixes bugs as a side effect). Source: review Part 5.4, register E10; child of #715.

Problem

The hosted Maven rewriter and its upstream restore find their edit points in the raw pom text:

  • patch/redirect/mod.rs#L6052-L6099:`` MAVEN_DEPENDENCY_BLOCK_RE (`(?s)<dependency\b[^>]>.?`) and `maven_tag_inner_range`, which takes the first `` / `` / `` substring in the block.
  • L6240 and L6389:`` "already wired" is pom_text.contains("<id>{repo_id}</id>").
  • insert_maven_repository / insert_maven_dependency_management L6510-L6545:`` replacen("<repositories>"), `(?s)\s*`, `replacen("")`.
  • Restore reuses the same regex in upstream/maven.rs#L59-L111`` (dep_matches, `dm_sections`, `remove_repository`).

None of these skip comments, CDATA, <profiles>, <build><plugins>…<dependencies> or <exclusions>. The reader that hosted VEX uses on the same file, formats::maven::parse_pom, skips all of them, with offsets preserved (blank_non_markup / open_tags / elements).`` So the writer edits elements the reader then refuses to attest.

Symptoms

I'll comment once on each.

Proposed change

  1. In formats/maven, expose a small offset-preserving query API over the masked text that parse_pom already builds: project-scope <dependency> elements (with managed / in_profile / in-build flags, <exclusions> blanked), the child-text ranges of groupId / artifactId / version / type, and the project-level <repositories> / <dependencyManagement><dependencies> / </project> anchors (self-closed forms included). parse_pom is rebuilt on the same calls.
  2. In the hosted rewriter, replace MavenDependencyMatch / maven_tag_inner_range / MAVEN_DEPENDENCY_BLOCK_RE / find_maven_dependency_matches, the <id> substring checks and the two insert_* anchors with those queries. The byte splices and the warning codes stay.
  3. In restore, dep_matches and dm_sections use the same queries, and restore's import of the hosted regex is deleted.

Deleted: MAVEN_DEPENDENCY_BLOCK_RE, maven_tag_inner_range, maven_tag_text_in, find_maven_dependency_matches, restore's dep_matches / dm_sections regexes.

Size and scope

formats/maven/mod.rs (+80), patch/redirect/mod.rs (−70 / +50), patch/redirect/upstream/maven.rs (−40 / +~30), plus tests. About 300 changed production lines. Out of scope: vendored build_repo_edit, the reactor, the CRLF of inserted blocks (#273), and ${property} coordinates.

Acceptance criteria

  • Regression tests in redirect for: a commented-out <dependency> with a literal version beside a versionless real one (the pin goes to <dependencyManagement>, the comment is byte-identical); a plugin <dependencies> entry for the same GA (untouched); <exclusions> before <groupId> (the direct literal is rewritten); <repositories/> and <dependencyManagement/> self-closed, and a comment between <dependencyManagement> and <dependencies> (no second section, Maven-parseable output)
  • For each case, vex::discover::maven attributes the rewritten pom (a round-trip test: rewrite, then discover)
  • The Maven redirect goldens (tests/fixtures/redirect/maven), upstream::maven tests (refusals_change_nothing, crlf_pom_round_trips, …) and the hosted e2e stay green; restore of every new case is byte-exact
  • grep -n MAVEN_DEPENDENCY_BLOCK_RE -r crates finds nothing

Dependencies

None blocking. Second child of #715; independent of #716. Should land before the child that moves maven_reactor::Doc into formats/maven, which then swaps the scanner under these queries without touching callers.

Activity

  1. added
    arch-audit
    refactor
    on Oct 3, 2026
  2. mikolalysenko commented on Oct 3, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Triaged as priority:p3 (Maven refactor). Child of #715; not a duplicate, and no open PR covers it.


    Generated by Claude Code

  3. mikolalysenko commented on Nov 26, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Architecture refactor routine: I checked this on main at cfc870f. The defects it describes are gone, so I'm closing it as not planned for what is left.

    What main does. The hosted Maven rewriter no longer finds dependencies with a regex. find_maven_dependency_matches reads maven_index::PomIndex, which is built on formats::maven::PomScope: it skips comments, CDATA, <build> and <reporting>, and flags <profiles>. The upstream restore reads the same scoped dependencies in dep_matches. It falls back to the block regex only for a pom that PomScope cannot read.

    Ran. A throwaway unit test gave rewrite_registry_redirect the five poms of the acceptance criteria:

    pom Result on main
    a commented-out <dependency> with a literal version, beside a real one with none the comment is byte-identical; the pin goes to a new <dependencyManagement>
    a plugin's <dependencies> entry for the same GA untouched; the pin goes to <dependencyManagement>
    <exclusions> before <groupId> the dependency's own <version> is rewritten
    self-closed <repositories/> and <dependencyManagement/> each is expanded in place, with no second section
    a comment between <dependencyManagement> and <dependencies> the pin is inserted past the comment, with no second section

    The restore tests over the same shapes pass:

    $ cargo test -p socket-patch-core --lib -- scoped_rewrites_round_trip \
        a_commented_repository_twin_does_not_block_restore \
        expanded_self_closed_sections_restore_to_one_empty_section
    test result: ok. 3 passed; 0 failed; 0 ignored
    

    scoped_rewrites_round_trip restores the comment-dependency, plugin-dependency, commented-repositories and depmgmt-comment goldens to their input.

    What is left. MAVEN_DEPENDENCY_BLOCK_RE, maven_tag_inner_range and maven_tag_text_in still exist, as that fallback and for reading a <repository>'s <url>. Deleting them changes nothing a user can see, and the routine's charter no longer takes up changes like that. Please reopen this if a pom turns up that the rewriter or the restore still gets wrong.


    Generated by Claude Code

  4. added a commit that references this issue on Nov 26, 2026
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-auditpm:mavenpriority:p3refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions