|
| 1 | +# Enhance Swift Testing JSON ABI with Rich Test Metadata |
| 2 | + |
| 3 | +* Proposal: [ST-NNNN](NNNN-augment-event-json-abi.md) |
| 4 | +* Authors: [Sam Khouri](https://github.com/bkhouri), |
| 5 | +* Review Manager: TBD |
| 6 | +* Status: **Awaiting review** |
| 7 | +* Implementation: [swiftlang/swift-testing#1429](https://github.com/swiftlang/swift-testing/pull/1429) |
| 8 | +* Review: [pitch](https://forums.swift.org/t/adding-additional-information-to-the-abi-json/83426) |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +This proposal enhances Swift Testing's event JSON ABI by exposing test |
| 13 | +metadata that is currently unavailable to external tools. By including test |
| 14 | +tags, bug associations, and time limits in the JSON output, this allows third-party |
| 15 | +tools to provide richer insights and more sophisticated test management capabilities. |
| 16 | + |
| 17 | +## Motivation |
| 18 | + |
| 19 | +Swift Testing's event JSON stream provides data for external tooling, |
| 20 | +enabling developers to build test analysis and reporting tools. |
| 21 | +However, the current implementation lacks access to some test metadata that |
| 22 | +developers may want to use to organize and manage their test suites. |
| 23 | + |
| 24 | +Currently missing from the JSON output are: |
| 25 | +- **Test tags**: Used for categorization |
| 26 | +- **Bug associations**: Critical for tracking which tests verify specific bug fixes |
| 27 | +- **Time limits**: Essential for performance monitoring and timeout management |
| 28 | + |
| 29 | +This missing metadata limits the capabilities of external tools. For example: |
| 30 | +- IDE extensions cannot provide tag-based test filtering |
| 31 | +- CI/CD systems cannot generate reports grouped by test categories |
| 32 | +- Performance monitoring tools cannot track tests with specific time constraints |
| 33 | +- Bug tracking integrations cannot correlate test failures with known issues |
| 34 | + |
| 35 | +By exposing this information, we unlock new possibilities for Swift Testing |
| 36 | +tooling ecosystem. |
| 37 | + |
| 38 | +## Proposed solution |
| 39 | + |
| 40 | +We propose enriching the test payload in the event JSON stream by adding three |
| 41 | +metadata fields: |
| 42 | + |
| 43 | +- **`tags`**: An array of string tags associated with the test, enabling categorization |
| 44 | + and filtering |
| 45 | +- **`bugs`**: An array of bug references, providing traceability between tests |
| 46 | + and issue tracking |
| 47 | +- **`timeLimit`**: The test's time limit in seconds, enabling performance monitoring |
| 48 | + and timeout analysis |
| 49 | + |
| 50 | +These additions leverage existing internal data structures, ensuring minimal performance |
| 51 | +impact while maximizing the value delivered to external tools. |
| 52 | + |
| 53 | +## Detailed design |
| 54 | + |
| 55 | +This enhancement builds upon the existing test metadata infrastructure already used |
| 56 | +internally by Swift Testing. The implementation reuses established data structures, |
| 57 | +ensuring consistency and minimizing complexity. |
| 58 | + |
| 59 | +### Implementation Strategy |
| 60 | + |
| 61 | +The new fields are conditionally included in the JSON output based on test |
| 62 | +configuration: |
| 63 | +- Fields are only included when the test actually uses the corresponding traits |
| 64 | +- Empty or unused traits result in omitted fields, keeping the JSON clean and |
| 65 | + efficient |
| 66 | +- This approach maintains backward compatibility while providing rich information |
| 67 | + when available |
| 68 | + |
| 69 | +### JSON Schema Changes |
| 70 | + |
| 71 | +The **Modified Backus-Naur Form (BNF)** delta would be: |
| 72 | + |
| 73 | +```diff |
| 74 | +diff --git a/Documentation/ABI/JSON.md b/Documentation/ABI/JSON.md |
| 75 | +index e4ff24a..1a82996 100644 |
| 76 | +--- a/Documentation/ABI/JSON.md |
| 77 | ++++ b/Documentation/ABI/JSON.md |
| 78 | +@@ -157,10 +157,26 @@ additional `"testCases"` field describing the individual test cases. |
| 79 | + ["displayName": <string>,] ; the user-supplied custom display name |
| 80 | + "sourceLocation": <source-location>, ; where the test is defined |
| 81 | + "id": <test-id>, |
| 82 | +- "isParameterized": <bool> ; is this a parameterized test function or not? |
| 83 | ++ "isParameterized": <bool>, ; is this a parameterized test function or not? |
| 84 | ++ ["tags": <array:tag>,] ; the tags associated with this test function |
| 85 | ++ ["bugs": <array:bug>,] ; the bugs associated with this test function |
| 86 | ++ ["timeLimit": <timeLimit>] ; the time limits associated with this test function |
| 87 | ++ |
| 88 | + } |
| 89 | + |
| 90 | + <test-id> ::= <string> ; an opaque string representing the test case |
| 91 | ++ |
| 92 | ++<tag> ::= <string> ; a string representation of a tag |
| 93 | ++ |
| 94 | ++<bug> ::= { |
| 95 | ++ ["url": <string>,] ; the bug url |
| 96 | ++ ["id": <string>,] ; the bug id |
| 97 | ++ "title": <string> ; the human readable bug title |
| 98 | ++} ; |
| 99 | ++ |
| 100 | ++<timeLimit> ::= <number> ; the test time limit (in seconds) |
| 101 | +``` |
| 102 | + |
| 103 | +## Source compatibility |
| 104 | + |
| 105 | +This proposal maintains full backward compatibility through careful design: |
| 106 | + |
| 107 | +- **ABI Version Protection**: New fields are conditionally included based on ABI |
| 108 | + version checks, ensuring older tools continue to function without modification |
| 109 | +- **Experimental Feature Migration**: The existing experimental `_tag` field is |
| 110 | + replaced with the `tags` array. Since experimental features don't provide |
| 111 | + stability guarantees, this replacement doesn't constitute a breaking change |
| 112 | +- **Graceful Degradation**: Tools that don't expect the new fields will simply ignore |
| 113 | +them, while updated tools can leverage the enhanced metadata |
| 114 | + |
| 115 | +No existing functionality is affected, making this a purely additive enhancement. |
| 116 | + |
| 117 | +## Integration with supporting tools |
| 118 | + |
| 119 | +The enhanced JSON ABI opens up exciting possibilities for the Swift Testing ecosystem: |
| 120 | + |
| 121 | +### Immediate Benefits for Tool Developers |
| 122 | +- **IDE Extensions**: Can now provide tag-based test filtering and organization |
| 123 | +- **CI/CD Integrations**: Can generate more detailed reports with test categorization |
| 124 | +- **Performance Monitoring**: Can track and alert on time limit violations |
| 125 | +- **Bug Tracking Integration**: Can correlate test results with known issues |
| 126 | + |
| 127 | +### Migration Path |
| 128 | +Existing tools will continue to work unchanged, as the new fields are purely additive. |
| 129 | +Tool developers can incrementally adopt the enhanced metadata at their own pace, |
| 130 | +choosing which fields provide the most value for their specific use cases. |
| 131 | + |
| 132 | +### Enhanced Capabilities |
| 133 | +With access to this metadata, tools can now offer features like: |
| 134 | +- Filtering test runs by tags for faster feedback cycles |
| 135 | +- Generating reports that group results by test categories |
| 136 | +- Tracking performance regressions against defined time limits |
| 137 | +- Automatically linking test failures to relevant bug reports |
| 138 | + |
| 139 | +## Future directions |
| 140 | + |
| 141 | +This enhancement establishes future richer tooling experiences: |
| 142 | + |
| 143 | +### Potential Extensions |
| 144 | +- **Additional Metadata**: Other test traits could be exposed as the ecosystem evolves |
| 145 | +- **Enhanced Bug Integration**: More sophisticated bug tracking integration with status updates |
| 146 | +- **Performance Analytics**: Historical time limit data for performance trend analysis |
| 147 | + |
| 148 | +### Ecosystem Growth |
| 149 | +By providing this metadata, we anticipate growth in the Swift Testing tooling |
| 150 | +ecosystem, with new tools emerging to take advantage of the richer data available. |
| 151 | +This proposal positions Swift Testing as a platform that truly enables innovative |
| 152 | +testing tools and workflows. |
| 153 | + |
| 154 | +## Alternatives considered |
| 155 | + |
| 156 | +### Alternative Field Naming |
| 157 | +- **`timeLimitInSeconds` vs `timeLimit`**: We chose the shorter `timeLimit` name for |
| 158 | + consistency with Swift Testing's existing API, with the time unit documented in the |
| 159 | + schema specification. The naming convention was discussed with the Testing Workgroup |
| 160 | + and it was decided that a seperata proposal should be made to on how to represent |
| 161 | + the time units in the name/value. |
| 162 | + |
| 163 | +### Alternative Data Structures |
| 164 | +- **Flattened vs Structured Bug Information**: We chose a structured approach for bug |
| 165 | + metadata to accommodate various bug tracking systems while maintaining extensibility |
| 166 | + |
| 167 | +### Implementation Approaches |
| 168 | +- **Always Include vs Conditional Fields**: We selected conditional inclusion to |
| 169 | + keep JSON output clean and avoid null values, improving the developer experience |
| 170 | + for tools consuming the data |
| 171 | + |
| 172 | +## Acknowledgments |
| 173 | + |
| 174 | +Thanks to [Jonathan Grynspan](https://github.com/grynspan) for suggesting to me |
| 175 | +I write this proposal and for providing feedback. |
| 176 | + |
| 177 | +Thanks to [Paul LeMarqaund](https://github.com/plemarquand) for providing proposal |
| 178 | +feedback before it was posted. |
0 commit comments