From 350befeb62bb6d32ccdac5de83339dd9b52c059d Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 20:19:03 -0500 Subject: [PATCH 01/11] test: add installed two-Home messaging and offline recovery journey Deepen notes: bind source and installed artifacts; start from ci-installed-journeys.py:1468 and direct.rs:66-84. Reuse fresh fixtures and owned process cleanup. Verify exact receiver content and settled sender time with real negative controls; installed Linux verification follows this commit. --- scripts/ci-installed-journeys.py | 182 ++++++++++++++++++ scripts/ci-installed-two-home-journey.mjs | 217 ++++++++++++++++++++++ scripts/ci-installed-two-home-test.py | 97 ++++++++++ scripts/ci-installed-two-home.test.mjs | 30 +++ 4 files changed, 526 insertions(+) create mode 100644 scripts/ci-installed-two-home-journey.mjs create mode 100644 scripts/ci-installed-two-home-test.py create mode 100644 scripts/ci-installed-two-home.test.mjs diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index 4149a70af..ef1817605 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -1712,6 +1712,179 @@ def ignore(directory, names): return target +def installed_message_identity(data): + """Use the same source/installed byte boundary as the other installed journeys.""" + receipt = json.loads((data / "receipts/source-home-installation.json").read_text()) + candidate = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip() + tree = subprocess.check_output(["git", "rev-parse", "HEAD^{tree}"], text=True).strip() + runtime = digest(data / "bin/elastos") + assert receipt["source"]["commit"] == candidate and receipt["source"]["tree"] == tree + assert receipt["source"]["clean"] is True and receipt["runtime"]["parity"] is True + assert receipt["runtime"]["built_sha256"] == receipt["runtime"]["installed_sha256"] == "sha256:" + runtime + assert receipt["components_sha256"] == "sha256:" + digest(data / "components.json") + capsules = data / "receipts/source-home-capsules.json" + assert receipt["source_home_capsule_metadata_receipt_sha256"] == "sha256:" + digest(capsules) + manifest = json.loads((data / "components.json").read_text()) + for name in ("home", "home-gui", "people", "inbox", "chat-room"): + entry = manifest["capsules"][name] + installed = data / "capsules" / name + assert "sha256:" + digest(installed / entry["entrypoint"]) == entry["entrypoint_sha256"] + for asset in entry["browser_assets"]: + assert "sha256:" + digest(installed / asset["path"]) == asset["sha256"] + return {"candidate": candidate, "source_tree": tree, "installed_runtime_sha256": runtime, + "source_components_sha256": digest(data / "components.json"), + "installation_receipt_sha256": digest(data / "receipts/source-home-installation.json")} + + +def remove_message_fixture(root): + """Remove only this fresh, process-free fixture; never follow a root/parent link.""" + root = Path(os.path.abspath(root)) + for path in (root, *root.parents): + assert stat.S_ISDIR(path.lstat().st_mode) and not path.is_symlink() + assert not owned_processes(process_rows(), -1, root) + before = root.lstat() + assert (root.lstat().st_dev, root.lstat().st_ino) == (before.st_dev, before.st_ino) + shutil.rmtree(root) + + +def two_home_receipt_valid(row, identity): + if any(row.get(key) != value for key, value in identity.items()): + return False + homes = row.get("homes", []) + cleanup = row.get("process_cleanup", []) + return (row.get("fixture_removed") is True and len(homes) == 3 + and {home.get("home") for home in homes} == {"a", "b", "community"} + and all(home.get("installed_runtime_sha256") == identity["installed_runtime_sha256"] for home in homes) + and len(cleanup) == 5 and all(item.get("status") == "passed" and item.get("after") + and sum(item["after"].values()) == 0 for item in cleanup) + and row.get("transport", {}).get("carrier_network") == "direct" + and row.get("transport", {}).get("mdns") is False + and all(row.get("results", {}).get(name) == "passed" for name in ( + "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) + and all(row.get("negative_controls", {}).get(name, {}).get("assertion_rejected") is True + for name in ("community_post", "direct_received", "sender_delivered")) + and row["negative_controls"]["sender_delivered"].get("api_state") == "pending" + and row["negative_controls"]["sender_delivered"].get("ui_detail") == "Sending") + + +def two_home_messages(home, data, evidence, network="same-host", fixture_root=None): + """Installed Community and Direct journey. Topology belongs to setup, not assertions.""" + if network != "same-host": + raise RuntimeError("unsupported two-Home network arrangement") + identity = installed_message_identity(data) + evidence.mkdir(parents=True, exist_ok=False) + root = fixture_root or home.parent / "two-home-message-fixture" + # Three fresh immutable copies; source fixtures never copy identity or user data. + require_disk_space(data) + root.mkdir(mode=0o700, parents=True, exist_ok=False) + control = root / "control" + control.mkdir(mode=0o700) + record = dict(identity, network_arrangement=network, results={}, homes=[], negative_controls={}) + receipt_path = evidence / "installed-journeys.json" + children, fixtures, browser = {}, {}, None + cleanup = [] + started = time.monotonic() + # Explicit environment excludes ambient relay, public-network and provider overrides. + def environment(owner): + return {"PATH": os.environ["PATH"], "HOME": str(owner[0]), "XDG_DATA_HOME": str(owner[1].parent), + "ELASTOS_CARRIER_NETWORK": "direct", "ELASTOS_CARRIER_MDNS": "0", + "ELASTOS_QUIET_RUNTIME_NOTICES": "1"} + protected = {8090, 61240, 61200, 61201, 62684, 8096, 61185} + def port(kind=socket.SOCK_STREAM): + while True: + number = free_port(kind) + if number not in protected: + return number + def launch(name): + owner = fixtures[name] + with (owner[0] / "runtime.private.log").open("ab") as log: + child = subprocess.Popen([str(owner[1] / "bin/elastos"), "gateway", "--addr", owner[2]], + env=environment(owner), stdout=log, stderr=log, start_new_session=True) + children[name] = child + wait_healthy(child, owner[2], "two-Home " + name) + def stop(name): + child = children.pop(name) + row = cleanup_runtime(child, fixtures[name][1]) + cleanup.append(dict(row, home=name)) + assert row["status"] == "passed", "two-Home process cleanup failed" + def configure(*arguments): + owner = fixtures["community"] + with (root / "configuration.private.log").open("ab") as log: + subprocess.run([str(owner[1] / "bin/elastos"), "collaboration-config", *map(str, arguments)], + env=environment(owner), stdout=log, stderr=log, check=True, timeout=60) + try: + for name in ("community", "a", "b"): + destination = root / name + copied = fresh_fixture(home, data, destination, include_engine=False) + assert installed_message_identity(copied) == identity + with (copied / "config.toml").open("a") as config: + config.write(f'carrier_bind_addr = "127.0.0.1:{port(socket.SOCK_DGRAM)}"\n') + fixtures[name] = (destination, copied, f"127.0.0.1:{port()}") + record["homes"].append({"home": name, "installed_runtime_sha256": digest(copied / "bin/elastos")}) + launch("community") + configure("create-authority-key", "--key", root / "authority.key") + configure("export-local-bootstrap-receipt", "--data-root", fixtures["community"][1], + "--runtime-kind", "gateway", "--output", root / "bootstrap.json") + configure("generate-initial", "--authority-key", root / "authority.key", "--network-id", "ci.two-home", + "--conversation-id", "community", "--bootstrap-peer", root / "bootstrap.json", "--output", root / "network.json") + configure("verify", "--input", root / "network.json") + stop("community") + for owner in fixtures.values(): + target = owner[1] / "collaboration-network-v1.json" + shutil.copy2(root / "network.json", target) + target.chmod(0o600) + for name in fixtures: + launch(name) + record["transport"] = {"carrier_network": "direct", "mdns": False, + "bootstrap": "disposable local Community", + "peer_route": "Carrier PeerDid; fixture supplies no HTTP peer routes"} + bases = ["http://localhost:" + fixtures[name][2].rsplit(":", 1)[1] for name in ("a", "b")] + with (root / "browser.private.log").open("wb") as log: + browser = subprocess.Popen(["node", "scripts/ci-installed-two-home-journey.mjs", *bases, + str(evidence), str(control)], stdout=log, stderr=log, start_new_session=True) + deadline, last = time.monotonic() + 420, 0 + while browser.poll() is None: + assert time.monotonic() < deadline, "two-Home browser deadline" + request = control / "request.json" + if request.exists(): + value = private_json(request) + if value["id"] > last: + assert value["id"] == last + 1 and value["action"] in {"stop_b", "start_b"} + stop("b") if value["action"] == "stop_b" else launch("b") + last = value["id"] + private_json(control / "response.json", {"id": last, "status": "passed"}) + time.sleep(.1) + observed = json.loads((evidence / "two-home-ui.json").read_text()) + record.update(observed) + if browser.returncode and (control / "error.private.txt").exists(): + record["browser_failure"] = redact((control / "error.private.txt").read_text(), [str(root)])[:1200] + assert browser.returncode == 0, "installed two-Home browser journey failed" + assert all(record["results"].get(name) == "passed" for name in ( + "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) + assert all(record["negative_controls"].get(name, {}).get("assertion_rejected") is True + for name in ("community_post", "direct_received", "sender_delivered")) + except BaseException as error: + record["failure"] = observer_failure("two_home_messages", error, [str(root), str(home)]) + raise + finally: + if browser and browser.poll() is None: + os.killpg(browser.pid, signal.SIGTERM) + try: + browser.wait(timeout=10) + except subprocess.TimeoutExpired: + os.killpg(browser.pid, signal.SIGKILL) + browser.wait(timeout=5) + for name in list(children): + stop(name) + record["process_cleanup"] = cleanup + record["elapsed_seconds"] = round(time.monotonic() - started, 2) + record["disk_after"] = require_disk_space(data) + # Private keys, sessions and Runtime logs have one lifecycle: this invocation. + remove_message_fixture(root) + record["fixture_removed"] = True + receipt_path.write_text(json.dumps(record, indent=2) + "\n") + + def repeat(home, data, evidence, count): if count != 3: raise RuntimeError("Mac timing series requires three fresh journeys") @@ -1747,7 +1920,16 @@ def repeat(home, data, evidence, count): parser.add_argument("--carrier-get", action="store_true") parser.add_argument("--finite-memory", type=int, choices=[1, 4]) parser.add_argument("--model-repair", action="store_true", help="real Stop, Get different model and interrupted Get/Home restart/Retry") + parser.add_argument("--two-home-messages", action="store_true") + parser.add_argument("--network-arrangement", choices=["same-host"], default="same-host") + parser.add_argument("--two-home-root", type=Path, help="fresh disposable fixture path; Mac QA uses ~/.local/share/elastos-qa/two-home/") args = parser.parse_args() + if args.two_home_messages: + if args.repeat or args.home_only or args.carrier_get or args.finite_memory or args.model_repair: + parser.error("two-Home messages is a separate installed journey") + two_home_messages(args.home.resolve(), args.data.resolve(), args.evidence.resolve(), + args.network_arrangement, args.two_home_root) + raise SystemExit(0) if args.model_repair and (sys.platform != "linux" or args.home_only or args.repeat or args.finite_memory): parser.error("--model-repair proves one production Linux Home with two signed models") if args.home_only and args.repeat: diff --git a/scripts/ci-installed-two-home-journey.mjs b/scripts/ci-installed-two-home-journey.mjs new file mode 100644 index 000000000..a346b0471 --- /dev/null +++ b/scripts/ci-installed-two-home-journey.mjs @@ -0,0 +1,217 @@ +import assert from 'node:assert/strict'; +import {createRequire} from 'node:module'; +import {writeFileSync, readFileSync, renameSync} from 'node:fs'; +import {fileURLToPath} from 'node:url'; +import {join} from 'node:path'; +export function assertCommunityMessage(poll, id, text) { + const message = poll.objects.find(row => row.message_id === id); + assert(message && message.body === text && !message.from_current_session, 'Community exact text from the other Home'); + return message; +} +export function assertReceivedDirect(messages, id, text) { + const message = messages.find(row => row.message_id === id); + assert(message && message.direction === 'incoming' && message.text === text && message.delivery_state === 'received', 'recipient exact direct message'); + return message; +} +export function assertSenderDelivery(message, detail) { + assert(message?.direction === 'outgoing' && message.delivery_state === 'receipt_settled', 'sender receipt settled'); + const time = new Date(message.created_at * 1000).toISOString().slice(11, 16); + assert.equal(detail, time, 'sender shows the message time, with neither Sending nor Expired'); +} +async function run() { + const require = createRequire(import.meta.url); + const {chromium} = require(process.env.BROWSER_OPERATOR_PLAYWRIGHT_CORE || '../elastos/tools/browser-playwright-engine/node_modules/playwright'); + const [baseA, baseB, evidence, control] = process.argv.slice(2); + const bases = [baseA, baseB]; + assert(bases.every(base => new URL(base).hostname === 'localhost'), 'installed journey uses localhost for passkeys'); + const result = {stage:'sign_in', results:{}, negative_controls:{}}; + let sequence = 0; + async function runtime(action) { + const id = ++sequence; + writeFileSync(join(control, 'request.json.next'), JSON.stringify({id, action}), {flag:'wx', mode:0o600}); + renameSync(join(control, 'request.json.next'), join(control, 'request.json')); + await until('owned Runtime action', async () => { + let reply; + try {reply = JSON.parse(readFileSync(join(control, 'response.json'), 'utf8'));} + catch (error) {if (error.code !== 'ENOENT') throw error;} + return reply?.id === id && reply.status === 'passed'; + }, 120000); + } + const sleep = ms => new Promise(resolve=>setTimeout(resolve,ms)); + async function until(label, fn, ms=150000) { + const end=Date.now()+ms; + while(Date.now()r.url().endsWith('/api/auth/passkey/register/complete')); + await page.locator('#home-unlock-primary').click(); + assert((await registered).ok(),'passkey registration'); + result.stage='home_ready_'+i; + await page.waitForFunction(()=>document.body.dataset.homeStatus==='ready'&&document.body.dataset.homeAuthority==='signed',null,{timeout:60000}); + async function app(target,query={}) { + const launch=await page.evaluate(async ({target,query})=>{ + const {fetchJson}=await import('/home/shell-core.js?v=home-wallpaper-20261030b'); + return fetchJson('/api/apps/home/launch',{method:'POST',body:JSON.stringify({target,query:{...query,home_origin:location.origin}})}); + },{target,query}); + const tab=await context.newPage(); + await tab.goto(new URL(launch.route,base).href,{waitUntil:'domcontentloaded'}); + return tab; + } + result.stage='people_launch_'+i; + const people=await app('people'); + homes.push({context,page,people,app,base}); + } + async function api(page,path,body) { + return page.evaluate(async ({path,body})=>{ + const token=new URLSearchParams(location.hash.slice(1)).get('home_token'); + const r=await fetch(path,{method:body===undefined?'GET':'POST',headers:{'content-type':'application/json','x-elastos-home-token':token},body:body===undefined?undefined:JSON.stringify(body),signal:AbortSignal.timeout(30000)}); + if(!r.ok) throw new Error('product API '+path+' HTTP '+r.status); + return r.json(); + },{path,body}); + } + const [a,b]=homes; + const communityA=await a.app('chat-room'), communityB=await b.app('chat-room'); + result.stage='community_post'; + await communityA.locator('#message-input:enabled').waitFor({timeout:90000}); + await api(communityB, '/api/apps/chat-room/session/start', {}); + const postText='Two Home Community '+crypto.randomUUID(); + const posted=await api(communityA, '/api/apps/chat-room/objects/send', {request_id:'two-home:'+crypto.randomUUID(),body:postText}); + let communityPoll; + await until('Community exact text at B', async()=>{ + communityPoll=await api(communityB, '/api/apps/chat-room/poll', {since:0,mark_read:false}); + return communityPoll.objects.some(row=>row.message_id===posted.message_id && row.body===postText); + }); + assert.throws(()=>assertCommunityMessage(communityPoll, posted.message_id, postText+' wrong'), {name:'AssertionError'}); + result.negative_controls.community_post={assertion_rejected:true, broken_input:'wrong expected text against real B poll'}; + assertCommunityMessage(communityPoll, posted.message_id, postText); + result.results.community_post='passed'; + result.community_text=postText; + await communityB.screenshot({path:join(evidence,'community-b-desktop.png'),fullPage:true}); + const profile=await api(b.people,'/api/apps/people/summary'); + assert(profile.profile_id,'B profile available'); + result.stage='contact_request'; + const request=await api(a.people,'/api/apps/people/contacts/request',{profile_id:profile.profile_id}); + result.observations.push({step:'contact_request',status:request.status}); + const inbox=await b.app('inbox'); + function action(value) { + if(!value||typeof value!=='object') return null; + if(typeof value.action_id==='string'&&value.action_id.startsWith('contact-accept-request:')) return value.action_id; + return Object.values(value).map(action).find(Boolean); + } + result.stage='contact_accept'; + const accept=await until('contact Inbox arrival',async()=>action(await api(inbox,'/api/apps/inbox/summary'))); + await api(inbox,'/api/apps/inbox/actions',{action_id:accept}); + result.observations.push({step:'contact_accept',status:'accepted'}); + const ac=await a.app('chat-room'), bc=await b.app('chat-room'); + result.stage='direct_conversation'; + const conversation=await until('A contact conversation',async()=> (await api(ac,'/api/apps/chat-room/direct/conversations')).conversations.find(c=>!c.removed)); + await until('B contact conversation',async()=> (await api(bc,'/api/apps/chat-room/direct/conversations')).conversations.find(c=>c.conversation_id===conversation.conversation_id)); + const text='Two Home direct '+crypto.randomUUID(); + result.stage='direct_send'; + const sent=await api(ac,'/api/apps/chat-room/direct/messages/send',{request_id:'two-home:'+crypto.randomUUID(),conversation_id:conversation.conversation_id,text}); + result.observations.push({step:'direct_send',status:sent.status,text}); + const path='/api/apps/chat-room/direct/conversations/'+encodeURIComponent(conversation.conversation_id)+'/messages'; + result.stage='direct_receive'; + let receivedMessages; + const received=await until('B direct exact text',async()=> { + receivedMessages=(await api(bc,path)).messages; + return receivedMessages.find(m=>m.text===text&&m.direction==='incoming'&&m.delivery_state==='received'); + }); + assert.throws(()=>assertReceivedDirect(receivedMessages, received.message_id, text+' wrong'), {name:'AssertionError'}); + result.negative_controls.direct_received={assertion_rejected:true, broken_input:'wrong expected text against real B messages'}; + assertReceivedDirect(receivedMessages, received.message_id, text); + result.results.direct_received='passed'; + const senderMessage=async expected=> (await api(ac,path)).messages.find(m=>m.text===expected&&m.direction==='outgoing'); + const settled=await until('A settled receipt',async()=> { + const message=await senderMessage(text); + return message?.delivery_state==='receipt_settled' && message; + }); + const direct=await a.app('chat-room',{conversation_id:conversation.conversation_id}); + async function detail(expected) { + const row=direct.locator('#message-list li.message.self-message').filter({has:direct.locator('.message-body').filter({hasText:expected})}); + await row.waitFor({state:'visible',timeout:60000}); + assert.equal(await row.locator('.message-body').innerText(),expected); + return row.locator('.message-meta > span').last().innerText(); + } + const senderDetail=await until('A delivered time',async()=>{ + const value=await detail(text); + return /^\d{2}:\d{2}$/.test(value)&&value; + }); + assertSenderDelivery(settled,senderDetail); + result.results.sender_delivered='passed'; + result.direct={text,recipient_state:received.delivery_state,sender_state:settled.delivery_state,sender_detail:senderDetail}; + result.stage='offline_pending'; + // Close B's projections before stopping its owned Runtime; retain only its passkey context. + for(const page of b.context.pages()) if(page!==b.page) await page.close(); + await runtime('stop_b'); + const offlineText='Two Home recovery '+crypto.randomUUID(); + const pendingSend=await api(ac,'/api/apps/chat-room/direct/messages/send',{request_id:'two-home:'+crypto.randomUUID(),conversation_id:conversation.conversation_id,text:offlineText}); + assert.equal(pendingSend.status,'pending'); + let pending; + await until('A Sending line',async()=>{ + pending=await senderMessage(offlineText); + return pending?.delivery_state==='pending' && await detail(offlineText)==='Sending'; + }); + for(let sample=0;sample<3;sample++) { + pending=await senderMessage(offlineText); + const value=await detail(offlineText); + assert.equal(pending.delivery_state,'pending'); + assert.equal(value,'Sending'); + assert.throws(()=>assertSenderDelivery(pending,value),{name:'AssertionError'}); + await sleep(500); + } + result.negative_controls.sender_delivered={assertion_rejected:true,broken_input:'B stopped before send',api_state:'pending',ui_detail:'Sending',samples:3}; + result.results.offline_pending='passed'; + result.stage='restart_delivery'; + await runtime('start_b'); + await b.page.reload({waitUntil:'domcontentloaded'}); + await b.page.waitForFunction(()=>document.body.dataset.homeStatus==='ready'||document.querySelector('#home-unlock')?.hidden===false,null,{timeout:60000}); + if(await b.page.locator('#home-unlock-primary').isVisible()) await b.page.locator('#home-unlock-primary').click(); + await b.page.waitForFunction(()=>document.body.dataset.homeStatus==='ready'&&document.body.dataset.homeAuthority==='signed',null,{timeout:60000}); + const restarted=await b.app('chat-room',{conversation_id:conversation.conversation_id}); + const recovered=await until('B receives after restart',async()=> (await api(restarted,path)).messages.find(m=>m.text===offlineText&&m.direction==='incoming'&&m.delivery_state==='received')); + const settledAfterRestart=await until('A receipt settles after restart',async()=>{ + const message=await senderMessage(offlineText); + return message?.delivery_state==='receipt_settled' && message; + }); + const recoveredDetail=await until('A time replaces Sending',async()=> { + const value=await detail(offlineText); + return /^\d{2}:\d{2}$/.test(value) && value; + }); + assertReceivedDirect([recovered],recovered.message_id,offlineText); + assertSenderDelivery(settledAfterRestart,recoveredDetail); + result.recovery={text:offlineText,recipient_state:recovered.delivery_state,sender_state:settledAfterRestart.delivery_state,sender_detail:recoveredDetail}; + result.results.restart_delivery='passed'; + await direct.screenshot({path:join(evidence,'direct-a-desktop.png'),fullPage:true}); + await direct.setViewportSize({width:390,height:844}); + await direct.screenshot({path:join(evidence,'direct-a-phone.png'),fullPage:true}); + result.status='passed'; + } catch(error) { + result.status='failed'; + result.failure=['AssertionError','TimeoutError'].includes(error.name)?error.name:'journey_failed'; + writeFileSync(join(control,'error.private.txt'),String(error.stack),{mode:0o600}); + process.exitCode=1; + } finally { + if(browser) await browser.close(); + writeFileSync(join(evidence,'two-home-ui.json'),JSON.stringify(result,null,2)+'\n',{mode:0o600}); + console.log(JSON.stringify({stage:result.stage,status:result.status})); + } + +} +if (process.argv[1] === fileURLToPath(import.meta.url)) await run(); diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py new file mode 100644 index 000000000..ddc060709 --- /dev/null +++ b/scripts/ci-installed-two-home-test.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +"""Receipt guards for the installed two-Home journey; no Runtime or browser mocks.""" +import copy +import json +from pathlib import Path +import runpy +import tempfile +import unittest +from unittest import mock + +ROOT = Path(__file__).resolve().parent.parent +JOURNEY = runpy.run_path(str(ROOT / 'scripts/ci-installed-journeys.py')) + + +class TwoHomeReceiptTests(unittest.TestCase): + def identity(self): + return {'candidate':'c'*40, 'source_tree':'d'*40, 'installed_runtime_sha256':'a'*64, + 'source_components_sha256':'b'*64, 'installation_receipt_sha256':'e'*64} + + def receipt(self): + identity = self.identity() + return {**identity, 'fixture_removed':True, + 'homes':[{'home':name, 'installed_runtime_sha256':identity['installed_runtime_sha256']} + for name in ('a','b','community')], + 'process_cleanup':[{'status':'passed', 'after':{'runtime':0}} for _ in range(5)], + 'transport':{'carrier_network':'direct','mdns':False}, + 'results':{name:'passed' for name in ('community_post','direct_received','sender_delivered', + 'offline_pending','restart_delivery')}, + 'negative_controls':{name:{'assertion_rejected':True, 'api_state':'pending', 'ui_detail':'Sending'} + for name in ('community_post','direct_received','sender_delivered')}} + + def test_acceptance_refuses_stale_identity_unchecked_failure_controls_or_surviving_processes(self): + valid = self.receipt() + check = JOURNEY['two_home_receipt_valid'] + self.assertTrue(check(valid, self.identity())) + for key in self.identity(): + changed = copy.deepcopy(valid) + changed[key] = 'stale' + self.assertFalse(check(changed, self.identity()), key) + for key, value in [('fixture_removed',False), ('homes',[]), ('process_cleanup',[])]: + changed = copy.deepcopy(valid) + changed[key] = value + self.assertFalse(check(changed, self.identity()), key) + for field in ('results','negative_controls'): + for name in valid[field]: + changed = copy.deepcopy(valid) + del changed[field][name] + self.assertFalse(check(changed, self.identity()), name) + changed = copy.deepcopy(valid) + changed['process_cleanup'][0]['after']['runtime'] = 1 + self.assertFalse(check(changed, self.identity())) + changed = copy.deepcopy(valid) + changed['negative_controls']['sender_delivered']['api_state'] = 'receipt_settled' + self.assertFalse(check(changed, self.identity())) + changed = copy.deepcopy(valid) + changed['homes'][1]['home'] = 'a' + self.assertFalse(check(changed, self.identity())) + + def test_source_identity_rejects_changed_runtime_and_browser_asset_before_launch(self): + identify = JOURNEY['installed_message_identity'] + with tempfile.TemporaryDirectory() as temporary: + data = Path(temporary) + (data/'bin').mkdir() + (data/'receipts').mkdir() + runtime = data/'bin/elastos' + runtime.write_bytes(b'fixture runtime') + manifest = {'capsules':{}} + for name in ('home','home-gui','people','inbox','chat-room'): + directory = data/'capsules'/name + directory.mkdir(parents=True) + (directory/'index.html').write_text('fixture page') + manifest['capsules'][name] = {'entrypoint':'index.html', + 'entrypoint_sha256':'sha256:'+JOURNEY['digest'](directory/'index.html'), + 'browser_assets':[{'path':'index.html','sha256':'sha256:'+JOURNEY['digest'](directory/'index.html')}]} + (data/'components.json').write_text(json.dumps(manifest)) + (data/'receipts/source-home-capsules.json').write_text('{}') + sha = 'sha256:'+JOURNEY['digest'](runtime) + receipt = {'source':{'commit':'c'*40,'tree':'d'*40,'clean':True}, + 'runtime':{'built_sha256':sha,'installed_sha256':sha,'parity':True}, + 'components_sha256':'sha256:'+JOURNEY['digest'](data/'components.json'), + 'source_home_capsule_metadata_receipt_sha256':'sha256:'+JOURNEY['digest'](data/'receipts/source-home-capsules.json')} + (data/'receipts/source-home-installation.json').write_text(json.dumps(receipt)) + def observe(): + with mock.patch.object(identify.__globals__['subprocess'], 'check_output', side_effect=['c'*40,'d'*40]): + return identify(data) + self.assertEqual(observe()['candidate'], 'c'*40) + (data/'capsules/chat-room/index.html').write_text('stale UI') + with self.assertRaises(AssertionError): + observe() + (data/'capsules/chat-room/index.html').write_text('fixture page') + runtime.write_bytes(b'stale binary') + with self.assertRaises(AssertionError): + observe() + + +if __name__ == '__main__': + unittest.main() diff --git a/scripts/ci-installed-two-home.test.mjs b/scripts/ci-installed-two-home.test.mjs new file mode 100644 index 000000000..63bbf34cc --- /dev/null +++ b/scripts/ci-installed-two-home.test.mjs @@ -0,0 +1,30 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import {assertCommunityMessage, assertReceivedDirect, assertSenderDelivery} from './ci-installed-two-home-journey.mjs'; + +test('Community proof rejects wrong text, wrong identity and the receiving Home own post', () => { + const message = {message_id:'post:one', body:'fresh post', from_current_session:false}; + assertCommunityMessage({objects:[message]}, 'post:one', 'fresh post'); + for (const broken of [{body:'other text'}, {message_id:'post:two'}, {from_current_session:true}]) { + assert.throws(() => assertCommunityMessage({objects:[{...message,...broken}]}, 'post:one', 'fresh post'), assert.AssertionError); + } +}); + +test('Direct receive proof requires the exact incoming message and received state', () => { + const message = {message_id:'dm:one', text:'fresh direct', direction:'incoming', delivery_state:'received'}; + assertReceivedDirect([message], 'dm:one', 'fresh direct'); + for (const broken of [{text:'other text'}, {message_id:'dm:two'}, {direction:'outgoing'}, {delivery_state:'pending'}]) { + assert.throws(() => assertReceivedDirect([{...message,...broken}], 'dm:one', 'fresh direct'), assert.AssertionError); + } +}); + +test('Sender delivered requires both the settled API state and the exact message time', () => { + const message = {direction:'outgoing', delivery_state:'receipt_settled', created_at:42}; + assertSenderDelivery(message, '00:00'); + for (const detail of ['Sending', 'Expired', '', 'Delivered', '01:00']) { + assert.throws(() => assertSenderDelivery(message, detail), assert.AssertionError); + } + for (const state of ['pending','expired','received']) { + assert.throws(() => assertSenderDelivery({...message,delivery_state:state}, '00:00'), assert.AssertionError); + } +}); From 7c289a2e3feb2ab4f8042eea7e098c680d0dcbf8 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 20:19:37 -0500 Subject: [PATCH 02/11] ci: require two-Home messages in installed Linux and Mac journeys --- .github/workflows/ci.yml | 12 ++++++++++++ scripts/ci-installed-journeys.sh | 17 ++++++++++++++++- scripts/ci-installed-two-home-test.py | 9 +++++++++ scripts/test-source-gate.sh | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5dc79976..fa6ba797a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -926,6 +926,11 @@ jobs: - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: '26' + - name: installed two-Home Community and direct messages + timeout-minutes: 10 + env: + CI_SOURCE_HOME: ${{ runner.temp }}/elastos-source-home + run: scripts/ci-installed-journeys.sh two-home-messages - name: prepare signed SmolLM2 fixture timeout-minutes: 20 env: @@ -950,6 +955,7 @@ jobs: - name: summarize installed model journey if: always() env: + CI_TWO_HOME_MESSAGES: 'true' CI_SOURCE_HOME: ${{ runner.temp }}/elastos-source-home CI_CARRIER_GET: ${{ matrix.os == 'ubuntu-24.04' }} CI_FINITE_MEMORY: ${{ matrix.os == 'ubuntu-24.04' }} @@ -1193,9 +1199,15 @@ jobs: env: CI_SOURCE_HOME: ${{ runner.temp }}/elastos-mac-test-home run: scripts/ci-installed-journeys.sh home-repeat + - name: installed two-Home Community and direct messages + timeout-minutes: 10 + env: + CI_SOURCE_HOME: ${{ runner.temp }}/elastos-mac-test-home + run: scripts/ci-installed-journeys.sh two-home-messages - name: summarize installed model journey if: always() env: + CI_TWO_HOME_MESSAGES: 'true' CI_SOURCE_HOME: ${{ runner.temp }}/elastos-mac-test-home run: scripts/ci-installed-journeys.sh summary - name: upload installed model journey diff --git a/scripts/ci-installed-journeys.sh b/scripts/ci-installed-journeys.sh index a0027969e..df4a3c42c 100755 --- a/scripts/ci-installed-journeys.sh +++ b/scripts/ci-installed-journeys.sh @@ -39,6 +39,9 @@ PY model-repair) python3 scripts/ci-installed-journeys.py "$CI_HOME" "$DATA" "$EVIDENCE/model-repair" --model-repair ;; + two-home-messages) + python3 scripts/ci-installed-journeys.py "$CI_HOME" "$DATA" "$EVIDENCE/two-home-messages" --two-home-messages + ;; home) python3 scripts/ci-installed-journeys.py "$CI_HOME" "$DATA" "$EVIDENCE/engine-absent-home" --home-only if [[ "${CI_FINITE_MEMORY:-false}" == true ]]; then @@ -83,6 +86,9 @@ except (OSError, ValueError, AssertionError, KeyError, RuntimeError): carrier = os.environ.get("CI_CARRIER_GET") == "true" finite = os.environ.get("CI_FINITE_MEMORY") == "true" repair = os.environ.get("CI_MODEL_REPAIR_JOURNEY") == "true" +messages_path = root / "two-home-messages/installed-journeys.json" +messages = json.loads(messages_path.read_text()) if messages_path.exists() else {} +messages_required = os.environ.get("CI_TWO_HOME_MESSAGES") == "true" results = {name: "failed or not run" for name in ( "home_screenshots", "model_package_admission", *(["carrier_get"] if carrier else []), "installed_runtime_reply", "model_timing_observer", "process_cleanup", "disk_reserve")} @@ -127,6 +133,14 @@ results["engine_absent_home"] = ("passed" if current(absence) and absence.get("e ("engine_absent_home", "engine_absent_refusal", "home_screenshots", "process_cleanup", "disk_reserve")) else "failed or not run") elapsed += absence.get("elapsed_seconds", 0) + absence.get("fixture_preparation_seconds", 0) +if messages_required: + try: + message_current = journey["two_home_receipt_valid"](messages, journey["installed_message_identity"](data)) + except (OSError, ValueError, KeyError, AssertionError): + message_current = False + for name in ("community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery"): + results["two_home_" + name] = "passed" if message_current else "failed or not run" +elapsed += messages.get("elapsed_seconds", 0) repair_path = root / "model-repair/installed-journeys.json" repair_record = json.loads(repair_path.read_text()) if repair and repair_path.exists() else {} if repair: @@ -145,6 +159,7 @@ if repair: "fixture_policy": "fresh Home state and engine process per run; verified source engine prerequisite; same host with potentially warm OS file cache" + ("; reply package only on a separate holder Home, fetched over Carrier" if carrier else ""), "engine_absent_home": absence, + "two_home_messages": messages, **({"finite_memory_refusal": memory} if finite else {}), **({"model_repair": repair_record} if repair else {}), }, indent=2) + "\n") @@ -176,5 +191,5 @@ if spread["status"] == "incomplete" or any(result != "passed" for result in resu raise SystemExit("installed journey acceptance is incomplete") PY ;; - *) echo "Usage: $0 prepare|home|home-repeat|model-repair|summary" >&2; exit 2 ;; + *) echo "Usage: $0 prepare|home|home-repeat|model-repair|two-home-messages|summary" >&2; exit 2 ;; esac diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index ddc060709..54b8ec03f 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -13,6 +13,15 @@ class TwoHomeReceiptTests(unittest.TestCase): + def test_source_home_jobs_run_and_require_the_message_receipt(self): + source = (ROOT/'.github/workflows/ci.yml').read_text() + for job in ('source-home-linux', 'source-home-macos'): + block = source.split('\n '+job+':\n', 1)[1].split('\n source-home-', 1)[0] + self.assertIn('run: scripts/ci-installed-journeys.sh two-home-messages', block) + summary = block.split('name: summarize installed model journey', 1)[1] + self.assertIn("CI_TWO_HOME_MESSAGES: 'true'", summary) + self.assertNotIn('continue-on-error:', block.split('name: installed two-Home Community',1)[1].split(' - name:',1)[0]) + def identity(self): return {'candidate':'c'*40, 'source_tree':'d'*40, 'installed_runtime_sha256':'a'*64, 'source_components_sha256':'b'*64, 'installation_receipt_sha256':'e'*64} diff --git a/scripts/test-source-gate.sh b/scripts/test-source-gate.sh index 86aedf932..df44f3ee1 100755 --- a/scripts/test-source-gate.sh +++ b/scripts/test-source-gate.sh @@ -42,6 +42,7 @@ product_ui() { release() { node --test scripts/ci-model-package.test.mjs scripts/ci-installed-home-failure.test.mjs python3 scripts/ci-release-policy-test.py + python3 scripts/ci-installed-two-home-test.py python3 scripts/ci-download-cache-test.py python3 scripts/components-release-integrity-check.py --self-test python3 scripts/publish-platform-artifacts-test.py From 472c23643096b6f2c010f2584f8e38e0cc3ad16e Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 20:27:52 -0500 Subject: [PATCH 03/11] test: make copied Homes private and verify direct-only endpoints --- scripts/ci-installed-journeys.py | 24 ++++++++++++++++++++--- scripts/ci-installed-two-home-journey.mjs | 17 +++++++++++++--- scripts/ci-installed-two-home-test.py | 24 ++++++++++++++++++++++- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index ef1817605..a4497c158 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -1695,9 +1695,9 @@ def ignore(directory, names): needed = sum(path.stat().st_size for name in immutable for path in (data / name).rglob("*") if path.is_file() and not path.is_symlink() and not any(parent in excluded for parent in (path, *path.parents))) require_disk_space(data, needed) - destination.mkdir(parents=True, exist_ok=False) + destination.mkdir(mode=0o700, parents=True, exist_ok=False) target = destination / data.relative_to(home) - target.mkdir(parents=True) + target.mkdir(mode=0o700, parents=True) for name in immutable: if (data / name).exists(): shutil.copytree(data / name, target / name, symlinks=True, ignore=ignore) @@ -1759,6 +1759,9 @@ def two_home_receipt_valid(row, identity): and sum(item["after"].values()) == 0 for item in cleanup) and row.get("transport", {}).get("carrier_network") == "direct" and row.get("transport", {}).get("mdns") is False + and row.get("browser_cross_home_http_requests") == 0 + and len(row.get("direct_endpoint_observations", [])) == 5 + and all(item.get("relay_endpoints") == 0 for item in row["direct_endpoint_observations"]) and all(row.get("results", {}).get(name) == "passed" for name in ( "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) and all(row.get("negative_controls", {}).get(name, {}).get("assertion_rejected") is True @@ -1779,7 +1782,8 @@ def two_home_messages(home, data, evidence, network="same-host", fixture_root=No root.mkdir(mode=0o700, parents=True, exist_ok=False) control = root / "control" control.mkdir(mode=0o700) - record = dict(identity, network_arrangement=network, results={}, homes=[], negative_controls={}) + record = dict(identity, network_arrangement=network, results={}, homes=[], negative_controls={}, + direct_endpoint_observations=[]) receipt_path = evidence / "installed-journeys.json" children, fixtures, browser = {}, {}, None cleanup = [] @@ -1802,6 +1806,20 @@ def launch(name): env=environment(owner), stdout=log, stderr=log, start_new_session=True) children[name] = child wait_healthy(child, owner[2], "two-Home " + name) + coordinates = json.loads(bounded_text(owner[1] / "gateway-runtime-coords.json")) + api = coordinates["api_url"].rstrip("/") + token = post_json(api + "/api/auth/attach", {"secret": coordinates["attach_secret"], "scope": "shell"})["token"] + ticket = post_json(api + "/api/provider/peer/get_ticket", {}, token)["data"]["ticket"] + assert len(ticket) <= 16384 + decoded = json.loads(base64.b32decode(ticket.upper() + "=" * (-len(ticket) % 8))) + def relay(value): + if isinstance(value, dict): + return any("relay" in key.lower() or relay(item) for key, item in value.items()) + if isinstance(value, list): + return any(map(relay, value)) + return isinstance(value, str) and value.startswith(("http://", "https://", "ws://", "wss://")) + assert decoded["endpoints"] and not relay(decoded), "direct-only fixture advertised a relay route" + record["direct_endpoint_observations"].append({"home": name, "relay_endpoints": 0}) def stop(name): child = children.pop(name) row = cleanup_runtime(child, fixtures[name][1]) diff --git a/scripts/ci-installed-two-home-journey.mjs b/scripts/ci-installed-two-home-journey.mjs index a346b0471..d485a4113 100644 --- a/scripts/ci-installed-two-home-journey.mjs +++ b/scripts/ci-installed-two-home-journey.mjs @@ -24,7 +24,7 @@ async function run() { const [baseA, baseB, evidence, control] = process.argv.slice(2); const bases = [baseA, baseB]; assert(bases.every(base => new URL(base).hostname === 'localhost'), 'installed journey uses localhost for passkeys'); - const result = {stage:'sign_in', results:{}, negative_controls:{}}; + const result = {stage:'sign_in', results:{}, negative_controls:{}, observations:[], browser_cross_home_http_requests:0}; let sequence = 0; async function runtime(action) { const id = ++sequence; @@ -49,7 +49,15 @@ async function run() { browser = await chromium.launch({headless:true}); const homes=[]; for(const [i,base] of bases.entries()) { - const context=await browser.newContext({timezoneId:'UTC', viewport:{width:1440,height:900}}); + const context=await browser.newContext({timezoneId:'UTC', serviceWorkers:'block', viewport:{width:1440,height:900}}); + await context.route('**/*', route => { + const url = new URL(route.request().url()); + if (['http:', 'https:'].includes(url.protocol) && url.origin !== base) { + result.browser_cross_home_http_requests++; + return route.abort(); + } + return route.continue(); + }); const page=await context.newPage(); const cdp=await context.newCDPSession(page); await cdp.send('WebAuthn.enable'); @@ -61,7 +69,9 @@ async function run() { result.stage='passkey_registration_'+i; const registered=page.waitForResponse(r=>r.url().endsWith('/api/auth/passkey/register/complete')); await page.locator('#home-unlock-primary').click(); - assert((await registered).ok(),'passkey registration'); + const registration = await registered; + result.registration_http_status = registration.status(); + if (!registration.ok()) throw new Error('passkey registration HTTP '+registration.status()+' '+await registration.text()); result.stage='home_ready_'+i; await page.waitForFunction(()=>document.body.dataset.homeStatus==='ready'&&document.body.dataset.homeAuthority==='signed',null,{timeout:60000}); async function app(target,query={}) { @@ -201,6 +211,7 @@ async function run() { await direct.screenshot({path:join(evidence,'direct-a-desktop.png'),fullPage:true}); await direct.setViewportSize({width:390,height:844}); await direct.screenshot({path:join(evidence,'direct-a-phone.png'),fullPage:true}); + assert.equal(result.browser_cross_home_http_requests,0,'browser calls only its own Home; peer delivery belongs to Carrier'); result.status='passed'; } catch(error) { result.status='failed'; diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index 54b8ec03f..757258d3c 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -4,6 +4,8 @@ import json from pathlib import Path import runpy +import os +import stat import tempfile import unittest from unittest import mock @@ -13,6 +15,23 @@ class TwoHomeReceiptTests(unittest.TestCase): + def test_fresh_home_and_data_are_private_with_the_operator_umask(self): + fresh = JOURNEY['fresh_fixture'] + with tempfile.TemporaryDirectory() as temporary: + home = Path(temporary)/'source' + data = home/'.local/share/elastos' + data.mkdir(parents=True) + (data/'components.json').write_text('{}') + prior = os.umask(0o022) + try: + with mock.patch.dict(fresh.__globals__, {'engine_paths':lambda _: (None,None,None,data/'missing-engine')}): + destination = Path(temporary)/'fresh' + copied = fresh(home,data,destination,include_engine=False) + self.assertEqual(stat.S_IMODE(destination.stat().st_mode),0o700) + self.assertEqual(stat.S_IMODE(copied.stat().st_mode),0o700) + finally: + os.umask(prior) + def test_source_home_jobs_run_and_require_the_message_receipt(self): source = (ROOT/'.github/workflows/ci.yml').read_text() for job in ('source-home-linux', 'source-home-macos'): @@ -33,6 +52,8 @@ def receipt(self): for name in ('a','b','community')], 'process_cleanup':[{'status':'passed', 'after':{'runtime':0}} for _ in range(5)], 'transport':{'carrier_network':'direct','mdns':False}, + 'browser_cross_home_http_requests':0, + 'direct_endpoint_observations':[{'relay_endpoints':0} for _ in range(5)], 'results':{name:'passed' for name in ('community_post','direct_received','sender_delivered', 'offline_pending','restart_delivery')}, 'negative_controls':{name:{'assertion_rejected':True, 'api_state':'pending', 'ui_detail':'Sending'} @@ -46,7 +67,8 @@ def test_acceptance_refuses_stale_identity_unchecked_failure_controls_or_survivi changed = copy.deepcopy(valid) changed[key] = 'stale' self.assertFalse(check(changed, self.identity()), key) - for key, value in [('fixture_removed',False), ('homes',[]), ('process_cleanup',[])]: + for key, value in [('fixture_removed',False), ('homes',[]), ('process_cleanup',[]), + ('browser_cross_home_http_requests',1), ('direct_endpoint_observations',[])]: changed = copy.deepcopy(valid) changed[key] = value self.assertFalse(check(changed, self.identity()), key) From d304e03c5e4507a81d322ff2f1c0dc8ca7258870 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 20:53:50 -0500 Subject: [PATCH 04/11] test: reject failed two-Home receipts in the acceptance summary --- scripts/ci-installed-journeys.py | 3 ++- scripts/ci-installed-two-home-test.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index a4497c158..3d09343f8 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -1752,7 +1752,8 @@ def two_home_receipt_valid(row, identity): return False homes = row.get("homes", []) cleanup = row.get("process_cleanup", []) - return (row.get("fixture_removed") is True and len(homes) == 3 + return (row.get("status") == "passed" and "failure" not in row and "browser_failure" not in row + and row.get("fixture_removed") is True and len(homes) == 3 and {home.get("home") for home in homes} == {"a", "b", "community"} and all(home.get("installed_runtime_sha256") == identity["installed_runtime_sha256"] for home in homes) and len(cleanup) == 5 and all(item.get("status") == "passed" and item.get("after") diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index 757258d3c..4b4e6aa1a 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -47,7 +47,7 @@ def identity(self): def receipt(self): identity = self.identity() - return {**identity, 'fixture_removed':True, + return {**identity, 'status':'passed', 'fixture_removed':True, 'homes':[{'home':name, 'installed_runtime_sha256':identity['installed_runtime_sha256']} for name in ('a','b','community')], 'process_cleanup':[{'status':'passed', 'after':{'runtime':0}} for _ in range(5)], @@ -67,7 +67,8 @@ def test_acceptance_refuses_stale_identity_unchecked_failure_controls_or_survivi changed = copy.deepcopy(valid) changed[key] = 'stale' self.assertFalse(check(changed, self.identity()), key) - for key, value in [('fixture_removed',False), ('homes',[]), ('process_cleanup',[]), + for key, value in [('status','failed'), ('failure',{'phase':'late failure'}), ('browser_failure','failed'), + ('fixture_removed',False), ('homes',[]), ('process_cleanup',[]), ('browser_cross_home_http_requests',1), ('direct_endpoint_observations',[])]: changed = copy.deepcopy(valid) changed[key] = value From 88d8bcf2130293085d4088c0386c3e307c121529 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 21:41:32 -0500 Subject: [PATCH 05/11] test: remove operator details and comparison-only controls --- scripts/ci-installed-journeys.py | 16 +++++----------- scripts/ci-installed-journeys.sh | 2 +- scripts/ci-installed-two-home-journey.mjs | 4 ---- scripts/ci-installed-two-home-test.py | 2 +- scripts/test-source-gate.sh | 2 +- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index 3d09343f8..9f3ffdafe 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -1766,7 +1766,7 @@ def two_home_receipt_valid(row, identity): and all(row.get("results", {}).get(name) == "passed" for name in ( "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) and all(row.get("negative_controls", {}).get(name, {}).get("assertion_rejected") is True - for name in ("community_post", "direct_received", "sender_delivered")) + for name in ("sender_delivered",)) and row["negative_controls"]["sender_delivered"].get("api_state") == "pending" and row["negative_controls"]["sender_delivered"].get("ui_detail") == "Sending") @@ -1794,12 +1794,6 @@ def environment(owner): return {"PATH": os.environ["PATH"], "HOME": str(owner[0]), "XDG_DATA_HOME": str(owner[1].parent), "ELASTOS_CARRIER_NETWORK": "direct", "ELASTOS_CARRIER_MDNS": "0", "ELASTOS_QUIET_RUNTIME_NOTICES": "1"} - protected = {8090, 61240, 61200, 61201, 62684, 8096, 61185} - def port(kind=socket.SOCK_STREAM): - while True: - number = free_port(kind) - if number not in protected: - return number def launch(name): owner = fixtures[name] with (owner[0] / "runtime.private.log").open("ab") as log: @@ -1837,8 +1831,8 @@ def configure(*arguments): copied = fresh_fixture(home, data, destination, include_engine=False) assert installed_message_identity(copied) == identity with (copied / "config.toml").open("a") as config: - config.write(f'carrier_bind_addr = "127.0.0.1:{port(socket.SOCK_DGRAM)}"\n') - fixtures[name] = (destination, copied, f"127.0.0.1:{port()}") + config.write(f'carrier_bind_addr = "127.0.0.1:{free_port(socket.SOCK_DGRAM)}"\n') + fixtures[name] = (destination, copied, f"127.0.0.1:{free_port()}") record["homes"].append({"home": name, "installed_runtime_sha256": digest(copied / "bin/elastos")}) launch("community") configure("create-authority-key", "--key", root / "authority.key") @@ -1881,7 +1875,7 @@ def configure(*arguments): assert all(record["results"].get(name) == "passed" for name in ( "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) assert all(record["negative_controls"].get(name, {}).get("assertion_rejected") is True - for name in ("community_post", "direct_received", "sender_delivered")) + for name in ("sender_delivered",)) except BaseException as error: record["failure"] = observer_failure("two_home_messages", error, [str(root), str(home)]) raise @@ -1941,7 +1935,7 @@ def repeat(home, data, evidence, count): parser.add_argument("--model-repair", action="store_true", help="real Stop, Get different model and interrupted Get/Home restart/Retry") parser.add_argument("--two-home-messages", action="store_true") parser.add_argument("--network-arrangement", choices=["same-host"], default="same-host") - parser.add_argument("--two-home-root", type=Path, help="fresh disposable fixture path; Mac QA uses ~/.local/share/elastos-qa/two-home/") + parser.add_argument("--two-home-root", type=Path, help="fresh disposable fixture path") args = parser.parse_args() if args.two_home_messages: if args.repeat or args.home_only or args.carrier_get or args.finite_memory or args.model_repair: diff --git a/scripts/ci-installed-journeys.sh b/scripts/ci-installed-journeys.sh index df4a3c42c..252ed9982 100755 --- a/scripts/ci-installed-journeys.sh +++ b/scripts/ci-installed-journeys.sh @@ -159,7 +159,7 @@ if repair: "fixture_policy": "fresh Home state and engine process per run; verified source engine prerequisite; same host with potentially warm OS file cache" + ("; reply package only on a separate holder Home, fetched over Carrier" if carrier else ""), "engine_absent_home": absence, - "two_home_messages": messages, + **({"two_home_messages": messages} if messages_required else {}), **({"finite_memory_refusal": memory} if finite else {}), **({"model_repair": repair_record} if repair else {}), }, indent=2) + "\n") diff --git a/scripts/ci-installed-two-home-journey.mjs b/scripts/ci-installed-two-home-journey.mjs index d485a4113..b21383f06 100644 --- a/scripts/ci-installed-two-home-journey.mjs +++ b/scripts/ci-installed-two-home-journey.mjs @@ -107,8 +107,6 @@ async function run() { communityPoll=await api(communityB, '/api/apps/chat-room/poll', {since:0,mark_read:false}); return communityPoll.objects.some(row=>row.message_id===posted.message_id && row.body===postText); }); - assert.throws(()=>assertCommunityMessage(communityPoll, posted.message_id, postText+' wrong'), {name:'AssertionError'}); - result.negative_controls.community_post={assertion_rejected:true, broken_input:'wrong expected text against real B poll'}; assertCommunityMessage(communityPoll, posted.message_id, postText); result.results.community_post='passed'; result.community_text=postText; @@ -143,8 +141,6 @@ async function run() { receivedMessages=(await api(bc,path)).messages; return receivedMessages.find(m=>m.text===text&&m.direction==='incoming'&&m.delivery_state==='received'); }); - assert.throws(()=>assertReceivedDirect(receivedMessages, received.message_id, text+' wrong'), {name:'AssertionError'}); - result.negative_controls.direct_received={assertion_rejected:true, broken_input:'wrong expected text against real B messages'}; assertReceivedDirect(receivedMessages, received.message_id, text); result.results.direct_received='passed'; const senderMessage=async expected=> (await api(ac,path)).messages.find(m=>m.text===expected&&m.direction==='outgoing'); diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index 4b4e6aa1a..bd4cfc62e 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -57,7 +57,7 @@ def receipt(self): 'results':{name:'passed' for name in ('community_post','direct_received','sender_delivered', 'offline_pending','restart_delivery')}, 'negative_controls':{name:{'assertion_rejected':True, 'api_state':'pending', 'ui_detail':'Sending'} - for name in ('community_post','direct_received','sender_delivered')}} + for name in ('sender_delivered',)}} def test_acceptance_refuses_stale_identity_unchecked_failure_controls_or_surviving_processes(self): valid = self.receipt() diff --git a/scripts/test-source-gate.sh b/scripts/test-source-gate.sh index df44f3ee1..ecfaddd9e 100755 --- a/scripts/test-source-gate.sh +++ b/scripts/test-source-gate.sh @@ -40,7 +40,7 @@ product_ui() { } release() { - node --test scripts/ci-model-package.test.mjs scripts/ci-installed-home-failure.test.mjs + node --test scripts/ci-model-package.test.mjs scripts/ci-installed-home-failure.test.mjs scripts/ci-installed-two-home.test.mjs python3 scripts/ci-release-policy-test.py python3 scripts/ci-installed-two-home-test.py python3 scripts/ci-download-cache-test.py From 2e10395c74ae5563468143aca1768bcdf50fdf13 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 21:42:13 -0500 Subject: [PATCH 06/11] test: validate observed Carrier addresses for the selected arrangement --- scripts/ci-installed-journeys.py | 71 ++++++++++++++++++--------- scripts/ci-installed-two-home-test.py | 27 ++++++++-- 2 files changed, 70 insertions(+), 28 deletions(-) diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index 9f3ffdafe..d05c21353 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -1747,7 +1747,39 @@ def remove_message_fixture(root): shutil.rmtree(root) -def two_home_receipt_valid(row, identity): +MESSAGE_NETWORKS = { + "same-host": { + "environment": {"ELASTOS_CARRIER_NETWORK": "direct", "ELASTOS_CARRIER_MDNS": "0"}, + "bind_host": "127.0.0.1", "browser_host": "localhost", "ticket_transport": "Ip", + "launches": {"community": 2, "a": 1, "b": 2}, + }, +} + + +def message_endpoints_valid(homes, observations, arrangement): + settings = MESSAGE_NETWORKS.get(arrangement) + if settings is None: + return False + addresses = {home.get("home"): home.get("carrier_bind_address", "") for home in homes} + if set(addresses) != set(settings["launches"]): + return False + for address in addresses.values(): + host, _, port = address.rpartition(":") + if host != settings["bind_host"] or not port.isdecimal() or not 0 < int(port) < 65536: + return False + counts = dict.fromkeys(settings["launches"], 0) + for observation in observations: + name = observation.get("home") + if name not in addresses or observation.get("ticket_addresses") != [ + {settings["ticket_transport"]: addresses[name]}]: + return False + counts[name] += 1 + return counts == settings["launches"] + + +def two_home_receipt_valid(row, identity, network_arrangement="same-host"): + if row.get("network_arrangement") != network_arrangement or network_arrangement not in MESSAGE_NETWORKS: + return False if any(row.get(key) != value for key, value in identity.items()): return False homes = row.get("homes", []) @@ -1758,11 +1790,8 @@ def two_home_receipt_valid(row, identity): and all(home.get("installed_runtime_sha256") == identity["installed_runtime_sha256"] for home in homes) and len(cleanup) == 5 and all(item.get("status") == "passed" and item.get("after") and sum(item["after"].values()) == 0 for item in cleanup) - and row.get("transport", {}).get("carrier_network") == "direct" - and row.get("transport", {}).get("mdns") is False and row.get("browser_cross_home_http_requests") == 0 - and len(row.get("direct_endpoint_observations", [])) == 5 - and all(item.get("relay_endpoints") == 0 for item in row["direct_endpoint_observations"]) + and message_endpoints_valid(homes, row.get("direct_endpoint_observations", []), network_arrangement) and all(row.get("results", {}).get(name) == "passed" for name in ( "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) and all(row.get("negative_controls", {}).get(name, {}).get("assertion_rejected") is True @@ -1773,8 +1802,9 @@ def two_home_receipt_valid(row, identity): def two_home_messages(home, data, evidence, network="same-host", fixture_root=None): """Installed Community and Direct journey. Topology belongs to setup, not assertions.""" - if network != "same-host": + if network not in MESSAGE_NETWORKS: raise RuntimeError("unsupported two-Home network arrangement") + settings = MESSAGE_NETWORKS[network] identity = installed_message_identity(data) evidence.mkdir(parents=True, exist_ok=False) root = fixture_root or home.parent / "two-home-message-fixture" @@ -1792,8 +1822,7 @@ def two_home_messages(home, data, evidence, network="same-host", fixture_root=No # Explicit environment excludes ambient relay, public-network and provider overrides. def environment(owner): return {"PATH": os.environ["PATH"], "HOME": str(owner[0]), "XDG_DATA_HOME": str(owner[1].parent), - "ELASTOS_CARRIER_NETWORK": "direct", "ELASTOS_CARRIER_MDNS": "0", - "ELASTOS_QUIET_RUNTIME_NOTICES": "1"} + **settings["environment"], "ELASTOS_QUIET_RUNTIME_NOTICES": "1"} def launch(name): owner = fixtures[name] with (owner[0] / "runtime.private.log").open("ab") as log: @@ -1807,14 +1836,11 @@ def launch(name): ticket = post_json(api + "/api/provider/peer/get_ticket", {}, token)["data"]["ticket"] assert len(ticket) <= 16384 decoded = json.loads(base64.b32decode(ticket.upper() + "=" * (-len(ticket) % 8))) - def relay(value): - if isinstance(value, dict): - return any("relay" in key.lower() or relay(item) for key, item in value.items()) - if isinstance(value, list): - return any(map(relay, value)) - return isinstance(value, str) and value.startswith(("http://", "https://", "ws://", "wss://")) - assert decoded["endpoints"] and not relay(decoded), "direct-only fixture advertised a relay route" - record["direct_endpoint_observations"].append({"home": name, "relay_endpoints": 0}) + endpoints = decoded["endpoints"] + assert len(endpoints) == 1, "fixture ticket must describe one installed Home" + observed = endpoints[0]["addrs"] + assert observed == [{settings["ticket_transport"]: owner[3]}], "ticket differs from configured Carrier address" + record["direct_endpoint_observations"].append({"home": name, "ticket_addresses": observed}) def stop(name): child = children.pop(name) row = cleanup_runtime(child, fixtures[name][1]) @@ -1830,10 +1856,12 @@ def configure(*arguments): destination = root / name copied = fresh_fixture(home, data, destination, include_engine=False) assert installed_message_identity(copied) == identity + carrier = f"{settings['bind_host']}:{free_port(socket.SOCK_DGRAM)}" with (copied / "config.toml").open("a") as config: - config.write(f'carrier_bind_addr = "127.0.0.1:{free_port(socket.SOCK_DGRAM)}"\n') - fixtures[name] = (destination, copied, f"127.0.0.1:{free_port()}") - record["homes"].append({"home": name, "installed_runtime_sha256": digest(copied / "bin/elastos")}) + config.write(f'carrier_bind_addr = "{carrier}"\n') + fixtures[name] = (destination, copied, f"{settings['bind_host']}:{free_port()}", carrier) + record["homes"].append({"home": name, "installed_runtime_sha256": digest(copied / "bin/elastos"), + "carrier_bind_address": carrier}) launch("community") configure("create-authority-key", "--key", root / "authority.key") configure("export-local-bootstrap-receipt", "--data-root", fixtures["community"][1], @@ -1848,10 +1876,7 @@ def configure(*arguments): target.chmod(0o600) for name in fixtures: launch(name) - record["transport"] = {"carrier_network": "direct", "mdns": False, - "bootstrap": "disposable local Community", - "peer_route": "Carrier PeerDid; fixture supplies no HTTP peer routes"} - bases = ["http://localhost:" + fixtures[name][2].rsplit(":", 1)[1] for name in ("a", "b")] + bases = [f"http://{settings['browser_host']}:" + fixtures[name][2].rsplit(":", 1)[1] for name in ("a", "b")] with (root / "browser.private.log").open("wb") as log: browser = subprocess.Popen(["node", "scripts/ci-installed-two-home-journey.mjs", *bases, str(evidence), str(control)], stdout=log, stderr=log, start_new_session=True) diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index bd4cfc62e..87dd6e603 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -47,13 +47,14 @@ def identity(self): def receipt(self): identity = self.identity() - return {**identity, 'status':'passed', 'fixture_removed':True, - 'homes':[{'home':name, 'installed_runtime_sha256':identity['installed_runtime_sha256']} - for name in ('a','b','community')], + return {**identity, 'status':'passed', 'fixture_removed':True, 'network_arrangement':'same-host', + 'homes':[{'home':name, 'installed_runtime_sha256':identity['installed_runtime_sha256'], + 'carrier_bind_address':f'127.0.0.1:{1025+index}'} + for index,name in enumerate(('a','b','community'))], 'process_cleanup':[{'status':'passed', 'after':{'runtime':0}} for _ in range(5)], - 'transport':{'carrier_network':'direct','mdns':False}, 'browser_cross_home_http_requests':0, - 'direct_endpoint_observations':[{'relay_endpoints':0} for _ in range(5)], + 'direct_endpoint_observations':[{'home':name,'ticket_addresses':[{'Ip':f'127.0.0.1:{1025+index}'}]} + for index,name in ((2,'community'),(2,'community'),(0,'a'),(1,'b'),(1,'b'))], 'results':{name:'passed' for name in ('community_post','direct_received','sender_delivered', 'offline_pending','restart_delivery')}, 'negative_controls':{name:{'assertion_rejected':True, 'api_state':'pending', 'ui_detail':'Sending'} @@ -88,6 +89,22 @@ def test_acceptance_refuses_stale_identity_unchecked_failure_controls_or_survivi changed['homes'][1]['home'] = 'a' self.assertFalse(check(changed, self.identity())) + def test_network_arrangement_and_each_observed_ticket_must_match_configuration(self): + check = JOURNEY['two_home_receipt_valid'] + valid = self.receipt() + changed = copy.deepcopy(valid) + changed['network_arrangement'] = 'two-nat' + self.assertFalse(check(changed, self.identity())) + self.assertFalse(check(valid, self.identity(), 'two-nat')) + for index in range(5): + for address in ({'Relay':'https://relay.invalid'}, {'Ip':'192.0.2.1:1234'}, {'Ip':'127.0.0.1:1234'}): + changed = copy.deepcopy(valid) + changed['direct_endpoint_observations'][index]['ticket_addresses'] = [address] + self.assertFalse(check(changed, self.identity()), (index, address)) + changed = copy.deepcopy(valid) + changed['homes'][0]['carrier_bind_address'] = '192.0.2.1:1234' + self.assertFalse(check(changed, self.identity())) + def test_source_identity_rejects_changed_runtime_and_browser_asset_before_launch(self): identify = JOURNEY['installed_message_identity'] with tempfile.TemporaryDirectory() as temporary: From 10648b6a3dae1f9de9e7e0fcf02b3eab32cd81c7 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 21:45:16 -0500 Subject: [PATCH 07/11] test: finish cleanup after failures and bound the installed journey --- .github/workflows/ci.yml | 10 +- scripts/ci-installed-journeys.py | 232 +++++++++++++++------- scripts/ci-installed-two-home-journey.mjs | 5 +- scripts/ci-installed-two-home-test.py | 93 +++++++++ 4 files changed, 263 insertions(+), 77 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa6ba797a..97dffd87f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -926,11 +926,6 @@ jobs: - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: '26' - - name: installed two-Home Community and direct messages - timeout-minutes: 10 - env: - CI_SOURCE_HOME: ${{ runner.temp }}/elastos-source-home - run: scripts/ci-installed-journeys.sh two-home-messages - name: prepare signed SmolLM2 fixture timeout-minutes: 20 env: @@ -952,6 +947,11 @@ jobs: CI_SOURCE_HOME: ${{ runner.temp }}/elastos-source-home CI_MODEL_REPAIR_JOURNEY: 'true' run: scripts/ci-installed-journeys.sh model-repair + - name: installed two-Home Community and direct messages + timeout-minutes: 10 + env: + CI_SOURCE_HOME: ${{ runner.temp }}/elastos-source-home + run: scripts/ci-installed-journeys.sh two-home-messages - name: summarize installed model journey if: always() env: diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index d05c21353..347f6d5fb 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -2,6 +2,7 @@ """Run journeys against this job's installed Home; save only public proof.""" import argparse import base64 +from contextlib import contextmanager import hashlib import json import os @@ -10,6 +11,7 @@ import select import secrets import signal +import shlex import shutil import socket import stat @@ -1549,7 +1551,8 @@ def run(home, data, evidence, model=True, carrier=False, memory_gib=0, repair=Fa record["finite_memory"] = finite.finish() record["process_cleanup"] = {"status": record["finite_memory"]["status"]} record["results"]["finite_memory_boundary"] = record["finite_memory"]["status"] - (evidence / "installed-journeys.json").write_text(json.dumps(record, indent=2) + "\n") + record["elapsed_seconds"] = round(time.monotonic() - started, 2) + (evidence / "installed-journeys.json").write_text(json.dumps(record, indent=2) + "\n") if holder: cleanup_runtime(holder, holder_data) raise @@ -1666,6 +1669,7 @@ def run(home, data, evidence, model=True, carrier=False, memory_gib=0, repair=Fa and record["process_cleanup"].get("before", {}).get("llama_server") == 0 else "failed") record["results"]["engine_absent_home"] = "passed" if record["engine_absent_after_ui"] else "failed" + record["elapsed_seconds"] = round(time.monotonic() - started, 2) (evidence / "installed-journeys.json").write_text(json.dumps(record, indent=2) + "\n") if record["process_cleanup"]["status"] != "passed": @@ -1741,12 +1745,108 @@ def remove_message_fixture(root): root = Path(os.path.abspath(root)) for path in (root, *root.parents): assert stat.S_ISDIR(path.lstat().st_mode) and not path.is_symlink() - assert not owned_processes(process_rows(), -1, root) - before = root.lstat() - assert (root.lstat().st_dev, root.lstat().st_ino) == (before.st_dev, before.st_ino) + assert not any(row["command"].startswith(str(root) + "/") for row in process_rows().values()) shutil.rmtree(root) +# The 10-minute CI step reserves 360 s for work, 150 s for process cleanup, +# and 30 s for disk/removal/receipt operations: 540 s, with 60 s runner margin. +@contextmanager +def message_timeout(seconds): + def expired(_signum, _frame): + raise TimeoutError("two-Home phase deadline") + started = time.monotonic() + previous = signal.signal(signal.SIGALRM, expired) + timer = signal.setitimer(signal.ITIMER_REAL, 0) + signal.setitimer(signal.ITIMER_REAL, min(seconds, timer[0]) if timer[0] else seconds) + try: + yield + finally: + signal.setitimer(signal.ITIMER_REAL, 0) + signal.signal(signal.SIGALRM, previous) + if timer[0]: + signal.setitimer(signal.ITIMER_REAL, max(.001, timer[0] - (time.monotonic() - started)), timer[1]) + + +def remember_message_processes(child, known, marker=None): + rows = {pid: row for pid, row in process_rows().items() + if not row["command"].endswith(" ")} + roots = {pid for pid, old in known.items() if pid in rows + and all(rows[pid][key] == old[key] for key in ("start", "command"))} + if not known and child.pid in rows and child.poll() is None: + roots.add(child.pid) + # Chromium has its own process group. Its unique fixture argument also + # identifies it if Node exits before the next descendant census. + if marker: + roots.update(pid for pid, row in rows.items() if marker in shlex.split(row["command"])) + for pid, row in rows.items(): + parent, visited = pid, set() + while parent in rows and parent not in roots and parent not in visited: + visited.add(parent) + parent = rows[parent]["ppid"] + if parent in roots: + known[pid] = row + return {pid: row for pid, row in known.items() if pid in rows + and all(rows[pid][key] == row[key] for key in ("start", "command"))} + + +def stop_message_processes(child, known, marker=None, grace=5, killed=3): + """Bounded TERM/KILL census, retaining detached children across reparenting.""" + remaining = remember_message_processes(child, known, marker) + for action, seconds in ((signal.SIGTERM, grace), (signal.SIGKILL, killed)): + for pid, row in remaining.items(): + latest = process_rows().get(pid) + if latest and all(latest[key] == row[key] for key in ("start", "command")): + try: + os.kill(pid, action) + except ProcessLookupError: + pass + end = time.monotonic() + seconds + while remaining and time.monotonic() < end: + child.poll() # Reap our child before checking the census. + time.sleep(.05) + remaining = remember_message_processes(child, known, marker) + if not remaining: + break + assert not remaining, "two-Home observer process survived cleanup" + + +def finish_message_fixture(root, data, evidence, record, children, fixtures, stop, browser, known, started): + """Attempt every cleanup and save the failure receipt before raising.""" + failures = [] + def attempt(label, action, seconds): + try: + with message_timeout(seconds): + action() + return True + except BaseException as error: + failures.append(observer_failure(label, error, [str(root)])) + return False + if browser: + attempt("browser_cleanup", lambda: stop_message_processes( + browser, known, "--two-home-fixture=" + str(root / "control")), 15) + for name in list(children): + child = children[name] + if not attempt("stop_" + name, lambda: stop(name), 35): + # A failed Runtime census/stop still gets an independent PID-bound + # attempt, then the next Home is stopped regardless of its result. + attempt("fallback_" + name, lambda: stop_message_processes( + child, owned_processes(process_rows(), child.pid, fixtures[name][1])), 10) + def remove_and_measure(): + attempt("disk_reserve", lambda: record.update(disk_after=require_disk_space(data)), 5) + if attempt("fixture_removal", lambda: remove_message_fixture(root), 20): + record["fixture_removed"] = True + with message_timeout(30): + remove_and_measure() + if failures: + record["cleanup_failures"] = failures + record["status"] = "failed" + record["elapsed_seconds"] = round(time.monotonic() - started, 2) + (evidence / "installed-journeys.json").write_text(json.dumps(record, indent=2) + "\n") + if failures: + raise RuntimeError("two-Home cleanup failed; see installed journey receipt") + + MESSAGE_NETWORKS = { "same-host": { "environment": {"ELASTOS_CARRIER_NETWORK": "direct", "ELASTOS_CARRIER_MDNS": "0"}, @@ -1815,8 +1915,8 @@ def two_home_messages(home, data, evidence, network="same-host", fixture_root=No control.mkdir(mode=0o700) record = dict(identity, network_arrangement=network, results={}, homes=[], negative_controls={}, direct_endpoint_observations=[]) - receipt_path = evidence / "installed-journeys.json" children, fixtures, browser = {}, {}, None + browser_processes = {} cleanup = [] started = time.monotonic() # Explicit environment excludes ambient relay, public-network and provider overrides. @@ -1824,6 +1924,7 @@ def environment(owner): return {"PATH": os.environ["PATH"], "HOME": str(owner[0]), "XDG_DATA_HOME": str(owner[1].parent), **settings["environment"], "ELASTOS_QUIET_RUNTIME_NOTICES": "1"} def launch(name): + assert name not in children, "Home already has an owned Runtime" owner = fixtures[name] with (owner[0] / "runtime.private.log").open("ab") as log: child = subprocess.Popen([str(owner[1] / "bin/elastos"), "gateway", "--addr", owner[2]], @@ -1842,85 +1943,74 @@ def launch(name): assert observed == [{settings["ticket_transport"]: owner[3]}], "ticket differs from configured Carrier address" record["direct_endpoint_observations"].append({"home": name, "ticket_addresses": observed}) def stop(name): - child = children.pop(name) - row = cleanup_runtime(child, fixtures[name][1]) + child = children[name] + with message_timeout(35): + row = cleanup_runtime(child, fixtures[name][1]) cleanup.append(dict(row, home=name)) assert row["status"] == "passed", "two-Home process cleanup failed" + del children[name] def configure(*arguments): owner = fixtures["community"] with (root / "configuration.private.log").open("ab") as log: subprocess.run([str(owner[1] / "bin/elastos"), "collaboration-config", *map(str, arguments)], env=environment(owner), stdout=log, stderr=log, check=True, timeout=60) try: - for name in ("community", "a", "b"): - destination = root / name - copied = fresh_fixture(home, data, destination, include_engine=False) - assert installed_message_identity(copied) == identity - carrier = f"{settings['bind_host']}:{free_port(socket.SOCK_DGRAM)}" - with (copied / "config.toml").open("a") as config: - config.write(f'carrier_bind_addr = "{carrier}"\n') - fixtures[name] = (destination, copied, f"{settings['bind_host']}:{free_port()}", carrier) - record["homes"].append({"home": name, "installed_runtime_sha256": digest(copied / "bin/elastos"), - "carrier_bind_address": carrier}) - launch("community") - configure("create-authority-key", "--key", root / "authority.key") - configure("export-local-bootstrap-receipt", "--data-root", fixtures["community"][1], - "--runtime-kind", "gateway", "--output", root / "bootstrap.json") - configure("generate-initial", "--authority-key", root / "authority.key", "--network-id", "ci.two-home", - "--conversation-id", "community", "--bootstrap-peer", root / "bootstrap.json", "--output", root / "network.json") - configure("verify", "--input", root / "network.json") - stop("community") - for owner in fixtures.values(): - target = owner[1] / "collaboration-network-v1.json" - shutil.copy2(root / "network.json", target) - target.chmod(0o600) - for name in fixtures: - launch(name) - bases = [f"http://{settings['browser_host']}:" + fixtures[name][2].rsplit(":", 1)[1] for name in ("a", "b")] - with (root / "browser.private.log").open("wb") as log: - browser = subprocess.Popen(["node", "scripts/ci-installed-two-home-journey.mjs", *bases, - str(evidence), str(control)], stdout=log, stderr=log, start_new_session=True) - deadline, last = time.monotonic() + 420, 0 - while browser.poll() is None: - assert time.monotonic() < deadline, "two-Home browser deadline" - request = control / "request.json" - if request.exists(): - value = private_json(request) - if value["id"] > last: - assert value["id"] == last + 1 and value["action"] in {"stop_b", "start_b"} - stop("b") if value["action"] == "stop_b" else launch("b") - last = value["id"] - private_json(control / "response.json", {"id": last, "status": "passed"}) - time.sleep(.1) - observed = json.loads((evidence / "two-home-ui.json").read_text()) - record.update(observed) - if browser.returncode and (control / "error.private.txt").exists(): - record["browser_failure"] = redact((control / "error.private.txt").read_text(), [str(root)])[:1200] - assert browser.returncode == 0, "installed two-Home browser journey failed" - assert all(record["results"].get(name) == "passed" for name in ( - "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) - assert all(record["negative_controls"].get(name, {}).get("assertion_rejected") is True - for name in ("sender_delivered",)) + with message_timeout(360): + for name in ("community", "a", "b"): + destination = root / name + copied = fresh_fixture(home, data, destination, include_engine=False) + assert installed_message_identity(copied) == identity + carrier = f"{settings['bind_host']}:{free_port(socket.SOCK_DGRAM)}" + with (copied / "config.toml").open("a") as config: + config.write(f'carrier_bind_addr = "{carrier}"\n') + fixtures[name] = (destination, copied, f"{settings['bind_host']}:{free_port()}", carrier) + record["homes"].append({"home": name, "installed_runtime_sha256": digest(copied / "bin/elastos"), + "carrier_bind_address": carrier}) + launch("community") + configure("create-authority-key", "--key", root / "authority.key") + configure("export-local-bootstrap-receipt", "--data-root", fixtures["community"][1], + "--runtime-kind", "gateway", "--output", root / "bootstrap.json") + configure("generate-initial", "--authority-key", root / "authority.key", "--network-id", "ci.two-home", + "--conversation-id", "community", "--bootstrap-peer", root / "bootstrap.json", "--output", root / "network.json") + configure("verify", "--input", root / "network.json") + stop("community") + for owner in fixtures.values(): + target = owner[1] / "collaboration-network-v1.json" + shutil.copy2(root / "network.json", target) + target.chmod(0o600) + for name in fixtures: + launch(name) + bases = [f"http://{settings['browser_host']}:" + fixtures[name][2].rsplit(":", 1)[1] for name in ("a", "b")] + with (root / "browser.private.log").open("wb") as log: + browser = subprocess.Popen(["node", "scripts/ci-installed-two-home-journey.mjs", *bases, + str(evidence), str(control)], stdout=log, stderr=log, start_new_session=True) + last = 0 + while browser.poll() is None: + remember_message_processes(browser, browser_processes, "--two-home-fixture=" + str(control)) + request = control / "request.json" + if request.exists(): + value = private_json(request) + if value["id"] > last: + assert value["id"] == last + 1 and value["action"] in {"stop_b", "start_b"} + stop("b") if value["action"] == "stop_b" else launch("b") + last = value["id"] + private_json(control / "response.json", {"id": last, "status": "passed"}) + time.sleep(.1) + observed = json.loads((evidence / "two-home-ui.json").read_text()) + record.update(observed) + if browser.returncode and (control / "error.private.txt").exists(): + record["browser_failure"] = redact((control / "error.private.txt").read_text(), [str(root)])[:1200] + assert browser.returncode == 0, "installed two-Home browser journey failed" + assert all(record["results"].get(name) == "passed" for name in ( + "community_post", "direct_received", "sender_delivered", "offline_pending", "restart_delivery")) + assert all(record["negative_controls"].get(name, {}).get("assertion_rejected") is True + for name in ("sender_delivered",)) except BaseException as error: record["failure"] = observer_failure("two_home_messages", error, [str(root), str(home)]) raise finally: - if browser and browser.poll() is None: - os.killpg(browser.pid, signal.SIGTERM) - try: - browser.wait(timeout=10) - except subprocess.TimeoutExpired: - os.killpg(browser.pid, signal.SIGKILL) - browser.wait(timeout=5) - for name in list(children): - stop(name) record["process_cleanup"] = cleanup - record["elapsed_seconds"] = round(time.monotonic() - started, 2) - record["disk_after"] = require_disk_space(data) - # Private keys, sessions and Runtime logs have one lifecycle: this invocation. - remove_message_fixture(root) - record["fixture_removed"] = True - receipt_path.write_text(json.dumps(record, indent=2) + "\n") + finish_message_fixture(root, data, evidence, record, children, fixtures, stop, browser, browser_processes, started) def repeat(home, data, evidence, count): diff --git a/scripts/ci-installed-two-home-journey.mjs b/scripts/ci-installed-two-home-journey.mjs index b21383f06..1518e6486 100644 --- a/scripts/ci-installed-two-home-journey.mjs +++ b/scripts/ci-installed-two-home-journey.mjs @@ -46,7 +46,7 @@ async function run() { let browser; try { result.stage='browser_launch'; - browser = await chromium.launch({headless:true}); + browser = await chromium.launch({headless:true, args:['--two-home-fixture='+control]}); const homes=[]; for(const [i,base] of bases.entries()) { const context=await browser.newContext({timezoneId:'UTC', serviceWorkers:'block', viewport:{width:1440,height:900}}); @@ -100,6 +100,7 @@ async function run() { result.stage='community_post'; await communityA.locator('#message-input:enabled').waitFor({timeout:90000}); await api(communityB, '/api/apps/chat-room/session/start', {}); + await communityB.locator('#message-input:enabled').waitFor({timeout:60000}); const postText='Two Home Community '+crypto.randomUUID(); const posted=await api(communityA, '/api/apps/chat-room/objects/send', {request_id:'two-home:'+crypto.randomUUID(),body:postText}); let communityPoll; @@ -108,6 +109,8 @@ async function run() { return communityPoll.objects.some(row=>row.message_id===posted.message_id && row.body===postText); }); assertCommunityMessage(communityPoll, posted.message_id, postText); + await communityB.locator('#message-list .message-body').filter({hasText:postText}).waitFor({state:'visible',timeout:60000}); + assert.equal(await communityB.locator('#message-list .message-body').filter({hasText:postText}).innerText(),postText); result.results.community_post='passed'; result.community_text=postText; await communityB.screenshot({path:join(evidence,'community-b-desktop.png'),fullPage:true}); diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index 87dd6e603..7d1a7fb12 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -6,6 +6,10 @@ import runpy import os import stat +import subprocess +import sys +import time +import signal import tempfile import unittest from unittest import mock @@ -34,6 +38,9 @@ def test_fresh_home_and_data_are_private_with_the_operator_umask(self): def test_source_home_jobs_run_and_require_the_message_receipt(self): source = (ROOT/'.github/workflows/ci.yml').read_text() + linux = source.split('\n source-home-linux:\n',1)[1].split('\n source-home-',1)[0] + self.assertLess(linux.index('run: scripts/ci-installed-journeys.sh model-repair'), + linux.index('run: scripts/ci-installed-journeys.sh two-home-messages')) for job in ('source-home-linux', 'source-home-macos'): block = source.split('\n '+job+':\n', 1)[1].split('\n source-home-', 1)[0] self.assertIn('run: scripts/ci-installed-journeys.sh two-home-messages', block) @@ -105,6 +112,92 @@ def test_network_arrangement_and_each_observed_ticket_must_match_configuration(s changed['homes'][0]['carrier_bind_address'] = '192.0.2.1:1234' self.assertFalse(check(changed, self.identity())) + def test_fixture_removal_refuses_nested_home_process(self): + remove = JOURNEY['remove_message_fixture'] + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary)/'fixture' + root.mkdir() + row = {'command':str(root/'b/data/bin/elastos')+' gateway'} + with mock.patch.dict(remove.__globals__, {'process_rows':lambda: {123:row}}): + with self.assertRaises(AssertionError): + remove(root) + self.assertTrue(root.exists()) + with mock.patch.dict(remove.__globals__, {'process_rows':lambda: {}}): + remove(root) + self.assertFalse(root.exists()) + + def test_failed_stop_and_disk_check_finish_other_stops_remove_keys_and_write_failure_receipt(self): + finish = JOURNEY['finish_message_fixture'] + for disk_fails in (False, True): + with self.subTest(disk_fails=disk_fails), tempfile.TemporaryDirectory() as temporary: + root = Path(temporary)/'fixture' + root.mkdir() + (root/'authority.key').write_text('disposable test key') + evidence = Path(temporary)/'evidence' + evidence.mkdir() + stopped = [] + children = {'a':mock.Mock(pid=101), 'b':mock.Mock(pid=102), 'community':mock.Mock(pid=103)} + def stop(name): + stopped.append(name) + if name == 'a': + raise RuntimeError('injected stop failure') + del children[name] + def disk(_): + if disk_fails: + raise RuntimeError('injected disk failure') + return {'free':123} + fallback = mock.Mock() + with mock.patch.dict(finish.__globals__, {'process_rows':lambda: {}, + 'stop_message_processes':fallback, 'require_disk_space':disk}): + with self.assertRaisesRegex(RuntimeError, 'cleanup failed'): + finish(root, root, evidence, {'status':'passed'}, children, + {name:(root,root) for name in children}, stop, None, {}, time.monotonic()) + self.assertEqual(stopped, ['a','b','community']) + fallback.assert_called_once() + self.assertFalse(root.exists()) + receipt = json.loads((evidence/'installed-journeys.json').read_text()) + self.assertEqual(receipt['status'], 'failed') + self.assertTrue(receipt['fixture_removed']) + self.assertEqual(len(receipt['cleanup_failures']), 2 if disk_fails else 1) + self.assertNotIn('disposable test key', json.dumps(receipt)) + + def test_work_deadline_interrupts_a_hung_phase_and_restores_the_timer(self): + before = signal.getsignal(signal.SIGALRM) + with self.assertRaises(TimeoutError): + with JOURNEY['message_timeout'](.05): + time.sleep(1) + self.assertEqual(signal.getitimer(signal.ITIMER_REAL), (0,0)) + self.assertEqual(signal.getsignal(signal.SIGALRM), before) + + def test_sigkill_fallback_stops_a_detached_browser_after_node_exits(self): + stop = JOURNEY['stop_message_processes'] + with tempfile.TemporaryDirectory() as temporary: + pidfile = Path(temporary)/'browser.pid' + marker = '--two-home-fixture='+temporary + detached_code = 'import signal,time; signal.signal(signal.SIGTERM,signal.SIG_IGN); time.sleep(60)' + parent_code = ('import subprocess,sys; from pathlib import Path; ' + 'p=subprocess.Popen([sys.executable,"-c",sys.argv[2],sys.argv[3]],start_new_session=True); ' + 'Path(sys.argv[1]).write_text(str(p.pid))') + parent = subprocess.Popen([sys.executable,'-c',parent_code,str(pidfile),detached_code,marker]) + detached = None + try: + parent.wait(timeout=5) + detached = int(pidfile.read_text()) + # Node has already exited; the fixture marker identifies Chromium. + with JOURNEY['message_timeout'](10): + stop(parent, {}, marker, grace=.2, killed=2) + rows = JOURNEY['process_rows']() + self.assertTrue(detached not in rows or rows[detached]['command'].endswith(' ')) + finally: + if detached: + try: + os.kill(detached, signal.SIGKILL) + except ProcessLookupError: + pass + if parent.poll() is None: + parent.kill() + parent.wait() + def test_source_identity_rejects_changed_runtime_and_browser_asset_before_launch(self): identify = JOURNEY['installed_message_identity'] with tempfile.TemporaryDirectory() as temporary: From eb896668ffe05d90180a2bb3c7c4c09000cf6925 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 21:47:59 -0500 Subject: [PATCH 08/11] test: prove detached browser cleanup reaches SIGKILL --- scripts/ci-installed-journeys.py | 3 +-- scripts/ci-installed-two-home-test.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index 347f6d5fb..fc8fc49a6 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -11,7 +11,6 @@ import select import secrets import signal -import shlex import shutil import socket import stat @@ -1778,7 +1777,7 @@ def remember_message_processes(child, known, marker=None): # Chromium has its own process group. Its unique fixture argument also # identifies it if Node exits before the next descendant census. if marker: - roots.update(pid for pid, row in rows.items() if marker in shlex.split(row["command"])) + roots.update(pid for pid, row in rows.items() if re.search(r"(?')) finally: From 4c4af9fde6023845cb689d406d14ffd04cdd0079 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 22:16:43 -0500 Subject: [PATCH 09/11] test: resolve Mac fixtures and restore shared journey behavior --- scripts/ci-installed-journeys.py | 4 +--- scripts/ci-installed-two-home-test.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index fc8fc49a6..2960eedc9 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -1550,8 +1550,7 @@ def run(home, data, evidence, model=True, carrier=False, memory_gib=0, repair=Fa record["finite_memory"] = finite.finish() record["process_cleanup"] = {"status": record["finite_memory"]["status"]} record["results"]["finite_memory_boundary"] = record["finite_memory"]["status"] - record["elapsed_seconds"] = round(time.monotonic() - started, 2) - (evidence / "installed-journeys.json").write_text(json.dumps(record, indent=2) + "\n") + (evidence / "installed-journeys.json").write_text(json.dumps(record, indent=2) + "\n") if holder: cleanup_runtime(holder, holder_data) raise @@ -1668,7 +1667,6 @@ def run(home, data, evidence, model=True, carrier=False, memory_gib=0, repair=Fa and record["process_cleanup"].get("before", {}).get("llama_server") == 0 else "failed") record["results"]["engine_absent_home"] = "passed" if record["engine_absent_after_ui"] else "failed" - record["elapsed_seconds"] = round(time.monotonic() - started, 2) (evidence / "installed-journeys.json").write_text(json.dumps(record, indent=2) + "\n") if record["process_cleanup"]["status"] != "passed": diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index 34bf36490..b6af83c54 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -22,14 +22,14 @@ class TwoHomeReceiptTests(unittest.TestCase): def test_fresh_home_and_data_are_private_with_the_operator_umask(self): fresh = JOURNEY['fresh_fixture'] with tempfile.TemporaryDirectory() as temporary: - home = Path(temporary)/'source' + home = Path(temporary).resolve()/'source' data = home/'.local/share/elastos' data.mkdir(parents=True) (data/'components.json').write_text('{}') prior = os.umask(0o022) try: with mock.patch.dict(fresh.__globals__, {'engine_paths':lambda _: (None,None,None,data/'missing-engine')}): - destination = Path(temporary)/'fresh' + destination = Path(temporary).resolve()/'fresh' copied = fresh(home,data,destination,include_engine=False) self.assertEqual(stat.S_IMODE(destination.stat().st_mode),0o700) self.assertEqual(stat.S_IMODE(copied.stat().st_mode),0o700) @@ -115,7 +115,7 @@ def test_network_arrangement_and_each_observed_ticket_must_match_configuration(s def test_fixture_removal_refuses_nested_home_process(self): remove = JOURNEY['remove_message_fixture'] with tempfile.TemporaryDirectory() as temporary: - root = Path(temporary)/'fixture' + root = Path(temporary).resolve()/'fixture' root.mkdir() row = {'command':str(root/'b/data/bin/elastos')+' gateway'} with mock.patch.dict(remove.__globals__, {'process_rows':lambda: {123:row}}): @@ -130,10 +130,10 @@ def test_failed_stop_and_disk_check_finish_other_stops_remove_keys_and_write_fai finish = JOURNEY['finish_message_fixture'] for disk_fails in (False, True): with self.subTest(disk_fails=disk_fails), tempfile.TemporaryDirectory() as temporary: - root = Path(temporary)/'fixture' + root = Path(temporary).resolve()/'fixture' root.mkdir() (root/'authority.key').write_text('disposable test key') - evidence = Path(temporary)/'evidence' + evidence = Path(temporary).resolve()/'evidence' evidence.mkdir() stopped = [] children = {'a':mock.Mock(pid=101), 'b':mock.Mock(pid=102), 'community':mock.Mock(pid=103)} @@ -172,9 +172,9 @@ def test_work_deadline_interrupts_a_hung_phase_and_restores_the_timer(self): def test_sigkill_fallback_stops_a_detached_browser_after_node_exits(self): stop = JOURNEY['stop_message_processes'] with tempfile.TemporaryDirectory() as temporary: - pidfile = Path(temporary)/'browser.pid' - marker = '--two-home-fixture='+temporary - termfile = Path(temporary)/'term-observed' + pidfile = Path(temporary).resolve()/'browser.pid' + marker = '--two-home-fixture='+str(Path(temporary).resolve()) + termfile = Path(temporary).resolve()/'term-observed' detached_code = ('import os,signal,sys,time; from pathlib import Path; ' 'signal.signal(signal.SIGTERM,lambda *_: Path(sys.argv[3]).write_text("TERM")); ' 'Path(sys.argv[2]).write_text(str(os.getpid())); time.sleep(60)') @@ -205,7 +205,7 @@ def test_sigkill_fallback_stops_a_detached_browser_after_node_exits(self): def test_source_identity_rejects_changed_runtime_and_browser_asset_before_launch(self): identify = JOURNEY['installed_message_identity'] with tempfile.TemporaryDirectory() as temporary: - data = Path(temporary) + data = Path(temporary).resolve() (data/'bin').mkdir() (data/'receipts').mkdir() runtime = data/'bin/elastos' From 45cf22c334c99339881cbb5c82ee03af45b3ec5d Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 22:20:22 -0500 Subject: [PATCH 10/11] test: make deadlines uncatchable by OS recovery and bound census cost --- scripts/ci-installed-journeys.py | 21 ++++++++++++++------- scripts/ci-installed-two-home-test.py | 27 ++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/scripts/ci-installed-journeys.py b/scripts/ci-installed-journeys.py index 2960eedc9..f85b89342 100644 --- a/scripts/ci-installed-journeys.py +++ b/scripts/ci-installed-journeys.py @@ -1748,10 +1748,14 @@ def remove_message_fixture(root): # The 10-minute CI step reserves 360 s for work, 150 s for process cleanup, # and 30 s for disk/removal/receipt operations: 540 s, with 60 s runner margin. +class MessageDeadline(BaseException): + """A phase deadline survives recoverable OS/network error handlers.""" + + @contextmanager def message_timeout(seconds): def expired(_signum, _frame): - raise TimeoutError("two-Home phase deadline") + raise MessageDeadline("two-Home phase deadline") started = time.monotonic() previous = signal.signal(signal.SIGALRM, expired) timer = signal.setitimer(signal.ITIMER_REAL, 0) @@ -1791,8 +1795,9 @@ def stop_message_processes(child, known, marker=None, grace=5, killed=3): """Bounded TERM/KILL census, retaining detached children across reparenting.""" remaining = remember_message_processes(child, known, marker) for action, seconds in ((signal.SIGTERM, grace), (signal.SIGKILL, killed)): + current = process_rows() for pid, row in remaining.items(): - latest = process_rows().get(pid) + latest = current.get(pid) if latest and all(latest[key] == row[key] for key in ("start", "command")): try: os.kill(pid, action) @@ -1801,7 +1806,7 @@ def stop_message_processes(child, known, marker=None, grace=5, killed=3): end = time.monotonic() + seconds while remaining and time.monotonic() < end: child.poll() # Reap our child before checking the census. - time.sleep(.05) + time.sleep(min(1, max(0, end - time.monotonic()))) remaining = remember_message_processes(child, known, marker) if not remaining: break @@ -1980,10 +1985,12 @@ def configure(*arguments): bases = [f"http://{settings['browser_host']}:" + fixtures[name][2].rsplit(":", 1)[1] for name in ("a", "b")] with (root / "browser.private.log").open("wb") as log: browser = subprocess.Popen(["node", "scripts/ci-installed-two-home-journey.mjs", *bases, - str(evidence), str(control)], stdout=log, stderr=log, start_new_session=True) - last = 0 + str(evidence), str(control), settings["browser_host"]], stdout=log, stderr=log, start_new_session=True) + last, next_census = 0, 0 while browser.poll() is None: - remember_message_processes(browser, browser_processes, "--two-home-fixture=" + str(control)) + if time.monotonic() >= next_census: + remember_message_processes(browser, browser_processes, "--two-home-fixture=" + str(control)) + next_census = time.monotonic() + 1 request = control / "request.json" if request.exists(): value = private_json(request) @@ -2046,7 +2053,7 @@ def repeat(home, data, evidence, count): parser.add_argument("--finite-memory", type=int, choices=[1, 4]) parser.add_argument("--model-repair", action="store_true", help="real Stop, Get different model and interrupted Get/Home restart/Retry") parser.add_argument("--two-home-messages", action="store_true") - parser.add_argument("--network-arrangement", choices=["same-host"], default="same-host") + parser.add_argument("--network-arrangement", choices=MESSAGE_NETWORKS.keys(), default="same-host") parser.add_argument("--two-home-root", type=Path, help="fresh disposable fixture path") args = parser.parse_args() if args.two_home_messages: diff --git a/scripts/ci-installed-two-home-test.py b/scripts/ci-installed-two-home-test.py index b6af83c54..218a5e48c 100644 --- a/scripts/ci-installed-two-home-test.py +++ b/scripts/ci-installed-two-home-test.py @@ -163,12 +163,37 @@ def disk(_): def test_work_deadline_interrupts_a_hung_phase_and_restores_the_timer(self): before = signal.getsignal(signal.SIGALRM) - with self.assertRaises(TimeoutError): + with self.assertRaises(JOURNEY['MessageDeadline']): with JOURNEY['message_timeout'](.05): time.sleep(1) self.assertEqual(signal.getitimer(signal.ITIMER_REAL), (0,0)) self.assertEqual(signal.getsignal(signal.SIGALRM), before) + def test_deadline_cannot_be_swallowed_by_an_oserror_handler(self): + swallowed = [] + with self.assertRaises(BaseException) as raised: + with JOURNEY['message_timeout'](.05): + try: + time.sleep(.2) + except OSError: + swallowed.append(True) + self.assertFalse(swallowed) + self.assertNotIsInstance(raised.exception, OSError) + + def test_signal_census_cost_does_not_grow_with_process_count(self): + stop = JOURNEY['stop_message_processes'] + counts = [] + for count in (2,20): + rows = {pid:{'ppid':0,'start':'fixture birth','command':'fixture child'} + for pid in range(100,100+count)} + census = mock.Mock(return_value=rows) + with mock.patch.dict(stop.__globals__, {'process_rows':census}), mock.patch.object(os,'kill'): + with self.assertRaises(AssertionError): + stop(mock.Mock(pid=100), rows.copy(), grace=0, killed=0) + counts.append(census.call_count) + self.assertEqual(counts[0], counts[1]) + self.assertLessEqual(counts[0], 4) + def test_sigkill_fallback_stops_a_detached_browser_after_node_exits(self): stop = JOURNEY['stop_message_processes'] with tempfile.TemporaryDirectory() as temporary: From 36df8ff14e11b22b753a2112c90c0d544acf7068 Mon Sep 17 00:00:00 2001 From: Anders Alm Date: Fri, 13 Nov 2026 22:20:22 -0500 Subject: [PATCH 11/11] test: pass arrangement host and record observed pending samples --- scripts/ci-installed-two-home-journey.mjs | 11 ++++++++--- scripts/ci-installed-two-home.test.mjs | 9 ++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/ci-installed-two-home-journey.mjs b/scripts/ci-installed-two-home-journey.mjs index 1518e6486..402b8e1b4 100644 --- a/scripts/ci-installed-two-home-journey.mjs +++ b/scripts/ci-installed-two-home-journey.mjs @@ -18,12 +18,15 @@ export function assertSenderDelivery(message, detail) { const time = new Date(message.created_at * 1000).toISOString().slice(11, 16); assert.equal(detail, time, 'sender shows the message time, with neither Sending nor Expired'); } +export function assertMessageOrigins(bases, browserHost) { + assert(browserHost && bases.every(base => new URL(base).hostname === browserHost), 'Home origins match the network arrangement browser host'); +} async function run() { const require = createRequire(import.meta.url); const {chromium} = require(process.env.BROWSER_OPERATOR_PLAYWRIGHT_CORE || '../elastos/tools/browser-playwright-engine/node_modules/playwright'); - const [baseA, baseB, evidence, control] = process.argv.slice(2); + const [baseA, baseB, evidence, control, browserHost] = process.argv.slice(2); const bases = [baseA, baseB]; - assert(bases.every(base => new URL(base).hostname === 'localhost'), 'installed journey uses localhost for passkeys'); + assertMessageOrigins(bases, browserHost); const result = {stage:'sign_in', results:{}, negative_controls:{}, observations:[], browser_cross_home_http_requests:0}; let sequence = 0; async function runtime(action) { @@ -177,15 +180,17 @@ async function run() { pending=await senderMessage(offlineText); return pending?.delivery_state==='pending' && await detail(offlineText)==='Sending'; }); + const pendingObservations=[]; for(let sample=0;sample<3;sample++) { pending=await senderMessage(offlineText); const value=await detail(offlineText); assert.equal(pending.delivery_state,'pending'); assert.equal(value,'Sending'); assert.throws(()=>assertSenderDelivery(pending,value),{name:'AssertionError'}); + pendingObservations.push({api_state:pending.delivery_state,ui_detail:value}); await sleep(500); } - result.negative_controls.sender_delivered={assertion_rejected:true,broken_input:'B stopped before send',api_state:'pending',ui_detail:'Sending',samples:3}; + result.negative_controls.sender_delivered={assertion_rejected:true,broken_input:'B stopped before send',...pendingObservations.at(-1),samples:pendingObservations.length,observations:pendingObservations}; result.results.offline_pending='passed'; result.stage='restart_delivery'; await runtime('start_b'); diff --git a/scripts/ci-installed-two-home.test.mjs b/scripts/ci-installed-two-home.test.mjs index 63bbf34cc..53f2429e4 100644 --- a/scripts/ci-installed-two-home.test.mjs +++ b/scripts/ci-installed-two-home.test.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import test from 'node:test'; -import {assertCommunityMessage, assertReceivedDirect, assertSenderDelivery} from './ci-installed-two-home-journey.mjs'; +import {assertCommunityMessage, assertReceivedDirect, assertSenderDelivery, assertMessageOrigins} from './ci-installed-two-home-journey.mjs'; test('Community proof rejects wrong text, wrong identity and the receiving Home own post', () => { const message = {message_id:'post:one', body:'fresh post', from_current_session:false}; @@ -28,3 +28,10 @@ test('Sender delivered requires both the settled API state and the exact message assert.throws(() => assertSenderDelivery({...message,delivery_state:state}, '00:00'), assert.AssertionError); } }); + +test('Home origins use the arrangement browser host and reject a mismatch', () => { + assertMessageOrigins(['http://localhost/','http://localhost/'], 'localhost'); + assertMessageOrigins(['http://127.0.0.1/','http://127.0.0.1/'], '127.0.0.1'); + assert.throws(()=>assertMessageOrigins(['http://localhost/','http://127.0.0.1/'], 'localhost'), assert.AssertionError); + assert.throws(()=>assertMessageOrigins(['http://localhost/'], undefined), assert.AssertionError); +});