Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/check-action-file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ on:
- 'scripts/test_select_coverage_artifacts.py'
- 'scripts/test_coverage_native_runtime.py'
- 'scripts/test_merge_trigger_tke_subject.py'
- 'scripts/test_ut_diagnostic_artifact.py'
- 'scripts/compact_coverage_profile.go'
- 'scripts/compact_coverage_profile_test.go'
- 'scripts/*race_seed*.py'
Expand Down Expand Up @@ -103,6 +104,8 @@ jobs:
run: python3 scripts/test_select_coverage_artifacts.py -v
- name: Test coverage native runtime paths
run: python3 scripts/test_coverage_native_runtime.py -v
- name: Test UT diagnostic artifact budget
run: python3 scripts/test_ut_diagnostic_artifact.py -v
- name: Test TKE merge subject identity contract
run: python3 scripts/test_merge_trigger_tke_subject.py -v
- name: Test SCA license scope selection
Expand Down
34 changes: 23 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ jobs:
root = Path(os.environ["GITHUB_WORKSPACE"])
stage = Path(os.environ["RUNNER_TEMP"]) / "ut-diagnostics"
limit = int(os.environ.get("UT_DIAGNOSTIC_MAX_BYTES", "262144000"))
manifest_reserve = 65536
manifest_reserve = min(65536, max(0, limit))
payload_limit = max(0, limit - manifest_reserve)
if stage.exists():
shutil.rmtree(stage)
Expand Down Expand Up @@ -350,15 +350,22 @@ jobs:
def priority(path):
name = path.name
if is_under(path, ut_report):
# A full raw report can exhaust the artifact budget. Retain
# the actual failures and small run diagnostics first.
if path == ut_report / "failed" / "result.txt":
return 0
if is_under(path, ut_report / "failed" / "outputs"):
return 3
return {
"top.txt": 0,
"ut-checkpoint.log": 1,
"ut-report.json": 2,
"ut-stderr.log": 3,
}.get(name, 4)
return 5
"ut-stderr.log": 1,
"ut-checkpoint.log": 2,
"ut-report.json": 4,
"top.txt": 5,
}.get(name, 6)
return 7

ordered = sorted(files, key=lambda path: (priority(path), str(path)))
remaining_critical = sum(priority(path) <= 3 for path in ordered)
entries = []
original_total = 0
stored_total = 0
Expand Down Expand Up @@ -424,19 +431,24 @@ jobs:
for source in ordered:
relative = source.relative_to(root)
destination = stage / relative
allowed = remaining
if priority(source) <= 3:
# One oversized diagnostic must not hide the other failures.
allowed //= remaining_critical
remaining_critical -= 1
try:
size = source.stat().st_size
original_total += size
destination.parent.mkdir(parents=True, exist_ok=True)
if size <= remaining:
stored = copy_limited(source, destination, remaining)
if size <= allowed:
stored = copy_limited(source, destination, allowed)
try:
final_size = source.stat().st_size
except OSError:
final_size = size
truncated = stored < final_size
elif remaining >= 128:
stored = copy_head_tail(source, destination, remaining)
elif allowed >= 128:
stored = copy_head_tail(source, destination, allowed)
truncated = True
else:
stored = 0
Expand Down
113 changes: 113 additions & 0 deletions scripts/test_ut_diagnostic_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""Exercise the trusted inline workflow using synthetic UT artifacts."""

import os
from pathlib import Path
import subprocess
import sys
import tempfile
import textwrap
import unittest


WORKFLOW = Path(__file__).resolve().parents[1] / ".github/workflows/ci.yaml"


def run_packager(workspace, runner_temp, limit):
workflow = WORKFLOW.read_text()
section = workflow.split(" - name: Bound UT diagnostic artifact\n", 1)[1]
script = section.split(" python3 - <<'PY'\n", 1)[1].split(
"\n PY", 1
)[0]
env = os.environ.copy()
env.update(
GITHUB_WORKSPACE=str(workspace),
RUNNER_TEMP=str(runner_temp),
UT_DIAGNOSTIC_MAX_BYTES=str(limit),
)
return subprocess.run(
[sys.executable, "-c", textwrap.dedent(script)],
env=env,
check=True,
capture_output=True,
text=True,
)


class UTDiagnosticArtifactTest(unittest.TestCase):
def setUp(self):
self.directory = tempfile.TemporaryDirectory()
self.addCleanup(self.directory.cleanup)
root = Path(self.directory.name)
self.workspace = root / "workspace"
self.runner = root / "runner"
self.workspace.mkdir()
self.runner.mkdir()
self.stage = self.runner / "ut-diagnostics"
self.limit = 65536 + 4096

def write(self, path, data):
file = self.workspace / path
file.parent.mkdir(parents=True, exist_ok=True)
file.write_bytes(data)

def assert_budget(self, limit):
total = sum(p.stat().st_size for p in self.stage.rglob("*") if p.is_file())
self.assertLessEqual(total, limit)

def test_failures_survive_an_oversized_raw_report(self):
self.write("ut-report/failed/result.txt", b"failed test\n")
self.write("ut-report/failed/outputs/pkg/TestFailure", b"actual failure\n")
self.write("ut-report/ut-stderr.log", b"stderr\n")
self.write("ut-report/ut-checkpoint.log", b"checkpoint\n")
self.write("ut-report/ut-report.json", b"R" * 12000)
self.write("ut-report/top.txt", b"T" * 6000)
run_packager(self.workspace, self.runner, self.limit)
for path in (
"ut-report/failed/result.txt",
"ut-report/failed/outputs/pkg/TestFailure",
"ut-report/ut-stderr.log",
"ut-report/ut-checkpoint.log",
):
self.assertEqual(
(self.workspace / path).read_bytes(), (self.stage / path).read_bytes()
)
report = (self.stage / "ut-report/ut-report.json").read_bytes()
self.assertIn(b"UT diagnostic file truncated", report)
self.assertIn(
b"ut-report/ut-report.json\toriginal_bytes=12000",
(self.stage / "manifest.txt").read_bytes(),
)
self.assert_budget(self.limit)
self.assertEqual((self.workspace / "ut-report/ut-report.json").stat().st_size, 12000)

def test_large_failures_share_the_budget(self):
paths = ["ut-report/failed/outputs/pkg/TestA", "ut-report/failed/outputs/pkg/TestB"]
for path in paths:
self.write(path, b"X" * 10000)
run_packager(self.workspace, self.runner, self.limit)
for path in paths:
self.assertIn(b"UT diagnostic file truncated", (self.stage / path).read_bytes())
self.assert_budget(self.limit)

def test_budget_smaller_than_manifest_reserve(self):
self.write("ut-report/failed/outputs/pkg/TestFailure", b"failure")
run_packager(self.workspace, self.runner, 32)
self.assert_budget(32)

def test_large_stderr_does_not_hide_failures(self):
self.write("ut-report/ut-stderr.log", b"E" * 12000)
self.write("ut-report/ut-checkpoint.log", b"C" * 12000)
self.write("ut-report/failed/outputs/pkg/TestFailure", b"actual failure")
run_packager(self.workspace, self.runner, self.limit)
self.assertEqual(
(self.stage / "ut-report/failed/outputs/pkg/TestFailure").read_bytes(),
b"actual failure",
)
self.assertIn(
b"UT diagnostic file truncated",
(self.stage / "ut-report/ut-stderr.log").read_bytes(),
)


if __name__ == "__main__":
unittest.main()
Loading