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
6 changes: 3 additions & 3 deletions audits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ These remain because coverage has not fully moved off them yet. Each one goes wh
its users does.

- **Core's legacy fixture loader** (`data.json`, `action.json`, `expected.json` through
`TemplatedTestBase`). It runs 193 legacy fixture directories; 363 cases have moved to the runner.
Of the 193:
`TemplatedTestBase`). It runs 186 legacy fixture directories; 370 cases have moved to the runner.
Of the 186:
- 98 are still locked: 96 have no documented source that reproduces them, and are listed under
`unresolved` in `form-review.json`;
- 23 are tracked as legacy-only in `cutover.json`;
- 16 are tracked as legacy-only in `cutover.json`;
- 69 never-locked fixtures have no pinned reference.
- **The legacy RST extractor** (`rst/`, `model/CodeBlock`). Cutover and the example inventory
read pages through it, with tested snippets spliced in and only the mongosh content of each
Expand Down
28 changes: 0 additions & 28 deletions audits/catalog/cutover.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,6 @@
"check" : "SOURCE",
"detail" : "the page documents a projection, which needs the unmapped findOptions",
"fixture" : "query/filters/nin/selectOnUnmatchingDocuments"
}, {
"check" : "SOURCE",
"detail" : "the page creates an index, which the runner does not seed yet",
"fixture" : "query/filters/text/caseAndDiacriticInsensitivity"
}, {
"check" : "SOURCE",
"detail" : "the page creates an index, which the runner does not seed yet",
"fixture" : "query/filters/text/caseSensitivity"
}, {
"check" : "SOURCE",
"detail" : "the page creates an index, which the runner does not seed yet",
"fixture" : "query/filters/text/excludeDocumentsThatContainATerm"
}, {
"check" : "SOURCE",
"detail" : "the page creates an index, which the runner does not seed yet",
"fixture" : "query/filters/text/matchAnyOfTheSearchTerms"
}, {
"check" : "SOURCE",
"detail" : "the page creates an index, which the runner does not seed yet",
"fixture" : "query/filters/text/queryADifferentLanguage"
}, {
"check" : "SOURCE",
"detail" : "the page creates an index, which the runner does not seed yet",
"fixture" : "query/filters/text/textWithASingleWord"
}, {
"check" : "SOURCE",
"detail" : "the page creates an index, which the runner does not seed yet",
"fixture" : "query/filters/text/textWithAnExactString"
} ],
"schemaVersion" : 1
}
669 changes: 669 additions & 0 deletions audits/catalog/fixture-migration.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,16 @@ object FixtureMigration {
)
.append("dataset", dataset?.let { BsonString(it) } ?: BsonNull.VALUE)
.append("collections", collections)
.append("indexes", BsonArray())
.append(
"indexes",
BsonArray(
documented.indexes.map { index ->
BsonDocument("collection", BsonString(index.collection))
.append("keys", index.keys)
.also { spec -> index.options?.let { spec["options"] = it } }
}
),
)
.append("action", action)
.append(
"expected",
Expand Down
56 changes: 43 additions & 13 deletions audits/src/main/kotlin/dev/morphia/audits/repairs/FormMigration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dev.morphia.audits.semantics.BsonDifferenceKind
import dev.morphia.audits.semantics.BsonPath
import dev.morphia.audits.shell.AggregateOperation
import dev.morphia.audits.shell.FindOperation
import dev.morphia.audits.shell.IndexOperation
import dev.morphia.audits.shell.InsertOperation
import dev.morphia.audits.shell.LegacyDocuments
import dev.morphia.audits.shell.ProgramBlock
Expand Down Expand Up @@ -175,6 +176,13 @@ enum class BlockRole {
data class SourceBlock(val role: BlockRole, val text: String, val sha256: String)

/** A documented operation in BSON: seed data by collection, the action, and its printed result. */
/** An index the page creates: its collection, key document and `createIndex` options. */
data class DocumentedIndex(
val collection: String,
val keys: BsonDocument,
val options: BsonDocument?,
)

data class DocumentedScenario(
val collection: String,
val data: Map<String, List<BsonDocument>>,
Expand All @@ -193,6 +201,8 @@ data class DocumentedScenario(
* addresses. The scenario never carries them; see [printed].
*/
val documents: List<BsonValue>? = null,
/** The indexes the page creates before the action, in order. */
val indexes: List<DocumentedIndex> = emptyList(),
)

data class FormOverride(
Expand Down Expand Up @@ -998,7 +1008,6 @@ object FormMigration {
val action = documented.alternatives.single()
require(shape == null || action.shape == shape) { "$label: action is ${action.shape}" }
val expected = blocks.filter { it.role == BlockRole.EXPECTED }
require(blocks.none { it.role == BlockRole.INDEX }) { "$label: indexes are not supported" }
val printed =
if (expected.isEmpty()) null
else
Expand All @@ -1015,6 +1024,7 @@ object FormMigration {
printed,
action.many,
listed.takeIf { it.isNotEmpty() && it.all { rows -> rows != null } }?.flatMap { it!! },
indexes = documented.indexes,
)
}

Expand Down Expand Up @@ -1051,6 +1061,7 @@ object FormMigration {
val alternatives: List<Action>,
val collection: String,
val data: Map<String, List<BsonValue>>,
val indexes: List<DocumentedIndex> = emptyList(),
)

private fun documented(blocks: List<SourceBlock>): Any {
Expand All @@ -1070,18 +1081,39 @@ object FormMigration {
blocks =
programs.mapIndexed { index, block ->
ProgramBlock("data$index", block.text, ProgramRole.SETUP)
} + ProgramBlock("action", action.text, ProgramRole.ACTION),
} +
blocks
.filter { it.role == BlockRole.INDEX }
.mapIndexed { index, block ->
ProgramBlock("index$index", block.text, ProgramRole.SETUP)
} +
ProgramBlock("action", action.text, ProgramRole.ACTION),
)
)
if (program.state != ShellLiteralState.NORMALIZED) {
return gap(FormGap.SOURCE_UNSUPPORTED, program.problems.joinToString { it.code })
}
val inserts =
program.commands
.filter { it.role == ProgramRole.SETUP }
val setup = program.commands.filter { it.role == ProgramRole.SETUP }
setup
.firstOrNull { it.operation !is InsertOperation && it.operation !is IndexOperation }
?.let {
return gap(FormGap.SOURCE_UNSUPPORTED, "setup ${it.operation.kind}")
}
val inserts = setup.filter { it.operation is InsertOperation }
val indexes =
setup
.filter { it.operation is IndexOperation }
.map {
it.operation as? InsertOperation
?: return gap(FormGap.SOURCE_UNSUPPORTED, "setup ${it.operation.kind}")
val index = it.operation as IndexOperation
DocumentedIndex(
it.namespace?.collection
?: return gap(
FormGap.SOURCE_UNSUPPORTED,
"an index without a collection",
),
index.keys.value().asDocument(),
index.options?.value()?.asDocument(),
)
}
val commands = program.commands.filter { it.role == ProgramRole.ACTION }
if (commands.isEmpty() || commands.map { it.namespace }.toSet().size != 1) {
Expand All @@ -1096,11 +1128,9 @@ object FormMigration {
}
val collection = commands.first().namespace!!.collection
val inserted =
program.commands
.filter { it.role == ProgramRole.SETUP }
.zip(inserts)
.groupBy({ it.first.namespace!!.collection }) { (_, insert) ->
insert.documents.map { it.value() }
inserts
.groupBy({ it.namespace!!.collection }) { command ->
(command.operation as InsertOperation).documents.map { it.value() }
}
.mapValues { (_, documents) -> documents.flatten() }
// A listing names no collection; it is the action's only when nothing else is documented.
Expand Down Expand Up @@ -1153,7 +1183,7 @@ object FormMigration {
if (alternatives.map { it.shape to it.many }.toSet().size != 1) {
return gap(FormGap.SOURCE_UNSUPPORTED, "action commands of different kinds")
}
return Documented(alternatives, collection, data)
return Documented(alternatives, collection, data, indexes)
}

private fun reproduce(
Expand Down
13 changes: 13 additions & 0 deletions audits/src/test/kotlin/dev/morphia/audits/offline/GeneratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class GeneratorTest {
|Match Larger Quantities
|~~~~~~~~~~~~~~~~~~~~~~~
|
|${block("db.inventory.createIndex( { qty: 1 }, { name: \"byQty\" } )")}
|${block("db.inventory.find( { qty: { ${'$'}gt: 20 } } )")}
|Project the Quantity
|~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -257,6 +258,18 @@ class GeneratorTest {
"core/src/test/java/dev/morphia/test/generated/filters/TestGt.java"
)
assertTrue("(query) -> query.filter(gt(\"qty\", 20)));" in find, find)
// The page's index travels with the case; the runner creates it before the action.
val found = generation.cases.first().manifest
assertEquals(
BsonDocument.parse(
"{collection: 'inventory', keys: {qty: 1}, options: {name: 'byQty'}}"
),
BsonDocument.parse(
generation.files.getValue("core/src/test/resources${found.scenario}")
)
.getArray("indexes")
.single(),
)
val update =
generation.files.getValue(
"core/src/test/java/dev/morphia/test/generated/updates/TestInc.java"
Expand Down
37 changes: 33 additions & 4 deletions core/src/test/java/dev/morphia/test/OperatorCaseRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
* published comparison only, a
* {@code requirements.minimumServer} skips the case on an older server, and a check the scenario lists under
* {@code skipped}, with its reason, is not run. This runner supports aggregations with exact or printed expected results
* and no tolerances or indexes, and a dataset only when the scenario skips its results; a scenario that needs any
* of them fails rather than being checked loosely.
* and no tolerances, and a dataset only when the scenario skips its results; a scenario that needs either fails rather
* than being checked loosely. Documented indexes are created on both databases after they are seeded.
*/
public class OperatorCaseRunner {
// Canonical extended JSON, so a failure shows BSON types: relaxed JSON prints an Int64 like an Int32.
Expand Down Expand Up @@ -236,6 +236,8 @@ private void run(OperatorCase operatorCase, String kind, Shape shape,
BsonDocument seeded = withIds(scenario.getDocument("collections"));
seed(morphia, seeded);
seed(reference, seeded);
index(morphia, scenario.getArray("indexes"));
index(reference, scenario.getArray("indexes"));

Execution execution = plan.apply(action, collection);
BsonArray documented = documented(action);
Expand Down Expand Up @@ -314,8 +316,11 @@ private static void supported(OperatorCase operatorCase, BsonDocument scenario)
if (!scenario.get("dataset").isNull() && !scenario.getDocument("skipped", new BsonDocument()).containsKey("results")) {
unsupported.add("dataset");
}
if (!scenario.getArray("indexes").isEmpty()) {
unsupported.add("indexes");
for (BsonValue index : scenario.getArray("indexes")) {
if (!index.isDocument() || !index.asDocument().isString("collection") || !index.asDocument().isDocument("keys")
|| !Set.of("collection", "keys", "options").containsAll(index.asDocument().keySet())) {
unsupported.add("index " + index);
}
}
for (BsonValue rule : comparison.getArray("rules")) {
if (Arrays.stream(Rule.values()).noneMatch(known -> known.name().equals(rule.asString().getValue()))) {
Expand Down Expand Up @@ -412,6 +417,30 @@ private void seed(MongoDatabase database, BsonDocument collections) {
});
}

/**
* Creates the documented indexes through {@code createIndexes}, so every option the page passes reaches the server
* as written. An index without a name gets the shell's default, its keys and values joined by underscores.
*/
private static void index(MongoDatabase database, BsonArray indexes) {
for (BsonValue value : indexes) {
BsonDocument index = value.asDocument();
BsonDocument keys = index.getDocument("keys");
BsonDocument spec = new BsonDocument("key", keys);
BsonDocument options = index.getDocument("options", new BsonDocument());
if (!options.containsKey("name")) {
List<String> parts = new ArrayList<>();
keys.forEach((field, order) -> {
parts.add(field);
parts.add(order.isString() ? order.asString().getValue() : String.valueOf(order.asNumber().intValue()));
});
spec.put("name", new BsonString(String.join("_", parts)));
}
spec.putAll(options);
database.runCommand(new BsonDocument("createIndexes", index.getString("collection"))
.append("indexes", new BsonArray(List.of(spec))));
}
}

/** {@code collections} with an {@code _id} given to each document that has none. */
private static BsonDocument withIds(BsonDocument collections) {
BsonDocument result = new BsonDocument();
Expand Down
63 changes: 63 additions & 0 deletions core/src/test/resources/dev/morphia/test/generated/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,41 @@
"name" : "query/filters/regex/extendRegexOptionsToMatchCharactersOutsideOfAscii",
"scenario" : "/dev/morphia/test/query/filters/regex/extendRegexOptionsToMatchCharactersOutsideOfAscii/scenario.json",
"test" : "dev.morphia.test.query.filters.TestRegex#testExtendRegexOptionsToMatchCharactersOutsideOfAscii"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/caseAndDiacriticInsensitivity",
"scenario" : "/dev/morphia/test/query/filters/text/caseAndDiacriticInsensitivity/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testCaseAndDiacriticInsensitivity"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/caseSensitivity",
"scenario" : "/dev/morphia/test/query/filters/text/caseSensitivity/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testCaseSensitivity"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/excludeDocumentsThatContainATerm",
"scenario" : "/dev/morphia/test/query/filters/text/excludeDocumentsThatContainATerm/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testExcludeDocumentsThatContainATerm"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/matchAnyOfTheSearchTerms",
"scenario" : "/dev/morphia/test/query/filters/text/matchAnyOfTheSearchTerms/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testMatchAnyOfTheSearchTerms"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/queryADifferentLanguage",
"scenario" : "/dev/morphia/test/query/filters/text/queryADifferentLanguage/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testQueryADifferentLanguage"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/textWithASingleWord",
"scenario" : "/dev/morphia/test/query/filters/text/textWithASingleWord/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testTextWithASingleWord"
}, {
"kind" : "CONVERTED",
"name" : "query/filters/text/textWithAnExactString",
"scenario" : "/dev/morphia/test/query/filters/text/textWithAnExactString/scenario.json",
"test" : "dev.morphia.test.query.filters.TestText#testTextWithAnExactString"
}, {
"kind" : "CONVERTED",
"name" : "query/updates/addToSet/eachModifier",
Expand Down Expand Up @@ -3321,6 +3356,34 @@
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/regex/extendRegexOptionsToMatchCharactersOutsideOfAscii/scenario.json",
"sha256" : "4f628b36f14ba15d1ad3003a1a79889e4db218c46bb2bd861f52a91986155fb9"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/caseAndDiacriticInsensitivity/scenario.json",
"sha256" : "23a6ed77264099ff60097e58840384f08ba1d4e7ea951530cc7effd614a57aa5"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/caseSensitivity/scenario.json",
"sha256" : "ab0dbfb8650d82cf58f4c8c0c3be0b04fb175e1b286e166ee3d3555fc5f09509"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/excludeDocumentsThatContainATerm/scenario.json",
"sha256" : "c733276cfe0aef91ad6305d9c68fea17d686c2d51d7682045517d8dbc5cb279a"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/matchAnyOfTheSearchTerms/scenario.json",
"sha256" : "c57491c7d383c8f957cc749980aaecdc30cbe5c0fcdcb99c7dab6f8acf6072fd"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/queryADifferentLanguage/scenario.json",
"sha256" : "f96a5fc66dd8a48fa6ffcaa220857295d31e777347cf7c8f0d3adadffa7506e5"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/textWithASingleWord/scenario.json",
"sha256" : "ba224a69fbd007e2e2be7cccee3e9cea001198df133b119ed7edb5dae00da5b3"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/filters/text/textWithAnExactString/scenario.json",
"sha256" : "eb71dbdc9a7918a19a15f805128266ed7383946a1a18134634a8dee607563b60"
}, {
"owner" : "GENERATED",
"path" : "src/test/resources/dev/morphia/test/query/updates/addToSet/eachModifier/scenario.json",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading