diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c694da9..ac2d441 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: run: flutter pub get - name: Install ObjectBox native library - run: curl -sSfL https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh | bash + run: bash scripts/objectbox_runtime.sh install - name: Analyze code run: flutter analyze diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c11780f..5f79a0a 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -4,6 +4,7 @@ ```sh flutter pub get +just objectbox-setup # once per machine (macOS/Linux) just gen flutter run ``` @@ -12,13 +13,15 @@ flutter run Use `just` for common workflows: -| Command | Description | -| ------------- | -------------------------------------- | -| `just format` | Run `dart format` | -| `just lint` | Run `flutter analyze` | -| `just test` | Run the full `flutter test` suite | -| `just gen` | Run `build_runner` for code generation | -| `just check` | Format, lint, and test in sequence | +| Command | Description | +| ---------------------- | ----------------------------------------------------- | +| `just format` | Run `dart format` | +| `just lint` | Run `flutter analyze` | +| `just objectbox-setup` | Install pinned ObjectBox native runtime (macOS/Linux) | +| `just objectbox-check` | Verify ObjectBox native runtime is present | +| `just test` | Run the full `flutter test` suite | +| `just gen` | Run `build_runner` for code generation | +| `just check` | Format, lint, and test in sequence | ## Architecture @@ -94,13 +97,20 @@ After modifying `EmbeddedPost`, run `just gen` to regenerate `objectbox.g.dart` #### Running unit tests (ObjectBox native library) -ObjectBox requires a platform native library to run `flutter test` locally: +ObjectBox requires a platform native library to run `flutter test` locally. +Lazurite standardizes this setup through a pinned installer script. + +Supported local platforms: macOS and Linux. + +Run this once per machine: ```sh -bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh) +just objectbox-setup ``` -This installs `lib/libobjectbox.dylib` (macOS) or the equivalent. The file is gitignored and not required to build the app. +`just test` and `just test-quiet` intentionally run a preflight check +(`just objectbox-check`) and fail fast with setup instructions if the +runtime is missing. ## Semantic Search @@ -119,11 +129,12 @@ Liked posts are synced from the Bluesky API and persisted locally in the `liked_ **`LikedPostsRepository`** (`lib/features/feed/data/liked_posts_repository.dart`): -| Method | Description | -| -------------------------------------------- | -------------------------------------------------------------------------------------------------------- | -| `syncLikes(accountDid)` | Paginate `getActorLikes` until a known URI is hit or 1000-post cap is reached; evicts oldest on overflow | -| `getLikedPosts(accountDid, {limit, offset})` | Paginated query ordered by `likedAt DESC` | -| `removeLike(accountDid, postUri)` | Delete a single entry | +| Method | Description | +| -------------------------------------------- | ----------------------------------------------------------------------------- | +| `syncLikes(accountDid)` | Paginate `getActorLikes` until a known URI is hit or 1000-post cap is reached | +| | evicts oldest on overflow | +| `getLikedPosts(accountDid, {limit, offset})` | Paginated query ordered by `likedAt DESC` | +| `removeLike(accountDid, postUri)` | Delete a single entry | ## Testing @@ -132,7 +143,7 @@ Run the full suite: ```sh just test # or with failure-only reporter (recommended for large suites): -flutter test --reporter=failures-only +just test-quiet ``` Coverage target: **>99%** (±5% acceptable). All new code must have tests. Widget tests use `NativeDatabase.memory()` for Drift and mocktail for API mocks. diff --git a/README.md b/README.md index c12c8b4..5d3ce24 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ flowchart LR ``` For development setup, tooling, database schema, and contribution notes, see [DEVELOPMENT.md](DEVELOPMENT.md). +If you run tests locally on macOS or Linux, run `just objectbox-setup` once +to install the pinned ObjectBox native runtime. ## References diff --git a/justfile b/justfile index 5167795..38e0283 100644 --- a/justfile +++ b/justfile @@ -11,12 +11,22 @@ alias fmt := format lint: flutter analyze +# Install pinned ObjectBox runtime library for local development +objectbox-setup: + bash scripts/objectbox_runtime.sh install + +# Verify ObjectBox runtime library is present (fails fast if missing) +objectbox-check: + bash scripts/objectbox_runtime.sh check + # Test with failures only to focus on failures and hanging tests test-quiet *paths='': + just objectbox-check flutter test {{ paths }} --reporter=failures-only --fail-fast --timeout=120s # Run all tests test *paths='': + just objectbox-check flutter test {{ paths }} --fail-fast --timeout=120s generate: diff --git a/scripts/objectbox_runtime.sh b/scripts/objectbox_runtime.sh new file mode 100755 index 0000000..dcc5c8f --- /dev/null +++ b/scripts/objectbox_runtime.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +set -euo pipefail + +readonly OBJECTBOX_DART_COMMIT="5c96e04" +readonly INSTALL_URL="https://raw.githubusercontent.com/objectbox/objectbox-dart/${OBJECTBOX_DART_COMMIT}/install.sh" +readonly SCRIPT_NAME="$(basename "$0")" + +usage() { + cat <<'EOF' +Usage: + scripts/objectbox_runtime.sh check + scripts/objectbox_runtime.sh install + +Commands: + check Verify the ObjectBox native runtime library exists for this platform. + install Install ObjectBox native runtime from a pinned upstream revision, + then run check. +EOF +} + +platform_label() { + case "$(uname -s)" in + Darwin) echo "macos" ;; + Linux) echo "linux" ;; + *) echo "unsupported" ;; + esac +} + +expected_libs() { + case "$(platform_label)" in + macos) + printf '%s\n' "lib/libobjectbox.dylib" + ;; + linux) + printf '%s\n' \ + "lib/libobjectbox.so" \ + "lib/libobjectbox-arm.so" \ + "lib/libobjectbox-arm64.so" + ;; + *) + return 1 + ;; + esac +} + +check_runtime() { + local platform + platform="$(platform_label)" + + if [[ "${platform}" == "unsupported" ]]; then + echo "Unsupported platform: $(uname -s). Supported local platforms: macOS and Linux." + return 2 + fi + + local found=1 + while IFS= read -r lib_path; do + if [[ -f "${lib_path}" ]]; then + found=0 + break + fi + done < <(expected_libs) + + if [[ "${found}" -ne 0 ]]; then + cat <