fix(core): own cache transports and accept cleanup reviews
This commit is contained in:
parent
bd9332b2f6
commit
b4ac6460ef
24 changed files with 504 additions and 97 deletions
|
|
@ -1,7 +1,11 @@
|
|||
import { expect, test } from 'bun:test';
|
||||
import { asValue, createContainer } from 'awilix';
|
||||
import { expect, mock, test } from 'bun:test';
|
||||
import type { PoolConfig } from 'pg';
|
||||
import { baseAppSchema } from '@stock-bot/config';
|
||||
import { appConfigSchema } from '../../libs/core/di/src/config/schemas';
|
||||
import { ServiceContainerBuilder } from '../../libs/core/di/src/container/builder';
|
||||
import type { ServiceDefinitions } from '../../libs/core/di/src/container/types';
|
||||
import { registerCacheServices } from '../../libs/core/di/src/registrations/cache.registration';
|
||||
|
||||
function configuration(enabled = true) {
|
||||
return baseAppSchema.parse({
|
||||
|
|
@ -42,8 +46,9 @@ for (const enabled of [true, false]) {
|
|||
.skipInitialization()
|
||||
.build();
|
||||
try {
|
||||
for (const name of ['cache', 'mongoClient', 'postgresClient'])
|
||||
for (const name of ['cache', 'mongoClient', 'postgresClient']) {
|
||||
expect(c.resolve(name)).toBeNull();
|
||||
}
|
||||
const config = c.resolve('config');
|
||||
expect(config.redis.enabled).toBe(false);
|
||||
expect(config.mongodb.enabled).toBe(false);
|
||||
|
|
@ -61,8 +66,9 @@ test('enable options do not override disabled configurations', async () => {
|
|||
.skipInitialization()
|
||||
.build();
|
||||
try {
|
||||
for (const name of ['cache', 'mongoClient', 'postgresClient'])
|
||||
for (const name of ['cache', 'mongoClient', 'postgresClient']) {
|
||||
expect(c.resolve(name)).toBeNull();
|
||||
}
|
||||
} finally {
|
||||
await c.dispose();
|
||||
}
|
||||
|
|
@ -106,7 +112,7 @@ test('PostgreSQL nondefault fields reach wire configuration and Mongo retains UR
|
|||
}
|
||||
});
|
||||
|
||||
test('flat QuestDB alias takes precedence without discarding credentials or schema settings', async () => {
|
||||
test('flat QuestDB alias and credentials reach the client; unsupported tuning is diagnosed', async () => {
|
||||
const c = await new ServiceContainerBuilder()
|
||||
.withConfig({
|
||||
...configuration(false),
|
||||
|
|
@ -123,6 +129,9 @@ test('flat QuestDB alias takes precedence without discarding credentials or sche
|
|||
} as never)
|
||||
.skipInitialization()
|
||||
.build();
|
||||
const logger = c.resolve('logger');
|
||||
const originalWarn = logger.warn;
|
||||
logger.warn = mock(() => {});
|
||||
try {
|
||||
expect(c.resolve('config').questdb).toMatchObject({
|
||||
influxPort: 29009,
|
||||
|
|
@ -131,7 +140,34 @@ test('flat QuestDB alias takes precedence without discarding credentials or sche
|
|||
user: 'fixture',
|
||||
password: 'fixture',
|
||||
});
|
||||
expect(c.resolve('questdbClient')!.configuration).toMatchObject({
|
||||
influxPort: 29009,
|
||||
user: 'fixture',
|
||||
password: 'fixture',
|
||||
});
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'QuestDB bufferSize/flushInterval are deprecated and have no effect; configure explicit writer batch options instead'
|
||||
);
|
||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
logger.warn = originalWarn;
|
||||
await c.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
test('default QuestDB compatibility settings do not produce tuning diagnostics', async () => {
|
||||
const c = await new ServiceContainerBuilder()
|
||||
.withConfig({ ...configuration(false), questdb: { enabled: true } } as never)
|
||||
.skipInitialization()
|
||||
.build();
|
||||
const logger = c.resolve('logger');
|
||||
const originalWarn = logger.warn;
|
||||
logger.warn = mock(() => {});
|
||||
try {
|
||||
expect(c.resolve('questdbClient')).not.toBeNull();
|
||||
expect(logger.warn).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
logger.warn = originalWarn;
|
||||
await c.dispose();
|
||||
}
|
||||
});
|
||||
|
|
@ -150,8 +186,9 @@ test('all-disabled default composition needs neither store settings nor connecti
|
|||
})
|
||||
.build();
|
||||
try {
|
||||
for (const name of ['cache', 'mongoClient', 'postgresClient', 'questdbClient'])
|
||||
for (const name of ['cache', 'mongoClient', 'postgresClient', 'questdbClient']) {
|
||||
expect(c.resolve(name)).toBeNull();
|
||||
}
|
||||
} finally {
|
||||
await c.dispose();
|
||||
}
|
||||
|
|
@ -193,11 +230,13 @@ test('Redis ACL username reaches cache and both queue connection settings withou
|
|||
new Response(child.stderr).text(),
|
||||
child.exited,
|
||||
]);
|
||||
if (code !== 0) throw new Error(`Redis transport probe failed: ${stderr}`);
|
||||
if (code !== 0) {
|
||||
throw new Error(`Redis transport probe failed: ${stderr}`);
|
||||
}
|
||||
const line = stdout.split('\n').find(line => line.startsWith('__redis_capture__'));
|
||||
expect(line).toBeDefined();
|
||||
const result = JSON.parse(line!.slice('__redis_capture__'.length));
|
||||
expect(result.captured).toHaveLength(2);
|
||||
expect(result.captured).toHaveLength(3);
|
||||
for (const config of [...result.captured, result.queue]) {
|
||||
expect(config).toMatchObject({
|
||||
host: 'redis.fixture.test',
|
||||
|
|
@ -206,3 +245,20 @@ test('Redis ACL username reaches cache and both queue connection settings withou
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('deprecated DI cache prefixes produce a diagnostic without echoing supplied values', () => {
|
||||
const logger = { warn: mock(() => {}) };
|
||||
// Registration validates the compatibility setting without constructing Redis transports.
|
||||
const container = createContainer<ServiceDefinitions>();
|
||||
container.register('logger', asValue(logger as unknown as ServiceDefinitions['logger']));
|
||||
const config = appConfigSchema.parse({
|
||||
redis: { enabled: true, keyPrefix: 'private-operator-prefix' },
|
||||
mongodb: { enabled: false, uri: 'mongodb://unused/test', database: 'test' },
|
||||
postgres: { enabled: false, database: 'test', user: 'test', password: 'fixture-only' },
|
||||
});
|
||||
registerCacheServices(container, config);
|
||||
expect(logger.warn).toHaveBeenCalledTimes(1);
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'Redis keyPrefix is deprecated at the DI boundary; service/global/proxy namespaces remain fixed'
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue