Skip to content

Share the yarn berry project gates between hosted and vendored modes #629

Description

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

Kind: refactor. Source: review Part 4.4 ("Yarn berry project gates are written twice") and 4.7 D; register E09.

Problem

The berry project-level refusals (mixed line endings, cacheKey, compressionLevel) are implemented once per mode. Verified on 045d7ec:

Piece Vendored Hosted
Supported cacheKey SUPPORTED_CACHE_KEY YARN_BERRY_SUPPORTED_CACHE_KEY ("matches the vendored backend's")
cacheKey extraction berry_metadata + berry_field over scan_blocks berry_cache_key,`` a split("\n\n") scan ("mirroring the vendored backend's `berry_field`")
Gate driver refuse_mixed_line_endings / refuse_unsupported_cache / refuse_unsupported_compression + yarn_berry_vendor_preflight preflight_yarn_berry_hosted
Refusal text three copies, worded differently three copies

Only yarnrc_compression_level is already shared (since #508 fixed #370 once for both modes). The rest has drifted:

Hosted mode also imports vendor::yarn_berry_lock::yarnrc_compression_level (redirect/mod.rs#L30), which is a redirect → vendor layering edge.

Symptoms and impact

#628. Any future berry gate, such as a new cache-format version, would again have to be added twice. The risk is low.

Proposed change

Add formats/yarn/berry_gates.rs, a pure module with no I/O:

  • SUPPORTED_CACHE_KEY, plus cache_key(lock_text) -> Option<&str> built on scan_blocks/berry_field;
  • yarnrc_compression_level, moved here;
  • fn check(lock: &str, manifest: Option<&str>, yarnrc: YarnrcState) -> Result<(), BerryGate>, where BerryGate is { MixedLineEndings { file }, CacheKey { found }, Compression { level }, YarnrcUnreadable } and owns the detail text.

Each mode maps BerryGate to its own code prefix (vendor_yarn_berry_* or redirect_yarn_berry_*), so the codes don't change.

Delete: YARN_BERRY_SUPPORTED_CACHE_KEY, berry_cache_key, the three refuse_* bodies' text, and the hosted refusal text. Keep this PR behavior-neutral apart from what #628 decides: either land #628's policy here, or keep hosted mode's manifest argument None until #628.

Size and scope

About 150 production lines moved and about 90 deleted, across vendor/yarn_berry_lock.rs, patch/redirect/mod.rs, a new formats/yarn/berry_gates.rs and the takeover caller in commands/scan/hosted.rs. Out of scope: the berry entry writers and restorers (E08), and the classic grammar.

Acceptance criteria

  • One cacheKey constant, one extractor and one gate function, used by vendored vendor/preflight, the hosted rewriter and the vendored→hosted takeover.
  • The codes are unchanged: vendor_yarn_berry_cache_unsupported, vendor_yarn_berry_mixed_line_endings, redirect_yarn_berry_cache_unsupported, redirect_yarn_berry_mixed_line_endings.
  • yarn_berry_warning_branches, mixed_line_endings_refuse_before_any_write, the yarnrc_compression_level_* tests and the takeover gate tests from Fix berry mode takeover reverting before gates (#468, #369) #470 stay green.
  • A table test feeds the same inputs (cacheKey 10, missing __metadata, compressionLevel: mixed, a mixed lock, a BOM lock) to both modes and asserts the same BerryGate.
  • patch/redirect no longer imports from vendor::yarn_berry_lock for gates.

Dependencies

Blocks nothing, and pairs with #628. It is part of review fix D (hosted yarn writers on LockBlock, E08).

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:claimedagent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)pm:yarn-berryYarn Berry (2+)priority:p1refactorStructural 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