Skip to content

Commit

Permalink
Change file structure of bug report, don't use hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
nwatson22 committed Jun 26, 2024
1 parent 6eedcbc commit c4f5058
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions pyk/src/pyk/kore/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from psutil import Process

from ..utils import FrozenDict, check_dir_path, check_file_path, filter_none, hash_str, run_process
from ..utils import FrozenDict, check_dir_path, check_file_path, filter_none, run_process
from . import manip
from .prelude import SORT_GENERATED_TOP_CELL
from .syntax import And, Equals, EVar, kore_term
Expand Down Expand Up @@ -69,7 +69,7 @@ def __exit__(self, *args: Any) -> None:
def close(self) -> None: ...

@abstractmethod
def command(self, bug_report_id: str, uid: str, bug_report_request: str) -> list[str]: ...
def command(self, req_name: str, bug_report_request: str) -> list[str]: ...

@abstractmethod
def description(self) -> str: ...
Expand Down Expand Up @@ -117,7 +117,7 @@ def close(self) -> None:
self._file.close()
self._sock.close()

def command(self, bug_report_id: str, uid: str, bug_report_request: str) -> list[str]:
def command(self, req_name: str, bug_report_request: str) -> list[str]:
return [
'cat',
bug_report_request,
Expand All @@ -127,7 +127,7 @@ def command(self, bug_report_id: str, uid: str, bug_report_request: str) -> list
self._host,
str(self._port),
'>',
f'rpc_{bug_report_id}/{uid:03}_actual.json',
f'{req_name}_actual.json',
]

def request(self, req: str) -> str:
Expand All @@ -154,7 +154,7 @@ def __init__(self, host: str, port: int, *, timeout: int | None = None):
def close(self) -> None:
pass

def command(self, bug_report_id: str, uid: str, bug_report_request: str) -> list[str]:
def command(self, req_name: str, bug_report_request: str) -> list[str]:
return [
'curl',
'-X',
Expand All @@ -165,7 +165,7 @@ def command(self, bug_report_id: str, uid: str, bug_report_request: str) -> list
'@' + bug_report_request,
'http://' + self._host + ':' + str(self._port),
'>',
f'rpc_{bug_report_id}/{uid:03}_actual.json',
f'{req_name}_actual.json',
]

def request(self, req: str) -> str:
Expand Down Expand Up @@ -259,7 +259,7 @@ class JsonRpcClient(ContextManager['JsonRpcClient']):
_transport: Transport
_req_id: int
_bug_report: BugReport | None
_bug_report_id: str
_bug_report_id: str | None

def __init__(
self,
Expand All @@ -279,7 +279,15 @@ def __init__(
raise AssertionError()
self._req_id = 1
self._bug_report = bug_report
self._bug_report_id = bug_report_id if bug_report_id is not None else str(id(self))
self._bug_report_id = bug_report_id
from traceback import format_stack

print(self.client_id)
print('\n'.join(format_stack()))

@property
def client_id(self) -> str:
return str(id(self))

def __enter__(self) -> JsonRpcClient:
return self
Expand All @@ -291,24 +299,25 @@ def close(self) -> None:
self._transport.close()

def request(self, method: str, **params: Any) -> dict[str, Any]:
# Generate unique ID regardless of different clients, repeated requests from the same client, etc.
uid = hash_str((id(self), self._req_id))
old_id = self._req_id
self._req_id += 1

payload = {
'jsonrpc': self._JSON_RPC_VERSION,
'id': uid,
'id': old_id,
'method': method,
'params': params,
}

server_addr = self._transport.description()
_LOGGER.info(f'Sending request to {server_addr}: {uid} - {method}')
_LOGGER.info(f'Sending request to {server_addr}: {old_id} - {method}')
req = json.dumps(payload)
base_name = self._bug_report_id if self._bug_report_id is not None else 'kore_rpc'
req_name = f'{base_name}/{self.client_id}/{old_id:03}'
if self._bug_report:
bug_report_request = f'rpc_{self._bug_report_id}/{uid:03}_request.json'
bug_report_request = f'{req_name}_request.json'
self._bug_report.add_file_contents(req, Path(bug_report_request))
self._bug_report.add_command(self._transport.command(self._bug_report_id, uid, bug_report_request))
self._bug_report.add_command(self._transport.command(req_name, bug_report_request))

_LOGGER.debug(f'Sending request to {server_addr}: {req}')
resp = self._transport.request(req)
Expand All @@ -317,23 +326,23 @@ def request(self, method: str, **params: Any) -> dict[str, Any]:
_LOGGER.debug(f'Received response from {server_addr}: {resp}')

if self._bug_report:
bug_report_response = f'rpc_{self._bug_report_id}/{uid:03}_response.json'
bug_report_response = f'{req_name}_response.json'
self._bug_report.add_file_contents(resp, Path(bug_report_response))
self._bug_report.add_command(
[
'diff',
'-b',
'-s',
f'rpc_{self._bug_report_id}/{uid:03}_actual.json',
f'rpc_{self._bug_report_id}/{uid:03}_response.json',
f'{req_name}_actual.json',
f'{req_name}_response.json',
]
)

data = json.loads(resp)
self._check(data)
assert data['id'] == uid
assert data['id'] == old_id

_LOGGER.info(f'Received response from {server_addr}: {uid} - {method}')
_LOGGER.info(f'Received response from {server_addr}: {old_id} - {method}')
return data['result']

@staticmethod
Expand Down

0 comments on commit c4f5058

Please sign in to comment.