Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[refactor] pkg/testutil: split tempdir.go - CaptureStderr and StripYAMLCommentHeader dont belong #60544

Description

@github-actions

Executive Summary

Semantic clustering analysis of the precomputed package slice for this run: pkg/testutil and pkg/timeutil (2 non-test .go files, 8 functions total). Each package contains exactly one non-test source file, so the analysis is narrow by design.

  • pkg/timeutil/format.go — clean, single-purpose, no findings.
  • pkg/testutil/tempdir.go2 of 4 functions are outliers relative to the file's name/purpose (temp-directory management), violating the one-file-per-feature convention.
  • No duplicate or near-duplicate implementations found within the analyzed scope.
Function Inventory

pkg/testutil/tempdir.go (package testutil)

  • GetTestRunDir() string — creates/returns the shared per-process test-run temp directory
  • TempDir(t *testing.T, pattern string) string — creates an isolated temp dir with t.Cleanup
  • CaptureStderr(t *testing.T, fn func()) string — pipes and captures os.Stderr during fn
  • StripYAMLCommentHeader(yamlContent string) string — strips leading # comment lines from YAML text

pkg/timeutil/format.go (package timeutil)

  • round1(v float64) float64 — private rounding helper
  • FormatDuration(d time.Duration) string — npm-debug-style duration formatting
  • FormatDurationMs(ms int) string — millisecond-input wrapper with overflow guard
  • FormatDurationNs(ns int64) string — nanosecond-input wrapper with zero/negative guard

Identified Issues

1. Outlier functions in pkg/testutil/tempdir.go

The file is named and documented around temp-directory lifecycle (GetTestRunDir, TempDir), but also contains two functions with unrelated responsibilities:

  • CaptureStderr(t *testing.T, fn func()) string (tempdir.go:76-100) — stderr piping/capture utility, unrelated to temp directories. Widely used (20+ call sites across pkg/workflow, pkg/cli, pkg/parser, pkg/actionpins).
  • StripYAMLCommentHeader(yamlContent string) string (tempdir.go:105-115) — YAML text-processing helper, unrelated to temp directories. Used in pkg/testutil/tempdir_test.go, pkg/testutil/spec_test.go, and 2 files in pkg/workflow.

Recommendation: Split tempdir.go by feature, per the one-file-per-feature convention:

  • Keep GetTestRunDir and TempDir in tempdir.go.
  • Move CaptureStderr to a new pkg/testutil/capture.go.
  • Move StripYAMLCommentHeader to a new pkg/testutil/yaml.go (or fold into an existing YAML-focused test helper file if one exists outside this scope).

No implementation changes needed — this is a same-package file move, so all existing testutil.XxxYyy call sites remain valid.

Estimated impact: Low effort (pure file split within one package), improves discoverability and keeps each file's contents matching its name.

2. pkg/timeutil/format.go — no issues found

All four functions (round1, FormatDuration, FormatDurationMs, FormatDurationNs) are duration-formatting concerns consistent with the file name. round1 is a small private helper (<5 lines) used only within this file — acceptable per the "trivial helper" exclusion.

3. Duplicate detection

No duplicate or near-duplicate functions were found. A repo-wide search for sibling capture/strip helpers (e.g. CaptureStdout, StripComment*) found none, so CaptureStderr and StripYAMLCommentHeader are not consolidation candidates — only relocation candidates.

Refactoring Recommendations

Priority 1 (low effort, do when touching this package)

  1. Move CaptureStderrpkg/testutil/capture.go.
  2. Move StripYAMLCommentHeaderpkg/testutil/yaml.go.

No Priority 2/3 items identified in this scope.

Analysis Metadata
  • Packages analyzed: pkg/testutil, pkg/timeutil (precomputed slice only)
  • Total Go files analyzed: 2 (tempdir.go, format.go)
  • Total functions cataloged: 8
  • Outliers found: 2 (both in tempdir.go)
  • Duplicates detected: 0
  • Detection method: Grep-based symbol/reference analysis + naming/purpose clustering
  • Analysis date: 2026-09-13

Warning

Firewall blocked 1 domain

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

  • api.anthropic.com

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

network:
  allowed:
    - defaults
    - "api.anthropic.com"

See Network Configuration for more information.

Generated by 🔧 Semantic Function Refactoring · claude · sonnet50 · 145.1 AIC · ⌖ 40.7 AIC · ⊞ 10.8K ·

  • expires on Sep 14, 2026, 6:41 PM UTC-08:00

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions