Cache config file layer discovery (#319) - #548
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Summary
WalkthroughThe CLI now uses ChangesConfiguration discovery and merge reuse
Sequence Diagram(s)sequenceDiagram
participant main
participant resolve_json_and_layers_with_env
participant discover_file_layers
participant merge_with_layers
main->>resolve_json_and_layers_with_env: resolve JSON mode and discover layers
resolve_json_and_layers_with_env->>discover_file_layers: load configuration layers
discover_file_layers-->>resolve_json_and_layers_with_env: return DiscoveryOutcome
resolve_json_and_layers_with_env-->>main: return JSON mode and DiscoveredLayers
main->>merge_with_layers: pass DiscoveredLayers
merge_with_layers-->>main: return merged CLI configuration
Poem
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 warning, 8 inconclusive)
✅ Passed checks (11 passed)
📋 Issue PlannerBuilt with CodeRabbit's Coding Plans for faster development and fewer bugs. View plan used: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideRefactors CLI configuration discovery and merge to cache file-backed config layers discovered in a single pre-pass driven by a generic Env interface, then reuse those layers for diagnostics and full merge; replaces custom EnvProvider with mockable::Env/DefaultEnv, adjusts JSON/merge flows and tests to use the cached DiscoveredLayers and the mockable test helpers. Sequence diagram for cached config layer discovery and mergesequenceDiagram
actor User
participant Main as main_rs
participant Diag as cli_diag
participant Discovery as cli_discovery
participant Merge as cli_merge
participant Env as DefaultEnv
User ->> Main: run_with_args
Main ->> Diag: resolve_diag_mode_or_exit(parsed_cli, matches, fallback_mode)
Diag ->> Diag: resolve_json_and_layers_with_env(cli, matches, Env)
Diag ->> Discovery: collect_diag_file_layers_with_env(cli, Env)
Discovery ->> Discovery: discover_file_layers(cli, Env)
Discovery ->> Env: resolve_config_selector(cli.config, Env)
Discovery -->> Diag: DiscoveredLayers
Diag ->> Diag: json_from_layers(DiscoveredLayers.layers())
Diag ->> Env: json_from_env(Env)
Diag -->> Main: (DiagMode, DiscoveredLayers)
Main ->> Discovery: DiscoveredLayers.replay_config_path_trace()
Main ->> Merge: merge_cli_or_exit(parsed_cli, matches, DiagMode, DiscoveredLayers)
Merge ->> Merge: merge_with_layers(cli, matches, Env, DiscoveredLayers)
Merge ->> Discovery: push_discovered_file_layers(composer, errors, DiscoveredLayers)
Merge ->> Env: Env.all()
Merge ->> Merge: Figment::from(EnvironmentLayer::new(env_entries))
Merge -->> Main: merged Cli
Main -->> User: exit code / program outcome
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. Ensure that this is validated against the current version of the codegraph. If further refinement to address this finding would be deleterious, please supply a clear explanatory one to two paragraph markdown message I can paste into the CodeScene web ui's diagnostic suppression function so this diagnostic can be silenced. src/cli/discovery_layer_tests.rs Comment on lines +201 to +219 fn discover_file_layers_records_an_explicit_load_error() -> Result<()> {
let dir = tempdir().context("create temporary config directory")?;
let cli = Cli {
config: Some(dir.path().join("missing.toml")),
..Cli::default()
};
let discovered = discover_file_layers(&cli, &empty_mock_env());
ensure!(
discovered.layers().is_empty(),
"a missing explicit config should not produce layers"
);
ensure!(
discovered.errors.len() == 1,
"a missing explicit config should record one error"
);
Ok(())
}❌ New issue: Code Duplication |
This comment was marked as resolved.
This comment was marked as resolved.
|
@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. Ensure that this is validated against the current version of the codegraph. If further refinement to address this finding would be deleterious, please supply a clear explanatory one to two paragraph markdown message I can paste into the CodeScene web ui's diagnostic suppression function so this diagnostic can be silenced. tests/logging_stderr/config_tracing.rs Comment on lines +136 to +139 ensure!(
joined.contains("resolved config path") && joined.contains("selector=\"cli_flag\""),
"verbose stderr should replay the cached selector decision: {joined}"
);❌ New issue: Code Duplication |
This comment was marked as resolved.
This comment was marked as resolved.
79f2d41 to
7847192
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78471925eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Replace the bespoke config-selector environment trait with `mockable::Env` so discovery and merging use the established injectable seam. Keep automatic discovery from re-reading `NETSUKE_CONFIG` after that injected lookup, and adapt deterministic unit, integration, and BDD coverage to `MockEnv`.
Discover file-backed configuration layers once during diagnostic resolution and pass that result into the full merge. This preserves existing standalone merge behaviour while removing repeated startup file loading. Keep verbose selector tracing by replaying the cached decision after the diagnostic output mode enables the tracing filter. Cover the shared flow with a mock environment that permits one config-selector lookup only.
Keep non-Unicode configuration selectors and process environment entries in their raw form so selection remains correct and environment-layer validation can apply its documented policy without a startup panic. Retain cached selector diagnostics through failed startup resolution, so verbose users receive the same bounded context for configuration errors.
Document the current mockable environment APIs and cached discovery handoff while removing the retired provider interfaces.
Retain bounded selector, branch, and project-scope metadata while loading configuration layers. Replay the original diagnostics after startup enables verbose output without rereading the environment or filesystem. Cover explicit and automatic replay paths, project-scope outcomes, and verbose stderr output while preserving the existing bounded trace schema.
Replace retired environment-provider references with the current `mockable::Env` boundary and describe the cached `DiscoveredLayers` handoff used by startup.
Update the CLI architecture references for `DiscoveryOutcome`, its `emit_diagnostics()` and `into_layers()` composition boundary, and the production raw-environment merge handoff.
Describe the current cached discovery and deferred-diagnostics helpers, and remove references to the retired direct file-layer push flow.
Keep discovery side-effect free by returning cached layers and bounded diagnostics in `DiscoveryOutcome`. Emit the retained events only at the startup or standalone merge composition boundary, so verbose output remains complete without a second discovery pass. Compile an external Cargo fixture against the public cached configuration API and cover deferred tracing, load warnings, and selector-free branches.
Register the compile-pass fixture's Cargo manifest so dependency updates continue to cover every checked-in Rust package and the manifest inventory gate remains accurate.
Record a bounded counter at each full-merge boundary to distinguish reuse of pre-discovered layers from standalone discovery. Keep paths, selectors, errors, and configuration values out of metric labels. Cover both outcomes with local recorders and document the telemetry contract for future startup observability work.
Explain the unstable cached-discovery hand-offs, the replacement environment seam, and standalone composition alternatives for API callers.
Keep deferred configuration diagnostics to their correlation hash, presence, selector, and failure-class fields so verbose output cannot disclose a raw configuration file name.
Make the compile-pass fixture explicitly discard its `OrthoResult` values without changing its cached-configuration flow or function-item binding.
Remove duplicate blank lines introduced while reconciling the migration and configuration documentation during the rebase.
df3a87c to
926a27f
Compare
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- revision and worktree ---'
git rev-parse --short HEAD
git status --short
printf '%s\n' '--- PR head and check state ---'
gh pr view 548 --repo leynos/netsuke \
--json headRefOid,updatedAt,files,statusCheckRollup \
--jq '{
headRefOid,
updatedAt,
files: [.files[].path],
checks: [.statusCheckRollup[] | {name, status, conclusion, workflowName}]
}'
printf '%s\n' '--- affected documentation changed from main ---'
base="$(git merge-base HEAD origin/main)"
git diff --name-status "$base" HEAD -- \
docs/users-guide.md \
docs/v0-1-0-migration-guide.md
printf '%s\n' '--- documentation coverage ---'
for file in docs/users-guide.md docs/v0-1-0-migration-guide.md; do
printf '%s\n' "--- $file ---"
rg -n -C2 \
'cached configuration discovery|discovered layers|ConfigEnvProvider|ConfigStdEnvProvider|mockable::(Env|DefaultEnv|MockEnv)|resolve_json_and_layers_(with_env|outcome_with_env)|merge_with_(layers|process_environment_layers|config|config_and_env)' \
"$file" || true
done
printf '%s\n' '--- public CLI configuration exports ---'
sed -n '1,120p' src/cli/mod.rs
printf '%s\n' '--- relevant public declarations ---'
rg -n -A16 -B3 \
'pub (fn|struct) (resolve_json_and_layers_with_env|resolve_json_and_layers_outcome_with_env|merge_with_layers|merge_with_process_environment_layers)|pub struct (DiscoveredLayers|DiscoveryOutcome)' \
src/cli/diag.rs src/cli/discovery.rs src/cli/merge.rs || true
printf '%s\n' '--- documentation validation targets ---'
rg -n -C2 \
'markdownlint|mdformat|prettier|^[[:space:]]*(fmt|format|markdownlint):' \
Makefile justfile package.json .github 2>/dev/null || trueLength of output: 5551 🏁 Script executed: #!/bin/bash
set -u
base="$(git merge-base HEAD origin/main)"
printf '%s\n' '--- documentation diff ---'
git diff --unified=3 "$base" HEAD -- \
docs/users-guide.md \
docs/v0-1-0-migration-guide.md || true
printf '%s\n' '--- users guide cached configuration section ---'
rg -n -i -A70 -B8 \
'cached configuration discovery|ConfigEnvProvider|ConfigStdEnvProvider' \
docs/users-guide.md || true
printf '%s\n' '--- migration guide cached configuration section ---'
rg -n -i -A100 -B8 \
'cached cli configuration api|cached configuration discovery|ConfigEnvProvider|ConfigStdEnvProvider' \
docs/v0-1-0-migration-guide.md || true
printf '%s\n' '--- current configuration exports ---'
sed -n '15,70p' src/cli/mod.rs || true
printf '%s\n' '--- resolution and merge signatures ---'
rg -n -A20 -B3 \
'pub fn (resolve_json_and_layers_with_env|resolve_json_and_layers_outcome_with_env|merge_with_layers|merge_with_process_environment_layers|merge_with_config|merge_with_config_and_env)' \
src/cli/diag.rs src/cli/merge.rs || true
exit 0Length of output: 18830
Mark the User-Facing Documentation warning as resolved at revision The users’ guide now documents cached configuration discovery, the required normal and diagnostic hand-offs, the The v0.1.0 migration guide now classifies this as a breaking unstable Rust API change. It gives the migration flow and identifies The current documentation matches the public exports and signatures in 🧠 Learnings usedYou are interacting with an AI system. |
Summary
This branch discovers file-backed configuration layers once during diagnostic
mode resolution and passes the loaded result to the full configuration merge.
It preserves standalone merge callers, selector precedence, and verbose
selector tracing without a second environment lookup or filesystem load.
The regression test drives the diagnostic and merge phases with one
mockable::MockEnv, requiring exactly oneNETSUKE_CONFIGlookup whileconfirming that configuration values remain merged.
Closes #319.
Validation
make check-fmtmake test(1,915 tests passed; 1 skipped; doctests passed)make lintmake typecheckcoderabbit review --agent(0 findings)References
Summary by Sourcery
Cache configuration file layer discovery so diagnostic JSON resolution and full configuration merge share a single environment-driven discovery pass.
New Features:
Bug Fixes:
Enhancements:
Build:
Tests: