Duplicate Code Opportunity
Summary
- Pattern: The five-argument call to
assembleAndValidateConfig({}, 'echo test', createMinimalLogAndLimits(), createMinimalNetworkOptions(), createMinimalAgentOptions()) is repeated 26 times across config-assembly.test.ts, always with an empty first argument and the same three factory-function calls for the mandatory parameters.
- Locations:
src/commands/validators/config-assembly.test.ts — the pattern appears at (e.g.) lines 196–202, 235–241, 255–261, 279–285, 300–306, 330–336, 353–359, 374–380, ... (26 call sites in total).
- Impact: ~130 duplicate lines in a single 600-line test file; adding or reordering a parameter to
assembleAndValidateConfig requires updating all 26 call sites.
Evidence
The following block (or its expect(() => { ... }).toThrow(...) wrapper) appears 26 times, differing only in the first argument:
assembleAndValidateConfig(
{}, // varies: {} or { awfDockerHost: '...' } or similar
'echo test',
createMinimalLogAndLimits(),
createMinimalNetworkOptions(),
createMinimalAgentOptions(),
);
Representative duplicate pair — lines 196–202 vs 235–241:
// line 196
assembleAndValidateConfig(
{},
'echo test',
createMinimalLogAndLimits(),
createMinimalNetworkOptions(),
createMinimalAgentOptions(),
);
// line 235 (structurally identical except first arg)
assembleAndValidateConfig(
{},
'echo test',
createMinimalLogAndLimits(),
createMinimalNetworkOptions(),
createMinimalAgentOptions(),
);
Suggested Refactoring
Add a local test helper that pre-fills the invariant arguments:
// Inside the describe block, after the factory functions are declared:
function callAssembleWith(options: Record<string, unknown> = {}) {
return assembleAndValidateConfig(
options,
'echo test',
createMinimalLogAndLimits(),
createMinimalNetworkOptions(),
createMinimalAgentOptions(),
);
}
Then each call site simplifies from 6 lines to 1:
// before
expect(() => {
assembleAndValidateConfig({}, 'echo test',
createMinimalLogAndLimits(), createMinimalNetworkOptions(), createMinimalAgentOptions());
}).toThrow('process.exit(1)');
// after
expect(() => callAssembleWith()).toThrow('process.exit(1)');
Affected Files
src/commands/validators/config-assembly.test.ts — 26 call sites throughout the file
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-05-27
Generated by Duplicate Code Detector · sonnet46 3.1M · ◷
Duplicate Code Opportunity
Summary
assembleAndValidateConfig({}, 'echo test', createMinimalLogAndLimits(), createMinimalNetworkOptions(), createMinimalAgentOptions())is repeated 26 times acrossconfig-assembly.test.ts, always with an empty first argument and the same three factory-function calls for the mandatory parameters.src/commands/validators/config-assembly.test.ts— the pattern appears at (e.g.) lines 196–202, 235–241, 255–261, 279–285, 300–306, 330–336, 353–359, 374–380, ... (26 call sites in total).assembleAndValidateConfigrequires updating all 26 call sites.Evidence
The following block (or its
expect(() => { ... }).toThrow(...)wrapper) appears 26 times, differing only in the first argument:Representative duplicate pair — lines 196–202 vs 235–241:
Suggested Refactoring
Add a local test helper that pre-fills the invariant arguments:
Then each call site simplifies from 6 lines to 1:
Affected Files
src/commands/validators/config-assembly.test.ts— 26 call sites throughout the fileEffort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-05-27