Clear final M0 bugs on master (T-5 verified, T-12, T-15, T-17)
This commit is contained in:
parent
ade0a3ef1d
commit
2ea7316af6
7 changed files with 148 additions and 17 deletions
4
.env
4
.env
|
|
@ -17,8 +17,8 @@ DATA_SERVICE_PORT=2001
|
||||||
WORKER_COUNT=1
|
WORKER_COUNT=1
|
||||||
WORKER_CONCURRENCY=2
|
WORKER_CONCURRENCY=2
|
||||||
|
|
||||||
WEBSHARE_API_KEY=y8ay534rcbybdkk3evnzmt640xxfhy7252ce2t98
|
WEBSHARE_API_KEY=
|
||||||
WEBSHARE_ROTATING_PROXY_URL=http://doimvbnb-rotate:w5fpiwrb9895@p.webshare.io:80/
|
WEBSHARE_ROTATING_PROXY_URL=
|
||||||
WEBSHARE_API_URL=https://proxy.webshare.io/api/v2/
|
WEBSHARE_API_URL=https://proxy.webshare.io/api/v2/
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@
|
||||||
"cachePrefix": "proxy:",
|
"cachePrefix": "proxy:",
|
||||||
"ttl": 3600,
|
"ttl": 3600,
|
||||||
"webshare": {
|
"webshare": {
|
||||||
"apiKey": "y8ay534rcbybdkk3evnzmt640xxfhy7252ce2t98",
|
"apiKey": "",
|
||||||
"apiUrl": "https://proxy.webshare.io/api/v2/"
|
"apiUrl": "https://proxy.webshare.io/api/v2/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -150,7 +150,7 @@
|
||||||
"name": "eod",
|
"name": "eod",
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"priority": 4,
|
"priority": 4,
|
||||||
"apiKey": "657fe003583a32.85708911",
|
"apiKey": "",
|
||||||
"baseUrl": "https://eodhistoricaldata.com/api",
|
"baseUrl": "https://eodhistoricaldata.com/api",
|
||||||
"tier": "free"
|
"tier": "free"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { hostname as osHostname, networkInterfaces } from 'node:os';
|
||||||
import type { StockAppConfig } from './schemas';
|
import type { StockAppConfig } from './schemas';
|
||||||
|
|
||||||
export type StockServiceName = 'dataIngestion' | 'dataPipeline' | 'webApi' | 'orchestrator';
|
export type StockServiceName = 'dataIngestion' | 'dataPipeline' | 'webApi' | 'orchestrator';
|
||||||
|
|
@ -532,9 +533,64 @@ function parseMongoTarget(uri?: string): ParsedMongoTarget {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLocalMachineHosts(): Set<string> {
|
||||||
|
const hosts = new Set<string>();
|
||||||
|
const rawHostname = osHostname().trim().toLowerCase().replace(/\.+$/, '');
|
||||||
|
if (rawHostname) {
|
||||||
|
hosts.add(rawHostname);
|
||||||
|
const shortName = rawHostname.split('.')[0];
|
||||||
|
if (shortName) {
|
||||||
|
hosts.add(shortName);
|
||||||
|
hosts.add(`${shortName}.local`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const ifaces = networkInterfaces();
|
||||||
|
for (const entries of Object.values(ifaces)) {
|
||||||
|
if (!entries) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry.address) {
|
||||||
|
const addr = entry.address.split('%')[0]?.trim().toLowerCase();
|
||||||
|
if (addr) {
|
||||||
|
hosts.add(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hosts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLocalMachineHost(host?: string): boolean {
|
||||||
|
if (!host) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isLoopbackHost(host)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const normalized = host
|
||||||
|
.trim()
|
||||||
|
.replace(/^\[|\]$/g, '')
|
||||||
|
.replace(/\.+$/, '')
|
||||||
|
.toLowerCase();
|
||||||
|
const localHosts = getLocalMachineHosts();
|
||||||
|
if (localHosts.has(normalized)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Also normalize numeric/decimal IPv4 spellings (e.g. hex or leading-zero LAN IP)
|
||||||
|
const numericOctets = parseNumericIpv4Octets(normalized) ?? parseDecimalIpv4Octets(normalized);
|
||||||
|
if (numericOctets !== null) {
|
||||||
|
const dotted = numericOctets.join('.');
|
||||||
|
if (localHosts.has(dotted)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function isQaMongoTargetHosts(target: ParsedMongoTarget): boolean {
|
function isQaMongoTargetHosts(target: ParsedMongoTarget): boolean {
|
||||||
return target.hosts.some(
|
return target.hosts.some(
|
||||||
entry => isLoopbackHost(entry.host) && (entry.port === undefined || entry.port === 27017)
|
entry => isLocalMachineHost(entry.host) && (entry.port === undefined || entry.port === 27017)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -543,7 +599,7 @@ function isQaMongoTarget(uri: string | undefined): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isQaPostgresTarget(pg: StockAppConfig['database']['postgres']): boolean {
|
function isQaPostgresTarget(pg: StockAppConfig['database']['postgres']): boolean {
|
||||||
return isLoopbackHost(pg.host) && pg.port === 5432 && pg.database === 'trading_bot';
|
return isLocalMachineHost(pg.host) && pg.port === 5432 && pg.database === 'trading_bot';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export const EOD_CONFIG = {
|
export const EOD_CONFIG = {
|
||||||
// API configuration
|
// API configuration
|
||||||
API_BASE_URL: 'https://eodhd.com/api/',
|
API_BASE_URL: 'https://eodhd.com/api/',
|
||||||
API_TOKEN: '657fe003583a32.85708911',
|
API_TOKEN: process.env.EOD_API_KEY ?? '',
|
||||||
};
|
};
|
||||||
|
|
@ -44,11 +44,21 @@ export function Operation(
|
||||||
if (!constructor.__operations) {
|
if (!constructor.__operations) {
|
||||||
constructor.__operations = [];
|
constructor.__operations = [];
|
||||||
}
|
}
|
||||||
constructor.__operations.push({
|
const methodKey = String(methodName);
|
||||||
name,
|
const existing = constructor.__operations.find(
|
||||||
method: String(methodName),
|
op => op.name === name && op.method === methodKey
|
||||||
batch: options?.batch,
|
);
|
||||||
});
|
if (existing) {
|
||||||
|
if (options?.batch !== undefined && existing.batch === undefined) {
|
||||||
|
existing.batch = options.batch;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
constructor.__operations.push({
|
||||||
|
name,
|
||||||
|
method: methodKey,
|
||||||
|
batch: options?.batch,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return descriptor;
|
return descriptor;
|
||||||
};
|
};
|
||||||
|
|
@ -82,11 +92,17 @@ export function QueueSchedule(
|
||||||
if (!constructor.__schedules) {
|
if (!constructor.__schedules) {
|
||||||
constructor.__schedules = [];
|
constructor.__schedules = [];
|
||||||
}
|
}
|
||||||
constructor.__schedules.push({
|
const operationKey = String(methodName);
|
||||||
operation: String(methodName),
|
const existingSchedule = constructor.__schedules.find(
|
||||||
cronPattern,
|
s => s.operation === operationKey && s.cronPattern === cronPattern
|
||||||
...options,
|
);
|
||||||
});
|
if (!existingSchedule) {
|
||||||
|
constructor.__schedules.push({
|
||||||
|
operation: operationKey,
|
||||||
|
cronPattern,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return descriptor;
|
return descriptor;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,26 @@ describe('Handler Decorators', () => {
|
||||||
expect(constructor.__schedules[1]).toMatchObject({ cronPattern: '0 0 * * *' });
|
expect(constructor.__schedules[1]).toMatchObject({ cronPattern: '0 0 * * *' });
|
||||||
expect(constructor.__schedules[2]).toMatchObject({ cronPattern: '0 0 * * 0' });
|
expect(constructor.__schedules[2]).toMatchObject({ cronPattern: '0 0 * * 0' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not register duplicate operation metadata when @Operation and @ScheduledOperation are both applied (T-17)', () => {
|
||||||
|
class DeduplicatedHandler {
|
||||||
|
@Operation('sync-all-exchanges')
|
||||||
|
@ScheduledOperation('sync-all-exchanges', '0 0 * * 0', {
|
||||||
|
priority: 10,
|
||||||
|
batch: { enabled: true, size: 25 },
|
||||||
|
})
|
||||||
|
async syncAllExchanges() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const constructor = DeduplicatedHandler as any;
|
||||||
|
expect(constructor.__operations).toHaveLength(1);
|
||||||
|
expect(constructor.__operations[0]).toEqual({
|
||||||
|
name: 'sync-all-exchanges',
|
||||||
|
method: 'syncAllExchanges',
|
||||||
|
batch: { enabled: true, size: 25 },
|
||||||
|
});
|
||||||
|
expect(constructor.__schedules).toHaveLength(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('decorator composition', () => {
|
describe('decorator composition', () => {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { hostname as osHostname, networkInterfaces } from 'node:os';
|
||||||
import { describe, expect, test } from 'bun:test';
|
import { describe, expect, test } from 'bun:test';
|
||||||
import { ConfigManager } from '@stock-bot/config';
|
import { ConfigManager } from '@stock-bot/config';
|
||||||
import { ServiceContainerBuilder } from '@stock-bot/di';
|
import { ServiceContainerBuilder } from '@stock-bot/di';
|
||||||
|
|
@ -299,6 +300,44 @@ describe('Environment safety & multi-env isolation', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('blocks QA MongoDB and PostgreSQL when targeted via machine hostname or local LAN IP (T-15)', () => {
|
||||||
|
const localHost = osHostname().trim();
|
||||||
|
if (localHost) {
|
||||||
|
const mongoByHostname = makeConfig({
|
||||||
|
environment: 'development',
|
||||||
|
mongoUri: `mongodb://trading_admin:pass@${localHost}:27017/stock`,
|
||||||
|
mongoDatabase: 'stock',
|
||||||
|
});
|
||||||
|
expect(() => assertEnvironmentSafety(mongoByHostname, 'dataIngestion', {})).toThrow(
|
||||||
|
/cannot open a writable MongoDB connection to QA MongoDB/
|
||||||
|
);
|
||||||
|
|
||||||
|
const pgByHostname = makeConfig({
|
||||||
|
environment: 'development',
|
||||||
|
pgHost: localHost,
|
||||||
|
pgPort: 5432,
|
||||||
|
pgDatabase: 'trading_bot',
|
||||||
|
});
|
||||||
|
expect(() => assertEnvironmentSafety(pgByHostname, 'dataPipeline', {})).toThrow(
|
||||||
|
/cannot target QA PostgreSQL/
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lanIpv4 = Object.values(networkInterfaces())
|
||||||
|
.flatMap(list => list ?? [])
|
||||||
|
.find(iface => iface.family === 'IPv4' && !iface.internal)?.address;
|
||||||
|
if (lanIpv4) {
|
||||||
|
const mongoByLanIp = makeConfig({
|
||||||
|
environment: 'development',
|
||||||
|
mongoUri: `mongodb://trading_admin:pass@${lanIpv4}:27017/stock`,
|
||||||
|
mongoDatabase: 'stock',
|
||||||
|
});
|
||||||
|
expect(() => assertEnvironmentSafety(mongoByLanIp, 'dataIngestion', {})).toThrow(
|
||||||
|
/cannot open a writable MongoDB connection to QA MongoDB/
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('blocks multi-host MongoDB seed lists targeting QA loopback :27017 for dataIngestion and dataPipeline', () => {
|
test('blocks multi-host MongoDB seed lists targeting QA loopback :27017 for dataIngestion and dataPipeline', () => {
|
||||||
const qaFirstIngestion = makeConfig({
|
const qaFirstIngestion = makeConfig({
|
||||||
environment: 'development',
|
environment: 'development',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue