mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-03 00:52:32 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
57 lines
2.7 KiB
YAML
57 lines
2.7 KiB
YAML
rules:
|
|
- id: api-response-must-match-schema
|
|
message: |
|
|
Returning a hand-assembled dict from a product viewset is a common
|
|
source of spec drift. The OpenAPI schema for this endpoint is built
|
|
from its `serializer_class` or `@extend_schema(responses=...)`
|
|
declaration — nothing checks that the dict you returned actually
|
|
matches that schema. When they diverge, generated FE types and MCP
|
|
tool schemas silently lie about the wire shape.
|
|
|
|
Why this matters: spectacular trusts the declaration, not the
|
|
runtime. A `Response({"foo": ...})` next to a `@extend_schema(
|
|
responses=FooSerializer)` produces a wrong-but-plausible spec that
|
|
flows downstream into `api.schemas.ts`, MCP tool definitions, and
|
|
anything else generated from `openapi.json`.
|
|
|
|
Instead of:
|
|
return Response({"id": str(run.id), "status": run.status, ...})
|
|
|
|
Use:
|
|
return Response(FooSerializer(instance=foo).data)
|
|
|
|
For products on the facade layout (visual_review-style), construct
|
|
a contract dataclass and pass it through a `DataclassSerializer` —
|
|
that gives you runtime type validation on top of spec alignment. See
|
|
the `isolating-product-facade-contracts` skill.
|
|
|
|
This rule is currently informational (WARNING severity). Findings
|
|
are the backlog of viewsets still assembling responses by hand.
|
|
Once a product's count hits zero, the path can be narrowed and
|
|
severity flipped to ERROR for that product.
|
|
languages: [python]
|
|
severity: WARNING
|
|
paths:
|
|
include:
|
|
- 'products/*/backend/'
|
|
# Test fixture lives here — must be in include so `semgrep --test` exercises the rule.
|
|
- '.semgrep/rules/devex/'
|
|
exclude:
|
|
- '**/tests/**'
|
|
- '**/test_*.py'
|
|
- '**/conftest.py'
|
|
patterns:
|
|
- pattern-either:
|
|
- pattern: return Response({...}, ...)
|
|
- pattern: return Response({...})
|
|
- pattern: return Response(data={...}, ...)
|
|
# Error / pagination / ack idioms are conventional DRF shapes — not
|
|
# data payloads. Match the dict's *first key* so we don't accidentally
|
|
# exempt larger payloads that happen to contain one of these names.
|
|
# `(?:data=)?` covers both `Response({...})` and `Response(data={...})`.
|
|
- pattern-not-regex: 'Response\(\s*(?:data=)?\{\s*"(detail|error|errors|message|status|success|ok|results|count|next|previous)"\s*:'
|
|
metadata:
|
|
category: best-practice
|
|
subcategory:
|
|
- audit
|