@ticket-gate/engine 0.0.0-stage → 0.1.0-rc.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/LICENSE +202 -0
- package/README.md +81 -2
- package/bin/ticket-gate.mjs +261 -0
- package/checks/assertions-unguarded.mjs +31 -0
- package/checks/assertions.mjs +319 -0
- package/checks/cache-report.mjs +313 -0
- package/checks/docs-stale.mjs +69 -0
- package/checks/duplication.mjs +258 -0
- package/checks/ratchet-options.mjs +51 -0
- package/checks/surface.mjs +397 -0
- package/cli.mjs +379 -0
- package/commands-config.mjs +55 -0
- package/config.mjs +597 -0
- package/digest.mjs +195 -0
- package/env-name.mjs +24 -0
- package/failures.mjs +256 -0
- package/fu.mjs +458 -0
- package/graph/js.mjs +517 -0
- package/graph/load-time.mjs +309 -0
- package/graph/typescript.mjs +28 -0
- package/hooks/pre-tool-use.mjs +213 -0
- package/hooks/stop.mjs +495 -0
- package/is-main.mjs +15 -0
- package/kill-group.mjs +13 -0
- package/ledger.mjs +186 -0
- package/lock.d.mts +72 -0
- package/lock.mjs +329 -0
- package/move-proof.mjs +206 -0
- package/mutations/check.mjs +506 -0
- package/mutations/cli.mjs +361 -0
- package/mutations/exec.mjs +120 -0
- package/mutations/gate.mjs +148 -0
- package/mutations/harness.mjs +240 -0
- package/mutations/kinds.mjs +148 -0
- package/mutations/locate.mjs +71 -0
- package/mutations/project.mjs +23 -0
- package/mutations/registry.mjs +173 -0
- package/mutations/rotate.mjs +419 -0
- package/mutations/rotation-status.mjs +93 -0
- package/mutations/run.mjs +252 -0
- package/mutations/select.mjs +333 -0
- package/mutations/served.mjs +216 -0
- package/mutations/validate.mjs +86 -0
- package/mutations/verdict.mjs +159 -0
- package/nightly/cli.mjs +30 -0
- package/nightly/define.mjs +111 -0
- package/nightly/e2e-runs.mjs +73 -0
- package/nightly/gate.mjs +25 -0
- package/nightly/io.mjs +109 -0
- package/nightly/launchd.mjs +42 -0
- package/nightly/record.mjs +231 -0
- package/nightly/run.mjs +470 -0
- package/nightly/schedule.mjs +76 -0
- package/nightly/seed.mjs +78 -0
- package/nightly/status.mjs +189 -0
- package/nightly/suites.mjs +43 -0
- package/nightly-config.mjs +38 -0
- package/nightly-window.mjs +6 -0
- package/pack-hooks-all.mjs +15 -0
- package/pack-hooks.mjs +26 -0
- package/package.json +19 -4
- package/plan.mjs +272 -0
- package/precheck.mjs +90 -0
- package/project.mjs +21 -0
- package/ratchet.mjs +431 -0
- package/receipt.mjs +34 -0
- package/review-map.mjs +432 -0
- package/root.mjs +33 -0
- package/run.mjs +291 -0
- package/runners/playwright.mjs +132 -0
- package/score/adapters/stryker.mjs +111 -0
- package/score/base.mjs +82 -0
- package/score/cli.mjs +182 -0
- package/score/judge.mjs +107 -0
- package/score/lines.mjs +40 -0
- package/score/schema.mjs +68 -0
- package/score/survivors.mjs +103 -0
- package/score/targets.mjs +34 -0
- package/score-config.mjs +120 -0
- package/selection/check.mjs +45 -0
- package/selection/cli.mjs +267 -0
- package/selection/define.mjs +55 -0
- package/selection/for.mjs +235 -0
- package/selection/graphs.mjs +38 -0
- package/selection/project.mjs +11 -0
- package/selection/select.mjs +159 -0
- package/selection/units.mjs +646 -0
- package/selection/value-rules.mjs +142 -0
- package/selection-config.mjs +76 -0
- package/serve.mjs +142 -0
- package/summary.mjs +34 -0
- package/tree.mjs +211 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ticket-gate/engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The engine of ticket-gate: a configurable verification gate for agent-driven ticket work.
|
|
4
|
+
|
|
5
|
+
It provides:
|
|
6
|
+
|
|
7
|
+
- the `ticket-gate` command (`verify`, `hook`, `review-map`, `move-check`, `fu`, `ratchet` (`ratchet --all` runs every ratchet with group `check`), `cache-report`, `docs-stale`, `mutate`, `mutations`, `score`, `select`, `nightly`);
|
|
8
|
+
- the mutation engine behind `mutate` and `mutations`, enabled by the `mutations` key of `defineGate`;
|
|
9
|
+
- the mutation score gate behind `score`, enabled by the `score` key of `defineGate`;
|
|
10
|
+
- the affected-spec selection behind `select` and `select check` (import-graph and spec-header based), enabled by the `selection` key of `defineGate`, with graph sources, rules and test runners from the `selectionGraphs`, `selectionRules` and `testRunners` pack hooks;
|
|
11
|
+
- `nightlyUnits({ selection, suite, full, runFrom })` (`selection/units.mjs`), the units of a step backed by a nightly record; it reads the record the gate's `nightly` key points at (`nightlyRecord(gate)`);
|
|
12
|
+
- the nightly (`ticket-gate nightly run [--now] | install | status`), enabled by the `nightly` key of `defineGate`; see Nightly below;
|
|
13
|
+
- `serve({ build, start, port, env }, { onSpawn })` (`serve.mjs`): refuses a busy port, builds, starts the server and resolves with `{ stop }` once the port answers; it rejects on a busy port, a failed build or a server that never answers, and `onSpawn(stop)` runs right after the spawn;
|
|
14
|
+
- the check modules in `checks/` (`surface`, `duplication`, `docs-stale`, `cache-report`, `ratchet-options`, `assertions`, `unguardedKind`), exported for a project's ratchets; `jscpd` is resolved from the consuming project;
|
|
15
|
+
- the `surface` manifest holds `entries` of `{ match, kind, why, owner? }`, an optional `ownerPattern`, `strict` and, when strict, `budget.check` and `budget.wiring` (non-negative integers; `strict: true` without both is exit 2);
|
|
16
|
+
- `strict: true` adds: a `pending` entry fails (rule 2), the code lines of `check` files over `budget.check` fail (rule 5), more than `budget.wiring` files of kind `wiring` fail (rule 6), and `budget.check` may only go down against the baseline's `budget.check` (`--update` records it and refuses a raise); a non-strict manifest ignores `budget`;
|
|
17
|
+
- pack commands: a pack's `packCommands` hook is an object of `name -> (args, { root, gate }) -> code`; `ticket-gate <name> [args]` calls it with the arguments after the name, the project root and the gate, and exits with the number it returns (0 when it returns nothing);
|
|
18
|
+
- `defineGate` and `step`, the API a project's `gate.config.mjs` is written against;
|
|
19
|
+
- the Stop and PreToolUse hooks, which make no network call and collect no telemetry;
|
|
20
|
+
- the receipt, ledger, review-map and follow-up register code.
|
|
21
|
+
|
|
22
|
+
## Assertions ratchet
|
|
23
|
+
|
|
24
|
+
`checks/assertions.mjs` exports `assertions(cfg)`: it counts configured needles per spec file, groups the totals by the areas named in each spec's header, and fails when an area's total drops below its baseline unless a green mutation receipt covers the dropped spec. A rise is reported as stale until the baseline is rewritten with `--update`. A project passes `check` under `ratchets`:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { defineGate } from '@ticket-gate/engine';
|
|
28
|
+
import { assertions } from '@ticket-gate/engine/checks/assertions.mjs';
|
|
29
|
+
import { unguardedKind } from '@ticket-gate/engine/checks/assertions-unguarded.mjs';
|
|
30
|
+
import { resolveSetup } from '@ticket-gate/engine/mutations/kinds.mjs';
|
|
31
|
+
|
|
32
|
+
const mutations = {
|
|
33
|
+
dir: 'gate/registry',
|
|
34
|
+
receipts: { ticket: '.gate/mutation-check.json', registry: '.gate/mutation-registry.json' },
|
|
35
|
+
kinds: { unguarded: unguardedKind({ from: /^tests\/.+\.test\.ts$/, fromHint: 'tests/<...>.test.ts' }) },
|
|
36
|
+
};
|
|
37
|
+
const a = assertions({
|
|
38
|
+
name: 'assertions',
|
|
39
|
+
specs: { dir: 'tests', match: /\.test\.ts$/, header: /^\/\/ areas: ([a-z]+(, [a-z]+)*)$/ },
|
|
40
|
+
areas: ['billing', 'search'],
|
|
41
|
+
counters: { asserts: 'expect(' },
|
|
42
|
+
from: 'tests/',
|
|
43
|
+
receipt: '.gate/mutation-check.json',
|
|
44
|
+
baseline: 'gate/assertions.json',
|
|
45
|
+
registry: 'gate/registry/',
|
|
46
|
+
comment: 'Never edit by hand: run the update command.',
|
|
47
|
+
commands: { update: 'npm run assertions -- --update', mutate: 'npm run mutate -- <ID>', usage: 'npm run assertions' },
|
|
48
|
+
setup: resolveSetup(mutations), // required under `ratchets`, which binds no setup
|
|
49
|
+
});
|
|
50
|
+
export default defineGate({
|
|
51
|
+
ratchets: { assertions: { check: a.check, group: 'check' } },
|
|
52
|
+
mutations,
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`unguardedKind` is a factory, not a registered kind: an `unguarded` registry entry records a guard no test bites, with a reason, and its `from` covers a dropped spec. `from` must not carry the `g` or `y` flag.
|
|
57
|
+
|
|
58
|
+
## Nightly
|
|
59
|
+
|
|
60
|
+
`defineGate({ nightly })` enables the nightly: an unattended run of your end-to-end suites on a scheduled worktree, with a record of each night. `nightly` is one object, checked by `defineNightly` (`nightly/define.mjs`); a bad one fails as `gate.config: nightly: <reason>`.
|
|
61
|
+
|
|
62
|
+
- `suites`: the suites, run in order. Each is `{ name, runner, limitS, keep? }`; `runner.run({ wt, io, args, limitS, env, out, dir })` returns the result and may add an `extra` value that is stored in the record; every suite after the first needs `runner.statusLine(view)`, which prints its line in `ticket-gate nightly status`, which also prints one `move-to-ci 1 (<name>)` line per suite after the first, from that suite's own time and busy nights; the first suite's time is the record's `firstMs` (written when there are two or more suites) or, for an older record, `ms`. `playwrightSuite({ cmd })` (`nightly/suites.mjs`) is the Playwright runner. A suite may set its own `keep` (`reports`: `'all'`, `'history'` or a positive integer; `traces`: a positive integer; the first suite keeps no traces) and its own flaky and move-to-CI handling. The rotation, when configured with `rotate: { command }`, runs last.
|
|
63
|
+
- `worktree: { dir, install }`, `window`, `remote`, `keep`, `selects` and `commands` as in `NIGHTLY_DEFAULTS` (`nightly/define.mjs`).
|
|
64
|
+
- `payloads`: environment setup around the suites (`name`, `preflight`, optional `before`, `after`, `io`). A pack adds its own through the `nightlyPayloads` hook, collected with `packHooksAll`; a duplicate payload name is a config error naming both givers.
|
|
65
|
+
- `scheduler`: `{ name, install(io, dir) }`, what `ticket-gate nightly install` calls (a returned number is the exit code); without it `install` exits 2 (the launchd one is `nightly/launchd.mjs`, macOS only: on another platform it prints one line and exits 2).
|
|
66
|
+
- `ticket-gate nightly run [--now]` runs one night, `ticket-gate nightly install` installs the scheduler job (macOS launchd), `ticket-gate nightly status` prints the status lines, including the two move-to-CI measures.
|
|
67
|
+
- The record (`{ latest, history }`) lives in the nightly directory. The gate also appends one line `{ ranAt, ms, mode, why }` to `e2e-runs.jsonl` there for every end-to-end run; `move-to-ci 2` prints the share of the last 14 days spent in a forced full run against the 25% limit.
|
|
68
|
+
|
|
69
|
+
It has no runtime dependencies and needs Node.js 22 or newer. Install an exact version:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
npm install --save-exact --save-dev @ticket-gate/engine@0.1.0-rc.1
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
What the gate does, how to configure it and how to release it are in the repository README:
|
|
76
|
+
https://github.com/dmitry-prohorov/ticket-gate#readme
|
|
77
|
+
|
|
78
|
+
- Getting started: https://github.com/dmitry-prohorov/ticket-gate/blob/main/docs/getting-started.md
|
|
79
|
+
- Configuration reference: https://github.com/dmitry-prohorov/ticket-gate/blob/main/docs/configuration.md
|
|
80
|
+
- A complete example project: https://github.com/dmitry-prohorov/ticket-gate/tree/main/examples/basic
|
|
81
|
+
|
|
82
|
+
Licence: Apache-2.0.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The engine CLI: one entry for every gate command. Commands load the project's gate.config.mjs
|
|
3
|
+
// (found by walking up from the working directory) only when they need it, so `--help` and the
|
|
4
|
+
// hook spawn work anywhere.
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import { dirname, join } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { isMain } from '../is-main.mjs';
|
|
9
|
+
|
|
10
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const HOOKS = ['stop', 'pre-tool-use'];
|
|
12
|
+
const USAGE = `usage: ticket-gate <command> [args]
|
|
13
|
+
verify [flags] run the steps the diff requires
|
|
14
|
+
hook stop|pre-tool-use run a hook (stdin and exit code pass through)
|
|
15
|
+
review-map [--base=REF] [--full]
|
|
16
|
+
move-check [--base=REF] prove a move-only diff (exit 1 while lines are unmatched)
|
|
17
|
+
fu list|show|next|close|check [args]
|
|
18
|
+
ratchet <name> [args] | ratchet --all [--update]
|
|
19
|
+
run a configured ratchet; --all runs every ratchet with group "check"
|
|
20
|
+
mutate <ID> | --registry (--ids=|--all|--changed) [--dry-run --typecheck --digest --only --file --defer]
|
|
21
|
+
| --rotate --ledger=<dir> [--budget-min= --batch= --deadline= --sha=]
|
|
22
|
+
prove a ticket's registry guards bite (needs mutations in gate.config.mjs)
|
|
23
|
+
mutations check [--fix] validate (and repair) the mutation registry
|
|
24
|
+
mutations select [--affected --paths=] list the registry entries a diff selects
|
|
25
|
+
select [--test-list | --replay=REV --count=N | --for=FILES | --drift=REPORT | --load-time] | select check
|
|
26
|
+
pick the e2e specs a diff reaches, or check the spec headers (needs selection in gate.config.mjs)
|
|
27
|
+
score --base=REF [--files= --report= --base-report=] judge a mutation report (needs score in gate.config.mjs)
|
|
28
|
+
cache-report [<session>|<path.jsonl>] [--json] price the cache use of a Claude Code session
|
|
29
|
+
docs-stale list the docs pages whose sources changed (needs docs in gate.config.mjs)
|
|
30
|
+
nightly run [--now] | install | status the nightly runner (needs nightly in gate.config.mjs)
|
|
31
|
+
<pack command> [args] a command a pack adds through packCommands`;
|
|
32
|
+
|
|
33
|
+
const say = (s) => console.log(s);
|
|
34
|
+
const warn = (s) => console.error(s);
|
|
35
|
+
|
|
36
|
+
function hook(event) {
|
|
37
|
+
if (!HOOKS.includes(event)) {
|
|
38
|
+
warn(
|
|
39
|
+
`ticket-gate: hook takes ${HOOKS.join(' or ')}, got ${event}\n${USAGE}`,
|
|
40
|
+
);
|
|
41
|
+
return 2;
|
|
42
|
+
}
|
|
43
|
+
const child = join(HERE, '..', 'hooks', `${event}.mjs`);
|
|
44
|
+
const r = spawnSync(process.execPath, [child], { stdio: 'inherit' });
|
|
45
|
+
return r.status ?? 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function score(args) {
|
|
49
|
+
const { GATE, ROOT } = await import('../project.mjs');
|
|
50
|
+
if (!GATE.score) {
|
|
51
|
+
warn('mutation: FAIL score is not configured: add a score key to gate.config.mjs');
|
|
52
|
+
return 2;
|
|
53
|
+
}
|
|
54
|
+
const { runScore } = await import('../score/cli.mjs');
|
|
55
|
+
return runScore(args, GATE.score, ROOT);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function select(args) {
|
|
59
|
+
const { GATE, ROOT } = await import('../project.mjs');
|
|
60
|
+
if (!GATE.selection) {
|
|
61
|
+
warn('select: FAIL selection is not configured: add a selection key to gate.config.mjs');
|
|
62
|
+
return 2;
|
|
63
|
+
}
|
|
64
|
+
if (args[0] === 'check') {
|
|
65
|
+
const { checkE2eAreas } = await import('../selection/check.mjs');
|
|
66
|
+
const problems = checkE2eAreas(ROOT, GATE.selection);
|
|
67
|
+
if (problems.length > 0) {
|
|
68
|
+
warn(`${problems.join('\n')}\n\nselect check: fix each line above.`);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
say(`select check: ${problems.counts.specs} specs, ${problems.counts.entries} entries ok`);
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
const { main } = await import('../selection/cli.mjs');
|
|
75
|
+
return main(args, GATE.selection);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function fu(args) {
|
|
79
|
+
const { GATE, ROOT } = await import('../project.mjs');
|
|
80
|
+
const { commandsOf } = await import('../config.mjs');
|
|
81
|
+
const fuCmd = commandsOf(GATE).fu;
|
|
82
|
+
const cfg = GATE.followUps;
|
|
83
|
+
if (!cfg) {
|
|
84
|
+
warn('fu: followUps.dir is not configured');
|
|
85
|
+
return 2;
|
|
86
|
+
}
|
|
87
|
+
const fuLib = await import('../fu.mjs');
|
|
88
|
+
if (args[0] === 'check')
|
|
89
|
+
return fuLib.runCheck(ROOT, cfg, { out: say, err: warn, fuCmd });
|
|
90
|
+
return fuLib.run(args, {
|
|
91
|
+
dir: join(ROOT, cfg.dir),
|
|
92
|
+
label: cfg.dir,
|
|
93
|
+
fuCmd,
|
|
94
|
+
out: say,
|
|
95
|
+
err: warn,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function mutation(cmd, args) {
|
|
100
|
+
const { GATE } = await import('../project.mjs');
|
|
101
|
+
const { runMutationCommand } = await import('../mutations/gate.mjs');
|
|
102
|
+
return runMutationCommand(cmd, args, GATE, { out: say, err: warn });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function ratchet(name, args) {
|
|
106
|
+
const { GATE, ROOT: root } = await import('../project.mjs');
|
|
107
|
+
const entry = GATE.ratchets?.[name];
|
|
108
|
+
if (!entry) {
|
|
109
|
+
warn(
|
|
110
|
+
`ratchet: unknown ${name ?? '(no name)'}; configured: ${Object.keys(GATE.ratchets ?? {}).join(', ') || 'none'}`,
|
|
111
|
+
);
|
|
112
|
+
return 2;
|
|
113
|
+
}
|
|
114
|
+
const baseline = entry.baseline ?? null;
|
|
115
|
+
const result = await entry.check({
|
|
116
|
+
root,
|
|
117
|
+
args,
|
|
118
|
+
update: args.includes('--update'),
|
|
119
|
+
baseline,
|
|
120
|
+
});
|
|
121
|
+
const code = Number.isInteger(result.code) ? result.code : 2;
|
|
122
|
+
(code === 0 ? say : warn)(result.lines.join('\n'));
|
|
123
|
+
if (code !== result.code) warn(`ratchet ${name}: exit 2 (code not an integer)`);
|
|
124
|
+
process.exitCode = code;
|
|
125
|
+
return Number(process.exitCode);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Run every ratchet with group "check", in config order; resolves to the worst exit code. */
|
|
129
|
+
async function ratchetAll(args) {
|
|
130
|
+
const { GATE, ROOT: root } = await import('../project.mjs');
|
|
131
|
+
const list = Object.entries(GATE.ratchets ?? {}).filter(([, e]) => e.group === 'check');
|
|
132
|
+
if (list.length === 0) {
|
|
133
|
+
warn('ratchet --all: no ratchet has group "check"; set group: \'check\' on a ratchet in gate.config.mjs');
|
|
134
|
+
return 2;
|
|
135
|
+
}
|
|
136
|
+
let worst = 0;
|
|
137
|
+
const failed = [];
|
|
138
|
+
for (const [name, entry] of list) {
|
|
139
|
+
let code;
|
|
140
|
+
try {
|
|
141
|
+
const result = await entry.check({
|
|
142
|
+
root,
|
|
143
|
+
args,
|
|
144
|
+
update: args.includes('--update'),
|
|
145
|
+
baseline: entry.baseline ?? null,
|
|
146
|
+
});
|
|
147
|
+
code = Number.isInteger(result.code) ? result.code : 2;
|
|
148
|
+
if (code !== result.code) result.lines = [...(result.lines ?? []), 'exit 2 (code not an integer)'];
|
|
149
|
+
(code === 0 ? say : warn)(result.lines.join('\n'));
|
|
150
|
+
(code === 0 ? say : warn)(`ratchet ${name}: ${code === 0 ? 'ok' : `exit ${code}`}`);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
code = 2;
|
|
153
|
+
warn(`ratchet ${name}: exit 2 (threw: ${e.message})`);
|
|
154
|
+
}
|
|
155
|
+
if (code !== 0) failed.push(name);
|
|
156
|
+
worst = Math.max(worst, code);
|
|
157
|
+
}
|
|
158
|
+
const tail = failed.length > 0 ? `: ${failed.join(', ')}` : '';
|
|
159
|
+
(worst === 0 ? say : warn)(`ratchet --all: ${list.length} ran, ${failed.length} failed${tail}`);
|
|
160
|
+
return worst;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function cacheReport(args) {
|
|
164
|
+
const { ROOT } = await import('../root.mjs');
|
|
165
|
+
const { runCacheReport } = await import('../checks/cache-report.mjs');
|
|
166
|
+
let result;
|
|
167
|
+
try {
|
|
168
|
+
result = runCacheReport({ root: ROOT, args });
|
|
169
|
+
} catch (e) {
|
|
170
|
+
warn(`cache-report: ${e.message}`);
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
(result.code === 0 ? say : warn)(result.lines.join('\n'));
|
|
174
|
+
return result.code;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function docsStale(args) {
|
|
178
|
+
const { GATE, ROOT: root } = await import('../project.mjs');
|
|
179
|
+
if (!GATE.docs) {
|
|
180
|
+
warn('docs-stale: FAIL docs is not configured: add docs.stamped to gate.config.mjs');
|
|
181
|
+
return 2;
|
|
182
|
+
}
|
|
183
|
+
const { docsStale: stale } = await import('../checks/docs-stale.mjs');
|
|
184
|
+
const { stamped, ext, exclude } = GATE.docs;
|
|
185
|
+
const result = stale({
|
|
186
|
+
root,
|
|
187
|
+
dirs: stamped,
|
|
188
|
+
...(ext !== undefined ? { ext } : {}),
|
|
189
|
+
...(exclude !== undefined ? { exclude } : {}),
|
|
190
|
+
});
|
|
191
|
+
say(result.lines.join('\n'));
|
|
192
|
+
return result.code;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function nightly(args) {
|
|
196
|
+
const { GATE } = await import('../project.mjs');
|
|
197
|
+
if (!GATE.nightly) {
|
|
198
|
+
warn('nightly: FAIL nightly is not configured: add a nightly key to gate.config.mjs');
|
|
199
|
+
return 2;
|
|
200
|
+
}
|
|
201
|
+
const { nightlyMain } = await import('../nightly/cli.mjs');
|
|
202
|
+
return nightlyMain(args, GATE.nightly);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Dispatch `argv` (without node and the script); resolves to the exit code. */
|
|
206
|
+
export async function run(argv) {
|
|
207
|
+
const [cmd, ...rest] = argv;
|
|
208
|
+
if (cmd === '--help' || cmd === '-h') return (say(USAGE), 0);
|
|
209
|
+
if (cmd === undefined) return (say(USAGE), 2);
|
|
210
|
+
if (cmd === 'verify') {
|
|
211
|
+
await (await import('../cli.mjs')).main(rest);
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
if (cmd === 'review-map') {
|
|
215
|
+
(await import('../review-map.mjs')).main(rest);
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
if (cmd === 'move-check') {
|
|
219
|
+
const { main } = await import('../move-proof.mjs');
|
|
220
|
+
const { commandsOf } = await import('../config.mjs');
|
|
221
|
+
const { GATE } = await import('../project.mjs');
|
|
222
|
+
main({ moveCheck: commandsOf(GATE).moveCheck, args: rest });
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
if (cmd === 'mutate') return mutation('mutate', rest);
|
|
226
|
+
if (cmd === 'mutations') {
|
|
227
|
+
const sub = rest[0];
|
|
228
|
+
if (sub !== 'check' && sub !== 'select') {
|
|
229
|
+
warn(`ticket-gate: mutations takes check or select, got ${sub ?? '(nothing)'}\n${USAGE}`);
|
|
230
|
+
return 2;
|
|
231
|
+
}
|
|
232
|
+
return mutation(`mutations ${sub}`, rest.slice(1));
|
|
233
|
+
}
|
|
234
|
+
if (cmd === 'score') return score(rest);
|
|
235
|
+
if (cmd === 'select') return select(rest);
|
|
236
|
+
if (cmd === 'hook') return hook(rest[0]);
|
|
237
|
+
if (cmd === 'fu') return fu(rest);
|
|
238
|
+
if (cmd === 'ratchet') return rest[0] === '--all' ? ratchetAll(rest.slice(1)) : ratchet(rest[0], rest.slice(1));
|
|
239
|
+
if (cmd === 'cache-report') return cacheReport(rest);
|
|
240
|
+
if (cmd === 'docs-stale') return docsStale(rest);
|
|
241
|
+
if (cmd === 'nightly') return nightly(rest);
|
|
242
|
+
// No gate.config.mjs means no pack commands: fall through to the unknown-command line.
|
|
243
|
+
const { GATE, ROOT: root } = await import('../project.mjs').catch((e) => {
|
|
244
|
+
// Only a missing gate.config.mjs means "no pack commands"; a missing import inside it is the user's error.
|
|
245
|
+
if (e?.code !== 'ERR_MODULE_NOT_FOUND' || !e.url?.endsWith('/gate.config.mjs')) throw e;
|
|
246
|
+
return { GATE: { packCommands: {} }, ROOT: process.cwd() };
|
|
247
|
+
});
|
|
248
|
+
const own = Object.hasOwn(GATE.packCommands, cmd) ? GATE.packCommands[cmd] : undefined;
|
|
249
|
+
if (own) return Number((await own.run(rest, { root, gate: GATE })) ?? 0);
|
|
250
|
+
warn(`ticket-gate: unknown command ${cmd}\n${USAGE}`);
|
|
251
|
+
return 2;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Run `cmd` with this process's arguments when `url` is the script being executed. */
|
|
255
|
+
export async function runAs(url, cmd) {
|
|
256
|
+
if (!isMain(url)) return;
|
|
257
|
+
process.exitCode = await run([cmd, ...process.argv.slice(2)]);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (isMain(import.meta.url))
|
|
261
|
+
process.exitCode = await run(process.argv.slice(2));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// The `unguarded` mutation kind: a guard no test bites, kept on the books with a reason and never
|
|
2
|
+
// run. It exists for the assertions ratchet, where its `from` covers a dropped spec.
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const isStr = (v) => typeof v === 'string' && v.trim() !== '';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {{ from: RegExp, fromHint: string, prefix?: string }} options `from` is what an entry's
|
|
9
|
+
* `from` must match, `fromHint` names that shape in the error, and `prefix` is prepended to
|
|
10
|
+
* `from` to choose the area file.
|
|
11
|
+
*/
|
|
12
|
+
export function unguardedKind({ from, fromHint, prefix = '' }) {
|
|
13
|
+
return {
|
|
14
|
+
name: 'unguarded',
|
|
15
|
+
runs: false,
|
|
16
|
+
fields: ['title', 'why', 'from'],
|
|
17
|
+
shape(e) {
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const f of ['title', 'why', 'from'])
|
|
20
|
+
if (!isStr(e[f])) out.push(`${f} must be a non-empty string`);
|
|
21
|
+
return out;
|
|
22
|
+
},
|
|
23
|
+
// `from` is checked on an entry of any kind.
|
|
24
|
+
strays(e) {
|
|
25
|
+
return e.from !== undefined && !from.test(String(e.from))
|
|
26
|
+
? [`from must match ${fromHint}`]
|
|
27
|
+
: [];
|
|
28
|
+
},
|
|
29
|
+
area: (e, dir) => `${dir}/${dirname(`${prefix}${e.from}`)}.json`,
|
|
30
|
+
};
|
|
31
|
+
}
|