Repository navigation
Description
Summary
The recovered-retry-artifact manifest format — a tab-separated, base64-encoded path\tkind line format used to hand off recovered artifact paths between an activated AppContainer test host and the retry orchestrator — is parsed and written independently in two different projects, with duplicated size-limit constants and duplicated base64 decode/re-encode logic.
Duplication Details
Pattern: Manifest encode/decode + size-limit constants duplicated
-
Severity: Medium
-
Occurrences: 2 (parsing side) + related constant duplication
-
Locations:
src/Platform/Microsoft.Testing.Extensions.PackagedApp/ActivatedAppTestHostHandle.cs, methodRecoverRetryArtifactManifest()(lines ~139-215) — introduced in Enable MTP for UWP and AppContainer Windows apps #11484. RedeclaresMaxManifestBytes = 16L * 1024 * 1024,MaxManifestLineChars = 64 * 1024,MaxManifestRecords = 10_000as localconsts, then manually parses each line: split on first\t, base64-decode the left side withEncoding.UTF8.GetString(Convert.FromBase64String(...)), and re-encodes recovered paths the same way for the destination manifest.src/Platform/Microsoft.Testing.Extensions.Retry/RetryOrchestrator.ArtifactRecovery.cs, methodCollectRecoveredArtifacts()(lines ~24-115) — same commit (Enable MTP for UWP and AppContainer Windows apps #11484). Declares the same three limits asprivate constfields onRetryOrchestrator(MaxRecoveredArtifactManifestBytes,MaxRecoveredArtifactManifestLineBytes/records), and independently parses the identicalpath\tkindbase64 format (including the samekind == "-"null-sentinel convention), plus adds a bounded streaming reader (BoundedManifestLineReader) that the PackagedApp side does not reuse.
-
Code Sample (writer side,
ActivatedAppTestHostHandle.cs):string sourcePath = Path.GetFullPath( Encoding.UTF8.GetString(Convert.FromBase64String(line.Substring(0, separatorIndex)))); ... recoveredLines.Add( $"{Convert.ToBase64String(Encoding.UTF8.GetBytes(Path.GetFullPath(recoveredPath)))}{line[separatorIndex..]}");
vs. reader side,
RetryOrchestrator.ArtifactRecovery.cs:string path = Encoding.UTF8.GetString(Convert.FromBase64String(line.Substring(0, separatorIndex))); string encodedKind = line.Substring(separatorIndex + 1); string? kind = encodedKind == "-" ? null : Encoding.UTF8.GetString(Convert.FromBase64String(encodedKind));
Impact Analysis
- Maintainability: The manifest is a hand-rolled wire format shared implicitly between a producer (
ActivatedAppTestHostHandle) and a consumer (RetryOrchestrator). Its encoding rules (tab separator, base64 fields,-sentinel for null kind, size limits) are currently documented only by the two independent implementations, so changing the format requires touching both in lockstep with no compiler-enforced link between them. - Bug Risk: The size-limit constants (
16 MBtotal,64 KBper line,10,000records) are duplicated as separate literals in two projects. A future tuning change to one limit without the other silently reintroduces mismatched truncation behavior between producer and consumer. - Code Bloat: ~90 combined lines of manifest-format logic that encodes the same tiny protocol.
Refactoring Recommendations
-
Extract a shared manifest serializer
- Create a small shared type (e.g.
RetryArtifactManifestwithWriteEntry/TryParseEntrystatic methods and the three limit constants) in a project referenced by bothMicrosoft.Testing.Extensions.PackagedAppandMicrosoft.Testing.Extensions.Retry(orSharedExtensionHelpersif both already reference it). - Estimated effort: Medium (~2-3 hours) — needs careful handling since
RetryOrchestrator.ArtifactRecovery.csalso owns the bounded streaming reader (BoundedManifestLineReader), which is more sophisticated than theFile.ReadLines-based approach inActivatedAppTestHostHandle.cs. - Benefits: Single source of truth for the wire format and its limits; producer and consumer can't drift out of sync; the streaming reader could be reused for the writer side too if beneficial.
- Create a small shared type (e.g.
-
At minimum, share the limit constants
- If a full serializer extraction is too invasive right now, at least move the three size-limit constants into one shared location referenced by both files, eliminating the risk of the two sides silently disagreeing.
- Estimated effort: Low (~30 min).
- Benefits: Removes the most bug-prone part of the duplication (mismatched limits) with minimal risk.
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 2 (ActivatedAppTestHostHandle.cs, RetryOrchestrator.ArtifactRecovery.cs)
- Detection Method: Semantic code analysis of manifest encode/decode logic introduced by Enable MTP for UWP and AppContainer Windows apps #11484
- Commit: 7287c75 (HEAD at analysis time)
🤖 Automated content by GitHub Copilot. Generated by the Duplicate Code Detector workflow. · copilot · auto · 100.8 AIC · ⌖ 7.37 AIC · ⊞ 13.4K · [◷]( · ◷)
Add this agentic workflow to your repo
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/duplicate-code-detector.md@main
- expires on Sep 30, 2026, 4:38 AM UTC
Activity