mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 20:29:18 +01:00
ci(runner): verify frozen Pi on native Intel macOS
Add an exclusive manual no-provider lane that rebuilds the reviewed Pi 1.0 source and lock closure, checks native Intel execution, and retains unchanged startup/SDK test evidence with owned cleanup. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
602f61812b
commit
d472a3c95e
9 files changed
+924
-3
No files matched your search
@@ -23,6 +23,10 @@ on:
|
||||
description: "Run the complete offline Runner verify command on GitHub-hosted Ubuntu without building an image"
|
||||
type: boolean
|
||||
default: false
|
||||
verify_pi_intel:
|
||||
description: "Verify frozen Pi 1.0 closed startup and SDK contracts on native Intel macOS (no provider prompts)"
|
||||
type: boolean
|
||||
default: false
|
||||
diagnose_ajv_pack:
|
||||
description: "Diagnose only pinned AJV npm directory packing on Linux (no Runner build/tests)"
|
||||
type: boolean
|
||||
@@ -57,7 +61,7 @@ permissions: {}
|
||||
|
||||
concurrency:
|
||||
# Publishing a newer image must not discard an earlier verification's evidence.
|
||||
group: docker-runner-check-${{ github.event.pull_request.number || github.ref }}-${{ inputs.diagnose_ajv_pack && 'ajv-diagnostic' || inputs.verify_runner && 'runner-verification' || inputs.source_root_tests_only && 'source-root-tests' || inputs.verify_source && 'verification' || inputs.verify_public_install && 'public-install' || inputs.build_eval_viewer && 'viewer' || 'image' }}
|
||||
group: docker-runner-check-${{ github.event.pull_request.number || github.ref }}-${{ inputs.verify_pi_intel && 'pi-native-intel' || inputs.diagnose_ajv_pack && 'ajv-diagnostic' || inputs.verify_runner && 'runner-verification' || inputs.source_root_tests_only && 'source-root-tests' || inputs.verify_source && 'verification' || inputs.verify_public_install && 'public-install' || inputs.build_eval_viewer && 'viewer' || 'image' }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
@@ -110,8 +114,9 @@ jobs:
|
||||
VERIFY_SOURCE: ${{ inputs.verify_source }}
|
||||
SOURCE_ROOT_TESTS_ONLY: ${{ inputs.source_root_tests_only }}
|
||||
IMAGE_MODE: ${{ inputs.publish_eval_image || inputs.verify_public_install || inputs.build_eval_viewer }}
|
||||
VERIFY_PI_INTEL: ${{ inputs.verify_pi_intel }}
|
||||
DIAGNOSE_AJV: ${{ inputs.diagnose_ajv_pack }}
|
||||
OTHER_MODE: ${{ inputs.publish_eval_image || inputs.verify_source || inputs.verify_public_install || inputs.build_eval_viewer }}
|
||||
OTHER_MODE: ${{ inputs.publish_eval_image || inputs.verify_source || inputs.verify_public_install || inputs.build_eval_viewer || inputs.verify_pi_intel }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
test "$REPOSITORY" = paperclipai/paperclip
|
||||
@@ -143,11 +148,69 @@ jobs:
|
||||
test "$EXPECTED_SOURCE_SHA" = 34f49a201a804564cfae81e425266b3f9f987e30
|
||||
test "$EXPECTED_LOCK_SHA256" = 5ae57d1ddd475691dac1f1cfbd4836e54f7da1956b47e6e705b218ae3070ae2e
|
||||
fi
|
||||
if [ "$VERIFY_PI_INTEL" = true ]; then
|
||||
test "$VERIFY_RUNNER" != true
|
||||
test "$VERIFY_SOURCE" != true
|
||||
test "$SOURCE_ROOT_TESTS_ONLY" != true
|
||||
test "$DIAGNOSE_AJV" != true
|
||||
test "$IMAGE_MODE" != true
|
||||
test "$EXPECTED_SOURCE_SHA" = 5eba61ece929dcfb2b0c1761825a2d9e557c2554
|
||||
test "$EXPECTED_LOCK_SHA256" = 38338a6867358440c5ab5993eaeb85fb501bc7df65d24acf52fbd63c880ee4ba
|
||||
# Standard hosted runner minutes are free for this public repository.
|
||||
# Artifact storage and unrelated resource costs are not inferred here.
|
||||
test "$(gh api "repos/$REPOSITORY" --jq '.visibility')" = public
|
||||
fi
|
||||
if [ -n "$EXPECTED_SOURCE_SHA" ]; then
|
||||
test "$target_sha" = "$EXPECTED_SOURCE_SHA"
|
||||
fi
|
||||
echo "target_sha=$target_sha" >> "$GITHUB_OUTPUT"
|
||||
|
||||
manual_pi_intel:
|
||||
name: Frozen Pi 1.0 native Intel startup and SDK contracts
|
||||
if: github.event_name == 'workflow_dispatch' && inputs.verify_pi_intel
|
||||
needs: authorize_manual
|
||||
runs-on: macos-15-intel
|
||||
timeout-minutes: 60
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout trusted CI helpers independently of candidate source
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
||||
with:
|
||||
ref: ${{ github.workflow_sha }}
|
||||
path: trusted-ci
|
||||
persist-credentials: false
|
||||
- name: Checkout exact frozen production source
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
||||
with:
|
||||
ref: ${{ needs.authorize_manual.outputs.target_sha }}
|
||||
path: candidate
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
|
||||
with:
|
||||
node-version: 24.21.0
|
||||
architecture: x64
|
||||
package-manager-cache: false
|
||||
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6
|
||||
with:
|
||||
version: 9.15.4
|
||||
package_json_file: candidate/package.json
|
||||
- name: Build frozen pack and run unchanged no-provider contracts once
|
||||
timeout-minutes: 55
|
||||
run: |
|
||||
set -euo pipefail
|
||||
python3 -B trusted-ci/scripts/ci/pi-intel/verify.py \
|
||||
--source "$GITHUB_WORKSPACE/candidate" \
|
||||
--output "$GITHUB_WORKSPACE/pi-intel-evidence"
|
||||
- name: Retain exact input, independent output, test, and cleanup evidence
|
||||
if: always()
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
||||
with:
|
||||
name: pi-native-intel-${{ github.run_id }}
|
||||
path: pi-intel-evidence/
|
||||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
manual_runner_verify:
|
||||
name: Full offline Runner verification on GitHub-hosted Ubuntu
|
||||
if: github.event_name == 'workflow_dispatch' && inputs.verify_runner
|
||||
@@ -434,7 +497,7 @@ jobs:
|
||||
|
||||
manual_image:
|
||||
name: Build and verify on EC2
|
||||
if: github.event_name == 'workflow_dispatch' && !inputs.verify_runner && !inputs.verify_source && !inputs.diagnose_ajv_pack
|
||||
if: github.event_name == 'workflow_dispatch' && !inputs.verify_runner && !inputs.verify_source && !inputs.diagnose_ajv_pack && !inputs.verify_pi_intel
|
||||
needs: authorize_manual
|
||||
runs-on: runs-on/fleet=paperclip-public-pr-x64/env=public-ci
|
||||
timeout-minutes: 90
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
"""Prospective private cleanup bounds; source/GO authority is deliberately absent."""
|
||||
INNER_GRACE_SECONDS = 45
|
||||
INNER_FORCE_SECONDS = 5
|
||||
OWNER_GRACE_SECONDS = INNER_GRACE_SECONDS + INNER_FORCE_SECONDS
|
||||
POSTGRES_GRACE_SECONDS = 20
|
||||
RESIDUAL_GRACE_SECONDS = 10
|
||||
KILL_GRACE_SECONDS = 5
|
||||
INSPECTION_RETRY_SECONDS = 5
|
||||
STOP_DEADLINE_SECONDS = 100
|
||||
CLEANUP_ALLOWANCE_SECONDS = 120
|
||||
LATE_CLOUD_OBSERVATION_SECONDS = 360
|
||||
CLOUD_REQUEST_ALLOWANCE_SECONDS = 60
|
||||
|
||||
def remote_bound(outer_seconds, runs, rates):
|
||||
seconds=outer_seconds+CLEANUP_ALLOWANCE_SECONDS+LATE_CLOUD_OBSERVATION_SECONDS+CLOUD_REQUEST_ALLOWANCE_SECONDS
|
||||
hourly=4*rates['cpuCoreHourUsd']+4*rates['memoryGiBHourUsd']+10*rates['storageGiBHourUsd']
|
||||
return {'billableWindowSeconds':seconds,'maximumSandboxes':runs,'perSandboxUsd':round(hourly*seconds/3600,9),'maximumInfrastructureUsd':round(hourly*seconds/3600*runs,9)}
|
||||
@@ -0,0 +1,41 @@
|
||||
"""Read-only inventory for Docker-extracted packs with internal hard links."""
|
||||
import hashlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
import stat
|
||||
|
||||
def closed_tree(root):
|
||||
root = Path(root)
|
||||
if root.is_symlink() or not root.is_dir():
|
||||
raise RuntimeError('Invalid inventory root')
|
||||
groups = {}
|
||||
rows = []
|
||||
for path in sorted(root.rglob('*')):
|
||||
info = path.lstat()
|
||||
row = {'path': path.relative_to(root).as_posix(), 'mode': stat.S_IMODE(info.st_mode)}
|
||||
if stat.S_ISLNK(info.st_mode):
|
||||
if not path.resolve(strict=True).is_relative_to(root.resolve()):
|
||||
raise RuntimeError('Symlink escapes pack')
|
||||
row.update(kind='symlink', target=os.readlink(path))
|
||||
elif stat.S_ISDIR(info.st_mode):
|
||||
row.update(kind='directory')
|
||||
elif stat.S_ISREG(info.st_mode):
|
||||
identity = (info.st_dev, info.st_ino)
|
||||
groups.setdefault(identity, []).append((path, info))
|
||||
digest = hashlib.sha256()
|
||||
with path.open('rb') as stream:
|
||||
for chunk in iter(lambda: stream.read(1024 * 1024), b''):
|
||||
digest.update(chunk)
|
||||
row.update(kind='file', sha256=digest.hexdigest(), size=info.st_size,
|
||||
hardlinkGroup=groups[identity][0][0].relative_to(root).as_posix(), links=info.st_nlink)
|
||||
else:
|
||||
raise RuntimeError('Nonregular pack file')
|
||||
rows.append(row)
|
||||
for identity, members in groups.items():
|
||||
for path, before in members:
|
||||
after = path.lstat()
|
||||
if ((after.st_dev, after.st_ino) != identity or after.st_nlink != len(members)
|
||||
or after.st_size != before.st_size or after.st_mtime_ns != before.st_mtime_ns
|
||||
or after.st_mode != before.st_mode):
|
||||
raise RuntimeError('Pack hard link escapes inventory or file changed')
|
||||
return rows
|
||||
@@ -0,0 +1,253 @@
|
||||
"""Private qualification cleanup. Journals identities, never argv/environment.
|
||||
|
||||
Postgres is not an ordinary kill-tree leaf. The installed embedded-postgres
|
||||
stop() uses SIGINT and awaits exit. Give a known wrapper sole graceful-signal ownership before native cleanup.
|
||||
Unknown database/initializer identities never receive fallback TERM/KILL.
|
||||
"""
|
||||
import datetime, hashlib, json, os, pathlib, shlex, signal, stat, subprocess, threading, time
|
||||
from cleanup_policy import (OWNER_GRACE_SECONDS,POSTGRES_GRACE_SECONDS,RESIDUAL_GRACE_SECONDS,KILL_GRACE_SECONDS,INSPECTION_RETRY_SECONDS,STOP_DEADLINE_SECONDS)
|
||||
|
||||
def now(): return datetime.datetime.now(datetime.timezone.utc).isoformat()
|
||||
def atomic_json(path, value):
|
||||
path=pathlib.Path(path); tmp=path.with_suffix('.tmp')
|
||||
tmp.write_text(json.dumps(value,indent=2)+'\n'); tmp.chmod(0o600); tmp.replace(path)
|
||||
def process_table():
|
||||
result={}
|
||||
for line in subprocess.check_output(['/bin/ps','-axo','pid=,ppid=,lstart=,stat=,comm='],text=True,timeout=2).splitlines():
|
||||
row=line.split(maxsplit=8)
|
||||
if len(row)!=9: continue
|
||||
status={'R':'running','S':'sleeping','I':'idle','T':'stopped','Z':'zombie','U':'uninterruptible'}.get(row[7][:1],'unknown')
|
||||
result[int(row[0])]={'parent':int(row[1]),'started':' '.join(row[2:7]),'status':status,'executable':row[8]}
|
||||
return result
|
||||
|
||||
class ProcessInspectionUnavailable(Exception):
|
||||
"""No trustworthy argv snapshot; caller must revalidate identity."""
|
||||
|
||||
def command_tokens(pid):
|
||||
# Inspect only an already owned PID; never persist or print this output.
|
||||
try:value=subprocess.check_output(['/bin/ps','-p',str(pid),'-o','command='],text=True,stderr=subprocess.DEVNULL,timeout=2)
|
||||
except (subprocess.SubprocessError,OSError) as error:raise ProcessInspectionUnavailable() from error
|
||||
if not value.strip() or len(value)>16384:raise ProcessInspectionUnavailable()
|
||||
try:return shlex.split(value)
|
||||
except ValueError as error:raise ProcessInspectionUnavailable() from error
|
||||
|
||||
class OwnedProcesses:
|
||||
def __init__(self, journal, private_root, app_root, sidecar_path, *, table=process_table,
|
||||
argv=command_tokens, send=os.kill, clock=time.monotonic, sleep=time.sleep,
|
||||
app_grace=OWNER_GRACE_SECONDS, postgres_grace=POSTGRES_GRACE_SECONDS, root_grace=RESIDUAL_GRACE_SECONDS, kill_grace=KILL_GRACE_SECONDS):
|
||||
self.journal=pathlib.Path(journal); self.root=pathlib.Path(private_root).resolve()
|
||||
st=self.root.lstat()
|
||||
if not stat.S_ISDIR(st.st_mode) or st.st_uid!=os.getuid() or st.st_mode&0o077: raise ValueError('private root ownership invalid')
|
||||
self.root_identity=(st.st_dev,st.st_ino,st.st_uid)
|
||||
self.app=str(pathlib.Path(app_root)); self.sidecar=str(pathlib.Path(sidecar_path))
|
||||
self.table=table;self.argv=argv;self.send=send;self.clock=clock;self.sleep=sleep
|
||||
self.budgets=(app_grace,postgres_grace,root_grace,kill_grace)
|
||||
self.owned={};self.actions=[];self.root_pid=None;self.lock=threading.RLock();self.stopping=False;self.stop_result=None
|
||||
self.postmasters={} # trusted paths are private in-memory only
|
||||
self.stop_done=threading.Event();self.stop_thread=None;self.stop_deadline=None;self.inspection_failures=0
|
||||
def _role(self,pid,row):
|
||||
name=pathlib.Path(row['executable']).name
|
||||
if name=='paperclip-runnerd': return 'runnerd'
|
||||
if name=='copilot': return 'copilot'
|
||||
if name=='initdb': return 'initdb'
|
||||
if name=='postgres' or name.startswith('postgres:'):
|
||||
tokens=self.argv(pid)
|
||||
if '-D' in tokens:
|
||||
i=tokens.index('-D')
|
||||
if i+1<len(tokens):
|
||||
data=pathlib.Path(tokens[i+1]).resolve()
|
||||
if data.is_relative_to(self.root):
|
||||
self.postmasters[pid]=data
|
||||
return 'postgres_postmaster_candidate'
|
||||
return 'postgres_backend'
|
||||
if name in ('node','nodejs'):
|
||||
tokens=self.argv(pid)
|
||||
if self.sidecar in tokens:return 'acpx_sidecar'
|
||||
if self.app+'/tests/runner-e2e/server-entry.ts' in tokens:return 'paperclip_server'
|
||||
if self.app+'/tests/runner-e2e/server.ts' in tokens:return 'product_server_supervisor'
|
||||
if self.app+'/tests/runner-e2e/launch.ts' in tokens:return 'product_launcher'
|
||||
return 'node'
|
||||
return {'sh':'shell','bash':'shell','zsh':'shell','python3':'supervisor','Python':'supervisor','Chromium':'browser'}.get(name,'other')
|
||||
def observe(self,root_pid=None):
|
||||
with self.lock:
|
||||
if root_pid is not None and self.root_pid is None:self.root_pid=root_pid
|
||||
rows=self.table();live={pid for pid,r in self.owned.items() if rows.get(pid,{}).get('started')==r['started']}
|
||||
if self.root_pid not in self.owned and self.root_pid in rows: live.add(self.root_pid)
|
||||
while True:
|
||||
extra={pid for pid,r in rows.items() if r['parent'] in live}-live
|
||||
if not extra:break
|
||||
live|=extra
|
||||
for pid in list(live):
|
||||
if self.stop_deadline is not None and self.clock()>=self.stop_deadline:raise ProcessInspectionUnavailable()
|
||||
row=rows[pid]
|
||||
if self.stopping or pid not in self.owned or self.owned[pid]['role']=='unresolved_inspection':
|
||||
try:role=self._role(pid,row)
|
||||
except ProcessInspectionUnavailable:
|
||||
current=self.table().get(pid)
|
||||
if current is None or current['started']!=row['started']:
|
||||
# Natural exit/reuse between snapshots is not a
|
||||
# supervisor failure and never creates ownership.
|
||||
live.discard(pid);rows.pop(pid,None);continue
|
||||
role='unresolved_inspection'
|
||||
if pid not in self.owned:self.owned[pid]={'parent':row['parent'],'started':row['started'],'role':role,'firstObservedAt':now(),'firstObservedMonotonic':self.clock()}
|
||||
else:self.owned[pid]['role']=role
|
||||
self.owned[pid].update(status=row['status'],lastObservedAt=now(),lastObservedMonotonic=self.clock())
|
||||
for pid,r in self.owned.items():
|
||||
if pid not in live:r['status']='gone_or_identity_changed'
|
||||
self._persist()
|
||||
return rows
|
||||
def _persist(self):
|
||||
with self.lock:atomic_json(self.journal,{'schema':'qualification-owned-processes/v2','recordedAt':now(),'rootPid':self.root_pid,'owned':self.owned,'actions':self.actions,'stopResult':self.stop_result,'rawArgvRetained':False,'rawEnvironmentRetained':False,'inspectionFailures':self.inspection_failures})
|
||||
def live(self,rows=None):
|
||||
rows=self.observe() if rows is None else rows
|
||||
return {pid for pid,r in self.owned.items() if rows.get(pid,{}).get('started')==r['started'] and rows[pid].get('status')!='zombie'}
|
||||
def _fresh(self):
|
||||
end=min(self.clock()+INSPECTION_RETRY_SECONDS,self.stop_deadline or float('inf'))
|
||||
while True:
|
||||
try:
|
||||
rows=self.observe()
|
||||
live=self.live(rows)
|
||||
if any(self.owned[pid]['role']=='unresolved_inspection' or rows[pid].get('status')=='unknown' for pid in live):raise ProcessInspectionUnavailable()
|
||||
return rows
|
||||
except (ProcessInspectionUnavailable,subprocess.SubprocessError,OSError):
|
||||
self.inspection_failures+=1
|
||||
if self.clock()>=end:raise ProcessInspectionUnavailable() from None
|
||||
self.sleep(min(.1,end-self.clock()))
|
||||
def _signal(self,pid,sig,reason):
|
||||
if pid<=1 or pid==os.getpid():raise ProcessInspectionUnavailable()
|
||||
rows=self._fresh();live=self.live(rows)
|
||||
if pid not in live:return False
|
||||
if reason=='sole_graceful_owner' and pid not in self._owners(live,rows):return False
|
||||
role=self.owned[pid]['role']
|
||||
# Reclassify at every signal boundary, including exec under the same PID.
|
||||
database=self._postgres(live) or any(self.owned[p]['role']=='initdb' for p in live)
|
||||
if (sig==signal.SIGKILL or reason=='post_owner_non_database_fallback') and database:raise ProcessInspectionUnavailable()
|
||||
if role=='initdb' or (role.startswith('postgres_') and (sig!=signal.SIGINT or not self._verified_postmaster(pid))):raise ProcessInspectionUnavailable()
|
||||
action={'at':now(),'pid':pid,'started':self.owned[pid]['started'],'role':role,'signal':signal.Signals(sig).name,'reason':reason,'delivery':'pending'}
|
||||
with self.lock:self.actions.append(action);self._persist()
|
||||
try:self.send(pid,sig)
|
||||
except ProcessLookupError:
|
||||
with self.lock:action['delivery']='not_delivered_process_absent';self._persist()
|
||||
return False
|
||||
with self.lock:action['delivery']='delivered';self._persist()
|
||||
return True
|
||||
def _postgres(self,live):return {pid for pid in live if self.owned[pid]['role'].startswith('postgres_')}
|
||||
def _verified_postmaster(self,pid):
|
||||
rows=self.observe(); r=self.owned.get(pid)
|
||||
if not r or pid not in self.live(rows) or pid not in self.postmasters:return False
|
||||
root_stat=self.root.lstat()
|
||||
if (root_stat.st_dev,root_stat.st_ino,root_stat.st_uid)!=self.root_identity:return False
|
||||
data=self.postmasters[pid];file=data/'postmaster.pid'
|
||||
try:
|
||||
fd=os.open(file,os.O_RDONLY|os.O_NOFOLLOW)
|
||||
try:
|
||||
st=os.fstat(fd)
|
||||
if not stat.S_ISREG(st.st_mode) or st.st_uid!=os.getuid() or st.st_nlink!=1 or st.st_size>4096:return False
|
||||
lines=os.read(fd,4096).decode().splitlines()
|
||||
finally:os.close(fd)
|
||||
if int(lines[0])!=pid or pathlib.Path(lines[1]).resolve()!=data:return False
|
||||
started=time.mktime(time.strptime(r['started'],'%a %b %d %H:%M:%S %Y'))
|
||||
if abs(int(lines[2])-started)>2:return False
|
||||
return True
|
||||
except (OSError,ValueError,IndexError):return False
|
||||
def _wait(self,seconds,predicate):
|
||||
end=min(self.clock()+seconds,self.stop_deadline or float('inf'))
|
||||
while True:
|
||||
rows=self._fresh();live=self.live(rows)
|
||||
if predicate(live):return True
|
||||
if self.stop_deadline is not None and self.clock()>=self.stop_deadline-1e-9:raise ProcessInspectionUnavailable()
|
||||
if self.clock()>=end-1e-9:return False
|
||||
self.sleep(min(.1,end-self.clock()))
|
||||
def stop(self,root_pid=None):
|
||||
thread=threading.get_ident()
|
||||
with self.lock:
|
||||
if self.stopping:owner=self.stop_thread==thread
|
||||
else:
|
||||
self.stopping=True;self.stop_thread=thread;owner=None
|
||||
self.stop_deadline=self.clock()+STOP_DEADLINE_SECONDS
|
||||
if owner is not None:
|
||||
if not owner:self.stop_done.wait(timeout=STOP_DEADLINE_SECONDS+2)
|
||||
return self.stop_result or {'status':'cleanup_in_progress','remainingOwnedPids':None,'postgresKilled':False}
|
||||
try:
|
||||
return self._stop(root_pid)
|
||||
except (ProcessInspectionUnavailable,subprocess.SubprocessError,OSError):
|
||||
return self._finish('unresolved_process_inspection',None)
|
||||
finally:self.stop_done.set()
|
||||
def _finish(self,status,live):
|
||||
self.stop_result={'status':status,'remainingOwnedPids':sorted(live) if live is not None else None,
|
||||
'lastObservedOwnedPids':sorted(pid for pid,r in self.owned.items() if r['status']!='gone_or_identity_changed'),
|
||||
'inspectionComplete':live is not None,'postgresKilled':False,
|
||||
'cleanupDurationSeconds':round(self.clock()-(self.stop_deadline-STOP_DEADLINE_SECONDS),3),
|
||||
'cleanupDeadlineSeconds':STOP_DEADLINE_SECONDS}
|
||||
if self.clock()>self.stop_deadline:self.stop_result['status']='unresolved_cleanup_deadline'
|
||||
self._persist();return self.stop_result
|
||||
def _owners(self,live,rows):
|
||||
# Prefer a wrapper while a server/database is live. Its stopServer path
|
||||
# owns the single signal to the real server. Never broadcast to providers.
|
||||
wrappers={pid for pid in live if self.owned[pid]['role']=='product_server_supervisor'}
|
||||
if len(wrappers)>1:
|
||||
# tsx may expose both its launcher and inner Node worker as server.ts.
|
||||
# Accept only one current, identity-validated ancestry chain; signal
|
||||
# its deepest wrapper, which owns stopServer, never both wrappers.
|
||||
def ancestors(pid):
|
||||
seen=set()
|
||||
while pid in live:
|
||||
if pid in seen:raise ProcessInspectionUnavailable()
|
||||
seen.add(pid)
|
||||
current=rows.get(pid)
|
||||
if not current or current['started']!=self.owned[pid]['started']:raise ProcessInspectionUnavailable()
|
||||
pid=current['parent']
|
||||
return seen
|
||||
candidates={pid for pid in wrappers if wrappers.issubset(ancestors(pid))}
|
||||
if len(candidates)!=1:raise ProcessInspectionUnavailable()
|
||||
owner=next(iter(candidates))
|
||||
if any(owner not in ancestors(pid) for pid in live if self.owned[pid]['role']=='paperclip_server'):
|
||||
raise ProcessInspectionUnavailable()
|
||||
return {owner}
|
||||
if wrappers:return wrappers
|
||||
servers={pid for pid in live if self.owned[pid]['role']=='paperclip_server'}
|
||||
if servers:return servers
|
||||
if self._postgres(live) or any(self.owned[p]['role']=='initdb' for p in live):return set()
|
||||
if self.root_pid in live:return {self.root_pid}
|
||||
return {pid for pid in live if self.owned[pid]['parent'] not in live}
|
||||
def _stop(self,root_pid=None):
|
||||
with self.lock:
|
||||
if self.root_pid is None:self.root_pid=root_pid
|
||||
app_grace,pg_grace,root_grace,kill_grace=self.budgets
|
||||
live=self.live(self._fresh())
|
||||
if not live:return self._finish('stopped',live)
|
||||
delivered=set();selection_end=min(self.clock()+INSPECTION_RETRY_SECONDS,self.stop_deadline)
|
||||
while not delivered:
|
||||
rows=self._fresh();live=self.live(rows)
|
||||
if not live:return self._finish('stopped',live)
|
||||
owners=self._owners(live,rows)
|
||||
if not owners:return self._finish('unresolved_database_owner',live)
|
||||
for pid in sorted(owners):
|
||||
if self._signal(pid,signal.SIGTERM,'sole_graceful_owner'):
|
||||
delivered.add(pid);break
|
||||
if not delivered:
|
||||
if self.clock()>=selection_end:return self._finish('unresolved_graceful_owner_delivery',self.live(self._fresh()))
|
||||
self.sleep(min(.1,selection_end-self.clock()))
|
||||
owners=delivered # Never signal a nested owner after any successful delivery.
|
||||
# Even an early root exit does not shorten this window for retained children.
|
||||
if self._wait(app_grace,lambda live:not live):return self._finish('stopped',set())
|
||||
live=self.live(self._fresh())
|
||||
if any(self.owned[p]['role']=='initdb' for p in live):return self._finish('unresolved_database_initialization',live)
|
||||
pg=self._postgres(live)
|
||||
for pid in sorted(pg):
|
||||
if self._verified_postmaster(pid):self._signal(pid,signal.SIGINT,'verified_postmaster_fast_shutdown')
|
||||
if pg and not self._wait(pg_grace,lambda live:not self._postgres(live)):
|
||||
return self._finish('unresolved_postgres_shutdown',self.live(self._fresh()))
|
||||
live=self.live(self._fresh())
|
||||
if any(self.owned[p]['role']=='initdb' for p in live):return self._finish('unresolved_database_initialization',live)
|
||||
# Inner owner had its full50s. Only now request remaining non-DB exits.
|
||||
for pid in sorted(live):
|
||||
if pid in owners or self.owned[pid]['role'] in ('paperclip_server','product_server_supervisor','product_launcher'):continue
|
||||
self._signal(pid,signal.SIGTERM,'post_owner_non_database_fallback')
|
||||
if self._wait(root_grace,lambda live:not live):return self._finish('stopped',set())
|
||||
live=self.live(self._fresh())
|
||||
if self._postgres(live) or any(self.owned[p]['role']=='initdb' for p in live):return self._finish('unresolved_late_database',live)
|
||||
for pid in sorted(live,reverse=True):self._signal(pid,signal.SIGKILL,'revalidated_non_database_fallback')
|
||||
self._wait(kill_grace,lambda live:not live)
|
||||
live=self.live(self._fresh())
|
||||
return self._finish('stopped' if not live else 'unresolved_owned_processes',live)
|
||||
@@ -0,0 +1,190 @@
|
||||
{
|
||||
"profiles": {
|
||||
"cursor": {
|
||||
"path": "packages/paperclip-runner/test/fixtures/cursor-acp/profile-v10-identity.json",
|
||||
"sha256": "86fbb9653fe2bfc911ed55af57cc461216197f070f504dc22a9a8dd325c0f3d9",
|
||||
"version": 10,
|
||||
"digest": "sha256:1df2a15b93bc3a14fa47fa3315344ba023fe2412048047cdc6f32096a6336564"
|
||||
},
|
||||
"copilot": {
|
||||
"path": "packages/paperclip-runner/test/fixtures/copilot-profile-v12-identity.json",
|
||||
"sha256": "5d9dc0d3cf2385315b13180af5431a3e1d90ccaa5653b7093a749ef12c2dfe3c",
|
||||
"version": 12,
|
||||
"digest": "sha256:48cecd8dc77a5533240fcf2f29d19be05380da4a79f8e5061480f94241db75a8"
|
||||
},
|
||||
"pi": {
|
||||
"path": "packages/paperclip-runner/test-fixtures/pi-acp/profile-v11-identity.json",
|
||||
"sha256": "7b253e94b1672dff0e7a4f4a50f3bb2270038d14f1ef27857f8bef67b9800a7f",
|
||||
"version": 11,
|
||||
"digest": "sha256:5e276f48c8a87b3e6165369faac62d3925282c84b98934575b1b7b97ad50b309"
|
||||
}
|
||||
},
|
||||
"candidateClosureDigests": {
|
||||
"cursor": {
|
||||
"darwin-arm64": "sha256:257424bd48e35412091c6adfc61e4648e836757ec1d240d890bba81a24918c30",
|
||||
"darwin-x64": "sha256:6f28c799c5afdc64fbdff8a2157f565f17ae7615efe014ac389d63bf70cf2be2",
|
||||
"linux-x64": "sha256:eadb8bb8ffb0450455b15b88c9b230307a9e149958a0c452d16dd157b4633d74"
|
||||
},
|
||||
"copilot": {
|
||||
"darwin-arm64": "sha256:362f2663e967fb9e34a814bac4619cbf89e6b23069c4051ab1f2f686852d0a32",
|
||||
"darwin-x64": "sha256:c08b7c3dd4e7bcf9a3e16ec6eba29cfa10308e865d196c5f120a3a15f6b3116a",
|
||||
"linux-x64": "sha256:a3d8f4367cfa1694d79e3f8b7930b6fbfe42a229c272b375b11951d631db8d07"
|
||||
},
|
||||
"pi": {
|
||||
"darwin-arm64": "sha256:a3e43c23f9603983a59fd256ca1dcf8bbd5cc2728dad095f7bcd3b3e62278597",
|
||||
"darwin-x64": "sha256:8c6e7802d47da9410af56e367f6cf7af572fcbf3e361627cee026e8cffc9bdd3",
|
||||
"linux-x64": "sha256:40e186c53db60d1ab5673ba34f33002e93cea518725a93395d241393b984caef"
|
||||
}
|
||||
},
|
||||
"additionalSourceFiles": {
|
||||
"packages/paperclip-runner/test/fixtures/copilot-message-identity-distributions-1.0.88.json": "7e1534d668a3db7acae15377b67d86fa80cc21ce699d021709b0b52ad314cfb2",
|
||||
"patches/pi-acp@0.0.33.patch": "429184a462f9acef5bef890f3537db3ef385ee7c06d9fe0c335158590005ab0a",
|
||||
"packages/paperclip-runner/scripts/pi-distribution/package.json": "c14f4050ef27dca91d3650e7446bc9927296a926224dba50a0e02f5d9fd4d95b",
|
||||
"packages/paperclip-runner/scripts/pi-distribution/package-lock.json": "f4b04d51c4d91a6529dc97af2f3f84c28a220d93a54b5555826c4d9fd30f0939",
|
||||
"packages/paperclip-runner/scripts/materialize-pi-distribution.mjs": "39bd8cc48791f8e54a953c7803334b965b9998943b0402008438d565ea2230be",
|
||||
"packages/paperclip-runner/scripts/build-node-startup-timeout.mjs": "545dbaf7062b1cd54176dafe3feb8877e5ccf19406f791172a3ad47dbfd73fc4",
|
||||
"packages/paperclip-runner/src/drivers/acpx/pi-acp-runtime.ts": "a0ec66a03cd9fa32e9aaafc4ac6840115883333000fd079ccba230706b763ac0",
|
||||
"packages/paperclip-runner/src/drivers/acpx/pi-runtime-extension.ts": "f3446be10d984c368c52202e768aefe9b4a25968e09922e98e3f016c9dc0198e",
|
||||
"packages/paperclip-runner/src/drivers/acpx/pi-verified-runtime.ts": "6a08420964ac3f8c91a248b90098cd025a47612ed4060de43db30d1ef80be296",
|
||||
"packages/paperclip-runner/src/drivers/acpx/pi-node-pins.ts": "ffc822aff64db315e461cbe44f03d704695de4a4296f643af79386c3556a1d46",
|
||||
"packages/paperclip-runner/src/drivers/acpx/pi-closure-pins.ts": "0941f56ea13b8eb309a345d2a1513e0ec53d201c81c755b356565505bc1df905",
|
||||
"packages/paperclip-runner/src/drivers/acpx/qualified-profiles.ts": "20185223c77ce6d5b67b270abdc0debc26166c7d3dd412a1ecea83f980429027",
|
||||
"packages/paperclip-runner/package.json": "a87426b0184e114e46c6f4ddbf3f4a9727cd591cf0a5ca900efde42198190fd1"
|
||||
},
|
||||
"permissionPolicySources": {
|
||||
"packages/paperclip-runner/src/drivers/acpx/copilot-permission-context.ts": {
|
||||
"declarationField": "permissionContextSourceSha256",
|
||||
"sha256": "fe1bb611bea289d81b1c7c973fbb01b93de133a7caa8fe78b7ff4ee1f485b224"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/acp-permission-adapter.ts": {
|
||||
"declarationField": "permissionAdapterSourceSha256",
|
||||
"sha256": "49421a779c76e286ce65d75052026eab9630b1995af9ccf045a2d43d284633ce"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/safe-locations.ts": {
|
||||
"declarationField": "permissionLocationsSourceSha256",
|
||||
"sha256": "f39a81da395b6e23aa2a1a45572a28846e5e81bfd3d764d9a456f74a79c752e9"
|
||||
},
|
||||
"packages/paperclip-runner/src/semantic-tools/redaction.ts": {
|
||||
"declarationField": "permissionRedactionSourceSha256",
|
||||
"sha256": "687270d7bbe3dccce6c2fed8664e76cda724b43e545cb153b9f54b018de52927"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/generated-sidecar-contract.ts": {
|
||||
"declarationField": "permissionClassifierSourceSha256",
|
||||
"sha256": "1161eabd82e26133e3b3db3ab567f65d52808b03f176e93497e02c8330349fb4"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/cursor-plan-tool-identity.ts": {
|
||||
"declarationField": "permissionIdentitySourceSha256",
|
||||
"sha256": "770b47305e571a81f344883057d0e4a482a1cd59ac77d045836593a8e739deb1"
|
||||
}
|
||||
},
|
||||
"semanticReceiptSources": {
|
||||
"packages/paperclip-runner/src/drivers/semantic-tool-receipt.ts": {
|
||||
"declarationField": "semanticReceiptSourceSha256",
|
||||
"sha256": "b2795726b2234a663fec1a6ca11f0551ae69882fe9e82aa39686e952d036e791"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/runner-tool-bridge.ts": {
|
||||
"declarationField": "semanticBridgeSourceSha256",
|
||||
"sha256": "8a43ebafb7a85dd1714ed6945670472666dcb63e8af32b4a74644163fa0e370d"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/copilot-tool-evidence.ts": {
|
||||
"declarationField": "toolEvidenceSourceSha256",
|
||||
"sha256": "4b517eed447615b3cc820af348ccc360978175149caa0bbc838d1f78332abe75"
|
||||
},
|
||||
"packages/paperclip-runner/src/cli/acpx-runtime-sidecar.ts": {
|
||||
"declarationField": "semanticSidecarSourceSha256",
|
||||
"sha256": "d58076d59ec23fe2261cba3aa0dca3e9f189105f0a5fa7ca3eeaac05cb338f31"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/sidecar-protocol.ts": {
|
||||
"declarationField": "semanticSidecarProtocolSourceSha256",
|
||||
"sha256": "165cad76f224d60f0dc7928736d47a16787eaa8ab9e4c2222488da5fc8ad632e"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/codex-acpx-driver.ts": {
|
||||
"declarationField": "semanticDirectDriverSourceSha256",
|
||||
"sha256": "31e36917ee3592fa6d8f4b86632129fdffae20c45aed2e0e367ccf523e064f88"
|
||||
},
|
||||
"packages/paperclip-runner/src/protocol/replay-contract.ts": {
|
||||
"declarationField": "semanticValidationSourceSha256",
|
||||
"sha256": "039fca52266fe21ba74ca64660d21228314d8ed737b19ba67941bfb25086e4d5"
|
||||
},
|
||||
"packages/paperclip-runner/src/protocol/result-normalization.ts": {
|
||||
"declarationField": "semanticNormalizationSourceSha256",
|
||||
"sha256": "b1ce59251bf9c671f66e0e5173646190b9a2d1bfc5bdb7fb123824213986b92b"
|
||||
},
|
||||
"packages/paperclip-runner/src/contracts/completion-result.ts": {
|
||||
"declarationField": "semanticCompletionContractSourceSha256",
|
||||
"sha256": "00a684f9aea87f68eabf0974681c52461bc308631a1252a89c4ed087d7158b28"
|
||||
},
|
||||
"packages/paperclip-runner/src/protocol/generated/standalone-validators.ts": {
|
||||
"declarationField": "semanticValidatorsSourceSha256",
|
||||
"sha256": "950b49b233d8dd62ff858398becfc55f0a181160cb8a434d9221b5c17816867c"
|
||||
},
|
||||
"packages/paperclip-runner/src/protocol/generated/schema-bundle.ts": {
|
||||
"declarationField": "semanticSchemaBundleSourceSha256",
|
||||
"sha256": "bb55e18c5563bf5ec226e301c3399229304f295e986865e96554f193535368f2"
|
||||
}
|
||||
},
|
||||
"cursorIdentitySources": {
|
||||
"packages/paperclip-runner/src/drivers/acpx/cursor-plan-tool-identity.ts": {
|
||||
"declarationField": "toolIdentitySourceSha256",
|
||||
"sha256": "770b47305e571a81f344883057d0e4a482a1cd59ac77d045836593a8e739deb1"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/acp-permission-adapter.ts": {
|
||||
"declarationField": "permissionAdapterSourceSha256",
|
||||
"sha256": "49421a779c76e286ce65d75052026eab9630b1995af9ccf045a2d43d284633ce"
|
||||
},
|
||||
"packages/paperclip-runner/src/drivers/acpx/cursor-tool-evidence.ts": {
|
||||
"declarationField": "toolEvidenceSourceSha256",
|
||||
"sha256": "8310308ed9605415cb28b7c350d83defef68e90cd30bc2f0491d3d09825e8cd9"
|
||||
}
|
||||
},
|
||||
"cursorDistribution": {
|
||||
"path": "packages/paperclip-runner/cursor-distributions.json",
|
||||
"sha256": "b8a56cc54b8f5ab7a21451a3b9083726d93dd018fff0c4a0dbce851a6b1949ec",
|
||||
"value": {
|
||||
"schema": "paperclip.cursor_distribution.v1",
|
||||
"version": "2026.09.26-dd393fe",
|
||||
"platforms": {
|
||||
"darwin-arm64": {
|
||||
"url": "https://downloads.cursor.com/lab/2026.09.26-dd393fe/darwin/arm64/agent-cli-package.tar.gz",
|
||||
"archiveSha256": "538827d96a779bab854a865c8e42859e8e87db34b5f69770261b90fc8cfff191",
|
||||
"closureSha256": "257424bd48e35412091c6adfc61e4648e836757ec1d240d890bba81a24918c30",
|
||||
"executable": "node",
|
||||
"entrypoint": "index.js",
|
||||
"vendorClosureSha256": "77394184a89b0e7384971181da19c3c82d83a399b04e7944b3f94fe3d7e62b25"
|
||||
},
|
||||
"darwin-x64": {
|
||||
"url": "https://downloads.cursor.com/lab/2026.09.26-dd393fe/darwin/x64/agent-cli-package.tar.gz",
|
||||
"archiveSha256": "ed1771c44cbf0f8059c67cac0d939e6a60eb730bd066d7dc4cbb14de314cfb6e",
|
||||
"closureSha256": "6f28c799c5afdc64fbdff8a2157f565f17ae7615efe014ac389d63bf70cf2be2",
|
||||
"executable": "node",
|
||||
"entrypoint": "index.js",
|
||||
"vendorClosureSha256": "7c8775160af74e5fb8d25a30e8412c1a6476b0661529078a686e5118fd1c5e5f"
|
||||
},
|
||||
"linux-x64": {
|
||||
"url": "https://downloads.cursor.com/lab/2026.09.26-dd393fe/linux/x64/agent-cli-package.tar.gz",
|
||||
"archiveSha256": "8085fd120f5c71f4eae7fea26a043718e5644e3071e4fab3220a0e58c51f9593",
|
||||
"closureSha256": "eadb8bb8ffb0450455b15b88c9b230307a9e149958a0c452d16dd157b4633d74",
|
||||
"executable": "node",
|
||||
"entrypoint": "index.js",
|
||||
"vendorClosureSha256": "bf04ef8ea6a63191067a6b3e15139aa2c793d8419daab246aa3f0a012e1bbcd9"
|
||||
}
|
||||
},
|
||||
"patchVersion": "paperclip-cursor-usage-v4"
|
||||
}
|
||||
},
|
||||
"localComparison": {
|
||||
"sourceRevision": "5eba61ece929dcfb2b0c1761825a2d9e557c2554",
|
||||
"sourceArchiveSha256": "f751f86b19701757d30501e39d47fe7d20a102e32f9e4c4df585074393e85237",
|
||||
"trackedLockSha256": "e11d69fa8702a906c293c1cb307c71df90d3b1f1617b3c23ebf17fa9a87fec79",
|
||||
"resolvedLockSha256": "38338a6867358440c5ab5993eaeb85fb501bc7df65d24acf52fbd63c880ee4ba",
|
||||
"nodeSha256": "7abcf39bd37ab251015337ff75304d7555f0d8e88c6e0fbf04bce8ce34636f49",
|
||||
"model": "openrouter/deepseek/deepseek-v4-flash-0731",
|
||||
"piRuntimeVersion": "1.0.0",
|
||||
"piServerVersion": "0.0.33",
|
||||
"acpxVersion": "0.13.1",
|
||||
"localPackDigest": "sha256:a7ae16b680c6fcaa9438faa46562ba31519bb0fb42e21b0a4b00e8936c462d89",
|
||||
"localDaemonSha256": "c0e9acdd461d5efe4a10f9fd751e8a67beceede4d43593951d7079edad657044",
|
||||
"localBuildReceiptSha256": "f9bdef008c11d30e89da20588e750df7689d4f5f7400ce3723fb467d82c53581",
|
||||
"note": "CI pack/daemon are fresh outputs; compare frozen inputs and native closure, not local output digests."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Observe only this test's final cleanup; source, assertions, and runtime stay unchanged.
|
||||
import fs from 'node:fs';
|
||||
import { syncBuiltinESMExports } from 'node:module';
|
||||
import { basename, dirname, resolve } from 'node:path';
|
||||
const original = fs.promises.rm;
|
||||
const owner = fs.realpathSync(process.env.PI_INTEL_OWNED_TMP);
|
||||
const retained = fs.realpathSync(process.env.PI_INTEL_RETAINED_STATE);
|
||||
fs.promises.rm = async function (path, options) {
|
||||
const absolute = typeof path === 'string' ? resolve(path) : null;
|
||||
if (!absolute || dirname(absolute) !== owner || !basename(absolute).startsWith('pi-closed-startup-')) {
|
||||
return original.call(this, path, options);
|
||||
}
|
||||
const info = await fs.promises.lstat(absolute);
|
||||
if (!info.isDirectory() || info.isSymbolicLink() || info.uid !== process.getuid()) {
|
||||
throw new Error('Refusing unowned Pi startup retention path');
|
||||
}
|
||||
try {
|
||||
await fs.promises.cp(absolute, `${retained}/${basename(absolute)}`, {
|
||||
recursive: true, errorOnExist: true, force: false, dereference: false,
|
||||
});
|
||||
} finally {
|
||||
// Capturing evidence must never prevent the original test's cleanup.
|
||||
await original.call(this, path, options);
|
||||
}
|
||||
};
|
||||
syncBuiltinESMExports();
|
||||
@@ -0,0 +1,99 @@
|
||||
"""Private build source admission; no execution on import."""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import stat
|
||||
import subprocess
|
||||
|
||||
ASSETS = 'packages/paperclip-runner/provider-assets'
|
||||
|
||||
def require(value, message):
|
||||
if not value:
|
||||
raise RuntimeError(message)
|
||||
|
||||
def sha(path):
|
||||
digest = hashlib.sha256()
|
||||
with Path(path).open('rb') as stream:
|
||||
for chunk in iter(lambda: stream.read(1024 * 1024), b''):
|
||||
digest.update(chunk)
|
||||
return digest.hexdigest()
|
||||
|
||||
def tree(root, allow_links=False):
|
||||
root = Path(root)
|
||||
require(root.is_dir() and not root.is_symlink(), 'Missing or linked inventory root')
|
||||
result = []
|
||||
for path in sorted(root.rglob('*')):
|
||||
info = path.lstat()
|
||||
item = {'path': path.relative_to(root).as_posix(), 'mode': stat.S_IMODE(info.st_mode)}
|
||||
if stat.S_ISLNK(info.st_mode):
|
||||
require(allow_links and path.resolve(strict=True).is_relative_to(root.resolve()), 'Inventory symlink escaped or forbidden')
|
||||
item.update(kind='symlink', target=os.readlink(path))
|
||||
elif stat.S_ISDIR(info.st_mode):
|
||||
item.update(kind='directory')
|
||||
else:
|
||||
require(stat.S_ISREG(info.st_mode) and info.st_nlink == 1, 'Inventory requires private regular files')
|
||||
item.update(kind='file', sha256=sha(path), size=info.st_size)
|
||||
result.append(item)
|
||||
return result
|
||||
|
||||
def verify_pack(pack, source, pins):
|
||||
pack = Path(pack)
|
||||
manifest = json.loads((pack / 'provider-pack.json').read_text())
|
||||
payload = manifest['payload']
|
||||
canonical = json.dumps(payload, sort_keys=True, separators=(',', ':'), ensure_ascii=False).encode()
|
||||
require(manifest['digest'] == 'sha256:' + hashlib.sha256(canonical).hexdigest(), 'Pack canonical digest mismatch')
|
||||
require(payload['runnerSourceRevision'] == source, 'Pack source mismatch')
|
||||
for agent, (_, digest) in pins.items():
|
||||
require(payload['candidateProviders'][agent]['profileDigest'] == digest, 'Pack candidate mismatch')
|
||||
def check(value):
|
||||
if isinstance(value, dict):
|
||||
if isinstance(value.get('path'), str) and isinstance(value.get('sha256'), str):
|
||||
relative = Path(value['path'])
|
||||
require(not relative.is_absolute() and '..' not in relative.parts, 'Unsafe pack artifact path')
|
||||
path = pack / relative
|
||||
require(path.resolve(strict=True).is_relative_to(pack.resolve()), 'Pack artifact escaped')
|
||||
require('sha256:' + sha(path) == value['sha256'], 'Pack artifact hash mismatch')
|
||||
for child in value.values():
|
||||
check(child)
|
||||
elif isinstance(value, list):
|
||||
for child in value:
|
||||
check(child)
|
||||
check(payload)
|
||||
return manifest
|
||||
|
||||
def verify_authority(stage, pack, expected):
|
||||
"""Recompute every byte before the generated-directory source exception."""
|
||||
stage, pack = Path(stage), Path(pack)
|
||||
require(expected is not None, 'Generated assets require a captured immutable inventory')
|
||||
require(tree(pack, allow_links=True) == expected['pack'], 'Immutable pack inventory drift')
|
||||
require(tree(stage / 'packages/paperclip-runner/dist') == expected['dist'], 'Controller dist inventory drift')
|
||||
assets = tree(stage / ASSETS)
|
||||
require(assets == expected['assets'] == tree(pack / 'provider-assets'), 'Generated asset inventory drift')
|
||||
# Every packed dist file must match the actual local controller copy.
|
||||
for item in tree(pack / 'dist'):
|
||||
if item['kind'] == 'file':
|
||||
path = stage / 'packages/paperclip-runner/dist' / item['path']
|
||||
require(sha(path) == item['sha256'], 'Packed/controller dist mismatch')
|
||||
|
||||
def verify_source(stage, source, lock_sha, pack=None, authority=None):
|
||||
stage = Path(stage)
|
||||
head = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=stage, text=True).strip()
|
||||
require(head == source, 'Stage HEAD changed')
|
||||
require(sha(stage / 'pnpm-lock.yaml') == lock_sha, 'Private overlay changed')
|
||||
generated = os.path.lexists(stage / ASSETS)
|
||||
if generated:
|
||||
require(pack is not None, 'Generated assets cannot be admitted before pack inventory')
|
||||
verify_authority(stage, pack, authority)
|
||||
else:
|
||||
require(authority is None, 'Verified generated authority disappeared')
|
||||
status = subprocess.check_output(['git', 'status', '--porcelain=v1', '-z', '--untracked-files=all'], cwd=stage)
|
||||
entries = [entry.decode('utf8') for entry in status.split(b'\0') if entry]
|
||||
require(' M pnpm-lock.yaml' in entries, 'Expected unstaged private lock overlay missing')
|
||||
for entry in entries:
|
||||
if entry == ' M pnpm-lock.yaml':
|
||||
continue
|
||||
require(generated and entry.startswith('?? ' + ASSETS + '/'), 'Unexpected source/untracked change')
|
||||
path = entry[3:]
|
||||
require(path in {ASSETS + '/' + row['path'] for row in authority['assets'] if row['kind'] == 'file'}, 'Untracked asset is outside verified inventory')
|
||||
return {'head': head, 'lockSha256': lock_sha, 'generatedAssetsAdmitted': generated, 'statusEntries': entries}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { createRequire } from 'node:module';
|
||||
import { readFileSync, readdirSync, readlinkSync, lstatSync, realpathSync } from 'node:fs';
|
||||
import { resolve, relative, isAbsolute, join } from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
export function requireTrue(value, message) { if (!value) throw new Error(message); }
|
||||
export function canonicalJson(value) {
|
||||
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;
|
||||
if (value !== null && typeof value === 'object') return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(',')}}`;
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
export function sha256File(path) { return `sha256:${createHash('sha256').update(readFileSync(path)).digest('hex')}`; }
|
||||
// Exactly the frozen builder's tree framing and localeCompare ordering.
|
||||
export function sha256Tree(root) {
|
||||
const hash = createHash('sha256');
|
||||
const visit = (directory, prefix = '') => {
|
||||
for (const entry of readdirSync(directory, { withFileTypes: true }).sort((a,b) => a.name.localeCompare(b.name))) {
|
||||
const p = prefix ? `${prefix}/${entry.name}` : entry.name;
|
||||
const absolute = join(directory, entry.name);
|
||||
if (entry.isDirectory()) { hash.update(`directory\0${p}\n`); visit(absolute, p); }
|
||||
else if (entry.isFile()) hash.update(`file\0${p}\0${sha256File(absolute)}\n`);
|
||||
else if (entry.isSymbolicLink()) hash.update(`symlink\0${p}\0${readlinkSync(absolute)}\n`);
|
||||
else throw new Error('Unsupported entry');
|
||||
}
|
||||
};
|
||||
visit(root); return `sha256:${hash.digest('hex')}`;
|
||||
}
|
||||
function contained(root, candidate) {
|
||||
const rel = relative(realpathSync(root), realpathSync(candidate));
|
||||
requireTrue(rel !== '..' && !rel.startsWith('../') && !isAbsolute(rel), 'Artifact escaped pack');
|
||||
}
|
||||
export function checkedArtifact(pack, entry, kind) {
|
||||
requireTrue(typeof entry?.path === 'string' && /^sha256:[a-f0-9]{64}$/.test(entry?.sha256), 'Malformed artifact');
|
||||
requireTrue(!isAbsolute(entry.path) && !entry.path.split('/').includes('..'), 'Unsafe artifact path');
|
||||
const path = resolve(pack, entry.path); contained(pack, path);
|
||||
const st = lstatSync(path);
|
||||
requireTrue(kind === 'directory' ? st.isDirectory() && !st.isSymbolicLink() : st.isFile() || st.isSymbolicLink(), 'Artifact type mismatch');
|
||||
const actual = kind === 'directory' ? sha256Tree(path) : sha256File(path);
|
||||
requireTrue(actual === entry.sha256, 'Artifact bytes mismatch: ' + entry.path);
|
||||
return { path: entry.path, kind, sha256: actual };
|
||||
}
|
||||
export function verifyPack(pack, source, platform, architecture) {
|
||||
const manifest = JSON.parse(readFileSync(join(pack, 'provider-pack.json')));
|
||||
const p = manifest.payload;
|
||||
requireTrue(manifest.schema === 'paperclip-runner/remote-provider-pack/v1', 'Wrong schema');
|
||||
requireTrue(manifest.digest === `sha256:${createHash('sha256').update(canonicalJson(p)).digest('hex')}`, 'Canonical manifest mismatch');
|
||||
requireTrue(p.runnerSourceRevision === source, 'Wrong source');
|
||||
requireTrue(p.target.platform === platform && p.target.architecture === architecture, 'Wrong target');
|
||||
const pins = { cursor: '1df2a15b93bc3a14fa47fa3315344ba023fe2412048047cdc6f32096a6336564', copilot: '48cecd8dc77a5533240fcf2f29d19be05380da4a79f8e5061480f94241db75a8', pi: '5e276f48c8a87b3e6165369faac62d3925282c84b98934575b1b7b97ad50b309' };
|
||||
requireTrue(Object.keys(p.candidateProviders).sort().join(',') === Object.keys(pins).sort().join(','), 'Wrong candidate set');
|
||||
const closurePins = JSON.parse(readFileSync(new URL('./profile-inputs.json', import.meta.url))).candidateClosureDigests;
|
||||
const checks = [];
|
||||
for (const [agent, digest] of Object.entries(pins)) {
|
||||
const c = p.candidateProviders[agent];
|
||||
requireTrue(c.profileDigest === 'sha256:' + digest && c.qualification === 'pending', 'Candidate identity mismatch');
|
||||
requireTrue(c.path === `provider-assets/${agent}/${platform}-${architecture}`, 'Unexpected candidate path');
|
||||
requireTrue(c.closureDigest === closurePins[agent]?.[`${platform}-${architecture}`], 'Native closure pin mismatch');
|
||||
checks.push(checkedArtifact(pack, c, 'directory'));
|
||||
}
|
||||
for (const entry of Object.values(p.artifacts)) checks.push(checkedArtifact(pack, entry, 'file'));
|
||||
requireTrue(sha256Tree(join(pack, 'dist')) === p.distDigest, 'Packed dist mismatch');
|
||||
const bridge = createHash('sha256').update(p.artifacts.opencodeProxy.sha256).update('\n').update(p.artifacts.acpxSidecar.sha256).update('\n').update(p.distDigest).digest('hex');
|
||||
requireTrue('sha256:' + bridge === p.bridgeDigest, 'Bridge mismatch');
|
||||
const r = createRequire(join(pack, 'package.json'));
|
||||
const acpx = r.resolve('acpx/package.json');
|
||||
const sdk = createRequire(acpx).resolve('@agentclientprotocol/sdk');
|
||||
requireTrue(JSON.parse(readFileSync(acpx)).version === '0.13.1' && sdk.includes('@agentclientprotocol+sdk@1.4.0_'), 'Wrong production ACPX/SDK');
|
||||
contained(pack, acpx); contained(pack, sdk);
|
||||
return { manifestDigest: manifest.digest, checks, distDigest: p.distDigest, bridgeDigest: p.bridgeDigest, acpx, sdk, target: p.target, sourceRevision: source };
|
||||
}
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
||||
requireTrue(process.argv.length === 6, 'Expected pack source platform architecture');
|
||||
console.log(JSON.stringify(verifyPack(...process.argv.slice(2))));
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Frozen Pi1 native Intel qualification evidence; no keys, prompts, or publication."""
|
||||
import argparse,datetime,difflib,hashlib,json,os,platform,shutil,signal,subprocess,sys,tempfile,time
|
||||
from pathlib import Path
|
||||
from closed_inventory import closed_tree
|
||||
from owned_processes import OwnedProcesses,atomic_json
|
||||
import source_guard
|
||||
|
||||
HERE=Path(__file__).resolve().parent
|
||||
INPUTS=json.loads((HERE/'profile-inputs.json').read_text())
|
||||
PIN=INPUTS['localComparison']
|
||||
SOURCE=PIN['sourceRevision']
|
||||
sha=source_guard.sha
|
||||
require=source_guard.require
|
||||
|
||||
def execute(args):
|
||||
stage=args.source.resolve(strict=True);out=args.output.resolve()
|
||||
out.mkdir(mode=0o700,parents=True,exist_ok=False)
|
||||
scratch=Path(tempfile.mkdtemp(prefix='pc-intel-',dir='/private/tmp'));scratch.chmod(0o700)
|
||||
identity=(scratch.stat().st_dev,scratch.stat().st_ino,scratch.stat().st_uid)
|
||||
receipt={'status':'running','sourceRevision':SOURCE,'trustedWorkflowRevision':os.environ['GITHUB_WORKFLOW_SHA'],
|
||||
'startedAt':datetime.datetime.now(datetime.timezone.utc).isoformat(),'runId':os.environ['GITHUB_RUN_ID'],'runAttempt':os.environ['GITHUB_RUN_ATTEMPT'],
|
||||
'runnerLabel':'macos-15-intel','hostIsBareMetalClaim':False,'providerCalls':0,'credentialsRead':False,
|
||||
'providerPromptsSubmitted':0,'imagePublications':0,'cloudSandboxesCreated':0,'automaticRetries':0,
|
||||
'model':PIN['model'],'commands':[],'helpers':{p.name:sha(p) for p in HERE.iterdir() if p.is_file()},
|
||||
'originalTestSourceUnmodified':True,'cleanupObserverUsed':True,'localComparison':PIN}
|
||||
def save():atomic_json(out/'receipt.json',receipt)
|
||||
save()
|
||||
inherited_path=os.environ['PATH']
|
||||
node=Path(shutil.which('node')).resolve(strict=True)
|
||||
pnpm=Path(shutil.which('pnpm')).resolve(strict=True)
|
||||
rustup=Path(shutil.which('rustup')).resolve(strict=True)
|
||||
env={'PATH':inherited_path,'HOME':str(scratch/'home'),'TMPDIR':str(scratch),'LANG':'en_US.UTF-8','CI':'true',
|
||||
'PAPERCLIP_TELEMETRY_ENABLED':'false','PAPERCLIP_RUNNER_SOURCE_REVISION':SOURCE,
|
||||
'CARGO_HOME':str(scratch/'cargo'),'RUSTUP_HOME':str(scratch/'rustup'),'CARGO_TARGET_DIR':str(scratch/'target'),
|
||||
'RUSTUP_TOOLCHAIN':'1.97.1','CARGO_BUILD_JOBS':'2','npm_config_audit':'false','npm_config_fund':'false',
|
||||
'npm_config_update_notifier':'false','npm_config_package_import_method':'copy'}
|
||||
Path(env['HOME']).mkdir(mode=0o700)
|
||||
active=None;owner=None;cleanup_ok=True
|
||||
def stop_signal(signum,_):raise InterruptedError('CI stopped with signal '+str(signum))
|
||||
signal.signal(signal.SIGTERM,stop_signal)
|
||||
def run(command,label,timeout,cwd=stage,command_env=None,owned=False):
|
||||
nonlocal active,owner,cleanup_ok
|
||||
row={'label':label,'startedAt':datetime.datetime.now(datetime.timezone.utc).isoformat(),'command':list(map(str,command)),'deadlineSeconds':timeout,'status':'running'}
|
||||
receipt['commands'].append(row);save();start=time.monotonic()
|
||||
with (out/(label+'.log')).open('x') as log:
|
||||
try:
|
||||
active=subprocess.Popen(row['command'],cwd=cwd,env=command_env or env,stdout=log,stderr=log,start_new_session=True)
|
||||
if owned:cleanup_ok=False;owner=OwnedProcesses(out/(label+'-processes.json'),scratch,stage,pack/'dist/cli/acpx-runtime-sidecar.cjs')
|
||||
while active.poll() is None:
|
||||
if owner:owner.observe(active.pid)
|
||||
require(time.monotonic()-start<timeout,'Command deadline exceeded: '+label)
|
||||
time.sleep(.1 if owner else .5)
|
||||
if owner:owner.observe(active.pid)
|
||||
finally:
|
||||
if active:
|
||||
if owner:
|
||||
shutdown=owner.stop(active.pid);row['shutdown']=shutdown
|
||||
cleanup_ok=shutdown['status']=='stopped' and not owner.live()
|
||||
require(cleanup_ok,'Owned descendants remain')
|
||||
elif active.poll() is None:
|
||||
require(os.getpgid(active.pid)==active.pid,'Process group identity changed')
|
||||
os.killpg(active.pid,signal.SIGTERM)
|
||||
try:active.wait(timeout=15)
|
||||
except subprocess.TimeoutExpired:os.killpg(active.pid,signal.SIGKILL)
|
||||
active.wait(timeout=10)
|
||||
row.update(exitCode=active.returncode,durationSeconds=round(time.monotonic()-start,3),logSha256=sha(out/(label+'.log')),status='passed' if active.returncode==0 else 'failed')
|
||||
active=None;owner=None;save()
|
||||
require(row['exitCode']==0,'Command failed without retry: '+label)
|
||||
return (out/(label+'.log')).read_text()
|
||||
def source_inventory():
|
||||
names=subprocess.check_output(['git','ls-files','-z'],cwd=stage).split(b'\0')
|
||||
return {os.fsdecode(n):sha(stage/os.fsdecode(n)) for n in names if n and (stage/os.fsdecode(n)).is_file()}
|
||||
try:
|
||||
require(platform.system()=='Darwin' and platform.machine()=='x86_64','Native Intel macOS required')
|
||||
translated=subprocess.run(['/usr/sbin/sysctl','-in','sysctl.proc_translated'],capture_output=True,text=True)
|
||||
arm=subprocess.run(['/usr/sbin/sysctl','-in','hw.optional.arm64'],capture_output=True,text=True)
|
||||
require(translated.stdout.strip() in ('','0') and arm.stdout.strip() in ('','0'),'Rosetta/ARM host rejected')
|
||||
hardware=run(['/usr/sbin/sysctl','hw.machine','machdep.cpu.vendor','machdep.cpu.brand_string'],'hardware',30)
|
||||
require('GenuineIntel' in hardware and 'x86_64' in hardware,'Intel hardware evidence missing')
|
||||
receipt['host']={'uname':platform.uname()._asdict(),'translated':translated.stdout.strip(),'translatedExitCode':translated.returncode,'arm64':arm.stdout.strip(),'arm64ExitCode':arm.returncode,'sysctl':hardware}
|
||||
require(sha(node)==PIN['nodeSha256'],'Official pinned Node bytes mismatch')
|
||||
require(json.loads(run([node,'-p','JSON.stringify([process.platform,process.arch,process.version])'],'node',30))==['darwin','x64','v24.21.0'],'Node architecture/version mismatch')
|
||||
require(run([pnpm,'--version'],'pnpm',30).strip()=='9.15.4','pnpm version mismatch')
|
||||
npm=Path(shutil.which('npm')).resolve(strict=True)
|
||||
receipt['packageManagers']={'pnpmEntrySha256':sha(pnpm),'pnpmVersion':'9.15.4','npmEntrySha256':sha(npm),'npmVersion':run([npm,'--version'],'npm-version',30).strip()}
|
||||
require(subprocess.check_output(['git','rev-parse','HEAD'],cwd=stage,text=True).strip()==SOURCE,'Wrong frozen source')
|
||||
require(not subprocess.check_output(['git','status','--porcelain'],cwd=stage),'Source checkout dirty')
|
||||
with (out/'source.tar').open('xb') as f:subprocess.run(['git','archive',SOURCE],cwd=stage,stdout=f,check=True)
|
||||
require(sha(out/'source.tar')==PIN['sourceArchiveSha256'],'Source archive mismatch')
|
||||
lock=stage/'pnpm-lock.yaml';original=lock.read_text();require(sha(lock)==PIN['trackedLockSha256'],'Tracked lock mismatch')
|
||||
require(original.count('xinuppsghzi2pwhozdhfegto3m')==4,'Unexpected overlay scope')
|
||||
resolved=original.replace('xinuppsghzi2pwhozdhfegto3m','glhukwf7nfpmpbdvrnmtdtjn5q')
|
||||
(out/'original-pnpm-lock.yaml').write_text(original);lock.write_text(resolved)
|
||||
require(sha(lock)==PIN['resolvedLockSha256'],'Resolved lock mismatch')
|
||||
shutil.copy2(lock,out/'resolved-pnpm-lock.yaml')
|
||||
(out/'lock.diff').write_text(''.join(difflib.unified_diff(original.splitlines(True),resolved.splitlines(True),fromfile='tracked-lock',tofile='resolved-lock')))
|
||||
for agent,pin in INPUTS['profiles'].items():
|
||||
p=stage/pin['path'];require(sha(p)==pin['sha256'],'Profile bytes changed: '+agent)
|
||||
data=json.loads(p.read_text());require(data['commandDigest']==pin['digest'],'Profile digest changed')
|
||||
for rel,digest in INPUTS['additionalSourceFiles'].items():require(sha(stage/rel)==digest,'Supplementary source changed: '+rel)
|
||||
receipt['sourceInputInventory']=source_inventory();atomic_json(out/'source-input-inventory.json',receipt.pop('sourceInputInventory'))
|
||||
receipt['sourceInputInventorySha256']=sha(out/'source-input-inventory.json');receipt['profiles']=INPUTS['profiles'];save()
|
||||
source_guard.verify_source(stage,SOURCE,PIN['resolvedLockSha256'])
|
||||
run([pnpm,'install','--frozen-lockfile','--ignore-scripts','--package-import-method','copy'],'install',600)
|
||||
source_guard.verify_source(stage,SOURCE,PIN['resolvedLockSha256'])
|
||||
run([pnpm,'--filter','@paperclipai/paperclip-runner','build:typescript'],'typescript',600)
|
||||
run([rustup,'toolchain','install','1.97.1','--profile','minimal','--component','rustfmt'],'rust-install',600)
|
||||
cargo=run([rustup,'which','--toolchain','1.97.1','cargo'],'cargo-path',30).strip()
|
||||
rustc=run([rustup,'which','--toolchain','1.97.1','rustc'],'rustc-path',30).strip();env['RUSTC']=rustc
|
||||
require(run([rustc,'--version'],'rust-version',30).startswith('rustc 1.97.1 '),'Wrong Rust')
|
||||
receipt['compiler']={'rustcSha256':sha(rustc),'cargoSha256':sha(cargo),'versionVerbose':run([rustc,'--version','--verbose'],'rust-version-verbose',30),'jobs':2}
|
||||
run([cargo,'build','--release','--target','x86_64-apple-darwin','--manifest-path','packages/paperclip-runner/runner/Cargo.toml','--locked','-p','paperclip-runner-core','--bin','paperclip-runnerd','-j','2'],'daemon-build',1500)
|
||||
daemon=stage/'packages/paperclip-runner/dist/bin/paperclip-runnerd';daemon.parent.mkdir(parents=True,exist_ok=True)
|
||||
shutil.copy2(scratch/'target/x86_64-apple-darwin/release/paperclip-runnerd',daemon)
|
||||
run(['/usr/bin/codesign','--force','--sign','-',daemon],'daemon-sign',30)
|
||||
require('Mach-O 64-bit executable x86_64' in run(['/usr/bin/file',daemon],'daemon-architecture',30),'Wrong daemon architecture')
|
||||
receipt['daemonBuildMetadata']=json.loads(run([daemon,'--build-metadata'],'daemon-metadata',30))
|
||||
pack=scratch/'provider-pack'
|
||||
run([node,'packages/paperclip-runner/scripts/build-provider-pack.mjs',pack,'--candidate-providers=pi,copilot,cursor'],'pack-build',600)
|
||||
verified=json.loads(run([node,HERE/'verify-pack.mjs',pack,SOURCE,'darwin','x64'],'pack-verify',180))
|
||||
require(sha(pack/'node_modules/node/bin/node')==PIN['nodeSha256'],'Pack Node mismatch')
|
||||
authority={'pack':source_guard.tree(pack,allow_links=True),'dist':source_guard.tree(stage/'packages/paperclip-runner/dist'),'assets':source_guard.tree(stage/source_guard.ASSETS)}
|
||||
source_guard.verify_source(stage,SOURCE,PIN['resolvedLockSha256'],pack,authority)
|
||||
atomic_json(out/'pack-inventory.json',closed_tree(pack));shutil.copy2(pack/'provider-pack.json',out/'provider-pack.json');shutil.copy2(daemon,out/'paperclip-runnerd')
|
||||
receipt.update(packVerification=verified,packManifestSha256=sha(out/'provider-pack.json'),packInventorySha256=sha(out/'pack-inventory.json'),daemonSha256=sha(daemon),nodeSha256=sha(node),buildInputsMatchLocal=True,outputDigestsAssumedEqual=False)
|
||||
test=stage/'packages/paperclip-runner/test/pi-closed-startup.test.mjs'
|
||||
require(sha(test)=='8967cf9c8cd130b68bf9d64abef8cb8d352af00646e2288b341d8c6ae758b47a','Closed startup test changed')
|
||||
receipt['testSourceSha256']={n:sha(stage/'packages/paperclip-runner/test'/n) for n in ['pi-closed-startup.test.mjs','pi-native-package-contract.test.mjs','pi-acp-package-contract.test.mjs']};save()
|
||||
retained=out/'retained-test-state';retained.mkdir(mode=0o700)
|
||||
testenv={'HOME':str(scratch/'home'),'TMPDIR':str(scratch),'PATH':'/usr/bin:/bin','LANG':'en_US.UTF-8',
|
||||
'PI_INTEL_OWNED_TMP':str(scratch),'PI_INTEL_RETAINED_STATE':str(retained),
|
||||
'PAPERCLIP_TEST_PI_STARTUP_PACKAGE_ROOT':str(pack),'PAPERCLIP_TEST_PI_STARTUP_RUNNER_BINARY':str(daemon),
|
||||
'PAPERCLIP_TEST_PI_RUNTIME_ROOT':str(pack/'provider-assets/pi/darwin-x64/runtime/node_modules/@earendil-works/pi-coding-agent'),
|
||||
'PAPERCLIP_TEST_PI_ACP_PACKAGE':str(pack/'provider-assets/pi/darwin-x64/runtime/node_modules/pi-acp/package.json')}
|
||||
# The observer is passed only to the test process; runtime children receive no NODE_OPTIONS.
|
||||
failures=[]
|
||||
for label,command in [('closed-startup',[node,'--import',HERE/'retain-test-state.mjs','--test',test]),('native-extension-contracts',[node,'--test',stage/'packages/paperclip-runner/test/pi-native-package-contract.test.mjs',stage/'packages/paperclip-runner/test/pi-acp-package-contract.test.mjs'])]:
|
||||
try:run(command,label,180,command_env=testenv,owned=True)
|
||||
except RuntimeError as e:failures.append(str(e))
|
||||
source_guard.verify_source(stage,SOURCE,PIN['resolvedLockSha256'],pack,authority)
|
||||
require(source_inventory()==json.loads((out/'source-input-inventory.json').read_text()),'Tracked source changed')
|
||||
require(closed_tree(pack)==json.loads((out/'pack-inventory.json').read_text()),'Pack changed during tests')
|
||||
receipt['retainedTestStateInventory']=closed_tree(retained)
|
||||
receipt['testFailures']=failures;require(not failures,'Native Intel test failure; no retry')
|
||||
receipt['status']='native_intel_no_provider_checks_passed_pending_review'
|
||||
except BaseException as error:
|
||||
receipt.update(status='failed_no_retry',errorType=type(error).__name__,error=str(error));raise
|
||||
finally:
|
||||
if scratch.exists():
|
||||
st=scratch.stat();require((st.st_dev,st.st_ino,st.st_uid)==identity and st.st_uid==os.getuid(),'Scratch ownership changed')
|
||||
if cleanup_ok:shutil.rmtree(scratch);receipt['scratchCleanup']='removed_verified_owned_root'
|
||||
else:receipt['scratchCleanup']='retained_unresolved_processes'
|
||||
receipt['finishedAt']=datetime.datetime.now(datetime.timezone.utc).isoformat();save()
|
||||
|
||||
if __name__=='__main__':
|
||||
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--source',type=Path,required=True);parser.add_argument('--output',type=Path,required=True);execute(parser.parse_args())
|
||||
Reference in new issue
Block a user