diff --git a/.github/workflows/flow-changelog-watch.yml b/.github/workflows/flow-changelog-watch.yml new file mode 100644 index 000000000..59a457cc9 --- /dev/null +++ b/.github/workflows/flow-changelog-watch.yml @@ -0,0 +1,49 @@ +name: Flow changelog watch + +# Flow announces product changes (models added or retired, composer and settings changes) +# on flow.google.com/changelogs. gflow drives Flow's private surfaces, so an entry there is +# often the first warning of a change that will break a command. The entries ship in the +# public shell bundle, so this job reads them with no account and no browser and opens one +# issue per new entry (label `flow-changelog`). A bundle that stops parsing fails the run. +# Spike: docs/superpowers/spikes/2026-12-05-changelog-bundle-discovery.md + +on: + schedule: + - cron: "30 6 * * *" # daily, 06:30 UTC + workflow_dispatch: + inputs: + dry_run: + description: "print the issue plan without opening issues" + type: boolean + default: false + +permissions: + contents: read + +# A manual run overlapping the schedule could open the same issue twice. +concurrency: + group: flow-changelog-watch + cancel-in-progress: false + +jobs: + flow-changelog: + name: Open an issue per new Flow changelog entry + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + issues: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + + - name: Install uv + uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 + + - name: Read the changelog entries and open issues for new ones + env: + GH_TOKEN: ${{ github.token }} + DRY_RUN: ${{ inputs.dry_run && '--dry-run' || '' }} + # Standard library only, so no project install is needed. + run: uv run --no-project --python 3.13 python scripts/ci/flow_changelog_watch.py $DRY_RUN diff --git a/CHANGELOG.md b/CHANGELOG.md index c91d9b6d3..1f0a13091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- **A daily `flow-changelog` job opens one issue per new entry on + flow.google.com/changelogs.** Flow announces model, composer and settings changes there, + often before a gflow command breaks on them. The entries ship in the public shell bundle, + so the job reads them with no account and no browser + ([spike](docs/superpowers/spikes/2026-12-05-changelog-bundle-discovery.md)). Entries that + existed when the job started are in a committed baseline; each later entry gets one + `flow-changelog` issue, keyed by the entry's id, and is never announced twice, even after + its issue is closed, as long as the issue keeps its label and its id marker. A bundle that + stops parsing, or more than five new entries at once, fails the run. `workflow_dispatch` with + `dry_run` prints the plan only ([#1800](https://github.com/ffroliva/gflow-cli/issues/1800)). + ### Changed - A usage error found while a generation command runs (an unknown `--tool`, a tool that does diff --git a/docs/FLOW_WIRE_RPCS.md b/docs/FLOW_WIRE_RPCS.md index 7ea43388d..5b8e7cc71 100644 --- a/docs/FLOW_WIRE_RPCS.md +++ b/docs/FLOW_WIRE_RPCS.md @@ -102,6 +102,7 @@ not driven. | Every commit and CI run | Every RPC id constant in `src/` has a row | `tests/test_flow_wire_rpcs_catalog.py` | | A spike sees an id that matters | Add a row with its evidence, or list it below | the spike skill | | Every night | Check every id in this table against the served JS with no cookies and no browser, record the build label, and archive the build's full descriptor list with what changed since the last build | the canary's `RPC-DRIFT` section (`scripts/canary/rpc_drift.py`, #1218); see [E2E_TESTING.md](E2E_TESTING.md#rpc-drift-check-1218) | +| Every day | Read the entries of `flow.google.com/changelogs` from the cookieless shell bundle and open one `flow-changelog` issue per new entry; an entry announcing a model, composer or wire change is the earliest warning of a change to this table | the `flow-changelog` job (`.github/workflows/flow-changelog-watch.yml`, `scripts/ci/flow_changelog_watch.py`, #1800); see the [bundle-discovery spike](superpowers/spikes/2026-12-05-changelog-bundle-discovery.md) | | `RPC-DRIFT` reports `ID-GONE` | First confirm with a page load (the served-JS spike's arm 2) that the id did not move to a module outside the four. If it is still absent, set `Status` to `gone` or `renamed -> X`, fill `Renamed from` on the new row, and update `Last verified` | a maintainer, from the canary comment. The canary never edits this file. | The served app holds about 267 ids in the RPC descriptor shape (`{Wa:"",hb:…,Za:!0,Xa:…,kb:…}` diff --git a/docs/superpowers/spikes/2026-12-05-changelog-bundle-discovery.md b/docs/superpowers/spikes/2026-12-05-changelog-bundle-discovery.md new file mode 100644 index 000000000..241412673 --- /dev/null +++ b/docs/superpowers/spikes/2026-12-05-changelog-bundle-discovery.md @@ -0,0 +1,64 @@ +# Spike: finding the changelog entries without a profile (#1800) + +**Date:** 2026-12-05 · **Account:** none (cookieless) · **Cost:** $0, no browser +· **Script:** [`scripts/dev/spike_changelog_bundle_discovery.py`](../../../scripts/dev/spike_changelog_bundle_discovery.py) +· **Follows:** the changelog section of the 2026-12-05 spike on the direct project lifecycle and +the changelog feed (#1229), which found the entries inside one public +`/_/mss/boq-labs-ai-sandbox/_/js/` bundle by loading `/changelogs` on a signed-in profile, and +left open how a client with no profile finds that bundle. + +## Question + +Does the shell that `flow.google.com` serves without cookies name the bundle that carries the +changelog entries, the way it names the script `scripts/canary/rpc_drift.py` reads? + +**Pre-registered reading:** if a script reachable from the cookieless shell carries the known +entry text, the watcher fetches that script and needs no profile. If none does, the entries live +in a module the shell does not name, and the next step is to find that module's name. + +## Method + +`httpx` GETs with no cookies and an `en-US` `Accept-Language`, for `https://flow.google.com/` and +`https://flow.google.com/changelogs`. For each page, every `/_/js/` script the shell names was +fetched as served, and again with `m=` replaced by `rpc_drift.FEATURE_MODULES`. Each response was +searched for the entry text found on the profile run. + +## Results + +| Shell | Script | Status | Length | Entry text | +|---|---|---|---|---| +| `/` | as served | 200 | 1,460,318 | present | +| `/` | feature modules | 200 | 6,615,641 | present | +| `/changelogs` | as served | 200 | 1,460,318 | present | +| `/changelogs` | feature modules | 200 | 6,615,641 | present | + +Both shells name the same single `/_/js/` script. The entries are an object-literal array in it: + +```js +var yzb=[{title:"…",date:"12/4/2026",id:"2026-12-03-v0-…"}, …] +``` + +- The variable name is minified and changes between builds. +- The minifier sometimes breaks the line before `id:`. +- Titles keep JavaScript escapes (`\u2026`). +- Dates are `M/D/YYYY`. + +A parser that allows whitespace between the keys reads 46 entries, with 46 distinct ids, matching +every `{title:"` in the script. + +Each entry's page is public at +`https://www.gstatic.com/aitestkitchen/website/flow/changelogs/.html`. The script builds that +URL for the app's changelog dialog, and a cookieless GET of the newest entry's page returned 200. + +The profile run of the earlier spike was served a Portuguese build of the same script (`pt`), +whose entries were in English too. The newest entry it rendered was older than the newest +entry in the `en_US` build read here. The two locale builds can carry different entry sets at +the same moment, so the watcher reads one fixed locale (`en-US`). + +## Consequences + +- A changelog watcher needs no account, no profile and no browser. It runs on hosted CI. +- The watcher keys entries by `id`. Titles and dates are display text. +- An empty parse means the format changed, so the watcher fails rather than report nothing new. +- **Not measured:** whether Flow edits an entry's title or date after publishing it. The + watcher opens an issue once per `id` and does not track later edits. diff --git a/scripts/ci/flow_changelog_baseline.json b/scripts/ci/flow_changelog_baseline.json new file mode 100644 index 000000000..0029add85 --- /dev/null +++ b/scripts/ci/flow_changelog_baseline.json @@ -0,0 +1,48 @@ +[ + "07_21_26_community_tools_launch_9d1984d6-624e-44b6-8671-2d4ce48868b2", + "08-26-26_omni_439461c7-439a-4e04-8f2e-8fc288897eb6", + "17b37e91-79b4-4845-8bd7-469929d5fec4", + "2025-02-03-v0-9a65f3ee-0db3-452a-87e2-19992e599e0f", + "2025-08-18-v0-9fe8aadb-aae6-46c7-bf0d-a8fe11ce18d5", + "2025-08-21-v0-80f5e009-a545-4476-bd7f-53842fbe952c", + "2025-08-26-v0-3fd83e53-2581-4352-b491-6a4a1ced375b", + "2025-09-10-v0-8b89f37b-f7ba-4819-801c-0f04ef578af7", + "2025-09-24-828276e9-0e5f-4868-a742-63cb4b05f8e6", + "2025-10-09-87762944-d2df-4666-b68e-4541d589aabc", + "2025-10-15-b9a851d-9fbb-49bb-95f9-270cbb9af9a8", + "2025-10-21-a41845ef-8e78-4f98-a0dc-64ea45f784ee", + "2025-10-28-v0-e56a33b0-7130-4be8-b58f-028712e5a253", + "2025-11-04-v0-ec25c664-fad7-4522-8d00-4e76e49ce5f8", + "2025-11-11-v0-baacbeac-33b6-4fad-96b7-4d517bf0c10a", + "2025-11-18-6a99b1dd-38fb-4faf-9bc5-28399303b7a7", + "2025-11-18-v0-5e3eb06f-e319-40d9-a277-1dfd3252a1fb", + "2025-11-20-v0-7d5dd0f1-f2d2-43a3-b255-233d2e7a3110", + "2025-11-21-v0-5077d03d-7c92-4620-a828-615891c937f3", + "2025-11-25-v0-4925732e-93b3-4765-bfcf-e597a9a93ac5", + "2025-12-02-v0-0761a040-c6c0-4d62-b1a4-310345da8878", + "2025-12-15-v0-333d6813-a2ef-4044-939c-c8c40661499f", + "2025-12-18-v0-e2054626-1ac3-4d64-81ec-3134a94549a4", + "2026-02-25b-8937c021-a92d-4e0f-8913-de655d126fce", + "2026-02-26b-a3b642ff-0d15-4f29-85aa-d92488c95033", + "2026-03-02-dbb81d57-8cb5-467b-8558-fa49e99f6662", + "2026-03-19-v1-3f4e036c-6a67-467f-a0e6-25cff0a0a8ab", + "2026-03-30-v0-72511146-ea4a-4b0b-808c-0851d8217471", + "2026-04-02-v0-f77616c4-b8ce-4e6d-9687-c23bd40baa32", + "2026-04-10-v0-e46f75f7-e0d4-4202-98e7-8985a8bea150", + "2026-04-16-v0-a8bcba80-04c0-4a1e-843b-bd3b8de74582", + "2026-04-21-v0-d3ad0784-1b05-4800-870e-c2e71a26e08f", + "2026-04-28-v0-08018419-2523-4641-976f-6293a72c7524", + "2026-05-16-v0-80e87fe8-f14b-4172-b2fb-58d89b010701", + "2026-06-04-v0-592e1b5a-8b61-4144-bdb6-946348b48e56", + "2026-06-10-v1-02b0b08c-06d1-47e5-b8f5-4cd8cab6c4bc", + "2026-06-23-v0-geo-street-5fb1f3c2-5f1b-469b-8492-6566d8d0d7e3", + "2026-09-03-v1-angular-2447aa1d-5f7d-4565-adf4-b1fa6efffd49", + "2026-09-09-v0-ios-launch-3d6a1b86-7198-4e1e-b000-e735ffe9e7cb", + "2026-11-02-v0-asset-management-b42e38ef-50c6-46f4-ac49-0325a661f859", + "2026-11-05-v0-119a1844-21e0-46dc-8495-b80da900395f", + "2026-11-19-v0-c8e4b912-7a3f-4e68-9d21-5f4a83b19c07", + "2026-12-03-v0-fbb13edf-cc2d-4b2f-899e-494e82b2d37d", + "5962e32c-5f59-47ca-b1b7-a9bdb8b924da", + "c54785a2-405c-4fb7-b69d-1fa40e3ecb93", + "tools-nb2lite-2026-07-01-a18bf458-e7f9-4abf-a2df-07686f573f02" +] diff --git a/scripts/ci/flow_changelog_watch.py b/scripts/ci/flow_changelog_watch.py new file mode 100644 index 000000000..8aa48fb2c --- /dev/null +++ b/scripts/ci/flow_changelog_watch.py @@ -0,0 +1,223 @@ +"""Open one GitHub issue per new entry on flow.google.com/changelogs. + +Flow announces product changes (new models, retired ones, UI changes) on its changelog page. +The entries ship inside the public shell bundle, which answers without cookies +(docs/superpowers/spikes/2026-12-05-changelog-bundle-discovery.md), so this job needs no +account and no browser. Each entry not in the committed baseline and not already named by a +``flow-changelog`` issue gets one issue. ``--dry-run`` prints the plan and changes nothing. + +A bundle that no longer parses fails the run (exit 2): an empty parse, an entry in another +shape or an undecodable title means the format changed, never that nothing is new. So do +more than ``MAX_NEW`` new entries at once (a re-keyed bundle or a lost baseline) and an issue +listing that reaches ``ISSUE_LIMIT`` (older markers may be missing). Standard library only. +""" + +from __future__ import annotations + +import argparse +import json +import re +import subprocess +import sys +import urllib.request +from dataclasses import dataclass +from pathlib import Path +from urllib.parse import urljoin + +SHELL = "https://flow.google.com/" +CHANGELOG_PAGE = "https://flow.google.com/changelogs" +#: Each entry's own page, as the app's changelog dialog loads it. +DETAIL_URL = "https://www.gstatic.com/aitestkitchen/website/flow/changelogs/" +LABEL = "flow-changelog" +MAX_NEW = 5 +ISSUE_LIMIT = 1000 +BASELINE = Path(__file__).with_name("flow_changelog_baseline.json") +UA = ( + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36" +) + +_SCRIPT_RE = re.compile(r']+src="([^"]*/_/js/[^"]*)"') +# `{title:"…",date:"M/D/YYYY",id:"…"}`; the minifier may break a line between keys. +_ENTRY_RE = re.compile( + r'\{\s*title:"((?:[^"\\]|\\.)*)",\s*date:"(\d{1,2}/\d{1,2}/\d{4})",\s*id:"([^"\\]+)"\s*\}' +) +_OPEN_RE = re.compile(r'\{\s*title:"') +# One escape pair at a time, so an escaped backslash is never read as the start of `\x`. +_ESCAPE_RE = re.compile(r"\\(x[0-9a-fA-F]{2}|.)") + + +class FormatChangedError(ValueError): + """The bundle's entries no longer read the way the watcher expects.""" + + +@dataclass(frozen=True) +class Entry: + id: str + title: str + date: str + + +def script_url(shell_html: str, base: str) -> str | None: + m = _SCRIPT_RE.search(shell_html) + return urljoin(base, m.group(1).replace("&", "&")) if m else None + + +def _json_escape(m: re.Match[str]) -> str: + """Rewrite the two JavaScript escapes JSON lacks (`\\xHH`, `\\'`); keep every other pair.""" + code = m.group(1) + if code == "'": + return "'" + return "\\u00" + code[1:] if len(code) == 3 else m.group(0) + + +def _decode(raw: str) -> str: + try: + text = json.loads('"' + _ESCAPE_RE.sub(_json_escape, raw) + '"') + text.encode("utf-8") # a lone surrogate cannot become an issue title + except (ValueError, UnicodeEncodeError) as err: + raise FormatChangedError(f"undecodable title: {raw!r}") from err + return str(text) + + +def entries(bundle: str) -> list[Entry]: + """The changelog entries in bundle order (newest first), JS string escapes decoded. + + Raises ``FormatChangedError`` when an entry opens the known way but does not parse.""" + found = [ + Entry(entry_id, _decode(title), date) for title, date, entry_id in _ENTRY_RE.findall(bundle) + ] + opened = len(_OPEN_RE.findall(bundle)) + if opened != len(found): + raise FormatChangedError(f"{opened} entries open, {len(found)} parse") + return found + + +def marker(entry_id: str) -> str: + return f"" + + +def title(entry: Entry) -> str: + return f"Flow changelog: {entry.title} ({entry.date})" + + +def plan(found: list[Entry], issues: list[dict[str, object]], baseline: set[str]) -> list[Entry]: + """New entries, oldest first. An issue in any state names its entry: a closed one is + never reopened or duplicated.""" + named = "\n".join(str(issue.get("body", "")) for issue in issues) + return [e for e in reversed(found) if e.id not in baseline and marker(e.id) not in named] + + +def body(entry: Entry) -> str: + return ( + f"Flow published a changelog entry: **{entry.title}** ({entry.date}).\n\n" + f"- Entry: {DETAIL_URL}{entry.id}.html\n" + f"- All entries: {CHANGELOG_PAGE}\n\n" + "Read it and decide whether it changes a surface gflow drives: a model added or " + "retired, a composer or settings change, a new tool, or a wire change. If it does, " + "open a spike or a fix and link it here; otherwise close this issue as not planned.\n\n" + "This issue is opened by the scheduled `flow-changelog` job " + "(`.github/workflows/flow-changelog-watch.yml`).\n\n" + "Keep this marker and the `flow-changelog` label: the job reads them so it never " + "opens this entry again.\n" + f"{marker(entry.id)}\n" + ) + + +def load_baseline() -> set[str]: + """The entries that existed when the watch started, so its first run opens nothing.""" + return set(json.loads(BASELINE.read_text(encoding="utf-8"))) + + +def _fetch(url: str) -> str: + req = urllib.request.Request( # noqa: S310 - fixed https URLs + url, headers={"User-Agent": UA, "Accept-Language": "en-US,en;q=0.9"} + ) + with urllib.request.urlopen(req, timeout=60) as resp: # noqa: S310 - fixed https URLs + return resp.read().decode("utf-8", errors="replace") + + +def _gh(*args: str, stdin: str | None = None) -> str: + done = subprocess.run( # noqa: S603 - argv list, no shell + ["gh", *args], # noqa: S607 - gh from the runner's PATH + input=stdin, + capture_output=True, + text=True, + check=False, + ) + if done.returncode: + sys.stderr.write(done.stderr) + done.check_returncode() + return done.stdout + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--dry-run", action="store_true", help="print the plan only") + args = parser.parse_args(argv) + + url = script_url(_fetch(SHELL), SHELL) + if url is None: + print("PARSE-CHANGED: the flow.google.com shell names no /_/js/ bundle", file=sys.stderr) + return 2 + try: + found = entries(_fetch(url)) + except FormatChangedError as err: + print(f"PARSE-CHANGED: {err}", file=sys.stderr) + return 2 + if not found: + print("PARSE-CHANGED: the shell bundle holds no changelog entries", file=sys.stderr) + return 2 + issues = json.loads( + _gh( + "issue", + "list", + "--label", + LABEL, + "--state", + "all", + "--limit", + str(ISSUE_LIMIT), + "--json", + "number,body", + ) + ) + if len(issues) >= ISSUE_LIMIT: + print(f"LISTING-FULL: {len(issues)} {LABEL} issues; raise ISSUE_LIMIT", file=sys.stderr) + return 2 + new = plan(found, issues, load_baseline()) + print(f"entries: {len(found)}; new: {len(new)}") + if len(new) > MAX_NEW: + print(f"TOO-MANY-NEW: {len(new)} > {MAX_NEW}; check the baseline", file=sys.stderr) + return 2 + for entry in new: + print("create", title(entry)) + if args.dry_run or not new: + return 0 + _gh( + "label", + "create", + LABEL, + "--force", + "--color", + "BFD4F2", + "--description", + "An entry on flow.google.com/changelogs", + ) + for entry in new: + _gh( + "issue", + "create", + "--title", + title(entry), + "--label", + LABEL, + "--body-file", + "-", + stdin=body(entry), + ) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/dev/spike_changelog_bundle_discovery.py b/scripts/dev/spike_changelog_bundle_discovery.py new file mode 100644 index 000000000..dacd36443 --- /dev/null +++ b/scripts/dev/spike_changelog_bundle_discovery.py @@ -0,0 +1,71 @@ +"""Spike (#1800): can a cookieless client find the bundle that carries flow.google.com/changelogs? + +The 2026-12-05 spike found the changelog entries inside one public +``/_/mss/boq-labs-ai-sandbox/_/js/`` bundle, by loading the page on a signed-in profile. A +watcher on hosted CI has no profile, so it must find that bundle from the cookieless shell, as +``scripts/canary/rpc_drift.py`` finds its descriptor bundle. + +Arms, each a cookieless ``httpx`` GET, $0, no browser, no account: + +* ``shell``: the cookieless shell's own ``/_/js/`` script URL, as served. +* ``features``: that URL with ``m=`` swapped for ``rpc_drift.FEATURE_MODULES``. +* ``changelogs``: the shell served for ``/changelogs`` (it redirects to ``/about`` on the client, + but the server may still name other scripts). + +For each fetched script: its length and how many ``changelog``-shaped markers it carries: +the known entry text ``MARKER`` and dates written as ``Month D, YYYY``. + +Pre-registered reading: + +* an arm's script carries ``MARKER`` -> the watcher fetches that URL, no profile needed. +* no arm carries it -> the entries live in a module the shell does not name; record the + module list and look for the changelog module's name in the shell or base script next. +""" + +from __future__ import annotations + +import re +import sys +from urllib.parse import urljoin + +import httpx + +sys.path.insert(0, "scripts/canary") +import rpc_drift # noqa: E402 + +#: Public entry text after the first date on /changelogs (the 2026-12-05 profile arm). +MARKER = "Easier asset management: undo," +_DATE_RE = re.compile( + r"(?:January|February|March|April|May|June|July|August|September|October|November|December)" + r" \d{1,2}, 20\d\d" +) +_SCRIPTS_RE = re.compile(r']+src="([^"]+)"') + + +def scan(label: str, url: str, client: httpx.Client) -> None: + resp = client.get(url) + text = resp.text + path = url.split("gstatic.com")[-1] + print( + f"{label}: {resp.status_code} len={len(text)} marker={MARKER in text} " + f"dates={len(_DATE_RE.findall(text))} path={path[:160]}" + ) + + +def main() -> None: + headers = {"User-Agent": rpc_drift.UA, "Accept-Language": "en-US,en;q=0.9"} + with httpx.Client(headers=headers, follow_redirects=True, timeout=60) as client: + for page in ("https://flow.google.com/", "https://flow.google.com/changelogs"): + shell = client.get(page) + srcs = [urljoin(page, s.replace("&", "&")) for s in _SCRIPTS_RE.findall(shell.text)] + js = [s for s in srcs if "/_/js/" in s] + print(f"\n{page} -> {shell.status_code} scripts={len(srcs)} js={len(js)}") + for i, src in enumerate(js): + scan(f" shell[{i}]", src, client) + features = rpc_drift.bundle_url(shell.text, page) + if features: + scan(" features", features, client) + + +if __name__ == "__main__": + main() diff --git a/tests/scripts/test_flow_changelog_watch.py b/tests/scripts/test_flow_changelog_watch.py new file mode 100644 index 000000000..8b02ffd19 --- /dev/null +++ b/tests/scripts/test_flow_changelog_watch.py @@ -0,0 +1,187 @@ +"""Unit tests for the Flow changelog watch (scripts/ci/flow_changelog_watch.py). + +Flow announces product changes on flow.google.com/changelogs; the entries ship inside the +public shell bundle (spike 2026-12-05). This job turns each new entry into one issue. +Offline: no network, no `gh`. +""" + +from __future__ import annotations + +import json + +import pytest + +from scripts.ci import flow_changelog_watch as cw + +# Two entries in the bundle's own shape: the minifier sometimes breaks the line before `id`. +_BUNDLE = ( + 'var yzb=[{title:"Side-by-side Tools",date:"12/4/2026",id:"2026-12-03-v0-aaa"},' + '{title:"Introducing\\u2026 Veo 3.1!",date:"10/29/2025",\nid:"2025-10-28-v0-bbb"}];' +) + + +def test_entries_are_read_in_both_minified_shapes_with_escapes_decoded() -> None: + assert cw.entries(_BUNDLE) == [ + cw.Entry("2026-12-03-v0-aaa", "Side-by-side Tools", "12/4/2026"), + cw.Entry("2025-10-28-v0-bbb", "Introducing… Veo 3.1!", "10/29/2025"), + ] + + +@pytest.mark.parametrize( + ("raw", "decoded"), + [ + # Raw strings: the bundle holds the backslash escapes, not the characters. + (r"a \x3c b \x3e c", "a < b > c"), # the minifier writes `<`, `>` and NBSP as \xHH + (r"it\'s", "it's"), + (r"a \\x41 b", r"a \x41 b"), # an escaped backslash is not the start of \x + (r"caf\u00e9 \ud83c\udf4c", "caf\u00e9 \U0001f34c"), + ], +) +def test_js_escapes_json_lacks_are_decoded(raw: str, decoded: str) -> None: + bundle = f'{{title:"{raw}",date:"1/2/2026",id:"x"}}' + assert cw.entries(bundle) == [cw.Entry("x", decoded, "1/2/2026")] + + +@pytest.mark.parametrize("raw", [r"\u{1F34C}", r"\ud83d alone", r"\0"]) +def test_an_escape_that_cannot_be_decoded_is_a_format_change(raw: str) -> None: + with pytest.raises(cw.FormatChangedError): + cw.entries(f'{{title:"{raw}",date:"1/2/2026",id:"x"}}') + + +def test_a_title_that_cannot_be_decoded_fails_the_run(monkeypatch: pytest.MonkeyPatch) -> None: + bad = r'{title:"\u{1F34C}",date:"1/2/2026",id:"x"}' + pages = {cw.SHELL: ''} + monkeypatch.setattr(cw, "_fetch", lambda url: pages.get(url, bad)) + monkeypatch.setattr(cw, "_gh", _no_gh) + assert cw.main(["--dry-run"]) == 2 + + +def test_more_new_entries_than_the_cap_fail_the_run_and_open_nothing( + monkeypatch: pytest.MonkeyPatch, +) -> None: + # A re-keyed bundle or an emptied baseline must not open dozens of issues. + many = "".join( + f'{{title:"T{i}",date:"1/{i + 1}/2026",id:"id-{i}"}},' for i in range(cw.MAX_NEW + 1) + ) + pages = {cw.SHELL: ''} + monkeypatch.setattr(cw, "_fetch", lambda url: pages.get(url, many)) + calls: list[tuple[str, ...]] = [] + monkeypatch.setattr(cw, "_gh", lambda *a, stdin=None: calls.append(a) or "[]") + monkeypatch.setattr(cw, "load_baseline", set) + assert cw.main([]) == 2 + assert not [c for c in calls if c[:2] == ("issue", "create")] + + +def test_a_bundle_without_the_shape_has_no_entries() -> None: + assert cw.entries('var a=[{name:"x",when:"1/1/2026"}];') == [] + + +def test_the_shell_names_its_bundle() -> None: + shell = '' + assert cw.script_url(shell, "https://flow.google.com/") == ( + "https://flow.google.com/_/mss/app/_/js/k=app.en/m=a&b=1" + ) + assert cw.script_url("", "https://flow.google.com/") is None + + +def test_plan_skips_the_baseline_and_entries_that_already_have_an_issue() -> None: + found = cw.entries(_BUNDLE) + [cw.Entry("2026-12-10-v0-ccc", "New", "12/10/2026")] + issues = [{"body": f"text\n{cw.marker('2026-12-03-v0-aaa')}\n"}] # any state counts + new = cw.plan(found, issues, baseline={"2025-10-28-v0-bbb"}) + assert [e.id for e in new] == ["2026-12-10-v0-ccc"] + + +def test_plan_opens_the_oldest_entry_first() -> None: + found = [cw.Entry("b", "Newer", "12/2/2026"), cw.Entry("a", "Older", "12/1/2026")] + assert [e.id for e in cw.plan(found, [], baseline=set())] == ["a", "b"] + + +def test_body_links_the_entry_and_carries_its_marker() -> None: + entry = cw.Entry("2026-12-03-v0-aaa", "Side-by-side Tools", "12/4/2026") + text = cw.body(entry) + assert cw.marker(entry.id) in text + assert "keep this marker" in text.lower() # an edited body must not lose it + assert f"{cw.DETAIL_URL}2026-12-03-v0-aaa.html" in text + assert cw.title(entry) == "Flow changelog: Side-by-side Tools (12/4/2026)" + + +def test_the_committed_baseline_parses_and_is_not_empty() -> None: + assert len(cw.load_baseline()) >= 40 + + +def test_a_bundle_with_no_entries_fails_the_run(monkeypatch: pytest.MonkeyPatch) -> None: + # An empty parse is "the bundle changed", never "nothing new": the job must go red. + monkeypatch.setattr(cw, "_fetch", lambda url: '') + monkeypatch.setattr(cw, "_gh", _no_gh) + assert cw.main(["--dry-run"]) == 2 + + +def test_a_shell_without_a_bundle_fails_the_run(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setattr(cw, "_fetch", lambda url: "") + monkeypatch.setattr(cw, "_gh", _no_gh) + assert cw.main(["--dry-run"]) == 2 + + +def test_an_entry_in_a_new_shape_fails_the_run(monkeypatch: pytest.MonkeyPatch) -> None: + # Old entries still parse; a new one with an extra key would be dropped silently. + bundle = _BUNDLE + '{title:"New",image:"x.png",date:"1/2/2027",id:"new"}' + pages = {cw.SHELL: ''} + monkeypatch.setattr(cw, "_fetch", lambda url: pages.get(url, bundle)) + monkeypatch.setattr(cw, "_gh", _no_gh) + assert cw.main(["--dry-run"]) == 2 + + +def test_a_shell_without_a_bundle_fetches_nothing_more(monkeypatch: pytest.MonkeyPatch) -> None: + fetched: list[str] = [] + monkeypatch.setattr(cw, "_fetch", lambda url: fetched.append(url) or "") + monkeypatch.setattr(cw, "_gh", _no_gh) + assert cw.main(["--dry-run"]) == 2 + assert fetched == [cw.SHELL] + + +def test_closed_issues_count_and_a_full_listing_fails_the_run( + monkeypatch: pytest.MonkeyPatch, +) -> None: + pages = {cw.SHELL: ''} + monkeypatch.setattr(cw, "_fetch", lambda url: pages.get(url, _BUNDLE)) + listed: list[tuple[str, ...]] = [] + full = json.dumps([{"number": i, "body": ""} for i in range(cw.ISSUE_LIMIT)]) + monkeypatch.setattr(cw, "_gh", lambda *a, stdin=None: listed.append(a) or full) + monkeypatch.setattr(cw, "load_baseline", set) + # A full page may have pushed the oldest markers out: refuse rather than re-announce. + assert cw.main(["--dry-run"]) == 2 + (args,) = listed + assert args[args.index("--state") + 1] == "all" + + +def test_dry_run_prints_the_plan_and_creates_nothing( + monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] +) -> None: + pages = {cw.SHELL: ''} + monkeypatch.setattr(cw, "_fetch", lambda url: pages.get(url, _BUNDLE)) + calls: list[tuple[str, ...]] = [] + monkeypatch.setattr(cw, "_gh", lambda *a, stdin=None: calls.append(a) or "[]") + monkeypatch.setattr(cw, "load_baseline", lambda: {"2025-10-28-v0-bbb"}) + assert cw.main(["--dry-run"]) == 0 + assert all(call[:2] == ("issue", "list") for call in calls) # read only + assert "create Flow changelog: Side-by-side Tools (12/4/2026)" in capsys.readouterr().out + + +def test_a_real_run_creates_one_labelled_issue_per_new_entry( + monkeypatch: pytest.MonkeyPatch, +) -> None: + pages = {cw.SHELL: ''} + monkeypatch.setattr(cw, "_fetch", lambda url: pages.get(url, _BUNDLE)) + calls: list[tuple[tuple[str, ...], str | None]] = [] + monkeypatch.setattr(cw, "_gh", lambda *a, stdin=None: calls.append((a, stdin)) or "[]") + monkeypatch.setattr(cw, "load_baseline", lambda: {"2025-10-28-v0-bbb"}) + assert cw.main([]) == 0 + creates = [(a, s) for a, s in calls if a[:2] == ("issue", "create")] + assert len(creates) == 1 + args, stdin = creates[0] + assert args[args.index("--label") + 1] == cw.LABEL + assert stdin is not None and cw.marker("2026-12-03-v0-aaa") in stdin + + +def _no_gh(*_: str, stdin: str | None = None) -> str: + raise AssertionError("gh must not be called")