Skip to content

The agent that grows with you

test: the Webapp login is the machine owner in the main tests that pinned it as a stranger

Teknium8b1040feb6b5
diff --git a/tests/gateway/fixtures/hosted_auth_probe.py b/tests/gateway/fixtures/hosted_auth_probe.py
index 788d40fbd84..337ef9677c7 100644
--- a/tests/gateway/fixtures/hosted_auth_probe.py
+++ b/tests/gateway/fixtures/hosted_auth_probe.py
@@ -1,4 +1,8 @@
-"""Loopback OIDC/model boundaries; daemon, auth, tickets and room controls are real."""
+"""Loopback OIDC/model boundaries; daemon, auth, tickets and room controls are real.
+
+Hermes is single-user: every signed-in Webapp tab is the machine owner, so two tabs share one
+Group Chat list and either may stop or approve, while a second IdP account cannot sign in at all.
+"""
import asyncio
import base64
from contextlib import ExitStack
@@ -20,6 +24,10 @@ from tests.gateway.fixtures.local_recovery_probe import child_env, daemon, rpc
from tests.waiting import async_wait_until
+#: Two signed-in Webapp tabs of the same owner account (Hermes is single-user).
+TABS = ('tab1', 'tab2')
+
+
class OIDC(BaseHTTPRequestHandler):
def log_message(self, *args):
pass
@@ -45,7 +53,7 @@ class OIDC(BaseHTTPRequestHandler):
params = {k: v[0] for k, v in parse_qs(url.query).items()}
assert params['client_id'] == 'room-fixture'
assert params['code_challenge_method'] == 'S256'
- assert params['subject'] in ('alice', 'bob')
+ assert params['subject'] in ('alice', 'mallory')
code = secrets.token_urlsafe(24)
self.server.codes[code] = params
self.send_response(302)
@@ -86,7 +94,7 @@ class Model(BaseHTTPRequestHandler):
self.server.requests.append(body)
text = str(next((m.get('content', '') for m in reversed(body.get('messages', []))
if m['role'] == 'user'), ''))
- for actor in ('alice', 'bob'):
+ for actor in TABS:
if 'BLOCK_' + actor in text:
self.server.blocked[actor].set()
self.server.release.wait(60)
@@ -112,7 +120,7 @@ class Model(BaseHTTPRequestHandler):
pass
-def login(client, issuer, actor):
+def callback(client, issuer, actor):
response = client.get('/auth/login', params={'provider': 'self-hosted'})
assert response.status_code == 302, response.text
authorize = response.headers['location']
@@ -120,8 +128,12 @@ def login(client, issuer, actor):
response = client.get(authorize + '&' + urlencode({'subject': actor}))
assert response.status_code == 302, response.text
# public_url enables the gate; route its callback to the owned loopback listener.
- callback = urlsplit(response.headers['location'])
- response = client.get(callback.path + '?' + callback.query)
+ redirect = urlsplit(response.headers['location'])
+ return client.get(redirect.path + '?' + redirect.query)
+
+
+def login(client, issuer, actor):
+ response = callback(client, issuer, actor)
assert response.status_code == 302, response.text
identity = client.get('/api/auth/me')
assert identity.status_code == 200, identity.text
@@ -151,7 +163,7 @@ def probe(tmp_path):
(removal / 'sentinel').write_text('owned fixture')
import shlex
model.command = 'rm -r -- ' + shlex.quote(str(removal))
- model.blocked = {actor: threading.Event() for actor in ('alice', 'bob')}
+ model.blocked = {actor: threading.Event() for actor in TABS}
model.release = threading.Event()
threads = [threading.Thread(target=s.serve_forever, daemon=True) for s in (oidc, model)]
for thread in threads:
@@ -176,61 +188,59 @@ def probe(tmp_path):
async def exercise(desc, tickets):
origin = desc['api_origin'].replace('http:', 'ws:') + '/api/ws'
- async with connect(origin + '?ticket=' + tickets[0]) as alice, connect(
- origin + '?ticket=' + tickets[1]) as bob:
- actors = [('alice', alice, bob), ('bob', bob, alice)]
- for actor, ws, _ in actors:
- result = await rpc(ws, 'groups.create', room_id=actor + '-room', name=actor, members=members)
+ async with connect(origin + '?ticket=' + tickets[0]) as one, connect(
+ origin + '?ticket=' + tickets[1]) as two:
+ tabs = [('tab1', one, two), ('tab2', two, one)]
+ rooms = sorted(tab + '-room' for tab, _, _ in tabs)
+ for tab, ws, _ in tabs:
+ result = await rpc(ws, 'groups.create', room_id=tab + '-room', name=tab, members=members)
assert 'result' in result, result
- denials = 0
- for actor, ws, other in actors:
- room = actor + '-room'
- listing = await rpc(ws, 'groups.list')
- assert [r['room_id'] for r in listing['result']['rooms']] == [room], listing
+ shared = 0
+ for tab, ws, other in tabs:
+ room = tab + '-room'
+ # Every signed-in tab is the machine owner: one Group Chat list on both.
+ for viewer in (ws, other):
+ listing = await rpc(viewer, 'groups.list')
+ assert sorted(r['room_id'] for r in listing['result']['rooms']) == rooms, listing
state = await rpc(ws, 'groups.state', room_id=room)
assert state['result']['room']['room_id'] == room, state
sent = await rpc(ws, 'groups.send', room_id=room, event_id='own-input',
- payload={'text': '@two BLOCK_' + actor, 'thread_id': 'thread'})
+ payload={'text': '@two BLOCK_' + tab, 'thread_id': 'thread'})
assert sent['result']['accepted'], sent
- assert await asyncio.to_thread(model.blocked[actor].wait, 30), state
+ assert await asyncio.to_thread(model.blocked[tab].wait, 30), state
before = await rpc(ws, 'groups.log', room_id=room)
- for method, params in [
- ('groups.create', {'name': 'hijack', 'members': members}),
- ('groups.state', {}), ('groups.log', {}),
- ('groups.send', {'event_id': 'forbidden', 'payload': {'text': 'FORBIDDEN', 'thread_id': 'thread'}}),
- ('groups.stop', {'cancel_id': 'foreign-stop'}),
- ]:
- rejected = await rpc(other, method, room_id=room, **params)
- assert rejected.get('error', {}).get('message') == 'permission_denied', rejected
- denials += 1
- after = await rpc(ws, 'groups.log', room_id=room)
+ for method in ('groups.state', 'groups.log'):
+ seen = await rpc(other, method, room_id=room)
+ assert 'result' in seen, seen
+ shared += 1
+ after = await rpc(other, 'groups.log', room_id=room)
assert after == before, (before, after)
state = await rpc(ws, 'groups.state', room_id=room)
assert state['result']['driver_status']['counts'].get('running') == 1, state
- for actor, ws, _ in actors:
- stopped = await rpc(ws, 'groups.stop', room_id=actor + '-room', cancel_id='owner-stop')
+ for tab, ws, _ in tabs:
+ stopped = await rpc(ws, 'groups.stop', room_id=tab + '-room', cancel_id='owner-stop')
assert stopped['result']['cancelled'] >= 1, stopped
- if actor == 'alice':
- sibling = await rpc(bob, 'groups.state', room_id='bob-room')
+ if tab == 'tab1':
+ sibling = await rpc(two, 'groups.state', room_id='tab2-room')
assert sibling['result']['driver_status']['counts'].get('running') == 1, sibling
model.release.set()
- for actor, ws, _ in actors:
+ for tab, ws, _ in tabs:
deadline = time.monotonic() + 90
while True:
- state = await rpc(ws, 'groups.state', room_id=actor + '-room')
+ state = await rpc(ws, 'groups.state', room_id=tab + '-room')
counts = state['result']['driver_status']['counts']
if not counts.get('running') and not counts.get('stopping'):
assert counts.get('cancelled', 0) >= 1, state
break
- assert time.monotonic() < deadline, f'{actor} room never settled its stop: {state}'
+ assert time.monotonic() < deadline, f'{tab} room never settled its stop: {state}'
await asyncio.sleep(.1)
assert len(model.requests) == 2, model.requests
- sent = await rpc(alice, 'groups.send', room_id='alice-room', event_id='approval',
+ sent = await rpc(one, 'groups.send', room_id='tab1-room', event_id='approval',
payload={'text': '@two APPROVE_HOSTED', 'thread_id': 'approval-thread'})
assert sent['result']['accepted'], sent
deadline = time.monotonic() + 90
while True:
- state = await rpc(alice, 'groups.state', room_id='alice-room')
+ state = await rpc(two, 'groups.state', room_id='tab1-room')
actions = state['result']['driver_status']['pending_actions']
approvals = [a for a in actions if a['kind'] == 'approval']
if approvals:
@@ -240,16 +250,13 @@ def probe(tmp_path):
assert removal.exists()
action = approvals[0]
params = {k: action[k] for k in ('member_id', 'task_id', 'execution_generation', 'request_id')}
- denied = await rpc(bob, 'groups.approve', room_id='alice-room', choice='once', **params)
- assert denied.get('error', {}).get('message') == 'permission_denied', denied
- accepted = await rpc(alice, 'groups.approve', room_id='alice-room', choice='once', **params)
+ # The owner answers from whichever tab it has open.
+ accepted = await rpc(two, 'groups.approve', room_id='tab1-room', choice='once', **params)
assert accepted.get('result', {}).get('approved'), accepted
await async_wait_until(lambda: not removal.exists(), timeout=90,
what='the approved removal to run')
- assert 'FORBIDDEN' not in json.dumps(model.requests)
- return {'actors': oidc.logins, 'rooms': ['alice-room', 'bob-room'],
- 'cross_actor_denials': denials, 'owner_stops': 2}
+ return {'actors': oidc.logins, 'rooms': rooms, 'shared_views': shared, 'owner_stops': 2}
try:
with daemon(root, target, env | {'HERMES_HOME': str(target)}, barrier=False), daemon(
@@ -259,8 +266,11 @@ def probe(tmp_path):
for credential in ('', 'Bearer invalid'):
rejected = clients[0].post('/api/auth/ws-ticket', headers={'Authorization': credential})
assert rejected.status_code == 401, rejected.text
- tickets = [login(client, oidc.issuer, actor)
- for client, actor in zip(clients, ('alice', 'bob'))]
+ tickets = [login(clients[0], oidc.issuer, 'alice')]
+ # Owner-only sign-in: another account of the same IdP is refused, not a second owner.
+ refused = callback(clients[1], oidc.issuer, 'mallory')
+ assert refused.status_code != 302 and 'not the owner' in refused.text, refused.text
+ tickets.append(login(clients[1], oidc.issuer, 'alice'))
return asyncio.run(exercise(desc, tickets))
finally:
model.release.set()
diff --git a/tests/gateway/fixtures/operator_cross_surface_peer.py b/tests/gateway/fixtures/operator_cross_surface_peer.py
index eeb31875d54..1f5c883e93b 100644
--- a/tests/gateway/fixtures/operator_cross_surface_peer.py
+++ b/tests/gateway/fixtures/operator_cross_surface_peer.py
@@ -135,14 +135,13 @@ async def probe(peer, creator):
assert await rpc(viewer, 'prompt.submit', **followup) == accepted
rows = list_session_admissions(authority.db, session_id=sid, pending_only=False)
assert len(rows) == 2, rows
+ # Hermes is single-user: the dashboard login is the machine owner, so both surfaces'
+ # admissions carry the owner's own OS subject and neither is an operator hand-off.
assert rows[0]['principal_id'] == original_owner, rows
- assert rows[1]['principal_id'] != original_owner, rows
- assert rows[1]['payload']['local_operator_v1'] == {
- 'profile_id': authority.profile_id, 'session_id': sid,
- 'principal_id': rows[1]['principal_id']}
+ assert rows[1]['principal_id'] == original_owner, rows
+ assert all('local_operator_v1' not in row['payload'] for row in rows), rows
attribution = [row['principal_id'] for row in rows]
- assert any(subject.startswith('uid:') for subject in attribution), attribution
- assert len(set(attribution)) == 2
+ assert all(subject.startswith('uid:') for subject in attribution), attribution
await owner.close()
await viewer.close()
# No connected viewer owns this accepted work. A new surface sees the same queue.
@@ -175,7 +174,7 @@ async def probe(peer, creator):
assert 'LOCAL_ACK_WS_SHARED' in json.dumps(snapshot['messages'])
assert 'local_operator_v1' not in json.dumps([initial, attached, accepted, replay, snapshot])
(home / 'operator-receipt.json').write_text(json.dumps(dict(
- creator=creator, model_requests=len(peer.requests), distinct_attribution=True,
+ creator=creator, model_requests=len(peer.requests), owner_attribution=True,
disconnect_survived=True, negative_boundaries=True)))
finally:
peer.release.set()
diff --git a/tests/gateway/test_hosted_room_auth_daemon.py b/tests/gateway/test_hosted_room_auth_daemon.py
index 4f58196c9fd..a2c6b5aa52d 100644
--- a/tests/gateway/test_hosted_room_auth_daemon.py
+++ b/tests/gateway/test_hosted_room_auth_daemon.py
@@ -1,10 +1,11 @@
-"""Hosted-room isolation over real OIDC-authenticated ordinary daemon sockets."""
+"""Hosted rooms over real OIDC-authenticated ordinary daemon sockets: one owner, many tabs."""
from tests.gateway.fixtures.hosted_auth_probe import probe
-def test_two_authenticated_actors_own_separate_hosted_rooms(tmp_path):
+def test_every_signed_in_tab_shares_the_owners_hosted_rooms(tmp_path):
receipt = probe(tmp_path)
- assert receipt['actors'] == ['alice', 'bob']
- assert receipt['rooms'] == ['alice-room', 'bob-room']
- assert receipt['cross_actor_denials'] == 10
+ # The second account's token exchange happened, then its sign-in was refused.
+ assert receipt['actors'] == ['alice', 'mallory', 'alice']
+ assert receipt['rooms'] == ['tab1-room', 'tab2-room']
+ assert receipt['shared_views'] == 4
assert receipt['owner_stops'] == 2
diff --git a/tests/gateway/test_operator_cross_surface.py b/tests/gateway/test_operator_cross_surface.py
index 1bd841e4a54..12d24f37263 100644
--- a/tests/gateway/test_operator_cross_surface.py
+++ b/tests/gateway/test_operator_cross_surface.py
@@ -1,4 +1,4 @@
-"""Real native bootstrap and dashboard login share one canonical worker, not identities."""
+"""Real native bootstrap and dashboard login share one canonical worker as one owner identity."""
import json
import os
from pathlib import Path
@@ -26,6 +26,6 @@ def test_operator_cross_surface_real_auth_fifo_and_attribution(tmp_path, creator
receipt = json.loads((home / 'operator-receipt.json').read_text())
assert receipt['creator'] == creator
assert receipt['model_requests'] == 2
- assert receipt['distinct_attribution'] is True
+ assert receipt['owner_attribution'] is True
assert receipt['disconnect_survived'] is True
assert receipt['negative_boundaries'] is True
diff --git a/tests/gateway/test_session_mutation_cold.py b/tests/gateway/test_session_mutation_cold.py
index d79e0507cc1..f6b2a94f5bd 100644
--- a/tests/gateway/test_session_mutation_cold.py
+++ b/tests/gateway/test_session_mutation_cold.py
@@ -25,5 +25,7 @@ def test_cold_import_mutation_binds_owner_across_restart(tmp_path):
with daemon(tmp_path) as (home, descriptor), httpx.Client(base_url=descriptor['api_origin'], trust_env=False) as client:
assert client.patch('/api/sessions/cold', headers=headers(ticket(home, descriptor)), json=body).json() == edited.json()
assert client.get('/api/sessions/cold/mutation-snapshot', headers=headers(ticket(home, descriptor))).status_code == 200
- denied = client.patch('/api/sessions/cold', headers={'Authorization': 'Bearer normal-http-owner'}, json=body | {'request_id': 'foreign'})
- assert denied.status_code == 403, denied.text
+ # The dashboard login is the owner the binding names: a new request on the stale revision is
+ # an ordinary revision conflict, not an ownership refusal.
+ login = client.patch('/api/sessions/cold', headers={'Authorization': 'Bearer normal-http-owner'}, json=body | {'request_id': 'login'})
+ assert login.status_code == 409 and 'revision_conflict' in login.text, login.text
diff --git a/tests/gateway/test_session_mutation_import_owner.py b/tests/gateway/test_session_mutation_import_owner.py
index f111f69a4f2..4cd72041a05 100644
--- a/tests/gateway/test_session_mutation_import_owner.py
+++ b/tests/gateway/test_session_mutation_import_owner.py
@@ -1,4 +1,5 @@
-"""The importer owns cold control before another authenticated actor can claim it."""
+"""The importer owns cold control in its receipt transaction. Hermes is single-user: the dashboard
+login is the machine owner, so it continues the owner's import (an exact retry), never a stranger."""
import httpx
import pytest
from tests.gateway.test_native_http_auth import daemon, ticket, headers
@@ -13,7 +14,7 @@ def test_import_atomically_binds_each_new_history_to_its_importer(tmp_path):
assert response.status_code == 200, response.text
for sid in ('cli-import', 'foreign-import'):
body = {'request_id': 'edit', 'expected_revision': 1, 'title': sid}
- stolen = client.patch('/api/sessions/' + sid, headers={'Authorization': 'Bearer normal-http-owner'}, json=body)
- assert stolen.status_code == 403, stolen.text
+ login = client.patch('/api/sessions/' + sid, headers={'Authorization': 'Bearer normal-http-owner'}, json=body)
+ assert login.status_code == 200, login.text
owned = client.patch('/api/sessions/' + sid, headers=headers(ticket(home, descriptor)), json=body)
- assert owned.status_code == 200, owned.text
+ assert owned.status_code == 200 and owned.json() == login.json(), owned.text
diff --git a/tests/gateway/test_session_mutation_retirement.py b/tests/gateway/test_session_mutation_retirement.py
index e688ed2848e..1354cd85f46 100644
--- a/tests/gateway/test_session_mutation_retirement.py
+++ b/tests/gateway/test_session_mutation_retirement.py
@@ -46,10 +46,11 @@ def test_native_delete_exact_retry_survives_owner_restart(tmp_path):
absent = {'ok': True, 'already_absent': True}
fresh = client.delete(path, params=params | {'request_id': 'different'}, headers=headers(ticket(home, descriptor)))
assert fresh.status_code == 200 and fresh.json() == absent, fresh.text
- foreign = client.delete(path, params=params, headers={'Authorization': 'Bearer normal-http-owner'})
- assert foreign.status_code != 200 or foreign.json() == absent, foreign.text
+ # The dashboard login is the owner, so its exact retry replays the owner's receipt.
+ login = client.delete(path, params=params, headers={'Authorization': 'Bearer normal-http-owner'})
+ assert login.status_code == 200 and login.json() == receipt, login.text
print(json.dumps({'native_delete_restart': receipt, 'changed_retry': changed.json(),
- 'fresh_request_status': fresh.status_code, 'foreign_status': foreign.status_code}))
+ 'fresh_request_status': fresh.status_code, 'login_status': login.status_code}))
def test_route_retirement_rolls_back_with_receipt_and_rejects_stale_mirror(tmp_path):
diff --git a/tests/gateway/test_used_delete_restart.py b/tests/gateway/test_used_delete_restart.py
index ece8ec824f3..228c3c34a51 100644
--- a/tests/gateway/test_used_delete_restart.py
+++ b/tests/gateway/test_used_delete_restart.py
@@ -119,10 +119,9 @@ def test_used_api_and_native_delete_restart_exact_retry(tmp_path):
assert retry.status_code == 200 and retry.json() == receipt, retry.text
changed = client.delete(path, params=params | {'expected_revision': 999}, headers=native_headers(ticket(home, desc)))
assert changed.status_code == 409 and 'admission_conflict' in changed.text
- foreign = client.delete(path, params=params, headers={'Authorization': 'Bearer foreign-dashboard-owner'})
- # Another principal never replays this receipt; for the gone id it gets main's
- # idempotent ``already_absent`` (Desktop ghost-row contract, #48641) at most.
- assert foreign.status_code != 200 or foreign.json() == {'ok': True, 'already_absent': True}, foreign.text
+ login = client.delete(path, params=params, headers={'Authorization': 'Bearer foreign-dashboard-owner'})
+ # The dashboard login is the machine owner: its exact retry replays the receipt.
+ assert login.status_code == 200 and login.json() == receipt, login.text
assert asyncio.run(api_request()) == first
asyncio.run(stale_native(desc, native_sid))
with sqlite3.connect(home / 'state.db') as db:
diff --git a/tests/hermes_cli/test_sessions_adopt.py b/tests/hermes_cli/test_sessions_adopt.py
index 2a3c06eaae1..714bfbdf23b 100644
--- a/tests/hermes_cli/test_sessions_adopt.py
+++ b/tests/hermes_cli/test_sessions_adopt.py
@@ -1,9 +1,9 @@
"""`hermes sessions adopt` brings a profile's pre-gateway chats under its gateway, as the host.
The Webapp's browser reaches the gateway through its dashboard mount as the login it authenticated
-(on a loopback bind, the session-token owner), which may not make the first claim on an unowned
-historical row (gateway-local-sessions.md, shared operator access). The host's own native client
-adopts them in one pass, after which the browser login continues each.
+(on a loopback bind, the session-token owner). Hermes is single-user, so that login is the machine
+owner: like native Desktop it may claim an old chat by opening it, and `adopt` brings the rest under
+the gateway in one pass, after which the browser login continues each.
"""
import argparse
import asyncio
@@ -76,14 +76,16 @@ async def _browser_resume(home, descriptor, sid):
def test_adopting_old_chats_lets_the_browser_login_continue_them(tmp_path, model_peer, monkeypatch, capsys):
with running_owner(tmp_path, model_peer, prepare=_seed, extra_env=_OWNER_ENV) as (home, descriptor, _env):
monkeypatch.setenv('HERMES_HOME', str(home))
- assert asyncio.run(_browser_resume(home, descriptor, 'old-desktop'))['error']['message'] == 'not_found'
+ # The browser login is the machine owner, exactly as native Desktop: it opens an old chat
+ # itself, and that first claim is the owner's (the adopt pass no longer offers it).
+ first = asyncio.run(_browser_resume(home, descriptor, 'old-desktop'))
+ assert first.get('result', {}).get('session_id') == 'old-desktop', first
status, out = _adopt(capsys, '--dry-run')
- assert status == 0 and '3 pre-gateway chat(s) to adopt (1 cli, 2 desktop)' in out, out
- assert asyncio.run(_browser_resume(home, descriptor, 'old-desktop'))['error']['message'] == 'not_found'
+ assert status == 0 and '2 pre-gateway chat(s) to adopt (1 cli, 1 desktop)' in out, out
status, out = _adopt(capsys)
- assert status == 0 and 'Adopted 3 chat(s).' in out, out
+ assert status == 0 and 'Adopted 2 chat(s).' in out, out
for sid in ('old-desktop', 'old-desktop-nous', 'old-cli'):
resumed = asyncio.run(_browser_resume(home, descriptor, sid))
assert resumed.get('result', {}).get('session_id') == sid, resumed