Add comprehensive bats test suite (103 tests across 6 modules)#1
Conversation
Agent-Logs-Url: https://github.com/Rahspide/box-en_ru/sessions/1a15cbc6-3c28-4093-a2ac-b452b2f12627 Co-authored-by: Rahspide <78867445+Rahspide@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Rahspide/box-en_ru/sessions/1a15cbc6-3c28-4093-a2ac-b452b2f12627 Co-authored-by: Rahspide <78867445+Rahspide@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds an initial automated test/CI foundation for the project’s shell scripts using a new Bats test suite and a GitHub Actions workflow to run it on every push/PR.
Changes:
- Introduces 6 new Bats test modules covering core script utilities (iptables helpers, URL masking, logging, UID resolution, WiFi filtering, net.inotify helpers).
- Adds shared test helpers to mock/patch
settings.inisourcing and provide a minimal runtime environment. - Adds a GitHub Actions workflow to install
bats/busyboxand execute the test suite in CI.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_ctr_utils.bats |
Tests WiFi/SSID/BSSID list matching + should_enable_service() behavior. |
tests/test_log.bats |
Tests log() formatting and non-TTY file output behavior. |
tests/test_mask_url.bats |
Tests mask_url() redaction behavior from box.tool. |
tests/test_net_inotify.bats |
Tests with_lock_or_skip() and iptables helper behaviors as defined in net.inotify. |
tests/test_box_iptables.bats |
Tests iptables helper functions from box.iptables using executable mocks. |
tests/test_find_packages_uid.bats |
Tests find_packages_uid() parsing, multi-user UID shifting, GID merge, dedup/sort. |
tests/helpers/common.bash |
Provides shared mock env + script patching to redirect settings.ini and normalize CRLF. |
.github/workflows/test.yml |
Adds CI job running the Bats suite on ubuntu-latest. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @test "is_bssid_in_list: регистр игнорируется (верхний регистр)" { | ||
| wifi_bssids_list=("AA:BB:CC:DD:EE:FF") | ||
| run is_bssid_in_list "AA:BB:CC:DD:EE:FF" | ||
| [ "$status" -eq 0 ] | ||
| } |
There was a problem hiding this comment.
Test name says BSSID matching is case-insensitive ("регистр игнорируется"), but the test only checks an exact uppercase match and is_bssid_in_list in ctr.utils is case-sensitive ([ "$bssid" = "$item" ]). Rename the test to reflect what it actually verifies, or add a mixed-case assertion if case-insensitive behavior is intended.
Agent-Logs-Url: https://github.com/Rahspide/box-en_ru/sessions/38560240-a883-44c9-93cd-0f435495c995 Co-authored-by: Rahspide <78867445+Rahspide@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @test "log: вывод имеет правильный формат HH:MM [Level]: message" { | ||
| run log Info "проверка формата" | ||
| [[ "$output" =~ ^[0-9]{2}:[0-9]{2}\ \[Info\]:\ проверка\ формата$ ]] | ||
| } |
There was a problem hiding this comment.
В тесте ожидается, что сообщение будет выведено в кавычках ("проверка формата"), но функция log() в box/settings.ini формирует строку как ${current_time} [$1]: $2 без добавления кавычек. Из-за этого матч по regex здесь будет стабильно падать. Предложение: убрать кавычки из ожидаемого паттерна либо заменить проверку на более точное соответствие реальному формату (без кавычек).
| @test "is_bssid_in_list: регистр игнорируется (верхний регистр)" { | ||
| wifi_bssids_list=("AA:BB:CC:DD:EE:FF") | ||
| run is_bssid_in_list "AA:BB:CC:DD:EE:FF" | ||
| [ "$status" -eq 0 ] | ||
| } |
There was a problem hiding this comment.
Название теста утверждает, что регистр BSSID игнорируется, но реализация is_bssid_in_list() в box/scripts/ctr.utils сравнивает строки напрямую ([ "$bssid" = "$item" ]), т.е. проверка регистронезависимости не выполняется. Сейчас тест лишь проверяет совпадение одинаковых строк в верхнем регистре. Предложение: либо переименовать тест (если регистр должен быть важен), либо изменить тест/настройки, чтобы реально проверять регистронезависимое сравнение (например, список в одном регистре, вход в другом) и при необходимости обновить реализацию.
net.inotify: условие||вrules_addмаскирует частичный сбой iptables||→&&в логирующем условии