From ab99f245849388fbb11c5b871c6ed26d5beb213d Mon Sep 17 00:00:00 2001 From: adrians5j Date: Tue, 14 Jul 2026 13:52:00 +0200 Subject: [PATCH] chore(testing): drop the dead context.db bag from dbPlugins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nothing in the codebase reads `context.db` anymore (the DI migration moved every reader onto storage-operations / DI abstractions), so the `context.db = new Db(...)` bag that the test-only `dbPlugins` helper sets was write-only dead weight — along with the DynamoDbDriver it constructed to feed it. Slim `dbPlugins` down to what's still live: registering `DbRegistryFeature` (the DDB-ES CMS storage resolves it in beforeInit). It now takes no args; the DDB and DDB-ES test setups call `dbPlugins()` and no longer build a throwaway driver. Removes the last `Db` instantiation in the repo. Test-only; no production change. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../__tests__/__api__/setupFile.js | 9 ++----- .../__tests__/__api__/setupFile.js | 9 ++----- packages/db-dynamodb/src/testing.ts | 27 +++++-------------- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js b/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js index 327aa54a340..37b529b324c 100644 --- a/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js +++ b/packages/api-headless-cms-ddb-es/__tests__/__api__/setupFile.js @@ -1,6 +1,6 @@ import { EntryBeforeCreateEventHandler } from "@webiny/api-headless-cms/features/contentEntry/CreateEntry/index.js"; import { dbPlugins } from "@webiny/db-dynamodb/testing.js"; -import { DynamoDbDriver, registerDynamoDBCore } from "@webiny/db-dynamodb"; +import { registerDynamoDBCore } from "@webiny/db-dynamodb"; import { getDocumentClient, simulateStream } from "@webiny/project-utils/testing/dynamodb/index.js"; import { registerCmsOpenSearchStorageOperations } from "../../src/index"; import { CmsEntryOpenSearchBodyModifier } from "../../src/features/CmsEntryOpenSearchBodyModifier/index.js"; @@ -70,12 +70,7 @@ setStorageOps("cms", () => { createOrRefreshIndexSubscription.name = "headlessCmsDdbEs.context.createOrRefreshIndexSubscription"; - const initializedDbPlugins = dbPlugins({ - table: process.env.DB_TABLE, - driver: new DynamoDbDriver({ - documentClient - }) - }); + const initializedDbPlugins = dbPlugins(); createOrRefreshIndexSubscription.name = "headlessCmsDdbEs.context.createOrRefreshIndexSubscription"; diff --git a/packages/api-headless-cms-ddb/__tests__/__api__/setupFile.js b/packages/api-headless-cms-ddb/__tests__/__api__/setupFile.js index f870e10ed11..cb8e73a8ab8 100644 --- a/packages/api-headless-cms-ddb/__tests__/__api__/setupFile.js +++ b/packages/api-headless-cms-ddb/__tests__/__api__/setupFile.js @@ -1,5 +1,5 @@ import { dbPlugins } from "@webiny/db-dynamodb/testing.js"; -import { DynamoDbDriver, registerDynamoDBCore } from "@webiny/db-dynamodb"; +import { registerDynamoDBCore } from "@webiny/db-dynamodb"; import { createCmsEntryFieldSortingPlugin, registerDynamoDbStorageOperations } from "../../src"; import { setStorageOps } from "@webiny/project-utils/testing/environment/index.js"; import { getDocumentClient } from "@webiny/project-utils/testing/dynamodb/index.js"; @@ -15,12 +15,7 @@ setStorageOps("cms", () => { /** * TODO remove when all apps are created with their own storage operations factory and drivers. */ - dbPlugins({ - table: process.env.DB_TABLE, - driver: new DynamoDbDriver({ - documentClient - }) - }), + dbPlugins(), createCmsEntryFieldSortingPlugin({ canUse: params => { const { fieldId } = params; diff --git a/packages/db-dynamodb/src/testing.ts b/packages/db-dynamodb/src/testing.ts index 43028eed635..3e1b62f743a 100644 --- a/packages/db-dynamodb/src/testing.ts +++ b/packages/db-dynamodb/src/testing.ts @@ -1,29 +1,16 @@ -import type { ConstructorArgs } from "@webiny/db"; -import { Db } from "@webiny/db"; import { createRegisterExtensionPlugin } from "@webiny/handler"; import { DbRegistryFeature } from "@webiny/db/exports/api/db.js"; -import type { Context } from "@webiny/api/types.js"; - -interface DbContext extends Context { - db: Db; -} /** - * @deprecated Test-only storage-preset glue: registers `DbRegistry` and sets the legacy `context.db` - * bag. Production wires the DB via storage-operations factories/drivers and never reads `context.db`. - * Used only by the DDB/DDB-ES `setupFile.js` test presets — remove once those move to their own - * storage-operations factories/drivers. The `DbRegistry` registration must be preserved (the DDB-ES - * CMS storage resolves it in `beforeInit`). + * @deprecated Test-only storage-preset glue: registers `DbRegistry`, which the DDB-ES CMS storage + * resolves in `beforeInit` to stage the entities it syncs to OpenSearch. (It used to also set a + * legacy `context.db` bag, but nothing reads `context.db` anymore, so that's gone.) Used only by the + * DDB / DDB-ES `setupFile.js` test presets — remove once those register `DbRegistryFeature` + * themselves, the way production does via `registerRequestStorage`. */ -export const dbPlugins = (args: ConstructorArgs) => { - const plugin = createRegisterExtensionPlugin(async context => { - if (context.db) { - return; - } - +export const dbPlugins = () => { + const plugin = createRegisterExtensionPlugin(async context => { DbRegistryFeature.register(context.container); - - context.db = new Db(args); }); plugin.name = "db-dynamodb/extension/db"; return [plugin];