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:31:29 -05:00
parent 5e255d7e30
commit 373936c312
6 changed files with 168 additions and 129 deletions

View file

@ -282,7 +282,12 @@ function parseQuestDbPort(raw: string): number {
return port;
}
function hasConflictingUrlSslSetting(rawUrl: string, explicitSsl: boolean): boolean {
function isQuestDbUrlTlsParamKey(rawKey: string): boolean {
const key = rawKey.trim().toLowerCase();
return key === 'uselibpqcompat' || key === 'ssl' || key.startsWith('ssl');
}
function hasQuestDbUrlTlsOptions(rawUrl: string): boolean {
let parsed: URL;
try {
parsed = new URL(rawUrl);
@ -290,45 +295,8 @@ function hasConflictingUrlSslSetting(rawUrl: string, explicitSsl: boolean): bool
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
) {
for (const [rawKey] of parsed.searchParams.entries()) {
if (isQuestDbUrlTlsParamKey(rawKey)) {
return true;
}
}
@ -374,10 +342,10 @@ function parseQuestDbConfig(data: {
);
}
const url = parsePgWireUrl(rawUrl, ENV_QUESTDB_URL);
if (ssl !== undefined && hasConflictingUrlSslSetting(url, ssl)) {
if (ssl !== undefined && hasQuestDbUrlTlsOptions(url)) {
throw new ResearchCopilotHostConfigError(
ENV_QUESTDB_SSL,
`Conflicting configuration variable "${ENV_QUESTDB_SSL}": conflicts with SSL query parameters in "${ENV_QUESTDB_URL}".`
`Conflicting configuration variable "${ENV_QUESTDB_SSL}": cannot be combined with TLS/SSL query parameters in "${ENV_QUESTDB_URL}". Configure TLS in either the URL or "${ENV_QUESTDB_SSL}", not both.`
);
}
return {

View file

@ -1243,17 +1243,29 @@ describe('runResearchCopilotStdioHost', () => {
});
// 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.
// and any URL TLS/SSL query parameters combined with 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=no-verify`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=disable`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=disable`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=require`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=require`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
@ -1262,6 +1274,10 @@ describe('runResearchCopilotStdioHost', () => {
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?ssl=false`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?ssl=false`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?ssl=true`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
@ -1274,6 +1290,10 @@ describe('runResearchCopilotStdioHost', () => {
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslrootcert=/etc/ssl/ca.pem`,
RESEARCH_MCP_QUESTDB_SSL: 'false',
},
{
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?uselibpqcompat=true`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
},
];
for (const override of invalidEnvs) {
let caughtInvalid: unknown;
@ -1287,27 +1307,34 @@ describe('runResearchCopilotStdioHost', () => {
expect((caughtInvalid as Error).message).not.toContain(questUrl);
}
// Compatible URL SSL query params + matching RESEARCH_MCP_QUESTDB_SSL are accepted.
const consistentSslEnable = parseResearchCopilotHostConfig(
// Single-source-of-truth TLS configs are accepted (URL-only TLS params without
// RESEARCH_MCP_QUESTDB_SSL, or clean URL with non-TLS query params + RESEARCH_MCP_QUESTDB_SSL).
const urlOnlyTlsEnable = parseResearchCopilotHostConfig(
buildValidEnv({
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=require`,
})
);
expect(urlOnlyTlsEnable.questdb).toEqual({
url: `${questUrl}?sslmode=require`,
});
const urlOnlyTlsDisable = parseResearchCopilotHostConfig(
buildValidEnv({
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?sslmode=disable`,
})
);
expect(urlOnlyTlsDisable.questdb).toEqual({
url: `${questUrl}?sslmode=disable`,
});
const flagOnlyTls = parseResearchCopilotHostConfig(
buildValidEnv({
RESEARCH_MCP_QUESTDB_URL: `${questUrl}?application_name=copilot`,
RESEARCH_MCP_QUESTDB_SSL: 'true',
})
);
expect(consistentSslEnable.questdb).toEqual({
url: `${questUrl}?sslmode=require`,
expect(flagOnlyTls.questdb).toEqual({
url: `${questUrl}?application_name=copilot`,
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]) {