HTML Report: source link + code snippet on Source tab (#5993) by thomhurst · Pull Request #6100 · thomhurst/TUnit (original) (raw)
Closes #5993. The HTML report's Source tab only showed path:line. When running in GitHub Actions it now also renders a "Jump to source" link and a lazily-fetched code snippet of the test method.
- Snippet is fetched client-side from raw.githubusercontent.com (or the Enterprise raw URL) on Source-tab activation and cached per file, so no source is embedded in the HTML (keeps file size small).
- Source-gen mode supplies an exact method end line (Roslyn span), giving a full-method snippet; reflection mode has no end line, so the client falls back to a fixed window from the declaration line. No source is parsed or read from disk at discovery time.
- Features degrade gracefully: hidden outside GitHub Actions, "Source unavailable" on fetch failure (e.g. private repos).
Shared GitHubSourceLink.ToRepoRelativePath helper extracted from GitHubReporter so both reporters strip workspace-relative paths the same way. CI context (repo/sha/workspace/serverUrl) is read once per report build.
Also fixes a pre-existing off-by-one: GitHubReporter source links added +1 to an already-1-based line number, pointing one line below the test.
[](/apps/claude)
…ppet
- ToRepoRelativePath now normalizes the workspace param internally (slashes + trailing slash) so callers no longer carry that hidden contract.
- Source snippet JS strips a leading UTF-8 BOM and splits on /\r?\n/ so Windows-authored files do not render a stray glyph or trailing \r per line.
- Add regression test for an un-normalized (backslash) workspace.
[](/apps/claude)
[](/apps/claude)
Prevent GITHUB_REPOSITORY/GITHUB_SHA leaking into subsequent tests.
[](/apps/claude)
Detect the CI provider (GitHub, GitLab, Bitbucket) in C# and emit pre-substituted URL templates into the report; the client only fills {path}/{line}/{start}/{end}, so there is zero provider-specific JS and the report shrinks. Inline snippets are enabled only where the raw endpoint allows cross-origin fetch (GitHub.com, Bitbucket Cloud); GitLab and GitHub Enterprise are link-only. Never default an unknown server to github.com.
[](/apps/claude)
Quality cleanup, no behavior change: rename GitHubSourceLink -> SourcePathResolver (now provider-agnostic), drop redundant workspace normalization at call sites (ToRepoRelativePath already normalizes), and switch the source-tab JS from string concatenation to template literals.
[](/apps/claude)
This was referenced
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})