Preserve pinned legacy SQL exclusions across Development branches

This commit is contained in:
Atlas Development Worker 2026-12-02 20:13:29 +00:00
parent e6b2a6d239
commit 217c3003e5
3 changed files with 17 additions and 2 deletions

View File

@ -9,7 +9,7 @@ PLAN_FIELDS = ('starting_schema_sha256', 'resulting_schema_sha256', 'migrations'
'omitted_migrations', 'prerequisites', 'postconditions', 'qualification')
def plan_source(source, baseline, sql):
def plan_source(source, baseline, sql, historical_source=None):
"""Keep every recorded hash; append new numbered migrations in filename order."""
import shutil
sql = Path(sql)
@ -27,6 +27,11 @@ def plan_source(source, baseline, sql):
elif candidate.stem in omitted or name in omitted:
item = omitted.get(candidate.stem, omitted.get(name))
require(file_digest(candidate) == item['sha256'], 'Omitted historical SQL changed: '+name)
elif historical_source and historical_source.get(name) == file_digest(candidate):
# Some legacy SQL was never part of the ledger (for example a
# superseded runtime-permissions script). Preserve its exclusion only
# when the actual successful source tree has the exact same bytes.
continue
elif re.fullmatch(r'[0-9]{3,}_[A-Za-z0-9_.-]+\.sql', name):
pending.append(candidate)
previous = plan['migrations'][-1]['id']

View File

@ -84,7 +84,8 @@ def main():
evidence = output/'evidence'
shutil.copytree(BASELINE/'evidence', evidence)
sql = output/'sql'
plan, pending = plan_source(source, baseline, sql)
historical_source = load(BASELINE/'legacy-source-sql.json')['files']
plan, pending = plan_source(source, baseline, sql, historical_source)
for step in baseline['migrations']:
shutil.copyfile(BASELINE/'sql'/step['file'], sql/step['file'])
qualification = None

View File

@ -49,6 +49,15 @@ class PlanTests(unittest.TestCase):
(self.old.parent/'339_Collision.sql').write_text('SELECT 1;')
with self.assertRaises(Refused): plan_source(self.source,self.baseline,self.root/'sql2')
def test_reviewed_legacy_source_exclusion_cannot_adopt_changed_or_new_sql(self):
legacy=self.old.parent/'320_Legacy.sql'
legacy.write_text('SELECT 1;')
index={legacy.name:file_digest(legacy)}
plan,pending=plan_source(self.source,self.baseline,self.root/'sql',index)
self.assertFalse(pending)
legacy.write_text('SELECT 2;')
with self.assertRaises(Refused):plan_source(self.source,self.baseline,self.root/'changed',index)
def test_broker_rejects_history_changes_and_path_substitution(self):
for field,value in [('mode','baseline'),('file','../outside.sql'),('requires',[])]:
plan=copy.deepcopy(self.baseline)