接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
110 lines
4.0 KiB
JavaScript
110 lines
4.0 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createAnalysisSessionClient } from '../src/agent/sessionClient.ts';
|
|
|
|
const tick = () => new Promise(resolve => setImmediate(resolve));
|
|
const deferred = () => {
|
|
let resolve, reject;
|
|
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
return { promise, resolve, reject };
|
|
};
|
|
|
|
function restoreFixture({ readList = async () => ({ items: [] }), readTurn } = {}) {
|
|
const opened = [];
|
|
const authorizationChecks = [];
|
|
const client = createAnalysisSessionClient({
|
|
userId: 'restore-fixture',
|
|
onUnauthorized: error => { authorizationChecks.push(error); return false; },
|
|
transport: {
|
|
analysisSessions: readList,
|
|
analysisTurn: readTurn,
|
|
analysisSessionFollow: async (id, { onEvent }) => {
|
|
opened.push(id);
|
|
onEvent({ event: 'snapshot', data: { id, turns: [{ id: 'requested-turn', status: 'COMPLETED' }] } });
|
|
},
|
|
},
|
|
});
|
|
return { client, opened, authorizationChecks };
|
|
}
|
|
|
|
test('replaying mount discards a stale turn lookup even before the replacement resolves', async t => {
|
|
const oldTurn = deferred();
|
|
const currentTurn = deferred();
|
|
let requests = 0;
|
|
const { client, opened, authorizationChecks } = restoreFixture({
|
|
readTurn: () => (++requests === 1 ? oldTurn.promise : currentTurn.promise),
|
|
});
|
|
t.after(client.dispose);
|
|
|
|
client.resume();
|
|
const first = client.openInitial({ turnId: 'requested-turn' });
|
|
client.suspend();
|
|
client.resume();
|
|
await tick();
|
|
assert.equal(requests, 2);
|
|
|
|
oldTurn.reject(Object.assign(new Error('old request unavailable'), { status: 503 }));
|
|
assert.equal(await first, false);
|
|
assert.equal(client.getSnapshot().historyLoading, true);
|
|
assert.equal(client.getSnapshot().historyError, '');
|
|
assert.deepEqual(authorizationChecks, []);
|
|
|
|
currentTurn.resolve({ sessionId: 'current-session' });
|
|
await tick();
|
|
assert.equal(client.getSnapshot().historyLoading, false);
|
|
assert.equal(client.getSnapshot().focusTurnId, 'requested-turn');
|
|
assert.deepEqual(opened, ['current-session']);
|
|
});
|
|
|
|
test('replaying mount shares a list read and finishes loading an empty history', async t => {
|
|
const list = deferred();
|
|
let requests = 0;
|
|
const { client, opened } = restoreFixture({ readList: () => { requests++; return list.promise; } });
|
|
t.after(client.dispose);
|
|
client.resume();
|
|
const first = client.openInitial();
|
|
client.suspend();
|
|
client.resume();
|
|
|
|
assert.equal(client.getSnapshot().historyLoading, true);
|
|
assert.equal(await client.submit('must wait for selection'), false);
|
|
list.resolve({ items: [] });
|
|
assert.equal(await first, false);
|
|
await tick();
|
|
assert.equal(requests, 1);
|
|
assert.equal(client.getSnapshot().historyLoading, false);
|
|
assert.equal(client.getSnapshot().historyError, '');
|
|
assert.deepEqual(opened, []);
|
|
});
|
|
|
|
test('a failed recent-session lookup can be retried without creating a conversation', async t => {
|
|
let requests = 0;
|
|
const { client, opened } = restoreFixture({
|
|
readList: async () => {
|
|
if (++requests === 1) throw new Error('session list unavailable');
|
|
return { items: [{ id: 'recent' }] };
|
|
},
|
|
});
|
|
t.after(client.dispose);
|
|
assert.equal(await client.openInitial(), false);
|
|
assert.equal(client.getSnapshot().historyLoading, false);
|
|
assert.equal(client.getSnapshot().historyError, 'session list unavailable');
|
|
assert.equal(await client.openInitial(), true);
|
|
assert.equal(client.getSnapshot().historyError, '');
|
|
assert.equal(client.getSnapshot().sessionId, 'recent');
|
|
assert.deepEqual(opened, ['recent']);
|
|
});
|
|
|
|
test('starting a new conversation invalidates a pending automatic selection', async t => {
|
|
const list = deferred();
|
|
const { client, opened } = restoreFixture({ readList: () => list.promise });
|
|
t.after(client.dispose);
|
|
const opening = client.openInitial();
|
|
client.newSession();
|
|
list.resolve({ items: [{ id: 'recent' }] });
|
|
assert.equal(await opening, false);
|
|
assert.equal(client.getSnapshot().historyLoading, false);
|
|
assert.equal(client.getSnapshot().sessionId, '');
|
|
assert.deepEqual(opened, []);
|
|
});
|