Skip to content

Add comprehensive bats test suite (103 tests across 6 modules)#1

Merged
Rahspide merged 4 commits into
translate/enfrom
copilot/analyze-test-coverage
Apr 20, 2026
Merged

Add comprehensive bats test suite (103 tests across 6 modules)#1
Rahspide merged 4 commits into
translate/enfrom
copilot/analyze-test-coverage

Conversation

Copilot AI commented Apr 20, 2026

Copy link
Copy Markdown
  • Найден баг в net.inotify: условие || в rules_add маскирует частичный сбой iptables
  • Исправлено: ||&& в логирующем условии
  • Написан тест, подтверждающий исправление (все 104 теста проходят)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ini sourcing and provide a minimal runtime environment.
  • Adds a GitHub Actions workflow to install bats/busybox and 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.

Comment thread tests/test_log.bats Outdated
Comment thread tests/test_ctr_utils.bats
Comment on lines +103 to +107
@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 ]
}

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Comment thread tests/test_box_iptables.bats Outdated
@Rahspide

Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/test_log.bats
Comment on lines +54 to +57
@test "log: вывод имеет правильный формат HH:MM [Level]: message" {
run log Info "проверка формата"
[[ "$output" =~ ^[0-9]{2}:[0-9]{2}\ \[Info\]:\ проверка\ формата$ ]]
}

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В тесте ожидается, что сообщение будет выведено в кавычках ("проверка формата"), но функция log() в box/settings.ini формирует строку как ${current_time} [$1]: $2 без добавления кавычек. Из-за этого матч по regex здесь будет стабильно падать. Предложение: убрать кавычки из ожидаемого паттерна либо заменить проверку на более точное соответствие реальному формату (без кавычек).

Copilot uses AI. Check for mistakes.
Comment thread tests/test_ctr_utils.bats
Comment on lines +103 to +107
@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 ]
}

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Название теста утверждает, что регистр BSSID игнорируется, но реализация is_bssid_in_list() в box/scripts/ctr.utils сравнивает строки напрямую ([ "$bssid" = "$item" ]), т.е. проверка регистронезависимости не выполняется. Сейчас тест лишь проверяет совпадение одинаковых строк в верхнем регистре. Предложение: либо переименовать тест (если регистр должен быть важен), либо изменить тест/настройки, чтобы реально проверять регистронезависимое сравнение (например, список в одном регистре, вход в другом) и при необходимости обновить реализацию.

Copilot uses AI. Check for mistakes.
@Rahspide Rahspide merged commit d3b147e into translate/en Apr 20, 2026
2 checks passed
@Rahspide Rahspide deleted the copilot/analyze-test-coverage branch April 22, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants