Skip to content

Commit 8c2b93d

Browse files
tamirdresherCopilot
andcommitted
fix: address remaining promotion CodeQL findings
Relates to #2538 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 2d651a1 commit 8c2b93d

5 files changed

Lines changed: 48 additions & 7 deletions

File tree

‎packages/squad-sdk/src/config/team-capabilities.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function sanitizeMetadataText(raw: unknown, maxLength: number = MAX_SUMMA
202202

203203
// HTML comments can smuggle markers, canaries, or directives.
204204
text = withoutHtmlComments(text);
205-
text = text.replace(/<!--/g, ' ').replace(/-->/g, ' ').replace(/--!>/g, ' ');
205+
text = text.replaceAll('<!--', ' ').replaceAll('-->', ' ').replaceAll('--!>', ' ');
206206
// Then remove tag-shaped content and escape residual opening brackets.
207207
text = text.replace(/<[^<>\n]{0,200}>/g, ' ');
208208
text = text.replace(/</g, '&lt;');

‎packages/squad-sdk/src/platform/detect.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export interface AzureDevOpsRemoteInfo {
2020
repo: string;
2121
}
2222

23+
function stripGitSuffix(repo: string): string {
24+
return repo.length > 4 && repo.toLowerCase().endsWith('.git') ? repo.slice(0, -4) : repo;
25+
}
26+
2327
/**
2428
* Parse a GitHub remote URL into owner/repo.
2529
* Supports HTTPS and SSH formats:
@@ -37,9 +41,9 @@ export function parseGitHubRemote(url: string): GitHubRemoteInfo | null {
3741
}
3842

3943
// SSH: git@github.com:owner/repo.git
40-
const sshMatch = url.match(/github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/i);
44+
const sshMatch = url.match(/^(?:[^@\s/:]+@)?github\.com:([^/]+)\/([^/]+)$/i);
4145
if (sshMatch) {
42-
return { owner: sshMatch[1]!, repo: sshMatch[2]! };
46+
return { owner: sshMatch[1]!, repo: stripGitSuffix(sshMatch[2]!) };
4347
}
4448

4549
return null;
@@ -91,10 +95,10 @@ export function parseAzureDevOpsRemote(url: string): AzureDevOpsRemoteInfo | nul
9195
// (Org subdomain keeps the no-dot constraint — the `.visualstudio.com` anchor
9296
// requires it. Only the repo capture is widened.)
9397
const vsMatch = url.match(
94-
/([^/.]+)\.visualstudio\.com\/([^/]+)\/_git\/([^/]+?)(?:\.git)?$/i,
98+
/^(?:https?|ssh|git):\/\/([^/.]+)\.visualstudio\.com\/([^/]+)\/_git\/([^/]+)$/i,
9599
);
96100
if (vsMatch) {
97-
return { org: decodeSegment(vsMatch[1]!), project: decodeSegment(vsMatch[2]!), repo: decodeSegment(vsMatch[3]!) };
101+
return { org: decodeSegment(vsMatch[1]!), project: decodeSegment(vsMatch[2]!), repo: decodeSegment(stripGitSuffix(vsMatch[3]!)) };
98102
}
99103

100104
return null;

‎packages/squad-sdk/src/ralph/triage.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,26 @@ function routeMatch(
406406
'agent', 'engineer', 'engineering', 'management', 'owner',
407407
'specialist', 'system', 'work',
408408
]);
409-
const tokens = (value: string): string[] =>
410-
value.toLowerCase().match(/[a-z0-9][a-z0-9+#.]*(?<!\.)/g) ?? [];
409+
const tokens = (value: string): string[] => {
410+
const text = value.toLowerCase();
411+
const result: string[] = [];
412+
const isAlphanumeric = (code: number) =>
413+
(code >= 48 && code <= 57) || (code >= 97 && code <= 122);
414+
let cursor = 0;
415+
while (cursor < text.length) {
416+
if (!isAlphanumeric(text.charCodeAt(cursor))) {
417+
cursor++;
418+
continue;
419+
}
420+
const start = cursor++;
421+
while (cursor < text.length &&
422+
(isAlphanumeric(text.charCodeAt(cursor)) || '+#.'.includes(text[cursor]!))) cursor++;
423+
let end = cursor;
424+
while (end > start && text[end - 1] === '.') end--;
425+
result.push(text.slice(start, end));
426+
}
427+
return result;
428+
};
411429
const containsPhrase = (haystack: string[], needle: string[]): boolean =>
412430
needle.length > 0 &&
413431
needle.length <= haystack.length &&

‎test/platform-adapter.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ describe('parseGitHubRemote', () => {
9797
expect(result).toEqual({ owner: 'owner', repo: 'repo' });
9898
});
9999

100+
it('does not parse an SSH host that merely ends with github.com', () => {
101+
expect(parseGitHubRemote('git@notgithub.com:owner/repo.git')).toBeNull();
102+
});
103+
100104
it('returns null for non-GitHub URLs', () => {
101105
expect(parseGitHubRemote('https://dev.azure.com/org/project/_git/repo')).toBeNull();
102106
});
@@ -168,6 +172,12 @@ describe('parseAzureDevOpsRemote', () => {
168172
expect(result).toEqual({ org: 'contoso', project: 'WebApp', repo: 'frontend' });
169173
});
170174

175+
it('parses a long legacy organization without backtracking', () => {
176+
const org = 'a'.repeat(10_000);
177+
const result = parseAzureDevOpsRemote(`https://${org}.visualstudio.com/WebApp/_git/frontend.git`);
178+
expect(result).toEqual({ org, project: 'WebApp', repo: 'frontend' });
179+
});
180+
171181
it('returns null for GitHub URLs', () => {
172182
expect(parseAzureDevOpsRemote('https://github.com/owner/repo.git')).toBeNull();
173183
});

‎test/ralph-triage.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,15 @@ describe('triageIssue()', () => {
368368
expect(decision?.source).toBe('routing-rule');
369369
});
370370

371+
it.each(['C++', 'C#', 'Node.js'])('matches punctuated technology keywords: %s', (keyword) => {
372+
const technologyRule: RoutingRule[] = [
373+
{ workType: 'Technology', agentName: 'Runtime Engineer', keywords: [keyword] },
374+
];
375+
const decision = triageIssue(issue(`Investigate ${keyword}...`), technologyRule, [], roster);
376+
expect(decision?.source).toBe('routing-rule');
377+
expect(decision?.agent.name).toBe('Runtime Engineer');
378+
});
379+
371380
it('prefers longer module path match (src/ralph/ over src/)', () => {
372381
const customModules: ModuleOwnership[] = [
373382
{ modulePath: 'src/', primary: 'Team Lead', secondary: null },

0 commit comments

Comments
 (0)