Flatten to three packages + extract mizan-runtime
packages/
mizan-runtime/ Framework-agnostic state engine (~150 lines)
Context registry, batched invalidation, fetch primitives
mizan-django/ Django server adapter (was packages/mizan-rpc/adapters/django/)
Codegen moved to mizan-django/generate/
mizan-react/ React adapter (was packages/mizan-csr/adapters/react/)
Removed premature abstractions: mizan-ast, mizan-schema, mizan-rpc,
mizan-csr, mizan-ssr stub packages. The actual architecture is three
concrete packages, not five abstract layers.
mizan-runtime implements the v1 spec: registerContext with params,
scoped invalidation via microtask batching, server-driven invalidation
from mutation responses, mizanFetch for context bundles, mizanCall for
mutations.
264 Django + 33 React tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
0
packages/mizan-django/tests/__init__.py
Normal file
0
packages/mizan-django/tests/__init__.py
Normal file
142
packages/mizan-django/tests/models.py
Normal file
142
packages/mizan-django/tests/models.py
Normal file
@@ -0,0 +1,142 @@
|
||||
from django.contrib.auth.models import (
|
||||
AbstractBaseUser,
|
||||
BaseUserManager,
|
||||
PermissionsMixin,
|
||||
)
|
||||
from django.db import models
|
||||
|
||||
|
||||
class EmailUserManager(BaseUserManager):
|
||||
"""Custom user manager using email as the unique identifier."""
|
||||
|
||||
def create_user(self, email, password=None, **extra_fields):
|
||||
if not email:
|
||||
raise ValueError("Email is required")
|
||||
email = self.normalize_email(email)
|
||||
user = self.model(email=email, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password=None, **extra_fields):
|
||||
extra_fields.setdefault("is_staff", True)
|
||||
extra_fields.setdefault("is_superuser", True)
|
||||
return self.create_user(email, password, **extra_fields)
|
||||
|
||||
|
||||
class EmailUser(AbstractBaseUser, PermissionsMixin):
|
||||
"""Minimal user model with email as USERNAME_FIELD.
|
||||
|
||||
Matches the calling convention used in mizan's test suite:
|
||||
User.objects.create_user(email="...", password="...", is_staff=True)
|
||||
"""
|
||||
|
||||
email = models.EmailField(unique=True)
|
||||
is_staff = models.BooleanField(default=False)
|
||||
is_active = models.BooleanField(default=True)
|
||||
|
||||
objects = EmailUserManager()
|
||||
|
||||
USERNAME_FIELD = "email"
|
||||
REQUIRED_FIELDS = []
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
|
||||
|
||||
# ─── Shape test models ──────────────────────────────────────────────────────
|
||||
|
||||
import uuid
|
||||
|
||||
|
||||
class TimestampMixin(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class Publisher(TimestampMixin):
|
||||
name = models.CharField(max_length=200)
|
||||
country = models.CharField(max_length=100, default="")
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
|
||||
|
||||
class Author(TimestampMixin):
|
||||
name = models.CharField(max_length=200)
|
||||
bio = models.TextField(default="")
|
||||
publisher = models.ForeignKey(
|
||||
Publisher, on_delete=models.CASCADE, related_name="authors"
|
||||
)
|
||||
mentor = models.ForeignKey(
|
||||
"self", on_delete=models.SET_NULL, null=True, blank=True, related_name="mentees"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
|
||||
|
||||
class Tag(models.Model):
|
||||
slug = models.SlugField(primary_key=True, max_length=100)
|
||||
label = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
|
||||
|
||||
class Book(TimestampMixin):
|
||||
title = models.CharField(max_length=300)
|
||||
isbn = models.CharField(max_length=13, unique=True)
|
||||
page_count = models.IntegerField(default=0)
|
||||
is_published = models.BooleanField(default=False)
|
||||
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name="books")
|
||||
editor = models.ForeignKey(
|
||||
Author,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="edited_books",
|
||||
)
|
||||
tags = models.ManyToManyField(Tag, blank=True, related_name="books")
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
|
||||
|
||||
class Chapter(TimestampMixin):
|
||||
book = models.ForeignKey(Book, on_delete=models.CASCADE, related_name="chapters")
|
||||
number = models.IntegerField()
|
||||
title = models.CharField(max_length=300)
|
||||
word_count = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
ordering = ["number"]
|
||||
unique_together = [("book", "number")]
|
||||
|
||||
|
||||
class Section(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
chapter = models.ForeignKey(
|
||||
Chapter, on_delete=models.CASCADE, related_name="sections"
|
||||
)
|
||||
heading = models.CharField(max_length=300)
|
||||
body = models.TextField(default="")
|
||||
position = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
ordering = ["position"]
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
parent = models.ForeignKey(
|
||||
"self", on_delete=models.CASCADE, null=True, blank=True, related_name="children"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
app_label = "tests"
|
||||
46
packages/mizan-django/tests/settings.py
Normal file
46
packages/mizan-django/tests/settings.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Django settings for running mizan's test suite standalone.
|
||||
|
||||
Usage:
|
||||
cd django/
|
||||
pip install -e ".[dev]"
|
||||
pytest
|
||||
"""
|
||||
|
||||
SECRET_KEY = "test-secret-key-for-standalone-tests-only"
|
||||
|
||||
DEBUG = True
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": ":memory:",
|
||||
}
|
||||
}
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"mizan",
|
||||
"tests",
|
||||
]
|
||||
|
||||
AUTH_USER_MODEL = "tests.EmailUser"
|
||||
|
||||
ROOT_URLCONF = "tests.urls"
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
# JWT settings for test_auth.py (can be overridden per-class with @override_settings)
|
||||
JWT_PRIVATE_KEY = "test-secret-key-for-testing-only"
|
||||
JWT_ALGORITHM = "HS256"
|
||||
|
||||
# Session engine (for test_auth.py SessionStore usage)
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.db"
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
]
|
||||
5
packages/mizan-django/tests/urls.py
Normal file
5
packages/mizan-django/tests/urls.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path("api/mizan/", include("mizan.urls")),
|
||||
]
|
||||
Reference in New Issue
Block a user