import json
p='/tmp/pom-tests-sql.json'; A=json.load(open(p))
# name: purpose, classification, restates, reason
M={
'setup: claimant should see the health paper':('Confirm the claimant can see the member health paper','behavior','no','The setup guard checks the live can_see_item result for the seeded claimant and paper.'),
'setup: person scope should stay on health':('Keep a person-scoped incapacity grant at health-only access','behavior','no','The setup guard checks the live incapacity grant level for the seeded person-scoped request.'),
'setup: a non-claimant should get nothing':('Deny incapacity access to a person who is not a claimant','behavior','no','The setup guard checks that the live grant helper returns none for a non-claimant.'),
'revert rule 6: health paper still opens':('Keep an unrecognized health paper inaccessible','behavior','no','The test replaces the health-paper classifier with false, then checks runtime item visibility.'),
'revert scope: person scope did not open the map':('Detect when ignoring person scope incorrectly grants map access','behavior','no','The test replaces the grant helper with a person-scope-blind version, then checks the resulting live grant.'),
'revert claimant: a non-claimant still gets nothing':('Detect when designation membership incorrectly grants a non-claimant access','behavior','no','The test substitutes designation-only claimant logic and checks the resulting live grant for a non-claimant.'),
'revert clock: day 31 stayed closed':('Detect when a filed incapacity request remains effective after day 30','behavior','no','The test removes the age condition from the grant helper and checks its live result for a 31-day-old request.'),
'setup raise: map should stay closed':('Keep map access closed before a raised incapacity request is opened','behavior','no','The setup guard checks the live grant while the request is still person-scoped at rung 4.'),
'revert raise: live level did not open the map, got %':('Detect a raised designation taking effect before the next Open action','behavior','no','The test substitutes immediate live-level logic, lowers the open request to rung 2, and checks the resulting grant.'),
'revert expiry: month 13 stayed closed':('Detect an open incapacity request that remains effective past its one-year expiry','behavior','no','The test removes the expiry predicate, runs the sweep, and checks the mutated grant helper result.'),
'revert estate box: map stayed closed without the tick':('Detect estate map access granted before the guardian confirmation tick','behavior','no','The test replaces the grant helper with an estate-scope check that ignores guardian confirmation and checks its runtime result.'),
'revert map: item id was not in the column set':('Require the financial-map function result to expose an item_id column','internals','yes','This checks the declared TABLE result through pg_get_function_result rather than invoking the mapper.'),
'revert map: column set stayed the locked four':('Keep the financial-map function result limited to its locked four columns','internals','yes','This checks the declared TABLE result through pg_get_function_result rather than exercising a query result.'),
'revert case: map_count was absent':('Confirm the case response can contain map_count in the negative-control mutation','behavior','no','The test installs a function returning map_count, invokes it, and fails if that runtime key is absent.'),
'revert death: could not find the end step':('Find the verified-death cleanup section before removing it for the mutation test','mixed','partial','This checks exact source anchors in verify_death; the same test block then executes the mutated function and checks runtime state.'),
'revert death: end step still in the definition':('Ensure the verified-death cleanup section was removed before the mutation test','mixed','partial','This inspects the modified function definition; the same test block then checks status and access after invoking it.'),
'revert death: status assertion still passed':('Detect when removing verified-death cleanup leaves the request ended','mixed','partial','The test executes a source-mutated verify_death and checks persisted request status; the mutation itself is a source-level change.'),
'revert death: access stayed open':('Ensure verified death still closes item access after the cleanup mutation','mixed','partial','The test executes a source-mutated verify_death and checks item visibility; the scenario combines source mutation and runtime behavior.'),
'revert supersede: could not find the earlier-open loop':('Find the earlier-request filter before disabling supersede for the mutation test','mixed','partial','This checks the exact source predicate before mutation; the same block invokes open_step_in_request and inspects persisted status.'),
'revert supersede: the first request still ended':('Detect when opening a new request still ends the earlier request after disabling supersede','mixed','partial','The test invokes the source-mutated open_step_in_request and checks the earlier request status.'),
'revert expired: could not find the reason':('Find the expired-reason assignment before changing it for the mutation test','mixed','partial','This checks the exact source assignment before mutation; the same block runs the sweep and inspects the persisted reason.'),
'revert expired: the reason stayed expired':('Detect when the expiry sweep still writes expired after changing its assignment','mixed','partial','The test runs the source-mutated sweep and checks the stored ended_reason.'),
'revert member_ended: could not find the reason':('Find the member-ended assignment before changing it for the mutation test','mixed','partial','This checks the exact source assignment before mutation; the same block calls end_step_in_access and inspects the stored reason.'),
'revert member_ended: the reason stayed member_ended':('Detect when ending access still writes member_ended after changing its assignment','mixed','partial','The test invokes the source-mutated end_step_in_access and checks the stored ended_reason.'),
'revert map log: a map row was still written':('Do not write a map-open audit row when the map logger is disabled','behavior','no','The test substitutes a logger that returns for map reads, invokes the financial map, and checks persisted audit rows.'),
'revert share: could not find the share rule':('Find the revoked-share predicate before disabling it for the mutation test','mixed','partial','This checks the exact source predicate before mutation; the same block creates a share and checks its audit effect.'),
'revert share: the log stayed quiet':('Detect when a shared-paper read fails to write its audit event after disabling the share predicate','mixed','partial','The test runs the source-mutated visibility helper, shares the paper, and checks the persisted audit event.'),
'revert name: them did not come back':('Confirm the pronoun fallback returns them in the negative-control mutation','behavior','no','The test installs a fallback returning them and invokes the helper to check the runtime value.'),
'GUARD DID NOT FIRE: %':('Fail the smoke-test helper when an expected guard statement succeeds','internals','no','This is the expect_error helper sentinel: it raises when the dynamic statement succeeds instead of raising the expected guard error.'),
'UNEXPECTED MESSAGE for %: wanted prefix %, got % (sqlstate %)':('Fail the smoke-test helper when a guard error message has the wrong prefix','internals','no','This is expect_error harness validation of the caught error message, not a production SQL assertion.'),
'UNEXPECTED SQLSTATE for %: wanted P0001, got % (%)':('Fail the smoke-test helper when an expected guard raises the wrong SQLSTATE','internals','no','This is expect_error harness validation of the caught SQLSTATE, not a production SQL assertion.'),
'CONSTRAINT DID NOT FIRE: %':('Fail the smoke-test helper when an expected constraint violation does not occur','internals','no','This is the expect_constraint helper sentinel for a successful dynamic statement.'),
'UNEXPECTED SQLSTATE for %: wanted constraint %, got P0001 (%)':('Fail the smoke-test helper when a guard exception substitutes for a constraint violation','internals','no','This is expect_constraint harness validation that the statement failed for a database constraint, not a guard RAISE.'),
'UNEXPECTED CONSTRAINT for %: wanted %, got % (sqlstate %: %)':('Fail the smoke-test helper when the wrong database constraint is violated','internals','no','This is expect_constraint harness validation of the actual constraint name.'),
'S0 onto seed missing published version':('Require a published ontology version before the physical-schema smoke checks','internals','no','This is a smoke-test prerequisite check against seeded catalog state.'),
'S0 legal_full_name/party.person missing':('Require the published legal_full_name property for party.person','internals','no','This is a smoke-test catalog prerequisite, not a behavior assertion.'),
'S0 write_item_assertion missing':('Require the write_item_assertion entry point before smoke tests','internals','yes','The guard asserts the deployed SQL function signature exists via to_regprocedure.'),
'S0 add_entity_relation missing':('Require the add_entity_relation entry point before smoke tests','internals','yes','The guard asserts the deployed SQL function signature exists via to_regprocedure.'),
'S0 retract_entity_relation missing':('Require the retract_entity_relation entry point before smoke tests','internals','yes','The guard asserts the deployed SQL function signature exists via to_regprocedure.'),
'S0 add_entity_relation must be SECURITY DEFINER owned by persynl_lifecycle':('Require add_entity_relation to be SECURITY DEFINER and lifecycle-owned','internals','yes','The guard checks pg_proc security-definer and owner metadata.'),
'S0 retract_entity_relation must be SECURITY DEFINER owned by persynl_lifecycle':('Require retract_entity_relation to be SECURITY DEFINER and lifecycle-owned','internals','yes','The guard checks pg_proc security-definer and owner metadata.'),
'S0 proposal lifecycle missing':('Require the proposal promotion, merge, and discard SQL entry points','internals','yes','The guard asserts deployed function signatures exist via to_regprocedure.'),
'S1 identity domain not stamped: %':('Stamp the party.person domain on the upserted identity assertion','behavior','no','The smoke test calls the identity upsert and checks the persisted assertion domain.'),
'S2 write_item_assertion did not stamp domain':('Stamp a domain on a written item assertion','behavior','no','The smoke test calls write_item_assertion and checks the persisted assertion domain.'),
'S3 parent_of set size %':('Keep both parent_of assertions current after inserting two relations','behavior','no','The smoke test inserts relations and checks the resulting current assertion count.'),
'S3 relation range not stamped: %':('Stamp the party.person range on a parent_of relation assertion','behavior','no','The smoke test creates a relation and checks its persisted range class.'),
'S3 retract left % current parent_of rows':('Retracting one parent_of relation leaves only the other relation current','behavior','no','The smoke test retracts the same relation twice and checks current assertion rows.'),
'S3 retract hard-deleted history':('Retraction preserves the relation assertion as superseded history','behavior','no','The smoke test checks the retracted assertion remains with superseded_at set.'),
'S4 dead _g6_mint_proposed_relation is still installed':('Keep the retired proposed-relation mint helper absent','internals','yes','The guard checks the installed SQL function catalog through to_regprocedure.'),
'S4 expected 2 pending relation identities, got %':('Keep same-key relation proposals distinct across domain and range identities','behavior','no','The smoke test inserts two relation proposal rows and checks both remain pending.'),
'S4 mint property failed: %':('Mint a proposed property with its requested key','behavior','no','The smoke test calls the mint helper and verifies its returned key.'),
'S4 second-domain mint failed: %':('Mint the same proposed property key in another domain','behavior','no','The smoke test calls the mint helper for a second domain and verifies its returned key.'),
'S4 expected 2 pending property identities, got %':('Keep same-key property proposals distinct across domains','behavior','no','The smoke test inserts two property proposal rows and checks both remain pending.'),
'S5 PUBLIC can execute write_item_assertion':('Revoke write_item_assertion execution from PUBLIC','behavior','yes','The guard checks the deployed execute privilege through information_schema.role_routine_grants.'),
'S5 persynl_lifecycle lacks schema USAGE':('Grant persynl_lifecycle USAGE on the public schema','behavior','yes','The guard checks the deployed schema privilege with has_schema_privilege.'),
'S5 service_role cannot execute write_item_assertion':('Grant service_role execute access to write_item_assertion','behavior','yes','The guard checks the deployed execute privilege with has_function_privilege.'),
}
assert len(M)==56, len(M)
for x in A:
 if x.get('framework')!='SQL procedural': continue
 if x['name'] not in M: raise SystemExit('unmapped: '+x['name'])
 purpose,cl,rest,reason=M[x['name']]
 x['purpose']=purpose; x['classification']=cl; x['restates']=rest; x['reason']=reason; x['confidence']='reviewed'
 x['execution_notes']='Reviewed SQL procedural guard in source context; no suites run.'
with open(p,'w') as f: json.dump(A,f,indent=2,ensure_ascii=False);f.write('\n')
print('updated',len(M),'remaining unresolved',sum(1 for x in A if x.get('framework')=='SQL procedural' and (x.get('classification')=='unknown' or x.get('restates')=='unknown')))
from collections import Counter
print('classification',Counter(x['classification'] for x in A if x.get('framework')=='SQL procedural'))
print('restates',Counter(x['restates'] for x in A if x.get('framework')=='SQL procedural'))
