Skip to content

code-yeongyu/oh-my-openagent / packages/shared-skills/skills/ulw-research

ulw-research

Unverified

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

FileKindSize
AGENTS.mdmarkdown9.2 KB
ATTRIBUTION.mdmarkdown2.4 KB
SKILL.mdskill md42.2 KB
references/deliverable-phase.mdmarkdown49.1 KB
references/fact-ledger-grammar.mdmarkdown6.8 KB
references/fact-ledger.mdmarkdown24.4 KB
references/fidelity-claim-kinds.mdmarkdown5.2 KB
references/markdown-blocks.mdmarkdown721 B
references/report-gates.mdmarkdown32.0 KB
references/report-visualization.mdmarkdown15.4 KB
references/research-collection.mdmarkdown26.8 KB
references/research-delivery.mdmarkdown14.3 KB
references/unit-rules.mdmarkdown16.3 KB
scripts/claim-kinds.mjsscript11.2 KB
scripts/claim-kinds.test.tsscript13.5 KB
scripts/claim-prefix.test.tsscript4.9 KB
scripts/claims-index.mjsscript5.3 KB
scripts/claims-index.test.tsscript5.7 KB
scripts/cli-support.mjsscript4.1 KB
scripts/cli-support.test.tsscript4.3 KB
scripts/contracts-validation.test.tsscript3.3 KB
scripts/contracts.mjsscript26.1 KB
scripts/contracts.test.tsscript7.9 KB
scripts/conversion-altered.test.tsscript11.0 KB
scripts/conversion-originals.test.tsscript22.7 KB
scripts/conversion-probe-classes.test.tsscript45.2 KB
scripts/conversion-probe.mjsscript13.5 KB
scripts/conversion-probe.test.tsscript11.6 KB
scripts/copy-returns-fidelity-policy.test.tsscript10.4 KB
scripts/copy-returns-polish.test.tsscript12.1 KB
scripts/copy-returns.test.tsscript10.6 KB
scripts/css-hiding.mjsscript9.1 KB
scripts/css-lite.mjsscript7.6 KB
scripts/css-lite.test.tsscript6.4 KB
scripts/delivery-barrier-meaning.test.tsscript12.3 KB
scripts/delivery-barrier.test.tsscript11.4 KB
scripts/design-spec.mjsscript7.2 KB
scripts/design-spec.test.tsscript6.7 KB
scripts/entities.mjsscript2.5 KB
scripts/entry-guard.mjsscript794 B
scripts/fact-commands-fill.mjsscript6.6 KB
scripts/fact-commands-meaning.mjsscript12.6 KB
scripts/fact-commands-polish.mjsscript10.3 KB
scripts/fact-commands-verify.mjsscript12.6 KB
scripts/fact-commands.mjsscript13.8 KB
scripts/fact-derive-2.test.tsscript7.2 KB
scripts/fact-derive.mjsscript4.9 KB
scripts/fact-derive.test.tsscript10.8 KB
scripts/fact-expr.mjsscript4.5 KB
scripts/fact-fill.mjsscript11.7 KB
scripts/fact-fill.test.tsscript10.7 KB
scripts/fact-ledger-grammar.test.tsscript11.8 KB
scripts/fact-ledger-kinds.mjsscript16.5 KB
scripts/fact-ledger-kinds.test.tsscript9.3 KB
scripts/fact-ledger-legacy.test.tsscript8.9 KB
scripts/fact-ledger-schema.mjsscript11.9 KB
scripts/fact-ledger-schema.test.tsscript1.5 KB
scripts/fact-ledger.mjsscript5.5 KB
scripts/fact-ledger.test.tsscript9.7 KB
scripts/fact-locate.mjsscript12.1 KB
scripts/fact-locate.test.tsscript7.2 KB
scripts/fact-pairs.mjsscript8.3 KB
scripts/fact-pairs.test.tsscript6.6 KB
scripts/fact-recompute.mjsscript4.8 KB
scripts/fact-unit-dimensions-2.test.tsscript8.4 KB
scripts/fact-unit-dimensions.test.tsscript11.9 KB
scripts/fact-unit-rules.test.tsscript8.9 KB
scripts/fidelity-binding.mjsscript6.7 KB
scripts/fidelity-binding.test.tsscript4.0 KB
scripts/fidelity-brief.mjsscript6.4 KB
scripts/fidelity-brief.test.tsscript7.8 KB
scripts/fidelity-claims.mjsscript5.1 KB
scripts/fidelity-csv.mjsscript1.1 KB
scripts/fidelity-lexicon.mjsscript8.1 KB
scripts/fidelity-lexicon.test.tsscript6.0 KB
scripts/fidelity-originals.mjsscript9.9 KB
scripts/fidelity-policy.mjsscript10.1 KB
scripts/fidelity-records.mjsscript13.4 KB
scripts/fidelity-snapshot-readability.mjsscript2.2 KB
scripts/fidelity-sources.mjsscript4.3 KB
scripts/fidelity-state.mjsscript2.1 KB
scripts/fidelity-state.test.tsscript1.7 KB
scripts/fidelity-trace.mjsscript6.1 KB
scripts/fidelity-trace.test.tsscript3.3 KB
scripts/fidelity-value-unit.mjsscript13.3 KB
scripts/fidelity-values.mjsscript16.1 KB
scripts/fidelity-values.test.tsscript15.8 KB
scripts/format-extract-css.mjsscript5.1 KB
scripts/format-extract.mjsscript10.3 KB
scripts/format-extract.test.tsscript11.2 KB
scripts/gates-context.test.tsscript2.6 KB
scripts/gates-fidelity.mjsscript6.3 KB
scripts/gates-fidelity.test.tsscript3.3 KB
scripts/gates-figures.mjsscript9.9 KB
scripts/gates-layout.mjsscript6.6 KB
scripts/gates-layout.test.tsscript12.4 KB
scripts/gates-static-headings.test.tsscript961 B
scripts/gates-static.mjsscript8.1 KB
scripts/gates-static.test.tsscript14.9 KB
scripts/gates-structure.mjsscript4.7 KB
scripts/gates-text.mjsscript7.2 KB
scripts/glossary-vocabulary.test.tsscript1.7 KB
scripts/html-foreign-object.mjsscript2.8 KB
scripts/html-lite.mjsscript9.7 KB
scripts/html-lite.test.tsscript7.9 KB
scripts/html-markup.mjsscript7.0 KB
scripts/html-text-map.mjsscript4.8 KB
scripts/html-text-map.test.tsscript15.2 KB
scripts/layout-probe.mjsscript4.6 KB
scripts/layout-probe.test.tsscript4.2 KB
scripts/lexicon.mjsscript2.6 KB
scripts/lexicon.test.tsscript3.2 KB
scripts/markdown-closers.mjsscript4.9 KB
scripts/md-lite-boundaries.test.tsscript2.2 KB
scripts/md-lite.mjsscript7.8 KB
scripts/md-lite.test.tsscript10.3 KB
scripts/meaning-check.mjsscript9.7 KB
scripts/meaning-check.test.tsscript12.0 KB
scripts/number-grammar.mjsscript2.1 KB
scripts/number-grammar.test.tsscript1.8 KB
scripts/numerals.mjsscript12.0 KB
scripts/numerals.test.tsscript6.1 KB
scripts/outcome-start.mjsscript3.8 KB
scripts/outcome-start.test.tsscript5.0 KB
scripts/outcome.mjsscript10.5 KB
scripts/outcome.test.tsscript12.8 KB
scripts/page-source-locator.test.tsscript11.7 KB
scripts/particles-ko.mjsscript4.8 KB
scripts/particles-ko.test.tsscript4.3 KB
scripts/placeholder.mjsscript9.3 KB
scripts/placeholder.test.tsscript3.8 KB
scripts/polish-apply.mjsscript6.8 KB
scripts/polish-apply.test.tsscript19.7 KB
scripts/polish-diff.mjsscript1.7 KB
scripts/polish-diff.test.tsscript10.1 KB
scripts/polish-markup.test.tsscript14.0 KB
scripts/polish-partial.test.tsscript2.5 KB
scripts/polish-project.mjsscript5.8 KB
scripts/polish-rules.mjsscript9.8 KB
scripts/rational.mjsscript5.2 KB
scripts/rational.test.tsscript1.9 KB
scripts/raw-decode.mjsscript4.5 KB
scripts/raw-locator.mjsscript2.4 KB
scripts/raw-snapshot.test.tsscript7.3 KB
scripts/references-fences.test.tsscript1.2 KB
scripts/repair-tracker.mjsscript7.5 KB
scripts/repair-tracker.test.tsscript10.8 KB
scripts/report-tools-2.test.tsscript16.1 KB
scripts/report-tools-3.test.tsscript9.3 KB
scripts/report-tools-4.test.tsscript10.1 KB
scripts/report-tools-5.test.tsscript14.6 KB
scripts/report-tools-commands.mjsscript12.9 KB
scripts/report-tools.mjsscript2.6 KB
scripts/report-tools.test.tsscript12.1 KB
scripts/sentence-split.mjsscript3.0 KB
scripts/sentence-split.test.tsscript4.5 KB
scripts/snapshot-readability.test.tsscript7.0 KB
scripts/source-commands.mjsscript12.4 KB
scripts/source-integrity.test.tsscript18.1 KB
scripts/source-refresh.mjsscript5.2 KB
scripts/source-snapshot.mjsscript9.9 KB
scripts/source-snapshot.test.tsscript6.3 KB
scripts/source-view.mjsscript5.0 KB
scripts/sources-citation.mjsscript12.1 KB
scripts/sources-citation.test.tsscript14.8 KB
scripts/tests/contracts-support.tsscript3.5 KB
scripts/tests/delivery-barrier-session.tsscript3.3 KB
scripts/tests/derive-clock.tsscript341 B
scripts/tests/fact-derive-support.tsscript1.9 KB
scripts/tests/fact-unit-dimensions-support.tsscript1.5 KB
scripts/tests/fact-unit-rules-support.tsscript16.8 KB
scripts/tests/fidelity-values-support.tsscript1.6 KB
scripts/tests/fixtures/assets/figure-1.svgother141 B
scripts/tests/fixtures/bad-report.htmlother2.1 KB
scripts/tests/fixtures/boxes.jsonconfig3.2 KB
scripts/tests/fixtures/conversion-probe.htmlother485 B
scripts/tests/fixtures/design-spec.mdmarkdown458 B
scripts/tests/fixtures/fidelity-brief-locked.mdmarkdown571 B
scripts/tests/fixtures/fidelity-brief-pending.mdmarkdown574 B
scripts/tests/fixtures/fidelity/assets/share.csvother40 B
scripts/tests/fixtures/fidelity/claim-graph.mdmarkdown449 B
scripts/tests/fixtures/fidelity/gen-legacy-dev.mjsscript5.0 KB
scripts/tests/fixtures/fidelity/ledger-basic.jsonconfig5.1 KB
scripts/tests/fixtures/fidelity/ledger-legacy-dev.jsonconfig18.3 KB
scripts/tests/fixtures/fidelity/ledger-verify.jsonconfig9.1 KB
scripts/tests/fixtures/fidelity/polish-edits.jsonconfig303 B
scripts/tests/fixtures/fidelity/report-bad.htmlother821 B
scripts/tests/fixtures/fidelity/report-good.htmlother2.4 KB
scripts/tests/fixtures/fidelity/sources/S4.htmlother680 B
scripts/tests/fixtures/fidelity/sources/S4/acronyms.jsonconfig36 B
scripts/tests/fixtures/fidelity/sources/S4/meta.jsonconfig256 B
scripts/tests/fixtures/fidelity/sources/S4/sentences.jsonlother623 B
scripts/tests/fixtures/fidelity/sources/S4/text.txtmarkdown300 B
scripts/tests/fixtures/fidelity/sources/S5/acronyms.jsonconfig3 B
scripts/tests/fixtures/fidelity/sources/S5/meta.jsonconfig235 B
scripts/tests/fixtures/fidelity/sources/S5/sentences.jsonlother53 B
scripts/tests/fixtures/fidelity/sources/S5/text.txtmarkdown10 B
scripts/tests/fixtures/fidelity/sources/S9.txtmarkdown128 B
scripts/tests/fixtures/good-report.htmlother2.7 KB
scripts/tests/fixtures/reference-report.htmlother2.5 KB

scripts/polish-apply.test.ts

View on GitHub
import { describe, expect, test } from "bun:test"

import { FACT_ELEMENT_TAGS, renderBlockquote, renderQuote, renderValueHtml } from "./placeholder.mjs"
import { applyEdits, cutSpan, POLISH_EDIT_FIELDS, project, validatePolishEdits } from "./polish-apply.mjs"
import { diffPolish } from "./polish-diff.mjs"

type Row = {
  fact_id: string
  kind: string
  quote: string
  raw: string
  value: string
  unit: string | null
  qualifier: string | null
}
const row = (
  fact_id: string,
  quote: string,
  raw: string,
  value: string,
  unit: string | null,
  qualifier: string | null = null,
): Row => ({
  fact_id,
  kind: "measured",
  quote,
  raw,
  value,
  unit,
  qualifier,
})
const REVENUE = row(
  "F1",
  "Revenue was about 10 million USD in 2025.",
  "10 million USD",
  "10000000",
  "USD",
  "approximate",
)
const SPAN = row("F2", "The bridge has a main span of 320 m.", "320 m", "320", "m")
const USERS = row("F3", "Usage reached 5,000 users.", "5,000 users", "5000", "users")
const BOUND = row("F4", "The bridge has a main span of up to 320 m.", "320 m", "320", "m", "upper_inclusive")
const LEDGER = { schemaVersion: 1, rows: [REVENUE, SPAN, USERS, BOUND], events: [] }
const f = (r: Row) => renderValueHtml(r, r.raw)
const doc = (body: string) => `<html><body>\n${body}\n</body></html>`
const edit = (before: string, after: string, reason = "polish") => ({ before, after, reason })
const codes = (list: { code: string }[]) => list.map((item) => item.code)

describe("applyEdits: hedges and qualifiers", () => {
  test("removing 'about' that the row quote carries is rejected and leaves the paragraph unchanged", () => {
    const html = doc(`<p>Revenue was about ${f(REVENUE)}.</p>`)
    const result = applyEdits(html, [edit(`Revenue was about ${f(REVENUE)}.`, `Revenue was ${f(REVENUE)}.`)], LEDGER)
    expect(result.applied).toEqual([])
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("about")
    expect(result.out).toBe(html)
  })

  test("removing a hedge the row quote lacks is applied", () => {
    const html = doc(`<p>The span was about ${f(SPAN)}.</p>`)
    const result = applyEdits(html, [edit("The span was about ", "The span was ")], LEDGER)
    expect(result.applied).toEqual([0])
    expect(result.rejected).toEqual([])
    expect(result.out).toBe(doc(`<p>The span was ${f(SPAN)}.</p>`))
  })

  test("dropping the row's qualifier ('up to') is rejected", () => {
    const html = doc(`<p>The main span is up to ${f(BOUND)}.</p>`)
    const result = applyEdits(
      html,
      [edit(`The main span is up to ${f(BOUND)}.`, `The main span is ${f(BOUND)}.`)],
      LEDGER,
    )
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("up to")
  })

  test("a claim-only sentence keeps the hedges of before", () => {
    const html = doc("<p>Results may improve [S1].</p>")
    expect(
      codes(applyEdits(html, [edit("Results may improve [S1].", "Results improve [S1].")], LEDGER).rejected),
    ).toEqual(["polish_edit_rejected"])
  })
})

describe("applyEdits: fact spans and numerals", () => {
  test("splitting a sentence with its fact spans intact is applied", () => {
    const html = doc(`<p>The span is ${f(SPAN)} and usage is ${f(USERS)}.</p>`)
    const result = applyEdits(html, [edit(" and usage is ", ". Usage is ")], LEDGER)
    expect(result.applied).toEqual([0])
    expect(result.out).toBe(doc(`<p>The span is ${f(SPAN)}. Usage is ${f(USERS)}.</p>`))
  })

  test("swapping two numerals is rejected", () => {
    const html = doc("<p>See Figure 1 and Figure 2 [S1].</p>")
    const result = applyEdits(
      html,
      [edit("See Figure 1 and Figure 2 [S1].", "See Figure 2 and Figure 1 [S1].")],
      LEDGER,
    )
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("numeral")
  })

  test("moving a decimal point is rejected", () => {
    const html = doc("<p>Throughput grew 3.5 times [S1].</p>")
    expect(codes(applyEdits(html, [edit("grew 3.5 times", "grew 35 times")], LEDGER).rejected)).toEqual([
      "polish_edit_rejected",
    ])
  })

  test("changing a plain unit ('320 m' to '320 mm') is rejected with a reason", () => {
    const html = doc("<p>The span is 320 m [S1].</p>")
    const result = applyEdits(html, [edit("The span is 320 m [S1].", "The span is 320 mm [S1].")], LEDGER)
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("numeral")
  })

  test("swapping the order of two fact spans is rejected", () => {
    const html = doc(`<p>The span is ${f(SPAN)} and usage is ${f(USERS)}.</p>`)
    const before = `The span is ${f(SPAN)} and usage is ${f(USERS)}.`
    const after = `Usage is ${f(USERS)} and the span is ${f(SPAN)}.`
    expect(codes(applyEdits(html, [edit(before, after)], LEDGER).rejected)).toEqual(["polish_edit_rejected"])
  })

  test("editing the rendered value inside a fact span is rejected", () => {
    const html = doc(`<p>The span is ${f(SPAN)}.</p>`)
    const changed = f(SPAN).replace(">320 m<", ">321 m<")
    expect(codes(applyEdits(html, [edit(f(SPAN), changed)], LEDGER).rejected)).toEqual(["polish_edit_rejected"])
  })
})

describe("applyEdits: links and location", () => {
  test("changing a link is rejected", () => {
    const html = doc('<p><a href="https://example.invalid/a">Reference</a> [S1].</p>')
    const before = '<a href="https://example.invalid/a">Reference</a>'
    const result = applyEdits(html, [edit(before, before.replace("/a", "/b"))], LEDGER)
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("href")
  })

  test("changing a data-claim id is rejected", () => {
    const html = doc('<p data-claim="C1">Results improve [S1].</p>')
    const result = applyEdits(html, [edit('data-claim="C1"', 'data-claim="C2"')], LEDGER)
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("markup changed")
  })

  test("a before that is not found is unlocated", () => {
    const result = applyEdits(doc("<p>Text [S1].</p>"), [edit("ABSENT", "replacement")], LEDGER)
    expect(codes(result.unlocated)).toEqual(["polish_edit_unlocated"])
    expect(result.applied).toEqual([])
  })

  test("a before that occurs twice is unlocated", () => {
    const result = applyEdits(doc("<p>The term and term appear [S1].</p>"), [edit("term", "word")], LEDGER)
    expect(codes(result.unlocated)).toEqual(["polish_edit_unlocated"])
  })

  test("before matches across normalized whitespace", () => {
    const html = doc("<p>Results\n   improve [S1].</p>")
    const result = applyEdits(html, [edit("Results improve [S1].", "Results clearly improve [S1].")], LEDGER)
    expect(result.applied).toEqual([0])
    expect(result.out).toBe(doc("<p>Results clearly improve [S1].</p>"))
  })

  test("edits apply in order; a later edit whose before is gone is unlocated", () => {
    const html = doc("<p>Results improve [S1].</p>")
    const result = applyEdits(
      html,
      [
        edit("Results improve [S1].", "Results improve steadily [S1]."),
        edit("Results improve [S1].", "Results improve rapidly [S1]."),
      ],
      LEDGER,
    )
    expect(result.applied).toEqual([0])
    expect(result.unlocated.map((item: { index: number }) => item.index)).toEqual([1])
    expect(result.out).toBe(doc("<p>Results improve steadily [S1].</p>"))
  })

  test("a rejected edit does not block a later good edit", () => {
    const html = doc(`<p>Revenue was about ${f(REVENUE)}.</p><p>Results improve [S1].</p>`)
    const result = applyEdits(
      html,
      [
        edit(`Revenue was about ${f(REVENUE)}.`, `Revenue was ${f(REVENUE)}.`),
        edit("Results improve [S1].", "Results clearly improve [S1]."),
      ],
      LEDGER,
    )
    expect(result.applied).toEqual([1])
    expect(result.rejected.map((item: { index: number }) => item.index)).toEqual([0])
    expect(result.out).toBe(doc(`<p>Revenue was about ${f(REVENUE)}.</p><p>Results clearly improve [S1].</p>`))
  })
})

describe("applyEdits: rendered visibility (review #11152 round 1)", () => {
  const html = doc(`<p>The span is ${f(SPAN)} [S1].</p>`)
  const hide = (after: string) => applyEdits(html, [edit(f(SPAN), after)], LEDGER)
  test.each([
    ["an HTML comment", `<!-- ${f(SPAN)} -->`],
    ["a hidden attribute", `<span hidden>${f(SPAN)}</span>`],
    ["display:none", `<span style="display: none">${f(SPAN)}</span>`],
    ["visibility:hidden", `<span style="visibility:hidden">${f(SPAN)}</span>`],
    ["font-size:0", `<span style="font-size:0px">${f(SPAN)}</span>`],
    ["a template", `<template>${f(SPAN)}</template>`],
    ["an unclosed hidden wrapper", `<div hidden>${f(SPAN)}`],
  ])("a fact span wrapped in %s is rejected and leaves the document unchanged", (_label, after) => {
    const result = hide(after)
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("markup changed")
    expect(result.out).toBe(html)
  })

  test("a data-claim span moved into a comment is rejected", () => {
    const claim = doc('<p><span data-claim="C1">Results improve</span> [S1].</p>')
    const before = '<span data-claim="C1">Results improve</span>'
    expect(codes(applyEdits(claim, [edit(before, `<!-- ${before} -->Results improve`)], LEDGER).rejected)).toEqual([
      "polish_edit_rejected",
    ])
  })

  test("a hedge hidden with a hidden attribute is rejected", () => {
    const claim = doc("<p>Results may improve [S1].</p>")
    const result = applyEdits(claim, [edit("Results may improve", "Results <span hidden>may</span> improve")], LEDGER)
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("markup changed")
  })
})

describe("applyEdits: the same rules as diffPolish (review #11152 round 1)", () => {
  test("adding a ticker is rejected", () => {
    const result = applyEdits(
      doc("<p>The firm reported growth [S1].</p>"),
      [edit("The firm reported", "AAPL reported")],
      LEDGER,
    )
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("tickers")
  })

  test("renaming an id that an internal link targets is rejected", () => {
    const html = doc('<h2 id="s1">Method</h2><p><a href="#s1">Method</a> [S1].</p>')
    const result = applyEdits(html, [edit('id="s1"', 'id="s2"')], LEDGER)
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("#s1")
  })

  test("dropping a table row is rejected", () => {
    const html = doc("<table><tr><td>A</td></tr><tr><td>B</td></tr></table>")
    expect(codes(applyEdits(html, [edit("<tr><td>B</td></tr>", "")], LEDGER).rejected)).toEqual([
      "polish_edit_rejected",
    ])
  })

  test("cumulative churn is caught at the edit that crosses the limit, against the original document", () => {
    const html = doc("<p>Alpha beta gamma. Delta epsilon zeta. Eta theta iota. Kappa lambda mu.</p>")
    const edits = [
      edit("Alpha beta gamma.", "Nu xi omicron."),
      edit("Delta epsilon zeta.", "Rho sigma tau."),
      edit("Eta theta iota.", "Phi chi psi."),
    ]
    const result = applyEdits(html, edits, LEDGER)
    expect(result.rejected.length).toBeGreaterThan(0)
    expect(result.rejected.at(-1)?.reason).toContain("percent of the normalized prose")
    expect(diffPolish(html, result.out, LEDGER)).toEqual([])
  })
})

describe("applyEdits: one baseline with diffPolish (review #11152 round 2, M1)", () => {
  const TOWER = row("F7", "The tower is 320 m tall.", "320 m", "320", "m")
  const ledger = { ...LEDGER, rows: [...LEDGER.rows, TOWER] }
  const html = doc(`<p>The tower is ${f(TOWER)} tall. It may be the tallest.</p>`)
  const pair = [edit(" tall. It may be", " tall and may be"), edit("and may be the tallest", "and is the tallest")]

  test("each edit of the hedge-stripping pair alone keeps the hedge", () => {
    expect(applyEdits(html, [pair[0]], ledger).applied).toEqual([0])
    const merged = applyEdits(html, [pair[0]], ledger).out
    expect(diffPolish(merged, applyEdits(merged, [pair[1]], ledger).out, ledger)).toEqual([])
  })

  test("the pair together is refused at the second edit, which strips the source document's hedge", () => {
    const result = applyEdits(html, pair, ledger)
    expect(result.applied).toEqual([0])
    expect(codes(result.rejected)).toEqual(["polish_edit_rejected"])
    expect(result.rejected[0].reason).toContain("may")
    expect(diffPolish(html, result.out, ledger)).toEqual([])
  })

  test("no cross-edit case remains: every applyEdits output is diffPolish-clean against the input", () => {
    const cases: [string, { before: string; after: string; reason: string }[]][] = [
      [html, pair],
      [
        doc("<p>Alpha beta gamma. Delta epsilon zeta. Eta theta iota. Kappa lambda mu.</p>"),
        [
          edit("Alpha beta gamma.", "Nu xi omicron."),
          edit("Delta epsilon zeta.", "Rho sigma tau."),
          edit("Eta theta iota.", "Phi chi psi."),
        ],
      ],
      [
        doc(`<p>The span is ${f(SPAN)} and usage is ${f(USERS)}.</p>`),
        [edit(" and usage is", ". Usage is"), edit("The span is", "Usage is"), edit(". Usage is", " and the span is")],
      ],
    ]
    for (const [input, edits] of cases)
      expect(diffPolish(input, applyEdits(input, edits, ledger).out, ledger)).toEqual([])
  })
})

describe("applyEdits: hidden content keeps its bytes and its class (review #11152 round 2, H1 and M2)", () => {
  const refused = (html: string, edits: { before: string; after: string; reason: string }[], word: string) => {
    const result = applyEdits(html, edits, LEDGER)
    expect(result.applied).toEqual([])
    expect(result.out).toBe(html)
    expect(result.rejected.map((item: { reason: string }) => item.reason).join(" | ")).toContain(word)
  }
  const flagged = (before: string, after: string) =>
    expect(codes(diffPolish(before, after, LEDGER))).toContain("polish_diff_fail")

  test("probe 1: a number under aria-hidden renders, so editing it is refused and flagged", () => {
    const html = doc('<p>Growth was <span aria-hidden="true">3.2% in 2024</span> overall.</p>')
    refused(html, [edit("3.2% in 2024", "9.9% in 2031")], "numerals")
    flagged(html, html.replace("3.2% in 2024", "9.9% in 2031"))
  })

  test("probe 2: a number after an unclosed <p hidden> is inside the hidden region, whose bytes may not change", () => {
    const html = doc("<p hidden>note<div>Revenue was 5 billion.</div>")
    refused(html, [edit("5 billion", "50 billion")], "numerals")
    flagged(html, html.replace("5 billion", "50 billion"))
  })

  test("a legitimately hidden region left byte-identical does not block a visible edit", () => {
    const html = doc("<p hidden>internal note 42</p><p>Results improve [S1].</p><!-- build 7 -->")
    const result = applyEdits(html, [edit("Results improve [S1].", "Results clearly improve [S1].")], LEDGER)
    expect(result.applied).toEqual([0])
    expect(diffPolish(html, result.out, LEDGER)).toEqual([])
  })

  const shown = doc(`<p>The span is <span>${f(SPAN)}</span> [S1].</p>`)
  const changed = f(SPAN).replace(">320 m<", ">321 m<")
  test("relabelling a visible fact span as hidden while changing its number, in one edit, is refused and flagged", () => {
    refused(shown, [edit(`<span>${f(SPAN)}</span>`, `<span hidden>${changed}</span>`)], "markup changed")
    flagged(shown, shown.replace(`<span>${f(SPAN)}</span>`, `<span hidden>${changed}</span>`))
  })

  test("the two-edit variant (hide, then change) is refused at both edits and flagged", () => {
    const edits = [edit(`<span>${f(SPAN)}`, `<span style="display:none">${f(SPAN)}`), edit(">320 m<", ">321 m<")]
    const result = applyEdits(shown, edits, LEDGER)
    expect(result.applied).toEqual([])
    expect(result.rejected[0].reason).toContain("markup changed")
    flagged(shown, shown.replace(`<span>${f(SPAN)}</span>`, `<span style="display:none">${changed}</span>`))
  })

  test("unhiding a hidden fact span with a changed value is refused and flagged", () => {
    const hidden = doc(`<p>The span is <span hidden>${f(SPAN)}</span> [S1].</p>`)
    refused(hidden, [edit(`<span hidden>${f(SPAN)}</span>`, `<span>${changed}</span>`)], "markup changed")
    flagged(hidden, hidden.replace(`<span hidden>${f(SPAN)}</span>`, `<span>${changed}</span>`))
  })

  test("a pure change of a fact or claim span's visibility class is flagged in both directions", () => {
    const claim = doc('<p><span data-claim="C1">Results improve</span> [S1].</p>')
    const hiddenClaim = claim.replace('<span data-claim="C1">', '<span hidden data-claim="C1">')
    for (const [before, after] of [
      [claim, hiddenClaim],
      [hiddenClaim, claim],
    ]) {
      expect(
        diffPolish(before, after, LEDGER).find((d: { code: string }) => d.code === "polish_diff_fail")?.message,
      ).toContain("markup changed")
    }
  })

  test.each([
    ["color:transparent"],
    ["max-height:0;overflow:hidden"],
    ["position:absolute;left:-9999px"],
    ["clip-path:inset(50%)"],
    ["transform:scale(0)"],
  ])("M2: wrapping a fact span in style=%s changes the markup and is refused and flagged", (style) => {
    const html = doc(`<p>The span is ${f(SPAN)} [S1].</p>`)
    refused(html, [edit(f(SPAN), `<span style="${style}">${f(SPAN)}</span>`)], "markup")
    flagged(html, html.replace(f(SPAN), `<span style="${style}">${f(SPAN)}</span>`))
  })

  test("M2: inserting a stylesheet is refused and flagged", () => {
    const html = doc(`<p>The span is ${f(SPAN)} [S1].</p>`)
    refused(html, [edit("The span is", "<style>.x{display:none}</style>The span is")], "markup")
    flagged(html, html.replace("The span is", "<style>.x{display:none}</style>The span is"))
  })
})

describe("polish fact spans come from the placeholder renderers (duplication sweep)", () => {
  const source = { ...SPAN, source_id: "S1", entity: null, valid_at: null }
  const rendered = [
    renderValueHtml(source, source.raw),
    renderQuote(source, "p:nth-of-type(1)", source.quote, "html"),
    renderBlockquote(source, "k1", "html"),
  ]

  test("the renderers emit exactly the FACT_ELEMENT_TAGS elements", () => {
    expect(rendered.map((html) => html.match(/^<([a-z]+)/)?.[1]).sort()).toEqual([...FACT_ELEMENT_TAGS].sort())
  })

  test.each(rendered.map((html) => [html.match(/^<([a-z]+)/)?.[1], html]))(
    "project and cutSpan recognize a rendered <%s>",
    (_tag, html) => {
      const markup = `<p>Before ${html} after.</p>`
      expect(project(markup).facts.map((fact: { id: string }) => fact.id)).toEqual(["F2"])
      const at = markup.indexOf(html)
      expect(cutSpan(markup, at + 3, at + html.length + 2)).toBe("F2")
      expect(cutSpan(markup, at, at + html.length)).toBeNull()
    },
  )
})

describe("validatePolishEdits: the edit contract (duplication sweep)", () => {
  test("the contract names before and after as required and reason as optional", () => {
    expect(POLISH_EDIT_FIELDS).toEqual({ before: "required", after: "required", reason: "optional" })
  })

  test.each([
    ["a non-array", { before: "a", after: "b" }, "array"],
    ["a null entry", [null], "edit 0"],
    ["a non-string before", [{ before: 1, after: "b" }], "before"],
    ["a missing after", [{ before: "a" }], "after"],
    ["a non-string reason", [{ before: "a", after: "b", reason: 3 }], "reason"],
  ])("%s is refused with a TypeError, by the validator and by applyEdits alike", (_label, edits, word) => {
    expect(() => validatePolishEdits(edits)).toThrow(TypeError)
    expect(() => validatePolishEdits(edits)).toThrow(word)
    expect(() => applyEdits("<p>a</p>", edits as never, LEDGER)).toThrow(word)
  })

  test("an edit without a reason is valid", () => {
    const edits = [{ before: "a", after: "b" }]
    expect(validatePolishEdits(edits)).toBe(edits)
  })
})
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall