Skip to content

End-to-end Python hook tests #7445

Description

@wbreza

End-to-End Python Hook Tests

Part of #7435 — Multi-Language Hook Support

User Story

As a developer maintaining the hook system, I want comprehensive end-to-end tests that verify the full Python hook lifecycle so regressions are caught automatically.

Solution Approach

Test scenario 1 — Happy path:

  1. Create test project with:
    • azure.yaml with preprovision Python hook
    • scripts/setup.py that reads an env var and writes it to a marker file
    • scripts/requirements.txt with a simple dependency
  2. Verify:
    • Hook detected as Python language hook
    • Virtual environment created (.venv exists)
    • Dependencies installed
    • Script executes successfully
    • Environment variables available to script
    • Exit code 0

Test scenario 2 — Auto-detect vs explicit:

  • Test with run: scripts/setup.py (auto-detect from .py)
  • Test with run: scripts/setup + language: python (explicit)
  • Both should execute identically

Test scenario 3 — Error cases:

  • Missing Python runtime → clear error with install URL
  • Missing script file → clear error
  • Script exits non-zero → error propagated
  • continueOnError: true + failing script → no error, continues

Test scenario 4 — Service-level hooks:

  • Python hook defined under a service, not project root
  • Verify project discovery scoped to service directory

Location: Follow existing patterns in test/functional/testdata/samples/ for fixtures, test/functional/ or pkg/ext/ for test files.

Files: test/functional/ or pkg/ext/hooks_runner_test.go (NEW/MODIFY), test fixtures

Acceptance Criteria

  • Tests pass on CI (requires Python installed in CI environment)
  • Validates complete flow: YAML → language detection → venv → install → execute → output
  • Tests both success and error paths
  • Tests environment variable passing
  • Tests both project-level and service-level hooks
  • Tests auto-detect and explicit language: field

References

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions