Prepare independent CLI builds and immutable Gitea release assets

This commit is contained in:
Anya Tokugawa committed 2026-11-06 02:21:28 +09:00
1 parent d3f4e668c4
commit e4fb4f309f
15 files changed
+396 -4

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
"""Exercise the actual packaged executable against a synthetic loopback API."""
import json
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
binary=str(Path(sys.argv[1]).resolve())
token='synthetic_session_'+('x'*40)
seen=[]
class Handler(BaseHTTPRequestHandler):
def log_message(self,*args):pass
def do_POST(self):
self.rfile.read(int(self.headers.get('Content-Length',0)))
if self.path=='/_/auth/login': self.reply({'access_token':token,'token_type':'Bearer','expires_in':3600})
elif self.path=='/_/auth/logout':self.reply({})
else:self.send_error(404)
def do_GET(self):
if self.headers.get('Authorization')!='Bearer '+token:self.send_error(401);return
seen.append(self.path)
self.reply({'items':[{'uuid':'synthetic-task','title':'Packaged CLI task','status':'todo'}]})
def reply(self,value):
self.send_response(200);self.send_header('Content-Type','application/json');self.end_headers();self.wfile.write(json.dumps(value).encode())
server=ThreadingHTTPServer(('127.0.0.1',0),Handler)
thread=threading.Thread(target=server.serve_forever,daemon=True);thread.start()
try:
with tempfile.TemporaryDirectory() as root:
env={**os.environ,'XDG_CONFIG_HOME':root}
def run(*args,stdin='',success=True):
p=subprocess.run([binary,*args],input=stdin,text=True,capture_output=True,env=env,timeout=15)
if token in p.stdout+p.stderr:raise AssertionError('Credential leaked')
if (p.returncode==0)!=success:raise AssertionError('Packaged command failed: '+str(args)+' '+p.stderr)
return p.stdout
run('configure','--origin',f'http://127.0.0.1:{server.server_port}','--username','synthetic')
run('login',stdin='synthetic-password\n')
if 'Packaged CLI task' not in run('task','list'):raise AssertionError('Task missing')
run('shell',stdin='pwd\nexit\n')
profile=Path(root)/'pages-cli/sessions/default.json'
if profile.stat().st_mode&0o077:raise AssertionError('Credential permissions')
profile.chmod(0o644);run('task','list',success=False);profile.chmod(0o600)
run('logout')
if not seen:raise AssertionError('No HTTP request')
print('Packaged CLI: configure/login/task-list/permissions/logout passed')
finally:server.shutdown();server.server_close();thread.join()