T-88: M1.1m — Security-master run composer: readers output + bar spans → Stage A → Stage B → Pass 6 → Pass 4 → match report + persist input (pure, in-memory, no new dependencies)
This commit is contained in:
parent
3bdf7a8da6
commit
8ccca45174
2 changed files with 23 additions and 10 deletions
|
|
@ -233,7 +233,7 @@ interface ExistingConflictRow {
|
|||
}
|
||||
|
||||
interface ExistingPass4ConflictRow {
|
||||
conflict_key: string;
|
||||
row_idx: number;
|
||||
}
|
||||
|
||||
interface PreparedInstrument {
|
||||
|
|
@ -1424,15 +1424,15 @@ async function persistWithinTransaction(
|
|||
const slice = pass4Conflicts.slice(offset, offset + chunkSize);
|
||||
const res = await client.query<ExistingPass4ConflictRow>(
|
||||
`SELECT DISTINCT
|
||||
u.conflict_key
|
||||
u.row_idx
|
||||
FROM resolution_conflict rc
|
||||
INNER JOIN UNNEST(
|
||||
$1::varchar[],
|
||||
$2::varchar[],
|
||||
$3::varchar[],
|
||||
$4::jsonb[],
|
||||
$5::text[]
|
||||
) AS u(source, source_id, conflict_kind, detail, conflict_key)
|
||||
$5::int4[]
|
||||
) AS u(source, source_id, conflict_kind, detail, row_idx)
|
||||
ON rc.source = u.source
|
||||
AND rc.source_id = u.source_id
|
||||
AND rc.conflict_kind = u.conflict_kind
|
||||
|
|
@ -1442,11 +1442,14 @@ async function persistWithinTransaction(
|
|||
slice.map(c => c.sourceId),
|
||||
slice.map(c => c.conflictKind),
|
||||
slice.map(c => c.detailJson),
|
||||
slice.map(c => c.key),
|
||||
slice.map((_, idx) => idx),
|
||||
]
|
||||
);
|
||||
for (const row of res.rows) {
|
||||
existingPass4ConflictKeys.add(row.conflict_key);
|
||||
const matched = slice[row.row_idx];
|
||||
if (matched !== undefined) {
|
||||
existingPass4ConflictKeys.add(matched.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -910,18 +910,28 @@ describe('persistSecurityMaster unit tests', () => {
|
|||
q => q.text.includes('FROM resolution_conflict rc') && q.text.includes('rc.detail = u.detail')
|
||||
);
|
||||
expect(pass4Selects.length).toBe(1);
|
||||
// Regression: PostgreSQL UTF-8 text/varchar rejects NUL bytes (\u0000); Pass 4 existence check
|
||||
// must pass integer row indices ($5::int4[]) rather than NUL-delimited internal keys.
|
||||
expect(pass4Selects[0]?.values?.[4]).toEqual([0, 1]);
|
||||
for (const param of pass4Selects[0]?.values ?? []) {
|
||||
if (Array.isArray(param)) {
|
||||
for (const item of param) {
|
||||
if (typeof item === 'string') {
|
||||
expect(item.includes('\u0000')).toBe(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const conflictInserts = first.queries.filter(q =>
|
||||
q.text.startsWith('INSERT INTO resolution_conflict')
|
||||
);
|
||||
expect(conflictInserts.length).toBe(1);
|
||||
expect((conflictInserts[0]?.values?.[0] as string[]).length).toBe(2);
|
||||
|
||||
// Second run: simulate pair 1 already existing in DB via its conflict_key -> only pair 2 inserted.
|
||||
const existingKey =
|
||||
'eod\u0000AAPL.US\u0000price_ratio_mismatch\u0000qm\u0000AAPL:US';
|
||||
// Second run: simulate pair 1 (index 0 in sorted slice) already existing in DB -> only pair 2 inserted.
|
||||
const second = createMockClient(text => {
|
||||
if (text.includes('FROM resolution_conflict rc') && text.includes('rc.detail = u.detail')) {
|
||||
return { rows: [{ conflict_key: existingKey }] };
|
||||
return { rows: [{ row_idx: 0 }] };
|
||||
}
|
||||
return { rows: [] };
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue