project-brain 0.22.4 → 0.24.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/README.md +1 -1
- package/package.json +6 -6
- package/templates/skills/brain-audit/SKILL.md +191 -8
- package/templates/skills/brain-audit/references/abuse.md +34 -24
- package/templates/skills/brain-audit/references/accessibility.md +41 -21
- package/templates/skills/brain-audit/references/ai.md +28 -18
- package/templates/skills/brain-audit/references/analytics.md +73 -0
- package/templates/skills/brain-audit/references/api.md +27 -17
- package/templates/skills/brain-audit/references/backend.md +24 -16
- package/templates/skills/brain-audit/references/complexity.md +30 -17
- package/templates/skills/brain-audit/references/concurrency.md +28 -19
- package/templates/skills/brain-audit/references/consistency.md +32 -24
- package/templates/skills/brain-audit/references/contract-drift.md +30 -19
- package/templates/skills/brain-audit/references/cost.md +35 -24
- package/templates/skills/brain-audit/references/cross-surface-parity.md +70 -0
- package/templates/skills/brain-audit/references/database.md +42 -24
- package/templates/skills/brain-audit/references/dependencies-licensing.md +34 -23
- package/templates/skills/brain-audit/references/design-system.md +99 -0
- package/templates/skills/brain-audit/references/devops.md +38 -24
- package/templates/skills/brain-audit/references/documentation.md +35 -23
- package/templates/skills/brain-audit/references/failure.md +33 -21
- package/templates/skills/brain-audit/references/feature-flags.md +87 -0
- package/templates/skills/brain-audit/references/flow-integrity.md +58 -33
- package/templates/skills/brain-audit/references/frontend.md +36 -19
- package/templates/skills/brain-audit/references/functional.md +38 -17
- package/templates/skills/brain-audit/references/future.md +32 -12
- package/templates/skills/brain-audit/references/goal.md +19 -12
- package/templates/skills/brain-audit/references/i18n.md +37 -23
- package/templates/skills/brain-audit/references/idempotency.md +76 -0
- package/templates/skills/brain-audit/references/infrastructure.md +31 -22
- package/templates/skills/brain-audit/references/mobile.md +32 -23
- package/templates/skills/brain-audit/references/multi-tenancy.md +74 -0
- package/templates/skills/brain-audit/references/numeric.md +70 -0
- package/templates/skills/brain-audit/references/observability.md +36 -21
- package/templates/skills/brain-audit/references/packaging.md +27 -19
- package/templates/skills/brain-audit/references/performance.md +48 -21
- package/templates/skills/brain-audit/references/privacy.md +39 -25
- package/templates/skills/brain-audit/references/product.md +31 -12
- package/templates/skills/brain-audit/references/prompt-spec-gap.md +25 -18
- package/templates/skills/brain-audit/references/reachability.md +28 -20
- package/templates/skills/brain-audit/references/repo-history.md +65 -0
- package/templates/skills/brain-audit/references/runtime.md +83 -0
- package/templates/skills/brain-audit/references/scalability.md +35 -22
- package/templates/skills/brain-audit/references/security.md +50 -33
- package/templates/skills/brain-audit/references/state-model.md +73 -0
- package/templates/skills/brain-audit/references/supply-chain.md +64 -0
- package/templates/skills/brain-audit/references/temporal.md +66 -0
- package/templates/skills/brain-audit/references/testing.md +49 -24
- package/templates/skills/brain-audit/references/tooling-baseline.md +77 -0
- package/templates/skills/brain-audit/references/type-safety.md +68 -0
- package/templates/skills/brain-audit/references/versioning-compatibility.md +33 -22
- package/templates/skills/brain-audit/references/visual-design.md +89 -0
- package/templates/skills/brain-audit/references/web-metadata.md +72 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Product Analytics
|
|
2
|
+
|
|
3
|
+
Can this team tell whether the product works for the people using it? Gate: a user-facing product — an analytics SDK is present, **or conspicuously absent**.
|
|
4
|
+
|
|
5
|
+
`observability.md` owns operational telemetry: logs, metrics, traces, alerts — the signals that tell the people running the system whether it is up and fast. This module owns a different audience entirely: product instrumentation, the signals that tell the team whether the product is actually working *for its users* — which flows complete, which fail, and where people give up. **Absence fires this gate rather than skipping it.** A user-facing product shipping with no instrumentation at all cannot distinguish success from failure by any means other than a support ticket, and that inability is the finding — report it once, at `High`, the same way `design-system.md` reports a missing token source, rather than as thirty separate missing events.
|
|
6
|
+
|
|
7
|
+
## Inventory
|
|
8
|
+
|
|
9
|
+
- [ ] `search_code` the analytics SDK import (Segment, Amplitude, Mixpanel, PostHog, GA4, RudderStack, or a custom `track()` wrapper) and enumerate every call site. This list is the yardstick every later check works against — nothing below means anything until this exists.
|
|
10
|
+
- [ ] For each `track(` call site found above, record where it fires (component, route, server handler) and what triggers it. An event fired from three different call sites for what is conceptually one user action is a red flag in its own right, addressed below.
|
|
11
|
+
- [ ] Server-side tracking calls, not only client SDK calls — `search_code` for a server-side analytics client or a webhook forwarding events. Distinguish these from the client inventory; they answer different reliability questions later in this module.
|
|
12
|
+
|
|
13
|
+
## Naming and shape
|
|
14
|
+
|
|
15
|
+
- [ ] Event naming convention — read a sample of event-name strings and determine which pattern the majority already follows (`snake_case` vs `Title Case`, object-action order such as `Product Viewed`/`plan_selected` vs a verb-first order), then flag the minority that breaks it. Do not import an external naming standard the project never adopted — Segment's and Amplitude's own object-action convention is the industry majority, not a rule to enforce over a project's existing, internally consistent choice.
|
|
16
|
+
- [ ] Action verbs are past tense, consistently — read the sample above for a mix of imperative (`Track Signup`) and past-tense (`Signup Completed`) forms within the same event set. An event fires after the action already happened; a present-tense minority alongside a past-tense majority is the same class of drift as inconsistent casing.
|
|
17
|
+
- [ ] The same conceptual event fired under two different names — `search_code` for near-duplicate strings (`signup_completed` and `user_registered` describing the same moment) and cross-reference the feature map from discovery to confirm they really are the same event before flagging.
|
|
18
|
+
- [ ] Events fired without the properties needed to answer the question they exist to answer — read the call site's property object against what the event's own name implies someone will ask (a `plan_selected` event with no plan identifier cannot answer "which plan"). **Falsify before flagging**: some SDKs auto-enrich events with context set at `identify()` or a wrapper — confirm the property is genuinely missing from the full payload, not just from this one call site.
|
|
19
|
+
- [ ] The same user action tracked twice from two independent call sites (a page-level listener and a component-level one both firing on one click) — `search_code` for the event name appearing at more than one site with overlapping trigger conditions, and confirm they are not deliberately distinct events sharing a name for different states.
|
|
20
|
+
|
|
21
|
+
## Tracking plan discipline
|
|
22
|
+
|
|
23
|
+
- [ ] Event and property names are fixed string literals, not built at runtime: `search_code` `track(` call sites whose first argument is a template literal, string concatenation, or a bare variable rather than a literal string. A dynamically generated event name cannot be validated against any schema and forks the taxonomy silently, one call at a time.
|
|
24
|
+
- [ ] A schema or generated client enforces the plan, not only a wiki page: `search_code` for a tracking-plan schema file (a JSON/YAML event catalogue, a codegen'd typed analytics client) or a CI step validating `track(` calls against it. Its absence is not itself a finding — most projects never adopt one — but if `README`/`CONTRIBUTING` claims a tracking plan exists, its absence from CI is worth surfacing as a gap between stated and actual practice.
|
|
25
|
+
|
|
26
|
+
## Funnel coverage
|
|
27
|
+
|
|
28
|
+
- [ ] For every flow `flow-integrity.md` traced, confirm its start, success, and failure are each instrumented — not only the happy path. `search_code` `track(` calls near the flow's entry point, its success branch, and its catch/error branch. **A funnel missing its failure event can only ever report success**, which makes the funnel's conversion number meaningless without anyone noticing, because nothing is technically broken.
|
|
29
|
+
- [ ] Empty states instrumented, not only populated ones — `search_code` `track(` calls inside a zero-result branch, an empty-list render, or an eligibility check that fails before the flow even starts. These are exactly the moments a team most needs visibility into and most often forgets to track, because nothing crashes.
|
|
30
|
+
- [ ] Error boundaries and caught exceptions fire a tracking event distinct from the success event — `search_code` `track(` calls inside `catch` blocks and error-boundary components, not merely a console log or an operational error report that never reaches product analytics.
|
|
31
|
+
|
|
32
|
+
## Sensitive data
|
|
33
|
+
|
|
34
|
+
- [ ] PII in event properties — cross-reference `privacy.md`; `search_code` `track(` call sites passing email, full name, phone, or any field that inventory identified as personal data.
|
|
35
|
+
- [ ] Free-text fields passed as event properties verbatim — `search_code` `track(` calls whose property object references a search-query, message, note, or comment field. These carry whatever the user typed, including data nobody designed the schema to hold.
|
|
36
|
+
- [ ] Full URLs captured as a property value — `search_code` `track(` calls passing `window.location.href` or a raw URL object — where the URL itself carries a session token or one-time link in its query string. The analytics platform then holds a credential it was never meant to receive.
|
|
37
|
+
|
|
38
|
+
## Consent and identity
|
|
39
|
+
|
|
40
|
+
- [ ] Consent gating — `search_code` for a consent-check utility wired before SDK initialisation or before the first `track()` call, in any jurisdiction where consent is required. The common real-world violation is ordering, not absence: a consent utility exists somewhere in the codebase, but the SDK init or script tag is reachable before it resolves — read the actual load order (script tag position, import order, a buffering config such as `wait_for_update`), not merely whether a consent utility exists anywhere in the repo. **Falsify before flagging**: some SDKs support a native consent-mode that buffers events until consent is granted rather than firing immediately — confirm the library's actual behaviour before reporting a violation.
|
|
41
|
+
- [ ] Anonymous-to-identified transition — `search_code` for an `identify()`/`alias()` call fired on login or signup, and confirm the anonymous ID collected pre-login is passed so sessions stitch together. Without this, every pre-signup event is permanently orphaned from the user it belonged to.
|
|
42
|
+
|
|
43
|
+
## Delivery and ownership
|
|
44
|
+
|
|
45
|
+
- [ ] Commercially significant events (purchase, checkout, subscription) tracked only via a client-side SDK call, with no server-side mirror — `search_code` for a corresponding server-side or webhook-driven event. Ad blockers and tracking-protection browsers drop client-side analytics calls silently; a revenue event with no server counterpart under-reports with no error anywhere in the stack.
|
|
46
|
+
- [ ] Development or staging traffic posting to the same analytics project as production — `search_code` for an environment-gated SDK key or write key, and confirm dev/staging events cannot land in the production dataset and skew it.
|
|
47
|
+
- [ ] Instrumentation still firing for a feature the codebase no longer serves — cross-reference `reachability.md`'s dead-code findings against the event inventory; a dead component still calling `track()` pollutes every dashboard reading that event with noise from a code path nobody can reach.
|
|
48
|
+
- [ ] A stated owner or dashboard for the event set — `search_code`/read `README`, a `CONTRIBUTING` doc, or an analytics-specific doc for a named owner or a linked dashboard. Instrumentation nobody is assigned to read decays the moment it is shipped, whether or not it is technically correct.
|
|
49
|
+
|
|
50
|
+
## Out of static reach
|
|
51
|
+
|
|
52
|
+
- Actual delivery rate — whether events fired in code are received, deduplicated, and processed correctly by the analytics platform.
|
|
53
|
+
- Dashboard accuracy and whether the metrics computed from these events match what the business actually reports elsewhere.
|
|
54
|
+
- Sampling or rate-limiting applied by the SDK or platform that silently drops a fraction of events under load.
|
|
55
|
+
- Whether the team actually reads the dashboard a stated owner is attached to — an assigned owner is evidence of intent, not proof of use.
|
|
56
|
+
|
|
57
|
+
## Severity guidance
|
|
58
|
+
|
|
59
|
+
| Situation | Severity |
|
|
60
|
+
|---|---|
|
|
61
|
+
| User-facing product with no analytics instrumentation at all | High |
|
|
62
|
+
| Commercially significant event tracked client-side only, no server mirror | High |
|
|
63
|
+
| PII or a token-bearing URL captured in event properties | High |
|
|
64
|
+
| Funnel with no failure or error event, only success | High |
|
|
65
|
+
| Consent-required jurisdiction with no consent gate before tracking | High |
|
|
66
|
+
| Same conceptual event fired under two different names | Medium |
|
|
67
|
+
| Event or property name built dynamically at runtime, not a fixed literal | Medium |
|
|
68
|
+
| Event fired without the properties its own purpose requires | Medium |
|
|
69
|
+
| No anonymous-to-identified stitching on login/signup | Medium |
|
|
70
|
+
| Dev/staging traffic landing in the production dataset | Medium |
|
|
71
|
+
| Dead code still firing tracking events | Low |
|
|
72
|
+
| No stated owner or dashboard for the event set | Low |
|
|
73
|
+
| Minor naming-convention drift on a small minority of events | Info / Low |
|
|
@@ -4,35 +4,43 @@ The contract as seen from outside. Gate: a server framework or API routes were d
|
|
|
4
4
|
|
|
5
5
|
## Surface inventory
|
|
6
6
|
|
|
7
|
-
- [ ] Enumerate every externally reachable endpoint, tool, or exported entry point. `search_code` the route-registration call, then `find_callers` on each handler.
|
|
8
|
-
- [ ] Each one is documented, or deliberately internal.
|
|
9
|
-
- [ ] No endpoint exists that the docs do not mention and no client calls — that belongs to `Reachability`, cross-reference it.
|
|
7
|
+
- [ ] Enumerate every externally reachable endpoint, tool, or exported entry point. `search_code` the route-registration call (`router.`, `app.get(`, `@Get(`, a tool/handler registry), then `find_callers` on each handler to confirm nothing routes to it a second time through a separate registration.
|
|
8
|
+
- [ ] Each one is documented, or deliberately internal. Cross-check the inventory above against the docs/OpenAPI artefact located by `search_code` for `openapi`, `swagger`, or `.graphql` — an endpoint present in one list and absent from the other is the finding.
|
|
9
|
+
- [ ] No endpoint exists that the docs do not mention and no client calls — that belongs to `Reachability`, cross-reference it rather than re-deriving it here.
|
|
10
10
|
|
|
11
11
|
## Contract shape
|
|
12
12
|
|
|
13
|
-
- [ ] Naming and pluralisation are consistent across the surface. `/users/:id` next to `/getAccount` is two conventions.
|
|
14
|
-
- [ ] Status codes are used for their meaning
|
|
15
|
-
- [ ] Error responses share one shape, and it includes something machine-readable — a code, not only prose.
|
|
16
|
-
- [ ] Pagination exists wherever a collection can grow, and it is the same mechanism everywhere.
|
|
17
|
-
- [ ] Field names and types are stable across endpoints.
|
|
13
|
+
- [ ] Naming and pluralisation are consistent across the surface. Diff the path list from the inventory above literally — `/users/:id` next to `/getAccount` is two conventions in one surface.
|
|
14
|
+
- [ ] Status codes are used for their meaning. `search_code` for a `200`/`res.status(200)` literal returned alongside an error-shaped body, or a `500` returned for what the handler logic shows is a validation failure.
|
|
15
|
+
- [ ] Error responses share one shape, and it includes something machine-readable — a code, not only prose. `search_code` the error-construction call across handlers; more than one shape is the finding — cross-reference `Backend`'s request-lifecycle check, and report the value divergence here.
|
|
16
|
+
- [ ] Pagination exists wherever a collection can grow, and it is the same mechanism everywhere. `search_code` for `limit`/`cursor`/`offset` parameters across list-returning endpoints; a collection endpoint with none of them is the finding. Where the mechanism is offset-based (`page=`/`offset=`) on a collection that also takes concurrent inserts or deletes, note it as a correctness risk, not only a performance one — a row can be skipped or duplicated across pages when the underlying set shifts mid-pagination, independent of how deep the paging goes; cursor/keyset pagination (a `WHERE (sort_col, id) < (last_seen...)` filter) does not have this failure mode because it tracks a data value, not a row position.
|
|
17
|
+
- [ ] Field names and types are stable across endpoints. `find_symbol` the response type for the same concept in two endpoints and diff them — `userId` here and `user_id` there is two vocabularies.
|
|
18
18
|
|
|
19
19
|
## Input contract
|
|
20
20
|
|
|
21
|
-
- [ ] Every parameter's type, required-ness, and bounds are declared, and the declaration is what actually validates.
|
|
22
|
-
- [ ] Unknown fields are rejected or ignored deliberately, not silently accepted and dropped.
|
|
23
|
-
- [ ] Defaults are documented, and the documented default matches the code.
|
|
21
|
+
- [ ] Every parameter's type, required-ness, and bounds are declared, and the declaration is what actually validates. `find_symbol` the schema, then confirm the handler calls `.parse()`/`.validate()` on it rather than importing the type only for documentation.
|
|
22
|
+
- [ ] Unknown fields are rejected or ignored deliberately, not silently accepted and dropped. `find_symbol` the schema's strict/passthrough setting — its absence is the validator's default, not a decision anyone made.
|
|
23
|
+
- [ ] Defaults are documented, and the documented default matches the code. `find_symbol` the schema's default value and diff it against the docs' stated default.
|
|
24
24
|
|
|
25
25
|
## Compatibility
|
|
26
26
|
|
|
27
|
-
- [ ] Breaking changes are versioned or gated. Compare the current shape against any published schema, generated client, or `openapi`/`graphql` artefact — that comparison belongs to `Contract Drift` if that gate is on.
|
|
28
|
-
- [ ]
|
|
29
|
-
- [ ]
|
|
27
|
+
- [ ] Breaking changes are versioned or gated. Compare the current shape against any published schema, generated client, or `openapi`/`graphql` artefact via `search_code` — that comparison belongs to `Contract Drift` if that gate is on; cross-reference rather than re-running it here.
|
|
28
|
+
- [ ] The versioning mechanism is one scheme, not a mix chosen ad hoc per endpoint. `search_code` the route prefixes (`/v1/`, `/v2/`) and any `Accept`-header or custom version-header handling across the surface — URI, header, and media-type versioning are all legitimate choices (URI is the most operationally common for public APIs — cache-friendly, visible in logs), but one endpoint quietly branching on a header nobody else uses is the finding, not the choice of mechanism itself.
|
|
29
|
+
- [ ] Optional fields are genuinely optional in every consumer. `find_callers` on the response type to see who destructures the field with no null check.
|
|
30
|
+
- [ ] Removed or renamed fields, and endpoints scheduled for removal, have a deprecation path. For an HTTP surface: `search_code` for a `Deprecation` response header being set (RFC 9745 — a Structured Field date, not a free-text string) and, once a removal date exists, a `Sunset` header (RFC 8594) whose date is never earlier than the `Deprecation` header's own date on the same response. For a non-HTTP surface: `search_code` for a `deprecated` marker or doc comment near the field the code no longer sets. Absence on a field or endpoint the docs mark deprecated is the finding.
|
|
30
31
|
|
|
31
32
|
## Discoverability
|
|
32
33
|
|
|
33
|
-
- [ ] A caller can find the full surface without reading the source.
|
|
34
|
-
- [ ] Examples in the docs are executable and current.
|
|
35
|
-
- [ ] Auth requirements are stated per endpoint, not only globally.
|
|
34
|
+
- [ ] A caller can find the full surface without reading the source. Confirm a docs/OpenAPI artefact exists and its endpoint count matches the inventory count above; a mismatch is the finding.
|
|
35
|
+
- [ ] Examples in the docs are executable and current. `find_symbol` the referenced handler's real signature and diff it against the documented example's parameters.
|
|
36
|
+
- [ ] Auth requirements are stated per endpoint, not only globally. `search_code` the docs/OpenAPI security annotations per path, then `find_callees` on the handler for an auth middleware in code with no matching stated requirement in docs.
|
|
37
|
+
|
|
38
|
+
## Out of static reach
|
|
39
|
+
|
|
40
|
+
- Whether the documented examples were actually executed against a running server recently, versus copy-pasted once and never rerun.
|
|
41
|
+
- Real client behaviour on an unknown field — whether a consumer silently ignores it or crashes depends on the client's own parser, not this repository.
|
|
42
|
+
- Actual latency or throughput of paginated versus unpaginated responses.
|
|
43
|
+
- Whether external consumers exist at all for an endpoint marked "internal" — that requires visibility outside this repository.
|
|
36
44
|
|
|
37
45
|
## Severity guidance
|
|
38
46
|
|
|
@@ -45,3 +53,5 @@ The contract as seen from outside. Gate: a server framework or API routes were d
|
|
|
45
53
|
| Inconsistent error shape across the surface | Medium |
|
|
46
54
|
| Naming convention drift | Low |
|
|
47
55
|
| Docs example that no longer matches the signature | Low |
|
|
56
|
+
| Offset pagination on a frequently-mutated collection, no cursor alternative | Low |
|
|
57
|
+
| Versioning mechanism mixed inconsistently across the surface | Low |
|
|
@@ -6,34 +6,42 @@ Orient with `repo_map` first — the highest-ranked symbols in a backend are usu
|
|
|
6
6
|
|
|
7
7
|
## Request lifecycle
|
|
8
8
|
|
|
9
|
-
- [ ] Every handler validates its input before using it.
|
|
10
|
-
- [ ] Auth runs before business logic, not inside it.
|
|
11
|
-
- [ ] One place owns request→response shape.
|
|
12
|
-
- [ ] Long operations do not block the request.
|
|
9
|
+
- [ ] Every handler validates its input before using it. `find_callees` from the handler to locate the first read of a request field, then confirm a schema or guard runs before it. Rule out: validation performed by framework middleware attached upstream of the handler — that still counts, it just is not visible inside the handler body.
|
|
10
|
+
- [ ] Auth runs before business logic, not inside it. `find_callees` on the handler: the auth/permission check must appear before the first call into a service or domain function, not interleaved after it has already done work.
|
|
11
|
+
- [ ] One place owns request→response shape. `search_code` the error-response construction across handlers (a literal like `res.status(`, the framework's error type, or the error-envelope constructor) — more than one shape assembled ad hoc is drift.
|
|
12
|
+
- [ ] Long operations do not block the request. `search_code` for a synchronous file, network, or CPU-bound call inside a handler with no queue or background dispatch around it; state the observed or estimated duration if found.
|
|
13
13
|
|
|
14
14
|
## Layering
|
|
15
15
|
|
|
16
|
-
- [ ] Handlers do not contain business logic, and business logic does not know about HTTP.
|
|
17
|
-
- [ ] Data access is isolated from business rules.
|
|
18
|
-
- [ ] No circular dependencies between modules. `trace_path` from a module back to itself.
|
|
16
|
+
- [ ] Handlers do not contain business logic, and business logic does not know about HTTP. `find_callees` on a domain/service function: a domain function reaching a request/response type (`req`, `res`, `Request`, `Response`) is a layering violation.
|
|
17
|
+
- [ ] Data access is isolated from business rules. `search_code` for SQL or query-builder literals inside a service/domain file rather than confined to a repository/DAO layer — a service building SQL inline couples two layers that change for different reasons.
|
|
18
|
+
- [ ] No circular dependencies between modules. `trace_path` from a module back to itself; a path found is the finding.
|
|
19
19
|
|
|
20
20
|
## Transactions and consistency
|
|
21
21
|
|
|
22
|
-
- [ ] Multi-step writes are transactional, or the partial-failure state is explicitly acceptable and documented.
|
|
23
|
-
- [ ] Nothing writes to two systems (DB + queue, DB + external API) without an outbox, retry, or documented tolerance for divergence.
|
|
24
|
-
- [ ] Read-modify-write sequences are safe against concurrent execution — see the `Concurrency` module if that gate is also on.
|
|
22
|
+
- [ ] Multi-step writes are transactional, or the partial-failure state is explicitly acceptable and documented. `find_callees` on the write function to enumerate its writes, then `search_code` for a `begin`/transaction call wrapping all of them rather than each committing independently.
|
|
23
|
+
- [ ] Nothing writes to two systems (DB + queue, DB + external API) without an outbox, retry, or documented tolerance for divergence. `find_callees` on the write path for a second side effect issued after the DB commit with no compensating mechanism between them.
|
|
24
|
+
- [ ] Read-modify-write sequences are safe against concurrent execution. `search_code` for a read followed by a write of the same record with no version check or row lock between them — see the `Concurrency` module for the fuller treatment if that gate is also on.
|
|
25
25
|
|
|
26
26
|
## Configuration and secrets
|
|
27
27
|
|
|
28
|
-
- [ ] No secret is hardcoded. `search_code` for likely literals: `secret`, `token`, `password`, `api_key`, `Bearer
|
|
29
|
-
- [ ] Every config value has a validated shape and a stated default, or fails loudly at startup rather than at first use.
|
|
30
|
-
- [ ] Environment variables read in code are declared somewhere — cross-check with `Reachability`'s used-but-never-declared sweep.
|
|
28
|
+
- [ ] No secret is hardcoded. `search_code` for likely literals: `secret`, `token`, `password`, `api_key`, `Bearer`, matched against a quoted string rather than an env or config read.
|
|
29
|
+
- [ ] Every config value has a validated shape and a stated default, or fails loudly at startup rather than at first use. `find_symbol` the config loader and confirm it throws or exits on a missing required value instead of silently returning `undefined`.
|
|
30
|
+
- [ ] Environment variables read in code are declared somewhere — cross-check with `Reachability`'s used-but-never-declared sweep rather than re-deriving it here.
|
|
31
31
|
|
|
32
32
|
## Resource handling
|
|
33
33
|
|
|
34
|
-
- [ ] Every acquired resource is released on both the success and the error path
|
|
35
|
-
- [ ] Connection pools are bounded and the bound is reachable from config.
|
|
36
|
-
- [ ] Timeouts exist on every outbound call. A missing timeout is a `High` — it converts a slow dependency into a hung server.
|
|
34
|
+
- [ ] Every acquired resource is released on both the success and the error path. `search_code` for the acquire call (`connect(`, `open(`, `lock(`) and confirm a `finally`/`defer`/context-manager releases it, not only a release line on the happy path.
|
|
35
|
+
- [ ] Connection pools are bounded and the bound is reachable from config. `search_code` the pool constructor and confirm its size argument is read from config, not a hardcoded literal.
|
|
36
|
+
- [ ] Timeouts exist on every outbound call. `search_code` the HTTP/DB client construction and confirm a timeout option is set. A missing timeout is a `High` — it converts a slow dependency into a hung server.
|
|
37
|
+
|
|
38
|
+
## Out of static reach
|
|
39
|
+
|
|
40
|
+
- Whether a validation schema is actually sufficient against real malicious input — source confirms a check runs, not that it is strict enough.
|
|
41
|
+
- Real request latency, and whether an operation genuinely blocks the event loop under production load rather than only in theory.
|
|
42
|
+
- Whether a transaction boundary set in code commits atomically at the database/driver level — that depends on the driver's real behaviour, not the call shape.
|
|
43
|
+
- Connection pool exhaustion under real concurrent traffic.
|
|
44
|
+
- Whether a startup failure path actually halts the process versus logging a fatal-looking message and continuing to serve traffic.
|
|
37
45
|
|
|
38
46
|
## Severity guidance
|
|
39
47
|
|
|
@@ -4,40 +4,52 @@ What is harder to change than it needs to be? Complexity is not line count — i
|
|
|
4
4
|
|
|
5
5
|
Use `repo_map` to find the structurally central symbols, then `impact` on each. **A symbol with a large blast radius and high internal complexity is the riskiest code in the project**, and that combination is what this module is for.
|
|
6
6
|
|
|
7
|
+
This module never computes a complexity score — no cyclomatic number, no cognitive-complexity number — because that requires running an analyser, and everything here is established by reading. If the project already has one committed (a linter's `complexity` rule, a SonarQube report, a CI badge), read it with the evidence in mind rather than at face value: cyclomatic complexity's correlation with real defects is weaker and more contested than it's often assumed to be — a formal critique (Shepperd, "A critique of cyclomatic complexity as a software metric") argues its predictive power may reduce mostly to code size — while a ceiling on the number (historically 10, sometimes relaxed to 15 with strong review and test discipline) remains a defensible *engineering* limit, which is a different and more modest claim than "this number predicts a bug." Cognitive Complexity (SonarSource, 2016) is the better-regarded metric specifically for *readability* — it was designed to fix cyclomatic complexity's blind spot for nesting and mixed boolean chains — but controlled studies still find it only a modest predictor of understandability, not of defects. Treat any such number, from this project or elsewhere, as a structural signal worth a closer read, never as proof on its own.
|
|
8
|
+
|
|
7
9
|
## Structural complexity
|
|
8
10
|
|
|
9
|
-
- [ ] Functions doing more than one thing
|
|
10
|
-
- [ ] Deep nesting
|
|
11
|
-
- [ ] Long parameter lists, especially with several of the same type —
|
|
12
|
-
- [ ] Boolean parameters that select behaviour. `render(true, false)` at the call site tells the reader nothing.
|
|
13
|
-
- [ ] Functions whose control flow depends on the *caller's* state rather than their arguments.
|
|
11
|
+
- [ ] Functions doing more than one thing — the tell is the name: `and`, `or`, `handle`, `process`, `manage`, or a name that describes the caller rather than the operation. `search_code` for definitions matching those verbs, then read each to confirm it does more than its name admits.
|
|
12
|
+
- [ ] Deep nesting — three levels of conditionals inside a loop is where off-by-one and missed-branch bugs live. Start from `repo_map`'s central symbols and read each; early returns and guard clauses usually collapse it.
|
|
13
|
+
- [ ] Long parameter lists, especially with several of the same type — `find_symbol` the signature. Every call site is a chance to swap two arguments silently, so cross-check with `find_callers` whether call sites actually differ only by argument order.
|
|
14
|
+
- [ ] Boolean parameters that select behaviour — `search_code` for call sites with adjacent boolean literals (`, true, false)`, `, false, true)`). `render(true, false)` at the call site tells the reader nothing without opening the definition.
|
|
15
|
+
- [ ] Functions whose control flow depends on the *caller's* state rather than their arguments — read the function body for a reference to module-level or global state, then `find_callers` to confirm different callers rely on different ambient state to get different behaviour.
|
|
14
16
|
|
|
15
17
|
## Coupling
|
|
16
18
|
|
|
17
19
|
- [ ] `impact` on the central symbols: how much of the codebase must be re-verified to change one of them? A high number is not automatically wrong, but it must be intentional.
|
|
18
|
-
- [ ] Modules that import from many others
|
|
19
|
-
- [ ] Cyclic dependencies
|
|
20
|
-
- [ ] Shared mutable state as a coupling mechanism. Two modules
|
|
21
|
-
- [ ] Reaching through an object to its internals (`a.b.c.d`) —
|
|
20
|
+
- [ ] Modules that import from many others — `find_callees` at module granularity. A module with a long callee list is coupled to all of them at once.
|
|
21
|
+
- [ ] Cyclic dependencies — `trace_path` from a module back to itself. A cycle means neither side can be understood alone.
|
|
22
|
+
- [ ] Shared mutable state as a coupling mechanism — `search_code` for an exported `let` or a mutable singleton, then `find_callers` on it. Two unrelated modules both writing to it are coupled without an interface.
|
|
23
|
+
- [ ] Reaching through an object to its internals (`a.b.c.d`) — `search_code` the deepest access chain seen while reading a central module. Each additional segment is one more assumption the caller makes about the callee's internal shape.
|
|
22
24
|
|
|
23
25
|
## Duplication that matters
|
|
24
26
|
|
|
25
|
-
- [ ] Duplicated *logic*, not duplicated *shape*. Two functions with the same structure and different meaning should stay separate; two encoding the same rule must not.
|
|
26
|
-
- [ ] The same business rule expressed in more than one place — a validation, a threshold, a format. `search_code` the literal value.
|
|
27
|
-
- [ ] Magic values repeated across files. One named constant, one place to change.
|
|
28
|
-
- [ ] Premature deduplication is its own finding
|
|
27
|
+
- [ ] Duplicated *logic*, not duplicated *shape*. Two functions with the same structure and different meaning should stay separate; two encoding the same rule must not. Once `search_code` surfaces structurally similar functions (same branch count, same operation order), read both bodies side by side to tell which case you're in.
|
|
28
|
+
- [ ] The same business rule expressed in more than one place — a validation, a threshold, a format. `search_code` the literal value (a magic number, a regex, a status string) across the repo; more than one hit outside a shared constant is the finding.
|
|
29
|
+
- [ ] Magic values repeated across files — `search_code` the literal. One named constant, one place to change.
|
|
30
|
+
- [ ] Premature deduplication is its own finding — `find_callers` on the shared abstraction. A count of one caller, plus three parameters that only exist to serve it, is complexity added for a reuse that never happened.
|
|
31
|
+
- [ ] An abstraction serving two or more callers that has grown parameters or conditionals existing only to accommodate one caller's divergence — `find_callers` the shared function or component and read what each call site actually needs from it. When the callers no longer share the same *reason* to call it, even though the code path is still shared, this is the wrong abstraction (Sandi Metz, "The Wrong Abstraction," 2016): the fix is to inline it back into each caller and let the duplication return, not add another parameter to keep forcing them together. This is the same smell as the one-caller case above, one caller further along — and more damaging, because it's now a live complexity tax on real call sites instead of unused generality.
|
|
29
32
|
|
|
30
33
|
## Cognitive load
|
|
31
34
|
|
|
32
|
-
- [ ] Names that require reading the implementation to understand. Cross-reference the naming-drift check in `functional.md`.
|
|
33
|
-
- [ ] Implicit ordering requirements — "call `init` before `run`" enforced only by convention
|
|
34
|
-
- [ ] Non-obvious code with no comment explaining *why
|
|
35
|
-
- [ ] Conditionals whose branches are hard to enumerate
|
|
35
|
+
- [ ] Names that require reading the implementation to understand — predict the function's behaviour from its name alone, then read the body and check the prediction held. Cross-reference the naming-drift check in `functional.md`.
|
|
36
|
+
- [ ] Implicit ordering requirements — "call `init` before `run`" enforced only by convention — `find_callers` on the second call to check every call site actually calls the first one first, and whether anything enforces it structurally (a state check, a type that only exists post-init) rather than by convention alone.
|
|
37
|
+
- [ ] Non-obvious code with no comment explaining *why* — read the functions `repo_map` and `impact` flag as central. Comments restating *what* the code does are noise; a missing *why* on a surprising line is a real gap.
|
|
38
|
+
- [ ] Conditionals whose branches are hard to enumerate — `search_code` for nested ternaries (`? ... ? ... :`) and `switch` statements missing a `break` before the next `case`.
|
|
36
39
|
|
|
37
40
|
## Dead weight
|
|
38
41
|
|
|
39
42
|
Report these under `Reachability` rather than here, but look for them while reading: unused parameters, options nothing sets, defensive checks for states that cannot occur, and abstraction layers that only forward.
|
|
40
43
|
|
|
44
|
+
## Out of static reach
|
|
45
|
+
|
|
46
|
+
- Whether a high-blast-radius symbol is actually risky in practice, or merely central and rarely touched — call-graph centrality is not change frequency; cross-reference `repo-history.md` for that signal.
|
|
47
|
+
- Whether coupling through shared state actually causes incorrect behaviour, which depends on execution order this module cannot observe.
|
|
48
|
+
- Whether a reader genuinely finds a given structure confusing — cognitive load is inferred from shape, not measured from a person.
|
|
49
|
+
- Whether an implicit ordering requirement has ever actually been violated in production.
|
|
50
|
+
- Whether the same rule reimplemented across services (a validation duplicated in a mobile client, say) is intentional platform divergence or drift — this module sees one repo at a time.
|
|
51
|
+
- Whether a reported complexity score (cyclomatic, cognitive, or otherwise) has ever correlated with an actual defect in this codebase specifically — the general research correlating either metric with real-world bug density is weaker than commonly assumed, and settling it here would require the historical defect data this module doesn't have.
|
|
52
|
+
|
|
41
53
|
## Severity guidance
|
|
42
54
|
|
|
43
55
|
| Situation | Severity |
|
|
@@ -47,6 +59,7 @@ Report these under `Reachability` rather than here, but look for them while read
|
|
|
47
59
|
| Cyclic dependency between modules | Medium |
|
|
48
60
|
| Implicit call-ordering requirement with no enforcement | Medium |
|
|
49
61
|
| Deeply nested control flow on a correctness-critical path | Medium |
|
|
62
|
+
| Shared abstraction kept alive with extra parameters for callers that no longer agree (the wrong abstraction) | Medium |
|
|
50
63
|
| Boolean parameter selecting behaviour | Low |
|
|
51
64
|
| Surprising line with no explanatory comment | Low |
|
|
52
65
|
| Abstraction with one caller | Low |
|
|
@@ -7,45 +7,53 @@ Concurrency defects are the ones that pass every test and fail in production, be
|
|
|
7
7
|
## Shared mutable state
|
|
8
8
|
|
|
9
9
|
- [ ] Identify every piece of state reachable from more than one concurrent path. `find_callers` on each module-level mutable binding — more than one caller on different paths is a candidate.
|
|
10
|
-
- [ ] Module-level `let`, mutable singletons, and caches populated lazily. Lazy initialisation under concurrency initialises twice.
|
|
11
|
-
- [ ] Objects passed by reference to concurrent consumers and mutated by any of them.
|
|
10
|
+
- [ ] Module-level `let`, mutable singletons, and caches populated lazily: `search_code` for a module-scope `let`/static field, or a lazy-init guard (`if (!cache) cache = …`). Lazy initialisation under concurrency initialises twice — the second caller reads a half-built value or triggers the expensive setup a second time.
|
|
11
|
+
- [ ] Objects passed by reference to concurrent consumers and mutated by any of them: `find_callers` on the function that hands out the reference, then read each caller for an in-place mutation (`.push`, a property assignment) instead of a read-only use.
|
|
12
12
|
|
|
13
13
|
## Read-modify-write
|
|
14
14
|
|
|
15
|
-
- [ ] Every read-then-write sequence on shared state. Between the read and the write, another actor can change it. Look for: counters, "check then create", "find or insert", version bumps, balance updates.
|
|
16
|
-
- [ ] The fix must be visible: an atomic operation, a compare-and-swap, a row lock, a unique constraint
|
|
17
|
-
- [ ] `check-then-act` on the filesystem
|
|
15
|
+
- [ ] Every read-then-write sequence on shared state: `search_code` for `+= 1`/`++` on a stored field, `findOrCreate`, `getOrCreate`, or a `SELECT` immediately followed by an `INSERT`/`UPDATE` in the same function. Between the read and the write, another actor can change it. Look for: counters, "check then create", "find or insert", version bumps, balance updates.
|
|
16
|
+
- [ ] The fix must be visible at the site found above: read it for an atomic operation, a compare-and-swap, a row lock, or a unique constraint. A comment saying it is safe is not a mechanism — if the site has none of these, it is the finding regardless of how it reads.
|
|
17
|
+
- [ ] `check-then-act` on the filesystem: `search_code` for `existsSync(` followed by a nearby `writeFile`/`mkdirSync` — the check and the act are two operations, and anything can happen between them. Prefer atomic create or accept-and-handle-the-error.
|
|
18
18
|
|
|
19
19
|
## Ordering
|
|
20
20
|
|
|
21
|
-
- [ ]
|
|
22
|
-
- [ ] `
|
|
23
|
-
- [ ]
|
|
24
|
-
- [ ]
|
|
21
|
+
- [ ] `Promise.all` over operations with hidden interdependencies: `search_code` for `Promise.all(`, then read each operand for a dependency on another operand in the same array — they will interleave, not run in the order they are written.
|
|
22
|
+
- [ ] Fire-and-forget calls whose effects a later step assumes: `search_code` for an async call with no `await` and no `.then`/`.catch`, then `find_callers` on the caller's caller to check whether a subsequent step relies on the fired-off work having finished.
|
|
23
|
+
- [ ] Event handlers that can be re-entered before the previous invocation finishes: `search_code` for `.on(`/`addEventListener` registering an `async` callback, then read it for an in-flight guard (a boolean flag, a lock) before the next event can start processing.
|
|
24
|
+
- [ ] A queue message or job whose visibility/lease timeout can expire mid-processing, letting a second worker pick it up while the first is still running: `search_code` for a heartbeat/lease-extension call (SQS's `ChangeMessageVisibility`, a job-lock renewal) inside a handler whose runtime can exceed the queue's timeout — SQS's own default visibility timeout is 30 seconds. Its absence on a handler with real duration is the finding: two workers now hold the same logical message concurrently, and whatever the handler writes is a read-modify-write race between them.
|
|
25
25
|
|
|
26
26
|
## Locks and resources
|
|
27
27
|
|
|
28
|
-
- [ ] Locks are always released, including on the error path. A lock held through a throw is a permanent deadlock.
|
|
29
|
-
- [ ] Lock acquisition order is consistent everywhere
|
|
30
|
-
- [ ] Locks have a timeout or a lease
|
|
31
|
-
- [ ] Nothing does I/O while holding a lock longer than necessary.
|
|
28
|
+
- [ ] Locks are always released, including on the error path: `search_code` for the lock/mutex acquire call (`.lock(`, `acquireLock`, `withLock`), then read whether the matching release sits in a `finally` block. A lock held through a throw is a permanent deadlock.
|
|
29
|
+
- [ ] Lock acquisition order is consistent everywhere: collect every acquire site found above and list the resources each one locks, in order — two sites taking A-then-B and B-then-A deadlock.
|
|
30
|
+
- [ ] Locks have a timeout or a lease: `search_code` the lock library's usage for a `timeout`/`ttl`/`lease` argument at each acquire site. Its absence means a dead holder blocks forever.
|
|
31
|
+
- [ ] Nothing does I/O while holding a lock longer than necessary: read the code between each acquire and its release for a network or database call inside the critical section.
|
|
32
32
|
|
|
33
33
|
## Cancellation
|
|
34
34
|
|
|
35
|
-
- [ ] Long operations are cancellable, and cancellation actually stops work
|
|
36
|
-
- [ ] Cancelled operations clean up
|
|
37
|
-
- [ ] A late result from a cancelled or superseded operation cannot overwrite a newer one.
|
|
35
|
+
- [ ] Long operations are cancellable, and cancellation actually stops work: `search_code` for `AbortController`/`AbortSignal`/a cancellation-token parameter on functions identified as long-running via `find_callees` (a loop or a chain of awaits). Its absence on an operation with real duration is the finding.
|
|
36
|
+
- [ ] Cancelled operations clean up: read the abort handler (`signal.addEventListener('abort', …)` or equivalent) for resource release or rollback — a cancellation that only stops listening, without releasing what it held, leaks.
|
|
37
|
+
- [ ] A late result from a cancelled or superseded operation cannot overwrite a newer one: `search_code` for a stored "latest request id"/sequence number compared before a result is applied (`if (id !== latestId) return`). Its absence on a handler triggered by rapid repeated calls (search, autocomplete, a fast double-click) is the finding — the same defect as the unmounted-component write in `frontend.md`.
|
|
38
38
|
|
|
39
39
|
## Signals and shutdown
|
|
40
40
|
|
|
41
|
-
- [ ] In-flight work completes or is safely abandoned on shutdown
|
|
42
|
-
- [ ] Shutdown is bounded
|
|
43
|
-
- [ ] Persistent handles (
|
|
41
|
+
- [ ] In-flight work completes or is safely abandoned on shutdown: `search_code` for `process.on('SIGTERM'`/`'SIGINT'`, then read whether the handler awaits outstanding work before exiting.
|
|
42
|
+
- [ ] Shutdown is bounded: read the shutdown handler for a forced-exit timeout wrapping the drain. Its absence means a hang on drain never resolves — worse than a forced exit.
|
|
43
|
+
- [ ] Persistent handles are closed on every exit path: for each resource opened elsewhere (`find_symbol` the db pool, WAL, or file-lock construction), `search_code` the shutdown handler for a matching `.close()`/`.end()`/`.disconnect()` call.
|
|
44
44
|
|
|
45
45
|
## Reporting
|
|
46
46
|
|
|
47
47
|
State each finding as an interleaving: "if A reaches line X while B is between lines Y and Z, then …". A concurrency finding without a concrete interleaving is unfalsifiable, and reviewers correctly dismiss it.
|
|
48
48
|
|
|
49
|
+
## Out of static reach
|
|
50
|
+
|
|
51
|
+
- Whether the interleaving described actually occurs under real load — thread/event-loop scheduling is not observable from source.
|
|
52
|
+
- Lock contention rate and wait time in production.
|
|
53
|
+
- Whether a race is merely possible or actually hit within any realistic time window.
|
|
54
|
+
- Actual behaviour of the runtime's scheduler or garbage collector during the interleaving.
|
|
55
|
+
- Whether a shutdown timeout value is long enough for real in-flight work to drain.
|
|
56
|
+
|
|
49
57
|
## Severity guidance
|
|
50
58
|
|
|
51
59
|
| Situation | Severity |
|
|
@@ -53,6 +61,7 @@ State each finding as an interleaving: "if A reaches line X while B is between l
|
|
|
53
61
|
| Read-modify-write on shared state with no atomicity | High |
|
|
54
62
|
| Lock not released on the error path | High |
|
|
55
63
|
| Inconsistent lock ordering across paths | High |
|
|
64
|
+
| Message/job redelivered on lease expiry while the original worker is still processing it | High |
|
|
56
65
|
| Late result overwriting a newer one | Medium |
|
|
57
66
|
| Lazy initialisation racing to initialise twice | Medium |
|
|
58
67
|
| Unawaited async call whose effect is later assumed | Medium |
|
|
@@ -6,45 +6,53 @@ The method here is comparison, not judgement. Find the dominant pattern with `se
|
|
|
6
6
|
|
|
7
7
|
## Naming
|
|
8
8
|
|
|
9
|
-
- [ ] Casing conventions per kind of thing (files, functions, types, constants, config keys) —
|
|
10
|
-
- [ ] The same concept has the same name everywhere
|
|
11
|
-
- [ ] Opposite operations use symmetric names
|
|
12
|
-
- [ ] Boolean names read as assertions — `
|
|
13
|
-
- [ ] Abbreviations are used consistently or not at all.
|
|
9
|
+
- [ ] Casing conventions per kind of thing (files, functions, types, constants, config keys) — `search_code` a sample of declarations for each kind, tally the casing style, and treat whichever covers the large majority as the standard. List every declaration using the other style.
|
|
10
|
+
- [ ] The same concept has the same name everywhere — `search_code` each candidate synonym (`user` / `account` / `member` for one entity) and compare hit counts. The minority name is the deviation, not automatically wrong, but it is a second mental model for one thing.
|
|
11
|
+
- [ ] Opposite operations use symmetric names — `search_code` one half of a known pair (`open`) and check whether its counterpart in the same module is `close` or something asymmetric like `dispose`.
|
|
12
|
+
- [ ] Boolean names read as assertions — `search_code` boolean-typed declarations or props; count how many use an `is`/`has`/`can` prefix versus a bare noun, and list the noun-named minority.
|
|
13
|
+
- [ ] Abbreviations are used consistently or not at all — `search_code` a common abbreviation (`cfg`, `ctx`, `mgr`, `req`/`res`) alongside its spelled-out form; whichever wins the majority is the convention.
|
|
14
14
|
|
|
15
15
|
## Structure
|
|
16
16
|
|
|
17
|
-
- [ ] Files are organised by one principle, not two competing ones (by type
|
|
18
|
-
- [ ] Similar things live in similar places
|
|
19
|
-
- [ ] Module entry points are consistent —
|
|
20
|
-
- [ ] Test file location and naming follow one rule.
|
|
17
|
+
- [ ] Files are organised by one principle, not two competing ones — `list_modules` (or read the top-level tree) and check whether the split is consistently by type (`controllers/`, `models/`) or consistently by feature (`billing/`, `auth/`). A tree mixing both is the finding.
|
|
18
|
+
- [ ] Similar things live in similar places — for a handful of same-role files (every route handler, say), `search_code` their directory pattern and confirm they land in the same shape of path.
|
|
19
|
+
- [ ] Module entry points are consistent — `search_code` for `index.ts`/`index.js` re-export barrels versus deep imports (`from '../foo/bar'`) reaching past a barrel that exists; tally which style dominates.
|
|
20
|
+
- [ ] Test file location and naming follow one rule — `search_code` for `.test.`, `.spec.`, and a co-located-vs-`__tests__/`-directory split. The minority pattern is the deviation.
|
|
21
21
|
|
|
22
22
|
## Idioms
|
|
23
23
|
|
|
24
|
-
- [ ] One way to do each recurring thing: error creation, logging, config reading, async style, validation.
|
|
25
|
-
- [ ] Async style is uniform
|
|
26
|
-
- [ ] Error handling shape is uniform — throw
|
|
27
|
-
- [ ] Data validation happens at consistent boundaries
|
|
28
|
-
- [ ] Immutability conventions are consistent —
|
|
24
|
+
- [ ] One way to do each recurring thing: error creation, logging, config reading, async style, validation — `search_code` each candidate (`new Error(`, a custom error factory, `console.log` vs. the logger import, `process.env.` vs. a config module) and tally which one the codebase actually uses.
|
|
25
|
+
- [ ] Async style is uniform — `search_code` for `.then(`, `async function`/`await`, and callback-style signatures (`(err, data) =>`) doing comparable work. Mixed styles for the same kind of operation forces the reader to context-switch.
|
|
26
|
+
- [ ] Error handling shape is uniform — `search_code` for `throw new` versus a return-result shape (`{ ok: false`, `Result<`, `[error, data]`). A codebase using both for the same kind of failure has two error-handling mental models live at once.
|
|
27
|
+
- [ ] Data validation happens at consistent boundaries — `search_code` the validation library's call sites (`.parse(`, `.validate(`) and note whether they cluster at the route/entry layer or are scattered three layers deep in some services and not others.
|
|
28
|
+
- [ ] Immutability conventions are consistent — `search_code` for mutating methods (`.push(`, `.splice(`, `+=` on a declared `const` object) against the dominant style found elsewhere. If most code avoids mutation, the places that mutate need a reason.
|
|
29
29
|
|
|
30
30
|
## Interfaces
|
|
31
31
|
|
|
32
|
-
- [ ] Functions with the same role have the same signature shape — options object vs. positional, sync vs. async, same parameter order.
|
|
33
|
-
- [ ] Return shapes are consistent for the same kind of operation. Cross-reference the output-correctness check in `functional.md`.
|
|
34
|
-
- [ ] Null vs. undefined vs. empty-collection means the same thing throughout.
|
|
35
|
-
- [ ] Optional parameters appear in the same position and default the same way.
|
|
32
|
+
- [ ] Functions with the same role have the same signature shape — `find_symbol` a handful of same-role functions (every repository `findBy*`, say) and diff their parameter shape: options object vs. positional, sync vs. async, same parameter order.
|
|
33
|
+
- [ ] Return shapes are consistent for the same kind of operation — `find_symbol` the same set and compare return types; a mix of throwing and returning `null` for "not found" across otherwise-identical functions is the deviation. Cross-reference the output-correctness check in `functional.md`.
|
|
34
|
+
- [ ] Null vs. undefined vs. empty-collection means the same thing throughout — `search_code` for `=== null`, `=== undefined`, and `.length === 0` used as "nothing here" checks across different modules; if all three appear for the same semantic case, the meaning has drifted.
|
|
35
|
+
- [ ] Optional parameters appear in the same position and default the same way — `find_symbol` the same function set and compare where the optional parameter sits and what its default is.
|
|
36
36
|
|
|
37
37
|
## Documentation and comments
|
|
38
38
|
|
|
39
|
-
- [ ] Comment style and density are uniform
|
|
40
|
-
- [ ] The documentation format is one format.
|
|
41
|
-
- [ ] Comments are current. A comment contradicting its code is `Medium` — readers trust comments, and this one lies. This is exactly how the "Close without binding" comment in this repo's own HTTP test came to mislead.
|
|
39
|
+
- [ ] Comment style and density are uniform — `search_code` the doc-comment marker (`/**`, `///`) and compare its count against the number of exported symbols from `find_symbol`. Partial coverage across an otherwise-documented module reads as intentional gaps, which is worse than no documentation at all.
|
|
40
|
+
- [ ] The documentation format is one format — `search_code` for competing doc styles (JSDoc blocks vs. plain `//` prose vs. a separate doc generator's syntax) and confirm one wins.
|
|
41
|
+
- [ ] Comments are current — for any comment making a factual claim about behaviour ("closes the connection", "always returns non-null"), read the code directly beneath it and confirm the claim still holds. A comment contradicting its code is `Medium` — readers trust comments, and this one lies. This is exactly how the "Close without binding" comment in this repo's own HTTP test came to mislead.
|
|
42
42
|
|
|
43
43
|
## Tooling agreement
|
|
44
44
|
|
|
45
|
-
- [ ] Formatter and linter config exist and the codebase actually conforms. A
|
|
46
|
-
- [ ] Committed config does not contradict itself
|
|
47
|
-
- [ ] Pre-commit or CI enforces what the config declares.
|
|
45
|
+
- [ ] Formatter and linter config exist and the codebase actually conforms — read the lint config's enabled rules, then `search_code` for a pattern one of those rules should have caught (`console.log` if `no-console` is on, say). A hit means the config is decoration. (As of 2026 the common combinations are Ruff for Python — largely displacing the older flake8/pylint/isort stack — and ESLint+Prettier or the newer single-tool Biome for JS/TS; the check here is that one combination was picked and enforced, not which.)
|
|
46
|
+
- [ ] Committed config does not contradict itself — read `.editorconfig`, the formatter config, and the linter config side by side for the same setting (indent size, quote style, line length) and diff the values.
|
|
47
|
+
- [ ] Pre-commit or CI enforces what the config declares — `search_code` for a pre-commit hook (`.husky/`, `.pre-commit-config.yaml`) and a lint/format step in the CI workflow files. Treat the two differently: a pre-commit hook with no matching CI step is enforced only for a developer who has the hook installed and hasn't bypassed it (`--no-verify`, or a fresh clone before the install step ran) — nothing stops a violation from merging. CI absent is the real gap; pre-commit absent with a CI lint step present is slower feedback, not a missing gate. Neither present means the standard is optional, and optional standards decay.
|
|
48
|
+
|
|
49
|
+
## Out of static reach
|
|
50
|
+
|
|
51
|
+
- Whether the dominant pattern is the one the team actually intends, versus an accident of who wrote the most code first.
|
|
52
|
+
- Whether an inconsistency genuinely confuses contributors in practice, versus being merely aesthetic.
|
|
53
|
+
- Comment accuracy for logic whose correctness cannot itself be verified by reading alone (cross-reference the tier ceiling on `inferred` findings).
|
|
54
|
+
- Whether a linter rule that exists but isn't enforced in CI is disabled locally by individual developers, or genuinely never runs at all.
|
|
55
|
+
- The historical intent behind a deviation — a file that breaks the pattern on purpose, with the reason recorded only in a closed PR discussion this audit cannot read.
|
|
48
56
|
|
|
49
57
|
## Severity guidance
|
|
50
58
|
|
|
@@ -9,37 +9,46 @@ A contract is a promise written in two or more places. This module checks whethe
|
|
|
9
9
|
## Schema vs. server
|
|
10
10
|
|
|
11
11
|
- [ ] Every operation in the schema exists in the implementation. `search_code` the operation name, then `find_symbol` on the handler.
|
|
12
|
-
- [ ] Every implemented operation appears in the schema.
|
|
13
|
-
- [ ] Field-level agreement: names, types, nullability, required-ness, enum members. Nullability drift is the most commonly missed and the most likely to crash a consumer.
|
|
14
|
-
- [ ] Declared error responses match what the server actually returns, including status codes.
|
|
15
|
-
- [ ] The schema is generated from the implementation or verified against it.
|
|
12
|
+
- [ ] Every implemented operation appears in the schema — `search_code` the route-registration/resolver list for operation names, then `search_code` each name against the schema file. A name present only on the server side is an undocumented endpoint, drift plus a `Reachability` question.
|
|
13
|
+
- [ ] Field-level agreement: names, types, nullability, required-ness, enum members — `find_symbol` the schema type and the implementation's corresponding type/model, and diff the field lists by hand. Nullability drift is the most commonly missed and the most likely to crash a consumer.
|
|
14
|
+
- [ ] Declared error responses match what the server actually returns, including status codes — `search_code` the status codes and error shapes thrown in the handler, then compare against the schema's documented responses for the same operation.
|
|
15
|
+
- [ ] The schema is generated from the implementation or verified against it — `search_code` the manifest/CI config for a codegen or schema-validation step (`openapi-generator`, `graphql-codegen`, a schema-diff check). None found means a hand-maintained schema with no check, which will drift — that is not a prediction, it is a certainty.
|
|
16
|
+
- [ ] For streaming operations (Server-Sent Events, JSON Lines, multipart/mixed — expressible in OpenAPI 3.2+ via `itemSchema`), the declared per-event shape matches what the handler actually emits. `search_code` the handler's stream-write calls and diff the emitted event shape against the schema's `itemSchema`. A schema still describing the operation as a single response body — the only option before 3.2 — while the implementation already streams typed events is drift the older schema shape cannot even express, not merely an outdated field.
|
|
16
17
|
|
|
17
18
|
## Schema vs. consumer
|
|
18
19
|
|
|
19
|
-
- [ ] Generated clients are regenerated from the current schema, and the generated output is either committed or built in CI. A stale committed client is drift with a long fuse.
|
|
20
|
-
- [ ] Hand-written consumer types match the schema. Cross-reference `api.md`: `find_callers` on the response type to see who destructures which fields.
|
|
21
|
-
- [ ] Consumers do not read fields the schema does not promise — including fields that happen to exist today but are undocumented.
|
|
22
|
-
- [ ] Consumers tolerate fields being added. A client
|
|
20
|
+
- [ ] Generated clients are regenerated from the current schema, and the generated output is either committed or built in CI — `search_code` the CI config for the client-generation command and check whether the generated directory is `.gitignore`d (built fresh) or committed (needs a staleness check). A stale committed client is drift with a long fuse.
|
|
21
|
+
- [ ] Hand-written consumer types match the schema. Cross-reference `api.md`: `find_callers` on the response type to see who destructures which fields, then diff those field names against the schema.
|
|
22
|
+
- [ ] Consumers do not read fields the schema does not promise — `search_code` the destructuring/property-access sites on a response object and check each accessed field appears in the schema, including fields that happen to exist today but are undocumented.
|
|
23
|
+
- [ ] Consumers tolerate fields being added — `search_code` for a strict/`.strict()` parsing mode or a validator configured to reject unknown keys on incoming responses. A client rejecting unknown fields makes every additive change breaking.
|
|
23
24
|
|
|
24
25
|
## Versioning of the contract
|
|
25
26
|
|
|
26
|
-
- [ ] Schema changes are classified as additive or breaking, and breaking ones are versioned. Cross-reference `versioning-compatibility.md`.
|
|
27
|
-
- [ ] These look additive and are not: narrowing a type, adding a required field, making an optional field required, removing an enum member, tightening a pattern.
|
|
28
|
-
- [ ] For protobuf: field numbers are never reused or renumbered, removed fields are reserved, and
|
|
29
|
-
- [ ] For GraphQL: removing a field or changing a type is breaking even when clients do not currently request it — someone's query will.
|
|
27
|
+
- [ ] Schema changes are classified as additive or breaking, and breaking ones are versioned — `search_code` for a schema version field or a CHANGELOG referencing the schema. Cross-reference `versioning-compatibility.md`.
|
|
28
|
+
- [ ] These look additive and are not: narrowing a type, adding a required field, making an optional field required, removing an enum member, tightening a pattern — read the schema file's recent git history (`git log -p` on the schema path) and check each change against this list.
|
|
29
|
+
- [ ] For protobuf: field numbers are never reused or renumbered, removed fields are reserved — read the `.proto` file, list every field number in the message, and confirm no gap in the sequence is unaccounted for by a `reserved` statement.
|
|
30
|
+
- [ ] For GraphQL: removing a field or changing a type is breaking even when clients do not currently request it — read the schema file's git history for removed fields or changed types; someone's query will break even if none in this repo does.
|
|
30
31
|
|
|
31
32
|
## Shared types across boundaries
|
|
32
33
|
|
|
33
|
-
- [ ] Types shared between packages or services come from one source, not duplicated definitions kept in sync by hand.
|
|
34
|
-
- [ ] Where duplication is unavoidable, a test asserts equivalence. Same anti-drift pattern as a manifest
|
|
35
|
-
- [ ] Serialisation boundaries agree on representation — date encoding, number precision, null vs. absent, empty vs. missing.
|
|
36
|
-
- [ ] Enum values agree on the wire, not only in name.
|
|
34
|
+
- [ ] Types shared between packages or services come from one source, not duplicated definitions kept in sync by hand — `search_code` the type name; if it is declared, not imported, in more than one package, that is a duplicate rather than a shared type.
|
|
35
|
+
- [ ] Where duplication is unavoidable, a test asserts equivalence — `search_code` the test suite for an assertion comparing the two duplicated definitions field-by-field. Same anti-drift pattern as a manifest-parity test: the hand-maintained copy is fine, the unguarded hand-maintained copy is not.
|
|
36
|
+
- [ ] Serialisation boundaries agree on representation — date encoding, number precision, null vs. absent, empty vs. missing — read the serializer on one side and the deserializer on the other for the same field and compare what each assumes.
|
|
37
|
+
- [ ] Enum values agree on the wire, not only in name — `find_symbol` both enum definitions and diff their underlying string/numeric values, not just the member names.
|
|
37
38
|
|
|
38
39
|
## Fixtures and tests
|
|
39
40
|
|
|
40
|
-
- [ ] Test fixtures are validated against the schema. A fixture that drifted from the contract makes the suite pass against a shape that no longer exists
|
|
41
|
-
- [ ] Contract tests exist at the boundary, not only unit tests on each side. Two sides each passing their own tests is exactly the state in which drift survives.
|
|
42
|
-
- [ ] Something in CI fails when the schema and the implementation disagree. If not, that missing check is the finding that generates all the others.
|
|
41
|
+
- [ ] Test fixtures are validated against the schema — `search_code` test setup for the fixture being passed through the schema's own parser/validator before use. A fixture that drifted from the contract makes the suite pass against a shape that no longer exists, and the tests then actively hide the drift.
|
|
42
|
+
- [ ] Contract tests exist at the boundary, not only unit tests on each side — `search_code` for a contract-testing tool: a Pact consumer test producing a `*.pact.json`/`pacts/` artefact plus a provider-side verification step that replays it (from disk or a Pact Broker), a Spring Cloud Contract stub, or a shared fixture package consumed by both producer and consumer — versus tests that only exercise one side in isolation. Two sides each passing their own tests is exactly the state in which drift survives; a pact file with no matching provider-verification step in CI is half the mechanism, and behaves like having none.
|
|
43
|
+
- [ ] Something in CI fails when the schema and the implementation disagree — `search_code` the CI workflow files for a schema-diff, contract-test, or codegen-verification step. If not, that missing check is the finding that generates all the others.
|
|
44
|
+
|
|
45
|
+
## Out of static reach
|
|
46
|
+
|
|
47
|
+
- Whether a consumer outside this repo — a mobile app, a partner integration — reads a field this module cannot see.
|
|
48
|
+
- Runtime behaviour when a field the schema promises is actually absent on the wire under a server-side conditional this audit didn't trace.
|
|
49
|
+
- Whether a client's "tolerant" handling of extra fields is truly forward-compatible, or merely untested against a field's removal.
|
|
50
|
+
- The provider's actual current schema version, when the local copy is unpinned — this module reads what's committed, not what production serves.
|
|
51
|
+
- The historical intent behind an intentionally undocumented endpoint (internal-only, deprecated-but-kept) versus true drift.
|
|
43
52
|
|
|
44
53
|
## Severity guidance
|
|
45
54
|
|
|
@@ -55,4 +64,6 @@ A contract is a promise written in two or more places. This module checks whethe
|
|
|
55
64
|
| Declared error responses that do not match reality | Medium |
|
|
56
65
|
| Duplicated shared types with no equivalence test | Medium |
|
|
57
66
|
| No CI check that schema and implementation agree | Medium |
|
|
67
|
+
| Streaming event shape drifted from the declared `itemSchema` | Medium |
|
|
68
|
+
| Pact file with no provider-side verification wired into CI | Medium |
|
|
58
69
|
| Client rejecting unknown fields | Low |
|