Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/api/local-workflow-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ export class LocalWorkflowStore {

getInstancesByBusinessKey(
businessKey: string,
status?: WorkflowStatus | WorkflowStatus[],
status?: WorkflowStatus[],
): LocalWorkflowInstance[] {
let filtered = this.instances.filter((i) => i.businessKey === businessKey);

if (status) {
const statuses = Array.isArray(status) ? status : [status];
filtered = filtered.filter((i) => statuses.includes(i.status));
filtered = filtered.filter((i) => status.includes(i.status));
}

return filtered;
Expand All @@ -81,7 +80,7 @@ export class LocalWorkflowStore {
}

updateStatus(instanceId: string, status: WorkflowStatus): UpdateStatusResult {
const instance = this.instances.find((i) => i.id === instanceId);
const instance = this.getInstance(instanceId);

if (!instance) {
return {
Expand All @@ -104,18 +103,14 @@ export class LocalWorkflowStore {
}

getAttributes(instanceId: string): Record<string, string>[] | undefined {
const instance = this.instances.find((i) => i.id === instanceId);
const instance = this.getInstance(instanceId);
return instance?.attributes;
}

getOutputs(instanceId: string): Record<string, unknown> | undefined {
const instance = this.instances.find((i) => i.id === instanceId);
const instance = this.getInstance(instanceId);
return instance?.outputs;
}

clear(): void {
this.instances = [];
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Removing clear() breaks test isolation for LocalWorkflowStore

The clear() method was the only way to reset the singleton localWorkflowStore between test runs. Since localWorkflowStore is a module-level singleton, tests that share the same process will accumulate instances across test cases. Without clear(), there is no mechanism to reset state, which can cause cross-test contamination and flaky test results.

Consider retaining the clear() method, or provide an alternative reset mechanism (e.g., a reset() alias) to support test isolation.

Suggested change
}
clear(): void {
this.instances = [];
}
}

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful


export const localWorkflowStore = new LocalWorkflowStore();
7 changes: 3 additions & 4 deletions lib/api/workflow-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface IWorkflowInstanceClient {

getWorkflowsByBusinessKey(
businessKey: string,
status: WorkflowStatus | WorkflowStatus[],
status: WorkflowStatus[],
): Promise<WorkflowInstance[]>;

updateWorkflowStatus(
Expand Down Expand Up @@ -93,13 +93,12 @@ export async function getWorkflowsByBusinessKey(
serviceUrl: string,
jwt: string,
businessKey: string,
status: WorkflowStatus | WorkflowStatus[],
status: WorkflowStatus[],
): Promise<WorkflowInstance[]> {
const encodedBusinessKey = encodeURIComponent(businessKey);
let queryUrl = `${serviceUrl}${BASE_PATH}/v1/workflow-instances?businessKey=${encodedBusinessKey}`;

const statuses = Array.isArray(status) ? status : [status];
statuses.forEach((s) => {
status.forEach((s) => {
queryUrl += `&status=${s}`;
});
LOG.debug('Invoking url: ' + queryUrl);
Expand Down
10 changes: 4 additions & 6 deletions srv/localProcessService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ class ProcessService extends cds.ApplicationService {
`==============================================================`,
);

const instances = localWorkflowStore.getInstancesByBusinessKey(
businessKey,
const instances = localWorkflowStore.getInstancesByBusinessKey(businessKey, [
WorkflowStatus.RUNNING,
);
]);

if (instances.length === 0) {
LOG.warn(`No running workflow instances found with businessKey: ${businessKey}`);
Expand Down Expand Up @@ -102,10 +101,9 @@ class ProcessService extends cds.ApplicationService {
`==============================================================`,
);

const instances = localWorkflowStore.getInstancesByBusinessKey(
businessKey,
const instances = localWorkflowStore.getInstancesByBusinessKey(businessKey, [
WorkflowStatus.SUSPENDED,
);
]);

if (instances.length === 0) {
LOG.warn(`No suspended workflow instances found with businessKey: ${businessKey}`);
Expand Down