chore(m2): execute host/quant verification, fix live blockers, and record M2 closure evidence (T-215)
This commit is contained in:
parent
87ae19e5f9
commit
a5184bb417
21 changed files with 1370 additions and 74 deletions
|
|
@ -62,6 +62,7 @@ const STRIPPED_TIMEOUT_PARAMS: ReadonlySet<string> = new Set([
|
|||
const POSTGRES_URL_PREFIX_RE = /^postgres(?:ql)?:\/\//i;
|
||||
const PORT_DIGITS_RE = /^\d+$/;
|
||||
const CONTROL_CHAR_RE = /[\r\n\0]/;
|
||||
const SCHEMA_IDENT_RE = /^[a-z_][a-z0-9_]*$/;
|
||||
|
||||
/**
|
||||
* Sanitized error thrown by {@link openResearchCopilotExecutor} and the
|
||||
|
|
@ -82,6 +83,7 @@ export class ResearchCopilotExecutorError extends Error {
|
|||
/** Configuration accepted by {@link openResearchCopilotExecutor}. */
|
||||
export interface ResearchCopilotExecutorConfig {
|
||||
readonly postgresUrl: string;
|
||||
readonly postgresSchema?: string;
|
||||
}
|
||||
|
||||
/** Minimal `pg.Pool` surface required by {@link openResearchCopilotExecutor}. */
|
||||
|
|
@ -237,6 +239,14 @@ function parseAndNormalizePoolConfig(config: ResearchCopilotExecutorConfig): Poo
|
|||
const envOptions = typeof process.env.PGOPTIONS === 'string' ? process.env.PGOPTIONS.trim() : '';
|
||||
const baseOptions = existingOptions.length > 0 ? existingOptions.join(' ') : envOptions;
|
||||
|
||||
let schemaOption = '';
|
||||
if (config.postgresSchema !== undefined) {
|
||||
if (typeof config.postgresSchema !== 'string' || !SCHEMA_IDENT_RE.test(config.postgresSchema)) {
|
||||
throw invalidConfigError();
|
||||
}
|
||||
schemaOption = `-c search_path=${config.postgresSchema},public`;
|
||||
}
|
||||
|
||||
const poolConfig: PoolConfig = {
|
||||
connectionString: parsed.toString(),
|
||||
max: RESEARCH_COPILOT_PG_POOL_MAX,
|
||||
|
|
@ -246,8 +256,9 @@ function parseAndNormalizePoolConfig(config: ResearchCopilotExecutorConfig): Poo
|
|||
lock_timeout: RESEARCH_COPILOT_PG_LOCK_TIMEOUT_MS,
|
||||
};
|
||||
|
||||
if (baseOptions.length > 0) {
|
||||
poolConfig.options = `${baseOptions} -c statement_timeout=${RESEARCH_COPILOT_PG_STATEMENT_TIMEOUT_MS} -c lock_timeout=${RESEARCH_COPILOT_PG_LOCK_TIMEOUT_MS}`;
|
||||
const combinedBase = [baseOptions, schemaOption].filter(s => s.length > 0).join(' ');
|
||||
if (combinedBase.length > 0) {
|
||||
poolConfig.options = `${combinedBase} -c statement_timeout=${RESEARCH_COPILOT_PG_STATEMENT_TIMEOUT_MS} -c lock_timeout=${RESEARCH_COPILOT_PG_LOCK_TIMEOUT_MS}`;
|
||||
}
|
||||
|
||||
return poolConfig;
|
||||
|
|
|
|||
|
|
@ -156,6 +156,58 @@ describe('openResearchCopilotExecutor', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('applies validated postgresSchema to pool search_path options and rejects invalid schemas', async () => {
|
||||
const previousPgOptions = process.env.PGOPTIONS;
|
||||
delete process.env.PGOPTIONS;
|
||||
try {
|
||||
const capturedConfigs: PoolConfig[] = [];
|
||||
const fake = createFakePool();
|
||||
|
||||
const handle = await openResearchCopilotExecutor(
|
||||
{ postgresUrl: VALID_URL, postgresSchema: 'm2_ec1_signoff' },
|
||||
{
|
||||
createPool(poolConfig) {
|
||||
capturedConfigs.push(poolConfig);
|
||||
return fake.pool;
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(capturedConfigs).toHaveLength(1);
|
||||
expect(capturedConfigs[0]?.options).toBe(
|
||||
`-c search_path=m2_ec1_signoff,public -c statement_timeout=${RESEARCH_COPILOT_PG_STATEMENT_TIMEOUT_MS} -c lock_timeout=${RESEARCH_COPILOT_PG_LOCK_TIMEOUT_MS}`
|
||||
);
|
||||
await handle.close();
|
||||
|
||||
let createPoolCalls = 0;
|
||||
for (const badSchema of ['', 'UPPER', '1bad', 'a-b', 'public; DROP TABLE x', 'a b']) {
|
||||
let caught: unknown;
|
||||
try {
|
||||
await openResearchCopilotExecutor(
|
||||
{ postgresUrl: VALID_URL, postgresSchema: badSchema },
|
||||
{
|
||||
createPool() {
|
||||
createPoolCalls += 1;
|
||||
return createFakePool().pool;
|
||||
},
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
assertNoSecretsLeaked(caught);
|
||||
expect((caught as ResearchCopilotExecutorError).code).toBe('INVALID_CONFIG');
|
||||
}
|
||||
expect(createPoolCalls).toBe(0);
|
||||
} finally {
|
||||
if (previousPgOptions === undefined) {
|
||||
delete process.env.PGOPTIONS;
|
||||
} else {
|
||||
process.env.PGOPTIONS = previousPgOptions;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('rejects invalid URLs with INVALID_CONFIG before constructing a pool', async () => {
|
||||
const invalidUrls = [
|
||||
'',
|
||||
|
|
|
|||
|
|
@ -140,8 +140,11 @@ export const mcpInitializeParamsSchema = z
|
|||
.object({
|
||||
name: z.string().min(1),
|
||||
version: z.string().min(1),
|
||||
title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
websiteUrl: z.string().optional(),
|
||||
})
|
||||
.strict()
|
||||
.passthrough()
|
||||
.optional(),
|
||||
_meta: mcpRequestMetaSchema.optional(),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -60,6 +60,37 @@ describe('MCP protocol & server core', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('initialize accepts MCP Implementation clientInfo metadata fields (title, description, websiteUrl)', async () => {
|
||||
const server = createMcpServer({
|
||||
name: 'stock-bot-research',
|
||||
version: '0.1.0',
|
||||
tools: [],
|
||||
});
|
||||
|
||||
const raw = await server.handleMessage(
|
||||
JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
id: 2,
|
||||
method: 'initialize',
|
||||
params: {
|
||||
protocolVersion: MCP_PROTOCOL_VERSION,
|
||||
capabilities: {},
|
||||
clientInfo: {
|
||||
name: 'claude-code',
|
||||
version: '2.1.84',
|
||||
title: 'Claude Code',
|
||||
description: 'Anthropic CLI client',
|
||||
websiteUrl: 'https://claude.ai',
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const response = parseResponse(raw);
|
||||
expect(response.error).toBeUndefined();
|
||||
expect(response.result?.protocolVersion).toBe(MCP_PROTOCOL_VERSION);
|
||||
});
|
||||
|
||||
test('notifications/initialized returns null (no response)', async () => {
|
||||
const server = createMcpServer({
|
||||
name: 'stock-bot-research',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue