fix(ci): prepare fail-closed exact-SHA code-only Stage release

This commit is contained in:
Canina Automation committed 2026-10-26 16:42:08 +00:00
1 parent af32ec14e1
commit 52a7aebb51
6 files changed
+141 -10

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
class CacheStageReleaseTests(unittest.TestCase):
def test_develop_uses_isolated_code_only_release(self):
deploy = (ROOT/'scripts/deploy.sh').read_text()
self.assertIn('exec bash "$SCRIPT_DIR/release-cache-stage.sh"', deploy)
workflow = (ROOT/'.gitea/workflows/deploy.yml').read_text()
self.assertIn('/raw/commit/${DEPLOY_SHA}/scripts/', workflow)
self.assertIn('DEPLOY_SHA: ${{ github.sha }}', workflow)
def test_release_is_serialized_and_fail_closed(self):
source = (ROOT/'scripts/release-cache-stage.sh').read_text()
self.assertLess(source.index('flock'), source.index('provision-revalidation-env.py --environment stage'))
self.assertIn('git archive "$DEPLOY_SHA"', source)
self.assertIn('--force-recreate backend_stage frontend_stage', source)
self.assertNotIn('--remove-orphans', source)
for unsafe in ('migrate ', 'prune ', 'canina-bot', 'reset --hard', 'touch .revalidation.env'):
self.assertNotIn(unsafe, source)
self.assertIn('git rev-parse HEAD', source)
self.assertIn('org.opencontainers.image.revision', source)
def test_runtime_secrets_never_enter_frontend_build_context(self):
ignore = (ROOT/'.dockerignore').read_text().splitlines()
self.assertIn('**/.revalidation.env*', ignore)
self.assertIn('**/.support*.env*', ignore)
def test_legacy_empty_secret_requires_explicit_repair(self):
import importlib.util
spec = importlib.util.spec_from_file_location('provision', ROOT/'scripts/provision-revalidation-env.py')
module = importlib.util.module_from_spec(spec); spec.loader.exec_module(module)
with tempfile.TemporaryDirectory() as d:
source, output = Path(d)/'source', Path(d)/'output'
source.touch()
with self.assertRaises(ValueError): module.provision(source, output)
module.provision(source, output, repair_empty=True)
self.assertEqual(source.read_bytes(), output.read_bytes())
self.assertEqual((Path(d)/'source.empty-before-provision').read_bytes(), b'')
if __name__ == '__main__': unittest.main()