From 91142b0b7f6e49913c04214622fc25d8facb1f84 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 13:54:28 -0600 Subject: [PATCH 1/3] fix(fleet-paperwork): create readback compares body, state and labels (#6901) cmd_create's readback verified only title and number, so a create whose body was dropped or mangled, or whose labels were not applied, reported 'created+verified'. The README already promised the comparison covers (title, body, state); this makes the code match it and adds the labels that were sent. Tests cover the four failure modes (dropped body, mangled body, closed state, missing labels) plus the passing and extra-label cases; the four failure-mode tests fail against the previous implementation. --- infra/fleet-paperwork/README.md | 3 +- infra/fleet-paperwork/fleet_paperwork.py | 28 +++++- .../tests/test_fleet_paperwork.py | 92 +++++++++++++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) diff --git a/infra/fleet-paperwork/README.md b/infra/fleet-paperwork/README.md index 6bfdaf974..17cf7f097 100644 --- a/infra/fleet-paperwork/README.md +++ b/infra/fleet-paperwork/README.md @@ -33,7 +33,8 @@ through a personal user token has two failure modes, both observed live on and `dezren39/fleet`. - **A filing is verified, or it is a failure.** Every create / comment / close is followed by a readback GET, and the result is compared (title, body, - state). A missing, empty, or mismatched readback exits nonzero. + state) — plus the labels that were sent, for create. A missing, empty, or + mismatched readback exits nonzero. - Creates are **deduped by exact title** (search API + byte-exact title comparison) and **paced** (default 3 s minimum between writes, enforced across invocations via the ledger), so re-running a batch is safe and diff --git a/infra/fleet-paperwork/fleet_paperwork.py b/infra/fleet-paperwork/fleet_paperwork.py index 8ad5f2aca..15dc585b0 100755 --- a/infra/fleet-paperwork/fleet_paperwork.py +++ b/infra/fleet-paperwork/fleet_paperwork.py @@ -463,10 +463,36 @@ def cmd_create(args) -> int: f"create in {args.repo} returned no issue number (response keys: " f"{sorted(created) if isinstance(created, dict) else type(created)})" ) - # Verify by readback — an unverified create counts as a failure. + # Verify by readback — an unverified create counts as a failure. The + # README promises the comparison covers (title, body, state) and the + # labels that were sent (#6901): a create whose body was dropped or + # mangled, or whose labels were not applied, must not report success. _, got = http("GET", f"/repos/{args.repo}/issues/{number}", token) if got.get("title") != title or got.get("number") != number: die(f"readback mismatch for {args.repo}#{number}: title={got.get('title')!r}") + if got.get("body") != body: + die( + f"readback mismatch for {args.repo}#{number}: body sent " + f"{len(body)} chars, read back {len(got.get('body') or '')} chars " + f"(body={_shape_name(got.get('body'))})" + ) + if got.get("state") != "open": + die( + f"readback mismatch for {args.repo}#{number}: state={got.get('state')!r}, " + f"expected 'open' for a freshly created issue" + ) + if args.label: + want = sorted(args.label) + have = sorted( + lbl.get("name") if isinstance(lbl, dict) else lbl + for lbl in (got.get("labels") or []) + ) + missing = [name for name in want if name not in have] + if missing: + die( + f"readback mismatch for {args.repo}#{number}: labels not applied: " + f"{missing} (read back {have})" + ) ledger_append("create", args.repo, str(number), title) print(f"created+verified: {args.repo}#{number} {created.get('html_url')}") return 0 diff --git a/infra/fleet-paperwork/tests/test_fleet_paperwork.py b/infra/fleet-paperwork/tests/test_fleet_paperwork.py index d8537ab97..6a4681a2a 100644 --- a/infra/fleet-paperwork/tests/test_fleet_paperwork.py +++ b/infra/fleet-paperwork/tests/test_fleet_paperwork.py @@ -116,6 +116,9 @@ class _FakeClient: def token_for(self, owner): return "test-token" + def assert_repo_in_scope(self, repo): + return None + class TestFindByExactTitle(unittest.TestCase): """The real find_by_exact_title against stubbed Search-API payloads, @@ -168,6 +171,95 @@ def test_exact_issue_past_first_page_is_found(self): self.assertEqual(len(paths), 2) +class TestCreateReadback(unittest.TestCase): + """#6901: the create readback must compare body, state and requested + labels against what was sent — not just title and number — so a create + whose body was dropped or whose labels were not applied fails loudly.""" + + TITLE = "Preserved branch: queue/x — decision needed" + BODY = "## Finding\n\nbody that the filer sent\n" + REPO = "developing-today/code" + + def run_create(self, readback_overrides, labels=None): + """Run cmd_create against stubbed HTTP. Returns (exit_code, paths).""" + paths = [] + created = {"number": 42, "html_url": "https://example.test/42"} + readback = { + "number": 42, + "title": self.TITLE, + "body": self.BODY, + "state": "open", + "labels": [{"name": n} for n in (labels or [])], + } + readback.update(readback_overrides) + + def fake_http(method, path, token, payload=None): + paths.append((method, path)) + if method == "POST": + return 200, created + return 200, readback + + args = [ + "create", + "--repo", + self.REPO, + "--title", + self.TITLE, + "--body", + self.BODY, + "--no-dedupe", + "--pace", + "0", + ] + for label in labels or []: + args += ["--label", label] + + with unittest.mock.patch.object(fp, "AppClient", lambda _s: _FakeClient()), \ + unittest.mock.patch.object( + fp, "find_by_exact_title", lambda *_a, **_k: None + ), \ + unittest.mock.patch.object(fp, "http", fake_http): + try: + code = fp.main(args) + except SystemExit as exc: + code = exc.code + return code, paths + + def test_matching_readback_passes(self): + code, paths = self.run_create({}) + self.assertEqual(code, 0) + self.assertEqual([m for m, _ in paths], ["POST", "GET"]) + + def test_dropped_body_fails(self): + code, _ = self.run_create({"body": ""}) + self.assertEqual(code, 1) + + def test_mangled_body_fails(self): + code, _ = self.run_create({"body": self.BODY.strip()}) + self.assertEqual(code, 1) + + def test_closed_state_fails(self): + code, _ = self.run_create({"state": "closed"}) + self.assertEqual(code, 1) + + def test_missing_labels_fail(self): + """Labels were requested but the readback shows none applied.""" + code, _ = self.run_create({"labels": []}, labels=["kind/bug"]) + self.assertEqual(code, 1) + + def test_applied_labels_pass(self): + code, _ = self.run_create({}, labels=["kind/bug", "effort/xs"]) + self.assertEqual(code, 0) + + def test_extra_labels_are_tolerated(self): + """GitHub may add labels on create; only the requested ones matter.""" + code, _ = self.run_create( + {"labels": [{"name": "kind/bug"}, {"name": "auto-added"}]}, + labels=["kind/bug"], + ) + self.assertEqual(code, 0) + + class TestGenericCommandArgs(unittest.TestCase): """The generic commands must not be able to act by accident: `api` requires an explicit --method for every call (no default to hide a From 5b0d0934fbeaefe8da46f98bf014be6faef94c2c Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Mon, 9 Nov 2026 17:50:39 -0600 Subject: [PATCH 2/3] test(fleet-paperwork): isolate create readback ledger --- infra/fleet-paperwork/tests/test_fleet_paperwork.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/infra/fleet-paperwork/tests/test_fleet_paperwork.py b/infra/fleet-paperwork/tests/test_fleet_paperwork.py index 6a4681a2a..e0c2dfe62 100644 --- a/infra/fleet-paperwork/tests/test_fleet_paperwork.py +++ b/infra/fleet-paperwork/tests/test_fleet_paperwork.py @@ -218,7 +218,8 @@ def fake_http(method, path, token, payload=None): unittest.mock.patch.object( fp, "find_by_exact_title", lambda *_a, **_k: None ), \ - unittest.mock.patch.object(fp, "http", fake_http): + unittest.mock.patch.object(fp, "http", fake_http), \ + unittest.mock.patch.object(fp, "ledger_append"): try: code = fp.main(args) except SystemExit as exc: From e48c43cf82e62046fed6b7c945bf0386dd0ac0b7 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Tue, 10 Nov 2026 13:18:55 -0600 Subject: [PATCH 3/3] fix(fleet-paperwork): shape-safe create readback diagnostics (Copilot review) Body/label readback comparisons no longer raise TypeError on non-string bodies or malformed label entries: lengths are computed defensively, labels are matched as a set of string names, and malformed entries die with a readback mismatch. fake_http stub aligned with fp.http() signature (body/expect). Adds tests for non-string body readback and malformed label entries. --- infra/fleet-paperwork/fleet_paperwork.py | 37 ++++++++++++++----- .../tests/test_fleet_paperwork.py | 10 ++++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/infra/fleet-paperwork/fleet_paperwork.py b/infra/fleet-paperwork/fleet_paperwork.py index 15dc585b0..9c7089116 100755 --- a/infra/fleet-paperwork/fleet_paperwork.py +++ b/infra/fleet-paperwork/fleet_paperwork.py @@ -470,11 +470,16 @@ def cmd_create(args) -> int: _, got = http("GET", f"/repos/{args.repo}/issues/{number}", token) if got.get("title") != title or got.get("number") != number: die(f"readback mismatch for {args.repo}#{number}: title={got.get('title')!r}") - if got.get("body") != body: + readback_body = got.get("body") + if readback_body != body: + sent_chars = len(body) if isinstance(body, str) else "n/a" + readback_chars = ( + len(readback_body) if isinstance(readback_body, str) else "n/a" + ) die( f"readback mismatch for {args.repo}#{number}: body sent " - f"{len(body)} chars, read back {len(got.get('body') or '')} chars " - f"(body={_shape_name(got.get('body'))})" + f"{sent_chars} chars, read back {readback_chars} chars " + f"(body={_shape_name(readback_body)})" ) if got.get("state") != "open": die( @@ -482,16 +487,28 @@ def cmd_create(args) -> int: f"expected 'open' for a freshly created issue" ) if args.label: - want = sorted(args.label) - have = sorted( - lbl.get("name") if isinstance(lbl, dict) else lbl - for lbl in (got.get("labels") or []) - ) - missing = [name for name in want if name not in have] + readback_labels = got.get("labels", []) + if not isinstance(readback_labels, list): + die( + f"readback mismatch for {args.repo}#{number}: labels have invalid " + f"shape (expected array, got {_shape_name(readback_labels)})" + ) + have = set() + for label in readback_labels: + name = label if isinstance(label, str) else ( + label.get("name") if isinstance(label, dict) else None + ) + if not isinstance(name, str): + die( + f"readback mismatch for {args.repo}#{number}: label entry has " + f"no string name (got {_shape_name(label)})" + ) + have.add(name) + missing = sorted(set(args.label) - have) if missing: die( f"readback mismatch for {args.repo}#{number}: labels not applied: " - f"{missing} (read back {have})" + f"{missing} (read back {sorted(have)})" ) ledger_append("create", args.repo, str(number), title) print(f"created+verified: {args.repo}#{number} {created.get('html_url')}") diff --git a/infra/fleet-paperwork/tests/test_fleet_paperwork.py b/infra/fleet-paperwork/tests/test_fleet_paperwork.py index e0c2dfe62..458f85a3f 100644 --- a/infra/fleet-paperwork/tests/test_fleet_paperwork.py +++ b/infra/fleet-paperwork/tests/test_fleet_paperwork.py @@ -193,7 +193,7 @@ def run_create(self, readback_overrides, labels=None): } readback.update(readback_overrides) - def fake_http(method, path, token, payload=None): + def fake_http(method, path, token, body=None, expect=dict): paths.append((method, path)) if method == "POST": return 200, created @@ -239,6 +239,10 @@ def test_mangled_body_fails(self): code, _ = self.run_create({"body": self.BODY.strip()}) self.assertEqual(code, 1) + def test_non_string_body_readback_fails_cleanly(self): + code, _ = self.run_create({"body": 42}) + self.assertEqual(code, 1) + def test_closed_state_fails(self): code, _ = self.run_create({"state": "closed"}) self.assertEqual(code, 1) @@ -248,6 +252,10 @@ def test_missing_labels_fail(self): code, _ = self.run_create({"labels": []}, labels=["kind/bug"]) self.assertEqual(code, 1) + def test_malformed_label_entry_fails_cleanly(self): + code, _ = self.run_create({"labels": [{"name": None}]}, labels=["kind/bug"]) + self.assertEqual(code, 1) + def test_applied_labels_pass(self): code, _ = self.run_create({}, labels=["kind/bug", "effort/xs"]) self.assertEqual(code, 0)