Skip to content

test: assert full chain has single head in hybrid test#15

Closed
jd wants to merge 1 commit intomainfrom
devs/jd/worktree-no-break-on-changes/I69504832cf0d9f6caaf0290df1f6ca0575adcd53
Closed

test: assert full chain has single head in hybrid test#15
jd wants to merge 1 commit intomainfrom
devs/jd/worktree-no-break-on-changes/I69504832cf0d9f6caaf0290df1f6ca0575adcd53

Conversation

@jd
Copy link
Member

@jd jd commented Mar 3, 2026

Extend test_dynamic_inserted_before_hybrid_no_multiple_heads to
reconstruct the complete chain (static + dynamic) using
get_down_revision for dynamic migrations and file parsing for
static ones, then verify there is exactly one head.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Copilot AI review requested due to automatic review settings March 3, 2026 17:00
@mergify mergify bot had a problem deploying to Mergify Merge Protections March 3, 2026 17:00 Failure
@mergify
Copy link

mergify bot commented Mar 3, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🔴 👀 Review Requirements

This rule is failing.
  • any of:
    • #approved-reviews-by>=1
    • author = dependabot[bot]
    • author = mergify-ci-bot

🔴 🔎 Reviews

This rule is failing.
  • #review-requested = 0
  • #review-threads-unresolved = 0
  • #changes-requested-reviews-by = 0

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=all-greens

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?:

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

@mergify mergify bot requested a review from a team March 3, 2026 17:02
@jd jd force-pushed the devs/jd/worktree-no-break-on-changes/I69504832cf0d9f6caaf0290df1f6ca0575adcd53 branch from 1c178e5 to 28c9ad5 Compare March 3, 2026 17:02
@mergify mergify bot had a problem deploying to Mergify Merge Protections March 3, 2026 17:03 Failure
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Extends the hybrid-chain regression test to reconstruct the complete migration graph (static + dynamic) and assert there is exactly one Alembic head, preventing a recurrence of “multiple heads” scenarios when dynamic migrations are inserted before a hybrid migration.

Changes:

  • Reconstructs a full {revision: down_revision} mapping by reading static down_revision from files and resolving dynamic ones via get_down_revision().
  • Adds a head computation (heads = all_revisions - pointed_to) and asserts a single expected head.
Comments suppressed due to low confidence (1)

tests/test_chain.py:480

  • The dynamic/static detection here uses a raw substring check ("get_down_revision(" in content), which can misclassify files if the string appears in a comment or import. Since the library already has _DYNAMIC_DOWN_REVISION_RE for this purpose, consider using that regex to match the same logic as production code and keep the test robust to harmless text changes.
    """get_down_revision auto-discovers versions_dir from caller's location."""
    versions_dir = tmp_path / "versions"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +469 to +474
files = _chain._parse_migration_files(versions_dir, git_order)
full = {f.revision: f.static_down_revision for f in files if not f.is_dynamic}
full.update(chain)
all_revs = set(full)
pointed_to = {v for v in full.values() if v is not None}
heads = all_revs - pointed_to
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

build_chain is a functools.cache and this test clears it before the patch, but doesn’t clear it afterward. For better test isolation (and to avoid leaving cached entries behind when this assertion fails), wrap this block in a try/finally that calls build_chain.cache_clear() in the finally (similar to nearby tests).

Copilot uses AI. Check for mistakes.
@jd jd force-pushed the devs/jd/worktree-no-break-on-changes/I69504832cf0d9f6caaf0290df1f6ca0575adcd53 branch from 28c9ad5 to f4cc95c Compare March 3, 2026 17:03
@mergify mergify bot had a problem deploying to Mergify Merge Protections March 3, 2026 17:03 Failure
Extend test_dynamic_inserted_before_hybrid_no_multiple_heads to
reconstruct the complete chain (static + dynamic) using
get_down_revision for dynamic migrations and file parsing for
static ones, then verify there is exactly one head.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change-Id: I69504832cf0d9f6caaf0290df1f6ca0575adcd53
Claude-Session-Id: f2902019-6258-4c62-9887-f23b8128665f
@jd jd force-pushed the devs/jd/worktree-no-break-on-changes/I69504832cf0d9f6caaf0290df1f6ca0575adcd53 branch from f4cc95c to fa2900f Compare March 3, 2026 17:10
@mergify mergify bot had a problem deploying to Mergify Merge Protections March 3, 2026 17:10 Failure
@jd jd closed this Mar 3, 2026
@jd jd deleted the devs/jd/worktree-no-break-on-changes/I69504832cf0d9f6caaf0290df1f6ca0575adcd53 branch March 3, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants