2 """Validate Slice 19A in a fresh SBCL 2.5.4 process with network access denied."""
14 ROOT
= pathlib
.Path(__file__
).resolve().parent
.parent
15 BASE
= '0573c4f710982dab1c3f2c9284adf459caaf73e9'
16 POLICY
= '(version 1)(allow default)(deny network*)'
17 NAMES
= ['validation', 'semantics', 'merging', 'associations', 'cxtm', 'occurrences',
18 'prefixes', 'integers', 'decimals', 'dates', 'datetimes', 'timezones',
19 'typed-names', 'scopes', 'variants', 'references', 'identifiers', 'reification', 'arity',
20 'relationships', 'templates', 'map-import']
24 return hashlib
.sha256(path
.read_bytes()).hexdigest()
28 parser
= argparse
.ArgumentParser(description
=__doc__
)
29 parser
.add_argument('--sbcl', default
=os
.environ
.get('SBCL', 'sbcl'))
30 parser
.add_argument('--output', default
=str(ROOT
/ 'reports/slice-19a'))
31 args
= parser
.parse_args()
32 runtime
= shutil
.which(args
.sbcl
)
33 assert runtime
is not None, 'SBCL executable not found'
34 output
= pathlib
.Path(args
.output
).resolve()
35 output
.mkdir(parents
=True, exist_ok
=True)
36 protected
= {str(p
.relative_to(ROOT
)): sha(p
) for directory
in ['vendor/cxtm', 'references']
37 for p
in (ROOT
/ directory
).rglob('*') if p
.is_file()}
38 sources
= {str(p
.relative_to(ROOT
)): sha(p
) for directory
in ['src', 'tests', 'scripts', 'docs']
39 for p
in (ROOT
/ directory
).rglob('*') if p
.is_file() and
40 '__pycache__' not in p
.parts
and p
.suffix
in ['.lisp', '.py', '.sh', '.md']}
41 sources
.update({p
: sha(ROOT
/ p
) for p
in ['topic-maps.asd', 'README.md']})
42 started
= datetime
.datetime
.now(datetime
.timezone
.utc
).isoformat()
43 version
= subprocess
.check_output([runtime
, '--version'], text
=True).strip()
44 assert version
== 'SBCL 2.5.4', version
45 with tempfile
.TemporaryDirectory(prefix
='tmdm-slice-19a-validation-') as temp
:
46 report
= pathlib
.Path(temp
) / 'validation.json'
47 command
= ['/usr/bin/sandbox-exec', '-p', POLICY
, '/usr/bin/env', 'PYTHONDONTWRITEBYTECODE=1',
48 'SBCL=' + runtime
, 'TOPIC_MAPS_REPORT=' + str(report
), str(ROOT
/ 'scripts/test.sh')]
49 result
= subprocess
.run(command
, cwd
=ROOT
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
50 (output
/ 'tests.log').write_bytes(result
.stdout
)
52 raise RuntimeError('Full regression failed: see ' + str(output
/ 'tests.log'))
53 log
= result
.stdout
.decode('utf-8')
55 source
= report
if name
== 'validation' else pathlib
.Path(str(report
) + '.' + name
+ '.json')
56 (output
/ (name
+ '.json')).write_bytes(source
.read_bytes())
57 old
= ROOT
/ 'reports/slice-18'
58 previous
= json
.loads((old
/ 'validation.json').read_text())
59 now
= json
.loads((output
/ 'validation.json').read_text())
60 assert now
['statuses'] == {'pass': 187, 'fail': 2, 'unsupported': 0, 'not-run': 84}
61 assert now
['cases'] == previous
['cases'], 'Imported case records changed'
62 # Every old report must retain its observations, checks and original outputs.
63 # CXTM's scope and additional model-check summary are the only new fields.
64 for name
in NAMES
[1:-1]:
65 prior
= json
.loads((old
/ (name
+ '.json')).read_text())
66 current
= json
.loads((output
/ (name
+ '.json')).read_text())
68 for key
in ['cases', 'contractCounts']:
69 assert prior
[key
] == current
[key
], name
+ ':' + key
71 assert prior
== current
, name
72 example
= (ROOT
/ 'docs/reading-map-content-import.md').read_text().split('```lisp\n', 1)[1].split('\n```', 1)[0]
73 inspection
= subprocess
.run(['/usr/bin/sandbox-exec', '-p', POLICY
, runtime
, '--noinform', '--no-sysinit',
74 '--no-userinit', '--script', '/dev/stdin'], input=example
.encode(), cwd
=ROOT
,
75 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
76 (output
/ 'describe.log').write_bytes(inspection
.stdout
)
77 assert inspection
.returncode
== 0, 'Documented inspection forms failed'
78 # Regression counterprobe: the BASE normalizer rejects the valid Reifier-first
79 # case before the equal reified Names can merge. No second checkout or runtime.
80 control
= '''(require :asdf)
81 (asdf:initialize-source-registry '(:source-registry :ignore-inherited-configuration))
82 (asdf:load-asd (truename "topic-maps.asd"))
83 (asdf:load-system "topic-maps/tmdm/import-tests")
84 (load (make-string-input-stream (uiop:run-program
85 (list "git" "show" "BASE:src/tmdm/merging.lisp") :output :string)))
87 (progn (topic-maps.import.tests::reifier-order-test) (error "Base control did not reproduce the defect"))
88 (topic-maps.tmdm:reification-error (c)
89 (assert (eq :reifier-conflict (topic-maps.tmdm:reification-error-code c)))
90 (format t "BASE-NORMALIZER-CONTROL-PASS: valid Reifier-first import rejected as ~A~%" c)))
91 '''.replace('BASE:', BASE
+ ':')
92 probe
= subprocess
.run(['/usr/bin/sandbox-exec', '-p', POLICY
, runtime
, '--noinform', '--no-sysinit',
93 '--no-userinit', '--script', '/dev/stdin'], input=control
.encode(), cwd
=ROOT
,
94 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
95 (output
/ 'base-normalizer-control.log').write_bytes(probe
.stdout
)
96 assert probe
.returncode
== 0, 'Base normalizer control failed'
97 for path
, value
in protected
.items():
98 assert sha(ROOT
/ path
) == value
, path
99 assert not subprocess
.check_output(['git', 'diff', BASE
, '--', 'vendor', 'references', 'src/ctm', 'src/cxtm'], cwd
=ROOT
)
100 for path
, value
in sources
.items():
101 assert sha(ROOT
/ path
) == value
, path
102 previous_totals
= json
.loads((old
/ 'execution.json').read_text())['regressionChecks']
103 totals
= {marker
: int(re
.search(r
'(?m)^' + marker
+ r
'-PASS: (\d+)', log
).group(1))
104 for marker
in [*previous_totals
, 'MAP-IMPORT']}
105 assert {k
: totals
[k
] for k
in previous_totals
} == previous_totals
106 evidence
= dict(baseCommit
=BASE
, branch
='codex/tmdm-slice-19a', runtime
=version
,
107 startedAtUTC
=started
, finishedAtUTC
=datetime
.datetime
.now(datetime
.timezone
.utc
).isoformat(),
108 command
=command
, exitCode
=result
.returncode
, freshSBCL
=True, network
='denied by sandbox-exec',
109 regressionChecks
=totals
, totalLispChecks
=sum(totals
.values()), importedStatuses
=now
['statuses'],
110 importedStatusChanges
=[], allPriorModelReportsAndCXTMOutputsUnchanged
=True,
111 originalCorpusAndReferencesUnchanged
=True, ctmAndCxtmSourcesUnchanged
=True,
112 documentedInspectionPassed
=True, baseNormalizerCounterprobePassed
=True, sourceSHA256
=sources
,
113 qualification
='TMDM content import model tests only. No CTM import or XTM contract executed. Two DateTime baseline FAILs unchanged.',
114 artifactsSHA256
={str(p
.relative_to(output
)): sha(p
) for p
in sorted(output
.rglob('*'))
115 if p
.is_file() and p
.name
!= 'execution.json'})
116 (output
/ 'execution.json').write_text(json
.dumps(evidence
, ensure_ascii
=False, indent
=2) + '\n')
117 print(json
.dumps({k
: evidence
[k
] for k
in ['runtime', 'regressionChecks', 'totalLispChecks', 'importedStatuses']}, sort_keys
=True))
118 print('SLICE-19A-VALIDATION-PASS: fresh offline regression; all imported contracts and prior model evidence unchanged')
121 if __name__
== '__main__':