test(sidebar-agent): regex-tolerant destructure check

Same class of brittleness as sidebar-security.test.ts fixed earlier
(commit 65bf4514). The destructure check asserted the exact string
`const { prompt, args, stateFile, cwd, tabId }` which breaks whenever
the destructure grows new fields — security added canary + pageUrl.

Regex pattern requires all five original fields in order, tolerates
additional fields in between. Preserves the test's intent without
churning on every field addition.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-20 04:32:23 +08:00
parent 27954de0b0
commit af1b1352bf
+5 -2
View File
@@ -462,8 +462,11 @@ describe('per-tab agent concurrency', () => {
test('sidebar-agent sends tabId with all events', () => {
// sendEvent should accept tabId parameter
expect(agentSrc).toContain('async function sendEvent(event: Record<string, any>, tabId?: number)');
// askClaude should extract tabId from queue entry
expect(agentSrc).toContain('const { prompt, args, stateFile, cwd, tabId }');
// askClaude destructures tabId from queue entry (regex tolerates
// additional fields like `canary` and `pageUrl` from security module).
expect(agentSrc).toMatch(
/const \{[^}]*\bprompt\b[^}]*\bargs\b[^}]*\bstateFile\b[^}]*\bcwd\b[^}]*\btabId\b[^}]*\}/
);
});
test('sidebar-agent allows concurrent agents across tabs', () => {