Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Need to preserve attachment source location info
  • Loading branch information
grynspan committed Aug 20, 2025
commit 0fc58d10c346bbdcc9d3de1c540dc8aa8c7e2967
8 changes: 8 additions & 0 deletions Sources/Testing/ABI/Encoded/ABI.EncodedAttachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ extension ABI {
/// - Warning: Inline attachment content is not yet part of the JSON schema.
var _bytes: Bytes?

/// The source location where this attachment was created.
///
/// - Warning: Attachment source locations are not yet part of the JSON
/// schema.
var _sourceLocation: SourceLocation?

init(encoding attachment: borrowing Attachment<AnyAttachable>, in eventContext: borrowing Event.Context) {
path = attachment.fileSystemPath
_preferredName = attachment.preferredName
Expand All @@ -73,6 +79,8 @@ extension ABI {
return nil
}
}

_sourceLocation = attachment.sourceLocation
}

/// A structure representing the bytes of an attachment.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Testing/Events/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ extension Event {
Issue(event)?.record()
case .valueAttached:
if let attachment = event.attachment {
Attachment.record(attachment)
Attachment.record(attachment, sourceLocation: attachment._sourceLocation ?? .__here())
}
default:
// Not handled here.
Expand Down
1 change: 1 addition & 0 deletions Tests/TestingTests/EventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private func MockXCTAttachmentAdd(_ string: String, named name: String) {
}

@Test func `Attachment is passed to fallback event handler`() async {
MockXCTAttachmentAdd("0123456789", named: "numbers.txt")
await confirmation("Attachment recorded") { valueAttached in
var configuration = Configuration()
configuration.eventHandler = { event, _ in
Expand Down