[tauri] TauriPlatforms: The shell around the built game, the Android privacy patch, the shell build of the game, and the device check
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Android 11 and earlier: no part of the garden is backed up (tauri-platforms.md D6).
|
||||
Copied into gen/android by scripts/android.ts. -->
|
||||
<full-backup-content>
|
||||
<exclude domain="root" path="." />
|
||||
<exclude domain="file" path="." />
|
||||
<exclude domain="database" path="." />
|
||||
<exclude domain="sharedpref" path="." />
|
||||
<exclude domain="external" path="." />
|
||||
<exclude domain="device_root" path="." />
|
||||
<exclude domain="device_file" path="." />
|
||||
<exclude domain="device_database" path="." />
|
||||
<exclude domain="device_sharedpref" path="." />
|
||||
</full-backup-content>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Android 12 and later. Nothing of the garden goes into a cloud backup or a device-to-device
|
||||
transfer: the care log, the keys and the chosen town stay on this device (CLAUDE.md §4,
|
||||
tauri-platforms.md D6). A rose moves only by the player's own hand, with Keep her safe.
|
||||
allowBackup="false" alone does not stop every device-transfer tool on Android 12+, so every
|
||||
domain is excluded here as well. Copied into gen/android by scripts/android.ts. -->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<exclude domain="root" path="." />
|
||||
<exclude domain="file" path="." />
|
||||
<exclude domain="database" path="." />
|
||||
<exclude domain="sharedpref" path="." />
|
||||
<exclude domain="external" path="." />
|
||||
<exclude domain="device_root" path="." />
|
||||
<exclude domain="device_file" path="." />
|
||||
<exclude domain="device_database" path="." />
|
||||
<exclude domain="device_sharedpref" path="." />
|
||||
</cloud-backup>
|
||||
<device-transfer>
|
||||
<exclude domain="root" path="." />
|
||||
<exclude domain="file" path="." />
|
||||
<exclude domain="database" path="." />
|
||||
<exclude domain="sharedpref" path="." />
|
||||
<exclude domain="external" path="." />
|
||||
<exclude domain="device_root" path="." />
|
||||
<exclude domain="device_file" path="." />
|
||||
<exclude domain="device_database" path="." />
|
||||
<exclude domain="device_sharedpref" path="." />
|
||||
</device-transfer>
|
||||
</data-extraction-rules>
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@rosea/tauri",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "The Tauri 2 shell: the Android, iOS and desktop apps around apps/rosea's built game (dist-tauri/). Imports no package.",
|
||||
"scripts": {
|
||||
"dev": "tsx scripts/icons.ts && tauri dev",
|
||||
"build:desktop": "tsx scripts/icons.ts && tauri build",
|
||||
"build:android": "tsx scripts/android.ts prepare && tauri android build --debug --apk --target aarch64 && tsx scripts/android.ts verify",
|
||||
"build:ios": "tsx scripts/ios.ts",
|
||||
"android:privacy": "tsx scripts/android.ts apply",
|
||||
"android:verify": "tsx scripts/android.ts verify",
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"test": "vitest run --reporter=verbose"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "2.12.5",
|
||||
"@types/node": "22.20.1",
|
||||
"tsx": "4.23.12",
|
||||
"typescript": "5.9.3",
|
||||
"vitest": "3.2.7"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* The Android app's privacy on the generated project, and the proof on the built APK
|
||||
* (src/android-privacy.ts; tauri-platforms.md D6).
|
||||
*
|
||||
* tsx scripts/android.ts prepare `tauri android init` if needed, icons, then apply
|
||||
* tsx scripts/android.ts apply patch the manifest, copy the rule files, then check
|
||||
* tsx scripts/android.ts check what the generated project lacks; exit 1 if anything
|
||||
* tsx scripts/android.ts verify [apk] the same, read from the BUILT APK with aapt2
|
||||
*
|
||||
* `apply` runs from tauri.android.conf.json's beforeBuildCommand, so `tauri android build`
|
||||
* cannot make an APK without it. A Gradle build started outside the Tauri CLI skips that hook;
|
||||
* `verify` reads the artefact itself, and `pnpm tauri:android` runs it last.
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { apkProblems, manifestProblems, patchManifest, RULE_FILES, RULE_SECTIONS, ruleProblems } from '../src/android-privacy.js';
|
||||
import { PACKAGE, SRC_TAURI, tauri } from './tauri.js';
|
||||
|
||||
const MAIN = join(SRC_TAURI, 'gen', 'android', 'app', 'src', 'main');
|
||||
const MANIFEST = join(MAIN, 'AndroidManifest.xml');
|
||||
const RES_FROM = join(PACKAGE, 'android', 'res', 'xml');
|
||||
const RES_TO = join(MAIN, 'res', 'xml');
|
||||
const OUTPUTS = join(SRC_TAURI, 'gen', 'android', 'app', 'build', 'outputs', 'apk');
|
||||
|
||||
function fail(problems: readonly string[]): never {
|
||||
for (const p of problems) console.error(`android: ${p}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function problems(): string[] {
|
||||
if (!existsSync(MANIFEST)) return [`no generated project (${MANIFEST}); run 'pnpm tauri:android'`];
|
||||
const found = manifestProblems(readFileSync(MANIFEST, 'utf8'));
|
||||
for (const f of RULE_FILES) {
|
||||
const at = join(RES_TO, f);
|
||||
if (!existsSync(at)) found.push(`res/xml/${f} is missing`);
|
||||
else if (readFileSync(at, 'utf8') !== readFileSync(join(RES_FROM, f), 'utf8')) found.push(`res/xml/${f} differs from android/res/xml/${f}`);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
function apply(): void {
|
||||
for (const f of RULE_FILES) {
|
||||
const left = ruleProblems(readFileSync(join(RES_FROM, f), 'utf8'), RULE_SECTIONS[f]);
|
||||
if (left.length > 0) fail(left.map((p) => `android/res/xml/${f}: ${p}`));
|
||||
}
|
||||
if (!existsSync(MANIFEST)) fail([`no generated project (${MANIFEST}); run 'pnpm tauri:android'`]);
|
||||
const before = readFileSync(MANIFEST, 'utf8');
|
||||
const after = patchManifest(before);
|
||||
mkdirSync(RES_TO, { recursive: true });
|
||||
for (const f of RULE_FILES) copyFileSync(join(RES_FROM, f), join(RES_TO, f));
|
||||
if (after !== before) writeFileSync(MANIFEST, after);
|
||||
const left = problems();
|
||||
if (left.length > 0) fail(left);
|
||||
console.log(
|
||||
`android: privacy ${after === before ? 'already in place' : 'applied'} ` +
|
||||
'(no INTERNET, no backup or transfer, WebView metrics and Safe Browsing off)'
|
||||
);
|
||||
}
|
||||
|
||||
function newestApk(dir: string): string | undefined {
|
||||
if (!existsSync(dir)) return undefined;
|
||||
let best: { path: string; at: number } | undefined;
|
||||
const walk = (d: string): void => {
|
||||
for (const name of readdirSync(d)) {
|
||||
const path = join(d, name);
|
||||
const stat = statSync(path);
|
||||
if (stat.isDirectory()) walk(path);
|
||||
else if (name.endsWith('.apk') && (!best || stat.mtimeMs > best.at)) best = { path, at: stat.mtimeMs };
|
||||
}
|
||||
};
|
||||
walk(dir);
|
||||
return best?.path;
|
||||
}
|
||||
|
||||
function aapt2(): string {
|
||||
const sdk = process.env['ANDROID_HOME'] ?? process.env['ANDROID_SDK_ROOT'];
|
||||
if (!sdk) fail(['ANDROID_HOME is not set']);
|
||||
const tools = join(sdk, 'build-tools');
|
||||
const versions = readdirSync(tools).sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
|
||||
const exe = process.platform === 'win32' ? 'aapt2.exe' : 'aapt2';
|
||||
for (const v of versions) if (existsSync(join(tools, v, exe))) return join(tools, v, exe);
|
||||
return fail([`no aapt2 under ${tools}`]);
|
||||
}
|
||||
|
||||
function verify(apk: string | undefined): void {
|
||||
const file = apk ?? newestApk(OUTPUTS);
|
||||
if (file === undefined || !existsSync(file)) fail([`no APK to verify under ${OUTPUTS}`]);
|
||||
const tool = aapt2();
|
||||
const run = (...args: string[]): string => {
|
||||
const r = spawnSync(tool, args, { encoding: 'utf8' });
|
||||
if (r.status !== 0) fail([`aapt2 ${args.join(' ')} failed: ${r.stderr}`]);
|
||||
return r.stdout;
|
||||
};
|
||||
const left = apkProblems(run('dump', 'permissions', file), run('dump', 'xmltree', '--file', 'AndroidManifest.xml', file));
|
||||
if (left.length > 0) fail(left);
|
||||
console.log(`android: ${file} verified (no permission asked, no backup, WebView metrics and Safe Browsing off)`);
|
||||
}
|
||||
|
||||
const [command, arg] = process.argv.slice(2);
|
||||
try {
|
||||
if (command === 'prepare') {
|
||||
if (!existsSync(MANIFEST)) tauri('android', 'init', '--ci', '--skip-targets-install');
|
||||
await import('./icons.js');
|
||||
apply();
|
||||
} else if (command === 'apply') apply();
|
||||
else if (command === 'check') {
|
||||
const left = problems();
|
||||
if (left.length > 0) fail(left);
|
||||
console.log('android: privacy in place');
|
||||
} else if (command === 'verify') verify(arg);
|
||||
else fail(['usage: android.ts prepare|apply|check|verify [apk]']);
|
||||
} catch (error) {
|
||||
fail([(error as Error).message]);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* The app's icons, made from the PWA's icon (`apps/rosea/public/icon.svg`) before every build
|
||||
* (tauri-platforms.md D8). They are build output, never committed: the only images in git are
|
||||
* the source SVG and optimised art under art/final/ (CLAUDE.md §5.2). The icon is still a
|
||||
* placeholder; the real one comes through the art pipeline (GAP_ANALYSIS G0.21).
|
||||
*
|
||||
* tsx scripts/icons.ts makes them when missing or older than the SVG
|
||||
*/
|
||||
import { existsSync, statSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { PACKAGE, SRC_TAURI, tauri } from './tauri.js';
|
||||
|
||||
const SOURCE = join(PACKAGE, '..', 'rosea', 'public', 'icon.svg');
|
||||
const MARK = join(SRC_TAURI, 'icons', 'icon.ico');
|
||||
const ANDROID = join(SRC_TAURI, 'gen', 'android');
|
||||
const ANDROID_MARK = join(ANDROID, 'app', 'src', 'main', 'res', 'mipmap-mdpi', 'ic_launcher.png');
|
||||
|
||||
const stale = (file: string): boolean => !existsSync(file) || statSync(file).mtimeMs < statSync(SOURCE).mtimeMs;
|
||||
|
||||
// `tauri icon` writes the Android launcher icons into gen/android only when that exists, so it
|
||||
// runs again after `tauri android init` (which puts Tauri's own logo there).
|
||||
if (stale(MARK) || (existsSync(ANDROID) && stale(ANDROID_MARK))) {
|
||||
tauri('icon', SOURCE);
|
||||
console.log('icons: made from apps/rosea/public/icon.svg');
|
||||
} else {
|
||||
console.log('icons: up to date');
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* The iOS app. Tauri can build it only on macOS with Xcode, and putting it on a phone needs an
|
||||
* Apple developer account (free for one's own device; paid for TestFlight and the App Store).
|
||||
* Elsewhere this refuses with that reason instead of failing somewhere deep in the CLI
|
||||
* (CLAUDE.md §8, *iOS cannot be built on Windows*; tauri-platforms.md G-T1).
|
||||
*
|
||||
* tsx scripts/ios.ts on macOS: `tauri ios init` once, icons, then `tauri ios build --debug`
|
||||
*/
|
||||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { SRC_TAURI, tauri } from './tauri.js';
|
||||
|
||||
if (process.platform !== 'darwin') {
|
||||
console.error(
|
||||
'ios: the iOS app can only be built on macOS with Xcode (and an Apple developer account to run it on a phone).\n' +
|
||||
`ios: this machine is ${process.platform}. Nothing was built. See .agents/features/tauri-platforms.md, G-T1.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!existsSync(join(SRC_TAURI, 'gen', 'apple'))) tauri('ios', 'init', '--ci');
|
||||
await import('./icons.js');
|
||||
tauri('ios', 'build', '--debug', ...process.argv.slice(2));
|
||||
@@ -0,0 +1,19 @@
|
||||
/** Runs the Tauri CLI of this package, in this package's folder, and stops the script if it fails. */
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
export const PACKAGE = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
export const SRC_TAURI = join(PACKAGE, 'src-tauri');
|
||||
|
||||
export function tauri(...args: string[]): void {
|
||||
const run = spawnSync('pnpm', ['exec', 'tauri', ...args], {
|
||||
cwd: PACKAGE,
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32'
|
||||
});
|
||||
if (run.status !== 0) {
|
||||
console.error(`tauri ${args.join(' ')} failed (exit ${String(run.status ?? run.signal)})`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
Generated
+4521
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "rosea-shell"
|
||||
version = "0.1.0"
|
||||
description = "The Tauri 2 shell of Rosea Domi: a window around the built game, and nothing else."
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix avoids a clash between the lib and the bin on Windows (cargo#8519).
|
||||
name = "rosea_shell_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.7.5", features = [] }
|
||||
|
||||
# No Tauri plugin and no other crate: the shell opens a window on the built game and does
|
||||
# nothing else. Each plugin that arrives later (notifications, Phase 6) is reviewed for
|
||||
# network access first (.agents/features/tauri-platforms.md D5).
|
||||
[dependencies]
|
||||
tauri = { version = "2.12.6", features = [] }
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
panic = "abort"
|
||||
strip = true
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//! The Tauri 2 shell of Rosea Domi (CLAUDE.md §2, *Four versions*).
|
||||
//!
|
||||
//! A window on the built game (`apps/rosea/dist-tauri/`) and nothing else: no command, no
|
||||
//! plugin, no file of its own. The game keeps everything in the webview's IndexedDB, exactly
|
||||
//! as in the PWA. `capabilities/` is absent on purpose, so the page is granted no IPC at all.
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.run(tauri::generate_context!())
|
||||
// Nothing to recover from here: without a window there is no garden to show.
|
||||
.expect("Rosea Domi could not open its window");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// No console window behind the garden in a release build on Windows.
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
rosea_shell_lib::run()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"build": {
|
||||
"beforeBuildCommand": "pnpm --filter @rosea/tauri android:privacy && pnpm --filter @rosea/app build:shell"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Rosea Domi",
|
||||
"version": "../../rosea/package.json",
|
||||
"identifier": "cz.mareknovak.domi.rosea",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm --filter @rosea/app dev:shell",
|
||||
"devUrl": "http://127.0.0.1:5173",
|
||||
"beforeBuildCommand": "pnpm --filter @rosea/app build:shell",
|
||||
"frontendDist": "../../rosea/dist-tauri"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"label": "main",
|
||||
"title": "Rosea Domi",
|
||||
"width": 480,
|
||||
"height": 800,
|
||||
"minWidth": 320,
|
||||
"minHeight": 480,
|
||||
"useHttpsScheme": true,
|
||||
"additionalBrowserArgs": "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection,DnsOverHttpsUpgrade,DohProviderGoogle,DohProviderGoogleDns,DohProviderCloudflare,msExperimentationAndConfigurationService,OptimizationHints,AutofillServerCommunication,MediaRouter,Translate --disable-background-networking --disable-component-update --disable-domain-reliability --disable-sync --no-pings --disable-client-side-phishing-detection --dns-prefetch-disable"
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; manifest-src 'self'; worker-src 'self'; object-src 'none'; base-uri 'self'; form-action 'none'"
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"],
|
||||
"category": "Game",
|
||||
"shortDescription": "A rose to tend, a fox to befriend, and the time we give to people.",
|
||||
"windows": { "nsis": { "installMode": "currentUser" } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "$schema": "https://schema.tauri.app/config/2", "bundle": { "targets": ["deb", "appimage"] } }
|
||||
@@ -0,0 +1 @@
|
||||
{ "$schema": "https://schema.tauri.app/config/2", "bundle": { "targets": ["app", "dmg"] } }
|
||||
@@ -0,0 +1 @@
|
||||
{ "$schema": "https://schema.tauri.app/config/2", "bundle": { "targets": ["nsis"] } }
|
||||
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* The Android app's privacy, applied to Tauri's generated project (tauri-platforms.md D6).
|
||||
*
|
||||
* `src-tauri/gen/android` is written by `tauri android init` and never committed, so every
|
||||
* clone starts from Tauri's stock manifest, which asks for `INTERNET` and lets Android copy the
|
||||
* app's data to the player's cloud backup. What must hold is carried here and applied before
|
||||
* every Android build; the build fails if anything is missing. The approach and the two rule
|
||||
* files follow Amicitia's (its `android-privacy.md`, measured there on 2026-11-08):
|
||||
*
|
||||
* - **no `INTERNET`**: Rosea has no network feature yet, so the kernel refuses the app any
|
||||
* socket, the webview's own traffic included. It comes back with the first feature that
|
||||
* needs the network (Phase 3), and that feature's doc measures the webview first;
|
||||
* - **no backup and no device transfer**: the care log, the keys and the chosen town stay on
|
||||
* this device; *Keep her safe* is how a rose moves;
|
||||
* - the WebView's **metrics** and **Safe Browsing** lookups off, for the day `INTERNET` returns.
|
||||
*
|
||||
* Pure functions on strings; the files are read and written by `scripts/android.ts`.
|
||||
*/
|
||||
|
||||
export const BACKUP_RULES = 'rosea_backup_rules';
|
||||
export const EXTRACTION_RULES = 'rosea_data_extraction_rules';
|
||||
export const RULE_FILES = [`${BACKUP_RULES}.xml`, `${EXTRACTION_RULES}.xml`] as const;
|
||||
|
||||
/** Attributes `<application>` must carry. */
|
||||
export const APPLICATION_ATTRS: Readonly<Record<string, string>> = {
|
||||
'android:allowBackup': 'false',
|
||||
'android:fullBackupContent': `@xml/${BACKUP_RULES}`,
|
||||
'android:dataExtractionRules': `@xml/${EXTRACTION_RULES}`
|
||||
};
|
||||
|
||||
/** WebView switches read from the manifest (developer.android.com, "Manage WebView objects"). */
|
||||
export const META_DATA: Readonly<Record<string, string>> = {
|
||||
'android.webkit.WebView.EnableSafeBrowsing': 'false',
|
||||
'android.webkit.WebView.MetricsOptOut': 'true'
|
||||
};
|
||||
|
||||
const BEGIN = '<!-- rosea-privacy: begin (apps/rosea-tauri/src/android-privacy.ts) -->';
|
||||
const END = '<!-- rosea-privacy: end -->';
|
||||
const INTERNET_LINE = /^[ \t]*<uses-permission\s+android:name="android\.permission\.INTERNET"\s*\/>[ \t]*\n/gm;
|
||||
const INTERNET_ANY = /android\.permission\.INTERNET/;
|
||||
|
||||
const escape = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
|
||||
/** The one `<application …>` opening tag, or an error naming what is wrong. */
|
||||
function applicationTag(xml: string): RegExpMatchArray & { index: number } {
|
||||
const tags = [...xml.matchAll(/<application\b[^>]*>/g)];
|
||||
if (tags.length !== 1) throw new Error(`expected one <application> tag, found ${tags.length}`);
|
||||
const tag = tags[0]!;
|
||||
if (tag[0].endsWith('/>')) throw new Error('<application/> is empty; expected a template with children');
|
||||
return tag as RegExpMatchArray & { index: number };
|
||||
}
|
||||
|
||||
function setAttribute(tag: string, name: string, value: string): string {
|
||||
const re = new RegExp(`(\\s${escape(name)}=")[^"]*(")`);
|
||||
if (re.test(tag)) return tag.replace(re, `$1${value}$2`);
|
||||
const indent = /\n([ \t]+)android:/.exec(tag)?.[1] ?? ' ';
|
||||
return tag.replace(/^<application\b/, `<application\n${indent}${name}="${value}"`);
|
||||
}
|
||||
|
||||
/** The manifest with the privacy settings in place. Throws, changing nothing, on an unexpected shape. */
|
||||
export function patchManifest(xml: string): string {
|
||||
const eol = xml.includes('\r\n') ? '\r\n' : '\n';
|
||||
let out = xml.replaceAll('\r\n', '\n');
|
||||
|
||||
// 1. <application> attributes.
|
||||
const tag = applicationTag(out);
|
||||
let patched = tag[0];
|
||||
for (const [name, value] of Object.entries(APPLICATION_ATTRS)) patched = setAttribute(patched, name, value);
|
||||
out = out.slice(0, tag.index) + patched + out.slice(tag.index + tag[0].length);
|
||||
|
||||
// 2. The meta-data block, replaced whole on every run, so a second run changes nothing.
|
||||
const from = out.indexOf(BEGIN);
|
||||
if (from >= 0) {
|
||||
const to = out.indexOf(END, from);
|
||||
if (to < 0) throw new Error('found the begin marker of the privacy block but not its end');
|
||||
const lineStart = out.lastIndexOf('\n', from) + 1;
|
||||
const lineEnd = out.indexOf('\n', to);
|
||||
out = out.slice(0, lineStart) + out.slice(lineEnd + 1);
|
||||
}
|
||||
const closes = [...out.matchAll(/^([ \t]*)<\/application>/gm)];
|
||||
if (closes.length !== 1) throw new Error(`expected one </application>, found ${closes.length}`);
|
||||
const close = closes[0]!;
|
||||
const indent = `${close[1] ?? ''} `;
|
||||
const block = [
|
||||
BEGIN,
|
||||
...Object.entries(META_DATA).map(([n, v]) => `<meta-data android:name="${n}" android:value="${v}" />`),
|
||||
END
|
||||
]
|
||||
.map((line) => `${indent}${line}\n`)
|
||||
.join('');
|
||||
out = out.slice(0, close.index) + block + out.slice(close.index);
|
||||
|
||||
// 3. INTERNET removed. Any other form of asking for it is refused rather than missed.
|
||||
out = out.replace(INTERNET_LINE, '');
|
||||
if (INTERNET_ANY.test(out)) throw new Error('INTERNET is requested in a form this patch does not remove');
|
||||
|
||||
return out.replaceAll('\n', eol);
|
||||
}
|
||||
|
||||
/** What the manifest lacks, by name; empty when it is in order. */
|
||||
export function manifestProblems(xml: string): string[] {
|
||||
const problems: string[] = [];
|
||||
let tag: string;
|
||||
try {
|
||||
tag = applicationTag(xml)[0];
|
||||
} catch (error) {
|
||||
return [(error as Error).message];
|
||||
}
|
||||
for (const [name, value] of Object.entries(APPLICATION_ATTRS)) {
|
||||
if (!new RegExp(`\\s${escape(name)}="${escape(value)}"`).test(tag)) problems.push(`<application> lacks ${name}="${value}"`);
|
||||
}
|
||||
for (const [name, value] of Object.entries(META_DATA)) {
|
||||
if (!new RegExp(`<meta-data\\s+android:name="${escape(name)}"\\s+android:value="${escape(value)}"\\s*/>`).test(xml)) {
|
||||
problems.push(`no meta-data ${name}=${value}`);
|
||||
}
|
||||
}
|
||||
if (INTERNET_ANY.test(xml)) problems.push('android.permission.INTERNET is requested');
|
||||
return problems;
|
||||
}
|
||||
|
||||
/** Every storage domain Android knows; each must be excluded. */
|
||||
export const DOMAINS = [
|
||||
'root', 'file', 'database', 'sharedpref', 'external',
|
||||
'device_root', 'device_file', 'device_database', 'device_sharedpref'
|
||||
] as const;
|
||||
|
||||
/** Where each rules file must exclude everything: '' is the file's root element. */
|
||||
export const RULE_SECTIONS: Readonly<Record<(typeof RULE_FILES)[number], readonly string[]>> = {
|
||||
[`${BACKUP_RULES}.xml`]: [''],
|
||||
[`${EXTRACTION_RULES}.xml`]: ['cloud-backup', 'device-transfer']
|
||||
} as Record<(typeof RULE_FILES)[number], readonly string[]>;
|
||||
|
||||
/** A rules file must exclude every domain in every section, and include nothing. */
|
||||
export function ruleProblems(xml: string, sections: readonly string[]): string[] {
|
||||
const problems: string[] = [];
|
||||
if (/<include\b/.test(xml)) problems.push('includes something');
|
||||
for (const section of sections) {
|
||||
const body = section ? new RegExp(`<${section}\\b[^>]*>([\\s\\S]*?)</${section}>`).exec(xml)?.[1] : xml;
|
||||
if (body === undefined) {
|
||||
problems.push(`no <${section}>`);
|
||||
continue;
|
||||
}
|
||||
for (const domain of DOMAINS) {
|
||||
if (!new RegExp(`<exclude\\s+domain="${domain}"\\s+path="\\."\\s*/>`).test(body)) {
|
||||
problems.push(`${section || 'root'}: ${domain} is not excluded`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the BUILT APK says, from `aapt2 dump permissions` and `aapt2 dump xmltree` of its
|
||||
* manifest: the proof is the artefact, not the source (Amicitia lessons/technical.md).
|
||||
* The manifest merge can add permissions from libraries; only the APK can tell.
|
||||
*/
|
||||
export function apkProblems(permissions: string, manifestTree: string): string[] {
|
||||
const problems: string[] = [];
|
||||
const asked = [...permissions.matchAll(/uses-permission: name='([^']+)'/g)].map((m) => m[1]!);
|
||||
// Tauri's stock app asks for nothing else today; a new one is a review question, not a pass.
|
||||
const allowed = new Set<string>([]);
|
||||
for (const name of asked) {
|
||||
if (name.endsWith('.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION')) continue; // androidx's own, signature-level
|
||||
if (!allowed.has(name)) problems.push(`the APK asks for ${name}`);
|
||||
}
|
||||
if (!/allowBackup\([^)]*\)=false/.test(manifestTree)) problems.push('the APK does not set allowBackup=false');
|
||||
for (const [name, value] of Object.entries(META_DATA)) {
|
||||
const at = manifestTree.indexOf(`"${name}"`);
|
||||
if (at < 0) problems.push(`the APK has no meta-data ${name}`);
|
||||
else if (!manifestTree.slice(at, at + 300).includes(value === 'true' ? '=true' : '=false') &&
|
||||
!manifestTree.slice(at, at + 300).includes(`"${value}"`)) {
|
||||
problems.push(`the APK's meta-data ${name} is not ${value}`);
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* The Android privacy patch (tauri-platforms.md D6), on Tauri 2.12.5's stock manifest exactly as
|
||||
* `tauri android init` wrote it (fixtures/AndroidManifest.stock.xml), and on the committed rule files.
|
||||
*/
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
APPLICATION_ATTRS,
|
||||
DOMAINS,
|
||||
manifestProblems,
|
||||
META_DATA,
|
||||
patchManifest,
|
||||
RULE_FILES,
|
||||
RULE_SECTIONS,
|
||||
ruleProblems
|
||||
} from '../src/android-privacy.js';
|
||||
|
||||
const HERE = dirname(fileURLToPath(import.meta.url));
|
||||
const STOCK = readFileSync(join(HERE, 'fixtures', 'AndroidManifest.stock.xml'), 'utf8').replaceAll('\r\n', '\n');
|
||||
const rules = (f: string): string => readFileSync(join(HERE, '..', 'android', 'res', 'xml', f), 'utf8');
|
||||
|
||||
describe('patchManifest', () => {
|
||||
const patched = patchManifest(STOCK);
|
||||
|
||||
it("removes Tauri's INTERNET permission: the kernel then refuses the app any socket", () => {
|
||||
expect(STOCK).toContain('android.permission.INTERNET');
|
||||
expect(patched).not.toContain('android.permission.INTERNET');
|
||||
});
|
||||
|
||||
it('turns backup and device transfer off on <application>', () => {
|
||||
const tag = /<application\b[^>]*>/.exec(patched)?.[0] ?? '';
|
||||
for (const [name, value] of Object.entries(APPLICATION_ATTRS)) expect(tag).toContain(`${name}="${value}"`);
|
||||
// What Tauri set is kept.
|
||||
expect(tag).toContain('android:icon="@mipmap/ic_launcher"');
|
||||
expect(tag).toContain('android:usesCleartextTraffic="${usesCleartextTraffic}"');
|
||||
});
|
||||
|
||||
it("switches the WebView's metrics and Safe Browsing off, inside <application>", () => {
|
||||
const inside = /<application\b[\s\S]*<\/application>/.exec(patched)?.[0] ?? '';
|
||||
for (const [name, value] of Object.entries(META_DATA)) {
|
||||
expect(inside).toContain(`<meta-data android:name="${name}" android:value="${value}" />`);
|
||||
}
|
||||
});
|
||||
|
||||
it('leaves the rest of the manifest as it was', () => {
|
||||
for (const keep of ['android:name=".MainActivity"', 'android.intent.category.LAUNCHER', 'androidx.core.content.FileProvider']) {
|
||||
expect(patched).toContain(keep);
|
||||
}
|
||||
});
|
||||
|
||||
it('changes nothing on a second run', () => {
|
||||
expect(patchManifest(patched)).toBe(patched);
|
||||
});
|
||||
|
||||
it('keeps Windows line endings when the file has them', () => {
|
||||
const crlf = patchManifest(STOCK.replaceAll('\n', '\r\n'));
|
||||
expect(crlf).toBe(patched.replaceAll('\n', '\r\n'));
|
||||
});
|
||||
|
||||
it('overwrites an allowBackup="true" rather than adding a second one', () => {
|
||||
const on = STOCK.replace('<application', '<application android:allowBackup="true"');
|
||||
const out = patchManifest(on);
|
||||
expect(out).toContain('android:allowBackup="false"');
|
||||
expect(out).not.toContain('android:allowBackup="true"');
|
||||
expect(out.match(/android:allowBackup=/g)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('refuses a manifest whose shape it does not know, rather than guessing', () => {
|
||||
expect(() => patchManifest(STOCK.replace('</application>', '</application><application></application>'))).toThrow(/application/);
|
||||
expect(() => patchManifest(STOCK.replace(/<application[\s\S]*<\/application>/, '<application />'))).toThrow();
|
||||
// INTERNET asked for in a form the line pattern does not match.
|
||||
const odd = STOCK.replace(
|
||||
'<uses-permission android:name="android.permission.INTERNET" />',
|
||||
'<uses-permission android:name="android.permission.INTERNET" android:maxSdkVersion="99" />'
|
||||
);
|
||||
expect(() => patchManifest(odd)).toThrow(/INTERNET/);
|
||||
});
|
||||
|
||||
it('removes INTERNET written over two lines too', () => {
|
||||
const split = STOCK.replace(
|
||||
'<uses-permission android:name="android.permission.INTERNET" />',
|
||||
'<uses-permission\n android:name="android.permission.INTERNET" />'
|
||||
);
|
||||
expect(patchManifest(split)).not.toContain('INTERNET');
|
||||
});
|
||||
});
|
||||
|
||||
describe('manifestProblems', () => {
|
||||
it("names everything missing from Tauri's stock manifest", () => {
|
||||
const problems = manifestProblems(STOCK);
|
||||
expect(problems).toContain('android.permission.INTERNET is requested');
|
||||
for (const name of Object.keys(APPLICATION_ATTRS)) expect(problems.join('\n')).toContain(name);
|
||||
for (const name of Object.keys(META_DATA)) expect(problems.join('\n')).toContain(name);
|
||||
expect(problems).toHaveLength(1 + Object.keys(APPLICATION_ATTRS).length + Object.keys(META_DATA).length);
|
||||
});
|
||||
|
||||
it('finds nothing missing once patched', () => {
|
||||
expect(manifestProblems(patchManifest(STOCK))).toEqual([]);
|
||||
});
|
||||
|
||||
it('notices a single switch turned back on', () => {
|
||||
const patched = patchManifest(STOCK);
|
||||
expect(manifestProblems(patched.replace('android:allowBackup="false"', 'android:allowBackup="true"'))).toEqual([
|
||||
'<application> lacks android:allowBackup="false"'
|
||||
]);
|
||||
expect(manifestProblems(patched.replace('android:value="true"', 'android:value="false"'))).toEqual([
|
||||
'no meta-data android.webkit.WebView.MetricsOptOut=true'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the committed rule files', () => {
|
||||
for (const f of RULE_FILES) {
|
||||
it(`${f} excludes every domain, in every section, and includes nothing`, () => {
|
||||
expect(ruleProblems(rules(f), RULE_SECTIONS[f])).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
it('a file that forgets one domain is caught, by name', () => {
|
||||
const f = 'rosea_data_extraction_rules.xml' as const;
|
||||
const text = rules(f);
|
||||
const firstDb = text.indexOf('<exclude domain="database" path="." />');
|
||||
const broken = text.slice(0, firstDb) + text.slice(firstDb + '<exclude domain="database" path="." />'.length);
|
||||
expect(ruleProblems(broken, RULE_SECTIONS[f])).toEqual(['cloud-backup: database is not excluded']);
|
||||
});
|
||||
|
||||
it('a file that includes something is caught', () => {
|
||||
const f = 'rosea_backup_rules.xml' as const;
|
||||
const broken = rules(f).replace('</full-backup-content>', '<include domain="file" path="." />\n</full-backup-content>');
|
||||
expect(ruleProblems(broken, RULE_SECTIONS[f])).toEqual(['includes something']);
|
||||
});
|
||||
|
||||
it('knows all nine storage domains', () => {
|
||||
expect(DOMAINS).toHaveLength(9);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* The shell's configuration holds what tauri-platforms.md decided (D3–D7, D10, D11). Each of
|
||||
* these is a value that fails silently at runtime, or worse, only after a release: a changed
|
||||
* identifier or origin leaves the player's rose behind in the old app.
|
||||
*/
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { CSP } from '../../rosea/csp.js';
|
||||
import { PRODUCT_NAME } from '../../../packages/schema/src/constants.js';
|
||||
|
||||
const SRC_TAURI = join(dirname(fileURLToPath(import.meta.url)), '..', 'src-tauri');
|
||||
/** The parts of a Tauri config these tests read. */
|
||||
interface TauriConf {
|
||||
productName?: string;
|
||||
identifier?: string;
|
||||
version?: string;
|
||||
build: { frontendDist: string; beforeBuildCommand: string; beforeDevCommand: string; devUrl: string };
|
||||
app: { windows: Record<string, unknown>[]; security: Record<string, unknown> };
|
||||
bundle: { targets?: string[] };
|
||||
plugins?: unknown;
|
||||
}
|
||||
const json = (name: string): TauriConf => JSON.parse(readFileSync(join(SRC_TAURI, name), 'utf8')) as TauriConf;
|
||||
const conf = json('tauri.conf.json');
|
||||
const window = conf.app.windows[0] ?? {};
|
||||
|
||||
describe('tauri.conf.json', () => {
|
||||
it('names the app with the product name, in the bundle and the window title (D3)', () => {
|
||||
expect(conf.productName).toBe(PRODUCT_NAME);
|
||||
expect(window['title']).toBe(PRODUCT_NAME);
|
||||
});
|
||||
|
||||
it('keeps the identifier it was released with: a new one is a different app (D3)', () => {
|
||||
expect(conf.identifier).toBe('cz.mareknovak.domi.rosea');
|
||||
});
|
||||
|
||||
it("reads its version from the game's package.json (D3)", () => {
|
||||
expect(conf.version).toBe('../../rosea/package.json');
|
||||
const pkg = JSON.parse(readFileSync(resolve(SRC_TAURI, String(conf.version)), 'utf8')) as Record<string, string>;
|
||||
expect(pkg['name']).toBe('@rosea/app');
|
||||
expect(pkg['version']).toMatch(/^\d+\.\d+\.\d+$/);
|
||||
});
|
||||
|
||||
it("delivers the PWA's content-security policy, the same string (D4)", () => {
|
||||
expect(conf.app.security['csp']).toBe(CSP);
|
||||
});
|
||||
|
||||
it("wraps the game's shell build and nothing else (D1, D2)", () => {
|
||||
expect(conf.build.frontendDist).toBe('../../rosea/dist-tauri');
|
||||
expect(resolve(SRC_TAURI, conf.build.frontendDist)).toBe(resolve(SRC_TAURI, '..', '..', 'rosea', 'dist-tauri'));
|
||||
expect(conf.build.beforeBuildCommand).toBe('pnpm --filter @rosea/app build:shell');
|
||||
expect(conf.build.beforeDevCommand).toBe('pnpm --filter @rosea/app dev:shell');
|
||||
});
|
||||
|
||||
it('runs its dev server on 127.0.0.1 only (CLAUDE.md §5.7)', () => {
|
||||
expect(new URL(conf.build.devUrl).hostname).toBe('127.0.0.1');
|
||||
const app = JSON.parse(readFileSync(join(SRC_TAURI, '..', '..', 'rosea', 'package.json'), 'utf8')) as { scripts: Record<string, string> };
|
||||
expect(app['scripts']['dev:shell']).toContain('--host 127.0.0.1');
|
||||
expect(app['scripts']['dev:shell']).toContain('--port 5173');
|
||||
expect(conf.build.devUrl).toBe('http://127.0.0.1:5173');
|
||||
});
|
||||
|
||||
it('keeps the https origin it was released with: IndexedDB lives per origin (D10)', () => {
|
||||
expect(window['useHttpsScheme']).toBe(true);
|
||||
});
|
||||
|
||||
it("switches WebView2's own traffic off (D7)", () => {
|
||||
const args = String(window['additionalBrowserArgs']);
|
||||
for (const flag of [
|
||||
'--disable-background-networking',
|
||||
'--disable-component-update',
|
||||
'--disable-domain-reliability',
|
||||
'--disable-sync',
|
||||
'--no-pings',
|
||||
'--disable-client-side-phishing-detection',
|
||||
'--dns-prefetch-disable'
|
||||
]) {
|
||||
expect(args.split(' ')).toContain(flag);
|
||||
}
|
||||
const disabled = /--disable-features=(\S+)/.exec(args)?.[1]?.split(',') ?? [];
|
||||
for (const feature of [
|
||||
// Tauri's own defaults, which a custom list must repeat.
|
||||
'msWebOOUI', 'msPdfOOUI', 'msSmartScreenProtection',
|
||||
'DnsOverHttpsUpgrade', 'msExperimentationAndConfigurationService', 'AutofillServerCommunication', 'OptimizationHints'
|
||||
]) {
|
||||
expect(disabled).toContain(feature);
|
||||
}
|
||||
});
|
||||
|
||||
it('builds only what each system can make (D11)', () => {
|
||||
expect(json('tauri.windows.conf.json').bundle.targets).toEqual(['nsis']);
|
||||
expect(json('tauri.macos.conf.json').bundle.targets).toEqual(['app', 'dmg']);
|
||||
expect(json('tauri.linux.conf.json').bundle.targets).toEqual(['deb', 'appimage']);
|
||||
expect(conf.bundle.targets).toBeUndefined();
|
||||
});
|
||||
|
||||
it('applies the Android privacy patch before the game is built for Android (D6)', () => {
|
||||
const before = json('tauri.android.conf.json').build.beforeBuildCommand;
|
||||
const patch = before.indexOf('pnpm --filter @rosea/tauri android:privacy');
|
||||
expect(patch).toBe(0);
|
||||
expect(before.indexOf('&& pnpm --filter @rosea/app build:shell')).toBeGreaterThan(patch);
|
||||
});
|
||||
});
|
||||
|
||||
describe('the Rust side (D5)', () => {
|
||||
it('depends on tauri alone: no plugin, no SDK', () => {
|
||||
const cargo = readFileSync(join(SRC_TAURI, 'Cargo.toml'), 'utf8');
|
||||
const deps = /\n\[dependencies\]\n([\s\S]*?)(?:\n\[|$)/.exec(cargo)?.[1] ?? '';
|
||||
const names = deps
|
||||
.split('\n')
|
||||
.map((l) => /^([A-Za-z0-9_-]+)\s*=/.exec(l)?.[1])
|
||||
.filter((n): n is string => n !== undefined);
|
||||
expect(names).toEqual(['tauri']);
|
||||
expect(cargo).not.toMatch(/\[target\.[^\]]*dependencies\]/);
|
||||
});
|
||||
|
||||
it('grants the page no IPC: there is no capabilities folder', () => {
|
||||
expect(existsSync(join(SRC_TAURI, 'capabilities'))).toBe(false);
|
||||
expect(conf.app.security['capabilities']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('declares no plugin configuration', () => {
|
||||
expect(conf.plugins).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<!-- AndroidTV support -->
|
||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||
|
||||
<application
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.rosea_shell"
|
||||
android:usesCleartextTraffic="${usesCleartextTraffic}">
|
||||
<activity
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
|
||||
android:launchMode="singleTask"
|
||||
android:label="@string/main_activity_title"
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<!-- AndroidTV support -->
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* The game's build for the shell (`vite build --mode tauri`, tauri-platforms.md D2), made into a
|
||||
* temporary folder and read: no service worker, no manifest, no <meta> policy, assets at the root,
|
||||
* and the shell constant replaced. The PWA's own build is checked by the e2e suites.
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
|
||||
const APP = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'rosea');
|
||||
let out = '';
|
||||
let html = '';
|
||||
let files: string[] = [];
|
||||
let scripts = '';
|
||||
|
||||
beforeAll(() => {
|
||||
out = mkdtempSync(join(tmpdir(), 'rosea-shell-build-'));
|
||||
const build = spawnSync('pnpm', ['exec', 'vite', 'build', '--mode', 'tauri', '--outDir', out, '--emptyOutDir', '--logLevel', 'error'], {
|
||||
cwd: APP,
|
||||
encoding: 'utf8',
|
||||
shell: process.platform === 'win32'
|
||||
});
|
||||
if (build.status !== 0) throw new Error(`vite build --mode tauri failed:\n${build.stdout}\n${build.stderr}`);
|
||||
files = readdirSync(out, { recursive: true, encoding: 'utf8' }).map((f) => f.replaceAll('\\', '/'));
|
||||
html = readFileSync(join(out, 'index.html'), 'utf8');
|
||||
scripts = files.filter((f) => f.endsWith('.js')).map((f) => readFileSync(join(out, f), 'utf8')).join('\n');
|
||||
}, 120_000);
|
||||
|
||||
afterAll(() => {
|
||||
if (out) rmSync(out, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('the game built for the shell', () => {
|
||||
it('has no service worker and no web manifest', () => {
|
||||
expect(files.filter((f) => /(^|\/)(sw|workbox-[^/]*|registerSW)\.js$/.test(f))).toEqual([]);
|
||||
expect(files.filter((f) => f.endsWith('.webmanifest'))).toEqual([]);
|
||||
expect(html).not.toContain('manifest');
|
||||
expect(scripts).not.toContain('navigator.serviceWorker.register');
|
||||
});
|
||||
|
||||
it('carries no <meta> content-security policy: Tauri delivers it (D4)', () => {
|
||||
expect(html).not.toContain('Content-Security-Policy');
|
||||
});
|
||||
|
||||
it('loads its assets from the root of the origin, not /Rosea/', () => {
|
||||
const urls = [...html.matchAll(/(?:src|href)="([^"]+)"/g)].map((m) => m[1]!);
|
||||
const assets = urls.filter((u) => u.includes('assets/'));
|
||||
expect(assets.length).toBeGreaterThanOrEqual(2);
|
||||
for (const u of assets) expect(u.startsWith('/assets/')).toBe(true);
|
||||
expect(html).not.toContain('/Rosea/');
|
||||
});
|
||||
|
||||
it('replaces the shell constant at build time: left in, it would throw in the webview', () => {
|
||||
expect(scripts).not.toContain('__ROSEA_SHELL__');
|
||||
});
|
||||
|
||||
it('ships no source maps', () => {
|
||||
expect(files.filter((f) => f.endsWith('.map'))).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "scripts/**/*.ts", "test/**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user