From 8d261cbd45f77bbdfc0702aa41937c1a2197fe41 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 28 Jul 2026 13:37:54 +0200 Subject: [PATCH 1/3] hackbot-ui: accept a Bugzilla bug URL in the bug ID field Add parseBugId(), which takes either a bare bug ID or a Bugzilla URL (show_bug.cgi?id=N or the short /N form), with unit tests run through node:test + tsx via `npm test`. --- .../hackbot-ui/components/TriggerForm.tsx | 21 +- services/hackbot-ui/lib/bugzilla.test.ts | 60 ++ services/hackbot-ui/lib/bugzilla.ts | 26 + services/hackbot-ui/package-lock.json | 519 ++++++++++++++++++ services/hackbot-ui/package.json | 4 +- services/hackbot-ui/tsconfig.json | 1 + 6 files changed, 619 insertions(+), 12 deletions(-) create mode 100644 services/hackbot-ui/lib/bugzilla.test.ts create mode 100644 services/hackbot-ui/lib/bugzilla.ts diff --git a/services/hackbot-ui/components/TriggerForm.tsx b/services/hackbot-ui/components/TriggerForm.tsx index 8c2dc6e5f7..645385e712 100644 --- a/services/hackbot-ui/components/TriggerForm.tsx +++ b/services/hackbot-ui/components/TriggerForm.tsx @@ -4,6 +4,7 @@ import { useRouter, useSearchParams } from "next/navigation"; import { useState } from "react"; import { AGENTS, type AgentValue } from "@/lib/agents"; +import { parseBugId } from "@/lib/bugzilla"; import { saveRun } from "@/lib/store"; import type { RunRef } from "@/lib/types"; @@ -55,8 +56,8 @@ export function TriggerForm() { const inputs: Record = {}; - const parsedBugId = bugId.trim() ? Number.parseInt(bugId, 10) : Number.NaN; - const hasBugId = Number.isInteger(parsedBugId) && parsedBugId > 0; + const parsedBugId = parseBugId(bugId); + const hasBugId = parsedBugId !== null; const hasBugData = isReproAgent && bugData.trim().length > 0; if (isBuildRepairAgent) { @@ -109,13 +110,13 @@ export function TriggerForm() { inputs.test_scope = testScope.trim(); } else if (!isReproAgent) { if (!hasBugId) { - setError("Enter a valid Bugzilla bug ID."); + setError("Enter a valid Bugzilla bug ID or bug URL."); return; } inputs.bug_id = parsedBugId; } else { if (!hasBugId && !hasBugData) { - setError("Provide a Bugzilla bug ID or paste report text."); + setError("Provide a Bugzilla bug ID (or bug URL) or paste report text."); return; } if (hasBugId) inputs.bug_id = parsedBugId; @@ -188,13 +189,12 @@ export function TriggerForm() {
setBugId(e.target.value)} required={!isReproAgent} @@ -220,11 +220,10 @@ export function TriggerForm() { {isBuildRepairAgent && ( <>
- + setBugId(e.target.value)} /> diff --git a/services/hackbot-ui/lib/bugzilla.test.ts b/services/hackbot-ui/lib/bugzilla.test.ts new file mode 100644 index 0000000000..6c65d77173 --- /dev/null +++ b/services/hackbot-ui/lib/bugzilla.test.ts @@ -0,0 +1,60 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; + +import { parseBugId } from "./bugzilla.ts"; + +test("accepts a bare bug ID", () => { + assert.equal(parseBugId("2058177"), 2058177); + assert.equal(parseBugId(" 2058177 "), 2058177); +}); + +test("accepts a show_bug.cgi URL", () => { + assert.equal( + parseBugId("https://bugzilla.mozilla.org/show_bug.cgi?id=2058177"), + 2058177 + ); + assert.equal( + parseBugId("http://bugzilla.mozilla.org/show_bug.cgi?id=2058177"), + 2058177 + ); + assert.equal( + parseBugId("//bugzilla.mozilla.org/show_bug.cgi?id=2058177"), + 2058177 + ); + assert.equal( + parseBugId("bugzilla.mozilla.org/show_bug.cgi?id=2058177"), + 2058177 + ); +}); + +test("ignores extra query parameters and fragments", () => { + assert.equal( + parseBugId( + "https://bugzilla.mozilla.org/show_bug.cgi?id=2058177&comment=5#c5" + ), + 2058177 + ); +}); + +test("accepts the short bugzilla.mozilla.org/ form", () => { + assert.equal(parseBugId("https://bugzilla.mozilla.org/2058177"), 2058177); + assert.equal(parseBugId("bugzilla.mozilla.org/2058177/"), 2058177); +}); + +test("rejects input without a usable bug ID", () => { + for (const value of [ + "", + " ", + "0", + "-1", + "12abc", + "abc", + "https://bugzilla.mozilla.org/show_bug.cgi?id=abc", + "https://bugzilla.mozilla.org/show_bug.cgi", + "https://example.com/foo", + "https://bugzilla.mozilla.org/describecomponents.cgi", + "http://", + ]) { + assert.equal(parseBugId(value), null, `expected null for ${value}`); + } +}); diff --git a/services/hackbot-ui/lib/bugzilla.ts b/services/hackbot-ui/lib/bugzilla.ts new file mode 100644 index 0000000000..a6377e5c4e --- /dev/null +++ b/services/hackbot-ui/lib/bugzilla.ts @@ -0,0 +1,26 @@ +/** + * Extract a bug ID from user input: either a bare ID ("1846789") or a Bugzilla + * URL ("https://bugzilla.mozilla.org/show_bug.cgi?id=1846789"). + * Returns null when the input does not contain a usable bug ID. + */ +export function parseBugId(value: string): number | null { + const trimmed = value.trim(); + if (!trimmed) return null; + + let candidate = trimmed; + if (/^(https?:)?\/\//i.test(trimmed) || /^bugzilla\./i.test(trimmed)) { + let url: URL; + try { + url = new URL(trimmed.startsWith("http") ? trimmed : `https://${trimmed}`); + } catch { + return null; + } + // show_bug.cgi?id=123, or the short form bugzilla.mozilla.org/123 + candidate = + url.searchParams.get("id") ?? url.pathname.replace(/^\/+|\/+$/g, ""); + } + + if (!/^\d+$/.test(candidate)) return null; + const parsed = Number.parseInt(candidate, 10); + return parsed > 0 ? parsed : null; +} diff --git a/services/hackbot-ui/package-lock.json b/services/hackbot-ui/package-lock.json index d603f4878c..07c86c713b 100644 --- a/services/hackbot-ui/package-lock.json +++ b/services/hackbot-ui/package-lock.json @@ -20,6 +20,7 @@ "@types/node": "^22.10.0", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", + "tsx": "^4.23.1", "typescript": "^5.7.0" } }, @@ -165,6 +166,448 @@ "tslib": "^2.4.0" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz", + "integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz", + "integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz", + "integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz", + "integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz", + "integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz", + "integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz", + "integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz", + "integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz", + "integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz", + "integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz", + "integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz", + "integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz", + "integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz", + "integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz", + "integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz", + "integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz", + "integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz", + "integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz", + "integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz", + "integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz", + "integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz", + "integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz", + "integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz", + "integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz", + "integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz", + "integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@img/colour": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", @@ -1197,6 +1640,48 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/esbuild": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", + "integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.1", + "@esbuild/android-arm": "0.28.1", + "@esbuild/android-arm64": "0.28.1", + "@esbuild/android-x64": "0.28.1", + "@esbuild/darwin-arm64": "0.28.1", + "@esbuild/darwin-x64": "0.28.1", + "@esbuild/freebsd-arm64": "0.28.1", + "@esbuild/freebsd-x64": "0.28.1", + "@esbuild/linux-arm": "0.28.1", + "@esbuild/linux-arm64": "0.28.1", + "@esbuild/linux-ia32": "0.28.1", + "@esbuild/linux-loong64": "0.28.1", + "@esbuild/linux-mips64el": "0.28.1", + "@esbuild/linux-ppc64": "0.28.1", + "@esbuild/linux-riscv64": "0.28.1", + "@esbuild/linux-s390x": "0.28.1", + "@esbuild/linux-x64": "0.28.1", + "@esbuild/netbsd-arm64": "0.28.1", + "@esbuild/netbsd-x64": "0.28.1", + "@esbuild/openbsd-arm64": "0.28.1", + "@esbuild/openbsd-x64": "0.28.1", + "@esbuild/openharmony-arm64": "0.28.1", + "@esbuild/sunos-x64": "0.28.1", + "@esbuild/win32-arm64": "0.28.1", + "@esbuild/win32-ia32": "0.28.1", + "@esbuild/win32-x64": "0.28.1" + } + }, "node_modules/escape-string-regexp": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", @@ -1225,6 +1710,21 @@ "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", "license": "MIT" }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/hast-util-to-jsx-runtime": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.6.tgz", @@ -2664,6 +3164,25 @@ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, + "node_modules/tsx": { + "version": "4.23.1", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.1.tgz", + "integrity": "sha512-GQHnkIfxyx1wYCOS/wonik5MVRZU9hi1TEZmzGZSCJB1y9YgoZ8H6itNE/u4suE+yLmOzuE4E5S4TZ/ZX2wcWQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.28.0" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", diff --git a/services/hackbot-ui/package.json b/services/hackbot-ui/package.json index 0404581ad8..cdb3fbd5c0 100644 --- a/services/hackbot-ui/package.json +++ b/services/hackbot-ui/package.json @@ -7,7 +7,8 @@ "dev": "next dev -p 3000", "build": "next build", "start": "next start -p 3000", - "lint": "next lint" + "lint": "next lint", + "test": "node --import tsx --test \"lib/**/*.test.ts\"" }, "dependencies": { "better-auth": "^1.6.0", @@ -22,6 +23,7 @@ "@types/node": "^22.10.0", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", + "tsx": "^4.23.1", "typescript": "^5.7.0" }, "overrides": { diff --git a/services/hackbot-ui/tsconfig.json b/services/hackbot-ui/tsconfig.json index 8c3a42db95..d6e036d90a 100644 --- a/services/hackbot-ui/tsconfig.json +++ b/services/hackbot-ui/tsconfig.json @@ -9,6 +9,7 @@ "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", + "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", From 8bcd47e7668e1c639ff8a8c762580407852d6fce Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 28 Jul 2026 13:57:17 +0200 Subject: [PATCH 2/3] hackbot-ui: run the unit tests in CI Add a hackbot_ui_tests_task Taskcluster task (node:lts, npm ci && npm test) and gate the PyPI-release and docker-push tasks on it. --- .taskcluster.yml | 20 +++++++++++++++++++ .../hackbot-ui/components/TriggerForm.tsx | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.taskcluster.yml b/.taskcluster.yml index 3c01808158..24e57c8434 100644 --- a/.taskcluster.yml +++ b/.taskcluster.yml @@ -263,6 +263,24 @@ tasks: name: bugbug ui build description: bugbug ui build + - $mergeDeep: + - { $eval: default_task_definition } + - taskId: { $eval: as_slugid("hackbot_ui_tests_task") } + payload: + image: node:lts + command: + - "/bin/sh" + - "-cxe" + - "git clone --quiet ${repository} /bugbug && + cd /bugbug && + git -c advice.detachedHead=false checkout ${head_rev} && + cd services/hackbot-ui && + npm ci --no-progress && + npm test" + metadata: + name: bugbug hackbot-ui tests + description: bugbug hackbot-ui tests + - $if: 'tasks_for == "github-push" && head_branch[:10] == "refs/tags/"' then: $mergeDeep: @@ -273,6 +291,7 @@ tasks: - { $eval: as_slugid("http_tests_task") } - { $eval: as_slugid("libs_tests_task") } - { $eval: as_slugid("frontend_build") } + - { $eval: as_slugid("hackbot_ui_tests_task") } - { $eval: as_slugid("packaging_test_task") } - { $eval: as_slugid("version_check_task") } - { $eval: as_slugid("integration_test") } @@ -305,6 +324,7 @@ tasks: - { $eval: as_slugid("http_tests_task") } - { $eval: as_slugid("libs_tests_task") } - { $eval: as_slugid("frontend_build") } + - { $eval: as_slugid("hackbot_ui_tests_task") } - { $eval: as_slugid("packaging_test_task") } scopes: - secrets:get:project/bugbug/deploy diff --git a/services/hackbot-ui/components/TriggerForm.tsx b/services/hackbot-ui/components/TriggerForm.tsx index 645385e712..0445c88c08 100644 --- a/services/hackbot-ui/components/TriggerForm.tsx +++ b/services/hackbot-ui/components/TriggerForm.tsx @@ -116,7 +116,9 @@ export function TriggerForm() { inputs.bug_id = parsedBugId; } else { if (!hasBugId && !hasBugData) { - setError("Provide a Bugzilla bug ID (or bug URL) or paste report text."); + setError( + "Provide a Bugzilla bug ID (or bug URL) or paste report text." + ); return; } if (hasBugId) inputs.bug_id = parsedBugId; From fa70b1ecd8a3ce8fff337dde99e9f05d70e5f790 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 28 Jul 2026 14:13:09 +0200 Subject: [PATCH 3/3] hackbot-ui: only accept URLs on known Bugzilla hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses review feedback: parseBugId() accepted any http(s) URL with a numeric id parameter, and normalized protocol-relative URLs into "https:////…", which dropped the hostname. Strip leading slashes before parsing and check the hostname against a Bugzilla allowlist. --- services/hackbot-ui/lib/bugzilla.test.ts | 23 +++++++++++++++++++++++ services/hackbot-ui/lib/bugzilla.ts | 16 ++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/services/hackbot-ui/lib/bugzilla.test.ts b/services/hackbot-ui/lib/bugzilla.test.ts index 6c65d77173..a932777069 100644 --- a/services/hackbot-ui/lib/bugzilla.test.ts +++ b/services/hackbot-ui/lib/bugzilla.test.ts @@ -41,6 +41,29 @@ test("accepts the short bugzilla.mozilla.org/ form", () => { assert.equal(parseBugId("bugzilla.mozilla.org/2058177/"), 2058177); }); +test("accepts the staging Bugzilla hosts", () => { + assert.equal( + parseBugId("https://bugzilla.allizom.org/show_bug.cgi?id=2058177"), + 2058177 + ); + assert.equal( + parseBugId("https://BUGZILLA-DEV.allizom.org/show_bug.cgi?id=2058177"), + 2058177 + ); +}); + +test("rejects a non-Bugzilla host carrying an id parameter", () => { + for (const value of [ + "https://example.com/?id=2058177", + "https://example.com/show_bug.cgi?id=2058177", + "https://bugzilla.mozilla.org.evil.example/show_bug.cgi?id=2058177", + "https://example.com/2058177", + "//example.com/show_bug.cgi?id=2058177", + ]) { + assert.equal(parseBugId(value), null, `expected null for ${value}`); + } +}); + test("rejects input without a usable bug ID", () => { for (const value of [ "", diff --git a/services/hackbot-ui/lib/bugzilla.ts b/services/hackbot-ui/lib/bugzilla.ts index a6377e5c4e..70ec907eda 100644 --- a/services/hackbot-ui/lib/bugzilla.ts +++ b/services/hackbot-ui/lib/bugzilla.ts @@ -1,3 +1,9 @@ +const BUGZILLA_HOSTS = [ + "bugzilla.mozilla.org", + "bugzilla.allizom.org", + "bugzilla-dev.allizom.org", +]; + /** * Extract a bug ID from user input: either a bare ID ("1846789") or a Bugzilla * URL ("https://bugzilla.mozilla.org/show_bug.cgi?id=1846789"). @@ -8,13 +14,19 @@ export function parseBugId(value: string): number | null { if (!trimmed) return null; let candidate = trimmed; - if (/^(https?:)?\/\//i.test(trimmed) || /^bugzilla\./i.test(trimmed)) { + if (trimmed.includes("/")) { + // Accept URLs with no scheme ("bugzilla.mozilla.org/…") and + // protocol-relative ones ("//bugzilla.mozilla.org/…") as well. + const withScheme = /^https?:\/\//i.test(trimmed) + ? trimmed + : `https://${trimmed.replace(/^\/+/, "")}`; let url: URL; try { - url = new URL(trimmed.startsWith("http") ? trimmed : `https://${trimmed}`); + url = new URL(withScheme); } catch { return null; } + if (!BUGZILLA_HOSTS.includes(url.hostname.toLowerCase())) return null; // show_bug.cgi?id=123, or the short form bugzilla.mozilla.org/123 candidate = url.searchParams.get("id") ?? url.pathname.replace(/^\/+|\/+$/g, "");