From 442186091bc42fe40e248535679affc1bc9e75ed Mon Sep 17 00:00:00 2001 From: Lav-developer <170819619+Lav-developer@users.noreply.github.com> Date: Sun, 13 Sep 2026 19:12:42 +0000 Subject: [PATCH] test(android): validate release version format, not a fixed 1.4.2/13 baseline The v1.4.3 release tag run failed on exactly two stale assertions in release-automation.test.mjs that pinned the previous production version (versionName 1.4.2 / versionCode 13) as a permanent baseline. The release workflow intentionally bumps versionName/versionCode for every production release (1.4.1/12, 1.4.2/13, 1.4.3/14, ...), so no test may treat any of them as permanent. Tests now validate FORMAT / STRUCTURE instead: - 'parses the real android/app/build.gradle': versionName exists and matches MAJOR.MINOR.PATCH; versionCode exists and is a positive integer. No exact-value assertions. - 'production baseline ... (1.4.2 / 13)' replaced with a future-proof check: build.gradle declares exactly one versionName and one versionCode, versionName is valid semver, versionCode is a positive integer within the Android signed 32-bit bound. CI organization (release gates unchanged / strengthened): - split the combined 'App logic + Worker API tests' checks job into separate 'worker-api' and 'android-app' jobs so a failing run always names the culprit; the release job needs both suites + release-apk, so both still gate releases. Android version bumps can no longer make a Worker API test failure look like a Worker problem (and vice versa). - the existing worker/test/app-update.test.cjs suite (previously not run in CI) is now part of the worker-api job. No changes to versionName/versionCode, the v1.4.3 tag, the release workflow's version/package/signing gates, the updater, Worker app-update logic, or any signing configuration. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com> --- .github/workflows/android-apk.yml | 53 +++++++++++++++----- android-app/README.md | 11 ++-- android-app/test/release-automation.test.mjs | 46 +++++++++++++---- 3 files changed, 84 insertions(+), 26 deletions(-) diff --git a/.github/workflows/android-apk.yml b/.github/workflows/android-apk.yml index 8003e71..0e0ea74 100644 --- a/.github/workflows/android-apk.yml +++ b/.github/workflows/android-apk.yml @@ -5,8 +5,9 @@ name: Android APK # Node, JDK 21 and the Android SDK; Gradle comes from the project wrapper. # # The APK is uploaded as a workflow artifact only (never committed, no -# releases are created). A `checks` job runs the Node test suites first so a -# broken app-logic change can't produce a green APK build unnoticed. +# releases are created). Two test jobs (`worker-api` and `android-app`) run +# the Node test suites first so a broken app-logic change can't produce a +# green APK build unnoticed — kept separate so failures name the culprit. # # When a semantic version tag vMAJOR.MINOR.PATCH is pushed, a release job # additionally validates the signed production APK and publishes a GitHub @@ -53,10 +54,18 @@ concurrency: cancel-in-progress: true jobs: - checks: - name: App logic + Worker API tests + # ──────────────────────────────────────────────────────────────────────── + # Test gates — deliberately kept as TWO separate jobs so a failing run + # always tells you exactly which suite broke: "Worker API tests" vs. + # "Android app logic + UI smoke tests". An Android version bump + # (versionName/versionCode in android/app/build.gradle) must never make + # the Worker API suite fail; the suites are isolated both here and in the + # test files (no fixed production-version baseline anywhere). + # ──────────────────────────────────────────────────────────────────────── + worker-api: + name: Worker API tests runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 10 steps: - name: Checkout repository @@ -67,18 +76,15 @@ jobs: with: node-version: '22' cache: npm - cache-dependency-path: | - android-app/package-lock.json - worker/package-lock.json + cache-dependency-path: worker/package-lock.json - # The Android app's unit tests + jsdom smoke test are dependency-free - # Node tests (jsdom is reused from the Worker devDependencies below). - name: Install Worker test dependencies run: npm ci --prefix worker --no-audit --no-fund - name: Run Worker API suite (unchanged backend contract) run: | node worker/test/worker.test.js + node worker/test/app-update.test.cjs node worker/test/frontend-smoke-test.cjs node worker/test/paper-smoke-test.cjs node worker/test/contribution-points-test.cjs @@ -86,6 +92,27 @@ jobs: node worker/test/duplicate-index-freshness-test.cjs node worker/test/admin-ia-test.cjs + android-app: + name: Android app logic + UI smoke tests + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout repository + uses: actions/checkout@v7 + + - name: Set up Node.js + uses: actions/setup-node@v7 + with: + node-version: '22' + cache: npm + cache-dependency-path: worker/package-lock.json + + # The Android app's unit tests + jsdom smoke test are dependency-free + # Node tests (jsdom is reused from the Worker devDependencies below). + - name: Install Worker test dependencies (jsdom reused by Android smoke tests) + run: npm ci --prefix worker --no-audit --no-fund + - name: Run Android app logic + UI smoke tests run: npm test --prefix android-app @@ -305,7 +332,8 @@ jobs: # Production GitHub Release. # # Activates ONLY when a semantic version tag vMAJOR.MINOR.PATCH is pushed - # AND the checks + release-apk jobs succeeded. Downloads the signed APK + # AND the worker-api, android-app and release-apk jobs succeeded. + # Downloads the signed APK # artifact, validates tag/version consistency, re-verifies the APK, and # creates (or safely updates) a GitHub Release with dsmnru-pyq.apk as the # direct asset. @@ -319,7 +347,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 needs: - - checks + - worker-api + - android-app - release-apk if: startsWith(github.ref, 'refs/tags/v') permissions: diff --git a/android-app/README.md b/android-app/README.md index 7b4349a..a92d550 100644 --- a/android-app/README.md +++ b/android-app/README.md @@ -226,10 +226,11 @@ cd android && ./gradlew assembleDebug ``` The GitHub Actions workflow (`.github/workflows/android-apk.yml`) runs on -pushes to `android-app` **and on pull requests targeting it**: the `checks` -job runs the Worker suite and the app's `npm test` (jsdom reused from the -Worker devDependencies) first, then the `debug-apk` job builds the debug APK -in the cloud and uploads it as a workflow artifact — nothing binary is +pushes to `android-app` **and on pull requests targeting it**: the +`worker-api` and `android-app` test jobs run the Worker suite and the app's +`npm test` (jsdom reused from the Worker devDependencies) first — kept as +separate jobs so a failure always names the culprit — then the `debug-apk` +job builds the debug APK in the cloud and uploads it as a workflow artifact — nothing binary is committed, and no releases are created automatically. A signed release APK/AAB can be added later via repository secrets (keystore + `google-services.json` are **never** committed; `build.gradle` @@ -248,7 +249,7 @@ with an existing package". The applicationId stays `com.dsmnru.pyq` across debug and release (one app identity, no second package). Release signing remains out-of-repo and unconfigured — no production keystore credentials exist in this repository. `versionCode` is bumped with every released -iteration (currently **5 / 1.3.1**). +iteration (currently **14 / 1.4.3**). ## Deferred by design diff --git a/android-app/test/release-automation.test.mjs b/android-app/test/release-automation.test.mjs index 4f8d1d1..c9c5be3 100644 --- a/android-app/test/release-automation.test.mjs +++ b/android-app/test/release-automation.test.mjs @@ -120,12 +120,15 @@ test('parses the real android/app/build.gradle', async () => { const text = await fs.readFile(gradlePath, 'utf8'); const parsed = parseGradleVersions(text); assert.ok(parsed, 'could not parse build.gradle'); + // versionName exists and is a strict MAJOR.MINOR.PATCH semantic version. + // The release flow bumps it for every production release, so only the + // FORMAT is asserted here — never a specific production version. + assert.equal(typeof parsed.versionName, 'string'); + assert.match(parsed.versionName, /^\d+\.\d+\.\d+$/, 'versionName must be MAJOR.MINOR.PATCH'); + // versionCode exists and is a positive integer. assert.equal(typeof parsed.versionCode, 'number'); + assert.ok(Number.isInteger(parsed.versionCode), 'versionCode must be an integer'); assert.ok(parsed.versionCode > 0, 'versionCode must be positive'); - assert.match(parsed.versionName, /^\d+\.\d+\.\d+$/, 'versionName must be semver-ish'); - // Baseline stated by the task. - assert.equal(parsed.versionName, '1.4.2', 'production baseline versionName'); - assert.equal(parsed.versionCode, 13, 'production baseline versionCode'); }); test('tag version must match Gradle versionName (release gate)', () => { @@ -236,9 +239,17 @@ test('workflow file declares tag trigger for v*.*.* and a release job', async () ); // Tag trigger. assert.match(wf, /tags:\s*\n\s*-\s*'v\*\.\*\.\*'/); - // Release job exists and depends on checks + release-apk. + // Release job exists and depends on BOTH test suites + release-apk, so a + // failing Worker API test or Android test blocks the release. assert.match(wf, /^\s{2}release:/m); - assert.match(wf, /needs:\s*\n\s*-\s*checks\s*\n\s*-\s*release-apk/); + assert.match(wf, /needs:\s*\n\s*-\s*worker-api\s*\n\s*-\s*android-app\s*\n\s*-\s*release-apk/); + // The two test suites live in SEPARATE jobs so a CI failure always names + // the culprit (Worker API vs. Android app) instead of one combined job. + // An Android version bump must never make the Worker API suite fail. + assert.match(wf, /^\s{2}worker-api:/m); + assert.match(wf, /^\s{2}android-app:/m); + assert.match(wf, /node worker\/test\/worker\.test\.js/); + assert.match(wf, /npm test --prefix android-app/); // Only runs on v* tags. assert.match(wf, /if:\s*startsWith\(github\.ref,\s*'refs\/tags\/v'\)/); // Has contents: write for release job. @@ -294,9 +305,26 @@ test('release job does NOT appear to use a PAT', async () => { assert.doesNotMatch(wf, /secrets\.(PAT|PERSONAL|RELEASE)_TOKEN/); }); -test('production baseline versions in build.gradle are unchanged (1.4.2 / 13)', async () => { +test('build.gradle declares exactly one release-ready versionName/versionCode (no fixed baseline)', async () => { const gradlePath = path.join(REPO_ROOT, 'android-app', 'android', 'app', 'build.gradle'); const text = await fs.readFile(gradlePath, 'utf8'); - assert.match(text, /versionCode\s+13\b/, 'versionCode baseline'); - assert.match(text, /versionName\s+"1\.4\.2"/, 'versionName baseline'); + // The release workflow bumps versionName/versionCode for EVERY production + // release (1.4.1/12 → 1.4.2/13 → 1.4.3/14 → …), so no test may pin a + // specific production version as a permanent baseline. Validate the + // SHAPE of the declarations instead: exactly one of each, and values + // suitable for an Android release. (Cross-checking these against the + // release tag and the built APK is the release job's job.) + const vnDecls = [...text.matchAll(/versionName\s+"([^"]*)"/g)]; + const vcDecls = [...text.matchAll(/versionCode\s+(\d+)/g)]; + assert.equal(vnDecls.length, 1, 'exactly one versionName declaration expected'); + assert.equal(vcDecls.length, 1, 'exactly one versionCode declaration expected'); + + const versionName = vnDecls[0][1]; + const versionCode = Number(vcDecls[0][1]); + // Valid semantic versionName (MAJOR.MINOR.PATCH, no prerelease). + assert.match(versionName, /^\d+\.\d+\.\d+$/, 'versionName must be valid MAJOR.MINOR.PATCH semver'); + // Positive integer versionCode, suitable for an Android release. + assert.ok(Number.isInteger(versionCode) && versionCode > 0, 'versionCode must be a positive integer'); + // Android versionCodes are signed 32-bit ints — stay within the bound. + assert.ok(versionCode <= 2147483647, 'versionCode must fit the Android signed 32-bit bound'); });