commit 4c483527c5c99491270a6b7382bb1e236f4d2ccd
parent 6912efc8517fa2e05e80c130720803cd31285391
Author: Christian Grothoff <christian@grothoff.org>
Date: Tue, 10 Nov 2026 23:44:51 +0100
add wallet simulator to CI/CD
Diffstat:
11 files changed, 456 insertions(+), 44 deletions(-)
diff --git a/contrib/ci/Containerfile b/contrib/ci/Containerfile
@@ -163,6 +163,64 @@ RUN yes | sdkmanager "system-images;android-36;google_apis;x86_64" \
RUN pipx install git+https://gitlab.com/fdroid/fdroidserver.git \
&& fdroid --version
+# The GNU Taler services the *wallet* simulator drives the app against.
+#
+# The POS simulator talks to the public demo deployment; the wallet simulator
+# cannot, because it needs a stack it is allowed to ruin -- it revokes
+# denominations, corrupts the wallet's database, injects faults and wipes the
+# bank between rounds -- and because the wallet has to reach every service on
+# a `localhost` URL, which is what `adb reverse` gives it. So the whole stack
+# runs beside the emulator in this container: exchange, merchant, auditor,
+# libeufin bank and donau, on Postgres. That is about 530 MB in an image
+# every job pulls; the same trade as the emulator below, and for the same
+# reason -- the buildbot's generic stage step passes only jobCmd, never a
+# containerFile, so there is one image.
+#
+# `sudo` is not a convenience: `backend/stack.sh` creates its database role
+# with `sudo -u postgres`, which is how it works on the dedicated host too.
+# `iproute2` provides the `ss` that stack.sh waits for ports with -- without
+# it the wait silently succeeds and the next service starts into an occupied
+# port. `jq` and `wget` are what taler-unified-setup.sh checks for before it
+# does anything at all: without them it exits with "SKIP: jq required" and the
+# stack never starts, which stack.sh can only report as "died before becoming
+# ready".
+RUN apt-get update && apt-get -qy install --no-install-recommends \
+ donau \
+ iproute2 \
+ jq \
+ libeufin-bank \
+ postgresql \
+ sudo \
+ taler-auditor \
+ taler-exchange \
+ taler-exchange-offline \
+ taler-merchant \
+ taler-terms-generator \
+ wget \
+ && rm -rf /var/lib/apt/lists/* \
+ && command -v taler-exchange-httpd taler-merchant-httpd taler-auditor-httpd \
+ libeufin-bank donau-httpd taler-exchange-offline taler-terms-generator \
+ pg_ctlcluster jq wget > /dev/null
+
+# `taler-unified-setup.sh` is the one piece of the stack the archive does not
+# package. It is a single script in the exchange's *source* tree (installed
+# by `make install`, not by any .deb), and `backend/stack.sh` is written
+# around it -- it is what starts the nine services with one call and prints
+# `READY:` when they are all answering.
+#
+# Taken from master rather than from a tag on purpose: the archive's packages
+# above are built from master too (they are versioned 1.6.16 while the newest
+# tag is v1.6.9), so master's script is the one that matches them. The clone
+# is shallow and discarded in the same layer, so the image carries the 32 kB
+# script and not the 45 MB of history.
+RUN set -eu; \
+ git clone --quiet --depth 1 --no-tags \
+ https://git.taler.net/exchange /tmp/exchange-src; \
+ install -m 0755 /tmp/exchange-src/src/testing/taler-unified-setup.sh /usr/bin/; \
+ rm -rf /tmp/exchange-src; \
+ bash -n /usr/bin/taler-unified-setup.sh; \
+ grep -q 'READY:' /usr/bin/taler-unified-setup.sh
+
# Deployment to F-droid nightly
ENV FDROID_REPO_KEY /inputs/fdroid-repo-key.txt
ENV NIGHTLY_KEYSTORE_PATH /inputs/taler-nightly.keystore
diff --git a/contrib/ci/jobs/5-coverage/README.md b/contrib/ci/jobs/5-coverage/README.md
@@ -40,10 +40,25 @@ It runs **every JVM unit test in the repository** — `taler-kotlin-android`,
`merchant-lib`, `merchant-terminal` and `wallet`, the four modules that have
any. `cashier` and `donau-verificator` have none.
+For the two apps a simulator drives, the tests run against the **`sim` build
+type** (`:merchant-terminal:testSimUnitTest`, `:wallet:testFdroidSimUnitTest`)
+rather than `debug`. That is not a preference: JaCoCo matches execution data
+to classes by a checksum of the class file, so unit-test and emulator data can
+only appear in one report if both were recorded against the same variant.
+Reporting the wallet against `fdroidDebug` would silently drop every `.ec`
+file the wallet simulator produced.
+
It does **not** run the integration suites — `pos-simulator/` drives the
-merchant terminal in an Android emulator, which takes about two and a half
-hours for the whole suite even with hardware acceleration. That is a nightly
-on its own worker, not something to put on every push.
+merchant terminal in an Android emulator and `wallet-simulator/` drives the
+wallet against a complete local Taler stack, each hours rather than minutes
+for a whole suite even with hardware acceleration — the POS one measured
+103.7 s per scenario over 57 runs, and the wallet's hundred-odd scenarios are
+of the same order. Those are nightlies on a
+KVM-capable worker — [`6-simulator-pos`](../6-simulator-pos/README.md) and
+[`7-simulator-wallet`](../7-simulator-wallet/README.md) — not something to put
+on every push. Each one ends by calling this job with its execution data, so
+the report here is the merged one and there is no second figure to disagree
+with it.
### The emulator does work in this container
@@ -92,11 +107,17 @@ Containerfile rather than the shared one.
## Feeding an emulator run in
-The job already takes the other half. A `pos-simulator` run writes JaCoCo
-`.ec` files to `$POS_SIM_ROOT/run/coverage`; drop those into
-`/inputs/emulator-coverage` (or point `EMULATOR_EC_DIR` elsewhere) and they
-are merged into the same report rather than needing a second one. The landing
-page then also lists which scenarios produced them.
+The job already takes the other half, and both nightlies use it: a
+`pos-simulator` run writes JaCoCo `.ec` files to `$POS_SIM_ROOT/run/coverage`
+and a `wallet-simulator` run to `/opt/taler-sim/run/coverage`. Drop either set
+into `/inputs/emulator-coverage` (or point `EMULATOR_EC_DIR` at it) and it is
+merged into the same report rather than needing a second one. The landing page
+then also lists which scenarios produced them.
+
+The wallet nightly additionally publishes a wallet-only report at
+<https://lcov.taler.net/taler-android-wallet/>, from the same execution data
+and with the wallet harness's own landing page — the repo-wide page here
+cannot say much about one app among six.
That is the whole integration, so when a worker with KVM exists the remaining
work is to run the suite there and hand the directory over:
@@ -108,6 +129,6 @@ rsync -a <worker>:/tmp/taler-pos-sim/run/coverage/ inputs/emulator-coverage/
contrib/ci/ci.sh 5-coverage
```
-Fuzzing stays out either way: `pos-simulator/driver/explore.py` is a random
-walk, so its coverage is not reproducible between runs and would make the
-trend line meaningless.
+Fuzzing stays out either way: `pos-simulator/driver/explore.py` and
+`wallet-simulator/driver/explore.py` are random walks, so their coverage is
+not reproducible between runs and would make the trend line meaningless.
diff --git a/contrib/ci/jobs/5-coverage/coverage.sh b/contrib/ci/jobs/5-coverage/coverage.sh
@@ -7,17 +7,22 @@
# the JVM: a source-annotated page per class, green and red down the gutter.
#
# What runs here is every JVM unit test in the repository. The *integration*
-# suites -- pos-simulator/, which drives the merchant terminal in an emulator
+# suites -- pos-simulator/, which drives the merchant terminal in an emulator,
+# and wallet-simulator/, which drives the wallet against a local Taler stack
# -- are not run by this job, and the reason is a hard one: an Android
# emulator needs /dev/kvm, a container only gets it if the host passes the
-# device *and* the CI user may open it, and even accelerated the pos-simulator
-# suite is about two and a half hours. That is a nightly on a KVM-capable
-# worker, not a job that runs on every push.
+# device *and* the CI user may open it, and even accelerated each of those
+# suites is hours rather than minutes -- the POS one measured 103.7 s per
+# scenario over 57 runs, and the wallet's is of the same order with a hundred
+# scenarios of its own. Those are nightlies on a KVM-capable worker
+# (6-simulator-pos and 7-simulator-wallet), not jobs that run on every push.
#
-# When such a worker exists, this script already takes its output: drop the
-# `.ec` files a simulator run produced into /inputs/emulator-coverage (or
-# point EMULATOR_EC_DIR at them) and they are merged in, raising the same
-# report rather than needing a second one.
+# Either nightly feeds its result back here rather than raising a report of
+# its own: drop the `.ec` files a simulator run produced into
+# /inputs/emulator-coverage (or point EMULATOR_EC_DIR at them) and they are
+# merged in. That is also why the variants below are the `sim` ones -- JaCoCo
+# matches execution data to classes by a checksum of the class file, so the
+# unit tests have to be reported against the same build type the emulator ran.
set -exuo pipefail
REPO_NAME=taler-android
@@ -36,7 +41,7 @@ mkdir -p "${WORK}" "${ARTIFACT_PATH}"
:taler-kotlin-android:testDebugUnitTest \
:merchant-lib:testDebugUnitTest \
:merchant-terminal:testSimUnitTest \
- :wallet:testFdroidDebugUnitTest
+ :wallet:testFdroidSimUnitTest
if [ ! -s "${CLI}" ]; then
curl -sSfL -o "${CLI}" \
@@ -75,7 +80,7 @@ add_module() { # add_module <module> <variant>
add_module taler-kotlin-android debug
add_module merchant-lib debug
add_module merchant-terminal sim
-add_module wallet fdroidDebug
+add_module wallet fdroidSim
[ "${#CLASS_ARGS[@]}" -gt 0 ] || { echo "no class files to report on" >&2; exit 1; }
@@ -92,8 +97,15 @@ cp "${WORK}/coverage.xml" "${ARTIFACT_PATH}/coverage.xml" || true
# JaCoCo's own report goes under html/, the landing page sits at the top of
# the artifact and links into it -- otherwise the two would both want to be
# index.html and the summary would clobber the report.
+# --also-gaps: the page discounts lines no `sim` build could ever enter, and
+# each simulator knows that about its own app -- the terminal's screenshot-only
+# composables on one side, the wallet's @Preview bodies (27 % of everything the
+# wallet half of this report calls "missed") on the other. Without the second
+# module the repo-wide figure would call the wallet's preview functions
+# uncovered work.
python3 pos-simulator/coverage/summary_html.py "${ARTIFACT_PATH}" \
"${EMULATOR_EC_DIR}" --title "GNU Taler ${REPO_NAME}" \
+ --also-gaps wallet-simulator/coverage \
|| echo "summary page not written" >&2
chmod -R a+rX "${ARTIFACT_PATH}"
diff --git a/pos-simulator/coverage/report.sh b/pos-simulator/coverage/report.sh
@@ -76,7 +76,15 @@ rm -f "$MERGED"
# the second file; POS_UNIT_EXEC=0 leaves it out, or names one explicitly.
UNIT_EXEC=${POS_UNIT_EXEC:-auto}
if [ "$UNIT_EXEC" = "auto" ]; then
- UNIT_EXEC=$(ls -1 "$REPO/merchant-terminal/build/outputs/unit_test_code_coverage/"*/*.exec 2>/dev/null | head -1 || true)
+ # This variant's own file, and not whichever one the directory lists
+ # first: a tree that has also built the debug tests has an exec file
+ # beside it, and merging that one in is worse than merging none -- jacoco
+ # drops every class whose checksum does not match and says so in a line
+ # nobody reads, so the report would quietly show the simulator's figure as
+ # the union.
+ UNIT_EXEC=$(ls -1 \
+ "$REPO/merchant-terminal/build/outputs/unit_test_code_coverage/${VARIANT}UnitTest/"*.exec \
+ 2>/dev/null | head -1 || true)
fi
UNION=""
if [ -n "$UNIT_EXEC" ] && [ "$UNIT_EXEC" != "0" ] && [ -s "$UNIT_EXEC" ]; then
diff --git a/pos-simulator/coverage/summary_html.py b/pos-simulator/coverage/summary_html.py
@@ -28,12 +28,27 @@ that needs this harness's own knowledge:
So this writes `index.html` beside JaCoCo's, links into it, and says both.
- summary_html.py <out-dir> [ec-dir] [--title NAME]
+ summary_html.py <out-dir> [ec-dir] [--title NAME] [--also-gaps DIR]
+
+`--also-gaps` names another harness's `coverage/` directory, whose `gaps.py`
+is asked for the lines *its* app cannot reach. Run over one module's report
+nothing needs it; run repo-wide from CI, where the wallet's execution data is
+in the same report, the wallet's @Preview bodies have to come off the
+denominator too or the page calls Android Studio's preview pane uncovered
+work.
+
+One sharp edge in that: these maps are keyed by source *basename*, so two
+modules with a file of the same name share an entry. Five names collide
+today (MainActivity.kt, MainViewModel.kt, Order.kt, PaymentManager.kt,
+RefundManager.kt) and none of them carries a discounted line in either
+module, so nothing is wrong now -- but adding an @Preview to one of those
+five would discount the same line numbers in the other module's file too.
"""
from __future__ import annotations
import html
+import importlib.util
import subprocess
import sys
import time
@@ -67,10 +82,36 @@ def scenarios_from(ec_dir: Path | None) -> list[str]:
# dump was called. Stripping only the two labels this harness
# happened to use listed `login_url_shapes-02` beside
# `login_url_shapes`, and every exploration step as its own scenario.
- names.add(re.sub(r"-\d{2}(-[\w-]+)?$", "", f.stem))
+ stem = re.sub(r"-\d{2}(-[\w-]+)?$", "", f.stem)
+ # The wallet harness names its episodes
+ # "suite-w0-<stamp>-<scenario>", so without this the repo-wide page
+ # lists a worker number and a unix timestamp as the scenario's name.
+ stem = re.sub(r"^(suite|qr|explore)-(w\d+|seed\d+)-\d+-", "", stem)
+ names.add(stem)
return sorted(names)
+def gaps_of(coverage_dir: Path):
+ """Another harness's `gaps.py`, loaded from its path.
+
+ By path and under a name of its own, because every simulator calls the
+ module `gaps` -- importing a second one normally would hand back the first
+ out of sys.modules and silently discount the wrong app's lines.
+ """
+ module_path = coverage_dir / "gaps.py"
+ if not module_path.is_file():
+ print(f"no gaps.py under {coverage_dir}", file=sys.stderr)
+ return None
+ name = f"gaps_{coverage_dir.parent.name.replace('-', '_')}"
+ spec = importlib.util.spec_from_file_location(name, module_path)
+ if spec is None or spec.loader is None:
+ return None
+ module = importlib.util.module_from_spec(spec)
+ sys.modules[name] = module
+ spec.loader.exec_module(module)
+ return module
+
+
def commit() -> str:
try:
out = subprocess.run(["git", "-C", str(REPO), "log", "-1",
@@ -118,6 +159,12 @@ def main(argv: list[str]) -> int:
i = argv.index("--title")
title = argv[i + 1]
del argv[i:i + 2]
+ also: list[Path] = []
+ while "--also-gaps" in argv:
+ i = argv.index("--also-gaps")
+ raw = Path(argv[i + 1])
+ also.append(raw if raw.is_absolute() else REPO / raw)
+ del argv[i:i + 2]
out_dir = Path(argv[0]) if argv else Path("out/coverage")
ec_dir = Path(argv[1]) if len(argv) > 1 else None
sim_xml = out_dir / "coverage.xml"
@@ -128,6 +175,12 @@ def main(argv: list[str]) -> int:
has_union = union_xml.exists()
skip = gaps.preview_lines(REPO)
+ for coverage_dir in also:
+ other = gaps_of(coverage_dir)
+ if other is None:
+ continue
+ for name, lines in other.preview_lines(REPO).items():
+ skip[name] = skip.get(name, set()) | lines
missed, covered, unreachable = gaps.source_misses(str(sim_xml), skip)
reachable_total = covered + missed - unreachable
reachable_pct = 100 * covered / reachable_total if reachable_total else 0.0
@@ -147,6 +200,10 @@ def main(argv: list[str]) -> int:
dead = sum(len(v) for v in gaps.dead_lines(REPO).values())
debug_only = sum(len(v) for v in gaps.debug_only_lines(REPO).values())
+ # Whatever is in the skip map and in neither of those two buckets is an
+ # @Preview body -- the wallet's, when a repo-wide run passed --also-gaps.
+ marked_total = sum(len(v) for v in skip.values())
+ previews = max(0, marked_total - dead - debug_only)
scenarios = scenarios_from(ec_dir)
ec_count = len(list(ec_dir.glob("*.ec"))) if ec_dir and ec_dir.is_dir() else 0
@@ -231,7 +288,10 @@ def main(argv: list[str]) -> int:
unreachable=f"{unreachable:,}",
debug_only=f"{debug_only:,}",
dead=f"{dead:,}",
- marked=f"{debug_only + dead:,}",
+ marked=f"{marked_total:,}",
+ previews=(f", and {previews:,} inside <code>@Preview</code> bodies, "
+ f"which exist for Android Studio's preview pane and which "
+ f"nothing calls" if previews else ""),
rows_counters="".join(rows_counters),
rows_pkg="".join(rows_pkg),
rows_methods="".join(rows_methods) or
@@ -355,7 +415,7 @@ reachable in principle and not by us.</p>
<p class="sub">{marked} source lines are marked as impossible for a
<code>sim</code> build to enter — {debug_only} in composables whose only
caller is the <code>debug</code> source set, {dead} in functions with no caller
-at all (<a href="https://bugs.gnunet.org/view?id=11981">11981</a>). Of those,
+at all (<a href="https://bugs.gnunet.org/view?id=11981">11981</a>){previews}. Of those,
<strong>{unreachable}</strong> are lines JaCoCo counted as missed, and it is
that figure which comes off the denominator above.</p>
diff --git a/wallet-simulator/README.md b/wallet-simulator/README.md
@@ -35,13 +35,18 @@ tripwire:/opt/taler-sim/
run/ stack/env.json, logs, emulator logs
```
-The checkout under `simulator/` in taler-android is the source of truth; push it
-with
+The checkout under `wallet-simulator/` in taler-android is the source of truth;
+push it with
```bash
-rsync -a simulator/ root@tripwire.taler.net:/opt/taler-sim/
+rsync -a wallet-simulator/ root@tripwire.taler.net:/opt/taler-sim/
```
+A reduced version of the same thing also runs **nightly in CI**, in one
+container, against a stack brought up beside the emulator -- see
+[`contrib/ci/jobs/7-simulator-wallet`](../contrib/ci/jobs/7-simulator-wallet/README.md).
+That is where the coverage report on <https://lcov.taler.net/> comes from.
+
## Running it
Bring the stack and one emulator up, then check that the basics work:
@@ -108,10 +113,20 @@ uninstrumented classes and the sources:
```bash
rsync -a root@tripwire.taler.net:/opt/taler-sim/run/coverage/ /tmp/ec/
-JAVA_HOME=/home/claude/jdk-17 simulator/coverage/report.sh /tmp/ec
-python3 simulator/coverage/gaps.py simulator/out/coverage/coverage.xml
+JAVA_HOME=/home/claude/jdk-17 wallet-simulator/coverage/report.sh /tmp/ec
+python3 wallet-simulator/coverage/gaps.py \
+ wallet-simulator/out/coverage/coverage.xml
```
+`report.sh` writes three things into `out/coverage/`: JaCoCo's own report
+under `html/`, the same thing with the module's JVM unit tests merged in under
+`html-with-units/` (both are only comparable when the tests ran against
+`fdroidSim`, which is what `:wallet:testFdroidSimUnitTest` does), and
+`index.html` -- a landing page over the top that says how much of the
+shortfall is reachable at all, what the figure does *not* cover (wallet-core
+is TypeScript inside QuickJS and cannot be instrumented), and which scenarios
+produced it. That page is what the nightly publishes.
+
`gaps.py` ranks what is still untouched. Four composables in that ranking have
no caller at all -- `PromptAddContactScreen`, `GridMenu`, `DemandAttention` and
`SelectExchangeDialogFragment`, about 190 lines -- so no scenario can ever
@@ -139,14 +154,33 @@ resolves to — `testFdroidSimUnitTest` rather than `testFdroidDebugUnitTest`.
`sim` is `initWith debug`, so the same tests run against the same code, and CI
asks for `:wallet:check` rather than a task name.
-### Developer mode is mandatory
-
-`HandleUriScreen` only accepts `taler+http://` URIs when developer mode is on,
-and `MainActivity` pushes the *persisted* flag into `MainViewModel` at every
-start — so a debug build does **not** come up in developer mode, whatever
-`BuildConfig.DEBUG` says. `Wallet.fresh_start()` therefore switches it on
-through Settings before anything else; without that step every URI from a local
-http stack comes back as "Unsupported URI".
+### Two settings are mandatory, and the app has neither on by default
+
+`Wallet.fresh_start()` turns both on through Settings before a scenario starts,
+in this order, because the app comes up without either:
+
+* **Developer mode.** `HandleUriScreen` only accepts `taler+http://` URIs when
+ it is on, and `MainActivity` pushes the *persisted* flag into
+ `MainViewModel` at every start — so a debug build does **not** come up in
+ developer mode, whatever `BuildConfig.DEBUG` says. Without this step every
+ URI from a local http stack comes back as "Unsupported URI".
+* **New main screen** (`MainScreen.kt` picks `NewMainScreen` when the
+ preference is on and `LegacyMainScreen` otherwise). Everything here is
+ written for the new one: its app bar carries the scan action and the
+ settings action, where the legacy screen puts scan, send, request, withdraw
+ and deposit inside a modal bottom sheet that nothing in the driver opens.
+ The row is only rendered while developer mode is on, which is why the order
+ above is not a preference.
+
+ The default was flipped to the legacy screen by `[wallet] hide new balances
+ screen behind dev mode toggle`, after this harness was written, and the
+ symptom was worth a day: `home()` looked for a label the legacy screen does
+ not have, pressed Back six times, left the app, and every scenario then
+ failed on something unrelated — "no label matching `^Settings$`; screen
+ showed: `['At a glance', 'Gmail', …]`", which is the *launcher*.
+ `Wallet.in_foreground()` now answers that question from the resumed
+ activity instead of from a label, because the launcher's own icon for this
+ app is labelled "Taler Wallet" and no text match can tell the two apart.
### A stack restart invalidates the wallet
@@ -345,7 +379,9 @@ fingerprinted so repeats collapse.
| `driver/dbprobe.py` | copy the wallet's SQLite database off the device and query it |
| `driver/replay.py` | replay an episode, and shrink it with ddmin |
| `coverage/report.sh` | merge `.ec` files into an HTML/XML report |
+| `coverage/summary_html.py` | the landing page over that report |
| `coverage/gaps.py` | rank what is still uncovered, and diff two reports |
+| `coverage/deadcode.py` | declarations nothing refers to, and coverage without them |
| `findings/new_finding.py` | scaffold a write-up from an episode's artifacts |
## Findings
diff --git a/wallet-simulator/backend/stack.sh b/wallet-simulator/backend/stack.sh
@@ -31,7 +31,12 @@ HERE="$(cd "$(dirname "$0")" && pwd)"
# sim-twister.conf to put the fault injector in front of the exchange.
CONF_NAME=${SIM_CONF:-sim.conf}
CONF_SRC="$HERE/$CONF_NAME"
+# The proxy daemon: the dedicated host builds it into /opt/twister, a CI
+# container installs the `taler-twister` package, which puts it on PATH.
TWISTER_BIN=${SIM_TWISTER_BIN:-/opt/twister/bin/taler-twister-service}
+if [ ! -x "$TWISTER_BIN" ] && command -v taler-twister-service >/dev/null; then
+ TWISTER_BIN=$(command -v taler-twister-service)
+fi
DB=${SIM_DB:-talersim}
# Services: exchange, merchant, libeufin bank, wirewatch, aggregator, transfer,
# merchant depositcheck, merchant wirewatch, donau.
diff --git a/wallet-simulator/coverage/report.sh b/wallet-simulator/coverage/report.sh
@@ -70,6 +70,40 @@ MERGED="$OUT_DIR/merged.exec"
rm -f "$MERGED"
"$JAVA" -jar "$CLI" merge "${EC_FILES[@]}" --destfile "$MERGED"
+# The emulator is not the only thing that covers this app: the wallet module
+# carries JVM unit tests, and a report that cannot see them invites us to
+# spend emulator time re-covering what a unit test already reaches. So both
+# are reported -- the simulator alone, which is what a round of scenarios
+# achieved, and the union, which is what is actually tested.
+#
+# `enableUnitTestCoverage` on the `sim` build type in wallet/build.gradle is
+# what produces the second file, and the build type matters: jacoco matches
+# execution data to classes by checksum, so the unit tests have to have run
+# against the same variant the emulator did
+# (`./gradlew :wallet:testFdroidSimUnitTest`). SIM_UNIT_EXEC=0 leaves it
+# out, or names one explicitly.
+UNIT_EXEC=${SIM_UNIT_EXEC:-auto}
+if [ "$UNIT_EXEC" = "auto" ]; then
+ # This variant's own file, and not whichever one the directory lists
+ # first: a tree that has also built fdroidDebug has an exec file beside
+ # it, and merging that one in is worse than merging none -- jacoco drops
+ # every class whose checksum does not match and says so in a line nobody
+ # reads, so the report would quietly show the simulator's figure as the
+ # union.
+ UNIT_EXEC=$(ls -1 \
+ "$REPO/wallet/build/outputs/unit_test_code_coverage/${VARIANT}UnitTest/"*.exec \
+ 2>/dev/null | head -1 || true)
+fi
+UNION=""
+if [ -n "$UNIT_EXEC" ] && [ "$UNIT_EXEC" != "0" ] && [ -s "$UNIT_EXEC" ]; then
+ UNION="$OUT_DIR/merged-with-units.exec"
+ rm -f "$UNION"
+ "$JAVA" -jar "$CLI" merge "${EC_FILES[@]}" "$UNIT_EXEC" --destfile "$UNION"
+ echo "including unit-test coverage from $UNIT_EXEC" >&2
+else
+ echo "no unit-test coverage merged (run :wallet:testFdroidSimUnitTest)" >&2
+fi
+
# Kotlin and Java classes land in separate trees; both belong in the report,
# and both must be the uninstrumented ones.
CLASS_ARGS=()
@@ -98,5 +132,33 @@ for counter in root.findall("counter"):
if total:
print(f"{t.lower():12} {covered:7}/{total:<7} {100 * covered / total:5.1f}%")
PY
+if [ -n "$UNION" ]; then
+ "$JAVA" -jar "$CLI" report "$UNION" \
+ "${CLASS_ARGS[@]}" \
+ --sourcefiles "$REPO/wallet/src/main/java" \
+ --sourcefiles "$REPO/taler-kotlin-android/src/main/java" \
+ --html "$OUT_DIR/html-with-units" \
+ --xml "$OUT_DIR/coverage-with-units.xml" \
+ --name "Taler wallet simulator + unit tests ($VARIANT)" >/dev/null
+ echo
+ echo "simulator and unit tests together:"
+ python3 "$(dirname "$0")/union_summary.py" \
+ "$OUT_DIR/coverage-with-units.xml" "$OUT_DIR/coverage.xml"
+else
+ # A stale pair from an earlier run would otherwise make the landing page
+ # claim a union it did not measure.
+ rm -f "$OUT_DIR/coverage-with-units.xml"
+ rm -rf "$OUT_DIR/html-with-units"
+fi
+
+# A landing page over the top of JaCoCo's own, because JaCoCo cannot know
+# which of the red lines no run could ever enter, nor what produced the
+# figures. Failure here must not fail the run: the numbers above are the
+# deliverable and this is a convenience.
+python3 "$(dirname "$0")/summary_html.py" "$OUT_DIR" "$EC_DIR" \
+ ${SIM_SUMMARY_ARGS:-} || echo "summary page not written" >&2
+
echo
-echo "report: $OUT_DIR/html/index.html" >&2
+echo "summary: $OUT_DIR/index.html" >&2
+echo "report: $OUT_DIR/html/index.html" >&2
+if [ -n "$UNION" ]; then echo "union: $OUT_DIR/html-with-units/index.html" >&2; fi
diff --git a/wallet-simulator/driver/twister.py b/wallet-simulator/driver/twister.py
@@ -39,13 +39,35 @@ Dot paths address nested fields, and a numeric token is an array index, so
from __future__ import annotations
import json
+import os
+import shutil
import subprocess
import threading
import time
from pathlib import Path
from typing import Callable
-BINARY = "/opt/twister/bin/taler-twister"
+
+def _binary() -> str:
+ """The twister *client* -- the thing that arms and disarms the proxy.
+
+ Three places, in order: SIM_TWISTER_CLI, the dedicated host's own build
+ under /opt/twister, and PATH. The last is what a CI container has, where
+ twister comes from the `taler-twister` Debian package as /usr/bin; before
+ this looked anywhere but /opt every fault-injection scenario there failed
+ with "no twister binary", which reads like a broken stack rather than a
+ harness that was looking in one hard-coded place.
+ """
+ chosen = os.environ.get("SIM_TWISTER_CLI")
+ if chosen:
+ return chosen
+ builtin = "/opt/twister/bin/taler-twister"
+ if Path(builtin).is_file():
+ return builtin
+ return shutil.which("taler-twister") or builtin
+
+
+BINARY = _binary()
DEFAULT_CONFIG = "/opt/taler-sim/run/stack/sim-twister.conf"
ENV_FILE = Path("/opt/taler-sim/run/stack/env.json")
diff --git a/wallet-simulator/driver/wallet.py b/wallet-simulator/driver/wallet.py
@@ -23,13 +23,28 @@ from __future__ import annotations
import re
import time
+from typing import Optional
-from device import Device, Screen
+from device import Device, Node, Screen
DEV_MODE_LABEL = "Developer mode"
# Only shown while developer mode is on, so it doubles as the check that the
# toggle took effect.
DEV_MODE_MARKER = "Withdraw demo KUDOS"
+# The wallet has two main screens and ships with a switch between them
+# (`MainScreen.kt`: NewMainScreen when the preference is on, LegacyMainScreen
+# otherwise, and since "hide new balances screen behind dev mode toggle" the
+# default is off). Everything in this harness is written for the new one --
+# its app bar carries the scan action and the settings action, where the
+# legacy screen puts the actions in a modal bottom sheet nothing here opens --
+# so `fresh_start` turns it on, next to developer mode and for the same
+# reason: the app does not come up in the state the simulator needs.
+NEW_MAIN_SCREEN_LABEL = "New main screen"
+# A label that only the main screen of *either* layout shows: the new screen's
+# app-bar title and the legacy screen's bottom-navigation item are both
+# `balances_title`. It has to cover both, because this is what the driver
+# steers by on the way to the switch above.
+HOME_MARKER = r"(?i)^(Scan QR code|Balances)$"
class Wallet:
@@ -58,16 +73,71 @@ class Wallet:
# granted again or the scan screen opens on a system dialog instead.
self.dev.grant_camera()
self.dev.launch()
- self.dev.wait_for(r"(?i)wallet|balance|withdraw", timeout=90)
+ self.wait_until_up()
if dev_mode:
self.enable_dev_mode()
+ # Developer mode first: the switch below is only rendered when
+ # developer mode is on (SettingsScreen.kt gates it), so the order
+ # is not a preference.
+ self.enable_new_main_screen()
+ self.wait_until_up()
+
+ def in_foreground(self, screen: Optional[Screen] = None) -> bool:
+ """Is the app the thing on screen?
+
+ A label match cannot answer this, and that is not hypothetical: the
+ launcher's own icon for this app is labelled "Taler Wallet", so a wait
+ for `wallet|balance|withdraw` is satisfied by the *home screen* with
+ the app not running at all -- and the scenario then fails thirty
+ seconds later looking for something else. The resumed activity can
+ answer it, and `Screen` already carries it.
+ """
+ activity = (screen.activity if screen is not None
+ else self.dev.current_activity())
+ return activity.startswith(self.dev.pkg + "/")
+
+ def wait_until_up(self, timeout: int = 180) -> Screen:
+ """Wait for the app's own main screen, cold start included.
+
+ `am start -W` returns at the first frame, which after a `pm clear` is
+ well before Compose has laid the main screen out. Three minutes
+ rather than one: the first start after a wipe has no AOT artifacts to
+ use and wallet-core has to create its database, which on a shared CI
+ worker is minutes rather than seconds.
+ """
+ deadline = time.monotonic() + timeout
+ last = Screen()
+ while time.monotonic() < deadline:
+ last = self.dev.dump()
+ if not self.in_foreground(last):
+ self.dev.launch()
+ time.sleep(2)
+ continue
+ if last.find(HOME_MARKER):
+ return last
+ time.sleep(1.5)
+ raise TimeoutError(
+ f"the wallet's main screen did not appear within {timeout}s; "
+ f"activity {last.activity!r}, screen showed: {last.texts()}"
+ )
def home(self, tries: int = 6) -> Screen:
"""Back out to the main screen."""
for _ in range(tries):
screen = self.dev.dump()
- if screen.find(r"(?i)^Scan QR code$") and not screen.find(r"(?i)^Close sheet$"):
+ if screen.find(HOME_MARKER) and not screen.find(r"(?i)^Close sheet$"):
return screen
+ # Back is only a way *back* while the app is in front. On the
+ # launcher it does nothing, and on the app's own main screen it
+ # leaves the app -- so a main screen this loop did not recognise
+ # used to end with six Back presses and every later label search
+ # reading the launcher: "no label matching '^Settings$'; screen
+ # showed: ['At a glance', 'Gmail', ...]". Relaunching is what the
+ # caller means by "go home".
+ if not self.in_foreground(screen):
+ self.dev.launch()
+ time.sleep(2)
+ continue
self.dev.back()
time.sleep(1)
return self.dev.dump()
@@ -165,6 +235,55 @@ class Wallet:
f"settings showed: {self.dev.dump().texts()}")
self.home()
+ def switch_state(self, screen: Screen, label: str) -> Optional[tuple[Node, bool]]:
+ """A settings switch row, and whether it is on.
+
+ The label and the switch are separate nodes; the switch is the
+ checkable one on the same line, which is also the only thing that
+ reports its state.
+ """
+ row = screen.find(label)
+ if row is None:
+ return None
+ _, y = row.center
+ for node in screen.nodes:
+ if node.checkable and node.bounds[1] <= y <= node.bounds[3]:
+ return row, node.checked
+ return row, False
+
+ def enable_new_main_screen(self) -> None:
+ """Switch the app to the main screen this harness is written for.
+
+ Not cosmetic: on the legacy main screen the actions the scenarios
+ drive -- scan, send, request, withdraw, deposit -- are inside a modal
+ bottom sheet that nothing here opens, and its app bar has no settings
+ action either. A build without the switch at all is left alone, so
+ this stays correct when the preference eventually goes away.
+ """
+ self.open_settings()
+ try:
+ screen = self.scroll_to_text(NEW_MAIN_SCREEN_LABEL)
+ except TimeoutError:
+ return
+ state = self.switch_state(screen, NEW_MAIN_SCREEN_LABEL)
+ if state is None:
+ return
+ row, already_on = state
+ if already_on:
+ self.home()
+ return
+ # The switch at the right-hand end of the row, as for developer mode;
+ # the label itself is not the clickable node.
+ width = max(n.bounds[2] for n in screen.nodes)
+ self.dev.tap(width - 100, row.center[1])
+ time.sleep(1.5)
+ screen = self.dev.dump()
+ state = self.switch_state(screen, NEW_MAIN_SCREEN_LABEL)
+ if state is not None and not state[1]:
+ self.dev.tap_node(row) # in case the switch moved
+ time.sleep(1.5)
+ self.home()
+
# -- entry points -----------------------------------------------------
def dismiss_permission_dialog(self) -> bool:
diff --git a/wallet/build.gradle b/wallet/build.gradle
@@ -74,6 +74,15 @@ android {
signingConfig signingConfigs.debug
minifyEnabled false
enableAndroidTestCoverage true
+ // Inherited from debug through initWith, and spelled out because
+ // the coverage report depends on it: the emulator is not the only
+ // thing that covers this app, and JaCoCo can only merge execution
+ // data with the *same* class files behind it. Reporting the
+ // simulator's .ec files and the JVM unit tests together therefore
+ // means both have to come from this build type, which is why
+ // contrib/ci/jobs/5-coverage runs :wallet:testFdroidSimUnitTest
+ // rather than the fdroidDebug one.
+ enableUnitTestCoverage true
matchingFallbacks = ['debug']
}
}