gabriel / musehub public
test_server_defaults.py python
107 lines 3.4 KB
Raw
sha256:a34090cc4a394a78bd72cbbe34b08cc59525141e19135b6c0ab154f10611b9ef debug(push/stream): instrument O-frame decode path with INF… Sonnet 4.6 patch 126 days ago
1 """All non-nullable columns with a Python-side default must also have a
2 server_default so that raw SQL inserts (migrations, scripts, bulk loads)
3 produce a valid row without specifying the value.
4
5 This covers the two most impactful categories:
6 - Booleans — always has a well-defined safe value (true / false)
7 - String enums / sentinel strings — open, pending, public, human, etc.
8 """
9 from __future__ import annotations
10
11 import pytest
12
13 from musehub.db.coord_models import MusehubCoordTask
14 from musehub.db.musehub_collaborator_models import MusehubCollaborator
15 from musehub.db.musehub_domain_models import MusehubDomain
16 from musehub.db.musehub_models import (
17 MusehubBackgroundJob,
18 MusehubBridgeMirror,
19 MusehubIdentity,
20 MusehubIntelApiSurface,
21 MusehubIntelBreakageIssue,
22 MusehubIntelClones,
23 MusehubIntelEntangle,
24 MusehubIntelResult,
25 MusehubIntelStable,
26 MusehubIntelType,
27 MusehubIssue,
28 MusehubIssueComment,
29 MusehubMist,
30 MusehubProfileSnapshot,
31 MusehubProposal,
32 MusehubProposalReview,
33 MusehubRelease,
34 MusehubRepo,
35 MusehubSession,
36 MusehubWebhook,
37 MusehubWebhookDelivery,
38 )
39
40
41 def _server_default(model, col_name: str):
42 return model.__table__.columns[col_name].server_default
43
44
45 def _assert_has_server_default(model, col_name: str) -> None:
46 sd = _server_default(model, col_name)
47 assert sd is not None, (
48 f"{model.__name__}.{col_name} has no server_default — "
49 "raw SQL inserts will fail or produce NULL"
50 )
51
52
53 # ---------------------------------------------------------------------------
54 # Booleans
55 # ---------------------------------------------------------------------------
56
57 BOOL_COLS = [
58 (MusehubRepo, "training_opt_out"),
59 (MusehubIdentity, "is_verified"),
60 (MusehubIssueComment, "is_deleted"),
61 (MusehubRelease, "is_draft"),
62 (MusehubWebhook, "active"),
63 (MusehubWebhookDelivery, "success"),
64 (MusehubSession, "is_active"),
65 (MusehubIntelEntangle, "structurally_linked"),
66 (MusehubIntelStable, "since_start"),
67 (MusehubIntelType, "return_is_any"),
68 (MusehubBridgeMirror, "auto_export"),
69 (MusehubProfileSnapshot, "is_stale"),
70 (MusehubDomain, "is_verified"),
71 (MusehubDomain, "is_deprecated"),
72 ]
73
74
75 @pytest.mark.parametrize("model,col", BOOL_COLS, ids=[f"{m.__name__}.{c}" for m, c in BOOL_COLS])
76 def test_bool_has_server_default(model, col):
77 _assert_has_server_default(model, col)
78
79
80 # ---------------------------------------------------------------------------
81 # String enums / sentinel strings
82 # ---------------------------------------------------------------------------
83
84 STR_ENUM_COLS = [
85 (MusehubRepo, "visibility"),
86 (MusehubIdentity, "identity_type"),
87 (MusehubIssue, "state"),
88 (MusehubProposal, "state"),
89 (MusehubProposalReview, "state"),
90 (MusehubRelease, "channel"),
91 (MusehubSession, "schema_version"),
92 (MusehubBackgroundJob, "status"),
93 (MusehubIntelApiSurface, "visibility"),
94 (MusehubMist, "visibility"),
95 (MusehubIntelBreakageIssue, "severity"),
96 (MusehubBridgeMirror, "git_branch"),
97 (MusehubCollaborator, "permission"),
98 (MusehubCoordTask, "queue"),
99 (MusehubCoordTask, "status"),
100 (MusehubDomain, "version"),
101 (MusehubDomain, "viewer_type"),
102 ]
103
104
105 @pytest.mark.parametrize("model,col", STR_ENUM_COLS, ids=[f"{m.__name__}.{c}" for m, c in STR_ENUM_COLS])
106 def test_str_enum_has_server_default(model, col):
107 _assert_has_server_default(model, col)
File History 1 commit
sha256:a34090cc4a394a78bd72cbbe34b08cc59525141e19135b6c0ab154f10611b9ef debug(push/stream): instrument O-frame decode path with INF… Sonnet 4.6 patch 126 days ago