From df2b83ac3e4c6af731d35a0f7bfc7abb78dd1a6f Mon Sep 17 00:00:00 2001 From: Gabriel Abreu Date: Mon, 16 Nov 2026 14:12:31 -0300 Subject: [PATCH 1/6] B-05 Build the grid board and the post pages from run records and Notion page states The site builder turns run records and recorded Notion page states into the desk log board (Sources by the four gates) and the blog, changelog, FAQ and social pages. Status comes only from Notion. A gate whose Draft fails the Check is held with its failing line and is never published. --- skills/launch-content/scripts/build_site.py | 448 ++++++++++++++++++ skills/launch-content/site/board.html | 252 ++++++++++ skills/launch-content/site/post.html | 120 +++++ tests/fixtures/site/notion.json | 47 ++ tests/fixtures/site/owners.json | 12 + .../site/records/brief-dashboards/run.json | 36 ++ .../site/records/brief-dashboards/snapshot.md | 1 + .../records/brief-seats/gates/blog/draft.md | 6 + .../brief-seats/gates/changelog/draft.md | 2 + .../records/brief-seats/gates/faq/draft.md | 3 + .../records/brief-seats/gates/social/draft.md | 2 + .../site/records/brief-seats/run.json | 70 +++ .../site/records/brief-seats/snapshot.md | 5 + .../site/records/pr-csv/gates/blog/draft.md | 6 + .../records/pr-csv/gates/changelog/draft.md | 3 + .../site/records/pr-csv/gates/faq/draft.md | 5 + .../site/records/pr-csv/gates/social/draft.md | 2 + tests/fixtures/site/records/pr-csv/run.json | 71 +++ .../fixtures/site/records/pr-csv/snapshot.md | 5 + .../records/pr-pdf/gates/changelog/draft.md | 2 + tests/fixtures/site/records/pr-pdf/run.json | 44 ++ .../fixtures/site/records/pr-pdf/snapshot.md | 3 + .../site/records/pr-refactor/run.json | 33 ++ .../site/records/pr-refactor/snapshot.md | 1 + .../pr-rounding/gates/changelog/draft.md | 3 + .../site/records/pr-rounding/run.json | 44 ++ .../site/records/pr-rounding/snapshot.md | 3 + tests/fixtures/site/skill/gates/blog.md | 7 + tests/fixtures/site/skill/gates/changelog.md | 7 + tests/fixtures/site/skill/gates/faq.md | 7 + tests/fixtures/site/skill/gates/social.md | 7 + tests/test_site.py | 248 ++++++++++ 32 files changed, 1505 insertions(+) create mode 100644 skills/launch-content/scripts/build_site.py create mode 100644 skills/launch-content/site/board.html create mode 100644 skills/launch-content/site/post.html create mode 100644 tests/fixtures/site/notion.json create mode 100644 tests/fixtures/site/owners.json create mode 100644 tests/fixtures/site/records/brief-dashboards/run.json create mode 100644 tests/fixtures/site/records/brief-dashboards/snapshot.md create mode 100644 tests/fixtures/site/records/brief-seats/gates/blog/draft.md create mode 100644 tests/fixtures/site/records/brief-seats/gates/changelog/draft.md create mode 100644 tests/fixtures/site/records/brief-seats/gates/faq/draft.md create mode 100644 tests/fixtures/site/records/brief-seats/gates/social/draft.md create mode 100644 tests/fixtures/site/records/brief-seats/run.json create mode 100644 tests/fixtures/site/records/brief-seats/snapshot.md create mode 100644 tests/fixtures/site/records/pr-csv/gates/blog/draft.md create mode 100644 tests/fixtures/site/records/pr-csv/gates/changelog/draft.md create mode 100644 tests/fixtures/site/records/pr-csv/gates/faq/draft.md create mode 100644 tests/fixtures/site/records/pr-csv/gates/social/draft.md create mode 100644 tests/fixtures/site/records/pr-csv/run.json create mode 100644 tests/fixtures/site/records/pr-csv/snapshot.md create mode 100644 tests/fixtures/site/records/pr-pdf/gates/changelog/draft.md create mode 100644 tests/fixtures/site/records/pr-pdf/run.json create mode 100644 tests/fixtures/site/records/pr-pdf/snapshot.md create mode 100644 tests/fixtures/site/records/pr-refactor/run.json create mode 100644 tests/fixtures/site/records/pr-refactor/snapshot.md create mode 100644 tests/fixtures/site/records/pr-rounding/gates/changelog/draft.md create mode 100644 tests/fixtures/site/records/pr-rounding/run.json create mode 100644 tests/fixtures/site/records/pr-rounding/snapshot.md create mode 100644 tests/fixtures/site/skill/gates/blog.md create mode 100644 tests/fixtures/site/skill/gates/changelog.md create mode 100644 tests/fixtures/site/skill/gates/faq.md create mode 100644 tests/fixtures/site/skill/gates/social.md create mode 100644 tests/test_site.py diff --git a/skills/launch-content/scripts/build_site.py b/skills/launch-content/scripts/build_site.py new file mode 100644 index 0000000..4b06835 --- /dev/null +++ b/skills/launch-content/scripts/build_site.py @@ -0,0 +1,448 @@ +"""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 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 Markdown 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.match(line): + continue + cited = check.CITATIONS.search(line) + body = (line[:cited.start()] if cited else line).strip() + mark = check.MARK.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 state.get("status") not in STATUS: + raise BuildError(f"{key} has the Notion Status \"{state.get('status')}\", expected one of {', '.join(STATUS)}") + return state + + +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.get("url", "") if state else "" + rounds = int(state.get("round", 1)) 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_words): + for number, line in enumerate((folder / "snapshot.md").read_text(encoding="utf-8").split("\n"), 1): + if check.find_run(check.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)} + 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'

    {quote_where(folder, check.words(claims[c][1]))}

    ' + 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
      {banned}
    \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}
    +

    Publishing cannot be undone.

    + Review and approve +
    +
    """ + + +def ref(claims, claim_id, root): + number = claims.get(claim_id, ("?",))[0] + return f'{number}' + + +def sentence(line, claims, root=""): + return f"

    {escape(line.text)}{''.join(ref(claims, c, root) 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) + sources = "\n".join(f"""
  • + {claims[c][0]} +
    +

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

    +

    {where}, {quote_where(folder, check.words(claims[c][1])).lower()}

    +
    +
  • """ 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) 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) 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} + 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 +
    + +
    +
    $company is a sample company.
    +
    +$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..9c2521f --- /dev/null +++ b/tests/test_site.py @@ -0,0 +1,248 @@ +"""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") + + +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 == "br": + self.handle_data(" ") + 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_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'Copy', 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"] From 6e000740d0c589460fe5c41ed3c2371c3eac592f Mon Sep 17 00:00:00 2001 From: Gabriel Abreu Date: Mon, 16 Nov 2026 14:23:42 -0300 Subject: [PATCH 2/6] B-05 Remove stale blog pages on rebuild, keep changelog and FAQ refs on the page, close keyed elements after a line break --- skills/launch-content/scripts/build_site.py | 19 +++++++----- tests/test_site.py | 32 ++++++++++++++++++++- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/skills/launch-content/scripts/build_site.py b/skills/launch-content/scripts/build_site.py index 4b06835..2fefb27 100644 --- a/skills/launch-content/scripts/build_site.py +++ b/skills/launch-content/scripts/build_site.py @@ -9,6 +9,7 @@ import argparse import json import re +import shutil import sys from datetime import datetime from html import escape @@ -261,13 +262,16 @@ def slip_html(folder, cell, owners): """ -def ref(claims, claim_id, root): - number = claims.get(claim_id, ("?",))[0] - return f'{number}' +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, root=""): - return f"

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

    " +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=""): @@ -336,7 +340,7 @@ def list_page(owners, title, current, entries, 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) for line in lines) + 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'])}

    @@ -357,7 +361,7 @@ def faq_entries(folder, run): return "\n".join(f"""
  • {escape(question)}

    -{chr(10).join(' ' + sentence(line, claims) for line in answer)} +{chr(10).join(' ' + sentence(line, claims, linked=False) for line in answer)}
  • """ for n, (question, answer) in enumerate(groups, 1)) @@ -415,6 +419,7 @@ def build(runs_folder, notion_path, owners_path, skill, out): 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} diff --git a/tests/test_site.py b/tests/test_site.py index 9c2521f..f2f1499 100644 --- a/tests/test_site.py +++ b/tests/test_site.py @@ -24,6 +24,9 @@ def build(out, notion=None, runs=None): 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.""" @@ -33,8 +36,9 @@ def __init__(self): def handle_starttag(self, tag, attrs): attrs = dict(attrs) - if tag == "br": + 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"]] = "" @@ -246,3 +250,29 @@ def test_a_passing_gate_with_no_notion_page_is_not_shown_as_drafted(tmp_path): 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) From 0adc809a3611a9ef22c91161a31bad6294d0e3ec Mon Sep 17 00:00:00 2001 From: Gabriel Abreu Date: Mon, 16 Nov 2026 14:27:21 -0300 Subject: [PATCH 3/6] B-05 Fail the build with the page key when a Notion page state is malformed --- skills/launch-content/scripts/build_site.py | 11 ++++++++--- tests/test_site.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/skills/launch-content/scripts/build_site.py b/skills/launch-content/scripts/build_site.py index 2fefb27..a5b60a4 100644 --- a/skills/launch-content/scripts/build_site.py +++ b/skills/launch-content/scripts/build_site.py @@ -102,9 +102,14 @@ 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)}") - return state + 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): @@ -116,8 +121,8 @@ def resolve(folder, run, gate, skill, notion): 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.get("url", "") if state else "" - rounds = int(state.get("round", 1)) if state else 1 + 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: diff --git a/tests/test_site.py b/tests/test_site.py index f2f1499..0893ed5 100644 --- a/tests/test_site.py +++ b/tests/test_site.py @@ -276,3 +276,17 @@ def test_every_reference_on_a_published_page_reaches_a_target_on_that_page(site) 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'), + ("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 From 2a495eb2d8e91c4cb047465882cee29fb0d0d960 Mon Sep 17 00:00:00 2001 From: Gabriel Abreu Date: Mon, 16 Nov 2026 14:42:54 -0300 Subject: [PATCH 4/6] B-05 Label the board button Review in Notion and drop the false undo line --- skills/launch-content/scripts/build_site.py | 3 +-- tests/test_site.py | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/skills/launch-content/scripts/build_site.py b/skills/launch-content/scripts/build_site.py index a5b60a4..004fc23 100644 --- a/skills/launch-content/scripts/build_site.py +++ b/skills/launch-content/scripts/build_site.py @@ -261,8 +261,7 @@ def slip_html(folder, cell, owners): {chr(10).join(first)} {more}{ban}
    -

    Publishing cannot be undone.

    - Review and approve + Review in Notion
    """ diff --git a/tests/test_site.py b/tests/test_site.py index 0893ed5..2827898 100644 --- a/tests/test_site.py +++ b/tests/test_site.py @@ -195,6 +195,12 @@ def test_the_headline_counts_the_week(board): 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") From 227de89f2b80b8523e854ef0d19133154585332c Mon Sep 17 00:00:00 2001 From: Gabriel Abreu Date: Mon, 16 Nov 2026 15:06:53 -0300 Subject: [PATCH 5/6] B-05 Read Draft lines and quotes with the merged Check's plain text grammar The merged Check replaced MARK and words with HEADING, plain_words and source_words. The builder now uses them, so a heading mark, a quote and a Snapshot line are read the way the Check reads them. --- skills/launch-content/scripts/build_site.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/skills/launch-content/scripts/build_site.py b/skills/launch-content/scripts/build_site.py index 004fc23..b4891a5 100644 --- a/skills/launch-content/scripts/build_site.py +++ b/skills/launch-content/scripts/build_site.py @@ -44,7 +44,7 @@ class BuildError(Exception): class Shown(NamedTuple): - """One Draft line as a reader sees it: its Markdown mark, its text without citations, and its claim ids.""" + """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, ...] @@ -70,11 +70,11 @@ def shown_lines(text): lines = [] for raw in text.replace("\r\n", "\n").split("\n"): line = raw.strip() - if not line or check.PART.match(line): + 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.MARK.match(body) + 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 @@ -224,7 +224,7 @@ def clock_html(runs): def quote_where(folder, claim_words): for number, line in enumerate((folder / "snapshot.md").read_text(encoding="utf-8").split("\n"), 1): - if check.find_run(check.words(line), claim_words) >= 0: + if check.find_run(check.source_words(line), claim_words) >= 0: return f"Snapshot, line {number}" return "Snapshot" @@ -236,7 +236,7 @@ def slip_html(folder, cell, owners): 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'

    {quote_where(folder, check.words(claims[c][1]))}

    ' + f'

    {quote_where(folder, check.plain_words(claims[c][1]))}

    ' for c in line.claims if c in claims) title = " is-title" if index == 0 and line.mark.startswith("#") else "" rows.append(f"""
  • @@ -300,7 +300,7 @@ def blog_page(folder, cell, owners, also, nav_links): {claims[c][0]}

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

    -

    {where}, {quote_where(folder, check.words(claims[c][1])).lower()}

    +

    {where}, {quote_where(folder, check.plain_words(claims[c][1])).lower()}

  • """ for c in cited) links = [f'the {label}' for gate, page, label in From 1763c449beff2a3dcc9c3e45c1a6e4d816dad7be Mon Sep 17 00:00:00 2001 From: Gabriel Abreu Date: Mon, 16 Nov 2026 15:21:35 -0300 Subject: [PATCH 6/6] B-05 Label owner claim quotes as Owner sources, test round 0 and true An owner claim's quote lives in its gate's owner_sources, as check.py checks it, so the blog page and the board slip now say Owner sources for it and skip the Snapshot search. Two malformed-state rows cover a round of 0 and a round of true. --- skills/launch-content/scripts/build_site.py | 13 +++++++++--- tests/test_site.py | 22 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/skills/launch-content/scripts/build_site.py b/skills/launch-content/scripts/build_site.py index b4891a5..bbc5838 100644 --- a/skills/launch-content/scripts/build_site.py +++ b/skills/launch-content/scripts/build_site.py @@ -222,7 +222,11 @@ def clock_html(runs): return f'
    {took}\n {week}\n
    ' -def quote_where(folder, claim_words): +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}" @@ -232,11 +236,12 @@ def quote_where(folder, claim_words): 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'

    {quote_where(folder, check.plain_words(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"""
  • @@ -296,11 +301,13 @@ def blog_page(folder, cell, owners, also, nav_links): 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])}"

    -

    {where}, {quote_where(folder, check.plain_words(claims[c][1])).lower()}

    +

    {places[c]}

  • """ for c in cited) links = [f'the {label}' for gate, page, label in diff --git a/tests/test_site.py b/tests/test_site.py index 2827898..1dfeda0 100644 --- a/tests/test_site.py +++ b/tests/test_site.py @@ -216,6 +216,26 @@ def test_a_blog_page_shows_each_line_next_to_its_quote(site): assert "Ready to post" in page and "approved by Sandbox owner" in page +def test_an_owner_claim_names_the_owner_sources_on_the_blog_page_and_the_slip(tmp_path): + runs = tmp_path / "records" + shutil.copytree(FIXTURES / "records", runs) + record = json.loads((runs / "pr-csv/run.json").read_text(encoding="utf-8")) + record["claims"].append({"id": "c4", "gate": "blog", "quote": "CSV export ships to every plan this week."}) + record["gates"]["blog"]["owner_sources"] = "CSV export ships to every plan this week." + (runs / "pr-csv/run.json").write_text(json.dumps(record), encoding="utf-8") + with (runs / "pr-csv/gates/blog/draft.md").open("a", encoding="utf-8") as draft: + draft.write("CSV export ships to every plan this week. [c4]\n") + assert build(tmp_path / "out", runs=runs).returncode == 0 + page = (tmp_path / "out/blog/pr-csv/index.html").read_text(encoding="utf-8") + assert re.search(r'id="c4".*?

    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" @@ -287,6 +307,8 @@ def test_every_reference_on_a_published_page_reaches_a_target_on_that_page(site) @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):