Skip to content

Commit e26be70

Browse files
authored
har -> corpus (#54)
2 parents 9195392 + a72dd03 commit e26be70

File tree

20 files changed

+2473
-623
lines changed

20 files changed

+2473
-623
lines changed

.claude/agents/corpus-fixer.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: corpus-fixer
3+
description: Use this agent when you need to fix or improve the detection logic for a specific Gitcasso corpus by testing changes in the corpus:view development environment. Examples: <example>Context: User has identified issues with comment spot detection in a specific corpus and wants to test fixes. user: 'The comment detection is missing some spots in corpus ABC123, can you help fix the enhancer logic?' assistant: 'I'll use the corpus-fixer agent to investigate and fix the detection issues in that corpus.' <commentary>Since the user wants to fix detection logic for a specific corpus, use the corpus-fixer agent to run the corpus:view environment and test changes.</commentary></example> <example>Context: User wants to validate that recent changes to an enhancer are working correctly. user: 'I made some changes to the GitHub enhancer, can you test it against corpus XYZ789?' assistant: 'Let me use the corpus-fixer agent to test your enhancer changes against that specific corpus.' <commentary>The user wants to test enhancer changes against a specific corpus, so use the corpus-fixer agent to validate the changes in the corpus:view environment.</commentary></example>
4+
model: inherit
5+
---
6+
7+
You are an expert Gitcasso corpus debugging specialist with deep knowledge of browser extension development. You operate exclusively within the `browser-extension` directory and specialize in using the corpus:view development environment to diagnose and fix detection logic issues.
8+
9+
Your primary workflow:
10+
11+
1. **Environment Setup**: Always start by reading the documentation at the top of the `corpus-view.ts` file to understand the dev environment.
12+
13+
2. **Launch Development Environment**: Execute `pnpm corpus:view` to bring up the corpus:view development environment. Ensure the environment starts successfully before proceeding.
14+
15+
3. **Browser Navigation**: Use the Playwright MCP to interact with the development environment. Navigate to the specific Gitcasso corpus that needs investigation or fixing.
16+
17+
4. **Code Synchronization**: Always click the button with id `gitcasso-rebuild-btn` to ensure you're testing against the latest code changes. Wait for the rebuild to complete before analyzing results.
18+
19+
5. **Detection Analysis**: Examine the detected spots in the `gitcasso-comment-spots` element. Analyze what spots are being detected, what might be missing, and identify patterns in the detection logic that need improvement.
20+
21+
6. **Enhancer Modification**: Based on your analysis, make targeted changes to the specific enhancer's detection logic. Focus on:
22+
- Improving selector accuracy
23+
- Handling edge cases in the DOM structure
24+
- Optimizing detection algorithms for the specific site pattern
25+
- Ensuring compatibility with dynamic content loading
26+
27+
7. **Iterative Testing**: After making changes, rebuild and test again to validate improvements. Continue this cycle until the detection logic works correctly for the target corpus.
28+
29+
8. **Documentation**: Clearly explain what issues you found, what changes you made, and why those changes improve the detection logic.
30+
31+
Key principles:
32+
- Always work incrementally - make small, targeted changes and test frequently
33+
- Focus on the specific corpus mentioned by the user unless told otherwise
34+
- Pay attention to browser console errors and network issues that might affect detection
35+
- Consider how your changes might impact other sites or corpus entries
36+
- Be methodical in your debugging approach - document what you try and what results you observe
37+
- Understand that corpus can be either HAR files (for initial page loads) or HTML snapshots (for post-interaction states)
38+
39+
You have expertise in CSS selectors, DOM manipulation, JavaScript debugging, and understanding how different websites structure their comment systems. Use this knowledge to create robust, reliable detection logic that works across various edge cases.

.claude/agents/har-fixer.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

.claude/commands/finish-wc.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
Run `git status` to see the changes in the working copy. Complete whatever tasks are necessary to complete this change. Make sure that `pnpm -r precommit` succeeds. Don't fix `precommit` just be reverting the changes, the goal is to complete the change.
1+
- run `git status` to see the changes in the working copy
2+
- **figure out the intent of the change**
3+
- complete whatever tasks are necessary to complete this change
4+
- make sure that `pnpm precommit` succeeds when you are done
5+
- don't fix `precommit` by reverting the changes, it is more important to complete the initial change

browser-extension/README.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,42 @@ When the `textarea` gets removed from the page, the `TextareaRegistry` is notifi
6969
## Testing
7070

7171
- `npm run playground` gives you a test environment where you can tinker with the popup with various test data, supports hot reload
72-
- `npm run har:view` gives you recordings of various web pages which you can see with and without enhancement by the browser extension
73-
74-
### Recording new HAR files
75-
76-
- the har recordings live in `tests/har`, they are complete recordings of the network requests of a single page load
77-
- you can add or change URLs in `tests/har-index.ts`
78-
- `npx playwright codegen https://github.com/login --save-storage=playwright/.auth/gh.json` will store new auth tokens
79-
- login manually, then close the browser
80-
- ***these cookies are very sensitive! we only run this script using a test account that has no permissions or memberships to anything, recommend you do the same!***
81-
- `pnpm run har:record` this records new snapshots using those auth tokens (it needs args, run it with no args for docs)
82-
- DO NOT COMMIT AND PUSH NEW OR CHANGED `har` files!
83-
- we try to sanitize these (see `har-record.ts` for details) but there may be important PII in them
84-
- if you need new HAR files for something, let us know and we will generate them ourselves using a dummy account
85-
- IF YOUR PR CHANGES OR ADDS HAR FILES WE WILL CLOSE IT. Ask for HAR files and we'll be happy to generate clean ones you can test against.
72+
- `npm run corpus:view` gives you recordings of various web pages which you can see with and without enhancement by the browser extension
73+
74+
### Test Corpus
75+
76+
We maintain a corpus of test pages in two formats for testing the browser extension:
77+
78+
#### HAR Corpus (Automated)
79+
80+
- For testing initial page loads and network requests
81+
- HAR recordings live in `tests/corpus/har/`, complete recordings of the network requests of a single page load
82+
- You can add or change URLs in `tests/corpus/_corpus-index.ts`
83+
- **Recording new HAR files:**
84+
- `npx playwright codegen https://github.com/login --save-storage=playwright/.auth/gh.json` will store new auth tokens
85+
- login manually, then close the browser
86+
- ***these cookies are very sensitive! we only run this script using a test account that has no permissions or memberships to anything, recommend you do the same!***
87+
- `pnpm run corpus:record:har` records new HAR files using those auth tokens (it needs args, run it with no args for docs)
88+
- DO NOT COMMIT AND PUSH NEW OR CHANGED HAR files!
89+
- we try to sanitize these (see `har-record.ts` for details) but there may be important PII in them
90+
- if you need new HAR files for something, let us know and we will generate them ourselves using a dummy account
91+
- IF YOUR PR CHANGES OR ADDS HAR FILES WE WILL CLOSE IT. Ask for HAR files and we'll be happy to generate clean ones you can test against.
92+
93+
#### HTML Corpus (Manual)
94+
95+
- For testing post-interaction states (e.g., expanded textareas, modal dialogs, dynamic content)
96+
- HTML snapshots live in `tests/corpus/html/`, manually captured using SingleFile browser extension
97+
- All assets are inlined in a single HTML file by SingleFile
98+
- **Creating new HTML corpus files:**
99+
1. Navigate to the desired page state (click buttons, expand textareas, etc.)
100+
2. Use SingleFile browser extension to save the complete page
101+
3. Save the `.html` file to `tests/corpus/html/` with a descriptive name
102+
4. Add an entry to `tests/corpus/_corpus-index.ts` with `type: 'html'` and a description of the captured state
103+
104+
#### Viewing Corpus Files
105+
106+
- Run `pnpm run corpus:view` to start the test server at http://localhost:3001
107+
- Select any corpus file to view in two modes:
108+
- **Clean**: Original page without extension
109+
- **Gitcasso**: Page with extension injected for testing
110+
- Both HAR and HTML corpus types are supported

browser-extension/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
"test": "vitest run",
6363
"playground": "vite --config vite.playground.config.ts",
6464
"playground:build": "vite build --config vite.playground.config.ts",
65-
"har:record": "tsx tests/har-record.ts",
66-
"har:view": "tsx tests/har-view.ts"
65+
"corpus:record:har": "tsx tests/har-record.ts",
66+
"corpus:view": "tsx tests/corpus-view.ts"
6767
},
6868
"type": "module",
6969
"version": "0.0.1"

browser-extension/src/entrypoints/content.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ function enhanceMaybe(textarea: HTMLTextAreaElement) {
9999
return
100100
}
101101

102-
logger.debug('activating textarea {}', textarea)
103102
injectStyles()
104-
105103
try {
106104
const location = detectLocation()
107105
logger.debug('[gitcasso] Calling tryToEnhance with location:', location)

browser-extension/src/lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export type LogLevel = (typeof LOG_LEVELS)[number]
99
export const CONFIG = {
1010
ADDED_OVERTYPE_CLASS: 'gitcasso-overtype',
1111
EXTENSION_NAME: 'gitcasso', // decorates logs
12-
LOG_LEVEL: 'INFO' satisfies LogLevel,
12+
LOG_LEVEL: 'DEBUG' satisfies LogLevel,
1313
MODE: 'PROD' satisfies ModeType,
1414
} as const

browser-extension/tests/har-fixture.ts renamed to browser-extension/tests/corpus-fixture.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ vi.mock('overtype', () => {
3030
})
3131

3232
import { describe as baseDescribe, test as baseTest, expect } from 'vitest'
33-
import type { PAGES } from './har/_har-index'
34-
import { cleanupDOM, setupHarDOM } from './har-fixture-utils'
33+
import type { CORPUS } from './corpus/_corpus-index'
34+
import { cleanupDOM, setupDOM } from './corpus-utils'
3535

3636
export const describe = baseDescribe
3737

3838
// Re-export expect from vitest
3939
export { expect }
4040

41-
// Fluent interface for HAR-based tests
42-
export function usingHar(harKey: keyof typeof PAGES) {
41+
// Fluent interface for any corpus type (HAR or HTML)
42+
export function forCorpus(corpusKey: keyof typeof CORPUS) {
4343
return {
4444
it: (name: string, fn: () => void | Promise<void>) => {
45-
return baseTest(`${harKey}:${name}`, async () => {
46-
// Setup HAR DOM before test
47-
await setupHarDOM(harKey)
45+
return baseTest(`${String(corpusKey)}:${name}`, async () => {
46+
// Setup DOM for any corpus type (delegates to HAR or HTML based on type)
47+
await setupDOM(corpusKey)
4848

4949
try {
5050
return await fn()

browser-extension/tests/har-fixture-utils.ts renamed to browser-extension/tests/corpus-utils.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path'
33
import { fileURLToPath } from 'node:url'
44
import type { Har as HarFile } from 'har-format'
55
import { parseHTML } from 'linkedom'
6-
import { PAGES } from './har/_har-index'
6+
import { CORPUS } from './corpus/_corpus-index'
77

88
const __dirname = path.dirname(fileURLToPath(import.meta.url))
99

@@ -32,21 +32,51 @@ export interface TestDOMContext {
3232
let currentDOMInstance: any = null
3333
let originalGlobals: Partial<TestDOMGlobals> = {}
3434

35-
export async function loadHtmlFromHar(key: keyof typeof PAGES): Promise<string> {
36-
const url = PAGES[key]
37-
const harPath = path.join(__dirname, 'har', `${key}.har`)
35+
export async function setupDOM(key: keyof typeof CORPUS): Promise<TestDOMGlobals> {
36+
const entry = CORPUS[key]
37+
if (!entry) {
38+
throw new Error(`Invalid corpus key: ${String(key)}`)
39+
}
40+
41+
let html: string
42+
if (entry.type === 'har') {
43+
html = await loadRootHtmlStringFromHar(key)
44+
} else if (entry.type === 'html') {
45+
html = await loadHtmlStringFromHtml(key)
46+
} else {
47+
throw new Error(`Unsupported corpus type: ${entry.type}`)
48+
}
49+
const domGlobals = createDOMFromString(html, entry.url)
50+
setupDOMFromHar(domGlobals)
51+
return domGlobals
52+
}
53+
54+
async function loadRootHtmlStringFromHar(key: keyof typeof CORPUS): Promise<string> {
55+
const entry = CORPUS[key]
56+
if (!entry || entry.type !== 'har') {
57+
throw new Error(`Invalid HAR corpus key: ${String(key)}`)
58+
}
59+
const url = entry.url
60+
const harPath = path.join(__dirname, 'corpus', `${String(key)}.har`)
3861
const harContent = await fs.readFile(harPath, 'utf-8')
3962
const harData: HarFile = JSON.parse(harContent)
4063
const mainEntry = harData.log.entries.find((entry) => entry.request.url === url)
41-
4264
if (!mainEntry) {
4365
throw new Error(`No entry found for URL: ${url} in HAR file: ${harPath}`)
4466
}
67+
return mainEntry.response.content.text!
68+
}
4569

46-
return mainEntry.response.content.text || ''
70+
async function loadHtmlStringFromHtml(key: keyof typeof CORPUS): Promise<string> {
71+
const entry = CORPUS[key]
72+
if (!entry || entry.type !== 'html') {
73+
throw new Error(`Invalid HTML corpus key: ${String(key)}`)
74+
}
75+
const htmlPath = path.join(__dirname, 'corpus', `${String(key)}.html`)
76+
return await fs.readFile(htmlPath, 'utf-8')
4777
}
4878

49-
export function createDOMFromHar(html: string, url: string): TestDOMGlobals {
79+
function createDOMFromString(html: string, url: string): TestDOMGlobals {
5080
const dom = parseHTML(html)
5181

5282
return {
@@ -68,7 +98,7 @@ export function createDOMFromHar(html: string, url: string): TestDOMGlobals {
6898
}
6999
}
70100

71-
export function setupDOMFromHar(domGlobals: TestDOMGlobals): void {
101+
function setupDOMFromHar(domGlobals: TestDOMGlobals): void {
72102
// Store original globals for cleanup
73103
originalGlobals = {
74104
Document: (globalThis as any).Document,
@@ -100,11 +130,3 @@ export function cleanupDOM(): void {
100130
originalGlobals = {}
101131
}
102132
}
103-
104-
export async function setupHarDOM(key: keyof typeof PAGES): Promise<TestDOMGlobals> {
105-
const html = await loadHtmlFromHar(key)
106-
const url = PAGES[key]
107-
const domGlobals = createDOMFromHar(html, url)
108-
setupDOMFromHar(domGlobals)
109-
return domGlobals
110-
}

0 commit comments

Comments
 (0)