T-210: M2.3s — Implement MarketDataStore.macroAsOf, crossSection, QuestDB fx('1m'), and copilot 1m routing

This commit is contained in:
Studio 2026-12-04 15:23:16 -05:00
parent c60365237f
commit 5e255d7e30
8 changed files with 587 additions and 37 deletions

View file

@ -282,6 +282,60 @@ function parseQuestDbPort(raw: string): number {
return port;
}
function hasConflictingUrlSslSetting(rawUrl: string, explicitSsl: boolean): boolean {
let parsed: URL;
try {
parsed = new URL(rawUrl);
} catch {
return false;
}
for (const [rawKey, rawValue] of parsed.searchParams.entries()) {
const key = rawKey.toLowerCase();
const value = rawValue.trim().toLowerCase();
if (key === 'sslmode') {
if (value === 'disable') {
if (explicitSsl) {
return true;
}
} else if (
value === 'require' ||
value === 'verify-ca' ||
value === 'verify-full' ||
value === 'no-verify'
) {
if (!explicitSsl) {
return true;
}
} else {
// `allow`, `prefer`, or any unrecognized sslmode conflicts with an explicit boolean override.
return true;
}
} else if (key === 'ssl') {
if (value === 'false' || value === '0') {
if (explicitSsl) {
return true;
}
} else if (value === 'true' || value === '1') {
if (!explicitSsl) {
return true;
}
} else {
return true;
}
} else if (
(key === 'sslcert' || key === 'sslkey' || key === 'sslrootcert') &&
value.length > 0 &&
!explicitSsl
) {
return true;
}
}
return false;
}
function parseQuestDbConfig(data: {
readonly [ENV_QUESTDB_URL]?: string;
readonly [ENV_QUESTDB_HOST]?: string;
@ -320,6 +374,12 @@ function parseQuestDbConfig(data: {
);
}
const url = parsePgWireUrl(rawUrl, ENV_QUESTDB_URL);
if (ssl !== undefined && hasConflictingUrlSslSetting(url, ssl)) {
throw new ResearchCopilotHostConfigError(
ENV_QUESTDB_SSL,
`Conflicting configuration variable "${ENV_QUESTDB_SSL}": conflicts with SSL query parameters in "${ENV_QUESTDB_URL}".`
);
}
return {
url,
...(ssl !== undefined ? { ssl } : {}),

View file

@ -1242,20 +1242,73 @@ describe('runResearchCopilotStdioHost', () => {
ssl: false,
});
// 4. Rejects conflicting URL + host, partial port-without-host, bad port, bad ssl, unknown var.
// 4. Rejects conflicting URL + host, partial port-without-host, bad port, bad ssl, unknown var,
// and conflicting URL SSL query parameters vs RESEARCH_MCP_QUESTDB_SSL without leaking secrets.
const invalidEnvs: Array<Record<string, string>> = [
{ RESEARCH_MCP_QUESTDB_URL: questUrl, RESEARCH_MCP_QUESTDB_HOST: '10.0.0.51' },
{ RESEARCH_MCP_QUESTDB_PG_PORT: '8812' },
{ RESEARCH_MCP_QUESTDB_HOST: '10.0.0.51', RESEARCH_MCP_QUESTDB_PG_PORT: '99999' },
{ RESEARCH_MCP_QUESTDB_HOST: '10.0.0.51', RESEARCH_MCP_QUESTDB_SSL: 'maybe' },
{ RESEARCH_MCP_QUESTDB_UNKNOWN: '1' },
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=disable`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=require`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?ssl=false`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?ssl=true`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=prefer`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslrootcert=/etc/ssl/ca.pem`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
},
];
for (const override of invalidEnvs) {
expect(() => parseResearchCopilotHostConfig(buildValidEnv(override))).toThrow(
ResearchCopilotHostConfigError
);
let caughtInvalid: unknown;
try {
parseResearchCopilotHostConfig(buildValidEnv(override));
} catch (err) {
caughtInvalid = err;
}
expect(caughtInvalid).toBeInstanceOf(ResearchCopilotHostConfigError);
expect((caughtInvalid as Error).message).not.toContain(questSecret);
expect((caughtInvalid as Error).message).not.toContain(questUrl);
}
// Compatible URL SSL query params + matching RESEARCH_MCP_QUESTDB_SSL are accepted.
const consistentSslEnable = parseResearchCopilotHostConfig(
buildValidEnv({
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=require`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
})
);
expect(consistentSslEnable.questdb).toEqual({
url: `${questUrl}?sslmode=require`,
ssl: true,
});
const consistentSslDisable = parseResearchCopilotHostConfig(
buildValidEnv({
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=disable`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
})
);
expect(consistentSslDisable.questdb).toEqual({
url: `${questUrl}?sslmode=disable`,
ssl: false,
});
// 5. Redacts QuestDB URL / password on openStore and cleanup errors.
for (const cfg of [urlConfig, hostFullConfig]) {
let caught: unknown;