+ """
+ 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'
')
+ 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"""
+ """
+
+
+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}
+
"""
+
+
+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"""
+
+
+
+$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
' 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