@@ -18,21 +18,32 @@ class CompatTest {
1818 if (SCENARIOS .isEmpty()) return fail(" No scenarios in ${Scenario ::class .java.packageName} , so nothing is checked." )
1919 val variants = SCENARIOS .flatMap(::variants)
2020 val outcomes = runAll(variants)
21- val version = pomVersion()
21+ val pom = PomVersion .read()
22+ val version = pom.version
2223 if (System .getProperty(" compat.capture" ) != null ) {
24+ if (! pom.isRelease) return fail(
25+ " pom.xml is at ${pom.text} , so a capture would record this branch instead of a release. Captures are taken from " +
26+ " the release tag, as AGENTS.md describes under Releases. To capture a release again with the scenarios you have, " +
27+ " run `git checkout vX.Y.Z -- pom.xml src/main` first and `git checkout HEAD -- pom.xml src/main` after."
28+ )
2329 val dir = File (CAPTURES , version.toString()).apply { mkdirs() }
2430 write(File (dir, " cases.tsv" ), outcomes)
2531 File (dir, " accepted.txt" ).takeUnless { it.exists() }?.writeText(" " )
2632 return
2733 }
2834
29- val (release, dir) = CAPTURES .listFiles().orEmpty().mapNotNull { file -> parseVersion(file.name)?.let { it to file } }
30- .filter { it.first <= version }.maxByOrNull { it.first }
31- ? : return fail(" No capture in $CAPTURES at or below $version . Capture the last release as AGENTS.md describes under Releases." )
35+ val captures = CAPTURES .listFiles().orEmpty().mapNotNull { file -> parseVersion(file.name)?.let { it to file } }
36+ val unreleased = captures.filterNot { pom.couldBeReleased(it.first) }
37+ if (unreleased.isNotEmpty()) return fail(
38+ " ${unreleased.joinToString { it.second.path }} can't hold a release, because pom.xml is at ${pom.text} . A capture made " +
39+ " on a branch records the branch, so it hides any break. Delete it. Captures are taken from the release tag, as " +
40+ " AGENTS.md describes under Releases."
41+ )
42+ val (release, dir) = captures.maxByOrNull { it.first }
43+ ? : return fail(" No capture in $CAPTURES . Capture the last release as AGENTS.md describes under Releases." )
3244 val released = read(File (dir, " cases.tsv" ))
3345 if (released.isEmpty()) return fail(" $dir /cases.tsv is empty, so nothing is checked. Capture $release as AGENTS.md describes under Releases." )
3446 val acceptedFile = File (dir, " accepted.txt" )
35- val accepted = readAccepted(acceptedFile)
3647 val major = version.major > release.major
3748 val warnMustNameOneOfEach = variants.associate { it.key to it.warnMustNameOneOfEach }
3849
@@ -44,9 +55,10 @@ class CompatTest {
4455 if (names.isEmpty()) return quotedNamesOrWholeMessage(outcomes.getValue(key).error!! ).all { name -> ownWarnings.any { it.names(name) } }
4556 return ownWarnings.any { warning -> names.all { alternatives -> alternatives.any(warning::names) } }
4657 }
58+ val protected = released.keys.filter(::builtWithItsSeedOnRelease)
59+ val accepted = readAccepted(acceptedFile, protected)
4760 fun isAccepted (key : CaseKey ) = accepted.any { it.matches(key) }
4861
49- val protected = released.keys.filter(::builtWithItsSeedOnRelease)
5062 val missing = protected.filterNot(outcomes::containsKey)
5163 val broken = protected.filter { outcomes[it]?.built == false }.filterNot(::repeatsSeedBreak)
5264 val stale = accepted.filter { entry -> (missing + broken).none(entry::matches) }
@@ -101,16 +113,27 @@ private class Accepted(val line: Int, val case: String) {
101113private val CAPTURES = File (" src/test/resources/compat" )
102114private const val SHOWN = 50
103115private const val PATTERN = " re:"
116+
117+ // Fits one operator on one directive or type in one scenario. 14.3.0 applying directives on type extensions, the widest
118+ // deliberate break so far, needs at most 15 per line that way.
119+ private const val MAX_PER_PATTERN = 20
104120private val REFERENCE = Regex (" #\\ d+|\\ d+\\ .\\ d+\\ .\\ d+ release notes" )
105121
106- private fun readAccepted (file : File ): List <Accepted > {
122+ private fun readAccepted (file : File , protected : List < CaseKey > ): List <Accepted > {
107123 val problems = mutableListOf<String >()
108124 val accepted = file.readLines().withIndex().filter { it.value.isNotBlank() }.mapNotNull { (index, text) ->
109125 val case = text.substringBefore(' \t ' )
110126 val reason = text.substringAfter(' \t ' , " " )
111127 val problem = when {
112128 ! REFERENCE .containsMatchIn(reason) -> " needs a tab and a reason that names an issue (#N) or the release notes (\" X.Y.Z release notes\" )"
113129 case.startsWith(PATTERN ) && runCatching { Regex (case.removePrefix(PATTERN )) }.isFailure -> " starts with $PATTERN but isn't a valid regex"
130+ case.startsWith(PATTERN ) -> Accepted (index + 1 , case).let { entry ->
131+ val matched = protected.filter(entry::matches)
132+ val scenarios = matched.map { it.scenario }.distinct()
133+ if (scenarios.size <= 1 && matched.size <= MAX_PER_PATTERN ) null
134+ else " accepts ${matched.size} cases in ${scenarios.size} scenarios, and a $PATTERN line may accept at most " +
135+ " $MAX_PER_PATTERN , all in one scenario. List the cases, one per line, or one $PATTERN line per scenario"
136+ }
114137 else -> null
115138 }
116139 problem?.let { problems + = " line ${index + 1 } $it : $text " }
@@ -178,10 +201,17 @@ private fun read(file: File): Map<CaseKey, Outcome> = file.readLines().filter {
178201 CaseKey (cells[0 ], cells[1 ], cells[2 ]) to Outcome (cells[3 ].takeUnless { it == " BUILT" }, cells.drop(4 ))
179202}
180203
181- private fun pomVersion (): KotlinVersion {
182- val pom = File (" pom.xml" ).readText()
183- val version = Regex (" <artifactId>graphql-java-tools</artifactId>\\ s*<version>([^<]+)</version>" ).find(pom)!! .groupValues[1 ]
184- return parseVersion(version.substringBefore(' -' ))!!
204+ private class PomVersion (val text : String ) {
205+ val version = parseVersion(text.substringBefore(' -' ))!!
206+ val isRelease = ' -' !in text
207+
208+ fun couldBeReleased (capture : KotlinVersion ) = if (isRelease) capture <= version else capture < version
209+
210+ companion object {
211+ fun read () = PomVersion (
212+ Regex (" <artifactId>graphql-java-tools</artifactId>\\ s*<version>([^<]+)</version>" ).find(File (" pom.xml" ).readText())!! .groupValues[1 ]
213+ )
214+ }
185215}
186216
187217private fun parseVersion (text : String ): KotlinVersion ? =
0 commit comments