Skip to content

Fix copylocks lint errors and Windows test failures in logging/common#538

Merged
frjcomp merged 9 commits intomainfrom
copilot/deep-test-analysis-go-project
Mar 4, 2026
Merged

Fix copylocks lint errors and Windows test failures in logging/common#538
frjcomp merged 9 commits intomainfrom
copilot/deep-test-analysis-go-project

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

Two CI failures on the copilot/deep-test-analysis-go-project branch: golangci-lint rejecting illegal sync.Once copies in hit_test.go, and Windows unit tests failing because InitLogger never closes the log file it opens, causing t.TempDir() cleanup to fail with "file in use by another process".

Changes

pkg/logging/hit_test.go — remove illegal sync.Once copy

sync.Once contains sync.noCopy, making value assignment a go vet (copylocks) error. The save/restore of globalHitWriterOnce was unnecessary: restoring globalHitWriter to its original non-nil value is sufficient, since Hit() only calls setupGlobalHitWriter() when globalHitWriter == nil.

// Before (illegal — sync.Once cannot be copied)
origOnce := globalHitWriterOnce
defer func() { globalHitWriterOnce = origOnce }()

// After — only writer is saved/restored; Once is reset at setup only
globalHitWriterOnce = sync.Once{} // assigning zero value is fine

internal/cmd/common/common.go — expose log file closer

Added var logFileCloser io.Closer to the package vars, assigned in InitLogger when a file is opened. This gives tests (and future shutdown paths) a handle to release the OS file descriptor.

internal/cmd/common/common_test.go — close file before TempDir cleanup

In TestInitLogger_ConsoleMode and TestInitLogger_JSONMode, the defer now restores log.Logger first (stops writes), then closes logFileCloser (releases the handle). Go defers run before t.Cleanup callbacks, so the file is closed before t.TempDir() tries to remove it.

defer func() {
    log.Logger = origLogger          // stop writing to file first
    if logFileCloser != nil && logFileCloser != origLogFileCloser {
        _ = logFileCloser.Close()    // release OS handle before TempDir cleanup
    }
    logFileCloser = origLogFileCloser
    // restore other vars...
}()

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…fy, new common package tests

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze test quality and coverage for Go project Improve test quality: table-driven tests, parallel execution, testify assertions, and new common package coverage Mar 3, 2026
@frjcomp frjcomp marked this pull request as ready for review March 3, 2026 14:04
Copilot AI review requested due to automatic review settings March 3, 2026 14:04
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 improves the quality, isolation, and coverage of the Go test suite for Pipeleek’s CLI and helper packages by strengthening assertions, adding table-driven patterns, and enabling parallel execution where safe.

Changes:

  • Refactors and strengthens CLI command tests using table-driven tests and testify (assert/require) assertions, including default flag value checks.
  • Adds new unit tests for internal/cmd/common to cover previously untested exported helpers and logging behavior.
  • Enables t.Parallel() across multiple pure/isolated tests in pkg/ to improve test runtime and reduce shared-state coupling.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/format/time_test.go Updates ParseISO8601 tests to assert expected time.Time behavior and runs subtests in parallel.
pkg/format/string_test.go Adds parallel execution to string helper tests (including subtests).
pkg/format/path_test.go Runs directory-check tests and subtests in parallel.
pkg/format/format_test.go Adds parallel execution to size/format-related tests and subtests.
pkg/config/validation_test.go Adds parallel execution to validation tests and subtests.
pkg/archive/strings_test.go Adds parallel execution across multiple string-extraction tests and subtests.
internal/cmd/root_test.go Consolidates global log-level tests into a table-driven test and strengthens flag assertions.
internal/cmd/gitlab/jobToken/jobtoken_test.go Converts manual assertions to testify and checks default flag values.
internal/cmd/gitlab/gitlab_test.go Strengthens assertions and checks default values for key flags.
internal/cmd/devops/devops_test.go Strengthens assertions and validates more flag defaults/shorthands.
internal/cmd/common/common_test.go Adds new tests covering internal/cmd/common helpers (logging hooks/writers/flags/pre-run setup).

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s, renovate, logging

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title Improve test quality: table-driven tests, parallel execution, testify assertions, and new common package coverage Improve test coverage across weak spots: +5.3pp total coverage Mar 3, 2026
…ConfigFileContents outDir, extract fetchVersionFromHTML, pure deduplicateFindingsWithState

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title Improve test coverage across weak spots: +5.3pp total coverage Improve test coverage: refactor for testability and add targeted unit tests Mar 3, 2026
…RenovateConfig, ValidateRenovateConfigService, downloadFile; add formatLevelWithHitColor and loadConfigFile tests

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title Improve test coverage: refactor for testability and add targeted unit tests Round 3: inject HTTP clients for testability; add branch tests for formatLevelWithHitColor, loadConfigFile, downloadFile Mar 3, 2026
…tLogger, SaveTerminalState, setupQueue, GetQueueStatus, analyzeQueueItem, Hit nil-path, setupGlobalHitWriter

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title Round 3: inject HTTP clients for testability; add branch tests for formatLevelWithHitColor, loadConfigFile, downloadFile Round 4: Boost unit test coverage across docs, common, gitlab/scan, and logging packages Mar 3, 2026
…t_test.go

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title Round 4: Boost unit test coverage across docs, common, gitlab/scan, and logging packages Fix sync.Once copylocks vet errors and Windows unit test failures in pkg/logging Mar 4, 2026
…estInitLogger tests

Co-authored-by: frjcomp <107982661+frjcomp@users.noreply.github.com>
Copilot AI changed the title Fix sync.Once copylocks vet errors and Windows unit test failures in pkg/logging Fix copylocks lint errors and Windows test failures in logging/common Mar 4, 2026
@frjcomp frjcomp merged commit 959ec0c into main Mar 4, 2026
12 checks passed
@frjcomp frjcomp deleted the copilot/deep-test-analysis-go-project branch March 4, 2026 10:21
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.

3 participants