Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions .github/verify-pr-spike/spike.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
bundles its own JavaScript, then runs the flow in $VERIFY_FLOW on each build
with the run ids the workflow passes in. Records timings, disk usage and bundle
checks. After each flow it reads the ids of the error events the app sent from
the device log; the `outputs` step hands them to the fetch job, one
comma-separated list per side.
the device log, and with $VERIFY_TRANSACTIONS set to `true` the ids of its
transactions too; the `outputs` step hands them to the fetch job, one
comma-separated list per side and kind.

Each subcommand is one workflow step. Results go to $RUNNER_TEMP/verify-pr-spike,
which the workflow uploads.
Expand Down Expand Up @@ -37,6 +38,8 @@
RESULTS = OUT / "results.json"
PATCH = OUT / f"pr{os.environ['VERIFY_PR']}.patch"
SIDES = ("without", "with")
# The workflow's `transactions` input: collect transaction ids as evidence.
TRANSACTIONS = os.environ["VERIFY_TRANSACTIONS"] == "true"
CORE = "packages/core"
CORE_SRC = f"{CORE}/src/"
# Same exclusions as the skill's patch (SKILL.md step 2).
Expand Down Expand Up @@ -65,6 +68,12 @@
# The sample's beforeSend log line (samples/react-native/src/App.tsx), one per
# error event the JavaScript SDK sends.
BEFORE_SEND_EVENT_ID = re.compile(r"'Event beforeSend:', '([0-9a-f]{32})'")
# The sample's beforeSendTransaction log line, one per transaction the
# JavaScript SDK sends.
BEFORE_SEND_TRANSACTION_ID = re.compile(r"'Transaction beforeSend:', '([0-9a-f]{32})'")
# Transaction ids passed to the fetch job per side, the first ones sent; the
# fetch job's MAX_TRANSACTIONS. results.json keeps them all.
MAX_TRANSACTIONS = 10


def load():
Expand Down Expand Up @@ -234,9 +243,9 @@ def adb(*args, **kwargs):
return run(["adb", *args], **kwargs)


def before_send_event_ids(logcat):
"""Event ids from the beforeSend log lines, in order, without duplicates."""
return list(dict.fromkeys(BEFORE_SEND_EVENT_ID.findall(logcat)))
def logged_ids(pattern, logcat):
"""Event ids from one kind of beforeSend log line, in order, without duplicates."""
return list(dict.fromkeys(pattern.findall(logcat)))


def run_side(side, results):
Expand Down Expand Up @@ -282,7 +291,9 @@ def run_side(side, results):
(run_dir / f"{run_id}.logcat").write_text(logcat, encoding="utf-8")
record["logcat_run_id_lines"] = logcat.count(run_id)
record["logcat_envelopes_sent"] = logcat.count("Envelope sent successfully")
record["event_ids"] = before_send_event_ids(logcat)
record["event_ids"] = logged_ids(BEFORE_SEND_EVENT_ID, logcat)
if TRANSACTIONS:
record["transaction_ids"] = logged_ids(BEFORE_SEND_TRANSACTION_ID, logcat)
with (run_dir / "screencap.png").open("wb") as png:
adb("exec-out", "screencap", "-p", stdout=png)
# An all-black screenshot compresses to a few KB; a real one is much larger.
Expand All @@ -300,19 +311,33 @@ def cmd_run(_args):
for side in SIDES:
if run_side(side, results) != 0:
failures.append(f"the Maestro flow failed for {side}")
if not results["runs"][side]["event_ids"]:
# With transactions, each side needs one and error events are optional.
record = results["runs"][side]
if TRANSACTIONS:
if not record["transaction_ids"]:
failures.append(f"no 'Transaction beforeSend:' event id in the device log for {side}")
elif not record["event_ids"]:
failures.append(f"no 'Event beforeSend:' event id in the device log for {side}")
save(results)
if failures:
sys.exit("; ".join(failures))


def cmd_outputs(_args):
"""Writes each side's event ids as a job output, a comma-separated list."""
"""Writes each side's error ids, and transaction ids if collected, as job outputs, comma-separated lists."""
runs = load()["runs"]
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
for side in SIDES:
fh.write(f"{side}_event_ids={','.join(runs[side]['event_ids'])}\n")
if not TRANSACTIONS:
continue
transaction_ids = runs[side]["transaction_ids"]
if len(transaction_ids) > MAX_TRANSACTIONS:
print(
f"{side}: {len(transaction_ids)} transaction ids, passing the first "
f"{MAX_TRANSACTIONS}; results.json has them all"
)
fh.write(f"{side}_transaction_ids={','.join(transaction_ids[:MAX_TRANSACTIONS])}\n")


def cmd_summary(_args):
Expand Down
Loading
Loading