#!/usr/bin/env python3 """Run the actual SafBrowserStore cursor-reading block on JVM test doubles. Requires a local Kotlin compiler and JDK; no SDK, Gradle, or downloads. This checks Kotlin control flow and resource cleanup, NOT Android API compatibility, Binder, URI grants, async IO, provider implementation, or device/UI behaviour. """ import argparse from pathlib import Path import shutil import subprocess ROOT = Path(__file__).resolve().parent.parent parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--source', type=Path, default=ROOT / 'androidApp/src/main/kotlin/dev/fileworkbench/android/browser/SafBrowserStore.kt', help='Optional historical source for reproducing the regression') args = parser.parse_args() compiler = shutil.which('kotlinc') java = shutil.which('java') if compiler is None or java is None: parser.error('Install kotlinc and a JDK, then rerun this offline check.') source = args.source.read_text(encoding='utf-8') # Copy verbatim, rather than maintaining a second corrected implementation. start_marker = ' val rows = ArrayList()' end_marker = ' BrowserListing(rows.distinctBy { it.id }, truncated, loading, information)' if source.count(start_marker) != 1 or source.count(end_marker) != 1: parser.error('Listing method changed shape; review and update the harness extraction boundaries.') start = source.index(start_marker) end = source.index(end_marker, start) + len(end_marker) block = source[start:end] template = (ROOT / 'scripts/regressions/FolderListingHarness.kt.template').read_text(encoding='utf-8') assert template.count('/* PRODUCTION_LISTING_BLOCK */') == 1 out = ROOT / 'out/folder-listing' out.mkdir(parents=True, exist_ok=True) generated = out / 'FolderListingHarness.kt' generated.write_text(template.replace('/* PRODUCTION_LISTING_BLOCK */', block), encoding='utf-8') core = sorted(str(p) for p in (ROOT / 'core/src/commonMain').rglob('*.kt')) jar = out / 'regression.jar' print(f'Source under test: {args.source}', flush=True) print('Extracted production cursor-reading block + real common models; Android APIs are test doubles.', flush=True) compiled = subprocess.run([compiler, *core, str(generated), '-jvm-target', '17', '-include-runtime', '-d', str(jar)], cwd=ROOT) if compiled.returncode: raise SystemExit(compiled.returncode) raise SystemExit(subprocess.run([java, '-cp', str(jar), 'dev.fileworkbench.testing.FolderListingHarnessKt'], cwd=ROOT).returncode)