fix(ordrestyring): preserve preflight database adapter (#40)
CI - Test & Build / Lint & Type Check (push) Canceled after 0s
CI - Test & Build / Backend Unit Tests (push) Canceled after 0s
CI - Test & Build / Frontend Build (push) Canceled after 0s
CI - Test & Build / Security Scan (push) Canceled after 0s
CI - Test & Build / E2E Tests (Playwright) (push) Canceled after 0s
CI - Test & Build / CI Summary (push) Canceled after 0s

* [verified] fix(ordrestyring): initialize database before preflight

* [verified] fix(ordrestyring): preserve promise pool preflight adapter

* test(ordrestyring): support pool-only service adapters

---------

Co-authored-by: alexpolo1 <[email protected]>
This commit is contained in:
Alex
2026-10-04 23:21:26 +02:00
committed by GitHub
co-authored by alexpolo1
parent b527bc1807
commit 68f06b773c
2 changed files with 18 additions and 2 deletions
@@ -14,6 +14,20 @@ describe('consumer read model safety contract', () => {
databaseService.pool = { execute: jest.fn().mockResolvedValue([[{ case_number: 'A' }]]) };
await expect(readModel.cases(['A'])).resolves.toEqual([{ case_number: 'A' }]);
});
test('keeps mysql promise pools on their promise execute adapter', async () => {
const execute = jest.fn().mockResolvedValue([[{ case_number: 'A' }]]);
const pool = { pool: { execute: jest.fn() }, execute, query: jest.fn() };
await expect(new OrdrestyringReadModel(pool, { env: {} }).cases(['A']))
.resolves.toEqual([{ case_number: 'A' }]);
expect(execute).toHaveBeenCalledTimes(1);
expect(pool.query).not.toHaveBeenCalled();
});
test('supports lightweight service wrappers that expose only pool.execute', async () => {
const execute = jest.fn().mockResolvedValue([[{ case_number: 'A' }]]);
await expect(new OrdrestyringReadModel({ pool: { execute } }, { env: {} }).cases(['A']))
.resolves.toEqual([{ case_number: 'A' }]);
expect(execute).toHaveBeenCalledTimes(1);
});
test('canonical default, domain override and invalid modes fail closed', async () => {
expect(model().mode('planning')).toBe('canonical');
expect(model([], { env: { ORDRESTYRING_READ_MODE: 'compare', ORDRESTYRING_READ_MODE_HISTORY: 'legacy' } }).mode('history')).toBe('legacy');
@@ -80,10 +80,12 @@ class OrdrestyringReadModel {
async rows(sql, params = []) {
if (this.connection && Object.prototype.hasOwnProperty.call(this.connection, 'pool')
&& typeof this.connection.query === 'function') {
&& typeof this.connection.query === 'function' && typeof this.connection.execute !== 'function') {
return this.connection.query(sql, params);
}
const connection = this.connection?.pool || this.connection;
const connection = typeof this.connection?.execute === 'function'
? this.connection
: this.connection?.pool || this.connection;
if (!connection) throw new Error('Ordrestyring canonical database unavailable');
if (connection.execute) {
const [rows] = await connection.execute(sql, params);