Skip to content
Open
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: 6 additions & 1 deletion audits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,12 @@ deletes the legacy fixture directory and records the move in `audits/catalog/fix
Run it before editing the legacy test, because it records the bound method's body digest; then move
the body into the named test, move the fixture's declaration in `form-review.json` from
`declarations` to `migrated` (it keeps pinning the source, and the ledger's copy must match it), and
regenerate `example-bindings.json`, the repair inventory and the form report. `manifest <root>` rewrites `core/src/test/resources/dev/morphia/test/generated/manifest.json` from
regenerate `example-bindings.json`, the repair inventory and the form report. `convert <root> <revision> <fixture>` converts a `testPipeline` case with an exact accepted override
in place: its legacy fixture files are replaced by the scenario, its unchanged test runs through the
runner's compatibility adapter, and the ledger records the move (kind `CONVERTED`, with the legacy
body text). Move its declaration to `migrated` as for `migrate`.

`manifest <root>` rewrites `core/src/test/resources/dev/morphia/test/generated/manifest.json` from
the migration ledger: every case with its scenario and test, and every owned file with its digest.
Core's `GeneratedCasesTest` checks the namespace against it in both directions, and an audits test
requires it to equal a fresh capture and every example to have one owner. See the
Expand Down
2 changes: 1 addition & 1 deletion audits/catalog/curated-repairs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7969,7 +7969,7 @@
"folder" : "aggregation/stages/shardedDataDistribution",
"reason" : "an admin function and not generally suited for morphia"
} ],
"repositoryRevision" : "bc710dc12d40f453d97e9939ec11d010448ef264",
"repositoryRevision" : "24d39a8da7a73e1a2535cb6796911812223d904f",
"schemaVersion" : 1,
"summary" : {
"assertion.BEHAVIOR" : 465,
Expand Down
64 changes: 63 additions & 1 deletion audits/catalog/fixture-migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"name" : "0d6e4079e36703ebd37c00722f5891d28b0e2811dc114b129215123adcce3605"
},
"fixture" : "aggregation/expressions/round/roundExpressionOperator",
"kind" : "MIGRATED",
"legacyBody" : "{\n testPipeline((aggregation) -> aggregation.pipeline(project().include(\"roundedValue\", round(\"$value\", 1))));\n }",
"legacyBodySha256" : "a2be79028bba1ec97deb1c8ad1e58a6e01c3dde423f217999f6be42faf58bdd8",
"legacyMethod" : "testRoundExpressionOperator",
"legacyType" : "dev.morphia.test.aggregation.expressions.TestRound",
Expand Down Expand Up @@ -55,8 +57,68 @@
"unexpandedIncludes" : [ ]
},
"scenario" : "core/src/test/resources/dev/morphia/test/generated/fixtures/expressions/round/roundExpressionOperator/scenario.json",
"scenarioSha256" : "79be7a769e0425ad801826b2525502b2dfcb62e5edbb24c1771abae2682e1140",
"scenarioSha256" : "84ffd1ef7b7a093e2a1eaf135d0b4332d895eec749403f4bdf1715ecc8301514",
"test" : "dev.morphia.test.generated.expressions.TestRound#roundExpressionOperator"
}, {
"files" : {
"action.json" : "5491eaf37c07ffb8cf5e7912e43d7881718c2dbfe2a081612221d9d546dd0b7f",
"data.json" : "e92f409d4f4d66bf0ca619c7ed5ec8ff5e09040dfbe324229fe00a18b144d8ff",
"expected.json" : "03ddfb9854df6e0b7a3d1558ea2771b85f555179a0a3cd3ebbf02bd39f3098f9",
"lock" : "20bab9bd1066dd460a747f75360c392507285431bc6dc7e9b0afcebae2d24080",
"name" : "0d6e4079e36703ebd37c00722f5891d28b0e2811dc114b129215123adcce3605"
},
"fixture" : "aggregation/expressions/trunc/truncExpressionOperator",
"kind" : "CONVERTED",
"legacyBody" : "{\n testPipeline((aggregation) -> aggregation.pipeline(project().include(\"truncatedValue\", trunc(\"$value\", 1))));\n }",
"legacyBodySha256" : "9c60a8ab6983ccac4b669deb60f62e928abf9dd18814a355dae0faee389e21d5",
"legacyMethod" : "testTruncExpressionOperator",
"legacyType" : "dev.morphia.test.aggregation.expressions.TestTrunc",
"ordered" : true,
"override" : {
"blocks" : [ {
"role" : "ACTION",
"sha256" : "2ded03ddd39154ebcfb4fc2ef2fe6ebfde81101a7feef07b016af9d3c570ede2",
"text" : "db.samples.aggregate([\n { $project: { truncatedValue: { $trunc: [ \"$value\", 1 ] } } }\n])"
}, {
"role" : "DATA",
"sha256" : "1525aa8e53f49221925c9ebadf216c1cb9e9613dd46af32cc6a4ad4bbe329280",
"text" : "db.samples.insertMany(\n [\n { _id: 1, value: 19.25 },\n { _id: 2, value: 28.73 },\n { _id: 3, value: 34.32 },\n { _id: 4, value: -45.34 }\n ]\n)"
}, {
"role" : "EXPECTED",
"sha256" : "03ddfb9854df6e0b7a3d1558ea2771b85f555179a0a3cd3ebbf02bd39f3098f9",
"text" : "{ \"_id\" : 1, \"truncatedValue\" : 19.2 }\n{ \"_id\" : 2, \"truncatedValue\" : 28.7 }\n{ \"_id\" : 3, \"truncatedValue\" : 34.3 }\n{ \"_id\" : 4, \"truncatedValue\" : -45.3 }"
} ],
"collections" : { },
"corrections" : [ ],
"example" : "main",
"fixture" : "aggregation/expressions/trunc/truncExpressionOperator",
"fixtureFiles" : {
"action.json" : "5491eaf37c07ffb8cf5e7912e43d7881718c2dbfe2a081612221d9d546dd0b7f",
"data.json" : "e92f409d4f4d66bf0ca619c7ed5ec8ff5e09040dfbe324229fe00a18b144d8ff",
"expected.json" : "03ddfb9854df6e0b7a3d1558ea2771b85f555179a0a3cd3ebbf02bd39f3098f9",
"name" : "0d6e4079e36703ebd37c00722f5891d28b0e2811dc114b129215123adcce3605"
},
"includes" : [ ],
"origin" : "948049a3364491f4905246224922d2dbb4197154",
"pageBlob" : "e417831c1b8b86779f5b7ee3890984f6f6b83f0d",
"retiredLock" : {
"name" : "lock",
"sha256" : "20bab9bd1066dd460a747f75360c392507285431bc6dc7e9b0afcebae2d24080",
"text" : "the expected results truncated 2 places instead of 1"
},
"retypes" : [ ],
"rules" : [ ],
"shape" : "PIPELINE",
"source" : {
"commit" : "744735632617f491f8d65071fae36735b6da1d8b",
"path" : "source/reference/operator/aggregation/trunc.txt",
"relation" : "AT_ORIGIN"
},
"unexpandedIncludes" : [ ]
},
"scenario" : "core/src/test/resources/dev/morphia/test/aggregation/expressions/trunc/truncExpressionOperator/scenario.json",
"scenarioSha256" : "44cc5777d8cf3bfeec8602a44a44bad26842be9599204255625cd843b13ceefa",
"test" : "dev.morphia.test.aggregation.expressions.TestTrunc#testTruncExpressionOperator"
} ],
"schemaVersion" : 1
}
47 changes: 3 additions & 44 deletions audits/catalog/form-migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -3666,47 +3666,6 @@
"relation" : "AT_ORIGIN"
},
"unexpandedIncludes" : [ ]
}, {
"blocks" : [ {
"role" : "ACTION",
"sha256" : "2ded03ddd39154ebcfb4fc2ef2fe6ebfde81101a7feef07b016af9d3c570ede2",
"text" : "db.samples.aggregate([\n { $project: { truncatedValue: { $trunc: [ \"$value\", 1 ] } } }\n])"
}, {
"role" : "DATA",
"sha256" : "1525aa8e53f49221925c9ebadf216c1cb9e9613dd46af32cc6a4ad4bbe329280",
"text" : "db.samples.insertMany(\n [\n { _id: 1, value: 19.25 },\n { _id: 2, value: 28.73 },\n { _id: 3, value: 34.32 },\n { _id: 4, value: -45.34 }\n ]\n)"
}, {
"role" : "EXPECTED",
"sha256" : "03ddfb9854df6e0b7a3d1558ea2771b85f555179a0a3cd3ebbf02bd39f3098f9",
"text" : "{ \"_id\" : 1, \"truncatedValue\" : 19.2 }\n{ \"_id\" : 2, \"truncatedValue\" : 28.7 }\n{ \"_id\" : 3, \"truncatedValue\" : 34.3 }\n{ \"_id\" : 4, \"truncatedValue\" : -45.3 }"
} ],
"collections" : { },
"corrections" : [ ],
"example" : "main",
"fixture" : "aggregation/expressions/trunc/truncExpressionOperator",
"fixtureFiles" : {
"action.json" : "5491eaf37c07ffb8cf5e7912e43d7881718c2dbfe2a081612221d9d546dd0b7f",
"data.json" : "e92f409d4f4d66bf0ca619c7ed5ec8ff5e09040dfbe324229fe00a18b144d8ff",
"expected.json" : "03ddfb9854df6e0b7a3d1558ea2771b85f555179a0a3cd3ebbf02bd39f3098f9",
"name" : "0d6e4079e36703ebd37c00722f5891d28b0e2811dc114b129215123adcce3605"
},
"includes" : [ ],
"origin" : "948049a3364491f4905246224922d2dbb4197154",
"pageBlob" : "e417831c1b8b86779f5b7ee3890984f6f6b83f0d",
"retiredLock" : {
"name" : "lock",
"sha256" : "20bab9bd1066dd460a747f75360c392507285431bc6dc7e9b0afcebae2d24080",
"text" : "the expected results truncated 2 places instead of 1"
},
"retypes" : [ ],
"rules" : [ ],
"shape" : "PIPELINE",
"source" : {
"commit" : "744735632617f491f8d65071fae36735b6da1d8b",
"path" : "source/reference/operator/aggregation/trunc.txt",
"relation" : "AT_ORIGIN"
},
"unexpandedIncludes" : [ ]
}, {
"blocks" : [ {
"role" : "ACTION",
Expand Down Expand Up @@ -7130,7 +7089,7 @@
},
"unexpandedIncludes" : [ ]
} ],
"repositoryRevision" : "bc710dc12d40f453d97e9939ec11d010448ef264",
"repositoryRevision" : "24d39a8da7a73e1a2535cb6796911812223d904f",
"rules" : [ {
"description" : "$cond: {if: a, then: b, else: c} and $cond: [a, b, c] are the same expression; the array form is canonical.",
"rule" : "COND_ARRAY"
Expand Down Expand Up @@ -7171,9 +7130,9 @@
"gap.REJECTED" : 1,
"gap.RESIDUAL_DIFFERENCE" : 48,
"gap.SOURCE_UNSUPPORTED" : 34,
"overrides" : 137,
"overrides" : 136,
"overrides.corrected" : 20,
"overrides.exact" : 56,
"overrides.exact" : 55,
"overrides.retyped" : 16,
"rule.ALTERNATIVE_COMMANDS" : 1,
"rule.COND_ARRAY" : 14,
Expand Down
32 changes: 16 additions & 16 deletions audits/catalog/form-review.json
Original file line number Diff line number Diff line change
Expand Up @@ -1791,22 +1791,6 @@
"path" : "source/reference/operator/aggregation/topN.txt",
"relation" : "AT_ORIGIN"
}
}, {
"corrections" : [ ],
"fixture" : "aggregation/expressions/trunc/truncExpressionOperator",
"includes" : [ ],
"justification" : null,
"lock" : "the expected results truncated 2 places instead of 1",
"marker" : "lock",
"origin" : "948049a3364491f4905246224922d2dbb4197154",
"pageBlob" : "e417831c1b8b86779f5b7ee3890984f6f6b83f0d",
"retypes" : [ ],
"rules" : [ ],
"source" : {
"commit" : "744735632617f491f8d65071fae36735b6da1d8b",
"path" : "source/reference/operator/aggregation/trunc.txt",
"relation" : "AT_ORIGIN"
}
}, {
"corrections" : [ ],
"fixture" : "aggregation/expressions/tsSecond/obtainTheNumberOfSecondsFromATimestampField",
Expand Down Expand Up @@ -3753,6 +3737,22 @@
"path" : "source/reference/operator/aggregation/round.txt",
"relation" : "AT_ORIGIN"
}
}, {
"corrections" : [ ],
"fixture" : "aggregation/expressions/trunc/truncExpressionOperator",
"includes" : [ ],
"justification" : null,
"lock" : "the expected results truncated 2 places instead of 1",
"marker" : "lock",
"origin" : "948049a3364491f4905246224922d2dbb4197154",
"pageBlob" : "e417831c1b8b86779f5b7ee3890984f6f6b83f0d",
"retypes" : [ ],
"rules" : [ ],
"source" : {
"commit" : "744735632617f491f8d65071fae36735b6da1d8b",
"path" : "source/reference/operator/aggregation/trunc.txt",
"relation" : "AT_ORIGIN"
}
} ],
"repository" : "mongodb/docs",
"schemaVersion" : 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ object LegacyBindings {
val disabled: Boolean,
val emptyBody: Boolean,
val bodySha256: String,
val body: String,
)

private class ParsedClass(
Expand All @@ -302,6 +303,17 @@ object LegacyBindings {
val methods: List<ParsedMethod>,
)

/**
* The exact source text of each test method body in [source] (a path relative to [repository]),
* the text whose SHA-256 a catalog records as `bodySha256`.
*/
fun bodies(repository: Path, source: String): Map<String, String> {
val root = repository.toRealPath()
return parse(root, listOf(root.resolve(source))).single().methods.associate {
it.name to it.body
}
}

private fun parse(root: Path, files: List<Path>): List<ParsedClass> {
if (files.isEmpty()) return emptyList()
val texts =
Expand Down Expand Up @@ -390,6 +402,7 @@ object LegacyBindings {
MessageDigest.getInstance("SHA-256")
.digest(text.substring(start, end).toByteArray(UTF_8))
),
body = text.substring(start, end),
)
}

Expand Down
21 changes: 13 additions & 8 deletions audits/src/main/kotlin/dev/morphia/audits/repairs/CaseManifest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ object CaseManifests {
private const val resources = "core/src/test/resources"

/**
* The manifest for the cases in [ledger]: each migrated case, its scenario (generated from the
* override) and its test source (a moved handwritten body, so protected).
* The manifest for the cases in [ledger]: each case, its scenario (generated from the override)
* and, for a migrated case, its test source (a moved handwritten body, so protected).
*/
fun capture(repository: Path, ledger: FixtureMigrationLedger): CaseManifest {
val root = repository.toRealPath()
Expand All @@ -37,7 +37,7 @@ object CaseManifests {
require(it.scenario.startsWith("$resources/")) {
"${it.fixture}: scenario outside core"
}
ManifestCase(it.fixture, "MIGRATED", it.scenario.removePrefix(resources), it.test)
ManifestCase(it.fixture, it.kind, it.scenario.removePrefix(resources), it.test)
}
val files =
ledger.migrations
Expand All @@ -46,7 +46,9 @@ object CaseManifests {
"core/src/test/java/" +
migrated.test.substringBefore('#').replace('.', '/') +
".java"
listOf(migrated.scenario to "GENERATED", source to "PROTECTED")
// A converted case's test stays a legacy test, owned by the binding manifest.
if (migrated.kind == CONVERTED) listOf(migrated.scenario to "GENERATED")
else listOf(migrated.scenario to "GENERATED", source to "PROTECTED")
}
.plus(protectedResources(root).map { it to "PROTECTED" })
.distinct()
Expand Down Expand Up @@ -85,13 +87,16 @@ object CaseManifests {
val legacy =
descriptor.classes.flatMap { type ->
type.bindings.map {
"${type.resources.removePrefix("dev/morphia/test/")}/${it.resource}"
"${type.resources.removePrefix("dev/morphia/test/")}/${it.resource}" to
"${type.type}#${it.method}"
}
}
// A converted case is run by its legacy test, so the two name one owner. Fixture
// directories that differ only by case collide on a case-insensitive file system.
val problems =
// Fixture directories differ only by case on a case-insensitive file system.
(legacy + manifest.cases.map { it.name })
.groupingBy { it.lowercase(Locale.ROOT) }
(legacy + manifest.cases.map { it.name to it.test })
.distinct()
.groupingBy { it.first.lowercase(Locale.ROOT) }
.eachCount()
.filterValues { it > 1 }
.keys
Expand Down
Loading