diff --git a/.github/workflows/current-site-transition-candidate.yml b/.github/workflows/current-site-transition-candidate.yml new file mode 100644 index 000000000..ebed6a431 --- /dev/null +++ b/.github/workflows/current-site-transition-candidate.yml @@ -0,0 +1,1118 @@ +# SOURCE-FROZEN R1 DRAFT: actual hosted/native/runtime qualification and exact-head review remain pending. +# Keep the independent intentional RED draft PR499 immutable and unmerged. +name: Current reader publication transition candidate +'on': + pull_request: + branches: [main] + paths: + - 'docs/site/current-model.mjs' + - 'docs/site/current.mjs' + - 'docs/site/dependency-model.mjs' + - 'docs/site/atlas.mjs' + - 'docs/site/atlas-shell.mjs' + - 'tools/site_transition_source_guard.py' + - 'tests/test_site_transition_source_guard.py' + - 'tests/test_current_site_transition.mjs' + - 'tests/fixtures/current_site_transition_20261022/**' + - 'tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json' + - 'tools/site_transition_capture_regression.py' + - 'tools/site_transition_capture_regression_supervisor.py' + - 'tools/site_transition_capture_regression_launcher.py' + - 'tests/fixtures/site_transition_capture_regression_20261025/**' + - '.github/workflows/current-site-transition-candidate.yml' +permissions: + contents: read +jobs: + frozen-reader-transition-candidate: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + steps: + - name: Record native event context and tool versions before setup + run: | + python3 -I -B -S - <<'PYCONTEXT' + import json, os, re, resource, signal, subprocess, sys + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + output.mkdir(parents=True, exist_ok=True) + for name in ('tap.stdout.tap', 'tap.stderr.txt'): + (output / name).write_bytes(b'') + (output / 'node-exit-code.txt').write_text('NOT_RUN\n') + event_raw = Path(os.environ['GITHUB_EVENT_PATH']).read_bytes() + event = json.loads(event_raw) + pr = event.get('pull_request') or {} + def version(command): + target = output / 'version.tmp' + child = None + def limit(): + resource.setrlimit(resource.RLIMIT_FSIZE, (128, 128)) + try: + with target.open('wb') as stream: + child = subprocess.Popen(command, stdout=stream, stderr=subprocess.DEVNULL, + start_new_session=True, preexec_fn=limit) + code = child.wait(timeout=5) + value = target.read_bytes() + if code != 0 or len(value) >= 128: + return {'status': 'UNAVAILABLE'} + value = value.decode('ascii').strip() + if not re.fullmatch(r'(?:v|Python )[0-9]+\.[0-9]+\.[0-9]+(?:[-+][A-Za-z0-9.]+)?', value): + return {'status': 'UNAVAILABLE'} + return {'status': 'OK', 'value': value, 'returncode': code} + except (OSError, UnicodeError, subprocess.TimeoutExpired): + return {'status': 'UNAVAILABLE'} + finally: + if child is not None: + try: os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: pass + try: child.wait(timeout=5) + except subprocess.TimeoutExpired: pass + target.unlink(missing_ok=True) + context = { + 'schema_version': 1, 'scientific_effect': 'NONE', + 'event_name': os.environ.get('GITHUB_EVENT_NAME'), + 'event_sha': os.environ.get('GITHUB_SHA'), + 'event_ref': os.environ.get('GITHUB_REF'), + 'repository': os.environ.get('GITHUB_REPOSITORY'), + 'run_id': os.environ.get('GITHUB_RUN_ID'), + 'run_attempt': os.environ.get('GITHUB_RUN_ATTEMPT'), + 'pull_request_number': pr.get('number', event.get('number')), + 'pull_request_head_sha': (pr.get('head') or {}).get('sha'), + 'pull_request_base_sha': (pr.get('base') or {}).get('sha'), + 'python_version': '.'.join(str(x) for x in sys.version_info[:3]), + 'node_version': version(['node', '--version']), + 'python_command_version': version(['python3', '--version']), + 'candidate_base_commit': None, + 'composition_binding': 'PENDING_FINAL_CANONICAL_COMPOSITION', + 'candidate_source_guard': 'not_started', 'node_phase': 'not_started', + } + context_raw = (json.dumps(context, indent=2) + '\n').encode() + if len(context_raw) > 65536: raise SystemExit('HOLD_CONTEXT_LIMIT') + (output / 'context.json').write_bytes(context_raw) + PYCONTEXT + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.sha }} + fetch-depth: 2 + persist-credentials: false + clean: true + - name: Require exact frozen fixtures test and candidate production source + run: | + python3 -I -B -S - <<'PYGUARD' + import hashlib, json, os, re, selectors, signal, stat, subprocess, time, types + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + context_path = output / 'context.json' + context = json.loads(context_path.read_text()) + def source_bytes(name, limit): + parts = name.split('/') + directory = os.open('.', os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + descriptor = None + try: + for part in parts[:-1]: + child = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory) + os.close(directory) + directory = child + descriptor = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=directory) + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or not 0 <= before.st_size <= limit: + raise ValueError('Unsafe or oversized immutable Source') + with os.fdopen(descriptor, 'rb', closefd=False) as stream: + raw = stream.read(limit + 1) + after = os.fstat(descriptor) + identity = lambda s: (s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + if len(raw) != before.st_size or identity(before) != identity(after): + raise ValueError('Immutable Source changed during read') + return raw + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + def bounded_git(arguments, limit): + process = subprocess.Popen(['git','--no-replace-objects',*arguments], + stdin=subprocess.DEVNULL,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,start_new_session=True) + poller = selectors.DefaultSelector() + os.set_blocking(process.stdout.fileno(),False) + poller.register(process.stdout,selectors.EVENT_READ) + raw, deadline = bytearray(), time.monotonic()+5 + try: + while poller.get_map(): + if time.monotonic()>=deadline: raise ValueError('Git read timeout; HOLD') + for key,_ in poller.select(0.05): + chunk=os.read(key.fileobj.fileno(),min(8192,limit+1-len(raw))) + if not chunk: poller.unregister(key.fileobj); break + raw.extend(chunk) + if len(raw)>limit: raise ValueError('Git output cap; HOLD') + if process.wait(timeout=2)!=0: raise ValueError('Git object read failed; HOLD') + return bytes(raw) + finally: + try: os.killpg(process.pid,signal.SIGKILL) + except ProcessLookupError: pass + process.wait(timeout=2) + process.stdout.close(); poller.close() + try: + head_raw = bounded_git(['rev-parse','--verify','HEAD'],41) + if not re.fullmatch(rb'[0-9a-f]{40}\n',head_raw): + raise ValueError('Invalid actual HEAD; HOLD') + checked_commit = head_raw[:-1].decode('ascii') + context['checked_commit'] = checked_commit + if checked_commit != context['event_sha']: + raise SystemExit('Checkout differs from tested event SHA') + fixture_root = Path('tests/fixtures/current_site_transition_20261022') + fixture_raw = (fixture_root / 'fixture-freeze.json').read_bytes() + if hashlib.sha256(fixture_raw).hexdigest() != '734f8837db6ea3f9bfe9d0f0adceb875c5af20c56767d89e7aa91c47184726d3': + raise SystemExit('Fixture freeze changed') + for entry in json.loads(fixture_raw)['files']: + raw = (fixture_root / entry['path']).read_bytes() + if (len(raw), hashlib.sha256(raw).hexdigest()) != (entry['bytes'], entry['sha256']): + raise SystemExit('Fixture changed: ' + entry['path']) + test_raw = Path('tests/test_current_site_transition.mjs').read_bytes() + if hashlib.sha256(test_raw).hexdigest() != 'a6434c9fc0c06a37d09d430bb3d8c043107e8472fa1585c1ab8cdff336b3f66a': + raise SystemExit('Test source changed') + required_candidate_freeze_sha256 = '08599cdf4c4251932e92ed622bf695db1bb502578fcb2c60da42daa89ebace5e' + if not re.fullmatch(r'[0-9a-f]{64}', required_candidate_freeze_sha256): + raise SystemExit('Unbound candidate freeze; private template is not publishable') + candidate_freeze_path = Path('tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json') + if not candidate_freeze_path.is_file() or candidate_freeze_path.is_symlink(): + raise SystemExit('Missing or unsafe candidate production freeze') + candidate_freeze_raw = candidate_freeze_path.read_bytes() + candidate_freeze_sha256 = hashlib.sha256(candidate_freeze_raw).hexdigest() + context['candidate_freeze_path'] = candidate_freeze_path.as_posix() + context['candidate_freeze_sha256'] = candidate_freeze_sha256 + context['candidate_freeze_expected_sha256'] = required_candidate_freeze_sha256 + if candidate_freeze_sha256 != required_candidate_freeze_sha256: + raise SystemExit('Candidate production freeze changed') + freeze = json.loads(candidate_freeze_raw) + if (set(freeze) != {'schema_version', 'candidate_base_commit', 'files'} + or type(freeze['schema_version']) is not int or freeze['schema_version'] != 1 + or not isinstance(freeze['candidate_base_commit'], str) + or not re.fullmatch(r'[0-9a-f]{40}', freeze['candidate_base_commit'])): + raise SystemExit('Unexpected candidate freeze schema or base') + guard_path = 'tools/site_transition_source_guard.py' + guard_raw = source_bytes(guard_path, 8192) + if (len(guard_raw) != 4249 or hashlib.sha256(guard_raw).hexdigest() != '69aa32de61db44014f3b78a4374dda1852ab6854fbf4ac988abef6abf88e1fc6'): + raise SystemExit('Merge guard Source changed') + guard = types.ModuleType('site_transition_source_guard') + guard.__file__ = str(Path(guard_path).absolute()) + exec(compile(guard_raw, guard.__file__, 'exec'), guard.__dict__) + commit_raw = bounded_git(['cat-file','commit',checked_commit],65536) + join = guard.verify_merge_join( + event_name=context['event_name'], repository=context['repository'], + event_ref=context['event_ref'], event_sha=context['event_sha'], + pr_number=context['pull_request_number'], event_head_sha=context['pull_request_head_sha'], + event_base_sha=context['pull_request_base_sha'], checked_commit=checked_commit, + actual_commit_raw=commit_raw, frozen_base_commit=freeze['candidate_base_commit']) + context.update(source_join=join, candidate_base_commit=join['candidate_base_commit'], + actual_tree_sha=join['actual_tree_sha'],actual_merge_parents=join['actual_merge_parents'], + composition_binding='FROZEN_SOURCE_JOIN') + context['merge_guard_source'] = {'path':guard_path,'bytes':len(guard_raw), + 'sha256':hashlib.sha256(guard_raw).hexdigest()} + expected_paths = ['docs/site/current-model.mjs', 'docs/site/current.mjs', 'docs/site/dependency-model.mjs'] + if (not isinstance(freeze['files'], list) or len(freeze['files']) != 3 + or any(not isinstance(entry, dict) for entry in freeze['files']) + or [entry.get('path') for entry in freeze['files']] != expected_paths): + raise SystemExit('Candidate freeze must bind exactly the three ordered production paths') + for entry in freeze['files']: + if (set(entry) != {'path', 'bytes', 'sha256', 'git_blob'} + or type(entry['bytes']) is not int or entry['bytes'] < 0 + or not isinstance(entry['sha256'], str) + or not re.fullmatch(r'[0-9a-f]{64}', entry['sha256']) + or not isinstance(entry['git_blob'], str) + or not re.fullmatch(r'[0-9a-f]{40}', entry['git_blob'])): + raise SystemExit('Malformed candidate production entry') + path = Path(entry['path']) + if not path.is_file() or path.is_symlink(): + raise SystemExit('Missing or unsafe candidate production path: ' + entry['path']) + raw = path.read_bytes() + blob = hashlib.sha1(b'blob ' + str(len(raw)).encode() + b'\0' + raw).hexdigest() + if (len(raw), hashlib.sha256(raw).hexdigest(), blob) != (entry['bytes'], entry['sha256'], entry['git_blob']): + raise SystemExit('Candidate production source differs: ' + entry['path']) + # Additive schema-1 custody: bind actual core30 inputs plus the workflow wrapper. + immutable_paths = [ + 'tools/site_transition_source_guard.py', + '.github/workflows/current-site-transition-candidate.yml', + 'tests/test_current_site_transition.mjs', + str(fixture_root / 'fixture-freeze.json'), candidate_freeze_path.as_posix(), + *[str(fixture_root / entry['path']) for entry in json.loads(fixture_raw)['files']], + *expected_paths, + ] + context['immutable_source_inputs'] = [] + for name in immutable_paths: + raw = source_bytes(name, 16777216) + context['immutable_source_inputs'].append({'path':name,'bytes':len(raw), + 'sha256':hashlib.sha256(raw).hexdigest()}) + # Rejoin the ledger to the already authenticated guard/test/freezes/modules. + if source_bytes(guard_path,8192) != guard_raw or source_bytes('tests/test_current_site_transition.mjs',32768) != test_raw: + raise SystemExit('Guard or test changed after qualification') + if source_bytes(str(fixture_root / 'fixture-freeze.json'),16384) != fixture_raw or source_bytes(candidate_freeze_path.as_posix(),16384) != candidate_freeze_raw: + raise SystemExit('Freeze changed after qualification') + for entry in [*json.loads(fixture_raw)['files'], *freeze['files']]: + name = str(fixture_root / entry['path']) if entry in json.loads(fixture_raw)['files'] else entry['path'] + raw = source_bytes(name,16777216) + if (len(raw),hashlib.sha256(raw).hexdigest()) != (entry['bytes'],entry['sha256']): + raise SystemExit('Input changed after qualification') + context['immutable_source_recheck'] = 'pending' + context['candidate_source_guard'] = 'passed' + except BaseException as error: + context['candidate_source_guard'] = 'failed' + context['candidate_source_guard_error'] = type(error).__name__ + raise + finally: + context_raw = (json.dumps(context, indent=2) + '\n').encode() + if len(context_raw) > 65536: raise SystemExit('HOLD_CONTEXT_LIMIT') + context_path.write_bytes(context_raw) + PYGUARD + - name: Capture bounded real Node TAP with a child deadline + run: | + python3 -I -B -S - <<'PYNODE' + import hashlib, json, os, resource, signal, stat, subprocess, time + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + context_path = output / 'context.json' + context = json.loads(context_path.read_bytes()) + def save(): + raw = (json.dumps(context, indent=2) + '\n').encode() + if len(raw) > 65536: raise SystemExit('HOLD_CONTEXT_LIMIT') + context_path.write_bytes(raw) + def recheck_sources(): + for entry in context['immutable_source_inputs']: + parts = entry['path'].split('/') + directory = os.open('.',os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW) + descriptor = None + try: + for part in parts[:-1]: + next_directory = os.open(part,os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW,dir_fd=directory) + os.close(directory); directory=next_directory + descriptor=os.open(parts[-1],os.O_RDONLY|os.O_NOFOLLOW|os.O_NONBLOCK,dir_fd=directory) + before=os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or before.st_size != entry['bytes'] or before.st_size > 16777216: + raise ValueError('Immutable Source unsafe or changed') + with os.fdopen(descriptor,'rb',closefd=False) as stream: raw=stream.read(entry['bytes']+1) + after=os.fstat(descriptor) + identity=lambda s:(s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + if identity(before)!=identity(after) or len(raw)!=entry['bytes'] or hashlib.sha256(raw).hexdigest()!=entry['sha256']: + raise ValueError('Immutable Source changed') + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + cap = 1048576 + def physical_limit(): + resource.setrlimit(resource.RLIMIT_FSIZE, (cap, cap)) + command = ['node', '--test', '--test-reporter=tap', 'tests/test_current_site_transition.mjs'] + context.update(node_phase='starting', node_command=command, capture_status='NOT_RUN', + capture_file_limit=cap, child_timeout_seconds=90) + child = None + code = None + status = 'REFUSED_SETUP' + cleanup_errors, capture_errors = [], [] + diagnostics_complete = False + began = time.monotonic() + paths = [output / 'tap.stdout.tap', output / 'tap.stderr.txt'] + try: + try: + save() + recheck_sources() + with paths[0].open('wb') as stdout, paths[1].open('wb') as stderr: + child = subprocess.Popen(command, stdout=stdout, stderr=stderr, + start_new_session=True, preexec_fn=physical_limit) + deadline = began + 90 + while True: + if any(path.stat().st_size >= cap for path in paths): + status = 'REFUSED_OUTPUT_LIMIT'; break + code = child.poll() + if code is not None: + status = 'REFUSED_OUTPUT_LIMIT' if code == -signal.SIGXFSZ else 'COMPLETED' + break + if time.monotonic() >= deadline: + status = 'TIMEOUT'; break + time.sleep(0.05) + except Exception as error: + capture_errors.append({'operation':'capture', 'error':type(error).__name__}) + context['node_start_error' if child is None else 'node_capture_error'] = type(error).__name__ + status = 'REFUSED_SETUP' if child is None else 'REFUSED_CAPTURE' + finally: + context['node_capture_outcome'] = status + if child is not None: + # Attempt group termination and reap independently, including normal exits. + try: os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: pass + except Exception as error: + cleanup_errors.append({'operation':'killpg', 'error':type(error).__name__}) + try: + code = child.wait(timeout=5) + except Exception as error: + cleanup_errors.append({'operation':'wait', 'error':type(error).__name__}) + status = 'REFUSED_REAP' if isinstance(error, subprocess.TimeoutExpired) else 'REFUSED_CLEANUP' + try: code = child.poll() + except Exception as poll_error: + cleanup_errors.append({'operation':'poll', 'error':type(poll_error).__name__}) + code = None + if type(code) is int: + context['node_returncode'] = code + try: (output / 'node-exit-code.txt').write_text(str(code) + '\n') + except Exception as error: + capture_errors.append({'operation':'exit_write', 'error':type(error).__name__}) + else: + capture_errors.append({'operation':'exit_code', 'error':'MissingIntegerReturnCode'}) + for path in paths: + descriptor = None + try: + descriptor = os.open(path, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK) + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1: + raise ValueError('Unsafe capture member') + if not 0 <= before.st_size <= cap: + status = 'REFUSED_OUTPUT_LIMIT'; continue + captured, eof = bytearray(), False + while len(captured) <= cap: + chunk = os.read(descriptor, min(8192, cap + 1 - len(captured))) + if not chunk: eof = True; break + captured.extend(chunk) + after = os.fstat(descriptor) + named = os.stat(path, follow_symlinks=False) + identity = lambda s: (s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + if identity(before) != identity(after) or identity(after) != identity(named): + raise ValueError('Capture member changed during read') + if len(captured) >= cap: + status = 'REFUSED_OUTPUT_LIMIT' + elif not eof or len(captured) != before.st_size: + raise ValueError('Capture member size or EOF changed') + except Exception as error: + capture_errors.append({'operation':'capture:'+path.name, 'error':type(error).__name__}) + finally: + if descriptor is not None: + try: os.close(descriptor) + except Exception as error: + capture_errors.append({'operation':'capture_close:'+path.name, 'error':type(error).__name__}) + if cleanup_errors and status != 'REFUSED_REAP': status = 'REFUSED_CLEANUP' + if capture_errors and child is not None: status = 'REFUSED_CAPTURE' + diagnostics_complete = True + finally: + if not diagnostics_complete: + status = 'REFUSED_CLEANUP' if child is not None else 'REFUSED_SETUP' + # Custody and context attempts cannot be skipped by capture/cleanup diagnostics. + try: + recheck_sources() + context['immutable_source_recheck'] = 'passed' + except Exception as error: + status = 'REFUSED_SOURCE_CHANGED' + context['immutable_source_recheck'] = 'failed' + context['immutable_source_recheck_error'] = type(error).__name__ + finally: + context.update(node_phase='completed' if child is not None else 'not_started', + capture_status=status, cleanup_errors=cleanup_errors, + capture_cleanup_diagnostics='completed' if diagnostics_complete else 'incomplete', + capture_errors=capture_errors, elapsed_seconds=round(time.monotonic()-began, 3)) + save() + if status != 'COMPLETED': raise SystemExit(1) + raise SystemExit(code if code >= 0 else 128 - code) + PYNODE + - name: Admit bounded report members and emit byte-exact log frames + id: capture_admission + if: always() + run: | + python3 -I -B -S - <<'PYEMIT' + import base64, hashlib, json, os + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + limits = {'context.json': 65536, 'tap.stdout.tap': 1048576, + 'tap.stderr.txt': 1048576, 'node-exit-code.txt': 32} + def setting(name, value): + with open(os.environ['GITHUB_OUTPUT'], 'a') as stream: stream.write(name + '=' + value + '\n') + setting('bounded', 'false') + try: + if any(not (output/name).is_file() or (output/name).is_symlink() for name in limits): + raise ValueError('MISSING_OR_UNSAFE_MEMBER') + sizes = {name: (output/name).stat().st_size for name in limits} + if any(sizes[name] > limits[name] for name in limits) or sum(sizes.values()) > 2162720: + raise ValueError('REPORT_BYTE_LIMIT') + members = {name: (output/name).read_bytes() for name in limits} + if any(len(members[name]) != sizes[name] for name in limits): raise ValueError('MEMBER_CHANGED') + context = json.loads(members['context.json']) + complete = (context.get('candidate_source_guard') == 'passed' and context.get('node_phase') == 'completed' + and context.get('capture_status') == 'COMPLETED' + and context.get('immutable_source_recheck') == 'passed' + and context.get('node_version', {}).get('status') == 'OK' + and context.get('python_command_version', {}).get('status') == 'OK' + and context.get('event_name') == 'pull_request' + and context.get('pull_request_head_sha') and context.get('pull_request_base_sha')) + exit_text = members['node-exit-code.txt'].decode('ascii').strip() + complete = bool(complete and exit_text == str(context.get('node_returncode'))) + classification = 'CAPTURE_COMPLETE_REQUIRES_TAP_REVIEW' if complete else 'HOLD' + for name, raw in members.items(): + sha = hashlib.sha256(raw).hexdigest() + print(f'CS_TRANSITION_FILE_BEGIN name={name} bytes={len(raw)} sha256={sha}') + count = 0 + for offset in range(0, len(raw), 3072): + chunk = base64.b64encode(raw[offset:offset+3072]).decode('ascii') + print(f'CS_TRANSITION_FILE_CHUNK name={name} index={count} data={chunk}') + count += 1 + print(f'CS_TRANSITION_FILE_END name={name} chunks={count} sha256={sha}') + print(f'CS_TRANSITION_EVIDENCE_END files=4 bytes={sum(sizes.values())} classification={classification}') + setting('bounded', 'true') + if not complete: raise SystemExit(1) + except Exception as error: + print('CS_TRANSITION_EVIDENCE_HOLD reason=' + type(error).__name__) + raise SystemExit(1) + PYEMIT + - name: Preserve exact bounded context TAP stderr and exit code including failures + if: always() && steps.capture_admission.outputs.bounded == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: current-site-transition-candidate-${{ github.run_id }}-${{ github.run_attempt }} + path: | + ${{ runner.temp }}/current-site-transition-candidate/context.json + ${{ runner.temp }}/current-site-transition-candidate/tap.stdout.tap + ${{ runner.temp }}/current-site-transition-candidate/tap.stderr.txt + ${{ runner.temp }}/current-site-transition-candidate/node-exit-code.txt + if-no-files-found: error + retention-days: 30 + + capture-wrapper-regressions: + runs-on: ubuntu-24.04 + timeout-minutes: 15 + permissions: + contents: read + steps: + - name: Check out exact pull request merge Source + id: capture_checkout + timeout-minutes: 3 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.sha }} + fetch-depth: 2 + clean: true + persist-credentials: false + - name: Authenticate explicit regression Source and stage read only repository layout + id: capture_prepare + if: always() + timeout-minutes: 1 + run: | + /usr/bin/python3 -I -B -S - prepare <<'PYREG_DRIVER' + import hashlib, json, os, re, selectors, signal, stat, subprocess, sys, time, types + from pathlib import Path + + MANIFEST_PIN = 'fd2572db155426a0101093b8667b1840d050a608948ff2aeb3dabf763c049232' + FREEZE_PIN = '08599cdf4c4251932e92ed622bf695db1bb502578fcb2c60da42daa89ebace5e' + FIXTURE = 'tests/fixtures/site_transition_capture_regression_20261025' + WORKFLOW = '.github/workflows/current-site-transition-candidate.yml' + MANIFEST = FIXTURE + '/source-fixture-manifest.json' + GUARD_SHA = '69aa32de61db44014f3b78a4374dda1852ab6854fbf4ac988abef6abf88e1fc6' + LIMITS = {'job-context.json':65536, 'source-before.json':262144, 'source-after.json':262144, + 'contract.json':65536, 'baseline.stdout.bin':1048576, 'baseline.stderr.bin':1048576, + 'baseline.receipt.json':262144, 'baseline.witness.json':65536, + 'candidate.stdout.bin':1048576, 'candidate.stderr.bin':1048576, + 'candidate.receipt.json':262144, 'candidate.witness.json':131072, + 'disposition.json':65536, 'baseline.spawn-trace.json':65536, 'candidate.spawn-trace.json':65536} + NATIVE_KEYS = ('GITHUB_EVENT_NAME','GITHUB_EVENT_PATH','GITHUB_SHA','GITHUB_REF','GITHUB_REPOSITORY', + 'GITHUB_RUN_ID','GITHUB_RUN_ATTEMPT','GITHUB_WORKFLOW_REF','GITHUB_WORKFLOW_SHA') + native = {key:os.environ.get(key) for key in NATIVE_KEYS} + base = Path(os.environ['RUNNER_TEMP']).resolve(strict=True) / 'site-transition-capture-regression' + + def encoded(value): + return (json.dumps(value, sort_keys=True, indent=2, ensure_ascii=True) + '\n').encode('ascii') + + def object_json(raw): + def unique(pairs): + value = {} + for key,item in pairs: + if key in value: raise ValueError('Duplicate JSON key') + value[key] = item + return value + return json.loads(raw, object_pairs_hook=unique) + + def pin(raw): + return {'bytes':len(raw), 'sha256':hashlib.sha256(raw).hexdigest()} + + def safe_read(path, limit): + path = Path(path) + if not path.is_absolute() or any(part in ('.','..') for part in path.parts[1:]): + raise ValueError('Physical absolute input required') + directory = os.open('/', os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + descriptor = None + try: + for part in path.parts[1:-1]: + following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory) + os.close(directory); directory = following + descriptor = os.open(path.name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=directory) + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or not 0 <= before.st_size <= limit: + raise ValueError('Unsafe or oversized input') + chunks, size = [], 0 + while size <= limit: + chunk = os.read(descriptor, min(65536, limit + 1 - size)) + if not chunk: break + chunks.append(chunk); size += len(chunk) + after = os.fstat(descriptor) + named = os.stat(path.name, dir_fd=directory, follow_symlinks=False) + shape = lambda s:(s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + raw = b''.join(chunks) + if shape(before) != shape(after) or shape(after) != shape(named) or len(raw) != before.st_size: + raise ValueError('Input changed during read') + return raw + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + + def write_json(path, value, limit): + raw = encoded(value) + if len(raw) > limit: raise ValueError('Bounded JSON limit') + path.write_bytes(raw) + + def clean_environment(state): + os.environ.clear() + os.environ.update(PATH='/usr/bin:/bin', HOME=str(base/'home'), TMPDIR=str(base/'tmp'), + LANG='C.UTF-8', LC_ALL='C.UTF-8', TZ='UTC', RUNNER_TEMP=str(base.parent)) + + def descriptor(path, raw): + return {'path':str(path), **pin(raw)} + + def capture_rows(state, label): + observed, errors = {}, [] + for row in state['inputs']: + for kind,root in [('original',Path(state['original_root'])),('staged',Path(state['staged_root']))]: + name = kind+':'+row['relative'] + try: + raw = safe_read(root/row['relative'], 2097152) + observed[name] = pin(raw) + if pin(raw) != row['pin']: raise ValueError('Immutable Source drift') + except BaseException as error: errors.append({'input':name,'error':type(error).__name__}) + for row in state.get('external_custody', []): + try: + raw = safe_read(row['path'], row['limit']); observed[row['path']] = pin(raw) + if pin(raw) != row['pin']: raise ValueError('Contract/native input drift') + except BaseException as error: errors.append({'input':row['path'],'error':type(error).__name__}) + state['custody'][label] = {'observed':observed,'errors':errors} + target = 'source-before.json' if label.startswith('before') else 'source-after.json' + selected = {key:value for key,value in state['custody'].items() if key.startswith('before') == label.startswith('before')} + write_json(base/target, selected, LIMITS[target]) + if errors: raise ValueError('Immutable custody HOLD') + + def helper(state): + row = next(row for row in state['inputs'] if row['relative'] == 'tools/site_transition_capture_regression_supervisor.py') + path = Path(state['staged_root'])/row['relative'] + raw = safe_read(path, 2097152) + if pin(raw) != row['pin']: raise ValueError('Supervisor captured Source changed') + module = types.ModuleType('site_capture_authenticated_supervisor') + module.__file__ = str(path) + exec(compile(raw, str(path), 'exec'), module.__dict__) + return module + + def bounded_git(arguments, limit): + process = subprocess.Popen(['git','--no-replace-objects',*arguments], + stdin=subprocess.DEVNULL,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,start_new_session=True) + poller = selectors.DefaultSelector() + os.set_blocking(process.stdout.fileno(),False) + poller.register(process.stdout,selectors.EVENT_READ) + raw, deadline = bytearray(), time.monotonic()+5 + try: + while poller.get_map(): + if time.monotonic()>=deadline: raise ValueError('Git read timeout; HOLD') + for key,_ in poller.select(0.05): + chunk=os.read(key.fileobj.fileno(),min(8192,limit+1-len(raw))) + if not chunk: poller.unregister(key.fileobj); break + raw.extend(chunk) + if len(raw)>limit: raise ValueError('Git output cap; HOLD') + if process.wait(timeout=2)!=0: raise ValueError('Git object read failed; HOLD') + return bytes(raw) + finally: + try: os.killpg(process.pid,signal.SIGKILL) + except ProcessLookupError: pass + process.wait(timeout=2) + process.stdout.close(); poller.close() + + def prepare(state): + if sys.platform != 'linux': raise ValueError('HOLD_UNSUPPORTED_PLATFORM') + clean_environment(state) + root = Path.cwd().resolve(strict=True) + if base.is_relative_to(root): raise ValueError('Temporary output inside repository') + if not re.fullmatch(r'[0-9a-f]{64}', MANIFEST_PIN) or not re.fullmatch(r'[0-9a-f]{64}', FREEZE_PIN): + raise ValueError('PENDING_FINAL_CANONICAL_COMPOSITION') + manifest_raw = safe_read(root/MANIFEST, 65536) + if hashlib.sha256(manifest_raw).hexdigest() != MANIFEST_PIN: raise ValueError('Manifest pin') + manifest = object_json(manifest_raw) + if set(manifest) != {'schema_version','status','fixture_root','members','external_inputs','selectors'}: + raise ValueError('Manifest schema') + if type(manifest['schema_version']) is not int or manifest['schema_version'] != 1 or manifest['status'] != 'ROOT_FROZEN_FINAL_CANONICAL_COMPOSITION' or manifest['fixture_root'] != FIXTURE: + raise ValueError('PENDING or wrong manifest') + if type(manifest['members']) is not list or len(manifest['members']) != 38 or set(manifest['external_inputs']) != {'guard','final_freeze'}: + raise ValueError('Exact manifest membership') + rows = [*manifest['members'], manifest['external_inputs']['guard'], manifest['external_inputs']['final_freeze']] + captured = {MANIFEST:manifest_raw} + for row in rows: + if set(row) != {'path','bytes','sha256','git_blob','role'} or type(row['path']) is not str: + raise ValueError('Manifest row') + relative = row['path']; parts = relative.split('/') + if relative.startswith('/') or any(part in ('','.','..') for part in parts) or relative in captured: + raise ValueError('Duplicate or unsafe member path') + if type(row['bytes']) is not int or not 0 <= row['bytes'] <= 2097152 or not re.fullmatch(r'[0-9a-f]{64}',row['sha256']) or not re.fullmatch(r'[0-9a-f]{40}',row['git_blob']): + raise ValueError('Unbound member descriptor') + raw = safe_read(root/relative, 2097152) + if pin(raw) != {key:row[key] for key in ('bytes','sha256')} or hashlib.sha1(b'blob '+str(len(raw)).encode()+b'\0'+raw).hexdigest() != row['git_blob']: + raise ValueError('Manifest member authentication') + captured[relative] = raw + captured[WORKFLOW] = safe_read(root/WORKFLOW, 262144) + if len(captured) != 42: raise ValueError('Exact 42 immutable Sources') + guard_row = manifest['external_inputs']['guard']; freeze_row = manifest['external_inputs']['final_freeze'] + if guard_row['path'] != 'tools/site_transition_source_guard.py' or guard_row['bytes'] != 4249 or guard_row['sha256'] != GUARD_SHA: + raise ValueError('Exact merge guard') + if freeze_row['path'] != 'tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json' or freeze_row['sha256'] != FREEZE_PIN: + raise ValueError('Common freeze join') + freeze = object_json(captured[freeze_row['path']]) + production = ['docs/site/current-model.mjs','docs/site/current.mjs','docs/site/dependency-model.mjs'] + if set(freeze) != {'schema_version','candidate_base_commit','files'} or type(freeze['schema_version']) is not int or freeze['schema_version'] != 1 or not re.fullmatch(r'[0-9a-f]{40}',freeze['candidate_base_commit']) or type(freeze['files']) is not list or len(freeze['files']) != 3 or [row.get('path') for row in freeze['files']] != production: + raise ValueError('Final three-member freeze schema') + for row in freeze['files']: + if set(row) != {'path','bytes','sha256','git_blob'} or type(row['bytes']) is not int or row['bytes'] < 0 or not re.fullmatch(r'[0-9a-f]{64}',row['sha256']) or not re.fullmatch(r'[0-9a-f]{40}',row['git_blob']): raise ValueError('Production freeze descriptor') + event_raw = safe_read(Path(native['GITHUB_EVENT_PATH']), 65536); event = object_json(event_raw) + head_raw = bounded_git(['rev-parse','--verify','HEAD'],41) + if not re.fullmatch(rb'[0-9a-f]{40}\n',head_raw): raise ValueError('Actual checked HEAD') + checked = head_raw[:-1].decode('ascii'); commit_raw = bounded_git(['cat-file','commit',checked],65536) + guard = types.ModuleType('site_capture_authenticated_guard'); guard.__file__ = str(root/guard_row['path']) + exec(compile(captured[guard_row['path']],guard.__file__,'exec'),guard.__dict__) + pr = event.get('pull_request') or {} + join = guard.verify_merge_join(event_name=native['GITHUB_EVENT_NAME'], repository=native['GITHUB_REPOSITORY'],event_ref=native['GITHUB_REF'],event_sha=native['GITHUB_SHA'],pr_number=pr.get('number',event.get('number')),event_head_sha=(pr.get('head') or {}).get('sha'),event_base_sha=(pr.get('base') or {}).get('sha'),checked_commit=checked,actual_commit_raw=commit_raw,frozen_base_commit=freeze['candidate_base_commit']) + stage = base/'staged-repo'; stage.mkdir(mode=0o700) + for relative,raw in captured.items(): + target = stage/relative; target.parent.mkdir(parents=True,exist_ok=True); target.write_bytes(raw); target.chmod(0o444) + for name,raw in [('native-event.json',event_raw),('literal-commit.raw',commit_raw)]: + target=base/name; target.write_bytes(raw); target.chmod(0o444) + closure = [descriptor(stage/path,raw) for path,raw in sorted(captured.items())] + seal_rows = [*closure, descriptor(base/'native-event.json',event_raw),descriptor(base/'literal-commit.raw',commit_raw)] + seal_path = base/'stage-seal.json'; write_json(seal_path,{'schema_version':1,'files':seal_rows,'excludes':['stage-seal.json','contract.json']},65536); seal_path.chmod(0o444) + executable = Path(sys.executable).resolve(strict=True); executable_raw = safe_read(executable,268435456) + at = lambda relative:descriptor(stage/relative,captured[relative]) + contract = {'status':'ROOT_FROZEN_EXECUTION_CONTRACT','platform':'linux','cwd':str(stage),'regression_root':str(stage/FIXTURE),'source_manifest':at(MANIFEST),'interpreter':{**descriptor(executable,executable_raw),'version':list(sys.version_info[:3])},'wall_seconds':{'baseline':120,'candidate':180},'harness':at('tools/site_transition_capture_regression.py'),'supervisor_source':at('tools/site_transition_capture_regression_supervisor.py'),'launcher_source':at('tools/site_transition_capture_regression_launcher.py'),'source_seal':descriptor(seal_path,safe_read(seal_path,65536)),'workflows':{'baseline':at(FIXTURE+'/baseline-current-site-transition-candidate.yml.txt'),'candidate':at(WORKFLOW)},'selectors':manifest['selectors'],'closure':closure,'allowed_child_argv_sha256':[],'expected_children':{}} + state.update(original_root=str(root),staged_root=str(stage),inputs=[{'relative':path,'pin':pin(raw)} for path,raw in sorted(captured.items())],source_join=join,native=native,workflow_execution_binding='PENDING_EXTERNAL_NATIVE_SOURCE_QUALIFICATION',manifest_sha256=MANIFEST_PIN,common_freeze_sha256=FREEZE_PIN) + supervisor = helper(state) + qualified = supervisor.closed_sources(contract) + commands = supervisor.derive_allowed_child_argv(contract,qualified) + contract['allowed_child_argv_sha256'] = [hashlib.sha256(supervisor.compact(command)).hexdigest() for command in commands] + contract['expected_children'] = supervisor.derive_expected_children(contract,qualified) + if len(commands) != 13 or contract['expected_children'] != {'baseline':1,'candidate':23}: raise ValueError('Actual closed child census') + write_json(base/'contract.json',contract,65536); (base/'contract.json').chmod(0o444) + state['contract_pin'] = pin(safe_read(base/'contract.json',65536)) + state['external_custody'] = [{'path':str(path),'pin':pin(safe_read(path,limit)),'limit':limit} for path,limit in [(base/'stage-seal.json',65536),(base/'contract.json',65536),(base/'native-event.json',65536),(base/'literal-commit.raw',65536),(executable,268435456)]] + for directory in sorted([stage,*[p for p in stage.rglob('*') if p.is_dir()]],key=lambda p:len(p.parts),reverse=True): directory.chmod(0o555) + state['prepared'] = True + capture_rows(state,'before_baseline') + + def preserve_selection(state, selection): + folder, copied = base/selection, {} + provenance=state.setdefault('preservation',{}) + for source,target in [('stdout.bin',selection+'.stdout.bin'),('stderr.bin',selection+'.stderr.bin'),('spawn-trace.jsonl',selection+'.spawn-trace.json'),('receipt.json',selection+'.receipt.json')]: + stage='read' + try: + raw=safe_read(folder/source,LIMITS[target]);stage='write';(base/target).write_bytes(raw);copied[source]=pin(raw) + except BaseException as error: + provenance[target]={'status':'MISSING' if stage=='read' and isinstance(error,FileNotFoundError) else 'REFUSED','stage':stage,'error':type(error).__name__,'detail':str(error)[:256]} + else:provenance[target]={'status':'COPIED','pin':copied[source]} + receipt = object_json(safe_read(base/(selection+'.receipt.json'),262144)) + evidence = receipt.get('regression_evidence') + if type(evidence) is dict and set(evidence) == {'harness_result','case_results','witnesses','subtests'}: + write_json(base/(selection+'.witness.json'),evidence,LIMITS[selection+'.witness.json']) + expected = 'BASELINE_CAUSAL_RED' if selection == 'baseline' else 'CANDIDATE_20_GREEN' + good = (receipt.get('disposition') == 'CAPTURE_COMPLETE_REQUIRES_HARNESS_REVIEW' + and receipt.get('regression_status') == expected and receipt.get('trace_complete') is True + and type(receipt.get('integer_exit')) is int and receipt['integer_exit'] == (1 if selection == 'baseline' else 0) + and receipt.get('verified_observed_cwd') == state['staged_root'] + and receipt.get('cleanup',{}).get('confirmed') is True and not receipt.get('cleanup',{}).get('errors') + and receipt.get('source_before') == receipt.get('source_after') and type(evidence) is dict + and set(evidence) == {'harness_result','case_results','witnesses','subtests'} and len(copied) == 4 + and all(receipt.get('captures',{}).get(name) == copied[name] for name in ('stdout.bin','stderr.bin','spawn-trace.jsonl'))) + state[selection] = expected if good else 'HOLD' + if not good: raise ValueError('Actual selection regression/capture evidence not admitted') + + def phase(state, selection): + if not state.get('prepared') or state.get('errors'): raise ValueError('HOLD_NOT_PREPARED') + if selection == 'candidate' and state.get('baseline') != 'BASELINE_CAUSAL_RED': raise ValueError('HOLD_BASELINE_NOT_CAUSAL_RED') + clean_environment(state) + original_argv = sys.argv[:] + try: + capture_rows(state,'before_'+selection) + supervisor = helper(state) + sys.argv = [str(Path(state['staged_root'])/'tools/site_transition_capture_regression_supervisor.py'),'--contract',str(base/'contract.json'),'--contract-sha256',state['contract_pin']['sha256'],'--selection',selection,'--output',str(base/selection)] + result = supervisor.main() + if result != 0: raise ValueError('Supervisor capture HOLD') + finally: + sys.argv = original_argv + try: preserve_selection(state,selection) + finally: capture_rows(state,'after_'+selection) + + def main(which): + state = {'schema_version':1,'scientific_effect':'NONE','prepared':False,'baseline':'NOT_RUN','candidate':'NOT_RUN','utility_controls':{'classification':'NOT_RUN'},'custody':{},'errors':[],'disposition':'HOLD','runtime_admission':'PENDING_ACTUAL_SUPPORTED_ROUTE','native':native} + if which == 'prepare': + base.mkdir(mode=0o700) + for name in ('home','tmp'): (base/name).mkdir(mode=0o700) + for name in LIMITS: + raw = b'' if name.endswith('.bin') or name.endswith('.spawn-trace.json') else encoded({'status':'HOLD_NOT_RUN','scientific_effect':'NONE'}) + (base/name).write_bytes(raw) + else: + state = object_json(safe_read(base/'job-state.json',262144)) + try: + if which == 'prepare': prepare(state) + elif which in ('baseline','candidate'): phase(state,which) + elif which == 'finish': + if state.get('inputs'): capture_rows(state,'final') + if state.get('errors') or state.get('baseline') != 'BASELINE_CAUSAL_RED' or state.get('candidate') != 'CANDIDATE_20_GREEN': raise ValueError('HOLD_INCOMPLETE_REGRESSION_GATES') + state['disposition'] = 'PENDING_UTILITY_CONTROLS' + else: raise ValueError('Unknown fixed phase') + except BaseException as error: + state['disposition'] = 'HOLD'; state['errors'].append({'phase':which,'error':type(error).__name__,'detail':str(error)[:1024]}) + if len(state['errors']) > 16: state['errors'] = state['errors'][:16] + finally: + for name in ('job-state.json','job-context.json','disposition.json'): + try: + value = state if name == 'job-state.json' else {key:value for key,value in state.items() if key not in ('inputs','custody','external_custody')} + if name == 'disposition.json': value = {'classification':state['disposition'],'baseline':state['baseline'],'candidate':state['candidate'],'errors':state['errors'],'preservation':state.get('preservation',{}),'native_workflow_source_binding':'EXTERNAL_ROOT_GATE','carrier_support':'PENDING_ACTUAL_LOG_QUALIFICATION','scientific_effect':'NONE'} + write_json(base/name,value,262144 if name == 'job-state.json' else 65536) + except BaseException as error: + state['disposition'] = 'HOLD'; state['errors'].append({'phase':which,'save':name,'error':type(error).__name__}) + print('CS_CAPTURE_REGRESSION_PHASE_HOLD '+which+' '+name+' '+type(error).__name__) + if state['disposition'] == 'HOLD' and (state['errors'] or which == 'finish'): raise SystemExit(1) + + main(sys.argv[1]) + PYREG_DRIVER + - name: Require the selected safe causal baseline RED witness + id: capture_baseline + if: always() + timeout-minutes: 3 + run: | + /usr/bin/python3 -I -B -S - baseline <<'PYREG_BASELINE' + import hashlib, json, os, stat, sys + from pathlib import Path + def read(path, limit): + directory = os.open('/', os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + descriptor = None + try: + for part in path.parts[1:-1]: + following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory) + os.close(directory); directory = following + descriptor = os.open(path.name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=directory) + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or not 0 <= before.st_size <= limit: raise ValueError('Unsafe bounded loader input') + chunks, total = [], 0 + while total <= limit: + block = os.read(descriptor, min(65536, limit+1-total)) + if not block: break + chunks.append(block); total += len(block) + after = os.fstat(descriptor); named = os.stat(path.name, dir_fd=directory, follow_symlinks=False) + shape = lambda row:(row.st_dev,row.st_ino,row.st_mode,row.st_nlink,row.st_size,row.st_mtime_ns,row.st_ctime_ns) + raw = b''.join(chunks) + if shape(before) != shape(after) or shape(after) != shape(named) or len(raw) != before.st_size: raise ValueError('Loader input changed') + return raw + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + phase = sys.argv[1] + if phase not in ('baseline','candidate','finish'): raise ValueError('Fixed phase only') + root = Path.cwd().resolve(strict=True) + workflow = root/'.github/workflows/current-site-transition-candidate.yml' + raw = read(workflow,262144) + state = json.loads(read(Path(os.environ['RUNNER_TEMP']).resolve(strict=True)/'site-transition-capture-regression/job-state.json',262144)) + if state.get('inputs'): + row = next(row for row in state['inputs'] if row['relative'] == '.github/workflows/current-site-transition-candidate.yml') + if row['pin'] != {'bytes':len(raw),'sha256':hashlib.sha256(raw).hexdigest()}: raise ValueError('Actual workflow driver Source drift') + lines = raw.splitlines(keepends=True) + header = b" /usr/bin/python3 -I -B -S - prepare <<'PYREG_DRIVER'\n" + starts = [index for index,line in enumerate(lines) if line == header] + if len(starts) != 1: raise ValueError('Unique reviewed workflow driver required') + end = lines.index(b' PYREG_DRIVER\n',starts[0]+1) + body = lines[starts[0]+1:end] + if not body or any(not line.startswith(b' ') for line in body): raise ValueError('Workflow scalar indentation') + source = b''.join(line[10:] for line in body) + sys.argv = ['reviewed-workflow-inline-driver',phase] + namespace = {'__name__':'__main__'} + exec(compile(source,str(workflow)+'#PYREG_DRIVER','exec'),namespace) + PYREG_BASELINE + - name: Require all twenty candidate regression controls and exact witnesses + id: capture_candidate + if: always() + timeout-minutes: 4 + run: | + /usr/bin/python3 -I -B -S - candidate <<'PYREG_CANDIDATE' + import hashlib, json, os, stat, sys + from pathlib import Path + def read(path, limit): + directory = os.open('/', os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + descriptor = None + try: + for part in path.parts[1:-1]: + following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory) + os.close(directory); directory = following + descriptor = os.open(path.name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=directory) + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or not 0 <= before.st_size <= limit: raise ValueError('Unsafe bounded loader input') + chunks, total = [], 0 + while total <= limit: + block = os.read(descriptor, min(65536, limit+1-total)) + if not block: break + chunks.append(block); total += len(block) + after = os.fstat(descriptor); named = os.stat(path.name, dir_fd=directory, follow_symlinks=False) + shape = lambda row:(row.st_dev,row.st_ino,row.st_mode,row.st_nlink,row.st_size,row.st_mtime_ns,row.st_ctime_ns) + raw = b''.join(chunks) + if shape(before) != shape(after) or shape(after) != shape(named) or len(raw) != before.st_size: raise ValueError('Loader input changed') + return raw + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + phase = sys.argv[1] + if phase not in ('baseline','candidate','finish'): raise ValueError('Fixed phase only') + root = Path.cwd().resolve(strict=True) + workflow = root/'.github/workflows/current-site-transition-candidate.yml' + raw = read(workflow,262144) + state = json.loads(read(Path(os.environ['RUNNER_TEMP']).resolve(strict=True)/'site-transition-capture-regression/job-state.json',262144)) + if state.get('inputs'): + row = next(row for row in state['inputs'] if row['relative'] == '.github/workflows/current-site-transition-candidate.yml') + if row['pin'] != {'bytes':len(raw),'sha256':hashlib.sha256(raw).hexdigest()}: raise ValueError('Actual workflow driver Source drift') + lines = raw.splitlines(keepends=True) + header = b" /usr/bin/python3 -I -B -S - prepare <<'PYREG_DRIVER'\n" + starts = [index for index,line in enumerate(lines) if line == header] + if len(starts) != 1: raise ValueError('Unique reviewed workflow driver required') + end = lines.index(b' PYREG_DRIVER\n',starts[0]+1) + body = lines[starts[0]+1:end] + if not body or any(not line.startswith(b' ') for line in body): raise ValueError('Workflow scalar indentation') + source = b''.join(line[10:] for line in body) + sys.argv = ['reviewed-workflow-inline-driver',phase] + namespace = {'__name__':'__main__'} + exec(compile(source,str(workflow)+'#PYREG_DRIVER','exec'),namespace) + PYREG_CANDIDATE + - name: Validate actual trace seeds refusal controls and final Source custody + id: capture_custody + if: always() + timeout-minutes: 1 + run: | + /usr/bin/python3 -I -B -S - finish <<'PYREG_CUSTODY' + import hashlib, json, os, stat, sys + from pathlib import Path + def read(path, limit): + directory = os.open('/', os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + descriptor = None + try: + for part in path.parts[1:-1]: + following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory) + os.close(directory); directory = following + descriptor = os.open(path.name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=directory) + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or not 0 <= before.st_size <= limit: raise ValueError('Unsafe bounded loader input') + chunks, total = [], 0 + while total <= limit: + block = os.read(descriptor, min(65536, limit+1-total)) + if not block: break + chunks.append(block); total += len(block) + after = os.fstat(descriptor); named = os.stat(path.name, dir_fd=directory, follow_symlinks=False) + shape = lambda row:(row.st_dev,row.st_ino,row.st_mode,row.st_nlink,row.st_size,row.st_mtime_ns,row.st_ctime_ns) + raw = b''.join(chunks) + if shape(before) != shape(after) or shape(after) != shape(named) or len(raw) != before.st_size: raise ValueError('Loader input changed') + return raw + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + phase = sys.argv[1] + if phase not in ('baseline','candidate','finish'): raise ValueError('Fixed phase only') + root = Path.cwd().resolve(strict=True) + workflow = root/'.github/workflows/current-site-transition-candidate.yml' + raw = read(workflow,262144) + state = json.loads(read(Path(os.environ['RUNNER_TEMP']).resolve(strict=True)/'site-transition-capture-regression/job-state.json',262144)) + if state.get('inputs'): + row = next(row for row in state['inputs'] if row['relative'] == '.github/workflows/current-site-transition-candidate.yml') + if row['pin'] != {'bytes':len(raw),'sha256':hashlib.sha256(raw).hexdigest()}: raise ValueError('Actual workflow driver Source drift') + lines = raw.splitlines(keepends=True) + header = b" /usr/bin/python3 -I -B -S - prepare <<'PYREG_DRIVER'\n" + starts = [index for index,line in enumerate(lines) if line == header] + if len(starts) != 1: raise ValueError('Unique reviewed workflow driver required') + end = lines.index(b' PYREG_DRIVER\n',starts[0]+1) + body = lines[starts[0]+1:end] + if not body or any(not line.startswith(b' ') for line in body): raise ValueError('Workflow scalar indentation') + source = b''.join(line[10:] for line in body) + sys.argv = ['reviewed-workflow-inline-driver',phase] + namespace = {'__name__':'__main__'} + exec(compile(source,str(workflow)+'#PYREG_DRIVER','exec'),namespace) + # Pure-function controls over actual captured trace seeds; never process receipts. + state = namespace['object_json'](namespace['safe_read'](namespace['base']/'job-state.json',262144)) + base = namespace['base']; safe_read = namespace['safe_read']; object_json = namespace['object_json'] + write_json = namespace['write_json']; controls = []; seeds = {} + state['utility_controls'] = {'classification':'HOLD_NOT_RUN','lane':'ACTUAL_HELPER_PURE_FUNCTIONS_WITH_SYNTHETIC_MUTATIONS','controls':controls,'seeds':seeds} + expected_ids = ['baseline_trace_positive','baseline_outcome_positive','candidate_trace_positive','candidate_outcome_positive','unknown_kind','duplicate_endpoint','reversed_spawn_pair','unlisted_argv','wrong_identity','extra_schema_field','wrong_case_order','trace_at_cap','observed_cwd_positive','wrong_observed_cwd','wrong_causal_baseline','wrong_candidate_witness'] + refusal_messages = {'unknown_kind':'Unknown trace kind','duplicate_endpoint':'Unique first launcher endpoint','reversed_spawn_pair':'Spawn must follow its unique begin','unlisted_argv':'Actual argv/hash/Source join','wrong_identity':'Spawned identity/actual argv join','extra_schema_field':'CASE_BEGIN schema','wrong_case_order':'Canonical actual case order','trace_at_cap':'Partial/oversized trace','wrong_observed_cwd':'Observed launch cwd mismatch'} + def clone(value): return json.loads(json.dumps(value)) + def control(identifier, api, selection, mutation, payload, expected, invoke): + row = {'id':identifier,'api':api,'selection':selection,'lane':'SYNTHETIC_PURE_FUNCTION_CONTROL' if mutation else 'ACTUAL_CAPTURED_SEED_CONTROL','mutation':mutation,'seed_trace_sha256':seeds[selection]['trace']['sha256'],'input_bytes':len(payload),'input_sha256':hashlib.sha256(payload).hexdigest(),'expected':expected,'result':'NOT_RUN'} + controls.append(row) + try: + observed = invoke() + except ValueError as error: + message = refusal_messages.get(identifier) + accepted = expected == 'ValueError' and str(error) == message + row.update(result='EXPECTED_REFUSAL' if accepted else 'UNEXPECTED_REFUSAL',error=type(error).__name__,detail=str(error)[:512],expected_refusal_detail=message) + if not accepted: raise + else: + accepted = expected != 'ValueError' and observed == expected + row.update(result='EXPECTED_VALUE' if accepted else 'UNEXPECTED_VALUE',observed=observed) + if not accepted: raise ValueError('Utility control unexpectedly admitted/refused: '+identifier) + try: + if state.get('disposition') != 'PENDING_UTILITY_CONTROLS' or state.get('errors'): raise ValueError('Control seeds not admitted') + namespace['clean_environment'](state); namespace['capture_rows'](state,'before_utility_controls') + supervisor = namespace['helper'](state) + contract_raw = safe_read(base/'contract.json',65536); contract = object_json(contract_raw) + summaries, traces, receipts = {}, {}, {} + for selection in ('baseline','candidate'): + trace = safe_read(base/(selection+'.spawn-trace.json'),65536) + receipt_raw = safe_read(base/(selection+'.receipt.json'),262144); receipt = object_json(receipt_raw) + identity = receipt['leader_identity_at_pidfd'] + seeds[selection] = {'trace':namespace['pin'](trace),'receipt':namespace['pin'](receipt_raw),'contract':namespace['pin'](contract_raw),'integer_exit':receipt['integer_exit'],'leader_identity':identity,'supervisor_pid':identity['ppid']} + traces[selection], receipts[selection] = trace, receipt + def validate(body, selected=selection, observed=receipt, held=identity): + return supervisor.validate_trace(body,contract,selected,observed['integer_exit'],observed['leader_pid'],held['ppid'],held) + summaries[selection] = validate(trace) + control(selection+'_trace_positive','validate_trace',selection,None,trace,state['staged_root'],lambda:validate(trace)['verified_observed_cwd']) + expected = 'BASELINE_CAUSAL_RED' if selection == 'baseline' else 'CANDIDATE_20_GREEN' + control(selection+'_outcome_positive','validate_regression_outcome',selection,None,supervisor.compact(summaries[selection]),expected,lambda:supervisor.validate_regression_outcome(summaries[selection],selection)) + events = summaries['candidate']['events'] + first_spawn = next(i for i,row in enumerate(events) if row['kind']=='SPAWN_BEGIN') + spawned = next(i for i,row in enumerate(events) if row['kind']=='SPAWNED') + cases = [i for i,row in enumerate(events) if row['kind']=='CASE_BEGIN'] + mutations = [] + def changed(identifier,index,key,value): + rows = clone(events); old = rows[index][key]; rows[index][key] = value + mutations.append((identifier,{'operation':'replace','index':index,'key':key,'before':old,'after':value},rows)) + changed('unknown_kind',1,'kind','UNKNOWN_CONTROL_KIND') + rows=clone(events);rows.insert(1,clone(rows[0]));mutations.append(('duplicate_endpoint',{'operation':'insert_clone','source_index':0,'at_index':1},rows)) + if spawned != first_spawn+1: raise ValueError('Actual seed does not have adjacent first spawn pair') + rows=clone(events);rows[first_spawn],rows[spawned]=rows[spawned],rows[first_spawn];mutations.append(('reversed_spawn_pair',{'operation':'swap','indices':[first_spawn,spawned]},rows)) + rows=clone(events);old=clone(rows[first_spawn]['argv']);rows[first_spawn]['argv'][-1]+=' # MUTATED_CONTROL';rows[first_spawn]['argv_sha256']=hashlib.sha256(supervisor.compact(rows[first_spawn]['argv'])).hexdigest();mutations.append(('unlisted_argv',{'operation':'replace_and_rehash_argv','index':first_spawn,'before':old,'after':rows[first_spawn]['argv']},rows)) + changed('wrong_identity',spawned,'ppid',events[spawned]['ppid']+1) + rows=clone(events);rows[1]['unexpected_control_field']=True;mutations.append(('extra_schema_field',{'operation':'add','index':1,'key':'unexpected_control_field','value':True},rows)) + rows=clone(events);old={'case_id':rows[cases[0]]['case_id'],'runtime_id':rows[cases[0]]['runtime_id']};new={key:rows[cases[1]][key] for key in old};rows[cases[0]].update(new);mutations.append(('wrong_case_order',{'operation':'replace_fields','index':cases[0],'before':old,'after':new},rows)) + for identifier,mutation,rows in mutations: + mutation['sequence_policy']='renumber_consecutive_indices' + for index,row in enumerate(rows):row['sequence']=index + body=b''.join(supervisor.compact(row) for row in rows) + control(identifier,'validate_trace','candidate',mutation,body,'ValueError',lambda:validate(body)['verified_observed_cwd']) + body=b'X'*65536 + control('trace_at_cap','validate_trace','candidate',{'operation':'replace_body','byte':88,'count':65536},body,'ValueError',lambda:validate(body)['verified_observed_cwd']) + cwd=summaries['candidate']['verified_observed_cwd'] + for identifier,observed,expected in [('observed_cwd_positive',cwd,cwd),('wrong_observed_cwd',cwd+'-wrong-control','ValueError')]: + payload=supervisor.compact({'contract_sha256':state['contract_pin']['sha256'],'observed_cwd':observed}) + control(identifier,'validate_launch_cwd','candidate',None if identifier.endswith('positive') else {'operation':'append_observed_cwd','suffix':'-wrong-control'},payload,expected,lambda:supervisor.validate_launch_cwd(contract,observed)) + for selection,identifier,key,value in [('baseline','wrong_causal_baseline','caught_type','OSError'),('candidate','wrong_candidate_witness','post_source_opens',0)]: + summary=clone(summaries[selection]);index=next(i for i,row in enumerate(summary['events']) if row['kind']=='CASE_WITNESS');old=summary['events'][index][key];summary['events'][index][key]=value + control(identifier,'validate_regression_outcome',selection,{'operation':'replace_summary_event_field','index':index,'key':key,'before':old,'after':value},supervisor.compact(summary),'HOLD',lambda:supervisor.validate_regression_outcome(summary,selection)) + if [row['id'] for row in controls] != expected_ids or any(row['result'] not in ('EXPECTED_VALUE','EXPECTED_REFUSAL') for row in controls): raise ValueError('Exact utility control census') + release=Path('/etc/os-release').resolve(strict=True); release_raw=safe_read(release,4096); release_text=release_raw.decode('ascii') + release_fields=dict(line.split('=',1) for line in release_text.splitlines() if '=' in line and not line.startswith('#')) + if release_fields.get('ID','').strip('"')!='ubuntu' or release_fields.get('VERSION_ID','').strip('"')!='24.04': raise ValueError('Unsupported Linux image route') + state['supported_software_observation']={'uname':list(os.uname()),'os_release':{'path':str(release),**namespace['pin'](release_raw),'text':release_text},'python':contract['interpreter'],'python_version_observed':list(sys.version_info[:3]),'pidfd_open_api':hasattr(os,'pidfd_open'),'pidfd_send_signal_api':hasattr(namespace['signal'],'pidfd_send_signal'),'selections':{key:{field:receipts[key].get(field) for field in ('elapsed_seconds','integer_exit','timeout','cap','cleanup','interpreter_after','captures')} for key in receipts},'qualification':'SCOPED_SOFTWARE_CI_OBSERVATION_ONLY_NOT_SCIENTIFIC_OR_CARRIER_ADMISSION'} + state['utility_controls']['classification']='PASS_16_PURE_FUNCTION_CONTROLS' + state['disposition']='PASS_CAPTURE_REGRESSIONS' + except BaseException as error: + state['disposition']='HOLD';state['errors'].append({'phase':'utility_controls','error':type(error).__name__,'detail':str(error)[:1024]}) + finally: + try:namespace['capture_rows'](state,'after_utility_controls_final') + except BaseException as error: + state['disposition']='HOLD';state['errors'].append({'phase':'utility_final_custody','error':type(error).__name__}) + for name in ('job-state.json','job-context.json','disposition.json'): + try: + value=state if name=='job-state.json' else {key:value for key,value in state.items() if key not in ('inputs','custody','external_custody')} + if name=='disposition.json':value={'classification':state['disposition'],'baseline':state['baseline'],'candidate':state['candidate'],'utility_controls':state['utility_controls'],'supported_software_observation':state.get('supported_software_observation'),'errors':state['errors'],'preservation':state.get('preservation',{}),'scientific_effect':'NONE','carrier_support':'PENDING_ACTUAL_LOG_QUALIFICATION','native_workflow_source_binding':'EXTERNAL_ROOT_GATE'} + write_json(base/name,value,262144 if name=='job-state.json' else 65536) + except BaseException as error: + state['disposition']='HOLD';state['errors'].append({'phase':'utility_save','member':name,'error':type(error).__name__}) + print('CS_CAPTURE_REGRESSION_UTILITY_HOLD '+name+' '+type(error).__name__) + if state['disposition']!='PASS_CAPTURE_REGRESSIONS':raise SystemExit(1) + PYREG_CUSTODY + - name: Always emit the fifteen complete bounded regression evidence members + id: capture_emission + if: always() + timeout-minutes: 2 + env: + CS_CHECKOUT_OUTCOME: ${{ steps.capture_checkout.outcome }} + CS_PREPARE_OUTCOME: ${{ steps.capture_prepare.outcome }} + CS_BASELINE_OUTCOME: ${{ steps.capture_baseline.outcome }} + CS_CANDIDATE_OUTCOME: ${{ steps.capture_candidate.outcome }} + CS_CUSTODY_OUTCOME: ${{ steps.capture_custody.outcome }} + run: | + /usr/bin/python3 -I -B -S - <<'PYREG_EVIDENCE' + import base64, hashlib, json, os, stat, sys + from pathlib import Path + base = Path(os.environ['RUNNER_TEMP']).resolve(strict=True)/'site-transition-capture-regression' + limits = {'job-context.json':65536,'source-before.json':262144,'source-after.json':262144, + 'contract.json':65536,'baseline.stdout.bin':1048576,'baseline.stderr.bin':1048576, + 'baseline.receipt.json':262144,'baseline.witness.json':65536, + 'candidate.stdout.bin':1048576,'candidate.stderr.bin':1048576, + 'candidate.receipt.json':262144,'candidate.witness.json':131072, + 'disposition.json':65536,'baseline.spawn-trace.json':65536,'candidate.spawn-trace.json':65536} + def encoded(value): return (json.dumps(value,sort_keys=True,indent=2,ensure_ascii=True)+'\n').encode('ascii') + def read(path,limit): + directory = os.open('/',os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW); descriptor = None + try: + for part in path.parts[1:-1]: + following=os.open(part,os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW,dir_fd=directory) + os.close(directory);directory=following + descriptor=os.open(path.name,os.O_RDONLY|os.O_NOFOLLOW|os.O_NONBLOCK,dir_fd=directory) + before=os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink!=1 or not 0<=before.st_size<=limit:raise ValueError('Unsafe bounded evidence') + chunks,total=[],0 + while total<=limit: + block=os.read(descriptor,min(65536,limit+1-total)) + if not block:break + chunks.append(block);total+=len(block) + after=os.fstat(descriptor);named=os.stat(path.name,dir_fd=directory,follow_symlinks=False) + shape=lambda row:(row.st_dev,row.st_ino,row.st_mode,row.st_nlink,row.st_size,row.st_mtime_ns,row.st_ctime_ns) + raw=b''.join(chunks) + if shape(before)!=shape(after) or shape(after)!=shape(named) or len(raw)!=before.st_size:raise ValueError('Evidence changed') + return raw + finally: + if descriptor is not None:os.close(descriptor) + os.close(directory) + missing, refused, files = [], [], {} + for name,limit in limits.items(): + try: files[name]=read(base/name,limit) + except FileNotFoundError: + missing.append(name) + files[name]=b'' if name.endswith('.bin') or name.endswith('.spawn-trace.json') else encoded({'status':'HOLD_MISSING_EVIDENCE','member':name,'scientific_effect':'NONE'}) + except BaseException as error: + refused.append({'member':name,'error':type(error).__name__}) + files[name]=encoded({'status':'HOLD_UNREADABLE_EVIDENCE','member':name,'error':type(error).__name__,'scientific_effect':'NONE'}) + try: disposition=json.loads(files['disposition.json']) + except (ValueError,UnicodeError): disposition={} + if type(disposition) is not dict:disposition={} + try: context=json.loads(files['job-context.json']) + except (ValueError,UnicodeError): context={} + if type(context) is not dict:context={} + tables=[row.get('preservation',{}) for row in (context,disposition)] + for selection in ('baseline','candidate'): + for suffix in ('stdout.bin','stderr.bin','spawn-trace.json','receipt.json'): + member=selection+'.'+suffix + records=[table.get(member) for table in tables if type(table) is dict and type(table.get(member)) is dict] + refusal=next((row for row in records if row.get('status')=='REFUSED'),None) + absent=any(row.get('status')=='MISSING' for row in records) + copied=any(row.get('status')=='COPIED' for row in records) + if refusal is not None: + if not any(row.get('member')==member for row in refused):refused.append({'member':member,'error':refusal.get('error','UnknownRefusal'),'stage':refusal.get('stage'),'detail':refusal.get('detail','')}) + elif absent or not copied: + if member not in missing:missing.append(member) + outcomes={key:os.environ.get(key) for key in ('CS_CHECKOUT_OUTCOME','CS_PREPARE_OUTCOME','CS_BASELINE_OUTCOME','CS_CANDIDATE_OUTCOME','CS_CUSTODY_OUTCOME')} + passed=disposition.get('classification')=='PASS_CAPTURE_REGRESSIONS' and not missing and not refused and all(value=='success' for value in outcomes.values()) + if len(files)!=15 or any(len(raw)>limits[name] for name,raw in files.items()) or sum(map(len,files.values()))>5767168:raise ValueError('Carrier raw census/cap HOLD') + rows=[{'name':name,'bytes':len(raw),'sha256':hashlib.sha256(raw).hexdigest(),'chunks':(len(raw)+3071)//3072} for name,raw in files.items()] + manifest=encoded({'schema_version':1,'carrier':'CS_CAPTURE_REGRESSION','members':rows,'member_count':15,'raw_bytes':sum(map(len,files.values())),'classification':'PASS_CAPTURE_REGRESSIONS' if passed else 'HOLD','step_outcomes':outcomes,'missing_original_members':missing,'refused_original_members':refused,'original_bytes_substituted_only_when_unavailable':True,'wire_cap':10485760,'scientific_effect':'NONE'}) + wire=0 + def emit(line): + global wire + raw=(line+'\n').encode('ascii');wire+=len(raw) + if wire>10485760:raise ValueError('Carrier wire cap HOLD') + sys.stdout.buffer.write(raw) + emit('CS_CAPTURE_REGRESSION_BEGIN 1 15 '+str(sum(map(len,files.values())))+' '+hashlib.sha256(manifest).hexdigest()) + emit('CS_CAPTURE_REGRESSION_MANIFEST '+base64.b64encode(manifest).decode('ascii')) + chunks=0 + for row in rows: + name=row['name'];raw=files[name] + emit('CS_CAPTURE_REGRESSION_FILE '+name+' '+str(len(raw))+' '+row['sha256']+' '+str(row['chunks'])) + for index,start in enumerate(range(0,len(raw),3072)): + block=raw[start:start+3072];chunks+=1 + emit('CS_CAPTURE_REGRESSION_CHUNK '+name+' '+str(index)+' '+str(len(block))+' '+hashlib.sha256(block).hexdigest()+' '+base64.b64encode(block).decode('ascii')) + emit('CS_CAPTURE_REGRESSION_FILE_END '+name+' '+str(row['chunks'])+' '+row['sha256']) + emit('CS_CAPTURE_REGRESSION_END 15 '+str(chunks)+' '+str(sum(map(len,files.values())))+' '+hashlib.sha256(manifest).hexdigest()) + sys.stdout.buffer.flush() + if not passed:raise SystemExit(1) + PYREG_EVIDENCE diff --git a/.github/workflows/site-asset-rewrite-proposal.yml b/.github/workflows/site-asset-rewrite-proposal.yml new file mode 100644 index 000000000..045f90bd3 --- /dev/null +++ b/.github/workflows/site-asset-rewrite-proposal.yml @@ -0,0 +1,125 @@ +# SOURCE-FROZEN R1 DRAFT: no hosted execution or mechanical rewrite acceptance is claimed. +name: Site asset rewrite proposal +'on': + pull_request: + types: [opened, synchronize, reopened] + branches: [main] + paths: + - 'docs/site/**' + - 'docs/public-math/**' + - 'tools/site_asset_release.py' + - 'tools/site_asset_rewrite_observation.py' + - 'tools/site_transition_source_guard.py' + - 'tests/test_site_transition_source_guard.py' + - 'tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json' + - '.github/workflows/site-asset-rewrite-proposal.yml' +permissions: + contents: read +jobs: + exact-mechanical-proposal: + runs-on: ubuntu-24.04 + timeout-minutes: 6 + permissions: + contents: read + steps: + - name: Check out the tested pull request merge + id: checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.sha }} + fetch-depth: 2 + persist-credentials: false + clean: true + - name: Guard capture source and emit a bounded exact proposal or HOLD + if: always() + env: + CHECKOUT_OUTCOME: ${{ steps.checkout.outcome }} + SITE_ASSET_CANDIDATE_FREEZE_SHA256: 08599cdf4c4251932e92ed622bf695db1bb502578fcb2c60da42daa89ebace5e + run: | + python3 -I -B -S - <<'PYBOOTSTRAP' + import hashlib, os, resource, signal, stat, subprocess, sys, tempfile + from pathlib import Path + try: + if os.environ.get('CHECKOUT_OUTCOME') != 'success': + raise ValueError('checkout') + root = Path.cwd().resolve(strict=True) + path = root / 'tools/site_asset_rewrite_observation.py' + if (root / 'tools').is_symlink() or not (root / 'tools').is_dir(): + raise ValueError('ancestor') + descriptor = os.open(path, os.O_RDONLY | os.O_NOFOLLOW) + try: + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or before.st_size > 32768: + raise ValueError('file') + raw = os.read(descriptor, 32769) + after = os.fstat(descriptor) + identity = lambda s: (s.st_dev, s.st_ino, s.st_mode, s.st_nlink, s.st_size, s.st_mtime_ns, s.st_ctime_ns) + if (len(raw) != before.st_size or identity(before) != identity(after) + or hashlib.sha256(raw).hexdigest() != 'befe4c3fc01a6c82766598c89ebf073a752ebb2e792d1b8a3721db742c72deb7'): + raise ValueError('source') + finally: + os.close(descriptor) + guard_path = root / 'tools/site_transition_source_guard.py' + descriptor = os.open(guard_path, os.O_RDONLY | os.O_NOFOLLOW) + try: + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or before.st_size != 4249: + raise ValueError('guard_file') + guard_raw = os.read(descriptor, 8193) + after = os.fstat(descriptor) + if (len(guard_raw) != 4249 or identity(before) != identity(after) + or hashlib.sha256(guard_raw).hexdigest() != '69aa32de61db44014f3b78a4374dda1852ab6854fbf4ac988abef6abf88e1fc6'): + raise ValueError('guard_source') + finally: + os.close(descriptor) + # Buffer the capture process too: setup/import errors never echo + # an arbitrary traceback or a partial apparently complete set. + temporary = Path(os.environ['RUNNER_TEMP']).resolve(strict=True) + if temporary.is_relative_to(root): + raise ValueError('temporary') + with tempfile.TemporaryDirectory(prefix='site-asset-carrier-', dir=temporary) as directory: + directory = Path(directory) + os.chmod(directory, 0o700) + # Run the exact authenticated capture bytes from the owned carrier directory. + staged_capture = directory / 'capture.py' + with staged_capture.open('xb') as stream: stream.write(raw) + staged_capture.chmod(0o444) + output, errors = directory / 'stdout', directory / 'stderr' + process, timed_out = None, False + def cap(): + resource.setrlimit(resource.RLIMIT_FSIZE, (1048576, 2097152)) + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + try: + with output.open('xb') as out, errors.open('xb') as err: + process = subprocess.Popen([sys.executable, '-I', '-B', '-S', str(staged_capture)], + stdin=subprocess.DEVNULL, stdout=out, stderr=err, + start_new_session=True, preexec_fn=cap) + try: + code = process.wait(timeout=300) + except subprocess.TimeoutExpired: + timed_out = True + code = None + finally: + if process is not None: + try: os.killpg(process.pid, signal.SIGKILL) + except ProcessLookupError: pass + try: process.wait(timeout=5) + except subprocess.TimeoutExpired: timed_out = True + with output.open('rb') as stream: + carrier = stream.read(950001) + with errors.open('rb') as stream: + error_bytes = stream.read(65537) + if timed_out or len(carrier) > 950000 or error_bytes or code not in (0, 1): + raise ValueError('capture') + expected = (b'disposition=PROPOSAL_COMPLETE_REQUIRES_REVIEW' if code == 0 + else b'disposition=HOLD') + lines = carrier.splitlines() + if not lines or not lines[-1].startswith(b'CS_ASSET_COMPLETE ') or not lines[-1].endswith(expected): + raise ValueError('incomplete') + sys.stdout.buffer.write(carrier) + sys.stdout.buffer.flush() + raise SystemExit(code) + except Exception: + print('CS_ASSET_HOLD code=BOOTSTRAP_OR_CAPTURE_SOURCE_ERROR complete_set=false', flush=True) + raise SystemExit(1) + PYBOOTSTRAP diff --git a/docs/site/atlas-claim-summary.mjs b/docs/site/atlas-claim-summary.mjs index a5142e7ba..2b2b0d2fc 100644 --- a/docs/site/atlas-claim-summary.mjs +++ b/docs/site/atlas-claim-summary.mjs @@ -1,7 +1,7 @@ -import {element,anchor} from './current.mjs?site-release=fc7e8a98c1e23f476962c4c83e95ed3ce817490007987112d9b2cf6d3d90b142'; -import {sourceForNode,sourceURL} from './current-model.mjs?site-release=a30d68465e3acda48eedce64854afebc7af5c84903a4e6b0c649e08007b08999'; +import {element,anchor} from './current.mjs?site-release=f739c9840cf6ee25ce9d3ca809e030f6652751fc6b9b21d3c5d3f398dbf82438'; +import {sourceForNode,sourceURL} from './current-model.mjs?site-release=4852e23a5fe1f95b7c7ec91ff3f9472e2c614fe962f7c328cc57bcf36aba950e'; -import {createFormalEvidence} from './atlas-formal-evidence.mjs?site-release=fd282a960cfe2944617c2227b25ef1455bc6b142dced7b33ad1af99bc0d56f87'; +import {createFormalEvidence} from './atlas-formal-evidence.mjs?site-release=aef53faa1be1af618d80d17f75bbc320560f6a03bbc3060aacd4db99f898b2c5'; // Presentation over the controller's admitted record. No acquisition, source // adoption, proof coverage inference, or scientific-status authority lives here. diff --git a/docs/site/atlas-formal-evidence-model.mjs b/docs/site/atlas-formal-evidence-model.mjs index 329787d83..7363137e1 100644 --- a/docs/site/atlas-formal-evidence-model.mjs +++ b/docs/site/atlas-formal-evidence-model.mjs @@ -1,4 +1,4 @@ -import {sourceForNode,sourceURL} from './current-model.mjs?site-release=a30d68465e3acda48eedce64854afebc7af5c84903a4e6b0c649e08007b08999'; +import {sourceForNode,sourceURL} from './current-model.mjs?site-release=4852e23a5fe1f95b7c7ec91ff3f9472e2c614fe962f7c328cc57bcf36aba950e'; import {EVIDENCE} from './atlas-formal-evidence-data.mjs?site-release=1ef5a9f4aa04b860ad8debf6b1981d0485b7bc1d8f0d970095e29ac2fe895d73'; const canonical=value=>JSON.stringify(value&&typeof value==='object'&&!Array.isArray(value) diff --git a/docs/site/atlas-formal-evidence.mjs b/docs/site/atlas-formal-evidence.mjs index 2f841a40e..179476dad 100644 --- a/docs/site/atlas-formal-evidence.mjs +++ b/docs/site/atlas-formal-evidence.mjs @@ -1,6 +1,6 @@ -import {element,anchor} from './current.mjs?site-release=fc7e8a98c1e23f476962c4c83e95ed3ce817490007987112d9b2cf6d3d90b142'; -import {sourceURL} from './current-model.mjs?site-release=a30d68465e3acda48eedce64854afebc7af5c84903a4e6b0c649e08007b08999'; -import {formalConnection} from './atlas-formal-evidence-model.mjs?site-release=36dbb1f470e2c49e660275ff8090f74e56489b4cda5d0ccfd7b25b67e276f348'; +import {element,anchor} from './current.mjs?site-release=f739c9840cf6ee25ce9d3ca809e030f6652751fc6b9b21d3c5d3f398dbf82438'; +import {sourceURL} from './current-model.mjs?site-release=4852e23a5fe1f95b7c7ec91ff3f9472e2c614fe962f7c328cc57bcf36aba950e'; +import {formalConnection} from './atlas-formal-evidence-model.mjs?site-release=9f8914bce2dbd78137539cceafc0d9b3ce5e7efd71feda150fa2c1b142905de7'; const receiptURL=new URL('./evidence/side24-main-3b39/receipt.json',import.meta.url).href; const typesURL=new URL('./evidence/side24-main-3b39/elaborated-types.log',import.meta.url).href; diff --git a/docs/site/atlas-shell.mjs b/docs/site/atlas-shell.mjs index 51bf957a9..8b397ac57 100644 --- a/docs/site/atlas-shell.mjs +++ b/docs/site/atlas-shell.mjs @@ -1,4 +1,4 @@ -import {installSpatialAtlas} from './atlas-spatial-shell.mjs?site-release=dbd841649f10dfbc4d2446521bba88396c532ed7a9b9df36866709af32d4ee2f'; +import {installSpatialAtlas} from './atlas-spatial-shell.mjs?site-release=3b00b531b051e842de809acb49dcbe03b78d040871437de53bf9a4a4bb63cfd8'; // Presentation only: this module never fetches, admits or classifies source data. export function viewForViewport(search,parsedView,narrow){ const requested=new URLSearchParams(search).get('atlas-view'); diff --git a/docs/site/atlas-spatial-shell.mjs b/docs/site/atlas-spatial-shell.mjs index 34bb4438c..029d8c85e 100644 --- a/docs/site/atlas-spatial-shell.mjs +++ b/docs/site/atlas-spatial-shell.mjs @@ -44,7 +44,7 @@ export function installSpatialAtlas({root,onChange}) { } function schedule(){if(!frame&&!disposed)frame=requestAnimationFrame(sync);} async function activate(){failureMessage='';active=true;const ticket=++generation;lastSignature='';status.textContent='Loading optional 3D renderer…';display(); - try{const [{currentSnapshot},{createSpatialRenderer}]=await Promise.all([import('./current.mjs?site-release=fc7e8a98c1e23f476962c4c83e95ed3ce817490007987112d9b2cf6d3d90b142'),import('./atlas-spatial.mjs?site-release=51162684675faa743673966321e285a5b533743b5e7b84005f0b4055dbdd5761')]);const snapshot=await currentSnapshot;if(ticket!==generation||disposed)return;if(!snapshot||refused())throw Error('source snapshot or bookmark did not verify');data=snapshot;renderer=createSpatialRenderer({host,onPick:pick,onFailure:fail});sync();} + try{const [{currentSnapshot},{createSpatialRenderer}]=await Promise.all([import('./current.mjs?site-release=f739c9840cf6ee25ce9d3ca809e030f6652751fc6b9b21d3c5d3f398dbf82438'),import('./atlas-spatial.mjs?site-release=51162684675faa743673966321e285a5b533743b5e7b84005f0b4055dbdd5761')]);const snapshot=await currentSnapshot;if(ticket!==generation||disposed)return;if(!snapshot||refused())throw Error('source snapshot or bookmark did not verify');data=snapshot;renderer=createSpatialRenderer({host,onPick:pick,onFailure:fail});sync();} catch(error){if(ticket===generation&&!disposed)fail(`3D unavailable: ${error.message}.`);} } function deactivate(){generation++;active=false;renderer?.dispose();renderer=null;delete host.dataset.ready;delete host.dataset.frames;lastSignature='';display();status.textContent='3D paused. Graph and List retain the selected claim and source snapshot.';} @@ -59,7 +59,7 @@ export function installSpatialAtlas({root,onChange}) { listen(window,'pagehide',()=>{deactivate();});listen(window,'pageshow',()=>restore(location.href)); function restore(url){const params=new URL(url,location.href).searchParams;focused=params.get('atlas-space-focus')==='dependencies';const wants=params.get('atlas-space')==='3d';if(wants&&!active)activate();else if(!wants&&active)deactivate();else schedule();} function decorateURL(url){if(active)url.searchParams.set('atlas-space','3d');else url.searchParams.delete('atlas-space');if(active&&focused)url.searchParams.set('atlas-space-focus','dependencies');else url.searchParams.delete('atlas-space-focus');return url;} - import('./current.mjs?site-release=fc7e8a98c1e23f476962c4c83e95ed3ce817490007987112d9b2cf6d3d90b142').then(m=>m.currentSnapshot).then(snapshot=>{if(!disposed){data=snapshot;schedule();}}); + import('./current.mjs?site-release=f739c9840cf6ee25ce9d3ca809e030f6652751fc6b9b21d3c5d3f398dbf82438').then(m=>m.currentSnapshot).then(snapshot=>{if(!disposed){data=snapshot;schedule();}}); display();restore(location.href); return {restore,decorateURL,dispose(){disposed=true;deactivate();cancelAnimationFrame(frame);observer.disconnect();visibility.disconnect();cleanup.forEach(fn=>fn());}}; } diff --git a/docs/site/atlas.mjs b/docs/site/atlas.mjs index fe9622175..a2c9a3a82 100644 --- a/docs/site/atlas.mjs +++ b/docs/site/atlas.mjs @@ -1,7 +1,7 @@ -import {currentSnapshot,element,anchor} from './current.mjs?site-release=fc7e8a98c1e23f476962c4c83e95ed3ce817490007987112d9b2cf6d3d90b142'; -import {hasNode,readState,neighborhood,searchGraph,downstreamReach,requiredDependencyPaths,REQUIRED_ROUTE_SEMANTICS,evidenceAxes,sourceURL,sourceForNode,staticNodeLinks,resumeProjection,RESUME_NOT_RECORDED,resumeFieldHref} from './current-model.mjs?site-release=a30d68465e3acda48eedce64854afebc7af5c84903a4e6b0c649e08007b08999'; -import {createAtlasShell,viewForViewport} from './atlas-shell.mjs?site-release=b6853b9dc8f370daaa52ba7204b4880a191e50aa04719a4b3c8501cf7d8e36b0'; -import {createClaimSummary} from './atlas-claim-summary.mjs?site-release=c3282397f25caaf0882d47f4433279c88bab7471df6eaf5b123f1e357da30c94'; +import {currentSnapshot,element,anchor} from './current.mjs?site-release=f739c9840cf6ee25ce9d3ca809e030f6652751fc6b9b21d3c5d3f398dbf82438'; +import {hasNode,readState,neighborhood,searchGraph,downstreamReach,requiredDependencyPaths,REQUIRED_ROUTE_SEMANTICS,evidenceAxes,sourceURL,sourceForNode,staticNodeLinks,resumeProjection,RESUME_NOT_RECORDED,resumeFieldHref} from './current-model.mjs?site-release=4852e23a5fe1f95b7c7ec91ff3f9472e2c614fe962f7c328cc57bcf36aba950e'; +import {createAtlasShell,viewForViewport} from './atlas-shell.mjs?site-release=839ee9a1f6aecf8ac8ff6889c737a41c568c338d13677fe62360e3452f2e02ca'; +import {createClaimSummary} from './atlas-claim-summary.mjs?site-release=ad01419c575287a4f41a4db70e30bbf17f6f84629cfb48cc987c596d49712138'; import {enableAtlasView,reconcileEquationOptions,createEquationAnnouncement} from './atlas-controls.mjs?site-release=58e7dd9a4fcfc326effc240080bbfac0cadd584908f84047b480fd9dcba522c7'; const byId=id=>document.getElementById(id); const svgElement=(tag,attrs)=>{const n=document.createElementNS('http://www.w3.org/2000/svg',tag);for(const [k,v]of Object.entries(attrs))n.setAttribute(k,String(v));return n;}; diff --git a/docs/site/cite.html b/docs/site/cite.html index eddc54645..e8a6c570b 100644 --- a/docs/site/cite.html +++ b/docs/site/cite.html @@ -7,7 +7,7 @@ - +
UNIVERSAL LAW MATHEMATICS IN THE OPEN
diff --git a/docs/site/compare-model.mjs b/docs/site/compare-model.mjs index c65e830c7..5350c5d66 100644 --- a/docs/site/compare-model.mjs +++ b/docs/site/compare-model.mjs @@ -1,6 +1,6 @@ import {parseStrictJSON} from "./reader-json.mjs?site-release=730b0b4d5c93a9e5aa5eee3feddd4070e9480db86af489c2982bfa0e39fca706"; export {parseStrictJSON}; -import { validateSnapshot, parseVerifiedSnapshot } from "./current-model.mjs?site-release=a30d68465e3acda48eedce64854afebc7af5c84903a4e6b0c649e08007b08999"; +import { validateSnapshot, parseVerifiedSnapshot } from "./current-model.mjs?site-release=4852e23a5fe1f95b7c7ec91ff3f9472e2c614fe962f7c328cc57bcf36aba950e"; const HEX = /^[0-9a-f]{64}$/; const ORIGIN = "https://d6g8k5htny-coder.github.io/main/site/"; export const MAX_BYTES = 32 * 1024 * 1024; diff --git a/docs/site/compare.html b/docs/site/compare.html index e06069d55..71ffee8a4 100644 --- a/docs/site/compare.html +++ b/docs/site/compare.html @@ -11,10 +11,10 @@ - + - + diff --git a/docs/site/compare.mjs b/docs/site/compare.mjs index e6a297e5f..21b2cc7a0 100644 --- a/docs/site/compare.mjs +++ b/docs/site/compare.mjs @@ -3,8 +3,8 @@ import { loadSelection, compareSnapshots, selectionDescription, -} from "./compare-model.mjs?site-release=4036fca2cd4519e4d09f2e19ffd38e64b3b2e6ce1ef20840dc52a9941d77d946"; -import { sourceURL } from "./current-model.mjs?site-release=a30d68465e3acda48eedce64854afebc7af5c84903a4e6b0c649e08007b08999"; +} from "./compare-model.mjs?site-release=1f2c064486df73dd5a5cf9a0015ea17df2cc44ec0a65908bbeeddd50075985c8"; +import { sourceURL } from "./current-model.mjs?site-release=4852e23a5fe1f95b7c7ec91ff3f9472e2c614fe962f7c328cc57bcf36aba950e"; const $ = (id) => document.getElementById(id); let publication, generation = 0, diff --git a/docs/site/current-model.mjs b/docs/site/current-model.mjs index e053a8ae3..a2a82a4e1 100644 --- a/docs/site/current-model.mjs +++ b/docs/site/current-model.mjs @@ -65,18 +65,97 @@ export async function parseVerifiedSnapshot(raw,identity,cryptoAPI=globalThis.cr } export async function fetchVerifiedSnapshot(fetcher,identity,{signal,cryptoAPI=globalThis.crypto}={}) { if(!DIGEST.test(identity?.sha256)||!Number.isSafeInteger(Number(identity?.bytes))||Number(identity.bytes)<0)throw Error('Invalid current source identity.'); - const read=async url=>{ + // Abort also bounds response-body consumption. Cancellation is best-effort; + // waiting for a stalled stream's cancel promise would defeat that budget. + const abortable=(operation,cancel)=>new Promise((resolve,reject)=>{ + let settled=false; + const finish=(complete,value)=>{ + if(settled)return; + settled=true;signal?.removeEventListener('abort',abort);complete(value); + }; + const abort=()=>{ + const error=signal?.reason??Object.assign(Error('Current source request aborted.'),{name:'AbortError'}); + finish(reject,error); + try{Promise.resolve(cancel?.()).catch(()=>{});}catch{} + }; + if(signal?.aborted){abort();return;} + signal?.addEventListener('abort',abort,{once:true}); + try{Promise.resolve(operation()).then(value=>finish(resolve,value),error=>finish(reject,error));} + catch(error){finish(reject,error);} + }); + const request=async url=>{ const response=await fetcher(url,{cache:'no-store',credentials:'omit',signal}); if(!response.ok)throw Error('Current source snapshot unavailable.'); - return parseVerifiedSnapshot(await response.arrayBuffer(),identity,cryptoAPI); + return response; + }; + const readBytes=async (response,limit,oversized,streamOnly=false)=>{ + // Metadata requires a bounded streaming reader. Preserve arrayBuffer + // support for the existing payload transport when no stream is exposed. + if(!response.body?.getReader){ + if(streamOnly)throw Error('Current source metadata bounded reading unavailable.'); + return new Uint8Array(await abortable(()=>response.arrayBuffer(),()=>response.body?.cancel())); + } + const reader=response.body.getReader(),chunks=[]; + let size=0,cancelled=false; + const cancel=()=>{ + if(cancelled)return; + cancelled=true; + try{Promise.resolve(reader.cancel()).catch(()=>{});}catch{} + }; + try{ + for(;;){ + const {done,value}=await abortable(()=>reader.read(),cancel); + if(done)break; + if(!(value instanceof Uint8Array))throw Error('Invalid current source response bytes.'); + if(value.byteLength>limit-size)throw oversized(); + if(value.byteLength){chunks.push(value.slice());size+=value.byteLength;} + } + }catch(error){cancel();throw error;} + finally{try{reader.releaseLock();}catch{}} + const bytes=new Uint8Array(size); + let offset=0; + for(const chunk of chunks){bytes.set(chunk,offset);offset+=chunk.byteLength;} + return bytes; + }; + const read=async (url,descriptor=identity)=>{ + const response=await request(url); + const bytes=await readBytes(response,Number(descriptor.bytes),()=>new SnapshotIntegrityError('Current payload byte count mismatch.')); + return abortable(()=>parseVerifiedSnapshot(bytes,descriptor,cryptoAPI)); + }; + const readMetadata=async()=>{ + const bytes=await readBytes(await request('current-meta.json'),16384,()=>Error('Oversized current source metadata.'),true); + const text=new TextDecoder('utf-8',{fatal:true}).decode(bytes); + const metadata=JSON.parse(text); + if(!metadata||typeof metadata!=='object'||Array.isArray(metadata))throw Error('Invalid current source metadata.'); + const keys=Object.keys(metadata).sort().join(','); + if(keys!=='bytes,observed_at,sha256'&&keys!=='archive,bytes,history_manifest_sha256,observed_at,sha256')throw Error('Invalid current source metadata fields.'); + // JSON.parse keeps only the last duplicate member. Inspect complete JSON + // string tokens as well, so escaped spellings cannot conceal duplicates. + const seen=new Set(); + for(const token of text.matchAll(/"(?:\\.|[^"\\])*"/g)){ + if(!/^\s*:/.test(text.slice(token.index+token[0].length)))continue; + const key=JSON.parse(token[0]); + if(seen.has(key))throw Error('Duplicate current source metadata field.'); + seen.add(key); + } + const digest=value=>typeof value==='string'&&DIGEST.test(value); + const observed=metadata.observed_at; + if(!digest(metadata.sha256)||!Number.isSafeInteger(metadata.bytes)||metadata.bytes<0||metadata.bytes>16777216|| + typeof observed!=='string'||!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/.test(observed)|| + !Number.isFinite(Date.parse(observed))||new Date(observed).toISOString()!==observed.slice(0,-1)+'.000Z'|| + (seen.has('archive')&&(!digest(metadata.archive)||!digest(metadata.history_manifest_sha256))))throw Error('Invalid current source metadata identity.'); + return metadata; }; try{return await read('current.json');} - catch(error){ - if(!(error instanceof SnapshotIntegrityError))throw error; - // A mutable alias can lag the page across publication. One digest-keyed - // request may recover it; only the advertised bytes can be admitted. - return read('current.json?observation='+identity.sha256); - } + catch(error){if(signal?.aborted||!(error instanceof SnapshotIntegrityError))throw error;} + // A mutable alias can lag the page across publication. Preserve the old + // digest-keyed retry before considering one coherent successor observation. + try{return await read('current.json?observation='+identity.sha256);} + catch(error){if(signal?.aborted||!(error instanceof SnapshotIntegrityError))throw error;} + const metadata=await readMetadata(); + const snapshot=await read('current.json?observation='+metadata.sha256,metadata); + if(snapshot.observed_at!==metadata.observed_at)throw Error('Current source observation time mismatch.'); + return snapshot; } export function freshness(observed,now=Date.now()) { const age=now-Date.parse(observed); diff --git a/docs/site/current.mjs b/docs/site/current.mjs index 86d1b7b23..3a86f3faf 100644 --- a/docs/site/current.mjs +++ b/docs/site/current.mjs @@ -1,4 +1,4 @@ -import {fetchVerifiedSnapshot,freshness,filterSources,sourceURL,projectCurrentAcquisitions,ACQUISITION_LABELS,ACQUISITION_UNAVAILABLE} from './current-model.mjs?site-release=a30d68465e3acda48eedce64854afebc7af5c84903a4e6b0c649e08007b08999'; +import {fetchVerifiedSnapshot,freshness,filterSources,sourceURL,projectCurrentAcquisitions,ACQUISITION_LABELS,ACQUISITION_UNAVAILABLE} from './current-model.mjs?site-release=4852e23a5fe1f95b7c7ec91ff3f9472e2c614fe962f7c328cc57bcf36aba950e'; export function element(tag,text,className) { const e=document.createElement(tag);if(text!==undefined)e.textContent=text;if(className)e.className=className;return e; } diff --git a/docs/site/dependencies.html b/docs/site/dependencies.html index 7e6a92adc..6efc05c0c 100644 --- a/docs/site/dependencies.html +++ b/docs/site/dependencies.html @@ -15,8 +15,8 @@ - - + + diff --git a/docs/site/explore.html b/docs/site/explore.html index dad68f03f..829b94cac 100644 --- a/docs/site/explore.html +++ b/docs/site/explore.html @@ -14,7 +14,7 @@ - + diff --git a/docs/site/index.html b/docs/site/index.html index 1d7ab651c..161b3a937 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -8,7 +8,7 @@ - + diff --git a/docs/site/measure.html b/docs/site/measure.html index be08ef506..723ecb4df 100644 --- a/docs/site/measure.html +++ b/docs/site/measure.html @@ -13,7 +13,7 @@ - + diff --git a/docs/site/museum.html b/docs/site/museum.html index da668b96f..97eacc4f1 100644 --- a/docs/site/museum.html +++ b/docs/site/museum.html @@ -12,7 +12,7 @@ - + diff --git a/docs/site/reproduce.html b/docs/site/reproduce.html index 46de47c9d..d47d57123 100644 --- a/docs/site/reproduce.html +++ b/docs/site/reproduce.html @@ -8,7 +8,7 @@ - +
UNIVERSAL LAW MATHEMATICS IN THE OPEN
diff --git a/docs/site/research-desk.mjs b/docs/site/research-desk.mjs index a2abc3517..9db7a475b 100644 --- a/docs/site/research-desk.mjs +++ b/docs/site/research-desk.mjs @@ -1,5 +1,5 @@ // Reader-owned navigation notes. Never a source, proof or status authority. -import {currentSnapshot} from './current.mjs?site-release=fc7e8a98c1e23f476962c4c83e95ed3ce817490007987112d9b2cf6d3d90b142'; +import {currentSnapshot} from './current.mjs?site-release=f739c9840cf6ee25ce9d3ca809e030f6652751fc6b9b21d3c5d3f398dbf82438'; import {SCHEMA,MAX_FILE_BYTES,validateEntry,entryKey,parseReadingList,mergeEntries,sourceHref,searchHref,readingListJSON} from './research-desk-store.mjs?site-release=547418ff3547b671266d1e46bf8d33f1f3eedf83571f6a0bb69ca9d7786ffaf3'; import {readingListCitationHref} from './reading-list-citation.mjs?site-release=02153e8e3acb70abca98685f5b274c0472eea6450ed2e9c3fc3125a7b0196968'; import {startLibrarySourceSearch} from './library-source-search.mjs?site-release=0f7fa4196362a427e070fc49f58f8a2935840e9d797358cb9d325e5db44ee612'; diff --git a/docs/site/research.html b/docs/site/research.html index 816dfd310..a00c6fcc3 100644 --- a/docs/site/research.html +++ b/docs/site/research.html @@ -36,7 +36,7 @@

Source observation

Metadata only: discoverable identity without included document content. Parsed graph: source read and verified during generation; parsed data included. Reference identity: source read and verified during generation; identity retained, document text omitted. Included excerpts: exact text spans, not the complete document. Unavailable: no qualified association. Mathematical review: unknown in this inventory. Applicability: unknown in this inventory. Acceptance: unknown in this inventory. Unknown does not mean unreviewed, rejected or inapplicable.

History capacity: 2 of 512 mathematical archives; 26330173 of 805306368 conservative retained bytes (including registry and release-key allowances). Publication refuses additional versions at capacity; no history is pruned.

- +
Reading map and terminologyAll seven dated cuts, four introductory paths, and the words used in their records diff --git a/docs/site/workspace.html b/docs/site/workspace.html index 70dc9e397..82b28e0d1 100644 --- a/docs/site/workspace.html +++ b/docs/site/workspace.html @@ -11,10 +11,10 @@ - + - + diff --git a/tests/fixtures/current_site_transition_20261022/fixture-freeze.json b/tests/fixtures/current_site_transition_20261022/fixture-freeze.json new file mode 100644 index 000000000..c3f828987 --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/fixture-freeze.json @@ -0,0 +1,46 @@ +{ + "synthetic": true, + "scientific_effect": "NONE", + "files": [ + { + "path": "identities.json", + "bytes": 373, + "sha256": "529a03e76a134680e0efb639a370924dc8f702cebbaf67a5669e8515e4ae5d64" + }, + { + "path": "new-meta.json", + "bytes": 319, + "sha256": "7d9922dc2e14ac095ba863b5a2641a8a52739d3db98e427130c98a815095848c" + }, + { + "path": "new-observation.json", + "bytes": 1555, + "sha256": "3999e53aaa093b5c484d75f17aa6f07c204802d4cc3ffaf7afff2aaa9dda7544" + }, + { + "path": "new-same-length-corrupt.json", + "bytes": 1555, + "sha256": "aa713f87ab7fc238ac23e60b556ec3820b1313b77e055e436005efee084d829f" + }, + { + "path": "old-meta.json", + "bytes": 319, + "sha256": "bf194d013761c919b211395a6fa7df6eee9f0e6a3f81086f0e783c11621142d8" + }, + { + "path": "old-observation.json", + "bytes": 1322, + "sha256": "275e20b313114ef28732e57cd1311cbc7bbbccb4a8756ba2d5b7a3cb4f6821c4" + }, + { + "path": "old-same-length-corrupt.json", + "bytes": 1322, + "sha256": "12f04a1c852805fffac000899ec39c11147c726b96f5209bfb6dbaa8a74b0d63" + }, + { + "path": "production-source-freeze.json", + "bytes": 754, + "sha256": "0e036ad58f7898954a362e6737fb9d0a98fb0f725ff4b4efed66e98b0a1b6196" + } + ] +} diff --git a/tests/fixtures/current_site_transition_20261022/identities.json b/tests/fixtures/current_site_transition_20261022/identities.json new file mode 100644 index 000000000..95bb47f5f --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/identities.json @@ -0,0 +1,14 @@ +{ + "synthetic": true, + "scientific_effect": "NONE", + "old": { + "sha256": "275e20b313114ef28732e57cd1311cbc7bbbccb4a8756ba2d5b7a3cb4f6821c4", + "bytes": 1322, + "observed_at": "2026-10-22T21:10:00Z" + }, + "new": { + "sha256": "3999e53aaa093b5c484d75f17aa6f07c204802d4cc3ffaf7afff2aaa9dda7544", + "bytes": 1555, + "observed_at": "2026-10-22T21:29:17Z" + } +} diff --git a/tests/fixtures/current_site_transition_20261022/new-meta.json b/tests/fixtures/current_site_transition_20261022/new-meta.json new file mode 100644 index 000000000..7795954e1 --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/new-meta.json @@ -0,0 +1,7 @@ +{ + "archive": "4444444444444444444444444444444444444444444444444444444444444444", + "bytes": 1555, + "history_manifest_sha256": "6666666666666666666666666666666666666666666666666666666666666666", + "observed_at": "2026-10-22T21:29:17Z", + "sha256": "3999e53aaa093b5c484d75f17aa6f07c204802d4cc3ffaf7afff2aaa9dda7544" +} diff --git a/tests/fixtures/current_site_transition_20261022/new-observation.json b/tests/fixtures/current_site_transition_20261022/new-observation.json new file mode 100644 index 000000000..5819552fb --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/new-observation.json @@ -0,0 +1,55 @@ +{ + "equations": [], + "graph": { + "data": { + "edges": [], + "nodes": { + "fixture.node": { + "classification": "OPEN_ACTIVE", + "kind": "inventory", + "source": "fixture/GRAPH.json" + } + } + }, + "identity": { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "dddddddddddddddddddddddddddddddddddddddd", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-", + "sha256": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + } + }, + "observed_at": "2026-10-22T21:29:17Z", + "references": [], + "repositories": [ + { + "commit": "cccccccccccccccccccccccccccccccccccccccc", + "repository": "d6g8k5htny-coder/main", + "tree": "2222222222222222222222222222222222222222" + }, + { + "commit": "dddddddddddddddddddddddddddddddddddddddd", + "repository": "d6g8k5htny-coder/Math-", + "tree": "3333333333333333333333333333333333333333" + } + ], + "schema_version": 1, + "scientific_effect": "NONE", + "sources": [ + { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "dddddddddddddddddddddddddddddddddddddddd", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-" + }, + { + "blob": "1111111111111111111111111111111111111111", + "bytes": 12, + "commit": "cccccccccccccccccccccccccccccccccccccccc", + "path": "fixture/NEW_SOURCE.md", + "repository": "d6g8k5htny-coder/main" + } + ] +} diff --git a/tests/fixtures/current_site_transition_20261022/new-same-length-corrupt.json b/tests/fixtures/current_site_transition_20261022/new-same-length-corrupt.json new file mode 100644 index 000000000..563ed81c0 --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/new-same-length-corrupt.json @@ -0,0 +1,55 @@ +{ + "equations": [], + "graph": { + "data": { + "edges": [], + "nodes": { + "fixture.node": { + "classification": "OPEN_ACTIVE", + "kind": "inventory", + "source": "fixture/GRAPH.json" + } + } + }, + "identity": { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "dddddddddddddddddddddddddddddddddddddddd", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-", + "sha256": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + } + }, + "observed_at": "2026-10-22T21:29:18Z", + "references": [], + "repositories": [ + { + "commit": "cccccccccccccccccccccccccccccccccccccccc", + "repository": "d6g8k5htny-coder/main", + "tree": "2222222222222222222222222222222222222222" + }, + { + "commit": "dddddddddddddddddddddddddddddddddddddddd", + "repository": "d6g8k5htny-coder/Math-", + "tree": "3333333333333333333333333333333333333333" + } + ], + "schema_version": 1, + "scientific_effect": "NONE", + "sources": [ + { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "dddddddddddddddddddddddddddddddddddddddd", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-" + }, + { + "blob": "1111111111111111111111111111111111111111", + "bytes": 12, + "commit": "cccccccccccccccccccccccccccccccccccccccc", + "path": "fixture/NEW_SOURCE.md", + "repository": "d6g8k5htny-coder/main" + } + ] +} diff --git a/tests/fixtures/current_site_transition_20261022/old-meta.json b/tests/fixtures/current_site_transition_20261022/old-meta.json new file mode 100644 index 000000000..fa200a701 --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/old-meta.json @@ -0,0 +1,7 @@ +{ + "archive": "5555555555555555555555555555555555555555555555555555555555555555", + "bytes": 1322, + "history_manifest_sha256": "7777777777777777777777777777777777777777777777777777777777777777", + "observed_at": "2026-10-22T21:10:00Z", + "sha256": "275e20b313114ef28732e57cd1311cbc7bbbccb4a8756ba2d5b7a3cb4f6821c4" +} diff --git a/tests/fixtures/current_site_transition_20261022/old-observation.json b/tests/fixtures/current_site_transition_20261022/old-observation.json new file mode 100644 index 000000000..d3641278f --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/old-observation.json @@ -0,0 +1,48 @@ +{ + "equations": [], + "graph": { + "data": { + "edges": [], + "nodes": { + "fixture.node": { + "classification": "OPEN_ACTIVE", + "kind": "inventory", + "source": "fixture/GRAPH.json" + } + } + }, + "identity": { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-", + "sha256": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + } + }, + "observed_at": "2026-10-22T21:10:00Z", + "references": [], + "repositories": [ + { + "commit": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "repository": "d6g8k5htny-coder/main", + "tree": "2222222222222222222222222222222222222222" + }, + { + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "repository": "d6g8k5htny-coder/Math-", + "tree": "3333333333333333333333333333333333333333" + } + ], + "schema_version": 1, + "scientific_effect": "NONE", + "sources": [ + { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-" + } + ] +} diff --git a/tests/fixtures/current_site_transition_20261022/old-same-length-corrupt.json b/tests/fixtures/current_site_transition_20261022/old-same-length-corrupt.json new file mode 100644 index 000000000..4ea8bceb3 --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/old-same-length-corrupt.json @@ -0,0 +1,48 @@ +{ + "equations": [], + "graph": { + "data": { + "edges": [], + "nodes": { + "fixture.node": { + "classification": "OPEN_ACTIVE", + "kind": "inventory", + "source": "fixture/GRAPH.json" + } + } + }, + "identity": { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-", + "sha256": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + } + }, + "observed_at": "2026-10-22T21:10:01Z", + "references": [], + "repositories": [ + { + "commit": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "repository": "d6g8k5htny-coder/main", + "tree": "2222222222222222222222222222222222222222" + }, + { + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "repository": "d6g8k5htny-coder/Math-", + "tree": "3333333333333333333333333333333333333333" + } + ], + "schema_version": 1, + "scientific_effect": "NONE", + "sources": [ + { + "blob": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "bytes": 10, + "commit": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "path": "fixture/GRAPH.json", + "repository": "d6g8k5htny-coder/Math-" + } + ] +} diff --git a/tests/fixtures/current_site_transition_20261022/production-source-freeze.json b/tests/fixtures/current_site_transition_20261022/production-source-freeze.json new file mode 100644 index 000000000..cd522dac0 --- /dev/null +++ b/tests/fixtures/current_site_transition_20261022/production-source-freeze.json @@ -0,0 +1,23 @@ +{ + "source_commit": "f946932c1ee19859d8778b0a7af359211e472d73", + "files": [ + { + "path": "docs/site/current-model.mjs", + "bytes": 24442, + "sha256": "b5acd87a0afafc14e087235df5fbf390f393c6883aee11cb91578da01a72d804", + "git_blob": "02264b21daae647e7f6a0a45246ef4bd2c3d69aa" + }, + { + "path": "docs/site/dependency-model.mjs", + "bytes": 16667, + "sha256": "d64be3db1178207db5fc457d32ecfd4a0e079d6e0e6d87927a57d59b48c8a17c", + "git_blob": "cb5db5ab0a7c056674efd7244a900702a5444644" + }, + { + "path": "docs/site/current.mjs", + "bytes": 4816, + "sha256": "3ac6bf1b54b62bf786af637b807738854f46f74b75fbd6e5c328d6a873bf8b6e", + "git_blob": "936eefb4cd8bb25cba84dd74c28f257210bc0046" + } + ] +} diff --git a/tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json b/tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json new file mode 100644 index 000000000..9114ccdff --- /dev/null +++ b/tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json @@ -0,0 +1,24 @@ +{ + "schema_version": 1, + "candidate_base_commit": "0acbc2ffe0f9edbd53cbe9aee466ccbe070b7e36", + "files": [ + { + "path": "docs/site/current-model.mjs", + "bytes": 30913, + "sha256": "3fcfd646b043a57d12708cda545f0b3acfc84566942f440d8dd4dc5ae68df278", + "git_blob": "a2a82a4e12d40e39d23176b72cd54a410ce4f407" + }, + { + "path": "docs/site/current.mjs", + "bytes": 4816, + "sha256": "db6a0c49e8dc3395555c9469e413cc72d6d90710cec8e3e8871ec524126d848b", + "git_blob": "3a86f3fafa49258e11aa74399cf51e33c2dd5ef6" + }, + { + "path": "docs/site/dependency-model.mjs", + "bytes": 16667, + "sha256": "d64be3db1178207db5fc457d32ecfd4a0e079d6e0e6d87927a57d59b48c8a17c", + "git_blob": "cb5db5ab0a7c056674efd7244a900702a5444644" + } + ] +} diff --git a/tests/fixtures/site_transition_capture_regression_20261025/baseline-current-site-transition-candidate.yml.txt b/tests/fixtures/site_transition_capture_regression_20261025/baseline-current-site-transition-candidate.yml.txt new file mode 100644 index 000000000..f9e853af6 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/baseline-current-site-transition-candidate.yml.txt @@ -0,0 +1,410 @@ +# PROVISIONAL SOURCE DRAFT: PENDING_FINAL_CANONICAL_COMPOSITION; fails closed until final freeze binding and review. +# Keep the independent intentional RED draft PR499 immutable and unmerged. +name: Current reader publication transition candidate +'on': + pull_request: + branches: [main] + paths: + - 'docs/site/current-model.mjs' + - 'docs/site/current.mjs' + - 'docs/site/dependency-model.mjs' + - 'docs/site/atlas.mjs' + - 'docs/site/atlas-shell.mjs' + - 'tools/site_transition_source_guard.py' + - 'tests/test_site_transition_source_guard.py' + - 'tests/test_current_site_transition.mjs' + - 'tests/fixtures/current_site_transition_20261022/**' + - 'tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json' + - '.github/workflows/current-site-transition-candidate.yml' +permissions: + contents: read +jobs: + frozen-reader-transition-candidate: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + contents: read + steps: + - name: Record native event context and tool versions before setup + run: | + python3 -B -S - <<'PYCONTEXT' + import json, os, re, resource, signal, subprocess, sys + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + output.mkdir(parents=True, exist_ok=True) + for name in ('tap.stdout.tap', 'tap.stderr.txt'): + (output / name).write_bytes(b'') + (output / 'node-exit-code.txt').write_text('NOT_RUN\n') + event_raw = Path(os.environ['GITHUB_EVENT_PATH']).read_bytes() + event = json.loads(event_raw) + pr = event.get('pull_request') or {} + def version(command): + target = output / 'version.tmp' + child = None + def limit(): + resource.setrlimit(resource.RLIMIT_FSIZE, (128, 128)) + try: + with target.open('wb') as stream: + child = subprocess.Popen(command, stdout=stream, stderr=subprocess.DEVNULL, + start_new_session=True, preexec_fn=limit) + code = child.wait(timeout=5) + value = target.read_bytes() + if code != 0 or len(value) >= 128: + return {'status': 'UNAVAILABLE'} + value = value.decode('ascii').strip() + if not re.fullmatch(r'(?:v|Python )[0-9]+\.[0-9]+\.[0-9]+(?:[-+][A-Za-z0-9.]+)?', value): + return {'status': 'UNAVAILABLE'} + return {'status': 'OK', 'value': value, 'returncode': code} + except (OSError, UnicodeError, subprocess.TimeoutExpired): + return {'status': 'UNAVAILABLE'} + finally: + if child is not None: + try: os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: pass + try: child.wait(timeout=5) + except subprocess.TimeoutExpired: pass + target.unlink(missing_ok=True) + context = { + 'schema_version': 1, 'scientific_effect': 'NONE', + 'event_name': os.environ.get('GITHUB_EVENT_NAME'), + 'event_sha': os.environ.get('GITHUB_SHA'), + 'event_ref': os.environ.get('GITHUB_REF'), + 'repository': os.environ.get('GITHUB_REPOSITORY'), + 'run_id': os.environ.get('GITHUB_RUN_ID'), + 'run_attempt': os.environ.get('GITHUB_RUN_ATTEMPT'), + 'pull_request_number': pr.get('number', event.get('number')), + 'pull_request_head_sha': (pr.get('head') or {}).get('sha'), + 'pull_request_base_sha': (pr.get('base') or {}).get('sha'), + 'python_version': '.'.join(str(x) for x in sys.version_info[:3]), + 'node_version': version(['node', '--version']), + 'python_command_version': version(['python3', '--version']), + 'candidate_base_commit': None, + 'composition_binding': 'PENDING_FINAL_CANONICAL_COMPOSITION', + 'candidate_source_guard': 'not_started', 'node_phase': 'not_started', + } + context_raw = (json.dumps(context, indent=2) + '\n').encode() + if len(context_raw) > 65536: raise SystemExit('HOLD_CONTEXT_LIMIT') + (output / 'context.json').write_bytes(context_raw) + PYCONTEXT + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.sha }} + fetch-depth: 2 + persist-credentials: false + clean: true + - name: Require exact frozen fixtures test and candidate production source + run: | + python3 -B -S - <<'PYGUARD' + import hashlib, json, os, re, selectors, signal, stat, subprocess, time, types + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + context_path = output / 'context.json' + context = json.loads(context_path.read_text()) + def source_bytes(name, limit): + parts = name.split('/') + directory = os.open('.', os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + descriptor = None + try: + for part in parts[:-1]: + child = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory) + os.close(directory) + directory = child + descriptor = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW, dir_fd=directory) + before = os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or not 0 <= before.st_size <= limit: + raise ValueError('Unsafe or oversized immutable Source') + with os.fdopen(descriptor, 'rb', closefd=False) as stream: + raw = stream.read(limit + 1) + after = os.fstat(descriptor) + identity = lambda s: (s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + if len(raw) != before.st_size or identity(before) != identity(after): + raise ValueError('Immutable Source changed during read') + return raw + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + def bounded_git(arguments, limit): + process = subprocess.Popen(['git','--no-replace-objects',*arguments], + stdin=subprocess.DEVNULL,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,start_new_session=True) + poller = selectors.DefaultSelector() + os.set_blocking(process.stdout.fileno(),False) + poller.register(process.stdout,selectors.EVENT_READ) + raw, deadline = bytearray(), time.monotonic()+5 + try: + while poller.get_map(): + if time.monotonic()>=deadline: raise ValueError('Git read timeout; HOLD') + for key,_ in poller.select(0.05): + chunk=os.read(key.fileobj.fileno(),min(8192,limit+1-len(raw))) + if not chunk: poller.unregister(key.fileobj); break + raw.extend(chunk) + if len(raw)>limit: raise ValueError('Git output cap; HOLD') + if process.wait(timeout=2)!=0: raise ValueError('Git object read failed; HOLD') + return bytes(raw) + finally: + try: os.killpg(process.pid,signal.SIGKILL) + except ProcessLookupError: pass + process.wait(timeout=2) + process.stdout.close(); poller.close() + try: + head_raw = bounded_git(['rev-parse','--verify','HEAD'],41) + if not re.fullmatch(rb'[0-9a-f]{40}\n',head_raw): + raise ValueError('Invalid actual HEAD; HOLD') + checked_commit = head_raw[:-1].decode('ascii') + context['checked_commit'] = checked_commit + if checked_commit != context['event_sha']: + raise SystemExit('Checkout differs from tested event SHA') + fixture_root = Path('tests/fixtures/current_site_transition_20261022') + fixture_raw = (fixture_root / 'fixture-freeze.json').read_bytes() + if hashlib.sha256(fixture_raw).hexdigest() != '734f8837db6ea3f9bfe9d0f0adceb875c5af20c56767d89e7aa91c47184726d3': + raise SystemExit('Fixture freeze changed') + for entry in json.loads(fixture_raw)['files']: + raw = (fixture_root / entry['path']).read_bytes() + if (len(raw), hashlib.sha256(raw).hexdigest()) != (entry['bytes'], entry['sha256']): + raise SystemExit('Fixture changed: ' + entry['path']) + test_raw = Path('tests/test_current_site_transition.mjs').read_bytes() + if hashlib.sha256(test_raw).hexdigest() != 'a6434c9fc0c06a37d09d430bb3d8c043107e8472fa1585c1ab8cdff336b3f66a': + raise SystemExit('Test source changed') + required_candidate_freeze_sha256 = 'PENDING_FINAL_CANONICAL_COMPOSITION' + if not re.fullmatch(r'[0-9a-f]{64}', required_candidate_freeze_sha256): + raise SystemExit('Unbound candidate freeze; private template is not publishable') + candidate_freeze_path = Path('tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json') + if not candidate_freeze_path.is_file() or candidate_freeze_path.is_symlink(): + raise SystemExit('Missing or unsafe candidate production freeze') + candidate_freeze_raw = candidate_freeze_path.read_bytes() + candidate_freeze_sha256 = hashlib.sha256(candidate_freeze_raw).hexdigest() + context['candidate_freeze_path'] = candidate_freeze_path.as_posix() + context['candidate_freeze_sha256'] = candidate_freeze_sha256 + context['candidate_freeze_expected_sha256'] = required_candidate_freeze_sha256 + if candidate_freeze_sha256 != required_candidate_freeze_sha256: + raise SystemExit('Candidate production freeze changed') + freeze = json.loads(candidate_freeze_raw) + if (set(freeze) != {'schema_version', 'candidate_base_commit', 'files'} + or type(freeze['schema_version']) is not int or freeze['schema_version'] != 1 + or not isinstance(freeze['candidate_base_commit'], str) + or not re.fullmatch(r'[0-9a-f]{40}', freeze['candidate_base_commit'])): + raise SystemExit('Unexpected candidate freeze schema or base') + guard_path = 'tools/site_transition_source_guard.py' + guard_raw = source_bytes(guard_path, 8192) + if (len(guard_raw) != 4249 or hashlib.sha256(guard_raw).hexdigest() != '69aa32de61db44014f3b78a4374dda1852ab6854fbf4ac988abef6abf88e1fc6'): + raise SystemExit('Merge guard Source changed') + guard = types.ModuleType('site_transition_source_guard') + guard.__file__ = str(Path(guard_path).absolute()) + exec(compile(guard_raw, guard.__file__, 'exec'), guard.__dict__) + commit_raw = bounded_git(['cat-file','commit',checked_commit],65536) + join = guard.verify_merge_join( + event_name=context['event_name'], repository=context['repository'], + event_ref=context['event_ref'], event_sha=context['event_sha'], + pr_number=context['pull_request_number'], event_head_sha=context['pull_request_head_sha'], + event_base_sha=context['pull_request_base_sha'], checked_commit=checked_commit, + actual_commit_raw=commit_raw, frozen_base_commit=freeze['candidate_base_commit']) + context.update(source_join=join, candidate_base_commit=join['candidate_base_commit'], + actual_tree_sha=join['actual_tree_sha'],actual_merge_parents=join['actual_merge_parents'], + composition_binding='FROZEN_SOURCE_JOIN') + context['merge_guard_source'] = {'path':guard_path,'bytes':len(guard_raw), + 'sha256':hashlib.sha256(guard_raw).hexdigest()} + expected_paths = ['docs/site/current-model.mjs', 'docs/site/current.mjs', 'docs/site/dependency-model.mjs'] + if (not isinstance(freeze['files'], list) or len(freeze['files']) != 3 + or any(not isinstance(entry, dict) for entry in freeze['files']) + or [entry.get('path') for entry in freeze['files']] != expected_paths): + raise SystemExit('Candidate freeze must bind exactly the three ordered production paths') + for entry in freeze['files']: + if (set(entry) != {'path', 'bytes', 'sha256', 'git_blob'} + or type(entry['bytes']) is not int or entry['bytes'] < 0 + or not isinstance(entry['sha256'], str) + or not re.fullmatch(r'[0-9a-f]{64}', entry['sha256']) + or not isinstance(entry['git_blob'], str) + or not re.fullmatch(r'[0-9a-f]{40}', entry['git_blob'])): + raise SystemExit('Malformed candidate production entry') + path = Path(entry['path']) + if not path.is_file() or path.is_symlink(): + raise SystemExit('Missing or unsafe candidate production path: ' + entry['path']) + raw = path.read_bytes() + blob = hashlib.sha1(b'blob ' + str(len(raw)).encode() + b'\0' + raw).hexdigest() + if (len(raw), hashlib.sha256(raw).hexdigest(), blob) != (entry['bytes'], entry['sha256'], entry['git_blob']): + raise SystemExit('Candidate production source differs: ' + entry['path']) + # Additive schema-1 custody: bind actual core30 inputs plus the workflow wrapper. + immutable_paths = [ + 'tools/site_transition_source_guard.py', + '.github/workflows/current-site-transition-candidate.yml', + 'tests/test_current_site_transition.mjs', + str(fixture_root / 'fixture-freeze.json'), candidate_freeze_path.as_posix(), + *[str(fixture_root / entry['path']) for entry in json.loads(fixture_raw)['files']], + *expected_paths, + ] + context['immutable_source_inputs'] = [] + for name in immutable_paths: + raw = source_bytes(name, 16777216) + context['immutable_source_inputs'].append({'path':name,'bytes':len(raw), + 'sha256':hashlib.sha256(raw).hexdigest()}) + # Rejoin the ledger to the already authenticated guard/test/freezes/modules. + if source_bytes(guard_path,8192) != guard_raw or source_bytes('tests/test_current_site_transition.mjs',32768) != test_raw: + raise SystemExit('Guard or test changed after qualification') + if source_bytes(str(fixture_root / 'fixture-freeze.json'),16384) != fixture_raw or source_bytes(candidate_freeze_path.as_posix(),16384) != candidate_freeze_raw: + raise SystemExit('Freeze changed after qualification') + for entry in [*json.loads(fixture_raw)['files'], *freeze['files']]: + name = str(fixture_root / entry['path']) if entry in json.loads(fixture_raw)['files'] else entry['path'] + raw = source_bytes(name,16777216) + if (len(raw),hashlib.sha256(raw).hexdigest()) != (entry['bytes'],entry['sha256']): + raise SystemExit('Input changed after qualification') + context['immutable_source_recheck'] = 'pending' + context['candidate_source_guard'] = 'passed' + except BaseException as error: + context['candidate_source_guard'] = 'failed' + context['candidate_source_guard_error'] = type(error).__name__ + raise + finally: + context_raw = (json.dumps(context, indent=2) + '\n').encode() + if len(context_raw) > 65536: raise SystemExit('HOLD_CONTEXT_LIMIT') + context_path.write_bytes(context_raw) + PYGUARD + - name: Capture bounded real Node TAP with a child deadline + run: | + python3 -B -S - <<'PYNODE' + import hashlib, json, os, resource, signal, stat, subprocess, time + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + context_path = output / 'context.json' + context = json.loads(context_path.read_bytes()) + def save(): + raw = (json.dumps(context, indent=2) + '\n').encode() + if len(raw) > 65536: raise SystemExit('HOLD_CONTEXT_LIMIT') + context_path.write_bytes(raw) + def recheck_sources(): + for entry in context['immutable_source_inputs']: + parts = entry['path'].split('/') + directory = os.open('.',os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW) + descriptor = None + try: + for part in parts[:-1]: + next_directory = os.open(part,os.O_RDONLY|os.O_DIRECTORY|os.O_NOFOLLOW,dir_fd=directory) + os.close(directory); directory=next_directory + descriptor=os.open(parts[-1],os.O_RDONLY|os.O_NOFOLLOW,dir_fd=directory) + before=os.fstat(descriptor) + if not stat.S_ISREG(before.st_mode) or before.st_nlink != 1 or before.st_size != entry['bytes'] or before.st_size > 16777216: + raise ValueError('Immutable Source unsafe or changed') + with os.fdopen(descriptor,'rb',closefd=False) as stream: raw=stream.read(entry['bytes']+1) + after=os.fstat(descriptor) + identity=lambda s:(s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + if identity(before)!=identity(after) or len(raw)!=entry['bytes'] or hashlib.sha256(raw).hexdigest()!=entry['sha256']: + raise ValueError('Immutable Source changed') + finally: + if descriptor is not None: os.close(descriptor) + os.close(directory) + cap = 1048576 + def physical_limit(): + resource.setrlimit(resource.RLIMIT_FSIZE, (cap, cap)) + command = ['node', '--test', '--test-reporter=tap', 'tests/test_current_site_transition.mjs'] + context.update(node_phase='starting', node_command=command, capture_status='NOT_RUN', + capture_file_limit=cap, child_timeout_seconds=90) + save() + child = None + status = 'REFUSED_SETUP' + began = time.monotonic() + paths = [output / 'tap.stdout.tap', output / 'tap.stderr.txt'] + try: + recheck_sources() + with paths[0].open('wb') as stdout, paths[1].open('wb') as stderr: + child = subprocess.Popen(command, stdout=stdout, stderr=stderr, + start_new_session=True, preexec_fn=physical_limit) + deadline = began + 90 + while True: + if any(path.stat().st_size >= cap for path in paths): + status = 'REFUSED_OUTPUT_LIMIT'; break + code = child.poll() + if code is not None: + status = 'REFUSED_OUTPUT_LIMIT' if code == -signal.SIGXFSZ else 'COMPLETED' + break + if time.monotonic() >= deadline: + status = 'TIMEOUT'; break + time.sleep(0.05) + except OSError as error: + context['node_start_error'] = type(error).__name__ + finally: + if child is not None: + # Also remove surviving descendants after a normal leader exit. + try: os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: pass + try: + code = child.wait(timeout=5) + except subprocess.TimeoutExpired: + status = 'REFUSED_REAP' + code = child.poll() + if code is not None: + (output / 'node-exit-code.txt').write_text(str(code) + '\n') + context['node_returncode'] = code + else: + code = None + if any(path.stat().st_size >= cap for path in paths): status = 'REFUSED_OUTPUT_LIMIT' + try: + recheck_sources() + context['immutable_source_recheck'] = 'passed' + except Exception as error: + status = 'REFUSED_SOURCE_CHANGED' + context['immutable_source_recheck'] = 'failed' + context['immutable_source_recheck_error'] = type(error).__name__ + context.update(node_phase='completed' if child is not None else 'not_started', + capture_status=status, elapsed_seconds=round(time.monotonic()-began, 3)) + save() + if status != 'COMPLETED': raise SystemExit(1) + raise SystemExit(code if code >= 0 else 128 - code) + PYNODE + - name: Admit bounded report members and emit byte-exact log frames + id: capture_admission + if: always() + run: | + python3 -B -S - <<'PYEMIT' + import base64, hashlib, json, os + from pathlib import Path + output = Path(os.environ['RUNNER_TEMP']) / 'current-site-transition-candidate' + limits = {'context.json': 65536, 'tap.stdout.tap': 1048576, + 'tap.stderr.txt': 1048576, 'node-exit-code.txt': 32} + def setting(name, value): + with open(os.environ['GITHUB_OUTPUT'], 'a') as stream: stream.write(name + '=' + value + '\n') + setting('bounded', 'false') + try: + if any(not (output/name).is_file() or (output/name).is_symlink() for name in limits): + raise ValueError('MISSING_OR_UNSAFE_MEMBER') + sizes = {name: (output/name).stat().st_size for name in limits} + if any(sizes[name] > limits[name] for name in limits) or sum(sizes.values()) > 2162720: + raise ValueError('REPORT_BYTE_LIMIT') + members = {name: (output/name).read_bytes() for name in limits} + if any(len(members[name]) != sizes[name] for name in limits): raise ValueError('MEMBER_CHANGED') + context = json.loads(members['context.json']) + complete = (context.get('candidate_source_guard') == 'passed' and context.get('node_phase') == 'completed' + and context.get('capture_status') == 'COMPLETED' + and context.get('immutable_source_recheck') == 'passed' + and context.get('node_version', {}).get('status') == 'OK' + and context.get('python_command_version', {}).get('status') == 'OK' + and context.get('event_name') == 'pull_request' + and context.get('pull_request_head_sha') and context.get('pull_request_base_sha')) + exit_text = members['node-exit-code.txt'].decode('ascii').strip() + complete = bool(complete and exit_text == str(context.get('node_returncode'))) + classification = 'CAPTURE_COMPLETE_REQUIRES_TAP_REVIEW' if complete else 'HOLD' + for name, raw in members.items(): + sha = hashlib.sha256(raw).hexdigest() + print(f'CS_TRANSITION_FILE_BEGIN name={name} bytes={len(raw)} sha256={sha}') + count = 0 + for offset in range(0, len(raw), 3072): + chunk = base64.b64encode(raw[offset:offset+3072]).decode('ascii') + print(f'CS_TRANSITION_FILE_CHUNK name={name} index={count} data={chunk}') + count += 1 + print(f'CS_TRANSITION_FILE_END name={name} chunks={count} sha256={sha}') + print(f'CS_TRANSITION_EVIDENCE_END files=4 bytes={sum(sizes.values())} classification={classification}') + setting('bounded', 'true') + if not complete: raise SystemExit(1) + except Exception as error: + print('CS_TRANSITION_EVIDENCE_HOLD reason=' + type(error).__name__) + raise SystemExit(1) + PYEMIT + - name: Preserve exact bounded context TAP stderr and exit code including failures + if: always() && steps.capture_admission.outputs.bounded == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: current-site-transition-candidate-${{ github.run_id }}-${{ github.run_attempt }} + path: | + ${{ runner.temp }}/current-site-transition-candidate/context.json + ${{ runner.temp }}/current-site-transition-candidate/tap.stdout.tap + ${{ runner.temp }}/current-site-transition-candidate/tap.stderr.txt + ${{ runner.temp }}/current-site-transition-candidate/node-exit-code.txt + if-no-files-found: error + retention-days: 30 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/capturedirectory.py b/tests/fixtures/site_transition_capture_regression_20261025/children/capturedirectory.py new file mode 100644 index 000000000..6dca79243 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/capturedirectory.py @@ -0,0 +1,4 @@ +from pathlib import Path +p = Path('runner/current-site-transition-candidate/tap.stdout.tap') +p.unlink() +p.mkdir() diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/capturefifo.py b/tests/fixtures/site_transition_capture_regression_20261025/children/capturefifo.py new file mode 100644 index 000000000..4856678c7 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/capturefifo.py @@ -0,0 +1,5 @@ +import os +from pathlib import Path +p = Path('runner/current-site-transition-candidate/tap.stdout.tap') +p.unlink() +os.mkfifo(p, 0o600) diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/capturehardlink.py b/tests/fixtures/site_transition_capture_regression_20261025/children/capturehardlink.py new file mode 100644 index 000000000..58bdc0307 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/capturehardlink.py @@ -0,0 +1,7 @@ +import os +from pathlib import Path +p = Path('runner/current-site-transition-candidate/tap.stdout.tap') +p.unlink() +q = Path('owned-hardlink-target.txt') +q.write_bytes(b'owned side input') +os.link(q, p) diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/capturesymlink.py b/tests/fixtures/site_transition_capture_regression_20261025/children/capturesymlink.py new file mode 100644 index 000000000..b735d9994 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/capturesymlink.py @@ -0,0 +1,4 @@ +from pathlib import Path +p = Path('runner/current-site-transition-candidate/tap.stdout.tap') +p.unlink() +p.symlink_to('../../inputs/member-01.txt') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/missingcapture.py b/tests/fixtures/site_transition_capture_regression_20261025/children/missingcapture.py new file mode 100644 index 000000000..7c47813c9 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/missingcapture.py @@ -0,0 +1,2 @@ +from pathlib import Path +Path('runner/current-site-transition-candidate/tap.stdout.tap').unlink() diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/nonzero.py b/tests/fixtures/site_transition_capture_regression_20261025/children/nonzero.py new file mode 100644 index 000000000..ecd8faf80 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/nonzero.py @@ -0,0 +1,3 @@ +import sys +print('TAP version 13\nnot ok 1 - expected refusal\n1..1') +sys.exit(7) diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/outputcap.py b/tests/fixtures/site_transition_capture_regression_20261025/children/outputcap.py new file mode 100644 index 000000000..c765f34a8 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/outputcap.py @@ -0,0 +1,2 @@ +import os +os.write(1, b'x' * 1048576) diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/sourcechange.py b/tests/fixtures/site_transition_capture_regression_20261025/children/sourcechange.py new file mode 100644 index 000000000..c8a8afad4 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/sourcechange.py @@ -0,0 +1,2 @@ +from pathlib import Path +Path('inputs/member-00.txt').write_text('changed') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/sourcefifo.py b/tests/fixtures/site_transition_capture_regression_20261025/children/sourcefifo.py new file mode 100644 index 000000000..d4aabe9a9 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/sourcefifo.py @@ -0,0 +1,5 @@ +import os +from pathlib import Path +p = Path('inputs/member-00.txt') +p.unlink() +os.mkfifo(p, 0o600) diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/success.py b/tests/fixtures/site_transition_capture_regression_20261025/children/success.py new file mode 100644 index 000000000..90beecd4c --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/success.py @@ -0,0 +1,3 @@ +import sys +print('TAP version 13\n1..0') +sys.exit(0) diff --git a/tests/fixtures/site_transition_capture_regression_20261025/children/timeout.py b/tests/fixtures/site_transition_capture_regression_20261025/children/timeout.py new file mode 100644 index 000000000..d3be16f1a --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/children/timeout.py @@ -0,0 +1,2 @@ +import time +time.sleep(30) diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-00.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-00.txt new file mode 100644 index 000000000..f5f5b8d31 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-00.txt @@ -0,0 +1 @@ +immutable member 0 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-01.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-01.txt new file mode 100644 index 000000000..6d1604b18 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-01.txt @@ -0,0 +1 @@ +immutable member 1 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-02.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-02.txt new file mode 100644 index 000000000..5f33be604 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-02.txt @@ -0,0 +1 @@ +immutable member 2 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-03.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-03.txt new file mode 100644 index 000000000..6e150d416 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-03.txt @@ -0,0 +1 @@ +immutable member 3 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-04.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-04.txt new file mode 100644 index 000000000..23e74b583 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-04.txt @@ -0,0 +1 @@ +immutable member 4 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-05.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-05.txt new file mode 100644 index 000000000..0a879e4d8 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-05.txt @@ -0,0 +1 @@ +immutable member 5 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-06.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-06.txt new file mode 100644 index 000000000..c8dcd5fe7 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-06.txt @@ -0,0 +1 @@ +immutable member 6 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-07.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-07.txt new file mode 100644 index 000000000..2ba3bd778 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-07.txt @@ -0,0 +1 @@ +immutable member 7 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-08.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-08.txt new file mode 100644 index 000000000..f9c873379 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-08.txt @@ -0,0 +1 @@ +immutable member 8 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-09.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-09.txt new file mode 100644 index 000000000..3d4505f44 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-09.txt @@ -0,0 +1 @@ +immutable member 9 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-10.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-10.txt new file mode 100644 index 000000000..ff9552186 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-10.txt @@ -0,0 +1 @@ +immutable member 10 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-11.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-11.txt new file mode 100644 index 000000000..0ebafb1a1 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-11.txt @@ -0,0 +1 @@ +immutable member 11 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-12.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-12.txt new file mode 100644 index 000000000..b7e67003e --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-12.txt @@ -0,0 +1 @@ +immutable member 12 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-13.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-13.txt new file mode 100644 index 000000000..de128c8bc --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-13.txt @@ -0,0 +1 @@ +immutable member 13 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-14.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-14.txt new file mode 100644 index 000000000..f20a5ea05 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-14.txt @@ -0,0 +1 @@ +immutable member 14 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-15.txt b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-15.txt new file mode 100644 index 000000000..fbc8c0ae4 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/inputs/member-15.txt @@ -0,0 +1 @@ +immutable member 15 diff --git a/tests/fixtures/site_transition_capture_regression_20261025/isolation_probe.py b/tests/fixtures/site_transition_capture_regression_20261025/isolation_probe.py new file mode 100644 index 000000000..14ffca364 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/isolation_probe.py @@ -0,0 +1,2 @@ +import hashlib, json, pathlib, selectors, base64 +print('STDLIB_BOUNDARY_OK') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/ledger.json b/tests/fixtures/site_transition_capture_regression_20261025/ledger.json new file mode 100644 index 000000000..797fb7de7 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/ledger.json @@ -0,0 +1,82 @@ +[ + { + "path": "inputs/member-00.txt", + "bytes": 19, + "sha256": "1e27b1582ed703b6f5d6fb682fca1a286716395d8101d34969bcc4595eba9bca" + }, + { + "path": "inputs/member-01.txt", + "bytes": 19, + "sha256": "597db69818a8538d4f5e4f907cbdf19f602eeaef22601d5029d888422848c648" + }, + { + "path": "inputs/member-02.txt", + "bytes": 19, + "sha256": "3c09544253c5e0d7e6fc55f9dfeaceb899488fc30f15fc929e20400278195250" + }, + { + "path": "inputs/member-03.txt", + "bytes": 19, + "sha256": "4222589ca0a27496167032e47548ac3a836c9a2612d7037c687d92aae654d9c7" + }, + { + "path": "inputs/member-04.txt", + "bytes": 19, + "sha256": "072e89e12d5d223daea4332f8357bafa15c1061f8a245494a426ef0f46bef033" + }, + { + "path": "inputs/member-05.txt", + "bytes": 19, + "sha256": "5e8d7c5fd8830f564576d37fc44302635290b8b7dedf680a926a3a9e4bfd23f0" + }, + { + "path": "inputs/member-06.txt", + "bytes": 19, + "sha256": "d0f5617405f24e0791460ee8b4ce3a3197e058430ff2b1ff1b433a046dc00ff8" + }, + { + "path": "inputs/member-07.txt", + "bytes": 19, + "sha256": "2c29c96186176603dd32fa4732beff000d29d3cce27911eb0cc3ccbb2db9c6bf" + }, + { + "path": "inputs/member-08.txt", + "bytes": 19, + "sha256": "c04bc0cc1fe40a112778223f5c7795dc90274b9c37d1142f0e628c9f1d45c9bb" + }, + { + "path": "inputs/member-09.txt", + "bytes": 19, + "sha256": "7fc62eff29e7b3fb4399724a88bb94137885eee6774fddde73c0e95a670c8a3c" + }, + { + "path": "inputs/member-10.txt", + "bytes": 20, + "sha256": "a8729a1e09256c3dda2f6bc78531474aad5dff8501a42f4952480576194688da" + }, + { + "path": "inputs/member-11.txt", + "bytes": 20, + "sha256": "b0e404ecfc12304459c7b18f0acda8d90dc542542dbc3c796d23b49617142190" + }, + { + "path": "inputs/member-12.txt", + "bytes": 20, + "sha256": "106bff73e6e9239909309994a38c68dd905b440556ae1248641c15cabf920178" + }, + { + "path": "inputs/member-13.txt", + "bytes": 20, + "sha256": "582e779b33163e4f91cf43006bdd05681b582c1de1e7a5cb1a3243fb7471725f" + }, + { + "path": "inputs/member-14.txt", + "bytes": 20, + "sha256": "45a86f1d617e8f6696cb31fffb7e647ea12db8374fb2ad266e73409528832e03" + }, + { + "path": "inputs/member-15.txt", + "bytes": 20, + "sha256": "75b36199669466326d6bef2e234ec55b293889f8977631b442aee62a3f2cfe11" + } +] diff --git a/tests/fixtures/site_transition_capture_regression_20261025/shadow/base64.py b/tests/fixtures/site_transition_capture_regression_20261025/shadow/base64.py new file mode 100644 index 000000000..8d08f146a --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/shadow/base64.py @@ -0,0 +1,3 @@ +with open('.import-shadow-marker', 'a') as stream: + stream.write('SHADOW_IMPORT\n') +raise RuntimeError('unqualified shadow imported') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/shadow/hashlib.py b/tests/fixtures/site_transition_capture_regression_20261025/shadow/hashlib.py new file mode 100644 index 000000000..8d08f146a --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/shadow/hashlib.py @@ -0,0 +1,3 @@ +with open('.import-shadow-marker', 'a') as stream: + stream.write('SHADOW_IMPORT\n') +raise RuntimeError('unqualified shadow imported') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/shadow/json.py b/tests/fixtures/site_transition_capture_regression_20261025/shadow/json.py new file mode 100644 index 000000000..8d08f146a --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/shadow/json.py @@ -0,0 +1,3 @@ +with open('.import-shadow-marker', 'a') as stream: + stream.write('SHADOW_IMPORT\n') +raise RuntimeError('unqualified shadow imported') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/shadow/pathlib.py b/tests/fixtures/site_transition_capture_regression_20261025/shadow/pathlib.py new file mode 100644 index 000000000..8d08f146a --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/shadow/pathlib.py @@ -0,0 +1,3 @@ +with open('.import-shadow-marker', 'a') as stream: + stream.write('SHADOW_IMPORT\n') +raise RuntimeError('unqualified shadow imported') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/shadow/selectors.py b/tests/fixtures/site_transition_capture_regression_20261025/shadow/selectors.py new file mode 100644 index 000000000..8d08f146a --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/shadow/selectors.py @@ -0,0 +1,3 @@ +with open('.import-shadow-marker', 'a') as stream: + stream.write('SHADOW_IMPORT\n') +raise RuntimeError('unqualified shadow imported') diff --git a/tests/fixtures/site_transition_capture_regression_20261025/source-fixture-manifest.json b/tests/fixtures/site_transition_capture_regression_20261025/source-fixture-manifest.json new file mode 100644 index 000000000..2d9e2ee70 --- /dev/null +++ b/tests/fixtures/site_transition_capture_regression_20261025/source-fixture-manifest.json @@ -0,0 +1,316 @@ +{ + "schema_version": 1, + "status": "ROOT_FROZEN_FINAL_CANONICAL_COMPOSITION", + "fixture_root": "tests/fixtures/site_transition_capture_regression_20261025", + "members": [ + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/baseline-current-site-transition-candidate.yml.txt", + "bytes": 25845, + "sha256": "203882fc99795884ff589d49d90f3c231f0f4b98f8959e8e558e91a5daa8bb99", + "git_blob": "f9e853af60e0d499b98d862b4ceea15880904348", + "role": "safe_historical_baseline_wrapper" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/capturedirectory.py", + "bytes": 114, + "sha256": "0e4154b266ea9840f278b6d764d71833144b21c4176450c54ba9d5f771ceb016", + "git_blob": "6dca792438a544945f5a57eaa02b1049943d7353", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/capturefifo.py", + "bytes": 134, + "sha256": "0780e4c00ee0a191af0ffa4249f0c6e67fe89a8a067c4a5778382bb7df569480", + "git_blob": "4856678c719f06404f63709451400c881c58913a", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/capturehardlink.py", + "bytes": 201, + "sha256": "3a4f83cbf013351f29bf0ca5b2709f9d05c9c599f194fd388d7cf765556291fd", + "git_blob": "58bdc030785670d8f5ae0e01ab763991ba94cfe7", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/capturesymlink.py", + "bytes": 147, + "sha256": "e603804171ad2651325f9d12013600f44f761c2c74f517a402b798fd1786cc85", + "git_blob": "b735d9994f4397d7d5bf5b8ae67b7d038c9c93ce", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/missingcapture.py", + "bytes": 98, + "sha256": "4f6ef91849bd473cf52a91d398c23a7984dc12b43208034e42f71d91b028d417", + "git_blob": "7c47813c97de6a4ece88cbd98b0e66f8970e7abc", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/nonzero.py", + "bytes": 82, + "sha256": "2031f5266a0babe67619af4ed8b437eac37ca042af758773f002a744d1cf249d", + "git_blob": "ecd8faf80015d9f3c40036e1ce8df9c6af2a7a06", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/outputcap.py", + "bytes": 38, + "sha256": "cf274b1458c21982888e716e32f9b9f1a41e34dad70e1fd35b11c7325a626dfd", + "git_blob": "c765f34a8b087d35a584269dc340ec107bfde2bb", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/sourcechange.py", + "bytes": 76, + "sha256": "9984fdfb01c9f347681cc256a8f8870694aca83a661df9f404cc0a4ca7df9c5b", + "git_blob": "c8a8afad4f4e758fb0b2bf28dbbd3001bc62f0cc", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/sourcefifo.py", + "bytes": 99, + "sha256": "9431381f53ba3ccb62710a8af786d1f03878d21aed184c764bd3d975c67bb818", + "git_blob": "d4aabe9a9bf7c1f0e2c50f3d2ee480550d580934", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/success.py", + "bytes": 53, + "sha256": "88a8a0715db647ee36c4c8e07a30ac4f8c67bcd7619eb63be37d0373de1c3164", + "git_blob": "90beecd4cb2f8ef490da3196045c439ff16906b0", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/children/timeout.py", + "bytes": 27, + "sha256": "2a94cbef640a9b690e55ff5d3eda1785e063a2cb14f731eb9b2ee535de3e758d", + "git_blob": "d3be16f1ad60d791fe35fda5ebe8876aaba63200", + "role": "fixed_stdlib_child" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-00.txt", + "bytes": 19, + "sha256": "1e27b1582ed703b6f5d6fb682fca1a286716395d8101d34969bcc4595eba9bca", + "git_blob": "f5f5b8d318847cdbc20f8d75dce7d705974409ab", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-01.txt", + "bytes": 19, + "sha256": "597db69818a8538d4f5e4f907cbdf19f602eeaef22601d5029d888422848c648", + "git_blob": "6d1604b18e0f92eef8410344f349c1286e01ac81", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-02.txt", + "bytes": 19, + "sha256": "3c09544253c5e0d7e6fc55f9dfeaceb899488fc30f15fc929e20400278195250", + "git_blob": "5f33be604c08930f8981599136d5ff54dc07a033", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-03.txt", + "bytes": 19, + "sha256": "4222589ca0a27496167032e47548ac3a836c9a2612d7037c687d92aae654d9c7", + "git_blob": "6e150d4161b556906f937e557d23064789221e27", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-04.txt", + "bytes": 19, + "sha256": "072e89e12d5d223daea4332f8357bafa15c1061f8a245494a426ef0f46bef033", + "git_blob": "23e74b583e1f3dbf23ab5bb0485c9f09f48d2ebe", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-05.txt", + "bytes": 19, + "sha256": "5e8d7c5fd8830f564576d37fc44302635290b8b7dedf680a926a3a9e4bfd23f0", + "git_blob": "0a879e4d86cd0b52fb9c6d2f6fcf3976c7d450f3", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-06.txt", + "bytes": 19, + "sha256": "d0f5617405f24e0791460ee8b4ce3a3197e058430ff2b1ff1b433a046dc00ff8", + "git_blob": "c8dcd5fe70519cf394b6c839b093302dbb39157e", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-07.txt", + "bytes": 19, + "sha256": "2c29c96186176603dd32fa4732beff000d29d3cce27911eb0cc3ccbb2db9c6bf", + "git_blob": "2ba3bd778743c380c1a80a3766ceba87d808f9f4", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-08.txt", + "bytes": 19, + "sha256": "c04bc0cc1fe40a112778223f5c7795dc90274b9c37d1142f0e628c9f1d45c9bb", + "git_blob": "f9c8733793d77ab79c8f051e73ab585a729edabc", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-09.txt", + "bytes": 19, + "sha256": "7fc62eff29e7b3fb4399724a88bb94137885eee6774fddde73c0e95a670c8a3c", + "git_blob": "3d4505f447a586e2cfa968ed2b27802dd78f12ad", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-10.txt", + "bytes": 20, + "sha256": "a8729a1e09256c3dda2f6bc78531474aad5dff8501a42f4952480576194688da", + "git_blob": "ff9552186c5ab1367b2a1935beba272cfa14e621", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-11.txt", + "bytes": 20, + "sha256": "b0e404ecfc12304459c7b18f0acda8d90dc542542dbc3c796d23b49617142190", + "git_blob": "0ebafb1a151cf2ce631baa0d3c276375086dc4bc", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-12.txt", + "bytes": 20, + "sha256": "106bff73e6e9239909309994a38c68dd905b440556ae1248641c15cabf920178", + "git_blob": "b7e67003e95a7ae2b6a5a5dba96ea4179cd14167", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-13.txt", + "bytes": 20, + "sha256": "582e779b33163e4f91cf43006bdd05681b582c1de1e7a5cb1a3243fb7471725f", + "git_blob": "de128c8bc0c7c5f74da6c5847a1af1e83583bf9d", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-14.txt", + "bytes": 20, + "sha256": "45a86f1d617e8f6696cb31fffb7e647ea12db8374fb2ad266e73409528832e03", + "git_blob": "f20a5ea054bff7d857f3d512c698fb1a1e9b6fc9", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/inputs/member-15.txt", + "bytes": 20, + "sha256": "75b36199669466326d6bef2e234ec55b293889f8977631b442aee62a3f2cfe11", + "git_blob": "fbc8c0ae49d681d5b9ba354c2997eaa0bd0313ca", + "role": "synthetic_immutable_ledger_member" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/isolation_probe.py", + "bytes": 77, + "sha256": "ee58878bffc5524e00fc7cec4b3eae5a7efacbafa02d89072379a29b9dd76493", + "git_blob": "14ffca364dc22a9e9efb7a249e151be2a1361d6c", + "role": "fixed_stdlib_import_probe" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/ledger.json", + "bytes": 2291, + "sha256": "1d594eba8cbf8b9ee0bc6870ab40cfb4f7078977295ba95cb2d0c38a45bee172", + "git_blob": "797fb7de7845d5ca1ebf18ea4f481db9eff5d3d7", + "role": "synthetic_input_ledger" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/shadow/base64.py", + "bytes": 137, + "sha256": "fb402cf6b6560b4b1c0b7ed73ca6a5d8ff61aff010127547bc0def31c2066f0c", + "git_blob": "8d08f146aa0e629dd59732961031a84ac78b2ddc", + "role": "fixed_import_shadow_marker" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/shadow/hashlib.py", + "bytes": 137, + "sha256": "fb402cf6b6560b4b1c0b7ed73ca6a5d8ff61aff010127547bc0def31c2066f0c", + "git_blob": "8d08f146aa0e629dd59732961031a84ac78b2ddc", + "role": "fixed_import_shadow_marker" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/shadow/json.py", + "bytes": 137, + "sha256": "fb402cf6b6560b4b1c0b7ed73ca6a5d8ff61aff010127547bc0def31c2066f0c", + "git_blob": "8d08f146aa0e629dd59732961031a84ac78b2ddc", + "role": "fixed_import_shadow_marker" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/shadow/pathlib.py", + "bytes": 137, + "sha256": "fb402cf6b6560b4b1c0b7ed73ca6a5d8ff61aff010127547bc0def31c2066f0c", + "git_blob": "8d08f146aa0e629dd59732961031a84ac78b2ddc", + "role": "fixed_import_shadow_marker" + }, + { + "path": "tests/fixtures/site_transition_capture_regression_20261025/shadow/selectors.py", + "bytes": 137, + "sha256": "fb402cf6b6560b4b1c0b7ed73ca6a5d8ff61aff010127547bc0def31c2066f0c", + "git_blob": "8d08f146aa0e629dd59732961031a84ac78b2ddc", + "role": "fixed_import_shadow_marker" + }, + { + "path": "tools/site_transition_capture_regression.py", + "bytes": 27562, + "sha256": "3101c98ab310b70c2b471054c1443d7323b36f530b3b9c193930e916fb3a46de", + "git_blob": "38ec85313071e06682152dbd6c7a4c985e17b9e2", + "role": "actual_wrapper_regression_harness" + }, + { + "path": "tools/site_transition_capture_regression_launcher.py", + "bytes": 7872, + "sha256": "488cfe44198e81eec3939e3d12d922f97e661253735060a88919a8e4a1d36206", + "git_blob": "becef2cedefd63d838d612d2df64185c44b4d8ee", + "role": "authenticated_capture_launcher" + }, + { + "path": "tools/site_transition_capture_regression_supervisor.py", + "bytes": 48255, + "sha256": "e2cf0241fc41ab1bf6a83e38a4d45811f7dd64ef0436942293ea416a4e7d9c54", + "git_blob": "cc327a4b819bfbf7324359562e1fd30a4756f34e", + "role": "fixed_linux_subreaper_supervisor" + } + ], + "external_inputs": { + "guard": { + "path": "tools/site_transition_source_guard.py", + "bytes": 4249, + "sha256": "69aa32de61db44014f3b78a4374dda1852ab6854fbf4ac988abef6abf88e1fc6", + "git_blob": "5b10c5c898173cf72e56da1067d87ca043a03c49", + "role": "authenticated_pure_merge_guard" + }, + "final_freeze": { + "path": "tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json", + "bytes": 785, + "sha256": "08599cdf4c4251932e92ed622bf695db1bb502578fcb2c60da42daa89ebace5e", + "git_blob": "9114ccdffad3dc44cbeb59c380a8a59775872a20", + "role": "final_common_candidate_freeze" + } + }, + "selectors": { + "baseline": [ + "InlineCaptureTests.test_missing_tap_does_not_skip_source_recheck_or_context_attempt" + ], + "candidate": [ + "InlineCaptureTests.test_actual_baseline_emitter_imports_shadow_and_candidate_emitter_holds_without_it", + "InlineCaptureTests.test_directory_capture_refuses_and_attempts_custody", + "InlineCaptureTests.test_exit_file_failure_does_not_skip_outer_custody", + "InlineCaptureTests.test_fifo_capture_refuses_without_blocking_and_attempts_custody", + "InlineCaptureTests.test_final_context_write_failure_is_attempted_and_propagated", + "InlineCaptureTests.test_hardlinked_capture_refuses_without_touching_source_ledger", + "InlineCaptureTests.test_interrupted_cleanup_never_claims_confirmed_completion", + "InlineCaptureTests.test_kill_error_is_separate_cleanup_hold", + "InlineCaptureTests.test_missing_tap_does_not_skip_source_recheck_or_context_attempt", + "InlineCaptureTests.test_nonzero_retains_child_failure_and_still_attempts_custody", + "InlineCaptureTests.test_output_cap_remains_hold_after_outer_custody", + "InlineCaptureTests.test_real_stdin_entrypoints_exclude_cwd_and_pythonpath_shadow", + "InlineCaptureTests.test_reap_error_is_separate_cleanup_hold", + "InlineCaptureTests.test_source_change_refuses_even_after_completed_child", + "InlineCaptureTests.test_source_input_fifo_refuses_without_blocking_and_attempts_context", + "InlineCaptureTests.test_spawn_setup_failure_never_becomes_completed", + "InlineCaptureTests.test_success_preserves_integer_zero_and_complete_capture", + "InlineCaptureTests.test_symlink_capture_refuses_and_attempts_custody", + "InlineCaptureTests.test_timeout_remains_hold_after_outer_custody", + "InlineCaptureTests.test_unreadable_tap_is_recorded_and_keeps_hold" + ] + } +} diff --git a/tests/test_current_observation_coherence.mjs b/tests/test_current_observation_coherence.mjs index 75c4fa7e8..3f1f4e8d6 100644 --- a/tests/test_current_observation_coherence.mjs +++ b/tests/test_current_observation_coherence.mjs @@ -27,17 +27,28 @@ test('mixed publication recovers once at the page digest while retaining the sam assert.deepEqual(result,data);assert.deepEqual(seen.map(x=>x.url),['current.json','current.json?observation='+id.sha256]); assert.ok(seen.every(x=>x.opts.cache==='no-store'&&x.opts.credentials==='omit'&&x.opts.signal===controller.signal)); }); -test('persistent digest mismatch refuses after two requests and never admits the old observation',async()=>{ - const {raw,old}=pair();let calls=0; - await assert.rejects(run(async()=>{calls++;return response(old);},identity(raw)),/digest mismatch/); - assert.equal(calls,2); +test('persistent digest mismatch refuses after one metadata recovery and never admits the wrong observation',async()=>{ + const {raw,old,data}=pair(),id=identity(raw),seen=[],controller=new AbortController(); + const keyed='current.json?observation='+id.sha256; + assert.equal(old.length,raw.length);assert.notEqual(identity(old).sha256,id.sha256); + await assert.rejects(run(async(url,opts)=>{ + seen.push({url,opts}); + return url==='current-meta.json'?new Response(encode({...id,observed_at:data.observed_at})):response(old); + },id,{signal:controller.signal}),/digest mismatch/); + assert.deepEqual(seen.map(x=>x.url),['current.json',keyed,'current-meta.json',keyed]); + assert.ok(seen.every(x=>x.opts.cache==='no-store'&&x.opts.credentials==='omit'&&x.opts.signal===controller.signal)); }); test('byte-count mismatch may recover but the recovery bytes are checked as strictly',async()=>{ - const {raw}=pair();let calls=0; - assert.equal((await run(async()=>response(++calls===1?Buffer.from('{}'):raw),identity(raw))).observed_at,'2026-10-20T12:06:05Z'); - assert.equal(calls,2);calls=0; - await assert.rejects(run(async()=>{calls++;return response(Buffer.from('{}'));},identity(raw)),/byte count mismatch/); + const {raw,data}=pair(),id=identity(raw);let calls=0; + assert.equal((await run(async()=>response(++calls===1?Buffer.from('{}'):raw),id)).observed_at,'2026-10-20T12:06:05Z'); assert.equal(calls,2); + const seen=[],controller=new AbortController(),keyed='current.json?observation='+id.sha256; + await assert.rejects(run(async(url,opts)=>{ + seen.push({url,opts}); + return url==='current-meta.json'?new Response(encode({...id,observed_at:data.observed_at})):response(Buffer.from('{}')); + },id,{signal:controller.signal}),/byte count mismatch/); + assert.deepEqual(seen.map(x=>x.url),['current.json',keyed,'current-meta.json',keyed]); + assert.ok(seen.every(x=>x.opts.cache==='no-store'&&x.opts.credentials==='omit'&&x.opts.signal===controller.signal)); }); test('HTTP refusal is not retried as an integrity mismatch',async()=>{ const {raw}=pair();let calls=0; diff --git a/tests/test_current_site_transition.mjs b/tests/test_current_site_transition.mjs new file mode 100644 index 000000000..4ed0c62fe --- /dev/null +++ b/tests/test_current_site_transition.mjs @@ -0,0 +1,172 @@ +// Private test-first source proposal. Never run locally in the authoring unit. +// Production break caught: a publication advances current.json while an open +// document still advertises the previous digest; the reader must recover one +// coherent verified successor pair, with no admission under the old digest. +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {webcrypto, createHash} from 'node:crypto'; +import {readFile} from 'node:fs/promises'; +import {fetchVerifiedSnapshot, parseVerifiedSnapshot} from '../docs/site/current-model.mjs'; + +const fixtureURL = name => new URL(`./fixtures/current_site_transition_20261022/${name}`, import.meta.url); +const raw = async name => new Uint8Array(await readFile(fixtureURL(name))); +const [oldRaw,newRaw,oldCorrupt,newCorrupt,identityRaw,oldMetaRaw,newMetaRaw] = await Promise.all([ + raw('old-observation.json'),raw('new-observation.json'),raw('old-same-length-corrupt.json'), + raw('new-same-length-corrupt.json'),raw('identities.json'),raw('old-meta.json'),raw('new-meta.json'), +]); +const decode = bytes => JSON.parse(new TextDecoder().decode(bytes)); +const identities=decode(identityRaw), oldIdentity=identities.old, newIdentity=identities.new; +const oldData=decode(oldRaw),newData=decode(newRaw),oldMeta=decode(oldMetaRaw),newMeta=decode(newMetaRaw); +const oldKey=`current.json?observation=${oldIdentity.sha256}`; +const newKey=`current.json?observation=${newIdentity.sha256}`; +const asBytes=value=>new TextEncoder().encode(JSON.stringify(value)); +const sha=bytes=>createHash('sha256').update(bytes).digest('hex'); +const reply=(url,body,status=200)=>({url,body,status}); +const transition=(metadata=newMetaRaw,body=newRaw)=>[ + reply('current.json',newRaw),reply(oldKey,newRaw),reply('current-meta.json',metadata),reply(newKey,body), +]; + +// Replace only the external transport. Production hashing, UTF-8 decoding, +// JSON parsing, snapshot validation, recovery decisions and abort propagation +// remain real. Native Response supplies the complete fetch response interface. +function transport(steps,{controller}={}) { + const calls=[]; + const fetcher=async(url,options={})=>{ + calls.push({url:String(url),options}); + if(options.signal?.aborted){const e=new Error('Fixture request aborted');e.name='AbortError';throw e;} + const step=steps[calls.length-1]; + if(!step||String(url)!==step.url)throw new Error(`Transport fixture rejected unexpected request ${String(url)}`); + if(step.waitForAbort)return new Promise((resolve,reject)=>{ + const abort=()=>{const e=new Error('Fixture request timed out');e.name='AbortError';reject(e);}; + options.signal.addEventListener('abort',abort,{once:true}); + // The timeout occurs only after this request starts; no race with crypto. + setTimeout(()=>controller.abort(),0); + }); + return new Response(step.body,{status:step.status??200,headers:{'Content-Type':'application/json'}}); + }; + return {fetcher,calls}; +} +async function outcome(fetcher,identity,signal) { + try{return {value:await fetchVerifiedSnapshot(fetcher,identity,{cryptoAPI:webcrypto,signal}),error:null};} + catch(error){return {value:null,error};} +} +function requests(calls,paths,signal) { + assert.deepEqual(calls.map(call=>call.url),paths,'The bounded recovery must use the specified same-origin requests exactly once.'); + for(const {options}of calls){ + assert.equal(options.cache,'no-store');assert.equal(options.credentials,'omit'); + assert.equal(options.method??'GET','GET');assert.equal(options.signal,signal,'One caller abort budget spans all requests.'); + } +} +function success(result,expected) { + assert.equal(result.error,null,`Expected a verified coherent observation, received ${result.error?.name}: ${result.error?.message}`); + assert.deepEqual(result.value,expected); +} +function refusal(result) {assert.equal(result.value,null);assert.ok(result.error instanceof Error,'Unverified or incoherent bytes must refuse.');} + +test('fixture positives are valid independently frozen old and new observations',async()=>{ + for(const [body,id,expected]of [[oldRaw,oldIdentity,oldData],[newRaw,newIdentity,newData]]){ + assert.equal(body.byteLength,id.bytes);assert.equal(sha(body),id.sha256); + assert.deepEqual(await parseVerifiedSnapshot(body,id,webcrypto),expected); + } + assert.notEqual(oldRaw.byteLength,newRaw.byteLength); + assert.equal(oldRaw.byteLength,oldCorrupt.byteLength);assert.notEqual(sha(oldRaw),sha(oldCorrupt)); +}); +for(const [name,body,id,expected]of [['old',oldRaw,oldIdentity,oldData],['new',newRaw,newIdentity,newData]]){ + test(`matching ${name} document and ${name} payload need exactly one verified request`,async()=>{ + const controller=new AbortController(),t=transport([reply('current.json',body)]); + success(await outcome(t.fetcher,id,controller.signal),expected);requests(t.calls,['current.json'],controller.signal); + }); +} +test('the existing digest-keyed retry still recovers an alias lagging a new document',async()=>{ + const controller=new AbortController(),t=transport([reply('current.json',oldRaw),reply(newKey,newRaw)]); + success(await outcome(t.fetcher,newIdentity,controller.signal),newData); + requests(t.calls,['current.json',newKey],controller.signal); +}); +test('old document plus newer payload automatically reacquires one verified successor pair',async()=>{ + const controller=new AbortController(),t=transport(transition()); + const result=await outcome(t.fetcher,oldIdentity,controller.signal); + // On unchanged f946 this is an AssertionError after the real count refusal, + // rather than an uncaught import/setup exception or a missing proposed API. + success(result,newData); + requests(t.calls,['current.json',oldKey,'current-meta.json',newKey],controller.signal); +}); +test('same-length digest mismatch also recovers without admitting corrupt old bytes',async()=>{ + const controller=new AbortController(),t=transport([ + reply('current.json',oldCorrupt),reply(oldKey,oldCorrupt),reply('current-meta.json',newMetaRaw),reply(newKey,newRaw), + ]); + success(await outcome(t.fetcher,oldIdentity,controller.signal),newData); + requests(t.calls,['current.json',oldKey,'current-meta.json',newKey],controller.signal); +}); +test('published legacy three-field metadata can bind a successor without an archive assumption',async()=>{ + const controller=new AbortController(),t=transport(transition(asBytes(newIdentity))); + success(await outcome(t.fetcher,oldIdentity,controller.signal),newData); + requests(t.calls,['current.json',oldKey,'current-meta.json',newKey],controller.signal); +}); + +const invalidMetadata=[ + ['malformed JSON',new TextEncoder().encode('{broken')], + ['missing digest',asBytes({bytes:newIdentity.bytes,observed_at:newIdentity.observed_at})], + ['unknown field',asBytes({...newMeta,private_url:'must not be accepted'})], + ['transient four-field schema',asBytes({...newIdentity,archive:'4'.repeat(64)})], + ['nonhex digest',asBytes({...newMeta,sha256:'not-a-digest'})], + ['string byte count',asBytes({...newMeta,bytes:String(newIdentity.bytes)})], + ['negative byte count',asBytes({...newMeta,bytes:-1})], + ['fractional byte count',asBytes({...newMeta,bytes:1.5})], + ['payload above existing 16 MiB bound',asBytes({...newMeta,bytes:16777217})], + ['invalid calendar timestamp',asBytes({...newMeta,observed_at:'2026-02-30T21:29:17Z'})], + ['invalid archive identity',asBytes({...newMeta,archive:'wrong'})], + ['invalid history identity',asBytes({...newMeta,history_manifest_sha256:'wrong'})], + ['metadata above 16 KiB',new TextEncoder().encode(JSON.stringify(newMeta).padEnd(16385,' '))], +]; +for(const [name,metadata]of invalidMetadata){ + test(`successor metadata refuses ${name} before requesting successor body`,async()=>{ + const controller=new AbortController(),t=transport(transition(metadata)); + refusal(await outcome(t.fetcher,oldIdentity,controller.signal)); + requests(t.calls,['current.json',oldKey,'current-meta.json'],controller.signal); + }); +} +test('metadata HTTP failure refuses without another body request or recovery cycle',async()=>{ + const controller=new AbortController(),steps=transition();steps[2]=reply('current-meta.json',newMetaRaw,503); + const t=transport(steps);refusal(await outcome(t.fetcher,oldIdentity,controller.signal)); + requests(t.calls,['current.json',oldKey,'current-meta.json'],controller.signal); +}); +test('verified successor body must have the metadata observation time',async()=>{ + const controller=new AbortController(),t=transport(transition(asBytes({...newMeta,observed_at:oldIdentity.observed_at}))); + refusal(await outcome(t.fetcher,oldIdentity,controller.signal)); + requests(t.calls,['current.json',oldKey,'current-meta.json',newKey],controller.signal); +}); +for(const [name,body]of [['byte count',oldRaw],['digest',newCorrupt]]){ + test(`successor ${name} mismatch refuses after four requests with no loop`,async()=>{ + const controller=new AbortController(),t=transport(transition(newMetaRaw,body)); + refusal(await outcome(t.fetcher,oldIdentity,controller.signal)); + requests(t.calls,['current.json',oldKey,'current-meta.json',newKey],controller.signal); + }); +} +for(const [name,index,paths]of [ + ['metadata',2,['current.json',oldKey,'current-meta.json']], + ['successor body',3,['current.json',oldKey,'current-meta.json',newKey]], +]){ + test(`one abort budget cancels a stalled ${name} request without another attempt`,{timeout:2000},async()=>{ + const controller=new AbortController(),steps=transition();steps[index]={url:paths.at(-1),waitForAbort:true}; + const t=transport(steps,{controller}),result=await outcome(t.fetcher,oldIdentity,controller.signal); + refusal(result);assert.equal(result.error.name,'AbortError');requests(t.calls,paths,controller.signal); + }); +} +test('an already aborted caller is refused without metadata recovery',async()=>{ + const controller=new AbortController();controller.abort();const t=transport([reply('current.json',oldRaw)]); + const result=await outcome(t.fetcher,oldIdentity,controller.signal);refusal(result);assert.equal(result.error.name,'AbortError'); + requests(t.calls,['current.json'],controller.signal); +}); +test('ordinary payload HTTP failure is not treated as a publication identity transition',async()=>{ + const controller=new AbortController(),t=transport([reply('current.json',oldRaw,503)]); + refusal(await outcome(t.fetcher,oldIdentity,controller.signal));requests(t.calls,['current.json'],controller.signal); +}); +test('invalid HTML descriptor is refused before any request',async()=>{ + const controller=new AbortController(),t=transport([]); + refusal(await outcome(t.fetcher,{sha256:'bad',bytes:oldIdentity.bytes},controller.signal));requests(t.calls,[],controller.signal); +}); +test('hash-matching invalid snapshot JSON never earns successor recovery',async()=>{ + const body=new TextEncoder().encode('{broken'),id={sha256:sha(body),bytes:body.byteLength}; + const controller=new AbortController(),t=transport([reply('current.json',body)]); + refusal(await outcome(t.fetcher,id,controller.signal));requests(t.calls,['current.json'],controller.signal); +}); diff --git a/tests/test_site_transition_source_guard.py b/tests/test_site_transition_source_guard.py new file mode 100644 index 000000000..c385df402 --- /dev/null +++ b/tests/test_site_transition_source_guard.py @@ -0,0 +1,169 @@ +"""Pure merge-identity boundary controls; no Git, network or project imports.""" +import hashlib +import importlib.util +from pathlib import Path +import unittest + + +SOURCE = Path(__file__).resolve().parents[1] / 'tools/site_transition_source_guard.py' +SPEC = importlib.util.spec_from_file_location('site_transition_source_guard', SOURCE) +guard = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(guard) + +BASE, HEAD, OTHER, TREE = ('1' * 40, '2' * 40, '3' * 40, '4' * 40) +AUTHOR = b'author Fixture 1700000000 +0000' +COMMITTER = b'committer Fixture 1700000000 +0000' + + +def literal_commit(parents=(BASE, HEAD), extra=(), message=b'Controlled merge fixture\n'): + lines = [b'tree ' + TREE.encode()] + lines += [b'parent ' + parent.encode() for parent in parents] + return b'\n'.join(lines + [AUTHOR, COMMITTER] + list(extra)) + b'\n\n' + message + + +def arguments(raw=None, **changes): + """Independent Git object framing constructs the declared fixture identity.""" + raw = literal_commit() if raw is None else raw + commit = hashlib.sha1(b'commit ' + str(len(raw)).encode('ascii') + b'\0' + raw).hexdigest() + result = dict(event_name='pull_request', repository='d6g8k5htny-coder/main', + event_ref='refs/pull/501/merge', event_sha=commit, pr_number=501, + event_head_sha=HEAD, event_base_sha=BASE, checked_commit=commit, + actual_commit_raw=raw, frozen_base_commit=BASE) + result.update(changes) + return result + + +class MergeJoinControls(unittest.TestCase): + def refuse(self, **values): + with self.assertRaises(guard.SourceJoinError): + guard.verify_merge_join(**values) + + def test_stale_event_base_preserves_observation_and_accepts_frozen_actual_parents(self): + # Break caught: the event base is incorrectly substituted for the frozen + # actual first parent, rejecting a valid currently tested composition. + values = arguments(event_base_sha=OTHER) + try: + record = guard.verify_merge_join(**values) + except guard.SourceJoinError as error: + self.fail('Valid frozen ordered parents were refused because of stale event metadata: ' + str(error)) + self.assertEqual(record['pull_request_base_sha'], OTHER) + self.assertEqual(record['candidate_base_commit'], BASE) + self.assertEqual(record['actual_merge_parents'], [BASE, HEAD]) + self.assertEqual(record['checked_commit'], values['checked_commit']) + self.assertEqual(record['actual_tree_sha'], TREE) + + def test_matching_event_and_actual_base_still_passes(self): + values = arguments() + expected = { + 'event_name': 'pull_request', 'repository': 'd6g8k5htny-coder/main', + 'event_ref': 'refs/pull/501/merge', 'event_sha': values['event_sha'], + 'pull_request_number': 501, 'pull_request_head_sha': HEAD, + 'pull_request_base_sha': BASE, 'checked_commit': values['checked_commit'], + 'actual_tree_sha': TREE, 'actual_merge_parents': [BASE, HEAD], + 'candidate_base_commit': BASE, + } + self.assertEqual(guard.verify_merge_join(**values), expected) + + def test_wrong_frozen_first_parent_refuses(self): + # Even agreeing event metadata must not authorize a moved frozen base. + self.refuse(**arguments(frozen_base_commit=OTHER)) + self.refuse(**arguments(literal_commit(parents=(OTHER, HEAD)), event_base_sha=OTHER)) + + def test_wrong_second_parent_refuses(self): + self.refuse(**arguments(literal_commit(parents=(BASE, OTHER)))) + self.refuse(**arguments(event_head_sha=OTHER)) + + def test_reversed_parents_refuse(self): + self.refuse(**arguments(literal_commit(parents=(HEAD, BASE)))) + + def test_third_parent_refuses(self): + self.refuse(**arguments(literal_commit(parents=(BASE, HEAD, OTHER)))) + + def test_missing_parent_refuses(self): + self.refuse(**arguments(literal_commit(parents=(BASE,)))) + self.refuse(**arguments(literal_commit(parents=()))) + + def test_wrong_checkout_or_event_sha_refuses(self): + self.refuse(**arguments(checked_commit=OTHER)) + self.refuse(**arguments(event_sha=OTHER)) + + def test_commit_body_hash_mismatch_refuses(self): + values = arguments() + values['actual_commit_raw'] += b'Additional message bytes\n' + self.refuse(**values) + + def test_wrong_repository_event_or_pr_ref_refuses(self): + for changes in ( + {'repository': 'other/repository'}, {'repository': None}, + {'event_name': 'pull_request_target'}, {'event_name': 'push'}, + {'event_ref': 'refs/heads/main'}, {'event_ref': 'refs/pull/502/merge'}, + {'event_ref': 'refs/pull/501/head'}, {'event_ref': 'refs/pull/0501/merge'}, + {'pr_number': True}, {'pr_number': 0}, {'pr_number': -1}, + {'pr_number': '501'}, {'pr_number': 501.0}, + ): + with self.subTest(changes=changes): + self.refuse(**arguments(**changes)) + + def test_malformed_sha_values_refuse(self): + for field in ('event_sha', 'event_head_sha', 'event_base_sha', + 'checked_commit', 'frozen_base_commit'): + for value in (None, False, 0, [], 'A' * 40, 'a' * 39, 'a' * 41, 'g' * 40, 'a' * 40 + '\n'): + with self.subTest(field=field, value=value): + self.refuse(**arguments(**{field: value})) + + def test_malformed_commit_header_refuses(self): + original = literal_commit() + malformed = { + 'missing separator': original.replace(b'\n\n', b'\n', 1), + 'bad tree': original.replace(TREE.encode(), b'f' * 39, 1), + 'duplicate tree': literal_commit(extra=(b'tree ' + TREE.encode(),)), + 'duplicate author': literal_commit(extra=(AUTHOR,)), + 'duplicate committer': literal_commit(extra=(COMMITTER,)), + 'missing author': original.replace(AUTHOR + b'\n', b'', 1), + 'missing committer': original.replace(COMMITTER + b'\n', b'', 1), + 'header NUL': literal_commit(extra=(b'encoding UTF-8\0',)), + 'header CR': literal_commit(extra=(b'encoding UTF-8\r',)), + 'tab continuation': literal_commit(extra=(b'gpgsig signature', b'\tcontinued')), + 'uppercase header': literal_commit(extra=(b'Encoding UTF-8',)), + 'empty header value': literal_commit(extra=(b'encoding ',)), + 'orphan continuation': original.replace(AUTHOR, b' orphan\n' + AUTHOR, 1), + 'identity continuation': literal_commit(extra=(b' identity continuation',)), + } + for name, raw in malformed.items(): + with self.subTest(name=name): + self.refuse(**arguments(raw)) + + def test_multiline_signature_header_preserves_literal_parent_join(self): + raw = literal_commit(extra=(b'gpgsig -----BEGIN PGP SIGNATURE-----', + b' ', b' encoded-signature', + b' -----END PGP SIGNATURE-----')) + result = guard.verify_merge_join(**arguments(raw)) + self.assertEqual(result['actual_merge_parents'], [BASE, HEAD]) + self.assertEqual(result['actual_tree_sha'], TREE) + + def test_header_line_bound_accepts_128_and_refuses_129(self): + # Five required lines plus 123 extension lines is the accepted boundary. + extension = tuple(b'x-fixture value' for _ in range(123)) + self.assertEqual(guard.verify_merge_join(**arguments(literal_commit(extra=extension)))['actual_tree_sha'], TREE) + self.refuse(**arguments(literal_commit(extra=extension + (b'x-fixture extra',)))) + + def test_commit_byte_bound_accepts_65536_and_refuses_65537(self): + header = literal_commit(message=b'') + exact = header + b'x' * (65536 - len(header)) + self.assertEqual(guard.verify_merge_join(**arguments(exact))['actual_tree_sha'], TREE) + self.refuse(**arguments(exact + b'x')) + + def test_mutable_or_nonbyte_commit_input_refuses(self): + for value in (None, '', bytearray(literal_commit()), memoryview(literal_commit())): + with self.subTest(value_type=type(value).__name__): + values = arguments() + values['actual_commit_raw'] = value + self.refuse(**values) + + def test_message_is_hashed_as_bytes_without_becoming_header(self): + raw = literal_commit(message=b'parent ' + OTHER.encode() + b'\n\x00non-UTF8:\xff\n') + self.assertEqual(guard.verify_merge_join(**arguments(raw))['actual_merge_parents'], [BASE, HEAD]) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/current_site_browser_check.py b/tools/current_site_browser_check.py index d8f9f9345..cadace0b6 100644 --- a/tools/current_site_browser_check.py +++ b/tools/current_site_browser_check.py @@ -286,24 +286,27 @@ def exercise_observation_coherence(browser,origin,output,report,data,expect): previous=re.sub(rb'("observed_at"\s*:\s*)'+re.escape(json.dumps(data['observed_at']).encode()),lambda m:m.group(1)+b'"2000-01-01T00:00:00Z"',raw,count=1) require(json.loads(previous)['observed_at']=='2000-01-01T00:00:00Z' and len(previous)==len(raw),'Mixed-observation fixture identity failed') digest=sha256(raw).hexdigest() + metadata=(ROOT/'docs/site/current-meta.json').read_bytes() + metadata_identity=json.loads(metadata) + require(metadata_identity.get('sha256')==digest and type(metadata_identity.get('bytes')) is int and metadata_identity['bytes']==len(raw) and metadata_identity.get('observed_at')==data['observed_at'],'Observation metadata fixture does not bind the expected payload') for persistent in [False,True]: case={'case':'observation-persistent-mismatch-refusal' if persistent else 'observation-integrity-recovery','passed':False, 'scope':'Controlled local old/new response fixture; no public cache-layer inference','requests':[],'page_errors':[], - 'expected_payload':{'bytes':len(raw),'sha256':digest},'old_payload':{'bytes':len(previous),'sha256':sha256(previous).hexdigest()}} + 'expected_payload':{'bytes':len(raw),'sha256':digest},'expected_metadata':{'bytes':len(metadata),'sha256':sha256(metadata).hexdigest()},'old_payload':{'bytes':len(previous),'sha256':sha256(previous).hexdigest()}} report['cases'].append(case) context=browser.new_context(viewport={'width':1200,'height':900},reduced_motion='reduce') page=context.new_page();page.on('pageerror',lambda e:case['page_errors'].append(str(e))) def respond(route): url=route.request.url;case['requests'].append(url) - body=previous if persistent or url==origin+'current.json' else raw + body=metadata if url==origin+'current-meta.json' else previous if persistent or url==origin+'current.json' else raw route.fulfill(status=200,content_type='application/json',body=body) try: - page.route('**/current.json*',respond);page.goto(origin+'dependencies.html') + page.route('**/current.json*',respond);page.route(origin+'current-meta.json',respond);page.goto(origin+'dependencies.html') if persistent: expect(page.locator('.current-state')).to_contain_text('Unavailable') expect(page.locator('#atlas-status')).to_contain_text('Unavailable') require(page.locator('#atlas-inspector h3').count()==0 and page.locator('#atlas-canvas .atlas-node').count()==0 and page.locator('#equation-content pre').count()==0,'Persistent mismatch admitted current content') - require(1<=len(case['requests'])<=2,'Persistent mismatch exceeded the bounded request budget') + require(case['requests']==[origin+'current.json',origin+'current.json?observation='+digest,origin+'current-meta.json',origin+'current.json?observation='+digest],'Persistent mismatch did not retain its exact bounded metadata recovery sequence') else: expect(page.locator('#atlas-inspector h3')).to_have_count(1) expect(page.locator('.current-state')).to_contain_text('Verified source observation: '+data['observed_at']) diff --git a/tools/site_asset_rewrite_observation.py b/tools/site_asset_rewrite_observation.py new file mode 100644 index 000000000..9c079df52 --- /dev/null +++ b/tools/site_asset_rewrite_observation.py @@ -0,0 +1,437 @@ +#!/usr/bin/env python3 +"""Hosted-only exact asset rewrite proposal capture; never applies a proposal.""" +import base64 +import hashlib +import json +import math +import os +from pathlib import Path, PurePosixPath +import re +import resource +import signal +import stat +import subprocess +import sys +import tempfile +import time +import types + +# PROVISIONAL: final canonical modules/freeze are not yet bound by either consumer. +GUARD = 'tools/site_transition_source_guard.py' +GUARD_SHA = '69aa32de61db44014f3b78a4374dda1852ab6854fbf4ac988abef6abf88e1fc6' +PRODUCER = 'tools/site_asset_release.py' +PRODUCER_SHA = '390ea41ad0b4426913757c186e341dfcc1d1abcdafce505f51607a3dd31c0ffd' +FREEZE = 'tests/fixtures/current_site_transition_candidate_20261022/production-source-freeze.json' +MODULES = {'docs/site/current-model.mjs', 'docs/site/current.mjs', 'docs/site/dependency-model.mjs'} +ROOTS = ('docs/site/', 'docs/public-math/') +EDITABLE = {'.html', '.js', '.mjs', '.css'} +FILE_LIMIT = 16 * 1024 * 1024 +NAMESPACE_LIMIT = 256 * 1024 * 1024 +BODY_LIMIT = 512 * 1024 +COUNT_LIMIT = 128 +CONTEXT_LIMIT = 65536 +STDIO_LIMIT = 1024 * 1024 +CARRIER_LIMIT = 950000 +CHUNK = 3072 + +class Hold(Exception): + pass + +def require(condition, code): + if not condition: + raise Hold(code) + +def digest(raw): + return hashlib.sha256(raw).hexdigest() + +def pin(raw): + return {'bytes': len(raw), 'sha256': digest(raw), + 'git_blob': hashlib.sha1(b'blob ' + str(len(raw)).encode('ascii') + b'\0' + raw).hexdigest()} + +def encoded(value): + return (json.dumps(value, sort_keys=True, separators=(',', ':'), ensure_ascii=True) + '\n').encode('ascii') + +def unique_object(pairs): + result = {} + for key, value in pairs: + require(key not in result, 'DUPLICATE_JSON_KEY') + result[key] = value + return result + +def load_json(raw): + return json.loads(raw.decode('utf-8'), object_pairs_hook=unique_object) + +def clean_path(name): + require(isinstance(name, str) and len(name) <= 4096 and + re.fullmatch(r'[A-Za-z0-9_./-]+', name) is not None and + all(part not in ('', '.', '..') for part in name.split('/')) and + not PurePosixPath(name).is_absolute(), 'UNSUPPORTED_TRACKED_PATH') + return name + +def safe_read(repo, name, limit): + """Open every ancestor relative to an owned directory fd, never a symlink.""" + parts = clean_path(name).split('/') + directory = os.open(repo, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW) + descriptor = None + try: + for part in parts[:-1]: + child = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory) + os.close(directory) + directory = child + descriptor = os.open(parts[-1], os.O_RDONLY | os.O_NOFOLLOW, dir_fd=directory) + before = os.fstat(descriptor) + require(stat.S_ISREG(before.st_mode) and before.st_nlink == 1 and + 0 <= before.st_size <= limit, 'UNSAFE_OR_OVERSIZED_FILE') + chunks, size = [], 0 + while True: + chunk = os.read(descriptor, min(65536, limit - size + 1)) + if not chunk: + break + size += len(chunk) + require(size <= limit, 'PHYSICAL_READ_LIMIT') + chunks.append(chunk) + after = os.fstat(descriptor) + identity = lambda s: (s.st_dev, s.st_ino, s.st_mode, s.st_nlink, s.st_size, + s.st_mtime_ns, s.st_ctime_ns) + require(identity(before) == identity(after) and size == after.st_size, 'FILE_CHANGED_DURING_READ') + return b''.join(chunks), identity(after) + finally: + if descriptor is not None: + os.close(descriptor) + os.close(directory) + +def child(command, repo, work, label, limit, seconds, deadline): + require(time.monotonic() < deadline, 'PARENT_DEADLINE') + target = work / (label + '.stdout') + errors = work / (label + '.stderr') + stream_limit = limit // 2 + process = None + status, code = 'SETUP_ERROR', None + def physical_cap(): + resource.setrlimit(resource.RLIMIT_FSIZE, (stream_limit, stream_limit)) + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + environment = {key: os.environ[key] for key in ('PATH', 'LANG', 'LC_ALL', 'TZ') if key in os.environ} + environment.update({'GIT_CONFIG_NOSYSTEM': '1', 'GIT_CONFIG_GLOBAL': '/dev/null', + 'GIT_TERMINAL_PROMPT': '0', 'GIT_OPTIONAL_LOCKS': '0'}) + started = time.monotonic() + try: + with target.open('xb') as stream, errors.open('xb') as error_stream: + process = subprocess.Popen(command, cwd=repo, env=environment, + stdin=subprocess.DEVNULL, stdout=stream, stderr=error_stream, + start_new_session=True, preexec_fn=physical_cap) + try: + code = process.wait(timeout=min(seconds, max(0.01, deadline - time.monotonic()))) + status = 'COMPLETED' if code == 0 else 'CHILD_ERROR' + except subprocess.TimeoutExpired: + status = 'TIMEOUT' + except OSError: + status = 'SETUP_ERROR' + finally: + if process is not None: + try: + os.killpg(process.pid, signal.SIGKILL) + except ProcessLookupError: + pass + try: + process.wait(timeout=5) + code = process.returncode + except subprocess.TimeoutExpired: + status = 'TERMINATION_UNCONFIRMED' + if target.exists(): + raw, _ = safe_read(work, target.name, stream_limit) + else: + raw = b'' + if errors.exists(): + stderr, _ = safe_read(work, errors.name, stream_limit) + else: + stderr = b'' + if len(raw) >= stream_limit or len(stderr) >= stream_limit: + status = 'OUTPUT_CAP' + result = {'phase': label, 'status': status, 'returncode': code, + 'elapsed_seconds': round(time.monotonic() - started, 3), + 'stdout': {'bytes': len(raw), 'sha256': digest(raw)}, + 'stderr': {'bytes': len(stderr), 'sha256': digest(stderr)}, + 'stdio_emitted': False, 'deadline_seconds': seconds, + 'physical_stdio_combined_limit': limit, 'physical_stdio_stream_limit': stream_limit} + return result, raw + +def git(repo, work, arguments, serial, deadline): + serial[0] += 1 + result, raw = child(['git', '-C', str(repo), *arguments], repo, work, + 'git-%04d' % serial[0], 4 * 1024 * 1024, 10, deadline) + require(result['status'] == 'COMPLETED', 'GIT_CAPTURE_FAILED') + return raw + +def tracked(repo, work, serial, deadline): + raw = git(repo, work, ['ls-files', '--stage', '-z'], serial, deadline) + approved, all_names, indexed = [], set(), {} + for entry in raw.split(b'\0'): + if not entry: + continue + prefix, separator, name_raw = entry.partition(b'\t') + require(separator == b'\t', 'INVALID_INDEX_RECORD') + mode, blob, stage = prefix.decode('ascii').split(' ') + name = name_raw.decode('utf-8') + require(name not in all_names and stage == '0', 'DUPLICATE_OR_UNMERGED_INDEX') + all_names.add(name) + if name.startswith(ROOTS): + clean_path(name) + require(mode in ('100644', '100755') and re.fullmatch(r'[0-9a-f]{40}', blob), 'NONORDINARY_TRACKED_INPUT') + approved.append(name) + indexed[name] = blob + require(approved and len(approved) <= 65536 and any(n.startswith('docs/site/') for n in approved), 'INVENTORY_LIMIT') + return raw, sorted(approved), indexed + +def snapshot(repo, names): + result, total = {}, 0 + for name in names: + raw, identity = safe_read(repo, name, FILE_LIMIT) + total += len(raw) + require(total <= NAMESPACE_LIMIT, 'NAMESPACE_BYTE_LIMIT') + result[name] = {'pin': pin(raw), 'identity': identity} + return result + +def check_clean(repo, work, serial, deadline): + require(not git(repo, work, ['diff', '--name-status', '-z', '--no-renames', 'HEAD', '--'], serial, deadline), 'DIRTY_TRACKED_BASELINE') + require(not git(repo, work, ['ls-files', '--others', '-z'], serial, deadline), 'UNTRACKED_BASELINE') + +def frame_set(context, records, bodies): + context_raw, records_raw = encoded(context), encoded(records) + require(len(context_raw) <= CONTEXT_LIMIT and len(records_raw) <= CONTEXT_LIMIT, 'CONTEXT_OR_RECORD_LIMIT') + members = [('context.json', context_raw), ('changes.json', records_raw), *bodies] + lines, aggregate, total = [], hashlib.sha256(b'CS_ASSET_SET_V1\0'), 0 + for name, raw in members: + sha, count = digest(raw), math.ceil(len(raw) / CHUNK) + header = 'name=%s bytes=%d sha256=%s chunks=%d' % (name, len(raw), sha, count) + lines.append('CS_ASSET_BEGIN ' + header) + for index in range(count): + value = base64.b64encode(raw[index * CHUNK:(index + 1) * CHUNK]).decode('ascii') + lines.append('CS_ASSET_CHUNK name=%s index=%d data=%s' % (name, index, value)) + lines.append('CS_ASSET_END ' + header) + aggregate.update(('%s\0%d\0%s\0' % (name, len(raw), sha)).encode('ascii')) + total += len(raw) + lines.append('CS_ASSET_COMPLETE files=%d bytes=%d sha256=%s disposition=%s' % + (len(members), total, aggregate.hexdigest(), context['disposition'])) + carrier = ('\n'.join(lines) + '\n').encode('ascii') + require(len(carrier) <= CARRIER_LIMIT, 'FRAME_CARRIER_LIMIT') + return carrier + +def observe(repo, work, context, deadline): + serial = [0] + expected = os.environ.get('SITE_ASSET_CANDIDATE_FREEZE_SHA256', '') + require(re.fullmatch(r'[0-9a-f]{64}', expected), 'UNBOUND_CANDIDATE_FREEZE') + context['candidate_freeze_sha256'] = expected + immutable_sources = {} + for label, source_path in (('capture_source', 'tools/site_asset_rewrite_observation.py'), + ('workflow_source', '.github/workflows/site-asset-rewrite-proposal.yml'), + ('merge_guard_source', GUARD)): + source_raw, _ = safe_read(repo, source_path, 32768) + context[label] = {'path': source_path, **pin(source_raw)} + immutable_sources[source_path] = source_raw + executed_path = Path(__file__).absolute() + executed_raw, _ = safe_read(executed_path.parent, executed_path.name, 32768) + require(executed_raw == immutable_sources['tools/site_asset_rewrite_observation.py'], + 'EXECUTED_CAPTURE_SOURCE_MISMATCH') + context['executed_capture_source'] = pin(executed_raw) + guard_raw = immutable_sources[GUARD] + require(len(guard_raw) == 4249 and digest(guard_raw) == GUARD_SHA, 'MERGE_GUARD_SOURCE_MISMATCH') + # Execute only the authenticated captured bytes, never a second mutable-path import. + guard = types.ModuleType('site_transition_source_guard') + guard.__file__ = str(repo / GUARD) + exec(compile(guard_raw, guard.__file__, 'exec'), guard.__dict__) + require(os.environ.get('GITHUB_EVENT_NAME') == 'pull_request' and + os.environ.get('GITHUB_REPOSITORY') == 'd6g8k5htny-coder/main', 'WRONG_EVENT_OR_REPOSITORY') + event_path = Path(os.environ['GITHUB_EVENT_PATH']) + require(event_path.is_absolute(), 'INVALID_EVENT_PATH') + event, _ = safe_read(event_path.parent, event_path.name, 1024 * 1024) + event = load_json(event) + pr = event['pull_request'] + number, head, base = event['number'], pr['head']['sha'], pr['base']['sha'] + require(type(number) is int and 1 <= number < 10**12 and + re.fullmatch(r'[0-9a-f]{40}', head) and re.fullmatch(r'[0-9a-f]{40}', base), 'INVALID_PR_CONTEXT') + checked = git(repo, work, ['rev-parse', 'HEAD'], serial, deadline).decode('ascii').strip() + require(checked == os.environ.get('GITHUB_SHA') and re.fullmatch(r'[0-9a-f]{40}', checked) and + os.environ.get('GITHUB_REF') == 'refs/pull/%d/merge' % number, 'WRONG_TESTED_COMMIT') + context.update({'event_name': 'pull_request', 'repository': 'd6g8k5htny-coder/main', + 'event_ref': os.environ['GITHUB_REF'], 'event_sha': os.environ['GITHUB_SHA'], + 'pull_request_number': number, 'head_sha': head, 'base_sha': base, + 'tested_commit': checked}) + for key in ('GITHUB_RUN_ID', 'GITHUB_RUN_ATTEMPT'): + value = os.environ.get(key, '') + require(re.fullmatch(r'[1-9][0-9]{0,19}', value), 'INVALID_RUN_CONTEXT') + context[key.lower()] = value + producer, _ = safe_read(repo, PRODUCER, 32768) + require(len(producer) == 26305 and digest(producer) == PRODUCER_SHA and + pin(producer)['git_blob'] == '6c7c1642745d7488ff42a1842ec0ed6b49b42951', 'PRODUCER_SOURCE_MISMATCH') + context['producer'] = {'path': PRODUCER, **pin(producer)} + freeze_raw, _ = safe_read(repo, FREEZE, 16384) + require(digest(freeze_raw) == expected, 'CANDIDATE_FREEZE_MISMATCH') + freeze = load_json(freeze_raw) + require(set(freeze) == {'schema_version', 'candidate_base_commit', 'files'} and + type(freeze['schema_version']) is int and freeze['schema_version'] == 1 and + isinstance(freeze['candidate_base_commit'], str) and + re.fullmatch(r'[0-9a-f]{40}', freeze['candidate_base_commit']) and + isinstance(freeze['files'], list) and len(freeze['files']) == 3, 'INVALID_CANDIDATE_FREEZE') + serial[0] += 1 + commit_capture, commit_raw = child( + ['git', '--no-replace-objects', 'cat-file', 'commit', checked], + repo, work, 'literal-commit-%04d' % serial[0], 131074, 10, deadline) + context['literal_commit_capture'] = commit_capture + require(commit_capture['status'] == 'COMPLETED' and 0 < len(commit_raw) <= 65536, + 'LITERAL_COMMIT_CAPTURE_FAILED') + join = guard.verify_merge_join( + event_name=os.environ.get('GITHUB_EVENT_NAME'), + repository=os.environ.get('GITHUB_REPOSITORY'), event_ref=os.environ.get('GITHUB_REF'), + event_sha=os.environ.get('GITHUB_SHA'), pr_number=number, event_head_sha=head, + event_base_sha=base, checked_commit=checked, actual_commit_raw=commit_raw, + frozen_base_commit=freeze['candidate_base_commit']) + context.update({'source_join': join, 'actual_tree_sha': join['actual_tree_sha'], + 'actual_merge_parents': join['actual_merge_parents'], + 'tested_merge_parents': join['actual_merge_parents'], + 'candidate_base_commit': join['candidate_base_commit']}) + found = set() + require([entry.get('path') if isinstance(entry, dict) else None for entry in freeze['files']] == + ['docs/site/current-model.mjs', 'docs/site/current.mjs', 'docs/site/dependency-model.mjs'], + 'CANDIDATE_MEMBER_ORDER_MISMATCH') + for entry in freeze['files']: + require(isinstance(entry, dict) and set(entry) == {'path', 'bytes', 'sha256', 'git_blob'} and + entry['path'] in MODULES and entry['path'] not in found and + type(entry['bytes']) is int and 0 <= entry['bytes'] <= FILE_LIMIT and + isinstance(entry['sha256'], str) and re.fullmatch(r'[0-9a-f]{64}', entry['sha256']) and + isinstance(entry['git_blob'], str) and re.fullmatch(r'[0-9a-f]{40}', entry['git_blob']), 'INVALID_CANDIDATE_MEMBER') + raw, _ = safe_read(repo, entry['path'], FILE_LIMIT) + require(pin(raw) == {key: entry[key] for key in ('bytes', 'sha256', 'git_blob')}, 'CANDIDATE_SOURCE_MISMATCH') + found.add(entry['path']) + require(found == MODULES, 'CANDIDATE_MEMBER_SET_MISMATCH') + context['candidate_freeze'] = {'path': FREEZE, **pin(freeze_raw)} + context['candidate_modules'] = freeze['files'] + check_clean(repo, work, serial, deadline) + before_index, names, indexed = tracked(repo, work, serial, deadline) + before = snapshot(repo, names) + require(all(before[name]['pin']['git_blob'] == indexed[name] for name in names), 'WORKTREE_INDEX_BYTES_MISMATCH') + context['inventory_before_sha256'] = digest(encoded({name: before[name]['pin'] for name in names})) + context['inventory_count'] = len(names) + context['source_guard'] = 'passed' + rewritten = None + for phase, arguments in (('rewrite', []), ('check', ['--check'])): + producer_now, _ = safe_read(repo, PRODUCER, 32768) + freeze_now, _ = safe_read(repo, FREEZE, 16384) + require(producer_now == producer and freeze_now == freeze_raw, 'PHASE_IMMUTABLE_INPUT_CHANGED') + for source_path, source_before in immutable_sources.items(): + source_now, _ = safe_read(repo, source_path, 32768) + require(source_now == source_before, 'PHASE_CAPTURE_WORKFLOW_OR_GUARD_CHANGED') + result, _ = child([sys.executable, '-I', '-B', '-S', PRODUCER, *arguments], repo, work, + phase, STDIO_LIMIT, 90, deadline) + context['producer_phases'].append(result) + require(result['status'] == 'COMPLETED', 'PRODUCER_' + phase.upper() + '_' + result['status']) + phase_index, phase_names, _ = tracked(repo, work, serial, deadline) + require(phase_index == before_index and phase_names == names, 'PHASE_MEMBERSHIP_OR_INDEX_CHANGED') + require(not git(repo, work, ['ls-files', '--others', '-z'], serial, deadline), 'PHASE_UNTRACKED_OUTPUT') + phase_state = snapshot(repo, names) + phase_diff = git(repo, work, ['diff', '--name-status', '-z', '--no-renames', 'HEAD', '--'], serial, deadline).split(b'\0') + if phase_diff and phase_diff[-1] == b'': + phase_diff.pop() + require(len(phase_diff) % 2 == 0, 'PHASE_INVALID_DIFF') + phase_changes = sorted(name for name in names if phase_state[name]['pin'] != before[name]['pin']) + require(len(phase_changes) <= COUNT_LIMIT and + all(name.startswith('docs/site/') and PurePosixPath(name).suffix in EDITABLE for name in phase_changes), + 'PHASE_INELIGIBLE_CHANGE_OR_COUNT') + require(all(before[name]['identity'][2] == phase_state[name]['identity'][2] for name in names), 'PHASE_MODE_CHANGED') + require(all(phase_diff[index] == b'M' for index in range(0, len(phase_diff), 2)) and + sorted(phase_diff[index + 1].decode('utf-8') for index in range(0, len(phase_diff), 2)) == phase_changes, + 'PHASE_ADD_DELETE_RENAME_TYPE_OR_OUTSIDE_CHANGE') + producer_after, _ = safe_read(repo, PRODUCER, 32768) + freeze_after, _ = safe_read(repo, FREEZE, 16384) + require(producer_after == producer and freeze_after == freeze_raw, 'PHASE_IMMUTABLE_INPUT_CHANGED') + for source_path, source_before in immutable_sources.items(): + source_after, _ = safe_read(repo, source_path, 32768) + require(source_after == source_before, 'PHASE_CAPTURE_WORKFLOW_OR_GUARD_CHANGED') + context[phase + '_inventory_sha256'] = digest(encoded({name: phase_state[name]['pin'] for name in names})) + if phase == 'rewrite': + rewritten = phase_state + else: + require(phase_state == rewritten, 'CHECK_PHASE_CHANGED_SOURCE') + after_index, after_names, _ = tracked(repo, work, serial, deadline) + require(after_index == before_index and after_names == names, 'TRACKED_MEMBERSHIP_OR_INDEX_CHANGED') + require(not git(repo, work, ['ls-files', '--others', '-z'], serial, deadline), 'UNTRACKED_OUTPUT') + after = snapshot(repo, names) + context['inventory_after_sha256'] = digest(encoded({name: after[name]['pin'] for name in names})) + changed = [] + for name in names: + require(before[name]['identity'][2] == after[name]['identity'][2], 'FILE_MODE_CHANGED') + if before[name]['pin'] != after[name]['pin']: + require(name.startswith('docs/site/') and PurePosixPath(name).suffix in EDITABLE, 'INELIGIBLE_CHANGED_FILE') + changed.append(name) + require(len(changed) <= COUNT_LIMIT, 'CHANGED_FILE_COUNT_LIMIT') + difference = git(repo, work, ['diff', '--name-status', '-z', '--no-renames', 'HEAD', '--'], serial, deadline).split(b'\0') + if difference and difference[-1] == b'': + difference.pop() + require(len(difference) % 2 == 0, 'INVALID_DIFF_RECORDS') + diff_names = [] + for index in range(0, len(difference), 2): + require(difference[index] == b'M', 'ADD_DELETE_RENAME_TYPE_OR_OUTSIDE_CHANGE') + diff_names.append(difference[index + 1].decode('utf-8')) + require(sorted(diff_names) == changed, 'OUTSIDE_OR_UNACCOUNTED_CHANGE') + records, bodies, total = [], [], 0 + for index, name in enumerate(changed): + raw, identity = safe_read(repo, name, min(FILE_LIMIT, BODY_LIMIT - total)) + require(pin(raw) == after[name]['pin'] and identity == after[name]['identity'], 'POST_SNAPSHOT_READBACK_MISMATCH') + total += len(raw) + require(total <= BODY_LIMIT, 'CHANGED_BODY_AGGREGATE_LIMIT') + body_name = 'body-%04d.bin' % index + records.append({'path': name, 'body_name': body_name, + 'preimage': before[name]['pin'], 'proposed': after[name]['pin']}) + bodies.append((body_name, raw)) + # Revalidate complete membership and diff after all exact body readbacks. + final_index, final_names, _ = tracked(repo, work, serial, deadline) + require(final_index == before_index and final_names == names, 'FINAL_MEMBERSHIP_CHANGED') + final = snapshot(repo, names) + require(final == after, 'FINAL_NAMESPACE_CHANGED') + require(not git(repo, work, ['ls-files', '--others', '-z'], serial, deadline), 'FINAL_UNTRACKED_OUTPUT') + require(git(repo, work, ['diff', '--name-status', '-z', '--no-renames', 'HEAD', '--'], serial, deadline).split(b'\0')[:-1] == difference, + 'FINAL_DIFF_CHANGED') + for source_path, source_before in immutable_sources.items(): + source_final, _ = safe_read(repo, source_path, 32768) + require(source_final == source_before, 'FINAL_CAPTURE_WORKFLOW_OR_GUARD_CHANGED') + context.update({'changed_file_count': len(records), 'changed_body_bytes': total, + 'complete_set': True, 'disposition': 'PROPOSAL_COMPLETE_REQUIRES_REVIEW'}) + return records, bodies + +def main(): + context = {'schema_version': 1, 'scientific_effect': 'NONE', 'source_guard': 'not_started', + 'disposition': 'HOLD', 'complete_set': False, 'producer_phases': [], + 'limits': {'changed_bytes': BODY_LIMIT, 'changed_files': COUNT_LIMIT, + 'context_bytes': CONTEXT_LIMIT, 'carrier_bytes': CARRIER_LIMIT, + 'chunk_bytes': CHUNK, 'producer_seconds_each': 90, 'producer_stdio_bytes_each': STDIO_LIMIT}, + 'python_version': '.'.join(map(str, sys.version_info[:3])), + 'producer_commands': [['python3', '-I', '-B', '-S', PRODUCER], + ['python3', '-I', '-B', '-S', PRODUCER, '--check']]} + records, bodies = [], [] + try: + repo = Path.cwd().resolve(strict=True) + temporary = Path(os.environ['RUNNER_TEMP']).resolve(strict=True) + require(not temporary.is_relative_to(repo), 'TEMP_INSIDE_CHECKOUT') + with tempfile.TemporaryDirectory(prefix='site-asset-proposal-', dir=temporary) as directory: + work = Path(directory) + os.chmod(work, 0o700) + records, bodies = observe(repo, work, context, time.monotonic() + 270) + except Hold as error: + context['failure_code'] = str(error) + except Exception: + context['failure_code'] = 'UNEXPECTED_SOURCE_OR_SETUP_ERROR' + if 'failure_code' in context: + context.update({'disposition': 'HOLD', 'complete_set': False, + 'changed_file_count': 0, 'changed_body_bytes': 0}) + records, bodies = [], [] + try: + carrier = frame_set(context, records, bodies) + except Exception: + context.update({'disposition': 'HOLD', 'complete_set': False, 'failure_code': 'REPORT_OR_CARRIER_LIMIT', + 'changed_file_count': 0, 'changed_body_bytes': 0}) + carrier = frame_set(context, [], []) + sys.stdout.buffer.write(carrier) + sys.stdout.buffer.flush() + return 0 if context['disposition'] == 'PROPOSAL_COMPLETE_REQUIRES_REVIEW' else 1 + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tools/site_transition_capture_regression.py b/tools/site_transition_capture_regression.py new file mode 100644 index 000000000..38ec85313 --- /dev/null +++ b/tools/site_transition_capture_regression.py @@ -0,0 +1,506 @@ +"""Durable Source-only actual-wrapper regressions: all results NOT_RUN here. + +Exercises the exact PYNODE body extracted from the supplied workflow, unmodified. +Real stdlib Python children stand in for Node; no project/Node/Git helper runs. +The wrapper's actual source inventory, physical cap, cleanup and context code run. +Fault adapters are at OS/file/process boundaries and retain real cleanup effects. +""" +import ast +import contextlib +import hashlib +import json +import os +from pathlib import Path +import re +import shlex +import signal +import subprocess +import sys +import tempfile +import textwrap +import time +import unittest +from unittest.mock import patch + +PROJECT_ROOT = Path(__file__).resolve().parents[1] +HARNESS_DIR = PROJECT_ROOT / 'tests/fixtures/site_transition_capture_regression_20261025' +BASELINE_WORKFLOW = HARNESS_DIR / 'baseline-current-site-transition-candidate.yml.txt' +DEFAULT_WORKFLOW = PROJECT_ROOT / '.github/workflows/current-site-transition-candidate.yml' +WORKFLOW = Path(os.environ.get('INLINE_WRAPPER_WORKFLOW', str(DEFAULT_WORKFLOW))) +CAPTURE_OBSERVER = globals().get('__capture_observer__') +CAPTURE_CONTRACT = globals().get('__capture_contract__') +REAL_POPEN = subprocess.Popen +REAL_KILLPG = os.killpg +REAL_OS_OPEN = os.open +REAL_WRITE_BYTES = Path.write_bytes +REAL_WRITE_TEXT = Path.write_text +REAL_MONOTONIC = time.monotonic + + +def blocks(workflow=WORKFLOW): + raw = workflow.read_text() + # The durable workflow also contains the independent regression job. Only + # the actual core job supplies these four code-under-test stdin bodies. + jobs = list(re.finditer(r'^ frozen-reader-transition-candidate:\n(.*?)(?=^ [A-Za-z0-9_-]+:|\Z)', + raw, re.M | re.S)) + if len(jobs) != 1: + raise AssertionError('Expected one actual frozen core job') + result = {} + for match in re.finditer(r"^ (python3[^\n]+) <<'(PY[A-Z]+)'\n(.*?)^ \2$", jobs[0].group(1), re.M | re.S): + result[match.group(2)] = (shlex.split(match.group(1)), textwrap.dedent(match.group(3))) + if set(result) != {'PYCONTEXT', 'PYGUARD', 'PYNODE', 'PYEMIT'}: + raise AssertionError('Expected all four real workflow stdin bodies') + return result + + + +def case_id(test): + identity = test.id() + prefix = '__main__.' + if not identity.startswith(prefix): + raise ValueError('HOLD_RUNTIME_CASE_ID') + return identity[len(prefix):] + + +def compact_state(context): + if type(context) is not dict: + raise ValueError('HOLD_CONTEXT_OBSERVATION_TYPE') + return {name: context.get(name) for name in ( + 'node_phase', 'capture_status', 'immutable_source_recheck', + 'node_returncode', 'capture_cleanup_diagnostics')} + + +def emit_observation(kind, **values): + if not callable(CAPTURE_OBSERVER): + raise ValueError('HOLD_AUTHENTICATED_LAUNCHER_REQUIRED') + # The authenticated launcher enforces the complete event schema/4096-byte + # row and 64KiB stream bounds. No expected outcome is inserted here. + CAPTURE_OBSERVER(kind, **values) + + +class InlineCaptureTests(unittest.TestCase): + def run_case(self, scenario): + # Independent hand-built source ledger; the production recheck must read it. + with tempfile.TemporaryDirectory(prefix='inline-wrapper-focused-') as temporary: + root = Path(temporary) + output = root / 'runner/current-site-transition-candidate' + output.mkdir(parents=True) + entries = json.loads((HARNESS_DIR / 'ledger.json').read_bytes()) + self.assertEqual(len(entries), 16) + for entry in entries: + path = root / entry['path'] + path.parent.mkdir(exist_ok=True) + data = (HARNESS_DIR / entry['path']).read_bytes() + self.assertEqual((len(data), hashlib.sha256(data).hexdigest()), (entry['bytes'], entry['sha256'])) + path.write_bytes(data) + initial = { + 'schema_version': 1, 'scientific_effect': 'NONE', + 'candidate_source_guard': 'passed', 'node_phase': 'not_started', + 'immutable_source_recheck': 'pending', 'immutable_source_inputs': entries, + 'node_version': {'status': 'OK'}, 'python_command_version': {'status': 'OK'}, + 'event_name': 'pull_request', 'pull_request_head_sha': '1' * 40, + 'pull_request_base_sha': '2' * 40, + } + context_path = output / 'context.json' + context_path.write_text(json.dumps(initial)) + for name in ['tap.stdout.tap', 'tap.stderr.txt']: + (output / name).write_bytes(b'') + (output / 'node-exit-code.txt').write_text('NOT_RUN\n') + source = blocks()['PYNODE'][1] + # Only parse/compile the acquired actual body; no copied wrapper algorithm. + code = compile(ast.parse(source, filename=str(WORKFLOW) + ':PYNODE'), str(WORKFLOW) + ':PYNODE', 'exec') + children, source_opens, save_attempts = [], [], [] + launch_attempts, source_phase_counts = [0], [0, 0] + child_name = {'nonzero': 'nonzero', 'timeout': 'timeout', + 'outputcap': 'outputcap', 'missingcapture': 'missingcapture', + 'sourcechange': 'sourcechange', 'capturefifo': 'capturefifo', + 'capturedirectory': 'capturedirectory', 'capturesymlink': 'capturesymlink', + 'capturehardlink': 'capturehardlink', 'sourcefifo': 'sourcefifo'}.get(scenario, 'success') + child_script = (HARNESS_DIR / 'children' / (child_name + '.py')).read_text() + + def launch(command, **kwargs): + launch_attempts[0] += 1 + if command != ['node', '--test', '--test-reporter=tap', 'tests/test_current_site_transition.mjs']: + raise AssertionError('Unexpected production child command') + if scenario == 'setupfailure': + raise OSError('injected spawn failure') + child = REAL_POPEN([sys.executable, '-I', '-B', '-S', '-c', child_script], **kwargs) + children.append(child) + if scenario == 'reapfailure': + real_wait = child.wait + def failed_wait(timeout=None): + real_wait(timeout=timeout) + raise subprocess.TimeoutExpired(command, timeout) + child.wait = failed_wait + return child + + def kill_group(pid, sig): + try: + REAL_KILLPG(pid, sig) + except ProcessLookupError: + if scenario not in ['killfailure', 'cleanupinterrupt']: + raise + if scenario == 'killfailure': + raise PermissionError('injected kill diagnostic after actual cleanup') + if scenario == 'cleanupinterrupt': + raise KeyboardInterrupt('injected interruption after actual cleanup') + + def open_source(path, *args, **kwargs): + if scenario == 'unreadablecapture' and Path(path).name == 'tap.stderr.txt' and args and args[0] & os.O_NONBLOCK: + raise PermissionError('injected unreadable descriptor capture') + if path == '.': + source_opens.append(path) + source_phase_counts[bool(launch_attempts[0])] += 1 + return REAL_OS_OPEN(path, *args, **kwargs) + + def save_bytes(path, data): + if path == context_path: + save_attempts.append(json.loads(data)) + if scenario == 'contextsavefailure' and len(save_attempts) == 2: + raise PermissionError('injected final context write failure') + return REAL_WRITE_BYTES(path, data) + + def write_text(path, data, *args, **kwargs): + if scenario == 'exitwritefailure' and path.name == 'node-exit-code.txt': + raise PermissionError('injected integer exit-file write failure') + return REAL_WRITE_TEXT(path, data, *args, **kwargs) + + clock_calls = [0] + def monotonic(): + if scenario == 'timeout': + clock_calls[0] += 1 + return 100.0 * (clock_calls[0] - 1) + return REAL_MONOTONIC() + + previous = Path.cwd() + caught = None + began = REAL_MONOTONIC() + try: + os.chdir(root) + with contextlib.ExitStack() as stack: + stack.enter_context(patch.dict(os.environ, {'RUNNER_TEMP': str(root / 'runner')})) + stack.enter_context(patch('subprocess.Popen', launch)) + stack.enter_context(patch('os.killpg', kill_group)) + stack.enter_context(patch('os.open', open_source)) + stack.enter_context(patch.object(Path, 'write_bytes', save_bytes)) + stack.enter_context(patch.object(Path, 'write_text', write_text)) + stack.enter_context(patch('time.monotonic', monotonic)) + try: + exec(code, {'__name__': '__main__'}) + except BaseException as error: + caught = error + finally: + os.chdir(previous) + # Harness-only safety cleanup still delegates to actual OS/process methods. + for child in children: + try: REAL_KILLPG(child.pid, signal.SIGKILL) + except ProcessLookupError: pass + subprocess.Popen.wait(child, timeout=5) + # Observe the actual failed/successful wrapper path BEFORE assertions. + # This records attempted writes separately from physically stored context. + context_read_error, witness_stored = None, None + try: + witness_stored = json.loads(context_path.read_bytes()) + except Exception as error: + context_read_error = type(error).__name__ + attempt = save_attempts[-1] if save_attempts else {} + emit_observation('CASE_WITNESS', case_id=case_id(self), scenario=scenario, + caught_type=type(caught).__name__ if caught is not None else None, + caught_exit=caught.code if isinstance(caught, SystemExit) and type(caught.code) is int else None, + pre_source_opens=source_phase_counts[0], post_source_opens=source_phase_counts[1], + total_source_opens=len(source_opens), + save_attempts=[compact_state(value) for value in save_attempts], + stored=compact_state(witness_stored) if witness_stored is not None else None, + capture_errors=attempt.get('capture_errors', []), + cleanup_errors=attempt.get('cleanup_errors', []), + stdout_missing=not (output / 'tap.stdout.tap').exists(), + child_count=len(children), elapsed_seconds=round(REAL_MONOTONIC() - began, 6), + context_read_error=context_read_error) + self.assertLess(REAL_MONOTONIC() - began, 12, 'Focused case exceeded its safety budget') + self.assertGreaterEqual(len(source_opens), 17, 'Actual post-child source read was skipped') + self.assertEqual(len(save_attempts), 2, 'Starting and outer-finally context writes must both be attempted') + final_attempt = save_attempts[-1] + self.assertIn(final_attempt['immutable_source_recheck'], ['passed', 'failed']) + stored = json.loads(context_path.read_bytes()) + files = {name: (output / name).read_bytes() for name in ['node-exit-code.txt']} + return caught, final_attempt, stored, files + + def test_success_preserves_integer_zero_and_complete_capture(self): + # Break caught: cleanup/custody diagnostics turn a real successful capture into HOLD. + error, context, _, files = self.run_case('success') + self.assertIsInstance(error, SystemExit) + self.assertEqual(error.code, 0) + self.assertEqual(context['capture_status'], 'COMPLETED') + self.assertEqual(context['node_returncode'], 0) + self.assertEqual(files['node-exit-code.txt'], b'0\n') + self.assertEqual(context['immutable_source_recheck'], 'passed') + + def test_nonzero_retains_child_failure_and_still_attempts_custody(self): + # Break caught: nonzero child exit is mislabeled as successful test evidence or lost. + error, context, _, files = self.run_case('nonzero') + self.assertEqual(error.code, 7) + self.assertEqual(context['capture_status'], 'COMPLETED') + self.assertEqual(context['node_returncode'], 7) + self.assertEqual(files['node-exit-code.txt'], b'7\n') + + def test_timeout_remains_hold_after_outer_custody(self): + error, context, _, _ = self.run_case('timeout') + self.assertEqual(error.code, 1) + self.assertEqual(context['capture_status'], 'TIMEOUT') + self.assertEqual(context['node_capture_outcome'], 'TIMEOUT') + + def test_output_cap_remains_hold_after_outer_custody(self): + error, context, _, _ = self.run_case('outputcap') + self.assertEqual(error.code, 1) + self.assertEqual(context['capture_status'], 'REFUSED_OUTPUT_LIMIT') + + def test_missing_tap_does_not_skip_source_recheck_or_context_attempt(self): + # Direct regression for reviewed P2-2: old final stat raises before recheck/save. + _, context, _, _ = self.run_case('missingcapture') + self.assertEqual(context['capture_status'], 'REFUSED_CAPTURE') + self.assertTrue(any(row['operation'].startswith('capture:') and row['error'] == 'FileNotFoundError' for row in context['capture_errors'])) + + def test_unreadable_tap_is_recorded_and_keeps_hold(self): + _, context, _, _ = self.run_case('unreadablecapture') + self.assertEqual(context['capture_status'], 'REFUSED_CAPTURE') + self.assertTrue(any(row['operation'] == 'capture:tap.stderr.txt' and row['error'] == 'PermissionError' for row in context['capture_errors'])) + + def test_exit_file_failure_does_not_skip_outer_custody(self): + _, context, _, files = self.run_case('exitwritefailure') + self.assertEqual(context['capture_status'], 'REFUSED_CAPTURE') + self.assertEqual(context['node_returncode'], 0) + self.assertEqual(files['node-exit-code.txt'], b'NOT_RUN\n') + self.assertIn({'operation': 'exit_write', 'error': 'PermissionError'}, context['capture_errors']) + + def test_kill_error_is_separate_cleanup_hold(self): + _, context, _, _ = self.run_case('killfailure') + self.assertEqual(context['capture_status'], 'REFUSED_CLEANUP') + self.assertIn({'operation': 'killpg', 'error': 'PermissionError'}, context['cleanup_errors']) + + def test_reap_error_is_separate_cleanup_hold(self): + _, context, _, _ = self.run_case('reapfailure') + self.assertEqual(context['capture_status'], 'REFUSED_REAP') + self.assertIn({'operation': 'wait', 'error': 'TimeoutExpired'}, context['cleanup_errors']) + + def test_interrupted_cleanup_never_claims_confirmed_completion(self): + error, context, _, _ = self.run_case('cleanupinterrupt') + self.assertIsInstance(error, KeyboardInterrupt) + self.assertEqual(context['capture_status'], 'REFUSED_CLEANUP') + self.assertEqual(context['capture_cleanup_diagnostics'], 'incomplete') + + def test_source_change_refuses_even_after_completed_child(self): + _, context, _, _ = self.run_case('sourcechange') + self.assertEqual(context['capture_status'], 'REFUSED_SOURCE_CHANGED') + self.assertEqual(context['immutable_source_recheck'], 'failed') + self.assertEqual(context['node_capture_outcome'], 'COMPLETED') + + def test_spawn_setup_failure_never_becomes_completed(self): + _, context, _, _ = self.run_case('setupfailure') + self.assertEqual(context['capture_status'], 'REFUSED_SETUP') + self.assertEqual(context['node_phase'], 'not_started') + self.assertIn({'operation': 'capture', 'error': 'OSError'}, context['capture_errors']) + + def test_final_context_write_failure_is_attempted_and_propagated(self): + error, attempted, stored, _ = self.run_case('contextsavefailure') + self.assertIsInstance(error, PermissionError) + self.assertEqual(attempted['immutable_source_recheck'], 'passed') + self.assertEqual(stored['capture_status'], 'NOT_RUN') + self.assertEqual(stored['node_phase'], 'starting') + + def test_fifo_capture_refuses_without_blocking_and_attempts_custody(self): + # Break caught: a replaced FIFO blocks a pathname open before outer-finally custody. + error, context, _, _ = self.run_case('capturefifo') + self.assertEqual(error.code, 1) + self.assertEqual(context['capture_status'], 'REFUSED_CAPTURE') + self.assertEqual(context['immutable_source_recheck'], 'passed') + self.assertTrue(any(row['operation'] == 'capture:tap.stdout.tap' for row in context['capture_errors'])) + + def test_directory_capture_refuses_and_attempts_custody(self): + _, context, _, _ = self.run_case('capturedirectory') + self.assertEqual(context['capture_status'], 'REFUSED_CAPTURE') + self.assertEqual(context['immutable_source_recheck'], 'passed') + + def test_symlink_capture_refuses_and_attempts_custody(self): + _, context, _, _ = self.run_case('capturesymlink') + self.assertEqual(context['capture_status'], 'REFUSED_CAPTURE') + self.assertEqual(context['immutable_source_recheck'], 'passed') + + def test_hardlinked_capture_refuses_without_touching_source_ledger(self): + _, context, _, _ = self.run_case('capturehardlink') + self.assertEqual(context['capture_status'], 'REFUSED_CAPTURE') + self.assertEqual(context['immutable_source_recheck'], 'passed') + + def test_source_input_fifo_refuses_without_blocking_and_attempts_context(self): + # Break caught: recheck_sources blocks opening FIFO before its regular-file fstat. + error, context, _, _ = self.run_case('sourcefifo') + self.assertEqual(error.code, 1) + self.assertEqual(context['capture_status'], 'REFUSED_SOURCE_CHANGED') + self.assertEqual(context['immutable_source_recheck'], 'failed') + self.assertEqual(context['immutable_source_recheck_error'], 'ValueError') + + def test_real_stdin_entrypoints_exclude_cwd_and_pythonpath_shadow(self): + # Break caught: removing isolation admits an actual hostile root/PYTHONPATH import. + with tempfile.TemporaryDirectory(prefix='inline-isolation-focused-') as temporary: + root = Path(temporary) + for module in ['hashlib', 'json', 'pathlib', 'selectors', 'base64']: + (root / (module + '.py')).write_bytes((HARNESS_DIR / 'shadow' / (module + '.py')).read_bytes()) + probe = (HARNESS_DIR / 'isolation_probe.py').read_text() + for name, (arguments, _) in blocks().items(): + with self.subTest(block=name): + result = subprocess.run(arguments, input=probe.encode(), cwd=root, + env={**os.environ, 'PYTHONPATH': str(root)}, capture_output=True, timeout=5) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout, b'STDLIB_BOUNDARY_OK\n') + + + def test_actual_baseline_emitter_imports_shadow_and_candidate_emitter_holds_without_it(self): + # Causal P2-1 control: actual pre-fix body admits shadow before its qualification; + # actual isolated candidate reaches its real pending-context HOLD without marker. + with tempfile.TemporaryDirectory(prefix='inline-import-causal-') as temporary: + root = Path(temporary) + output = root / 'runner/current-site-transition-candidate' + output.mkdir(parents=True) + (root / 'hashlib.py').write_bytes((HARNESS_DIR / 'shadow/hashlib.py').read_bytes()) + (output / 'context.json').write_text(json.dumps({ + 'schema_version': 1, 'candidate_source_guard': 'not_started', + 'composition_binding': 'PENDING_FINAL_CANONICAL_COMPOSITION', + 'node_phase': 'not_started', 'immutable_source_recheck': 'pending'})) + for name in ['tap.stdout.tap', 'tap.stderr.txt']: + (output / name).write_bytes(b'') + (output / 'node-exit-code.txt').write_text('NOT_RUN\n') + environment = {**os.environ, 'PYTHONPATH': str(root), + 'RUNNER_TEMP': str(root / 'runner'), 'GITHUB_OUTPUT': str(root / 'github-output')} + old_argv, old_body = blocks(BASELINE_WORKFLOW)['PYEMIT'] + old = subprocess.run(old_argv, input=old_body.encode(), cwd=root, + env=environment, capture_output=True, timeout=5) + self.assertEqual(old.returncode, 1) + self.assertIn(b'unqualified shadow imported', old.stderr) + marker = root / '.import-shadow-marker' + self.assertEqual(marker.read_bytes(), b'SHADOW_IMPORT\n') + marker.unlink() + new_argv, new_body = blocks()['PYEMIT'] + new = subprocess.run(new_argv, input=new_body.encode(), cwd=root, + env=environment, capture_output=True, timeout=5) + self.assertEqual(new.returncode, 1) + self.assertFalse(marker.exists()) + self.assertIn(b'classification=HOLD', new.stdout) + self.assertEqual(new.stdout.count(b'CS_TRANSITION_FILE_BEGIN '), 4) + self.assertEqual(new.stderr, b'') + + +class ObservedTextResult(unittest.TextTestResult): + """Actual unittest callbacks, with full originals left in stderr.""" + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.observed_order = [] + self.observed_ends = [] + self.observed_subtests = 0 + self._terminal = {} + + def startTest(self, test): + super().startTest(test) + identity = case_id(test) + self.observed_order.append(identity) + emit_observation('CASE_BEGIN', case_id=identity, runtime_id=test.id()) + + def _outcome(self, test, status, error=None, formatted=None, message=''): + identity = case_id(test) + prior = self._terminal.get(identity) + if prior is not None and prior['status'] in ('FAIL', 'ERROR') and status == 'PASS': + return + raw = formatted.encode('utf-8') if formatted is not None else b'' + self._terminal[identity] = { + 'case_id': identity, 'runtime_id': test.id(), 'status': status, + 'exception_type': error[0].__name__ if error is not None else None, + 'message': (str(error[1]) if error is not None else message)[:512], + 'traceback_bytes': len(raw), + 'traceback_sha256': hashlib.sha256(raw).hexdigest() if formatted is not None else None, + } + + def addSuccess(self, test): + super().addSuccess(test) + self._outcome(test, 'PASS') + + def addFailure(self, test, err): + super().addFailure(test, err) + self._outcome(test, 'FAIL', err, self.failures[-1][1]) + + def addError(self, test, err): + super().addError(test, err) + self._outcome(test, 'ERROR', err, self.errors[-1][1]) + + def addSkip(self, test, reason): + super().addSkip(test, reason) + self._outcome(test, 'SKIP', message=str(reason)) + + def addExpectedFailure(self, test, err): + super().addExpectedFailure(test, err) + self._outcome(test, 'EXPECTED_FAILURE', err, self.expectedFailures[-1][1]) + + def addUnexpectedSuccess(self, test): + super().addUnexpectedSuccess(test) + self._outcome(test, 'UNEXPECTED_SUCCESS') + + def addSubTest(self, test, subtest, err): + super().addSubTest(test, subtest, err) + status = 'PASS' if err is None else 'FAIL' if issubclass(err[0], test.failureException) else 'ERROR' + self.observed_subtests += 1 + emit_observation('CASE_SUBTEST', case_id=case_id(test), + subtest_id=str(subtest)[:512], status=status, + exception_type=err[0].__name__ if err is not None else None, + message=str(err[1])[:512] if err is not None else '') + if err is not None: + formatted = self.failures[-1][1] if status == 'FAIL' else self.errors[-1][1] + self._outcome(test, status, err, formatted) + + def stopTest(self, test): + identity = case_id(test) + if identity not in self._terminal: + raise ValueError('HOLD_MISSING_ACTUAL_CASE_OUTCOME') + row = self._terminal.pop(identity) + self.observed_ends.append(row) + emit_observation('CASE_END', **row) + super().stopTest(test) + + +def main(): + # This file has no standalone/ambient wrapper-selection route. Only the + # authenticated fixed launcher supplies its contract and event callback. + if sys.platform != 'linux' or type(CAPTURE_CONTRACT) is not dict or not callable(CAPTURE_OBSERVER): + raise ValueError('HOLD_SUPPORTED_AUTHENTICATED_LAUNCHER_REQUIRED') + contract = CAPTURE_CONTRACT + if contract.get('status') != 'ROOT_FROZEN_EXECUTION_CONTRACT': + raise ValueError('HOLD_PENDING_EXECUTION_CONTRACT') + selection = os.environ.get('SITE_CAPTURE_SELECTION') + if selection not in ('baseline', 'candidate'): + raise ValueError('HOLD_FIXED_SELECTION_REQUIRED') + expected_workflow = BASELINE_WORKFLOW if selection == 'baseline' else DEFAULT_WORKFLOW + if WORKFLOW != expected_workflow or str(WORKFLOW) != contract['workflows'][selection]['path']: + raise ValueError('HOLD_WORKFLOW_OVERRIDE') + if Path.cwd() != PROJECT_ROOT or str(PROJECT_ROOT) != contract['cwd']: + raise ValueError('HOLD_ACTUAL_HARNESS_CWD') + if str(Path(__file__).resolve()) != contract['harness']['path']: + raise ValueError('HOLD_ACTUAL_HARNESS_SOURCE_PATH') + actual_candidate = sorted('InlineCaptureTests.' + name for name, value in InlineCaptureTests.__dict__.items() + if name.startswith('test_') and callable(value)) + baseline = ['InlineCaptureTests.test_missing_tap_does_not_skip_source_recheck_or_context_attempt'] + if contract['selectors']['candidate'] != actual_candidate or contract['selectors']['baseline'] != baseline: + raise ValueError('HOLD_EXACT_SELECTOR_CENSUS') + selectors = contract['selectors'][selection] + if sys.argv[1:] != selectors or len(actual_candidate) != 20: + raise ValueError('HOLD_EXPLICIT_CANONICAL_SELECTOR_ORDER') + suite = unittest.defaultTestLoader.loadTestsFromNames(selectors, module=sys.modules[__name__]) + if suite.countTestCases() != len(selectors): + raise ValueError('HOLD_ACTUAL_CASE_COUNT') + result = unittest.TextTestRunner(stream=sys.stderr, verbosity=2, resultclass=ObservedTextResult).run(suite) + counts = {status: sum(row['status'] == status for row in result.observed_ends) + for status in ('PASS', 'FAIL', 'ERROR', 'SKIP', 'EXPECTED_FAILURE', 'UNEXPECTED_SUCCESS')} + emit_observation('HARNESS_RESULT', tests_run=result.testsRun, passed=counts['PASS'], + failed=counts['FAIL'], errors=counts['ERROR'], skipped=counts['SKIP'], + expected_failures=counts['EXPECTED_FAILURE'], unexpected_successes=counts['UNEXPECTED_SUCCESS'], + ordered_cases=result.observed_order, subtests=result.observed_subtests) + return 0 if result.wasSuccessful() else 1 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tools/site_transition_capture_regression_launcher.py b/tools/site_transition_capture_regression_launcher.py new file mode 100644 index 000000000..becef2ced --- /dev/null +++ b/tools/site_transition_capture_regression_launcher.py @@ -0,0 +1,170 @@ +"""Source-only closed-harness launcher. NOT_RUN; requires a Root-frozen contract.""" +import argparse +import hashlib +import io +import json +import os +from pathlib import Path +import signal +import stat +import subprocess +import sys +import time +import types + +REAL_POPEN = subprocess.Popen +REAL_MONOTONIC = time.monotonic +TRACE_LIMIT = 65536 +TRACE_ROW_CAP = 4096 + + +def packed(value): + return (json.dumps(value,sort_keys=True,separators=(',',':'))+'\n').encode('ascii') + + +def checked(entry, maximum=2097152): + path=Path(entry['path']) + if not path.is_absolute() or path.resolve()!=path: + raise ValueError('Physical absolute Source path required') + fd=os.open(path,os.O_RDONLY|os.O_NOFOLLOW|os.O_NONBLOCK) + try: + a=os.fstat(fd) + if not stat.S_ISREG(a.st_mode) or a.st_nlink!=1 or not 0<=a.st_size<=maximum: + raise ValueError('Unsafe Source') + raw=b'' + while len(raw)<=maximum: + part=os.read(fd,min(65536,maximum+1-len(raw))) + if not part:break + raw+=part + b=os.fstat(fd) + shape=lambda s:(s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + if shape(a)!=shape(b) or len(raw)!=entry['bytes'] or hashlib.sha256(raw).hexdigest()!=entry['sha256']: + raise ValueError('Source identity mismatch') + return raw + finally:os.close(fd) + + +def proc_identity(pid): + with open('/proc/%d/stat'%pid,'rb') as stream:raw=stream.read(4097) + if len(raw)>4096:raise ValueError('Process identity cap') + fields=raw.rsplit(b')',1)[1].split() + return {'pid':pid,'ppid':int(fields[1]),'pgid':int(fields[2]),'start_ticks':int(fields[19])} + + +def validate_launch_cwd(contract,observed_cwd=None): + """Record an actual physical execution cwd, never the contract label alone.""" + expected=contract['cwd'] + if type(expected) is not str:raise ValueError('Frozen cwd type') + path=Path(expected) + if not path.is_absolute() or path.resolve()!=path or not path.is_dir(): + raise ValueError('Physical frozen cwd required') + observed=os.getcwd() if observed_cwd is None else observed_cwd + if type(observed) is not str or observed!=expected or str(Path(observed).resolve())!=observed: + raise ValueError('Observed launch cwd mismatch') + return observed + + +def main(): + parser=argparse.ArgumentParser(description=__doc__) + parser.add_argument('--contract',required=True,type=Path) + parser.add_argument('--contract-sha256',required=True) + parser.add_argument('--selection',required=True,choices=['baseline','candidate']) + parser.add_argument('--trace',required=True,type=Path) + args=parser.parse_args() + descriptor=os.open(args.contract,os.O_RDONLY|os.O_NOFOLLOW|os.O_NONBLOCK) + try: + info=os.fstat(descriptor) + if not stat.S_ISREG(info.st_mode) or info.st_nlink!=1 or info.st_size>65536: + raise ValueError('Contract shape') + raw=os.read(descriptor,65537) + if len(raw)!=info.st_size:raise ValueError('Contract short read') + finally:os.close(descriptor) + if len(raw)>65536 or hashlib.sha256(raw).hexdigest()!=args.contract_sha256: + raise ValueError('Contract identity') + contract=json.loads(raw) + if contract['status']!='ROOT_FROZEN_EXECUTION_CONTRACT' or sys.platform!='linux': + raise ValueError('PENDING or unsupported platform') + observed_cwd=validate_launch_cwd(contract) + signal.signal(signal.SIGCHLD,signal.SIG_DFL) + captured={entry['path']:checked(entry) for entry in contract['closure']} + manifest=json.loads(captured[contract['source_manifest']['path']]) + if manifest.get('status')!='ROOT_FROZEN_FINAL_CANONICAL_COMPOSITION': + raise ValueError('PENDING Source manifest') + harness=captured[contract['harness']['path']] + workflow=contract['workflows'][args.selection] + if captured[workflow['path']]!=checked(workflow):raise ValueError('Workflow capture join') + checked(contract['source_seal']) + trace=os.open(args.trace,os.O_WRONLY|os.O_APPEND|os.O_NOFOLLOW|os.O_NONBLOCK) + info=os.fstat(trace) + if not stat.S_ISREG(info.st_mode) or info.st_nlink!=1:raise ValueError('Unsafe trace') + serial=[0] + def event(kind,**values): + row=packed({'kind':kind,'sequence':serial[0],'monotonic':REAL_MONOTONIC(),**values}) + serial[0]+=1 + if len(row)>TRACE_ROW_CAP or os.fstat(trace).st_size+len(row)>TRACE_LIMIT: + raise ValueError('Trace cap') + if os.write(trace,row)!=len(row):raise ValueError('Partial trace') + allowed=set(contract['allowed_child_argv_sha256']) + class ObservedPopen(REAL_POPEN): + # Class inheritance preserves Popen.wait(child,...), context-manager, + # communicate/poll and intentional instance-level wait fault adapters. + def __init__(self,*values,**kwargs): + command=values[0] if values else kwargs.get('args') + if not isinstance(command,(list,tuple)) or not all(type(x) is str for x in command): + raise ValueError('Closed argv required') + argv_sha=hashlib.sha256(packed(list(command))).hexdigest() + if argv_sha not in allowed or kwargs.get('shell',False) or kwargs.get('executable') is not None: + raise ValueError('Unqualified child argv') + token=serial[0] + actual_argv=list(command) + event('SPAWN_BEGIN',token=token,argv=actual_argv,argv_sha256=argv_sha) + try: + super().__init__(*values,**kwargs) + event('SPAWNED',token=token,argv=actual_argv,argv_sha256=argv_sha,**proc_identity(self.pid)) + except BaseException as error: + event('SPAWN_FAILED',token=token,error=type(error).__name__) + raise + # Frozen executable bodies must not be hash-then-path-reread. The closed + # harness reads workflow/child/probe/shadow bodies only through these two + # Path methods. Mutable owned case files continue through real methods. + real_read_bytes=Path.read_bytes + real_read_text=Path.read_text + def captured_bytes(path): + body=captured.get(str(path)) + return body if body is not None else real_read_bytes(path) + def captured_text(path,encoding=None,errors=None): + body=captured.get(str(path)) + if body is None:return real_read_text(path,encoding=encoding,errors=errors) + with io.TextIOWrapper(io.BytesIO(body),encoding=encoding,errors=errors) as stream: + return stream.read() + Path.read_bytes=captured_bytes + Path.read_text=captured_text + subprocess.Popen=ObservedPopen + event('LAUNCHER_BEGIN',observed_cwd=observed_cwd,**proc_identity(os.getpid())) + os.environ.pop('PYTHONPATH',None) + os.environ['INLINE_WRAPPER_WORKFLOW']=workflow['path'] + os.environ['SITE_CAPTURE_SELECTION']=args.selection + selectors=contract['selectors'][args.selection] + sys.argv=[contract['harness']['path'],*selectors] + module=types.ModuleType('__main__') + module.__dict__.update(__file__=contract['harness']['path'],__package__=None,__spec__=None, + __builtins__=__builtins__,__capture_observer__=event, + __capture_contract__=contract) + # unittest.main discovers sys.modules['__main__']; an anonymous exec dict + # would silently discover zero harness tests. + sys.modules['__main__']=module + namespace=module.__dict__ + code=2 + try: + # Authenticated captured bytes, not a later mutable-path runpy import. + exec(compile(harness,contract['harness']['path'],'exec'),namespace) + code=0 + except SystemExit as error: + code=error.code if type(error.code) is int else 0 if error.code is None else 1 + finally: + try:event('HARNESS_END',exit_code=code) + finally:os.close(trace) + return code + + +if __name__=='__main__':raise SystemExit(main()) diff --git a/tools/site_transition_capture_regression_supervisor.py b/tools/site_transition_capture_regression_supervisor.py new file mode 100644 index 000000000..cc327a4b8 --- /dev/null +++ b/tools/site_transition_capture_regression_supervisor.py @@ -0,0 +1,727 @@ +"""Source-only closed inline-harness watchdog; Linux containment only, NOT_RUN. + +Darwin intentionally refuses before launch: PS identity-then-kill is not atomic. +No arbitrary command API. Root must freeze/review all contract/Source first. +""" +import argparse +import ast +import ctypes +import hashlib +import json +import math +import os +from pathlib import Path +import re +import resource +import shlex +import signal +import stat +import sys +import time + +CAP=1048576 +TRACE_CAP=65536 +BASELINE='InlineCaptureTests.test_missing_tap_does_not_skip_source_recheck_or_context_attempt' +FIXTURE_ROOT='tests/fixtures/site_transition_capture_regression_20261025' +FROZEN_MANIFEST='ROOT_FROZEN_FINAL_CANONICAL_COMPOSITION' +TRACE_ROW_CAP=4096 +MEMBER_PATHS=tuple(sorted([ + 'tools/site_transition_capture_regression.py', + 'tools/site_transition_capture_regression_supervisor.py', + 'tools/site_transition_capture_regression_launcher.py', + *[FIXTURE_ROOT+'/inputs/member-%02d.txt'%number for number in range(16)], + *[FIXTURE_ROOT+'/children/'+name+'.py' for name in ('capturedirectory','capturefifo','capturehardlink','capturesymlink','missingcapture','nonzero','outputcap','sourcechange','sourcefifo','success','timeout')], + *[FIXTURE_ROOT+'/shadow/'+name+'.py' for name in ('base64','hashlib','json','pathlib','selectors')], + FIXTURE_ROOT+'/ledger.json',FIXTURE_ROOT+'/isolation_probe.py', + FIXTURE_ROOT+'/baseline-current-site-transition-candidate.yml.txt', +])) + + +def packed(value):return (json.dumps(value,sort_keys=True,indent=2)+'\n').encode('ascii') + + +def compact(value):return (json.dumps(value,sort_keys=True,separators=(',',':'))+'\n').encode('ascii') + + +def unique_object(pairs): + result={} + for key,value in pairs: + if key in result:raise ValueError('Duplicate JSON key') + result[key]=value + return result + + +def json_value(raw):return json.loads(raw,object_pairs_hook=unique_object) + + +def exact_keys(value,keys,label): + if type(value) is not dict or set(value)!=set(keys):raise ValueError(label+' schema') + + +def text_value(value,maximum=512): + return type(value) is str and len(value)<=maximum + + +def integer(value,minimum=0):return type(value) is int and value>=minimum + + +def finite_number(value): + return type(value) in (int,float) and math.isfinite(value) and value>=0 + + +def digest(value,length=64): + return type(value) is str and len(value)==length and all(c in '0123456789abcdef' for c in value) + + +def physical_root(contract): + value=contract['cwd'] + if type(value) is not str:raise ValueError('Physical frozen cwd type') + root=Path(value) + if not root.is_absolute() or root.resolve()!=root or not root.is_dir(): + raise ValueError('Physical frozen cwd required') + return root + + +def validate_launch_cwd(contract,observed_cwd=None): + """Check observed execution cwd; this function does not change directories.""" + expected=str(physical_root(contract)) + observed=os.getcwd() if observed_cwd is None else observed_cwd + if type(observed) is not str or observed!=expected: + raise ValueError('Observed launch cwd mismatch') + if str(Path(observed).resolve())!=observed:raise ValueError('Observed cwd is not physical') + return observed + + +def manifest_row(row,root): + exact_keys(row,('path','bytes','sha256','git_blob','role'),'Manifest row') + relative=Path(row['path']) if type(row['path']) is str else None + if relative is None or relative.is_absolute() or not relative.parts or '..' in relative.parts or str(relative)!=row['path']: + raise ValueError('Manifest relative path') + if not integer(row['bytes']) or not digest(row['sha256']) or not digest(row['git_blob'],40) or not text_value(row['role'],128): + raise ValueError('Pending or malformed manifest row') + path=root/relative + if path.resolve()!=path:raise ValueError('Nonphysical manifest member') + return {'path':str(path),'bytes':row['bytes'],'sha256':row['sha256']} + + +def closed_sources(contract): + """Authenticate only the explicit durable manifest, never a recursive tree.""" + root=physical_root(contract);fixture=root/FIXTURE_ROOT + if contract['regression_root']!=str(fixture):raise ValueError('Physical regression root') + expected_paths={ + 'harness':root/'tools/site_transition_capture_regression.py', + 'supervisor_source':root/'tools/site_transition_capture_regression_supervisor.py', + 'launcher_source':root/'tools/site_transition_capture_regression_launcher.py', + 'source_manifest':fixture/'source-fixture-manifest.json', + } + for label,path in expected_paths.items(): + if contract[label]['path']!=str(path):raise ValueError('Durable Source layout') + if contract['workflows']['baseline']['path']!=str(fixture/'baseline-current-site-transition-candidate.yml.txt') or contract['workflows']['candidate']['path']!=str(root/'.github/workflows/current-site-transition-candidate.yml'): + raise ValueError('Durable workflow layout') + manifest=json_value(checked(contract['source_manifest'])) + exact_keys(manifest,('schema_version','status','fixture_root','members','external_inputs','selectors'),'Manifest') + if type(manifest['schema_version']) is not int or manifest['schema_version']!=1 or manifest['status']!=FROZEN_MANIFEST: + raise ValueError('PENDING Source manifest') + if manifest['fixture_root']!=FIXTURE_ROOT or manifest['selectors']!=contract['selectors']: + raise ValueError('Manifest root/selector join') + if type(manifest['members']) is not list or len(manifest['members'])!=38: + raise ValueError('Exact 38 Source members') + if sorted(row['path'] for row in manifest['members'])!=list(MEMBER_PATHS): + raise ValueError('Exact durable member path census') + external=manifest['external_inputs'] + exact_keys(external,('guard','final_freeze'),'External Source inputs') + rows=[*manifest['members'],external['guard'],external['final_freeze']] + entries=[manifest_row(row,root) for row in rows] + entries.extend([contract['source_manifest'],contract['workflows']['candidate']]) + if len({entry['path'] for entry in entries})!=42:raise ValueError('Duplicate durable closure') + closure=contract['closure'] + if type(closure) is not list or len(closure)!=42:raise ValueError('Exact durable closure size') + for entry in closure:exact_keys(entry,('path','bytes','sha256'),'Closure descriptor') + actual={entry['path']:entry for entry in closure} + if len(actual)!=42 or actual!={entry['path']:entry for entry in entries}: + raise ValueError('Exact manifest/closure join') + for label in ('harness','supervisor_source','launcher_source'): + if actual.get(contract[label]['path'])!=contract[label]:raise ValueError('Executable Source closure join') + for value in contract['workflows'].values(): + if actual.get(value['path'])!=value:raise ValueError('Workflow Source closure join') + if contract['source_seal']['path'] in actual:raise ValueError('Source seal must be external') + captured={path:checked(entry) for path,entry in actual.items()} + for row,entry in zip(rows,entries): + raw=captured[entry['path']] + if hashlib.sha1(b'blob '+str(len(raw)).encode('ascii')+b'\0'+raw).hexdigest()!=row['git_blob']: + raise ValueError('Manifest Git blob join') + return captured + + +def workflow_entries(raw): + """Select the four actual code-under-test entries from their named job.""" + text=raw.decode('utf-8') + jobs=list(re.finditer(r'^ frozen-reader-transition-candidate:\n(.*?)(?=^ [A-Za-z0-9_-]+:|\Z)',text,re.M|re.S)) + if len(jobs)!=1:raise ValueError('Unique actual frozen core workflow job') + blocks=re.findall(r"^ (python3[^\n]+) <<'(PY[A-Z]+)'\n",jobs[0].group(1),re.M) + if len(blocks)!=4 or {name for _,name in blocks}!={'PYCONTEXT','PYGUARD','PYNODE','PYEMIT'}: + raise ValueError('Authenticated workflow stdin entries') + return {name:shlex.split(command) for command,name in blocks} + + +def derive_allowed_child_argv(contract,captured): + """Derive the closed argv census from authenticated child/workflow bytes.""" + fixture=Path(contract['regression_root']);commands=[] + for name in ('capturedirectory','capturefifo','capturehardlink','capturesymlink','missingcapture','nonzero','outputcap','sourcechange','sourcefifo','success','timeout'): + raw=captured[str(fixture/'children'/(name+'.py'))] + body=raw.decode('utf-8').replace('\r\n','\n').replace('\r','\n') + commands.append([contract['interpreter']['path'],'-I','-B','-S','-c',body]) + for descriptor in contract['workflows'].values(): + commands.extend(workflow_entries(captured[descriptor['path']]).values()) + result={hashlib.sha256(compact(command)).hexdigest():command for command in commands} + if len(result)!=13:raise ValueError('Exact derived 13 child argv') + return [result[sha] for sha in sorted(result)] + + +def child_argv(contract,captured): + result={hashlib.sha256(compact(command)).hexdigest():command for command in derive_allowed_child_argv(contract,captured)} + if type(contract['allowed_child_argv_sha256']) is not list or contract['allowed_child_argv_sha256']!=sorted(result): + raise ValueError('Derived allowed child argv join') + return result + + +def derive_expected_children(contract,captured): + """Closed Source census: run_case children plus the two stdin controls.""" + tree=ast.parse(captured[contract['harness']['path']]);methods={} + for cls in tree.body: + if isinstance(cls,ast.ClassDef) and cls.name=='InlineCaptureTests': + methods={cls.name+'.'+method.name:method for method in cls.body if isinstance(method,ast.FunctionDef) and method.name.startswith('test_')} + if len(methods)!=20 or contract['selectors']['candidate']!=sorted(methods) or contract['selectors']['baseline']!=[BASELINE]: + raise ValueError('Exact Source selectors for child census') + counts={} + for name,method in methods.items(): + calls=[node for node in ast.walk(method) if isinstance(node,ast.Call)] + cases=[node for node in calls if isinstance(node.func,ast.Attribute) and node.func.attr=='run_case'] + runs=[node for node in calls if isinstance(node.func,ast.Attribute) and isinstance(node.func.value,ast.Name) and node.func.value.id=='subprocess' and node.func.attr=='run'] + if cases: + if len(cases)!=1 or len(cases[0].args)!=1 or not isinstance(cases[0].args[0],ast.Constant) or type(cases[0].args[0].value) is not str or runs: + raise ValueError('Closed run_case child census') + counts[name]=0 if cases[0].args[0].value=='setupfailure' else 1 + elif name=='InlineCaptureTests.test_real_stdin_entrypoints_exclude_cwd_and_pythonpath_shadow' and len(runs)==1: + counts[name]=len(workflow_entries(captured[contract['workflows']['candidate']['path']])) + elif name=='InlineCaptureTests.test_actual_baseline_emitter_imports_shadow_and_candidate_emitter_holds_without_it' and len(runs)==2: + counts[name]=len(runs) + else:raise ValueError('Unqualified child-producing case Source') + result={'baseline':counts[BASELINE],'candidate':sum(counts.values())} + if result!={'baseline':1,'candidate':23}:raise ValueError('Exact derived durable child census') + return result + + +def checked(entry, maximum=2097152): + path=Path(entry['path']) + if not path.is_absolute() or path.resolve()!=path:raise ValueError('Physical absolute path required') + fd=os.open(path,os.O_RDONLY|os.O_NOFOLLOW|os.O_NONBLOCK) + try: + a=os.fstat(fd) + if not stat.S_ISREG(a.st_mode) or a.st_nlink!=1 or not 0<=a.st_size<=maximum: + raise ValueError('Nonregular/oversized Source') + parts=[];size=0 + while size<=maximum: + part=os.read(fd,min(65536,maximum+1-size)) + if not part:break + parts.append(part);size+=len(part) + b=os.fstat(fd);raw=b''.join(parts) + shape=lambda s:(s.st_dev,s.st_ino,s.st_mode,s.st_nlink,s.st_size,s.st_mtime_ns,s.st_ctime_ns) + if shape(a)!=shape(b) or len(raw)!=entry['bytes'] or hashlib.sha256(raw).hexdigest()!=entry['sha256']: + raise ValueError('Source identity mismatch') + return raw + finally:os.close(fd) + + +def file_pin(path,maximum): + fd=os.open(path,os.O_RDONLY|os.O_NOFOLLOW|os.O_NONBLOCK) + try: + s=os.fstat(fd) + if not stat.S_ISREG(s.st_mode) or s.st_nlink!=1 or s.st_size>maximum:raise ValueError('Capture shape') + raw=os.read(fd,maximum+1) + if len(raw)!=s.st_size:raise ValueError('Capture short read') + return {'bytes':len(raw),'sha256':hashlib.sha256(raw).hexdigest()},raw + finally:os.close(fd) + + +def own_children(): + # This enumerates only this dedicated subreaper's direct children, never + # foreign process commandlines. Do not reap until pidfd ownership is held. + path='/proc/self/task/%d/children'%os.getpid() + with open(path,'rb') as stream:raw=stream.read(16385) + if len(raw)>16384:raise ValueError('Owned child list cap') + values=[int(x) for x in raw.split()] + if len(values)>128:raise ValueError('Owned child count cap') + return values + + +def proc_identity(pid): + with open('/proc/%d/stat'%pid,'rb') as stream:raw=stream.read(4097) + if len(raw)>4096:raise ValueError('Owned process identity cap') + fields=raw.rsplit(b')',1)[1].split() + return {'pid':pid,'ppid':int(fields[1]),'pgid':int(fields[2]), + 'start_ticks':int(fields[19]),'state':fields[0].decode('ascii')} + + +def cleanup_owned(seconds=10): + began=time.monotonic();deadline=began+seconds;observed={};errors=[] + while time.monotonic()=deadline:break + fd=None + try: + # Parent is this single-threaded process, SIGCHLD is default, + # no concurrent wait/reaper exists: unreaped PID cannot reuse. + fd=os.pidfd_open(pid,0) + identity=proc_identity(pid) + if identity['ppid']!=os.getpid():raise ValueError('Direct-child ownership changed') + signal.pidfd_send_signal(fd,signal.SIGKILL,None,0) + waited,status=os.waitpid(pid,os.WNOHANG) + observed[pid]={'pid':pid,'pidfd_signal':'SIGKILL','reaped':waited==pid, + 'wait_status':status if waited==pid else None,'identity':identity} + if len(observed)>256:raise ValueError('Owned cleanup trace cap') + except ProcessLookupError: + try:os.waitpid(pid,os.WNOHANG) + except ChildProcessError:pass + except (OSError,ChildProcessError) as error: + if len(errors)>=32:raise ValueError('Cleanup error capacity') + errors.append({'pid':pid,'error':type(error).__name__}) + finally: + if fd is not None:os.close(fd) + time.sleep(0.02) + return {'confirmed':not own_children(),'observed':list(observed.values()),'errors':errors,'elapsed_seconds':round(time.monotonic()-began,6)} + + +def validate(contract,selection): + if type(contract) is not dict or contract.get('status')!='ROOT_FROZEN_EXECUTION_CONTRACT':raise ValueError('PENDING execution contract') + if contract['platform']!='linux' or not sys.platform.startswith('linux'): + raise ValueError('SOURCE_HOLD_UNSUPPORTED_DARWIN_CONTAINMENT') + if not hasattr(os,'pidfd_open') or not hasattr(signal,'pidfd_send_signal'): + raise ValueError('SOURCE_HOLD_PIDFD_UNAVAILABLE') + captured=closed_sources(contract) # Reject pending Source manifest before any fork. + if list(sys.version_info[:3])!=contract['interpreter']['version'] or str(Path(sys.executable).resolve())!=contract['interpreter']['path']: + raise ValueError('Interpreter identity/version') + checked(contract['interpreter'],268435456) + ceiling=120 if selection=='baseline' else 180 + if type(contract['wall_seconds'][selection]) is not int or not 1<=contract['wall_seconds'][selection]<=ceiling: + raise ValueError('Wall ceiling') + if contract['selectors']['baseline']!=[BASELINE]:raise ValueError('Baseline selector') + source=captured[contract['harness']['path']] + tree=ast.parse(source) + names=[c.name+'.'+n.name for c in tree.body if isinstance(c,ast.ClassDef) and c.name=='InlineCaptureTests' + for n in c.body if isinstance(n,ast.FunctionDef) and n.name.startswith('test_')] + if len(names)!=20 or len(set(names))!=20 or contract['selectors']['candidate']!=sorted(names): + raise ValueError('Exact 20 sorted candidate selectors') + if contract['expected_children']!=derive_expected_children(contract,captured) or any(type(value) is not int for value in contract['expected_children'].values()): + raise ValueError('Actual durable child census') + child_argv(contract,captured) + descriptor=os.pidfd_open(os.getpid(),0) + try:signal.pidfd_send_signal(descriptor,0,None,0) + finally:os.close(descriptor) + return source + + +def validate_trace(body,contract,selection,integer_exit,leader_pid,supervisor_pid,leader_identity): + """Validate evidence only. Trace fields never authorize process signals.""" + if type(body) is not bytes or not body or len(body)>=TRACE_CAP or not body.endswith(b'\n'): + raise ValueError('Partial/oversized trace') + lines=body.splitlines() + if any(not line or len(line)+1>TRACE_ROW_CAP for line in lines):raise ValueError('Trace row bound') + events=[json_value(line) for line in lines] + if any(compact(row)!=line+b'\n' for row,line in zip(events,lines)): + raise ValueError('Noncanonical trace encoding') + base={'kind','sequence','monotonic'} + identity={'pid','ppid','pgid','start_ticks'} + schemas={ + 'LAUNCHER_BEGIN':identity|{'observed_cwd'}, + 'SPAWN_BEGIN':{'token','argv','argv_sha256'}, + 'SPAWNED':identity|{'token','argv','argv_sha256'}, + 'SPAWN_FAILED':{'token','error'}, + 'CASE_BEGIN':{'case_id','runtime_id'}, + 'CASE_END':{'case_id','runtime_id','status','exception_type','message','traceback_bytes','traceback_sha256'}, + 'CASE_SUBTEST':{'case_id','subtest_id','status','exception_type','message'}, + 'CASE_WITNESS':{'case_id','scenario','caught_type','caught_exit','pre_source_opens','post_source_opens','total_source_opens','save_attempts','stored','capture_errors','cleanup_errors','stdout_missing','child_count','elapsed_seconds','context_read_error'}, + 'HARNESS_RESULT':{'tests_run','passed','failed','errors','skipped','expected_failures','unexpected_successes','ordered_cases','subtests'}, + 'HARNESS_END':{'exit_code'}, + } + expected=contract['selectors'][selection] + captured={entry['path']:checked(entry) for entry in contract['closure']} + allowed=child_argv(contract,captured) + tree=ast.parse(captured[contract['harness']['path']]) + scenarios={} + for cls in tree.body: + if not isinstance(cls,ast.ClassDef) or cls.name!='InlineCaptureTests':continue + for method in cls.body: + if not isinstance(method,ast.FunctionDef):continue + calls=[node for node in ast.walk(method) if isinstance(node,ast.Call) and isinstance(node.func,ast.Attribute) and node.func.attr=='run_case'] + if calls: + if len(calls)!=1 or len(calls[0].args)!=1 or not isinstance(calls[0].args[0],ast.Constant) or type(calls[0].args[0].value) is not str: + raise ValueError('Closed run_case scenario Source') + scenarios[cls.name+'.'+method.name]=calls[0].args[0].value + if len(scenarios)!=18:raise ValueError('Exact run_case scenario Source census') + cases=[];completed=[];current=None;pending=None;tokens=set();identities=set();spawn_count=0 + case_spawns={};witnesses=set();statuses=[];subtests=0;subtest_labels=[];result=None;previous=-1.0;launcher=None + isolation='InlineCaptureTests.test_real_stdin_entrypoints_exclude_cwd_and_pythonpath_shadow' + nullable_string=lambda value: value is None or text_value(value) + def check_identity(row): + if any(not integer(row[key],1 if key!='start_ticks' else 0) for key in identity):raise ValueError('Trace process identity type') + def check_errors(rows): + if type(rows) is not list or len(rows)>8:raise ValueError('Witness error bound') + for row in rows: + exact_keys(row,('operation','error'),'Witness error') + if not all(text_value(row[key],128) for key in row):raise ValueError('Witness error type') + def check_state(state): + if state is None:return + exact_keys(state,('node_phase','capture_status','immutable_source_recheck','node_returncode','capture_cleanup_diagnostics'),'Witness state') + for key in ('node_phase','capture_status','immutable_source_recheck','capture_cleanup_diagnostics'): + if not nullable_string(state[key]):raise ValueError('Witness state type') + if state['node_returncode'] is not None and type(state['node_returncode']) is not int:raise ValueError('Witness returncode type') + for index,row in enumerate(events): + if type(row) is not dict or type(row.get('kind')) is not str or row['kind'] not in schemas: + raise ValueError('Unknown trace kind') + kind=row['kind'];exact_keys(row,base|schemas[kind],kind) + if type(row['sequence']) is not int or row['sequence']!=index:raise ValueError('Consecutive trace sequence') + if not finite_number(row['monotonic']) or row['monotonic']=len(expected) or row['case_id']!=expected[len(cases)]: + raise ValueError('Canonical actual case order') + if row['runtime_id']!='__main__.'+row['case_id']:raise ValueError('Case runtime identity') + current=row['case_id'];cases.append(current);case_spawns[current]=0 + elif kind in ('SPAWN_BEGIN','SPAWNED','SPAWN_FAILED'): + if current is None or not integer(row['token']):raise ValueError('Spawn outside actual case') + if kind=='SPAWN_BEGIN': + if pending is not None or row['token'] in tokens or row['token']!=index:raise ValueError('Unique ordered spawn token') + argv=row['argv'] + if type(argv) is not list or not 1<=len(argv)<=16 or any(not text_value(value,2048) for value in argv):raise ValueError('Actual argv shape') + sha=hashlib.sha256(compact(argv)).hexdigest() + if row['argv_sha256']!=sha or allowed.get(sha)!=argv:raise ValueError('Actual argv/hash/Source join') + tokens.add(row['token']);pending=row + else: + if pending is None or row['token']!=pending['token']:raise ValueError('Spawn must follow its unique begin') + if kind=='SPAWN_FAILED': + if not text_value(row['error'],128):raise ValueError('Spawn failure type') + raise ValueError('Failed child spawn evidence') + check_identity(row) + if row['ppid']!=launcher['pid'] or row['argv']!=pending['argv'] or row['argv_sha256']!=pending['argv_sha256']: + raise ValueError('Spawned identity/actual argv join') + expected_pgid=row['pid'] if len(row['argv'])==6 and row['argv'][4]=='-c' else launcher['pgid'] + if row['pid'] in (launcher['pid'],supervisor_pid) or row['pgid']!=expected_pgid or row['start_ticks']2:raise ValueError('Witness save bound') + for state in row['save_attempts']:check_state(state) + check_state(row['stored']);check_errors(row['capture_errors']);check_errors(row['cleanup_errors']) + if type(row['stdout_missing']) is not bool or not finite_number(row['elapsed_seconds']) or not nullable_string(row['context_read_error']): + raise ValueError('Witness physical result types') + witnesses.add(current) + elif kind=='CASE_SUBTEST': + if current is None or pending is not None or row['case_id']!=current or not text_value(row['subtest_id'],512) or row['status'] not in ('PASS','FAIL','ERROR') or not nullable_string(row['exception_type']) or not text_value(row['message']): + raise ValueError('Current-case actual subtest schema') + labels=re.findall(r"\(block='(PYCONTEXT|PYGUARD|PYNODE|PYEMIT)'\)$",row['subtest_id']) + if current!=isolation or len(labels)!=1 or labels[0] in subtest_labels: + raise ValueError('Unique actual stdin subtest label') + if row['status']=='PASS' and (row['exception_type'] is not None or row['message']):raise ValueError('PASS subtest exception contradiction') + if row['status']!='PASS' and not row['exception_type']:raise ValueError('Missing actual subtest exception') + subtest_labels.extend(labels) + subtests+=1 + elif kind=='CASE_END': + if current is None or pending is not None or row['case_id']!=current or row['runtime_id']!='__main__.'+current: + raise ValueError('Ordered unique case endpoint') + status=row['status'] + if status not in ('PASS','FAIL','ERROR','SKIP','EXPECTED_FAILURE','UNEXPECTED_SUCCESS') or not nullable_string(row['exception_type']) or not text_value(row['message']) or not integer(row['traceback_bytes']): + raise ValueError('Actual case result schema') + if row['traceback_sha256'] is not None and not digest(row['traceback_sha256']):raise ValueError('Actual traceback hash') + if (row['traceback_bytes']==0)!=(row['traceback_sha256'] is None):raise ValueError('Traceback length/hash join') + if status=='PASS' and (row['exception_type'] is not None or row['message'] or row['traceback_bytes']):raise ValueError('PASS exception contradiction') + if status in ('FAIL','ERROR','EXPECTED_FAILURE') and (not text_value(row['exception_type'],128) or not row['exception_type'] or not row['traceback_bytes']):raise ValueError('Missing actual failure exception') + if current in scenarios and current not in witnesses:raise ValueError('Missing actual case witness') + if current==isolation and subtest_labels!=['PYCONTEXT','PYGUARD','PYNODE','PYEMIT']: + raise ValueError('Complete ordered actual stdin subtests') + statuses.append(status);completed.append(current);current=None + elif kind=='HARNESS_RESULT': + if current is not None or pending is not None or cases!=expected or completed!=expected or row['ordered_cases']!=cases: + raise ValueError('Complete actual unittest case census') + keys={'passed':'PASS','failed':'FAIL','errors':'ERROR','skipped':'SKIP','expected_failures':'EXPECTED_FAILURE','unexpected_successes':'UNEXPECTED_SUCCESS'} + if not integer(row['tests_run']) or row['tests_run']!=len(expected) or not integer(row['subtests']) or row['subtests']!=subtests: + raise ValueError('Actual unittest result census') + for key,status in keys.items(): + if not integer(row[key]) or row[key]!=statuses.count(status):raise ValueError('Actual unittest status counts') + result=row + if len(events)<4 or events[-1]['kind']!='HARNESS_END' or spawn_count!=contract['expected_children'][selection] or witnesses!={case for case in expected if case in scenarios}: + raise ValueError('Incomplete trace/child/witness census') + return {'verified_observed_cwd':launcher['observed_cwd'],'launcher_identity':{key:launcher[key] for key in identity}, + 'spawned_children':spawn_count,'ordered_cases':cases,'harness_result':result, + 'case_results':[row for row in events if row['kind']=='CASE_END'], + 'witnesses':[row for row in events if row['kind']=='CASE_WITNESS'], + 'subtests':[row for row in events if row['kind']=='CASE_SUBTEST'],'events':events} + + +def validate_regression_outcome(summary,selection): + """Classify actual validated observations separately from capture completion. + + This is an admission predicate over observed rows. It never manufactures a + missing witness, result, exception or expected value in the evidence. + """ + rows=summary['events'];result=summary['harness_result'] + ends=[row for row in rows if row['kind']=='CASE_END'] + witnesses=[row for row in rows if row['kind']=='CASE_WITNESS'] + subtests=[row for row in rows if row['kind']=='CASE_SUBTEST'] + starting={'node_phase':'starting','capture_status':'NOT_RUN','immutable_source_recheck':'pending', + 'node_returncode':None,'capture_cleanup_diagnostics':None} + if selection=='baseline': + if len(ends)!=1 or len(witnesses)!=1 or subtests or result['tests_run']!=1 or result['failed']!=1 or any(result[key] for key in ('passed','errors','skipped','expected_failures','unexpected_successes')): + return 'HOLD' + end=ends[0];witness=witnesses[0] + if end['case_id']!=BASELINE or end['status']!='FAIL' or end['exception_type']!='AssertionError' or 'Actual post-child source read was skipped' not in end['message']: + return 'HOLD' + if witness['scenario']!='missingcapture' or witness['caught_type']!='FileNotFoundError' or witness['caught_exit'] is not None or (witness['pre_source_opens'],witness['post_source_opens'],witness['total_source_opens'])!=(16,0,16): + return 'HOLD' + if witness['save_attempts']!=[starting] or witness['stored']!=starting or witness['stdout_missing'] is not True or witness['child_count']!=1 or witness['context_read_error'] is not None or witness['capture_errors'] or witness['cleanup_errors']: + return 'HOLD' + return 'BASELINE_CAUSAL_RED' + if selection!='candidate' or len(ends)!=20 or len(witnesses)!=18 or result['tests_run']!=20 or result['passed']!=20 or any(result[key] for key in ('failed','errors','skipped','expected_failures','unexpected_successes')): + return 'HOLD' + isolation='InlineCaptureTests.test_real_stdin_entrypoints_exclude_cwd_and_pythonpath_shadow' + if len(subtests)!=4 or any(row['case_id']!=isolation or row['status']!='PASS' or row['exception_type'] is not None or row['message'] for row in subtests) or len({row['subtest_id'] for row in subtests})!=4: + return 'HOLD' + statuses={'success':'COMPLETED','nonzero':'COMPLETED','timeout':'TIMEOUT','outputcap':'REFUSED_OUTPUT_LIMIT', + 'missingcapture':'REFUSED_CAPTURE','unreadablecapture':'REFUSED_CAPTURE','exitwritefailure':'REFUSED_CAPTURE', + 'killfailure':'REFUSED_CLEANUP','reapfailure':'REFUSED_REAP','cleanupinterrupt':'REFUSED_CLEANUP', + 'sourcechange':'REFUSED_SOURCE_CHANGED','sourcefifo':'REFUSED_SOURCE_CHANGED','setupfailure':'REFUSED_SETUP', + 'contextsavefailure':'COMPLETED','capturefifo':'REFUSED_CAPTURE','capturedirectory':'REFUSED_CAPTURE', + 'capturesymlink':'REFUSED_CAPTURE','capturehardlink':'REFUSED_CAPTURE'} + if {row['scenario'] for row in witnesses}!=set(statuses):return 'HOLD' + required_capture={ + 'missingcapture':('capture:tap.stdout.tap','FileNotFoundError'), + 'unreadablecapture':('capture:tap.stderr.txt','PermissionError'), + 'exitwritefailure':('exit_write','PermissionError'), + 'capturefifo':('capture:tap.stdout.tap','ValueError'), + 'capturedirectory':('capture:tap.stdout.tap','ValueError'), + 'capturesymlink':('capture:tap.stdout.tap','OSError'), + 'capturehardlink':('capture:tap.stdout.tap','ValueError'), + 'setupfailure':('capture','OSError')} + required_cleanup={'killfailure':('killpg','PermissionError'),'reapfailure':('wait','TimeoutExpired')} + for witness in witnesses: + scenario=witness['scenario'] + if witness['pre_source_opens']!=16 or witness['post_source_opens']<1 or witness['total_source_opens']<17 or len(witness['save_attempts'])!=2 or witness['context_read_error'] is not None or witness['save_attempts'][0]!=starting: + return 'HOLD' + final=witness['save_attempts'][1] + if final is None or final['capture_status']!=statuses[scenario] or final['node_phase']!=('not_started' if scenario=='setupfailure' else 'completed') or final['immutable_source_recheck']!=('failed' if scenario in ('sourcechange','sourcefifo') else 'passed') or final['capture_cleanup_diagnostics']!=('incomplete' if scenario=='cleanupinterrupt' else 'completed'): + return 'HOLD' + if witness['child_count']!=(0 if scenario=='setupfailure' else 1) or witness['stdout_missing']!=(scenario=='missingcapture'): + return 'HOLD' + if scenario=='contextsavefailure': + if witness['stored']!=starting or witness['caught_type']!='PermissionError' or witness['caught_exit'] is not None:return 'HOLD' + else: + if witness['stored']!=final:return 'HOLD' + if scenario=='cleanupinterrupt': + if witness['caught_type']!='KeyboardInterrupt' or witness['caught_exit'] is not None:return 'HOLD' + else: + code=0 if scenario=='success' else 7 if scenario=='nonzero' else 1 + if witness['caught_type']!='SystemExit' or witness['caught_exit']!=code:return 'HOLD' + if scenario in ('cleanupinterrupt','setupfailure'): + if final['node_returncode'] is not None:return 'HOLD' + elif type(final['node_returncode']) is not int:return 'HOLD' + if scenario in ('success','nonzero') and final['node_returncode']!=(0 if scenario=='success' else 7):return 'HOLD' + capture={(row['operation'],row['error']) for row in witness['capture_errors']} + cleanup={(row['operation'],row['error']) for row in witness['cleanup_errors']} + if scenario in required_capture: + required=required_capture[scenario] + allowed={required}|({('capture','FileNotFoundError')} if scenario=='missingcapture' else set()) + if required not in capture or not capture<=allowed:return 'HOLD' + elif capture:return 'HOLD' + if scenario in required_cleanup: + if cleanup!={required_cleanup[scenario]}:return 'HOLD' + elif cleanup:return 'HOLD' + return 'CANDIDATE_20_GREEN' + + +def main(): + started=time.monotonic() + parser=argparse.ArgumentParser(description=__doc__) + parser.add_argument('--contract',required=True,type=Path) + parser.add_argument('--contract-sha256',required=True) + parser.add_argument('--selection',required=True,choices=['baseline','candidate']) + parser.add_argument('--output',required=True,type=Path) + args=parser.parse_args() + root=args.output + root.mkdir(mode=0o700) + if root.resolve()!=root:raise ValueError('Physical owned output path') + receipt={'schema_version':1,'disposition':'HOLD_NOT_RUN','selection':args.selection, + 'harness_status':'NOT_RUN','integer_exit':None,'timeout':False,'cap':False, + 'cleanup':{'confirmed':False},'source_before':{},'source_after':{},'scientific_effect':'NONE', + 'verified_observed_cwd':None,'regression_status':'HOLD'} + leader_pid=None;leader_fd=None;enabled=False + try: + _,raw=file_pin(args.contract,65536) + if len(raw)>65536 or hashlib.sha256(raw).hexdigest()!=args.contract_sha256:raise ValueError('Contract hash') + receipt['contract_before']={'bytes':len(raw),'sha256':hashlib.sha256(raw).hexdigest()} + contract=json_value(raw);validate(contract,args.selection) + for label in ['supervisor_source','launcher_source','source_seal']:checked(contract[label]) + _,executed_source=file_pin(Path(__file__),2097152) + if checked(contract['supervisor_source'])!=executed_source:raise ValueError('Supervisor executed Source') + deadline=started+contract['wall_seconds'][args.selection] + for entry in [*contract['closure'],contract['source_seal']]: + checked(entry);receipt['source_before'][entry['path']]={'bytes':entry['bytes'],'sha256':entry['sha256']} + if time.monotonic()>=deadline:raise TimeoutError('Whole invocation setup wall') + for name in ['home','tmp']:(root/name).mkdir(mode=0o700) + staged=root/'launcher.py';launcher_bytes=checked(contract['launcher_source']) + staged.write_bytes(launcher_bytes);staged.chmod(0o400) + staged_contract=root/'execution-contract.json';staged_contract.write_bytes(raw);staged_contract.chmod(0o400) + trace=root/'spawn-trace.jsonl';trace.write_bytes(b'') + paths=[root/'stdout.bin',root/'stderr.bin'] + libc=ctypes.CDLL(None,use_errno=True) + signal.signal(signal.SIGCHLD,signal.SIG_DFL) + if libc.prctl(36,1,0,0,0)!=0:raise OSError(ctypes.get_errno(),'subreaper unavailable') + enabled=True + if own_children():raise ValueError('Dedicated supervisor already has children') + interpreter=contract['interpreter']['path'] + # The physical binary may be named python3.12. The owned PATH exposes + # only an explicit python3 symlink to that exact authenticated target. + binary_dir=root/'bin';binary_dir.mkdir(mode=0o700) + (binary_dir/'python3').symlink_to(interpreter) + receipt['python3_alias']={'path':str(binary_dir/'python3'),'target':interpreter} + env={'PATH':str(binary_dir),'HOME':str(root/'home'), + 'TMPDIR':str(root/'tmp'),'LANG':'C.UTF-8','LC_ALL':'C.UTF-8','TZ':'UTC', + 'PYTHONDONTWRITEBYTECODE':'1','INLINE_WRAPPER_WORKFLOW':contract['workflows'][args.selection]['path']} + env['SITE_CAPTURE_SELECTION']=args.selection + command=[interpreter,'-I','-B','-S',str(staged),'--contract',str(staged_contract), + '--contract-sha256',args.contract_sha256,'--selection',args.selection,'--trace',str(trace)] + receipt.update(command=command,expected_cwd=contract['cwd'],environment=env,wall_seconds=contract['wall_seconds'][args.selection],stream_cap=CAP) + if time.monotonic()>=deadline: + receipt['timeout']=True + raise TimeoutError('Whole invocation setup wall') + with paths[0].open('xb') as out,paths[1].open('xb') as err: + receipt['launch_attempted']=True + # Parent returns from fork without waiting on a Popen preexec/ + # error-pipe handshake; watchdog covers child setup/exec as well. + leader_pid=os.fork() + if leader_pid==0: + try: + os.setsid() + os.chdir(contract['cwd']) + validate_launch_cwd(contract) + resource.setrlimit(resource.RLIMIT_FSIZE,(CAP,CAP)) + resource.setrlimit(resource.RLIMIT_CORE,(0,0)) + null=os.open(os.devnull,os.O_RDONLY) + os.dup2(null,0);os.dup2(out.fileno(),1);os.dup2(err.fileno(),2) + if null>2:os.close(null) + os.execve(interpreter,command,env) + except BaseException as error: + try:os.write(2,('FIXED_LAUNCH_FAILED '+type(error).__name__+'\n').encode('ascii')) + finally:os._exit(126) + leader_fd=os.pidfd_open(leader_pid,0) + receipt['leader_identity_at_pidfd']=proc_identity(leader_pid) + if receipt['leader_identity_at_pidfd']['ppid']!=os.getpid():raise ValueError('Original leader ownership changed') + receipt['harness_status']='STARTED' + receipt['leader_pid']=leader_pid + while True: + if any(p.stat().st_size>=CAP for p in paths) or trace.stat().st_size>=TRACE_CAP: + receipt['cap']=True;break + waited,status=os.waitpid(leader_pid,os.WNOHANG) + if waited==leader_pid: + receipt['integer_exit']=os.waitstatus_to_exitcode(status);break + if time.monotonic()>=deadline:receipt['timeout']=True;break + time.sleep(0.02) + except BaseException as error: + receipt['error']=type(error).__name__+': '+str(error)[:1000] + finally: + if leader_fd is not None: + # This is the original child even after PID reuse. Signal/close + # diagnostics cannot bypass the separate adoption cleanup below. + try:signal.pidfd_send_signal(leader_fd,signal.SIGKILL,None,0) + except ProcessLookupError:pass + except BaseException as error:receipt['leader_signal_error']=type(error).__name__ + finally: + try:os.close(leader_fd) + except BaseException as error:receipt['leader_close_error']=type(error).__name__ + if enabled and receipt.get('launch_attempted'): + try:receipt['cleanup']=cleanup_owned(10) + except BaseException as error:receipt['cleanup']={'confirmed':False,'error':type(error).__name__} + if leader_pid is not None and receipt['integer_exit'] is None: + for row in receipt['cleanup'].get('observed',[]): + if row['pid']==leader_pid and row['reaped']: + receipt['integer_exit']=os.waitstatus_to_exitcode(row['wait_status']) + # No Popen fallback can invent exit0 after independent waitpid. + try: + if 'contract' in locals() and contract.get('status')=='ROOT_FROZEN_EXECUTION_CONTRACT': + after_contract,_=file_pin(args.contract,65536) + if after_contract!=receipt['contract_before']:raise ValueError('Execution contract changed') + receipt['contract_after']=after_contract + if 'staged' in locals(): + after_staged,_=file_pin(staged,2097152) + if after_staged!={'bytes':len(launcher_bytes),'sha256':hashlib.sha256(launcher_bytes).hexdigest()}:raise ValueError('Staged launcher changed') + staged_contract_pin,_=file_pin(staged_contract,65536) + if staged_contract_pin!=receipt['contract_before']:raise ValueError('Staged contract changed') + receipt['staged_after']={'launcher':after_staged,'contract':staged_contract_pin} + checked(contract['interpreter'],268435456) + receipt['interpreter_after']={'path':contract['interpreter']['path'], + 'sha256':contract['interpreter']['sha256'],'bytes':contract['interpreter']['bytes']} + for entry in [*contract['closure'],contract['source_seal']]: + checked(entry);receipt['source_after'][entry['path']]={'bytes':entry['bytes'],'sha256':entry['sha256']} + except BaseException as error:receipt['source_after_error']=type(error).__name__ + try: + if leader_pid is not None: + receipt['captures']={} + for name,maximum in [('stdout.bin',CAP),('stderr.bin',CAP),('spawn-trace.jsonl',TRACE_CAP)]: + identity,body=file_pin(root/name,maximum);receipt['captures'][name]=identity + if identity['bytes']>=maximum:receipt['cap']=True + if name=='spawn-trace.jsonl': + summary=validate_trace(body,contract,args.selection,receipt['integer_exit'],leader_pid,os.getpid(),receipt['leader_identity_at_pidfd']) + receipt['verified_observed_cwd']=summary['verified_observed_cwd'] + receipt['trace_validation']={key:summary[key] for key in ('verified_observed_cwd','launcher_identity','spawned_children','ordered_cases')} + receipt['regression_evidence']={key:summary[key] for key in ('harness_result','case_results','witnesses','subtests')} + receipt['regression_status']=validate_regression_outcome(summary,args.selection) + receipt['trace_complete']=True + except BaseException as error:receipt['capture_or_trace_error']=type(error).__name__+': '+str(error)[:500] + receipt['elapsed_seconds']=round(time.monotonic()-started,6) + good=(leader_pid is not None and type(receipt['integer_exit']) is int and not receipt['timeout'] and not receipt['cap'] + and receipt['cleanup']['confirmed'] and not receipt['cleanup'].get('errors') and receipt.get('trace_complete') is True + and receipt.get('verified_observed_cwd')==contract['cwd'] + and receipt['source_before']==receipt['source_after'] and not any(k in receipt for k in ['error','source_after_error','capture_or_trace_error','leader_signal_error','leader_close_error'])) + receipt['disposition']='CAPTURE_COMPLETE_REQUIRES_HARNESS_REVIEW' if good else 'HOLD_INCOMPLETE_OR_NOT_RUN' + result=packed(receipt) + if len(result)>262144: + receipt={'schema_version':1,'disposition':'HOLD_RECEIPT_CAP', + 'omitted_receipt_bytes':len(result),'omitted_receipt_sha256':hashlib.sha256(result).hexdigest(), + 'harness_status':'UNKNOWN_REVIEW_ORIGINAL_CAPTURES','scientific_effect':'NONE'} + result=packed(receipt) + (root/'receipt.json').write_bytes(result) + print(receipt['disposition']) + return 0 if receipt['disposition']=='CAPTURE_COMPLETE_REQUIRES_HARNESS_REVIEW' else 2 + + +if __name__=='__main__':raise SystemExit(main()) diff --git a/tools/site_transition_source_guard.py b/tools/site_transition_source_guard.py new file mode 100644 index 000000000..5b10c5c89 --- /dev/null +++ b/tools/site_transition_source_guard.py @@ -0,0 +1,74 @@ +"""Pure identity checks for an explicitly frozen pull-request merge source. + +Callers must acquire literal commit bytes and authenticate this module before +loading it. This function performs no Git, filesystem, network or child work. +""" +import hashlib +import re + + +class SourceJoinError(ValueError): + """The supplied source and native identities cannot establish this join.""" + + +def verify_merge_join(*, event_name: str, repository: str, event_ref: str, + event_sha: str, pr_number: int, event_head_sha: str, + event_base_sha: str, checked_commit: str, + actual_commit_raw: bytes, frozen_base_commit: str) -> dict: + """Validate literal native identities; return the retained join record.""" + for value in (event_sha, event_head_sha, event_base_sha, + checked_commit, frozen_base_commit): + if type(value) is not str or re.fullmatch(r'[0-9a-f]{40}', value) is None: + raise SourceJoinError('Invalid source commit identity') + if (type(event_name) is not str or event_name != 'pull_request' + or type(repository) is not str or repository != 'd6g8k5htny-coder/main' + or type(pr_number) is not int or not 1 <= pr_number < 10**12 + or type(event_ref) is not str + or event_ref != 'refs/pull/%d/merge' % pr_number): + raise SourceJoinError('Unexpected repository or pull-request event') + if checked_commit != event_sha: + raise SourceJoinError('Checked commit differs from tested event') + if type(actual_commit_raw) is not bytes or not 0 < len(actual_commit_raw) <= 65536: + raise SourceJoinError('Invalid or oversized literal commit bytes') + framed = b'commit ' + str(len(actual_commit_raw)).encode('ascii') + b'\0' + actual_commit_raw + if hashlib.sha1(framed).hexdigest() != checked_commit: + raise SourceJoinError('Literal commit bytes differ from checked commit') + header, separator, _message = actual_commit_raw.partition(b'\n\n') + if not separator or not header or b'\0' in header: + raise SourceJoinError('Invalid literal commit header') + lines = header.split(b'\n') + if not 5 <= len(lines) <= 128 or re.fullmatch(rb'tree [0-9a-f]{40}', lines[0]) is None: + raise SourceJoinError('Invalid tree header or header line count') + if any(re.fullmatch(rb'parent [0-9a-f]{40}', line) is None for line in lines[1:3]): + raise SourceJoinError('Exactly two literal ordered parents required') + previous = None + counts = {'author': 0, 'committer': 0} + for line in lines[3:]: + if not line or re.search(rb'[\x00-\x1f\x7f]', line): + raise SourceJoinError('Invalid control or empty commit header') + if line.startswith(b' '): + if previous is None or previous in (b'author', b'committer', b'encoding'): + raise SourceJoinError('Orphan or invalid header continuation') + continue + if re.fullmatch(rb'[a-z][a-z0-9-]* [^\x00-\x1f\x7f]+', line) is None: + raise SourceJoinError('Malformed remaining commit header') + key = line.split(b' ', 1)[0] + if key in (b'parent', b'tree'): + raise SourceJoinError('Extra parent or tree header') + if key.decode('ascii') in counts: + counts[key.decode('ascii')] += 1 + previous = key + if counts != {'author': 1, 'committer': 1}: + raise SourceJoinError('Missing or duplicate author or committer') + parents = [line[7:].decode('ascii') for line in lines[1:3]] + # The event base is retained as observed metadata; only the explicitly + # frozen base and event head identify the required actual parent order. + if parents != [frozen_base_commit, event_head_sha]: + raise SourceJoinError('Frozen-base/head/tested-merge join mismatch') + return { + 'event_name': event_name, 'repository': repository, 'event_ref': event_ref, + 'event_sha': event_sha, 'pull_request_number': pr_number, + 'pull_request_head_sha': event_head_sha, 'pull_request_base_sha': event_base_sha, + 'checked_commit': checked_commit, 'actual_tree_sha': lines[0][5:].decode('ascii'), + 'actual_merge_parents': parents, 'candidate_base_commit': frozen_base_commit, + }