Files
elizaos--eliza/packages/app/scripts/android-renderer-stamp.test.mjs
wehub-resource-sync 426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:43:05 +08:00

213 lines
5.6 KiB
JavaScript

/**
* Unit tests for the Android APK renderer freshness guard. The fixtures are
* minimal zip files with the same `assets/public` manifest path Gradle packages
* into real APKs, so the verifier can fail stale installs without adb.
*/
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { verifyInstalledApkHash } from "./lib/android-device.mjs";
import {
ANDROID_APK_RENDERER_MANIFEST_PATH,
assertAndroidApkRendererFresh,
compareAndroidRendererBuildIds,
freshAndroidRendererManifestPath,
readAndroidApkRendererManifest,
} from "./lib/android-renderer-stamp.mjs";
const tempDirs = [];
function tempDir() {
const dir = mkdtempSync(path.join(os.tmpdir(), "android-renderer-stamp-"));
tempDirs.push(dir);
return dir;
}
function u16(value) {
const buffer = Buffer.alloc(2);
buffer.writeUInt16LE(value);
return buffer;
}
function u32(value) {
const buffer = Buffer.alloc(4);
buffer.writeUInt32LE(value);
return buffer;
}
function writeStoredZipEntry(zipPath, entryName, content) {
const name = Buffer.from(entryName);
const data = Buffer.from(content);
const local = Buffer.concat([
u32(0x04034b50),
u16(20),
u16(0),
u16(0),
u16(0),
u16(0),
u32(0),
u32(data.length),
u32(data.length),
u16(name.length),
u16(0),
name,
data,
]);
const centralOffset = local.length;
const central = Buffer.concat([
u32(0x02014b50),
u16(20),
u16(20),
u16(0),
u16(0),
u16(0),
u16(0),
u32(0),
u32(data.length),
u32(data.length),
u16(name.length),
u16(0),
u16(0),
u16(0),
u16(0),
u32(0),
u32(0),
name,
]);
const eocd = Buffer.concat([
u32(0x06054b50),
u16(0),
u16(0),
u16(1),
u16(1),
u32(central.length),
u32(centralOffset),
u16(0),
]);
writeFileSync(zipPath, Buffer.concat([local, central, eocd]));
}
function writeApk(repoRoot, buildId) {
const apkPath = path.join(repoRoot, "app-debug.apk");
writeStoredZipEntry(
apkPath,
ANDROID_APK_RENDERER_MANIFEST_PATH,
JSON.stringify({ buildId, builtAt: "2026-07-05T00:00:00.000Z" }),
);
return apkPath;
}
function writeFreshDist(repoRoot, buildId) {
const dist = path.join(repoRoot, "packages", "app", "dist");
mkdirSync(dist, { recursive: true });
writeFileSync(
path.join(dist, "eliza-renderer-build.json"),
JSON.stringify({ buildId, builtAt: "2026-07-05T00:01:00.000Z" }),
);
}
afterEach(() => {
delete process.env.ELIZA_ANDROID_RENDERER_DIST;
delete process.env.ELIZA_SMOKE_RENDERER_DIST;
for (const dir of tempDirs.splice(0)) {
rmSync(dir, { recursive: true, force: true });
}
});
describe("Android renderer stamp", () => {
it("reads the renderer manifest packaged in an APK", () => {
const repoRoot = tempDir();
const apkPath = writeApk(repoRoot, "packaged");
expect(readAndroidApkRendererManifest(apkPath)).toMatchObject({
buildId: "packaged",
});
});
it("accepts matching fresh and packaged build ids", () => {
expect(
compareAndroidRendererBuildIds({
fresh: { buildId: "same", builtAt: "now" },
packaged: { buildId: "same" },
}),
).toEqual({ buildId: "same", builtAt: "now" });
});
it("rejects stale packaged renderer manifests", () => {
expect(() =>
compareAndroidRendererBuildIds({
fresh: { buildId: "fresh" },
packaged: { buildId: "old" },
}),
).toThrow(/stale Android APK/);
});
it("rejects a fresh dist manifest from another commit", () => {
expect(() =>
compareAndroidRendererBuildIds({
fresh: { buildId: "same", commit: "111111111111" },
packaged: { buildId: "same" },
expectedCommit: "222222222222",
}),
).toThrow(/stale Android dist/);
});
it("compares a packaged APK against the freshly built dist manifest", () => {
const repoRoot = tempDir();
writeFreshDist(repoRoot, "same");
const apkPath = writeApk(repoRoot, "same");
expect(
assertAndroidApkRendererFresh({
apkPath,
repoRoot,
expectedCommit: null,
}),
).toEqual({
buildId: "same",
builtAt: "2026-07-05T00:01:00.000Z",
});
});
it("prefers the Android renderer dist override over the generic smoke override", () => {
const repoRoot = tempDir();
const smokeDist = path.join(repoRoot, "smoke-dist");
const androidDist = path.join(repoRoot, "android-dist");
process.env.ELIZA_SMOKE_RENDERER_DIST = smokeDist;
process.env.ELIZA_ANDROID_RENDERER_DIST = androidDist;
expect(freshAndroidRendererManifestPath({ repoRoot })).toBe(
path.join(androidDist, "eliza-renderer-build.json"),
);
});
it("fails when the APK is missing the renderer manifest", () => {
const repoRoot = tempDir();
const apkPath = path.join(repoRoot, "missing.apk");
writeStoredZipEntry(apkPath, "assets/public/index.html", "<html></html>");
expect(() => readAndroidApkRendererManifest(apkPath)).toThrow(
/missing assets\/public\/eliza-renderer-build\.json/,
);
});
it("accepts an installed APK hash that matches the local file", () => {
expect(
verifyInstalledApkHash({
localHash: "abc123",
deviceHash: "abc123",
}),
).toEqual({ sha256: "abc123" });
});
it("rejects an installed APK hash mismatch", () => {
expect(() =>
verifyInstalledApkHash({
localHash: "fresh",
deviceHash: "stale",
}),
).toThrow(/on-device APK does not match installed file/);
});
});