Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
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
17 changes: 17 additions & 0 deletions .github/ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
The Training regression workflow compiles and assembles the project on Corretto 17,
then compares JUnit outcomes with the verified baseline commit recorded in
`baseline.json` (11 tests, two intentional exercise failures).

New failures, changed failure types, missing tests, skipped tests, missing reports,
and build errors fail CI. Previously failing exercises may pass; new passing tests
are allowed. The baseline records test identities and exception types only, without
assertion messages, expected values, or solutions. Baseline changes require review.

Raw build output and JUnit reports are not uploaded or printed by the training
workflow because assertions can disclose exercise answers. CI uploads only counts,
commit identifiers, and a generic result. To diagnose a failure locally, run
`./gradlew clean build` on JDK 17. To run the same CI gate, use
`python3 .github/ci/check_training.py`.

This gate detects regressions relative to the baseline. It does not certify that
the exercises are complete or that all exercise tests pass.
93 changes: 93 additions & 0 deletions .github/ci/baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"commit": "2a3803733de53b67af200a821aca0bcb41173d64",
"cases": [
{
"id": [
"app/build/test-results/test/TEST-base.project.AppTest.xml",
"base.project.AppTest",
"appHasAGreeting()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-base.project.SampleTest$#306a#3093#304b#30c6#30b9#30c8.xml",
"base.project.SampleTest$\u306a\u3093\u304b\u30c6\u30b9\u30c8",
"test()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml",
"book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8",
"\u8ffd\u52a0\u3059\u308b\u672c\u304c\u7a7a\u306e\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u3092\u305d\u306e\u307e\u307e\u8fd4\u3059\u3053\u3068()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml",
"book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8",
"\u8ffd\u52a0\u3059\u308b\u672c\u3068\u521d\u671f\u72b6\u614b\u306e\u672c\u306b\u91cd\u8907\u304c\u3042\u308b\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u672c\u3092\u91cd\u8907\u3092\u7701\u3044\u3066\u8ffd\u52a0\u3059\u308b\u3053\u3068()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml",
"book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8",
"\u8ffd\u52a0\u3059\u308b\u672c\u3068\u521d\u671f\u72b6\u614b\u306e\u672c\u306b\u91cd\u8907\u304c\u306a\u3044\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u672c\u3092\u305d\u306e\u307e\u307e\u8ffd\u52a0\u3059\u308b\u3053\u3068()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml",
"book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8",
"\u8ffd\u52a0\u3059\u308b\u672c\u306e\u4e2d\u3067\u91cd\u8907\u304c\u3042\u308b\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u672c\u3092\u91cd\u8907\u3092\u7701\u3044\u3066\u8ffd\u52a0\u3059\u308b\u3053\u3068()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-book.BookAppTest$#30b7#30c1#30e5#30a8#30fc#30b7#30e7#30f31#306e#30c6#30b9#30c8.xml",
"book.BookAppTest$\u30b7\u30c1\u30e5\u30a8\u30fc\u30b7\u30e7\u30f31\u306e\u30c6\u30b9\u30c8",
"\u91cd\u8907\u3092\u7701\u3044\u305f\u7d50\u679c\u4f55\u3082\u6b8b\u3089\u306a\u304b\u3063\u305f\u5834\u5408_\u5165\u529b\u3057\u305f\u30ea\u30b9\u30c8\u3092\u305d\u306e\u307e\u307e\u51fa\u529b\u3059\u308b\u3053\u3068()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-broker.RunnerBrokerTest.xml",
"broker.RunnerBrokerTest",
"Runnable\u306e\u767b\u9332\u3068\u5b9f\u884c\u304c\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068()"
],
"failure_type": "java.lang.NullPointerException"
},
{
"id": [
"app/build/test-results/test/TEST-date.DateApiTest$actualNow#306e#30c6#30b9#30c8.xml",
"date.DateApiTest$actualNow\u306e\u30c6\u30b9\u30c8",
"\u51fa\u529b\u78ba\u8a8d()"
],
"failure_type": "org.opentest4j.AssertionFailedError"
},
{
"id": [
"app/build/test-results/test/TEST-pickling.PicklingTest$doPickle#306e#30c6#30b9#30c8.xml",
"pickling.PicklingTest$doPickle\u306e\u30c6\u30b9\u30c8",
"\u52d5\u4f5c\u78ba\u8a8d()"
],
"failure_type": null
},
{
"id": [
"app/build/test-results/test/TEST-testability.EditedTimeTest$getTest.xml",
"testability.EditedTimeTest$getTest",
"\u51fa\u529b\u306e\u30c6\u30b9\u30c8()"
],
"failure_type": null
}
]
}
77 changes: 77 additions & 0 deletions .github/ci/check_training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""Detect regressions without changing exercises or exposing assertion answers."""
import json
import os
from pathlib import Path
import subprocess
import tempfile
import xml.etree.ElementTree as ET


def read_cases(repo):
reports = sorted(repo.glob('**/build/test-results/test/TEST-*.xml'))
if not reports:
raise ValueError('No JUnit reports were produced')
cases = {}
for report in reports:
suite = ET.parse(report).getroot()
for case in suite.iter('testcase'):
key = (report.relative_to(repo).as_posix(), case.get('classname'), case.get('name'))
if key in cases:
raise ValueError('Duplicate test identity')
if case.find('skipped') is not None or case.find('error') is not None:
raise ValueError('A test was skipped or had an execution error')
failure = case.find('failure')
cases[key] = None if failure is None else failure.get('type', 'unknown')
if not cases:
raise ValueError('JUnit reports contained no tests')
return cases


def compare(baseline, current, exit_code):
expected = {tuple(case['id']): case['failure_type'] for case in baseline['cases']}
if not expected or len(expected) != len(baseline['cases']):
raise ValueError('Invalid baseline')
if expected.keys() - current.keys():
raise ValueError('Previously executed tests are missing')
failed = {key: kind for key, kind in current.items() if kind is not None}
if any(key not in expected or expected[key] != kind for key, kind in failed.items()):
raise ValueError('A new or changed test failure was detected')
if exit_code not in (0, 1) or (exit_code == 0) != (not failed):
raise ValueError('Gradle exit status does not match the test results')
return {'tests': len(current), 'existing_failures': len(failed), 'new_failures': 0,
'baseline_failures_now_passing': sum(kind is not None and current[key] is None
for key, kind in expected.items())}


def main():
repo = Path(__file__).resolve().parents[2]
baseline = json.loads((Path(__file__).with_name('baseline.json')).read_text())
summary = {'baseline_commit': baseline['commit'], 'source_commit': os.environ.get('GITHUB_SHA'),
'status': 'failed'}
destination = repo / 'build/ci/training-summary.json'
try:
# Capture raw compiler/test output privately: assertion output can reveal exercise answers.
with tempfile.TemporaryFile() as log:
gradle = ['bash', './gradlew', '--no-daemon', '--console=plain', '-Dorg.gradle.jvmargs=-Xmx512m']
built = subprocess.run(gradle + ['clean', 'assemble', 'testClasses'], cwd=repo,
stdout=log, stderr=subprocess.STDOUT)
if built.returncode:
raise ValueError('Compilation or assembly failed; reproduce locally for diagnostics')
tested = subprocess.run(gradle + ['test'], cwd=repo, stdout=log, stderr=subprocess.STDOUT)
summary.update(compare(baseline, read_cases(repo), tested.returncode))
summary['status'] = 'passed'
print('Regression check passed: {tests} tests, {existing_failures} existing failures, '
'{new_failures} new failures.'.format(**summary))
return 0
except (ValueError, ET.ParseError, OSError) as exc:
# Do not print exception contents from XML, subprocesses or user exercise code.
summary['reason'] = str(exc) if type(exc) is ValueError else 'Unable to read test results or run the build'
print('Regression check failed: ' + summary['reason'])
return 1
finally:
destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_text(json.dumps(summary, indent=2) + '\n', encoding='utf-8')


if __name__ == '__main__':
raise SystemExit(main())
66 changes: 66 additions & 0 deletions .github/ci/test_regression_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import tempfile
from pathlib import Path
import unittest

from check_training import compare, read_cases


class RegressionGuardTest(unittest.TestCase):
def setUp(self):
self.key = ('app/build/test-results/test/TEST-Lesson.xml', 'Lesson', 'exercise')
self.baseline = {'cases': [{'id': list(self.key), 'failure_type': 'AssertionError'}]}

def test_existing_failure_is_preserved(self):
self.assertEqual(compare(self.baseline, {self.key: 'AssertionError'}, 1)['new_failures'], 0)

def test_existing_failure_may_be_fixed(self):
self.assertEqual(compare(self.baseline, {self.key: None}, 0)['baseline_failures_now_passing'], 1)

def test_new_failure_is_rejected(self):
with self.assertRaises(ValueError):
compare(self.baseline, {self.key: 'AssertionError', ('new', 'new', 'new'): 'AssertionError'}, 1)

def test_changed_failure_is_rejected(self):
with self.assertRaises(ValueError):
compare(self.baseline, {self.key: 'NullPointerException'}, 1)

def test_removed_test_is_rejected(self):
with self.assertRaises(ValueError):
compare(self.baseline, {}, 0)

def test_infrastructure_exit_is_rejected(self):
for code in [0, 2, -9]:
with self.subTest(code=code), self.assertRaises(ValueError):
compare(self.baseline, {self.key: 'AssertionError'}, code)

def test_missing_or_empty_xml_is_rejected(self):
with tempfile.TemporaryDirectory() as directory:
repo = Path(directory)
with self.assertRaises(ValueError):
read_cases(repo)
report = repo / self.key[0]
report.parent.mkdir(parents=True)
report.write_text('<testsuite/>')
with self.assertRaises(ValueError):
read_cases(repo)

def test_skip_error_and_duplicate_are_rejected(self):
for child in ['<skipped/>', '<error type="InfrastructureError"/>']:
with self.subTest(child=child), tempfile.TemporaryDirectory() as directory:
repo = Path(directory)
report = repo / self.key[0]
report.parent.mkdir(parents=True)
report.write_text('<testsuite><testcase classname="Lesson" name="exercise">' + child + '</testcase></testsuite>')
with self.assertRaises(ValueError):
read_cases(repo)
with tempfile.TemporaryDirectory() as directory:
repo = Path(directory)
report = repo / self.key[0]
report.parent.mkdir(parents=True)
report.write_text('<testsuite>' + '<testcase classname="Lesson" name="exercise"/>' * 2 + '</testsuite>')
with self.assertRaises(ValueError):
read_cases(repo)


if __name__ == '__main__':
unittest.main()
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Training regression

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: corretto
java-version: '17'
- name: Check exercise regressions without publishing answers
run: |
python3 -m unittest discover -s .github/ci -p "test_*.py"
python3 .github/ci/check_training.py
- name: Preserve sanitized regression summary
if: ${{ always() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: training-summary-${{ github.run_attempt }}
path: |
build/ci/training-summary.json
if-no-files-found: error
retention-days: 14
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
// Use JUnit Jupiter for testing.
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
// AssertJの演習用 https://mvnrepository.com/artifact/org.assertj/assertj-core
testImplementation("org.assertj:assertj-core:3.23.1")
testImplementation("org.assertj:assertj-core:3.27.7")
}

application {
Expand All @@ -57,4 +57,4 @@ tasks {

tasks.withType<Wrapper> {
gradleVersion = gradle.gradleVersion
}
}
Binary file modified app/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion app/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=94da89692fc3ca6d2d0ce6bb48548762ea0f1897ba444286f5c7f3759c7af651
Loading