code-yeongyu/oh-my-openagent / packages/shared-skills/skills/ulw-research
ulw-research
UnverifiedRuns maximum-saturation research with a cooperating team, claim-graph gating, and a cited, QA'd deliverable. Use when the user explicitly asks for research or a deep investigation, including any 'ulw' research wording.
scripts/layout-probe.test.ts
View on GitHubimport { describe, expect, test } from "bun:test"
import { parseHtml, selectorPath } from "./html-lite.mjs"
import { buildProbeSource, PATH_FUNCTION_SOURCE, PROBE_VERSION, ProbeError } from "./layout-probe.mjs"
// A minimal element adapter over the html-lite tree: exactly the DOM surface the path rule reads.
function adapt(node, parentAdapter, cache) {
if (cache.has(node)) return cache.get(node)
const el = { tagName: node.tag.toUpperCase(), id: node.attrs.id ?? "", parentElement: parentAdapter, children: [] }
cache.set(node, el)
el.children = node.children.filter((c) => c.tag !== "#text").map((c) => adapt(c, el, cache))
return el
}
function pathRule() {
return new Function(`${PATH_FUNCTION_SOURCE}; return ulwSelectorPath;`)()
}
const FIXTURE = `<!doctype html><html><head><style>p{}</style></head><body>
<main id="top"><section><h2>A</h2><p>one</p><p>two</p><figure class="fig"><img src="a.png"><figcaption>c</figcaption></figure></section>
<section id="results"><h2>B</h2><p>x</p><figure><svg width="300"><text>t</text></svg></figure><figure><img src="b.png"></figure></section>
<section><div id="dup"></div><div id="dup"><p>y</p></div></section></main></body></html>`
describe("PATH_FUNCTION_SOURCE", () => {
test("#given the html-lite tree of a fixture #when the in-page path rule runs on an adapter of every element #then it equals html-lite selectorPath", () => {
// given
const doc = parseHtml(FIXTURE)
const ids = new Map()
const cache = new Map()
const elements = []
const walk = (node, parentAdapter) => {
if (node.tag === "#text") return
const el = adapt(node, parentAdapter, cache)
if (node.tag !== "#root" && node.parent) elements.push([node, el])
if (el.id) ids.set(el.id, (ids.get(el.id) ?? 0) + 1)
for (const child of node.children) walk(child, el)
}
walk(doc, null)
const rule = pathRule()
// when
const mismatches = elements
.filter(([node]) => node.tag !== "html" && node.tag !== "head" && node.tag !== "#root")
.map(([node, el]) => [selectorPath(node), rule(el, (id) => ids.get(id) ?? 0)])
.filter(([expected, actual]) => expected !== actual)
// then
expect(elements.length).toBeGreaterThan(10)
expect(mismatches).toEqual([])
})
test("#given a duplicated id #when a descendant path is built #then the duplicate is not used as an anchor", () => {
const doc = parseHtml(FIXTURE)
const p = []
const find = (n) => {
if (n.tag === "p" && n.parent?.attrs.id === "dup") p.push(n)
n.children.forEach(find)
}
find(doc)
expect(selectorPath(p[0])).toBe("#top > section:nth-of-type(3) > div:nth-of-type(2) > p")
})
})
describe("buildProbeSource", () => {
test("#given defaults #when built #then it is one async IIFE expression that parses and carries the version, cap, and image wait", () => {
const src = buildProbeSource()
expect(src).toMatch(/^\(async \(\) => \{[\s\S]*\}\)\(\)\s*$/)
expect(src.includes('img.loading = "eager"')).toBe(true)
expect(() => new Function(`return ${src}`)).not.toThrow()
expect(src.includes("const CAP = 400;")).toBe(true)
expect(src.includes(`probe_version: ${PROBE_VERSION}`)).toBe(true)
})
test("#given cap 50 and a custom root #when built #then both are embedded as literals", () => {
const src = buildProbeSource({ cap: 50, root: "article.report" })
expect(src.includes("const CAP = 50;")).toBe(true)
expect(src.includes('document.querySelector("article.report")')).toBe(true)
})
test("#given cap 0 or a fractional cap #when built #then a typed ProbeError is thrown", () => {
expect(() => buildProbeSource({ cap: 0 })).toThrow(ProbeError)
expect(() => buildProbeSource({ cap: 1.5 })).toThrow(ProbeError)
})
test("#given an empty root #when built #then a typed ProbeError is thrown", () => {
expect(() => buildProbeSource({ root: "" })).toThrow(ProbeError)
expect(() => buildProbeSource({ root: " " })).toThrow(ProbeError)
})
test("#given a root containing a double quote #when built #then the source still parses", () => {
const src = buildProbeSource({ root: 'main[data-x="1"]' })
expect(() => new Function(`return ${src}`)).not.toThrow()
})
})
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |