diff --git a/README.md b/README.md index 931d0a4a..004c7e61 100644 --- a/README.md +++ b/README.md @@ -727,6 +727,9 @@ be recreated for changed port bindings to take effect. Routine exchange/symbol/provider-mapping syncs are non-destructive. Legacy `clearFirst: true` requests are rejected; scheduled exchange syncs no longer reset data. +When upgrading a long-lived Dragonfly/BullMQ instance from an earlier release, remove any +stale repeatable IB sync jobs left in the ingestion queue so old repeat schedules do not +keep firing after scheduled jobs default off. The transactional sync paths share one checked-out PostgreSQL connection and one transaction-scoped advisory lock. SQL errors roll back the whole batch and sync status, and existing curated exchange/provider mappings are preserved. Do not add pooled diff --git a/apps/stock/data-pipeline/src/security-master/instrument-stage-a.ts b/apps/stock/data-pipeline/src/security-master/instrument-stage-a.ts index c667bb54..f840113e 100644 --- a/apps/stock/data-pipeline/src/security-master/instrument-stage-a.ts +++ b/apps/stock/data-pipeline/src/security-master/instrument-stage-a.ts @@ -179,8 +179,8 @@ export function matchInstrumentsStageA( for (let i = 0; i < records.length; i++) { const record = records[i]; - if (record === undefined) { - continue; + if (record === undefined || record === null || typeof record !== 'object') { + throw new TypeError(`Invalid Stage A record at index ${i}: expected a record object`); } if (!isStageASource(record.source)) { throw new Error( @@ -243,13 +243,15 @@ export function matchInstrumentsStageA( const normalizedCusip = normalizeCode(record.cusip); if (normalizedCusip !== null) { const normalizedCountry = normalizeCode(record.country); - let derivedCountry: NorthAmericaCountry | null = null; - if (normalizedCountry !== null) { - derivedCountry = isNorthAmericaCountry(normalizedCountry) ? normalizedCountry : null; - } else { - const isinPrefix = resolved.isin.slice(0, 2); - derivedCountry = isNorthAmericaCountry(isinPrefix) ? isinPrefix : null; - } + const isinPrefix = resolved.isin.slice(0, 2); + // For US/CA ISINs, the ISIN prefix is the authoritative issuer country so interlisted + // shares carrying a listing country (e.g. CA-issued SHOP on NYSE with country 'US') + // are not quarantined as false isin_cusip_mismatch conflicts. + const derivedCountry: NorthAmericaCountry | null = isNorthAmericaCountry(isinPrefix) + ? isinPrefix + : normalizedCountry !== null && isNorthAmericaCountry(normalizedCountry) + ? normalizedCountry + : null; if (derivedCountry !== null) { const derivedIsin = cusipToIsin(normalizedCusip, derivedCountry); diff --git a/package.json b/package.json index dfc99bdc..0e2a41b8 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,9 @@ "test:e2e:install": "playwright install chromium", "test:libs": "turbo run test --filter='./libs/**'", "test:apps": "turbo run test --filter=./apps/*/*", - "lint": "eslint apps/stock libs tools --ext .ts,.tsx", - "lint:fix": "eslint apps/stock libs tools --ext .ts,.tsx --fix", - "lint:check": "eslint apps/stock libs tools --ext .ts,.tsx --max-warnings 0", + "lint": "eslint apps/stock libs tools test --ext .ts,.tsx", + "lint:fix": "eslint apps/stock libs tools test --ext .ts,.tsx --fix", + "lint:check": "eslint apps/stock libs tools test --ext .ts,.tsx --max-warnings 0", "lint:apps": "eslint apps --ext .ts,.tsx", "lint:libs": "eslint libs --ext .ts,.tsx", "format": "./scripts/format.sh", diff --git a/test/integration/monitoring-readiness-ui.test.tsx b/test/integration/monitoring-readiness-ui.test.tsx index de94d682..19e16f22 100644 --- a/test/integration/monitoring-readiness-ui.test.tsx +++ b/test/integration/monitoring-readiness-ui.test.tsx @@ -69,8 +69,8 @@ afterEach(async () => { afterAll(() => { for (const key of keys) { const descriptor = previous.get(key); - if (descriptor) Object.defineProperty(globalThis, key, descriptor); - else Reflect.deleteProperty(globalThis, key); + if (descriptor) {Object.defineProperty(globalThis, key, descriptor);} + else {Reflect.deleteProperty(globalThis, key);} } browser.happyDOM.abort(); }); diff --git a/test/integration/monitoring-readiness.test.ts b/test/integration/monitoring-readiness.test.ts index 59b7e374..97be47a5 100644 --- a/test/integration/monitoring-readiness.test.ts +++ b/test/integration/monitoring-readiness.test.ts @@ -281,7 +281,7 @@ test('worker count inspection failure is unknown at the queue adapter boundary, getDelayed: empty, isPaused: async () => false, getWorkers: async () => { - if (workers === undefined) throw new Error('worker inspection unavailable'); + if (workers === undefined) {throw new Error('worker inspection unavailable');} return workers; }, }; diff --git a/test/integration/navigation.test.tsx b/test/integration/navigation.test.tsx index 976378ca..2e1993a8 100644 --- a/test/integration/navigation.test.tsx +++ b/test/integration/navigation.test.tsx @@ -10,7 +10,7 @@ test('the shared desktop/mobile menu advertises working workflows only', () => { item.href, ...(item.children?.map(child => child.href) ?? []), ]); - for (const href of ['/portfolio', '/analytics', '/settings']) expect(hrefs).not.toContain(href); + for (const href of ['/portfolio', '/analytics', '/settings']) {expect(hrefs).not.toContain(href);} for (const href of [ '/strategies', '/backtests', @@ -20,7 +20,7 @@ test('the shared desktop/mobile menu advertises working workflows only', () => { '/symbols', '/system/monitoring', ]) - expect(hrefs).toContain(href); + {expect(hrefs).toContain(href);} }); for (const name of ['Portfolio', 'Analytics', 'Settings']) { test(`${name} direct-page fallback explains availability and links to existing analytics`, () => { diff --git a/test/integration/research-http-transport.test.ts b/test/integration/research-http-transport.test.ts index c5eb8a2e..382ddbb7 100644 --- a/test/integration/research-http-transport.test.ts +++ b/test/integration/research-http-transport.test.ts @@ -12,8 +12,8 @@ beforeAll(async () => { ({ requestJson } = await import('../../apps/stock/web-app/src/lib/requestJson')); }); afterAll(() => { - if (original) Object.defineProperty(globalThis, 'window', original); - else Reflect.deleteProperty(globalThis, 'window'); + if (original) {Object.defineProperty(globalThis, 'window', original);} + else {Reflect.deleteProperty(globalThis, 'window');} browser.happyDOM.abort(); }); const errors = { @@ -23,7 +23,7 @@ const errors = { failureLabel: 'failed', }; const parse = (body: unknown) => { - if (body !== 42) throw new Error('wrong identity'); + if (body !== 42) {throw new Error('wrong identity');} return body; }; function respond(body: string, status = 200) { diff --git a/test/integration/strategy-state-copy.test.ts b/test/integration/strategy-state-copy.test.ts index d862d619..56b64098 100644 --- a/test/integration/strategy-state-copy.test.ts +++ b/test/integration/strategy-state-copy.test.ts @@ -58,6 +58,7 @@ test('both copying paths reject lossy state without reading getters, even when f new Date(), Object.create(null), Object.create({ x: 1 }), + // eslint-disable-next-line no-sparse-arrays [, 1], [undefined], extraArrayKey, @@ -69,9 +70,9 @@ test('both copying paths reject lossy state without reading getters, even when f cyclic, ]; for (const copy of [stateCopy, frozenStateCopy]) { - for (const value of invalid) expect(() => copy(value)).toThrow(); + for (const value of invalid) {expect(() => copy(value)).toThrow();} for (const value of [accessor, arrayAccessor, cyclic]) - expect(() => copy(Object.freeze(value))).toThrow(); + {expect(() => copy(Object.freeze(value))).toThrow();} } expect(reads).toBe(0); }); diff --git a/test/unit/mongodb-read-only.test.ts b/test/unit/mongodb-read-only.test.ts index c4e5c4df..27e94434 100644 --- a/test/unit/mongodb-read-only.test.ts +++ b/test/unit/mongodb-read-only.test.ts @@ -781,7 +781,9 @@ describe('MongoDBClient read-only mode (offline)', () => { if (mode === 'next') { while (true) { const item = await (mappedCursor.next as () => Promise)(); - if (item == null) break; + if (item === null || item === undefined) { + break; + } results.push(item); } } else if (mode === 'toArray') { diff --git a/test/unit/security-master-instrument-stage-a.test.ts b/test/unit/security-master-instrument-stage-a.test.ts index e888dc15..f793889f 100644 --- a/test/unit/security-master-instrument-stage-a.test.ts +++ b/test/unit/security-master-instrument-stage-a.test.ts @@ -300,6 +300,49 @@ describe('security master Pass 3 Stage A instrument matcher', () => { assertConservationAndSchema(result, 5); }); + test('rejects sparse input arrays instead of silently skewing stats (T-54)', () => { + const sparse = new Array(2) as unknown as Parameters[0]; + sparse[1] = { + source: 'eod', + sourceId: 'AAPL.US', + isin: 'US0378331005', + cusip: '037833100', + country: 'US', + }; + expect(() => matchInstrumentsStageA(sparse)).toThrow(TypeError); + }); + + test('does not quarantine interlisted US/CA shares when listing country differs from issuer country (T-55)', () => { + const result = matchInstrumentsStageA([ + { + source: 'eod', + sourceId: 'SHOP.TO', + isin: 'CA82509L1076', + cusip: '82509L107', + country: 'CA', + currency: 'CAD', + name: 'Shopify Inc.', + }, + { + source: 'eod', + sourceId: 'SHOP.US', + isin: 'CA82509L1076', + cusip: '82509L107', + country: 'US', + currency: 'USD', + name: 'Shopify Inc.', + }, + ]); + + expect(result.conflicts).toEqual([]); + expect(result.unresolved).toEqual([]); + expect(result.instruments).toHaveLength(1); + expect(result.instruments[0]?.primaryIsin).toBe('CA82509L1076'); + expect(result.instruments[0]?.issuerCountry).toBe('CA'); + expect(result.instruments[0]?.members.map(m => m.sourceId)).toEqual(['SHOP.TO', 'SHOP.US']); + assertConservationAndSchema(result, 2); + }); + test('quarantines isin_cusip_mismatch and duplicate_source_id without joining any instrument', () => { const result = matchInstrumentsStageA([ // Explicit CA country mismatch