fix(check): fail closed on malformed hubs + shared iter_hubs() helper#50
Merged
Conversation
Extract `Workspace::iter_hubs()` so the four filesystem commands (check, lint, suggest, for) share one hub-load loop that carries the parse result per-hub, forcing each caller to handle a malformed hub explicitly (#36). On that helper, close two fail-open paths in the gate (#35): an unparseable hub now emits an `Unresolvable` divergence instead of being silently skipped, and a hash error returns `Unresolvable` instead of `.ok()?` counting it clean. Closes #35, #36 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a claim on check_workspace governing #35's invariant — an unparseable hub yields an Unresolvable divergence rather than being silently skipped — so a future refactor can't quietly reintroduce the fail-open. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #35 and #36 (one logical change set — the issues recommend doing #36 first so #35 lands cleaner).
#36 — shared hub-iteration helper
Adds
Workspace::iter_hubs()(surf-cli/src/workspace.rs) returningVec<LoadedHub>, each carrying the parseResult<Hub, HubError>per-hub. I/O failure still hard-errors the run; the parse result — the thing that was being handled inconsistently across commands — is now surfaced so every caller must match on it. The four filesystem commands (check,lint,suggest,for) migrate onto it.#35 — close the gate's fail-open paths
Unresolvabledivergence (gate exits non-zero) instead of being silentlycontinued.Unresolvableinstead of.ok()?mapping it to "no divergence".Tests
malformed_hub_blocks_check: a frontmatter typo produces oneUnresolvabledivergence with aninvalid hub: …detail.resolve()runs beforehash_anchor_with, so a reachable input that resolves but fails to hash is not readily constructible; existing resolve-error tests already cover theUnresolvablepath. No contrived test added.Verification
cargo test --all,cargo clippy --all-targets --all-features -- -D warnings,cargo fmt --all --checkall pass.surf checkexit 1 with anUNRESOLVEDline and a matchingunresolvableJSON divergence.surf lint+surf checkpass on this repo (the two anchored functions I edited,check_claimandfind, were re-verified — their prose still holds).🤖 Generated with Claude Code