Skip to content

Fix round-41 vespera_macro findings (cfg gates, path resolution, cron aliases, export cache) - #520

Open
owjs3901 wants to merge 1 commit into
mainfrom
fix/macrorest-round41
Open

owjs3901 wants to merge 1 commit into
mainfrom
fix/macrorest-round41

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Round-41 fixes for the vespera_macro scope (plus one small vespera_core helper).

Findings

ID Status Change
R41-MR0-M1 (medium) Fixed A route file's own inner #![cfg(..)] now gates its routes on the slow path (cfg_routes, not an ungated route). An inner #![cfg(test)] makes a stored route file test-only. The module tree also applies a declarer's inner cfg to the modules it declares. Cron discovery applies a file's inner cfg to its jobs (same class).
R41-M1-L1 Fixed (module_tree was already right) path_tree now resolves an inline top-level #[path] block against the declaring file's directory. See the rustc result below.
R41-MR3-L1 Refuted in practice See below. Doc corrected only.
R41-MR3-L2 Fixed A lifetime or const named like a module no longer makes a::NotFound a dangling reference. A type parameter head (T::Assoc) is still rejected.
R41-MR4-L1 Fixed $ref fragments are percent-decoded before the name is taken, via the new vespera_core::schema::split_schema_ref (its raw suffix is kept). schema_name_of_ref now delegates to it.
R41-MR5-L1 Fixed use vespera::cron as job; (also grouped) and use vespera as v; + #[v::cron] are recognised per module. A foreign cron alias and deeper paths are not claimed.
R41-MR6-L1 Fixed An export_app! cache hit compares the content-addressed include copy with its validated sidecar (the sidecar minus its catch-all key). A truncated or edited copy regenerates.
R41-MR6-L2 Fixed The harness-build test also probes prune_superseded_older_than(Duration::ZERO) and asserts the library copy survives.

rustc #[path] probe (R41-M1-L1)

Scratch crate, cargo run (rustc in this toolchain):

  • src/routes.rs containing #[path = "d"] mod h { pub mod x; }, with src/d/x.rs present: the build loads src/d/x.rs.
  • Same with only src/routes/d/x.rs present (src/d/x.rs removed): E0583, file not found. The child-directory candidate is never loaded.

So an inline top-level #[path] in a non-mod-rs file is relative to the declaring file's directory. Inside an inline block, a mod x; resolves under the block's directory as before. The module_tree resolver already followed this rule. path_tree did not, and is fixed. Tests were added to both resolvers' test sets.

R41-MR3-L1 refutation

responses = [(400, Page::<User>)] is already rejected by the #[route] argument parser (args.rs, "responses type must not have generic arguments"), which runs before response_type_path. No compiled route can reach the dropped-arguments path. I first added a second check in typed_response_entry, but it was unreachable from any test, so I reverted it to keep the line-coverage gate at 100%. Only the response_type_path doc was corrected to say the argument parser rejects such paths.

Verification

  • cargo test -j 2 -p vespera_macro --tests: 6530 unit tests and the trybuild UI suite pass.
  • cargo test -j 2 -p vespera_core --lib: 337 pass.
  • cargo clippy -p vespera_core -p vespera_macro --all-targets -- -D warnings clean; -p vespera_macro --no-default-features --all-targets clean.
  • cargo fmt -p vespera_macro -p vespera_core -- --check clean.
  • Changed files are all under the 1000-line cap (largest: router_codegen/export.rs 967, vespera_impl/cron_discovery.rs 961).
  • Tarpaulin was not run locally (it is a CI gate); each new line is reached by a test by inspection.
  • route_impl.rs moved its ROUTE_STORAGE test block to a new sidecar route_impl/tests_storage.rs for the cap.

Changepack

.changepacks/changepack_log_macrorest_round41.json: all seven packages at Patch.

🤖 Generated with Claude Code

…R5-L1, MR6-L1/L2)

- Route files: a route file's own inner #![cfg(..)] gates its routes on
  the slow path (cfg_routes, not an ungated route), and an inner
  #![cfg(test)] makes a stored route file test-only. A declarer's inner
  cfg gates the modules it declares (module tree).
- Module tree vs test-scope: rustc resolves an inline #[path = "d"] mod h
  at the top of a non-mod-rs file against the declaring file's directory
  (src/routes.rs -> src/d/x.rs, checked with a scratch crate: the
  src/routes/d/x.rs child-dir candidate does not compile). path_tree now
  follows that rule.
- $ref rewrite: the fragment is percent-decoded before the name is taken
  (Pet%2Fx names Pet, suffix kept raw), via a new vespera_core
  split_schema_ref helper.
- Generic handlers: only a type parameter can head a path, so a lifetime
  or const named like a module (a::NotFound under <'a>) is no longer
  rejected as a dangling reference.
- Cron scan: jobs spelled through a local alias of vespera::cron
  (use vespera::cron as job) or of the vespera crate (use vespera as v)
  are discovered; a file's own inner #![cfg] gates its jobs.
- export_app! cache hits validate the content-addressed include copy
  against its sidecar instead of only checking that it exists.
- Test hygiene: the harness-build test probes prune_superseded_older_than
  with zero grace.

Refuted: R41-MR3-L1 (a generic-argument responses type silently dropped).
args.rs already rejects it at the #[route] attribute, before
response_type_path runs, so no compiled route can reach the drop; only the
doc was corrected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant