Skip to content

Inject ScrollbackStore and ScrollbackIndex so tests can't pollute scrollback either#36

Merged
buggerman merged 1 commit into
scrollback-recovery-scriptfrom
scrollback-store-injection
Apr 26, 2026
Merged

Inject ScrollbackStore and ScrollbackIndex so tests can't pollute scrollback either#36
buggerman merged 1 commit into
scrollback-recovery-scriptfrom
scrollback-store-injection

Conversation

@buggerman
Copy link
Copy Markdown
Owner

Summary

Changes

  • Sources/BryggaCore/IRC/IRCSession.swift — adds private let scrollbackStore and private let scrollbackIndex. Constructor becomes init(server:connection:scrollbackStore:scrollbackIndex:). Routes record(_:in:), recordServer(_:), loadScrollbackIfNeeded(for:), and finalizeChathistoryBatch through the injected instances. Stores are captured into local vars before Task blocks to avoid strong-self capture.
  • Sources/BryggaCore/Models/AppState.swift — adds scrollbackStore and scrollbackIndex properties. Constructor becomes init(store:scrollbackStore:scrollbackIndex:). restoreFromStore's rehydrate task, closePrivateMessage's clear, and removeServer's clear all go through the injected instances. addServer(...) plumbs them through to every IRCSession it constructs.
  • Sources/Brygga/BryggaApp.swiftAppState(store: .shared)AppState(store: .shared, scrollbackStore: .shared, scrollbackIndex: .shared).
  • Tests/AppStateNavigationTests.swift — replaces makeStore() with makeDeps() returning a (ServerStore, ScrollbackStore, ScrollbackIndex) triple, all rooted under a unique tempdir. Updates all three AppState(...) construction sites.
  • Tests/IRCSessionTests.swiftmakeSession(...) now constructs both stores per-call (tempdir + :memory: SQLite) and passes them to IRCSession.

Test plan

  • swift build — passes
  • swift test — 132 tests pass
  • swiftformat --lint . — clean
  • Manual verification that swift test no longer touches the prod scrollback paths:
    SCROLLBACK="$HOME/Library/Application Support/Brygga/scrollback"
    SQLITE="$HOME/Library/Application Support/Brygga/scrollback.sqlite"
    echo "before: $(find "$SCROLLBACK" -mindepth 1 -maxdepth 1 -type d | wc -l) dirs, $(stat -f %z "$SQLITE") bytes"
    swift test > /dev/null
    echo "after:  $(find "$SCROLLBACK" -mindepth 1 -maxdepth 1 -type d | wc -l) dirs, $(stat -f %z "$SQLITE") bytes"
    Verified locally: dir count and DB size unchanged (246 dirs, 475136 bytes both before and after).

Risk / rollback

  • API change: IRCSession.init(server:connection:) is removed. AppState.init(store:) is removed. Any external consumer passing only (server, connection) or only (store:) would need to update. Internal call sites all updated in this PR.
  • Default .shared instances keep prod behavior identical — same JSONL paths, same SQLite path, no migrations.
  • Revert: this single commit. Reverting reintroduces test pollution but doesn't break anything else.

Stacking note

Per the squash-merge stacked-PR rule for this repo: merge this PR first (lands both this and the recovery script onto main as one squashed commit), then close #35 — its content has already landed.

@buggerman buggerman merged commit f48247d into scrollback-recovery-script Apr 26, 2026
@buggerman buggerman deleted the scrollback-store-injection branch April 26, 2026 21:27
buggerman added a commit that referenced this pull request Apr 26, 2026
* Add scrollback recovery script for the test-pollution incident

* Inject ScrollbackStore and ScrollbackIndex so tests can't pollute scrollback either (#36)
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