Skip to content

Replace test set-style map[string]bool usage with map[string]struct{}#37257

Merged
pelikhan merged 4 commits into
mainfrom
copilot/lint-monster-fix-set-type-fixes
Jun 6, 2026
Merged

Replace test set-style map[string]bool usage with map[string]struct{}#37257
pelikhan merged 4 commits into
mainfrom
copilot/lint-monster-fix-set-type-fixes

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 6, 2026

Daily linting flagged widespread test-only set patterns implemented as map[string]bool, which are non-idiomatic and allocate unnecessary values. This change converts the flagged set usages to map[string]struct{} and updates related write/read patterns without changing test intent.

  • Scope: test set patterns

    • Converted flagged set-style declarations in tests from map[string]bool to map[string]struct{}.
    • Updated set writes from m[k] = true to m[k] = struct{}{}.
  • Membership checks and assertions

    • Reworked membership checks to existence semantics (_, ok := m[k]) where direct boolean reads were used.
    • Updated assertion patterns accordingly (for example, to assert.Contains / assert.NotContains for set membership checks).
  • Compatibility where APIs still require map[string]bool

    • Added a small converter helper in pkg/cli/engine_secrets.go (stringSetToBoolMap) and used it in affected tests that pass set data into bool-map APIs, keeping production behavior unchanged while allowing idiomatic set representation in test setup.
// before
values := make(map[string]bool)
values[o.Value] = true
assert.True(t, values["daily"])

// after
values := make(map[string]struct{})
values[o.Value] = struct{}{}
assert.Contains(t, values, "daily")

Copilot AI and others added 2 commits June 6, 2026 05:45
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix set type usages from map[string]bool to map[string]struct{} Replace test set-style map[string]bool usage with map[string]struct{} Jun 6, 2026
Copilot AI requested a review from gh-aw-bot June 6, 2026 05:56
@pelikhan pelikhan marked this pull request as ready for review June 6, 2026 14:39
Copilot AI review requested due to automatic review settings June 6, 2026 14:39
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

🧠 Matt Pocock Skills Reviewer failed during the skills-based review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

🧪 Test Quality Sentinel completed test quality analysis.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

Design Decision Gate 🏗️ failed during design decision gate check.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

PR Code Quality Reviewer completed the code quality review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes test-only “set” usage across the codebase by replacing map[string]bool patterns with idiomatic map[string]struct{} and updating related membership checks and assertions. It also introduces a small compatibility converter for cases where existing APIs still accept map[string]bool.

Changes:

  • Converted many test/fuzz set-like maps from map[string]bool to map[string]struct{} and updated write patterns to m[k] = struct{}{}.
  • Reworked membership checks to use key-existence (_, ok := m[k]) and updated assertions to assert.Contains / assert.NotContains where appropriate.
  • Added stringSetToBoolMap in pkg/cli/engine_secrets.go to bridge tests that still call map[string]bool APIs.
Show a summary per file
File Description
pkg/workflow/tools_types_test.go Uses map[string]struct{} + delete to verify expected tool names without ordering sensitivity.
pkg/workflow/maintenance_workflow_test.go Converts result set to map[string]struct{} and uses existence checks for membership assertions.
pkg/workflow/known_needs_expressions_test.go Replaces boolean reads with assert.Contains / assert.NotContains against a struct{} set.
pkg/workflow/github_toolsets_test.go Migrates multiple set-like maps to map[string]struct{} with existence checks.
pkg/workflow/git_commands_test.go Switches editing-tool membership tracking to map[string]struct{} and updates checks accordingly.
pkg/workflow/expression_extraction_fuzz_test.go Uses map[string]struct{} to detect duplicates in fuzz outputs.
pkg/workflow/ecosystem_domains_test.go Uses a struct{} set to detect duplicate domains.
pkg/workflow/domains_test.go Replaces domain membership bool-map with existence semantics on a struct{} set.
pkg/workflow/domains_blocked_test.go Replaces domain accumulation map with map[string]struct{}.
pkg/workflow/custom_job_condition_test.go Converts expected/actual result comparisons to struct{} sets.
pkg/workflow/compiler_jobs_test.go Uses map[string]struct{} to validate included/excluded job sets.
pkg/workflow/claude_engine_tools_test.go Converts expected/actual tool collections into struct{} sets and compares via existence checks.
pkg/workflow/bash_merge_test.go Uses map[string]struct{} for order-independent membership validation.
pkg/workflow/agentic_engine_test.go Uses assert.NotContains with a struct{} set to detect duplicates.
pkg/sliceutil/sliceutil_test.go Updates the MapKeys test to use a map[string]struct{} input.
pkg/parser/schema_deprecated_test.go Uses struct{} sets for found fields/paths membership checks.
pkg/parser/mcp_test.go Uses map[string]struct{} for order-independent args comparison via reflect.DeepEqual.
pkg/cli/tokens_bootstrap_test.go Uses assert.Contains on a struct{} set of engine secret names.
pkg/cli/secrets_test.go Converts expected/actual secret name sets to map[string]struct{} with existence checks.
pkg/cli/packages_test.go Uses map[string]struct{} for the seen-set in tests and converts via stringSetToBoolMap for bool-map APIs.
pkg/cli/logs_report_test.go Represents allowed/denied domain sets as map[string]struct{} and converts for bool-map API usage.
pkg/cli/engine_secrets.go Adds stringSetToBoolMap converter helper for tests interacting with bool-map APIs.
pkg/cli/engine_secrets_test.go Updates existing-secrets sets to map[string]struct{} and converts when calling bool-map APIs.
pkg/cli/dependency_graph_test.go Uses map[string]struct{} sets for membership assertions on affected workflows.
pkg/cli/copilot_events_jsonl_test.go Uses assert.Contains on a struct{} set of tool call names.
pkg/cli/add_interactive_schedule_test.go Uses map[string]struct{} for schedule option membership checks with assert.Contains.
pkg/actionpins/actionpins_internal_test.go Avoids map[string]bool as a test set while still populating the Warnings map[string]bool API.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 27/27 changed files
  • Comments generated: 2

Comment thread pkg/cli/engine_secrets.go
Comment on lines +177 to +187
func stringSetToBoolMap(set map[string]struct{}) map[string]bool {
if len(set) == 0 {
return map[string]bool{}
}

result := make(map[string]bool, len(set))
for item := range set {
result[item] = true
}
return result
}
Comment thread pkg/cli/engine_secrets.go
Comment on lines +177 to +187
func stringSetToBoolMap(set map[string]struct{}) map[string]bool {
if len(set) == 0 {
return map[string]bool{}
}

result := make(map[string]bool, len(set))
for item := range set {
result[item] = true
}
return result
}
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

🧪 Test Quality Sentinel Report

Test Quality Score: 94/100 — Excellent

Analyzed 32 modified test function(s) across 26 test files: 32 design tests (100%), 0 implementation tests (0%), 0 guideline violations. This PR is a pure mechanical refactoring — replacing map[string]bool set patterns with idiomatic map[string]struct{}{}.

📊 Metrics & Test Classification (32 tests analyzed)
Metric Value
New/modified tests analyzed 32
✅ Design tests (behavioral contracts) 32 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases ~26 (81%)
Duplicate test clusters 0
Test inflation detected No
🚨 Coding-guideline violations 0

Test Classification Details

Test File Classification Issues Detected
TestInitWarnings_InitializesAndPreservesMap pkg/actionpins/actionpins_internal_test.go ✅ Design None
TestBuildScheduleOptions pkg/cli/add_interactive_schedule_test.go ✅ Design None
TestParseEventsJSONLFile pkg/cli/copilot_events_jsonl_test.go ✅ Design None
TestGetAffectedWorkflows (4 t.Run blocks) pkg/cli/dependency_graph_test.go ✅ Design None
TestGetRequiredSecretsForEngine pkg/cli/engine_secrets_test.go ✅ Design None
TestGetEngineSecretNameAndValue pkg/cli/engine_secrets_test.go ✅ Design None — includes error case (unknown engine)
TestGetMissingRequiredSecrets pkg/cli/engine_secrets_test.go ✅ Design None — nil map, empty, optional/required, alternatives
TestConvertDomainsToSortedSlices pkg/cli/logs_report_test.go ✅ Design None — includes empty-map case
collectLocalIncludeDependenciesRecursive test pkg/cli/packages_test.go ✅ Design None
TestExtractSecretsFromConfig pkg/cli/secrets_test.go ✅ Design None
TestGetRequiredSecretRequirements pkg/cli/tokens_bootstrap_test.go ✅ Design None
TestParseMCPConfig pkg/parser/mcp_test.go ✅ Design None
TestFindDeprecatedFieldsInFrontmatter pkg/parser/schema_deprecated_test.go ✅ Design None
TestFindDeprecatedFieldsInFrontmatterDeep pkg/parser/schema_deprecated_test.go ✅ Design None
TestMapKeys pkg/sliceutil/sliceutil_test.go ✅ Design None
TestEngineRegistry_GetAllAgentManifestFolders pkg/workflow/agentic_engine_test.go ✅ Design None — deduplication check
TestEngineRegistry_GetAllAgentManifestFiles pkg/workflow/agentic_engine_test.go ✅ Design None — deduplication check
TestBashToolsMergeCustomWithDefaults pkg/workflow/bash_merge_test.go ✅ Design None
TestClaudeEngineComputeAllowedTools pkg/workflow/claude_engine_tools_test.go ✅ Design None — bidirectional set comparison
TestGetCustomJobsDependingOnPreActivationExcludesActivationDependents pkg/workflow/compiler_jobs_test.go ✅ Design None — checks both included and excluded jobs
TestGetCustomJobsDependingOnPreActivation pkg/workflow/custom_job_condition_test.go ✅ Design None
TestGetBlockedDomains pkg/workflow/domains_blocked_test.go ✅ Design None
TestMergeAPITargetDomains pkg/workflow/domains_test.go ✅ Design None — checks both wantIn and wantNotIn
TestEcosystemDomainsUniqueness pkg/workflow/ecosystem_domains_test.go ✅ Design None — uniqueness invariant
FuzzExtractTerminalSubExpressions pkg/workflow/expression_extraction_fuzz_test.go ✅ Design None — property-based, duplicate detection
FuzzExtractExpressions pkg/workflow/expression_extraction_fuzz_test.go ✅ Design None — property-based, uppercase + dup detection
TestAdditionalClaudeToolsForSafeOutputs pkg/workflow/git_commands_test.go ✅ Design None — checks both expected-present and unexpected-absent
TestParseGitHubToolsets pkg/workflow/github_toolsets_test.go ✅ Design None — checks excluded toolsets not present
TestParseGitHubToolsetsDeduplication pkg/workflow/github_toolsets_test.go ✅ Design None
TestFilterExpressionsForActivation pkg/workflow/known_needs_expressions_test.go ✅ Design None — checks both expected and excluded
TestCollectSideRepoTargets pkg/workflow/maintenance_workflow_test.go ✅ Design None
TestGetToolNames pkg/workflow/tools_types_test.go ✅ Design None — improved delete-based check

Language Support

Tests analyzed:

  • 🐹 Go (*_test.go): 32 tests — all unit (//go:build !integration)
  • 🟨 JavaScript (*.test.cjs, *.test.js): 0 tests changed

Verdict

Check passed. 0% of modified tests are implementation tests (threshold: 30%). This is a clean idiomatic refactoring — all test logic and behavioral contracts are preserved. The map[string]struct{} pattern is more memory-efficient and the updated assert.Contains / assert.NotContains calls are semantically clearer.

📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal function calls (mocking internals)
  • Only test the happy path with typical inputs
  • Break during legitimate refactoring even when behavior is correct
  • Give false assurance: they pass even when the system is wrong

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.

References: §27065144413

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 781.2K · 234.4 AIC · ⌖ 19.9 AIC ·

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 94/100. Test quality is excellent — 0% of modified tests are implementation tests (threshold: 30%). All 32 modified tests preserve their behavioral contracts through this idiomatic map[string]struct{} refactoring. No coding-guideline violations detected.

@pelikhan pelikhan merged commit 51480c7 into main Jun 6, 2026
64 of 66 checks passed
@pelikhan pelikhan deleted the copilot/lint-monster-fix-set-type-fixes branch June 6, 2026 14:52
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Two maintainability issues with the engine_secrets.go lint remediation strategy; everything else (CutPrefix refactor, YAML tag fix, lock-file recompile, test-local set conversions) looks correct.

🔍 Findings

Test helper leaked into production source

stringSetToBoolMap is only called from _test.go files but lives in engine_secrets.go. It should be moved to engine_secrets_test.go. Details in the inline comment at line 177.

Lint fix direction is inverted

Test code was changed to use map[string]struct{}{} while the production API (getMissingRequiredSecrets, GetEngineSecretNameAndValue, EngineSecretConfig.ExistingSecrets, etc.) still uses map[string]bool. This leaves the actual linting violation in production code untouched and adds a redundant allocation at every test call site. Details and alternatives in the inline comment at line 159.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer · sonnet46 616.5K · 3.92 AIC · ⌖ 13.2 AIC

Comments that could not be inline-anchored

pkg/cli/engine_secrets.go:177

Test-only helper placed in production code: stringSetToBoolMap is only called from test files but lives in the production package, adding dead weight to the binary and muddying the package API.

<details>
<summary>💡 Suggested fix</summary>

Move the function body verbatim into engine_secrets_test.go (or a shared testhelpers_test.go). Since it is in the same package (package cli), the test files can access all unexported identifiers without it being in the production source.

</details>

<details><summary>pkg/cli/engine_secrets.go:159</summary>

**Lint fix applied in the wrong direction**: the `seenmapbool` violation exists in both test and production code, but only the test side was changed. `getMissingRequiredSecrets`, `GetEngineSecretNameAndValue`, `displayMissingSecrets`, `displaySecretsSummaryTable`, and the `ExistingSecrets` struct field all still take/hold `map[string]bool` used purely as a membership set.

&lt;details&gt;
&lt;summary&gt;💡 Impact and suggested approach&lt;/summary&gt;

The current approach:
1. Changed test-side maps to `map[stri…

</details>

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.

[lint-monster] [Lint] Test Set-Type Fixes: map[string]bool → map[string]struct{} - 243 findings

5 participants