@@ -96,6 +96,80 @@ period; its graduation and platform-aligned version are staged for 3.0. Consult
9696the [ CTRF package documentation] ( ../src/MTP/Microsoft.Testing.Extensions.CtrfReport/PACKAGE.md )
9797for the schema and version-specific identity/retry guarantees.
9898
99+ ### Index a TRX report for selective retrieval
100+
101+ The development version of the TRX extension provides an opt-in ` agent-trx `
102+ tool. After the test run, invoke the ** test application** that registered the
103+ extension, not ` dotnet test ` :
104+
105+ ``` powershell
106+ dotnet .\Tests\bin\Release\net10.0\Tests.dll agent-trx --input-trx $reportPath --output-jsonl $indexPath
107+ ```
108+
109+ Choose the final report for one module and a new ` .jsonl ` path in an existing
110+ directory. The tool does not overwrite the output. It does not change the test
111+ run or its exit code; save that exit code and the complete terminal log separately.
112+ Process each module independently, and select the final consolidated retry report.
113+
114+ The UTF-8 JSONL file starts with a header, followed by ` failureCount ` failure
115+ records, followed by detail records. A failure's ` excerpt ` contains at most 512
116+ UTF-8 bytes of its message and stack trace; ` omittedBytes ` records the rest.
117+ ` offset ` is a decimal ** byte** offset from the beginning of the file, and ` length `
118+ is the total byte length of its detail chunks including their newlines. The
119+ byte range contains one or more JSONL detail chunks. Each has the same
120+ ` executionId ` , a zero-based ` part ` , a ` last ` flag and a ` trxOutputXml ` fragment.
121+ Concatenating the fragments reconstructs that result's TRX ` <Output> ` , including
122+ captured output. When no ` <Output> ` exists, the single fragment is ` null ` .
123+ The header's ` detailChunkByteLimit ` bounds the UTF-8 bytes of each unescaped
124+ fragment; JSON escaping and record metadata add bytes. Read the index and seek
125+ to one detail without reading the whole file into the model context:
126+
127+ ``` powershell
128+ $reader = [System.IO.StreamReader]::new($indexPath, [System.Text.Encoding]::UTF8)
129+ try {
130+ $header = $reader.ReadLine() | ConvertFrom-Json
131+ $failures = @(for ($i = 0; $i -lt $header.failureCount; $i++) {
132+ $reader.ReadLine() | ConvertFrom-Json
133+ })
134+ } finally {
135+ $reader.Dispose()
136+ }
137+
138+ if ($failures.Count -gt 0) {
139+ $row = $failures[0]
140+ $stream = [System.IO.File]::OpenRead($indexPath)
141+ try {
142+ $stream.Position = [long]::Parse($row.offset)
143+ $details = [System.IO.StreamReader]::new($stream, [System.Text.Encoding]::UTF8, $false)
144+ $remaining = [long]$row.length
145+ $part = 0
146+ while ($remaining -gt 0) {
147+ $line = $details.ReadLine()
148+ if ($null -eq $line) { throw 'Incomplete detail record.' }
149+ $remaining -= [System.Text.Encoding]::UTF8.GetByteCount($line) + 1
150+ $chunk = $line | ConvertFrom-Json
151+ if ($remaining -lt 0 -or $chunk.executionId -ne $row.executionId -or
152+ $chunk.part -ne $part -or $chunk.last -ne ($remaining -eq 0)) {
153+ throw 'Invalid detail record.'
154+ }
155+ # Inspect this fragment or append it to reconstruct the complete XML.
156+ $part++
157+ }
158+ } finally {
159+ $stream.Dispose()
160+ }
161+ }
162+ ```
163+
164+ ` testId ` and ` executionId ` identify TRX records, not framework rerun UIDs. The
165+ header marks execution completeness and diagnostic retention as unknown: a
166+ missing failure, empty index, or successfully created file does not establish a
167+ successful or complete run. TRX may itself truncate diagnostics. If the report
168+ or tool is unavailable, incomplete, or incompatible, use the saved exit code,
169+ terminal log and other original artifacts; do not treat the projection as a
170+ replacement for them. Nested TRX results and unknown result types are rejected,
171+ not silently omitted. The file may contain sensitive diagnostics.
172+
99173When consuming a CTRF document, select failures before sending data to a model.
100174For example, with ` $reportPath ` pointing to the chosen final report:
101175
0 commit comments