Commit b9f34a6
committed
review: log schema drift + harden get_composer envelope (#30)
CodeRabbit follow-ups to the round-2 wiring pass:
1. The three bubble-loading loops (api/workspaces.py:583, 1025;
api/search.py:149) caught SchemaError, json.JSONDecodeError and
ValueError together and dropped the row silently. That broke the
read-boundary contract — a drifted bubble would simply vanish with
no operator signal. Split the catches: SchemaError now logs
`Schema drift in bubble <bid>: <reason>`; JSONDecodeError /
ValueError still pass silently because that's a parser-noise issue,
not a schema-contract issue.
2. get_composer() at api/composers.py:125 trusted that the per-workspace
blob was a dict with a list-valued allComposers. A drifted local row
like `[]` or `"…"` raised AttributeError on data.get(...) and turned
schema drift into a 500. Mirrored the three envelope guards
list_composers() already applies at line 60–74 (data is dict,
allComposers present, allComposers is list) and wrapped the outer
try with `except SchemaError` so drift logs the db_path and falls
through to the global fallback instead of 500'ing.
3. scripts/ lacked __init__.py while every other top-level package
directory (api/, models/, utils/, tests/) has one. The new
`from scripts import export` calls in tests resolve at runtime via
the sys.path insert in the test header, but mypy was reporting
inconsistent module resolution on scripts.export — a CI typecheck
risk. Added an empty scripts/__init__.py to match convention.
3 new regression tests in tests/test_models_wired_at_read_sites.py:
- test_bubble_schema_drift_is_logged_not_swallowed_silently —
seeds a malformed bubble, captures stdout, asserts the
`Schema drift in bubble <bid>` line is present.
- test_get_composer_handles_non_dict_envelope_via_fallback —
replaces composer.composerData with a list payload, asserts
the endpoint returns 200 via the global fallback (was 500
before the envelope guards).
- test_get_composer_handles_non_list_all_composers_via_fallback —
same shape for non-list allComposers.
Verified locally:
- python -m unittest discover tests: 223 passed (was 220)
- python -m unittest tests.test_models_wired_at_read_sites: 13/13
- mypy resolves scripts.export consistently1 parent 16f861d commit b9f34a6
5 files changed
Lines changed: 112 additions & 9 deletions
File tree
- api
- scripts
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
128 | 146 | | |
129 | 147 | | |
130 | 148 | | |
| |||
135 | 153 | | |
136 | 154 | | |
137 | 155 | | |
| 156 | + | |
| 157 | + | |
138 | 158 | | |
139 | 159 | | |
140 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
586 | | - | |
587 | | - | |
588 | | - | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
589 | 592 | | |
590 | 593 | | |
591 | 594 | | |
| |||
1022 | 1025 | | |
1023 | 1026 | | |
1024 | 1027 | | |
1025 | | - | |
1026 | | - | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
1027 | 1034 | | |
1028 | 1035 | | |
1029 | 1036 | | |
| |||
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
131 | 163 | | |
132 | 164 | | |
133 | 165 | | |
| |||
289 | 321 | | |
290 | 322 | | |
291 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
292 | 365 | | |
293 | 366 | | |
294 | 367 | | |
| |||
0 commit comments