import pathlib,ast,json
R=pathlib.Path('/Users/dave/Code/pom-vault');rows=[]
static={'test_scripts_never_touch_supabase','test_no_terraform_cfn_futurevault','test_no_terraform_no_futurevault_call','test_scripts_use_nested_status_and_dev_stage'}
meta={'test_files_exist','test_scripts_are_executable','test_docs_name_the_operator_steps','test_env_example_lists_project_name_and_role','test_input_is_retention_inventory','test_output_is_outside_dropped_schema'}
overrides={
 'test_attach_uses_hasher_and_callback_shape':('mixed','no','Confirms missing database yields failure through injected dependencies; callback assertions also pin collaborator arguments.'),
 'test_two_paths_same_sha_second_run':('mixed','partial','Production orchestration runs, but the fake attach callback implements blob deduplication and item creation itself. Counts partly validate the fake rather than real SQL storage.'),
 'test_quotes_title_and_uses_create_item_mine':('internals','yes','Checks generated SQL for chosen writer calls, INSERT fragments and absence of extract text; does not execute it to prove quoting, visibility or deduplication.'),
 'test_user_data_has_caddy_and_deploy_user':('mixed','partial','Checks generated cloud-init output but pins package command order and exact YAML fragments without booting an instance.'),
 'test_nested_get_status_fixture':('mixed','partial','Checks query literal and separately indexes fixture fields; does not execute the returned query against the fixture.'),
}
for p in sorted((R/'scripts').glob('*test*.py')):
 s=p.read_text(); tree=ast.parse(s)
 for n in ast.walk(tree):
  if not isinstance(n,ast.FunctionDef) or not n.name.startswith('test_'):continue
  body=ast.get_source_segment(s,n); name=n.name
  cl,rest,reason='behavior','no','Asserts function results, CLI outputs/refusals or emitted requests against independent fixture expectations.'
  if name in static:cl,rest,reason='internals','yes','Scans script source for required/forbidden implementation strings; does not exercise the claimed operational restriction.'
  elif name in meta:cl,rest,reason='internals','no','Checks packaging, documentation or configured path contract; does not prove runtime product behavior.'
  if name in overrides:cl,rest,reason=overrides[name]
  rows.append(dict(file=str(p.relative_to(R)),line=n.lineno,name=name,purpose=name.removeprefix('test_').replace('_',' ').capitalize()+'.',classification=cl,restates=rest,reason=reason,execution_notes='Python test function; not executed. Fixture/CLI dependencies vary; AWS harness is designed for stubbed/dry-run checks.',evidence=body,confidence='reviewed assertions',framework='Python'))
for f,purpose in [('test_catalog_metadata.py','Validates catalog metadata generation, published mappings, lock-text guards, migration immutability, and invalid ontology fixtures.'),('test_document_kinds.py','Validates document-kind generation determinism, coverage, clarification choices, target mappings and invalid ontology refusal.')]:
 p=R/'product/persynl-physical-data-model'/f;s=p.read_text();n=next(n for n in ast.parse(s).body if isinstance(n,ast.FunctionDef) and n.name=='main')
 rows.append(dict(file=str(p.relative_to(R)),line=n.lineno,name='main fixture harness',purpose=purpose,classification='mixed',restates='partial',reason='Combines real generator/invalid-input behavior with hard-coded catalog and generated SQL structure checks. Kept as one monolithic declared harness, not one row per assertion.',execution_notes='Direct Python entrypoint; requires ontology dependencies. Not included in npm test. Not executed.',evidence=ast.get_source_segment(s,n),confidence='reviewed representative checks; grouped harness',framework='Python script'))
for line,name,purpose in [(33,'clean TAP passes','Accept a TAP stream whose plan matches passing results.'),(38,'plan mismatch fails','Reject a TAP stream with fewer results than its plan.'),(43,'not ok fails','Reject a TAP stream with a failing assertion.')]:
 rows.append(dict(file='scripts/tap-check.sh',line=line,name=name,purpose=purpose,classification='behavior',restates='no',reason='Feeds synthetic TAP output to the actual protocol checker and tests its exit status.',execution_notes='Run with --self-test; not executed.',confidence='reviewed',framework='Shell'))
pathlib.Path('/tmp/pom-tests-scripts.json').write_text(json.dumps(rows,indent=2));print('rows',len(rows))
