Skip to content

Commit ca9c68b

Browse files
nullvariantcodex
andcommitted
test(submodule): cover commit hash validation branches
Add focused tests for the private commit hash validator so SonarQube and Codecov can account for the short-hash and non-hex rejection branches. Local verification: - npm run lint --workspace git-id-switcher -- --no-cache - npm run compile --workspace git-id-switcher - npm run test:coverage --workspace git-id-switcher Signed-off-by: Null;Variant <null@nullvariant.com> 🖥️ IDE: [Zed](https://zed.dev/) Co-authored-by: GPT-5.5 <codex@openai.com> Model-Raw: gpt-5.5
1 parent c508ad4 commit ca9c68b

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

extensions/git-id-switcher/src/core/submodule.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,10 @@ export function getSubmoduleDepth(): number {
529529
export function getMaxSubmoduleDepth(): number {
530530
return MAX_SUBMODULE_DEPTH;
531531
}
532+
533+
/**
534+
* Test-only exports for private validation helpers.
535+
*/
536+
export const __testExports = {
537+
isValidCommitHash,
538+
};

extensions/git-id-switcher/src/test/submodule.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
setIdentityForSubmodules,
2323
isSubmoduleSupportEnabled,
2424
getSubmoduleDepth,
25+
__testExports,
2526
} from '../core/submodule';
2627
import { _resetCache, _setMockVSCode } from '../core/vscodeLoader';
2728

@@ -402,6 +403,33 @@ function testWorkspaceBoundary(): void {
402403
console.log(' Workspace boundary enforcement passed');
403404
}
404405

406+
/**
407+
* Test commit hash validation branch coverage.
408+
*/
409+
function testCommitHashValidation(): void {
410+
console.log('Testing commit hash validation...');
411+
412+
const { isValidCommitHash } = __testExports;
413+
414+
assert.strictEqual(
415+
isValidCommitHash('0123456789abcdef0123456789abcdef01234567'),
416+
true,
417+
'40-character lowercase hex hash should be valid'
418+
);
419+
assert.strictEqual(
420+
isValidCommitHash('a'.repeat(39)),
421+
false,
422+
'Short hash should be invalid'
423+
);
424+
assert.strictEqual(
425+
isValidCommitHash('g'.repeat(40)),
426+
false,
427+
'Non-hex hash should be invalid'
428+
);
429+
430+
console.log(' Commit hash validation tests passed');
431+
}
432+
405433
/**
406434
* Test regex pattern strictness (40-char SHA-1)
407435
*
@@ -1139,6 +1167,7 @@ export async function runSubmoduleTests(): Promise<void> {
11391167
testPermissionErrorHandling();
11401168
testMaxSubmoduleDepth();
11411169
testWorkspaceBoundary();
1170+
testCommitHashValidation();
11421171
testRegexPatternStrictness();
11431172
testInvalidWorkspacePaths();
11441173

0 commit comments

Comments
 (0)