Skip to content

Get the spec suite green (74 failures → 0) - #344

Open
leowilkin wants to merge 2 commits into
mainfrom
fix/spec-factories
Open

leowilkin wants to merge 2 commits into
mainfrom
fix/spec-factories

Conversation

@leowilkin

Copy link
Copy Markdown
Member

why

bundle exec rspec on main: 657 examples, 74 failures. CI only runs brakeman and rubocop, never rspec, so nobody saw them pile up. many of the failing examples are persona/verification specs, so that code had very little real coverage.

after this: 658 examples, 0 failures, stable across random-order runs. no app code changes, only specs and factories.

what was wrong

cause failures
sidebar_spec.rb reopened Components::Base and stubbed self.include and the helper macros as no-ops so it could load without rails. that leaked into the whole process: every phlex component loaded afterwards lost its includes. these specs failed only in a full run and passed on their own. ~30
the persona_verification factory's :pending / :approved / :rejected / :fatal_rejection traits built a persona record with a different inquiry id (and identity), which fails persona_record_matches_inquiry. persona_inquiry_id now follows the record. ~29
persona_lifecycle_spec: the identity's create-time before_commit leaves the in-memory record dirty, and the stubbed current_identity carried that into with_lock. the identity is now reloaded, as prod does on every request. 10
step_up_spec was written before require_pending_step_up. it now opens the step-up page first, like the real flow. 6
four one-offs: identity_spec predates the india persona flag; authorized_applications_spec counted the app name, which also appears in the revoke confirmation; persona_verification_spec expected approve! to send the approved mail, but callers send it; manual_verification_call_spec read the never-cleared enqueued_jobs list. 4

found along the way, not changed here

  • Identity#copy_legal_name_if_needed never persists anything. it's a before_commit that runs after the INSERT, so the legal names it copies only ever exist in memory. code that reads them falls back to first/last name, so nothing visibly breaks. making it actually save (before_create) would change signup data, so that's a separate decision.
  • CI should run rspec. that needs a postgres service in ci.yml. happy to add it in a follow-up once this lands.

also in this PR

4003fb9 is the CI-fix commit from #342/#343 (lint offense, brakeman 8.1.0 bump, email typo _html key), cherry-picked because main's lint and scan_ruby are red. whichever merges first, the others rebase over it.

both were already failing on main:

- rubocop: missing spaces inside the array brackets in backup_code.rb
- brakeman: bin/brakeman runs --ensure-latest, so 8.1.0 coming out
  failed every PR. bumped to 8.1.0, which raised two new warnings:
  - a weak XSS on the email typo banner. it was already escaped, but
    switching to an _html translation key lets rails do the escaping
    and drops the manual html_escape + html_safe
  - rails 8.0 EOL on 2026-11-07. ignored with a note — the 8.1
    upgrade needs its own PR before then
CI doesn't run rspec, so these piled up unnoticed. no app code changes.

- sidebar_spec reopened Components::Base to stub `self.include` and the
  helper macros as no-ops, so it could load without rails. that leaked
  into the whole process: every phlex component loaded after it lost
  its includes. ~30 unrelated specs failed only in a full run. it now
  loads rails_helper like everything else.
- persona_verification factory: the record-bearing traits built a
  persona record with a different inquiry_id (and identity), tripping
  persona_record_matches_inquiry. persona_inquiry_id now follows the
  record.
- persona_lifecycle_spec: identity's create-time before_commit leaves
  the in-memory record dirty, and the stubbed current_identity carried
  it into with_lock. reload it, as prod does per request.
- step_up_spec predates require_pending_step_up — open the step-up page
  first, as the real flow does.
- identity_spec predates the india persona rollout flag.
- authorized_applications_spec counted the app name, which also appears
  in the revoke confirmation. count cards instead.
- persona_verification_spec expected approve! to send the approved
  mail; callers send it, so assert it doesn't (a double mail otherwise).
- manual_verification_call_spec read the never-cleared enqueued_jobs
  list, picking up mail jobs from earlier examples.
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedgem/​brakeman@​8.0.6 ⏵ 8.1.075 +110010010070

View full report

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