Skip to content

[Duplicate Code] Repeated network-isolation workflow test setup in cli-workflow.test.ts #6490

Description

@github-actions

Duplicate Code Opportunity

Summary

  • Pattern: The same network-isolation test harness is repeated across several cases: mockedRuntimeNeedsStaticDns, mockedGetTopologyContainerIps, mockedPatchComposeWithTopologyHosts, the startContainers stub, and the runMainWorkflow(...) invocation.
  • Locations: src/cli-workflow.test.ts lines 671-705, 707-735, 769-799, and 801-827.
  • Impact: Roughly 80+ repeated lines across one large integration test file; changes to the workflow setup or topology assertions require updating several nearly identical blocks.

Evidence

Representative repeated setup blocks:

mockedRuntimeNeedsStaticDns.mockReturnValue(true);
const peerIps = new Map([['mcp-gateway', '172.30.0.100']]);
mockedGetTopologyContainerIps.mockResolvedValue(peerIps);
mockedPatchComposeWithTopologyHosts.mockImplementation(() => {});

const config: WrapperConfig = {
  ...baseConfig,
  networkIsolation: true,
  topologyAttach: ['mcp-gateway'],
  containerRuntime: 'gvisor',
};

const startContainers = jest.fn().mockImplementation(
  async (_workDir: string, _domains: string[], _logs?: string, _skip?: boolean, onNetworkReady?: () => Promise<void>) => {
    if (onNetworkReady) await onNetworkReady();
  },
);

await runMainWorkflow(
  config,
  createWorkflowDependencies({ startContainers, connectTopologyContainers }),
  createWorkflowOptions(),
);
mockedRuntimeNeedsStaticDns.mockReturnValue(false);
const peerIps = new Map([['peer', '10.0.0.1']]);
mockedGetTopologyContainerIps.mockResolvedValue(peerIps);
mockedPatchComposeWithTopologyHosts.mockImplementation(() => {});

const config: WrapperConfig = {
  ...baseConfig,
  networkIsolation: true,
  topologyAttach: ['peer'],
  difcProxyHost: 'proxy.corp.com:18443',
};

const startContainers = jest.fn().mockImplementation(
  async (_workDir: string, _domains: string[], _logs?: string, _skip?: boolean, onNetworkReady?: () => Promise<void>) => {
    if (onNetworkReady) await onNetworkReady();
  },
);

await runMainWorkflow(
  config,
  createWorkflowDependencies({ startContainers, connectTopologyContainers: jest.fn() }),
  createWorkflowOptions(),
);

Suggested Refactoring

Extract a small helper for the repeated topology-test harness, e.g. runNetworkIsolationWorkflow({ configOverrides, peerIps, connectTopologyContainers, expectedHost }), so each case only declares its unique assertion.

Affected Files

  • src/cli-workflow.test.ts — lines 671-705
  • src/cli-workflow.test.ts — lines 707-735
  • src/cli-workflow.test.ts — lines 769-799
  • src/cli-workflow.test.ts — lines 801-827

Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-07-22

Generated by Duplicate Code Detector · 8.11 AIC · ⊞ 23.7K ·

  • expires on Aug 21, 2026, 6:37 AM UTC

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions