Skip to content

Commit 1a59c69

Browse files
committed
fix: add folderKey
1 parent ec54e8c commit 1a59c69

8 files changed

Lines changed: 51 additions & 21 deletions

File tree

samples/process-app-v0/src/components/ProcessInstances.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export const ProcessInstances = () => {
227227
}
228228

229229
try {
230-
executionHistory = await sdk.maestro.processes.instances.getExecutionHistory(instance.instanceId);
230+
executionHistory = await sdk.maestro.processes.instances.getExecutionHistory(instance.instanceId, instance.folderKey);
231231
} catch (err) {
232232
console.error('Error fetching execution history:', err);
233233
// Continue without execution history

samples/process-app-v1/src/components/ProcessInstances.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export const ProcessInstances = () => {
249249

250250
try {
251251
// Use modular ProcessInstances service directly
252-
executionHistory = await processInstances.getExecutionHistory(instance.instanceId);
252+
executionHistory = await processInstances.getExecutionHistory(instance.instanceId, instance.folderKey);
253253
} catch (err) {
254254
console.error('Error fetching execution history:', err);
255255
// Continue without execution history

src/models/maestro/process-instances.models.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ export interface ProcessInstancesServiceModel {
9696
/**
9797
* Get execution history (spans) for a process instance
9898
* @param instanceId The ID of the instance to get history for
99+
* @param folderKey The folder key for authorization
99100
* @returns Promise resolving to execution history
100101
* {@link ProcessInstanceExecutionHistoryResponse}
101102
* @example
102103
* ```typescript
103104
* // Get execution history for a process instance
104105
* const history = await processInstances.getExecutionHistory(
105-
* <instanceId>
106+
* <instanceId>,
107+
* <folderKey>
106108
* );
107109
*
108110
* // Analyze execution timeline
@@ -113,7 +115,7 @@ export interface ProcessInstancesServiceModel {
113115
* });
114116
* ```
115117
*/
116-
getExecutionHistory(instanceId: string): Promise<ProcessInstanceExecutionHistoryResponse[]>;
118+
getExecutionHistory(instanceId: string, folderKey: string): Promise<ProcessInstanceExecutionHistoryResponse[]>;
117119

118120
/**
119121
* Get BPMN XML file for a process instance
@@ -355,8 +357,9 @@ function createProcessInstanceMethods(instanceData: RawProcessInstanceGetRespons
355357

356358
async getExecutionHistory(): Promise<ProcessInstanceExecutionHistoryResponse[]> {
357359
if (!instanceData.instanceId) throw new Error('Process instance ID is undefined');
360+
if (!instanceData.folderKey) throw new Error('Process instance folder key is undefined');
358361

359-
return service.getExecutionHistory(instanceData.instanceId);
362+
return service.getExecutionHistory(instanceData.instanceId, instanceData.folderKey);
360363
},
361364

362365
async getBpmn(): Promise<BpmnXmlString> {

src/services/maestro/processes/process-instances.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,27 @@ export class ProcessInstancesService extends BaseService implements ProcessInsta
119119
/**
120120
* Get execution history (spans) for a process instance
121121
* @param instanceId The ID of the instance to get history for
122+
* @param folderKey The folder key for authorization
122123
* @returns Promise<ProcessInstanceExecutionHistoryResponse[]>
123124
*/
124125
@track('ProcessInstances.GetExecutionHistory')
125-
async getExecutionHistory(instanceId: string): Promise<ProcessInstanceExecutionHistoryResponse[]> {
126+
async getExecutionHistory(instanceId: string, folderKey: string): Promise<ProcessInstanceExecutionHistoryResponse[]> {
126127
// Call element-executions API to get structural BPMN data and traceId
127128
const elementExecResponse = await this.get<ElementExecutionsApiResponse>(
128-
MAESTRO_ENDPOINTS.INSTANCES.GET_ELEMENT_EXECUTIONS(instanceId)
129+
MAESTRO_ENDPOINTS.INSTANCES.GET_ELEMENT_EXECUTIONS(instanceId),
130+
{
131+
headers: createHeaders({ [FOLDER_KEY]: folderKey })
132+
}
129133
);
130134

131135
const traceId = elementExecResponse.data.instanceId;
132136

133137
// Call spans API with traceId to get trace/span details
134138
const spansResponse = await this.get<TraceSpan[]>(
135-
MAESTRO_ENDPOINTS.TRACES.GET_SPANS(traceId)
139+
MAESTRO_ENDPOINTS.TRACES.GET_SPANS(traceId),
140+
{
141+
headers: createHeaders({ [FOLDER_KEY]: folderKey })
142+
}
136143
);
137144

138145
// Create span lookup by Id for merging

src/utils/constants/endpoints/maestro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const MAESTRO_ENDPOINTS = {
2828
GET_BY_INSTANCE: (instanceId: string) => `${PIMS_BASE}/api/v1/instances/${instanceId}/incidents`,
2929
},
3030
TRACES: {
31-
GET_SPANS: (traceId: string) => `${LLMOPS_BASE}api/Traces/spans?traceId=${traceId}`,
31+
GET_SPANS: (traceId: string) => `${LLMOPS_BASE}/api/Traces/spans?traceId=${traceId}`,
3232
},
3333
CASES: {
3434
GET_CASE_JSON: (instanceId: string) => `${PIMS_BASE}/api/v1/cases/${instanceId}/case-json`,

tests/integration/shared/maestro/process-instances.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe.each(modes)('Maestro Process Instances - Integration Tests [%s]', (mode
249249
const { processInstances } = getServices();
250250

251251
try {
252-
const result = await processInstances.getExecutionHistory(testInstanceId);
252+
const result = await processInstances.getExecutionHistory(testInstanceId, config.folderId || '');
253253

254254
expect(result).toBeDefined();
255255
expect(Array.isArray(result)).toBe(true);

tests/unit/models/maestro/process-instances.test.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,20 @@ describe('Process Instance Models', () => {
230230
});
231231

232232
describe('processInstance.getExecutionHistory()', () => {
233-
it('should call processInstance.getExecutionHistory with bound instanceId', async () => {
233+
it('should call processInstance.getExecutionHistory with bound instanceId and folderKey', async () => {
234234
const mockInstanceData = createMockProcessInstance();
235235
const instance = createProcessInstanceWithMethods(mockInstanceData, mockService);
236-
236+
237237
const mockHistory = [createMockExecutionHistory()];
238238
mockService.getExecutionHistory = vi.fn().mockResolvedValue(mockHistory);
239239

240-
240+
241241
const result = await instance.getExecutionHistory();
242242

243-
243+
244244
expect(mockService.getExecutionHistory).toHaveBeenCalledWith(
245-
MAESTRO_TEST_CONSTANTS.INSTANCE_ID
245+
MAESTRO_TEST_CONSTANTS.INSTANCE_ID,
246+
MAESTRO_TEST_CONSTANTS.FOLDER_KEY
246247
);
247248
expect(result).toEqual(mockHistory);
248249
});
@@ -252,9 +253,18 @@ describe('Process Instance Models', () => {
252253
const invalidInstanceData = { ...mockInstanceData, instanceId: undefined as any };
253254
const invalidInstance = createProcessInstanceWithMethods(invalidInstanceData, mockService);
254255

255-
256+
256257
await expect(invalidInstance.getExecutionHistory()).rejects.toThrow('Process instance ID is undefined');
257258
});
259+
260+
it('should throw error if folderKey is undefined', async () => {
261+
const mockInstanceData = createMockProcessInstance();
262+
const invalidInstanceData = { ...mockInstanceData, folderKey: undefined as any };
263+
const invalidInstance = createProcessInstanceWithMethods(invalidInstanceData, mockService);
264+
265+
266+
await expect(invalidInstance.getExecutionHistory()).rejects.toThrow('Process instance folder key is undefined');
267+
});
258268
});
259269

260270
describe('processInstance.getBpmn()', () => {

tests/unit/services/maestro/process-instances.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,30 @@ describe('ProcessInstancesService', () => {
210210
describe('getExecutionHistory', () => {
211211
it('should return execution history for process instance', async () => {
212212
const instanceId = MAESTRO_TEST_CONSTANTS.INSTANCE_ID;
213+
const folderKey = MAESTRO_TEST_CONSTANTS.FOLDER_KEY;
213214

214215
mockApiClient.get
215216
.mockResolvedValueOnce(createMockElementExecutionsResponse())
216217
.mockResolvedValueOnce([createMockTraceSpan()]);
217218

218-
const result = await service.getExecutionHistory(instanceId);
219+
const result = await service.getExecutionHistory(instanceId, folderKey);
219220

220221
expect(mockApiClient.get).toHaveBeenCalledWith(
221222
MAESTRO_ENDPOINTS.INSTANCES.GET_ELEMENT_EXECUTIONS(instanceId),
222-
{}
223+
{
224+
headers: expect.objectContaining({
225+
[FOLDER_KEY]: folderKey
226+
})
227+
}
223228
);
224229

225230
expect(mockApiClient.get).toHaveBeenCalledWith(
226231
MAESTRO_ENDPOINTS.TRACES.GET_SPANS(instanceId),
227-
{}
232+
{
233+
headers: expect.objectContaining({
234+
[FOLDER_KEY]: folderKey
235+
})
236+
}
228237
);
229238

230239
expect(result).toHaveLength(1);
@@ -235,6 +244,7 @@ describe('ProcessInstancesService', () => {
235244

236245
it('should only include spans matched to elementRuns', async () => {
237246
const instanceId = MAESTRO_TEST_CONSTANTS.INSTANCE_ID;
247+
const folderKey = MAESTRO_TEST_CONSTANTS.FOLDER_KEY;
238248
const unmatchedSpan = createMockTraceSpan({
239249
Id: 'nested-agent-span-1',
240250
ParentId: MAESTRO_TEST_CONSTANTS.SPAN_ID,
@@ -246,7 +256,7 @@ describe('ProcessInstancesService', () => {
246256
.mockResolvedValueOnce(createMockElementExecutionsResponse())
247257
.mockResolvedValueOnce([createMockTraceSpan(), unmatchedSpan]);
248258

249-
const result = await service.getExecutionHistory(instanceId);
259+
const result = await service.getExecutionHistory(instanceId, folderKey);
250260

251261
// Only the matched elementRun span should be included
252262
expect(result).toHaveLength(1);
@@ -257,7 +267,7 @@ describe('ProcessInstancesService', () => {
257267
const error = new Error(TEST_CONSTANTS.ERROR_MESSAGE);
258268
mockApiClient.get.mockRejectedValue(error);
259269

260-
await expect(service.getExecutionHistory(MAESTRO_TEST_CONSTANTS.INSTANCE_ID)).rejects.toThrow(TEST_CONSTANTS.ERROR_MESSAGE);
270+
await expect(service.getExecutionHistory(MAESTRO_TEST_CONSTANTS.INSTANCE_ID, MAESTRO_TEST_CONSTANTS.FOLDER_KEY)).rejects.toThrow(TEST_CONSTANTS.ERROR_MESSAGE);
261271
});
262272
});
263273

0 commit comments

Comments
 (0)