test(catalog-backend): simplify onConflict().ignore() and add UNIQUE constraint test

Remove the explicit column list from .onConflict() calls in test setup —
ON CONFLICT DO NOTHING without a target is equivalent since (entity_id,
key, value) is the only unique constraint on the search table.

Add a dedicated test in syncSearchRows that directly inserts a duplicate
row and verifies it is silently rejected via the UNIQUE constraint.

Signed-off-by: Fredrik Adelöw <freben@spotify.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Fredrik Adelöw
2026-05-11 12:55:10 +02:00
parent bb6c46adc0
commit 930c575e58
2 changed files with 22 additions and 2 deletions
@@ -224,6 +224,26 @@ describe.each(databases.eachSupportedId())('syncSearchRows, %p', databaseId => {
expect(rows.map(r => r.value).sort()).toEqual(['java', 'python', 'rust']);
});
it('silently rejects a direct duplicate insert via the UNIQUE constraint', async () => {
await syncSearchRows(knex, 'e1', [row('a', 'x'), row('b', 'y')]);
// Simulate a concurrent process inserting a duplicate directly —
// the UNIQUE constraint on (entity_id, key, value) should reject it
// silently. ON CONFLICT without a column list covers any unique
// constraint on the table, which is safe since (entity_id, key, value)
// is the only one.
await knex<DbSearchRow>('search')
.insert({ entity_id: 'e1', key: 'a', value: 'x', original_value: 'x' })
.onConflict()
.ignore();
const rows = await getSearchRows();
expect(rows).toHaveLength(2);
expect(rows.find(r => r.key === 'a')).toEqual(
expect.objectContaining({ key: 'a', value: 'x' }),
);
});
it('simulates the typical steady-state case with one changed row', async () => {
// Build a realistic-ish set of search rows
const initial = [
@@ -2031,7 +2031,7 @@ describe('DefaultEntitiesCatalog', () => {
original_value: 'B Test Entity',
},
])
.onConflict(['entity_id', 'key', 'value'])
.onConflict()
.ignore();
const catalog = new DefaultEntitiesCatalog({
@@ -2422,7 +2422,7 @@ describe('DefaultEntitiesCatalog', () => {
original_value: 'one',
},
])
.onConflict(['entity_id', 'key', 'value'])
.onConflict()
.ignore();
const catalog = new DefaultEntitiesCatalog({