Skip to content

⚒️ Forge: Refactor repetitive compare_field calls in diff_config.rs#625

Open
madmax983 wants to merge 1 commit into
trunkfrom
forge/refactor-diff-config-16519351247515352404
Open

⚒️ Forge: Refactor repetitive compare_field calls in diff_config.rs#625
madmax983 wants to merge 1 commit into
trunkfrom
forge/refactor-diff-config-16519351247515352404

Conversation

@madmax983
Copy link
Copy Markdown
Owner

  • 🚬 Smell: Repetitive block of compare_field with 8 arguments, duplicating paths and variables across 18 calls.
  • ✨ Solution: Abstracted the call into cmp_manifest and cmp_limits closures to simplify field comparisons.
  • 🧼 Benefit: Reduces boilerplate significantly, making the run method readable.
  • 🛡️ Verification: Cargo formatting, clippy and tests passed. No logic change.

PR created automatically by Jules for task 16519351247515352404 started by @madmax983

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors src/run/diff_config.rs to reduce boilerplate by introducing local closures (cmp_manifest and cmp_limits) for comparing manifest and limit fields. The reviewer suggests further simplifying the code: first, by replacing the cmp_manifest closure with a macro (cmp_manifest!) to avoid passing mutable vector references on every call; and second, by capturing the mutable vectors directly within the cmp_limits closure since they are used in a single contiguous block.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/run/diff_config.rs
Comment on lines +82 to +98
let cmp_manifest = |group: &str,
field: &str,
compared_fields: &mut Vec<ComparedField>,
changed_fields: &mut Vec<ChangedField>,
ignored_fields: &mut Vec<IgnoredField>| {
let path = format!(".{field}");
compare_field(
group,
&path,
&get_field_val(&baseline_manifest, &[group, field]),
&get_field_val(&candidate_manifest, &[group, field]),
compared_fields,
changed_fields,
ignored_fields,
&ignore_patterns,
);
};
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.

medium

Instead of a closure that requires passing compared_fields, changed_fields, and ignored_fields as arguments in every single call (due to borrow checker limitations across intermissions), we can define a macro cmp_manifest!. This allows direct access to the variables in the outer scope without passing them, significantly reducing boilerplate.

    macro_rules! cmp_manifest {
        ($group:expr, $field:expr) => {
            compare_field(
                $group,
                &format!(".{}", $field),
                &get_field_val(&baseline_manifest, &[$group, $field]),
                &get_field_val(&candidate_manifest, &[$group, $field]),
                &mut compared_fields,
                &mut changed_fields,
                &mut ignored_fields,
                &ignore_patterns,
            );
        };
    }

Comment thread src/run/diff_config.rs
Comment on lines +101 to 151
cmp_manifest(
"harness",
".name",
&get_field_val(&baseline_manifest, &["harness", "name"]),
&get_field_val(&candidate_manifest, &["harness", "name"]),
"name",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"harness",
".version",
&get_field_val(&baseline_manifest, &["harness", "version"]),
&get_field_val(&candidate_manifest, &["harness", "version"]),
"version",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"harness",
".git_sha",
&get_field_val(&baseline_manifest, &["harness", "git_sha"]),
&get_field_val(&candidate_manifest, &["harness", "git_sha"]),
"git_sha",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"harness",
".git_dirty",
&get_field_val(&baseline_manifest, &["harness", "git_dirty"]),
&get_field_val(&candidate_manifest, &["harness", "git_dirty"]),
"git_dirty",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);

// 2. dataset
compare_field(
cmp_manifest(
"dataset",
".path",
&get_field_val(&baseline_manifest, &["dataset", "path"]),
&get_field_val(&candidate_manifest, &["dataset", "path"]),
"path",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"dataset",
".sha256",
&get_field_val(&baseline_manifest, &["dataset", "sha256"]),
&get_field_val(&candidate_manifest, &["dataset", "sha256"]),
"sha256",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"dataset",
".instance_count",
&get_field_val(&baseline_manifest, &["dataset", "instance_count"]),
&get_field_val(&candidate_manifest, &["dataset", "instance_count"]),
"instance_count",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
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.

medium

Use the newly defined cmp_manifest! macro to simplify the field comparisons for harness and dataset.

    cmp_manifest!("harness", "name");
    cmp_manifest!("harness", "version");
    cmp_manifest!("harness", "git_sha");
    cmp_manifest!("harness", "git_dirty");

    // 2. dataset
    cmp_manifest!("dataset", "path");
    cmp_manifest!("dataset", "sha256");
    cmp_manifest!("dataset", "instance_count");

Comment thread src/run/diff_config.rs
Comment on lines +180 to 230
cmp_manifest(
"prompt_template",
".source",
&get_field_val(&baseline_manifest, &["prompt_template", "source"]),
&get_field_val(&candidate_manifest, &["prompt_template", "source"]),
"source",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"prompt_template",
".path",
&get_field_val(&baseline_manifest, &["prompt_template", "path"]),
&get_field_val(&candidate_manifest, &["prompt_template", "path"]),
"path",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"prompt_template",
".sha256",
&get_field_val(&baseline_manifest, &["prompt_template", "sha256"]),
&get_field_val(&candidate_manifest, &["prompt_template", "sha256"]),
"sha256",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);

// 4. model
compare_field(
cmp_manifest(
"model",
".name",
&get_field_val(&baseline_manifest, &["model", "name"]),
&get_field_val(&candidate_manifest, &["model", "name"]),
"name",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"model",
".backend",
&get_field_val(&baseline_manifest, &["model", "backend"]),
&get_field_val(&candidate_manifest, &["model", "backend"]),
"backend",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"model",
".backend_version",
&get_field_val(&baseline_manifest, &["model", "backend_version"]),
&get_field_val(&candidate_manifest, &["model", "backend_version"]),
"backend_version",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
cmp_manifest(
"model",
".base_url",
&get_field_val(&baseline_manifest, &["model", "base_url"]),
&get_field_val(&candidate_manifest, &["model", "base_url"]),
"base_url",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
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.

medium

Use the newly defined cmp_manifest! macro to simplify the field comparisons for prompt_template and model.

    cmp_manifest!("prompt_template", "source");
    cmp_manifest!("prompt_template", "path");
    cmp_manifest!("prompt_template", "sha256");

    // 4. model
    cmp_manifest!("model", "name");
    cmp_manifest!("model", "backend");
    cmp_manifest!("model", "backend_version");
    cmp_manifest!("model", "base_url");

Comment thread src/run/diff_config.rs
Comment on lines +275 to 315
let cmp_limits = |field: &str,
compared_fields: &mut Vec<ComparedField>,
changed_fields: &mut Vec<ChangedField>,
ignored_fields: &mut Vec<IgnoredField>| {
let path = format!(".{field}");
compare_field(
"limits",
&path,
&get_field_val(&base_limits, &[field]),
&get_field_val(&cand_limits, &[field]),
compared_fields,
changed_fields,
ignored_fields,
&ignore_patterns,
);
};

cmp_limits(
"step_limit",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
"limits",
".per_task_budget_usd",
&get_field_val(&base_limits, &["per_task_budget_usd"]),
&get_field_val(&cand_limits, &["per_task_budget_usd"]),
cmp_limits(
"per_task_budget_usd",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
"limits",
".task_timeout_secs",
&get_field_val(&base_limits, &["task_timeout_secs"]),
&get_field_val(&cand_limits, &["task_timeout_secs"]),
cmp_limits(
"task_timeout_secs",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
compare_field(
"limits",
".sweep_cost_limit_usd",
&get_field_val(&base_limits, &["sweep_cost_limit_usd"]),
&get_field_val(&cand_limits, &["sweep_cost_limit_usd"]),
cmp_limits(
"sweep_cost_limit_usd",
&mut compared_fields,
&mut changed_fields,
&mut ignored_fields,
&ignore_patterns,
);
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.

medium

Since cmp_limits is defined and used within a single contiguous block with no other intervening borrows of compared_fields, changed_fields, or ignored_fields, we can simplify the closure by capturing these variables mutably from the outer scope. This eliminates the need to pass them as arguments in every call.

    let mut cmp_limits = |field: &str| {
        let path = format!(".{field}");
        compare_field(
            "limits",
            &path,
            &get_field_val(&base_limits, &[field]),
            &get_field_val(&cand_limits, &[field]),
            &mut compared_fields,
            &mut changed_fields,
            &mut ignored_fields,
            &ignore_patterns,
        );
    };

    cmp_limits("step_limit");
    cmp_limits("per_task_budget_usd");
    cmp_limits("task_timeout_secs");
    cmp_limits("sweep_cost_limit_usd");

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.40%. Comparing base (e98c81c) to head (e055971).

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk     #625      +/-   ##
==========================================
- Coverage   85.40%   85.40%   -0.01%     
==========================================
  Files         116      116              
  Lines       67035    67021      -14     
==========================================
- Hits        57250    57236      -14     
  Misses       9785     9785              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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