Skip to content

Commit df1f8ce

Browse files
[dev] [Marfuen] mariano/trigger-errors-3 (#1733)
* refactor: dont crash trigger on cloud tests job * chore: fix types * chore: add forced fail prop for testing * chore: fix types * refactor(cloud-tests): integrate trigger token creation and update session handling * refactor(cloud-tests): remove debug console logs from TestsLayout * chore: remove leftover code * chore: dont throw --------- Co-authored-by: Mariano Fuentes <[email protected]>
1 parent 0d34e8b commit df1f8ce

File tree

2 files changed

+33
-44
lines changed

2 files changed

+33
-44
lines changed

apps/app/src/jobs/tasks/integration/integration-results.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export const sendIntegrationResults = schemaTask({
113113
logger.info(`Integration run completed for ${integration.name}`);
114114
return { success: true, totalResults: results.length, results };
115115
} catch (error) {
116-
logger.error(`Error running integration: ${error}`);
116+
const errorMessage = error instanceof Error ? error.message : String(error);
117+
logger.error(`Error running integration: ${errorMessage}`);
117118

118119
// Record the failure using model name that matches the database
119120
try {
@@ -125,7 +126,7 @@ export const sendIntegrationResults = schemaTask({
125126
status: 'error',
126127
severity: 'ERROR',
127128
resultDetails: {
128-
error: error instanceof Error ? error.message : String(error),
129+
error: errorMessage,
129130
},
130131
integrationId: integration.integration_id,
131132
organizationId: integration.organization.id,
@@ -135,7 +136,10 @@ export const sendIntegrationResults = schemaTask({
135136
logger.error(`Failed to create error record: ${createError}`);
136137
}
137138

138-
throw error;
139+
return {
140+
success: false,
141+
error: errorMessage,
142+
};
139143
}
140144
},
141145
});

apps/app/src/jobs/tasks/integration/run-integration-tests.ts

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { sendIntegrationResults } from './integration-results';
44

55
export const runIntegrationTests = task({
66
id: 'run-integration-tests',
7-
run: async (payload: { organizationId: string; forceFailure?: boolean }) => {
8-
const { organizationId, forceFailure = false } = payload;
7+
run: async (payload: { organizationId: string }) => {
8+
const { organizationId } = payload;
99

1010
logger.info(`Running integration tests for organization: ${organizationId}`);
1111

@@ -44,32 +44,6 @@ export const runIntegrationTests = task({
4444
`Found ${integrations.length} integrations to test for organization: ${organizationId}`,
4545
);
4646

47-
if (forceFailure) {
48-
await new Promise((resolve) => setTimeout(resolve, 5000));
49-
50-
const forcedFailureMessage =
51-
'Test failure: intentionally failing integration job for UI verification';
52-
53-
const forcedFailedIntegrations = integrations.map((integration) => ({
54-
id: integration.id,
55-
integrationId: integration.integrationId,
56-
name: integration.name,
57-
error: forcedFailureMessage,
58-
}));
59-
60-
logger.warn(
61-
`Force-failing integration tests for organization ${organizationId}: ${forcedFailureMessage}`,
62-
);
63-
64-
return {
65-
success: false,
66-
organizationId,
67-
integrationsCount: integrations.length,
68-
errors: [forcedFailureMessage],
69-
failedIntegrations: forcedFailedIntegrations,
70-
};
71-
}
72-
7347
const batchItems = integrations.map((integration) => ({
7448
payload: {
7549
integration: {
@@ -94,21 +68,32 @@ export const runIntegrationTests = task({
9468
}> = [];
9569

9670
batchHandle.runs.forEach((run, index) => {
97-
if (run.ok) {
98-
return;
99-
}
100-
10171
const integration = integrations[index];
102-
const errorValue = run.error;
103-
const errorMessage =
104-
errorValue instanceof Error ? errorValue.message : String(errorValue ?? 'Unknown error');
10572

106-
failedIntegrations.push({
107-
id: integration.id,
108-
integrationId: integration.integrationId,
109-
name: integration.name,
110-
error: errorMessage,
111-
});
73+
if (run.ok) {
74+
// Check if the task completed but returned success: false
75+
const runOutput = run.output as { success?: boolean; error?: string } | undefined;
76+
77+
if (runOutput && runOutput.success === false) {
78+
failedIntegrations.push({
79+
id: integration.id,
80+
integrationId: integration.integrationId,
81+
name: integration.name,
82+
error: runOutput.error || 'Integration failed',
83+
});
84+
}
85+
} else {
86+
// Task crashed or threw an error
87+
const errorMessage =
88+
run.error instanceof Error ? run.error.message : String(run.error ?? 'Unknown error');
89+
90+
failedIntegrations.push({
91+
id: integration.id,
92+
integrationId: integration.integrationId,
93+
name: integration.name,
94+
error: errorMessage,
95+
});
96+
}
11297
});
11398

11499
if (failedIntegrations.length > 0) {

0 commit comments

Comments
 (0)