Skip to content

Commit 5ac2ac4

Browse files
feat: add support for version bounded parsing and migration (hoppscotch#5127)
- CLI Collection runner enhancements: - Support mixed versions - child collections based on different versions compared to the parent collection. - Better support for incoming data via IDs conforming to older formats. - Bump `verzod` across packages. - Relevant updates to test suite. - Bump `zod` under `selfhost-desktop`.
1 parent 07c7917 commit 5ac2ac4

File tree

20 files changed

+446
-102
lines changed

20 files changed

+446
-102
lines changed

packages/hoppscotch-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hoppscotch/cli",
3-
"version": "0.23.0",
3+
"version": "0.23.1",
44
"description": "A CLI to run Hoppscotch test scripts in CI environments.",
55
"homepage": "https://hoppscotch.io",
66
"type": "module",
@@ -50,7 +50,7 @@
5050
"lodash-es": "4.17.21",
5151
"papaparse": "5.4.1",
5252
"qs": "6.13.0",
53-
"verzod": "0.2.4",
53+
"verzod": "0.3.0",
5454
"xmlbuilder2": "3.1.1",
5555
"zod": "3.25.32"
5656
},

packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ describe("hopp test [options] <file_path_or_id>", { timeout: 100000 }, () => {
8989
expect(error).toBeNull();
9090
});
9191
});
92+
93+
describe("Mixed versions", () => {
94+
test("Successfully processes children based on valid version ranges", async () => {
95+
const args = `test ${getTestJsonFilePath("valid-mixed-versions-coll.json", "collection")}`;
96+
const { error } = await runCLI(args);
97+
98+
expect(error).toBeNull();
99+
});
100+
101+
test("Errors with the code `MALFORMED_COLLECTION` if the children fall out of valid version ranges", async () => {
102+
const args = `test ${getTestJsonFilePath("invalid-mixed-versions-coll.json", "collection")}`;
103+
104+
const { stderr } = await runCLI(args);
105+
const out = getErrorCode(stderr);
106+
107+
expect(out).toBe<HoppErrorCode>("MALFORMED_COLLECTION");
108+
});
109+
});
92110
});
93111

94112
describe("Environments", () => {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"v": 5,
3+
"id": "cmbgcmyly10yhdjet63hiorps",
4+
"name": "Invalid mixed versions collection",
5+
"folders": [
6+
{
7+
"v": 8,
8+
"id": "cmbgnb4h100v613phgrz6vku9",
9+
"name": "fold1",
10+
"folders": [],
11+
"requests": [
12+
{
13+
"v": "13",
14+
"name": "req",
15+
"method": "GET",
16+
"endpoint": "https://echo.hoppscotch.io",
17+
"params": [],
18+
"headers": [],
19+
"preRequestScript": "",
20+
"testScript": "",
21+
"auth": {
22+
"authType": "inherit",
23+
"authActive": true
24+
},
25+
"body": {
26+
"contentType": null,
27+
"body": null
28+
},
29+
"requestVariables": [],
30+
"responses": {}
31+
}
32+
],
33+
"auth": {
34+
"authType": "inherit",
35+
"authActive": true
36+
},
37+
"headers": [],
38+
"_ref_id": "coll_mbgnb8zy_eab190e2-6770-428c-8645-f49e88a3fe90"
39+
}
40+
],
41+
"requests": [],
42+
"auth": {
43+
"authType": "inherit",
44+
"authActive": true
45+
},
46+
"headers": [],
47+
"_ref_id": "coll_mbgnb8zy_7c3f6eca-bd94-44a5-90e3-3f7c2126d63e"
48+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"v": 8,
3+
"id": "cmbgcmyly10yhdjet63hiorps",
4+
"name": "Valid mixed versions collection",
5+
"folders": [
6+
{
7+
"v": 7,
8+
"id": "cmbgnb4h100v613phgrz6vku9",
9+
"name": "fold1",
10+
"folders": [
11+
{
12+
"v": 6,
13+
"id": "cmbhux44609zs2triccmql79r",
14+
"name": "fold2",
15+
"folders": [
16+
{
17+
"v": 5,
18+
"id": "cmbhux6es09zv2triton3kzv4",
19+
"name": "fold3",
20+
"folders": [
21+
{
22+
"v": 4,
23+
"id": "cmbhux9vo0b2t13ph6dwapwh3",
24+
"name": "fold4",
25+
"folders": [],
26+
"requests": [
27+
{
28+
"v": "13",
29+
"name": "req",
30+
"method": "GET",
31+
"endpoint": "https://echo.hoppscotch.io",
32+
"params": [],
33+
"headers": [],
34+
"preRequestScript": "",
35+
"testScript": "",
36+
"auth": {
37+
"authType": "inherit",
38+
"authActive": true
39+
},
40+
"body": {
41+
"contentType": null,
42+
"body": null
43+
},
44+
"requestVariables": [],
45+
"responses": {}
46+
}
47+
],
48+
"auth": {
49+
"authType": "inherit",
50+
"authActive": true
51+
},
52+
"headers": [],
53+
"_ref_id": "coll_mbhuxoci_023b77eb-ed0c-4ec7-97ca-f46cf327cc54"
54+
}
55+
],
56+
"requests": [],
57+
"auth": {
58+
"authType": "inherit",
59+
"authActive": true
60+
},
61+
"headers": [],
62+
"_ref_id": "coll_mbhuxoci_d22767f4-fd0a-4264-a86a-ba4a87c009cb"
63+
}
64+
],
65+
"requests": [],
66+
"auth": {
67+
"authType": "inherit",
68+
"authActive": true
69+
},
70+
"headers": [],
71+
"_ref_id": "coll_mbhuxoci_0effd54f-8e08-441f-9b44-95d02ff1861e"
72+
}
73+
],
74+
"requests": [],
75+
"auth": {
76+
"authType": "inherit",
77+
"authActive": true
78+
},
79+
"headers": [],
80+
"_ref_id": "coll_mbhuxoci_d7eee2ab-a921-447f-931d-bdce8c715770"
81+
}
82+
],
83+
"requests": [],
84+
"auth": {
85+
"authType": "inherit",
86+
"authActive": true
87+
},
88+
"headers": [],
89+
"_ref_id": "coll_mbhuxoci_a8fc710e-04c1-489c-a183-7f16946a7225"
90+
}

packages/hoppscotch-cli/src/__tests__/unit/fixtures/workspace-access.mock.ts

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,81 @@ export const TRANSFORMED_COLLECTIONS_WITHOUT_AUTH_HEADERS_AT_CERTAIN_LEVELS_MOCK
13651365
},
13661366
];
13671367

1368-
export const WORKSPACE_ENVIRONMENT_MOCK: WorkspaceEnvironment = {
1368+
export const WORKSPACE_ENVIRONMENT_V0_FORMAT_MOCK = {
1369+
id: "clwudd68q00079rufju8uo3om",
1370+
teamID: "clws3hg58000011o8h07glsb1",
1371+
name: "Workspace environment v0 format",
1372+
variables: [
1373+
{
1374+
key: "firstName",
1375+
value: "John",
1376+
},
1377+
{
1378+
key: "lastName",
1379+
value: "Doe",
1380+
},
1381+
],
1382+
};
1383+
1384+
export const TRANSFORMED_ENVIRONMENT_V0_FORMAT_MOCK: Environment = {
1385+
v: EnvironmentSchemaVersion,
1386+
id: "clwudd68q00079rufju8uo3om",
1387+
name: "Workspace environment v0 format",
1388+
variables: [
1389+
{
1390+
key: "firstName",
1391+
initialValue: "John",
1392+
currentValue: "John",
1393+
secret: false,
1394+
},
1395+
{
1396+
key: "lastName",
1397+
initialValue: "Doe",
1398+
currentValue: "Doe",
1399+
secret: false,
1400+
},
1401+
],
1402+
};
1403+
1404+
export const WORKSPACE_ENVIRONMENT_V1_FORMAT_MOCK = {
1405+
id: "clwudd68q00079rufju8uo3om",
1406+
teamID: "clws3hg58000011o8h07glsb1",
1407+
name: "Workspace environment v1 format",
1408+
variables: [
1409+
{
1410+
key: "firstName",
1411+
value: "John",
1412+
secret: false,
1413+
},
1414+
{
1415+
key: "lastName",
1416+
value: "Doe",
1417+
secret: false,
1418+
},
1419+
],
1420+
};
1421+
1422+
export const TRANSFORMED_ENVIRONMENT_V1_FORMAT_MOCK: Environment = {
1423+
v: EnvironmentSchemaVersion,
1424+
id: "clwudd68q00079rufju8uo3om",
1425+
name: "Workspace environment v1 format",
1426+
variables: [
1427+
{
1428+
key: "firstName",
1429+
initialValue: "John",
1430+
currentValue: "John",
1431+
secret: false,
1432+
},
1433+
{
1434+
key: "lastName",
1435+
initialValue: "Doe",
1436+
currentValue: "Doe",
1437+
secret: false,
1438+
},
1439+
],
1440+
};
1441+
1442+
export const WORKSPACE_ENVIRONMENT_V2_FORMAT_MOCK: WorkspaceEnvironment = {
13691443
id: "clwudd68q00079rufju8uo3on",
13701444
teamID: "clws3hg58000011o8h07glsb1",
13711445
name: "Response body sample",
@@ -1421,7 +1495,7 @@ export const WORKSPACE_ENVIRONMENT_MOCK: WorkspaceEnvironment = {
14211495
],
14221496
};
14231497

1424-
export const TRANSFORMED_ENVIRONMENT_MOCK: Environment = {
1498+
export const TRANSFORMED_ENVIRONMENT_V2_FORMAT_MOCK: Environment = {
14251499
v: EnvironmentSchemaVersion,
14261500
id: "clwudd68q00079rufju8uo3on",
14271501
name: "Response body sample",

packages/hoppscotch-cli/src/__tests__/unit/workspace-access.spec.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import {
77
import {
88
TRANSFORMED_COLLECTIONS_WITHOUT_AUTH_HEADERS_AT_CERTAIN_LEVELS_MOCK,
99
TRANSFORMED_DEEPLY_NESTED_COLLECTIONS_WITH_AUTH_HEADERS_MOCK,
10-
TRANSFORMED_ENVIRONMENT_MOCK,
10+
TRANSFORMED_ENVIRONMENT_V0_FORMAT_MOCK,
11+
TRANSFORMED_ENVIRONMENT_V1_FORMAT_MOCK,
12+
TRANSFORMED_ENVIRONMENT_V2_FORMAT_MOCK,
1113
TRANSFORMED_MULTIPLE_CHILD_COLLECTIONS_WITH_AUTH_HEADERS_MOCK,
1214
WORKSPACE_COLLECTIONS_WITHOUT_AUTH_HEADERS_AT_CERTAIN_LEVELS_MOCK,
1315
WORKSPACE_DEEPLY_NESTED_COLLECTIONS_WITH_AUTH_HEADERS_MOCK,
14-
WORKSPACE_ENVIRONMENT_MOCK,
16+
WORKSPACE_ENVIRONMENT_V0_FORMAT_MOCK,
17+
WORKSPACE_ENVIRONMENT_V1_FORMAT_MOCK,
18+
WORKSPACE_ENVIRONMENT_V2_FORMAT_MOCK,
1519
WORKSPACE_MULTIPLE_CHILD_COLLECTIONS_WITH_AUTH_HEADERS_MOCK,
1620
} from "./fixtures/workspace-access.mock";
1721

@@ -45,10 +49,24 @@ describe("workspace-access", () => {
4549
});
4650

4751
describe("transformWorkspaceEnvironment", () => {
48-
test("Successfully transforms environment data conforming to the format received from the network call to the `HoppEnvironment` format", () => {
49-
expect(transformWorkspaceEnvironment(WORKSPACE_ENVIRONMENT_MOCK)).toEqual(
50-
TRANSFORMED_ENVIRONMENT_MOCK
51-
);
52+
test("Successfully transforms environment data conforming to the `v0` format received from the network call to the `HoppEnvironment` format", () => {
53+
expect(
54+
// @ts-expect-error: Testing legacy format transformation
55+
transformWorkspaceEnvironment(WORKSPACE_ENVIRONMENT_V0_FORMAT_MOCK)
56+
).toEqual(TRANSFORMED_ENVIRONMENT_V0_FORMAT_MOCK);
57+
});
58+
59+
test("Successfully transforms environment data conforming to the `v1` format received from the network call to the `HoppEnvironment` format", () => {
60+
expect(
61+
// @ts-expect-error: Testing legacy format transformation
62+
transformWorkspaceEnvironment(WORKSPACE_ENVIRONMENT_V1_FORMAT_MOCK)
63+
).toEqual(TRANSFORMED_ENVIRONMENT_V1_FORMAT_MOCK);
64+
});
65+
66+
test("Successfully transforms environment data conforming to the `v2` format received from the network call to the `HoppEnvironment` format", () => {
67+
expect(
68+
transformWorkspaceEnvironment(WORKSPACE_ENVIRONMENT_V2_FORMAT_MOCK)
69+
).toEqual(TRANSFORMED_ENVIRONMENT_V2_FORMAT_MOCK);
5270
});
5371
});
5472
});

0 commit comments

Comments
 (0)