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 · ◷
Duplicate Code Opportunity
Summary
writeConfigs()call with a 10-field base configuration object is copy-pasted into 18 individual test cases insrc/config-writer.test.ts. Only one or two fields differ per test.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)Evidence
Every test repeats this block verbatim (only the variant fields differ):
Occurrence 1 (
lines 79–90):Occurrence 2 (
lines 223–235) — differs only inallowedDomains:Occurrence 3 (
lines 292–305) — addsgeminiApiKey:grep -c "agentCommand: 'echo test'" src/config-writer.test.tsreturns 18.Suggested Refactoring
Extract a shared base config constant and spread it:
Declare
baseWriteConfigin the outerdescribescope (or abeforeEach) soworkDir: tempDirresolves correctly via closure.Affected Files
src/config-writer.test.ts— 18 occurrences throughout the fileEffort Estimate
Low — pure refactor, no logic change, only test file affected
Detected by Duplicate Code Detector workflow. Run date: 2026-05-29