Skip to content

Commit ee8f914

Browse files
committed
chore(respect): changes after review
1 parent adb2b59 commit ee8f914

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const RESPECT_TIMEOUT = 3600000; // 1 hour in milliseconds
2-
export const MAX_FETCH_TIMEOUT = 20000; // 20 seconds in milliseconds
1+
export const DEFAULT_RESPECT_TIMEOUT = 3600000; // 1 hour in milliseconds
2+
export const DEFAULT_MAX_FETCH_TIMEOUT = 20000; // 20 seconds in milliseconds

packages/respect-core/src/handlers/run.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { DefaultLogger } from '../utils/logger/logger';
1212
import { exitWithError } from '../utils/exit-with-error';
1313
import { writeFileSync } from 'node:fs';
1414
import { indent } from '../utils/cli-outputs';
15-
import { Timer } from '../modules/timeout-timer';
16-
import { type JsonLogs, type CommandArgs, type RunArgv } from '../types';
15+
import { Timer } from '../modules/timeout-timer/timer';
16+
17+
import type { JsonLogs, CommandArgs, RunArgv } from '../types';
1718

1819
export type RespectOptions = {
1920
files: string[];

packages/respect-core/src/modules/__tests__/flow-runner/run-step.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3990,7 +3990,9 @@ describe('runStep', () => {
39903990
const mockTimer = {
39913991
isTimedOut: jest.fn().mockReturnValue(true),
39923992
};
3993-
jest.spyOn(require('../../timeout-timer').Timer, 'getInstance').mockReturnValue(mockTimer);
3993+
jest
3994+
.spyOn(require('../../timeout-timer/timer').Timer, 'getInstance')
3995+
.mockReturnValue(mockTimer);
39943996

39953997
const checks: Check[] = [];
39963998
const step = {

packages/respect-core/src/modules/cli-output/display-errors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export function displayErrors(workflows: WorkflowExecutionResult[]) {
4848

4949
for (const failedCheckIndex in failedStepChecks) {
5050
const { name, message, severity } = failedStepChecks[failedCheckIndex];
51-
const showErrorMessage = ![
51+
const showRespectInnerErrorMessage = [
5252
CHECKS.UNEXPECTED_ERROR,
5353
CHECKS.GLOBAL_TIMEOUT_ERROR,
5454
CHECKS.MAX_STEPS_REACHED_ERROR,
5555
].includes(name);
56-
const messageToDisplay = showErrorMessage
57-
? indent(`${removeExtraIndentation(message)}${RESET_ESCAPE_CODE}\n`, 6)
58-
: indent(`Reason: ${message}`, 4);
56+
const messageToDisplay = showRespectInnerErrorMessage
57+
? indent(`Reason: ${message}`, 4)
58+
: indent(`${removeExtraIndentation(message)}${RESET_ESCAPE_CODE}\n`, 6);
5959

6060
logger.printNewLine();
6161

packages/respect-core/src/modules/flow-runner/run-step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '../config-parser';
1919
import { evaluateRuntimeExpressionPayload } from '../runtime-expressions';
2020
import { DefaultLogger } from '../../utils/logger/logger';
21-
import { Timer } from '../timeout-timer';
21+
import { Timer } from '../timeout-timer/timer';
2222

2323
import type {
2424
Check,

packages/respect-core/src/modules/timeout-timer/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/respect-core/src/modules/timeout-timer/timer.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RESPECT_TIMEOUT } from '../../consts';
1+
import { DEFAULT_RESPECT_TIMEOUT } from '../../consts';
22

33
export class Timer {
44
private static instance: Timer;
@@ -16,10 +16,9 @@ export class Timer {
1616
}
1717

1818
public isTimedOut(): boolean {
19-
const elapsedTime = Date.now() - this.startTime;
20-
const timeout = parseInt(process.env.RESPECT_TIMEOUT || RESPECT_TIMEOUT.toString(), 10);
21-
const remainingTime = Math.max(0, timeout - elapsedTime);
22-
23-
return remainingTime <= 0;
19+
const timeout = isNaN(+(process.env.RESPECT_TIMEOUT as string))
20+
? DEFAULT_RESPECT_TIMEOUT
21+
: +(process.env.RESPECT_TIMEOUT as string);
22+
return Date.now() - this.startTime > timeout;
2423
}
2524
}

packages/respect-core/src/utils/api-fetcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getResponseSchema } from '../modules/description-parser';
1717
import { collectSecretFields } from '../modules/flow-runner';
1818
import { createMtlsClient } from './mtls/create-mtls-client';
1919
import { DefaultLogger } from './logger/logger';
20-
import { MAX_FETCH_TIMEOUT } from '../consts';
20+
import { DEFAULT_MAX_FETCH_TIMEOUT } from '../consts';
2121

2222
import type { RequestData } from '../modules/flow-runner';
2323

@@ -239,7 +239,7 @@ export class ApiFetcher implements IFetcher {
239239
body: encodedBody,
240240
}),
241241
redirect: 'follow',
242-
signal: AbortSignal.timeout(MAX_FETCH_TIMEOUT),
242+
signal: AbortSignal.timeout(DEFAULT_MAX_FETCH_TIMEOUT),
243243
// Required for application/octet-stream content type requests
244244
...(headers['content-type'] === 'application/octet-stream' && {
245245
duplex: 'half',

0 commit comments

Comments
 (0)