Skip to content

Add tests for the index refresh and staging wiring - #576

Merged
hannesa2 merged 1 commit into
gitx:masterfrom
goneng:add-tests-for-index-refresh-wiring
Aug 20, 2026
Merged

hannesa2 merged 1 commit into
gitx:masterfrom
goneng:add-tests-for-index-refresh-wiring

Conversation

@goneng

@goneng goneng commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Follows up on #571, where you asked for tests covering those changes.

Of the three commits that landed there, only 777e6784 carried tests, and
they cover the pure reconcile seam rather than what surrounds it. This adds
nine cases for the rest:

  • Staging reads the index back (24849b90) - staging and unstaging ask
    git and then re-read, a rejected update-index reads nothing back, and
    staged paths reach git NUL-terminated
  • A refresh announces the index only once it has been reconciled - the
    ordering change folded into 777e6784; neither the success nor the
    failure arm of a per-command result may announce an index update
  • Overlapping refreshes coalesce (74197e56) - a request arriving
    during a refresh is deferred rather than discarded, and a burst collapses
    into exactly one re-run

Notes for review

No repository on disk, no git process, no FSEvents, no async settling. That
works because -[PBGitRepository init] touches nothing outside itself, and
the two collaborators that would otherwise reach the filesystem are ordinary
overridable methods, so test-local subclasses record the calls instead of
making them. The whole suite runs in about two seconds.

One production change: the refresh guard in -refresh and its other half in
the completion block are extracted into -beginRefreshOrDeferIt and
-endRefreshTakingDeferred, so the coalescing contract can be asserted
directly. Same logic, same serial queue, just named.

Being straight about what the coalescing cases are: a contract test for the
state machine, not a reproduction of the original bug. Losing the settling
event of a rebase burst only reproduces against a real repository on disk,
and was verified by hand for #571. The other two groups do fail against the
pre-fix code.

The GitXTests target gains a header search path for Classes/Util, which
PBGitRepository_PBGitBinarySupport.h needs.

Test plan

  • xcodebuild test -workspace GitX.xcworkspace -scheme GitX -only-testing:GitXTests
    • 23 tests pass, 14 existing plus 9 new, in ~2s
  • Each new case was checked to be load-bearing by breaking the behaviour it
    guards and confirming it goes red:
    • removing the [self refresh] after update-index fails the two staging
      cases on the read-back count
    • restoring [self postIndexUpdated] in postIndexRefreshSuccess:message:
      trips both inverted expectations
    • dropping the deferred request instead of re-running it fails both
      coalescing cases, while the "nothing was deferred" case correctly stays
      green

Add tests for the two commits of gitx#571 that landed without any, and for
the notification ordering that the third one changed.

PBGitIndexReconcileTests covers how the file list is derived, but
nothing exercised what surrounds it: that staging re-reads the index
rather than trusting the flags it has just set, that a refresh announces
the file list only once it has been rebuilt from all three commands, and
that a request arriving during a refresh is deferred rather than
discarded.

None of that needs a repository on disk. -[PBGitRepository init] touches
nothing outside itself, and the two collaborators that would otherwise
reach the filesystem are ordinary overridable methods, so test-local
subclasses record the calls instead of making them.

- Extract the refresh guard into -beginRefreshOrDeferIt and
  -endRefreshTakingDeferred so the coalescing contract can be asserted
  directly, leaving what they do unchanged
- Add PBGitIndexRefreshTests: staging and unstaging ask git and then
  read the index back, a rejected update-index reads nothing back,
  neither arm of a per-command result announces an index update, and a
  burst of requests collapses into exactly one re-run
- Give the GitXTests target a header search path for Classes/Util, which
  PBGitRepository_PBGitBinarySupport.h needs
@hannesa2
hannesa2 merged commit 854f514 into gitx:master Aug 20, 2026
3 checks passed
@goneng
goneng deleted the add-tests-for-index-refresh-wiring branch August 20, 2026 06:33
@goneng goneng mentioned this pull request Aug 20, 2026
1 task done
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