Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
91 changes: 91 additions & 0 deletions .github/workflows/mobile-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Android package

on:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: android-package-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
name: Signed Android APK
runs-on: ubuntu-24.04
environment: android-signing
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup pnpm
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10

- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .node-version

- name: Setup Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: '21'

- name: Install workspace dependencies
uses: ./.github/actions/install-workspace-dependencies
with:
packages: '@uselexora/lexora @uselexora/lexora-buddy...'

- name: Prepare Android SDK
run: sdkmanager 'platforms;android-36' 'build-tools;36.0.0'

- name: Verify Android client
working-directory: apps/mobile
run: ./gradlew --no-daemon :android:testDebugUnitTest :android:lintRelease

- name: Build signed APK
working-directory: apps/mobile
env:
LEXORA_ANDROID_KEYSTORE_BASE64: ${{ secrets.LEXORA_ANDROID_KEYSTORE_BASE64 }}
LEXORA_ANDROID_STORE_PASSWORD: ${{ secrets.LEXORA_ANDROID_STORE_PASSWORD }}
LEXORA_ANDROID_KEY_ALIAS: ${{ secrets.LEXORA_ANDROID_KEY_ALIAS }}
LEXORA_ANDROID_KEY_PASSWORD: ${{ secrets.LEXORA_ANDROID_KEY_PASSWORD }}
shell: bash
run: |
set -euo pipefail
: "${LEXORA_ANDROID_KEYSTORE_BASE64:?Missing signing keystore}"
: "${LEXORA_ANDROID_STORE_PASSWORD:?Missing keystore password}"
: "${LEXORA_ANDROID_KEY_ALIAS:?Missing signing alias}"
: "${LEXORA_ANDROID_KEY_PASSWORD:?Missing key password}"
umask 077
export LEXORA_ANDROID_KEYSTORE="$RUNNER_TEMP/lexora-android-release.p12"
trap 'rm -f "$LEXORA_ANDROID_KEYSTORE"' EXIT
printf '%s' "$LEXORA_ANDROID_KEYSTORE_BASE64" | base64 --decode > "$LEXORA_ANDROID_KEYSTORE"
unset LEXORA_ANDROID_KEYSTORE_BASE64
./gradlew --no-daemon :android:assembleRelease
"$ANDROID_HOME/build-tools/36.0.0/apksigner" verify --verbose --print-certs android/build/outputs/apk/release/android-release.apk | tee android/build/outputs/apk/release/signature.txt
expected="$(cat android/release-certificate.sha256)"
grep -Fx "Signer #1 certificate SHA-256 digest: $expected" android/build/outputs/apk/release/signature.txt
cd android/build/outputs/apk/release
sha256sum android-release.apk > android-release.apk.sha256

- name: Remove signing material
if: always()
run: rm -f "$RUNNER_TEMP/lexora-android-release.p12"

- name: Upload signed package
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: lexora-android-apk
path: |
apps/mobile/android/build/outputs/apk/release/android-release.apk
apps/mobile/android/build/outputs/apk/release/android-release.apk.sha256
apps/mobile/android/build/outputs/apk/release/output-metadata.json
apps/mobile/android/build/outputs/apk/release/signature.txt
if-no-files-found: error
retention-days: 14
9 changes: 9 additions & 0 deletions .playwright/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ pnpm test:e2e
`pnpm test` 执行无 GUI 的 Vitest 测试。`pnpm test:e2e` 构建当前 Electron 应用并执行 Playwright Test;可追加测试文件名或 `--grep` 筛选场景。Linux 需要 `Xvfb`,Electron 必须能启用 Chromium sandbox。

Electron 测试位于 `__tests__/*.e2e.mjs`,复用 `fixtures/electron.mjs` 的 `test`、`expect`;辅助逻辑测试使用 `__tests__/*.spec.mjs`。

Android 已安装调试 APK 和测试 APK、并通过 `adb` 连接后,可运行双端审批、草稿、附件、历史、进程恢复与任务控制联测:

```sh
LEXORA_TEST_ANDROID_SERIAL=emulator-5554 pnpm test:e2e mobile-desktop.e2e.mjs mobile-approvals.e2e.mjs mobile-task-controls.e2e.mjs mobile-history.e2e.mjs mobile-recovery.e2e.mjs mobile-content.e2e.mjs mobile-interruption.e2e.mjs
# 普通 Node Core 与 Electron Host 联测需先构建配套服务
pnpm --filter @uselexora/lexora-buddy build:desktop
LEXORA_TEST_MOBILE_SERVICE_MODE=daemon LEXORA_TEST_ANDROID_SERIAL=emulator-5554 pnpm exec playwright test --config .playwright/scripts/playwright.config.mjs mobile-desktop.e2e.mjs mobile-approvals.e2e.mjs mobile-task-controls.e2e.mjs mobile-history.e2e.mjs mobile-recovery.e2e.mjs mobile-content.e2e.mjs mobile-interruption.e2e.mjs
```
62 changes: 62 additions & 0 deletions .playwright/scripts/__tests__/attachment-publication.e2e.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { execFile } from 'node:child_process'
import fs from 'node:fs/promises'
import { createRequire, isBuiltin } from 'node:module'
import os from 'node:os'
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { promisify } from 'node:util'
import { expect, test } from '@playwright/test'

const execute = promisify(execFile)
const root = fileURLToPath(new URL('../../../', import.meta.url))
const requireBuddy = createRequire(path.join(root, 'apps/buddy/package.json'))
const checkpoints = ['prepared', 'file-synced', 'renamed', 'directory-synced', 'published', 'bound']

test('interrupted file publication recovers only durable attachment ownership', async () => {
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'lexora-attachment-publication-'))
const report = []
try {
const { build } = await import(pathToFileURL(requireBuddy.resolve('vite')).href)
await build({ configFile: false, logLevel: 'error', build: {
ssr: path.join(root, '.playwright/scripts/fixtures/attachment-publication-crash.ts'),
outDir: path.join(directory, 'harness'),
target: 'node26',
rolldownOptions: { external: isBuiltin, output: { entryFileNames: 'publication.mjs', format: 'es' } },
} })
const entry = path.join(directory, 'harness/publication.mjs')
for (const checkpoint of checkpoints) {
const profile = path.join(directory, checkpoint)
const unknown = path.join(profile, 'profile/drafts/unknown/keep.txt')
await fs.mkdir(path.dirname(unknown), { recursive: true })
await fs.writeFile(unknown, 'unknown files are preserved')
let interrupted
try {
await execute(process.execPath, [entry, 'publish', profile, checkpoint], { timeout: 30000 })
}
catch (error) { interrupted = error }
expect(interrupted, checkpoint).toBeTruthy()
expect(JSON.parse(interrupted.stdout.trim())).toEqual({ checkpoint })
const result = await execute(process.execPath, [entry, 'recover', profile], { timeout: 30000 })
const recovery = JSON.parse(result.stdout.trim())
const bound = checkpoint === 'bound'
expect(recovery.files).toHaveLength(1)
expect(recovery.files[0].state).toBe(bound ? 'ready' : 'deleted')
expect(recovery.references).toEqual(bound ? [{ kind: 'draft', owner_id: 'crash-draft' }] : [])
expect(recovery.bytes).toEqual(bound ? ['durable attachment bytes'] : [])
expect(recovery.preparations).toEqual([{ state: bound ? 'settled' : 'aborted', reserved_bytes: 0 }])
expect(await fs.readFile(unknown, 'utf8')).toBe('unknown files are preserved')
const repeat = JSON.parse((await execute(process.execPath, [entry, 'recover', profile], { timeout: 30000 })).stdout.trim())
expect(repeat.files).toEqual(recovery.files)
expect(repeat.references).toEqual(recovery.references)
expect(repeat.recovered.removedOrphanFiles).toBe(0)
report.push({ checkpoint, ...recovery })
}
}
finally {
const reportPath = test.info().outputPath('attachment-publication.json')
await fs.writeFile(reportPath, JSON.stringify(report, null, 2))
await test.info().attach('attachment-publication.json', { path: reportPath, contentType: 'application/json' })
await fs.rm(directory, { recursive: true, force: true })
}
})
88 changes: 88 additions & 0 deletions .playwright/scripts/__tests__/browser-platform-lifetime.e2e.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Buffer } from 'node:buffer'
import { createServer } from 'node:http'
import { expect, test } from '../fixtures/electron.mjs'

test('platform browser survives workbench destruction, rejects stale presentation and reattaches the same interactive page', async ({ buddy }, testInfo) => {
const server = createServer((_request, response) => {
response.setHeader('Content-Type', 'text/html; charset=utf-8')
response.end('<!doctype html><title>Background browser fixture</title><style>body{margin:0;background:rgb(210,30,40);font:20px sans-serif}input{margin:20px;height:40px}button{height:40px}</style><input id="text" value="preserved"><button onclick="window.clicks=(window.clicks||0)+1">Count</button><div id="ticks"></div><script>window.ticks=0;setInterval(()=>document.querySelector("#ticks").textContent=String(++window.ticks),20)</script>')
})
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))
try {
const url = `http://127.0.0.1:${server.address().port}/`
const instance = await buddy.createInstance('browser-background')
const { app, page } = await instance.launch()
const state = await page.evaluate(async (url) => {
const state = await window.lexoraDesktop.browser.ensureSession(null, 'lifetime-test')
return window.lexoraDesktop.browser.navigate(state.sessionId, url)
}, url)
const pageId = await app.evaluate(({ webContents }, url) => webContents.getAllWebContents().find(contents => contents.getURL() === url)?.id, url)
expect(typeof pageId).toBe('number')
const bounds = { x: 40, y: 100, width: 620, height: 300 }
const oldToken = await page.evaluate(() => window.lexoraDesktop.browser.acquirePresentation())
const presentation = { presentationId: oldToken, sessionId: state.sessionId, pageId: state.pageId, visible: true, bounds, clip: bounds }
await page.evaluate(input => window.lexoraDesktop.browser.present(input), presentation)
const initial = await app.evaluate(async ({ webContents }, id) => {
const contents = webContents.fromId(id)
contents.focus()
await contents.executeJavaScript('document.querySelector("#text").focus()')
contents.insertText(' retained')
return { text: await contents.executeJavaScript('document.querySelector("#text").value'), ticks: await contents.executeJavaScript('window.ticks'), zoom: contents.getZoomFactor(), size: (await contents.capturePage()).getSize() }
}, pageId)
expect(initial.text).toContain('retained')
expect(initial.size.width).toBeGreaterThan(0)
await page.evaluate(async sessionId => window.lexoraDesktop.browser.setZoomFactor(sessionId, 1.25), state.sessionId)
await page.evaluate(input => window.lexoraDesktop.browser.present(input), { ...presentation, visible: false })
await app.evaluate(({ BrowserWindow }) => {
const window = BrowserWindow.getAllWindows().find(window => window.webContents.getURL().startsWith('lexora-app:'))
if (!window)
throw new Error('Workbench is missing')
setImmediate(() => window.destroy())
})
await expect.poll(() => app.evaluate(async ({ webContents }, id) => (await webContents.fromId(id)?.debugger.sendCommand('Runtime.evaluate', { expression: 'window.ticks', returnByValue: true }))?.result?.value, pageId)).toBeGreaterThan(initial.ticks + 2)
const offline = await app.evaluate(async ({ webContents }, id) => {
const contents = webContents.fromId(id)
await contents.debugger.sendCommand('Runtime.evaluate', { expression: 'document.querySelector("button").click()' })
const snapshot = await contents.capturePage(undefined, { stayHidden: true })
return { clicks: await contents.executeJavaScript('window.clicks'), text: await contents.executeJavaScript('document.querySelector("#text").value'), screenshotBytes: snapshot.toPNG().length }
}, pageId)
expect(offline).toMatchObject({ clicks: 1, text: initial.text })
expect(offline.screenshotBytes).toBeGreaterThan(100)
const newWindow = app.waitForEvent('window')
await app.evaluate(({ app }) => app.emit('activate'))
const reopened = await newWindow
await expect(reopened.locator('.desktop-workbench-area__tasks .tiptap:visible').first()).toBeVisible()
const stale = await reopened.evaluate(async (input) => {
try {
await window.lexoraDesktop.browser.present(input)
return false
}
catch { return true }
}, presentation)
expect(stale).toBe(true)
const guests = await reopened.evaluate(() => window.lexoraDesktop.browser.listGuests())
expect(guests).toContainEqual(expect.objectContaining({ sessionId: state.sessionId, pageId: state.pageId }))
const nextToken = await reopened.evaluate(() => window.lexoraDesktop.browser.acquirePresentation())
await reopened.evaluate(input => window.lexoraDesktop.browser.present(input), { ...presentation, presentationId: nextToken })
const resumed = await app.evaluate(async ({ webContents }, id) => {
const contents = webContents.fromId(id)
const button = await contents.executeJavaScript('(()=>{const r=document.querySelector("button").getBoundingClientRect();return {x:r.x+r.width/2,y:r.y+r.height/2}})()')
const point = { x: Math.round(button.x * contents.getZoomFactor()), y: Math.round(button.y * contents.getZoomFactor()) }
contents.sendInputEvent({ type: 'mouseDown', button: 'left', clickCount: 1, ...point })
contents.sendInputEvent({ type: 'mouseUp', button: 'left', clickCount: 1, ...point })
return { id: contents.id, zoom: contents.getZoomFactor(), text: await contents.executeJavaScript('document.querySelector("#text").value') }
}, pageId)
expect(resumed).toEqual({ id: pageId, zoom: 1.25, text: initial.text })
await expect.poll(() => app.evaluate(({ webContents }, id) => webContents.fromId(id).executeJavaScript('window.clicks'), pageId)).toBe(2)
await expect.poll(() => app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows().filter(window => window.webContents.getURL().startsWith('lexora-app:')).length)).toBe(1)
const image = await app.evaluate(async ({ desktopCapturer }) => {
const [screen] = await desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 1500, height: 950 } })
return screen.thumbnail.toPNG().toString('base64')
})
await testInfo.attach('reattached-browser', { body: Buffer.from(image, 'base64'), contentType: 'image/png' })
}
finally {
server.closeAllConnections()
await new Promise(resolve => server.close(resolve))
}
})
Loading
Loading