Skip to content

Commit f3b09eb

Browse files
chore: implement respect_max_steps (#1945)
* chore: implement respect_max_steps * chore: remove recors from fake-db * chore: fix git ignore * chore: update e2e snapshot * chore: fix json logs * chore: fix types --------- Co-authored-by: DmitryAnansky <[email protected]>
1 parent 77d1c1b commit f3b09eb

File tree

14 files changed

+330
-58
lines changed

14 files changed

+330
-58
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fake-db.json
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
11
{
2-
"items": [
3-
{
4-
"id": "a959",
5-
"value": 9
6-
},
7-
{
8-
"id": "1768",
9-
"value": 6
10-
},
11-
{
12-
"id": "6e43",
13-
"value": 10
14-
},
15-
{
16-
"id": "8cf3",
17-
"value": 7
18-
}
19-
]
2+
"items": []
203
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should quit an infinite loop on RESPECT_MAX_STEPS 1`] = `
4+
"────────────────────────────────────────────────────────────────────────────────
5+
6+
Running workflow arazzo.yaml / infinite
7+
8+
✗ GET /ping - step pre-step
9+
10+
    Request URL: https://bad-api-url.com/api/ping
11+
12+
    ✗ failed network request
13+
14+
Running failure action continue for the step pre-step
15+
16+
Running child workflow for the step with-nested
17+
Running workflow arazzo.yaml / nested-workflow
18+
19+
✗ GET /ping - step step-1
20+
21+
    Request URL: https://bad-api-url.com/api/ping
22+
23+
    ✗ failed network request
24+
25+
Running failure action next-step for the step step-1
26+
27+
✗ GET /ping - step step-2
28+
29+
    Request URL: https://bad-api-url.com/api/ping
30+
31+
    ✗ failed network request
32+
33+
34+
35+
✗ GET /ping - step ping
36+
37+
    Request URL: https://bad-api-url.com/api/ping
38+
39+
    ✗ failed network request
40+
41+
Running failure action infinite-loop for the step ping
42+
43+
✗ GET /ping - step ping
44+
45+
    Request URL: https://bad-api-url.com/api/ping
46+
47+
    ✗ failed network request
48+
49+
Running failure action infinite-loop for the step ping
50+
51+
✗ GET /ping - step ping
52+
53+
    Request URL: https://bad-api-url.com/api/ping
54+
55+
    ✗ failed network request
56+
57+
Running failure action infinite-loop for the step ping
58+
59+
✗ GET /ping - step ping
60+
61+
    Request URL: https://bad-api-url.com/api/ping
62+
63+
    ✗ failed network request
64+
65+
Running failure action infinite-loop for the step ping
66+
67+
✗ GET /ping - step ping
68+
69+
    Request URL: https://bad-api-url.com/api/ping
70+
71+
    ✗ failed network request
72+
73+
Running failure action infinite-loop for the step ping
74+
75+
✗ GET /ping - step ping
76+
77+
    Request URL: https://bad-api-url.com/api/ping
78+
79+
    ✗ failed network request
80+
81+
Running failure action infinite-loop for the step ping
82+
83+
✗ GET /ping - step ping
84+
85+
    Request URL: https://bad-api-url.com/api/ping
86+
87+
    ✗ failed network request
88+
89+
Running failure action infinite-loop for the step ping
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
  Failed tests info:
101+
102+
  Workflow name: infinite
103+
104+
    stepId - pre-step
105+
    ✗ failed network request
106+
      fetch failed
107+
      
108+
    stepId - step-1
109+
    ✗ failed network request
110+
      fetch failed
111+
      
112+
    stepId - step-2
113+
    ✗ failed network request
114+
      fetch failed
115+
      
116+
    stepId - ping
117+
    ✗ failed network request
118+
      fetch failed
119+
      
120+
    stepId - ping
121+
    ✗ failed network request
122+
      fetch failed
123+
      
124+
    stepId - ping
125+
    ✗ failed network request
126+
      fetch failed
127+
      
128+
    stepId - ping
129+
    ✗ failed network request
130+
      fetch failed
131+
      
132+
    stepId - ping
133+
    ✗ failed network request
134+
      fetch failed
135+
      
136+
    stepId - ping
137+
    ✗ failed network request
138+
      fetch failed
139+
      
140+
    stepId - ping
141+
    ✗ failed network request
142+
      fetch failed
143+
      
144+
    stepId - ping
145+
    ✗ unexpected error
146+
    Reason: Max steps (10) reached
147+
  Summary for arazzo.yaml
148+
  
149+
  Workflows: 1 failed, 1 total
150+
  Steps: 11 failed, 11 total
151+
  Checks: 11 failed, 11 total
152+
  Time: <test>ms
153+
154+
155+
┌─────────────────────────────────────────────────────┬────────────┬─────────┬─────────┬──────────┬─────────┐
156+
│ Filename │ Workflows │ Passed │ Failed │ Warnings │ Skipped │
157+
├─────────────────────────────────────────────────────┼────────────┼─────────┼─────────┼──────────┼─────────┤
158+
│ x arazzo.yaml │ 1 │ 0 │ 1 │ - │ - │
159+
└─────────────────────────────────────────────────────┴────────────┴─────────┴─────────┴──────────┴─────────┘
160+
161+
162+
163+
Tests exited with error
164+
"
165+
`;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
arazzo: 1.0.1
2+
info:
3+
title: Arazzo
4+
version: 1.0.0
5+
description: Test infinite loop
6+
sourceDescriptions:
7+
- name: oas
8+
type: openapi
9+
url: ./oas.yaml
10+
workflows:
11+
- workflowId: infinite
12+
steps:
13+
- stepId: pre-step
14+
description: Pre-step
15+
operationId: ping
16+
onFailure:
17+
- name: continue
18+
type: goto
19+
stepId: with-nested
20+
21+
- stepId: with-nested
22+
description: With nested workflow
23+
workflowId: nested-workflow
24+
25+
- stepId: ping
26+
description: Ping the API
27+
operationId: ping
28+
onFailure:
29+
- name: infinite-loop
30+
type: goto
31+
stepId: ping
32+
33+
- workflowId: nested-workflow
34+
steps:
35+
- stepId: step-1
36+
description: Step 1
37+
operationId: ping
38+
onFailure:
39+
- name: next-step
40+
type: goto
41+
stepId: step-2
42+
- stepId: step-2
43+
description: Step 2
44+
operationId: ping
45+
onFailure:
46+
- name: end
47+
type: end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { getParams, getCommandOutput } from '../utils';
2+
import { join } from 'path';
3+
4+
test('should quit an infinite loop on RESPECT_MAX_STEPS', () => {
5+
const indexEntryPoint = join(process.cwd(), 'packages/cli/lib/index.js');
6+
const fixturesPath = join(__dirname, 'arazzo.yaml');
7+
const args = getParams(indexEntryPoint, [
8+
'respect',
9+
fixturesPath,
10+
'--verbose',
11+
'--workflow',
12+
'infinite',
13+
]);
14+
15+
const result = getCommandOutput(args, {
16+
RESPECT_MAX_STEPS: '10',
17+
});
18+
19+
expect(result).toMatchSnapshot();
20+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Arazzo
4+
version: 1.0.0
5+
description: Arazzo API
6+
license:
7+
name: MIT
8+
servers:
9+
- url: https://bad-api-url.com/api
10+
paths:
11+
/ping:
12+
get:
13+
security: []
14+
summary: Ping
15+
operationId: ping
16+
responses:
17+
'200':
18+
description: A list of users

__tests__/respect/severity-off-level/__snapshots__/severity-off-level.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ exports[`should use off severity level 1`] = `
346346
┌─────────────────────────────────────────────────────────────┬────────────┬─────────┬─────────┬──────────┬─────────┐
347347
│ Filename │ Workflows │ Passed │ Failed │ Warnings │ Skipped │
348348
├─────────────────────────────────────────────────────────────┼────────────┼─────────┼─────────┼──────────┼─────────┤
349-
│ ✓ severity-level.yaml │ 2 │ 2 │ - │ - │ 2
349+
│ ✓ severity-level.yaml │ 2 │ 2 │ - │ - │ -
350350
└─────────────────────────────────────────────────────────────┴────────────┴─────────┴─────────┴──────────┴─────────┘
351351
352352

__tests__/respect/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function getParams(indexEntryPoint: string, args: string[] = []): string[
77
return [indexEntryPoint, ...args];
88
}
99

10-
export function getCommandOutput(args: string[]) {
10+
export function getCommandOutput(args: string[], env?: Record<string, string>) {
1111
const result = spawnSync('node', args, {
1212
encoding: 'utf-8',
1313
stdio: 'pipe',
@@ -16,6 +16,7 @@ export function getCommandOutput(args: string[]) {
1616
NODE_ENV: 'test',
1717
NO_COLOR: 'TRUE',
1818
FORCE_COLOR: '0',
19+
...env,
1920
},
2021
});
2122

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
8787
if (jsonOutputFile) {
8888
writeFileSync(
8989
jsonOutputFile,
90-
JSON.stringify({
91-
files: composeJsonLogsFiles(runAllFilesResult),
92-
status: hasProblems ? 'error' : hasWarnings ? 'warn' : 'success',
93-
totalTime: performance.now() - startedAt,
94-
} as JsonLogs),
90+
JSON.stringify(
91+
{
92+
files: composeJsonLogsFiles(runAllFilesResult),
93+
status: hasProblems ? 'error' : hasWarnings ? 'warn' : 'success',
94+
totalTime: performance.now() - startedAt,
95+
} as JsonLogs,
96+
null,
97+
2
98+
),
9599
'utf-8'
96100
);
97101
logger.log(blue(indent(`JSON logs saved in ${green(jsonOutputFile)}`, 2)));

0 commit comments

Comments
 (0)