Skip to content

fix(test): pin 000086 migration test to version 86, not HEAD - #1436

Merged
cristim merged 1 commit into
mainfrom
fix/migration-test-pin-version
Jul 17, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/migration-test-pin-version

Conversation

@cristim

@cristim cristim commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Summary

TestMigration_RemoveApproveOwnFromStandardUsers (added by PR #1422) was failing on the Integration Tests job of PR #808 (fix/292-wave4, migration 000087) and PR #1428 (fix/qa-nonadmin-settings-rbac, migration 000088).

Root cause: real cross-migration interaction, not a flake.

The test has two sub-tests:

  1. "approve-own removed, sibling own-verbs retained" - migrated from 83 to HEAD, then asserted specific permissions. Passes on both branches (087 and 088 don't touch purchases permissions), but is fragile.

  2. "down migration restores approve-own" - called RunMigrations (migrates to HEAD), then RollbackMigrations(1). On a branch where HEAD=087, this rolls back 087.down (marketplace) -- not 000086.down -- leaving approve-own absent and failing the assertion. Same on HEAD=088. Deterministic failure on both branches.

Fix: Replace both RunMigrations calls with MigrateToVersion(ctx, pool, migrationsPath, 86) so each sub-test is pinned to exactly the migration it covers. This is the same pattern already used correctly in 000088_grant_view_config_to_nonadmin_groups_test.go (which pins to 86 before testing 088).

Verification

go test -tags=integration -run TestMigration_RemoveApproveOwnFromStandardUsers ./internal/database/postgres/migrations/ -count=3 -v
Branch context Migration latest Result
fix/migration-test-pin-version (main) 000086 9 passed
Simulated fix/292-wave4 (#808) 000087 9 passed
Simulated fix/qa-nonadmin-settings-rbac (#1428) 000088 9 passed

Static gates: go build ./... clean, go vet clean, golangci-lint no issues, gocyclo -over 10 exit 0.

Test plan

Summary by CodeRabbit

  • Tests
    • Improved migration integration test reliability by targeting migration version 000086 explicitly.
    • Added deterministic coverage confirming the removal and restoration of the approve-own:purchases permission while preserving related permissions.

TestMigration_RemoveApproveOwnFromStandardUsers failed on PR #808
(000087 marketplace) and PR #1428 (000088 view:config) because:

- Sub-test 1 called RunMigrations (to HEAD) instead of pinning to 86;
  later migrations could alter the same group's permissions.
- Sub-test 2 (down migration) called RunMigrations then
  RollbackMigrations(1), which rolls back the LATEST migration rather
  than 000086.down. On a branch where HEAD=087, the rollback runs
  087.down (marketplace), leaving approve-own absent and failing the
  assertion.

Fix: replace both RunMigrations calls with MigrateToVersion(86) so the
test is isolated to exactly the migration it covers, regardless of how
many migrations land on downstream branches. This is the same pattern
already used correctly in 000088_grant_view_config_to_nonadmin_groups_test.go.

Verified: go test -tags=integration -count=3 passes on the fix branch
(latest=086), a worktree simulating HEAD=087, and a worktree simulating
HEAD=088.

Closes the cross-migration interaction blocking #808 and #1428 CI.
@cristim cristim added triaged Item has been triaged priority/p1 Next up; this sprint severity/high Significant harm urgency/this-sprint Within the current sprint impact/internal Team-internal only effort/xs Trivial / one-liner type/bug Defect labels Jul 17, 2026
@cristim

cristim commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0c23879-2dfb-491a-bfce-cc98aeb2aff3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The migration integration test now pins PostgreSQL to version 000086 before checking removal and restoration of approve-own:purchases, while confirming sibling verbs remain unchanged.

Changes

Migration test determinism

Layer / File(s) Summary
Pin migration state for forward and rollback tests
internal/database/postgres/migrations/000086_remove_approve_own_from_standard_users_test.go
Both subtests target migration version 000086 directly, validating the forward permission removal and deterministic rollback restoration.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: pinning the migration test to version 86 instead of HEAD.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/migration-test-pin-version

Comment @coderabbitai help to get the list of available commands.

@cristim
cristim merged commit 7f0573d into main Jul 17, 2026
18 of 20 checks passed
@cristim
cristim deleted the fix/migration-test-pin-version branch July 17, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/internal Team-internal only priority/p1 Next up; this sprint severity/high Significant harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant