Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .github/race-weights
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
# on 2026-11-18, against 16 to 26 s before, because the picture-sizes preset
# plans its 21 pictures at their smallest twice (tfg preset show, a dry run).
# Each weighs what it took where it paid, the rest the most any of them paid.
# The two guards of the plan on several goroutines took 85.0 s and 24.6 s in
# their first part, on an EPYC 7763, on 2026-11-18. The review of the pull
# request that brought them made them dearer the same day - a heavier range,
# a jxl coded while it plans - and on the owner's machine under -race they
# went from 47.0 to 47.7 s and from 11.3 to 24.0 s, so 86.2 and 52.2.
#
# A test that is not here and takes 60 s or more fails its part with the line
# to add. A test that is here and no longer exists fails every part.
Expand All @@ -35,6 +40,7 @@ unlisted 0.58
124.3 TestFreeBoxesCarryPaddingOfAnyLength
99.9 TestEveryBase64TextSizeIsExact
93.8 TestAFilmPictureLargerThanAnyAV1LevelIsRefusedNotBroken
86.2 TestAPlanIsTheSameHoweverManyFilesArePlannedAtOnce
84.3 TestEveryFormatsMapIsTheOneItsStructureReadsBack
68.2 TestADeclaredDefaultIsTheOneTheFormatUses
65.9 TestNoGeneratorHoldsTheWholeFileInMemory
Expand All @@ -52,6 +58,7 @@ unlisted 0.58
55.6 TestTheArchiveScanLooksIntoTheArchivesInside
55.3 TestAFilmOfANamedSizeKeepsEveryPictureInsideItsReserve
52.2 TestChoosingAToolLaysTheScreenOutAsIfItOpenedWithIt
52.2 TestThePicturesPlannedAtOnceHoldNoMoreThanTheMemorySettingLeaves
52.0 TestEveryLanguageDescribesEverythingTheProgramCanProduce
38.6 TestAContainerStopsBetweenTheFilesItPlans
37.5 TestEveryPictureNamedAfterARefusalShowsOne
Expand Down
77 changes: 77 additions & 0 deletions .github/scripts/guard_part.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# Which guards one part of a job runs, and whether it ran every one of them.
#
# guard_part.sh pick PART PARTS LISTED [flag...] writes mine.txt
# guard_part.sh ran LOG fails on a test never started
#
# The guards are split over the parts of three jobs of ci.yml - the tests on
# each system, coverage and the race detector - because one process of them
# reached the eighteen minutes it is given on Windows and macOS (O361). This is
# the one place the three agree on how a part is picked and how it is checked.
#
# pick asks the test binary for its tests, with the flags it will be built with
# (the race job passes -race, because a file in the package builds only without
# it), and keeps the ones race_parts.py lays into this part by the weights in
# .github/race-weights. Listed rather than written down, so a new guard cannot
# be missed by a list kept by hand. It fails when the index the job was given is
# not the one the matrix lists, or below the total, and when the part is given
# no test - go test with nothing to run passes.
#
# ran fails when the log of a part (go test -v) never started a test the part
# was given, by name rather than by count, so a stray line that looks like a
# start cannot stand in for a test that did not run.
set -euo pipefail

# python3 where it runs, python otherwise: the Windows runner may carry only
# the second, and a python3 there can be the stub that sends you to the store.
python_here() {
local py
for py in python3 python; do
if "$py" -c 'import sys' >/dev/null 2>&1; then
echo "$py"
return
fi
done
echo "neither python3 nor python runs here, and the split of the guards is a Python script." >&2
exit 1
}

pick() {
local part=$1 parts=$2 listed=$3
shift 3
if [ "$part" != "$listed" ] || [ "$part" -ge "$parts" ]; then
echo "job $part of $parts is part $listed in the matrix, and the split needs the two equal and below the total."
echo "List strategy.matrix.part as 0, 1, 2 and on, in order, and check the context names in this step's env."
exit 1
fi
go test -tags "$(cat .github/build-tags)" ./internal/guard/ "$@" -list '.*' > listed.txt || { cat listed.txt; exit 1; }
grep -E '^(Test|Fuzz|Example)' listed.txt > names.txt || { echo "the test binary listed no Test, Fuzz or Example function. What it printed:"; cat listed.txt; exit 1; }
# Without carriage returns: Python on Windows ends its lines with them, and a
# name with one never equals the name go test prints when it starts it.
"$(python_here)" .github/scripts/race_parts.py split names.txt .github/race-weights "$part" "$parts" | tr -d '\r' > mine.txt
local planned
planned=$(wc -l < mine.txt)
echo "part $part of $parts runs $planned of $(wc -l < names.txt) tests"
if [ "$planned" -eq 0 ]; then
echo "part $part of $parts was given no test - the checksum of no listed name lands here."
echo "With this few tests, use fewer parts in strategy.matrix.part."
exit 1
fi
}

ran() {
local log=$1 missing
missing=$(comm -23 <(sort mine.txt) <(sed -n 's/^=== RUN \([^/]*\)$/\1/p' "$log" | tr -d '\r' | sort -u))
if [ -n "$missing" ]; then
echo "this part was given $(wc -l < mine.txt) tests and never ran these:"
echo "$missing"
echo "Each of these is a name the part did not reach, or a test the binary skipped before it started."
exit 1
fi
}

case "${1:-}" in
pick) shift; pick "$@" ;;
ran) shift; ran "$@" ;;
*) echo "usage: guard_part.sh pick PART PARTS LISTED [flag...] | ran LOG" >&2; exit 2 ;;
esac
52 changes: 50 additions & 2 deletions .github/scripts/race_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

race_parts.py split NAMES WEIGHTS PART PARTS > mine.txt
race_parts.py unlisted WEIGHTS LOG
race_parts.py verdict WHAT JOBS

split prints the names of NAMES (one per line, as go test -list gives them)
that part PART of PARTS runs. The tests WEIGHTS names are laid out by their
Expand All @@ -14,7 +15,11 @@
does not name took UNLISTED_CEILING seconds or more. Such a test is laid out as
if it were light, and the parts stop being even without anything saying so.

Both fail closed, with a sentence that names what to change: a weight for a
verdict reads the jobs of a workflow run and fails unless every part of WHAT
ran and passed. The checks main's rules require are those verdicts, because a
part carries its number in its name and the rules name jobs.

They fail closed, with a sentence that names what to change: a weight for a
test the binary does not list (renamed or removed), a line that is not a
weight, a name given twice, no "unlisted" line, or a part outside the parts.
"""
Expand All @@ -35,6 +40,9 @@
# which ended the script with a traceback instead of passing the line by.
TOP = re.compile(r"^--- (?:PASS|FAIL|SKIP): (\S+) \(([0-9]+(?:\.[0-9]+)?)s\)$")

# A job of a part as ci.yml names it: "guards on windows-latest (part 1 of 2)".
PART_NAME = re.compile(r"^(.+) \(part ([0-9]+) of ([0-9]+)\)$")


def refuse(message):
print(message, file=sys.stderr)
Expand Down Expand Up @@ -137,14 +145,54 @@ def check_unlisted(weights_path, log_path):
"as if they were light:\n%s\nAdd each line above to %s." % (UNLISTED_CEILING, lines, weights_path))


def verdict(what, jobs_path):
"""Fail unless every part of WHAT ran in this workflow and passed.

JOBS is the jobs of the run, a name and a conclusion to a line with a tab
between, as the verdict jobs of ci.yml ask the API for them. A part is a
job named WHAT (part I of N). Every N has to agree, every I below N has to
be there once, and every one has to have succeeded - a part that never ran
is as red as one that failed, because its tests ran nowhere.
"""
found, counts = {}, set()
for line in read_lines(jobs_path, "list of jobs"):
name, _, conclusion = line.partition("\t")
named = PART_NAME.match(name.strip())
if not named or named.group(1) != what:
continue
part, parts = int(named.group(2)), int(named.group(3))
if part in found:
refuse("two jobs of this run are part %d of %s." % (part, what))
found[part] = conclusion.strip()
counts.add(parts)
if not found:
refuse("no job of this run is a part of %s, so nothing says its tests passed." % what)
if len(counts) != 1:
refuse("the parts of %s disagree about how many there are: %s." % (what, ", ".join(sorted(str(n) for n in counts))))
parts = counts.pop()
failed = False
for part in range(parts):
conclusion = found.get(part, "")
print("part %d of %d of %s: %s" % (part, parts, what, conclusion or "did not run in this workflow"))
failed = failed or conclusion != "success"
for part in sorted(p for p in found if p >= parts):
print("part %d of %s is past its %d parts, so the matrix and the number in the name disagree" % (part, what, parts))
failed = True
if failed:
sys.exit(1)


def main():
args = sys.argv[1:]
if len(args) == 5 and args[0] == "split":
split(*args[1:])
elif len(args) == 3 and args[0] == "unlisted":
check_unlisted(*args[1:])
elif len(args) == 3 and args[0] == "verdict":
verdict(*args[1:])
else:
refuse("usage: race_parts.py split NAMES WEIGHTS PART PARTS | race_parts.py unlisted WEIGHTS LOG")
refuse("usage: race_parts.py split NAMES WEIGHTS PART PARTS | race_parts.py unlisted WEIGHTS LOG"
" | race_parts.py verdict WHAT JOBS")


if __name__ == "__main__":
Expand Down
Loading
Loading