Skip to content

Commit d765962

Browse files
bradygasterCopilot
andcommitted
fix: ignore CommonMark tab-indented commands
Closes #2103 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c49a590 commit d765962

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎test/gh-aw-command-parse.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ describe('gh-aw: shared /squad command contract (#1824)', () => {
3838
])('%s call site', (_name, payload) => {
3939
it.each([
4040
['/squad cast', 'cast', null],
41+
[' /squad cast ', 'cast', null],
4142
[' /squad cast ', 'cast', null],
43+
[' /squad cast ', 'cast', null],
4244
['Context first.\n\n/squad status ', 'status', null],
4345
['/squad research Focus only on proposal P1', 'research', null],
4446
['/squad activate phase 2', 'activate', 2],
@@ -95,6 +97,9 @@ describe('gh-aw: shared /squad command contract (#1824)', () => {
9597
['````text\n```` trailing-info\n/squad cast\n````', 'code after a fence with trailing info'],
9698
[' /squad cast', 'four-space-indented code'],
9799
['\t/squad cast', 'tab-indented code'],
100+
[' \t/squad cast', 'one-space-plus-tab-indented code'],
101+
[' \t/squad cast', 'two-spaces-plus-tab-indented code'],
102+
[' \t/squad cast', 'three-spaces-plus-tab-indented code'],
98103
])('ignores %s instead of activating control-plane work', (body) => {
99104
expect(classifySquadCommand(payload(body), 'issues')).toEqual({
100105
status: 'none',
@@ -285,4 +290,34 @@ describe('gh-aw: shared /squad command contract (#1824)', () => {
285290
rmSync(root, { recursive: true, force: true });
286291
}
287292
});
293+
294+
it('realistic CommonMark tab-indentation mutation exposes hidden commands and is caught', async () => {
295+
mkdirSync(TEST_ROOT, { recursive: true });
296+
const root = mkdtempSync(join(TEST_ROOT, 'command-indent-mutant-'));
297+
try {
298+
const source = join(process.cwd(), 'workflows', 'shared', 'squad-command-contract.mjs');
299+
const mutant = join(root, 'squad-command-contract-mutant.mjs');
300+
cpSync(source, mutant);
301+
const original = readFileSync(mutant, 'utf8');
302+
const changed = original.replace(
303+
'/^(?: {4}| {0,3}\\t)/',
304+
'/^(?: {4}|\\t)/',
305+
);
306+
expect(changed).not.toBe(original);
307+
writeFileSync(mutant, changed);
308+
const module = await import(`${pathToFileURL(mutant).href}?mutation=${Date.now()}`);
309+
for (const body of [' \t/squad cast', ' \t/squad cast', ' \t/squad cast']) {
310+
expect(module.classifySquadCommand(comment(body), 'issue_comment')).toMatchObject({
311+
status: 'accepted',
312+
mode: 'cast',
313+
});
314+
expect(classifySquadCommand(comment(body), 'issue_comment')).toEqual({
315+
status: 'none',
316+
source: 'comment',
317+
});
318+
}
319+
} finally {
320+
rmSync(root, { recursive: true, force: true });
321+
}
322+
});
288323
});

‎workflows/shared/squad-command-contract.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function extractInvocation(source, text) {
135135
};
136136
continue;
137137
}
138-
if (/^(?: {4}|\t)/.test(originalLine)) continue;
138+
if (/^(?: {4}| {0,3}\t)/.test(originalLine)) continue;
139139
const line = originalLine.replace(/`+[^`]*`+/g, '').trim();
140140
if (!/^\/squad/i.test(line)) continue;
141141
const slash = line.match(/^\/squad(?:\s|$)/);

‎workflows/squad-workflows.manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"package_destination": ".github/workflows/shared/squad-command-contract.mjs",
106106
"destination": ".github/workflows/shared/squad-command-contract.mjs",
107107
"ownership": "manifest",
108-
"sha256": "137e30129602128cbea33fb4f113e66761fe14c9b1db906dff3b6f681f19de58"
108+
"sha256": "9c6d70b7c590b36488de48e5e8b2fcaa59793115060bb85bac9dbfd6fe934b7d"
109109
},
110110
{
111111
"path": "shared/squad-cast-validator.mjs",

0 commit comments

Comments
 (0)