Skip to content

[dead-code] chore: remove dead functions — 1 function removed#26418

Merged
pelikhan merged 1 commit intomainfrom
dead-code/remove-NewCompilerWithVersion-20260415-43442af9d9c545ad
Apr 15, 2026
Merged

[dead-code] chore: remove dead functions — 1 function removed#26418
pelikhan merged 1 commit intomainfrom
dead-code/remove-NewCompilerWithVersion-20260415-43442af9d9c545ad

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Dead Code Removal

This PR removes unreachable Go functions identified by the deadcode static analyzer.

Functions Removed

Function File
NewCompilerWithVersion pkg/workflow/compiler_types.go

Migration

NewCompilerWithVersion(version) was a deprecated wrapper around NewCompiler() that set the compiler version. It was unreachable from all production binaries (only called from test files). This PR:

  1. Adds a WithVersion(version string) CompilerOption functional option to compiler_types.go
  2. Replaces all NewCompilerWithVersion("x") calls in 34 test files with NewCompiler(WithVersion("x"))
  3. Removes the deprecated NewCompilerWithVersion function

Tests Removed

None — the existing tests were migrated to use NewCompiler(WithVersion(...)) instead.

Verification

  • go build ./... — passes
  • go vet ./... — passes
  • go vet -tags=integration ./... — passes
  • make fmt — Go code formatted (JS formatter pre-existing issue unrelated to this change)
  • go test ./pkg/workflow/... — passes (24s)

Dead Function Count

  • Before this batch: 6 unprocessed functions (4 live in WASM: CompileToYAML, ParseWorkflowString, WithSkipValidation, WithNoEmit, WithWorkflowIdentifier)
  • Removed in this PR: 1 function
  • Remaining: ~5 functions (WASM-protected)

Automated by Dead Code Removal workflow — https://github.com/github/gh-aw/actions/runs/24453403088

Generated by Dead Code Removal Agent · ● 1.4M ·

  • expires on Apr 18, 2026, 12:13 PM UTC

Replace deprecated NewCompilerWithVersion(v) with NewCompiler(WithVersion(v))
across all test files. Add WithVersion functional option to compiler_types.go
so callers can set version through the standard options pattern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review April 15, 2026 12:51
Copilot AI review requested due to automatic review settings April 15, 2026 12:51
@pelikhan pelikhan merged commit 19bf794 into main Apr 15, 2026
54 checks passed
@pelikhan pelikhan deleted the dead-code/remove-NewCompilerWithVersion-20260415-43442af9d9c545ad branch April 15, 2026 12:51
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

Removes the deprecated/unreachable NewCompilerWithVersion constructor by introducing a WithVersion(version string) functional option and migrating test call sites to the new option-based constructor.

Changes:

  • Added WithVersion(version string) CompilerOption to configure compiler version via functional options.
  • Replaced NewCompilerWithVersion("...") usage across tests with NewCompiler(WithVersion("...")).
  • Removed the deprecated NewCompilerWithVersion function from compiler_types.go.
Show a summary per file
File Description
pkg/workflow/compiler_types.go Adds WithVersion option and removes deprecated NewCompilerWithVersion constructor.
pkg/workflow/top_level_github_app_import_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_outputs_import_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_outputs_fix_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_outputs_default_max_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_outputs_call_workflow_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_outputs_app_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_outputs_app_import_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_outputs_allow_workflows_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/safe_jobs_threat_detection_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/permissions_explicit_empty_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/local_action_permissions_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/github_mcp_app_token_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/firewall_workflow_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/firewall_args_integration_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/error_wrapping_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/dispatch_workflow_validation_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/dispatch_workflow_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/dispatch_repository_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/compiler_yaml_error_wrapping_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/compiler_validation_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/compiler_custom_actions_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/compiler_cache_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/compiler_activation_job_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/checkout_import_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/call_workflow_validation_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/call_workflow_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/call_workflow_permissions_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/call_workflow_compilation_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/blocked_domains_integration_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/aw_info_versions_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/assign_to_agent_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/allow_github_references_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/activation_checkout_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).
pkg/workflow/action_reference_test.go Migrates compiler construction to NewCompiler(WithVersion(...)).

Copilot's findings

Tip

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

  • Files reviewed: 35/35 changed files
  • Comments generated: 1

func WithVersion(version string) CompilerOption {
return func(c *Compiler) { c.version = version }
}

Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

NewCompilerWithVersion was an exported API and is referenced in repo documentation (e.g., pkg/workflow/README.md and scratchpad/actions.md). After removing it, those docs will be stale and examples won’t compile. Please update the docs to use NewCompiler(WithVersion("...")) (or consider keeping a deprecated wrapper until docs/users migrate).

Suggested change
// NewCompilerWithVersion is retained as a compatibility wrapper for callers using the
// previous constructor API.
//
// Deprecated: use NewCompiler(append([]CompilerOption{WithVersion(version)}, opts...)...) instead.
func NewCompilerWithVersion(version string, opts ...CompilerOption) *Compiler {
return NewCompiler(append([]CompilerOption{WithVersion(version)}, opts...)...)
}

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor Author

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (205 new lines in pkg/) but does not have a linked Architecture Decision Record (ADR).

AI has analyzed the PR diff and generated a draft ADR to help you get started:

📄 Draft ADR: docs/adr/26418-remove-newcompilerwithversion-in-favor-of-functional-options.md

Note: This PR was already merged before the ADR could be pushed to the branch. The draft ADR should be committed directly to main via a follow-up PR.

What was decided (as inferred from the diff)

The PR removes the legacy NewCompilerWithVersion(version string) constructor and introduces WithVersion(version string) CompilerOption to complete the Compiler's functional options API. All 34 test call sites were migrated from NewCompilerWithVersion("x") to NewCompiler(WithVersion("x")).

Draft ADR Content

📋 View full draft ADR
# ADR-26418: Remove `NewCompilerWithVersion` in Favor of Functional Options

**Date**: 2026-04-15
**Status**: Draft
**Deciders**: pelikhan, github-actions[bot]

## Context

The `Compiler` struct in `pkg/workflow` uses a functional options pattern (`CompilerOption`) for construction-time configuration. A legacy constructor `NewCompilerWithVersion(version string)` existed alongside `NewCompiler(opts ...CompilerOption)` as a convenience wrapper. Static analysis via `deadcode` identified it as unreachable from all production binaries—it appeared only in 34 test files. Seven other `CompilerOption` functions already existed (`WithVerbose`, `WithEngineOverride`, `WithSkipValidation`, etc.), making version the one outlier that bypassed the pattern.

## Decision

We will remove `NewCompilerWithVersion` and expose version configuration through a new `WithVersion(version string) CompilerOption`, consistent with all other `Compiler` options. All 34 test call sites are migrated from `NewCompilerWithVersion("x")` to `NewCompiler(WithVersion("x"))`. This closes the API inconsistency and makes `NewCompiler` the single construction path.

## Alternatives Considered

### Alternative 1: Retain `NewCompilerWithVersion` permanently
Rejected: it is dead code in production, the migration cost is low, and retaining it leaves two construction paths with no guidance on which to prefer.

### Alternative 2: Promote it to a first-class constructor
Rejected: it conflicts with the established direction of the package where every other configuration dimension uses `CompilerOption`.

### Alternative 3: Refactor to a struct-based `CompilerConfig`
Rejected: out of scope, breaking change across the codebase, discards the composability benefits of the existing functional options pattern.

## Consequences

### Positive
- `Compiler` construction is now fully consistent: one constructor, all options via `CompilerOption`.
- `NewCompilerWithVersion` is no longer a dead code path.
- `WithVersion` composes naturally with other options (e.g., `NewCompiler(WithVersion("1.0"), WithSkipValidation(true))`).

### Negative
- 34 test files required mechanical migration; each call site is slightly more verbose.
- External consumers importing `NewCompilerWithVersion` would experience a breaking change (confirmed non-issue: function was unreachable externally).

### Neutral
- Action mode detection behavior is unchanged; `WithVersion` is a pure setter.
- Test readability is marginally reduced for single-option call sites.

What to do next

  1. Create a follow-up PR that adds docs/adr/26418-remove-newcompilerwithversion-in-favor-of-functional-options.md to main
  2. Review and refine the draft — add any context the AI couldn't infer
  3. Reference the ADR in future PRs that extend the functional options API

Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. This decision — completing the functional options API by removing NewCompilerWithVersion — is worth recording so future contributors understand the API contract and don't re-introduce named constructors.


📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 26418-remove-newcompilerwithversion-in-favor-of-functional-options.md for PR #26418).

References: §24455512078

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · ● 171K ·

@github-actions
Copy link
Copy Markdown
Contributor Author

🧪 Test Quality Sentinel Report

Test Quality Score: 100/100

Excellent — mechanical maintenance change, no new test functions

Metric Value
New test functions introduced 0
Modified test files 34
Nature of all changes Constructor rename only
✅ Design tests (behavioral contracts) N/A — no new tests
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases N/A
Duplicate test clusters 0
Test inflation detected No
🚨 Coding-guideline violations None

What Changed

This PR removes the dead helper function NewCompilerWithVersion from pkg/workflow/compiler_types.go and replaces every call site in 34 test files with the equivalent functional-options form:

- compiler := NewCompilerWithVersion("1.0.0")
+ compiler := NewCompiler(WithVersion("1.0.0"))

The change is purely mechanical — 202 call sites across 34 files were updated with an identical one-line substitution. No assertions were added, removed, or modified. No test logic changed. The behavioral coverage of the test suite is identical to what it was before.


Test Classification Details

No new test functions were introduced. All 34 modified files received only the constructor-rename substitution. The underlying tests were not reclassified because their behavioral contracts are unchanged.

📋 Modified test files (34)
File Changes
action_reference_test.go 3× constructor rename
activation_checkout_test.go 1× constructor rename
allow_github_references_test.go 1× constructor rename
assign_to_agent_test.go 1× constructor rename
aw_info_versions_test.go 5× constructor rename
blocked_domains_integration_test.go 5× constructor rename
call_workflow_compilation_test.go 5× constructor rename
call_workflow_permissions_test.go 6× constructor rename
call_workflow_test.go 5× constructor rename
call_workflow_validation_test.go 7× constructor rename
checkout_import_test.go 5× constructor rename
compiler_activation_job_test.go 11× constructor rename
compiler_cache_test.go 1× constructor rename
compiler_custom_actions_test.go 8× constructor rename
compiler_validation_test.go 1× constructor rename
compiler_yaml_error_wrapping_test.go 3× constructor rename
dispatch_repository_test.go 16× constructor rename
dispatch_workflow_test.go 7× constructor rename
dispatch_workflow_validation_test.go 6× constructor rename
error_wrapping_test.go 7× constructor rename
firewall_args_integration_test.go 5× constructor rename
firewall_workflow_test.go 1× constructor rename
github_mcp_app_token_test.go 12× constructor rename
local_action_permissions_test.go 2× constructor rename
permissions_explicit_empty_test.go 1× constructor rename
safe_jobs_threat_detection_test.go 4× constructor rename
safe_outputs_allow_workflows_test.go 4× constructor rename
safe_outputs_app_import_test.go 2× constructor rename
safe_outputs_app_test.go 4× constructor rename
safe_outputs_call_workflow_test.go 8× constructor rename
safe_outputs_default_max_test.go 4× constructor rename
safe_outputs_fix_test.go 2× constructor rename
safe_outputs_import_test.go 32× constructor rename
top_level_github_app_import_test.go 15× constructor rename

Flagged Tests — Requires Review

None. No test logic was changed; no red flags detected.


Language Support

Tests analyzed:

  • 🐹 Go (*_test.go): ~202 call-site updates across 34 files — unit (//go:build !integration) and integration (//go:build integration)
  • 🟨 JavaScript (*.test.cjs, *.test.js): 0 tests changed

Verdict

Check passed. 0% of new/modified tests are implementation tests. This is a pure dead-code removal — the NewCompilerWithVersion convenience wrapper was eliminated and all test files were updated to the equivalent NewCompiler(WithVersion(...)) call. Behavioral coverage is completely unchanged.


📖 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: §24455512042

🧪 Test quality analysis by Test Quality Sentinel · ● 1.5M ·

Copy link
Copy Markdown
Contributor Author

@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: 100/100. This is a pure dead-code removal — NewCompilerWithVersion was replaced with NewCompiler(WithVersion(...)) across 34 test files with 202 identical mechanical substitutions. No test logic changed, no behavioral coverage changed, no guideline violations detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants