Skip to content

Track tests/lib/common.sh and exit add-profile-labels.py through sys.exit - #367

Merged
NormB merged 2 commits into
mainfrom
fix/tests-lib-common
Oct 15, 2026
Merged

NormB merged 2 commits into
mainfrom
fix/tests-lib-common

Conversation

@NormB

@NormB NormB commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Two small fixes, each with a test written first and seen failing.

Track tests/lib/common.sh (the .gitignore lib/ defect)

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. 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 the source line in a fresh clone.

  • .gitignore: lib/ and lib64/ are anchored to the top level (/lib/, /lib64/); the !scripts/lib/ exception is no longer needed. No directory named lib or lib64 is ignored today, so nothing else is uncovered.
  • tests/lib/common.sh is reconstructed from what the two scripts call (found by parsing both with shfmt --to-json and listing called names that are neither defined nor commands): info, success, warn, fail (same output and counter updates as tests/test-fastapi.sh), is_container_running, get_password_from_vault (KV v2 via curl; token from VAULT_TOKEN or ~/.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_results exit status, both helpers fail cleanly with no stack, and both scripts run with a stub docker and no Vault token: 12/12 negative and 10/10 performance tests report skipped, exit 0. Before the fix all 8 checks failed. 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 Validate Shell Scripts.
  • 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.

Exit add-profile-labels.py through sys.exit (CodeQL #33)

exit(main()) relied on the site module; under python3 -S it raised NameError. Now sys.exit(main()). tests/test-add-profile-labels.sh runs a copy under python3 -S in a temp tree with no docker-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-files passes every hook on this branch.

NormB added 2 commits October 15, 2026 11:22
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.
@NormB
NormB merged commit c724321 into main Oct 15, 2026
31 checks passed
@NormB
NormB deleted the fix/tests-lib-common branch October 15, 2026 15:28
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.

1 participant