fix: repair generated JavaScript session package errors

This commit is contained in:
shiyue
2026-08-29 22:47:08 +08:00
parent 97b4a32dda
commit 6fff9023b2
3 changed files with 31 additions and 1 deletions

View File

@@ -67,7 +67,9 @@ async function main() {
response = { ok: true, conversationId: payload.sourceSessionId };
break;
case 'ccweb_script_get_last_message':
response = { ok: true, conversationId: payload.args.conversationId, message: '服务端最后消息' };
response = payload.args.conversationId === 'error-test'
? { ok: false, code: 'conversation_not_found', message: '目标对话不存在。', conversationId: 'error-test' }
: { ok: true, conversationId: payload.args.conversationId, message: '服务端最后消息' };
break;
case 'ccweb_script_get_conversation_status':
statusCallCount += 1;
@@ -156,6 +158,24 @@ async function main() {
assert.equal(succeeded.stderr, '');
assert.equal(notifications.length, 0);
assert.equal(runtime.writeScript({
name: 'error.js',
content: [
"import { getLastMessage } from '@ccweb/session';",
"try { await getLastMessage('error-test'); } catch (error) {",
" console.log(JSON.stringify({ name: error.name, code: error.code, message: error.message, details: error.details }));",
'}',
].join('\n'),
}, sourceId).ok, true);
const errorStart = runtime.runScript({ name: 'error.js' }, sourceId);
const errorRun = await waitForRun(runtime, sourceId, errorStart.runId, (run) => run.status === 'succeeded');
assert.equal(errorRun.exitCode, 0);
const errorResult = JSON.parse(errorRun.stdout.trim());
assert.equal(errorResult.name, 'Error');
assert.equal(errorResult.code, 'conversation_not_found');
assert.equal(errorResult.message, '目标对话不存在。');
assert.equal(errorResult.details.conversationId, 'error-test');
assert.equal(runtime.writeScript({ name: 'failed.js', content: "console.error('expected failure'); process.exit(3);" }, sourceId).ok, true);
const failedStart = runtime.runScript({ name: 'failed.js' }, sourceId);
const failed = await waitForRun(runtime, sourceId, failedStart.runId, (run) => run.status === 'failed');