codeveto 0.1.0__py3-none-any.whl
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.
- codeveto/__init__.py +3 -0
- codeveto/__main__.py +8 -0
- codeveto/ai/__init__.py +19 -0
- codeveto/ai/harness.py +303 -0
- codeveto/ai/packets.py +855 -0
- codeveto/ai/policy.py +222 -0
- codeveto/ai/prompt.py +101 -0
- codeveto/ai/providers/__init__.py +178 -0
- codeveto/ai/providers/claude.py +247 -0
- codeveto/ai/providers/openai_compat.py +246 -0
- codeveto/ai/runner.py +293 -0
- codeveto/ai/verify.py +324 -0
- codeveto/anchor.py +211 -0
- codeveto/cli.py +247 -0
- codeveto/cli_explain.py +49 -0
- codeveto/cli_hook.py +31 -0
- codeveto/cli_init.py +254 -0
- codeveto/cli_mcp.py +29 -0
- codeveto/cli_packets.py +35 -0
- codeveto/cli_publish.py +29 -0
- codeveto/cli_review.py +362 -0
- codeveto/cli_rules.py +78 -0
- codeveto/cli_verify.py +47 -0
- codeveto/config.py +1229 -0
- codeveto/data/README.md +16 -0
- codeveto/data/ai-wire.schema.json +53 -0
- codeveto/data/prompts/system.md +57 -0
- codeveto/data/report-v1.schema.json +268 -0
- codeveto/data/templates/forgejo-codeveto.yml +104 -0
- codeveto/data/templates/github-codeveto.yml +18 -0
- codeveto/embedded.py +311 -0
- codeveto/engine.py +1570 -0
- codeveto/git.py +1549 -0
- codeveto/globs.py +348 -0
- codeveto/integrations/__init__.py +1 -0
- codeveto/integrations/hooks.py +327 -0
- codeveto/integrations/mcp.py +770 -0
- codeveto/integrations/mcp_ai.py +77 -0
- codeveto/integrations/prepush.py +222 -0
- codeveto/jsonsafe.py +60 -0
- codeveto/languages.py +539 -0
- codeveto/lexers.py +2560 -0
- codeveto/model.py +372 -0
- codeveto/publish/__init__.py +28 -0
- codeveto/publish/action.py +330 -0
- codeveto/publish/common.py +84 -0
- codeveto/publish/diff.py +208 -0
- codeveto/publish/event.py +241 -0
- codeveto/publish/forgejo.py +184 -0
- codeveto/publish/github.py +380 -0
- codeveto/publish/http.py +263 -0
- codeveto/publish/pull.py +218 -0
- codeveto/publish/untrusted.py +110 -0
- codeveto/py.typed +0 -0
- codeveto/redact.py +113 -0
- codeveto/render/__init__.py +64 -0
- codeveto/render/agent.py +43 -0
- codeveto/render/github.py +101 -0
- codeveto/render/json.py +23 -0
- codeveto/render/markdown.py +208 -0
- codeveto/render/safe.py +249 -0
- codeveto/render/sarif.py +217 -0
- codeveto/render/text.py +210 -0
- codeveto/report.py +252 -0
- codeveto/rules/__init__.py +84 -0
- codeveto/rules/agent.py +2972 -0
- codeveto/rules/base.py +1026 -0
- codeveto/rules/ci.py +1708 -0
- codeveto/rules/config.py +493 -0
- codeveto/rules/deps.py +1693 -0
- codeveto/rules/docker.py +479 -0
- codeveto/rules/examples/__init__.py +148 -0
- codeveto/rules/examples/agent.py +839 -0
- codeveto/rules/examples/ci.py +1046 -0
- codeveto/rules/examples/config.py +191 -0
- codeveto/rules/examples/deps.py +369 -0
- codeveto/rules/examples/docker.py +157 -0
- codeveto/rules/examples/go.py +241 -0
- codeveto/rules/examples/hygiene.py +466 -0
- codeveto/rules/examples/js.py +462 -0
- codeveto/rules/examples/python.py +595 -0
- codeveto/rules/examples/rust.py +268 -0
- codeveto/rules/examples/secrets.py +561 -0
- codeveto/rules/examples/security.py +608 -0
- codeveto/rules/examples/shell.py +174 -0
- codeveto/rules/examples/sql.py +194 -0
- codeveto/rules/examples/tests.py +497 -0
- codeveto/rules/go.py +328 -0
- codeveto/rules/hygiene.py +1094 -0
- codeveto/rules/js.py +768 -0
- codeveto/rules/python.py +1642 -0
- codeveto/rules/rust.py +209 -0
- codeveto/rules/secrets.py +1335 -0
- codeveto/rules/security.py +3680 -0
- codeveto/rules/shell.py +867 -0
- codeveto/rules/sql.py +629 -0
- codeveto/rules/tests.py +1404 -0
- codeveto/schema.py +384 -0
- codeveto/statements.py +607 -0
- codeveto/worktree.py +1176 -0
- codeveto/yamlish.py +1179 -0
- codeveto-0.1.0.dist-info/METADATA +253 -0
- codeveto-0.1.0.dist-info/RECORD +106 -0
- codeveto-0.1.0.dist-info/WHEEL +4 -0
- codeveto-0.1.0.dist-info/entry_points.txt +2 -0
- codeveto-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"""Examples for the tests pack."""
|
|
2
|
+
|
|
3
|
+
from codeveto.rules.base import Change, Example, bad, good
|
|
4
|
+
|
|
5
|
+
_CART_TEST_OLD = (
|
|
6
|
+
"describe('cart', () => {\n"
|
|
7
|
+
" it('adds items', () => {\n"
|
|
8
|
+
" expect(add(1, 2)).toBe(3);\n"
|
|
9
|
+
" });\n"
|
|
10
|
+
"});\n"
|
|
11
|
+
)
|
|
12
|
+
_GO_TEST_OLD = (
|
|
13
|
+
'package store\n\nimport "testing"\n\n'
|
|
14
|
+
"func TestPut(t *testing.T) {\n"
|
|
15
|
+
"\tif err := Put(1); err != nil {\n"
|
|
16
|
+
"\t\tt.Fatal(err)\n"
|
|
17
|
+
"\t}\n"
|
|
18
|
+
"}\n"
|
|
19
|
+
)
|
|
20
|
+
_TAX_TEST = (
|
|
21
|
+
"from shop.tax import vat\n\n\n"
|
|
22
|
+
"def test_vat_rounds():\n assert vat(10) == 2.0\n\n\n"
|
|
23
|
+
"def test_vat_zero():\n assert vat(0) == 0\n"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
EXAMPLES = {
|
|
27
|
+
"tests/focused-test": [
|
|
28
|
+
bad(
|
|
29
|
+
"web/src/cart.test.ts",
|
|
30
|
+
"describe('cart', () => {\n"
|
|
31
|
+
" it.only('adds items', () => { // expect\n"
|
|
32
|
+
" expect(add(1, 2)).toBe(3);\n"
|
|
33
|
+
" });\n"
|
|
34
|
+
"});\n",
|
|
35
|
+
old=_CART_TEST_OLD,
|
|
36
|
+
note="A .only left in after debugging: CI runs this one test of the file.",
|
|
37
|
+
),
|
|
38
|
+
bad(
|
|
39
|
+
"e2e/login.spec.ts",
|
|
40
|
+
"test.describe.only('login', () => { // expect\n"
|
|
41
|
+
" test('accepts a valid password', async ({ page }) => {\n"
|
|
42
|
+
" await page.goto('/login');\n"
|
|
43
|
+
" });\n"
|
|
44
|
+
"});\n",
|
|
45
|
+
note="Playwright's test.describe.only.",
|
|
46
|
+
),
|
|
47
|
+
bad(
|
|
48
|
+
"spec/math.spec.js",
|
|
49
|
+
"fdescribe('math', () => { // expect\n"
|
|
50
|
+
" it('adds', () => expect(1 + 1).toBe(2));\n"
|
|
51
|
+
"});\n",
|
|
52
|
+
note="Jasmine's f-prefixed focus.",
|
|
53
|
+
),
|
|
54
|
+
bad(
|
|
55
|
+
"tests/test_api.py",
|
|
56
|
+
"import pytest\n\n\n"
|
|
57
|
+
"@pytest.mark.focus # expect\n"
|
|
58
|
+
"def test_health(client):\n"
|
|
59
|
+
' assert client.get("/health").status_code == 200\n',
|
|
60
|
+
note="Focus plugins for pytest use a marker.",
|
|
61
|
+
),
|
|
62
|
+
good(
|
|
63
|
+
"web/src/cart.test.ts",
|
|
64
|
+
"describe('cart', () => {\n"
|
|
65
|
+
" // use it.only('...') locally to debug one case\n"
|
|
66
|
+
" it('fits the curve', () => {\n"
|
|
67
|
+
" const curve = model.fit(points);\n"
|
|
68
|
+
" expect(fit(points)).toEqual(curve);\n"
|
|
69
|
+
" });\n"
|
|
70
|
+
"});\n",
|
|
71
|
+
old=_CART_TEST_OLD,
|
|
72
|
+
note="Comments, model.fit and a helper named fit without a title are not focus.",
|
|
73
|
+
),
|
|
74
|
+
good(
|
|
75
|
+
"src/testing/runner.ts",
|
|
76
|
+
"export const it = { only: (name: string) => name };\n"
|
|
77
|
+
"export const registered = it.only('smoke');\n",
|
|
78
|
+
note="A source file that defines such names is not a test file.",
|
|
79
|
+
),
|
|
80
|
+
],
|
|
81
|
+
"tests/skipped-test": [
|
|
82
|
+
bad(
|
|
83
|
+
"web/src/cart.test.ts",
|
|
84
|
+
"describe('cart', () => {\n"
|
|
85
|
+
" it.skip('adds items', () => { // expect\n"
|
|
86
|
+
" expect(add(1, 2)).toBe(3);\n"
|
|
87
|
+
" });\n"
|
|
88
|
+
"});\n",
|
|
89
|
+
old=_CART_TEST_OLD,
|
|
90
|
+
),
|
|
91
|
+
bad(
|
|
92
|
+
"tests/test_sync.py",
|
|
93
|
+
"import pytest\n\n\n"
|
|
94
|
+
'@pytest.mark.skip(reason="flaky on CI") # expect\n'
|
|
95
|
+
"def test_sync():\n"
|
|
96
|
+
" assert sync() == 3\n",
|
|
97
|
+
old="def test_sync():\n assert sync() == 3\n",
|
|
98
|
+
),
|
|
99
|
+
bad(
|
|
100
|
+
"internal/store/store_test.go",
|
|
101
|
+
'package store\n\nimport "testing"\n\n'
|
|
102
|
+
"func TestPut(t *testing.T) {\n"
|
|
103
|
+
'\tt.Skip("flaky on CI") // expect\n'
|
|
104
|
+
"\tif err := Put(1); err != nil {\n"
|
|
105
|
+
"\t\tt.Fatal(err)\n"
|
|
106
|
+
"\t}\n"
|
|
107
|
+
"}\n",
|
|
108
|
+
old=_GO_TEST_OLD,
|
|
109
|
+
note="A Go skip with no condition around it.",
|
|
110
|
+
),
|
|
111
|
+
bad(
|
|
112
|
+
"tests/upload.rs",
|
|
113
|
+
"#[test]\n#[ignore] // expect\nfn uploads_large_files() {\n"
|
|
114
|
+
" assert_eq!(upload(1 << 20), Ok(()));\n}\n",
|
|
115
|
+
),
|
|
116
|
+
good(
|
|
117
|
+
"e2e/clipboard.spec.ts",
|
|
118
|
+
"test('copies the link', async ({ page, browserName }) => {\n"
|
|
119
|
+
" test.skip(browserName === 'webkit', 'no clipboard API in WebKit');\n"
|
|
120
|
+
" await page.click('#copy');\n"
|
|
121
|
+
"});\n",
|
|
122
|
+
note="Playwright's conditional skip states when and why.",
|
|
123
|
+
),
|
|
124
|
+
good(
|
|
125
|
+
"tests/test_paths.py",
|
|
126
|
+
"import sys\n\nimport pytest\n\n\n"
|
|
127
|
+
'@pytest.mark.skipif(sys.platform == "win32", reason="POSIX paths")\n'
|
|
128
|
+
"def test_posix_paths():\n"
|
|
129
|
+
' assert normalize("a//b") == "a/b"\n\n\n'
|
|
130
|
+
"def test_network(online):\n"
|
|
131
|
+
" if not online:\n"
|
|
132
|
+
' pytest.skip("needs network")\n'
|
|
133
|
+
' assert fetch("/") == 200\n',
|
|
134
|
+
note="skipif with a real condition and pytest.skip behind an if.",
|
|
135
|
+
),
|
|
136
|
+
good(
|
|
137
|
+
"internal/store/store_test.go",
|
|
138
|
+
'package store\n\nimport "testing"\n\n'
|
|
139
|
+
"func TestPut(t *testing.T) {\n"
|
|
140
|
+
"\tif testing.Short() {\n"
|
|
141
|
+
'\t\tt.Skip("slow")\n'
|
|
142
|
+
"\t}\n"
|
|
143
|
+
"\tif err := Put(1); err != nil {\n"
|
|
144
|
+
"\t\tt.Fatal(err)\n"
|
|
145
|
+
"\t}\n"
|
|
146
|
+
"}\n",
|
|
147
|
+
old=_GO_TEST_OLD,
|
|
148
|
+
note="A Go skip under a condition.",
|
|
149
|
+
),
|
|
150
|
+
],
|
|
151
|
+
"tests/assertion-removed": [
|
|
152
|
+
bad(
|
|
153
|
+
"tests/test_cart.py",
|
|
154
|
+
"def test_total():\n assert total([1, 2]) == 3\n",
|
|
155
|
+
old="def test_total():\n"
|
|
156
|
+
" assert total([1, 2]) == 3\n"
|
|
157
|
+
" assert total([]) == 0 # expect\n",
|
|
158
|
+
note="Reported on the old side, at the removed assertion.",
|
|
159
|
+
),
|
|
160
|
+
bad(
|
|
161
|
+
"web/src/cart.test.ts",
|
|
162
|
+
"it('adds items', () => {\n const cart = add(1, 2);\n});\n",
|
|
163
|
+
old="it('adds items', () => {\n"
|
|
164
|
+
" const cart = add(1, 2);\n"
|
|
165
|
+
" expect(cart.total).toBe(3); // expect\n"
|
|
166
|
+
"});\n",
|
|
167
|
+
note="The test still runs, but checks nothing.",
|
|
168
|
+
),
|
|
169
|
+
good(
|
|
170
|
+
"tests/test_cart.py",
|
|
171
|
+
"def test_total():\n assert total([1, 2]) == 3\n assert total([]) == 0.0\n",
|
|
172
|
+
old="def test_total():\n assert total([1, 2]) == 3\n assert total([]) == 0\n",
|
|
173
|
+
note="An assertion changed, none removed.",
|
|
174
|
+
),
|
|
175
|
+
good(
|
|
176
|
+
"tests/test_cart.py",
|
|
177
|
+
"def test_total():\n"
|
|
178
|
+
" assert_totals({(1, 2): 3, (): 0})\n\n\n"
|
|
179
|
+
"def assert_totals(cases):\n"
|
|
180
|
+
" for items, expected in cases.items():\n"
|
|
181
|
+
" assert total(list(items)) == expected\n",
|
|
182
|
+
old="def test_total():\n assert total([1, 2]) == 3\n assert total([]) == 0\n",
|
|
183
|
+
note="Assertions moved into a helper keep their count.",
|
|
184
|
+
),
|
|
185
|
+
],
|
|
186
|
+
"tests/tautological-assertion": [
|
|
187
|
+
bad(
|
|
188
|
+
"tests/test_orders.py",
|
|
189
|
+
"def test_order_total():\n"
|
|
190
|
+
" order = make_order()\n"
|
|
191
|
+
" assert order.total == order.total # expect\n"
|
|
192
|
+
" assert True # expect\n",
|
|
193
|
+
),
|
|
194
|
+
bad(
|
|
195
|
+
"web/src/cart.test.ts",
|
|
196
|
+
"it('adds items', () => {\n expect(true).toBe(true); // expect\n});\n",
|
|
197
|
+
),
|
|
198
|
+
bad(
|
|
199
|
+
"src/test/java/com/example/OrderTest.java",
|
|
200
|
+
"class OrderTest {\n"
|
|
201
|
+
" @Test\n"
|
|
202
|
+
" void total() {\n"
|
|
203
|
+
" long expected = 3;\n"
|
|
204
|
+
" assertEquals(expected, expected); // expect\n"
|
|
205
|
+
" }\n"
|
|
206
|
+
"}\n",
|
|
207
|
+
),
|
|
208
|
+
bad(
|
|
209
|
+
"tests/test_orders.py",
|
|
210
|
+
'def test_order_total():\n assert (make_order().total == 3, "total") # expect\n',
|
|
211
|
+
note="A parenthesized assert with a message is a tuple, which is always true.",
|
|
212
|
+
),
|
|
213
|
+
good(
|
|
214
|
+
"tests/test_orders.py",
|
|
215
|
+
"def test_ids_are_stable():\n"
|
|
216
|
+
" assert order_id(1) == order_id(1)\n"
|
|
217
|
+
" assert make_order().total == 3\n",
|
|
218
|
+
note="Operands with calls may test determinism.",
|
|
219
|
+
),
|
|
220
|
+
good(
|
|
221
|
+
"web/src/cart.test.ts",
|
|
222
|
+
"it('adds items', () => {\n"
|
|
223
|
+
" // expect(true).toBe(true) was a placeholder\n"
|
|
224
|
+
" expect(add(1, 2)).toBe(3);\n"
|
|
225
|
+
" expect(total).toBe(expected);\n"
|
|
226
|
+
"});\n",
|
|
227
|
+
),
|
|
228
|
+
],
|
|
229
|
+
"tests/test-deleted": [
|
|
230
|
+
Example(
|
|
231
|
+
kind="bad",
|
|
232
|
+
files={"tests/test_tax.py": Change(old=_TAX_TEST, new=None)},
|
|
233
|
+
expect=(("tests/test_tax.py", None, "new"),),
|
|
234
|
+
note="The tests go, the tax code stays.",
|
|
235
|
+
),
|
|
236
|
+
Example(
|
|
237
|
+
kind="bad",
|
|
238
|
+
files={
|
|
239
|
+
"tests/test_tax.py": Change(
|
|
240
|
+
old=_TAX_TEST,
|
|
241
|
+
new="from shop.tax import vat\n\n\n"
|
|
242
|
+
"def test_vat_rounds():\n assert vat(10) == 2.0\n",
|
|
243
|
+
)
|
|
244
|
+
},
|
|
245
|
+
expect=(("tests/test_tax.py", 8, "old"),),
|
|
246
|
+
note="Reported at the removed test on the old side.",
|
|
247
|
+
),
|
|
248
|
+
Example(
|
|
249
|
+
kind="good",
|
|
250
|
+
files={
|
|
251
|
+
"tests/test_tax.py": Change(old=_TAX_TEST, new=None),
|
|
252
|
+
"src/shop/tax.py": Change(old="def vat(amount):\n return amount * 0.2\n"),
|
|
253
|
+
},
|
|
254
|
+
note="The tested module is deleted in the same change.",
|
|
255
|
+
),
|
|
256
|
+
Example(
|
|
257
|
+
kind="good",
|
|
258
|
+
files={
|
|
259
|
+
"tests/test_tax.py": Change(
|
|
260
|
+
old=_TAX_TEST,
|
|
261
|
+
new="from shop.tax import vat\n\n\n"
|
|
262
|
+
"def test_vat_rounds():\n assert vat(10) == 2.0\n",
|
|
263
|
+
),
|
|
264
|
+
"tests/test_tax_edges.py": Change(
|
|
265
|
+
new="from shop.tax import vat\n\n\n"
|
|
266
|
+
"def test_vat_zero():\n assert vat(0) == 0\n"
|
|
267
|
+
),
|
|
268
|
+
},
|
|
269
|
+
note="A test moved to another file is not deleted.",
|
|
270
|
+
),
|
|
271
|
+
Example(
|
|
272
|
+
kind="good",
|
|
273
|
+
files={
|
|
274
|
+
"tests/unit/test_tax.py": Change(
|
|
275
|
+
old=_TAX_TEST, new=_TAX_TEST, old_path="tests/test_tax.py"
|
|
276
|
+
)
|
|
277
|
+
},
|
|
278
|
+
note="A renamed test file is not a deletion.",
|
|
279
|
+
),
|
|
280
|
+
],
|
|
281
|
+
"tests/test-env-branch": [
|
|
282
|
+
bad(
|
|
283
|
+
"src/app/db.py",
|
|
284
|
+
"import sys\n\n"
|
|
285
|
+
'if "pytest" in sys.modules: # expect\n'
|
|
286
|
+
' DATABASE_URL = "sqlite://"\n'
|
|
287
|
+
"else:\n"
|
|
288
|
+
' DATABASE_URL = "postgresql://db/app"\n',
|
|
289
|
+
),
|
|
290
|
+
bad(
|
|
291
|
+
"src/lib/mailer.ts",
|
|
292
|
+
"export function send(message: Message): void {\n"
|
|
293
|
+
" if (process.env.NODE_ENV === 'test') { // expect\n"
|
|
294
|
+
" return;\n"
|
|
295
|
+
" }\n"
|
|
296
|
+
" transport.send(message);\n"
|
|
297
|
+
"}\n",
|
|
298
|
+
note="Tests never exercise the real send path.",
|
|
299
|
+
),
|
|
300
|
+
good(
|
|
301
|
+
"babel.config.js",
|
|
302
|
+
"module.exports = {\n"
|
|
303
|
+
" presets: process.env.NODE_ENV === 'test' ? ['@babel/preset-env'] : [],\n"
|
|
304
|
+
"};\n",
|
|
305
|
+
note="Tool configs branch on the test environment by design.",
|
|
306
|
+
),
|
|
307
|
+
good(
|
|
308
|
+
"src/app/settings.py",
|
|
309
|
+
"import os\n\n"
|
|
310
|
+
"# Tests set APP_ENV instead of checking PYTEST_CURRENT_TEST here.\n"
|
|
311
|
+
'APP_ENV = os.environ.get("APP_ENV", "production")\n',
|
|
312
|
+
note="Mentions in comments and an injected setting are fine.",
|
|
313
|
+
),
|
|
314
|
+
],
|
|
315
|
+
"tests/coverage-threshold-lowered": [
|
|
316
|
+
bad(
|
|
317
|
+
"pyproject.toml",
|
|
318
|
+
"[tool.coverage.report]\nfail_under = 85 # expect\nshow_missing = true\n",
|
|
319
|
+
old="[tool.coverage.report]\nfail_under = 90\nshow_missing = true\n",
|
|
320
|
+
),
|
|
321
|
+
bad(
|
|
322
|
+
"package.json",
|
|
323
|
+
'{\n "name": "shop",\n "jest": {\n "coverageThreshold": {\n'
|
|
324
|
+
' "global": {\n "lines": 80 // expect\n }\n }\n }\n}\n',
|
|
325
|
+
old='{\n "name": "shop",\n "jest": {\n "coverageThreshold": {\n'
|
|
326
|
+
' "global": {\n "lines": 90\n }\n }\n }\n}\n',
|
|
327
|
+
),
|
|
328
|
+
bad(
|
|
329
|
+
".coveragerc",
|
|
330
|
+
"[run]\nbranch = True\n",
|
|
331
|
+
old="[run]\nbranch = True\n\n[report]\nfail_under = 90 # expect\n",
|
|
332
|
+
note="A removed threshold is reported at the old line.",
|
|
333
|
+
),
|
|
334
|
+
bad(
|
|
335
|
+
"codecov.yml",
|
|
336
|
+
"coverage:\n status:\n project:\n default:\n target: 70% # expect\n",
|
|
337
|
+
old="coverage:\n status:\n project:\n default:\n target: 80%\n",
|
|
338
|
+
),
|
|
339
|
+
good(
|
|
340
|
+
"pyproject.toml",
|
|
341
|
+
"[tool.coverage.report]\nfail_under = 95\nshow_missing = true\n",
|
|
342
|
+
old="[tool.coverage.report]\nfail_under = 90\nshow_missing = true\n",
|
|
343
|
+
note="Raising the bar is fine.",
|
|
344
|
+
),
|
|
345
|
+
good(
|
|
346
|
+
"package.json",
|
|
347
|
+
'{\n "name": "shop",\n "version": "1.1.0",\n'
|
|
348
|
+
' "jest": { "coverageThreshold": { "global": { "lines": 90 } } }\n}\n',
|
|
349
|
+
old='{\n "name": "shop",\n "version": "1.0.0",\n "jest": {\n'
|
|
350
|
+
' "coverageThreshold": { "global": { "lines": 90 } }\n }\n}\n',
|
|
351
|
+
note="Reformatting keeps the value.",
|
|
352
|
+
),
|
|
353
|
+
],
|
|
354
|
+
"tests/sleep-in-test": [
|
|
355
|
+
bad(
|
|
356
|
+
"tests/test_worker.py",
|
|
357
|
+
"import time\n\n\n"
|
|
358
|
+
"def test_worker_finishes(worker):\n"
|
|
359
|
+
" worker.start()\n"
|
|
360
|
+
" time.sleep(2) # expect\n"
|
|
361
|
+
" assert worker.done\n",
|
|
362
|
+
),
|
|
363
|
+
bad(
|
|
364
|
+
"internal/queue/queue_test.go",
|
|
365
|
+
'package queue\n\nimport (\n\t"testing"\n\t"time"\n)\n\n'
|
|
366
|
+
"func TestDrain(t *testing.T) {\n"
|
|
367
|
+
"\tq := New()\n"
|
|
368
|
+
"\ttime.Sleep(100 * time.Millisecond) // expect\n"
|
|
369
|
+
"\tif q.Len() != 0 {\n\t\tt.Fatal(q.Len())\n\t}\n"
|
|
370
|
+
"}\n",
|
|
371
|
+
),
|
|
372
|
+
bad(
|
|
373
|
+
"web/src/poll.test.ts",
|
|
374
|
+
"it('polls', async () => {\n"
|
|
375
|
+
" await new Promise((resolve) => setTimeout(resolve, 500)); // expect\n"
|
|
376
|
+
" expect(calls).toBe(1);\n"
|
|
377
|
+
"});\n",
|
|
378
|
+
),
|
|
379
|
+
good(
|
|
380
|
+
"tests/test_worker.py",
|
|
381
|
+
"import asyncio\n\n\n"
|
|
382
|
+
"async def test_worker_yields(worker):\n"
|
|
383
|
+
" await asyncio.sleep(0)\n"
|
|
384
|
+
" assert worker.started\n",
|
|
385
|
+
note="sleep(0) only yields to the event loop.",
|
|
386
|
+
),
|
|
387
|
+
good(
|
|
388
|
+
"src/app/retry.py",
|
|
389
|
+
"import time\n\n\n"
|
|
390
|
+
"def retry(call, attempts=3):\n"
|
|
391
|
+
" for n in range(attempts):\n"
|
|
392
|
+
" try:\n"
|
|
393
|
+
" return call()\n"
|
|
394
|
+
" except TimeoutError:\n"
|
|
395
|
+
" time.sleep(2**n)\n"
|
|
396
|
+
" return call()\n",
|
|
397
|
+
note="Back-off in production code is not a test sleep.",
|
|
398
|
+
),
|
|
399
|
+
],
|
|
400
|
+
"tests/untested-change": [
|
|
401
|
+
Example(
|
|
402
|
+
kind="bad",
|
|
403
|
+
files={
|
|
404
|
+
"src/shop/cart.py": Change(
|
|
405
|
+
old="def total(items):\n return sum(items)\n",
|
|
406
|
+
new="def total(items):\n return round(sum(items), 2)\n",
|
|
407
|
+
),
|
|
408
|
+
"CHANGELOG.md": Change(old="# Changes\n", new="# Changes\n\n- Round totals.\n"),
|
|
409
|
+
},
|
|
410
|
+
expect=(("src/shop/cart.py", 2, "new"),),
|
|
411
|
+
note="Behaviour changed; only the changelog came with it.",
|
|
412
|
+
),
|
|
413
|
+
Example(
|
|
414
|
+
kind="bad",
|
|
415
|
+
files={
|
|
416
|
+
"internal/rate/limit.go": Change(
|
|
417
|
+
new="package rate\n\nfunc Allow(n, max int) bool {\n\treturn n < max\n}\n"
|
|
418
|
+
),
|
|
419
|
+
"web/src/format.ts": Change(
|
|
420
|
+
new="export function money(cents: number): string {\n"
|
|
421
|
+
" return (cents / 100).toFixed(2);\n}\n"
|
|
422
|
+
),
|
|
423
|
+
},
|
|
424
|
+
expect=(("internal/rate/limit.go", 1, "new"),),
|
|
425
|
+
note="Reported once, at the first changed source file.",
|
|
426
|
+
),
|
|
427
|
+
Example(
|
|
428
|
+
kind="bad",
|
|
429
|
+
files={
|
|
430
|
+
"src/shop/cart.py": Change(
|
|
431
|
+
old="def total(items):\n return sum(items)\n",
|
|
432
|
+
new="def total(items):\n return round(sum(items), 2)\n",
|
|
433
|
+
),
|
|
434
|
+
"tests/test_cart.py": Change(
|
|
435
|
+
old="def test_total():\n assert total([1]) == 1\n", new=None
|
|
436
|
+
),
|
|
437
|
+
"tests/test_tax.py": Change(
|
|
438
|
+
old="def test_tax():\n assert tax(1) == 0.2\n",
|
|
439
|
+
new="def test_tax():\n assert tax(1) == 0.2 # rounded\n",
|
|
440
|
+
),
|
|
441
|
+
},
|
|
442
|
+
expect=(("src/shop/cart.py", 2, "new"),),
|
|
443
|
+
note="Deleting a test file and re-spacing a test line are not test changes.",
|
|
444
|
+
),
|
|
445
|
+
Example(
|
|
446
|
+
kind="good",
|
|
447
|
+
files={
|
|
448
|
+
"src/shop/cart.py": Change(
|
|
449
|
+
old="def total(items):\n return sum(items)\n",
|
|
450
|
+
new="def total(items):\n return round(sum(items), 2)\n",
|
|
451
|
+
),
|
|
452
|
+
"tests/test_cart.py": Change(
|
|
453
|
+
old="from shop.cart import total\n",
|
|
454
|
+
new="from shop.cart import total\n\n\n"
|
|
455
|
+
"def test_total_rounds():\n assert total([0.1, 0.2]) == 0.3\n",
|
|
456
|
+
),
|
|
457
|
+
},
|
|
458
|
+
),
|
|
459
|
+
Example(
|
|
460
|
+
kind="good",
|
|
461
|
+
files={
|
|
462
|
+
"src/shop/cart.py": Change(
|
|
463
|
+
old='def total(items):\n """Sum."""\n return sum(items)\n',
|
|
464
|
+
new="def total(items):\n"
|
|
465
|
+
' """Sum the item prices."""\n'
|
|
466
|
+
" # Prices are already rounded by the catalogue.\n"
|
|
467
|
+
" return sum(items)\n",
|
|
468
|
+
),
|
|
469
|
+
},
|
|
470
|
+
note="Comment and docstring edits change no code.",
|
|
471
|
+
),
|
|
472
|
+
Example(
|
|
473
|
+
kind="good",
|
|
474
|
+
files={
|
|
475
|
+
"src/lib.rs": Change(
|
|
476
|
+
old="pub fn double(x: i32) -> i32 {\n x * 2\n}\n\n"
|
|
477
|
+
"#[cfg(test)]\nmod tests {\n use super::*;\n}\n",
|
|
478
|
+
new="pub fn double(x: i32) -> i32 {\n x * 2\n}\n\n"
|
|
479
|
+
"pub fn triple(x: i32) -> i32 {\n x * 3\n}\n\n"
|
|
480
|
+
"#[cfg(test)]\nmod tests {\n use super::*;\n\n"
|
|
481
|
+
" #[test]\n fn triples() {\n assert_eq!(triple(2), 6);\n }\n}\n",
|
|
482
|
+
),
|
|
483
|
+
},
|
|
484
|
+
note="A change inside an in-file test region is a test change.",
|
|
485
|
+
),
|
|
486
|
+
Example(
|
|
487
|
+
kind="good",
|
|
488
|
+
files={
|
|
489
|
+
"scripts/deploy.sh": Change(
|
|
490
|
+
old='#!/bin/sh\nset -eu\necho "deploying"\n',
|
|
491
|
+
new='#!/bin/sh\nset -eu\necho "deploying to ${TARGET:-staging}"\n',
|
|
492
|
+
),
|
|
493
|
+
},
|
|
494
|
+
note="Shell scripts are not expected to come with unit tests.",
|
|
495
|
+
),
|
|
496
|
+
],
|
|
497
|
+
}
|