From ab97ec143fd37a0cd13966667f1f079de8acede7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 15 Oct 2026 17:24:52 +0000 Subject: [PATCH 1/2] test(service-datasource): pay the drivers' first load at module top in the two slow suites datasource-pool-support and default-datasource-driver-factory each paid a cold transform of @objectstack/core's source (the package's vitest alias) inside their first case that builds a real driver: 7-9 s of each file's ~9 s of clocked wall. Module-top side-effect imports of the drivers the cases build move that load into collection, per the clocked-window rule. No case, it/describe line or expect line changes. Claude-Session: https://claude.ai/code/session_017WLmd5in9RXu7AjyHR8fKQ Co-authored-by: Claude --- .../__tests__/datasource-pool-support.test.ts | 16 ++++++++++++++ .../default-datasource-driver-factory.test.ts | 21 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts b/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts index 5d3aaf41fa8..b0636afb69a 100644 --- a/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts +++ b/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts @@ -65,6 +65,22 @@ import { import { DatasourceAdminService, type StoredDatasource } from '../datasource-admin-service.js'; import type { IDatasourceDriverFactory } from '../contracts/datasource-driver-factory.js'; import type { IDataDriver } from '@objectstack/spec/contracts'; +// [#23184] The drivers' first module load is paid HERE, at module load, and not +// inside the first clocked case: clocked windows measure behaviour, never +// loading (AGENTS.md, Build & Test; the clocked-window rule of +// `check-test-source-alias`). The factory reaches every driver through a lazy +// `await import()`, and each of these drivers imports `@objectstack/core`, which +// this package's vitest config aliases to its SOURCE. So the first `create()` +// to get past the pool gate (`memory WITHOUT a pool`) used to pay a cold +// transform of core's whole module graph: 7-9 s of this file's ~9 s of clocked +// wall on a 4 vCPU dev container, against milliseconds of construction. The +// list is every driver a case here builds (`memory`; `sqlite`, `postgres` and +// `mysql` through `driver-sql`; `mongodb`). The module cache hands the factory +// these same instances, so nothing a case runs is different. No turso import: +// no case here gets past the pool gate on that arm. +import '@objectstack/driver-memory'; +import '@objectstack/driver-sql'; +import '@objectstack/driver-mongodb'; describe('#5714 — which driver arms read a declared `pool`', () => { it('names the two sqlite arms, `memory` and `turso` as unable to honour it (#5931 / #7243)', () => { diff --git a/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts b/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts index 184ca635d2e..11362b378a7 100644 --- a/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts +++ b/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts @@ -23,6 +23,27 @@ import { } from '../default-datasource-driver-factory.js'; import { isUnbuiltWorkspaceFailure } from '../connect-failure-remedy.js'; import { MissingDriverPackageError } from '../missing-driver-package-error.js'; +// [#23184] The drivers' first module load is paid HERE, at module load, and not +// inside the first clocked case: clocked windows measure behaviour, never +// loading (AGENTS.md, Build & Test; the clocked-window rule of +// `check-test-source-alias`). The factory reaches every driver through a lazy +// `await import()`, and each of these drivers imports `@objectstack/core`, which +// this package's vitest config aliases to its SOURCE. So the first case to +// build a real driver (the file-backed `sqlite-wasm` round trip) used to pay a +// cold transform of core's whole module graph: 7-9 s of this file's ~9.5 s of +// clocked wall on a 4 vCPU dev container, against about 0.1 s of round trip. +// The list is every driver the construction suites build; the module cache +// hands the factory these same instances, so nothing a case runs is different. +// ⛔ `@objectstack/driver-turso` stays OUT of this list: the turso +// missing-package case below stages its absence without `vi.resetModules()`, +// so it needs the factory's own lazy import to be that package's first. The +// `sqlite-wasm` and `mongodb` absence cases reset the module registry before +// they mock, so loading their packages here first is the same condition the +// construction suites already created for them. +import '@objectstack/driver-sql'; +import '@objectstack/driver-sqlite-wasm'; +import '@objectstack/driver-memory'; +import '@objectstack/driver-mongodb'; const factory = () => createDefaultDatasourceDriverFactory({ dev: false }); From d3c912af7274e7bd6a3aa9d0813910e900f4e156 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 15 Oct 2026 17:56:18 +0000 Subject: [PATCH 2/2] test(service-datasource): preload core and driver-sql, not the census-ledgered drivers The first cut side-effect-imported driver-memory and driver-mongodb at module top. check:driver-memory-census reds on any new binding of driver-memory (a ruled census), and check:test-source-alias reds on a new unaliased test import of driver-mongodb. Neither is the cost anyway: the 7-9 s is @objectstack/core's source transform, which every driver imports. So the files now preload @objectstack/core plus driver-sql (and driver-sqlite-wasm in the factory suite); driver-memory and driver-mongodb still load in their first case, at 0.2-0.5 s each. Claude-Session: https://claude.ai/code/session_017WLmd5in9RXu7AjyHR8fKQ Co-authored-by: Claude --- .../__tests__/datasource-pool-support.test.ts | 31 ++++++++------- .../default-datasource-driver-factory.test.ts | 38 ++++++++++--------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts b/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts index b0636afb69a..c3bfbb5df87 100644 --- a/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts +++ b/packages/services/service-datasource/src/__tests__/datasource-pool-support.test.ts @@ -65,22 +65,25 @@ import { import { DatasourceAdminService, type StoredDatasource } from '../datasource-admin-service.js'; import type { IDatasourceDriverFactory } from '../contracts/datasource-driver-factory.js'; import type { IDataDriver } from '@objectstack/spec/contracts'; -// [#23184] The drivers' first module load is paid HERE, at module load, and not -// inside the first clocked case: clocked windows measure behaviour, never -// loading (AGENTS.md, Build & Test; the clocked-window rule of +// [#23184] The first load of what the drivers stand on is paid HERE, at module +// load, and not inside the first clocked case: clocked windows measure +// behaviour, never loading (AGENTS.md, Build & Test; the clocked-window rule of // `check-test-source-alias`). The factory reaches every driver through a lazy -// `await import()`, and each of these drivers imports `@objectstack/core`, which -// this package's vitest config aliases to its SOURCE. So the first `create()` -// to get past the pool gate (`memory WITHOUT a pool`) used to pay a cold -// transform of core's whole module graph: 7-9 s of this file's ~9 s of clocked -// wall on a 4 vCPU dev container, against milliseconds of construction. The -// list is every driver a case here builds (`memory`; `sqlite`, `postgres` and -// `mysql` through `driver-sql`; `mongodb`). The module cache hands the factory -// these same instances, so nothing a case runs is different. No turso import: -// no case here gets past the pool gate on that arm. -import '@objectstack/driver-memory'; +// `await import()`, and every driver imports `@objectstack/core`, which this +// package's vitest config aliases to its SOURCE. So the first `create()` to get +// past the pool gate (`memory WITHOUT a pool`) used to pay a cold transform of +// core's whole module graph: 7-9 s of this file's ~9 s of clocked wall on a +// 4 vCPU dev container, against milliseconds of construction. `driver-sql` +// (knex; the `sqlite`, `postgres` and `mysql` arms) is the next 0.5-1.3 s. +// The module cache hands the drivers these same instances, so nothing a case +// runs is different. Two drivers are deliberately NOT listed and still load in +// their first case (0.2-0.5 s each once core is loaded): `driver-memory`, +// whose every module binding is a ruled census entry +// (`check:driver-memory-census`), and `driver-mongodb`, which this package's +// tests resolve through `dist/` only from the factory, so a test-file import +// would be a new unaliased artifact import (`check:test-source-alias`). +import '@objectstack/core'; import '@objectstack/driver-sql'; -import '@objectstack/driver-mongodb'; describe('#5714 — which driver arms read a declared `pool`', () => { it('names the two sqlite arms, `memory` and `turso` as unable to honour it (#5931 / #7243)', () => { diff --git a/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts b/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts index 11362b378a7..dcd3a6fa131 100644 --- a/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts +++ b/packages/services/service-datasource/src/__tests__/default-datasource-driver-factory.test.ts @@ -23,27 +23,31 @@ import { } from '../default-datasource-driver-factory.js'; import { isUnbuiltWorkspaceFailure } from '../connect-failure-remedy.js'; import { MissingDriverPackageError } from '../missing-driver-package-error.js'; -// [#23184] The drivers' first module load is paid HERE, at module load, and not -// inside the first clocked case: clocked windows measure behaviour, never -// loading (AGENTS.md, Build & Test; the clocked-window rule of +// [#23184] The first load of what the drivers stand on is paid HERE, at module +// load, and not inside the first clocked case: clocked windows measure +// behaviour, never loading (AGENTS.md, Build & Test; the clocked-window rule of // `check-test-source-alias`). The factory reaches every driver through a lazy -// `await import()`, and each of these drivers imports `@objectstack/core`, which -// this package's vitest config aliases to its SOURCE. So the first case to -// build a real driver (the file-backed `sqlite-wasm` round trip) used to pay a -// cold transform of core's whole module graph: 7-9 s of this file's ~9.5 s of +// `await import()`, and every driver imports `@objectstack/core`, which this +// package's vitest config aliases to its SOURCE. So the first case to build a +// real driver (the file-backed `sqlite-wasm` round trip) used to pay a cold +// transform of core's whole module graph: 7-9 s of this file's ~9.5 s of // clocked wall on a 4 vCPU dev container, against about 0.1 s of round trip. -// The list is every driver the construction suites build; the module cache -// hands the factory these same instances, so nothing a case runs is different. -// ⛔ `@objectstack/driver-turso` stays OUT of this list: the turso -// missing-package case below stages its absence without `vi.resetModules()`, -// so it needs the factory's own lazy import to be that package's first. The -// `sqlite-wasm` and `mongodb` absence cases reset the module registry before -// they mock, so loading their packages here first is the same condition the -// construction suites already created for them. +// `driver-sql` (knex, which `driver-sqlite-wasm` builds on) is the next +// 0.5-1.3 s. The module cache hands the drivers these same instances, so +// nothing a case runs is different. Three drivers are deliberately NOT listed: +// `driver-memory`, whose every module binding is a ruled census entry +// (`check:driver-memory-census`), and `driver-mongodb`, which this package's +// tests resolve through `dist/` only from the factory, so a test-file import +// would be a new unaliased artifact import (`check:test-source-alias`); each +// still loads in its first case (0.2-0.5 s once core is loaded). And ⛔ +// `driver-turso`, because the turso missing-package case below stages its +// absence WITHOUT `vi.resetModules()`, so the factory's own lazy import must be +// that package's first. The `sqlite-wasm` absence case resets the module +// registry before it mocks, so loading that package here first is the same +// condition the construction suites already created for it. +import '@objectstack/core'; import '@objectstack/driver-sql'; import '@objectstack/driver-sqlite-wasm'; -import '@objectstack/driver-memory'; -import '@objectstack/driver-mongodb'; const factory = () => createDefaultDatasourceDriverFactory({ dev: false });