From 23a2a2cd18389321d2f608531623e218b82b9c88 Mon Sep 17 00:00:00 2001 From: Miguel Dalberto Pedro Date: Thu, 24 Sep 2026 18:31:39 -0300 Subject: [PATCH 1/6] Send who requested the build in the metrics payload Adds --buildUserEmail and --changeAuthorEmail to uploadMetadata.py, sent as the top-level build_user_email and change_author_email keys on every schema version, v1 per-design fallback included. Blank values are left out. The dashboard stores them on the build and attributes the build to the user who started it, so a "my branches" view can include builds a user started by hand. They describe the build rather than the payload's shape, so they do not bump payload_schema_version. The backend must already register them as metadata before this lands: a v1 message carries metrics at its root, and an older backend would ingest the keys as metrics. Signed-off-by: Miguel Dalberto Pedro --- flow/util/uploadMetadata.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/flow/util/uploadMetadata.py b/flow/util/uploadMetadata.py index 6918ccf2b4..4cd7a71854 100755 --- a/flow/util/uploadMetadata.py +++ b/flow/util/uploadMetadata.py @@ -51,6 +51,21 @@ "pinned commit rather than the built one. When supplied alongside " "--jobName the payload is emitted as schema v4.", ) +parser.add_argument( + "--buildUserEmail", + type=str, + default=None, + help="Email of the Jenkins user who started the build by hand " + "(BUILD_USER_EMAIL). Omitted for SCM, timer and branch-scan triggers. " + "The dashboard attributes the build to this user.", +) +parser.add_argument( + "--changeAuthorEmail", + type=str, + default=None, + help="Email of the pull request's author on a PR build " + "(CHANGE_AUTHOR_EMAIL). Empty when the author's GitHub email is private.", +) # --- PUBSUB args --- parser.add_argument( @@ -193,6 +208,23 @@ def resolve_schema_version(args, provenance): return 4 if provenance else 3 +def resolve_requester(args): + """Who asked for the build, as the payload keys the backend reads. + + Blank values are left out rather than sent empty. The keys ride on every + schema version: the backend reads them by presence, and they describe the + build rather than the payload's shape, so they do not bump the version. + """ + requester = {} + for key, value in ( + ("build_user_email", args.buildUserEmail), + ("change_author_email", args.changeAuthorEmail), + ): + if value and value.strip(): + requester[key] = value.strip() + return requester + + def build_pipeline_payload(design_records, args, provenance=None): """Return the pipeline-level payload dict. @@ -220,6 +252,7 @@ def build_pipeline_payload(design_records, args, provenance=None): # the payload. if schema_version == 4: payload.update(provenance) + payload.update(resolve_requester(args)) return payload @@ -261,6 +294,7 @@ def publish_v1_per_design(publisher, topic_path, design_records, args, provenanc key presence rather than by version. """ futures = [] + requester = resolve_requester(args) for d in design_records: payload = { "build_id": args.buildID, @@ -273,6 +307,7 @@ def publish_v1_per_design(publisher, topic_path, design_records, args, provenanc } if provenance: payload.update(provenance) + payload.update(requester) payload.update(d["metrics"]) message_data = json.dumps(payload, default=str).encode("utf-8") From 16344f7e0c4eceb86858933484fea773eefef308 Mon Sep 17 00:00:00 2001 From: Miguel Dalberto Pedro Date: Wed, 21 Oct 2026 14:21:38 -0300 Subject: [PATCH 2/6] Test the requester keys in the pipeline and v1 payloads uploadMetadata.py does its work at import time, so the tests run it as a subprocess against a temporary reports/ tree, with stub google.cloud modules recording each published message. They cover both requester flags set, one blank, and both absent, on the pipeline payload and on the per-design v1 fallback messages. The absent case compares the whole payload, which proves that a build without the flags publishes exactly what it did before the flags existed. Signed-off-by: Miguel Dalberto Pedro --- flow/test/test_uploadMetadata.py | 224 +++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 flow/test/test_uploadMetadata.py diff --git a/flow/test/test_uploadMetadata.py b/flow/test/test_uploadMetadata.py new file mode 100644 index 0000000000..8584e4a1d7 --- /dev/null +++ b/flow/test/test_uploadMetadata.py @@ -0,0 +1,224 @@ +#!/usr/bin/env python3 + +"""Tests for the Pub/Sub payload that uploadMetadata.py publishes. + +uploadMetadata.py does its work at import time (it parses arguments, changes +to flow/ and walks reports/), so it runs here as a subprocess. The script is +copied into a temporary util/ directory next to a temporary reports/ tree, +which makes that tree the one it walks, and stub google.cloud modules on +PYTHONPATH record every published message instead of sending it. +""" + +import json +import os +import shutil +import subprocess +import sys +import tempfile +import unittest + +SCRIPT = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "util", "uploadMetadata.py" +) + +STUB_PUBSUB = """ +import json +import os + + +class _Future: + def __init__(self, message_id): + self._message_id = message_id + + def result(self): + return self._message_id + + +class PublisherClient: + def __init__(self, credentials=None): + pass + + def topic_path(self, project, topic): + return f"projects/{project}/topics/{topic}" + + def publish(self, topic_path, data, **attributes): + with open(os.environ["STUB_PUBSUB_OUT"], "a") as f: + record = {"data": json.loads(data), "attributes": attributes} + f.write(json.dumps(record) + "\\n") + return _Future("stub-id") +""" + +STUB_SERVICE_ACCOUNT = """ +class Credentials: + @staticmethod + def from_service_account_file(path): + return None +""" + +# Large enough to push the pipeline payload over the 8 MB cap, so the script +# falls back to one v1 message per design. +OVERSIZED_METRICS = {"blob": "x" * (9 * 1024 * 1024)} + + +class TestUploadMetadata(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + root = self.tmp.name + self.flow = os.path.join(root, "flow") + os.makedirs(os.path.join(self.flow, "util")) + os.makedirs(os.path.join(self.flow, "reports")) + shutil.copy(SCRIPT, os.path.join(self.flow, "util")) + + stubs = os.path.join(root, "stubs") + files = { + "google/__init__.py": "", + "google/cloud/__init__.py": "", + "google/cloud/pubsub_v1.py": STUB_PUBSUB, + "google/oauth2/__init__.py": "", + "google/oauth2/service_account.py": STUB_SERVICE_ACCOUNT, + } + for rel, content in files.items(): + path = os.path.join(stubs, rel) + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, "w") as f: + f.write(content) + self.stubs = stubs + self.out = os.path.join(root, "published.jsonl") + + def tearDown(self): + self.tmp.cleanup() + + def add_design(self, platform, design, variant="base", metrics=None): + report_dir = os.path.join(self.flow, "reports", platform, design, variant) + os.makedirs(report_dir) + with open(os.path.join(report_dir, "metadata.json"), "w") as f: + json.dump(metrics or {"finish:area": 1.0}, f) + + def run_script(self, *extra): + env = dict(os.environ) + env["PYTHONPATH"] = self.stubs + env["STUB_PUBSUB_OUT"] = self.out + cmd = [ + sys.executable, + os.path.join(self.flow, "util", "uploadMetadata.py"), + "--buildID", + "42", + "--branchName", + "master", + "--pipelineID", + "jenkins-ORFS-master-42", + "--commitSHA", + "abc123", + "--jenkinsURL", + "http://jenkins/job/ORFS/42/", + "--jenkinsEnv", + "public", + "--pubsubProjectID", + "test-project", + *extra, + ] + result = subprocess.run(cmd, env=env, capture_output=True, text=True) + messages = [] + if os.path.exists(self.out): + with open(self.out) as f: + messages = [json.loads(line) for line in f] + return result, messages + + def test_pipeline_payload_without_requester_is_unchanged(self): + self.add_design("nangate45", "gcd", metrics={"finish:area": 5.0}) + result, messages = self.run_script("--jobName", "ORFS") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = messages[0]["data"] + self.assertEqual( + payload, + { + "payload_schema_version": 3, + "jenkins_env": "public", + "build_id": "42", + "branch_name": "master", + "pipeline_id": "jenkins-ORFS-master-42", + "change_branch": None, + "commit_sha": "abc123", + "jenkins_url": "http://jenkins/job/ORFS/42/", + "job_name": "ORFS", + "designs": [ + { + "platform": "nangate45", + "design": "gcd", + "variant": "base", + "metrics": {"finish__area": 5.0}, + } + ], + }, + ) + + def test_v1_message_without_requester_is_unchanged(self): + self.add_design("nangate45", "gcd", metrics=OVERSIZED_METRICS) + result, messages = self.run_script() + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(len(messages), 1) + payload = messages[0]["data"] + self.assertEqual(payload.pop("blob"), OVERSIZED_METRICS["blob"]) + self.assertEqual( + payload, + { + "build_id": "42", + "branch_name": "master", + "pipeline_id": "jenkins-ORFS-master-42", + "change_branch": None, + "commit_sha": "abc123", + "jenkins_url": "http://jenkins/job/ORFS/42/", + "jenkins_env": "public", + }, + ) + + def test_both_requester_flags_reach_pipeline_payload(self): + self.add_design("nangate45", "gcd") + result, messages = self.run_script( + "--buildUserEmail", + " ada@example.com ", + "--changeAuthorEmail", + "bob@example.com", + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = messages[0]["data"] + self.assertEqual(payload["build_user_email"], "ada@example.com") + self.assertEqual(payload["change_author_email"], "bob@example.com") + self.assertEqual(payload["payload_schema_version"], 2) + + def test_both_requester_flags_reach_v1_messages(self): + self.add_design("nangate45", "gcd", metrics=OVERSIZED_METRICS) + result, messages = self.run_script( + "--buildUserEmail", + "ada@example.com", + "--changeAuthorEmail", + "bob@example.com", + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = messages[0]["data"] + self.assertEqual(payload["build_user_email"], "ada@example.com") + self.assertEqual(payload["change_author_email"], "bob@example.com") + + def test_blank_requester_flag_is_omitted(self): + self.add_design("nangate45", "gcd") + result, messages = self.run_script( + "--buildUserEmail", " ", "--changeAuthorEmail", "bob@example.com" + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = messages[0]["data"] + self.assertNotIn("build_user_email", payload) + self.assertEqual(payload["change_author_email"], "bob@example.com") + + def test_blank_requester_flag_is_omitted_from_v1_messages(self): + self.add_design("nangate45", "gcd", metrics=OVERSIZED_METRICS) + result, messages = self.run_script( + "--buildUserEmail", "ada@example.com", "--changeAuthorEmail", "" + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = messages[0]["data"] + self.assertEqual(payload["build_user_email"], "ada@example.com") + self.assertNotIn("change_author_email", payload) + + +if __name__ == "__main__": + unittest.main() From 33f8f011d5e571920a3ec50e460a52ab5728a1e9 Mon Sep 17 00:00:00 2001 From: Miguel Dalberto Pedro Date: Wed, 21 Oct 2026 14:25:09 -0300 Subject: [PATCH 3/6] Drop requester values that are not email addresses An unset Groovy variable interpolates as the string "null", which resolve_requester used to accept as an email because it only rejected blank values. A value without an "@" is now dropped with a warning. The requester is resolved once in the main flow and passed to both payload builders. Resolving it inside each builder made the warning print twice when the pipeline payload exceeded the size cap and the script fell back to per-design v1 messages. Signed-off-by: Miguel Dalberto Pedro --- flow/test/test_uploadMetadata.py | 20 +++++++++++++++++ flow/util/uploadMetadata.py | 37 +++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/flow/test/test_uploadMetadata.py b/flow/test/test_uploadMetadata.py index 8584e4a1d7..dea5e534e7 100644 --- a/flow/test/test_uploadMetadata.py +++ b/flow/test/test_uploadMetadata.py @@ -220,5 +220,25 @@ def test_blank_requester_flag_is_omitted_from_v1_messages(self): self.assertNotIn("change_author_email", payload) + def test_requester_without_at_sign_is_dropped(self): + self.add_design("nangate45", "gcd") + result, messages = self.run_script( + "--buildUserEmail", "null", "--changeAuthorEmail", "None" + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = messages[0]["data"] + self.assertNotIn("build_user_email", payload) + self.assertNotIn("change_author_email", payload) + self.assertIn("[WARN] Not sending --buildUserEmail: 'null'", result.stdout) + self.assertIn("[WARN] Not sending --changeAuthorEmail: 'None'", result.stdout) + + def test_v1_fallback_warns_about_requester_once(self): + self.add_design("nangate45", "gcd", metrics=OVERSIZED_METRICS) + result, messages = self.run_script("--buildUserEmail", "null") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertNotIn("build_user_email", messages[0]["data"]) + self.assertEqual(result.stdout.count("Not sending --buildUserEmail"), 1) + + if __name__ == "__main__": unittest.main() diff --git a/flow/util/uploadMetadata.py b/flow/util/uploadMetadata.py index 613ad03a8e..61bb35dd3f 100755 --- a/flow/util/uploadMetadata.py +++ b/flow/util/uploadMetadata.py @@ -212,21 +212,28 @@ def resolve_schema_version(args, provenance): def resolve_requester(args): """Who asked for the build, as the payload keys the backend reads. - Blank values are left out rather than sent empty. The keys ride on every + Blank values are left out rather than sent empty, and a value without an + "@" is dropped with a warning: an unset Groovy variable interpolates as the + string "null", which must not be stored as an email. The keys ride on every schema version: the backend reads them by presence, and they describe the build rather than the payload's shape, so they do not bump the version. """ requester = {} - for key, value in ( - ("build_user_email", args.buildUserEmail), - ("change_author_email", args.changeAuthorEmail), + for key, flag, value in ( + ("build_user_email", "--buildUserEmail", args.buildUserEmail), + ("change_author_email", "--changeAuthorEmail", args.changeAuthorEmail), ): - if value and value.strip(): - requester[key] = value.strip() + value = (value or "").strip() + if not value: + continue + if "@" not in value: + print(f"[WARN] Not sending {flag}: '{value}' is not an email address.") + continue + requester[key] = value return requester -def build_pipeline_payload(design_records, args, provenance=None): +def build_pipeline_payload(design_records, args, provenance=None, requester=None): """Return the pipeline-level payload dict. Emits schema v2 (no job name), v3 (job name) or v4 (job name plus build @@ -253,7 +260,8 @@ def build_pipeline_payload(design_records, args, provenance=None): # the payload. if schema_version == 4: payload.update(provenance) - payload.update(resolve_requester(args)) + if requester: + payload.update(requester) return payload @@ -277,7 +285,9 @@ def publish_pipeline_report( print(f"[INFO] Published pipeline report to Pub/Sub (message ID: {message_id}).") -def publish_v1_per_design(publisher, topic_path, design_records, args, provenance=None): +def publish_v1_per_design( + publisher, topic_path, design_records, args, provenance=None, requester=None +): """Fallback path used when the v2 pipeline payload exceeds MAX_PUBSUB_BYTES. Emits one v1-format message per design (no payload_schema_version, metrics @@ -295,7 +305,6 @@ def publish_v1_per_design(publisher, topic_path, design_records, args, provenanc key presence rather than by version. """ futures = [] - requester = resolve_requester(args) failed = 0 for d in design_records: payload = { @@ -309,7 +318,8 @@ def publish_v1_per_design(publisher, topic_path, design_records, args, provenanc } if provenance: payload.update(provenance) - payload.update(requester) + if requester: + payload.update(requester) payload.update(d["metrics"]) message_data = json.dumps(payload, default=str).encode("utf-8") @@ -398,7 +408,8 @@ def publish_v1_per_design(publisher, topic_path, design_records, args, provenanc # builds are compared against. if publisher and design_records: provenance = load_provenance(args.provenanceFile) - payload = build_pipeline_payload(design_records, args, provenance) + requester = resolve_requester(args) + payload = build_pipeline_payload(design_records, args, provenance, requester) message_data = json.dumps(payload, default=str).encode("utf-8") if len(message_data) > MAX_PUBSUB_BYTES: @@ -408,7 +419,7 @@ def publish_v1_per_design(publisher, topic_path, design_records, args, provenanc f"({len(design_records)} messages)." ) failed = publish_v1_per_design( - publisher, topic_path, design_records, args, provenance + publisher, topic_path, design_records, args, provenance, requester ) if failed: print( From ce9cfd333e3b9bfa9b1ef6bc46c6a1c19798e983 Mon Sep 17 00:00:00 2001 From: Miguel Dalberto Pedro Date: Wed, 21 Oct 2026 14:27:26 -0300 Subject: [PATCH 4/6] Read the requester emails from the environment A Jenkins sh step echoes its command line under sh -x, so passing --buildUserEmail puts the user's address in the console log. When a requester flag is absent, the value now comes from UPLOAD_BUILD_USER_EMAIL or UPLOAD_CHANGE_AUTHOR_EMAIL, so the caller can keep the address out of the command line. An empty flag counts as given and suppresses the variable. Values from the environment go through the same blank and "@" checks as the flags. Signed-off-by: Miguel Dalberto Pedro --- flow/test/test_uploadMetadata.py | 58 +++++++++++++++++++++++++++++++- flow/util/uploadMetadata.py | 31 +++++++++++++---- 2 files changed, 81 insertions(+), 8 deletions(-) diff --git a/flow/test/test_uploadMetadata.py b/flow/test/test_uploadMetadata.py index dea5e534e7..597ba681c2 100644 --- a/flow/test/test_uploadMetadata.py +++ b/flow/test/test_uploadMetadata.py @@ -55,6 +55,8 @@ def from_service_account_file(path): return None """ +REQUESTER_ENV = ("UPLOAD_BUILD_USER_EMAIL", "UPLOAD_CHANGE_AUTHOR_EMAIL") + # Large enough to push the pipeline payload over the 8 MB cap, so the script # falls back to one v1 message per design. OVERSIZED_METRICS = {"blob": "x" * (9 * 1024 * 1024)} @@ -94,8 +96,11 @@ def add_design(self, platform, design, variant="base", metrics=None): with open(os.path.join(report_dir, "metadata.json"), "w") as f: json.dump(metrics or {"finish:area": 1.0}, f) - def run_script(self, *extra): + def run_script(self, *extra, extra_env=None): env = dict(os.environ) + for name in REQUESTER_ENV: + env.pop(name, None) + env.update(extra_env or {}) env["PYTHONPATH"] = self.stubs env["STUB_PUBSUB_OUT"] = self.out cmd = [ @@ -240,5 +245,56 @@ def test_v1_fallback_warns_about_requester_once(self): self.assertEqual(result.stdout.count("Not sending --buildUserEmail"), 1) + def test_requester_is_read_from_environment(self): + self.add_design("nangate45", "gcd") + result, messages = self.run_script( + extra_env={ + "UPLOAD_BUILD_USER_EMAIL": "ada@example.com", + "UPLOAD_CHANGE_AUTHOR_EMAIL": " bob@example.com ", + } + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = messages[0]["data"] + self.assertEqual(payload["build_user_email"], "ada@example.com") + self.assertEqual(payload["change_author_email"], "bob@example.com") + + def test_requester_flag_overrides_environment(self): + self.add_design("nangate45", "gcd") + result, messages = self.run_script( + "--buildUserEmail", + "ada@example.com", + extra_env={"UPLOAD_BUILD_USER_EMAIL": "other@example.com"}, + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(messages[0]["data"]["build_user_email"], "ada@example.com") + + def test_empty_requester_flag_suppresses_environment(self): + self.add_design("nangate45", "gcd") + result, messages = self.run_script( + "--buildUserEmail", + "", + extra_env={"UPLOAD_BUILD_USER_EMAIL": "ada@example.com"}, + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertNotIn("build_user_email", messages[0]["data"]) + + def test_environment_requester_is_validated(self): + self.add_design("nangate45", "gcd") + result, messages = self.run_script( + extra_env={"UPLOAD_BUILD_USER_EMAIL": "null"} + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertNotIn("build_user_email", messages[0]["data"]) + self.assertIn("[WARN] Not sending --buildUserEmail: 'null'", result.stdout) + + def test_environment_requester_reaches_v1_messages(self): + self.add_design("nangate45", "gcd", metrics=OVERSIZED_METRICS) + result, messages = self.run_script( + extra_env={"UPLOAD_CHANGE_AUTHOR_EMAIL": "bob@example.com"} + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(messages[0]["data"]["change_author_email"], "bob@example.com") + + if __name__ == "__main__": unittest.main() diff --git a/flow/util/uploadMetadata.py b/flow/util/uploadMetadata.py index 61bb35dd3f..94a4564167 100755 --- a/flow/util/uploadMetadata.py +++ b/flow/util/uploadMetadata.py @@ -58,14 +58,17 @@ default=None, help="Email of the Jenkins user who started the build by hand " "(BUILD_USER_EMAIL). Omitted for SCM, timer and branch-scan triggers. " - "The dashboard attributes the build to this user.", + "The dashboard attributes the build to this user. Defaults to " + "$UPLOAD_BUILD_USER_EMAIL, which keeps the address out of a traced " + "(sh -x) command line.", ) parser.add_argument( "--changeAuthorEmail", type=str, default=None, help="Email of the pull request's author on a PR build " - "(CHANGE_AUTHOR_EMAIL). Empty when the author's GitHub email is private.", + "(CHANGE_AUTHOR_EMAIL). Empty when the author's GitHub email is private. " + "Defaults to $UPLOAD_CHANGE_AUTHOR_EMAIL.", ) # --- PUBSUB args --- @@ -212,18 +215,32 @@ def resolve_schema_version(args, provenance): def resolve_requester(args): """Who asked for the build, as the payload keys the backend reads. - Blank values are left out rather than sent empty, and a value without an + Each value comes from its flag or, when the flag is absent, from its + environment variable. An empty flag counts as given, so it suppresses the + variable. Blank values are left out rather than sent empty, and a value without an "@" is dropped with a warning: an unset Groovy variable interpolates as the string "null", which must not be stored as an email. The keys ride on every schema version: the backend reads them by presence, and they describe the build rather than the payload's shape, so they do not bump the version. """ requester = {} - for key, flag, value in ( - ("build_user_email", "--buildUserEmail", args.buildUserEmail), - ("change_author_email", "--changeAuthorEmail", args.changeAuthorEmail), + for key, flag, value, env_var in ( + ( + "build_user_email", + "--buildUserEmail", + args.buildUserEmail, + "UPLOAD_BUILD_USER_EMAIL", + ), + ( + "change_author_email", + "--changeAuthorEmail", + args.changeAuthorEmail, + "UPLOAD_CHANGE_AUTHOR_EMAIL", + ), ): - value = (value or "").strip() + if value is None: + value = os.environ.get(env_var, "") + value = value.strip() if not value: continue if "@" not in value: From 12d4cc64685ffd8b1b2e389238920d5c88eb1f80 Mon Sep 17 00:00:00 2001 From: Miguel Dalberto Pedro Date: Wed, 21 Oct 2026 14:45:55 -0300 Subject: [PATCH 5/6] Apply the requester keys after the metrics in v1 messages A v1 message flattens the metrics onto the message root, so a metric named like a requester key replaced who asked for the build. The requester keys now go on last. The pipeline payload nests the metrics under each design and cannot collide. Signed-off-by: Miguel Dalberto Pedro --- flow/test/test_uploadMetadata.py | 8 ++++++++ flow/util/uploadMetadata.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/flow/test/test_uploadMetadata.py b/flow/test/test_uploadMetadata.py index 597ba681c2..2ca1fa712b 100644 --- a/flow/test/test_uploadMetadata.py +++ b/flow/test/test_uploadMetadata.py @@ -296,5 +296,13 @@ def test_environment_requester_reaches_v1_messages(self): self.assertEqual(messages[0]["data"]["change_author_email"], "bob@example.com") + def test_requester_keys_win_over_same_named_v1_metric(self): + metrics = dict(OVERSIZED_METRICS, build_user_email="metric") + self.add_design("nangate45", "gcd", metrics=metrics) + result, messages = self.run_script("--buildUserEmail", "ada@example.com") + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(messages[0]["data"]["build_user_email"], "ada@example.com") + + if __name__ == "__main__": unittest.main() diff --git a/flow/util/uploadMetadata.py b/flow/util/uploadMetadata.py index 94a4564167..b499b041dd 100755 --- a/flow/util/uploadMetadata.py +++ b/flow/util/uploadMetadata.py @@ -320,6 +320,9 @@ def publish_v1_per_design( requirement: a v1 message declares no schema version, so there is nothing for the extra keys to contradict, and the backend reads provenance here by key presence rather than by version. + + The requester keys go on after the metrics, so a metric that happened to + share their name could not replace who asked for the build. """ futures = [] failed = 0 @@ -335,9 +338,9 @@ def publish_v1_per_design( } if provenance: payload.update(provenance) + payload.update(d["metrics"]) if requester: payload.update(requester) - payload.update(d["metrics"]) message_data = json.dumps(payload, default=str).encode("utf-8") try: From 5a13da804c0d920b2ec22229e5e51d639de72215 Mon Sep 17 00:00:00 2001 From: Miguel Dalberto Pedro Date: Thu, 22 Oct 2026 08:24:51 -0300 Subject: [PATCH 6/6] Restore the oversized-payload test the merge left a stray assignment in Merging master put a REQUESTER_ENV assignment in the middle of test_v1_fallback_warns_that_design_count_is_dropped and left its comment unindented, so the black check failed. The test is master's again, and black also drops the extra blank lines between the new tests. Signed-off-by: Miguel Dalberto Pedro --- flow/test/test_uploadMetadata.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/flow/test/test_uploadMetadata.py b/flow/test/test_uploadMetadata.py index d9d0ef444e..92555ed5a5 100755 --- a/flow/test/test_uploadMetadata.py +++ b/flow/test/test_uploadMetadata.py @@ -303,9 +303,7 @@ def test_only_skipped_platforms_publishes_empty_report(self): self.assertIn("[WARN] No design records were collected", result.stdout) def test_v1_fallback_warns_that_design_count_is_dropped(self): - REQUESTER_ENV = ("UPLOAD_BUILD_USER_EMAIL", "UPLOAD_CHANGE_AUTHOR_EMAIL") - -# Large enough to push the pipeline payload over the 8 MB cap. + # Large enough to push the pipeline payload over the 8 MB cap. self.add_design("nangate45", "gcd", metrics={"blob": "x" * (9 * 1024 * 1024)}) result, messages = self.run_script("--expectedDesigns", "3") self.assertEqual(result.returncode, 0, result.stdout + result.stderr) @@ -450,7 +448,6 @@ def test_blank_requester_flag_is_omitted_from_v1_messages(self): self.assertEqual(payload["build_user_email"], "ada@example.com") self.assertNotIn("change_author_email", payload) - def test_requester_without_at_sign_is_dropped(self): self.add_design("nangate45", "gcd") result, messages = self.run_script( @@ -470,7 +467,6 @@ def test_v1_fallback_warns_about_requester_once(self): self.assertNotIn("build_user_email", messages[0]["data"]) self.assertEqual(result.stdout.count("Not sending --buildUserEmail"), 1) - def test_requester_is_read_from_environment(self): self.add_design("nangate45", "gcd") result, messages = self.run_script( @@ -521,7 +517,6 @@ def test_environment_requester_reaches_v1_messages(self): self.assertEqual(result.returncode, 0, result.stdout + result.stderr) self.assertEqual(messages[0]["data"]["change_author_email"], "bob@example.com") - def test_requester_keys_win_over_same_named_v1_metric(self): metrics = dict(OVERSIZED_METRICS, build_user_email="metric") self.add_design("nangate45", "gcd", metrics=metrics)