@schwabyio/gta 0.13.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/SPEC.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # The Gravity file format
2
2
 
3
- Version 0.9
3
+ Version 0.14.1, the version of Gravity and `gta` that reads it: the two are released
4
+ together.
4
5
 
5
6
  This document specifies the YAML files that **Gravity**, the desktop app, and **`gta`**,
6
7
  the command-line runner, read and write. Together they make up Gravity Test
@@ -26,18 +27,19 @@ is a complete, valid project to start from.
26
27
 
27
28
  ## At a glance
28
29
 
29
- | File | Where | What it is | § |
30
- | ----------------------------- | ------------------------------------------ | ------------------------------------------- | ---- |
31
- | `collections/<id>.yml` | `collections/`, or one directory inside it | A collection: requests run in order | §2 |
32
- | `collections/<id>.csv\|.json` | Beside its collection | A data file: the collection runs once a row | §2.8 |
33
- | `environments/<name>.yml` | `environments/` | Variables, secrets and flags for one target | §6 |
34
- | `project.yml` | The project folder | Name, global project, variables, trust | §1.1 |
35
- | `settings.yml` | The project folder | How `gta` runs the project | §1.3 |
36
- | `requests/<id>.yml` | `requests/`, or one directory inside it | A request set, run by `use:` | §2.5 |
37
- | `endpoints/<id>.yml` | `endpoints/`, or one directory inside it | Defaults and checks per method and path | §2.6 |
38
- | `bases/<id>.yml` | `bases/`, or one directory inside it | A base collection, for `extends:` | §2.7 |
39
- | `checks/<name>.js` | `checks/` | Shared check functions | §5 |
40
- | `.env` | The project folder, never committed | Values for secrets | §6 |
30
+ | File | Where | What it is | § |
31
+ | ----------------------------- | --------------------------------------- | ------------------------------------------- | ---- |
32
+ | `collections/<id>.yml` | `collections/`, or one folder inside it | A collection: requests run in order | §2 |
33
+ | `collections/<id>.csv\|.json` | Beside its collection | A data file: the collection runs once a row | §2.8 |
34
+ | `environments/<name>.yml` | `environments/` | Variables, secrets and flags for one target | §6 |
35
+ | `project.yml` | The project folder | Name, global project, variables, trust | §1.1 |
36
+ | `settings.yml` | The project folder | How `gta` runs the project | §1.3 |
37
+ | `rules.yml` | The project folder | How the project's files are written | §1.4 |
38
+ | `requests/<id>.yml` | `requests/`, or one folder inside it | Reusable requests, run by `use:` | §2.5 |
39
+ | `endpoints/<id>.yml` | `endpoints/`, or one folder inside it | Defaults and checks per method and path | §2.6 |
40
+ | `bases/<id>.yml` | `bases/`, or one folder inside it | A base collection, for `extends:` | §2.7 |
41
+ | `checks/<name>.js` | `checks/` | Shared check functions | §5 |
42
+ | `.env` | The project folder, never committed | Values for secrets | §6 |
41
43
 
42
44
  The smallest project `gta` runs is three files:
43
45
 
@@ -89,16 +91,17 @@ A **project** is a folder holding `collections/` and, usually, `environments/`:
89
91
  payments/ a project
90
92
  ├── project.yml optional (§1.1)
91
93
  ├── settings.yml how gta runs it (§1.3)
94
+ ├── rules.yml how its files are written (§1.4)
92
95
  ├── collections/
93
96
  │ ├── smoke.yml a collection
94
- │ └── checkout/ a directory grouping collections: one level only
97
+ │ └── checkout/ a folder grouping collections: one level only
95
98
  │ ├── sessions.yml
96
99
  │ ├── sessions.csv its data file (§2.8)
97
100
  │ └── refunds.yml
98
101
  ├── environments/
99
102
  │ ├── local.yml
100
103
  │ └── staging.yml
101
- ├── requests/ request sets (§2.5)
104
+ ├── requests/ reusable requests (§2.5)
102
105
  ├── endpoints/ endpoint bases (§2.6)
103
106
  ├── bases/ base collections (§2.7)
104
107
  ├── checks/ check files (§5)
@@ -106,17 +109,17 @@ payments/ a project
106
109
  └── .env secret values; not committed (§6)
107
110
  ```
108
111
 
109
- **Every `.yml` file directly in `collections/`, or in a directory one level down, is a
112
+ **Every `.yml` file directly in `collections/`, or in a folder one level down, is a
110
113
  collection.** Nothing else is. Discovery is exact: no other `.yml` in a repository is
111
114
  mistaken for a collection. A file that does not parse is reported as a broken
112
115
  collection, never skipped in silence.
113
116
 
114
- - A directory inside a directory of `collections/` is reported as a problem and not
117
+ - A folder inside a folder of `collections/` is reported as a problem and not
115
118
  read. `requests/`, `endpoints/` and `bases/` are read to the same depth, and
116
119
  `checks/` only at its top level.
117
- - Names starting with `.` are ignored, as are the directories `node_modules`, `.git`,
120
+ - Names starting with `.` are ignored, as are the folders `node_modules`, `.git`,
118
121
  `reports`, `test-results`, `out` and `dist`.
119
- - Directories carry no configuration and need no file of their own. They group
122
+ - Folders carry no configuration and need no file of their own. They group
120
123
  collections for display and for running a group.
121
124
 
122
125
  A project is any folder: the root of a repository, or one service of a monorepo. A
@@ -160,8 +163,8 @@ The file is optional, and so is every key in it. Any other key is an error.
160
163
  | `tls.ca` | list of relative paths | none | Certificate files that requests trust (below). |
161
164
 
162
165
  **`uses`** names a **global project**: an ordinary project whose `project.yml`
163
- variables, `environments/`, `requests/`, `endpoints/`, `bases/`, `checks/` and
164
- `settings.yml` every project using it shares.
166
+ variables, `environments/`, `requests/`, `endpoints/`, `bases/`, `checks/`,
167
+ `settings.yml` and `rules.yml` every project using it shares.
165
168
 
166
169
  - It must be a relative path. An absolute path is refused, since it would only work on
167
170
  one machine. Write it with `/`; `\` reads the same.
@@ -170,7 +173,15 @@ variables, `environments/`, `requests/`, `endpoints/`, `bases/`, `checks/` and
170
173
  - An environment in the global project merges under the project's environment of the
171
174
  same name, key by key, and the project's values win. An environment only the global
172
175
  project has is available too.
173
- - The global project's `settings.yml` lies under the project's the same way (§1.3).
176
+ - The global project's `settings.yml` lies under the project's the same way (§1.3), and
177
+ so does its `rules.yml` (§1.4).
178
+ - A global project's own `collections/` is **not** shared: a project using it never
179
+ sees or runs those collections. A global project needs none. It may have one for a
180
+ single purpose: **testing what it shares**. A collection there can `use:` its reusable
181
+ requests, `extends:` its bases and call its checks, against its own environments, so a
182
+ broken shared piece fails in one place, before every project relying on it does.
183
+ Those collections run only when the global project itself does, as a project in
184
+ Gravity or with `gta` in its folder, such as its own CI job.
174
185
 
175
186
  **`tls.ca`** lists certificate files that requests trust, for a server whose certificate
176
187
  a company or local CA signed, or a server's own self-signed certificate. A request
@@ -203,11 +214,11 @@ Projects are shared between macOS, Windows and Linux, and read the same on all t
203
214
  `use:` or `extends:` name, `uses`, a `tls.ca` file, a file a body sends, and an
204
215
  environment's file name. One that differs only in case is an error on every platform,
205
216
  naming the spelling on disk. The folders and files of §1 are lower case.
206
- - **No two names in one directory may differ only in case**, such as `Checkout/` and
217
+ - **No two names in one folder may differ only in case**, such as `Checkout/` and
207
218
  `checkout/`: Linux can hold both, but a macOS or Windows checkout only one. This
208
219
  applies in `collections/`, `requests/`, `endpoints/`, `bases/`, `environments/` and
209
220
  `checks/`. Collection ids are unique ignoring case too (§2).
210
- - File, directory and environment names must avoid what Windows refuses: the characters
221
+ - File, folder and environment names must avoid what Windows refuses: the characters
211
222
  `< > : " / \ | ? *`, control characters, a trailing dot or space, and the names `CON`,
212
223
  `PRN`, `AUX`, `NUL`, `CONIN$`, `CONOUT$`, `COM1`–`COM9` and `LPT1`–`LPT9`, with or
213
224
  without an extension. A file with such a name, made on macOS or Linux, is reported.
@@ -282,7 +293,7 @@ global project's `settings.yml`, the project's, the environment variable, the fl
282
293
  | --------------------- | ----------------------------------------------------------- |
283
294
  | `gta get` | Nothing. It lists what `gta all` would run. |
284
295
  | `gta all` | Every collection, except those with `exclude: true` (§2.4). |
285
- | `gta smoke,checkout/` | The collections and directories named, in that order. |
296
+ | `gta smoke,checkout/` | The collections and folders named, in that order. |
286
297
 
287
298
  `gta get` also reports each `use:` and `extends:` that would stop a run, and each file a
288
299
  body names that is in neither the project nor its global project (§2.2), in every
@@ -290,11 +301,159 @@ collection, including those `gta all` leaves out (Appendix A). A file path with
290
301
  `{{variables}}` is left to the run. It exits `1` when it finds one, or a broken
291
302
  collection, and `0` otherwise.
292
303
 
293
- A collection is named by its `id`, or by its place (`checkout/sessions`). A directory is
294
- named by its name, and `checkout/` names only the directory. `--flag name=value` sets a
304
+ A collection is named by its `id`, or by its place (`checkout/sessions`). A folder is
305
+ named by its name, and `checkout/` names only the folder. `--flag name=value` sets a
295
306
  feature flag (§2.9), and `--json` prints the results as JSON. The exit code is `0` when
296
307
  everything passed, `1` when something failed, and `2` when `gta` could not run.
297
308
 
309
+ ### 1.4 `rules.yml`
310
+
311
+ How a project's files are named, laid out and written, so that everyone working on it,
312
+ people and coding agents alike, keeps it consistent. It sits beside `project.yml`, is
313
+ committed, and is optional. `gta lint` checks the project against it. Gravity, the
314
+ desktop app, marks each file, folder and step that breaks a rule, and will not create or
315
+ rename a file or folder that would.
316
+
317
+ ```yaml
318
+ ids:
319
+ collections: kebab-case # or a pattern, such as '{folder}-[a-z0-9-]+'
320
+ requests: camelCase
321
+ layout:
322
+ folders: required # every collection in a folder of collections/
323
+ folderNames: [accounts, payments, smoke]
324
+ maxSteps: 30
325
+ steps:
326
+ names: required
327
+ url: ^\{\{baseUrl\}\} # no host written out
328
+ docs:
329
+ collections: required
330
+ tags:
331
+ allowed: [smoke, regression, slow]
332
+ tests:
333
+ only: [gta] # tests call the gta.* functions, and nothing else
334
+ statusCode: required
335
+ guide: |
336
+ Name each step for what it proves. Logins go through `requests/login`.
337
+ ```
338
+
339
+ **Rules never change a run.** A file that breaks one opens, sends and runs as before.
340
+ `gta lint` reports it, and a CI job running `gta lint` fails on it. Gravity marks it, and
341
+ flags what `tests.only` does not allow as a script is typed.
342
+
343
+ | Rule | Value | What it checks |
344
+ | -------------------- | ---------------------- | ------------------------------------------------------------------------------- |
345
+ | `ids.collections` | style or pattern | Each collection's id, its file name (§2). |
346
+ | `ids.requests` | style or pattern | Each reusable requests file's id (§2.5). |
347
+ | `ids.bases` | style or pattern | Each base collection's id (§2.7). |
348
+ | `ids.endpoints` | style or pattern | Each endpoints file's id (§2.6). |
349
+ | `layout.folders` | `required` | Every collection sits in a folder of `collections/`, none at its top. |
350
+ | `layout.folderNames` | list, style or pattern | Each folder of `collections/`: one of the list, or following the format. |
351
+ | `layout.maxSteps` | integer ≥ 1 | The most steps a collection has in `steps`; `setup` and `teardown` aside. |
352
+ | `steps.names` | `required` | Every step has a `name`, and no other step of its file has the same one. |
353
+ | `steps.url` | pattern | Every request step's URL, as written, matches it (below). |
354
+ | `docs.collections` | `required` | Every collection has `docs`. |
355
+ | `docs.requests` | `required` | Every reusable requests file has `docs`. |
356
+ | `docs.steps` | `required` | Every step of a collection or reusable requests file has `docs`, in every list. |
357
+ | `tags.allowed` | list of tags | Every tag on a collection or a step is one of these. |
358
+ | `tags.collections` | `required` | Every collection has `tags` of its own. |
359
+ | `tests.only` | list (below) | What a `tests` script may call. |
360
+ | `tests.everyStep` | `required` | Every step that sends a request or reads a connection is checked (below). |
361
+ | `tests.statusCode` | `required` | Every request step's checks include its status code (below). |
362
+
363
+ - Any other group or rule is an error, as is a value of the wrong type.
364
+ - A rule that takes `required` also takes `optional`, which turns it off.
365
+ - A **style** is one of `kebab-case` (`create-user`), `snake_case` (`create_user`),
366
+ `camelCase` (`createUser`) and `PascalCase` (`CreateUser`). Lower case, in the first two,
367
+ includes digits: `404-handling` is kebab-case.
368
+ - A **pattern** is a JavaScript regular expression that the whole name must match, as if
369
+ it began with `^` and ended with `$`. `{folder}` in it stands for the folder the file is
370
+ in, so `{folder}-[a-z0-9-]+` asks for `collections/payments/payments-refunds.yml`. A
371
+ value that is not a style and has none of a pattern's characters (`^`, `$`, `.`, `*`,
372
+ `+`, `?`, `(`, `)`, `[`, `]`, `{`, `}`, `|` or a backslash) is an error, so a
373
+ misspelled style is not taken for a pattern.
374
+ - Rules check the project's own files, in `collections/`, `requests/`, `bases/` and
375
+ `endpoints/`. A global project's files follow the global project's `rules.yml`, checked
376
+ when `gta lint` runs in its folder.
377
+ - `steps.*`, `docs.steps`, `tests.everyStep` and `tests.statusCode` are about the steps of
378
+ collections and reusable requests files. An endpoint is a method and a path pattern,
379
+ not a step that runs, so they leave endpoints files alone.
380
+
381
+ **`steps.url`** is a JavaScript regular expression that each request step's URL, as
382
+ written with its `{{variables}}`, must match. Unlike an id pattern it is not anchored:
383
+ `^\{\{baseUrl\}\}` asks that every URL start with `{{baseUrl}}`, so no host is written
384
+ out in a step. A use step and a step reading a connection have no URL of their own.
385
+
386
+ **`tests.everyStep` and `tests.statusCode`** count every script that runs after a step's
387
+ response, wherever it is written: the step's own `tests`, its file's, its base
388
+ collection's (§2.7) and its endpoint's (§2.6), unless the step has `base: false`. With
389
+ `tests.statusCode`, one of them calls `gta.expectResponseStatusCodeToBe`, in any branch,
390
+ or calls a check function (§5) whose own code does. A use step is left to its reusable
391
+ requests file, whose steps are checked there. A step reading a connection needs tests
392
+ under `tests.everyStep`, but has no status code of its own to check.
393
+
394
+ **`tests.only`** lists what a `tests` script may call. It must list `gta`:
395
+
396
+ | Entry | Allows |
397
+ | ---------- | --------------------------------------------------------- |
398
+ | `gta` | The `gta.*` functions (§5), except `gta.test`. |
399
+ | `gta.test` | Named checks of your own, with any code inside them (§5). |
400
+ | `checks` | The project's check files, `checks.<file>.<function>()`. |
401
+ | `console` | `console.log()` and the rest. |
402
+
403
+ With `only: [gta]`, a `tests` script holds calls to `gta.*` functions and nothing else:
404
+
405
+ - **Every argument is a value**: a string, number, `true`, `false`, `null` or regular
406
+ expression, a template string, a list or object of values, or `new RegExp(…)` of
407
+ values. It may read `res`, `req`, `params`, `endpoint` and `item` (§5), call another
408
+ `gta.*` function such as `gta.get('id')`, or `JSON.parse` a value, since `gta.set` keeps
409
+ a list or object as JSON text.
410
+ - **An `if` may choose by feature flag** (§2.9): its condition is `gta.flag()` calls
411
+ compared with values, joined by `!`, `&&` and `||`, and what it holds follows the same
412
+ rules.
413
+ - **Nothing else**: no variables, loops, functions of your own, `assert`, `checks.*` or
414
+ `gta.test`. This is checked on the script's syntax, so a call cannot be hidden by
415
+ renaming it (`const c = checks`).
416
+
417
+ ```yaml
418
+ tests: |
419
+ gta.expectResponseStatusCodeToBe(200)
420
+ gta.expectResponseBodyToHaveProperty('owner', gta.get('userId'))
421
+ gta.set('nextPage', res.body.links.next)
422
+ if (gta.flag('newCheckout') === true) {
423
+ gta.expectResponseBodyToHaveProperty('version', 2)
424
+ }
425
+ ```
426
+
427
+ `tests.only` checks every `tests` script: a collection's own and each of its steps', and
428
+ those of reusable requests files, base collections and endpoints files.
429
+ `before.script` is not checked.
430
+
431
+ **`guide`** is Markdown, for what no rule can check: how steps are named, which request
432
+ set a login goes through, what a collection is for. `gta rules` prints it after the
433
+ rules, and Gravity shows it in Project settings. Each file's guide is read, the global
434
+ project's first, so a project adds to a shared guide rather than replacing it.
435
+
436
+ **From the global project.** A global project (§1.1) can have a `rules.yml` too, and it
437
+ lies under the project's, rule by rule. There is no switch to turn this off: a project
438
+ changes a shared rule by setting it in its own file, and turns it off with `null`, or
439
+ `optional` for a `required` rule. A group set to `null`, such as `tags: null`, turns off
440
+ every rule in it. Neither file is required.
441
+
442
+ **Checking.** From a project folder, or a global project's:
443
+
444
+ | Command | Does |
445
+ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
446
+ | `gta lint` | Checks every file against the rules, and prints each finding at its file and line, with its rule and the file the rule came from. Exits `1` on a finding. |
447
+ | `gta rules` | Lists each rule set, its value, the file it came from and what it means, rules turned off included, then the guide. |
448
+
449
+ - Neither needs `settings.yml` or runs anything, and both take `--json`.
450
+ - A file that will not parse is a finding, since no rule could be checked in it.
451
+ - Both exit `2` when a rule is not valid, or `project.yml` names a global project that
452
+ cannot be used: its rules would quietly go unchecked.
453
+ - A coding agent can run `gta rules` to learn a project's conventions before writing, and
454
+ `gta lint --json` after, to fix what it finds. Gravity offers to add a section saying so
455
+ to the project's `AGENTS.md`, which coding agents read; nothing is written until asked.
456
+
298
457
  ---
299
458
 
300
459
  ## 2. Collection file
@@ -337,24 +496,24 @@ steps:
337
496
 
338
497
  Any key not listed here is an error.
339
498
 
340
- | Key | Type | Required | Default | Meaning |
341
- | ---------- | ------------------- | -------- | ------- | ------------------------------------------------------------------------------ |
342
- | `id` | string | **yes** | | The file name without `.yml` (below). |
343
- | `steps` | list of steps | no | `[]` | The requests, in run order (§2.1). |
344
- | `setup` | list of steps | no | | Run once before `steps`; what it sets lasts the run (§2.10). |
345
- | `teardown` | list of steps | no | | Run once after the rest, even when a step failed (§2.10). |
346
- | `docs` | string | no | | Markdown. |
347
- | `tags` | list of tags | no | | Tags that select the whole collection (§2.4). |
348
- | `stepTags` | boolean | no | `false` | `true` lets steps carry their own tags (§2.4). |
349
- | `exclude` | boolean | no | `false` | `true` leaves it out of group runs (§2.4). |
350
- | `flags` | map | no | | Feature flags the whole collection needs (§2.9). |
351
- | `headers` | map | no | | Sent with every step; a step's own header of the same name wins (§2.3). |
352
- | `settings` | map | no | | Defaults for every step (§2.3). |
353
- | `vars` | map of plain values | no | | Collection variables (§4). |
354
- | `before` | map | no | | `script:` run before every step (§5). |
355
- | `tests` | string | no | | JavaScript run after every step, before the step's own (§5). |
356
- | `extends` | string | no | | A base collection to build on (§2.7). |
357
- | `params` | map | no | | The inputs it takes as a request set (§2.5). Only in `requests/`, in practice. |
499
+ | Key | Type | Required | Default | Meaning |
500
+ | ---------- | ------------------- | -------- | ------- | ----------------------------------------------------------------------------------------- |
501
+ | `id` | string | **yes** | | The file name without `.yml` (below). |
502
+ | `steps` | list of steps | no | `[]` | The requests, in run order (§2.1). |
503
+ | `setup` | list of steps | no | | Run once before `steps`; what it sets lasts the run (§2.10). |
504
+ | `teardown` | list of steps | no | | Run once after the rest, even when a step failed (§2.10). |
505
+ | `docs` | string | no | | Markdown. |
506
+ | `tags` | list of tags | no | | Tags that select the whole collection (§2.4). |
507
+ | `stepTags` | boolean | no | `false` | `true` lets steps carry their own tags (§2.4). |
508
+ | `exclude` | boolean | no | `false` | `true` leaves it out of group runs (§2.4). |
509
+ | `flags` | map | no | | Feature flags the whole collection needs (§2.9). |
510
+ | `headers` | map | no | | Sent with every step; a step's own header of the same name wins (§2.3). |
511
+ | `settings` | map | no | | Defaults for every step (§2.3). |
512
+ | `vars` | map of plain values | no | | Collection variables (§4). |
513
+ | `before` | map | no | | `script:` run before every step (§5). |
514
+ | `tests` | string | no | | JavaScript run after every step, before the step's own (§5). |
515
+ | `extends` | string | no | | A base collection to build on (§2.7). |
516
+ | `params` | map | no | | The inputs it takes as a reusable requests file (§2.5). Only in `requests/`, in practice. |
358
517
 
359
518
  A collection has no `name` key. Its `id` is its name, and a file with `name:` is
360
519
  rejected with a message saying so.
@@ -367,7 +526,7 @@ exactly. `collections/checkout/sessions.yml` starts `id: sessions`.
367
526
  - **It must match the file name.** A file whose `id` is missing or different is a
368
527
  broken collection. Renaming a file means changing its `id` too.
369
528
  - **It must be unique in its home, ignoring case.** No two files in a project's
370
- `collections/` may share an id, including files in different directories of it; the
529
+ `collections/` may share an id, including files in different folders of it; the
371
530
  same holds for `requests/`, `bases/` and `endpoints/`. Case is ignored because macOS
372
531
  and Windows file systems ignore it. Every file sharing an id is broken.
373
532
  - **It is letters, digits and `- _ .`, starting with a letter or digit**:
@@ -388,29 +547,29 @@ key**, in capitals, whose value is the URL as a string.
388
547
 
389
548
  Methods: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS`.
390
549
 
391
- | Key | Type | Required | Meaning |
392
- | ------------ | ------------ | -------- | ------------------------------------------------------------------------- |
393
- | `<METHOD>` | string | **yes** | The URL, query string included. |
394
- | `name` | string | no | Display name. Defaults to the method and URL. |
395
- | `headers` | map | no | Over the collection's headers (§2.3). |
396
- | `body` | map | no | Exactly one kind of body (§2.2). |
397
- | `settings` | map | no | Over the collection's settings (§2.3). |
398
- | `before` | map | no | `script:` run before the request (§5). |
399
- | `tests` | string | no | The checks, as JavaScript: calls on `gta` (§3) and any other code (§5). |
400
- | `tags` | list of tags | no | The step's own tags. Only with `stepTags: true` on the collection (§2.4). |
401
- | `flags` | map | no | Feature flags the step needs (§2.9). |
402
- | `forEach` | string | no | Send the request once for each item of a list (below). |
403
- | `useTests` | `true` | no | In a request set: the use step's `tests` check this response (§2.5). |
404
- | `connection` | string | no | Keep the event stream this request opens as a connection (§2.11). |
405
- | `base` | `false` | no | `false` leaves the step's endpoint base out (§2.6). |
406
- | `docs` | string | no | Markdown. |
550
+ | Key | Type | Required | Meaning |
551
+ | ------------ | ------------ | -------- | ------------------------------------------------------------------------------- |
552
+ | `<METHOD>` | string | **yes** | The URL, query string included. |
553
+ | `name` | string | no | Display name. Defaults to the method and URL. |
554
+ | `headers` | map | no | Over the collection's headers (§2.3). |
555
+ | `body` | map | no | Exactly one kind of body (§2.2). |
556
+ | `settings` | map | no | Over the collection's settings (§2.3). |
557
+ | `before` | map | no | `script:` run before the request (§5). |
558
+ | `tests` | string | no | The checks, as JavaScript: calls on `gta` (§3) and any other code (§5). |
559
+ | `tags` | list of tags | no | The step's own tags. Only with `stepTags: true` on the collection (§2.4). |
560
+ | `flags` | map | no | Feature flags the step needs (§2.9). |
561
+ | `forEach` | string | no | Send the request once for each item of a list (below). |
562
+ | `useTests` | `true` | no | In a reusable requests file: the use step's `tests` check this response (§2.5). |
563
+ | `connection` | string | no | Keep the event stream this request opens as a connection (§2.11). |
564
+ | `base` | `false` | no | `false` leaves the step's endpoint base out (§2.6). |
565
+ | `docs` | string | no | Markdown. |
407
566
 
408
567
  - A step with two method keys is an error, and so is a step with none, unless it is a
409
568
  use step or reads a connection.
410
569
  - **The URL is authoritative, query string included.** There is no separate block of
411
570
  query parameters. Editors show a parameter table as a view over the URL.
412
- - A step may instead run a request set with `use:` (§2.5). A use step has no method
413
- key.
571
+ - A step may instead run reusable requests with `use:` (§2.5). A use step has no
572
+ method key.
414
573
  - A step may also read a connection, an event stream an earlier step keeps open, with
415
574
  `connection:` and no method key (§2.11).
416
575
  - **Any other key is an error**, so a misspelled key such as `heders:` fails at once
@@ -504,13 +663,14 @@ declared multipart type without a boundary, such as `multipart/mixed`, gets one
504
663
  A declared boundary is used as written.
505
664
 
506
665
  **Files**, in `body.file` and a multipart part's `file`, are read from the folder of
507
- the project the step belongs to. For a step of a request set, that is the set's own
508
- project, which may be a global one. The path is the same wherever the collection sits
509
- inside `collections/`.
666
+ the project the step belongs to. For a step of a reusable requests file, that is the
667
+ file's own project, which may be a global one. The path is the same wherever the
668
+ collection sits inside `collections/`.
510
669
 
511
- A file that is not there is looked for in the global project (§1.1), as a request set
512
- or a base collection is, so projects can share one copy of a file. A project's own file
513
- of the same path wins. `global:` before the path reads only the global project's:
670
+ A file that is not there is looked for in the global project (§1.1), as a reusable
671
+ requests file or a base collection is, so projects can share one copy of a file. A
672
+ project's own file of the same path wins. `global:` before the path reads only the
673
+ global project's:
514
674
 
515
675
  ```yaml
516
676
  body:
@@ -647,15 +807,16 @@ else selects it. With `stepTags: true`, its steps whose tags match are dropped f
647
807
  was selected.
648
808
 
649
809
  **`exclude: true`** leaves a collection out of group runs: `gta all`, with or without
650
- tags, and a directory named to `gta`. Named on its own, it still runs. Use it for work in
810
+ tags, and a folder named to `gta`. Named on its own, it still runs. Use it for work in
651
811
  progress, a manual-only collection, or one waiting on a fix. `gta` lists what it left
652
812
  out, so a suite never shrinks without saying so.
653
813
 
654
- ### 2.5 Request sets and `use:`
814
+ ### 2.5 Reusable requests and `use:`
655
815
 
656
- A **request set** is a collection in `requests/`, directly or one directory down, with a
657
- `params:` key: the inputs it takes. A step elsewhere runs it with **`use:`**, and passes
658
- values with **`with:`**.
816
+ **Reusable requests** are one or more requests that any step can run with **`use:`**,
817
+ passing values with **`with:`**. They are written in a **reusable requests file**: a
818
+ collection in `requests/`, directly or one folder down, with a `params:` key, the
819
+ inputs it takes.
659
820
 
660
821
  ```yaml
661
822
  # requests/login.yml
@@ -700,39 +861,40 @@ values. No variable can take the place of a `params.` name.
700
861
 
701
862
  A default may name variables and other params, as in
702
863
  `email: '{{params.accountId}}@example.com'`. Like a `with:` value, it is resolved once
703
- for each use, so `accountId: '{{$uuid}}'` is one id wherever the set reads it.
864
+ for each use, so `accountId: '{{$uuid}}'` is one id wherever the file reads it.
704
865
 
705
866
  **A use step** holds only `use`, `with`, `name`, `tags`, `flags`, `docs` and `tests`. A
706
867
  method key, `headers`, `body`, `settings` or `before` on it is an error, and `with`
707
868
  without `use` is an error too.
708
869
 
709
- - **Finding the set.** `use: login` is `requests/login.yml` in the project, else in its
710
- global project. `use: auth/login` is one directory down. `use: global:login` looks
870
+ - **Finding the file.** `use: login` is `requests/login.yml` in the project, else in its
871
+ global project. `use: auth/login` is one folder down. `use: global:login` looks
711
872
  only in the global project.
712
873
  - **`with:`** gives plain values; a param left out takes its default. A string may hold
713
- `{{variables}}`, resolved as the set's first request starts, just after the
874
+ `{{variables}}`, resolved as the file's first request starts, just after the
714
875
  collection's `before.script` has run for it: a value that script sets for each step
715
- (§4) reaches the set. A missing required value, a name the set does not take, or a
716
- value or default that cannot be resolved stops the set's steps before anything is
717
- sent.
718
- - **Running.** A use step runs each of the set's steps in turn, in the collection's
876
+ (§4) reaches the file's requests. A missing required value, a name the file does not
877
+ take, or a value or default that cannot be resolved stops the file's steps before
878
+ anything is sent.
879
+ - **Running.** A use step runs each of the file's steps in turn, in the collection's
719
880
  variable scope, so what one sets the next can read, and so can the steps after the use
720
881
  step. Each request is reported as its own result. When the use step has a `name`,
721
- reports use it: `sign in` for a set of one step, `sign in › get profile` for a longer
882
+ reports use it: `sign in` for a file of one step, `sign in › get profile` for a longer
722
883
  one.
723
- - **Layers.** Headers and settings: the collection's, under the set's, under each
724
- step's own. Scripts run collection, then set, then step: `before.script` before the
884
+ - **Layers.** Headers and settings: the collection's, under the file's, under each
885
+ step's own. Scripts run collection, then file, then step: `before.script` before the
725
886
  request and `tests` after. The use step's own `tests` run last, on the response of
726
- the set's step marked `useTests: true`, or else its last step. `params` is the set's
727
- alone: the collection's scripts, and a base collection's or an endpoint's (§2.6,
728
- §2.7), never see it. In an endpoint's `before.script`, a segment written as
887
+ the file's step marked `useTests: true`, or else its last step. `params` is the
888
+ file's alone: the collection's scripts, and a base collection's or an endpoint's
889
+ (§2.6, §2.7), never see it. In an endpoint's `before.script`, a segment written as
729
890
  `{{params.id}}` reads as written.
730
- - **One level.** A request set must not `use:` another, and has `params`, not `vars`. A
731
- file in `requests/` without `params` is not a request set.
891
+ - **One level.** A reusable requests file must not `use:` another, and has `params`,
892
+ not `vars`. A file in `requests/` without `params` is not a reusable requests file.
732
893
 
733
- **Saving under the caller's name.** A set can take the name to save a value under as a
734
- param, save it with `gta.set(params.saveAs, …)`, and read it back in its later steps
735
- with `{{@params.saveAs}}` (§4). The caller then reads it by the name it chose:
894
+ **Saving under the caller's name.** A reusable requests file can take the name to save
895
+ a value under as a param, save it with `gta.set(params.saveAs, …)`, and read it back in
896
+ its later steps with `{{@params.saveAs}}` (§4). The caller then reads it by the name it
897
+ chose:
736
898
 
737
899
  ```yaml
738
900
  # requests/create-user.yml
@@ -761,7 +923,8 @@ steps:
761
923
  headers: { Authorization: 'Bearer {{token1}}' }
762
924
  ```
763
925
 
764
- Only one step of a set may have `useTests`, and only a set's steps.
926
+ Only one step of a reusable requests file may have `useTests`, and no other file's
927
+ steps.
765
928
 
766
929
  ### 2.6 Endpoint bases
767
930
 
@@ -802,8 +965,8 @@ steps:
802
965
  `endpoint.id` is `42` for `{{baseUrl}}/users/{{userId}}` with `userId: 42`.
803
966
  - **What applies**, outermost first: the endpoints file's own `headers`, `settings`,
804
967
  `before` and `tests`, then the endpoint's, then the base collection's (§2.7), the
805
- collection's, the request set's (§2.5) and the step's. Nearer headers and settings
806
- win.
968
+ collection's, the reusable requests file's (§2.5) and the step's. Nearer headers and
969
+ settings win.
807
970
  - **A step's own check replaces the base's check of the same thing**: the status, a
808
971
  header by name, or a body property by path. A negative test only says what it expects,
809
972
  so checking for a 404 replaces the base's 200. Checks of other things stay, and named
@@ -872,7 +1035,8 @@ userId,expectedStatus,iterationLabel
872
1035
  string**: a zip code `01234` stays `01234`. A short row leaves its last columns empty;
873
1036
  a row with more values than the header is an error.
874
1037
  - **JSON** is an array of objects, one per row. Values keep their type, which must be
875
- string, number, boolean or null.
1038
+ string, number, boolean or null. A row must not name a column twice: JSON readers keep
1039
+ only the last value, so it is an error rather than a value quietly lost.
876
1040
  - **`.csv` wins** when both exist. The name must match exactly, case included.
877
1041
  - A data file must be at most 10 MB and have at least one row. The header must not have
878
1042
  an empty or repeated column name. A data file that will not read makes the collection
@@ -902,8 +1066,8 @@ steps:
902
1066
  ```
903
1067
 
904
1068
  - **Every flag named must have the value given.** A collection's `flags` apply to each
905
- of its steps, and a use step's to each request of its set. Values compare as text, so
906
- `true` matches `true` or `"true"`, and `2` matches `"2"`.
1069
+ of its steps, and a use step's to each of its reusable requests. Values compare as
1070
+ text, so `true` matches `true` or `"true"`, and `2` matches `"2"`.
907
1071
  - **A step whose flags do not hold is skipped**, not failed. It sends nothing and is
908
1072
  reported as skipped with the reason, such as `feature flag newCheckout is off`. A
909
1073
  skipped step never fails a run.
@@ -987,7 +1151,8 @@ steps: # once per row of approved-domains.csv, as before
987
1151
  - **The collection applies to them**: its headers, settings, `before`, `tests` and
988
1152
  flags, as to any step. Their steps may be use steps and may use `forEach`, but carry
989
1153
  no `tags`: they run whenever the collection does.
990
- - A request set, a base collection and an endpoints file have no setup or teardown.
1154
+ - A reusable requests file, a base collection and an endpoints file have no setup or
1155
+ teardown.
991
1156
  - Reports name their results `setup › log in` and `teardown › remove the grant`. Running
992
1157
  a single step in the desktop app does not run them.
993
1158
 
@@ -1160,6 +1325,10 @@ saying so, and the checks after it still run.
1160
1325
  every item of a simple `list`, in any order. A `RegExp` in the list is a pattern some item
1161
1326
  must match as text, and so is one held by an object in the list:
1162
1327
  `[/^admin/, { name: /^Grace/ }]`. A pattern never matches an object or array item.
1328
+ An object in the list matches an item holding each of its properties, and the item may
1329
+ have others; a property that is itself an object is matched the same way, so
1330
+ `{ data: { status: 'reversed' } }` finds an item whose `data` has that `status` among
1331
+ other properties. An array compares whole.
1163
1332
 
1164
1333
  A list of `{ pathToProperty, expectedValue, specialHandling? }` objects describes **one**
1165
1334
  item, property by property; call it once per item. A property may appear twice, once to
@@ -1246,7 +1415,7 @@ to. Whitespace inside the braces is ignored. In code, read a variable with
1246
1415
  - **`{{@name}}` reads the variable `name` names.** With `saveAs: token1`,
1247
1416
  `{{@saveAs}}` is the value of `token1`. The name may itself be built from variables.
1248
1417
  A name that is not text, or names no variable, fails like an unknown variable. A
1249
- request set uses it to read what it saved under its caller's name (§2.5).
1418
+ reusable requests file uses it to read what it saved under its caller's name (§2.5).
1250
1419
  - **In YAML, quote a value that starts with `{{`.** Unquoted, YAML reads `{` as a map.
1251
1420
 
1252
1421
  ### Built-in variables
@@ -1359,7 +1528,7 @@ military zone letter (`U` is -08:00, not UTC).
1359
1528
  | `req` | `method`, `url`, `headers`, `body`: as sent in `tests`, as written in `before.script`, where a script may change `headers` and `body` (below). |
1360
1529
  | `assert` | Node's strict `assert`, for use inside `gta.test`. |
1361
1530
  | `console` | Captured into the step's result. |
1362
- | `params` | A request set's params (§2.5), in its own scripts and in the tests of the use step running it. |
1531
+ | `params` | A reusable requests file's params (§2.5), in its own scripts and in the tests of the use step running it. |
1363
1532
  | `endpoint` | An endpoint base's `{name}` values (§2.6), in its scripts and in every script of a step under it. |
1364
1533
  | `checks` | The project's check files (below). |
1365
1534
 
@@ -1403,7 +1572,10 @@ delete req.headers['X-Debug']
1403
1572
 
1404
1573
  - `req.body` is text, and can be changed for a `json`, `xml`, `text` or `graphql` body.
1405
1574
  A form, multipart or file body is built from its parts, so it cannot.
1406
- - `req.headers` is a map of names to values: add, change or delete them.
1575
+ - `req.headers` is a map of names to values: add, change or delete them. A header sent
1576
+ more than once reads as its values joined with `, `, as `res.headers` does, and is
1577
+ still sent once per value unless the script changes it. Set an array to send one
1578
+ header per value.
1407
1579
  - Variables in what the script writes resolve afterwards, as in the file.
1408
1580
  - Anything else is a pre-request error, and nothing is sent.
1409
1581
 
@@ -1465,7 +1637,8 @@ global project's root.
1465
1637
  - A secret with no value anywhere fails the run, naming it. An empty credential is never
1466
1638
  sent.
1467
1639
  - Reports replace a secret's value with `[secret: NAME]`, wherever it appears. So does
1468
- the desktop app where it shows a request as sent.
1640
+ the desktop app where it shows a request as sent, or what a script wrote with
1641
+ `console`.
1469
1642
  - `.env` holds `NAME=value` lines. `#` starts a comment line, `export ` before a name is
1470
1643
  allowed, and a value may be quoted. It must not be committed.
1471
1644
 
@@ -1510,7 +1683,7 @@ it. Rules checked at run time fail the step, or the run, before anything is sent
1510
1683
  - It must be YAML that parses, holding a mapping, in a file ending in `.yml`.
1511
1684
  - Unknown keys are errors in: a collection's top level, a step, `settings`, `before`,
1512
1685
  `body`, `project.yml`, `tls`, an environment file, an environment's `flags`, a param
1513
- spec and `settings.yml`.
1686
+ spec, `settings.yml` and `rules.yml`.
1514
1687
 
1515
1688
  **Collections**
1516
1689
 
@@ -1536,7 +1709,8 @@ it. Rules checked at run time fail the step, or the run, before anything is sent
1536
1709
  - There is no `expect:` key; checks go in `tests`.
1537
1710
  - `base` is only ever `false`.
1538
1711
  - `forEach` is a string, and a use step has none.
1539
- - `useTests` is only ever `true`, only on a request set's step, and on one step at most.
1712
+ - `useTests` is only ever `true`, only on a reusable requests file's step, and on one
1713
+ step at most.
1540
1714
  - A step reading a connection has no `headers`, `body`, `base` or `forEach`. A step
1541
1715
  opening one has no `forEach`, and a use step has no `connection` (§2.11).
1542
1716
 
@@ -1561,13 +1735,14 @@ it. Rules checked at run time fail the step, or the run, before anything is sent
1561
1735
 
1562
1736
  **Library files**
1563
1737
 
1564
- - A request set (`requests/`) has `params`, uses no other set, and has no `vars`.
1738
+ - A reusable requests file (`requests/`) has `params`, uses no other, and has no
1739
+ `vars`.
1565
1740
  - A base collection (`bases/`) has no `steps`, `setup`, `teardown` or `params`, and no
1566
1741
  `extends`.
1567
1742
  - An endpoint (`endpoints/`) has a URL that is a path starting with `/`, and no use
1568
1743
  steps or connections. An endpoints file has no `setup` or `teardown`.
1569
1744
  - A check file's name is a JavaScript identifier; if it isn't, the file is not loaded.
1570
- - `collections/`, `requests/`, `endpoints/` and `bases/` hold files at most one directory
1745
+ - `collections/`, `requests/`, `endpoints/` and `bases/` hold files at most one folder
1571
1746
  down.
1572
1747
 
1573
1748
  **Portability (§1.2)**
@@ -1578,7 +1753,7 @@ it. Rules checked at run time fail the step, or the run, before anything is sent
1578
1753
  `Collections/`.
1579
1754
  - No two names in `collections/`, `requests/`, `endpoints/`, `bases/`, `environments/`
1580
1755
  or `checks/` differ only in case.
1581
- - No file or directory name is one Windows refuses.
1756
+ - No file or folder name is one Windows refuses.
1582
1757
 
1583
1758
  **Projects**
1584
1759
 
@@ -1587,6 +1762,9 @@ it. Rules checked at run time fail the step, or the run, before anything is sent
1587
1762
  - Each `tls.ca` file exists and holds a PEM or DER certificate.
1588
1763
  - `settings.yml` exists for `gta`; a global project's is optional. The `environmentType`
1589
1764
  a run ends up with, if any, names an environment that exists.
1765
+ - In `rules.yml`, each rule has a value of the type §1.4 gives it, a pattern compiles,
1766
+ `tests.only` lists `gta`, and `guide` is a string. What breaks a rule is a finding of `gta lint`, never an
1767
+ error: it stops nothing (§1.4).
1590
1768
 
1591
1769
  **At run time**
1592
1770
 
@@ -1597,7 +1775,7 @@ it. Rules checked at run time fail the step, or the run, before anything is sent
1597
1775
  seconds, printing a JSON object.
1598
1776
  - Every file a body names can be read from the project folder, or its global
1599
1777
  project's (§2.2).
1600
- - Every `use:` and `extends:` names a usable file, and every `with:` suits its set.
1778
+ - Every `use:` and `extends:` names a usable file, and every `with:` suits its file.
1601
1779
  `gta get` checks these, and the body files named without `{{variables}}`, without
1602
1780
  running anything (§1.3).
1603
1781
  - A step's `forEach` resolves to a JSON array.