From 1720e45f70c700c353ff70ebd9f42afc398da363 Mon Sep 17 00:00:00 2001 From: Studio Date: Fri, 27 Nov 2026 14:07:31 -0500 Subject: [PATCH] T-29: lint:check fails on existing issues, so `bun run check` (M0 exit criterion 1) can't go green --- apps/stock/config/src/env-safety.ts | 6 +-- .../src/services/research-agents.service.ts | 44 ++++++++++++------- libs/core/cache/test/redis-cache.test.ts | 4 +- .../shutdown/test/shutdown-dispose.test.ts | 4 +- libs/data/mongodb/src/client.ts | 16 +++---- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/apps/stock/config/src/env-safety.ts b/apps/stock/config/src/env-safety.ts index e70fd1c9..2b17c4c9 100644 --- a/apps/stock/config/src/env-safety.ts +++ b/apps/stock/config/src/env-safety.ts @@ -167,8 +167,8 @@ const VALID_IPV6_ZONE_ID = /^[a-z0-9._~-]+$/i; // Any URL authority/path/query/fragment delimiter, whitespace, or control char inside a // decoded MongoDB seed host would be re-interpreted by ServerDescription.hostAddress's // WHATWG URL re-parse (e.g., "localhost%2f:27018" -> "localhost/:27018" -> localhost:27017). -const FORBIDDEN_MONGO_HOST_CHARS = /[/?#@:\\[\],\s\x00-\x1f\x7f]/; -const FORBIDDEN_MONGO_IPV6_HOST_CHARS = /[/?#@\\[\],\s\x00-\x1f\x7f]/; +const FORBIDDEN_MONGO_HOST_CHARS = /[/?#@:\\[\],\s]/; +const FORBIDDEN_MONGO_IPV6_HOST_CHARS = /[/?#@\\[\],\s]/; function isValidIpv6WithZoneId(host: string): boolean { const zoneIdx = host.indexOf('%'); @@ -216,7 +216,7 @@ function decodeMongoHost(rawHost: string, isBracketedIpv6 = false): string { const forbiddenChars = isBracketedIpv6 ? FORBIDDEN_MONGO_IPV6_HOST_CHARS : FORBIDDEN_MONGO_HOST_CHARS; - if (forbiddenChars.test(current)) { + if (hasAsciiControlChar(current) || forbiddenChars.test(current)) { throw new Error(`Safety guard: invalid characters in MongoDB host "${rawHost}".`); } return current.toLowerCase(); diff --git a/apps/stock/web-api/src/services/research-agents.service.ts b/apps/stock/web-api/src/services/research-agents.service.ts index 689a698b..7b303176 100644 --- a/apps/stock/web-api/src/services/research-agents.service.ts +++ b/apps/stock/web-api/src/services/research-agents.service.ts @@ -328,14 +328,17 @@ export class ResearchAgentsService { const url = new URL(request.url); const path = url.pathname; const project = /^\/api\/v2\/research-projects\/([^/]+)(?:\/|$)/.exec(path); - if (project && !allowedProjectIds.includes(project[1]!.toLowerCase())) { - return deny(); + if (project) { + const projectId = project[1]; + if (!projectId || !allowedProjectIds.includes(projectId.toLowerCase())) { + return deny(); + } } if (request.method === 'GET' || request.method === 'HEAD') { const narrative = /^\/api\/v2\/(hypotheses|analysis-artifacts)\/([^/]+)(?:\/|$)/.exec(path); if (narrative) { - const narrativeId = narrative[2]!; - if (!strictUuid.test(narrativeId)) { + const narrativeId = narrative[2]; + if (!narrativeId || !strictUuid.test(narrativeId)) { return deny(); } const table = narrative[1] === 'hypotheses' ? 'research_hypotheses' : 'analysis_artifacts'; @@ -347,21 +350,28 @@ export class ResearchAgentsService { } } const backtest = /^\/api\/v2\/backtests\/([^/]+)(?:\/|$)/.exec(path); - if (backtest && !grantedBacktestIds.includes(backtest[1]!.toLowerCase())) { - return deny(); + if (backtest) { + const backtestId = backtest[1]; + if (!backtestId || !grantedBacktestIds.includes(backtestId.toLowerCase())) { + return deny(); + } } if (path === '/api/v2/experiments/compare') { const leftIds = url.searchParams.getAll('leftId'); const rightIds = url.searchParams.getAll('rightId'); + const leftId = leftIds[0]; + const rightId = rightIds[0]; if ( leftIds.length !== 1 || rightIds.length !== 1 || - !strictUuid.test(leftIds[0]!) || - !strictUuid.test(rightIds[0]!) + !leftId || + !rightId || + !strictUuid.test(leftId) || + !strictUuid.test(rightId) ) { return deny(); } - const uniqueIds = [...new Set([leftIds[0]!.toLowerCase(), rightIds[0]!.toLowerCase()])]; + const uniqueIds = [...new Set([leftId.toLowerCase(), rightId.toLowerCase()])]; const rows = ( await this.database.query( 'SELECT id,submission_principal FROM research_experiments WHERE id=ANY($1::uuid[])', @@ -387,8 +397,8 @@ export class ResearchAgentsService { const experiment = /^\/api\/v2\/experiments\/(walk-forward\/|validation\/)?([^/]+)(?:\/|$)/.exec(path); if (experiment) { - const experimentId = experiment[2]!; - if (!strictUuid.test(experimentId)) { + const experimentId = experiment[2]; + if (!experimentId || !strictUuid.test(experimentId)) { return deny(); } const table = @@ -405,8 +415,8 @@ export class ResearchAgentsService { } const run = /^\/api\/v2\/runs\/([^/]+)(?:\/|$)/.exec(path); if (run) { - const runId = run[1]!; - if (!strictUuid.test(runId)) { + const runId = run[1]; + if (!runId || !strictUuid.test(runId)) { return deny(); } const owned = ( @@ -418,8 +428,8 @@ export class ResearchAgentsService { } const strategy = /^\/api\/v2\/strategies\/([^/]+)(?:\/|$)/.exec(path); if (strategy) { - const strategyId = strategy[1]!; - if (!strictUuid.test(strategyId)) { + const strategyId = strategy[1]; + if (!strategyId || !strictUuid.test(strategyId)) { return deny(); } const permittedStrategy = ( @@ -439,8 +449,8 @@ export class ResearchAgentsService { } const strategyVersion = /^\/api\/v2\/strategy-versions\/([^/]+)(?:\/|$)/.exec(path); if (strategyVersion) { - const versionId = strategyVersion[1]!; - if (!strictUuid.test(versionId)) { + const versionId = strategyVersion[1]; + if (!versionId || !strictUuid.test(versionId)) { return deny(); } const permittedVersion = ( diff --git a/libs/core/cache/test/redis-cache.test.ts b/libs/core/cache/test/redis-cache.test.ts index e93ce530..3284e948 100644 --- a/libs/core/cache/test/redis-cache.test.ts +++ b/libs/core/cache/test/redis-cache.test.ts @@ -42,7 +42,9 @@ describe.skipIf(!testRedisUrl)('RedisCache', () => { }); afterEach(async () => { - if (!cache) return; + if (!cache) { + return; + } try { await cache.clear(); } finally { diff --git a/libs/core/shutdown/test/shutdown-dispose.test.ts b/libs/core/shutdown/test/shutdown-dispose.test.ts index 0e9c02ba..2eb336d4 100644 --- a/libs/core/shutdown/test/shutdown-dispose.test.ts +++ b/libs/core/shutdown/test/shutdown-dispose.test.ts @@ -3,9 +3,9 @@ import { Shutdown } from '../src/shutdown'; // These tests use the real `process` listener registry (no stubs) because the // regression being guarded is listeners leaking across test files in one bun process. -const SIGNALS = ['SIGTERM', 'SIGINT'] as const; +type TrackedSignal = 'SIGTERM' | 'SIGINT'; -function listenerCounts(): Record<(typeof SIGNALS)[number], number> { +function listenerCounts(): Record { return { SIGTERM: process.listenerCount('SIGTERM'), SIGINT: process.listenerCount('SIGINT'), diff --git a/libs/data/mongodb/src/client.ts b/libs/data/mongodb/src/client.ts index 85007288..b06e91fb 100644 --- a/libs/data/mongodb/src/client.ts +++ b/libs/data/mongodb/src/client.ts @@ -249,7 +249,7 @@ export class MongoDBClient { cursor.next().then( doc => { - if (doc == null) { + if (doc === null || doc === undefined) { readInProgress = false; closeCursor().then( () => { @@ -279,7 +279,7 @@ export class MongoDBClient { this.destroy(err instanceof Error ? err : new Error(String(err))); return; } - if (output == null) { + if (output === null || output === undefined) { readNext(); return; } @@ -542,10 +542,10 @@ export class MongoDBClient { if (typeof fn !== 'function') { throw new TypeError('Cursor does not implement "map"'); } - let receiver: unknown; + const receiverRef: { current: unknown } = { current: undefined }; const guardedTransform = typeof transform === 'function' - ? (doc: unknown) => transform.call(receiver, doc) + ? (doc: unknown) => transform.call(receiverRef.current, doc) : transform; const mapped = fn.call(cursor, guardedTransform); const result = @@ -554,7 +554,7 @@ export class MongoDBClient { : mapped && typeof mapped === 'object' ? this.wrapReadOnlyCursor(mapped as object) : mapped; - receiver = result; + receiverRef.current = result; return result; }, clone: () => { @@ -751,17 +751,17 @@ export class MongoDBClient { return wrapped; }, map: (transform: (doc: T) => TMapped) => { - let receiver: unknown; + const receiverRef: { current: unknown } = { current: undefined }; const guardedTransform = typeof transform === 'function' - ? (doc: T) => transform.call(receiver, doc) + ? (doc: T) => transform.call(receiverRef.current, doc) : transform; const mapped = cursor.map(guardedTransform); const result = mapped === (cursor as unknown) ? wrapped : this.wrapReadOnlyAggregationCursor(mapped as unknown as AggregationCursor); - receiver = result; + receiverRef.current = result; return result; }, clone: () => this.wrapReadOnlyAggregationCursor(cursor.clone()),