mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-02 14:32:45 +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.
87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
# Test cases for max-tools-require-serializer rule
|
|
# This file is used by `semgrep --test` to verify the rule works correctly.
|
|
#
|
|
# Note: This rule only applies to files named max_tools.py, but semgrep's test
|
|
# framework runs tests against this .py file directly, so we test the patterns here.
|
|
|
|
from products.feature_flags.backend.api.feature_flag import FeatureFlagSerializer
|
|
from insights.models import Tag, TaggedItem
|
|
from products.feature_flags.backend.models.feature_flag import FeatureFlag
|
|
|
|
from products.experiments.backend.models.experiment import Experiment
|
|
from products.surveys.backend.models import Survey
|
|
|
|
# ============================================================
|
|
# max-tools-direct-model-create (WARNING - should use serializer)
|
|
# ============================================================
|
|
|
|
|
|
def vulnerable_direct_create(team):
|
|
# ruleid: max-tools-direct-model-create
|
|
flag = FeatureFlag.objects.create(team=team, key="test-flag", name="Test Flag")
|
|
return flag
|
|
|
|
|
|
def vulnerable_direct_create_multiline(self, flag_schema, filters):
|
|
# ruleid: max-tools-direct-model-create
|
|
FeatureFlag.objects.create(
|
|
team=self._team,
|
|
created_by=self._user,
|
|
key=flag_schema.key,
|
|
name=flag_schema.name,
|
|
active=flag_schema.active,
|
|
filters=filters,
|
|
)
|
|
|
|
|
|
# ============================================================
|
|
# OK cases - should NOT trigger the rule
|
|
# ============================================================
|
|
|
|
|
|
def safe_using_serializer(data, request):
|
|
# Using serializer - correct pattern
|
|
# ok: max-tools-direct-model-create
|
|
serializer = FeatureFlagSerializer(data=data, context={"request": request})
|
|
serializer.is_valid(raise_exception=True)
|
|
flag = serializer.save()
|
|
return flag
|
|
|
|
|
|
def safe_different_model(team_id):
|
|
# Different model not in the list
|
|
# ok: max-tools-direct-model-create
|
|
Tag.objects.create(name="test-tag", team_id=team_id)
|
|
|
|
|
|
def safe_tagged_item(tag, flag):
|
|
# TaggedItem not in list - no dedicated serializer
|
|
# ok: max-tools-direct-model-create
|
|
TaggedItem.objects.create(tag=tag, feature_flag=flag)
|
|
|
|
|
|
def safe_experiment_not_in_list(team):
|
|
# Experiment not in list yet
|
|
# ok: max-tools-direct-model-create
|
|
Experiment.objects.create(team=team, name="test")
|
|
|
|
|
|
def safe_survey_not_in_list(team):
|
|
# Survey not in list yet
|
|
# ok: max-tools-direct-model-create
|
|
Survey.objects.create(team=team, name="test")
|
|
|
|
|
|
def safe_get_or_create(team):
|
|
# get_or_create is different
|
|
# ok: max-tools-direct-model-create
|
|
FeatureFlag.objects.get_or_create(team=team, key="test")
|
|
|
|
|
|
def safe_filter_and_get(team):
|
|
# filter/get operations are fine
|
|
# ok: max-tools-direct-model-create
|
|
FeatureFlag.objects.filter(team=team, key="test")
|
|
# ok: max-tools-direct-model-create
|
|
FeatureFlag.objects.get(team=team, key="test")
|