Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[Duplicate Code] Share network configuration mock setup across network tests

Closed
#10,432 0 comments 1 reaction 2 assignees View on GitHub

Maintainers usually reply within 1 day

@lpcox is already working on this.

Since Oct 21, 2026.

  • #10434 by @copilot-swe-agent — merged

Assessment

This issue has not been assessed yet.

Description

code-quality refactoring

Duplicate Code Opportunity

Summary
  • Pattern: The normal and uncovered-branches network test suites repeat the same mocked module aliases and setupNetworkConfigMocks initialization.

  • Locations: File(s) and line ranges containing duplicates

    • src/commands/network-setup-branches.test.ts: lines 27-43
    • src/commands/network-setup.test.ts: lines 20-36
  • Impact: This is security-sensitive network configuration test scaffolding. Duplicated mock wiring can drift, causing branch tests to exercise different resolver/logger behavior and increasing maintenance burden.

Evidence

src/commands/network-setup-branches.test.ts lines 27-43:

const mockedNetworkLogger = logger as jest.Mocked<typeof logger>;
const mockedDnsResolver = dnsResolver as jest.Mocked<typeof dnsResolver>;
const mockedUpstreamProxy = upstreamProxy as jest.Mocked<typeof upstreamProxy>;
const mockedOptionParsers = optionParsers as jest.Mocked<typeof optionParsers>;

describe('resolveNetworkConfig – uncovered branches', () => {
  let processExitSpy: jest.SpyInstance;

  beforeEach(() => {
    processExitSpy = setupNetworkConfigMocks({
      detectHostDnsServers: mockedDnsResolver.detectHostDnsServers as jest.Mock,

src/commands/network-setup.test.ts lines 20-36:

const mockedLogger = logger as jest.Mocked<typeof logger>;
const mockedDnsResolver = dnsResolver as jest.Mocked<typeof dnsResolver>;
const mockedUpstreamProxy = upstreamProxy as jest.Mocked<typeof upstreamProxy>;
const mockedOptionParsers = optionParsers as jest.Mocked<typeof optionParsers>;

describe('resolveNetworkConfig', () => {
  let processExitSpy: jest.SpyInstance;

  beforeEach(() => {
    processExitSpy = setupNetworkConfigMocks({
      detectHostDnsServers: mockedDnsResolver.detectHostDnsServers as jest.Mock,
Suggested Refactoring

Move the shared mocked-module declarations and beforeEach setup into a reusable test helper, or consolidate the branch coverage into the main network setup suite. Parameterize only the suite description and branch-specific behavior.

Affected Files
  • src/commands/network-setup-branches.test.ts — lines 27-43
  • src/commands/network-setup.test.ts — lines 20-36
Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-10-21

Generated by Duplicate Code Detector · copilot · gpt54mini · 1.03 AIC · ⊞ 29.8K · ◷

  • expires on Nov 20, 2026, 9:53 PM UTC
Dominant language
TypeScript
Stars
150
Forks
76
Avg merge
4h 11m
Merged PRs (30d)
463

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/gh-aw-firewall

All issues in github/gh-aw-firewall

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.