Skip to content

GITHUB_STEP_SUMMARY can exceed the limit with non-ASCII charactors #73

Description

@kzrnm

Version

v3.0.3

Environment

.NET 10

Steps to reproduce

Set the output destination with GITHUB_STEP_SUMMARY="./test-summary.md", then run the following tests using xunit.v3.mtp-v2 v3.2.2.

namespace Test;

public class UnitTest
{
    public static TheoryData<string> GetText()
        => new(Enumerable.Range('一', 0xA000 - '一').Select(char.ConvertFromUtf32)
            .Select(c => string.Join("", Enumerable.Repeat(c, 10))));

    [Theory]
    [MemberData(nameof(GetText))]
    public void Test1(string text) => Assert.True(text.Length > 0);
    [Theory]
    [MemberData(nameof(GetText))]
    public void Test2(string text) => Assert.True(text.Length > 0);
}

Details

test-summary.md

The summary should be under 1024 KB, but it is 3404 KB. It seems the issue is that it’s being truncated based on char length rather than the UTF-8 byte count.

private string TruncateSummary(string content)
{
// Try to extract the underlying file path from the summary writer to monitor file size
var filePath = summaryWriter is StreamWriter writer
? writer.BaseStream switch
{
ContentionTolerantWriteFileStream cts => cts.FilePath,
FileStream fs => fs.Name,
_ => null,
}
: null;
if (string.IsNullOrWhiteSpace(filePath))
return content;
var existingSize = File.Exists(filePath) ? new FileInfo(filePath).Length : 0L;
// Calculate required size for the summary content
var contentSize = Encoding.UTF8.GetByteCount(content);
var newLineSize = Encoding.UTF8.GetByteCount(Environment.NewLine);
var requiredSize = contentSize + newLineSize * 3;
if (existingSize + requiredSize > GitHubEnvironment.SummaryFileSizeLimit)
{
var availableSize = (int)
Math.Min(
GitHubEnvironment.SummaryFileSizeLimit - existingSize - newLineSize * 3L,
int.MaxValue
);
return
// There is enough space to fit the whole content
availableSize > 0
&& requiredSize <= availableSize
? content
// There is enough space to fit some of the content
: availableSize > 0 && requiredSize > availableSize ? content[..availableSize]
// There is no space at all
: string.Empty;
}
return content;
}

Checklist

  • I have looked through existing issues to make sure that this bug has not been reported before
  • I have provided a descriptive title for this issue
  • I have made sure that this bug is reproducible on the latest version of the package
  • I have provided all the information needed to reproduce this bug as efficiently as possible
  • I have sponsored this project

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions