Skip to content

DM-54689: Test private-API hygiene — public secrets setter on ContextDependency; tests/support/arq_testing.py count_jobs_by_name helper #269

@jonathansick

Description

@jonathansick

Metadata

Field Value
Parent PRD #232
Jira Key DM-54689
Jira URL https://rubinobs.atlassian.net/browse/DM-54689
Task Order 24
Type AFK
Blocked by None
Parallel with #266, #267, #268
Branch tickets/DM-54689-github-webhook

Origin

Review of PR #264

What to build

Two test-infrastructure improvements that remove direct private-attr access from the webhook test suite (and adjacent tests):

  1. Public secrets setter on ContextDependency. The github_app_enabled fixture in tests/handlers/webhooks_github_test.py (lines 52-80) currently saves and pokes _github_app_id, _github_app_private_key, and _github_webhook_secret directly on the context_dependency singleton. Add a public method (e.g. set_github_secrets(app_id, private_key, webhook_secret)) on ContextDependency and have the fixture use it.

    Out of scope for this issue: tests/conftest.py:119-125 also pokes _superadmin_usernames and _user_info_store directly. That is a parallel piece of test-infrastructure hygiene; flag it for a separate follow-up rather than expanding scope here.

  2. tests/support/arq_testing.py helper. Tests currently access arq_dependency._arq_queue and arq_queue._job_metadata directly to count dashboard_sync jobs. Centralize via a helper so private-API access lives in one place.

    Known direct-access sites to migrate:

    • tests/handlers/webhooks_github_test.py:42-49 (_count_dashboard_sync_jobs).
    • tests/storage/queue_backend_test.py:29-36.
    • tests/worker/build_processing_test.py:468-472.

Approach sketch

  • ContextDependency.set_github_secrets(app_id: int | None, private_key: SecretStr | None, webhook_secret: SecretStr | None) -> None — synchronous, scoped to the three GitHub-App fields. The existing async initialize is broader and not appropriate for narrow test fixture use. Document intent in the docstring.
  • New file tests/support/arq_testing.py exporting:
    • count_jobs_by_name(arq_queue: MockArqQueue, name: str, queue_name: str | None = None) -> int
    • get_jobs_by_name(arq_queue: MockArqQueue, name: str, queue_name: str | None = None) -> list[JobMetadata] (if useful for debug assertions)
  • Migrate the three known call sites in this issue.

Acceptance criteria

  • ContextDependency.set_github_secrets(...) exists and is documented.
  • github_app_enabled fixture uses set_github_secrets rather than direct private-attr assignment for the three GitHub App secrets.
  • tests/support/arq_testing.py exists and exports count_jobs_by_name (plus get_jobs_by_name if added).
  • All three known direct-access sites use the helper. grep -R "_job_metadata" tests/ returns matches only inside tests/support/arq_testing.py.
  • Full test suite passes (TC_HOST=localhost TESTCONTAINERS_RYUK_DISABLED=true uv run --only-group=nox nox -s test).

Metadata

Metadata

Assignees

No one assigned

    Labels

    prd-taskImplementation task from a PRD

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions