AGENTS.md
analysis/test-data-manager/AGENTS.mdAGENTS.md
Quality
66/100
Scores the file, not the repository.Length
899 words
15 headings · 8 code blocksRepository
53k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Test Data Manager - Agent Guidelines23Automated system for managing test data files across multiple test configurations.45## Module Overview67This module provides infrastructure for:8- Comparing test outputs with expected files using variant chains9- Automatic file management (creation, update, redundancy removal)10- Test discovery, grouping, and conflict detection1112**Structure:**13- `testFixtures/` — Runtime API for use by other modules14- `tests/` — Module's own test suite1516For conceptual details (variant chains, conflicts, convergence), see [README.md](README.md).17For running test data management tasks (checking/updating test data via Gradle), see [test-data-manager-convention](../../repo/gradle-build-conventions/test-data-manager-convention/README.md).1819## Testing Guidelines (for tests within this module)2021### Core Principles22231. **Readable multi-line string expectations** — Format results as human-readable strings, compare with `assertEquals`242. **Custom formatters** — Create formatters that produce deterministic, readable output253. **Domain-specific assertion helpers** — Encapsulate complex assertions in named functions264. **Descriptive test names** — Use backticks with clear descriptions2728### Testing Patterns2930#### Pattern 1: Readable Output Formatting3132Create formatters that produce deterministic, human-readable output for complex results.3334From `TestDiscoveryAndGroupingIntegrationTest.kt`:3536```kotlin37private fun formatResult(result: GroupingResult): String = buildString {38 for (group in result.groups) {39 val header = if (group.variantDepth == 0) "Group 0 (golden)" else "Group ${group.variantDepth}"40 appendLine("=== $header ===")41 for (test in group.tests.sortedBy { it.displayName }) {42 appendLine("${test.displayName} -> ${test.variantChain}")43 }44 appendLine()45 }46}.trimEnd()4748@Test49fun `discovery finds all tests`() {50 val result = runDiscovery()51 assertEquals(expected.trimIndent(), formatResult(result))52}53```5455#### Pattern 2: Domain-Specific Assertions5657Encapsulate complex assertions in helper functions with clear names.5859From `TestDataManagerGroupingTest.kt`:6061```kotlin62private fun assertGrouping(tests: List<DiscoveredTest>, expected: String) {63 val result = groupByVariantDepth(tests)64 val actual = result.groups.joinToString("\n") { group ->65 "depth=${group.variantDepth}: ${group.uniqueVariantChains.joinToString(", ")}"66 }67 assertEquals(expected.trimIndent(), actual)68}6970private fun assertConflicts(tests: List<DiscoveredTest>, expected: String) {71 val conflicts = validateConflicts(tests)72 val actual = conflicts.joinToString("\n") {73 "${it.chainA} vs ${it.chainB}: '${it.conflictingVariant}'"74 }75 assertEquals(expected.trimIndent(), actual)76}7778@Test79fun `tests grouped by variant depth`() {80 assertGrouping(81 tests = listOf(82 DiscoveredTest("1", "golden", emptyList()),83 DiscoveredTest("2", "js", listOf("js")),84 ),85 expected = """86 depth=0: []87 depth=1: [js]88 """89 )90}91```9293#### Pattern 3: State-Based Testing with Setup/Assert Helpers9495For file-based operations, use setup and assertion helpers.9697From `ManagedTestAssertionsTest.kt`:9899```kotlin100private fun assertFileState(expected: String) {101 val actual = listOf("test.txt", "test.js.txt").mapNotNull { name ->102 val file = tempDir.resolve(name)103 if (file.exists()) "$name: ${file.readText().trim()}" else null104 }.joinToString("\n")105 assertEquals(expected.trimIndent(), actual)106}107108private fun setupFiles(vararg files: Pair<String, String>) {109 for ((name, content) in files) {110 tempDir.resolve(name).writeText("$content\n")111 }112}113114@Test115fun `UPDATE mode - mismatch updates file`() {116 setupFiles("test.txt" to "old")117 runAssertion(variantChain = emptyList(), actual = "new")118 assertFileState("test.txt: new")119}120```121122#### Pattern 4: Filter Testing with Base Class123124For JUnit filter tests, extend `AbstractPostDiscoveryFilterTest`.125126From `ManagedTestFilterTest.kt`:127128```kotlin129internal class ManagedTestFilterTest : AbstractPostDiscoveryFilterTest() {130 @Test131 fun `ClassSource with ManagedTest is included`() {132 assertIncluded(133 filter = ManagedTestFilter,134 descriptor = descriptorFromClass<FakeGoldenAnalysisApiTestGenerated>(),135 )136 }137138 @Test139 fun `ClassSource without ManagedTest is excluded`() {140 assertExcluded(141 filter = ManagedTestFilter,142 descriptor = descriptorFromClass<NoMetadataClass>(),143 )144 }145}146```147148Available utilities from `AbstractPostDiscoveryFilterTest`:149- `assertIncluded(filter, descriptor)` / `assertExcluded(filter, descriptor)`150- `descriptorFromClass<T>()` — Create descriptor from class151- `descriptorFromMethod(method)` — Create descriptor from method reference152- `descriptorWithSource(source)` — Create descriptor with custom source153154#### Pattern 5: Fake Test Classes for Integration Testing155156Create fake test classes in `tests/.../fakes/` to simulate real test configurations.157158```kotlin159// Base class for all fakes160abstract class FakeManagedTest : ManagedTest161162// Golden test (no variant)163@TestMetadata("testData/analysis/api")164class FakeGoldenAnalysisApiTestGenerated : FakeManagedTest() {165 override val variantChain = emptyList<String>()166167 @Test168 @TestMetadata("symbols.kt")169 fun testSymbols() {}170}171172// Multi-level variant test173@TestMetadata("testData/lightClasses")174class FakeWasmLightClassesTestGenerated : FakeManagedTest() {175 override val variantChain = listOf("knm", "wasm")176177 @Test178 @TestMetadata("simple.kt")179 fun testSimple() {}180}181```182183## Usage from Other Modules184185### Implementing ManagedTest186187Implement `ManagedTest` interface and provide variant chain:188189```kotlin190abstract class MyTestBase : ManagedTest {191 override val variantChain: List<String>192 get() = emptyList()193}194```195196Variant chain rules:197- `[]` (empty) — Golden/default configuration, writes to `.txt`198- `["js"]` — Single variant, writes to `.js.txt`199- `["knm", "wasm"]` — Multi-level variant, writes to `.wasm.txt` (last element only)200201### Using Assertions202203Use the extension function `ManagedTest.assertEqualsToTestDataFile()` for comparing test output:204205```kotlin206class MyTest : ManagedTest {207 override val variantChain = listOf("js")208209 fun runTest(testDataFile: File) {210 val actual = computeResult()211 assertEqualsToTestDataFile(212 testDataPath = testDataFile.toPath(),213 actual = actual,214 extension = ".txt",215 )216 }217}218```219220Or use `ManagedTestAssertions.assertEqualsToTestDataFile()` directly:221222```kotlin223ManagedTestAssertions.assertEqualsToTestDataFile(224 testDataPath = testDataFile.toPath(),225 actual = actualContent,226 variantChain = variantChain,227 extension = ".txt",228)229```230231232### Behavior Matrix233234| Scenario | UPDATE mode | CHECK mode (local) | CHECK mode (CI) |235|---------------------------|-------------|--------------------|-----------------|236| actual=null, file missing | Pass | Pass | Pass |237| actual=null, file exists | Delete | Delete + throw | Throw |238| File missing (golden) | Create | Create + throw | Throw |239| File missing (secondary) | Create | Throw | Throw |240| Content matches | Pass | Pass | Pass |241| Write-target redundant | Delete | Delete + throw | Throw |242| Content mismatch | Update | Throw | Throw |243244## Key Classes Reference245246| Class | Location | Purpose |247|--------------------------|----------------------|--------------------------------------------------|248| `ManagedTest` | testFixtures | Interface for tests managed by the system |249| `ManagedTestAssertions` | testFixtures | Assertion functions for test data comparison |250| `TestDataManagerRunner` | testFixtures | Main runner (discovery, grouping, execution) |251| `TestDataContext` | testFixtures | File path resolution and mode for variant chains |252| `ManagedTestFilter` | testFixtures/filters | JUnit filter for ManagedTest implementations |253| `TestMetadataFilter` | testFixtures/filters | JUnit filter by @TestMetadata paths |254| `VariantChainComparator` | testFixtures | Orders variant chains by depth |255
Also in JetBrains/kotlin
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| JetBrains/kotlincompiler/AGENTS.md · 53k | AGENTS.md | buildtestgit | 52/100 | 3 days ago | |
| JetBrains/kotlincompiler/build-tools/AGENTS.md · 53k | AGENTS.md | buildteststylearch+2 | 89/100 | 3 days ago | |
| JetBrains/kotlinCLAUDE.md · 53k | CLAUDE.md | agent-behaviour | 25/100 | 3 days ago | |
| JetBrains/kotlinanalysis/AGENTS.md · 53k | AGENTS.md | teststylearchapi+1 | 86/100 | 3 days ago | |
| JetBrains/kotlincompiler/fir/analysis-tests/AGENTS.md · 53k | AGENTS.md | testlint-formatarchdeployment | 74/100 | 3 days ago | |
| JetBrains/kotlincompiler/psi/AGENTS.md · 53k | AGENTS.md | teststylearchtesting-strategy+3 | 81/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| elastic/elasticsearchx-pack/plugin/inference/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+3 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago | |
| react/react-nativepackages/react-native-compatibility-check/AGENTS.md · 126k | AGENTS.md | testlint-formatstylearch+4 | 99/100 | 3 days ago | |
| kurikomi-labs/komi-storeAGENTS.md · 17k | AGENTS.md | buildlint-formatstylearch+1 | 97/100 | 3 days ago | |
| tiann/KernelSUAGENTS.md · 18k | AGENTS.md | setupbuildlint-formatstyle+4 | 97/100 | 3 days ago | |
| elastic/elasticsearchAGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+6 | 96/100 | 3 days ago | |
| alibaba/nacosAGENTS.md · 33k | AGENTS.md | buildtestlint-formatstyle+6 | 96/100 | 3 days ago | |
| ktorio/ktorAGENTS.md · 14k | AGENTS.md | buildlint-formatstylearch+7 | 96/100 | 3 days ago |
