Repository navigation
Track tests/lib/common.sh and exit add-profile-labels.py through sys.exit - #367
Merged
Merged
Conversation
tests/test-negative.sh and tests/test-performance.sh source tests/lib/common.sh, but the Python-template rule `lib/` in .gitignore matched every directory named lib, so the file was never committed: neither git history (`git log --all -- tests/lib`) nor the main checkout has it, and both scripts stop at the `source` line in a fresh clone. The rule is now anchored to the top level (`/lib/`, `/lib64/`), which also makes the `!scripts/lib/` exception unnecessary. No directory named lib or lib64 is ignored today, so the change uncovers nothing else. The library is written from what the two scripts call: info, success, warn and fail (the same output and counter updates as the helpers in tests/test-fastapi.sh), is_container_running, get_password_from_vault (KV v2 over curl, token from VAULT_TOKEN or ~/.config/vault/root-token, as test-performance.sh reads it), test_suite_setup, print_test_results (returns 1 when a test failed) and test_suite_teardown. tests/test-common-lib.sh checks that git does not ignore the file, that it defines the nine helpers, the counter updates and the print_test_results exit status, and runs both scripts with a stub docker and no Vault token: all 12 negative and 10 performance tests report themselves as skipped and each script exits 0. On the previous tree all 8 checks fail; reverting the .gitignore rule, the success counter, the print_test_results status or the Vault token check each fails its own check. CI runs it in the Validate Shell Scripts job. The shellcheck disable comments in the two scripts said .gitignore excluded the library; they now say which variables the library reads and which nothing reads.
The script ended with `exit(main())`. exit is added by the site module, so under `python3 -S` the last line raised NameError instead of returning main()'s status (CodeQL py/use-of-exit-or-quit, alert 33). It now imports sys and calls sys.exit(main()). tests/test-add-profile-labels.sh runs a copy of the script under `python3 -S` in a temporary tree with no docker-compose.yml, so main() returns 1 without touching any file, and requires exit status 1, the "not found" message and no NameError. Before the change it failed on the NameError. CI runs it in the Test Python Scripts job.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small fixes, each with a test written first and seen failing.
Track tests/lib/common.sh (the
.gitignorelib/defect)tests/test-negative.shandtests/test-performance.shsourcetests/lib/common.sh, but the Python-template rulelib/in.gitignorematched every directory namedlib. The file never existed in git history (git log --all -- 'tests/lib/*'is empty) and is not in the main checkout either, so both scripts stopped at thesourceline in a fresh clone..gitignore:lib/andlib64/are anchored to the top level (/lib/,/lib64/); the!scripts/lib/exception is no longer needed. No directory namedliborlib64is ignored today, so nothing else is uncovered.tests/lib/common.shis reconstructed from what the two scripts call (found by parsing both withshfmt --to-jsonand listing called names that are neither defined nor commands):info,success,warn,fail(same output and counter updates astests/test-fastapi.sh),is_container_running,get_password_from_vault(KV v2 via curl; token fromVAULT_TOKENor~/.config/vault/root-token),test_suite_setup,print_test_results(returns 1 on failures),test_suite_teardown.tests/test-common-lib.sh(8 checks): not ignored by git, all nine helpers defined, counter updates,print_test_resultsexit status, both helpers fail cleanly with no stack, and both scripts run with a stubdockerand no Vault token: 12/12 negative and 10/10 performance tests report skipped, exit 0. Before the fix all 8 checks failed. Reverting the.gitignorerule, thesuccesscounter, theprint_test_resultsstatus or the Vault token check each fails its own check. CI runs it in Validate Shell Scripts..gitignoreexcluded the library; they now say which variables the library reads and which nothing reads.Exit add-profile-labels.py through sys.exit (CodeQL #33)
exit(main())relied on the site module; underpython3 -Sit raised NameError. Nowsys.exit(main()).tests/test-add-profile-labels.shruns a copy underpython3 -Sin a temp tree with nodocker-compose.yml(main returns 1, no file touched) and failed on the NameError before the change. CI runs it in Test Python Scripts.uvx pre-commit run --all-filespasses every hook on this branch.