2 """Record one full offline fresh-SBCL run. No relocation or cache management."""
14 ROOT
= pathlib
.Path(__file__
).resolve().parent
.parent
15 BASE
= 'aeb017e4f4846f2e6a701e581d20eef84a8b83d9'
16 POLICY
= '(version 1)(allow default)(deny network*)'
17 NAMES
= ['validation', 'semantics', 'merging', 'associations', 'cxtm', 'occurrences',
18 'prefixes', 'integers', 'decimals', 'dates', 'datetimes', 'timezones', 'typed-names', 'scopes', 'variants']
22 return hashlib
.sha256(path
.read_bytes()).hexdigest()
26 parser
= argparse
.ArgumentParser(description
=__doc__
)
27 parser
.add_argument('--sbcl', default
=os
.environ
.get('SBCL', 'sbcl'))
28 parser
.add_argument('--output', default
=str(ROOT
/ 'reports/slice-14'))
29 args
= parser
.parse_args()
30 runtime
= shutil
.which(args
.sbcl
)
32 raise RuntimeError('SBCL executable not found: ' + args
.sbcl
)
33 output
= pathlib
.Path(args
.output
).resolve()
34 output
.mkdir(parents
=True, exist_ok
=True)
35 protected
= {str(p
.relative_to(ROOT
)): sha(p
) for directory
in ['vendor/cxtm', 'references']
36 for p
in (ROOT
/ directory
).rglob('*') if p
.is_file()}
37 sources
= {str(p
.relative_to(ROOT
)): sha(p
) for directory
in ['src', 'tests', 'scripts']
38 for p
in (ROOT
/ directory
).rglob('*') if p
.is_file() and
39 '__pycache__' not in p
.parts
and p
.suffix
in ['.lisp', '.py', '.sh']}
40 sources
['topic-maps.asd'] = sha(ROOT
/ 'topic-maps.asd')
41 version
= subprocess
.check_output([runtime
, '--version'], text
=True).strip()
42 started
= datetime
.datetime
.now(datetime
.timezone
.utc
).isoformat()
43 with tempfile
.TemporaryDirectory(prefix
='ctm-slice-14-validation-') as temp
:
44 report
= pathlib
.Path(temp
) / 'validation.json'
45 command
= ['/usr/bin/sandbox-exec', '-p', POLICY
, '/usr/bin/env', 'PYTHONDONTWRITEBYTECODE=1',
46 'SBCL=' + runtime
, 'TOPIC_MAPS_REPORT=' + str(report
), str(ROOT
/ 'scripts/test.sh')]
47 result
= subprocess
.run(command
, cwd
=ROOT
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
48 (output
/ 'tests.log').write_bytes(result
.stdout
)
50 raise RuntimeError('Full regression failed: see ' + str(output
/ 'tests.log'))
51 log
= result
.stdout
.decode('utf-8')
53 source
= report
if name
== 'validation' else pathlib
.Path(str(report
) + '.' + name
+ '.json')
54 (output
/ (name
+ '.json')).write_bytes(source
.read_bytes())
55 old
= ROOT
/ 'reports/slice-13'
56 for name
in ['semantics', 'merging', 'associations', 'occurrences', 'prefixes', 'integers', 'decimals', 'dates', 'datetimes', 'timezones', 'typed-names', 'scopes']:
57 key
= 'lexicalProbes' if name
== 'timezones' else 'cases'
58 assert json
.loads((old
/ (name
+ '.json')).read_text())[key
] == json
.loads((output
/ (name
+ '.json')).read_text())[key
], name
59 previous
= json
.loads((old
/ 'cxtm.json').read_text())
60 current
= json
.loads((output
/ 'cxtm.json').read_text())
61 assert previous
['cases'] == current
['cases'][:61]
62 original
= json
.loads((old
/ 'validation.json').read_text())
63 now
= json
.loads((output
/ 'validation.json').read_text())
64 transitions
= [(a
['id'], a
['status'], b
['status']) for a
, b
in zip(original
['cases'], now
['cases']) if a
['status'] != b
['status']]
65 assert transitions
== [(id, 'not-run', 'pass') for id in ['ctm/in/variant-duplicate.ctm', 'ctm/in/variant.ctm', 'ctm/in/variants.ctm', 'ctm/invalid/variant-no-scope.ctm']], transitions
66 assert now
['statuses'] == {'pass': 71, 'fail': 2, 'unsupported': 0, 'not-run': 200}
67 assert current
['contractCounts'] == {'pass': 62, 'fail': 2}
68 actual_dir
= output
/ 'actual'
69 actual_dir
.mkdir(exist_ok
=True)
70 for case
in current
['cases']:
71 if case
['id'] in ['ctm/in/' + n
+ '.ctm' for n
in ['variant', 'variants', 'variant-duplicate']]:
72 (actual_dir
/ (pathlib
.Path(case
['id']).name
+ '.cxtm')).write_bytes(case
['actualCXTM'].encode('utf-8'))
73 document
= (ROOT
/ 'docs/reading-variants.md').read_text()
74 example
= document
.split('```lisp\n', 1)[1].split('\n```', 1)[0]
75 inspection
= subprocess
.run(['/usr/bin/sandbox-exec', '-p', POLICY
, runtime
, '--noinform', '--no-sysinit',
76 '--no-userinit', '--script', '/dev/stdin'], input=example
.encode(), cwd
=ROOT
,
77 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
78 (output
/ 'describe.log').write_bytes(inspection
.stdout
)
79 assert inspection
.returncode
== 0
80 for path
, value
in protected
.items():
81 assert sha(ROOT
/ path
) == value
, path
82 for path
, value
in sources
.items():
83 assert sha(ROOT
/ path
) == value
, path
84 markers
= ['FOUNDATION', 'CTM-IDENTITY-SEMANTICS', 'CTM-MERGING-SEMANTICS', 'CTM-ASSOCIATIONS-SEMANTICS',
85 'CXTM', 'OCCURRENCES', 'PREFIX-DATATYPES', 'INTEGERS', 'DECIMALS', 'DATES', 'DATETIMES', 'TIMEZONES', 'TYPED-NAMES', 'SCOPES', 'VARIANTS']
86 totals
= {marker
: int(re
.search(r
'(?m)^' + marker
+ r
'-PASS: (\d+)', log
).group(1)) for marker
in markers
}
87 evidence
= dict(baseCommit
=BASE
, branch
='codex/ctm-slice-14', runtime
=version
,
88 startedAtUTC
=started
, finishedAtUTC
=datetime
.datetime
.now(datetime
.timezone
.utc
).isoformat(),
89 command
=command
, exitCode
=result
.returncode
, freshSBCL
=True, network
='denied by sandbox-exec',
90 regressionChecks
=totals
, totalLispChecks
=sum(totals
.values()), importedStatuses
=now
['statuses'],
91 transitions
=transitions
, previous61CXTMOutputsAndOutcomesUnchanged
=True, originalCorpusAndReferencesUnchanged
=True,
92 sourceSHA256
=sources
, documentedInspectionPassed
=True,
93 qualification
='Pinned CTM draft-era corpus; regression assertion PASS does not erase the two normative baseline FAILs.',
94 artifactsSHA256
={str(p
.relative_to(output
)): sha(p
) for p
in sorted(output
.rglob('*'))
95 if p
.is_file() and p
.name
!= 'execution.json'})
96 (output
/ 'execution.json').write_text(json
.dumps(evidence
, ensure_ascii
=False, indent
=2) + '\n')
97 print(json
.dumps({k
: evidence
[k
] for k
in ['runtime', 'regressionChecks', 'totalLispChecks', 'importedStatuses', 'transitions']}, sort_keys
=True))
98 print('SLICE-14-VALIDATION-PASS: fresh offline SBCL; retained outputs unchanged; three original Variant comparisons and one specific rejection')
101 if __name__
== '__main__':