Add page data delivery and publication guards

This commit is contained in:
john
2026-07-08 21:10:47 +08:00
parent 8d629e7a4e
commit eea14c1855
66 changed files with 3035 additions and 413 deletions
+52 -1
View File
@@ -6,7 +6,7 @@ import path from 'node:path';
import test from 'node:test';
import { createAgentRunGateway } from './agent-run-gateway.mjs';
function createFakePool() {
function createFakePool({ sessionDeliverables = {} } = {}) {
const runs = new Map();
const events = [];
@@ -191,6 +191,10 @@ function createFakePool() {
});
return [{ affectedRows: 1 }];
}
if (sql.includes('FROM h5_page_records p') && sql.includes('source_session_id')) {
const [userId, sessionId] = params;
return [sessionDeliverables[`${userId}:${sessionId}`] ?? []];
}
if (sql.includes('UPDATE h5_agent_runs SET')) {
const id = params.at(-1);
const row = runs.get(id);
@@ -322,6 +326,53 @@ test('agent run awaits session Finish before succeeding when proxy supports it',
assert.equal(finishEvents.length, 1);
});
test('agent run succeeds when Finish is missing but session pages were already created', async () => {
const pool = createFakePool({
sessionDeliverables: {
'user-1:session-deliverable-1': [{
page_id: 'page-front',
title: '供应商数据上报',
publication_id: 'pub-front',
publication_status: 'online',
public_url: 'http://127.0.0.1:5173/u/john/pages/page-front',
}],
},
});
const gateway = createAgentRunGateway({
pool,
userAuth: {},
tkmindProxy: {
async startSessionForUser() {
return { id: 'session-deliverable-1' };
},
async submitSessionReplyAndAwaitFinishForUser() {
const err = new Error('session event stream ended before Finish');
err.code = 'SESSION_REPLY_INCOMPLETE';
throw err;
},
},
retryDelaysMs: [],
});
const run = await gateway.createRun('user-1', {
requestId: 'req-deliverable-recover',
userMessage: {
role: 'user',
content: [{ type: 'text', text: '生成填报系统' }],
},
});
await waitFor(() => pool.runs.get(run.id)?.status === 'succeeded');
assert.equal(
pool.events.some((event) => event.runId === run.id && event.eventType === 'run_recovered_from_deliverables'),
true,
);
assert.equal(
pool.events.some((event) => event.runId === run.id && event.eventType === 'session_finished'),
false,
);
});
test('agent run uses direct chat service for eligible chat messages', async () => {
const pool = createFakePool();
const directRuns = [];