@rt-tools/agent-kit 0.23.0 → 0.26.0
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/README.md +8 -2
- package/assets/agents/business-analyst.md +51 -50
- package/assets/agents/conscience.md +37 -35
- package/assets/agents/project-manager.md +49 -48
- package/assets/agents/prose-editor.md +31 -29
- package/assets/agents/qa-engineer.md +50 -48
- package/assets/agents/rules-reviewer.md +63 -58
- package/assets/agents/skill-curator.md +83 -78
- package/assets/agents/spec-critic.md +34 -29
- package/assets/agents/spec-writer.md +35 -32
- package/assets/agents/strict-teacher.md +39 -37
- package/assets/checks/archive-age.mjs +48 -28
- package/assets/checks/archive-prune.mjs +16 -14
- package/assets/checks/board-epics.github.mjs +75 -41
- package/assets/checks/board-folders.mjs +61 -0
- package/assets/checks/board-gh.github.mjs +35 -26
- package/assets/checks/board-long-work.github.mjs +24 -24
- package/assets/checks/board-paths.github.mjs +21 -16
- package/assets/checks/board-runs.github.mjs +45 -43
- package/assets/checks/board-titles.github.mjs +19 -17
- package/assets/checks/board.github.mjs +150 -128
- package/assets/checks/check-archive-age.mjs +23 -19
- package/assets/checks/check-board.github.mjs +179 -157
- package/assets/checks/check-descriptions.mjs +30 -29
- package/assets/checks/check-doc-paths.mjs +104 -82
- package/assets/checks/check-dupes.mjs +84 -80
- package/assets/checks/check-file-size.mjs +79 -70
- package/assets/checks/check-glossary.mjs +47 -37
- package/assets/checks/check-hook-scope.mjs +30 -27
- package/assets/checks/check-lib-layers.mjs +22 -21
- package/assets/checks/check-profile-drift.mjs +48 -43
- package/assets/checks/check-prose-style.mjs +125 -33
- package/assets/checks/check-push-gate.mjs +53 -50
- package/assets/checks/check-reuse.mjs +50 -40
- package/assets/checks/check-schema-drift.mjs +87 -83
- package/assets/checks/check-specs.mjs +155 -134
- package/assets/checks/check-state-next.mjs +66 -52
- package/assets/checks/check-states.mjs +32 -30
- package/assets/checks/check-styles.mjs +52 -51
- package/assets/checks/check-turn-map.mjs +54 -46
- package/assets/checks/lib-boundaries.mjs +32 -30
- package/assets/checks/lib-common.mjs +30 -29
- package/assets/checks/lib-domains.mjs +34 -34
- package/assets/checks/lib-manifests.mjs +17 -15
- package/assets/checks/lib-reexports.mjs +18 -18
- package/assets/checks/rt-kit-checks.config.mjs +174 -142
- package/assets/checks/signals.mjs +43 -39
- package/assets/checks/spec-anchors.mjs +114 -87
- package/assets/checks/spec-common.mjs +128 -84
- package/assets/checks/spec-contract.mjs +30 -30
- package/assets/checks/spec-proposed.mjs +27 -24
- package/assets/checks/spec-scenarios.mjs +51 -28
- package/assets/checks/task-new.github.mjs +85 -56
- package/assets/commands/feedback.md +65 -59
- package/assets/commands/next-session.md +64 -57
- package/assets/commands/skill-curator.md +83 -79
- package/assets/defaults/gate-map.sh +115 -91
- package/assets/defaults/project.sh +228 -178
- package/assets/defaults/shell.sh +85 -65
- package/assets/defaults/turn-map.md +45 -44
- package/assets/docs/GLOSSARY.md +142 -65
- package/assets/hooks/browser-device-id.sh +12 -12
- package/assets/hooks/browser-guard-device-id.sh +46 -14
- package/assets/hooks/browser-guard-no-asking.sh +5 -4
- package/assets/hooks/browser-guard-no-listing.sh +12 -11
- package/assets/hooks/browser-guard-no-other-drivers.sh +48 -42
- package/assets/hooks/browser-guard-require-select.sh +34 -23
- package/assets/hooks/claim-guard.sh +62 -56
- package/assets/hooks/commit-msg.sh +11 -10
- package/assets/hooks/conscience-guard.sh +91 -45
- package/assets/hooks/constitution-index.sh +16 -16
- package/assets/hooks/deny-tail.sh +28 -26
- package/assets/hooks/dev-server-guard.sh +46 -43
- package/assets/hooks/dispatch.sh +84 -39
- package/assets/hooks/docs-guard.sh +105 -86
- package/assets/hooks/exam-guard.sh +146 -84
- package/assets/hooks/git-guard-delivery-conflict.sh +38 -36
- package/assets/hooks/git-guard-delivery-draft.sh +85 -0
- package/assets/hooks/git-guard-delivery-folder.sh +50 -43
- package/assets/hooks/git-guard-delivery-signature.sh +88 -52
- package/assets/hooks/git-guard-delivery.sh +207 -253
- package/assets/hooks/git-guard-main.sh +65 -26
- package/assets/hooks/git-guard-push-tests.sh +133 -75
- package/assets/hooks/glossary-load.sh +23 -22
- package/assets/hooks/grill-gate-ask.sh +12 -11
- package/assets/hooks/grill-gate.sh +94 -87
- package/assets/hooks/guard-note.sh +20 -19
- package/assets/hooks/handoff-entry-guard.sh +26 -24
- package/assets/hooks/handoff-write.sh +74 -67
- package/assets/hooks/hook-input.sh +70 -50
- package/assets/hooks/lint-after-edit.sh +95 -61
- package/assets/hooks/observe.sh +28 -26
- package/assets/hooks/override-write-guard.sh +23 -21
- package/assets/hooks/postmortem-guard.sh +42 -39
- package/assets/hooks/profile-check.sh +22 -20
- package/assets/hooks/proposal-guard.sh +57 -49
- package/assets/hooks/prose-style-guard.sh +19 -17
- package/assets/hooks/qa-dataid-guard.sh +52 -49
- package/assets/hooks/rerun-guard.sh +31 -30
- package/assets/hooks/reuse-first-guard.sh +108 -87
- package/assets/hooks/roles.sh +14 -14
- package/assets/hooks/rule-article.sh +36 -34
- package/assets/hooks/rule-source-guard.sh +52 -36
- package/assets/hooks/skill-gate-layers.sh +59 -57
- package/assets/hooks/skill-gate-rearm.sh +15 -8
- package/assets/hooks/skill-gate.sh +89 -81
- package/assets/hooks/skill-loaded.sh +6 -6
- package/assets/hooks/sql-guard-parse.sh +68 -66
- package/assets/hooks/sql-guard-request.sh +48 -46
- package/assets/hooks/sql-guard-target.sh +57 -51
- package/assets/hooks/sql-guard-write.sh +84 -79
- package/assets/hooks/sql-guard.sh +52 -47
- package/assets/hooks/stand-login-guard.sh +104 -0
- package/assets/hooks/task-context-load.sh +60 -55
- package/assets/hooks/task-flow-context.sh +87 -69
- package/assets/hooks/task-flow-draft-guard.sh +55 -48
- package/assets/hooks/task-flow-guard.sh +67 -64
- package/assets/hooks/turn-entry-load.sh +39 -32
- package/assets/hooks/turn-exit-guard.sh +256 -204
- package/assets/hooks/turn-exit-patterns.sh +53 -0
- package/assets/hooks/utf8.sh +11 -11
- package/assets/hooks/waiting-turn-guard.sh +94 -94
- package/assets/hooks/window-fill-guard.sh +70 -62
- package/assets/hooks/work-start-guard.sh +52 -49
- package/assets/hooks/write-targets.sh +115 -30
- package/assets/laws/autonomous-work.md +29 -27
- package/assets/laws/code-structure.md +31 -30
- package/assets/laws/delivery.md +148 -137
- package/assets/laws/entity-editing.md +52 -50
- package/assets/laws/entity-models.md +14 -13
- package/assets/laws/frontend-application.md +39 -38
- package/assets/laws/lib-imports.md +27 -27
- package/assets/laws/lists.md +31 -29
- package/assets/laws/navigation.md +37 -37
- package/assets/laws/observability.md +41 -40
- package/assets/laws/project-documentation.md +106 -99
- package/assets/laws/reuse-first.md +31 -29
- package/assets/laws/shared-code.md +27 -27
- package/assets/laws/verifiability.md +131 -114
- package/assets/laws/work-conduct.md +250 -250
- package/assets/patterns/admin-lists-screen.md +72 -69
- package/assets/patterns/admin-nav-item.md +51 -46
- package/assets/patterns/angular-patterns-state.md +32 -31
- package/assets/patterns/api-layer-pair.md +33 -31
- package/assets/patterns/autonomous-work-run.md +50 -49
- package/assets/patterns/browser-verification-measure.md +143 -67
- package/assets/patterns/browser-verification-stand.md +181 -128
- package/assets/patterns/component-structure-new.md +51 -42
- package/assets/patterns/dependencies-upgrade.md +55 -39
- package/assets/patterns/doc-style-human.md +93 -0
- package/assets/patterns/doc-style-sweep.md +82 -79
- package/assets/patterns/doc-style-trace.md +87 -81
- package/assets/patterns/doc-style-write.md +130 -122
- package/assets/patterns/entity-aside.md +77 -63
- package/assets/patterns/entity-models-new.md +37 -37
- package/assets/patterns/entity-store.md +33 -33
- package/assets/patterns/git-workflow-commit.azure.md +94 -75
- package/assets/patterns/git-workflow-commit.github.md +153 -129
- package/assets/patterns/git-workflow-commit.gitlab.md +96 -78
- package/assets/patterns/git-workflow-docker.md +165 -147
- package/assets/patterns/git-workflow-freshness.md +45 -45
- package/assets/patterns/git-workflow-merge.md +99 -86
- package/assets/patterns/git-workflow-migration.md +54 -52
- package/assets/patterns/git-workflow-pr-ready.md +57 -56
- package/assets/patterns/git-workflow-pr.azure.md +126 -121
- package/assets/patterns/git-workflow-pr.github.md +179 -175
- package/assets/patterns/git-workflow-pr.gitlab.md +138 -131
- package/assets/patterns/git-workflow-restart.md +35 -31
- package/assets/patterns/git-workflow-secrets.md +80 -73
- package/assets/patterns/git-workflow-stack.md +131 -106
- package/assets/patterns/lib-layers-move.md +62 -53
- package/assets/patterns/lib-layers-new.md +59 -45
- package/assets/patterns/observability-record.md +72 -67
- package/assets/patterns/platform-access-di.md +31 -29
- package/assets/patterns/reuse-first-extend.md +66 -61
- package/assets/patterns/shared-code-new.md +39 -38
- package/assets/patterns/spec-driven-domain.md +161 -151
- package/assets/patterns/spec-driven-rule.md +179 -168
- package/assets/patterns/spec-driven-sweep.md +41 -39
- package/assets/patterns/status-report-table.github.md +37 -36
- package/assets/patterns/styling-bem-component.md +42 -42
- package/assets/patterns/styling-bem-layout.md +39 -34
- package/assets/patterns/styling-bem-sheet.md +59 -58
- package/assets/patterns/task-flow-archive.md +222 -215
- package/assets/patterns/task-flow-close.md +215 -203
- package/assets/patterns/task-flow-handoff.md +154 -145
- package/assets/patterns/task-flow-resume.md +138 -133
- package/assets/patterns/task-flow-start.md +204 -192
- package/assets/patterns/testing-e2e.md +103 -92
- package/assets/patterns/testing-unit.md +77 -70
- package/assets/patterns/ts-procedure.md +32 -29
- package/assets/patterns/turn-entry-map.md +50 -48
- package/assets/pitfalls/agent-kit.md +152 -141
- package/assets/pitfalls/doc-style.md +96 -91
- package/assets/pitfalls/git-workflow.azure.md +49 -46
- package/assets/pitfalls/git-workflow.github.md +264 -234
- package/assets/pitfalls/git-workflow.gitlab.md +49 -45
- package/assets/pitfalls/spec-driven.md +73 -71
- package/assets/pitfalls/styling-bem.md +46 -40
- package/assets/pitfalls/task-flow.md +262 -246
- package/assets/pitfalls/testing.md +99 -92
- package/assets/pitfalls/turn-conduct.md +96 -81
- package/assets/rules/angular-patterns.md +81 -80
- package/assets/rules/api-layer.md +77 -74
- package/assets/rules/autonomous-work.md +75 -74
- package/assets/rules/browser-verification.md +223 -188
- package/assets/rules/component-structure.md +72 -69
- package/assets/rules/dependencies.md +74 -67
- package/assets/rules/deploy-flow.azure.md +118 -108
- package/assets/rules/deploy-flow.github.md +145 -135
- package/assets/rules/deploy-flow.gitlab.md +120 -110
- package/assets/rules/doc-style.md +209 -148
- package/assets/rules/entity-conventions.needs-admin.md +81 -79
- package/assets/rules/entity-models.md +73 -70
- package/assets/rules/git-workflow.azure.md +224 -228
- package/assets/rules/git-workflow.github.md +250 -242
- package/assets/rules/git-workflow.gitlab.md +218 -217
- package/assets/rules/lib-layers.md +85 -86
- package/assets/rules/lists.md +101 -97
- package/assets/rules/navigation.md +78 -78
- package/assets/rules/observability.needs-app.md +165 -153
- package/assets/rules/platform-access.md +76 -75
- package/assets/rules/reuse-first.md +153 -137
- package/assets/rules/shared-code.md +82 -79
- package/assets/rules/spec-driven.md +272 -260
- package/assets/rules/status-report.md +55 -58
- package/assets/rules/styling-bem.md +83 -72
- package/assets/rules/task-flow.md +282 -270
- package/assets/rules/testing.md +224 -188
- package/assets/rules/turn-conduct.md +255 -258
- package/assets/rules/turn-entry.md +92 -87
- package/assets/rules/typescript-conventions.md +94 -88
- package/assets/samples/specs/_template/spec.md +47 -47
- package/assets/samples/tasks/_template/grill.md +20 -20
- package/assets/samples/tasks/_template/plan.md +32 -30
- package/assets/samples/tasks/_template/progress.md +16 -16
- package/assets/skills/agent-kit-extend.md +129 -113
- package/assets/skills/agent-kit.md +236 -222
- package/assets/skills/write-a-skill.md +76 -71
- package/assets/templates/findings.md +19 -19
- package/assets/templates/gate-map.sh +16 -14
- package/assets/templates/implementation.md +28 -27
- package/assets/templates/pattern.md +17 -17
- package/assets/templates/pitfalls.md +6 -6
- package/assets/templates/postmortem.md +24 -23
- package/assets/templates/project.sh +24 -24
- package/assets/templates/proposal.md +62 -60
- package/assets/templates/rule.md +38 -38
- package/assets/workflows/feature.js +46 -46
- package/assets/workflows/plan.js +54 -54
- package/lib/catalog.d.ts +2 -0
- package/lib/catalog.d.ts.map +1 -1
- package/lib/catalog.js +4 -3
- package/lib/catalog.js.map +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +68 -4
- package/lib/commands.js.map +1 -1
- package/lib/companion.js +3 -2
- package/lib/companion.js.map +1 -1
- package/lib/enroll.d.ts +7 -1
- package/lib/enroll.d.ts.map +1 -1
- package/lib/enroll.js +13 -4
- package/lib/enroll.js.map +1 -1
- package/lib/observations.d.ts +10 -1
- package/lib/observations.d.ts.map +1 -1
- package/lib/observations.js +1 -0
- package/lib/observations.js.map +1 -1
- package/lib/override-marks.d.ts +24 -0
- package/lib/override-marks.d.ts.map +1 -0
- package/lib/override-marks.js +98 -0
- package/lib/override-marks.js.map +1 -0
- package/lib/plan.d.ts +11 -0
- package/lib/plan.d.ts.map +1 -1
- package/lib/plan.js +10 -1
- package/lib/plan.js.map +1 -1
- package/lib/ship.d.ts +0 -7
- package/lib/ship.d.ts.map +1 -1
- package/lib/ship.js +10 -2
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.js +7 -3
- package/lib/shipment.js.map +1 -1
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +45 -11
- package/lib/sync.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.26.0.tgz +0 -0
- package/rt-tools-agent-kit-0.23.0.tgz +0 -0
|
@@ -2,129 +2,140 @@
|
|
|
2
2
|
name: testing-e2e
|
|
3
3
|
kind: pattern
|
|
4
4
|
rule: testing
|
|
5
|
-
description:
|
|
5
|
+
description: Pattern of rule testing. Load when editing and running end-to-end tests in apps/site-e2e and apps/admin-e2e — what an end-to-end test closes, ready-made run commands, a stand from the production build behind real nginx, test switches. Not for unit tests — that is pattern testing-unit.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
# End-to-end tests
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Pattern of the rule `testing`. What must be true — the law
|
|
11
11
|
`docs/constitution/verifiability.md`.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## When to use
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
15
|
+
- A test file in `apps/site-e2e/src` or `apps/admin-e2e/src` is being written or edited.
|
|
16
|
+
- A defect visible only on the production configuration needs reproducing.
|
|
17
|
+
- A stand is being prepared for a run against nginx.
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## An end-to-end test closes accumulated state
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
Its case is the one where state accumulates by clicks: an open panel, an active route, the guard
|
|
22
|
+
of the previous screen. Everything checked by one visit to an address is cheaper to close by a
|
|
23
|
+
unit test on a pure function or by a screen measurement.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
Hence the method: clicks on the same elements the owner clicks, several in a row, with no reload
|
|
26
|
+
between them. Entering by a direct address raises the application anew, it has no accumulated state,
|
|
27
|
+
and the pass reads as "the defect is not confirmed". That is how a panel that got stuck in the
|
|
28
|
+
address on leaving for a neighbouring section went out to production.
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
Elements are found by `qa-dataid`: classes change together with the layout, and a search by role
|
|
31
|
+
and text breaks on translations.
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Run
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
npx nx e2e
|
|
37
|
-
npx nx e2e
|
|
38
|
-
BASE_URL=http://localhost:{{dockerSitePort}} npx nx e2e site-e2e -- --project=chromium # против внешнего стенда
|
|
36
|
+
npx nx e2e <suite target> -- --project=chromium
|
|
37
|
+
BASE_URL=http://localhost:$PROXY_SITE_PORT npx nx e2e <suite target> -- --project=chromium # against an external stand
|
|
39
38
|
```
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
The runner target names and the port numbers are each tree's own: the pattern does not know them.
|
|
41
|
+
The tree names them by its own profile — by environment variables or by an override section of
|
|
42
|
+
this pattern, where the ready-made commands stand with its names.
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
же файлы дали три падения на восьми воркерах и ноль на одном.
|
|
44
|
+
By default the config goes to the site stand port and picks up the server already raised. With
|
|
45
|
+
`BASE_URL` no server of its own is started.
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
The full admin suite is run **by one worker** (`--workers=1`): tests with a real session edit the
|
|
48
|
+
same objects of the live database and get in each other's way in a parallel run. The same files
|
|
49
|
+
gave three failures on eight workers and zero on one.
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
монтируется отдельной строкой и почему каталогом, а не файлом. Здесь важно одно: против такого
|
|
52
|
-
стенда прогон идёт с `BASE_URL`, и вместе с ним включаются проверки перенаправлений локалей.
|
|
51
|
+
## A stand from the production build behind real nginx
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
How to raise it — pattern `browser-verification-stand`; it also says why the main config is
|
|
54
|
+
mounted by a separate line and why as a directory, not as a file. One thing matters here: against
|
|
55
|
+
such a stand the run goes with `BASE_URL`, and with it the locale redirect checks switch on.
|
|
56
|
+
|
|
57
|
+
## Switches
|
|
55
58
|
|
|
56
59
|
```typescript
|
|
57
60
|
const ALLOW_RENAME: boolean = process.env['E2E_ALLOW_SLUG_RENAME'] === '1';
|
|
58
61
|
test.skip(!ALLOW_RENAME, 'меняет живой адрес объекта: включается E2E_ALLOW_SLUG_RENAME=1');
|
|
59
62
|
```
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
управляются переменной.
|
|
64
|
+
Switches come in two kinds, and only the first counts as coverage. **A switch by stand state**
|
|
65
|
+
skips a case the stand never has by design — the scenario is closed, and it needs no mark. **A
|
|
66
|
+
switch by environment variable** leaves the test unrun: the scenario behind it is listed as
|
|
67
|
+
covered while nothing checks it, and such a scenario carries a partial-coverage mark with a
|
|
68
|
+
reason. Of the three below not one belongs to the first kind: all three are driven by a variable.
|
|
67
69
|
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
- `BEHIND_NGINX`
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- `HAS_ADMIN_SESSION`
|
|
74
|
-
- `playwright/no-skipped-test`
|
|
75
|
-
|
|
70
|
+
- A test that irreversibly changes stand data is skipped by default and switched on by its own
|
|
71
|
+
variable.
|
|
72
|
+
- `BEHIND_NGINX` in `home.smoke.spec.ts` is `!!process.env['BASE_URL']`: with it the locale
|
|
73
|
+
redirect checks wake. A bare page-serving server does not pass them, and two failures look like
|
|
74
|
+
a regression.
|
|
75
|
+
- `HAS_ADMIN_SESSION` in `sign-in.ts` — the pair `E2E_ADMIN_EMAIL` and `E2E_ADMIN_PASSWORD`.
|
|
76
|
+
- `playwright/no-skipped-test` is switched off in `eslint.config.mjs`: the test switch here is a
|
|
77
|
+
technique, not a forgotten `test.skip`.
|
|
76
78
|
|
|
77
|
-
##
|
|
79
|
+
## A redirect code is checked by the answer, not by following it
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
The browser follows the redirect itself, and the code after it is the code of the final page: a
|
|
82
|
+
test named "answers 301" asserted 200 and would not have noticed a permanent redirect replaced by
|
|
83
|
+
a temporary one. The answer itself is asked, without following it:
|
|
82
84
|
|
|
83
85
|
```ts
|
|
84
|
-
const answer = await request.get('
|
|
86
|
+
const answer = await request.get('/old-address', { maxRedirects: 0 });
|
|
85
87
|
|
|
86
88
|
expect(answer.status()).toBe(301);
|
|
87
|
-
expect(answer.headers()['location']).toBe('
|
|
89
|
+
expect(answer.headers()['location']).toBe('/new-address');
|
|
88
90
|
```
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
-
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
-
|
|
129
|
-
|
|
130
|
-
|
|
92
|
+
Telling a permanent redirect from a temporary one is needed where an agreement rests on it: search
|
|
93
|
+
robots and the browser remember only the permanent one, and the difference between 301 and 302 is
|
|
94
|
+
visible only in the answer.
|
|
95
|
+
|
|
96
|
+
## The screen state after an action is awaited by polling, not read on the next line
|
|
97
|
+
|
|
98
|
+
Between the click and the new content lies the network: the filter goes into the address by the
|
|
99
|
+
click, and the rows arrive by the server's answer, and those read at once are still the old ones.
|
|
100
|
+
A test that reads a column on the next line passes on its own machine and turns red in the
|
|
101
|
+
pipeline: there the answer comes later, and the difference between machines decides the outcome.
|
|
102
|
+
|
|
103
|
+
So the state itself is awaited — by polling until it matches the expected one, not by one read and
|
|
104
|
+
not by a pause for a time. A pause checks the machine: on a free one it is always enough, on a busy
|
|
105
|
+
one it is not, and which test did not make it turns out a matter of chance.
|
|
106
|
+
|
|
107
|
+
This knowledge is entered in the rule, not in the shared module of the suite. Written only as code,
|
|
108
|
+
it is known to whoever wrote it — the next test repeats the miss, because it reads the rule, not the
|
|
109
|
+
code.
|
|
110
|
+
|
|
111
|
+
## Common misses
|
|
112
|
+
|
|
113
|
+
- **Take the rendering server port with care:** the developer's stand goes by the same name
|
|
114
|
+
`ssr:<rendering port>` through `host-gateway`, and while a foreign process hangs on it, the stand
|
|
115
|
+
serves a foreign build.
|
|
116
|
+
- There is one browser — chromium; narrow screen — `--project=mobile-chrome`. The error "Executable
|
|
117
|
+
doesn't exist" is taken apart in the rule `testing`: the same one comes after a Playwright version
|
|
118
|
+
change.
|
|
119
|
+
- Admin tests without a session are skipped silently — the run looks successful, while less than
|
|
120
|
+
half was checked.
|
|
121
|
+
- The nginx config is mounted as a directory, not as a single file: the editor recreates the file,
|
|
122
|
+
and the container is left with a truncated copy.
|
|
123
|
+
- **Not only what the screen requests is substituted, but also what the header requests.** The
|
|
124
|
+
unread counter is requested on every screen under the header. Without a substitution the real
|
|
125
|
+
server answers that request, refuses the fake sign-in, the interceptor drops the session, and
|
|
126
|
+
fifty-nine tests fail on the vanished header — it looks like a screen defect.
|
|
127
|
+
- **State that lives only during an operation is not checked by a test.** The upload list under the
|
|
128
|
+
button is visible while the files are in flight: on substituted answers they land before the test
|
|
129
|
+
manages to read it, and the test turns red every other run. What is checked is either the final
|
|
130
|
+
state (the row's `data-state` became `done`) or the same intermediate one — but on an answer the
|
|
131
|
+
test itself delayed and itself releases.
|
|
132
|
+
- **A double moved from a test file into the suite's shared file leaves the exclusion of the
|
|
133
|
+
duplicate check.** It skips test files and reads everything else, doubles and settings included,
|
|
134
|
+
and compares the declaration name — not the value and not the purpose. A setting that lay in a
|
|
135
|
+
test file under a common name matches, after the move, the one of the same name in another layer,
|
|
136
|
+
and the check turns red on a file the edit did not touch. Taking such red apart takes a separate
|
|
137
|
+
turn. On the move the name gets the prefix of its suite; no line goes into the known list — it
|
|
138
|
+
only shrinks.
|
|
139
|
+
- **A build directory removed under a mounted volume leaves the container with an empty root:** the
|
|
140
|
+
stand answers 403 to everything, and all tests fail at once. After
|
|
141
|
+
`rm -rf dist/apps/<application>` the container is recreated.
|
|
@@ -2,32 +2,33 @@
|
|
|
2
2
|
name: testing-unit
|
|
3
3
|
kind: pattern
|
|
4
4
|
rule: testing
|
|
5
|
-
description:
|
|
5
|
+
description: Pattern of rule testing. Load when creating or editing *.spec.ts under Vitest — the ready-made layout of describe and it, the fixture builder, the scenario id in the title, a Connect procedure test with a hand-written database double. Not for end-to-end tests — that is pattern testing-e2e.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
# A test on a pure function and on a procedure
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Pattern of the rule `testing`. What must be true — the law
|
|
11
11
|
`docs/constitution/verifiability.md`.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## When to use
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
15
|
+
- A `*.spec.ts` next to the source is being created or edited.
|
|
16
|
+
- Logic has to be moved out of a component or a service so that there is something to check it
|
|
17
|
+
with.
|
|
18
|
+
- A test on a Connect procedure is being written.
|
|
18
19
|
|
|
19
|
-
##
|
|
20
|
+
## Imports are explicit
|
|
20
21
|
|
|
21
|
-
`globals: true`
|
|
22
|
+
`globals: true` stands in the config, but the list is written anyway:
|
|
22
23
|
|
|
23
24
|
```typescript
|
|
24
25
|
import { describe, expect, it } from 'vitest';
|
|
25
26
|
```
|
|
26
27
|
|
|
27
|
-
##
|
|
28
|
+
## One `describe` per function
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
The block name matches the function name word for word; the `it` titles are sentences in Russian,
|
|
31
|
+
present tense, about behaviour, not about the internals:
|
|
31
32
|
|
|
32
33
|
```typescript
|
|
33
34
|
describe('applyDayClick', () => {
|
|
@@ -37,12 +38,13 @@ describe('applyDayClick', () => {
|
|
|
37
38
|
});
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
The scenario id from `docs/specs/<domain>/scenarios.md` stands at the start of the title, followed
|
|
42
|
+
by a dash. Edge cases are separate `it` blocks in the same `describe`, not one test with a dozen
|
|
43
|
+
assertions.
|
|
42
44
|
|
|
43
|
-
##
|
|
45
|
+
## A fixture is built by a function with `Partial<T>`
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
Not by a repeated literal:
|
|
46
48
|
|
|
47
49
|
```typescript
|
|
48
50
|
function day(iso: string, overrides: Partial<ICalendarDay> = {}): ICalendarDay {
|
|
@@ -57,74 +59,79 @@ function day(iso: string, overrides: Partial<ICalendarDay> = {}): ICalendarDay {
|
|
|
57
59
|
}
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
Shared constants (`PRICING`, `BUSY`) lie at the top of the file, at module scope.
|
|
61
63
|
|
|
62
|
-
##
|
|
64
|
+
## A decision is moved into a pure function
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
`*.calculator.ts
|
|
66
|
-
`libs/site/common/booking/util/src/lib/availability-calendar.logic.ts`
|
|
67
|
-
`libs/api
|
|
66
|
+
The dominant form in this tree: the logic moves into `*.logic.ts`, `*.util.ts` or
|
|
67
|
+
`*.calculator.ts` and is checked by a call — without `TestBed`, without substituting dependencies.
|
|
68
|
+
Samples — `libs/site/common/booking/util/src/lib/availability-calendar.logic.ts` and
|
|
69
|
+
`libs/api/<quote domain>/util/src/lib/quote.calculator.ts`.
|
|
68
70
|
|
|
69
|
-
##
|
|
71
|
+
## A procedure is called directly
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
`libs/api
|
|
73
|
+
The handler is the `handle` method of the procedure class in the `feature` layer of its domain. The
|
|
74
|
+
database double is written by hand; the sample is `FakePrismaClient` in
|
|
75
|
+
`libs/api/<booking domain>/feature/src/lib/link-booking.procedure.spec.ts`:
|
|
74
76
|
|
|
75
77
|
```typescript
|
|
76
78
|
const prisma: FakePrismaClient = new FakePrismaClient();
|
|
77
79
|
await procedureWith(prisma, emitter).handle(request());
|
|
78
80
|
```
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
What is checked is the order of actions, the rollback when half of it is refused, the idempotence
|
|
83
|
+
of a repeat and what exactly went into the database. The layout of fields is guarded by the tests
|
|
84
|
+
of the `api` layer and is not repeated here.
|
|
82
85
|
|
|
83
|
-
##
|
|
86
|
+
## A one-off proof test
|
|
84
87
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
A defect that is otherwise confirmed only by reading the code is proved by a test written for the
|
|
89
|
+
time of the investigation: it raises the real procedure, substitutes its only way out and counts
|
|
90
|
+
the calls.
|
|
88
91
|
|
|
89
92
|
```typescript
|
|
90
93
|
globalThis.fetch = (): Promise<Response> => Promise.resolve(Response.json({ success: false }));
|
|
91
94
|
```
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
-
|
|
130
|
-
|
|
96
|
+
The number before the edit and the number after are the only form of answer such a check gives. "A
|
|
97
|
+
hundred calls out of a hundred" and "twenty out of a hundred" can be told apart, and "the code looks
|
|
98
|
+
right" cannot.
|
|
99
|
+
|
|
100
|
+
The second way to take the "before" is to put back the version of the file from the point where
|
|
101
|
+
the branch diverged and run the branch's test: the test failing is the reproduction of the defect.
|
|
102
|
+
After that the file is restored from the copy, and the restoration is checked by running the same
|
|
103
|
+
test, not by memory.
|
|
104
|
+
|
|
105
|
+
Doubles of the neighbours are not invented: the working set is taken from the test of a
|
|
106
|
+
neighbouring procedure of the same domain. A double assembled by type fails not on the assertion
|
|
107
|
+
but on the call of a method it does not have.
|
|
108
|
+
|
|
109
|
+
**Such a file is not committed.** It lives until the end of the investigation and is removed
|
|
110
|
+
together with it; a check worth keeping is rewritten as an ordinary `*.spec.ts` with the scenario
|
|
111
|
+
id in the title and goes in the branch. The sign of a temporary file is that its title names no
|
|
112
|
+
scenario at all.
|
|
113
|
+
|
|
114
|
+
## Green that checks nothing
|
|
115
|
+
|
|
116
|
+
**A probe that expects silence goes paired with a probe that expects a refusal.** Silence also comes
|
|
117
|
+
when there was nothing to check with. A prefix before a command in the pipeline acts on one link,
|
|
118
|
+
and a hook that got an empty value is silent exactly like a hook that has nothing to refuse. Two
|
|
119
|
+
probes out of three are green then — they expected silence — and the miss is visible only by the
|
|
120
|
+
third, which expects a refusal.
|
|
121
|
+
|
|
122
|
+
**A probe on a mine that does not go off is green without the fix.** A scenario on the table of
|
|
123
|
+
refusal codes for a spec without procedures would have passed before the edit too: the audit
|
|
124
|
+
never has to read that table at all. Such a probe is checked from both sides — the previous state
|
|
125
|
+
is brought back for a minute and the probe is run: it did not turn red, so the probe guards
|
|
126
|
+
nothing.
|
|
127
|
+
|
|
128
|
+
## Common misses
|
|
129
|
+
|
|
130
|
+
- A lib without its own `vitest.config.mts`: `nx test <project>` passes green without running a
|
|
131
|
+
single file. Before writing the first test in a lib, check that the config is next to it.
|
|
132
|
+
- Substituting a module (`vi.mock`) would hide what the test is created for — which call went to
|
|
133
|
+
the database and in what order. The double is written by hand.
|
|
134
|
+
- Do not create your own helpers for assertions: `expect(...).toBe(...)` and `.toEqual(...)`
|
|
135
|
+
directly.
|
|
136
|
+
- A title with a scenario id that does not exist takes `npm run check:specs` down, while the tests
|
|
137
|
+
themselves stay green.
|
|
@@ -2,25 +2,26 @@
|
|
|
2
2
|
name: ts-procedure
|
|
3
3
|
kind: pattern
|
|
4
4
|
rule: typescript-conventions
|
|
5
|
-
description:
|
|
5
|
+
description: Pattern of rule typescript-conventions. Load when creating or editing a Connect procedure on the backend — the ready-made class with the method field and the handler, dependencies through the constructor, file and class names. Access to a procedure is described by the access rule of the tree.
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
# A Connect procedure
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Pattern of the rule `typescript-conventions`. What must be true — the law
|
|
11
11
|
`docs/constitution/code-structure.md`.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## When to use
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
15
|
+
- A new backend procedure is created.
|
|
16
|
+
- The body of an existing one is edited.
|
|
17
|
+
- A domain moves onto the vertical cut.
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## One procedure — one class
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
The file `<procedure>.procedure.ts` in the `feature` layer of its domain, the class
|
|
22
|
+
`<Procedure>Procedure`, a public field `method` with the descriptor from the contract and a
|
|
23
|
+
public method `handle` with the body. Dependencies come through the constructor — on the backend
|
|
24
|
+
the DI is NestJS's, there is no `inject()` there.
|
|
24
25
|
|
|
25
26
|
```typescript
|
|
26
27
|
@Injectable()
|
|
@@ -41,26 +42,28 @@ export class PingProcedure implements IConnectProcedure<typeof HealthService.met
|
|
|
41
42
|
}
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
The access declaration is mandatory, and there is exactly one; what declares it is said by the
|
|
46
|
+
access rule of the tree that has such a rule.
|
|
46
47
|
|
|
47
|
-
##
|
|
48
|
+
## Why this shape
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
`router.service`
|
|
52
|
-
|
|
50
|
+
The previous one — `register(router)` with bodies in closures inside `router.service(...)` — made
|
|
51
|
+
the handler unreachable for a test: only a class with a `register` method stuck out. And
|
|
52
|
+
`router.service` stubs every method not passed with an `Unimplemented` answer, so one proto
|
|
53
|
+
service could not be served by two domains.
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
The class solves both: `handle` is called by the test directly, and the registry puts the
|
|
56
|
+
procedures in one by one through `router.rpc`.
|
|
56
57
|
|
|
57
|
-
##
|
|
58
|
+
## Common misses
|
|
58
59
|
|
|
59
|
-
-
|
|
60
|
-
|
|
61
|
-
- `inject()`
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
- A third suffix: `*.rpc.ts` and `*.connect.ts` are the previous names, they leave together with
|
|
61
|
+
the last domain moved, and no new such files are created.
|
|
62
|
+
- `inject()` in a procedure class: on the backend dependencies go through the constructor.
|
|
63
|
+
- The body in a closure inside the router registration: a test cannot reach it.
|
|
64
|
+
- A procedure without an access declaration: the application does not start.
|
|
65
|
+
- An `as` cast in model translation: on the backend it is forbidden the same as in a frontend
|
|
66
|
+
mapper.
|
|
67
|
+
- An own type for the result of Prisma's `groupBy`: it is conditional, assembled from the call
|
|
68
|
+
arguments, and does not match one written out by hand. Where the keys are few, a `count` per
|
|
69
|
+
key goes in `Promise.all`.
|