Skip to content

Commit af729d4

Browse files
committed
Retrying failed commands and failed command state
1 parent 6a87a81 commit af729d4

File tree

4 files changed

+78
-52
lines changed

4 files changed

+78
-52
lines changed

packages/host/app/components/matrix/room-message-command.gts

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default class RoomMessageCommand extends Component<Signature> {
267267
class='retry-button'
268268
@size='small'
269269
@kind='secondary-dark'
270-
data-test-ai-bot-retry-button
270+
data-test-retry-command-button
271271
>
272272
Retry
273273
</Button>

packages/host/tests/acceptance/commands-test.gts

+55-39
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
import { setupMockMatrix } from '../helpers/mock-matrix';
6262
import { setupApplicationTest } from '../helpers/setup';
6363
import { pauseTest } from '@ember/test-helpers';
64+
import { suspendGlobalErrorHook } from '../helpers/uncaught-exceptions';
6465

6566
let matrixRoomId = '';
6667
let maybeBoomShouldBoom = true;
@@ -1139,49 +1140,64 @@ module('Acceptance | Commands tests', function (hooks) {
11391140
);
11401141
});
11411142

1142-
test('a command that errors when executing allows retry', async function (assert) {
1143-
await visitOperatorMode({
1144-
stacks: [
1145-
[
1143+
module('suspending global error hook', (hooks) => {
1144+
suspendGlobalErrorHook(hooks);
1145+
1146+
test('a command that errors when executing allows retry', async function (assert) {
1147+
await visitOperatorMode({
1148+
stacks: [
1149+
[
1150+
{
1151+
id: `${testRealmURL}Person/hassan`,
1152+
format: 'isolated',
1153+
},
1154+
],
1155+
],
1156+
});
1157+
1158+
await click('[data-test-maybe-boom-via-ai-assistant]');
1159+
await waitUntil(() => getRoomIds().length > 0);
1160+
1161+
await click('[data-test-open-ai-assistant-room-button]');
1162+
let roomId = getRoomIds().pop()!;
1163+
let message = getRoomEvents(roomId).pop()!;
1164+
let boxelMessageData = JSON.parse(message.content.data);
1165+
let toolName = boxelMessageData.context.tools[0].function.name;
1166+
maybeBoomShouldBoom = true;
1167+
simulateRemoteMessage(roomId, '@aibot:localhost', {
1168+
body: 'Will it boom?',
1169+
msgtype: APP_BOXEL_MESSAGE_MSGTYPE,
1170+
formatted_body: 'Will it boom?',
1171+
format: 'org.matrix.custom.html',
1172+
[APP_BOXEL_COMMAND_REQUESTS_KEY]: [
11461173
{
1147-
id: `${testRealmURL}Person/hassan`,
1148-
format: 'isolated',
1174+
id: '8406a6eb-a3d5-494f-a7f3-ae9880115756',
1175+
name: toolName,
1176+
arguments: {},
11491177
},
11501178
],
1151-
],
1152-
});
1153-
1154-
await click('[data-test-maybe-boom-via-ai-assistant]');
1155-
await waitUntil(() => getRoomIds().length > 0);
1156-
1157-
await click('[data-test-open-ai-assistant-room-button]');
1158-
let roomId = getRoomIds().pop()!;
1159-
let message = getRoomEvents(roomId).pop()!;
1160-
let boxelMessageData = JSON.parse(message.content.data);
1161-
let toolName = boxelMessageData.context.tools[0].function.name;
1179+
});
11621180

1163-
simulateRemoteMessage(roomId, '@aibot:localhost', {
1164-
body: 'Will it boom?',
1165-
msgtype: APP_BOXEL_MESSAGE_MSGTYPE,
1166-
formatted_body: 'Will it boom?',
1167-
format: 'org.matrix.custom.html',
1168-
[APP_BOXEL_COMMAND_REQUESTS_KEY]: [
1169-
{
1170-
id: '8406a6eb-a3d5-494f-a7f3-ae9880115756',
1171-
name: toolName,
1172-
arguments: {},
1173-
},
1174-
],
1181+
await settled();
1182+
let commandResultEvents = await getRoomEvents(roomId).filter(
1183+
(event) => event.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE,
1184+
);
1185+
assert.equal(
1186+
commandResultEvents.length,
1187+
0,
1188+
'No command result event dispatched',
1189+
);
1190+
maybeBoomShouldBoom = false;
1191+
await click('[data-test-retry-command-button]');
1192+
commandResultEvents = await getRoomEvents(roomId).filter(
1193+
(event) => event.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE,
1194+
);
1195+
assert.equal(
1196+
commandResultEvents.length,
1197+
1,
1198+
'No command result event dispatched',
1199+
);
1200+
assert.dom('[data-test-apply-state="applied"]').exists();
11751201
});
1176-
1177-
await settled();
1178-
let commandResultEvents = await getRoomEvents(roomId).filter(
1179-
(event) => event.type === APP_BOXEL_COMMAND_RESULT_EVENT_TYPE,
1180-
);
1181-
assert.equal(
1182-
commandResultEvents.length,
1183-
0,
1184-
'No command result event dispatched',
1185-
);
11861202
});
11871203
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function suspendGlobalErrorHook(hooks: NestedHooks) {
2+
let tmp: any;
3+
let capturedExceptions: any[] = [];
4+
hooks.before(() => {
5+
tmp = QUnit.onUncaughtException;
6+
QUnit.onUncaughtException = (err) => {
7+
capturedExceptions.push(err);
8+
};
9+
});
10+
11+
hooks.after(() => {
12+
QUnit.onUncaughtException = tmp;
13+
capturedExceptions = [];
14+
});
15+
return { capturedExceptions };
16+
}

packages/host/tests/integration/components/ai-assistant-panel-test.gts

+6-12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
import { setupMockMatrix } from '../../helpers/mock-matrix';
5959
import { renderComponent } from '../../helpers/render-component';
6060
import { setupRenderingTest } from '../../helpers/setup';
61+
import { suspendGlobalErrorHook } from '../../helpers/uncaught-exceptions';
6162

6263
module('Integration | ai-assistant-panel', function (hooks) {
6364
const realmName = 'Operator Mode Workspace';
@@ -1192,18 +1193,8 @@ module('Integration | ai-assistant-panel', function (hooks) {
11921193
});
11931194

11941195
module('suspending global error hook', (hooks) => {
1195-
let tmp: any;
1196-
let uncaughtException: any;
1197-
hooks.before(() => {
1198-
tmp = QUnit.onUncaughtException;
1199-
QUnit.onUncaughtException = (err) => {
1200-
uncaughtException = err;
1201-
};
1202-
});
1196+
let { capturedExceptions } = suspendGlobalErrorHook(hooks);
12031197

1204-
hooks.after(() => {
1205-
QUnit.onUncaughtException = tmp;
1206-
});
12071198
test('it can handle an error during room creation', async function (assert) {
12081199
await setCardInOperatorModeState();
12091200
await renderComponent(
@@ -1227,7 +1218,10 @@ module('Integration | ai-assistant-panel', function (hooks) {
12271218
assert.dom('[data-test-room-error]').exists();
12281219
assert.dom('[data-test-room]').doesNotExist();
12291220
assert.dom('[data-test-past-sessions-button]').isDisabled();
1230-
assert.strictEqual(uncaughtException.message, 'Intentional error thrown');
1221+
assert.strictEqual(
1222+
capturedExceptions[0].message,
1223+
'Intentional error thrown',
1224+
);
12311225
await percySnapshot(
12321226
'Integration | ai-assistant-panel | it can handle an error during room creation | error state',
12331227
);

0 commit comments

Comments
 (0)