GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add real-GitHub fixture suite, modern diffstat parser, Firefox lint · sudo-vaibhav/pr-diff-plus@86182cc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • README.md
  • extension/src
    • content.js
    • lib.js
  • package-lock.json
  • package.json
  • playwright.config.js
  • tests
    • e2e
      • extension.spec.js
      • harness.js
      • realgithub.spec.js
    • fixtures
      • _capture.mjs
      • real-github-pr.html
    • unit
      • lib.test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ playwright-report/
44
.DS_Store
55
*.log
66
/tmp/
7+
web-ext-artifacts/
8+
.gstack/
Collapse file

‎README.md‎

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 numberDiff line numberDiff line change
@@ -56,17 +56,39 @@ tests/
5656

5757
## Tests
5858

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-
6159
```bash
6260
npm install
6361
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
6766
```
6867

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.
7092

7193
## Why complexity scoring matters
7294

Collapse file

‎extension/src/content.js‎

Copy file name to clipboardExpand all lines: extension/src/content.js
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const LIB = globalThis.PRDP_LIB ?? (typeof window !== 'undefined' ? window.PRDP_LIB : undefined);
44
if (!LIB) { console.error('[PRDP] lib.js not loaded'); return; }
55
const {
6-
isGenerated, isTest, complexityScore, parseStats,
6+
isGenerated, isTest, complexityScore, parseStats, parseDiffstat,
77
getPRKeyFromPath, isFilesPath,
88
buildTree, flattenChains
99
} = LIB;
@@ -66,17 +66,25 @@
6666
.find(a => /^diff-[a-f0-9]+$/.test(a.id)) || (/^diff-[a-f0-9]+$/.test(el.id) ? el : null);
6767
const anchor = anchorEl?.id || el.id || '';
6868

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;
6972
const titleEl = el.querySelector('.file-info a[title], a.Link--primary[title], [data-path]');
7073
const path =
74+
wrapper.getAttribute?.('data-file-path') ||
7175
titleEl?.getAttribute('title') ||
7276
titleEl?.getAttribute('data-path') ||
7377
titleEl?.textContent?.trim() ||
7478
el.querySelector('.file-info')?.textContent?.trim()?.split('\n')[0] ||
7579
`file-${out.length}`;
7680

7781
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+
});
8088

8189
out.push({
8290
el,
Collapse file

‎extension/src/lib.js‎

Copy file name to clipboardExpand all lines: extension/src/lib.js
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,36 @@ function prdp_parseStats(text) {
5858
};
5959
}
6060

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+
6191
function prdp_getPRKeyFromPath(pathname) {
6292
var m = pathname.match(PRDP_PR_PATH_RE);
6393
return m ? (m[1] + '/' + m[2] + '#' + m[3]) : null;
@@ -124,6 +154,7 @@ var PRDP_LIB = {
124154
fileWeight: prdp_fileWeight,
125155
complexityScore: prdp_complexityScore,
126156
parseStats: prdp_parseStats,
157+
parseDiffstat: prdp_parseDiffstat,
127158
getPRKeyFromPath: prdp_getPRKeyFromPath,
128159
isFilesPath: prdp_isFilesPath,
129160
buildTree: prdp_buildTree,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.