test: Add unit test coverage for hardware_detect utility

Đang mở Phù hợp với người mới
#1,786 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
79/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

Đọc backend/app/utils/hardware_detect.py và làm theo các mẫu kiểm thử hiện có trong backend/tests. Thêm backend/tests/test_hardware_detect.py với các lệnh gọi hệ thống được mô phỏng để kiểm thử năm hàm công khai được nêu tên và các trường hợp biên đã liệt kê. Chạy tệp kiểm thử mới; hoàn tất khi các kiểm thử chạy thành công trên những đường dẫn phát hiện được chỉ định mà không cần phần cứng vật lý.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement

What's missing

backend/app/utils/hardware_detect.py has zero test coverage right now. This module is responsible for figuring out what hardware a user's machine has (GPU, Apple Silicon, RAM) and recommending the right AI model tier (nano / small / medium). It's a pretty critical piece — if something breaks here, users silently end up with the wrong model for their hardware.

What I'd like to add

A test file backend/tests/test_hardware_detect.py covering all 5 public functions:

  • detect_physical_gpu() — nvidia-smi not found, single/multiple GPU parsing, error handling (OSError, timeout), blank-line stripping
  • detect_apple_silicon() — non-Mac returns None, non-arm64 returns None, sysctl happy path, sysctl failure fallback chain (processor → generic string)
  • detect_apple_silicon_tier() — base M1/M2 → small, Pro/Max/Ultra/M3+ → medium, non-Apple → None
  • detect_hardware_tier() — Apple Silicon path, GPU-present path, RAM-based tiers, boundary values at exactly 4 GB and 8 GB
  • get_hardware_info() — returned dict has the right keys and values, gpu_detected flag correctness

All system calls (shutil.which, subprocess.run, platform.*, psutil.virtual_memory, ort.get_available_providers) will be mocked so the tests run on any machine without needing actual hardware.

Why it matters

This module quietly drives model selection for the whole app. Having tests here means we catch regressions early — especially around edge cases like timeouts, missing tools, or future chip names.


I'd like to work on this — I've already explored the module and have a good idea of what the test cases should look like. Happy to put up a PR!

Ngôn ngữ chính
Python
Star
322
Fork
793
Merge trung bình
6 ngày 11 giờ
Pull request đã merge (30 ngày)
21

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AOSSIE-Org/PictoPy

Tất cả issue của AOSSIE-Org/PictoPy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.