From 58d32f9581ac297ea6524a1e5d3c0febf09ab34b Mon Sep 17 00:00:00 2001 From: Raluca Pintilii Pereira Coutinho Date: Wed, 12 Nov 2025 16:27:25 +0100 Subject: [PATCH 1/2] Add test for API Collection icon rendering in external references Adds test to verify that articles with task groups from external references get collectionGroup role for correct icon display. The test is temporarily skipped until the fix is implemented in the next commit. rdar://135837611 --- .../DocumentationContentRendererTests.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift b/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift index daf92c4e17..8d8b6094de 100644 --- a/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift @@ -131,6 +131,26 @@ class DocumentationContentRendererTests: XCTestCase { ] ) } + + func testRenderKindAndRoleForAPICollection() throws { + throw XCTSkip("TDD: Temporarily disabled while implementing API Collection icon fix") + + // Articles with task groups should get collectionGroup role for external references + let apiCollectionSummary = LinkDestinationSummary( + kind: .article, + language: .swift, + relativePresentationURL: URL(string: "/documentation/test/external/api-collection")!, + referenceURL: URL(string: "doc://com.example.test/documentation/test/external/api-collection")!, + title: "External API Collection", + availableLanguages: [.swift], + taskGroups: [LinkDestinationSummary.TaskGroup(title: "Symbols", identifiers: ["doc://com.example.test/symbol1"])], + variants: [] + ) + + let (kind, role) = DocumentationContentRenderer.renderKindAndRole(.article, semantic: nil, linkSummary: apiCollectionSummary) + XCTAssertEqual(kind, RenderNode.Kind.article) + XCTAssertEqual(role, "collectionGroup") + } } private extension DocumentationDataVariantsTrait { From b385a2421e32ce8fc0bd885414848e7fa3b7031c Mon Sep 17 00:00:00 2001 From: Raluca Pintilii Pereira Coutinho Date: Wed, 12 Nov 2025 16:33:46 +0100 Subject: [PATCH 2/2] Fix API Collection icon rendering for external references Implements detection of API Collections in external references by checking for task groups in LinkDestinationSummary. Articles with task groups are treated as API Collections and get collectionGroup role for correct icon display. Removes test skip to enable validation of the fix. rdar://135837611 --- .../Link Resolution/ExternalPathHierarchyResolver.swift | 2 +- .../Model/Rendering/DocumentationContentRenderer.swift | 5 ++++- .../Rendering/DocumentationContentRendererTests.swift | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftDocC/Infrastructure/Link Resolution/ExternalPathHierarchyResolver.swift b/Sources/SwiftDocC/Infrastructure/Link Resolution/ExternalPathHierarchyResolver.swift index 44477ca526..4378130aa1 100644 --- a/Sources/SwiftDocC/Infrastructure/Link Resolution/ExternalPathHierarchyResolver.swift +++ b/Sources/SwiftDocC/Infrastructure/Link Resolution/ExternalPathHierarchyResolver.swift @@ -165,7 +165,7 @@ extension LinkDestinationSummary { /// Create a topic render render reference for this link summary and its content variants. func makeTopicRenderReference() -> TopicRenderReference { - let (kind, role) = DocumentationContentRenderer.renderKindAndRole(kind, semantic: nil) + let (kind, role) = DocumentationContentRenderer.renderKindAndRole(kind, semantic: nil, linkSummary: self) var titleVariants = VariantCollection(defaultValue: title) var abstractVariants = VariantCollection(defaultValue: abstract ?? []) diff --git a/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift b/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift index 0d6ee8dd40..20fcf8d739 100644 --- a/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift +++ b/Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift @@ -247,7 +247,7 @@ public class DocumentationContentRenderer { return true } - static func renderKindAndRole(_ kind: DocumentationNode.Kind?, semantic: Semantic?) -> (RenderNode.Kind, String) { + static func renderKindAndRole(_ kind: DocumentationNode.Kind?, semantic: Semantic? = nil, linkSummary: LinkDestinationSummary? = nil) -> (RenderNode.Kind, String) { guard let kind else { return (.article, role(for: .article).rawValue) } @@ -270,6 +270,9 @@ public class DocumentationContentRenderer { default: if let article = semantic as? Article { return (.article, roleForArticle(article, nodeKind: kind).rawValue) + } else if kind == .article, let summary = linkSummary, summary.taskGroups != nil { + // For external references: Articles with task groups are API Collections and should have collectionGroup role + return (.article, Self.role(for: .collectionGroup).rawValue) } else { return (.article, role) } diff --git a/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift b/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift index 8d8b6094de..a04678f09f 100644 --- a/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift +++ b/Tests/SwiftDocCTests/Rendering/DocumentationContentRendererTests.swift @@ -133,8 +133,6 @@ class DocumentationContentRendererTests: XCTestCase { } func testRenderKindAndRoleForAPICollection() throws { - throw XCTSkip("TDD: Temporarily disabled while implementing API Collection icon fix") - // Articles with task groups should get collectionGroup role for external references let apiCollectionSummary = LinkDestinationSummary( kind: .article,