Skip to content

Bug 2020752 - [PHABBUGZ] Improve testing of phabricator and bmo integration - #2790

Open
dklawren wants to merge 2 commits into
mozilla:masterfrom
dklawren:2020752
Open

dklawren wants to merge 2 commits into
mozilla:masterfrom
dklawren:2020752

Conversation

@dklawren

@dklawren dklawren commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Add a mocked PhabBugz test suite and seed approval-mozilla-* flag types

Summary

Adds a test suite for the Bugzilla/Phabricator integration that runs without
a Phabricator server. Every Conduit call goes to an in-process fake that
answers with the response shapes from the Conduit API docs. The tests live in
extensions/PhabBugz/t/bmo/, so CI's existing test_bmo job picks them up
and runs them against the real MySQL database. No CI changes are needed.

Also seeds the approval-mozilla-* flag types in generate_bmo_data.pl, so
set_attachment_approval_flags can be tested. This includes the common
production failure where the flag is not enabled for the bug's
product/component.

No production code is changed.

Changes

Test helpers (extensions/PhabBugz/t/bmo/lib/PhabTest/)

  • Conduit.pm: a fake Conduit server. It overrides Mojo::UserAgent::post
    and records every call. It answers from an in-memory directory of users,
    projects, revisions, repositories, policies, feed stories, transactions and
    edges, and applies *.edit calls to that directory. Tests can queue
    failures: Conduit errors, HTTP errors, non-JSON bodies, network errors and
    an invalid feed cursor. A call to a method the fake doesn't handle fails the
    test.
  • Fixtures.pm: builders for complete Conduit objects.
  • Env.pm: per-file setup and teardown for the shared database. It creates
    fixtures with unique names, restores the phabbugz cursors, deactivates
    test groups, and only ever sets PhabBugz params in memory.

Tests (13 files)

  • conduit-request.t: how request() encodes calls, and how it handles
    missing config, HTTP 4xx/5xx, bad or truncated JSON, Conduit errors (with
    and without no_die), network failures and a missing result.
  • model-{user,project,policy,revision,repository-comment}.t: lookups,
    paging, lazy builders, the exact transactions each mutator sends, privacy
    helpers, and errors from Phabricator. model-user.t also covers syncing a
    disabled BMO account to Phabricator.
  • util.t: bug role PHIDs, revision attachments, auto-assignment, reviewer
    rotation and intermittent reviewers.
  • webservice.t: bug_revisions, user and the phab-bot permission checks.
  • approval-flags.t:
    • ? on new revisions, + only from release managers, X handling
    • legacy repo name mapping, disabled flags, unknown repos
    • the flag not enabled for the bug's product or component, both called
      directly and through the feed
  • feed-stories.t, feed-users.t, feed-groups.t: the daemon's periodic
    loops, covering:
    • cursor handling and paging
    • skipped stories
    • public, private and invalid bugs
    • uplift forms
    • new-user subscriptions and username-squatter alerts
    • group project sync
    • rollback and failure handling, including invalid-cursor retries
  • feed-run-query.t: the daemon wrapper logs errors, clears the watchdog
    alarm and keeps running.

Seed data (scripts/generate_bmo_data.pl)

  • approval-mozilla-{beta,release,esr140}: enabled only for
    Firefox :: General, so bugzilla.mozilla.org and Firefox :: Installer
    reproduce the "flag not enabled" case.
  • approval-mozilla-esr115: seeded but disabled (is_active = 0).
  • The insert loop takes an optional is_active, defaulting to 1. The existing
    flag types are unchanged.

Issues found (left as TODO tests, not fixed here)

  1. One failing story stalls the feed for good. feed_query has no
    per-story error handling, so the cursor never moves past the failing story.
    The most likely trigger is an approval flag that isn't enabled for the
    bug's product/component: set_flags throws invalid_flag_association and
    the whole story is rolled back.
  2. Project::update never sends the join policy.
  3. Group sync only re-applies project policies when membership changes.
  4. revision/comments.html.tmpl doesn't load terms. The
    invalid-bug comment posted to Phabricator reads "invalid ID", with the
    word "bug" missing.

Also noted, but tested as current behavior rather than as TODOs:

  • Policy->create([]) sends a fallback rule without a rule key.
  • A new revision in needs-revision creates an approval - flag without a
    release manager check.

Testing

docker compose -f docker-compose.test.yml down
docker compose -f docker-compose.test.yml run -e CI=1 bmo.test test_bmo t/bmo/*.t extensions/*/t/bmo/*.t
  • test_bmo: 40 files, 1,786 tests pass. The PhabBugz suite was also run
    twice in one database session to check that it cleans up after itself.
  • test_webservices: 45 files, 3,907 tests pass with the new seed data.
  • test_sanity: the critic, goodperl and whitespace checks pass.
  • Selenium tests: not run.

🤖 Generated with Claude Code

@dklawren
dklawren requested review from Xzzz and cgsheeh and a balanced review from Copilot October 18, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Fixture ID collisions and unrealistic attachment responses undermine test isolation and integration coverage.

2 open issues
What changed in this PR

Expands PhabBugz integration testing against BMO using an in-process fake Phabricator Conduit service.

Changes:

  • Adds reusable fixtures, request simulation and test-environment helpers.
  • Covers models, synchronization, permissions, approval flags and failure handling.
  • Seeds product-scoped and disabled uplift approval flags.
File Description
scripts/​generate_bmo_data.pl Seeds uplift approval flag types.
extensions/​PhabBugz/​t/​bmo/​webservice.t Tests endpoints and permissions.
extensions/​PhabBugz/​t/​bmo/​util.t Tests attachments and reviewer helpers.
extensions/​PhabBugz/​t/​bmo/​model-user.t Tests account lookup and synchronization.
extensions/​PhabBugz/​t/​bmo/​model-revision.t Tests revision models and privacy helpers.
extensions/​PhabBugz/​t/​bmo/​model-repository-comment.t Tests repository and comment models.
extensions/​PhabBugz/​t/​bmo/​model-project.t Tests project lookup and updates.
extensions/​PhabBugz/​t/​bmo/​model-policy.t Tests custom policy handling.
extensions/​PhabBugz/​t/​bmo/​lib/​PhabTest/​Fixtures.pm Builds Conduit fixtures.
extensions/​PhabBugz/​t/​bmo/​lib/​PhabTest/​Env.pm Provides setup and teardown helpers.
extensions/​PhabBugz/​t/​bmo/​lib/​PhabTest/​Conduit.pm Simulates and records Conduit requests.
extensions/​PhabBugz/​t/​bmo/​feed-users.t Tests new-user synchronization.
extensions/​PhabBugz/​t/​bmo/​feed-stories.t Tests revision synchronization and failures.
extensions/​PhabBugz/​t/​bmo/​feed-run-query.t Tests daemon error handling and cleanup.
extensions/​PhabBugz/​t/​bmo/​feed-groups.t Tests group membership synchronization.
extensions/​PhabBugz/​t/​bmo/​conduit-request.t Tests transport encoding and errors.
extensions/​PhabBugz/​t/​bmo/​approval-flags.t Tests uplift approval flag behavior.

Review effort: Balanced

Comment thread extensions/PhabBugz/t/bmo/lib/PhabTest/Conduit.pm Outdated
Comment thread extensions/PhabBugz/t/bmo/lib/PhabTest/Fixtures.pm Outdated

This branch has not been deployed

No deployments
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.

2 participants