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 · ◷
Duplicate Code Opportunity
Summary
mockedRuntimeNeedsStaticDns,mockedGetTopologyContainerIps,mockedPatchComposeWithTopologyHosts, thestartContainersstub, and therunMainWorkflow(...)invocation.src/cli-workflow.test.tslines 671-705, 707-735, 769-799, and 801-827.Evidence
Representative repeated setup blocks:
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-705src/cli-workflow.test.ts— lines 707-735src/cli-workflow.test.ts— lines 769-799src/cli-workflow.test.ts— lines 801-827Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-07-22