From 5160c700ce6571fe43a938acc857905bba14bf17 Mon Sep 17 00:00:00 2001 From: bailey Date: Wed, 16 Jul 2025 15:50:47 -0600 Subject: [PATCH 1/3] sync invalid tests --- ...-commandFailedEvent-databaseName-type.json | 29 +++++++++++++++++++ ...t-commandFailedEvent-databaseName-type.yml | 16 ++++++++++ ...mmandSucceededEvent-databaseName-type.json | 29 +++++++++++++++++++ ...ommandSucceededEvent-databaseName-type.yml | 16 ++++++++++ 4 files changed, 90 insertions(+) create mode 100644 test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.json create mode 100644 test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.yml create mode 100644 test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.json create mode 100644 test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.yml diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.json b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.json new file mode 100644 index 00000000000..f6a305b89a7 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.json @@ -0,0 +1,29 @@ +{ + "description": "expectedCommandEvent-commandFailedEvent-databaseName-type", + "schemaVersion": "1.15", + "createEntities": [ + { + "client": { + "id": "client0" + } + } + ], + "tests": [ + { + "description": "foo", + "operations": [], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandFailedEvent": { + "databaseName": 0 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.yml b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.yml new file mode 100644 index 00000000000..9ab33ad59e2 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandFailedEvent-databaseName-type.yml @@ -0,0 +1,16 @@ +description: "expectedCommandEvent-commandFailedEvent-databaseName-type" + +schemaVersion: "1.15" + +createEntities: + - client: + id: &client0 "client0" + +tests: + - description: "foo" + operations: [] + expectEvents: + - client: *client0 + events: + - commandFailedEvent: + databaseName: 0 diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.json b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.json new file mode 100644 index 00000000000..47b8c8bb9d0 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.json @@ -0,0 +1,29 @@ +{ + "description": "expectedCommandEvent-commandSucceededEvent-databaseName-type", + "schemaVersion": "1.15", + "createEntities": [ + { + "client": { + "id": "client0" + } + } + ], + "tests": [ + { + "description": "foo", + "operations": [], + "expectEvents": [ + { + "client": "client0", + "events": [ + { + "commandSucceededEvent": { + "databaseName": 0 + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.yml b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.yml new file mode 100644 index 00000000000..94adc2b7305 --- /dev/null +++ b/test/spec/unified-test-format/invalid/expectedCommandEvent-commandSucceededEvent-databaseName-type.yml @@ -0,0 +1,16 @@ +description: "expectedCommandEvent-commandSucceededEvent-databaseName-type" + +schemaVersion: "1.15" + +createEntities: + - client: + id: &client0 "client0" + +tests: + - description: "foo" + operations: [] + expectEvents: + - client: *client0 + events: + - commandSucceededEvent: + databaseName: 0 From fe90c8e4152009ba0c5c39b940f6373d5e681c62 Mon Sep 17 00:00:00 2001 From: bailey Date: Wed, 16 Jul 2025 15:47:28 -0600 Subject: [PATCH 2/3] add dbName to cmd events --- src/cmap/command_monitoring_events.ts | 4 +++ test/tools/unified-spec-runner/match.ts | 44 +++++++++++++++--------- test/tools/unified-spec-runner/schema.ts | 2 ++ 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/cmap/command_monitoring_events.ts b/src/cmap/command_monitoring_events.ts index 992b9dc47c9..b5e7c776d57 100644 --- a/src/cmap/command_monitoring_events.ts +++ b/src/cmap/command_monitoring_events.ts @@ -96,6 +96,7 @@ export class CommandSucceededEvent { commandName: string; reply: unknown; serviceId?: ObjectId; + databaseName: string; /** @internal */ name = COMMAND_SUCCEEDED; @@ -127,6 +128,7 @@ export class CommandSucceededEvent { this.duration = calculateDurationInMs(started); this.reply = maybeRedact(commandName, cmd, extractReply(reply)); this.serverConnectionId = serverConnectionId; + this.databaseName = command.databaseName; } /* @internal */ @@ -154,6 +156,7 @@ export class CommandFailedEvent { commandName: string; failure: Error; serviceId?: ObjectId; + databaseName: string; /** @internal */ name = COMMAND_FAILED; @@ -186,6 +189,7 @@ export class CommandFailedEvent { this.duration = calculateDurationInMs(started); this.failure = maybeRedact(commandName, cmd, error) as Error; this.serverConnectionId = serverConnectionId; + this.databaseName = command.databaseName; } /* @internal */ diff --git a/test/tools/unified-spec-runner/match.ts b/test/tools/unified-spec-runner/match.ts index 1b8d0d7836e..2e3c35a4dcc 100644 --- a/test/tools/unified-spec-runner/match.ts +++ b/test/tools/unified-spec-runner/match.ts @@ -461,16 +461,14 @@ function compareCommandStartedEvents( if (expected!.commandName) { expect( expected!.commandName, - `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${ - actual.commandName + `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${actual.commandName }` ).to.equal(actual.commandName); } if (expected!.databaseName) { expect( expected!.databaseName, - `expected ${prefix}.databaseName to equal ${expected!.databaseName} but received ${ - actual.databaseName + `expected ${prefix}.databaseName to equal ${expected!.databaseName} but received ${actual.databaseName }` ).to.equal(actual.databaseName); } @@ -478,37 +476,49 @@ function compareCommandStartedEvents( function compareCommandSucceededEvents( actual: CommandSucceededEvent, - expected: ExpectedCommandEvent['commandSucceededEvent'], + expected: NonNullable, entities: EntitiesMap, prefix: string ) { - if (expected!.reply) { - resultCheck(actual.reply as Document, expected!.reply, entities, [prefix]); + if (expected.reply) { + resultCheck(actual.reply as Document, expected.reply, entities, [prefix]); } - if (expected!.commandName) { + if (expected.commandName) { expect( - expected!.commandName, - `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${ - actual.commandName + expected.commandName, + `expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName }` ).to.equal(actual.commandName); } + if (expected.databaseName) { + expect( + expected.databaseName, + `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${actual.databaseName + }` + ).to.equal(actual.databaseName); + } } function compareCommandFailedEvents( actual: CommandFailedEvent, - expected: ExpectedCommandEvent['commandFailedEvent'], - entities: EntitiesMap, + expected: NonNullable, + _entities: EntitiesMap, prefix: string ) { - if (expected!.commandName) { + if (expected.commandName) { expect( - expected!.commandName, - `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${ - actual.commandName + expected.commandName, + `expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName }` ).to.equal(actual.commandName); } + if (expected.databaseName) { + expect( + expected.databaseName, + `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${actual.databaseName + }` + ).to.equal(actual.databaseName); + } } function expectInstanceOf any>( diff --git a/test/tools/unified-spec-runner/schema.ts b/test/tools/unified-spec-runner/schema.ts index d52192e645c..cd2bd3ff3d5 100644 --- a/test/tools/unified-spec-runner/schema.ts +++ b/test/tools/unified-spec-runner/schema.ts @@ -312,10 +312,12 @@ export interface ExpectedCommandEvent { commandSucceededEvent?: { reply?: Document; commandName?: string; + databaseName?: string; hasServerConnectionId?: boolean; }; commandFailedEvent?: { commandName?: string; + databaseName?: string; hasServerConnectionId?: boolean; }; } From 9278b437ed4c68bac200b15820055ca079f033cb Mon Sep 17 00:00:00 2001 From: bailey Date: Thu, 17 Jul 2025 09:05:57 -0600 Subject: [PATCH 3/3] lint --- test/tools/unified-spec-runner/match.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/tools/unified-spec-runner/match.ts b/test/tools/unified-spec-runner/match.ts index 2e3c35a4dcc..06a23388c01 100644 --- a/test/tools/unified-spec-runner/match.ts +++ b/test/tools/unified-spec-runner/match.ts @@ -461,14 +461,16 @@ function compareCommandStartedEvents( if (expected!.commandName) { expect( expected!.commandName, - `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${actual.commandName + `expected ${prefix}.commandName to equal ${expected!.commandName} but received ${ + actual.commandName }` ).to.equal(actual.commandName); } if (expected!.databaseName) { expect( expected!.databaseName, - `expected ${prefix}.databaseName to equal ${expected!.databaseName} but received ${actual.databaseName + `expected ${prefix}.databaseName to equal ${expected!.databaseName} but received ${ + actual.databaseName }` ).to.equal(actual.databaseName); } @@ -486,14 +488,16 @@ function compareCommandSucceededEvents( if (expected.commandName) { expect( expected.commandName, - `expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName + `expected ${prefix}.commandName to equal ${expected.commandName} but received ${ + actual.commandName }` ).to.equal(actual.commandName); } if (expected.databaseName) { expect( expected.databaseName, - `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${actual.databaseName + `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${ + actual.databaseName }` ).to.equal(actual.databaseName); } @@ -508,14 +512,16 @@ function compareCommandFailedEvents( if (expected.commandName) { expect( expected.commandName, - `expected ${prefix}.commandName to equal ${expected.commandName} but received ${actual.commandName + `expected ${prefix}.commandName to equal ${expected.commandName} but received ${ + actual.commandName }` ).to.equal(actual.commandName); } if (expected.databaseName) { expect( expected.databaseName, - `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${actual.databaseName + `expected ${prefix}.databaseName to equal ${expected.databaseName} but received ${ + actual.databaseName }` ).to.equal(actual.databaseName); }