Files
goclaw/internal/skills/runtime_detection_test.go
Duy /zuey/andGitHub 425cecb9a3 feat(packages): Phase 2b — apk update flow + pkg-helper v2 protocol (#900) (#7)
* feat(packages): add apk update flow + pkg-helper v2 protocol

- APK update checker/executor via helper IPC (runtime detection, upgrade scan via apk list --upgradable)
- BREAKING: pkg-helper v2 protocol (5 actions: check_apk/check_pip/check_npm/exec_apk/exec_pip, code/data fields, renewable 10min deadline, apkMutex, 1MB scanner)
- Edition gating: SupportsApk + IsAlpineRuntime double-gate (Standard/Full only)
- Backend 3-branch wiring: alpine/apt/yum routes + update_registry, dep_installer helpers
- i18n: 5 apk keys (EN/VI/ZH catalogs)
- Frontend: source pill Alpine badge, APK in updates-list/summary-bar/update-all modal
- E2E tests: apk_e2e build tag covering checker/executor/helper protocol
- Docs: packages-apk.md, security/changelog updates
- Plans + reports under plans/260417-1500-packages-update-phase2b-apk-pkghelper/ + plans/reports/

* docs(packages): journal Phase 2b apk + pkg-helper v2
2026-05-11 15:41:27 +07:00

51 lines
1.7 KiB
Go

package skills
import (
"testing"
)
// TestIsAlpineRuntime_NoPanic verifies the function executes without panic
// and returns a consistent cached result on repeated calls.
// The actual boolean value is environment-dependent (true on Alpine CI,
// false on macOS/Debian dev hosts) — we verify determinism, not the value.
func TestIsAlpineRuntime_NoPanic(t *testing.T) {
first := IsAlpineRuntime()
second := IsAlpineRuntime()
if first != second {
t.Errorf("IsAlpineRuntime() returned different values on consecutive calls: %v then %v (must be cached)", first, second)
}
}
// TestOverrideAlpineRuntime_ForcesTrue verifies the test-only override hook
// correctly forces IsAlpineRuntime to return true.
func TestOverrideAlpineRuntime_ForcesTrue(t *testing.T) {
overrideAlpineRuntime(true)
if !IsAlpineRuntime() {
t.Error("overrideAlpineRuntime(true): IsAlpineRuntime() returned false, want true")
}
}
// TestOverrideAlpineRuntime_ForcesFalse verifies the test-only override hook
// correctly forces IsAlpineRuntime to return false.
func TestOverrideAlpineRuntime_ForcesFalse(t *testing.T) {
overrideAlpineRuntime(false)
if IsAlpineRuntime() {
t.Error("overrideAlpineRuntime(false): IsAlpineRuntime() returned true, want false")
}
}
// TestOverrideAlpineRuntime_Idempotent verifies that calling the override
// twice gives the last value and the result stays stable.
func TestOverrideAlpineRuntime_Idempotent(t *testing.T) {
overrideAlpineRuntime(true)
overrideAlpineRuntime(false)
if IsAlpineRuntime() {
t.Error("second overrideAlpineRuntime(false) should win: IsAlpineRuntime() returned true")
}
// A second read must be consistent.
if IsAlpineRuntime() {
t.Error("IsAlpineRuntime() not stable after override — cache broken")
}
}