[Duplicate Code] Repeated lstat identity-swap stub and fixture setup in src/nvx/live-mount-policy.test.ts

Open Beginner friendly
#12,023 0 comments 1 reaction 2 assignees View on GitHub

Maintainers usually reply within 1 day

@lpcox is already working on this.

Since Nov 29, 2026.

  • #12341 by @lpcox — closed without merging

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

code-quality refactoring

Duplicate Code Opportunity

Summary
  • Pattern: An lstat stub 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.ts lines 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-293
  • src/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 the lstat function. The delayed-swap behavior becomes an option, so both tests share one implementation.
  • Extract the setup into a withSensitivePolicyDir(value, run) helper that derives source and mcpLogs once.
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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/gh-aw-firewall

All issues in github/gh-aw-firewall

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.