import { execFileSync } from "node:child_process"; import { existsSync, readFileSync } from "node:fs"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; const browserRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const androidRoot = resolve(browserRoot, "../peach-android"); const localJavaHome = "/opt/homebrew/opt/openjdk@17"; const javaHome = process.env.JAVA_HOME ?? (existsSync(localJavaHome) ? localJavaHome : undefined); const browserCoordinator = readFileSync( resolve(browserRoot, "src/background/sync-coordinator.ts"), "utf8", ); const androidCoordinator = readFileSync( resolve(androidRoot, "app/src/main/java/com/peachpasswords/sync/SyncCoordinator.kt"), "utf8", ); if (browserCoordinator.includes('helloIn.version === localVersion')) { throw new Error("Browser still contains the forbidden equal-version fast path"); } if (!browserCoordinator.includes("helloIn.deviceManifestVersion === DEVICE_MANIFEST_VERSION")) { throw new Error("Browser does not negotiate device manifests from SYNC_HELLO"); } if (!androidCoordinator.includes("val exchangeDeviceManifest = vault.negotiatesDeviceManifest(hello)")) { throw new Error("Android does not negotiate device manifests from SYNC_HELLO"); } execFileSync( "npm", [ "test", "--", "--run", "src/background/sync-coordinator.test.ts", "src/shared/sync-padding.test.ts", "src/shared/rendezvous.test.ts", "src/shared/device-manifest.test.ts", "src/crypto/peachPayload.test.ts", "src/shared/sync-entry-envelope.kat.test.ts", "src/shared/vault-adopt.test.ts", ], { cwd: browserRoot, stdio: "inherit" }, ); execFileSync( resolve(androidRoot, "gradlew"), [ "--no-configuration-cache", "testDebugUnitTest", "--tests", "com.peachpasswords.sync.SyncCoordinatorTest", "--tests", "com.peachpasswords.sync.LockedSyncSpoolModelTest", "--tests", "com.peachpasswords.sync.SyncPaddingTest", "--tests", "com.peachpasswords.sync.DeviceManifestSupportTest", "--tests", "com.peachpasswords.CrossPlatformKATTest", "--tests", "com.peachpasswords.vault.PeachScriptTest", "--tests", "com.peachpasswords.sync.SyncEntryEnvelopeKatTest", "--tests", "com.peachpasswords.sync.VaultAdoptTest", ], { cwd: androidRoot, env: { ...process.env, ...(javaHome ? { JAVA_HOME: javaHome } : {}) }, stdio: "inherit", }, ); console.log("Cross-client sync protocol gate passed.");