Skip to content

[Duplicate Code] writeConfigs() base config object repeated 18 times in config-writer.test.ts #4028

Description

@github-actions

Duplicate Code Opportunity

Summary

  • Pattern: The writeConfigs() call with a 10-field base configuration object is copy-pasted into 18 individual test cases in src/config-writer.test.ts. Only one or two fields differ per test.
  • Locations: src/config-writer.test.ts — at least 18 occurrences spread throughout the file (e.g., lines 79–90, 96–109, 223–235, 270–282, 292–305, 311–332, 454–466, 483–495, and ~10 more)
  • Impact: ~10–12 lines per occurrence × 18 occurrences = ~180 duplicated lines; any change to the base config shape (e.g., adding a required field) requires 18 edits instead of one

Evidence

Every test repeats this block verbatim (only the variant fields differ):

Occurrence 1 (lines 79–90):

await writeConfigs({
  workDir: tempDir,
  sslBump: true,
  allowedDomains: [],
  agentCommand: 'echo test',
  logLevel: 'info',
  keepContainers: false,
  buildLocal: false,
  imageRegistry: 'ghcr.io/github/gh-aw-firewall',
  imageTag: 'latest',
})

Occurrence 2 (lines 223–235) — differs only in allowedDomains:

await writeConfigs({
  workDir: tempDir,
  sslBump: false,
  allowedDomains: [],
  agentCommand: 'echo test',
  logLevel: 'info',
  keepContainers: false,
  buildLocal: false,
  imageRegistry: 'ghcr.io/github/gh-aw-firewall',
  imageTag: 'latest',
});

Occurrence 3 (lines 292–305) — adds geminiApiKey:

await writeConfigs({
  workDir: tempDir,
  sslBump: false,
  allowedDomains: [],
  agentCommand: 'echo test',
  logLevel: 'info',
  keepContainers: false,
  buildLocal: false,
  imageRegistry: 'ghcr.io/github/gh-aw-firewall',
  imageTag: 'latest',
  geminiApiKey: 'test-key',
});

grep -c "agentCommand: 'echo test'" src/config-writer.test.ts returns 18.

Suggested Refactoring

Extract a shared base config constant and spread it:

const baseWriteConfig = {
  workDir: tempDir,
  sslBump: false,
  allowedDomains: [] as string[],
  agentCommand: 'echo test',
  logLevel: 'info' as const,
  keepContainers: false,
  buildLocal: false,
  imageRegistry: 'ghcr.io/github/gh-aw-firewall',
  imageTag: 'latest',
};

// Each test then becomes:
await writeConfigs({ ...baseWriteConfig, geminiApiKey: 'test-key' });

Declare baseWriteConfig in the outer describe scope (or a beforeEach) so workDir: tempDir resolves correctly via closure.

Affected Files

  • src/config-writer.test.ts — 18 occurrences throughout the file

Effort Estimate

Low — pure refactor, no logic change, only test file affected


Detected by Duplicate Code Detector workflow. Run date: 2026-05-29

Generated by Duplicate Code Detector · sonnet46 1.4M ·

  • expires on Jun 28, 2026, 10:17 PM UTC

Metadata

Metadata

Assignees

Type

No type

Fields

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