Files
cproudlock 3ac41c1556
All checks were successful
CI / backend (push) Successful in 1m45s
CI / naming (push) Successful in 2s
CI / frontend (push) Successful in 8s
Back out app auto-seeding; fix report-status + PCTypesStrict bugs (manifest review)
A deep Fable review of the real manifest corpus (READ-ONLY reference) showed the
manifests are an ENFORCEMENT PROGRAM, not an application inventory, and that
auto-seeding the Applications catalog from entry Type + Name was wrong:

- The catalog ALREADY tracks these apps from the classic-shopdb migration, with
  version histories (PC - DMIS, UDC x11 versions, eMX / eDNC, CLM, CSF, Oracle
  Database, FormTracePak). Seeding from manifest labels created DUPLICATES under
  different names (PC-DMIS 2016 vs PC - DMIS; eDNC (bundles NTLARS) vs eMX / eDNC;
  OpenText HostExplorer ShopFloor vs CSF). It also misclassified config drops
  (eMxInfo.txt) as apps and could never match a PC's reported ARP name.
So the seed-applications command + service are removed. Properly linking
manifest entries to the EXISTING catalog is a curated feature, not label-scraping.

Two REAL bugs the review found are fixed and kept:
- Report status (R4): every healthy cycle runs Always/no-detection scripts the
  engine counts as "installed", so keying self-heal off installed>0 marked the
  common scope selfhealed forever and made 'ok' unreachable. Status now derives
  from explicit per-entry self-heal flags only; the stored flag no longer infers
  from action=='installed'; the client kit doc reflects it.
- PCTypesStrict (R5): the runtime engine has no strict handling (preinstall
  runner only). filters.matches_pctype now applies strict only when phase ==
  'preinstall'; simulate + parity thread the scope phase through; the strict test
  uses a preinstall scope.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-12 21:56:18 -04:00

107 lines
4.1 KiB
Python

"""P1 behavioral-parity harness (Gate A).
Proves the model is lossless WITHOUT byte-diffing: for each manifest, import it
into in-memory rows and render it back out, then check that
1. every entry is field-for-field identical (engine-relevant fields only,
dropping _comment and key order), in the same order, AND
2. the same entries fire in the same order for a set of machine-profile
fixtures, using the same filter logic the engine uses (filters.py).
Runs with no database (build_scope produces detached ORM objects whose
relationship lists are read directly), so it is cheap to re-run and wrap in CI.
Output is one readable line per scope.
"""
import json
import os
from .importer import build_scope
from .serializer import scope_to_manifest, canonical_entry
from .filters import applicable_entry_names
_FIXTURES_PATH = os.path.join(os.path.dirname(__file__), 'parityfixtures.json')
def load_fixtures():
with open(_FIXTURES_PATH) as handle:
return json.load(handle)
def check_scope(scopename, phase, original, fixtures):
"""Compare an original manifest against its import+export round-trip."""
rebuilt = scope_to_manifest(build_scope(scopename, phase, original))
orig_apps = original.get('Applications') or []
rebuilt_apps = rebuilt.get('Applications') or []
# Check 0: scope-level fields (Version, Site) round-trip.
firstdiff = None
for key in ('Version', 'Site'):
if str(original.get(key) or '') != str(rebuilt.get(key) or ''):
firstdiff = (f'scope field {key}: '
f'{original.get(key)!r} vs {rebuilt.get(key)!r}')
break
scope_ok = firstdiff is None
# Check 1: field-identical, order-preserving.
identical = 0
if firstdiff is None and len(orig_apps) != len(rebuilt_apps):
firstdiff = (f'entry count {len(orig_apps)} vs {len(rebuilt_apps)}')
for i in range(min(len(orig_apps), len(rebuilt_apps))):
co = canonical_entry(orig_apps[i])
cr = canonical_entry(rebuilt_apps[i])
if co == cr:
identical += 1
elif firstdiff is None:
name = orig_apps[i].get('Name', f'#{i}')
diffkeys = sorted(
k for k in set(co) | set(cr) if co.get(k) != cr.get(k))
firstdiff = f'entry "{name}" differs on {diffkeys}'
# Check 2: same entries fire in the same order for each profile. Inject the
# scope phase so PCTypesStrict is honored only for preinstall (see filters).
profiles_same = 0
for base_profile in fixtures:
profile = {**base_profile, 'phase': phase}
if (applicable_entry_names(orig_apps, profile)
== applicable_entry_names(rebuilt_apps, profile)):
profiles_same += 1
elif firstdiff is None:
firstdiff = f'filter mismatch for profile {profile.get("label")}'
passed = (scope_ok
and identical == len(orig_apps) == len(rebuilt_apps)
and profiles_same == len(fixtures))
return {
'scopename': scopename,
'phase': phase,
'entries_total': len(orig_apps),
'entries_identical': identical,
'profiles_total': len(fixtures),
'profiles_same': profiles_same,
'passed': passed,
'firstdiff': firstdiff,
}
def run_parity(manifests, fixtures=None):
"""Run parity over a list of (scopename, phase, manifest_dict). Returns
(results, all_passed)."""
fixtures = fixtures if fixtures is not None else load_fixtures()
results = [check_scope(name, phase, manifest, fixtures)
for name, phase, manifest in manifests]
return results, all(r['passed'] for r in results)
def format_result(result):
"""One human-readable line for a scope result."""
status = 'PASS' if result['passed'] else 'FAIL'
line = (f"scope {result['scopename']:<28} "
f"entries {result['entries_identical']}/{result['entries_total']} identical "
f"profiles {result['profiles_same']}/{result['profiles_total']} same-fire "
f"{status}")
if not result['passed'] and result['firstdiff']:
line += f"\n -> {result['firstdiff']}"
return line