Skip to content

ci: enforce pytest as required gate on all PRs, fix pre-existing test failures#56

Merged
advaitpatel merged 1 commit into
mainfrom
ci/enforce-tests-on-pr
Apr 2, 2026
Merged

ci: enforce pytest as required gate on all PRs, fix pre-existing test failures#56
advaitpatel merged 1 commit into
mainfrom
ci/enforce-tests-on-pr

Conversation

@advaitpatel
Copy link
Copy Markdown
Collaborator

Description

Makes tests a hard requirement before any PR can merge. Previously both workflows either skipped pytest entirely or used continue-on-error: true, meaning broken tests never blocked a merge.

Workflow changes

python-app.yml

  • Added Run unit tests step: pytest tests/ -v — fails the job if any test fails
  • Removed all emojis from echo output
  • Reordered steps: tests run before CLI smoke tests so the job fails fast on unit test failures
  • Removed OPENAI_API_KEY from the pytest step (unit tests use mocks, no real key needed)

coverage.yml

  • Removed continue-on-error: true from pytest step — test failures now fail the coverage job
  • Removed emojis from step summaries

Test fixes (pre-existing failures that would have broken CI)

File Fix
docker_scanner.py _validate_file_path Check .. in raw input before Path.resolve() — resolved paths never contain .. so the traversal guard was silently bypassed
docker_scanner.py _validate_image_name Replace character blacklist with a whitelist regex — spaces and other unlisted chars are now correctly rejected
tests/test_utils.py Fix mock targets from utils.get_openai_api_key (doesn't exist) to config_manager.get_config which is what get_llm() actually calls
tests/test_docker_scanner.py Compare resolved paths on both sides to handle macOS /var/private/var symlink
tests/test_integration.py Same resolved-path fix

Test results

16 passed, 1 failed (local only)

The 1 remaining local failure (test_get_openai_api_key_missing) is environment-specific — triggered by a real OPENAI_API_KEY in the developer's shell. Passes in CI where no key is injected into the pytest step.

After merging — enable branch protection

To fully enforce this, go to:
GitHub → Settings → Branches → Add rule → Branch name: main

Check:

  • Require status checks to pass before merging
  • Required checks: build-and-test (from python-app.yml)
  • Require branches to be up to date before merging

This makes it impossible to merge a PR with failing tests.

Type of Change

  • Build / CI configuration
  • Bug fix (path traversal check, image name validation)

…st failures

Workflows:
- python-app.yml: add 'Run unit tests' step (pytest tests/ -v) that fails the
  job on any test failure; remove emojis from echo output; reorder steps so
  tests run before CLI smoke tests
- coverage.yml: remove continue-on-error: true from pytest step so test
  failures now fail the coverage job; remove emojis from step summaries

Test fixes (pre-existing failures that would have blocked CI):
- docker_scanner.py _validate_file_path: check '..' in raw input string
  before Path.resolve() — resolved paths never contain '..' so the traversal
  guard was silently bypassed on Linux
- docker_scanner.py _validate_image_name: replace blacklist with a whitelist
  regex so spaces and other unlisted characters are rejected
- tests/test_utils.py: fix mock targets from 'utils.get_openai_api_key'
  (does not exist) to 'config_manager.get_config' which is what get_llm()
  actually calls
- tests/test_docker_scanner.py: compare resolved paths on both sides to
  handle macOS /var -> /private/var symlink
- tests/test_integration.py: same resolved-path fix

Result: 16/17 tests pass locally (1 remaining failure is environment-specific
— real OPENAI_API_KEY in shell env; passes in CI where no key is injected)
@advaitpatel advaitpatel merged commit af26c36 into main Apr 2, 2026
6 checks passed
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