[Duplicate Code] Repeated lstat identity-swap stub and fixture setup in src/nvx/live-mount-policy.test.ts
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- testing
Research direction
Start with src/nvx/live-mount-policy.test.ts, lines 164-182 and 351-369, where the two lstat identity-swap stubs live, and lines 277-293 and 302-318 for the duplicated sensitive-policy fixture setup. Compare the two stubs closely, since only one has the delayed-swap counter (++mcpLogsStats < 3), before merging them into one helper with a swapAfterCalls option. Done means the shared helpers replace the copies and the existing tests in that file still pass with the same behavior.
Written by the indexing model from the issue text.
Description
Duplicate Code Opportunity
Summary
- Pattern: An
lstatstub that swaps the returned{dev, ino, uid, gid}identity for one target path is copied verbatim in two tests. The sensitive-policy fixture setup is copied in two more tests. - Locations:
src/nvx/live-mount-policy.test.tslines 164-182 and 351-369 (stub); lines 277-293 and 302-318 (fixture setup) - Impact: About 36 duplicated lines (jscpd). Estimated 20 net lines saved. Security-relevant: these stubs exercise identity-swap detection for sensitive mount-policy paths. One copy has a delayed-swap counter (
++mcpLogsStats < 3) and the other does not, so the copies can drift apart and leave one behavior untested.
Evidence
Identity-swap lstat stub:
src/nvx/live-mount-policy.test.ts: lines 164-182
lstat: async (candidate) => {
const stats = await fs.lstat(candidate);
if (candidate !== npmrc) return stats;
return {
dev: stats.dev,
ino: stats.ino,
uid: stats.uid,
gid: stats.gid,
Same stub, delayed-swap variant:
src/nvx/live-mount-policy.test.ts: lines 351-369
lstat: async (candidate) => {
const stats = await fs.lstat(candidate);
if (candidate !== mcpLogs || ++mcpLogsStats < 3) return stats;
return {
dev: stats.dev,
ino: stats.ino,
uid: stats.uid,
gid: stats.gid,
Fixture setup, repeated in two tests:
src/nvx/live-mount-policy.test.ts: lines 277-293src/nvx/live-mount-policy.test.ts: lines 302-318
const value = await fixture();
const source = path.join(value.root, 'gh-aw');
const mcpLogs = path.join(source, 'mcp-logs');
await fs.mkdir(source);
try {
Suggested Refactoring
- Add a local helper such as
stubLstatIdentity(target, { swapAfterCalls = 0 })that returns thelstatfunction. The delayed-swap behavior becomes an option, so both tests share one implementation. - Extract the setup into a
withSensitivePolicyDir(value, run)helper that derivessourceandmcpLogsonce.
Affected Files
src/nvx/live-mount-policy.test.ts— lines 164-182, 277-293, 302-318, 351-369
Effort Estimate
Low
Detected by Duplicate Code Detector workflow. Run date: 2026-11-23
Generated by Duplicate Code Detector · copilot · routed: haiku55 xhigh · ~3 AIC · ⊞ 18.2K · ◷
- expires on Dec 23, 2026, 9:54 PM UTC
- Dominant language
- TypeScript
- Stars
- 169
- Forks
- 89
- Avg merge
- 5h 18m
- Merged PRs (30d)
- 450
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from github/gh-aw-firewall
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
github/gh-aw-firewall#12415 ·
Maintainers usually reply within 1 day
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
github/gh-aw-firewall#12411 ·
Maintainers usually reply within 1 day
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
github/gh-aw-firewall#12345 ·
Maintainers usually reply within 1 day
-
awf-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
github/gh-aw-firewall#11612 ·
Maintainers usually reply within 1 day
-
agentic-workflows automated dependencies
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
github/gh-aw-firewall#3837 ·
Maintainers usually reply within 1 day
All issues in github/gh-aw-firewall
Similar issues
-
agents-window vscode api adoption
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
alefragnani/vscode-copy-word#126 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
opensro-dev/opensro#4949 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
agent:linux priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
fa0311/better-tokuly#1204 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day