fix: add session_id index in tool_results

This commit is contained in:
tommy0103
2026-07-16 02:54:15 +08:00
parent 1e4e5ec2d8
commit cec66d0656
2 changed files with 19 additions and 0 deletions
+18
View File
@@ -1,6 +1,7 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { DatabaseSync } from 'node:sqlite';
import { extractContentType, extractMessageIsMeta } from '../packages/core/src/db.ts';
@@ -49,6 +50,23 @@ test('messages schema stores the raw content block type', async () => {
assert.match(source, /CREATE TRIGGER IF NOT EXISTS messages_fts_ad AFTER DELETE ON messages/);
});
test('tool results schema indexes live session patch lookups', async () => {
const db = new DatabaseSync(':memory:');
try {
db.exec(await readExecutableSchema());
const plan = db.prepare(
'EXPLAIN QUERY PLAN SELECT * FROM tool_results WHERE session_id = ?',
).all('session-1');
assert.ok(
plan.some(row => /USING INDEX idx_tr_session/.test(String(row.detail))),
`expected idx_tr_session lookup, got: ${plan.map(row => row.detail).join('; ')}`,
);
} finally {
db.close();
}
});
test('schema reference stays focused on raw SQL structure', async () => {
const ref = await readSchemaReference();