Skip to content

Export subnetsOverlap to eliminate test duplication#22

Merged
Mossaka merged 4 commits intomainfrom
copilot/refactor-subnet-overlap-function
Oct 30, 2025
Merged

Export subnetsOverlap to eliminate test duplication#22
Mossaka merged 4 commits intomainfrom
copilot/refactor-subnet-overlap-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 30, 2025

The unit test duplicated the entire subnetsOverlap implementation (23 lines) instead of importing it from docker-manager.ts.

Changes:

  • Export subnetsOverlap from docker-manager.ts
  • Import and use the exported function in tests
// Before: docker-manager.test.ts
const subnetsOverlap = (subnet1: string, subnet2: string): boolean => {
  // 23 lines of duplicated implementation
};

// After: docker-manager.test.ts
import { generateDockerCompose, subnetsOverlap } from './docker-manager';
Original prompt

why does the unit test has const subnetsOverlap = (subnet1: string, subnet2: string): boolean => {
const [ip1, cidr1] = subnet1.split('/');
const [ip2, cidr2] = subnet2.split('/');

  const ipToNumber = (ip: string): number => {
    return ip.split('.').reduce((acc, octet) => (acc << 8) + parseInt(octet, 10), 0) >>> 0;
  };

  const getNetworkRange = (ip: string, cidr: string): [number, number] => {
    const ipNum = ipToNumber(ip);
    const maskBits = parseInt(cidr, 10);
    const mask = (0xffffffff << (32 - maskBits)) >>> 0;
    const networkAddr = (ipNum & mask) >>> 0;
    const broadcastAddr = (networkAddr | ~mask) >>> 0;
    return [networkAddr, broadcastAddr];
  };

  const [start1, end1] = getNetworkRange(ip1, cidr1);
  const [start2, end2] = getNetworkRange(ip2, cidr2);

  return (start1 <= end2 && end1 >= start2);
};

this should be expose by the docker-manager.ts, no? The unit test shuldn't dupliate the same logic

The user has attached the following files as relevant context:

  • AGENTS.md

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Mossaka and others added 2 commits October 30, 2025 16:46
Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor subnetsOverlap function for reuse in docker-manager Export subnetsOverlap to eliminate test duplication Oct 30, 2025
Copilot AI requested a review from Mossaka October 30, 2025 16:57
Base automatically changed from mossaka/cli-add-workflow-test to main October 30, 2025 16:59
@Mossaka Mossaka marked this pull request as ready for review October 30, 2025 18:34
@Mossaka Mossaka merged commit 939b701 into main Oct 30, 2025
3 of 6 checks passed
@Mossaka Mossaka deleted the copilot/refactor-subnet-overlap-function branch October 30, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants