[dead-code] chore: remove dead functions — 4 functions removed#23882
[dead-code] chore: remove dead functions — 4 functions removed#23882
Conversation
Remove unreachable Go functions identified by the deadcode static analyzer: - Compiler.buildInlineDetectionSteps (deprecated wrapper around buildDetectionJobSteps) - Compiler.formatSafeOutputsRunsOn (superseded by formatFrameworkJobRunsOn) - extractSafeScriptsFromFrontmatter (unused internal helper) - ErrorCollector.HasErrors (redundant with Count() > 0) Update test callers: - Replace buildInlineDetectionSteps with buildDetectionJobSteps in threat detection tests - Remove exclusive TestBuildInlineDetectionSteps, TestFormatSafeOutputsRunsOn, TestFormatSafeOutputsRunsOnEdgeCases, TestExtractSafeScriptsFromFrontmatter, and TestExtractSafeScriptsFromFrontmatterEmpty test functions - Replace HasErrors() assertions with Count() equivalents Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Removes unreachable Go code (and associated tests) flagged by the deadcode analyzer to reduce maintenance surface area in the workflow compiler.
Changes:
- Removed 4 dead/unreachable functions from the workflow package.
- Updated remaining tests to call the non-deprecated implementations directly (e.g.,
buildDetectionJobSteps,Count()). - Deleted tests that only covered the removed dead functions and cleaned up related imports.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/workflow_errors.go | Removes redundant ErrorCollector.HasErrors helper. |
| pkg/workflow/error_aggregation_test.go | Updates assertions to use Count() instead of HasErrors(). |
| pkg/workflow/threat_detection.go | Removes deprecated wrapper buildInlineDetectionSteps. |
| pkg/workflow/threat_detection_test.go | Removes wrapper-specific test and updates callers to buildDetectionJobSteps. |
| pkg/workflow/threat_detection_file_access_test.go | Updates callers to buildDetectionJobSteps and trims now-stale commentary. |
| pkg/workflow/safe_outputs_runtime.go | Removes superseded formatSafeOutputsRunsOn helper. |
| pkg/workflow/safe_outputs_test.go | Removes test that only covered removed formatSafeOutputsRunsOn and drops unused import. |
| pkg/workflow/safe_outputs_runs_on_test.go | Removes edge-case test that only covered removed formatSafeOutputsRunsOn. |
| pkg/workflow/safe_scripts.go | Removes unused internal helper extractSafeScriptsFromFrontmatter. |
| pkg/workflow/safe_scripts_test.go | Removes tests that only covered removed extractSafeScriptsFromFrontmatter. |
Comments suppressed due to low confidence (2)
pkg/workflow/error_aggregation_test.go:83
- These back-to-back assertions duplicate the same
collector.Count() == 0check with slightly different messages. Consider removing one to keep the test focused and avoid redundant failures.
assert.Equal(t, 0, collector.Count(), "Should not have errors")
assert.Equal(t, 0, collector.Count(), "Should have zero count")
pkg/workflow/threat_detection_test.go:213
- This test (and its comments/error messages) still refer to “inline detection steps”, but the code now calls
buildDetectionJobSteps, and the PR description notes detection runs in a separate detection job. Updating the test name/comments/messages to match the current behavior would reduce confusion for future maintainers.
func TestThreatDetectionInlineStepsDependencies(t *testing.T) {
// Test that inline detection steps are generated when threat detection is enabled
// and that safe-output jobs can check detection results via agent job outputs
compiler := NewCompiler()
data := &WorkflowData{
SafeOutputs: &SafeOutputsConfig{
ThreatDetection: &ThreatDetectionConfig{},
},
}
// Build inline detection steps
steps := compiler.buildDetectionJobSteps(data)
if steps == nil {
t.Fatal("Expected inline detection steps to be created")
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assert.Equal(t, tt.failFast, collector.failFast, "Fail-fast setting should match") | ||
| assert.False(t, collector.HasErrors(), "New collector should have no errors") | ||
| assert.Equal(t, 0, collector.Count(), "New collector should have no errors") | ||
| assert.Equal(t, 0, collector.Count(), "New collector should have zero count") |
There was a problem hiding this comment.
These two assertions both call collector.Count() with essentially the same expectation/message. Consider keeping a single assertion here to avoid redundant checks and reduce noise in the test output when it fails.
This issue also appears on line 82 of the same file.
| assert.Equal(t, 0, collector.Count(), "New collector should have zero count") |
| // TestExtractSafeScriptsFromFrontmatter verifies extraction from frontmatter | ||
| func TestExtractSafeScriptsFromFrontmatter(t *testing.T) { | ||
| frontmatter := map[string]any{ | ||
| "safe-outputs": map[string]any{ | ||
| "scripts": map[string]any{ | ||
| "my-handler": map[string]any{ | ||
| "description": "A custom handler", | ||
| // Users write only the body — no module.exports or main declaration needed | ||
| "script": "return async (m) => ({ success: true });", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| result := extractSafeScriptsFromFrontmatter(frontmatter) | ||
|
|
||
| require.Len(t, result, 1, "Should have one script") | ||
| script, exists := result["my-handler"] | ||
| require.True(t, exists, "Should have my-handler script") | ||
| assert.Equal(t, "A custom handler", script.Description, "Description should match") | ||
| } | ||
|
|
||
| // TestExtractSafeScriptsFromFrontmatterEmpty verifies empty result when no scripts | ||
| func TestExtractSafeScriptsFromFrontmatterEmpty(t *testing.T) { | ||
| frontmatter := map[string]any{ | ||
| "safe-outputs": map[string]any{ | ||
| "create-issue": map[string]any{}, | ||
| }, | ||
| } | ||
|
|
||
| result := extractSafeScriptsFromFrontmatter(frontmatter) | ||
| assert.Empty(t, result, "Should return empty map when no scripts") | ||
| } | ||
|
|
||
| // TestBuildCustomSafeOutputScriptsJSON verifies JSON generation for script env var | ||
| func TestBuildCustomSafeOutputScriptsJSON(t *testing.T) { |
There was a problem hiding this comment.
This comment says “TestExtractSafeScriptsFromFrontmatter verifies extraction from frontmatter”, but the TestExtractSafeScriptsFromFrontmatter* tests were removed. Please remove or update the comment so it doesn’t suggest a missing test.
There was a problem hiding this comment.
💥 Automated smoke test review - all systems nominal!
💥 [THE END] — Illustrated by Smoke Claude
| require.NotNil(t, collector, "Collector should be created") | ||
| assert.Equal(t, tt.failFast, collector.failFast, "Fail-fast setting should match") | ||
| assert.False(t, collector.HasErrors(), "New collector should have no errors") | ||
| assert.Equal(t, 0, collector.Count(), "New collector should have no errors") |
There was a problem hiding this comment.
Good change — using collector.Count() directly instead of the removed HasErrors() method makes the intent clearer and eliminates the need for a separate predicate method.
| return make(map[string]*SafeScriptConfig) | ||
| } | ||
|
|
||
| // isSafeScriptName returns true if the script name is safe for use as a filename component. |
There was a problem hiding this comment.
Removing extractSafeScriptsFromFrontmatter keeps the package surface clean. The parseSafeScriptsConfig helper below is the right entry point for callers that already have the scripts map.
Dead Code Removal
This PR removes unreachable Go functions identified by the
deadcodestatic analyzer.Functions Removed
Compiler.buildInlineDetectionStepspkg/workflow/threat_detection.goCompiler.formatSafeOutputsRunsOnpkg/workflow/safe_outputs_runtime.goextractSafeScriptsFromFrontmatterpkg/workflow/safe_scripts.goErrorCollector.HasErrorspkg/workflow/workflow_errors.goNotes
buildInlineDetectionStepswas a one-line deprecated wrapper aroundbuildDetectionJobSteps; test callers were updated to callbuildDetectionJobStepsdirectly.formatSafeOutputsRunsOnwas superseded by the more generalformatFrameworkJobRunsOn.extractSafeScriptsFromFrontmatterwas an internal helper with no production callers.ErrorCollector.HasErrorswas redundant —Count() > 0is equivalent; test assertions updated.Tests Removed
TestBuildInlineDetectionStepspkg/workflow/threat_detection_test.goTestFormatSafeOutputsRunsOnpkg/workflow/safe_outputs_test.goTestFormatSafeOutputsRunsOnEdgeCasespkg/workflow/safe_outputs_runs_on_test.goTestExtractSafeScriptsFromFrontmatterpkg/workflow/safe_scripts_test.goTestExtractSafeScriptsFromFrontmatterEmptypkg/workflow/safe_scripts_test.goVerification
go build ./...— passesgo vet ./...— passesgo vet -tags=integration ./...— passesmake fmt— no changes neededgo test ./pkg/workflow/...— all tests passDead Function Count
Automated by Dead Code Removal workflow — https://github.com/github/gh-aw/actions/runs/23847489282
✨ PR Review Safe Output Test - Run 23848854083