Skip to content

[Duplicate Code] 26 identical assembleAndValidateConfig call sites in config-assembly.test.ts #3940

@github-actions

Description

@github-actions

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 ·

  • expires on Jun 26, 2026, 10:20 PM UTC

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions