This commit is contained in:
seb
2026-10-12 18:01:25 +02:00
parent 2e961252f7
commit 88ff9e08a9
12 changed files with 104 additions and 27 deletions

View File

@@ -33,6 +33,7 @@ async function run() {
const list = await store.modelconversation.list(userA);
assert.equal(list.length, 1);
assert.equal(list[0].first_user_message, null);
assert.deepEqual(await store.modelmessage.list(userA, conv.id), []);
@@ -65,6 +66,7 @@ async function run() {
const msgs = await store.modelmessage.list(userA, conv.id);
assert.deepEqual(msgs.map((m) => m.message), ['hello', 'echo: hello', 'second']);
assert.deepEqual(msgs.map((m) => m.role), ['user', 'assistant', 'user']);
assert.equal((await store.modelconversation.list(userA)).find((c) => c.id === conv.id).first_user_message, 'hello');
// Other user cannot see or write
const userB = await store.google_auth.add('mc-b@example.com');
@@ -74,6 +76,33 @@ async function run() {
await assert.rejects(store.modelmessage.list(userB, conv.id), /Conversation not found/);
await assert.rejects(store.modelmessage.add(userB, conv.id, { message: 'x' }), /Conversation not found/);
// started_by: top-level is null, subagents link to their originator, list exposes it
assert.equal(conv.started_by, null);
const sub1 = await store.modelconversation.create(userA, { provider: 'openrouter', model: 'm', started_by: conv.id });
assert.equal(sub1.started_by, conv.id);
const sub2 = await store.modelconversation.create(userA, { provider: 'openrouter', model: 'm', started_by: sub1.id });
const sibling = await store.modelconversation.create(userA, { provider: 'openrouter', model: 'm' });
await assert.rejects(
store.modelconversation.create(userA, { provider: 'openrouter', model: 'm', started_by: 0 }),
/Invalid started_by/,
);
const listed = await store.modelconversation.list(userA);
assert.equal(listed.find((c) => c.id === sub2.id).started_by, sub1.id);
assert.equal((await store.modelconversation.get(userA, sub1.id)).started_by, conv.id);
await store.modelmessage.add(userA, sub2.id, { message: 'deep' });
// Deleting a child removes only its own chain; deleting the root removes the whole chain
await store.modelconversation.delete(userA, sub2.id);
await assert.rejects(store.modelconversation.get(userA, sub2.id), /Conversation not found/);
await store.modelconversation.get(userA, sub1.id);
const sub3 = await store.modelconversation.create(userA, { provider: 'openrouter', model: 'm', started_by: sub1.id });
await store.modelconversation.delete(userA, conv.id);
for (const gone of [conv.id, sub1.id, sub3.id]) {
await assert.rejects(store.modelconversation.get(userA, gone), /Conversation not found/);
}
await store.modelconversation.get(userA, sibling.id);
await assert.rejects(store.modelconversation.delete(userA, conv.id), /Conversation not found/);
console.log('PASS');
} finally {
await provider.close?.();