ratch 0.1.0__tar.gz

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.
Files changed (68) hide show
  1. ratch-0.1.0/LICENSE +201 -0
  2. ratch-0.1.0/PKG-INFO +10 -0
  3. ratch-0.1.0/README.md +30 -0
  4. ratch-0.1.0/pyproject.toml +48 -0
  5. ratch-0.1.0/ratch/__init__.py +27 -0
  6. ratch-0.1.0/ratch/__main__.py +6 -0
  7. ratch-0.1.0/ratch/check.py +46 -0
  8. ratch-0.1.0/ratch/checks/__init__.py +7 -0
  9. ratch-0.1.0/ratch/checks/ai_signatures.py +125 -0
  10. ratch-0.1.0/ratch/checks/bdd_conventions.py +108 -0
  11. ratch-0.1.0/ratch/checks/catalog_size.py +64 -0
  12. ratch-0.1.0/ratch/checks/circular_import.py +120 -0
  13. ratch-0.1.0/ratch/checks/commit_heatmap.py +89 -0
  14. ratch-0.1.0/ratch/checks/conflict_markers.py +79 -0
  15. ratch-0.1.0/ratch/checks/doc_counts.py +111 -0
  16. ratch-0.1.0/ratch/checks/docs_render.py +87 -0
  17. ratch-0.1.0/ratch/checks/first_person.py +131 -0
  18. ratch-0.1.0/ratch/checks/font_cdn.py +84 -0
  19. ratch-0.1.0/ratch/checks/forbidden_literal.py +131 -0
  20. ratch-0.1.0/ratch/checks/hash_named_test.py +83 -0
  21. ratch-0.1.0/ratch/checks/manifest_purity.py +187 -0
  22. ratch-0.1.0/ratch/checks/plugin_registry.py +425 -0
  23. ratch-0.1.0/ratch/checks/pytest_skip.py +92 -0
  24. ratch-0.1.0/ratch/checks/todo_issue.py +80 -0
  25. ratch-0.1.0/ratch/checks/vacuous_assert.py +81 -0
  26. ratch-0.1.0/ratch/cli.py +60 -0
  27. ratch-0.1.0/ratch/pytest_plugin.py +54 -0
  28. ratch-0.1.0/ratch/registry.py +36 -0
  29. ratch-0.1.0/ratch/reporter.py +26 -0
  30. ratch-0.1.0/ratch/result.py +71 -0
  31. ratch-0.1.0/ratch/runner.py +118 -0
  32. ratch-0.1.0/ratch/testing.py +133 -0
  33. ratch-0.1.0/ratch/workspace.py +188 -0
  34. ratch-0.1.0/ratch.egg-info/PKG-INFO +10 -0
  35. ratch-0.1.0/ratch.egg-info/SOURCES.txt +66 -0
  36. ratch-0.1.0/ratch.egg-info/dependency_links.txt +1 -0
  37. ratch-0.1.0/ratch.egg-info/entry_points.txt +24 -0
  38. ratch-0.1.0/ratch.egg-info/requires.txt +3 -0
  39. ratch-0.1.0/ratch.egg-info/top_level.txt +1 -0
  40. ratch-0.1.0/setup.cfg +4 -0
  41. ratch-0.1.0/tests/test_ai_signatures.py +103 -0
  42. ratch-0.1.0/tests/test_bdd_conventions.py +83 -0
  43. ratch-0.1.0/tests/test_catalog_size.py +38 -0
  44. ratch-0.1.0/tests/test_check.py +70 -0
  45. ratch-0.1.0/tests/test_circular_import.py +48 -0
  46. ratch-0.1.0/tests/test_cli.py +83 -0
  47. ratch-0.1.0/tests/test_commit_heatmap.py +37 -0
  48. ratch-0.1.0/tests/test_conflict_markers.py +35 -0
  49. ratch-0.1.0/tests/test_doc_counts.py +50 -0
  50. ratch-0.1.0/tests/test_docs_render.py +42 -0
  51. ratch-0.1.0/tests/test_first_person.py +117 -0
  52. ratch-0.1.0/tests/test_font_cdn.py +38 -0
  53. ratch-0.1.0/tests/test_forbidden_literal.py +64 -0
  54. ratch-0.1.0/tests/test_hash_named_test.py +32 -0
  55. ratch-0.1.0/tests/test_manifest_purity.py +94 -0
  56. ratch-0.1.0/tests/test_plugin_registry.py +109 -0
  57. ratch-0.1.0/tests/test_pytest_seam.py +99 -0
  58. ratch-0.1.0/tests/test_pytest_skip.py +37 -0
  59. ratch-0.1.0/tests/test_registry.py +87 -0
  60. ratch-0.1.0/tests/test_reporter.py +28 -0
  61. ratch-0.1.0/tests/test_result.py +41 -0
  62. ratch-0.1.0/tests/test_runner.py +114 -0
  63. ratch-0.1.0/tests/test_self_host.py +35 -0
  64. ratch-0.1.0/tests/test_self_host_blackbox.py +84 -0
  65. ratch-0.1.0/tests/test_testing.py +53 -0
  66. ratch-0.1.0/tests/test_todo_issue.py +33 -0
  67. ratch-0.1.0/tests/test_vacuous_assert.py +45 -0
  68. ratch-0.1.0/tests/test_workspace.py +249 -0
ratch-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 wan9yu
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
ratch-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: ratch
3
+ Version: 0.1.0
4
+ Summary: The ratchet only turns one way: code is the single source of truth.
5
+ License: Apache-2.0
6
+ Requires-Python: >=3.11
7
+ License-File: LICENSE
8
+ Provides-Extra: dev
9
+ Requires-Dist: pytest; extra == "dev"
10
+ Dynamic: license-file
ratch-0.1.0/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # ratch
2
+
3
+ [![ci](https://github.com/wan9yu/ratch/actions/workflows/ci.yml/badge.svg)](https://github.com/wan9yu/ratch/actions/workflows/ci.yml)
4
+
5
+ <!-- ratch:authored -->
6
+ ratch is a ratchet for repository invariants: a small set of Tier A checks
7
+ that fail a commit the moment a mechanical, provable rule is broken, and stay
8
+ silent otherwise. Each check is configured by instantiation, proven by its own
9
+ plants, and carries a four-heading docstring stating the rule and its evidence.
10
+ The ratchet only turns one way: once a check ships, the repository it gates
11
+ cannot regress on that rule without the check itself changing.
12
+
13
+ Install from git, add a `ratch_checks.py` at the repository root (see
14
+ `examples/ratch_checks.py`), then run `python -m ratch check`.
15
+
16
+ ratch will never gate on judgment. It does not score, grade, or block on:
17
+
18
+ - naming quality
19
+ - abstraction quality
20
+ - prose quality (including commit-message quality)
21
+ - test meaningfulness
22
+
23
+ Those are decisions to not write code for: a machine cannot prove taste, so
24
+ ratch does not pretend to. Those calls belong to review by people. ratch
25
+ gates only what a machine can prove.
26
+ <!-- ratch:authored:end -->
27
+
28
+ <!-- ratch:generated:checks -->
29
+ catalog_n=17
30
+ <!-- ratch:generated:checks:end -->
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ratch"
7
+ version = "0.1.0"
8
+ description = "The ratchet only turns one way: code is the single source of truth."
9
+ license = {text = "Apache-2.0"}
10
+ requires-python = ">=3.11"
11
+
12
+ [project.optional-dependencies]
13
+ dev = ["pytest"]
14
+
15
+ [project.scripts]
16
+ ratch = "ratch.cli:main"
17
+
18
+ [project.entry-points.pytest11]
19
+ ratch = "ratch.pytest_plugin"
20
+
21
+ [project.entry-points."ratch.checks"]
22
+ no-forbidden-literal = "ratch.checks.forbidden_literal:NoForbiddenLiteral"
23
+ no-first-person = "ratch.checks.first_person:NoFirstPerson"
24
+ no-ai-signatures = "ratch.checks.ai_signatures:NoAiSignatures"
25
+ no-circular-import = "ratch.checks.circular_import:NoCircularImport"
26
+ plugin-registry = "ratch.checks.plugin_registry:PluginRegistry"
27
+ manifest-purity = "ratch.checks.manifest_purity:ManifestPurity"
28
+ no-conflict-markers = "ratch.checks.conflict_markers:NoConflictMarkers"
29
+ no-vacuous-assert = "ratch.checks.vacuous_assert:NoVacuousAssert"
30
+ bdd-test-conventions = "ratch.checks.bdd_conventions:BddTestConventions"
31
+ no-pytest-skip = "ratch.checks.pytest_skip:NoPytestSkip"
32
+ no-hash-named-test = "ratch.checks.hash_named_test:NoHashNamedTest"
33
+ todo-has-issue-ref = "ratch.checks.todo_issue:TodoHasIssueRef"
34
+ no-external-font-cdn = "ratch.checks.font_cdn:NoExternalFontCdn"
35
+ doc-counts-match-ssot = "ratch.checks.doc_counts:DocCountsMatchSSot"
36
+ docs-equal-fresh-render = "ratch.checks.docs_render:DocsEqualFreshRender"
37
+ catalog-size = "ratch.checks.catalog_size:CatalogSize"
38
+ commit-heatmap = "ratch.checks.commit_heatmap:CommitHeatmap"
39
+
40
+ [tool.setuptools.packages.find]
41
+ include = ["ratch*"]
42
+
43
+ # REQUIRED: pytest's default `python_functions` is `test*`, which does NOT collect
44
+ # BDD-named `*_should_*` functions. Without this block every "watch it pass" step
45
+ # silently collects nothing (exit 5, "no tests ran") — the plan cannot be executed.
46
+ [tool.pytest.ini_options]
47
+ python_functions = ["*_should_*"]
48
+ testpaths = ["tests"]
@@ -0,0 +1,27 @@
1
+ """ratch — a ratchet for repository invariants.
2
+
3
+ Decision: code is the single source of truth (SSOT); docs are pointers,
4
+ generated, or signed. Rejected: a docs/ tree. Because: a copied fact rots.
5
+ """
6
+
7
+ from ratch.result import (
8
+ EXIT,
9
+ PRECEDENCE,
10
+ Finding,
11
+ MeasuredValue,
12
+ MState,
13
+ Result,
14
+ State,
15
+ run_exit_code,
16
+ )
17
+
18
+ __all__ = [
19
+ "EXIT",
20
+ "PRECEDENCE",
21
+ "Finding",
22
+ "MeasuredValue",
23
+ "MState",
24
+ "Result",
25
+ "State",
26
+ "run_exit_code",
27
+ ]
@@ -0,0 +1,6 @@
1
+ """Enable 'python -m ratch'."""
2
+ import sys
3
+
4
+ from ratch.cli import main
5
+
6
+ sys.exit(main())
@@ -0,0 +1,46 @@
1
+ """The Check contract: the shape every rule instance must present.
2
+
3
+ A check is configured by instantiation — constructor arguments on the
4
+ instance, never a config file. The runtime-checkable Protocol lets the
5
+ runner accept any object that exposes this shape, keeping rules and the
6
+ engine decoupled.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from collections.abc import Iterable
12
+ from dataclasses import dataclass
13
+ from typing import TYPE_CHECKING, Protocol, runtime_checkable
14
+
15
+ from ratch.result import Result
16
+
17
+ if TYPE_CHECKING:
18
+ # TYPE_CHECKING-only: resolves the Workspace forward reference for
19
+ # static type checkers; not imported at runtime (no ratch code calls
20
+ # get_type_hints on these annotations, and this avoids a runtime
21
+ # import).
22
+ from ratch.workspace import Workspace
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class Plant:
27
+ label: str
28
+ planted_ws: object
29
+ expected: tuple[str, str, str]
30
+
31
+
32
+ @runtime_checkable
33
+ class Check(Protocol):
34
+ id: str
35
+ tier: str
36
+ kind: str
37
+ scope: str
38
+ proven_in: tuple[str, ...]
39
+ confidence: str
40
+ tolerates_unparseable: bool
41
+
42
+ def check(self, ws) -> Result: ...
43
+
44
+ def plants(self, ws) -> Iterable[Plant]: ...
45
+
46
+ def fixture(self, kit) -> Workspace: ...
@@ -0,0 +1,7 @@
1
+ """Shipped check plugins. Discovery is via entry points, not this module."""
2
+
3
+
4
+ def is_test_py(path):
5
+ return path.endswith(".py") and (
6
+ path.startswith("tests/") or "/tests/" in path
7
+ )
@@ -0,0 +1,125 @@
1
+ """No-AI-signatures check."""
2
+ from __future__ import annotations
3
+
4
+ import re
5
+ from subprocess import CompletedProcess
6
+
7
+ from ratch.check import Plant
8
+ from ratch.result import Finding, Result, State
9
+ from ratch.testing import FakeWorkspace
10
+
11
+
12
+ def _log_text(commits):
13
+ """Render commits exactly as ws.git_log(fmt=...) would: each commit is
14
+ ``sha\\0an\\0ae\\0cn\\0ce\\0body\\0`` and git joins records with ``\\n``."""
15
+ recs = ["\x00".join(c) + "\x00" for c in commits]
16
+ return "\n".join(recs) + "\n"
17
+
18
+
19
+ class NoAiSignatures:
20
+ """Forbid AI-attribution shapes anywhere in the full commit history.
21
+
22
+ Rule:
23
+ No commit message or committer/author identity, across the entire
24
+ reachable history, may match any configured attribution shape.
25
+
26
+ Why:
27
+ An AI attribution trailer or bot identity is a provenance leak that
28
+ survives squash and rebase; only a scan of the whole history proves
29
+ its absence, and a shallow clone that hides history must not read as
30
+ clean.
31
+
32
+ Proven in:
33
+ agent-runner/tests/invariants/test_no_ai_signatures.py
34
+
35
+ Not this:
36
+ Not a judgment on who or what wrote the code. Only fixed attribution
37
+ SHAPES are rejected; authorship, naming, and content are untouched.
38
+ """
39
+
40
+ id = "no-ai-signatures"
41
+ tier = "A"
42
+ kind = "gate"
43
+ scope = "global"
44
+ proven_in = ("agent-runner/tests/invariants/test_no_ai_signatures.py",)
45
+ confidence = "breadth"
46
+ tolerates_unparseable = False
47
+
48
+ def __init__(self, patterns=(
49
+ r"Co-Authored-By:",
50
+ r"Generated with",
51
+ r"Assisted by",
52
+ "\N{ROBOT FACE}",
53
+ r"[\w.+-]+@users\.noreply\.[\w.]+",
54
+ ), min_surface=1):
55
+ if min_surface < 1:
56
+ raise ValueError("min_surface must be >= 1")
57
+ self.patterns = tuple(patterns)
58
+ self.min_surface = min_surface
59
+
60
+ def _state(self, findings, examined_n):
61
+ if findings:
62
+ return State.FAIL
63
+ if examined_n < self.min_surface:
64
+ return State.VACUOUS
65
+ return State.PASS
66
+
67
+ def _is_shallow(self, ws):
68
+ proc = ws.run(["git", "rev-parse", "--is-shallow-repository"])
69
+ return proc.stdout.strip() == "true"
70
+
71
+ def check(self, ws):
72
+ findings = []
73
+ examined_n = 0
74
+ if not self._is_shallow(ws):
75
+ raw = ws.git_log(
76
+ rng=None,
77
+ fmt="%H%x00%an%x00%ae%x00%cn%x00%ce%x00%B%x00",
78
+ )
79
+ fields = raw.split("\x00")
80
+ for i in range(0, len(fields) - 5, 6):
81
+ sha = fields[i].strip()
82
+ an, ae, cn, ce, body = fields[i + 1:i + 6]
83
+ examined_n += 1
84
+ haystack = "\n".join([an, ae, cn, ce, body])
85
+ for pattern in self.patterns:
86
+ # IGNORECASE so GitHub's canonical `Co-authored-by:` casing
87
+ # (and `generated with` / `assisted by`) is caught too
88
+ # (resolves Fable finding: default missed lowercase trailers).
89
+ if re.search(pattern, haystack, re.IGNORECASE):
90
+ anchor = f"{sha[:9]}:{pattern}"
91
+ findings.append(
92
+ Finding(self.id, "<commit>", anchor,
93
+ message=f"provenance leak {anchor}")
94
+ )
95
+ return Result(
96
+ self.id, self._state(findings, examined_n),
97
+ examined_n=examined_n, skipped_n=ws.skipped_n,
98
+ unparseable_n=0, findings=findings,
99
+ )
100
+
101
+ def plants(self, ws):
102
+ sha = "0f1e2d3c4b5a6978"
103
+ bot = "".join(["c", "l", "a", "u", "d", "e"]) # vendor token, never typed whole
104
+ body = f"feat: thing\n\nCo-Authored-By: {bot} <{bot}-bot@example.test>\n"
105
+ planted = FakeWorkspace(
106
+ files={"ok.py": "x = 1\n"},
107
+ run_table={("git", "rev-parse", "--is-shallow-repository"):
108
+ CompletedProcess([], 0, stdout="false\n")},
109
+ git_log_text=_log_text([(sha, "Dev", "dev@example.test",
110
+ "Dev", "dev@example.test", body)]),
111
+ )
112
+ yield Plant(
113
+ label="commit:co-authored-by",
114
+ planted_ws=planted, # type: ignore[arg-type]
115
+ expected=(self.id, "<commit>", f"{sha[:9]}:Co-Authored-By:"),
116
+ )
117
+
118
+ def fixture(self, kit):
119
+ return FakeWorkspace(
120
+ files={"clean.py": "x = 1\n"},
121
+ run_table={("git", "rev-parse", "--is-shallow-repository"):
122
+ CompletedProcess([], 0, stdout="false\n")},
123
+ git_log_text=_log_text([("feedface12345678", "Dev", "dev@example.test",
124
+ "Dev", "dev@example.test", "feat: initial\n")]),
125
+ )
@@ -0,0 +1,108 @@
1
+ """BDD test-naming check."""
2
+ from __future__ import annotations
3
+
4
+ import ast
5
+
6
+ from ratch.check import Plant
7
+ from ratch.checks import is_test_py
8
+ from ratch.result import Finding, Result, State
9
+ from ratch.testing import FakeWorkspace
10
+
11
+
12
+ def _is_bdd_name(name):
13
+ if name.startswith("test_"):
14
+ return False
15
+ if "_should_" not in name or "_when_" not in name:
16
+ return False
17
+ return "or" not in name.split("_")
18
+
19
+
20
+ class BddTestConventions:
21
+ """Require BDD test names in tracked test modules.
22
+
23
+ Rule:
24
+ In tracked tests/*.py, every top-level def whose name does not
25
+ start with underscore must contain _should_ and _when_, must not
26
+ start with test_, and must not use or as a snake_case segment.
27
+
28
+ Why:
29
+ A test name that reads as a sentence is the readable spec; a
30
+ machine can prove the shape so pytest collection and review
31
+ share one convention.
32
+
33
+ Proven in:
34
+ internal/pillar-1-teeth.md
35
+
36
+ Not this:
37
+ Not a requirement on private helpers. Not a ban on tokens that
38
+ merely contain the letters o-r (error, format). Not a change to
39
+ pytest python_functions.
40
+ """
41
+
42
+ id = "bdd-test-conventions"
43
+ tier = "A"
44
+ kind = "gate"
45
+ scope = "global"
46
+ proven_in = ("internal/pillar-1-teeth.md",)
47
+ confidence = "inferred"
48
+ tolerates_unparseable = False
49
+
50
+ def __init__(self, min_surface=1):
51
+ if min_surface < 1:
52
+ raise ValueError("min_surface must be >= 1")
53
+ self.min_surface = min_surface
54
+
55
+ def _state(self, findings, examined_n):
56
+ if findings:
57
+ return State.FAIL
58
+ if examined_n < self.min_surface:
59
+ return State.VACUOUS
60
+ return State.PASS
61
+
62
+ def check(self, ws):
63
+ findings = []
64
+ examined_n = 0
65
+ for path in ws.tracked_files():
66
+ if not is_test_py(path):
67
+ continue
68
+ examined_n += 1
69
+ tree = ws.ast(path)
70
+ if tree is None:
71
+ continue
72
+ for node in tree.body:
73
+ if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
74
+ continue
75
+ name = node.name
76
+ if name.startswith("_"):
77
+ continue
78
+ if not _is_bdd_name(name):
79
+ findings.append(
80
+ Finding(self.id, path, name,
81
+ message=f"bdd name: {name}")
82
+ )
83
+ return Result(
84
+ self.id, self._state(findings, examined_n),
85
+ examined_n=examined_n, skipped_n=ws.skipped_n,
86
+ unparseable_n=ws.unparseable_n, findings=findings,
87
+ )
88
+
89
+ def plants(self, ws):
90
+ yield Plant(
91
+ label="test-prefix",
92
+ planted_ws=FakeWorkspace(
93
+ files={"tests/t.py": "def test_foo():\n pass\n"}
94
+ ),
95
+ expected=(self.id, "tests/t.py", "test_foo"),
96
+ )
97
+ yield Plant(
98
+ label="or-segment",
99
+ planted_ws=FakeWorkspace(
100
+ files={"tests/t.py": "def foo_should_pass_or_fail_when_x():\n pass\n"}
101
+ ),
102
+ expected=(self.id, "tests/t.py", "foo_should_pass_or_fail_when_x"),
103
+ )
104
+
105
+ def fixture(self, kit):
106
+ return FakeWorkspace(
107
+ files={"tests/t.py": "def foo_should_bar_when_baz():\n pass\n"}
108
+ )
@@ -0,0 +1,64 @@
1
+ """catalog-size eye."""
2
+ from ratch.check import Plant
3
+ from ratch.result import MeasuredValue, MState, Result, State
4
+ from ratch.testing import FakeWorkspace
5
+
6
+
7
+ class CatalogSize:
8
+ """Report how many checks are installed, without gating.
9
+
10
+ Rule:
11
+ The installed ratch.checks catalog size is reported as a
12
+ measured value.
13
+
14
+ Why:
15
+ A gate that failed the run because the catalog was empty would
16
+ confuse absence of plugins with a rule break; an eye only
17
+ measures.
18
+
19
+ Proven in:
20
+ internal/specs/2026-09-17-ratchet-v1-spine-design.md
21
+
22
+ Not this:
23
+ Not a gate. VACUOUS on an empty catalog does not fail the run.
24
+ """
25
+
26
+ id = "catalog-size"
27
+ tier = "A"
28
+ kind = "eye"
29
+ scope = "global"
30
+ proven_in = ("internal/specs/2026-09-17-ratchet-v1-spine-design.md",)
31
+ confidence = "inferred"
32
+ tolerates_unparseable = False
33
+
34
+ def __init__(self, min_surface=1):
35
+ if min_surface < 1:
36
+ raise ValueError("min_surface must be >= 1")
37
+ self.min_surface = min_surface
38
+
39
+ def check(self, ws):
40
+ n = len(ws.plugin_classes())
41
+ measured = MeasuredValue(
42
+ value=n, state=MState.MEASURED,
43
+ source="plugin_classes", measured_at=ws.now(),
44
+ )
45
+ if n < self.min_surface:
46
+ state = State.VACUOUS
47
+ else:
48
+ state = State.PASS
49
+ return Result(
50
+ self.id, state, examined_n=n, findings=[], measured=measured,
51
+ )
52
+
53
+ def plants(self, ws):
54
+ yield Plant(
55
+ label="empty-catalog",
56
+ planted_ws=FakeWorkspace(files={"a.py": "x = 1\n"}, plugin_classes={}),
57
+ expected=(self.id, "catalog", "0"),
58
+ )
59
+
60
+ def fixture(self, kit):
61
+ return FakeWorkspace(
62
+ files={"a.py": "x = 1\n"},
63
+ plugin_classes={"no-forbidden-literal": object},
64
+ )