Skip to content

Commit 5b5265d

Browse files
nullvariantcodex
andcommitted
test(submodule): cover remaining Sonar branches
Add focused tests for branch suffix parsing and workspace validation fallback handling so the submodule coverage report no longer has uncovered lines or branches in src/core/submodule.ts. 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 ca9c68b commit 5b5265d

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ function stripBranchSuffix(str: string): string {
122122
}
123123
/* c8 ignore stop */
124124

125+
function getWorkspaceValidationFailureReason(workspaceValidation: {
126+
reason?: string;
127+
}): string {
128+
return workspaceValidation.reason ?? "Invalid workspace path";
129+
}
130+
125131
/**
126132
* Parse and validate a single submodule entry from git status output.
127133
* Uses pure string operations to prevent ReDoS vulnerabilities.
@@ -270,7 +276,7 @@ export async function listSubmodules(
270276
if (!workspaceValidation.valid || !workspaceValidation.normalizedPath) {
271277
securityLogger.logValidationFailure(
272278
"submoduleWorkspace",
273-
workspaceValidation.reason ?? "Invalid workspace path",
279+
getWorkspaceValidationFailureReason(workspaceValidation),
274280
);
275281
return [];
276282
}
@@ -534,5 +540,7 @@ export function getMaxSubmoduleDepth(): number {
534540
* Test-only exports for private validation helpers.
535541
*/
536542
export const __testExports = {
543+
getWorkspaceValidationFailureReason,
537544
isValidCommitHash,
545+
stripBranchSuffix,
538546
};

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,55 @@ function testCommitHashValidation(): void {
430430
console.log(' Commit hash validation tests passed');
431431
}
432432

433+
/**
434+
* Test branch suffix parsing branch coverage.
435+
*/
436+
function testBranchSuffixParsing(): void {
437+
console.log('Testing branch suffix parsing...');
438+
439+
const { stripBranchSuffix } = __testExports;
440+
441+
assert.strictEqual(
442+
stripBranchSuffix('vendor/lib'),
443+
'vendor/lib',
444+
'Path without branch suffix should remain unchanged'
445+
);
446+
assert.strictEqual(
447+
stripBranchSuffix('vendor/lib main)'),
448+
'vendor/lib main)',
449+
'Malformed suffix without opening parenthesis should remain unchanged'
450+
);
451+
assert.strictEqual(
452+
stripBranchSuffix('vendor/lib (main)'),
453+
'vendor/lib',
454+
'Valid branch suffix should be stripped'
455+
);
456+
457+
console.log(' Branch suffix parsing tests passed');
458+
}
459+
460+
/**
461+
* Test workspace validation failure reason fallback branch coverage.
462+
*/
463+
function testWorkspaceValidationFailureReason(): void {
464+
console.log('Testing workspace validation failure reason...');
465+
466+
const { getWorkspaceValidationFailureReason } = __testExports;
467+
468+
assert.strictEqual(
469+
getWorkspaceValidationFailureReason({ reason: 'Workspace path is empty' }),
470+
'Workspace path is empty',
471+
'Provided workspace validation reason should be used'
472+
);
473+
assert.strictEqual(
474+
getWorkspaceValidationFailureReason({}),
475+
'Invalid workspace path',
476+
'Fallback reason should be used when validation has no reason'
477+
);
478+
479+
console.log(' Workspace validation failure reason tests passed');
480+
}
481+
433482
/**
434483
* Test regex pattern strictness (40-char SHA-1)
435484
*
@@ -1168,6 +1217,8 @@ export async function runSubmoduleTests(): Promise<void> {
11681217
testMaxSubmoduleDepth();
11691218
testWorkspaceBoundary();
11701219
testCommitHashValidation();
1220+
testBranchSuffixParsing();
1221+
testWorkspaceValidationFailureReason();
11711222
testRegexPatternStrictness();
11721223
testInvalidWorkspacePaths();
11731224

0 commit comments

Comments
 (0)