@rt-tools/agent-kit 0.24.0 → 0.27.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/assets/agents/business-analyst.md +51 -50
- package/assets/agents/cargo-writer.md +54 -0
- 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-epic-link.github.mjs +29 -0
- package/assets/checks/board-epics.github.mjs +286 -49
- 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 +29 -25
- package/assets/checks/board-paths.github.mjs +21 -16
- package/assets/checks/board-pull-state.github.mjs +168 -0
- package/assets/checks/board-runs.github.mjs +45 -43
- package/assets/checks/board-task-dirs.github.mjs +98 -0
- package/assets/checks/board-titles.github.mjs +19 -17
- package/assets/checks/board.github.mjs +133 -194
- package/assets/checks/check-archive-age.mjs +23 -19
- package/assets/checks/check-board.github.mjs +131 -263
- package/assets/checks/check-descriptions.mjs +30 -29
- package/assets/checks/check-doc-paths.mjs +91 -88
- package/assets/checks/check-dupes.mjs +84 -80
- package/assets/checks/check-file-size.mjs +74 -71
- 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 +138 -39
- package/assets/checks/check-push-gate.mjs +53 -50
- package/assets/checks/check-reuse.mjs +50 -40
- package/assets/checks/check-schema-drift.mjs +104 -84
- 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/epic-table.github.mjs +268 -0
- 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 +187 -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/specs-for.mjs +214 -0
- package/assets/checks/task-new.github.mjs +315 -61
- package/assets/commands/feedback.md +65 -59
- package/assets/commands/next-session.md +64 -57
- package/assets/commands/night.md +115 -0
- package/assets/commands/skill-curator.md +83 -79
- package/assets/defaults/gate-map.sh +108 -97
- package/assets/defaults/project.sh +232 -185
- package/assets/defaults/shell.sh +73 -68
- package/assets/defaults/turn-map.md +47 -44
- package/assets/docs/GLOSSARY.md +142 -65
- package/assets/hooks/browser-device-id.sh +16 -12
- package/assets/hooks/browser-guard-device-id.sh +34 -28
- 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 +14 -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 +50 -43
- package/assets/hooks/dispatch.sh +60 -46
- package/assets/hooks/docs-guard.sh +100 -91
- package/assets/hooks/epic-over.sh +49 -0
- package/assets/hooks/epic-stop-guard.sh +108 -0
- package/assets/hooks/exam-guard.sh +105 -93
- package/assets/hooks/git-guard-delivery-conflict.sh +41 -36
- package/assets/hooks/git-guard-delivery-draft.sh +48 -38
- package/assets/hooks/git-guard-delivery-epic.sh +167 -0
- package/assets/hooks/git-guard-delivery-folder.sh +50 -43
- package/assets/hooks/git-guard-delivery-signature.sh +119 -53
- package/assets/hooks/git-guard-delivery.sh +223 -183
- package/assets/hooks/git-guard-main.sh +38 -34
- package/assets/hooks/git-guard-push-tests.sh +99 -87
- 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 +45 -25
- package/assets/hooks/handoff-write.sh +74 -67
- package/assets/hooks/hook-input.sh +67 -58
- 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 +49 -24
- package/assets/hooks/qa-dataid-guard.sh +83 -58
- 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 +39 -34
- package/assets/hooks/rule-source-guard.sh +47 -42
- package/assets/hooks/skill-gate-layers.sh +63 -57
- package/assets/hooks/skill-gate-rearm.sh +15 -8
- package/assets/hooks/skill-gate.sh +89 -81
- package/assets/hooks/skill-loaded.sh +10 -6
- package/assets/hooks/sql-guard-parse.sh +71 -66
- package/assets/hooks/sql-guard-request.sh +51 -46
- package/assets/hooks/sql-guard-target.sh +60 -51
- package/assets/hooks/sql-guard-write.sh +87 -79
- package/assets/hooks/sql-guard.sh +52 -47
- package/assets/hooks/stand-login-guard.sh +43 -37
- 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 +260 -204
- package/assets/hooks/turn-exit-patterns.sh +63 -0
- package/assets/hooks/utf8.sh +14 -11
- package/assets/hooks/waiting-turn-guard.sh +104 -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 +99 -44
- package/assets/laws/autonomous-work.md +29 -27
- package/assets/laws/code-structure.md +31 -30
- package/assets/laws/delivery.md +170 -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 -124
- package/assets/laws/work-conduct.md +250 -244
- 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 +124 -88
- package/assets/patterns/browser-verification-stand.md +169 -157
- package/assets/patterns/component-structure-new.md +51 -42
- package/assets/patterns/dependencies-upgrade.md +55 -39
- package/assets/patterns/doc-style-human.md +55 -37
- 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 -87
- package/assets/patterns/git-workflow-commit.github.md +160 -142
- package/assets/patterns/git-workflow-commit.gitlab.md +96 -90
- 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 +102 -94
- 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 +127 -122
- package/assets/patterns/git-workflow-pr.github.md +186 -177
- package/assets/patterns/git-workflow-pr.gitlab.md +139 -132
- 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 +136 -107
- 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 +48 -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 +234 -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 +228 -202
- package/assets/patterns/testing-e2e.md +102 -101
- 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 +172 -142
- package/assets/pitfalls/doc-style.md +96 -91
- package/assets/pitfalls/git-workflow.azure.md +49 -46
- package/assets/pitfalls/git-workflow.github.md +270 -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 +87 -74
- package/assets/rules/browser-verification.md +223 -214
- 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 +201 -173
- 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 +268 -239
- 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 -143
- package/assets/rules/shared-code.md +82 -79
- package/assets/rules/spec-driven.md +279 -260
- package/assets/rules/status-report.md +62 -58
- package/assets/rules/styling-bem.md +81 -77
- package/assets/rules/task-flow.md +303 -270
- package/assets/rules/testing.md +224 -209
- package/assets/rules/turn-conduct.md +262 -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 +259 -233
- 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/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +8 -1
- package/bin/agent-kit.js.map +1 -1
- package/lib/cargo-prose.d.ts +41 -0
- package/lib/cargo-prose.d.ts.map +1 -0
- package/lib/cargo-prose.js +88 -0
- package/lib/cargo-prose.js.map +1 -0
- package/lib/cargo.d.ts +12 -1
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +8 -2
- package/lib/cargo.js.map +1 -1
- 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 +5 -2
- 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 +12 -3
- package/lib/enroll.js.map +1 -1
- package/lib/fate.d.ts +29 -0
- package/lib/fate.d.ts.map +1 -0
- package/lib/fate.js +147 -0
- package/lib/fate.js.map +1 -0
- package/lib/override-marks.d.ts +7 -0
- package/lib/override-marks.d.ts.map +1 -1
- package/lib/override-marks.js +14 -0
- package/lib/override-marks.js.map +1 -1
- 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 +29 -9
- package/lib/ship.d.ts.map +1 -1
- package/lib/ship.js +44 -2
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.fixture.d.ts +8 -1
- package/lib/shipment.fixture.d.ts.map +1 -1
- package/lib/shipment.fixture.js +9 -0
- package/lib/shipment.fixture.js.map +1 -1
- package/lib/shipment.js +38 -5
- 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.27.0.tgz +0 -0
- package/rt-tools-agent-kit-0.24.0.tgz +0 -0
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The sweeping check that the ready-made was not bypassed.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* The guard `reuse-first-guard.sh` judges an edit at the moment it is written and knows only the
|
|
6
|
+
* added text. What was written before it nobody counts: the styling check measures classes, the
|
|
7
|
+
* linters types and techniques, and that a screen is assembled from a native button instead of the
|
|
8
|
+
* button of the kit is seen by none of them. This check answers another question — «and how much
|
|
9
|
+
* of that is in the tree right now» — and therefore looks at the whole file, not at the edit.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* The signs do not lie here: they are declared as bundles per package of rt-tools, and the tree
|
|
12
|
+
* names in the setting of the checks the ones it takes. The same list is read by the guard — they
|
|
13
|
+
* must not diverge, otherwise an edit passes the guard and falls on the gate. Its own signs the
|
|
14
|
+
* tree appends by a file of its own.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* There are two differences from the guard. The first: the inventory of the kit is not read — the
|
|
17
|
+
* guard asks the disk because it answers for one edit, while a sweeping check cares about what has
|
|
18
|
+
* piled up, and a missing package would silently zero the digest. The second: the marker
|
|
19
|
+
* `native-ok` takes off its own line and the next one, not the whole file.
|
|
18
20
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* What piled up by the moment the check was started lies in tools/reuse-allowlist.json and does not
|
|
22
|
+
* count as a refusal: the gate falls on a new discrepancy, while the old stays a visible number in
|
|
23
|
+
* the digest. A snapshot of the list — `node tools/check-reuse.mjs --baseline`.
|
|
22
24
|
*
|
|
23
|
-
*
|
|
25
|
+
* A non-zero exit code and the list of discrepancies.
|
|
24
26
|
*/
|
|
25
27
|
import { readFileSync, readdirSync } from 'node:fs';
|
|
26
28
|
import { join } from 'node:path';
|
|
@@ -33,15 +35,16 @@ const SOURCE_ROOTS = CONFIG.sourceRoots;
|
|
|
33
35
|
const SKIPPED_DIRS = CONFIG.skippedDirs;
|
|
34
36
|
const BACKEND_ROOTS = CONFIG.backendRoots;
|
|
35
37
|
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
38
|
+
// A shortage of signs is a refusal, not empty work: the check stands in the push gate, and a green
|
|
39
|
+
// answer without a single file read is indistinguishable from an honest zero. The refusal is
|
|
40
|
+
// printed as a line, not as a call stack: it is read by whoever sets up the tree, not by whoever
|
|
41
|
+
// edits this check.
|
|
39
42
|
let SIGNALS;
|
|
40
43
|
try {
|
|
41
44
|
SIGNALS = loadSignals(CONFIG.reuse ?? {}, ROOT);
|
|
42
45
|
} catch (failure) {
|
|
43
46
|
console.error(`check-reuse: ${failure.message}`);
|
|
44
|
-
console.error('\
|
|
47
|
+
console.error('\nThe rule of uniformity is `reuse-first`.');
|
|
45
48
|
process.exit(1);
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -50,12 +53,13 @@ function count(text, expression) {
|
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
|
-
*
|
|
56
|
+
* How many times the sign is seen in the text.
|
|
54
57
|
*
|
|
55
|
-
* `strip`
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
58
|
+
* `strip` crosses out the prescribed variant before the count: the button of the kit has the same
|
|
59
|
+
* substring `<button`, and without the crossing out it would count as a violation by itself. `all`
|
|
60
|
+
* demands a match of every template at once — that is how a host stretched over the whole screen is
|
|
61
|
+
* described. `cancel` puts the sign out whole: the base is already inherited, the ready-made is
|
|
62
|
+
* already called.
|
|
59
63
|
*/
|
|
60
64
|
function found(signal, text) {
|
|
61
65
|
const body = signal.strip ? text.replace(new RegExp(signal.strip, 'gs'), '') : text;
|
|
@@ -89,17 +93,18 @@ function collectFiles(dir) {
|
|
|
89
93
|
return files;
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
/**
|
|
96
|
+
/** Tests, storybook and end-to-end tests are not judged: the native is fitting there */
|
|
93
97
|
function judged(path) {
|
|
94
98
|
return !/\.stories\.(ts|html)$|\.spec\.ts$|\/site-e2e\/|\/admin-e2e\//.test(path);
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
102
|
+
* The marker is a deliberate deviation named by the author. The line where it stands is taken off,
|
|
103
|
+
* and the one that follows it: in markup the marker is put as a comment above the code, because the
|
|
104
|
+
* formatter spreads a long tag over lines and takes the first attribute off the line of the tag
|
|
105
|
+
* name — the sign counts the tag name, and the marker ends up below. Further than the next line the
|
|
106
|
+
* marker does not reach: it does not put out the whole file, otherwise one allowed case would cover
|
|
107
|
+
* its neighbours.
|
|
103
108
|
*/
|
|
104
109
|
function withoutMarked(text) {
|
|
105
110
|
const lines = text.split('\n');
|
|
@@ -117,7 +122,11 @@ for (const root of SOURCE_ROOTS) {
|
|
|
117
122
|
const text = withoutMarked(readFileSync(join(ROOT, path), 'utf8'));
|
|
118
123
|
for (const signal of SIGNALS) {
|
|
119
124
|
const skipped = signal.skipBackendRoots && BACKEND_ROOTS.some((root) => path.startsWith(root));
|
|
120
|
-
|
|
125
|
+
// `exceptNamed` is the reverse side of `onlyNamed`: a tree that writes the ready-made
|
|
126
|
+
// itself takes the folders of the source of that ready-made out from under the sign,
|
|
127
|
+
// not the bundle whole.
|
|
128
|
+
const excluded = signal.exceptNamed && new RegExp(signal.exceptNamed).test(path);
|
|
129
|
+
if (!path.endsWith(signal.ext) || skipped || excluded || (signal.onlyNamed && !new RegExp(signal.onlyNamed).test(path))) {
|
|
121
130
|
continue;
|
|
122
131
|
}
|
|
123
132
|
const times = found(signal, text);
|
|
@@ -137,21 +146,22 @@ if (process.argv.includes('--baseline')) {
|
|
|
137
146
|
}
|
|
138
147
|
|
|
139
148
|
const problems = [
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
...
|
|
149
|
+
// The ready-made is named with a reservation on purpose: the sign judges the tag, and the place
|
|
150
|
+
// of showing it does not. Replacing one's own paragraph of a refusal with a ready-made component
|
|
151
|
+
// of the same screen closes the sign and leaves the violation in place — thirteen templates were
|
|
152
|
+
// repaired that way at once. The output line is a measurement, not an instruction.
|
|
153
|
+
...fresh.map((finding) => `${finding.key} — the ready-made (if the place of use is right): ${finding.instead}`),
|
|
154
|
+
...stale.map((key) => `${key}: listed in ${ALLOWLIST}, and the tree carries no such divergence any more — fix the line or remove it`),
|
|
145
155
|
];
|
|
146
156
|
|
|
147
157
|
if (problems.length > 0) {
|
|
148
|
-
console.error(`check-reuse:
|
|
158
|
+
console.error(`check-reuse: divergences ${problems.length}\n`);
|
|
149
159
|
problems.forEach((problem) => console.error(` ${problem}`));
|
|
150
|
-
console.error('\
|
|
160
|
+
console.error('\nThe rule of uniformity is `reuse-first`.');
|
|
151
161
|
process.exit(1);
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
const places = findings.reduce((sum, finding) => sum + Number(finding.key.match(/×(\d+)/)[1]), 0);
|
|
155
165
|
console.log(
|
|
156
|
-
`check-reuse:
|
|
166
|
+
`check-reuse: places where the ready-made was bypassed: ${places} in ${findings.length} signs — accepted ${findings.length - debt.size}, debt ${debt.size}, no new ones`
|
|
157
167
|
);
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The check that the migrations and `prisma/schema.prisma` describe one and the same database.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Neither the linter nor the build sees a divergence between them: it lives not in the code but
|
|
6
|
+
* between the schema and the SQL. That is how a migration creating two indexes the schema did not
|
|
7
|
+
* declare went into the main branch — the rollout fell already in the pipeline.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* What is measured is the migrations, not the database of whoever runs the check. A developer's
|
|
10
|
+
* database lawfully carries the trace of any unfinished branch: one such held the push of someone
|
|
11
|
+
* else's edit with four tables and eight columns that the schema of the main branch does not
|
|
12
|
+
* have — while the migrations and the schema agreed.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* So the migrations are applied to a one-off shadow database, and it is that one which is
|
|
15
|
+
* compared. The shadow database is started for every run and torn down after: left between runs,
|
|
16
|
+
* it will itself accumulate the trace of a branch with a migration, and the check will again start
|
|
17
|
+
* judging the state of the machine instead of the repository.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* A non-zero return code and an explanation of the divergence.
|
|
20
20
|
*/
|
|
21
21
|
import { spawnSync } from 'node:child_process';
|
|
22
22
|
import { existsSync, readFileSync } from 'node:fs';
|
|
@@ -24,16 +24,16 @@ import { join } from 'node:path';
|
|
|
24
24
|
import process from 'node:process';
|
|
25
25
|
import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
|
|
26
26
|
|
|
27
|
-
/**
|
|
27
|
+
/** The suffix of the shadow database: by it one sees that it is the shadow being torn down, not somebody's working base */
|
|
28
28
|
const SHADOW_SUFFIX = '_gate_shadow';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* The signs of the production database — the same as in `sql-guard`. The schema in production
|
|
32
|
+
* changes only by a rollout, and the check goes there neither to read nor to write.
|
|
33
33
|
*/
|
|
34
34
|
const PRODUCTION_MARKS = CONFIG.productionMarks ?? [];
|
|
35
35
|
|
|
36
|
-
/**
|
|
36
|
+
/** The server is alive but the database is not there; there is no server at all — both mean "nowhere to check" */
|
|
37
37
|
const SERVER_DOWN_CODES = ['ECONNREFUSED', 'ENOTFOUND', 'EHOSTUNREACH', 'ETIMEDOUT'];
|
|
38
38
|
|
|
39
39
|
function databaseUrl() {
|
|
@@ -58,7 +58,7 @@ function databaseUrl() {
|
|
|
58
58
|
: '';
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/**
|
|
61
|
+
/** The address of the shadow database and the address of the service one it is started and torn down from */
|
|
62
62
|
function shadowAddresses(url) {
|
|
63
63
|
const parsed = new URL(url);
|
|
64
64
|
const name = decodeURIComponent(parsed.pathname.replace(/^\//, ''));
|
|
@@ -67,36 +67,38 @@ function shadowAddresses(url) {
|
|
|
67
67
|
const shadow = new URL(url);
|
|
68
68
|
shadow.pathname = `/${encodeURIComponent(shadowName)}`;
|
|
69
69
|
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
70
|
+
// A database can be started and torn down only from another database of the same server;
|
|
71
|
+
// `postgres` is always there, and the working one will not do for this — the teardown happens
|
|
72
|
+
// while connections to it are alive.
|
|
73
73
|
const service = new URL(url);
|
|
74
74
|
service.pathname = '/postgres';
|
|
75
75
|
|
|
76
76
|
return { shadowName, shadowUrl: shadow.toString(), serviceUrl: service.toString() };
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
79
|
+
// The code by which the check declares that there was nothing to look at. Formerly every such exit
|
|
80
|
+
// was a zero: the line about the skip went to the output, and in the digest of the push gate the
|
|
81
|
+
// zero stood next to the checks that had passed and differed from them in nothing — the set read
|
|
82
|
+
// as checked in full. The push guard knows the number too: it names what was skipped out loud
|
|
83
|
+
// without refusing the push, because a check with nothing to look at is not a breakage.
|
|
84
84
|
const SKIP = Number(process.env.RT_SKIP_CODE ?? 7);
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* Whether the branch touched the storage — the schema or the migrations directory.
|
|
88
88
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
89
|
+
* Skipping the check is lawful exactly up to this line. A database on a developer's machine is shut
|
|
90
|
+
* down as a matter of routine, and there is nothing in that to refuse a push of documentation for;
|
|
91
|
+
* but a branch that edited the migrations goes into main blind without a run of the chain — and
|
|
92
|
+
* falls not there but at the rollout. That is how production fell: five fields appeared in the
|
|
93
|
+
* schema without migrations, some pages started answering "not found", half an hour of downtime,
|
|
94
|
+
* fixed by a rollback. The gate was green all the while: the check returned the skip code.
|
|
94
95
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
96
|
+
* Both sides are looked at — what is uncommitted in the working tree and the branch's contribution
|
|
97
|
+
* from main. The contribution alone is not enough: an edit that has not reached a commit yet goes
|
|
98
|
+
* out with the same push right after.
|
|
97
99
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
+
* FAIL-OPEN: no git, no main branch, the call fell — it counts as not touched. A check that refuses
|
|
101
|
+
* a push out of its own blindness is worse than a skip: there is nothing in it to fix.
|
|
100
102
|
*/
|
|
101
103
|
function touchedStorage() {
|
|
102
104
|
const paths = [CONFIG.schemaFile, CONFIG.migrationsDir].filter(Boolean);
|
|
@@ -110,8 +112,8 @@ function touchedStorage() {
|
|
|
110
112
|
return out.status === 0 ? (out.stdout ?? '') : '';
|
|
111
113
|
};
|
|
112
114
|
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
+
// The main branch is taken by the remote ref: the local one is a snapshot of the last pull, and
|
|
116
|
+
// a contribution counted from it lies exactly in the direction where the check stays silent.
|
|
115
117
|
const main = CONFIG.mainBranch ?? 'main';
|
|
116
118
|
const base = [`origin/${main}`, main].find((ref) => git(['rev-parse', '--verify', '--quiet', ref]).trim()) ?? '';
|
|
117
119
|
|
|
@@ -129,18 +131,18 @@ function prisma(args, url) {
|
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
async function withServiceClient(serviceUrl, run) {
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
//
|
|
134
|
+
// The database client is pulled in on the spot, not by an import at the top: a tree without
|
|
135
|
+
// storage does not keep this package in its dependencies, and a static import would drop the
|
|
136
|
+
// check before it managed to say that there is nothing here to audit.
|
|
135
137
|
const pg = (await import('pg')).default;
|
|
136
138
|
const client = new pg.Client({ connectionString: serviceUrl });
|
|
137
139
|
try {
|
|
138
140
|
await client.connect();
|
|
139
141
|
} catch (error) {
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
+
// Docker shut down is an ordinary state of the machine, not a reason to keep documentation
|
|
143
|
+
// from being pushed.
|
|
142
144
|
if (SERVER_DOWN_CODES.includes(error?.code)) {
|
|
143
|
-
return unavailable('
|
|
145
|
+
return unavailable('the database is unavailable');
|
|
144
146
|
}
|
|
145
147
|
throw error;
|
|
146
148
|
}
|
|
@@ -153,54 +155,56 @@ async function withServiceClient(serviceUrl, run) {
|
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
/**
|
|
156
|
-
*
|
|
158
|
+
* The answer to "nowhere to check": a skip or a refusal — depending on whether the branch touched
|
|
159
|
+
* the storage.
|
|
157
160
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
161
|
+
* The refusal names what to raise the database with. "Nowhere" said on its own the executor reads
|
|
162
|
+
* as a permission: raising it is not his duty, and the gate is green.
|
|
160
163
|
*/
|
|
161
164
|
function unavailable(why) {
|
|
162
165
|
if (!touchedStorage()) {
|
|
163
|
-
console.log(`check-schema-drift: ${why} —
|
|
166
|
+
console.log(`check-schema-drift: ${why} — there is nowhere to check`);
|
|
164
167
|
|
|
165
168
|
return SKIP;
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
console.error(`check-schema-drift: ${why},
|
|
171
|
+
console.error(`check-schema-drift: ${why}, and the branch edited the schema or the migrations — there is nowhere to check, though there was something to check\n`);
|
|
169
172
|
console.error(
|
|
170
|
-
'
|
|
171
|
-
'
|
|
172
|
-
'
|
|
173
|
-
'
|
|
174
|
-
'
|
|
175
|
-
'
|
|
173
|
+
'The chain of migrations on an empty storage is the only place where their true order shows:\n' +
|
|
174
|
+
'the timestamp is set by the minute of creation, and a migration from a branch started earlier\n' +
|
|
175
|
+
'stands before the one it depends on. On the deployed storage of a developer it applies, on a\n' +
|
|
176
|
+
'clean one it fails — and that shows for the first time at the rollout.\n\n' +
|
|
177
|
+
'Raise the database and repeat; when it is not at hand, the chain runs on a one-off container —\n' +
|
|
178
|
+
'the ready-made commands are in the pattern `git-workflow-migration`.'
|
|
176
179
|
);
|
|
177
180
|
|
|
178
181
|
return 1;
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
async function main() {
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
//
|
|
185
|
+
// A name that is not set is asked about separately from a file that does not exist. Glued to
|
|
186
|
+
// the root, an empty name gives the root itself — and the root is always there, so the check
|
|
187
|
+
// went on as if the schema were in place. A tree without storage says just that: there is no
|
|
188
|
+
// name, there is nothing to audit.
|
|
185
189
|
if (!CONFIG.schemaFile) {
|
|
186
|
-
console.log('check-schema-drift:
|
|
190
|
+
console.log('check-schema-drift: the schema file name is not set — there is nothing to check');
|
|
187
191
|
|
|
188
192
|
return SKIP;
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
if (!existsSync(join(ROOT, CONFIG.schemaFile))) {
|
|
192
|
-
console.log('check-schema-drift:
|
|
196
|
+
console.log('check-schema-drift: there is no schema — there is nothing to check');
|
|
193
197
|
|
|
194
198
|
return SKIP;
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
const url = databaseUrl();
|
|
198
202
|
if (!url) {
|
|
199
|
-
return unavailable('
|
|
203
|
+
return unavailable('the database address is not set');
|
|
200
204
|
}
|
|
201
205
|
|
|
202
206
|
if (PRODUCTION_MARKS.some((mark) => url.includes(mark))) {
|
|
203
|
-
console.log('check-schema-drift:
|
|
207
|
+
console.log('check-schema-drift: the address is production — the check does not go there');
|
|
204
208
|
|
|
205
209
|
return SKIP;
|
|
206
210
|
}
|
|
@@ -208,46 +212,62 @@ async function main() {
|
|
|
208
212
|
const { shadowName, shadowUrl, serviceUrl } = shadowAddresses(url);
|
|
209
213
|
|
|
210
214
|
return withServiceClient(serviceUrl, async (client) => {
|
|
211
|
-
//
|
|
215
|
+
// The identifier is quoted: the database name comes from the address, not from the text of the query
|
|
212
216
|
const quoted = `"${shadowName.replace(/"/g, '""')}"`;
|
|
213
217
|
await client.query(`DROP DATABASE IF EXISTS ${quoted}`);
|
|
218
|
+
// The shadow database is created here rather than left to `migrate deploy`. The seventh
|
|
219
|
+
// edition of the client goes to the storage through an adapter and creates nothing: a
|
|
220
|
+
// missing database it answers with `P1001`, «Can't reach database server», while the server
|
|
221
|
+
// answers and the port is open. Read as it is written, that refusal says the machine has no
|
|
222
|
+
// storage at all — and the check created to catch a migration that falls on a clean database
|
|
223
|
+
// stayed silent about exactly that.
|
|
224
|
+
await client.query(`CREATE DATABASE ${quoted}`);
|
|
214
225
|
|
|
215
226
|
try {
|
|
216
|
-
// Базу заводит сам `migrate deploy`: своей команды создания не нужно
|
|
217
227
|
const deploy = prisma(['migrate', 'deploy'], shadowUrl);
|
|
218
228
|
if (deploy.status !== 0) {
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
const said = `${deploy.stdout ?? ''}${deploy.stderr ?? ''}`;
|
|
230
|
+
// `P1001` names an unreachable server, and the client says it about a missing
|
|
231
|
+
// database too — the two are indistinguishable in its answer. The shadow database
|
|
232
|
+
// was created a line above, so here it means the check itself, not the migrations:
|
|
233
|
+
// said as a refusal of the migrations, it sends whoever reads it to look for a
|
|
234
|
+
// divergence that does not exist.
|
|
235
|
+
console.error(
|
|
236
|
+
said.includes('P1001')
|
|
237
|
+
? 'check-schema-drift: the shadow database did not answer, and this is a defect of the check rather than of the migrations\n'
|
|
238
|
+
: 'check-schema-drift: the migrations do not apply to a clean database\n'
|
|
239
|
+
);
|
|
240
|
+
console.error(said);
|
|
221
241
|
|
|
222
242
|
return 1;
|
|
223
243
|
}
|
|
224
244
|
|
|
225
|
-
// `--exit-code`: 0 —
|
|
245
|
+
// `--exit-code`: 0 — no divergences, 2 — there are some, anything else — a failure of the command itself
|
|
226
246
|
const diff = prisma(
|
|
227
247
|
['migrate', 'diff', '--from-config-datasource', '--to-schema', CONFIG.schemaFile, '--exit-code'],
|
|
228
248
|
shadowUrl
|
|
229
249
|
);
|
|
230
250
|
if (diff.status === 2) {
|
|
231
|
-
console.error('check-schema-drift:
|
|
251
|
+
console.error('check-schema-drift: the migrations and the schema describe different databases\n');
|
|
232
252
|
console.error(`${diff.stdout ?? ''}${diff.stderr ?? ''}`);
|
|
233
253
|
console.error(
|
|
234
|
-
'\
|
|
254
|
+
'\nEither the schema was edited without a migration, or the migration creates what the schema does not declare.\nHow a migration is written — the pattern `git-workflow-migration`.'
|
|
235
255
|
);
|
|
236
256
|
|
|
237
257
|
return 1;
|
|
238
258
|
}
|
|
239
259
|
if (diff.status !== 0) {
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
console.error('check-schema-drift:
|
|
260
|
+
// Neither "agreed" nor "diverged" — the comparison command itself did not work. A
|
|
261
|
+
// skip here is indistinguishable from migrations that agreed, and it was by exactly
|
|
262
|
+
// that the check stayed silent about an empty schema name: with it the check called
|
|
263
|
+
// the comparison without a required argument, and the refusal read as a green gate.
|
|
264
|
+
console.error('check-schema-drift: the comparison did not work out\n');
|
|
245
265
|
console.error(`${diff.stdout ?? ''}${diff.stderr ?? ''}`);
|
|
246
266
|
|
|
247
267
|
return 1;
|
|
248
268
|
}
|
|
249
269
|
|
|
250
|
-
console.log('check-schema-drift:
|
|
270
|
+
console.log('check-schema-drift: the migrations and the schema match');
|
|
251
271
|
|
|
252
272
|
return 0;
|
|
253
273
|
} finally {
|
|
@@ -259,16 +279,16 @@ async function main() {
|
|
|
259
279
|
main().then(
|
|
260
280
|
(code) => process.exit(code),
|
|
261
281
|
(error) => {
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
console.error(`check-schema-drift:
|
|
282
|
+
// A broken harness is not a skip but a refusal. "Nowhere to check" the check says itself and
|
|
283
|
+
// earlier: no schema, no address, a production address, the server does not answer — all of
|
|
284
|
+
// these are lawful exits with a zero, and each is named by a line of its own. What reaches
|
|
285
|
+
// here is what the check did not foresee, and a silent zero here means "the gate is green
|
|
286
|
+
// because the audit did not work out". There is nothing to tell it from "audited and
|
|
287
|
+
// agreed": behind such a zero the check stood switched off until it was called by hand.
|
|
288
|
+
console.error(`check-schema-drift: the check did not work out — ${error?.message ?? error}\n`);
|
|
269
289
|
console.error(
|
|
270
|
-
'
|
|
271
|
-
'
|
|
290
|
+
'This is a refusal of the check itself, not a divergence of the schema. Fix the harness: a missing package is installed at the root,\n' +
|
|
291
|
+
'an empty name of the schema or of the migrations directory is set in the checks config of the tree.'
|
|
272
292
|
);
|
|
273
293
|
process.exit(1);
|
|
274
294
|
}
|