Various AI inspired code changes (And MOAR TESTS) - #2015
Conversation
1af69c7 to
74ca192
Compare
This is wrong. https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_size |
yubiuser
left a comment
There was a problem hiding this comment.
Replace eval with bash array in build.sh — the previous approach built a command string and passed it to eval, which is vulnerable to shell injection if branch names or fork names contain metacharacters.
This is certainly correct, but what is the attack vector here? Someone tricking themselves into a shell injection?
e541815 to
b69a091
Compare
|
(Note: this PR was largely written by Claude — responding here on its behalf) Fair point on both counts. The editorconfig change has already been dropped — that was simply incorrect on my part. On the |
|
I think we could improve the overall test logic and readability. Currently, we have 3 "default" container (setup in |
Previously a malformed or unreadable crontab would silently fail, leaving gravity updates and the update checker permanently disabled with no indication in the logs. Now logs a clear error message. Signed-off-by: Adam Warner <me@adamwarner.co.uk> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add CONTAINER_PACKAGES shared container (ADDITIONAL_PACKAGES=wget) and a test that verifies the package is installed and on PATH - Add inline container test for TAIL_FTL_LOG=true, verifying that FTL log lines tagged [FTL] appear in docker logs output Signed-off-by: Adam Warner <me@adamwarner.co.uk> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Building a command string and calling eval is harder to reason about and requires careful manual quoting. Replacing with a bash array makes each argument explicit and removes the fragile string substitution previously used to toggle --no-cache and update the tag value. Signed-off-by: Adam Warner <me@adamwarner.co.uk> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b69a091 to
1f356d2
Compare
Container creation, waiting, and teardown previously lived in run.sh and were passed to test_suite.bats via exported environment variables. This scattered container lifecycle between two files and required custom inline logic for tests that needed their own container. Replace test_suite.bats with two focused files, each owning their container via setup_file/teardown_file: - test_default.bats: plain container; covers FTL binary, cron, password generation, and graceful shutdown (run last, sequentially) - test_env_vars.bats: custom UID/GID, FTLCONF_ vars, ADDITIONAL_PACKAGES, and TAIL_FTL_LOG=0 all exercised in a single container Extract start_container and wait_for_log into test/helpers.sh, which each .bats file loads directly. run.sh now only builds the image, installs BATS, and invokes the test files. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Adam Warner <me@adamwarner.co.uk>
|
@yubiuser - see latest commit, I actually pared it down quite a lot from what it was originally suggesting - it wanting 7 different BATS files with various container scenarios. These two container scenarios cover all use cases we have in the tests currently and there is no need to start a fresh container for every single test. Does that make it easier to follow? |
Add tests for areas of container behaviour not previously exercised: - crond is running (not just that the crontab file is valid) - Logrotate config is installed at /etc/pihole/logrotate - Default DNS upstreams (8.8.8.8/8.8.4.4) applied when none configured - Web interface accessible at /admin/ (default port and custom port) - /pihole.docker.tag build metadata file is present - macvendor.db is present and configured in FTL - FTL is running as the pihole user (validates DNSMASQ_USER default) - Capabilities are applied to pihole-FTL (validates fix_capabilities) - WEBPASSWORD_FILE reads the web password from a Docker secret Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Adam Warner <me@adamwarner.co.uk>
Summary
A handful of code quality and robustness improvements identified during a review of the codebase following the BATS test suite migration.
Log error if crontab install fails —
start_cron()was calling/usr/bin/crontabwithout checking the return code. A malformed crontab would silently fail, leaving gravity updates and the update checker permanently disabled with no indication in the logs.Expand BATS test coverage — adds two previously untested areas:
ADDITIONAL_PACKAGES: a third shared container is started withADDITIONAL_PACKAGES=wgetand a test verifies the package is installedTAIL_FTL_LOG=0: an inline container test verifies that settingTAIL_FTL_LOG=0suppresses FTL log output and emits the expected notice (the default enabled path is already exercised implicitly byCONTAINER_DEFAULT)Replace
evalwith a bash array inbuild.sh— the previous approach built a command string and calledeval, which is harder to reason about and requires careful quoting. Replacing it with a proper bash array makes argument handling explicit and removes the fragile string substitution used to toggle--no-cacheand the tag value.Test plan
ADDITIONAL_PACKAGEStest passesTAIL_FTL_LOG=0test passesBy submitting this pull request, I confirm the following:
🤖 Generated with Claude Code