Duplicate Code Opportunity
Summary
- Pattern: The bounded-agent and bounded-query ingress conformance tests duplicate the same socket setup, broker stub, request helpers, and transport parity assertions.
- Locations:
src/bounded-agent/ingress-conformance.test.ts lines 91-133 and src/bounded-query/ingress-conformance.test.ts lines 77-119, plus the shared follow-on assertion block at src/bounded-agent/ingress-conformance.test.ts lines 133-161 and src/bounded-query/ingress-conformance.test.ts lines 119-147.
- Impact: More than 20 duplicate lines in a security-relevant transport/ingress test path, with repeated setup across two near-identical suites.
Evidence
Both files build the same temporary socket root, same broker stub, same TCP + Unix server pair, same listenOnSocket / listenOnTcp setup, and same request helpers:
root = fs.mkdtempSync(path.join(os.tmpdir(), 'awf-bounded-agent-ingress-test-'));
socketPath = path.join(root, 'broker.sock');
handled = [];
const broker = {
handle: (incoming: unknown, respond: (body: string) => void) => {
handled.push(incoming);
respond(incoming === undefined ? CANONICAL_ERROR : CANONICAL_OK);
return Promise.resolve();
},
};
unixServer = createServer({ broker, audit });
tcpServer = createTcpServer({
broker,
audit,
capabilities: { query: CAPABILITY, probe: PROBE_CAPABILITY },
});
await listenOnSocket(unixServer, { socketPath, socketDir: root, socketUid: process.getuid?.() ?? 0, socketGid: process.getgid?.() ?? 0 }, audit);
await listenOnTcp(tcpServer, { tcpPort: 0 });
tcpPort = (tcpServer.address() as AddressInfo).port;
And both suites re-declare the same unixRequest / tcpRequest helpers and transport-parity assertions immediately afterward.
Suggested Refactoring
Extract a shared ingress test harness helper that owns:
- temp socket root creation and cleanup
- broker/audit server wiring
unixRequest and tcpRequest helpers
- common transport parity assertions
Then keep only the bounded-agent vs bounded-query domain-specific expectations in each suite.
Affected Files
src/bounded-agent/ingress-conformance.test.ts — lines 91-161
src/bounded-query/ingress-conformance.test.ts — lines 77-147
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-08-06
Generated by Duplicate Code Detector · gpt54mini · 4.96 AIC · ⊞ 25.8K · ◷
Duplicate Code Opportunity
Summary
src/bounded-agent/ingress-conformance.test.tslines 91-133 andsrc/bounded-query/ingress-conformance.test.tslines 77-119, plus the shared follow-on assertion block atsrc/bounded-agent/ingress-conformance.test.tslines 133-161 andsrc/bounded-query/ingress-conformance.test.tslines 119-147.Evidence
Both files build the same temporary socket root, same
brokerstub, same TCP + Unix server pair, samelistenOnSocket/listenOnTcpsetup, and same request helpers:And both suites re-declare the same
unixRequest/tcpRequesthelpers and transport-parity assertions immediately afterward.Suggested Refactoring
Extract a shared ingress test harness helper that owns:
unixRequestandtcpRequesthelpersThen keep only the bounded-agent vs bounded-query domain-specific expectations in each suite.
Affected Files
src/bounded-agent/ingress-conformance.test.ts— lines 91-161src/bounded-query/ingress-conformance.test.ts— lines 77-147Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-08-06