GeezerVison is showing github.com — Add real-GitHub fixture suite, modern diffstat parser, Firefox lint · sudo-vaibhav/pr-diff-plus@86182cc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .gitignore +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,3 +4,5 @@ playwright-report/ | 4 | 4 | .DS_Store | 5 | 5 | *.log | 6 | 6 | /tmp/ | | 7 | +web-ext-artifacts/ | | 8 | +.gstack/ |
Collapse file Copy file name to clipboardExpand all lines: README.md +28-6Lines changed: 28 additions & 6 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -56,17 +56,39 @@ tests/ | 56 | 56 |
| 57 | 57 | ## Tests | 58 | 58 |
| 59 | | -Pure-function tests run in milliseconds. End-to-end tests load the real extension into Playwright's bundled Chromium against a local fixture (deterministic — no GitHub markup drift, no auth needed). | 60 | | - | 61 | 59 | ```bash | 62 | 60 | npm install | 63 | 61 | npx playwright install chromium | 64 | | -npm test # unit (vitest) | 65 | | -npm run test:e2e # e2e (playwright) | 66 | | -npm run test:all # both | | 62 | +npm test # unit (vitest) — 68 tests, ~400ms | | 63 | +npm run test:e2e # e2e (playwright) — 29 tests on Chromium, ~16s | | 64 | +npm run lint:firefox # web-ext lint — Firefox compatibility check | | 65 | +npm run test:all # all of the above | 67 | 66 | ``` | 68 | 67 |
| 69 | | -The e2e harness rewrites `manifest.json` to match `<all_urls>` and serves the fixture via a local Node http server, then launches Chromium with `--load-extension=`. | | 68 | +### Unit (`tests/unit/lib.test.js`) | | 69 | +Pure-function tests against `extension/src/lib.js`. Loaded into a Node `vm` sandbox so the same code paths the browser runs are exercised. Covers: path classification (generated / test / docs), file weighting, complexity scoring, the multi-format diffstat parser (legacy aria-label, +/- text, modern block-ratio estimation), URL parsing, tree building, and chain flattening. | | 70 | + | | 71 | +### E2E (`tests/e2e/`) | | 72 | +Two suites, both load the real extension into Playwright's bundled Chromium via `--load-extension=`: | | 73 | + | | 74 | +- **`extension.spec.js`** — synthetic fixture (`tests/fixtures/pr-page.html`). Deterministic, fast, exercises every UI path (sidebar, tree/flat toggle, filter, sort, keyboard shortcuts, approval, hide-approved, auto-collapse, persistence). | | 75 | +- **`realgithub.spec.js`** — real GitHub PR markup snapshot (`tests/fixtures/real-github-pr.html`). Validates the extension still parses current GitHub layout (`copilot-diff-entry`, `data-file-path`, modern block-based diffstat). Re-capture when GitHub ships layout changes: | | 76 | + | | 77 | + ```bash | | 78 | + npm run fixture:capture # default: facebook/react#28000 | | 79 | + node tests/fixtures/_capture.mjs https://github.com/owner/repo/pull/N/files # any public PR | | 80 | + ``` | | 81 | + | | 82 | +The harness rewrites `manifest.json` to match `<all_urls>`, serves fixtures via a local Node http server at GitHub-shaped paths (`/owner/repo/pull/N/files`), and gives each test a unique PR number so `chrome.storage.local` keys don't collide. | | 83 | + | | 84 | +### Firefox | | 85 | + | | 86 | +Playwright's bundled Firefox doesn't honor profile-side install of unsigned extensions, so the e2e suite runs Chromium-only. For Firefox we use: | | 87 | + | | 88 | +- **`web-ext lint`** in CI (`npm run lint:firefox`) — catches MV3 manifest issues, unsupported APIs, and unsafe patterns | | 89 | +- **Manual smoke** — `about:debugging` → This Firefox → Load Temporary Add-on → pick `extension/manifest.json` | | 90 | + | | 91 | +The harness in `tests/e2e/harness.js` retains the Firefox launch path (unpacked install into profile) for when upstream Playwright ships first-class WebExtension support. | 70 | 92 |
| 71 | 93 | ## Why complexity scoring matters | 72 | 94 |
| |
Collapse file Copy file name to clipboardExpand all lines: extension/src/content.js +11-3Lines changed: 11 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const LIB = globalThis.PRDP_LIB ?? (typeof window !== 'undefined' ? window.PRDP_LIB : undefined); | 4 | 4 | if (!LIB) { console.error('[PRDP] lib.js not loaded'); return; } | 5 | 5 | const { | 6 | | - isGenerated, isTest, complexityScore, parseStats, | | 6 | + isGenerated, isTest, complexityScore, parseStats, parseDiffstat, | 7 | 7 | getPRKeyFromPath, isFilesPath, | 8 | 8 | buildTree, flattenChains | 9 | 9 | } = LIB; | | 66 | 66 | .find(a => /^diff-[a-f0-9]+$/.test(a.id)) || (/^diff-[a-f0-9]+$/.test(el.id) ? el : null); | 67 | 67 | const anchor = anchorEl?.id || el.id || ''; | 68 | 68 |
| | 69 | + // Path: prefer data-file-path on copilot-diff-entry (modern GitHub), | | 70 | + // then title attribute on file-info link, then anchor href, then text. | | 71 | + const wrapper = raw.tagName === 'COPILOT-DIFF-ENTRY' ? raw : el; | 69 | 72 | const titleEl = el.querySelector('.file-info a[title], a.Link--primary[title], [data-path]'); | 70 | 73 | const path = | | 74 | + wrapper.getAttribute?.('data-file-path') || | 71 | 75 | titleEl?.getAttribute('title') || | 72 | 76 | titleEl?.getAttribute('data-path') || | 73 | 77 | titleEl?.textContent?.trim() || | 74 | 78 | el.querySelector('.file-info')?.textContent?.trim()?.split('\n')[0] || | 75 | 79 | `file-${out.length}`; | 76 | 80 |
| 77 | 81 | const statsEl = el.querySelector('.diffstat, [data-testid="file-diffstat"]'); | 78 | | - const statsRaw = statsEl?.getAttribute('aria-label') || statsEl?.textContent || ''; | 79 | | - const { added, removed } = parseStats(statsRaw); | | 82 | + const { added, removed } = parseDiffstat({ | | 83 | + text: statsEl?.textContent || '', | | 84 | + ariaLabel: statsEl?.getAttribute('aria-label') || '', | | 85 | + addedBlocks: el.querySelectorAll('.diffstat-block-added').length, | | 86 | + deletedBlocks: el.querySelectorAll('.diffstat-block-deleted').length | | 87 | + }); | 80 | 88 |
| 81 | 89 | out.push({ | 82 | 90 | el, | |
Collapse file Copy file name to clipboardExpand all lines: extension/src/lib.js +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,6 +58,36 @@ function prdp_parseStats(text) { | 58 | 58 | }; | 59 | 59 | } | 60 | 60 |
| | 61 | +// Modern GitHub renders the diffstat as `<span class="diffstat">10 <block/><block/>…</span>` | | 62 | +// where the leading number is total churn and the colored blocks visualize | | 63 | +// the added:deleted:neutral ratio. There are no per-file +/- text numbers in | | 64 | +// the DOM. Estimate by ratio when blocks present, fall back to text parser. | | 65 | +function prdp_parseDiffstat(input) { | | 66 | + var text = (input && input.text) || ''; | | 67 | + var addedBlocks = (input && input.addedBlocks) || 0; | | 68 | + var deletedBlocks = (input && input.deletedBlocks) || 0; | | 69 | + var ariaLabel = (input && input.ariaLabel) || ''; | | 70 | + | | 71 | + // Format A: aria-label text like "10 additions, 3 deletions" | | 72 | + var fromAria = prdp_parseStats(ariaLabel); | | 73 | + if (fromAria.added || fromAria.removed) return fromAria; | | 74 | + | | 75 | + // Format B: explicit "+N -N" or "N additions" text | | 76 | + var fromText = prdp_parseStats(text); | | 77 | + if (fromText.added || fromText.removed) return fromText; | | 78 | + | | 79 | + // Format C: leading total + colored block ratio | | 80 | + var totalM = text.match(/^\s*(\d+)/); | | 81 | + var total = totalM ? parseInt(totalM[1], 10) : 0; | | 82 | + if (total > 0 && (addedBlocks + deletedBlocks) > 0) { | | 83 | + var added = Math.round(total * addedBlocks / (addedBlocks + deletedBlocks)); | | 84 | + var removed = total - added; | | 85 | + return { added: added, removed: removed }; | | 86 | + } | | 87 | + | | 88 | + return { added: 0, removed: 0 }; | | 89 | +} | | 90 | + | 61 | 91 | function prdp_getPRKeyFromPath(pathname) { | 62 | 92 | var m = pathname.match(PRDP_PR_PATH_RE); | 63 | 93 | return m ? (m[1] + '/' + m[2] + '#' + m[3]) : null; | @@ -124,6 +154,7 @@ var PRDP_LIB = { | 124 | 154 | fileWeight: prdp_fileWeight, | 125 | 155 | complexityScore: prdp_complexityScore, | 126 | 156 | parseStats: prdp_parseStats, | | 157 | + parseDiffstat: prdp_parseDiffstat, | 127 | 158 | getPRKeyFromPath: prdp_getPRKeyFromPath, | 128 | 159 | isFilesPath: prdp_isFilesPath, | 129 | 160 | buildTree: prdp_buildTree, | |
|