Retain configuration provenance in hash and index diagnostics #2326
[P3] Separate nested-constraint enforcement from provenance tracking
This also changes which inputs enable hash enforcement. With requirements.txt containing -c policy.txt and an unhashed pinned requirement, --require-hashes in policy.txt now makes install/sync fail; the base implementation only merged constraint entries here. The new nested-constraint tests therefore cover a policy change as well as diagnostics. Move this enforcement change and its regression tests into a separate preparatory fix so its compatibility implications can be reviewed independently of the provenance plumbing.
<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->
Merging this PR will improve performance by 16.3%
<details>
<summary>:warning: <b>8 benchmarks spent significant time in system calls</b></summary>
System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.
> Measurement and system calls
> - `discover_workspace_from_all_members_with_excludes
-discover_workspace_from_all_members
-resolve_warm_airflow
-install_wheel_many_files
-run_python_version_synthetic_workspace
-resolve_warm_jupyter_universal
-unpack_sdist_many_files
-resolve_warm_jupyter
</details>
<details>
<summary>:warning: <b>Different runtime environments detected</b></summary>
Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.
> Open the report in CodSpeed to investigate
</details>
⚡ 1 improved benchmark ✅ 68 untouched benchmarks ⏩ 35 skipped benchmarks[^skipped]
Performance Changes
| | Mode | Benchmark | BASE | HEAD | Efficiency |
| --- | ---- | --------- | ------ | ------ | ---------- |
| ⚡ :warning: | Simulation | discover_workspace_from_all_members_with_excludes | 165.6 ms | 142.4 ms | +16.3% |
[!TIP]
Curious why performance improved? Comment @codspeedbot explain why performance improved` on this PR, or directly use the CodSpeed MCP with your agent.
---
<sub>Comparing <code>zb/configuration-provenance</code> (a0081fb) with <code>main</code> (64e2ac8)</sub>
<a href="https://app.codspeed.io/astral-sh/uv-dev/branches/zb%2Fconfiguration-provenance?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>
[^skipped]: 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
I don't know how I'd improve this necessarily, but flagging that it's pretty hard to read.
(Also FWICT any hints here get dropped anyways in enabled_hints?)
I think these two match statements could be merged for clarity.
I also noticed this during review, I think I agree that it'd be best as a separate PR.
[P3] Derive the transparent schema instead of forwarding private hooks
This implementation delegates every schema method to T, including _schemars_private_* hooks. A feature-gated JsonSchema derive with transparent schema behavior handles the single non-skipped field, following the existing DisplaySafeUrl pattern in uv-redacted. Use that derive and retain #[serde(skip)] on sources; this preserves the value-only schema while avoiding handwritten coupling to schemars internals.
[P3] Put command-specific regressions in their existing test suites
This uv run scenario and hash_sync_environment are registered under the pip_install test target, so focused runs of the existing run and pip_sync suites miss their new provenance coverage. The script test also combines two independent command paths. Move this invocation into a separately named test in crates/uv/tests/project/run.rs, and move the sync case into crates/uv/tests/pip/pip_sync.rs, alongside their existing script-configuration and hash-checking tests.
[P2] Update the existing nested-constraints snapshot
Collecting these hints also changes install_require_hashes_in_nested_constraints_txt in crates/uv/tests/pip_install/pip_install.rs. Its fixture enables hash checking through -c constraints.txt, so it now emits the hint identifying constraints.txt at line 1, included from requirements.txt at line 1. The existing snapshot still expects only the error and will no longer match. Update that snapshot alongside the new provenance tests.
[P3] Keep filesystem configuration sources explicitly local
From<&Path> interprets the literal path - as RequirementsInput::Stdin, but read_file reads it as an ordinary file. Consequently, --config-file - with pip.require-hashes = true attributes the resulting error to “script metadata read from stdin” instead of the configuration file. Construct RequirementsInput::Local(path.to_path_buf()) here so attaching provenance does not reinterpret the known filesystem source.
[P3] Generate provenance in the existing index-hint path
This introduces a second index-hint eligibility check over the unreduced error tree. The existing PubGrubReportFormatter::generate_hints uses the reduced tree and invokes index_hints for Custom/NoVersions incompatibilities; this pass also includes packages mentioned only in dependency edges. Attribution consequently follows different relevance rules, and future hint changes must maintain both paths. Generate a structured provenance hint in the existing UnavailablePackage::NoIndex handling, including its find-links branch, and leave this implementation responsible for rendering the collected hints.
woodruffw
zaniebot
--require-hashesand--no-indexfailures can be caused by configuration or nested requirements directives whose origins are lost during settings resolution. IntroduceSourced<T>to carry effective source information into hash and resolver diagnostics, identifying environment variables, configuration keys, and requirements file line numbers and include chains.Scalar precedence retains the winning declaration, while cumulative flags retain every enabling declaration. Source metadata is excluded from value equality, hashing, serialization, and configuration schemas.
Includes the nested-constraints hash enforcement from astral-sh/uv#22275, so included constraints retain both their policy and its source.