T-161: M2.1j (re-queue) — PostgreSQL findings adapter for the MCP copilot: FindingWritePort (atomic idempotent append) + listFindings / listProviderCaveats readers over an injected executor in libs/research/src/mcp/adapters/postgres-findings.ts (no new deps)
This commit is contained in:
parent
a535ebefb5
commit
3064e15c0f
4 changed files with 236 additions and 35 deletions
|
|
@ -269,7 +269,7 @@ Server-only, dependency-free JSON-RPC 2.0 / Model Context Protocol core exported
|
|||
- **`createPostgresFindingWritePort({ executor, schema? })`** and **`createPostgresKnowledgeReaders({ executor, schema? })`** (exported from `@stock-bot/research/mcp` alongside `PostgresFindingsExecutor`, `PostgresFindingsOptions`, `PostgresKnowledgeReaders`, `PostgresFindingsError`, and `PostgresFindingsErrorCode`) back `file_finding` (`FindingWritePort`) and the `findings` / `provider_caveats` halves of `read_knowledge` (`Pick<KnowledgePort, 'listFindings' | 'listProviderCaveats'>`) over `37-research-findings.sql` with zero runtime `pg` dependency.
|
||||
- **Inputs, schema & row validation:** Validates `executor.query` (`INVALID_EXECUTOR`) and optional `schema` against `^[a-z_][a-z0-9_]*$` (`INVALID_SCHEMA`; defaults to the executor's `search_path`), binds every caller value via `$n` parameters, issues zero `UPDATE`/`DELETE` statements, and fails closed (`INVALID_ROW`) on malformed result envelopes, non-1D/non-string ref arrays, unknown `kind`, or invalid timestamps (converting PostgreSQL `Date` values or strictly parsed timezone-qualified ISO-8601 strings to UTC ISO-8601 output).
|
||||
- **Atomic idempotency & autocommit requirement:** Unkeyed appends execute a plain `INSERT ... RETURNING id, created_at`. Keyed appends use `INSERT ... ON CONFLICT (idempotency_key) WHERE idempotency_key IS NOT NULL DO NOTHING RETURNING id, created_at` followed by a separate keyed `SELECT` on zero rows (and on same-ID `23505` primary-key retries), comparing normalized `kind`, `title`, `summary`, `trialRefs`, and `evidenceRefs` via `areFiledFindingPayloadsEqual`. Pass an autocommit, fresh-snapshot `READ COMMITTED` executor (such as a `pg.Pool`, not a `REPEATABLE READ`/`SERIALIZABLE` or explicit `BEGIN` transaction unless the executor rolls back a `SAVEPOINT` before rethrowing errors) so concurrent callers observe the committed winner and `23505` retry lookups do not hit `25P02`.
|
||||
- **Reader filtering & research-visible corpus boundary:** `listFindings` and `listProviderCaveats` push down case-sensitive exact `id` (taking precedence over `query`), escaped `ILIKE` substring matching (`%`, `_`, `\`) for ASCII queries, and `lower(provider) = lower($n::text)` (matching `idx_provider_caveats_lower_provider`) for ASCII provider filters, falling back to JavaScript `.toLowerCase()` matching on validated candidates for non-ASCII text (e.g., Greek final sigma) so PostgreSQL libc casing never drops `read_knowledge` matches. All eligible rows are returned ordered by `id ASC` with no `LIMIT` so `createReadKnowledgeTool` owns ranking and global limits. Because `findings` and `provider_caveats` carry no Vault visibility column, callers must bind the adapter to a research-visible corpus and keep `createFileFindingTool` responsible for verifying `trialRefs` via `trialLookup` before writing.
|
||||
- **Reader filtering & research-visible corpus boundary:** `listFindings` and `listProviderCaveats` push down case-sensitive exact `id` (taking precedence over `query`), escaped `ILIKE` substring matching (`%`, `_`, `\`) for ASCII queries, and `lower(provider) = lower($n::text)` (matching `idx_provider_caveats_lower_provider`) for ASCII provider filters while retaining non-ASCII stored rows as candidates (and omitting SQL casing filters for non-ASCII selectors), then applying JavaScript `.toLowerCase()` matching after row validation so PostgreSQL libc/C collation casing (e.g., Greek final sigma or `BİST` / `K`) never drops `read_knowledge` matches. All eligible rows are returned ordered by `id ASC` with no `LIMIT` so `createReadKnowledgeTool` owns ranking and global limits. Because `findings` and `provider_caveats` carry no Vault visibility column, callers must bind the adapter to a research-visible corpus and keep `createFileFindingTool` responsible for verifying `trialRefs` via `trialLookup` before writing.
|
||||
|
||||
### Copilot Server
|
||||
|
||||
|
|
|
|||
|
|
@ -139,14 +139,23 @@ function escapeLikePattern(value: string): string {
|
|||
return value.replace(/[\\%_]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* PostgreSQL POSIX regex matching any non-ASCII character (`> 0x7F`).
|
||||
*
|
||||
* Used alongside ASCII SQL pushdown (`ILIKE` / `lower()`) so rows containing
|
||||
* non-ASCII stored text (e.g. `BİST` under `C` collation or `K` U+212A) are
|
||||
* kept as candidates and evaluated with JavaScript's `.toLowerCase()` rules.
|
||||
*/
|
||||
const PG_NON_ASCII_REGEX = "'[^\\x01-\\x7f]'";
|
||||
|
||||
/**
|
||||
* Returns `true` when every UTF-16 code unit in `value` is ASCII (`<= 0x7F`).
|
||||
*
|
||||
* PostgreSQL libc `ILIKE` / `lower()` lowercases characters individually, which
|
||||
* diverges from JavaScript's context-sensitive Unicode `.toLowerCase()` (e.g.
|
||||
* Greek final sigma `ΚΟΣΜΟΣ` -> `κοσμος`). SQL pushdown is used only for ASCII
|
||||
* text where casing agrees with `read_knowledge`; non-ASCII queries fall back
|
||||
* to filtering validated candidates with JavaScript's `.toLowerCase()` rules.
|
||||
* PostgreSQL `ILIKE` / `lower()` agrees with JavaScript `.toLowerCase()` only
|
||||
* when both the selector and the stored text are pure ASCII. Non-ASCII
|
||||
* selectors omit SQL casing filters, and ASCII selectors retain non-ASCII
|
||||
* stored rows as candidates; all returned rows are then filtered with
|
||||
* JavaScript's `.toLowerCase()` rules after validation.
|
||||
*/
|
||||
function isAsciiOnly(value: string): boolean {
|
||||
for (let i = 0; i < value.length; i += 1) {
|
||||
|
|
@ -607,17 +616,18 @@ export function createPostgresKnowledgeReaders(
|
|||
`FROM ${findingsTable}`,
|
||||
];
|
||||
const params: unknown[] = [];
|
||||
let fallbackNormalizedQuery: string | null = null;
|
||||
let normalizedQuery: string | null = null;
|
||||
|
||||
if (q.id !== undefined) {
|
||||
params.push(q.id);
|
||||
lines.push('WHERE id = $1::text');
|
||||
} else if (q.query !== undefined) {
|
||||
normalizedQuery = q.query.toLowerCase();
|
||||
if (isAsciiOnly(q.query)) {
|
||||
params.push(`%${escapeLikePattern(q.query)}%`);
|
||||
lines.push("WHERE title ILIKE $1::text ESCAPE '\\' OR summary ILIKE $1::text ESCAPE '\\'");
|
||||
} else {
|
||||
fallbackNormalizedQuery = q.query.toLowerCase();
|
||||
lines.push(
|
||||
`WHERE title ILIKE $1::text ESCAPE '\\' OR summary ILIKE $1::text ESCAPE '\\' OR title ~ ${PG_NON_ASCII_REGEX} OR summary ~ ${PG_NON_ASCII_REGEX}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -629,9 +639,9 @@ export function createPostgresKnowledgeReaders(
|
|||
for (let i = 0; i < rows.length; i += 1) {
|
||||
const finding = parseFindingRow(rows[i]);
|
||||
if (
|
||||
fallbackNormalizedQuery !== null &&
|
||||
!finding.title.toLowerCase().includes(fallbackNormalizedQuery) &&
|
||||
!finding.summary.toLowerCase().includes(fallbackNormalizedQuery)
|
||||
normalizedQuery !== null &&
|
||||
!finding.title.toLowerCase().includes(normalizedQuery) &&
|
||||
!finding.summary.toLowerCase().includes(normalizedQuery)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -652,15 +662,16 @@ export function createPostgresKnowledgeReaders(
|
|||
];
|
||||
const conditions: string[] = [];
|
||||
const params: unknown[] = [];
|
||||
let fallbackNormalizedProvider: string | null = null;
|
||||
let fallbackNormalizedQuery: string | null = null;
|
||||
let normalizedProvider: string | null = null;
|
||||
let normalizedQuery: string | null = null;
|
||||
|
||||
if (q.provider !== undefined) {
|
||||
normalizedProvider = q.provider.toLowerCase();
|
||||
if (isAsciiOnly(q.provider)) {
|
||||
params.push(q.provider);
|
||||
conditions.push(`lower(provider) = lower($${params.length}::text)`);
|
||||
} else {
|
||||
fallbackNormalizedProvider = q.provider.toLowerCase();
|
||||
conditions.push(
|
||||
`(lower(provider) = lower($${params.length}::text) OR provider ~ ${PG_NON_ASCII_REGEX})`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -668,14 +679,13 @@ export function createPostgresKnowledgeReaders(
|
|||
params.push(q.id);
|
||||
conditions.push(`id = $${params.length}::text`);
|
||||
} else if (q.query !== undefined) {
|
||||
normalizedQuery = q.query.toLowerCase();
|
||||
if (isAsciiOnly(q.query)) {
|
||||
params.push(`%${escapeLikePattern(q.query)}%`);
|
||||
const idx = params.length;
|
||||
conditions.push(
|
||||
`(provider ILIKE $${idx}::text ESCAPE '\\' OR dataset ILIKE $${idx}::text ESCAPE '\\' OR caveat ILIKE $${idx}::text ESCAPE '\\')`
|
||||
`(provider ILIKE $${idx}::text ESCAPE '\\' OR dataset ILIKE $${idx}::text ESCAPE '\\' OR caveat ILIKE $${idx}::text ESCAPE '\\' OR provider ~ ${PG_NON_ASCII_REGEX} OR dataset ~ ${PG_NON_ASCII_REGEX} OR caveat ~ ${PG_NON_ASCII_REGEX})`
|
||||
);
|
||||
} else {
|
||||
fallbackNormalizedQuery = q.query.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -691,16 +701,16 @@ export function createPostgresKnowledgeReaders(
|
|||
for (let i = 0; i < rows.length; i += 1) {
|
||||
const caveat = parseProviderCaveatRow(rows[i]);
|
||||
if (
|
||||
fallbackNormalizedProvider !== null &&
|
||||
caveat.provider.toLowerCase() !== fallbackNormalizedProvider
|
||||
normalizedProvider !== null &&
|
||||
caveat.provider.toLowerCase() !== normalizedProvider
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
fallbackNormalizedQuery !== null &&
|
||||
!caveat.provider.toLowerCase().includes(fallbackNormalizedQuery) &&
|
||||
!caveat.dataset.toLowerCase().includes(fallbackNormalizedQuery) &&
|
||||
!caveat.caveat.toLowerCase().includes(fallbackNormalizedQuery)
|
||||
normalizedQuery !== null &&
|
||||
!caveat.provider.toLowerCase().includes(normalizedQuery) &&
|
||||
!caveat.dataset.toLowerCase().includes(normalizedQuery) &&
|
||||
!caveat.caveat.toLowerCase().includes(normalizedQuery)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -361,10 +361,10 @@ describe('createPostgresKnowledgeReaders (fake executor)', () => {
|
|||
expect(fake.calls[1]!.text).not.toContain(injection);
|
||||
expect(fake.calls[1]!.params).toEqual([injection]);
|
||||
|
||||
// Escaped ILIKE query on title and summary
|
||||
// Escaped ILIKE query on title and summary (retaining non-ASCII stored rows as candidates)
|
||||
await readers.listFindings({ query: '100% pure_wild\\path' });
|
||||
expect(fake.calls[2]!.text).toContain(
|
||||
"WHERE title ILIKE $1::text ESCAPE '\\' OR summary ILIKE $1::text ESCAPE '\\'"
|
||||
"WHERE title ILIKE $1::text ESCAPE '\\' OR summary ILIKE $1::text ESCAPE '\\' OR title ~ '[^\\x01-\\x7f]' OR summary ~ '[^\\x01-\\x7f]'"
|
||||
);
|
||||
expect(fake.calls[2]!.params).toEqual(['%100\\% pure\\_wild\\\\path%']);
|
||||
|
||||
|
|
@ -402,7 +402,7 @@ describe('createPostgresKnowledgeReaders (fake executor)', () => {
|
|||
query: 'ignored',
|
||||
});
|
||||
expect(fake.calls[1]!.text).toContain(
|
||||
'WHERE lower(provider) = lower($1::text) AND id = $2::text'
|
||||
"WHERE (lower(provider) = lower($1::text) OR provider ~ '[^\\x01-\\x7f]') AND id = $2::text"
|
||||
);
|
||||
expect(fake.calls[1]!.text).not.toContain('ILIKE');
|
||||
expect(fake.calls[1]!.params).toEqual(['eodhd', 'caveat-001']);
|
||||
|
|
@ -413,14 +413,14 @@ describe('createPostgresKnowledgeReaders (fake executor)', () => {
|
|||
query: '50%_ratio\\inv',
|
||||
});
|
||||
expect(fake.calls[2]!.text).toContain(
|
||||
"WHERE lower(provider) = lower($1::text) AND (provider ILIKE $2::text ESCAPE '\\' OR dataset ILIKE $2::text ESCAPE '\\' OR caveat ILIKE $2::text ESCAPE '\\')"
|
||||
"WHERE (lower(provider) = lower($1::text) OR provider ~ '[^\\x01-\\x7f]') AND (provider ILIKE $2::text ESCAPE '\\' OR dataset ILIKE $2::text ESCAPE '\\' OR caveat ILIKE $2::text ESCAPE '\\' OR provider ~ '[^\\x01-\\x7f]' OR dataset ~ '[^\\x01-\\x7f]' OR caveat ~ '[^\\x01-\\x7f]')"
|
||||
);
|
||||
expect(fake.calls[2]!.params).toEqual(['QuoteMedia', '%50\\%\\_ratio\\\\inv%']);
|
||||
|
||||
// Query only
|
||||
await readers.listProviderCaveats({ query: 'split' });
|
||||
expect(fake.calls[3]!.text).toContain(
|
||||
"WHERE (provider ILIKE $1::text ESCAPE '\\' OR dataset ILIKE $1::text ESCAPE '\\' OR caveat ILIKE $1::text ESCAPE '\\')"
|
||||
"WHERE (provider ILIKE $1::text ESCAPE '\\' OR dataset ILIKE $1::text ESCAPE '\\' OR caveat ILIKE $1::text ESCAPE '\\' OR provider ~ '[^\\x01-\\x7f]' OR dataset ~ '[^\\x01-\\x7f]' OR caveat ~ '[^\\x01-\\x7f]')"
|
||||
);
|
||||
expect(fake.calls[3]!.params).toEqual(['%split%']);
|
||||
|
||||
|
|
@ -452,7 +452,9 @@ describe('createPostgresKnowledgeReaders (fake executor)', () => {
|
|||
query: 'ΚΟΣΜΟΣ',
|
||||
});
|
||||
expect(caveatMatches.map(r => r.id)).toEqual(['c-1']);
|
||||
expect(caveatFake.calls[0]!.text).toContain('WHERE lower(provider) = lower($1::text)');
|
||||
expect(caveatFake.calls[0]!.text).toContain(
|
||||
"WHERE (lower(provider) = lower($1::text) OR provider ~ '[^\\x01-\\x7f]')"
|
||||
);
|
||||
expect(caveatFake.calls[0]!.text).not.toContain('ILIKE');
|
||||
expect(caveatFake.calls[0]!.params).toEqual(['eodhd']);
|
||||
|
||||
|
|
@ -469,8 +471,56 @@ describe('createPostgresKnowledgeReaders (fake executor)', () => {
|
|||
expect(nonAsciiProvFake.calls[0]!.text).not.toContain('WHERE');
|
||||
expect(nonAsciiProvFake.calls[0]!.params).toEqual([]);
|
||||
|
||||
// ASCII query / ASCII provider against Unicode stored rows (e.g. BİST and K under C collation):
|
||||
// SQL retains non-ASCII stored rows as candidates and JS .toLowerCase() filters out non-matches.
|
||||
const asciiAgainstUnicodeFindingFake = createFakeExecutor([
|
||||
makeRawFindingRow({
|
||||
id: 'f-bist',
|
||||
title: 'BİST exchange coverage',
|
||||
summary: 'Turkish equities.',
|
||||
}),
|
||||
makeRawFindingRow({
|
||||
id: 'f-other-unicode',
|
||||
title: 'κόσμος',
|
||||
summary: 'Unrelated Greek finding.',
|
||||
}),
|
||||
]);
|
||||
const asciiFindingReaders = createPostgresKnowledgeReaders({
|
||||
executor: asciiAgainstUnicodeFindingFake.executor,
|
||||
});
|
||||
expect((await asciiFindingReaders.listFindings({ query: 'bi' })).map(r => r.id)).toEqual([
|
||||
'f-bist',
|
||||
]);
|
||||
|
||||
const asciiAgainstUnicodeCaveatFake = createFakeExecutor([
|
||||
makeRawCaveatRow({
|
||||
id: 'c-kelvin',
|
||||
provider: 'K',
|
||||
dataset: 'ds',
|
||||
caveat: 'BİST feed note.',
|
||||
}),
|
||||
makeRawCaveatRow({
|
||||
id: 'c-other-unicode',
|
||||
provider: 'κόσμος',
|
||||
dataset: 'ds',
|
||||
caveat: 'Unrelated.',
|
||||
}),
|
||||
]);
|
||||
const asciiCaveatReaders = createPostgresKnowledgeReaders({
|
||||
executor: asciiAgainstUnicodeCaveatFake.executor,
|
||||
});
|
||||
expect(
|
||||
(await asciiCaveatReaders.listProviderCaveats({ provider: 'k', query: 'bi' })).map(r => r.id)
|
||||
).toEqual(['c-kelvin']);
|
||||
|
||||
assertNoMutationOrReaderLimitSql(
|
||||
[...findingFake.calls, ...caveatFake.calls, ...nonAsciiProvFake.calls],
|
||||
[
|
||||
...findingFake.calls,
|
||||
...caveatFake.calls,
|
||||
...nonAsciiProvFake.calls,
|
||||
...asciiAgainstUnicodeFindingFake.calls,
|
||||
...asciiAgainstUnicodeCaveatFake.calls,
|
||||
],
|
||||
true
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -296,13 +296,15 @@ describe.skipIf(!url)('PostgreSQL MCP findings & provider caveats adapter', () =
|
|||
loserRecord: FiledFindingRecord
|
||||
) => {
|
||||
const winnerClient = await f.pool.connect();
|
||||
const loserClient = await f.pool.connect();
|
||||
let winnerOpen = false;
|
||||
cleanup.push(async () => {
|
||||
if (winnerOpen) {
|
||||
await winnerClient.query('ROLLBACK').catch(() => {});
|
||||
}
|
||||
winnerClient.release();
|
||||
});
|
||||
const loserClient = await f.pool.connect();
|
||||
cleanup.push(() => {
|
||||
loserClient.release();
|
||||
});
|
||||
|
||||
|
|
@ -660,4 +662,143 @@ describe.skipIf(!url)('PostgreSQL MCP findings & provider caveats adapter', () =
|
|||
expect(sigmaCaveats.rowCount).toBe(1);
|
||||
expect(sigmaCaveats.rows[0]?.id).toBe('caveat-sigma-1');
|
||||
});
|
||||
|
||||
test('matches ASCII queries and providers against Unicode stored text under PostgreSQL C collation through MCP', async () => {
|
||||
const f = await createIsolatedFixture();
|
||||
|
||||
// Force C collation on text columns to reproduce the C-collation casing mismatch
|
||||
// regardless of the host test database's default collation.
|
||||
await f.pool.query(`
|
||||
ALTER TABLE findings
|
||||
ALTER COLUMN title TYPE TEXT COLLATE "C",
|
||||
ALTER COLUMN summary TYPE TEXT COLLATE "C";
|
||||
ALTER TABLE provider_caveats
|
||||
ALTER COLUMN provider TYPE TEXT COLLATE "C",
|
||||
ALTER COLUMN dataset TYPE TEXT COLLATE "C",
|
||||
ALTER COLUMN caveat TYPE TEXT COLLATE "C";
|
||||
`);
|
||||
|
||||
// Prove PostgreSQL C collation itself fails both direct SQL casing comparisons.
|
||||
const pgCheck = (
|
||||
await f.pool.query<{ ilike_match: boolean; lower_match: boolean }>(
|
||||
`SELECT
|
||||
('BİST exchange coverage' COLLATE "C" ILIKE '%bi%') AS ilike_match,
|
||||
(lower('K' COLLATE "C") = lower('k' COLLATE "C")) AS lower_match`
|
||||
)
|
||||
).rows[0]!;
|
||||
expect(pgCheck.ilike_match).toBe(false);
|
||||
expect(pgCheck.lower_match).toBe(false);
|
||||
|
||||
const executor = createPgExecutor(f.pool);
|
||||
const writePort = createPostgresFindingWritePort({ executor });
|
||||
const readers = createPostgresKnowledgeReaders({ executor });
|
||||
|
||||
let idSeq = 0;
|
||||
const server = createMcpServer({
|
||||
name: 'stock-bot-research',
|
||||
version: '0.1.0',
|
||||
tools: [
|
||||
createFileFindingTool({
|
||||
port: writePort,
|
||||
trialLookup: {
|
||||
hasResearchVisibleTrial(ref) {
|
||||
return ref === '101';
|
||||
},
|
||||
},
|
||||
newId: () => {
|
||||
idSeq += 1;
|
||||
return `finding-c-coll-${idSeq}`;
|
||||
},
|
||||
now: () => new Date(FIXED_TS),
|
||||
}),
|
||||
createReadKnowledgeTool({
|
||||
port: {
|
||||
listLibraryCards: async () => [],
|
||||
...readers,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const callTool = async (name: string, args: Record<string, unknown>) => {
|
||||
const raw = await server.handleMessage(
|
||||
JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
id: `req-c-coll-${name}`,
|
||||
method: 'tools/call',
|
||||
params: { name, arguments: args },
|
||||
})
|
||||
);
|
||||
expect(raw).not.toBeNull();
|
||||
const parsed = JSON.parse(raw!) as {
|
||||
result: { isError?: boolean; content: Array<{ text: string }> };
|
||||
};
|
||||
return parsed.result;
|
||||
};
|
||||
|
||||
// File Unicode finding 'BİST exchange coverage' and an unrelated Unicode finding 'κόσμος'
|
||||
const bistFileRes = await callTool('file_finding', {
|
||||
kind: 'finding',
|
||||
title: 'BİST exchange coverage',
|
||||
summary: 'Turkish equities universe check.',
|
||||
trialRefs: ['101'],
|
||||
evidenceRefs: [],
|
||||
});
|
||||
expect(bistFileRes.isError).toBeUndefined();
|
||||
const bistReceipt = JSON.parse(bistFileRes.content[0]!.text) as FileFindingResultPayload;
|
||||
|
||||
const unrelatedFileRes = await callTool('file_finding', {
|
||||
kind: 'finding',
|
||||
title: 'κόσμος',
|
||||
summary: 'Unrelated Greek finding.',
|
||||
trialRefs: ['101'],
|
||||
evidenceRefs: [],
|
||||
});
|
||||
expect(unrelatedFileRes.isError).toBeUndefined();
|
||||
|
||||
// ASCII query 'bi' must match 'BİST exchange coverage' and exclude 'κόσμος'
|
||||
const bistReadRes = await callTool('read_knowledge', {
|
||||
source: 'findings',
|
||||
query: 'bi',
|
||||
});
|
||||
expect(bistReadRes.isError).toBeUndefined();
|
||||
const bistKnowledge = JSON.parse(
|
||||
bistReadRes.content[0]!.text
|
||||
) as ReadKnowledgeResultPayload;
|
||||
expect(bistKnowledge.rowCount).toBe(1);
|
||||
expect(bistKnowledge.rows[0]?.id).toBe(bistReceipt.id);
|
||||
|
||||
// Provider caveats: ASCII query against 'BİST' text, and ASCII provider 'k' against 'K' (U+212A)
|
||||
await f.pool.query(
|
||||
`INSERT INTO provider_caveats (id, provider, dataset, caveat, created_at)
|
||||
VALUES
|
||||
('caveat-c-bist', 'EODHD', 'eodPrices', 'BİST intraday feed caveat.', $1::timestamptz),
|
||||
('caveat-c-kelvin', 'K', 'kelvinBars', 'Kelvin sign provider caveat.', $1::timestamptz),
|
||||
('caveat-c-greek', 'EODHD', 'eodPrices', 'Unrelated κόσμος caveat.', $1::timestamptz)`,
|
||||
[FIXED_TS]
|
||||
);
|
||||
|
||||
const bistCaveatRes = await callTool('read_knowledge', {
|
||||
source: 'provider_caveats',
|
||||
provider: 'eodhd',
|
||||
query: 'bi',
|
||||
});
|
||||
expect(bistCaveatRes.isError).toBeUndefined();
|
||||
const bistCaveats = JSON.parse(
|
||||
bistCaveatRes.content[0]!.text
|
||||
) as ReadKnowledgeResultPayload;
|
||||
expect(bistCaveats.rowCount).toBe(1);
|
||||
expect(bistCaveats.rows[0]?.id).toBe('caveat-c-bist');
|
||||
|
||||
const kelvinCaveatRes = await callTool('read_knowledge', {
|
||||
source: 'provider_caveats',
|
||||
provider: 'k',
|
||||
});
|
||||
expect(kelvinCaveatRes.isError).toBeUndefined();
|
||||
const kelvinCaveats = JSON.parse(
|
||||
kelvinCaveatRes.content[0]!.text
|
||||
) as ReadKnowledgeResultPayload;
|
||||
expect(kelvinCaveats.rowCount).toBe(1);
|
||||
expect(kelvinCaveats.rows[0]?.id).toBe('caveat-c-kelvin');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue