fix(quality): resolve CodeQL unused local variables and add Python & Shell test suites - #222
Open
aghassemlouei wants to merge 6 commits into
Open
fix(quality): resolve CodeQL unused local variables and add Python & Shell test suites#222aghassemlouei wants to merge 6 commits into
aghassemlouei wants to merge 6 commits into
Conversation
…local-variable) Removes and cleans up unused local variables across tools and CLI modules flagged by CodeQL rule py/unused-local-variable: - auth.py: ignore unused project tuple element from google.auth.default - data_stores.py: remove unused response assignment in create_data_store_schema - gem4gov.py: remove unused response, engine_response, headers, and exception variables - changelog.py: remove unused exception variable in main - state_iam.py: remove unused org_ids variable in get_bindings - tfdoc.py: remove unused exception variables and unused dirnames loop variable Signed-off-by: Alijohn Ghassemlouei <aghassemlouei@users.noreply.github.com>
aghassemlouei
requested review from
Calvin-Cheng1,
mgcarey-google and
woodham1
September 6, 2026 17:24
Signed-off-by: Alijohn Ghassemlouei <aghassemlouei@google.com>
aghassemlouei
enabled auto-merge (rebase)
September 6, 2026 18:52
…dation Adds comprehensive automated testing for Python CLI/tools and shell scripts: - tests/gem4gov_cli/: unit tests for auth and data_stores (mocking discovery and auth APIs) - tests/tools/: unit tests for check_boilerplate, state_iam, and tfdoc - tests/scripts/: automated shell syntax validation (bash -n across all 27 scripts) and unit tests for common-functions.sh (env var validation, logging, backups) - tools/run_tests.sh: unified test runner executing Python unit tests, shell tests, and CodeQL unused local variable checks - .github/workflows/ci.yml: added shell-tests and python-tests jobs to CI pipeline - tools/state_iam.py: converted regex strings to raw strings to avoid SyntaxWarning Signed-off-by: Alijohn Ghassemlouei <aghassemlouei@users.noreply.github.com>
…on 3.11 compatibility - .github/workflows/ci.yml: restrict top-level workflow permissions to contents: read, scope elevated permissions (pull-requests: write, security-events: write) to the security-scan job, and set persist-credentials: false on actions/checkout to satisfy Zizmor - gem4gov.py: fix f-string quote nesting on lines 400-414 for Python 3.11 compatibility - data_stores.py, setup.py, check_names.py, check_boilerplate.py, tfdoc.py, check_documentation.py: remove unused imports and unneeded f-string prefixes flagged by pyflakes - tests/__init__.py: use dynamic importlib loading to prevent pyflakes unused import warnings Signed-off-by: Alijohn Ghassemlouei <aghassemlouei@users.noreply.github.com>
…gem4gov.py Signed-off-by: Alijohn Ghassemlouei <aghassemlouei@users.noreply.github.com>
…rison in test_auth.py Resolves CodeQL imprecise assert alert on line 25 of test_auth.py. Signed-off-by: Alijohn Ghassemlouei <aghassemlouei@users.noreply.github.com>
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.
Description
Resolves all 16 unused local variables identified across 6 Python files by GitHub CodeQL quality rule
py/unused-local-variable, and introduces comprehensive automated testing and CI validation for both Python tools/CLI and Shell scripts across the repository.CodeQL & Code Quality Remediations:
blueprints/fedramp-high/gemini-enterprise/gem4gov-cli/auth.py:projectunpacking with discard variablecredentials, _ = google.auth.default(...).blueprints/fedramp-high/gemini-enterprise/gem4gov-cli/data_stores.py:responsevariable assignment fromrequest.execute()increate_data_store_schema().blueprints/fedramp-high/gemini-enterprise/gem4gov-cli/gem4gov.py:credentialsassignment ininit().responsevariable assignments from API calls inconfigure_identity_provider()andconfigure_cmek().eng_responsein engine existence check withincreate_engine().inner_eexception binding increate_engine().headersdictionaries inconfigure_idp_for_widget()anddisable_user_event_collection().engine_responseassignments inconfigure_gemini_enterprise_for_fedramp_high(),configure_gemini_enterprise_for_il4(), andconfigure_gemini_enterprise_for_il5().tools/changelog.py:as einmain().tools/state_iam.py:org_ids = {}inget_bindings().r"^service-\\d{8}",r"^bq-\\d{8}") to eliminate Python 3.12+SyntaxWarning.tools/tfdoc.py:except (IOError, OSError) as e:withexcept (IOError, OSError):inparse_outputs(),parse_recipes(), andparse_variables().dirnamesloop variable with_inos.walk(module_path).New Automated Test Suites & CI Pipeline:
tests/):tests/gem4gov_cli/test_auth.py: Testscheck_rolespermission evaluation viatestIamPermissions,get_user_emailresolution and error handling, andget_credentials.tests/gem4gov_cli/test_data_stores.py: Testsgenerate_idformat and uniqueness,parse_http_errorJSON decoding and fallbacks, andvalidate_data_storeschema validation.tests/tools/test_check_boilerplate.py: Tests Apache 2.0 license boilerplate header detection and exclusions.tests/tools/test_state_iam.py: Tests organization alias mapping and IAM binding resource extraction.tests/tools/test_tfdoc.py: Tests regex pattern matching (COUNT_TEST_RE,TAG_RE) and HCL parsing.tests/scripts/):tests/scripts/test_shell_syntax.sh: Automated syntax validation (bash -n) across all 27 shell scripts in the repository.tests/scripts/test_common_functions.sh: Unit tests forscripts/common-functions.shverifyingvalidate_env_vars, logging tags/formatting (log_info,log_warn,log_error,log_debug), andbackup_configfile operations.tests/scripts/run_shell_tests.sh: Automated shell test orchestrator.tools/run_tests.sh: Single command running Python unit tests, shell script tests, and AST/CodeQL unused local variable verification..github/workflows/ci.yml):shell-testsjob executingrun_shell_tests.sh.python-testsjob setting up Python, runningpyflakes(guaranteeing CodeQL quality compliance), and runningpytest.Fixes # N/A (CodeQL rule
py/unused-local-variable)Type of Change
Deployment & Compliance Impact
Checklist
Code Quality & Reusability
modules/orfast/can be leveraged for this change.documentation/naming-convention.md.Documentation
README.mdof the modified module or blueprint. (N/A - Internal code quality and test harness addition)Security
Testing
Testing Performed
python3 -m unittest discover -s tests -t . -p "test_*.py" -v: 28 tests ran and passed (0 errors, 0 failures).bash tests/scripts/run_shell_tests.sh: 27 shell scripts passed syntax checks (bash -n), and 12 unit tests intest_common_functions.shpassed.bash tools/run_tests.sh: All 3 stages (Python unit tests, Shell test suites, AST/CodeQL compilation checks) passed with 0 errors.py/unused-local-variableVerification:pyflakesand custom AST symbol visitor: 0 unused local variables remaining.