From 92edeeaf9f7f12b2305a2215bd3f986e5cf357b6 Mon Sep 17 00:00:00 2001 From: Studio Date: Sat, 28 Nov 2026 13:31:52 -0500 Subject: [PATCH 1/2] =?UTF-8?q?T-78:=20M1.1j=20=E2=80=94=20Persist=20Pass?= =?UTF-8?q?=203/5/6=20results=20into=20the=20security=20master:=20idempote?= =?UTF-8?q?nt=20PostgreSQL=20loader=20with=20permanent=20`listing=5Fid`s?= =?UTF-8?q?=20and=20`override`=20precedence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/stock/data-pipeline/README.md | 4 ++-- apps/stock/data-pipeline/src/security-master/persist.ts | 6 +++--- test/postgres/security-master-persist.test.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/stock/data-pipeline/README.md b/apps/stock/data-pipeline/README.md index f61e3161..0d31cee1 100644 --- a/apps/stock/data-pipeline/README.md +++ b/apps/stock/data-pipeline/README.md @@ -79,8 +79,8 @@ bun --env-file=/home/boki/.studio/test-env/stock-bot.env test test/postgres/secu - **Recorded baseline (`2026-11-28`, host PostgreSQL isolated `stock_bot_safety_*` schema, default `chunkSize = 5000`):** - Workload: `20,000` instruments, `20,000` listings, `60,000` provider mappings (`100,000` core rows; `140,000` total rows including `20,000` `instrument_identifier_history` and `20,000` `listing_symbol_history` rows). - - Observed end-to-end test wall time: `2.20s` (`2200.02ms`, reported by `bun test`; includes isolated schema migration, synthetic fixture construction, `persistSecurityMaster`, and `COUNT(*)` verification because `test/setup.ts` suppresses `console.info`). - - Throughput (conservative lower bound over full test wall time): `45,454` core rows/s (`100,000 / 2.20002s`), `63,636` total rows/s (`140,000 / 2.20002s`). + - Observed end-to-end test wall time: `2.36s` (`2359.01ms`, reported by `bun test`; includes isolated schema migration, synthetic fixture construction, `persistSecurityMaster`, and `COUNT(*)` verification). + - Throughput (conservative lower bound over full test wall time): `42,391` core rows/s (`100,000 / 2.35901s`), `59,347` total rows/s (`140,000 / 2.35901s`). ## Read-Only Source-Symbol Readers (`source-symbol-readers.ts`) `apps/stock/data-pipeline/src/security-master/source-symbol-readers.ts` adapts raw `eodSymbols`, `ibSymbols`, `qmSymbols`, `ceoSymbols`, and `eodSymbolChange` documents into deterministic Stage A (`StageASourceRecord`) and Stage B (`StageBEodListingInput`, `StageBIbContractInput`, `StageBTickerSourceInput`, `StageBSymbolChangeInput`) inputs via `readSecurityMasterSources`: diff --git a/apps/stock/data-pipeline/src/security-master/persist.ts b/apps/stock/data-pipeline/src/security-master/persist.ts index 5981f7f7..5fbce262 100644 --- a/apps/stock/data-pipeline/src/security-master/persist.ts +++ b/apps/stock/data-pipeline/src/security-master/persist.ts @@ -6,9 +6,9 @@ * schema, default `chunkSize = 5000`): * - Command: `bun --env-file=/home/boki/.studio/test-env/stock-bot.env test test/postgres/security-master-persist.test.ts` * - Workload: 20,000 instruments, 20,000 listings, 60,000 mappings (100,000 core rows; 140,000 total rows). - * - Observed end-to-end test wall time: 2.20s (2200.02ms, including schema setup, fixture generation, - * persistence, and COUNT(*) verification because `test/setup.ts` suppresses `console.info`). - * - Throughput (lower bound over full test wall time): 45,454 core rows/s, 63,636 total rows/s. + * - Observed end-to-end test wall time: 2.36s (2359.01ms, including schema setup, fixture generation, + * persistence, and COUNT(*) verification). + * - Throughput (lower bound over full test wall time): 42,391 core rows/s, 59,347 total rows/s. */ import type { DelistingChainResult, diff --git a/test/postgres/security-master-persist.test.ts b/test/postgres/security-master-persist.test.ts index ac5b0339..190aa890 100644 --- a/test/postgres/security-master-persist.test.ts +++ b/test/postgres/security-master-persist.test.ts @@ -1970,8 +1970,8 @@ describe.skipIf(!url)('persistSecurityMaster PostgreSQL integration', () => { expect(counts.listing).toBe(instrumentCount); expect(counts.provider_mapping).toBe(instrumentCount * 3); - console.info( - `[security-master-persist benchmark] ${instrumentCount} instruments, ${instrumentCount} listings, ${instrumentCount * 3} mappings (${totalAllRows} total rows) persisted in ${elapsedSec.toFixed(2)}s (${Math.round(totalCoreRows / elapsedSec)} core rows/s, ${Math.round(totalAllRows / elapsedSec)} total rows/s)` + process.stdout.write( + `[security-master-persist benchmark] ${instrumentCount} instruments, ${instrumentCount} listings, ${instrumentCount * 3} mappings (${totalAllRows} total rows) persisted in ${elapsedSec.toFixed(2)}s (${Math.round(totalCoreRows / elapsedSec)} core rows/s, ${Math.round(totalAllRows / elapsedSec)} total rows/s)\n` ); }, 120_000 From bc1dcf86a431db39b7cddc138d29aa5493d49776 Mon Sep 17 00:00:00 2001 From: Studio Date: Sat, 28 Nov 2026 13:38:23 -0500 Subject: [PATCH 2/2] T-78: tests --- ...urity-master-persist-benchmark-doc.test.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/unit/security-master-persist-benchmark-doc.test.ts diff --git a/test/unit/security-master-persist-benchmark-doc.test.ts b/test/unit/security-master-persist-benchmark-doc.test.ts new file mode 100644 index 00000000..2042fc23 --- /dev/null +++ b/test/unit/security-master-persist-benchmark-doc.test.ts @@ -0,0 +1,61 @@ +import { describe, expect, test } from 'bun:test'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +// Guards the recorded persistSecurityMaster benchmark baseline against drift: the README and the +// persist.ts module doc must quote the same measurement, and each quoted rows/s figure must equal +// rows / elapsed seconds for the documented workload. +const repoRoot = join(import.meta.dir, '..', '..'); +const readmePath = join(repoRoot, 'apps/stock/data-pipeline/README.md'); +const persistPath = join(repoRoot, 'apps/stock/data-pipeline/src/security-master/persist.ts'); +const benchmarkTestPath = join(repoRoot, 'test/postgres/security-master-persist.test.ts'); + +const CORE_ROWS = 100_000; // 20,000 instruments + 20,000 listings + 60,000 mappings +const TOTAL_ROWS = 140_000; // core + 20,000 identifier history + 20,000 symbol history + +function toNumber(text: string): number { + return Number(text.replace(/,/g, '')); +} + +function parseBaseline(doc: string) { + const wall = doc.match(/\(`?([\d.]+)ms/); + const core = doc.match(/([\d,]+)`? core rows\/s/); + const total = doc.match(/([\d,]+)`? total rows\/s/); + expect(wall).not.toBeNull(); + expect(core).not.toBeNull(); + expect(total).not.toBeNull(); + return { + elapsedMs: toNumber(wall![1]!), + coreRowsPerSec: toNumber(core![1]!), + totalRowsPerSec: toNumber(total![1]!), + }; +} + +describe('security-master persist benchmark baseline documentation', () => { + const readme = readFileSync(readmePath, 'utf8'); + const persistDoc = readFileSync(persistPath, 'utf8').split('*/')[0]!; + + test('README rows/s figures equal documented rows divided by recorded wall time', () => { + const { elapsedMs, coreRowsPerSec, totalRowsPerSec } = parseBaseline(readme); + + expect(coreRowsPerSec).toBe(Math.round(CORE_ROWS / (elapsedMs / 1000))); + expect(totalRowsPerSec).toBe(Math.round(TOTAL_ROWS / (elapsedMs / 1000))); + }); + + test('persist.ts module doc quotes the same baseline as the README', () => { + const fromReadme = parseBaseline(readme); + const fromDoc = parseBaseline(persistDoc); + + expect(fromDoc).toEqual(fromReadme); + }); + + test('benchmark result line is written to stdout, not the muted console.info', () => { + const source = readFileSync(benchmarkTestPath, 'utf8'); + const lineIndex = source.indexOf('[security-master-persist benchmark]'); + expect(lineIndex).toBeGreaterThan(-1); + + const preceding = source.slice(Math.max(0, lineIndex - 200), lineIndex); + expect(preceding).toContain('process.stdout.write('); + expect(preceding).not.toContain('console.info('); + }); +});