From 0298d18f186e5b44dc24e53be006779332450e46 Mon Sep 17 00:00:00 2001 From: Xaltha Date: Mon, 23 Nov 2026 19:12:18 +0000 Subject: [PATCH] feat(pm-console): check the Android app with no connection on a device in CI (#13500) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Android app is the site in Chrome, and the site already works offline (service worker cache, outbox, Background Sync) — but that had only ever been checked in a desktop browser, never on a device. This adds the check the issue asks for, and writes what Android does differently into the README. - pm-console-android-offline workflow (nightly 07:17 UTC, manual): builds the APK against the demo edge on the runner, starts the demo edge, starts an emulator, and drives the app: open, aeroplane mode, open again from the icon, answer a question, swipe the app away, network back — then checks the demo edge saw that answer exactly once. - offline-check.sh: the adb driver for the steps above. - The APK builds against a demo site: -PpmConsoleSite / PM_CONSOLE_SITE, defaulting to https://pm.security.cab, so the release build is unchanged. A demo site is plain http, so the app opens as a Custom Tab rather than a verified TWA there. - The demo host records every canned action it runs to PM_CONSOLE_DEMO_ACT_LOG (one JSON line each), the witness the driver counts; unset, the demo writes nothing. Covered by test/demo-act-log.test.ts. - README: what Android does differently under 'With no connection' (the sync survives the app being swiped away; the undo pause is the page's own), and the check named in both READMEs. Refs #13500 --- .../workflows/pm-console-android-offline.yml | 79 ++++++ pm-stack/console/README.md | 23 +- pm-stack/console/android/README.md | 9 +- pm-stack/console/android/app/build.gradle | 12 +- pm-stack/console/android/build.sh | 10 +- pm-stack/console/android/offline-check.sh | 261 ++++++++++++++++++ pm-stack/console/scripts/demo-state.ts | 26 +- pm-stack/console/test/demo-act-log.test.ts | 48 ++++ 8 files changed, 459 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/pm-console-android-offline.yml create mode 100755 pm-stack/console/android/offline-check.sh create mode 100644 pm-stack/console/test/demo-act-log.test.ts diff --git a/.github/workflows/pm-console-android-offline.yml b/.github/workflows/pm-console-android-offline.yml new file mode 100644 index 0000000000..e1c4b79e8c --- /dev/null +++ b/.github/workflows/pm-console-android-offline.yml @@ -0,0 +1,79 @@ +name: pm-console-android offline + +# CI tier policy: see .github/ci-policy.md. This is CI, not a release, +# so it runs on the nightly schedule and by hand, never on push. +# +# Checks the PM console Android app with no connection on a device in +# CI (#13500): it builds the app against the demo edge on the runner, +# starts an emulator, installs the APK, and drives it — open, aeroplane +# mode, open again from the icon, answer a question, swipe the app +# away, network back — then checks the demo edge saw that answer +# exactly once. What Android does differently from desktop Chrome is +# in pm-stack/console/README.md under "With no connection". +on: + schedule: + - cron: "17 7 * * *" + workflow_dispatch: + +permissions: + contents: read + +# One run at a time, in order; a newer run never cancels one that is +# driving the emulator. +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +jobs: + offline-check: + name: "check the app with no connection on a device" + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v7 + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + - name: Build the APK against the demo edge + # The emulator reaches this machine as 10.0.2.2. The site is + # plain http there, so the app opens as a Custom Tab rather + # than a verified Trusted Web Activity; the web content under + # test is the same. + env: + PM_CONSOLE_SITE: http://10.0.2.2:4897 + run: bash pm-stack/console/android/build.sh + - name: Start the demo edge + env: + PM_CONSOLE_DEMO_ACT_LOG: ${{ github.workspace }}/pm-console-acts.jsonl + run: | + : >pm-console-acts.jsonl + nohup bun run pm-stack/console/scripts/edge-demo.ts 4897 >edge-demo.log 2>&1 & + echo $! >edge-demo.pid + disown + for attempt in $(seq 1 30); do + if curl -fsS --max-time 5 "http://127.0.0.1:4897/console/health" >/dev/null 2>&1; then + echo "demo edge answers at http://127.0.0.1:4897/console/health" + exit 0 + fi + sleep 2 + done + echo "the demo edge did not answer its health check" >&2 + cat edge-demo.log >&2 + exit 1 + - name: Check the app with no connection + uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2 + with: + api-level: 34 + target: google_apis + arch: x86_64 + profile: pixel_7 + disable-animations: true + emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim + script: bash pm-stack/console/android/offline-check.sh --apk pm-stack/console/android/app/build/outputs/apk/release/app-release.apk --edge-url http://127.0.0.1:4897 --act-log pm-console-acts.jsonl + - name: Keep the act log and the edge log + if: always() + uses: actions/upload-artifact@v7 + with: + name: pm-console-android-offline-logs + path: | + pm-console-acts.jsonl + edge-demo.log + if-no-files-found: warn diff --git a/pm-stack/console/README.md b/pm-stack/console/README.md index a50ea37edd..1ccb39ddf4 100644 --- a/pm-stack/console/README.md +++ b/pm-stack/console/README.md @@ -260,6 +260,23 @@ the Android app alike (which is the same site in Chrome). being done is told so, and asks again. And a name keeps to the side that first took it, Cloudflare or a machine, whichever would be chosen for it later. + + On Android the app is the same site in Chrome, so the same worker and + the same outbox run there — the difference is only the page's life. + Swiping the app away closes the page, not the worker: the sync stays + registered, and Chrome wakes the worker when the network is back, so + an answer made offline is still sent with the app closed. There is no + deadline in the app: the sync stays registered until it runs, or the + browser says it is its last call for it, and then opening the app + sends what waits. The one thing the page owns is the few seconds an + answer waits before it is written down (the undo pause): if the app + is closed in that pause, the page tries to write it as it hides, and + if that write does not reach the outbox the answer is lost and the + question stays open. The `pm-console-android-offline` workflow + checks this every night and on demand: an emulator, the app against + the demo edge, aeroplane mode, an answer made offline, the app + swiped away, and the answer arriving exactly once when the network + is back. - **"Sent" means recorded.** An answer the platform took and did not record (a question that was settled in the meantime) is not counted as sent: it is listed under "could not be done", with why. A question @@ -417,4 +434,8 @@ offered. See its README. Because it is the site, it opens with no connection and keeps what is done there exactly as the site does (above, "With no connection"): text dictated or shared into it with no signal lands in Ask, is kept when -sent, and goes when the phone is connected again. +sent, and goes when the phone is connected again. The Android half of +that is checked on a device in CI, not only in a desktop browser: the +`pm-console-android-offline` workflow starts an emulator, installs the +built APK, and drives it against the demo edge with the network off +and on again. diff --git a/pm-stack/console/android/README.md b/pm-stack/console/android/README.md index 72ce96762f..e9cd8185f2 100644 --- a/pm-stack/console/android/README.md +++ b/pm-stack/console/android/README.md @@ -141,5 +141,10 @@ The page says which it is. Later builds install over it. The native parts are checked by compiling the build and reading its merged manifest; the site's side of each (the Ask box taking handed-over -words, linking a phone, the summary) is tested in `test/`. They have not -been exercised by an automated run on a device. +words, linking a phone, the summary) is tested in `test/`. The app +with no connection is checked on a device in CI: the +`pm-console-android-offline` workflow (nightly, and on demand) starts +an emulator, installs the built APK, and drives it against the demo +edge — open, aeroplane mode, open again from the icon, answer a +question, swipe the app away, network back — and checks the demo edge +saw that answer exactly once. See `offline-check.sh` for the steps. diff --git a/pm-stack/console/android/app/build.gradle b/pm-stack/console/android/app/build.gradle index af3178cb23..e6f1dc81de 100644 --- a/pm-stack/console/android/app/build.gradle +++ b/pm-stack/console/android/app/build.gradle @@ -10,7 +10,8 @@ plugins { id 'com.android.application' } -def site = 'https://pm.security.cab' +def site = findProperty('pmConsoleSite') ?: 'https://pm.security.cab' +def siteHost = new URI(site).host def keystore = System.getenv('PM_ANDROID_KEYSTORE') // A release names its own version (build.sh works both out from the // commit, so a later build always installs over an earlier one). A @@ -28,7 +29,14 @@ android { targetSdk 34 versionCode releaseCode ? releaseCode.toInteger() : 3 versionName releaseName ?: '0.3.0' - manifestPlaceholders = [hostName: 'pm.security.cab', defaultUrl: "${site}/console/"] + // The site the app opens. The offline check builds it against + // the demo edge on the runner instead + // (-PpmConsoleSite=http://10.0.2.2:4897, via PM_CONSOLE_SITE in + // build.sh); anything else keeps the real site, and the release + // build is unchanged. A demo site is plain http, so the app + // opens there as a Custom Tab rather than a verified Trusted + // Web Activity; the web content under test is the same. + manifestPlaceholders = [hostName: siteHost, defaultUrl: "${site}/console/"] // The app's half of the link to the site. The site's half is // /.well-known/assetlinks.json, served by pm-console. resValue 'string', 'console_url', "${site}/console/" diff --git a/pm-stack/console/android/build.sh b/pm-stack/console/android/build.sh index 7d07956d12..b5271241c9 100755 --- a/pm-stack/console/android/build.sh +++ b/pm-stack/console/android/build.sh @@ -4,7 +4,9 @@ # Inputs (environment): # KEYSTORE_B64 base64 of the PKCS#12 signing keystore (key alias pmconsole) # PM_ANDROID_KEYSTORE_PASSWORD its password -# GRADLE_VERSION Gradle to fetch (default 8.9; AGP 8.5 needs 8.7 or later) +# PM_CONSOLE_SITE site the app opens (default https://pm.security.cab); +# the offline check sets it to the demo edge +# on the runner, http://10.0.2.2:4897 # Needs: a JDK 17 or 21, an Android SDK at ANDROID_HOME, curl, unzip. # # With both keystore variables set the result is app/build/outputs/apk/release/pm-console.apk, @@ -58,7 +60,11 @@ if [ -n "${KEYSTORE_B64:-}" ] && [ -n "${PM_ANDROID_KEYSTORE_PASSWORD:-}" ]; the export PM_ANDROID_KEYSTORE="$keystore" fi -"$GRADLE" --no-daemon --console=plain assembleRelease +GRADLE_ARGS=(--no-daemon --console=plain assembleRelease) +if [ -n "${PM_CONSOLE_SITE:-}" ]; then + GRADLE_ARGS+=("-PpmConsoleSite=$PM_CONSOLE_SITE") +fi +"$GRADLE" "${GRADLE_ARGS[@]}" printf '%s\n%s\n' "${PM_ANDROID_VERSION_NAME:-0.3.0}" "${PM_ANDROID_VERSION_CODE:-3}" >"$OUT/version" echo "build.sh: version ${PM_ANDROID_VERSION_NAME:-0.3.0} (code ${PM_ANDROID_VERSION_CODE:-3})" diff --git a/pm-stack/console/android/offline-check.sh b/pm-stack/console/android/offline-check.sh new file mode 100755 index 0000000000..fe3ddffda0 --- /dev/null +++ b/pm-stack/console/android/offline-check.sh @@ -0,0 +1,261 @@ +#!/usr/bin/env bash +# offline-check.sh — drive the PM console Android app on an emulator +# against the demo edge, with the network off and on again. +# +# Usage: +# offline-check.sh --apk --edge-url --act-log +# [--answer-label ] [--question-text ] +# [--next-question-text ] +# +# The caller starts the emulator and the demo edge first: the APK is +# built against the emulator's view of the edge +# (PM_CONSOLE_SITE=http://10.0.2.2:), the edge answers at +# --edge-url from this machine, and --act-log is the file the edge +# appends every action it runs to (PM_CONSOLE_DEMO_ACT_LOG). +# +# The check, in order: +# 1. the app opens against the demo edge and shows the demo's question +# 2. with the network off, the app opened again from its icon shows +# the same question from what the device kept +# 3. the question is answered while offline, the app is swiped away, +# and the network comes back +# 4. the demo edge saw that answer exactly once, and reopening the +# app no longer shows the question +# +# Needs: adb, python3, uiautomator on the emulator. Exits non-zero +# naming the step that failed, with the last screen's text on stderr. +# A step that only sets the scene (Chrome's first-run screen, say) +# never fails the check by itself: the wait for the app's own text is +# what decides. +set -euo pipefail + +APK="" +EDGE_URL="" +ACT_LOG="" +ANSWER_LABEL="Build new attachment storage" +QUESTION_TEXT="For S7 attachments and multimedia, build new storage, or reuse a mechanism outside pm-stack that you name?" +NEXT_QUESTION_TEXT="Which checks must pass before a batch merges?" +PKG="today.developing.pmconsole" +LAUNCHER="today.developing.pmconsole/com.google.androidbrowserhelper.trusted.LauncherActivity" + +usage() { + echo "usage: offline-check.sh --apk --edge-url --act-log [--answer-label ] [--question-text ] [--next-question-text ]" >&2 + exit 2 +} + +while [ $# -gt 0 ]; do + case "$1" in + --apk) APK="${2:-}"; shift 2 ;; + --edge-url) EDGE_URL="${2:-}"; shift 2 ;; + --act-log) ACT_LOG="${2:-}"; shift 2 ;; + --answer-label) ANSWER_LABEL="${2:-}"; shift 2 ;; + --question-text) QUESTION_TEXT="${2:-}"; shift 2 ;; + --next-question-text) NEXT_QUESTION_TEXT="${2:-}"; shift 2 ;; + *) echo "offline-check: unknown argument: $1" >&2; usage ;; + esac +done +[ -n "$APK" ] && [ -n "$EDGE_URL" ] && [ -n "$ACT_LOG" ] || usage +[ -f "$APK" ] || { echo "offline-check: no APK at $APK" >&2; exit 2; } + +# The screen as the emulator sees it, one text per line. +screen_text() { + adb exec-out uiautomator dump /dev/tty 2>/dev/null | python3 -c ' +import sys, xml.etree.ElementTree as ET +raw = sys.stdin.buffer.read() +start = raw.find(b"/dev/null | python3 -c ' +import sys, xml.etree.ElementTree as ET +needle = sys.argv[1] +raw = sys.stdin.buffer.read() +start = raw.find(b"&2 + screen_text >&2 || true + echo "--- end screen ---" >&2 +} + +fail() { + echo "offline-check: FAILED: $*" >&2 + dump_for_log + exit 1 +} + +wait_text() { + local needle="$1" timeout="${2:-60}" i=0 + while [ "$i" -lt "$timeout" ]; do + if screen_text | grep -qF "$needle"; then return 0; fi + sleep 2 + i=$((i + 2)) + done + return 1 +} + +wait_no_text() { + local needle="$1" timeout="${2:-30}" i=0 + while [ "$i" -lt "$timeout" ]; do + if ! screen_text | grep -qF "$needle"; then return 0; fi + sleep 2 + i=$((i + 2)) + done + return 1 +} + +tap_text() { + local needle="$1" xy + xy="$(tap_xy "$needle")" || return 1 + adb shell input tap "$xy" +} + +# One action arriving at the demo edge, counted from its log. +count_answer() { + python3 -c ' +import json, sys +kind, qid, option = sys.argv[1], sys.argv[2], sys.argv[3] +n = 0 +try: + with open(sys.argv[4]) as f: + for line in f: + try: + e = json.loads(line) + except ValueError: + continue + a = e.get("args") or {} + if e.get("kind") == kind and a.get("qid") == qid and a.get("option") == option: + n += 1 +except FileNotFoundError: + pass +print(n) +' "question.answer" "q7" "opt-1" "$ACT_LOG" +} + +airplane() { + local want="$1" # on or off + if [ "$want" = "on" ]; then + adb shell cmd connectivity airplane-mode enable >/dev/null + else + adb shell cmd connectivity airplane-mode disable >/dev/null + fi + local expect="0" + [ "$want" = "on" ] && expect="1" + local i=0 got="" + while [ "$i" -lt 30 ]; do + got="$(adb shell settings get global airplane_mode_on 2>/dev/null | tr -d '[:space:]')" + [ "$got" = "$expect" ] && return 0 + sleep 2 + i=$((i + 2)) + done + return 1 +} + +# Open the app the way the home screen does. +launch_from_icon() { + adb shell monkey -p "$PKG" -c android.intent.category.LAUNCHER 1 >/dev/null 2>&1 +} + +echo "offline-check: waiting for the emulator" +adb wait-for-device +i=0 +while [ "$i" -lt 120 ]; do + [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '[:space:]')" = "1" ] && break + sleep 5 + i=$((i + 5)) +done +[ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '[:space:]')" = "1" ] || fail "emulator did not finish booting" + +# Chrome's first-run screen would stand between the app and its page: +# tell it not to show, before it first starts. +adb shell 'echo "chrome --no-first-run --disable-fre" > /data/local/tmp/chrome-command-line' 2>/dev/null || true +adb shell am force-stop com.android.chrome 2>/dev/null || true + +echo "offline-check: installing the APK" +adb install -r -g "$APK" || fail "could not install $APK" +adb shell am force-stop "$PKG" 2>/dev/null || true + +echo "offline-check: 1. the app opens against the demo edge" +launch_from_icon +wait_text "Needs me" 120 || fail "the app did not open to the console (no 'Needs me' tab)" +tap_text "Needs me" || fail "could not open the Needs me tab" +wait_text "$QUESTION_TEXT" 60 || fail "the demo question is not shown" + +echo "offline-check: 2. with no connection, opened again it shows what it kept" +airplane on || fail "could not turn aeroplane mode on" +launch_from_icon +wait_text "$QUESTION_TEXT" 60 || fail "opened with no connection, the app does not show the question it last saw" + +echo "offline-check: 3. answered while offline, app swiped away, network back" +tap_text "$ANSWER_LABEL" || fail "could not tap the answer '$ANSWER_LABEL'" +wait_no_text "$QUESTION_TEXT" 30 || fail "the answered question is still listed" +# The answer is only written to the outbox when its 4.5-second undo +# window runs out (app.js: later), so the app stays open past that +# before it is swiped away: swiping sooner would lose the answer with +# the page, and the check would be testing the undo timer, not the +# sync. Eight seconds leaves room for the write and the sync to be +# registered. +sleep 8 +# Swiped away: the task leaves recents, so the page is gone and only +# Chrome's worker is left to send what was kept. +adb shell input keyevent KEYCODE_APP_SWITCH +sleep 2 +adb shell input swipe 540 1300 540 200 300 +sleep 2 +if adb shell dumpsys activity activities 2>/dev/null | grep -q "$PKG"; then + adb shell am force-stop "$PKG" 2>/dev/null || true + sleep 2 +fi +if adb shell pidof "$PKG" >/dev/null 2>&1; then + fail "the app is still running after being swiped away" +fi +airplane off || fail "could not turn aeroplane mode off" + +echo "offline-check: 4. the edge saw the answer exactly once" +i=0 +seen="0" +while [ "$i" -lt 60 ]; do + seen="$(count_answer)" + [ "$seen" = "1" ] && break + sleep 2 + i=$((i + 2)) +done +[ "$seen" = "1" ] || fail "the demo edge saw the answer $seen times, not once (log: $ACT_LOG)" +launch_from_icon +wait_text "Needs me" 60 || fail "the app did not reopen after the answer was sent" +tap_text "Needs me" || fail "could not open the Needs me tab again" +wait_text "$NEXT_QUESTION_TEXT" 60 || fail "the Needs me list did not load after the answer was sent" +if screen_text | grep -qF "$QUESTION_TEXT"; then + fail "the answered question is back in the list after being sent" +fi + +echo "offline-check: passed — the app opened offline, the answer made offline was sent once with the app swiped away, and the question is gone" +if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then + { + echo "The Android app opened with no connection, showed the question it last saw, and the answer made offline reached the demo edge exactly once after the app was swiped away and the network came back." + } >>"$GITHUB_STEP_SUMMARY" +fi diff --git a/pm-stack/console/scripts/demo-state.ts b/pm-stack/console/scripts/demo-state.ts index 027ee71e6c..441b5d041d 100644 --- a/pm-stack/console/scripts/demo-state.ts +++ b/pm-stack/console/scripts/demo-state.ts @@ -2,6 +2,7 @@ // server code answers, only the sources are canned, and every action // succeeds. demo.ts serves it directly; edge-demo.ts puts the edge in // front of it. +import { appendFileSync } from "node:fs"; import { actions as realActions } from "../src/actions.ts"; import { readConfig } from "../src/config.ts"; import { Devices, Limiter } from "../src/devices.ts"; @@ -630,7 +631,27 @@ const cfg = readConfig({ HOME: "/tmp", PM_CONSOLE_DASHBOARD_URL: "" }); const docs = new Docs( Object.fromEntries(Object.entries(state).map(([name, data]) => [name, { ttlMs: 3_600_000, load: async () => data }])), ); -const done = (result: unknown) => ({ run: async () => result, touch: [] as string[], audit: () => ({}) }); +// The offline check's witness: when PM_CONSOLE_DEMO_ACT_LOG names a +// file, every canned action the demo host runs is appended there as one +// JSON line (kind, args, time), so a driver outside the browser can +// count what arrived and when. Unset, the demo writes nothing. A log +// that cannot be written is reported on stderr and the action still +// runs: the check then fails at its own count, not inside the demo. +const done = (kind: string, result: unknown) => ({ + run: async (args: unknown) => { + const actLog = process.env.PM_CONSOLE_DEMO_ACT_LOG; + if (actLog) { + try { + appendFileSync(actLog, `${JSON.stringify({ at: new Date().toISOString(), kind, args })}\n`); + } catch (error) { + console.error(`demo act log ${actLog} not writable: ${error}`); + } + } + return result; + }, + touch: [] as string[], + audit: () => ({}), +}); // Linking a phone is the real thing, kept in a file under /tmp. const devices = new Devices(fileStore("/tmp/pm-console-demo-devices.json")); const phones = { devices, link: new Limiter(30, 60_000), refused: new Limiter(60, 60_000) }; @@ -645,6 +666,7 @@ const table = new Proxy({} as Record>, { typeof kind === "string" && (kind.startsWith("device.") || kind === "sso.google" || kind === "intake.send") ? real[kind] : done( + typeof kind === "string" ? kind : String(kind), kind === "ask.send" ? { issue: 12503, queued: true } : kind === "questions.accept" @@ -654,7 +676,7 @@ const table = new Proxy({} as Record>, { has: () => true, // The kinds a real machine has, for where what it can do is listed. ownKeys: () => Object.keys(real), - getOwnPropertyDescriptor: () => ({ configurable: true, enumerable: true, value: done({}) }), + getOwnPropertyDescriptor: () => ({ configurable: true, enumerable: true, value: done("?", {}) }), }); /** The made-up host: canned state, and actions that all succeed. */ diff --git a/pm-stack/console/test/demo-act-log.test.ts b/pm-stack/console/test/demo-act-log.test.ts new file mode 100644 index 0000000000..51bd47a0d7 --- /dev/null +++ b/pm-stack/console/test/demo-act-log.test.ts @@ -0,0 +1,48 @@ +// pm-console demo: the act log the offline check counts on. +// +// Oracle: the file the demo appends to, read back here. A canned action +// is one JSON line (kind, args, time); with the variable unset nothing +// is written, so the demo is unchanged for everyone else. +import { describe, expect, test } from "bun:test"; +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { demoDeps } from "../scripts/demo-state.ts"; + +describe("demo act log", () => { + test("records a canned action as one JSON line, and writes nothing when unset", async () => { + const dir = mkdtempSync(join(tmpdir(), "pm-console-demo-act-log-")); + try { + const log = join(dir, "acts.jsonl"); + process.env.PM_CONSOLE_DEMO_ACT_LOG = log; + await demoDeps.actions!["question.answer"].run({ + set: "2026-11-17", + ledger: "ledger-2026-11-17-7", + qid: "q7", + option: "opt-1", + }); + const lines = readFileSync(log, "utf8").trim().split("\n"); + expect(lines).toHaveLength(1); + const entry = JSON.parse(lines[0]) as { at: string; kind: string; args: unknown }; + expect(entry.kind).toBe("question.answer"); + expect(entry.args).toEqual({ + set: "2026-11-17", + ledger: "ledger-2026-11-17-7", + qid: "q7", + option: "opt-1", + }); + expect(typeof entry.at).toBe("string"); + delete process.env.PM_CONSOLE_DEMO_ACT_LOG; + await demoDeps.actions!["question.answer"].run({ + set: "2026-11-17", + ledger: "ledger-2026-11-17-7", + qid: "q7", + option: "opt-1", + }); + expect(readFileSync(log, "utf8").trim().split("\n")).toHaveLength(1); + } finally { + delete process.env.PM_CONSOLE_DEMO_ACT_LOG; + rmSync(dir, { recursive: true, force: true }); + } + }); +});