diff --git a/skills/launch-content/scripts/build_site.py b/skills/launch-content/scripts/build_site.py new file mode 100644 index 0000000..bbc5838 --- /dev/null +++ b/skills/launch-content/scripts/build_site.py @@ -0,0 +1,464 @@ +"""The site builder: run records and Notion page states in, the board and the published pages out. + +Usage: python build_site.py RUNS_FOLDER --notion NOTION_JSON --owners OWNERS_JSON --out SITE_FOLDER [--skill SKILL_FOLDER] + +NOTION_JSON maps "/" to {"status", "round", "url"}, recorded from the gates database. +A gate's Status is read only from it, never from run.json, and a gate whose Draft fails the Check is held. +""" + +import argparse +import json +import re +import shutil +import sys +from datetime import datetime +from html import escape +from pathlib import Path +from string import Template +from typing import NamedTuple + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import check # noqa: E402 + +GATES = {"blog": "Blog post", "changelog": "Changelog", "social": "Social post", "faq": "FAQ update"} +STATUS = { + "Drafted": ("review", False), + "Needs changes": ("back", False), + "Ready to post": ("ok", True), + "Posted": ("ok", True), + "Rejected": ("skip", False), +} +NEXT = [("customer-email", "Customer email", "Lifecycle"), + ("video-script", "Video script", "Video"), + ("site-animation", "Site animation", "Design")] +KINDS = {"pull_request": ("Pull request", "is-pr", "merged pull request"), + "briefing": ("Product brief", "is-brief", "product brief")} +COUNTS = re.compile(r"(\d+) lines, (\d+) claims, (\d+/\d+) parts") +PERSON = ('') +SITE = Path(__file__).resolve().parents[1] / "site" + + +class BuildError(Exception): + pass + + +class Shown(NamedTuple): + """One Draft line as a reader sees it: its heading mark, its text without citations, and its claim ids.""" + mark: str + text: str + claims: tuple[str, ...] + + +class Cell(NamedTuple): + run: dict + gate: str + stamp: str + tone: str + published: bool + counts: str + round: int + url: str + held: str + + +def plural(n, word): + return f"{n} {word}" if n == "1" else f"{n} {word}s" + + +def shown_lines(text): + lines = [] + for raw in text.replace("\r\n", "\n").split("\n"): + line = raw.strip() + if not line or check.PART.fullmatch(line): + continue + cited = check.CITATIONS.search(line) + body = (line[:cited.start()] if cited else line).strip() + mark = check.HEADING.match(body) + lines.append(Shown(mark.group(0) if mark else "", body[mark.end():] if mark else body, + tuple(check.CLAIM_ID.findall(cited.group(0))) if cited else ())) + return lines + + +def read_json(path): + try: + return json.loads(path.read_text(encoding="utf-8")) + except (OSError, json.JSONDecodeError) as problem: + raise BuildError(f"{path.name} cannot be read: {problem}") from None + + +def owner_role(skill, gate): + path = skill / "gates" / f"{gate}.md" + block = check.CONTRACT.search(path.read_text(encoding="utf-8")) if path.is_file() else None + return json.loads(block.group(1)).get("owner_role", "") if block else "" + + +def owner(owners, role): + name = owners.get("roles", {}).get(role, "") + return " · ".join(part for part in (name, role.capitalize()) if part) + + +def page_state(notion, key): + state = notion.get(key) + if state is None: + return None + if not isinstance(state, dict): + raise BuildError(f"{key} must be an object with status, round and url") + if state.get("status") not in STATUS: + raise BuildError(f"{key} has the Notion Status \"{state.get('status')}\", expected one of {', '.join(STATUS)}") + rounds = state.get("round", 1) + if isinstance(rounds, bool) or not isinstance(rounds, int) or rounds < 1: + raise BuildError(f"{key} has the round \"{rounds}\", expected a whole number") + return {"status": state["status"], "round": rounds, "url": str(state.get("url") or "")} + + +def resolve(folder, run, gate, skill, notion): + """One cell: held when the Check fails, else the Status of its Notion page, else no page yet.""" + try: + failures, stamps = check.check(folder, gate, skill) + except check.Unreadable as problem: + failures, stamps = [str(problem)], [] + state = page_state(notion, f"{run['id']}/{gate}") + found = COUNTS.search(stamps[0]) if stamps else None + counts = " · ".join((plural(found[1], "line"), plural(found[2], "claim"), f"{found[3]} parts")) if found else "" + url = state["url"] if state else "" + rounds = state["round"] if state else 1 + if failures: + return Cell(run, gate, "HELD BY THE CHECK", "back", False, counts, rounds, url, failures[0]) + if state is None: + return Cell(run, gate, "NO PAGE YET", "skip", False, counts, rounds, url, "") + tone, published = STATUS[state["status"]] + return Cell(run, gate, state["status"].upper(), tone, published, counts, rounds, url, "") + + +def when(stamp, layout): + try: + return datetime.fromisoformat(stamp.replace("Z", "+00:00")).strftime(layout) + except (AttributeError, ValueError): + return "" + + +def load_runs(folder): + runs = [] + for path in sorted(folder.glob("*/run.json")): + run = read_json(path) + problems = check.record_problems(run) + if problems: + raise BuildError(f"{path.parent.name}: {problems[0]}") + runs.append((path.parent, run)) + return sorted(runs, key=lambda item: item[1]["source"].get("received", ""), reverse=True) + + +def link(cell): + if cell.published: + return {"blog": f"blog/{cell.run['id']}/index.html", "changelog": "changelog/index.html", + "faq": "faq/index.html", "social": "social/index.html"}[cell.gate] + return cell.url or "#" + + +def cell_html(cell, owners, selected): + key = f"{cell.run['id']}/{cell.gate}" + role = cell.run["gates"][cell.gate].get("owner_role", "") + attrs = ' class="cell is-selected" href="#open" aria-current="true"' if selected else f' class="cell" href="{escape(link(cell))}"' + held = f'\n {escape(cell.held)}' if cell.held else "" + counts = f'\n {escape(cell.counts)}' if cell.counts else "" + return f""" + {GATES[cell.gate]} + {cell.stamp}{counts}{held} + round {cell.round} · {escape(owner(owners, role))} + """ + + +def row_html(run, cells, owners, selected): + kind, kind_class, _ = KINDS[run["source"]["kind"]] + decision = run["verdict"]["decision"] + quiet = {"write": "", "ask": " is-ask", "skip": " is-quiet"}[decision] + head = f"""
  • +
    + {when(run['source'].get('received'), '%a
    %H:%M')}
    + {escape(run['source']['title'])}{kind} +
    """ + if decision == "ask": + questions = run["source"]["open_questions"] + items = "".join(f"
  • {escape(q)}
  • " for q in questions) + body = f""" + ASK + {plural(str(len(questions)), 'question')} for product
      {items}
    +
    """ + elif decision == "skip": + body = f""" + SKIP + {escape(run['verdict'].get('reason', ''))} + """ + else: + body = "\n".join(cell_html(cells[g], owners, cells[g] is selected) if g in cells + else f' ' + for g in GATES) + return f"{head}\n{body}\n " + + +def clock_html(runs): + writes = [run for _, run in runs if run["verdict"]["decision"] == "write"] + asked = sum(run["verdict"]["decision"] == "ask" for _, run in runs) + week = (f'

    This week {len(runs)} arrived
    {len(writes)} drafted · ' + f'{asked} asked · {len(runs) - len(writes) - asked} skipped

    ') + took = "" + for run in writes: + times = run.get("times", {}) + try: + start, end = (datetime.fromisoformat(times[k].replace("Z", "+00:00")) for k in ("received", "proposed")) + except (KeyError, AttributeError, ValueError): + continue + n = str(len(run["gates"])) + line = (f"one {KINDS[run['source']['kind']][2]} became {plural(n, 'draft')} for " + f"{plural(str(len({g.get('owner_role') for g in run['gates'].values()})), 'owner')}") + seconds = int((end - start).total_seconds()) + took = (f'\n
    \n
    {seconds}s
    \n' + f'

    {line}

    \n
    ') + label = f"{seconds} seconds: {line}" + break + else: + label = "This week" + return f'
    {took}\n {week}\n
    ' + + +def quote_where(folder, claim): + """An owner claim's quote lives in the Owner sources of its gate, as check.py checks it; any other in the Snapshot.""" + if "gate" in claim: + return "Owner sources" + claim_words = check.plain_words(claim["quote"]) + for number, line in enumerate((folder / "snapshot.md").read_text(encoding="utf-8").split("\n"), 1): + if check.find_run(check.source_words(line), claim_words) >= 0: + return f"Snapshot, line {number}" + return "Snapshot" + + +def slip_html(folder, cell, owners): + run = cell.run + claims = {c["id"]: (n, c["quote"]) for n, c in enumerate(run["claims"], 1)} + places = {c["id"]: quote_where(folder, c) for c in run["claims"]} + rows = [] + for index, line in enumerate(shown_lines((folder / "gates" / cell.gate / "draft.md").read_text(encoding="utf-8"))): + ids = " ".join(str(claims[c][0]) for c in line.claims if c in claims) + quotes = "".join(f'

    "{escape(claims[c][1])}"

    ' + f'

    {places[c]}

    ' + for c in line.claims if c in claims) + title = " is-title" if index == 0 and line.mark.startswith("#") else "" + rows.append(f"""
  • +

    {escape(line.text)}

    + {f'{ids}' if ids else ""} +
    {quotes}
    +
  • """) + first, rest = rows[:2], rows[2:] + more = (f'
    \n {plural(str(len(rest)), "more line")}\n' + f'
      \n' + "\n".join(rest) + "\n
    \n
    \n") if rest else "" + banned = "".join(f"
  • {escape(p)}
  • " for p in run["source"]["do_not_say"]) + ban = (f'
    \n

    Banned phrases

    \n \n' + f'

    None found

    \n
    \n') if banned else "" + role = run["gates"][cell.gate].get("owner_role", "") + return f"""
    +
    + {cell.stamp} +

    {GATES[cell.gate]}{escape(run['source']['title'])}

    + {PERSON}{escape(owner(owners, role))} +
    +
      +{chr(10).join(first)} +
    +{more}{ban} +
    """ + + +def ref(claims, claim_id, linked): + """A link to the quote list on a blog page; elsewhere the quote rides in the title, since no quote list is on the page.""" + number, quote = claims.get(claim_id, ("?", "")) + if linked: + return f'{number}' + return f'{number}' + + +def sentence(line, claims, linked=True): + return f"

    {escape(line.text)}{''.join(ref(claims, c, linked) for c in line.claims)}

    " + + +def post_page(owners, title, root, current, main, nav_links, script=""): + pages = [("What is new", nav_links.get("blog")), ("Changelog", "changelog/index.html"), + ("FAQ", "faq/index.html"), ("Social", "social/index.html")] + nav = "\n".join(f' {label}' + for label, href in pages if href) + return Template((SITE / "post.html").read_text(encoding="utf-8")).substitute( + title=escape(title), company=escape(owners.get("company", "")), root=root, nav=nav, main=main, script=script) + + +def blog_page(folder, cell, owners, also, nav_links): + run = cell.run + claims = {c["id"]: (n, c["quote"]) for n, c in enumerate(run["claims"], 1)} + lines = shown_lines((folder / "gates/blog/draft.md").read_text(encoding="utf-8")) + title = next((line.text for line in lines if line.mark == "# "), run["source"]["title"]) + body = "\n".join(" " + sentence(line, claims) for line in lines if line.mark != "# ") + cited = list(dict.fromkeys(c for line in lines for c in line.claims if c in claims)) + kind = KINDS[run["source"]["kind"]][0] + where = (f'{kind}' if run["source"].get("link") else kind) + places = {c["id"]: quote_where(folder, c) if "gate" in c else f"{where}, {quote_where(folder, c).lower()}" + for c in run["claims"]} + sources = "\n".join(f"""
  • + {claims[c][0]} +
    +

    "{escape(claims[c][1])}"

    +

    {places[c]}

    +
    +
  • """ for c in cited) + links = [f'the {label}' for gate, page, label in + (("changelog", "changelog", "changelog"), ("faq", "faq", "FAQ")) if gate in also] + via_also = f'\n Also in {" and ".join(links)}' if links else "" + role = run["gates"]["blog"].get("owner_role", "") + name = owners.get("roles", {}).get(role, "") + main = f"""

    {escape(str(run['verdict'].get('tier') or 'Launch').capitalize())}, arrived {when(run['source'].get('received'), '%A at %H:%M')}

    +

    {escape(title)}

    + +
    +
    +{body} +
    +
    + +

    + {escape(cell.stamp.capitalize())} + Blog post · approved by {escape(name)}, {escape(role.capitalize())}{via_also} +

    + + """ + return post_page(owners, title, "../../", "What is new", main, nav_links) + + +def list_page(owners, title, current, entries, nav_links, script=""): + main = f"""

    {title}, newest first

    +

    {title}

    + +
      +{entries} +
    """ + return post_page(owners, title, "../", current, main, nav_links, script) + + +def changelog_entry(folder, run): + claims = {c["id"]: (n, c["quote"]) for n, c in enumerate(run["claims"], 1)} + lines = shown_lines((folder / "gates/changelog/draft.md").read_text(encoding="utf-8")) + body = "\n".join(" " + sentence(line, claims, linked=False) for line in lines) + return f"""
  • +

    {when(run['source'].get('received'), '%a %d %b %Y')}

    +

    {escape(run['source']['title'])}

    +
    +{body} +
    +
  • """ + + +def faq_entries(folder, run): + claims = {c["id"]: (n, c["quote"]) for n, c in enumerate(run["claims"], 1)} + groups = [] + for line in shown_lines((folder / "gates/faq/draft.md").read_text(encoding="utf-8")): + if line.mark == "## ": + groups.append((re.sub(r"^Q:\s*", "", line.text), [])) + elif groups: + groups[-1][1].append(line) + return "\n".join(f"""
  • +

    {escape(question)}

    +
    +{chr(10).join(' ' + sentence(line, claims, linked=False) for line in answer)} +
    +
  • """ for n, (question, answer) in enumerate(groups, 1)) + + +COPY_SCRIPT = """""" + + +def social_card(folder, run): + lines = shown_lines((folder / "gates/social/draft.md").read_text(encoding="utf-8")) + text = "\n".join(f"

    {escape(line.text)}

    " for line in lines) + return f"""
  • +

    {escape(run['source']['title'])}

    +
    +{text} +
    + +
  • """ + + +def write(path, text): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text, encoding="utf-8", newline="\n") + + +def build(runs_folder, notion_path, owners_path, skill, out): + owners = read_json(owners_path) + notion = read_json(notion_path) + runs = load_runs(runs_folder) + cells = {run["id"]: {g: resolve(folder, run, g, skill, notion) for g in run["gates"] if g in GATES} + for folder, run in runs} + selected = next((c for _, run in runs for c in cells[run["id"]].values() if c.tone in ("review", "back") and not c.held), None) + folders = {run["id"]: folder for folder, run in runs} + + heads = "\n".join(f"""
    + {label} + {PERSON}{escape(owner(owners, owner_role(skill, g)))} +
    """ for g, label in GATES.items()) + rows = "\n".join(row_html(run, cells[run["id"]], owners, selected) for _, run in runs) + nexts = "\n".join(f"""
  • + {label} + Owner: {role} + adds one file +
  • """ for key, label, role in NEXT) + mode = str(runs[0][1]["mode"]).capitalize() if runs else "Suggest" + write(out / "index.html", Template((SITE / "board.html").read_text(encoding="utf-8")).substitute( + company=escape(owners.get("company", "")), mode=f"Mode: {escape(mode)} · Autonomous locked", + clock=clock_html(runs), heads=heads, rows=rows, nexts=nexts, + slip=slip_html(folders[selected.run["id"]], selected, owners) if selected else "")) + + published = {g: [c for _, run in runs for c in [cells[run["id"]].get(g)] if c and c.published] for g in GATES} + shutil.rmtree(out / "blog", ignore_errors=True) + nav_links = {"blog": f"blog/{published['blog'][0].run['id']}/index.html"} if published["blog"] else {} + for cell in published["blog"]: + also = {g for g, c in cells[cell.run["id"]].items() if c.published} + write(out / "blog" / cell.run["id"] / "index.html", blog_page(folders[cell.run["id"]], cell, owners, also, nav_links)) + write(out / "changelog/index.html", list_page(owners, "Changelog", "Changelog", "\n".join( + changelog_entry(folders[c.run["id"]], c.run) for c in published["changelog"]), nav_links)) + write(out / "faq/index.html", list_page(owners, "FAQ", "FAQ", "\n".join( + faq_entries(folders[c.run["id"]], c.run) for c in published["faq"]), nav_links)) + write(out / "social/index.html", list_page(owners, "Social", "Social", "\n".join( + social_card(folders[c.run["id"]], c.run) for c in published["social"]), nav_links, COPY_SCRIPT)) + + +def main(argv=None): + parser = argparse.ArgumentParser(description="Build the board and the published pages from run records.") + parser.add_argument("runs", type=Path) + parser.add_argument("--notion", type=Path, required=True) + parser.add_argument("--owners", type=Path, required=True) + parser.add_argument("--out", type=Path, required=True) + parser.add_argument("--skill", type=Path, default=Path(__file__).resolve().parents[1]) + args = parser.parse_args(argv) + try: + build(args.runs, args.notion, args.owners, args.skill, args.out) + except BuildError as problem: + print(f"FAIL {problem}", file=sys.stderr) + return 1 + print(f"built {args.out}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/skills/launch-content/site/board.html b/skills/launch-content/site/board.html new file mode 100644 index 0000000..613172f --- /dev/null +++ b/skills/launch-content/site/board.html @@ -0,0 +1,252 @@ + + + + + +Launch desk, $company + + + + + + +
    + +
    +
    + $company +

    Launch desk

    +
    +

    $mode

    +
    + +$clock + +
    +
    + +
    +
    +

    In this sandbox one person plays every owner.

    +$heads +
    + +
      +$rows +
    +
    + +
      + +$nexts +
    + +
    + +
    +$slip +
    +
    +
    + + diff --git a/skills/launch-content/site/post.html b/skills/launch-content/site/post.html new file mode 100644 index 0000000..aceaa3f --- /dev/null +++ b/skills/launch-content/site/post.html @@ -0,0 +1,120 @@ + + + + + +$title, $company + + + + + + + +
    +
    + $company + +
    +
    + +
    +$main +
    + + +$script + + diff --git a/tests/fixtures/site/notion.json b/tests/fixtures/site/notion.json new file mode 100644 index 0000000..145199c --- /dev/null +++ b/tests/fixtures/site/notion.json @@ -0,0 +1,47 @@ +{ + "pr-csv/blog": { + "status": "Ready to post", + "round": 2, + "url": "https://www.notion.so/example-pr-csv-blog" + }, + "pr-csv/changelog": { + "status": "Posted", + "round": 1, + "url": "https://www.notion.so/example-pr-csv-changelog" + }, + "pr-csv/social": { + "status": "Ready to post", + "round": 1, + "url": "https://www.notion.so/example-pr-csv-social" + }, + "pr-csv/faq": { + "status": "Posted", + "round": 3, + "url": "https://www.notion.so/example-pr-csv-faq" + }, + "brief-seats/blog": { + "status": "Drafted", + "round": 1, + "url": "https://www.notion.so/example-brief-seats-blog" + }, + "brief-seats/changelog": { + "status": "Needs changes", + "round": 2, + "url": "https://www.notion.so/example-brief-seats-changelog" + }, + "brief-seats/social": { + "status": "Drafted", + "round": 1, + "url": "https://www.notion.so/example-brief-seats-social" + }, + "brief-seats/faq": { + "status": "Drafted", + "round": 1, + "url": "https://www.notion.so/example-brief-seats-faq" + }, + "pr-pdf/changelog": { + "status": "Rejected", + "round": 1, + "url": "https://www.notion.so/example-pr-pdf-changelog" + } +} diff --git a/tests/fixtures/site/owners.json b/tests/fixtures/site/owners.json new file mode 100644 index 0000000..ed7593c --- /dev/null +++ b/tests/fixtures/site/owners.json @@ -0,0 +1,12 @@ +{ + "company": "Harbor Reports", + "roles": { + "content": "Sandbox owner", + "marketing": "Sandbox owner", + "social": "Sandbox owner", + "support": "Sandbox owner" + }, + "manager": "Sandbox owner", + "review_surface": "notion", + "posting": "manager" +} diff --git a/tests/fixtures/site/records/brief-dashboards/run.json b/tests/fixtures/site/records/brief-dashboards/run.json new file mode 100644 index 0000000..4aeb73b --- /dev/null +++ b/tests/fixtures/site/records/brief-dashboards/run.json @@ -0,0 +1,36 @@ +{ + "id": "brief-dashboards", + "source": { + "kind": "briefing", + "title": "Faster dashboards", + "link": "", + "author": "", + "received": "2026-11-17T16:20:00Z", + "do_not_say": [], + "open_questions": [ + "Which plans get the faster dashboards?", + "Is the old dashboard still available?" + ] + }, + "mode": "suggest", + "verdict": { + "decision": "ask", + "tier": null, + "rule": 1, + "quote": "Faster dashboards", + "reason": "Product has open questions." + }, + "claims": [], + "gates": {}, + "steps": { + "snapshot": "done", + "verdict": "done", + "claims": "done", + "gates": {} + }, + "times": { + "received": "2026-11-17T16:20:00Z", + "verdict": "", + "proposed": "" + } +} diff --git a/tests/fixtures/site/records/brief-dashboards/snapshot.md b/tests/fixtures/site/records/brief-dashboards/snapshot.md new file mode 100644 index 0000000..4eceb1d --- /dev/null +++ b/tests/fixtures/site/records/brief-dashboards/snapshot.md @@ -0,0 +1 @@ +# Faster dashboards diff --git a/tests/fixtures/site/records/brief-seats/gates/blog/draft.md b/tests/fixtures/site/records/brief-seats/gates/blog/draft.md new file mode 100644 index 0000000..6abecc7 --- /dev/null +++ b/tests/fixtures/site/records/brief-seats/gates/blog/draft.md @@ -0,0 +1,6 @@ + +# Team seats for sales managers + +A manager now invites each rep to a team seat. [s1] +Each rep connects their own export once. [s2] +The manager sees one weekly report for the whole team. [s3] diff --git a/tests/fixtures/site/records/brief-seats/gates/changelog/draft.md b/tests/fixtures/site/records/brief-seats/gates/changelog/draft.md new file mode 100644 index 0000000..2c08909 --- /dev/null +++ b/tests/fixtures/site/records/brief-seats/gates/changelog/draft.md @@ -0,0 +1,2 @@ + +Managers can invite each rep to a team seat. [s1] diff --git a/tests/fixtures/site/records/brief-seats/gates/faq/draft.md b/tests/fixtures/site/records/brief-seats/gates/faq/draft.md new file mode 100644 index 0000000..3063299 --- /dev/null +++ b/tests/fixtures/site/records/brief-seats/gates/faq/draft.md @@ -0,0 +1,3 @@ + +## Q: Who connects the exports? +Each rep connects their own export once. [s2] diff --git a/tests/fixtures/site/records/brief-seats/gates/social/draft.md b/tests/fixtures/site/records/brief-seats/gates/social/draft.md new file mode 100644 index 0000000..bf9fe58 --- /dev/null +++ b/tests/fixtures/site/records/brief-seats/gates/social/draft.md @@ -0,0 +1,2 @@ + +One weekly report for the whole team, with each rep on a seat. [s1, s3] diff --git a/tests/fixtures/site/records/brief-seats/run.json b/tests/fixtures/site/records/brief-seats/run.json new file mode 100644 index 0000000..181b2f0 --- /dev/null +++ b/tests/fixtures/site/records/brief-seats/run.json @@ -0,0 +1,70 @@ +{ + "id": "brief-seats", + "source": { + "kind": "briefing", + "title": "Team seats for sales managers", + "link": "", + "author": "", + "received": "2026-11-18T15:33:00Z", + "do_not_say": [ + "per-seat pricing", + "unlimited seats" + ], + "open_questions": [] + }, + "mode": "suggest", + "verdict": { + "decision": "write", + "tier": "launch", + "rule": 1, + "quote": "Team seats for sales managers", + "reason": "" + }, + "claims": [ + { + "id": "s1", + "quote": "Team seats let a manager invite each rep." + }, + { + "id": "s2", + "quote": "Each rep connects their own export once." + }, + { + "id": "s3", + "quote": "The manager sees one weekly report for the whole team." + } + ], + "gates": { + "blog": { + "contract": "gates/blog.md", + "owner_role": "content", + "check": {} + }, + "changelog": { + "contract": "gates/changelog.md", + "owner_role": "marketing", + "check": {} + }, + "social": { + "contract": "gates/social.md", + "owner_role": "social", + "check": {} + }, + "faq": { + "contract": "gates/faq.md", + "owner_role": "support", + "check": {} + } + }, + "steps": { + "snapshot": "done", + "verdict": "done", + "claims": "done", + "gates": {} + }, + "times": { + "received": "2026-11-18T15:33:00Z", + "verdict": "", + "proposed": "" + } +} diff --git a/tests/fixtures/site/records/brief-seats/snapshot.md b/tests/fixtures/site/records/brief-seats/snapshot.md new file mode 100644 index 0000000..73ae739 --- /dev/null +++ b/tests/fixtures/site/records/brief-seats/snapshot.md @@ -0,0 +1,5 @@ +# Team seats + +Team seats let a manager invite each rep. +Each rep connects their own export once. +The manager sees one weekly report for the whole team. diff --git a/tests/fixtures/site/records/pr-csv/gates/blog/draft.md b/tests/fixtures/site/records/pr-csv/gates/blog/draft.md new file mode 100644 index 0000000..6e7637b --- /dev/null +++ b/tests/fixtures/site/records/pr-csv/gates/blog/draft.md @@ -0,0 +1,6 @@ + +# CSV export for every report + +Any report now exports as CSV from the Export menu. [c1] +The export keeps the filters you picked. [c2] +In our tests, exports of up to 50000 rows finished in under 10 seconds. [c3] diff --git a/tests/fixtures/site/records/pr-csv/gates/changelog/draft.md b/tests/fixtures/site/records/pr-csv/gates/changelog/draft.md new file mode 100644 index 0000000..8254b73 --- /dev/null +++ b/tests/fixtures/site/records/pr-csv/gates/changelog/draft.md @@ -0,0 +1,3 @@ + +Reports export as CSV from the Export menu. [c1] +The export keeps your filters. [c2] diff --git a/tests/fixtures/site/records/pr-csv/gates/faq/draft.md b/tests/fixtures/site/records/pr-csv/gates/faq/draft.md new file mode 100644 index 0000000..340c08f --- /dev/null +++ b/tests/fixtures/site/records/pr-csv/gates/faq/draft.md @@ -0,0 +1,5 @@ + +## Q: Can I export a report as CSV? +Yes, from the Export menu on any report. [c1] +## Q: Does the export keep my filters? +Yes, the export keeps the filters you picked. [c2] diff --git a/tests/fixtures/site/records/pr-csv/gates/social/draft.md b/tests/fixtures/site/records/pr-csv/gates/social/draft.md new file mode 100644 index 0000000..eef6790 --- /dev/null +++ b/tests/fixtures/site/records/pr-csv/gates/social/draft.md @@ -0,0 +1,2 @@ + +Every report now exports as CSV, up to 50000 rows in under 10 seconds. [c1, c3] diff --git a/tests/fixtures/site/records/pr-csv/run.json b/tests/fixtures/site/records/pr-csv/run.json new file mode 100644 index 0000000..0f1eb96 --- /dev/null +++ b/tests/fixtures/site/records/pr-csv/run.json @@ -0,0 +1,71 @@ +{ + "id": "pr-csv", + "source": { + "kind": "pull_request", + "title": "Add CSV export", + "link": "", + "author": "", + "received": "2026-11-19T14:06:00Z", + "do_not_say": [ + "beta price" + ], + "open_questions": [] + }, + "mode": "suggest", + "verdict": { + "decision": "write", + "tier": "launch", + "rule": 1, + "quote": "Add CSV export", + "reason": "" + }, + "claims": [ + { + "id": "c1", + "quote": "Any report now exports as CSV from the Export menu." + }, + { + "id": "c2", + "quote": "The export keeps the filters the user picked." + }, + { + "id": "c3", + "quote": "Exports up to 50000 rows finish in under 10 seconds in our tests." + } + ], + "gates": { + "blog": { + "contract": "gates/blog.md", + "owner_role": "content", + "check": {}, + "status": "Rejected" + }, + "changelog": { + "contract": "gates/changelog.md", + "owner_role": "marketing", + "check": {} + }, + "social": { + "contract": "gates/social.md", + "owner_role": "social", + "check": {}, + "status": "Drafted" + }, + "faq": { + "contract": "gates/faq.md", + "owner_role": "support", + "check": {} + } + }, + "steps": { + "snapshot": "done", + "verdict": "done", + "claims": "done", + "gates": {} + }, + "times": { + "received": "2026-11-19T14:06:00Z", + "verdict": "", + "proposed": "2026-11-19T14:07:08Z" + } +} diff --git a/tests/fixtures/site/records/pr-csv/snapshot.md b/tests/fixtures/site/records/pr-csv/snapshot.md new file mode 100644 index 0000000..fb582a8 --- /dev/null +++ b/tests/fixtures/site/records/pr-csv/snapshot.md @@ -0,0 +1,5 @@ +# Add CSV export + +Any report now exports as CSV from the Export menu. +The export keeps the filters the user picked. +Exports up to 50000 rows finish in under 10 seconds in our tests. diff --git a/tests/fixtures/site/records/pr-pdf/gates/changelog/draft.md b/tests/fixtures/site/records/pr-pdf/gates/changelog/draft.md new file mode 100644 index 0000000..7c16caf --- /dev/null +++ b/tests/fixtures/site/records/pr-pdf/gates/changelog/draft.md @@ -0,0 +1,2 @@ + +Reports export as PDF from the Export menu. [p1] diff --git a/tests/fixtures/site/records/pr-pdf/run.json b/tests/fixtures/site/records/pr-pdf/run.json new file mode 100644 index 0000000..8db3aff --- /dev/null +++ b/tests/fixtures/site/records/pr-pdf/run.json @@ -0,0 +1,44 @@ +{ + "id": "pr-pdf", + "source": { + "kind": "pull_request", + "title": "Add PDF export", + "link": "", + "author": "", + "received": "2026-11-17T17:02:00Z", + "do_not_say": [], + "open_questions": [] + }, + "mode": "suggest", + "verdict": { + "decision": "write", + "tier": "changelog", + "rule": 1, + "quote": "Add PDF export", + "reason": "" + }, + "claims": [ + { + "id": "p1", + "quote": "Any report now exports as PDF from the Export menu." + } + ], + "gates": { + "changelog": { + "contract": "gates/changelog.md", + "owner_role": "marketing", + "check": {} + } + }, + "steps": { + "snapshot": "done", + "verdict": "done", + "claims": "done", + "gates": {} + }, + "times": { + "received": "2026-11-17T17:02:00Z", + "verdict": "", + "proposed": "" + } +} diff --git a/tests/fixtures/site/records/pr-pdf/snapshot.md b/tests/fixtures/site/records/pr-pdf/snapshot.md new file mode 100644 index 0000000..e314640 --- /dev/null +++ b/tests/fixtures/site/records/pr-pdf/snapshot.md @@ -0,0 +1,3 @@ +# Add PDF export + +Any report now exports as PDF from the Export menu. diff --git a/tests/fixtures/site/records/pr-refactor/run.json b/tests/fixtures/site/records/pr-refactor/run.json new file mode 100644 index 0000000..90ee6a6 --- /dev/null +++ b/tests/fixtures/site/records/pr-refactor/run.json @@ -0,0 +1,33 @@ +{ + "id": "pr-refactor", + "source": { + "kind": "pull_request", + "title": "Refactor date helpers", + "link": "", + "author": "", + "received": "2026-11-17T11:15:00Z", + "do_not_say": [], + "open_questions": [] + }, + "mode": "suggest", + "verdict": { + "decision": "skip", + "tier": null, + "rule": 1, + "quote": "Refactor date helpers", + "reason": "Not user facing" + }, + "claims": [], + "gates": {}, + "steps": { + "snapshot": "done", + "verdict": "done", + "claims": "done", + "gates": {} + }, + "times": { + "received": "2026-11-17T11:15:00Z", + "verdict": "", + "proposed": "" + } +} diff --git a/tests/fixtures/site/records/pr-refactor/snapshot.md b/tests/fixtures/site/records/pr-refactor/snapshot.md new file mode 100644 index 0000000..47493ad --- /dev/null +++ b/tests/fixtures/site/records/pr-refactor/snapshot.md @@ -0,0 +1 @@ +# Refactor date helpers diff --git a/tests/fixtures/site/records/pr-rounding/gates/changelog/draft.md b/tests/fixtures/site/records/pr-rounding/gates/changelog/draft.md new file mode 100644 index 0000000..ffb9787 --- /dev/null +++ b/tests/fixtures/site/records/pr-rounding/gates/changelog/draft.md @@ -0,0 +1,3 @@ + +Totals on the pipeline report round to two decimals. [r1] +It is the best report on the market. diff --git a/tests/fixtures/site/records/pr-rounding/run.json b/tests/fixtures/site/records/pr-rounding/run.json new file mode 100644 index 0000000..43ba6f1 --- /dev/null +++ b/tests/fixtures/site/records/pr-rounding/run.json @@ -0,0 +1,44 @@ +{ + "id": "pr-rounding", + "source": { + "kind": "pull_request", + "title": "Fix totals rounding on the pipeline report", + "link": "", + "author": "", + "received": "2026-11-18T10:41:00Z", + "do_not_say": [], + "open_questions": [] + }, + "mode": "suggest", + "verdict": { + "decision": "write", + "tier": "changelog", + "rule": 1, + "quote": "Fix totals rounding on the pipeline report", + "reason": "" + }, + "claims": [ + { + "id": "r1", + "quote": "Totals on the pipeline report now round to two decimals." + } + ], + "gates": { + "changelog": { + "contract": "gates/changelog.md", + "owner_role": "marketing", + "check": {} + } + }, + "steps": { + "snapshot": "done", + "verdict": "done", + "claims": "done", + "gates": {} + }, + "times": { + "received": "2026-11-18T10:41:00Z", + "verdict": "", + "proposed": "" + } +} diff --git a/tests/fixtures/site/records/pr-rounding/snapshot.md b/tests/fixtures/site/records/pr-rounding/snapshot.md new file mode 100644 index 0000000..1ec596e --- /dev/null +++ b/tests/fixtures/site/records/pr-rounding/snapshot.md @@ -0,0 +1,3 @@ +# Fix totals rounding + +Totals on the pipeline report now round to two decimals. diff --git a/tests/fixtures/site/skill/gates/blog.md b/tests/fixtures/site/skill/gates/blog.md new file mode 100644 index 0000000..dccdec8 --- /dev/null +++ b/tests/fixtures/site/skill/gates/blog.md @@ -0,0 +1,7 @@ +# Blog post + +A small contract used only by the site builder tests. + +```json +{"owner_role": "content", "parts": ["title", "body"], "uncited": ["# "], "lines": [2, 10]} +``` diff --git a/tests/fixtures/site/skill/gates/changelog.md b/tests/fixtures/site/skill/gates/changelog.md new file mode 100644 index 0000000..cf28fca --- /dev/null +++ b/tests/fixtures/site/skill/gates/changelog.md @@ -0,0 +1,7 @@ +# Changelog + +A small contract used only by the site builder tests. + +```json +{"owner_role": "marketing", "parts": ["entry"], "uncited": [], "lines": [1, 5]} +``` diff --git a/tests/fixtures/site/skill/gates/faq.md b/tests/fixtures/site/skill/gates/faq.md new file mode 100644 index 0000000..92ea033 --- /dev/null +++ b/tests/fixtures/site/skill/gates/faq.md @@ -0,0 +1,7 @@ +# FAQ update + +A small contract used only by the site builder tests. + +```json +{"owner_role": "support", "parts": ["qa"], "uncited": ["## "], "lines": [2, 8]} +``` diff --git a/tests/fixtures/site/skill/gates/social.md b/tests/fixtures/site/skill/gates/social.md new file mode 100644 index 0000000..511be40 --- /dev/null +++ b/tests/fixtures/site/skill/gates/social.md @@ -0,0 +1,7 @@ +# Social post + +A small contract used only by the site builder tests. + +```json +{"owner_role": "social", "parts": ["post"], "uncited": [], "lines": [1, 3]} +``` diff --git a/tests/test_site.py b/tests/test_site.py new file mode 100644 index 0000000..1dfeda0 --- /dev/null +++ b/tests/test_site.py @@ -0,0 +1,320 @@ +"""The site builder, driven as a command: run records and Notion page states in, a static site out.""" + +import json +import re +import shutil +import subprocess +import sys +from html.parser import HTMLParser +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parents[1] +BUILD = ROOT / "skills/launch-content/scripts/build_site.py" +FIXTURES = ROOT / "tests/fixtures/site" + + +def build(out, notion=None, runs=None): + args = [sys.executable, str(BUILD), str(runs or FIXTURES / "records"), + "--notion", str(notion or FIXTURES / "notion.json"), + "--owners", str(FIXTURES / "owners.json"), + "--skill", str(FIXTURES / "skill"), + "--out", str(out)] + return subprocess.run(args, capture_output=True, text=True, encoding="utf-8") + + +VOID = {"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"} + + +class Keyed(HTMLParser): + """Collects the visible text of every element that carries data-key, and the text of the whole page.""" + + def __init__(self): + super().__init__() + self.open, self.text, self.classes, self.page = [], {}, {}, [] + + def handle_starttag(self, tag, attrs): + attrs = dict(attrs) + if tag in VOID: + self.handle_data(" ") + return + if "data-key" in attrs: + self.open.append([attrs["data-key"], 0]) + self.text[attrs["data-key"]] = "" + self.classes[attrs["data-key"]] = attrs.get("class", "") + elif self.open: + self.open[-1][1] += 1 + if tag in ("p", "li", "span", "div", "h1", "h2", "a", "b"): + self.handle_data(" ") + + def handle_endtag(self, tag): + if self.open: + if self.open[-1][1]: + self.open[-1][1] -= 1 + else: + self.open.pop() + + def handle_data(self, data): + self.page.append(data) + for key, _ in self.open: + self.text[key] += data + + +def squash(text): + return re.sub(r"\s+", " ", text).strip() + + +def parse(path): + parser = Keyed() + parser.feed(path.read_text(encoding="utf-8")) + return {k: squash(v) for k, v in parser.text.items()}, parser.classes, squash("".join(parser.page)) + + +@pytest.fixture(scope="module") +def site(tmp_path_factory): + out = tmp_path_factory.mktemp("site") + result = build(out) + assert result.returncode == 0, result.stderr + return out + + +@pytest.fixture(scope="module") +def board(site): + return parse(site / "index.html") + + +def test_board_is_a_grid_of_sources_by_the_four_gates(board): + text, classes, page = board + heads = [text[f"head/{g}"] for g in ("blog", "changelog", "social", "faq")] + assert [h.split(" Sandbox owner")[0] for h in heads] == ["Blog post", "Changelog", "Social post", "FAQ update"] + assert all("Sandbox owner" in h for h in heads) + rows = [k for k in text if k.startswith("row/")] + assert rows == ["row/pr-csv", "row/brief-seats", "row/pr-rounding", "row/pr-pdf", "row/brief-dashboards", "row/pr-refactor"] + assert [k for k in text if k.startswith("cell/pr-csv/")] == [f"cell/pr-csv/{g}" for g in ("blog", "changelog", "social", "faq")] + assert "Thu 14:06" in text["row/pr-csv"] + + +def test_board_keeps_the_desk_log_look(site): + design_tokens = ["--paper: #E9F0E0", "--slip: #FFFDF2", "Courier Prime", ".stamp.review", ".stamp.ask"] + built = (site / "index.html").read_text(encoding="utf-8") + assert all(token in built for token in design_tokens) + + +def test_each_cell_status_comes_from_notion_and_never_from_the_run_record(board): + text, _, _ = board + assert "READY TO POST" in text["cell/pr-csv/blog"] + assert "POSTED" in text["cell/pr-csv/changelog"] + assert "READY TO POST" in text["cell/pr-csv/social"] + assert "DRAFTED" in text["cell/brief-seats/blog"] + assert "NEEDS CHANGES" in text["cell/brief-seats/changelog"] + assert "REJECTED" in text["cell/pr-pdf/changelog"] + assert "DRAFTED" not in text["cell/pr-csv/social"] + assert "REJECTED" not in text["cell/pr-csv/blog"] + + +def test_an_unknown_notion_status_fails_the_build(tmp_path): + notion = json.loads((FIXTURES / "notion.json").read_text(encoding="utf-8")) + notion["pr-csv/blog"]["status"] = "Approved" + (tmp_path / "notion.json").write_text(json.dumps(notion), encoding="utf-8") + result = build(tmp_path / "out", notion=tmp_path / "notion.json") + assert result.returncode == 1 + assert 'pr-csv/blog has the Notion Status "Approved"' in result.stderr + + +def test_a_cell_shows_counts_round_owner_and_status_and_no_percentage(board): + text, _, _ = board + cell = text["cell/pr-csv/blog"] + assert "4 lines · 3 claims · 2/2 parts" in cell + assert "round 2" in cell + assert "Sandbox owner" in cell + assert "1 line · 2 claims · 1/1 parts" in text["cell/pr-csv/social"] + assert all("%" not in value for key, value in text.items() if key.startswith("cell/")) + + +def test_a_gate_with_no_page_and_a_failed_check_is_held_by_the_check(board): + text, _, _ = board + cell = text["cell/pr-rounding/changelog"] + assert "HELD BY THE CHECK" in cell + assert 'changelog line 3 cites no claim: "it is the best report on the market"' in cell + assert "DRAFTED" not in cell + + +def test_a_failed_check_holds_the_gate_even_when_notion_says_ready_to_post(tmp_path): + notion = json.loads((FIXTURES / "notion.json").read_text(encoding="utf-8")) + notion["pr-rounding/changelog"] = {"status": "Ready to post", "round": 1, "url": "https://www.notion.so/example"} + (tmp_path / "notion.json").write_text(json.dumps(notion), encoding="utf-8") + result = build(tmp_path / "out", notion=tmp_path / "notion.json") + assert result.returncode == 0, result.stderr + text, _, _ = parse(tmp_path / "out/index.html") + assert "HELD BY THE CHECK" in text["cell/pr-rounding/changelog"] + changelog = (tmp_path / "out/changelog/index.html").read_text(encoding="utf-8") + assert "pipeline report" not in changelog + + +def test_a_gate_the_verdict_did_not_open_is_an_empty_cell(board): + text, classes, _ = board + assert text["cell/pr-rounding/blog"] == "" + assert "is-empty" in classes["cell/pr-rounding/blog"] + + +def test_ask_and_skip_rows_span_the_gates_with_their_reason(board): + text, classes, _ = board + ask = text["row/brief-dashboards"] + assert "ASK" in ask and "2 questions for product" in ask + assert "Which plans get the faster dashboards?" in ask + assert "Is the old dashboard still available?" in ask + assert "is-ask" in classes["row/brief-dashboards"] + skip = text["row/pr-refactor"] + assert "SKIP" in skip and "Not user facing" in skip + assert "is-quiet" in classes["row/pr-refactor"] + assert not [k for k in text if k.startswith(("cell/brief-dashboards/", "cell/pr-refactor/"))] + + +def test_board_shows_the_mode_line_and_the_sandbox_line(board): + _, _, page = board + assert "Mode: Suggest · Autonomous locked" in page + assert "In this sandbox one person plays every owner." in page + + +def test_the_three_roadmap_columns_are_greyed_with_owner_role_and_one_file(board): + text, classes, _ = board + nexts = [k for k in text if k.startswith("next/")] + assert nexts == ["next/customer-email", "next/video-script", "next/site-animation"] + for key in nexts: + assert "adds one file" in text[key].lower() + assert "Owner:" in text[key] + assert "Customer email" in text["next/customer-email"] + assert classes["next"].split() == ["next"], "the roadmap sits in the dashed grey Next block" + assert all(text[key] in text["next"] for key in nexts) + + +def test_the_headline_counts_the_week(board): + _, _, page = board + assert "68s" in page.replace(" ", "") + assert "6 arrived" in page and "4 drafted · 1 asked · 1 skipped" in page + + +def test_the_open_slip_sends_the_reader_to_notion_and_makes_no_undo_claim(board): + _, _, page = board + assert "Review in Notion" in page + assert "cannot be undone" not in page + + +def test_a_blog_page_shows_each_line_next_to_its_quote(site): + text, _, page = parse(site / "blog/pr-csv/index.html") + html = (site / "blog/pr-csv/index.html").read_text(encoding="utf-8") + assert "

    CSV export for every report

    " in html + for sentence, claim, quote in [ + ("Any report now exports as CSV from the Export menu.", "c1", "Any report now exports as CSV from the Export menu."), + ("The export keeps the filters you picked.", "c2", "The export keeps the filters the user picked."), + ("In our tests, exports of up to 50000 rows finished in under 10 seconds.", "c3", + "Exports up to 50000 rows finish in under 10 seconds in our tests."), + ]: + assert re.search(re.escape(sentence) + rf'Owner sources

    ', page, re.S) + notion = json.loads((FIXTURES / "notion.json").read_text(encoding="utf-8")) + notion["pr-csv/blog"]["status"] = "Drafted" + (tmp_path / "notion.json").write_text(json.dumps(notion), encoding="utf-8") + assert build(tmp_path / "board", notion=tmp_path / "notion.json", runs=runs).returncode == 0 + slip = (tmp_path / "board/index.html").read_text(encoding="utf-8") + assert 'every plan this week."

    Owner sources

    ' in slip + + +def test_only_a_ready_to_post_or_posted_blog_gate_gets_a_page(site): + assert (site / "blog/pr-csv/index.html").is_file() + assert not (site / "blog/brief-seats").exists(), "a Drafted gate is not published" + + +def test_the_changelog_lists_published_entries_newest_first(tmp_path): + notion = json.loads((FIXTURES / "notion.json").read_text(encoding="utf-8")) + notion["brief-seats/changelog"]["status"] = "Posted" + (tmp_path / "notion.json").write_text(json.dumps(notion), encoding="utf-8") + assert build(tmp_path / "out", notion=tmp_path / "notion.json").returncode == 0 + text, _, _ = parse(tmp_path / "out/changelog/index.html") + assert [k for k in text if k.startswith("changelog/")] == ["changelog/pr-csv", "changelog/brief-seats"] + assert "Reports export as CSV from the Export menu." in text["changelog/pr-csv"] + assert "Managers can invite each rep to a team seat." in text["changelog/brief-seats"] + assert "PDF" not in "".join(text.values()), "a Rejected gate is not published" + + +def test_the_faq_lists_each_question_with_its_answer(site): + text, _, _ = parse(site / "faq/index.html") + assert text["faq/pr-csv/1"] == "Can I export a report as CSV? Yes, from the Export menu on any report. 1" + assert text["faq/pr-csv/2"] == "Does the export keep my filters? Yes, the export keeps the filters you picked. 2" + + +def test_a_social_card_has_its_text_and_a_copy_button(site): + html = (site / "social/index.html").read_text(encoding="utf-8") + text, _, _ = parse(site / "social/index.html") + assert "Every report now exports as CSV, up to 50000 rows in under 10 seconds." in text["social/pr-csv"] + assert re.search(r'', html) + assert 'id="social-pr-csv"' in html and "navigator.clipboard.writeText" in html + assert "social/brief-seats" not in text, "a Drafted gate is not published" + + +def test_a_passing_gate_with_no_notion_page_is_not_shown_as_drafted(tmp_path): + notion = json.loads((FIXTURES / "notion.json").read_text(encoding="utf-8")) + del notion["brief-seats/social"] + (tmp_path / "notion.json").write_text(json.dumps(notion), encoding="utf-8") + assert build(tmp_path / "out", notion=tmp_path / "notion.json").returncode == 0 + text, _, _ = parse(tmp_path / "out/index.html") + assert "NO PAGE YET" in text["cell/brief-seats/social"] + assert "DRAFTED" not in text["cell/brief-seats/social"] + + +def test_the_text_reader_closes_a_keyed_element_that_holds_a_line_break(): + parser = Keyed() + parser.feed('
    A
    B
    C
    ') + assert squash(parser.text["a"]) == "A B" + assert squash(parser.text["b"]) == "C" + + +def test_a_rebuild_removes_a_blog_page_whose_gate_is_no_longer_published(tmp_path): + out = tmp_path / "out" + assert build(out).returncode == 0 + assert (out / "blog/pr-csv/index.html").is_file() + notion = json.loads((FIXTURES / "notion.json").read_text(encoding="utf-8")) + notion["pr-csv/blog"]["status"] = "Rejected" + (tmp_path / "notion.json").write_text(json.dumps(notion), encoding="utf-8") + assert build(out, notion=tmp_path / "notion.json").returncode == 0 + assert not (out / "blog/pr-csv").exists() + + +def test_every_reference_on_a_published_page_reaches_a_target_on_that_page(site): + for page in ("blog/pr-csv/index.html", "changelog/index.html", "faq/index.html"): + html = (site / page).read_text(encoding="utf-8") + targets = set(re.findall(r'\bid="([^"]+)"', html)) + anchors = re.findall(r'href="#([^"]+)"', html) + assert all(anchor in targets for anchor in anchors), (page, anchors, targets) + + +@pytest.mark.parametrize("entry, problem", [ + ({"status": "Drafted", "round": "two"}, 'pr-csv/blog has the round "two", expected a whole number'), + ({"status": "Drafted", "round": None}, 'pr-csv/blog has the round "None", expected a whole number'), + ({"status": "Drafted", "round": 0}, 'pr-csv/blog has the round "0", expected a whole number'), + ({"status": "Drafted", "round": True}, 'pr-csv/blog has the round "True", expected a whole number'), + ("Drafted", "pr-csv/blog must be an object with status, round and url"), +]) +def test_a_malformed_notion_page_state_fails_the_build_with_its_key(tmp_path, entry, problem): + notion = json.loads((FIXTURES / "notion.json").read_text(encoding="utf-8")) + notion["pr-csv/blog"] = entry + (tmp_path / "notion.json").write_text(json.dumps(notion), encoding="utf-8") + result = build(tmp_path / "out", notion=tmp_path / "notion.json") + assert result.returncode == 1 + assert f"FAIL {problem}" in result.stderr