Files
floci/.github/ci/compat-allowlist-check.py
T
Hector Ventura ea06896984 test(compat): run the Java SDK suite nightly in cn-north-1 against an allowlist of known failures (#4790)
* test(compat): run the Java SDK suite nightly in cn-north-1 against an allowlist of known failures

Part of #4272 (P11). The partition work is covered by unit and integration
tests over all eight partitions, but nothing ran a real SDK whose own
partition logic (arn:aws-cn: ARNs, China signing scopes, the LocationConstraint
S3 CreateBucket sends) has to round-trip.

The Partition Compatibility workflow runs after each Nightly against the image
it published, or on dispatch with an image and region: Floci starts with
FLOCI_DEFAULT_REGION=cn-north-1 and sdk-test-java runs with AWS_REGION set,
which TestFixtures now reads (default us-east-1, so the per-PR legs are
unchanged). It runs once a night rather than per PR, to keep the shared runner
pools free.

compat-allowlist-check.py compares the JUnit results with
compat-partition-allowlist-<region>.txt and fails on a failure the list does
not name, on an entry that no longer fails, or on missing results, so the list
only shrinks. The cn-north-1 list holds the 112 failures measured locally on
main plus #4787: 96 tests that pin commercial ARNs, regions or zones, 13 that
exercise commercial-only behaviour, and 3 still to explain.

* test(compat): pin the nightly China run to its image's commit and catch an aborted suite

Greptile on #4790: the workflow checked out the Nightly run's head_sha but
pulled the mutable floci/floci:nightly tag, so the image and the tests could
come from different commits; it now pulls the image first and checks out the
commit in its org.opencontainers.image.revision label. And Maven exits
non-zero for allowlisted failures too, so a suite that stopped partway could
pass; the checker now takes --test-sources and requires a report for every
test class in that tree.

The cn-north-1 allowlist groups its entries by the verified cause: the RDS and
SSO portal entries are Floci bugs (an RdsService ownership check against the
literal partition "aws", and an arn:aws: seeded Identity Center instance),
and SsoAdminAccountAssignmentTest#createInstanceQuotaUsesAwsSdk passes alone
and fails only after OrganizationsTest leaves an organization behind.
2026-10-01 00:33:54 -04:00

95 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""Compare a compat suite's JUnit results with an allowlist of known failures.
Usage: compat-allowlist-check.py <results-dir> <allowlist> [--test-sources <dir>]
Reads every TEST-*.xml under <results-dir> and collects the test cases that
failed or errored. The allowlist names the failures that are known and
accepted, one per line: `Class#method` for one test or `Class` for every test
in a class, by simple class name (no package). `#`-comments and blank lines
are ignored. A missing allowlist file is an empty one.
Fails when:
- a test fails that the allowlist does not name (a regression), or
- an allowlist entry matches no failing test (the gap is closed: delete the
line, so the list only ever shrinks), or
- no results were found (the suite did not run), or
- with --test-sources, there are fewer result files than test classes in that
source tree (the suite stopped partway: Maven exits non-zero for allowlisted
failures too, so its status cannot tell the two apart).
"""
import argparse
import re
import sys
import xml.etree.ElementTree as ET
from pathlib import Path
TEST_ANNOTATION = re.compile(r'@(?:Test|ParameterizedTest|RepeatedTest|TestFactory|TestTemplate)\b')
def load_allowlist(path):
if not Path(path).exists():
return []
# `Class#method` carries a `#`, so a comment is a line starting with `#` or a ` #` suffix.
entries = []
for raw in Path(path).read_text().splitlines():
line = raw.split(' #', 1)[0].strip()
if line and not line.startswith('#'):
entries.append(line)
return entries
def failing_tests(results_dir):
failed = set()
files = sorted(Path(results_dir).glob('TEST-*.xml'))
for path in files:
root = ET.parse(path).getroot()
for case in root.iter('testcase'):
if case.find('failure') is not None or case.find('error') is not None:
simple_class = case.get('classname', '').rsplit('.', 1)[-1]
failed.add(f"{simple_class}#{case.get('name', '')}")
return files, failed
def test_class_count(source_dir):
return sum(1 for path in Path(source_dir).rglob('*.java')
if TEST_ANNOTATION.search(path.read_text(encoding='utf-8')))
def matches(entry, test_id):
return test_id == entry if '#' in entry else test_id.split('#', 1)[0] == entry
def main(argv):
parser = argparse.ArgumentParser(description='Compare JUnit results with an allowlist.')
parser.add_argument('results_dir')
parser.add_argument('allowlist')
parser.add_argument('--test-sources', help='test source tree; requires a report per test class')
args = parser.parse_args(argv[1:])
files, failed = failing_tests(args.results_dir)
if not files:
print(f'::error::No TEST-*.xml results under {args.results_dir}: the suite did not run.')
return 1
if args.test_sources:
expected = test_class_count(args.test_sources)
if len(files) < expected:
print(f'::error::{len(files)} result files for {expected} test classes: the suite stopped partway.')
return 1
allowlist = load_allowlist(args.allowlist)
unexpected = sorted(t for t in failed if not any(matches(e, t) for e in allowlist))
stale = [e for e in allowlist if not any(matches(e, t) for t in failed)]
expected = sorted(t for t in failed if t not in unexpected)
print(f'{len(files)} result files, {len(failed)} failing tests, '
f'{len(expected)} allowlisted, {len(allowlist)} allowlist entries.')
for test_id in unexpected:
print(f'::error::Not in the allowlist: {test_id}')
for entry in stale:
print(f'::error::Allowlist entry no longer fails, delete it: {entry}')
return 1 if unexpected or stale else 0
if __name__ == '__main__':
sys.exit(main(sys.argv))