@sentry/warden 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +441 -0
- package/README.md +2 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +6 -5
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +9 -4
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -1
- package/dist/cli/help.js.map +1 -1
- package/dist/sdk/verify.d.ts.map +1 -1
- package/dist/sdk/verify.js +6 -10
- package/dist/sdk/verify.js.map +1 -1
- package/package.json +1 -1
- package/src/builtin-skills/code-review/SKILL.md +85 -0
- package/src/builtin-skills/code-review/SOURCES.md +42 -0
- package/src/builtin-skills/code-review/SPEC.md +110 -0
- package/src/builtin-skills/code-review/references/github-workflows.md +88 -0
- package/src/builtin-skills/code-review/references/javascript-typescript.md +73 -0
- package/src/builtin-skills/code-review/references/python.md +77 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Python Bug Review Notes
|
|
2
|
+
|
|
3
|
+
Use this when reviewing Python, Django, Flask, FastAPI, Celery, or Python service code. These notes refine the core `code-review` skill; they do not add style, architecture, security, or performance-only scope.
|
|
4
|
+
|
|
5
|
+
## Runtime Boundaries
|
|
6
|
+
|
|
7
|
+
- Type hints are not runtime validation. Treat request data, query params, env vars, external API responses, database rows, task payloads, and deserialized files as shape-unknown until validated.
|
|
8
|
+
- Pydantic models, DRF serializers, dataclasses, typed dicts, Django model fields, migrations, and existing tests can prove the intended contract. Read them before reporting a mismatch.
|
|
9
|
+
- Decorators and framework hooks can change call order, transaction scope, auth context, and exception behavior. Verify the effective path.
|
|
10
|
+
- Background tasks and management commands often run outside request transactions and sessions. Check idempotency, tenant/account context, and retry behavior before reporting.
|
|
11
|
+
|
|
12
|
+
## High-Signal Patterns
|
|
13
|
+
|
|
14
|
+
| Pattern | Bug Shape | Safer Shape |
|
|
15
|
+
|---------|-----------|-------------|
|
|
16
|
+
| Mutable defaults | Function, dataclass, or model defaults reuse lists, dicts, sets, or objects across calls or instances. | Use `None` plus initialization, `default_factory`, or framework-specific callable defaults. |
|
|
17
|
+
| Falsey fallback | `value or default` treats `0`, `False`, or `""` as absent when those are valid values. | Check `is None`, missing keys, or explicit sentinel values. |
|
|
18
|
+
| Missing `None` handling | `.first()`, `.get()`, optional config, env values, cache reads, or external responses are dereferenced without proving presence. | Add explicit absence handling or enforce presence at the boundary. |
|
|
19
|
+
| Swallowed errors | Broad `except` returns success, empty data, or partial defaults that callers treat as complete. | Propagate failure, return explicit partial state, or compensate rolled-back work. |
|
|
20
|
+
| Transaction gaps | Multiple writes, task enqueues, cache updates, or file operations can partially succeed when a later step fails. | Use transactions, `on_commit`, idempotency keys, or compensation. |
|
|
21
|
+
| Async mismatch | Coroutine is not awaited, blocking I/O runs in an async endpoint, or async context managers are entered incorrectly. | Await coroutines, use async clients, and keep blocking work out of event-loop paths. |
|
|
22
|
+
| Iterator exhaustion | Generators, queryset iterators, request streams, or file objects are consumed once and then reused as if still populated. | Materialize intentionally or pass a fresh iterator/stream. |
|
|
23
|
+
| Timezone and precision | Naive and aware datetimes are mixed, date boundaries use server local time, or decimal money is converted to float. | Normalize timezone and use `Decimal` or integer minor units for money. |
|
|
24
|
+
| Query and migration drift | Renamed fields, changed defaults, non-null constraints, data migrations, or backfills miss existing rows or write wrong records. | Include backward-compatible migrations and scoped update filters. |
|
|
25
|
+
| Task retry side effects | Celery or queue retries duplicate emails, charges, state transitions, or external calls. | Make side effects idempotent or persist completion before retryable boundaries. |
|
|
26
|
+
|
|
27
|
+
## False-Positive Controls
|
|
28
|
+
|
|
29
|
+
- Django ORM, SQLAlchemy, and Pydantic can enforce contracts. Verify the exact model, serializer, or schema before reporting.
|
|
30
|
+
- `get_or_create`, `update_or_create`, database constraints, and transactions can mitigate duplicate or partial-write paths.
|
|
31
|
+
- A broad `except` is not a finding if the caller receives explicit failure state and no partial success is claimed.
|
|
32
|
+
- Mutable values are safe when created inside the function or supplied by a documented immutable factory.
|
|
33
|
+
- QuerySet laziness is not a bug by itself. Show the changed evaluation order that produces wrong data.
|
|
34
|
+
- Type-checker-only issues are findings only when they deterministically break runtime behavior, packaging, or CI.
|
|
35
|
+
|
|
36
|
+
## Minimal Examples
|
|
37
|
+
|
|
38
|
+
**Report: mutable default**
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
def collect_errors(error, bucket=[]):
|
|
42
|
+
bucket.append(error)
|
|
43
|
+
return bucket
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Every call shares the same list, so unrelated requests can see stale errors.
|
|
47
|
+
|
|
48
|
+
**Report: swallowed partial failure**
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
try:
|
|
52
|
+
charge_customer(invoice)
|
|
53
|
+
mark_paid(invoice)
|
|
54
|
+
except Exception:
|
|
55
|
+
return {"ok": True}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The caller receives success even if charging or persistence failed.
|
|
59
|
+
|
|
60
|
+
**Report: missing absence handling**
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
profile = Profile.objects.filter(user_id=user_id).first()
|
|
64
|
+
return profile.timezone
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
If profiles are optional or not yet created, this crashes instead of following the expected fallback.
|
|
68
|
+
|
|
69
|
+
**Do not report: dataclass default factory**
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
@dataclass
|
|
73
|
+
class Batch:
|
|
74
|
+
items: list[str] = field(default_factory=list)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Each instance receives a fresh list.
|