mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:25:19 +00:00
Skip media-wipe detached tasks under tests (shared-filesystem race)
panicClearAllData and clearCurrentPublicTimeline delete the real ~/Library/Application Support/files tree in detached utility-priority tasks. The SPM test process shares that tree and ChatViewModelTests invoke both methods, so under parallel scheduling the wipe lands at a nondeterministic time — deleting media a concurrently running test just wrote (and the developer's real app data with it). Guard both with the existing TestEnvironment.isRunningTests pattern, mirroring the same fix on feat/mesh-diagnostics (#1377). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -291,6 +291,11 @@ final class ChatPublicConversationCoordinator: PublicMessagePipelineDelegate {
|
|||||||
context.clearPublicConversation(ConversationID(channelID: context.activeChannel))
|
context.clearPublicConversation(ConversationID(channelID: context.activeChannel))
|
||||||
|
|
||||||
Task.detached(priority: .utility) {
|
Task.detached(priority: .utility) {
|
||||||
|
// Skipped under tests: the test process shares the user's real
|
||||||
|
// ~/Library/Application Support/files tree, and this detached
|
||||||
|
// wipe fires at a nondeterministic time — racing tests that
|
||||||
|
// write media there (see the same guard in panicClearAllData).
|
||||||
|
guard !TestEnvironment.isRunningTests else { return }
|
||||||
do {
|
do {
|
||||||
let base = try FileManager.default.url(
|
let base = try FileManager.default.url(
|
||||||
for: .applicationSupportDirectory,
|
for: .applicationSupportDirectory,
|
||||||
|
|||||||
@@ -1274,6 +1274,13 @@ final class ChatViewModel: ObservableObject, BitchatDelegate, TransportEventDele
|
|||||||
|
|
||||||
// Delete ALL media files (incoming and outgoing) in background
|
// Delete ALL media files (incoming and outgoing) in background
|
||||||
Task.detached(priority: .utility) {
|
Task.detached(priority: .utility) {
|
||||||
|
// Skipped under tests: the test process shares the user's real
|
||||||
|
// ~/Library/Application Support/files tree, and this detached
|
||||||
|
// utility-priority wipe fires at a nondeterministic time —
|
||||||
|
// deleting media that concurrently running tests (e.g. the
|
||||||
|
// sendImage flow) just wrote there, and the developer's real
|
||||||
|
// app data with it.
|
||||||
|
guard !TestEnvironment.isRunningTests else { return }
|
||||||
do {
|
do {
|
||||||
let base = try FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
let base = try FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
||||||
let filesDir = base.appendingPathComponent("files", isDirectory: true)
|
let filesDir = base.appendingPathComponent("files", isDirectory: true)
|
||||||
|
|||||||
Reference in New Issue
Block a user