Skip to content

Inject config environment access (#293)#330

Open
lodyai[bot] wants to merge 7 commits into
mainfrom
issue-293-refactor-collect-diag-file-layers
Open

Inject config environment access (#293)#330
lodyai[bot] wants to merge 7 commits into
mainfrom
issue-293-refactor-collect-diag-file-layers

Conversation

@lodyai

@lodyai lodyai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

This branch completes the issue #293 environment-access refactor for early CLI
configuration resolution. It introduces an EnvProvider port, threads it
through explicit config selection and early diagnostic JSON resolution, and
removes the remaining direct process-environment dependency from
collect_diag_file_layers.

Closes #293.

Review walkthrough

Validation

  • cargo test --workspace config_merge: passed.
  • make check-fmt: passed.
  • make lint: passed.
  • make test: passed.
  • make markdownlint: passed.
  • make nixie: passed.
  • coderabbit review --agent: completed with zero findings on the main implementation pass.

Notes

make fmt was run after the documentation edit. Its Rust formatting step
completed, but the target exits non-zero in the Markdown formatting phase
because the underlying markdownlint --fix command reports repository-wide
line-length findings in pre-existing untouched documents. The formatter also
rewrote unrelated Markdown files, so those unrelated edits were restored. The
actual validation gates make check-fmt, make markdownlint, and make nixie
all pass on this branch.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @LodyAI[bot], you have reached your weekly rate limit of 2500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@lodyai[bot], we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 3 hours, 50 minutes, and 32 seconds. Learn how PR review limits work.

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7a9d6c27-d4f9-48ee-a3cb-45873c506a06

📥 Commits

Reviewing files that changed from the base of the PR and between 2ec7231 and 5c35764.

📒 Files selected for processing (9)
  • build.rs
  • docs/developers-guide.md
  • docs/netsuke-design.md
  • docs/rstest-bdd-v0-5-0-migration-guide.md
  • src/cli/diag.rs
  • src/cli/discovery.rs
  • src/cli/mod.rs
  • src/main.rs
  • tests/cli_tests/merge.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-293-refactor-collect-diag-file-layers

Comment @coderabbitai help to get the list of available commands and usage tips.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lodyai lodyai Bot force-pushed the issue-293-refactor-collect-diag-file-layers branch from ef01af0 to e0a6dd0 Compare June 8, 2026 20:31
codescene-delta-analysis[bot]

This comment was marked as outdated.

@lodyai lodyai Bot force-pushed the issue-293-refactor-collect-diag-file-layers branch from e0a6dd0 to ba1bce1 Compare June 8, 2026 22:17
codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos

leynos commented Jun 12, 2026

Copy link
Copy Markdown
Owner

@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.

Code Duplication

src/main.rs:

What lead to degradation?

The module contains 2 functions with similar structure: merge_cli_or_exit,resolve_diag_mode_or_exit

Why does this problem occur?

Duplicated code often leads to code that's harder to change since the same logical change has to be done in multiple functions. More duplication gives lower code health.

How to fix it?

A certain degree of duplicated code might be acceptable. The problems start when it is the same behavior that is duplicated across the functions in the module, ie. a violation of the Don't Repeat Yourself (DRY) principle. DRY violations lead to code that is changed together in predictable patterns, which is both expensive and risky. DRY violations can be identified using CodeScene's X-Ray analysis to detect clusters of change coupled functions with high code similarity. Read More
Once you have identified the similarities across functions, look to extract and encapsulate the concept that varies into its own function(s). These shared abstractions can then be re-used, which minimizes the amount of duplication and simplifies change.

@coderabbitai

This comment was marked as resolved.

@leynos

leynos commented Jun 15, 2026

Copy link
Copy Markdown
Owner

@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.

Code Duplication

src/main.rs:

What lead to degradation?

The module contains 2 functions with similar structure: merge_cli_or_exit,resolve_diag_mode_or_exit

Why does this problem occur?

Duplicated code often leads to code that's harder to change since the same logical change has to be done in multiple functions. More duplication gives lower code health.

How to fix it?

A certain degree of duplicated code might be acceptable. The problems start when it is the same behavior that is duplicated across the functions in the module, ie. a violation of the Don't Repeat Yourself (DRY) principle. DRY violations lead to code that is changed together in predictable patterns, which is both expensive and risky. DRY violations can be identified using CodeScene's X-Ray analysis to detect clusters of change coupled functions with high code similarity. Read More
Once you have identified the similarities across functions, look to extract and encapsulate the concept that varies into its own function(s). These shared abstractions can then be re-used, which minimizes the amount of duplication and simplifies change.

@coderabbitai

This comment was marked as resolved.

codescene-delta-analysis[bot]

This comment was marked as outdated.

leynos added 6 commits June 16, 2026 01:59
Introduce an `EnvProvider` port for CLI configuration resolution.
Thread it through explicit config selection, diagnostic layer
collection, and early diagnostic JSON resolution so tests can use
deterministic environment doubles instead of process-wide mutation.

Reject malformed `NETSUKE_DIAG_JSON` values with a validation error,
and keep discovery load errors visible while resolving startup
diagnostic mode.
Drop provider-free compatibility wrappers that became dead code after the
rebase onto the split `discovery` and `diag` modules. Keep the injected
provider helpers as the single internal path for config selection and early
JSON diagnostic resolution.

Update the related internal docs and test helper so the branch stays clean
under warnings-denied typechecking and Clippy.
Extract the shared configuration-error exit conversion used by early
diagnostic-mode resolution and full config merging.

Keep both callers as fallible combinator chains so the exit handling stays in
one place while preserving each function's public shape.
Convert wrapped Mermaid node labels to quoted labels with explicit line
breaks so `merman-cli` can parse the affected documentation diagrams.
Remove a duplicated unfenced Rust example that broke Markdown linting after the rebase and keep the conflict-resolved developer guide wrapped in the repository's documented style.
@lodyai lodyai Bot force-pushed the issue-293-refactor-collect-diag-file-layers branch from 273e983 to 678929e Compare June 16, 2026 00:04
codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos leynos marked this pull request as ready for review June 16, 2026 09:28

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @leynos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 678929ea38

ℹ️ 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".

Comment thread src/cli/diag.rs Outdated
env: &impl EnvProvider,
) -> OrthoResult<bool> {
let mut diag_json = diag_json_from_file_layers(cli, env)?;
if let Some(env_diag_json) = diag_json_from_env(env)? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honour CLI diag-json before env validation

When NETSUKE_DIAG_JSON contains a malformed value but the user supplies a higher-precedence CLI override such as --diag-json, this ? returns a validation error before diag_json_from_matches can apply the command-line value. That makes startup fail even though the CLI layer would otherwise replace the bad environment value for diag_json; check explicit CLI matches before validating the lower-precedence env fallback, or skip this env validation when the CLI value is present.

Useful? React with 👍 / 👎.

Skip parsing `NETSUKE_DIAG_JSON` when a command-line diagnostic JSON
selector is already present. The CLI layer has higher precedence, so a
malformed lower-precedence environment value must not prevent startup from
using `--diag-json` or `--output-format json`.

Add regression coverage for both CLI override paths against malformed
environment input.

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates Failed
Enforce advisory code health rules (1 file with Code Duplication)

Our agent can fix these. Install it.

Gates Passed
5 Quality Gates Passed

Reason for failure
Enforce advisory code health rules Violations Code Health Impact
diag.rs 1 advisory rule 10.00 → 9.39 Suppress

See analysis details in CodeScene

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

Comment thread src/cli/diag.rs
Comment on lines +236 to +267
fn resolve_merged_diag_json_honours_cli_output_format_before_malformed_env()
-> anyhow::Result<()> {
let dir = tempdir()?;
let config_path = dir.path().join("netsuke.toml");
std::fs::write(&config_path, "diag_json = false\n")?;
let cli = Cli::parse_from([
"netsuke",
"--config",
config_path
.to_str()
.expect("temp config path should be UTF-8"),
"--output-format",
"json",
]);
let matches = Cli::command().get_matches_from([
"netsuke",
"--config",
config_path
.to_str()
.expect("temp config path should be UTF-8"),
"--output-format",
"json",
]);
let env = TestEnv::default().with_var("NETSUKE_DIAG_JSON", "yes");

ensure!(
resolve_merged_diag_json_with_env(&cli, &matches, &env)?,
"CLI --output-format json should override malformed diagnostic JSON env"
);

Ok(())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Code Duplication
The module contains 2 functions with similar structure: tests.resolve_merged_diag_json_honours_cli_diag_json_before_malformed_env,tests.resolve_merged_diag_json_honours_cli_output_format_before_malformed_env

Suppress

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.

Refactor collect_diag_file_layers to return Result, expose fallibility in resolve_merged_diag_json, and inject environment access via trait interface

1 participant