fix(release): gate generated Prisma client against live production catalog

This commit is contained in:
devops committed 2026-10-25 12:43:20 +00:00
1 parent 2a341d3969
commit cf9b80bbb3
3 files changed
+139 -2

No files matched your search

@@ -0,0 +1,56 @@
"""Generated-client drift must block a release even with unchanged Git schema."""
import importlib.util
from pathlib import Path
import unittest
SPEC = importlib.util.spec_from_file_location('release', Path(__file__).parents[1]/'production-release.py')
m = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(m)
class SchemaGate(unittest.TestCase):
def test_unchanged_source_baseline_new_client_drift(self):
# Both Git SHAs already contain these fields; the old runtime client did not.
models = [{'name':'User','dbName':'users','fields':[
{'name':n,'dbName':n,'kind':'scalar','type':t,'isList':False}
for n,t in [('id','String'),('auth_expires_at','DateTime'),
('stage_test_session','String'),('stage_test_generation','String')]]},
{'name':'PrepareWorkflowOutbox','dbName':'prepare_workflow_outbox','fields':[
{'name':'id','kind':'scalar','type':'String','isList':False}]}]
old_catalog = [{'table':'users','column':'id','type':'uuid'}]
with self.assertRaisesRegex(ValueError, 'auth_expires_at.*prepare_workflow_outbox'):
m.validate_catalog(models, old_catalog)
def test_gate_pins_built_image_and_reads_live_catalog_before_replacement(self):
import json
from unittest.mock import patch
image = 'sha256:'+'c'*64
runtime = {'Image':'sha256:'+'d'*64,'Id':'running-id','State':{'Running':True}}
models = [{'name':'User','dbName':'users','fields':[{'name':'id','kind':'scalar'}]}]
responses = [json.dumps([runtime]), json.dumps([{'Id':image}]),
json.dumps(models), json.dumps([{'table':'users','column':'id','type':'uuid'}]),
json.dumps([runtime])]
with patch.object(m.subprocess,'check_output',side_effect=responses) as run:
result = m.schema_gate('canina-production-backend_prod:'+'a'*40)
self.assertEqual(result['target_image'], image)
calls = [c.args[0] for c in run.call_args_list]
self.assertIn(image, calls[2])
self.assertIn('--network', calls[2])
self.assertIn('running-id', calls[3])
self.assertIn('READ ONLY', calls[3][-1])
script = Path(__file__).parents[1].joinpath('rollout-production.sh').read_text()
self.assertLess(script.index('production-release.py schema-check'), script.index('started=true'))
def test_catalog_failure_never_falls_back_to_source_diff(self):
from unittest.mock import patch
import subprocess
with patch.object(m.subprocess,'check_output',side_effect=subprocess.CalledProcessError(1,['docker'])):
with self.assertRaises(subprocess.CalledProcessError):
m.schema_gate('target')
def test_exact_guard_paths_allowed_and_receipt_not_bound_to_checkout(self):
self.assertIn('scripts/tests/test_release_schema_guard.py', m.ALLOWED)
source = Path(__file__).parents[1].joinpath('production-release.py').read_text()
self.assertNotIn("['git','-C','/opt/services/canina/prod','rev-parse','HEAD']", source)
self.assertIn("r.get('production_images')", source)
if __name__ == '__main__': unittest.main()