52 lines
3.1 KiB
Python
52 lines
3.1 KiB
Python
"""Joint source test: encrypted PC journal -> signed ECS progress -> card projection."""
|
|
import importlib
|
|
from pathlib import Path
|
|
import sys
|
|
import types
|
|
import httpx
|
|
import pytest
|
|
from test_credential_api import env,wire
|
|
from test_task_delivery import task
|
|
from test_task_cards import setup_cards
|
|
|
|
|
|
async def test_native_states_reach_signed_server_and_existing_card(env,tmp_path,monkeypatch):
|
|
client=Path(__file__).resolve().parents[3]/'hainuo-build-remote-C-20261112/integrations/work-relay/service/relay'
|
|
if not client.is_dir():pytest.skip('paired client source not present')
|
|
package=types.ModuleType('joint_pc_relay');package.__path__=[str(client)]
|
|
monkeypatch.setitem(sys.modules,'joint_pc_relay',package)
|
|
journal_module=importlib.import_module('joint_pc_relay.task_journal')
|
|
native=importlib.import_module('joint_pc_relay.hainuo1065')
|
|
monkeypatch.setattr(journal_module,'protect',lambda data:b'test:'+data)
|
|
monkeypatch.setattr(journal_module,'unprotect',lambda data:data[5:])
|
|
clock=[0.0]
|
|
# Patch only the native module clock, not shared time.monotonic used by event loop.
|
|
monkeypatch.setattr(native,'time',types.SimpleNamespace(monotonic=lambda:clock[0],time=__import__('time').time))
|
|
async def no_wait(_):clock[0]+=1
|
|
monkeypatch.setattr(native,'asyncio',types.SimpleNamespace(sleep=no_wait))
|
|
context={'task_id':'task-durable','conversation_id':'synthetic-conversation'}
|
|
ledger=journal_module.TaskJournal(tmp_path);ledger.begin(context,'synthetic')
|
|
task(env);cards,calls,card_clock=setup_cards(env,monkeypatch)
|
|
states=iter(['running','waiting_for_approval','running','completed']);reported=[];posts=[]
|
|
run_id='run_'+'a'*32
|
|
def handler(request):
|
|
if request.method=='POST':posts.append(request);return httpx.Response(202,json={'run_id':run_id})
|
|
return httpx.Response(200,json={'run_id':run_id,'status':next(states),'output':'synthetic result'})
|
|
config=tmp_path/'native.json';config.write_text(__import__('json').dumps({'url':'http://127.0.0.1:8643','api_key':'fake-'*10,'mode':'text-only'}))
|
|
adapter=native.Hainuo1065Agent(config,transport=httpx.MockTransport(handler));adapter.model='synthetic'
|
|
async def progress():
|
|
saved=ledger.get(context);path='/work/v2/tasks/progress'
|
|
response=await env['client'].post(path,json=wire(env,path,task_id=context['task_id'],
|
|
execution_state=saved['execution_state'],status_sequence=saved['status_sequence']))
|
|
assert response.status_code==200,response.text
|
|
reported.append(response.json()['execution_state'])
|
|
card_clock[0]+=6;await cards.flush()
|
|
try:
|
|
assert await adapter._execute_run('synthetic',{'X-Hermes-Session-Id':'synthetic-session'},progress,journal=ledger,context=context)=='synthetic result'
|
|
assert reported==['running','waiting_for_approval','running','completed']
|
|
assert ledger.get(context)['status_sequence']==4
|
|
assert len(posts)==1
|
|
assert [call[0] for call in calls]==['create','update','update','update']
|
|
assert len(env['platform'].replies)==0 # Execution completion is not result delivery.
|
|
finally:await adapter.close()
|