Fix: Prevent AuthManager state pollution on connection verification (#348)

* Fix: Prevent AuthManager state pollution on connection verification

Modified `ConnectViewModel.connect()` to construct a temporary OkHttpClient and Retrofit builder, isolated from the global `ApiClient` state. The connection verification is executed using this temporary service. Only upon a successful HTTP response does the system persist the configured `host`, `port`, and `token` to the global `AuthManager` and triggers an `ApiClient.rebuild()`. This resolves the issue where a failed connection attempt would overwrite active and verified profiles. Extracted `createTempService` factory to `ApiClient` for robustness and clean tests.

Fixes #260

* Fix: Prevent AuthManager state pollution on connection verification

Modified `ConnectViewModel.connect()` to construct a temporary OkHttpClient and Retrofit builder, isolated from the global `ApiClient` state. The connection verification is executed using this temporary service. Only upon a successful HTTP response does the system persist the configured `host`, `port`, and `token` to the global `AuthManager` and triggers an `ApiClient.rebuild()`. This resolves the issue where a failed connection attempt would overwrite active and verified profiles. Extracted `createTempService` factory to `ApiClient` for robustness and clean tests.

Fixes #260

---------

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-06-23 20:49:58 +03:00
1 parent c21e3e9ed0
commit 2c6e437a5b
42 files changed
+296 -667

No files matched your search

+4 -38
View File
@@ -191,40 +191,7 @@ jobs:
retention-days: 7
# ─────────────────────────────────────────────────────────────────────
# Job 5: Release Compile — verifies release variant compiles.
# Catches issues like debugImplementation-scoped dependencies that
# main source code depends on (e.g. okhttp3.logging.HttpLoggingInterceptor).
# debug-only CI jobs (ktlint, lint, tests) won't catch these.
# ─────────────────────────────────────────────────────────────────────
release-compile:
name: Release Compile Check
needs: [ktlint, android-lint, unit-tests]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '17'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6
with:
validate-wrappers: true
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTED_KEY }}
- name: Grant Execute Permission for Gradlew
run: chmod +x gradlew
- name: Compile release Kotlin
run: ./gradlew compileReleaseKotlin
# ─────────────────────────────────────────────────────────────────────
# Job 6: Instrumented tests — runs on Android emulator.
# Job 5: Instrumented tests — runs on Android emulator.
# Required for Compose UI tests (TEST-09, TEST-14) and Navigation3 tests
# that need a real Activity lifecycle. Cannot run on JVM.
# ─────────────────────────────────────────────────────────────────────
@@ -289,11 +256,11 @@ jobs:
retention-days: 7
# ─────────────────────────────────────────────────────────────────────
# Job 7: PR status summary — aggregates all checks.
# Job 6: PR status summary — aggregates all checks.
# ─────────────────────────────────────────────────────────────────────
ci-summary:
name: CI Summary
needs: [ktlint, android-lint, unit-tests, build, release-compile]
needs: [ktlint, android-lint, unit-tests, build]
runs-on: ubuntu-latest
timeout-minutes: 2
if: always()
@@ -304,10 +271,9 @@ jobs:
LINT_RESULT: ${{ needs.android-lint.result }}
TEST_RESULT: ${{ needs.unit-tests.result }}
BUILD_RESULT: ${{ needs.build.result }}
RELEASE_COMPILE_RESULT: ${{ needs.release-compile.result }}
run: |
FAILED=0
for entry in "ktlint:$KTLINT_RESULT" "android-lint:$LINT_RESULT" "unit-tests:$TEST_RESULT" "build:$BUILD_RESULT" "release-compile:$RELEASE_COMPILE_RESULT"; do
for entry in "ktlint:$KTLINT_RESULT" "android-lint:$LINT_RESULT" "unit-tests:$TEST_RESULT" "build:$BUILD_RESULT"; do
name="${entry%%:*}"
result="${entry#*:}"
echo "::notice::$name = $result"