Skip to content

Add edge case tests and fix duplicate source ID validation#3

Merged
fbosch merged 6 commits intomasterfrom
copilot/test-edge-cases-tool
Jan 31, 2026
Merged

Add edge case tests and fix duplicate source ID validation#3
fbosch merged 6 commits intomasterfrom
copilot/test-edge-cases-tool

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

Testing revealed two validation gaps: duplicate source IDs silently overwrite in the lock file, and unknown config fields pass validation. Added 58 tests covering boundary conditions, malformed inputs, path handling, and security scenarios.

Validation Fixes

Duplicate source IDs now rejected

// src/config.ts
const idSet = new Set<string>();
const duplicates: string[] = [];
for (const source of sources) {
  if (idSet.has(source.id)) {
    duplicates.push(source.id);
  }
  idSet.add(source.id);
}
if (duplicates.length > 0) {
  throw new Error(`Duplicate source IDs found: ${duplicates.join(", ")}`);
}

Strict schema validation

// src/config-schema.ts
export const SourceSchema = z.object({
  id: z.string().min(1),
  repo: z.string().min(1),
  // ... other fields
}).strict();  // Now rejects unknown fields

Test Coverage Added

Config validation (25 tests)

  • Empty/negative/zero values for maxBytes, maxFiles, depth
  • Malformed JSON, BOM handling, corrupted lock files
  • Duplicate IDs, unknown fields, whitespace-only strings

Input variants (24 tests)

  • Source IDs with special chars, slashes, Unicode, null bytes
  • Various URL protocols (https, http, git, ssh, file)
  • Glob patterns, ref formats, cross-platform paths

Security & paths (9 tests)

  • Path traversal protection verified
  • Unicode filenames, deeply nested directories (7+ levels)
  • Symlink exclusion, resource limit enforcement

Edge Cases Documented

Allowed but potentially problematic (documented in tests):

  • Whitespace-only source IDs
  • Null bytes in source IDs (valid JSON, risky for filesystems)
  • Special characters in IDs (:, |, *, ?, <)
  • Path traversal patterns in IDs (../)

All changes backward compatible. Test suite: 61 → 119 tests, 0 CodeQL alerts.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits January 31, 2026 12:59
Co-authored-by: fbosch <6979916+fbosch@users.noreply.github.com>
Co-authored-by: fbosch <6979916+fbosch@users.noreply.github.com>
Co-authored-by: fbosch <6979916+fbosch@users.noreply.github.com>
Co-authored-by: fbosch <6979916+fbosch@users.noreply.github.com>
Copilot AI changed the title [WIP] Try to break the tool and identify edge cases Add edge case tests and fix duplicate source ID validation Jan 31, 2026
Copilot AI requested a review from fbosch January 31, 2026 13:10
@fbosch fbosch marked this pull request as ready for review January 31, 2026 13:13
@fbosch fbosch merged commit 80c7330 into master Jan 31, 2026
0 of 2 checks passed
@fbosch fbosch deleted the copilot/test-edge-cases-tool branch January 31, 2026 16:57
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