Skip to content

test(gem4gov-cli): accept an all-digit suffix in the generate_id test - #362

Merged
aghassemlouei merged 1 commit into
google:mainfrom
digitalresistor:test/gem4gov-generate-id-flake
Oct 26, 2026
Merged

aghassemlouei merged 1 commit into
google:mainfrom
digitalresistor:test/gem4gov-generate-id-flake

Conversation

@digitalresistor

Copy link
Copy Markdown
Contributor

Description

Stop the test_generate_id_format test in the tests/test_data_stores.py file from failing at random on unrelated pull requests.

The generate_id function in the blueprints/gemini-enterprise/gem4gov-cli/data_stores.py file picks six characters from lowercase letters and digits. The test asserted suffix.islower(), but Python's str.islower() method returns False for a string without letters, such as "482193".

  • Six random digits come up in about one run out of 2,200, and that failed the Python unit tests of fix(0-bootstrap): let the Stage 0 folders inherit the logging settings #361, which does not touch the CLI.
  • The test now checks that every suffix character belongs to the alphabet that generate_id uses.
  • A new test_generate_id_allows_an_all_digit_suffix test forces an all-digit suffix through a patched secrets.choice function, so the case runs on every build.
  • The change touches only the test file, so the CLI behavior stays the same.

No GitHub issue exists for this change.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Deployment & Compliance Impact

  • Applicable Regimes:
    • US Region Restricted (e.g., Access Policy constraint)
    • FedRAMP Moderate
    • FedRAMP High
    • DoD IL4
    • DoD IL5
    • General / All
  • NIST 800-53r5 Controls: None. The change only fixes a test.

Checklist

Code Quality & Reusability

  • My code adheres to the Maximize Reusability principle. I have not redefined common elements and have reused existing base configurations and modules where possible.
  • I have checked that no existing module or configuration in modules/ or fast/stages-aw/ can be leveraged for this change.
  • My code follows the established naming conventions outlined in docs/naming-convention.md.

Documentation

  • I have updated the README.md of the modified module or blueprint.
  • I have added/updated documentation for inputs (variables) and outputs.

Security

  • My change adheres to GCP security best practices and the principle of least privilege.
  • I have ensured compliance with the targeted regime (FedRAMP Moderate, FedRAMP High, IL4, IL5, etc.).

Testing

  • I have tested my changes locally.
  • I have included details of my testing in this PR.

Testing Performed

  • The CI run on fix(0-bootstrap): let the Stage 0 folders inherit the logging settings #361 failed on test_generate_id_format with AssertionError: False is not true at the suffix.islower() assertion.
  • With secrets.choice patched to return a digit, generate_id returns ds-777777, and the old assertion rejects that value.
  • uv run --locked pytest in the repository root passes 109 tests, including the new test.
  • ruff format --check and ruff check pass for the test file.

generate_id picks six characters from lowercase letters and digits, but
the test asserted suffix.islower(), which Python returns False for when
the suffix has no letters. About one run in 2,200 drew six digits and
failed CI on an unrelated pull request.

- Check the suffix characters against the generate_id alphabet.
- Add a deterministic test that forces an all-digit suffix.
@github-actions github-actions Bot added the Gemini - Government Gemini for Government (G4G) related label Oct 26, 2026
@aghassemlouei aghassemlouei added Bug Something isn't working Gemini - Enterprise Gemini Enterprise (GE) related Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - Low Minor polish, typo fixes, or technical debt; nice to have; pick up when time permits Scope - Blueprint Related to solution blueprints in the blueprints directory and removed Gemini - Enterprise Gemini Enterprise (GE) related labels Oct 26, 2026

@aghassemlouei aghassemlouei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified tests/test_data_stores.py via bash tools/run_tests.sh and bash tools/lint.sh:

  • Replacing suffix.isalnum() and suffix.islower() with self.assertLessEqual(set(suffix), set(string.ascii_lowercase + string.digits)) removes the 1 / 2,176 flake when secrets.choice produces an all-digit 6-character suffix.
  • test_generate_id_allows_an_all_digit_suffix deterministically covers the all-digit suffix path.

@aghassemlouei
aghassemlouei enabled auto-merge (squash) October 26, 2026 21:13
@aghassemlouei
aghassemlouei merged commit d21e899 into google:main Oct 26, 2026
16 checks passed
@aghassemlouei aghassemlouei mentioned this pull request Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Gemini - Government Gemini for Government (G4G) related Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - Low Minor polish, typo fixes, or technical debt; nice to have; pick up when time permits Scope - Blueprint Related to solution blueprints in the blueprints directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants