Repository navigation
feat: align Android SDK with core update document API #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+6,980
−4,825
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Bump this when upgrading the FFI, then run `node scripts/install.mjs`. | ||
| # (`ffi/<version>` for releases, `prerelease/<sha>` for prereleases). | ||
| # See releases from https://github.com/webview-bundle/webview-bundles. | ||
| prerelease/76b4cbf | ||
| # See releases from https://github.com/webview-bundle/webview-bundle. | ||
| prerelease/f62e1f4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { createHash } from "node:crypto"; | ||
| import { readFile } from "node:fs/promises"; | ||
| import { createServer } from "node:http"; | ||
| import type { AddressInfo } from "node:net"; | ||
|
|
||
| export async function startFixtureRemote(host: string) { | ||
| const bundles = new Map( | ||
| await Promise.all( | ||
| ["0.4.1", "0.4.2"].map( | ||
| async (version) => | ||
| [ | ||
| version, | ||
| await readFile( | ||
| new URL(`./fixtures/${version}.wvb`, import.meta.url), | ||
| ), | ||
| ] as const, | ||
| ), | ||
| ), | ||
| ); | ||
| let version = "0.4.1"; | ||
| const server = createServer((request, response) => { | ||
| const path = new URL(request.url ?? "/", "http://localhost").pathname; | ||
| if (path === "/update") { | ||
| const etag = `"testbed-${version}"`; | ||
| if (request.headers["if-none-match"] === etag) { | ||
| response.writeHead(304).end(); | ||
| return; | ||
| } | ||
| const bytes = bundles.get(version)!; | ||
| response.writeHead(200, { "content-type": "application/json", etag }); | ||
| response.end( | ||
| JSON.stringify({ | ||
| id: `testbed-${version}`, | ||
| createdAt: "2026-10-09T00:00:00Z", | ||
| runtimeVersion: 1, | ||
| bundles: [ | ||
| { | ||
| name: "testbed", | ||
| version, | ||
| integrity: `sha256:${createHash("sha256").update(bytes).digest("base64")}`, | ||
| }, | ||
| ], | ||
| metadata: { channel: "stable" }, | ||
| }), | ||
| ); | ||
| return; | ||
| } | ||
| const match = /^\/bundles\/testbed\/([^/]+)$/.exec(path); | ||
| const bytes = match ? bundles.get(match[1]!) : undefined; | ||
| if (!bytes) { | ||
| response.writeHead(404).end(); | ||
| return; | ||
| } | ||
| response.writeHead(200, { | ||
| "content-type": "application/octet-stream", | ||
| "content-length": bytes.length, | ||
| }); | ||
| response.end(bytes); | ||
| }); | ||
| await new Promise<void>((resolve, reject) => { | ||
| server.once("error", reject); | ||
| server.listen(0, "0.0.0.0", resolve); | ||
| }); | ||
| return { | ||
| endpoint: `http://${host}:${(server.address() as AddressInfo).port}`, | ||
| setVersion(next: string) { | ||
| if (!bundles.has(next)) | ||
| throw new Error(`Unknown fixture version: ${next}`); | ||
| version = next; | ||
| }, | ||
| close: () => | ||
| new Promise<void>((resolve, reject) => | ||
| server.close((error) => (error ? reject(error) : resolve())), | ||
| ), | ||
| }; | ||
| } | ||
| export type FixtureRemote = Awaited<ReturnType<typeof startFixtureRemote>>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,134 +1,24 @@ | ||
| import { createAppiumDriver } from "@wvb-playground/testdriver/appium"; | ||
| import { | ||
| methodSel, | ||
| sel, | ||
| testCases, | ||
| defineTestbedSuite, | ||
| defineTestbedUpdateSuite, | ||
| type WebviewDriver, | ||
| } from "@wvb-playground/webview-testbed/testing"; | ||
| import { beforeAll, describe, expect, test } from "vitest"; | ||
| import { type Driver, getTestContext } from "./context.js"; | ||
| import { beforeAll, describe } from "vitest"; | ||
| import { getTestContext } from "./context.js"; | ||
|
|
||
| // Drives the `@wvb-playground/webview-testbed` bundle inside the Android WebView. The | ||
| // testapp ships the builtin `testbed` bundle and points its updater at the live | ||
| // playground remote (https://playground-remote.wvb.dev). | ||
| describe("testbed (android)", () => { | ||
| const BASE_URL = "https://testbed.wvb"; | ||
| const BUNDLE = "testbed"; | ||
| const BUILTIN_VERSION = "0.2.0"; | ||
| const REMOTE_VERSION = "0.3.0"; | ||
|
|
||
| // Loading the app shell (a full navigation) and the network download need more | ||
| // headroom than the driver's default. | ||
| const NAV_TIMEOUT = 30_000; | ||
| const RESULT_TIMEOUT = 90_000; | ||
|
|
||
| let browser: Driver; | ||
| describe("testbed UI (android)", () => { | ||
| let driver: WebviewDriver; | ||
|
|
||
| beforeAll(() => { | ||
| browser = getTestContext().driver; | ||
| driver = createAppiumDriver(browser, { | ||
| baseURL: BASE_URL, | ||
| defaultTimeoutMs: NAV_TIMEOUT, | ||
| driver = createAppiumDriver(getTestContext().driver, { | ||
| baseURL: "https://testbed.wvb", | ||
| defaultTimeoutMs: 30_000, | ||
| }); | ||
| }); | ||
|
|
||
| async function open(): Promise<void> { | ||
| await driver.goto("/"); | ||
| await driver.waitForVisible(sel.appShell, { timeoutMs: NAV_TIMEOUT }); | ||
| } | ||
|
|
||
| /** | ||
| * Runs one testbed method card on a freshly-loaded page and returns its terminal | ||
| * outcome. Reloading first guarantees the card starts idle (its result element is | ||
| * only rendered once a call settles), so waiting for the result can never observe a | ||
| * stale value left by an earlier run of the same method. | ||
| */ | ||
| async function runMethod( | ||
| id: string, | ||
| params: Record<string, string> = {}, | ||
| ): Promise<{ status: string | null; text: string }> { | ||
| await open(); | ||
| for (const [name, value] of Object.entries(params)) { | ||
| await driver.fill(methodSel.param(id, name), value); | ||
| } | ||
| await driver.click(methodSel.run(id)); | ||
| await driver.waitForVisible(methodSel.result(id), { timeoutMs: RESULT_TIMEOUT }); | ||
| const outcome = { | ||
| status: await driver.getAttribute(methodSel.result(id), "data-status"), | ||
| text: await driver.text(methodSel.result(id)), | ||
| }; | ||
| console.log(`[testbed] ${id} -> ${outcome.status}: ${outcome.text}`); | ||
| return outcome; | ||
| } | ||
|
|
||
| function parseJson(text: string): Record<string, unknown> { | ||
| try { | ||
| return JSON.parse(text) as Record<string, unknown>; | ||
| } catch { | ||
| throw new Error(`expected a JSON result, got: ${text}`); | ||
| } | ||
| } | ||
|
|
||
| // The only test that *asserts* the real remote download succeeds. Skipped on CI: | ||
| // this fill + reload + download sequence hangs on the GitHub Actions Android emulator | ||
| // (the network is reachable — the generic suite below downloads over it — but this | ||
| // specific flow stalls there). It passes locally, and the generic suite still | ||
| // exercises the download (as ok|error) on CI. | ||
| test.skipIf(!!process.env.CI)( | ||
| "downloads + installs the real remote update (builtin 0.2.0 -> remote 0.3.0)", | ||
| async () => { | ||
| await open(); | ||
| expect(await driver.text(sel.platformType)).toBe("android"); | ||
|
|
||
| const before = parseJson( | ||
| (await runMethod("source.loadVersion", { bundleName: BUNDLE })).text, | ||
| ); | ||
| expect(before).toEqual({ type: "builtin", version: BUILTIN_VERSION }); | ||
|
|
||
| const update = await runMethod("updater.getUpdate", { bundleName: BUNDLE }); | ||
| expect(update.status).toBe("ok"); | ||
| const info = parseJson(update.text); | ||
| expect(info.name).toBe(BUNDLE); | ||
| expect(info.version).toBe(REMOTE_VERSION); | ||
| expect(info.isAvailable).toBe(true); | ||
| expect(info.localVersion).toBe(BUILTIN_VERSION); | ||
|
|
||
| const download = await runMethod("updater.download", { bundleName: BUNDLE }); | ||
| expect(download.status).toBe("ok"); | ||
| expect(parseJson(download.text).version).toBe(REMOTE_VERSION); | ||
|
|
||
| const install = await runMethod("updater.install", { | ||
| bundleName: BUNDLE, | ||
| version: REMOTE_VERSION, | ||
| }); | ||
| expect(install.status).toBe("ok"); | ||
|
|
||
| const after = parseJson( | ||
| (await runMethod("source.loadVersion", { bundleName: BUNDLE })).text, | ||
| ); | ||
| expect(after).toEqual({ type: "remote", version: REMOTE_VERSION }); | ||
|
|
||
| // Drop the cached descriptor so the next request loads the freshly-installed | ||
| // version, and cache-bust so the WebView can't serve stale HTML. | ||
| await runMethod("source.unloadDescriptor", { bundleName: BUNDLE }); | ||
| await driver.goto(`/?updated=${Date.now()}`); | ||
| await driver.waitForVisible(sel.appShell, { timeoutMs: NAV_TIMEOUT }); | ||
| expect(await driver.text(".app__version")).toContain(REMOTE_VERSION); | ||
| }, | ||
| 240_000, | ||
| defineTestbedUpdateSuite( | ||
| () => driver, | ||
| () => getTestContext().fixtureRemote, | ||
| ); | ||
|
|
||
| // The platform-agnostic suite the testbed package ships (each `@wvb/bridge` method | ||
| // asserted to render an ok|error outcome). The "raw invoke" case is the only one that | ||
| // fills a text input, which hangs on the CI Android emulator; skip it there (its | ||
| // coverage overlaps source.listBundles). Runs after the strict update test so it | ||
| // can't perturb that test's clean starting state. | ||
| for (const testCase of testCases) { | ||
| const register = | ||
| process.env.CI && testCase.name.startsWith("raw invoke") ? test.skip : test; | ||
| register(testCase.name, async () => { | ||
| await testCase.run(driver); | ||
| }); | ||
| } | ||
| defineTestbedSuite(() => driver); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Clean up the fixture remote when context creation fails.
If
remote()rejects orswitchToWebview()times out,createTestContextnever returns a context. The fixture HTTP server remains open. The Appium server and any emulator started by this call also remain running. Clean up resources acquired during creation before rethrowing the error.🤖 Prompt for AI Agents