Skip to content

fix: deduplicate test function names in render_test_plan#938

Merged
chubes4 merged 1 commit intomainfrom
fix/test-gen-dedup-names
Mar 23, 2026
Merged

fix: deduplicate test function names in render_test_plan#938
chubes4 merged 1 commit intomainfrom
fix/test-gen-dedup-names

Conversation

@chubes4
Copy link
Member

@chubes4 chubes4 commented Mar 23, 2026

Summary

Fixes duplicate test function names that break compilation in auto-generated tests (#818).

Problem

When a function has multiple branches with identical slugified conditions (e.g., two None => return false match arms), the test generator produces duplicate fn test_foo_none_return_false() definitions. Rust compilation fails:

error[E0428]: the name `test_artifact_is_fresh_none_return_false` is defined multiple times

This is one of the bugs causing the pre-existing cargo test compilation failures in version_overrides.rs.

Fix

render_test_plan now tracks seen test names in a HashMap. When a duplicate is detected, it appends a numeric suffix (_2, _3, etc.):

test_check_status_none_return_false     // first occurrence
test_check_status_none_return_false_2   // second
test_check_status_none_return_false_3   // third

Test

Added test_render_test_plan_deduplicates_identical_names — 3 cases with identical names, verifies suffix behavior.

When multiple branches produce identical slugified conditions (e.g. two
'None => return false' match arms), the test generator now appends
numeric suffixes (_2, _3, ...) instead of producing duplicate function
names that prevent compilation.

Tracks seen names in a HashMap during rendering and only appends a
suffix when a name has been used before. Includes a unit test with
3 identical names verifying the suffix behavior.
@chubes4 chubes4 merged commit e0ceae4 into main Mar 23, 2026
1 check passed
@chubes4 chubes4 deleted the fix/test-gen-dedup-names branch March 23, 2026 02:07
@homeboy-ci
Copy link
Contributor

homeboy-ci bot commented Mar 23, 2026

Homeboy Results — homeboy

Audit

Failure Digest

Audit Failure Digest

  • Alignment score: 0.921
  • Severity counts: info: 2, unknown: 3, warning: 14
  • Outliers in current run: 3
  • Parsed outlier entries: 3
  • Drift increased: yes
  • New findings since baseline: 3
    1. intra-method-duplication — Duplicated block in test_render_test_plan_deduplicates_identical_names — 7 identical lines at line 2158 and line 2166 (intra-method-duplication::src/core/engine/contract_testgen.rs::IntraMethodDuplicate)
    2. dead_code — Public function 'generate_tests_for_file' is not referenced by any other file (dead_code::src/core/engine/contract_testgen.rs::UnreferencedExport)
    3. dead_code — Public function 'generate_tests_for_methods' is not referenced by any other file (dead_code::src/core/engine/contract_testgen.rs::UnreferencedExport)
  • Top actionable findings:
    1. src/core/engine/contract_testgen.rs — god_file — File has 2940 lines (threshold: 1000)
    2. src/core/engine/contract_testgen.rs — intra_method_duplicate — Duplicated block in test_render_test_plan_deduplicates_identical_names — 7 identical lines at line 2158 and line 2166
    3. src/core/engine/contract_testgen.rs — unreferenced_export — Public function 'generate_tests_for_file' is not referenced by any other file
    4. src/core/engine/contract_testgen.rs — unreferenced_export — Public function 'generate_tests_for_methods' is not referenced by any other file
    5. src/core/engine/contract_testgen.rs — missing_test_method — Method 'build_project_type_registry' has no corresponding test (expected 'test_build_project_type_registry')
All parsed audit findings (19)
1. **src/core/engine/contract_testgen.rs** — god_file — File has 2940 lines (threshold: 1000)
2. **src/core/engine/contract_testgen.rs** — intra_method_duplicate — Duplicated block in `test_render_test_plan_deduplicates_identical_names` — 7 identical lines at line 2158 and line 2166
3. **src/core/engine/contract_testgen.rs** — unreferenced_export — Public function 'generate_tests_for_file' is not referenced by any other file
4. **src/core/engine/contract_testgen.rs** — unreferenced_export — Public function 'generate_tests_for_methods' is not referenced by any other file
5. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'build_project_type_registry' has no corresponding test (expected 'test_build_project_type_registry')
6. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'generate_test_plan' has no corresponding test (expected 'test_generate_test_plan')
7. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'generate_test_plan_with_types' has no corresponding test (expected 'test_generate_test_plan_with_types')
8. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'generate_tests_for_file' has no corresponding test (expected 'test_generate_tests_for_file')
9. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'generate_tests_for_file_with_types' has no corresponding test (expected 'test_generate_tests_for_file_with_types')
10. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'generate_tests_for_methods' has no corresponding test (expected 'test_generate_tests_for_methods')
11. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'generate_tests_for_methods_with_types' has no corresponding test (expected 'test_generate_tests_for_methods_with_types')
12. **src/core/engine/contract_testgen.rs** — missing_test_method — Method 'render_test_plan' has no corresponding test (expected 'test_render_test_plan')
13. **src/core/engine/contract_testgen.rs** — orphaned_test — Test method 'test_empty_grammar' references 'empty_grammar' which no longer exists in the source
14. **src/core/engine/contract_testgen.rs** — orphaned_test — Test method 'test_enrich_assertion_replaces_todo_with_field_hints' references 'enrich_assertion_replaces_todo_with_field_hints' which no longer exists in the source
15. **src/core/engine/contract_testgen.rs** — orphaned_test — Test method 'test_enrich_assertion_skips_when_no_type_in_registry' references 'enrich_assertion_skips_when_no_type_in_registry' which no longer exists in the source
16. **src/core/engine/contract_testgen.rs** — orphaned_test — Test method 'test_full_grammar' references 'full_grammar' which no longer exists in the source
17. **src/commands/docs.rs** — outlier — (outlier)
18. **tests/commands/deploy_test.rs** — outlier — (outlier)
19. **src/core/engine/undo/snapshot.rs** — outlier — (outlier)
- Full audit log: https://github.com/Extra-Chill/homeboy/actions/runs/23418370905

Autofixability classification

  • Overall: auto_fixable
  • Autofix enabled: yes
  • Autofix attempted this run: no
  • Auto-fixable failed commands:
    • audit
  • Failed commands with available automated fixes:
    • audit

Machine-readable artifacts

  • homeboy-lint-summary.json
  • homeboy-test-failures.json
  • homeboy-audit-summary.json
  • homeboy-autofixability.json

⚡ Scope: changed files only

audit (changed files only)

Auto-refactor

ℹ️ Autofix enabled, but no fixable file changes were produced

Failure Digest

Autofixability classification

  • Overall: human_needed
  • Autofix enabled: yes
  • Autofix attempted this run: no
  • Human-needed failed commands:
    • refactor --from all

Machine-readable artifacts

  • homeboy-lint-summary.json
  • homeboy-test-failures.json
  • homeboy-audit-summary.json
  • homeboy-autofixability.json

⚡ Scope: changed files only

refactor --from all

Tooling versions
  • Homeboy CLI: homeboy 0.85.3+4a281d3
  • Extension: rust from https://github.com/Extra-Chill/homeboy-extensions
  • Extension revision: unknown
  • Action: Extra-Chill/homeboy-action@v2

Homeboy Action v1

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