diff --git a/nextlinegraphql/plugins/ctrl/graphql/mutations/Exec.gql b/nextlinegraphql/plugins/ctrl/graphql/mutations/Exec.gql index e5276de..36f1654 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/mutations/Exec.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/mutations/Exec.gql @@ -1,3 +1,5 @@ mutation Exec { - exec + ctrl { + exec + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql b/nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql index 89ae454..a24dc70 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql @@ -1,3 +1,5 @@ mutation LoadExampleScript { - loadExampleScript + ctrl { + loadExampleScript + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/mutations/Reset.gql b/nextlinegraphql/plugins/ctrl/graphql/mutations/Reset.gql index a56d8ba..b75be60 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/mutations/Reset.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/mutations/Reset.gql @@ -1,3 +1,5 @@ mutation Reset($statement: String) { - reset(statement: $statement) + ctrl { + reset(statement: $statement) + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/mutations/RunAndContinue.gql b/nextlinegraphql/plugins/ctrl/graphql/mutations/RunAndContinue.gql index 3540bcd..6cb8f28 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/mutations/RunAndContinue.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/mutations/RunAndContinue.gql @@ -1,3 +1,5 @@ mutation RunAndContinue { - runAndContinue + ctrl { + runAndContinue + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/mutations/SendPdbCommand.gql b/nextlinegraphql/plugins/ctrl/graphql/mutations/SendPdbCommand.gql index b7ecf5d..b17997f 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/mutations/SendPdbCommand.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/mutations/SendPdbCommand.gql @@ -1,3 +1,5 @@ mutation SendPdbCommand($command: String!, $promptNo: Int!, $traceNo: Int!) { - sendPdbCommand(command: $command, promptNo: $promptNo, traceNo: $traceNo) + ctrl { + sendPdbCommand(command: $command, promptNo: $promptNo, traceNo: $traceNo) + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/queries/Exception.gql b/nextlinegraphql/plugins/ctrl/graphql/queries/Exception.gql index 70a10eb..c5045c9 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/queries/Exception.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/queries/Exception.gql @@ -1,3 +1,5 @@ query Exception { - exception + ctrl { + exception + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/queries/Source.gql b/nextlinegraphql/plugins/ctrl/graphql/queries/Source.gql index 5fcad58..a6c2e95 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/queries/Source.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/queries/Source.gql @@ -1,3 +1,5 @@ query Source($fileName: String) { - source(fileName: $fileName) + ctrl { + source(fileName: $fileName) + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/queries/SourceLine.gql b/nextlinegraphql/plugins/ctrl/graphql/queries/SourceLine.gql index b49b326..7f8c65c 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/queries/SourceLine.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/queries/SourceLine.gql @@ -1,3 +1,5 @@ query SourceLine($lineNo: Int!, $fileName: String) { - sourceLine(lineNo: $lineNo, fileName: $fileName) + ctrl { + sourceLine(lineNo: $lineNo, fileName: $fileName) + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/queries/State.gql b/nextlinegraphql/plugins/ctrl/graphql/queries/State.gql index 02fb528..51deba6 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/queries/State.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/queries/State.gql @@ -1,3 +1,5 @@ query State { - state + ctrl { + state + } } diff --git a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Counter.gql b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Counter.gql index 0ea4f66..b93e379 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Counter.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Counter.gql @@ -1,3 +1,3 @@ subscription Counter { - counter + ctrlCounter } diff --git a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Prompting.gql b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Prompting.gql index 4a4bd53..35a0e4b 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Prompting.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Prompting.gql @@ -1,5 +1,5 @@ subscription Prompting($traceId: Int!) { - prompting(traceId: $traceId) { + ctrlPrompting(traceId: $traceId) { prompting fileName lineNo diff --git a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/State.gql b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/State.gql index 118bb52..78dde9f 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/State.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/State.gql @@ -1,3 +1,3 @@ subscription State { - state + ctrlState } diff --git a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Stdout.gql b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Stdout.gql index 2d00b43..3b75df0 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Stdout.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/Stdout.gql @@ -1,3 +1,3 @@ subscription Stdout { - stdout + ctrlStdout } diff --git a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/TraceIds.gql b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/TraceIds.gql index 08ad7c4..0e015ed 100644 --- a/nextlinegraphql/plugins/ctrl/graphql/subscriptions/TraceIds.gql +++ b/nextlinegraphql/plugins/ctrl/graphql/subscriptions/TraceIds.gql @@ -1,3 +1,3 @@ subscription TraceIds { - traceIds + ctrlTraceIds } diff --git a/nextlinegraphql/plugins/ctrl/schema/mutation.py b/nextlinegraphql/plugins/ctrl/schema/mutation.py index 5031688..47ff22a 100644 --- a/nextlinegraphql/plugins/ctrl/schema/mutation.py +++ b/nextlinegraphql/plugins/ctrl/schema/mutation.py @@ -71,7 +71,7 @@ async def mutate_load_example_script(info: Info) -> bool: @strawberry.type -class Mutation: +class MutationCtrl: exec: bool = strawberry.field(resolver=mutate_exec) run_and_continue: bool = strawberry.field(resolver=mutate_run_and_continue) reset: bool = strawberry.field(resolver=mutate_reset) @@ -80,3 +80,10 @@ class Mutation: terminate: bool = strawberry.field(resolver=mutate_terminate) kill: bool = strawberry.field(resolver=mutate_kill) load_example_script: bool = strawberry.field(resolver=mutate_load_example_script) + + +@strawberry.type +class Mutation: + @strawberry.field + def ctrl(self) -> MutationCtrl: + return MutationCtrl() diff --git a/nextlinegraphql/plugins/ctrl/schema/query.py b/nextlinegraphql/plugins/ctrl/schema/query.py index 9118a6b..ed93a52 100644 --- a/nextlinegraphql/plugins/ctrl/schema/query.py +++ b/nextlinegraphql/plugins/ctrl/schema/query.py @@ -49,7 +49,7 @@ def query_continuous_enabled(info: Info) -> bool: @strawberry.type -class Query: +class QueryCtrl: hello: str = strawberry.field(resolver=query_hello) state: str = strawberry.field(resolver=query_state) run_no: int = strawberry.field(resolver=query_run_no) @@ -58,3 +58,10 @@ class Query: source_line: str = strawberry.field(resolver=query_source_line) exception: Optional[str] = strawberry.field(resolver=query_exception) continuous_enabled: bool = strawberry.field(resolver=query_continuous_enabled) + + +@strawberry.type +class Query: + @strawberry.field + def ctrl(self) -> QueryCtrl: + return QueryCtrl() diff --git a/nextlinegraphql/plugins/ctrl/schema/subscription.py b/nextlinegraphql/plugins/ctrl/schema/subscription.py index d43b9f1..da7794e 100644 --- a/nextlinegraphql/plugins/ctrl/schema/subscription.py +++ b/nextlinegraphql/plugins/ctrl/schema/subscription.py @@ -73,24 +73,24 @@ def subscribe_continuous_enabled(info: Info) -> AsyncIterator[bool]: @strawberry.type class Subscription: - counter: AsyncIterator[int] = strawberry.field( + ctrl_counter: AsyncIterator[int] = strawberry.field( is_subscription=True, resolver=subscribe_counter ) - state: AsyncIterator[str] = strawberry.field( + ctrl_state: AsyncIterator[str] = strawberry.field( is_subscription=True, resolver=subscribe_state ) - run_no: AsyncIterator[int] = strawberry.field( + ctrl_run_no: AsyncIterator[int] = strawberry.field( is_subscription=True, resolver=subscribe_run_no ) - trace_ids: AsyncIterator[tuple[int, ...]] = strawberry.field( + ctrl_trace_ids: AsyncIterator[tuple[int, ...]] = strawberry.field( is_subscription=True, resolver=subscribe_trace_ids ) - prompting: AsyncIterator[PromptingData] = strawberry.field( + ctrl_prompting: AsyncIterator[PromptingData] = strawberry.field( is_subscription=True, resolver=subscribe_prompting ) - stdout: AsyncIterator[str] = strawberry.field( + ctrl_stdout: AsyncIterator[str] = strawberry.field( is_subscription=True, resolver=subscribe_stdout ) - continuous_enabled: AsyncIterator[bool] = strawberry.field( + ctrl_continuous_enabled: AsyncIterator[bool] = strawberry.field( is_subscription=True, resolver=subscribe_continuous_enabled ) diff --git a/tests/plugins/ctrl/schema/examples/test_async_asgi_testclient.py b/tests/plugins/ctrl/schema/examples/test_async_asgi_testclient.py index b023371..ed5a074 100644 --- a/tests/plugins/ctrl/schema/examples/test_async_asgi_testclient.py +++ b/tests/plugins/ctrl/schema/examples/test_async_asgi_testclient.py @@ -4,7 +4,9 @@ async def test_query(): query = ''' - { hello } + { ctrl + { hello } + } ''' data = {'query': query} @@ -16,14 +18,14 @@ async def test_query(): async with TestClient(create_app()) as client: resp = await client.post('/', json=data, headers=headers) assert resp.status_code == 200 - expect = {'data': {'hello': 'Hello, Mozilla/5.0!'}} + expect = {'data': {'ctrl': {'hello': 'Hello, Mozilla/5.0!'}}} assert expect == resp.json() async def test_subscription(): query = ''' subscription { - counter + ctrlCounter } ''' @@ -45,7 +47,7 @@ async def test_subscription(): expect = { 'type': 'data', 'id': '1', - 'payload': {'data': {'counter': 1}}, + 'payload': {'data': {'ctrlCounter': 1}}, } actual = await ws.receive_json() assert expect == actual @@ -53,7 +55,7 @@ async def test_subscription(): expect = { 'type': 'data', 'id': '1', - 'payload': {'data': {'counter': 2}}, + 'payload': {'data': {'ctrlCounter': 2}}, } actual = await ws.receive_json() assert expect == actual @@ -61,7 +63,7 @@ async def test_subscription(): expect = { 'type': 'data', 'id': '1', - 'payload': {'data': {'counter': 3}}, + 'payload': {'data': {'ctrlCounter': 3}}, } actual = await ws.receive_json() assert expect == actual @@ -69,7 +71,7 @@ async def test_subscription(): expect = { 'type': 'data', 'id': '1', - 'payload': {'data': {'counter': 4}}, + 'payload': {'data': {'ctrlCounter': 4}}, } actual = await ws.receive_json() assert expect == actual @@ -77,7 +79,7 @@ async def test_subscription(): expect = { 'type': 'data', 'id': '1', - 'payload': {'data': {'counter': 5}}, + 'payload': {'data': {'ctrlCounter': 5}}, } actual = await ws.receive_json() assert expect == actual diff --git a/tests/plugins/ctrl/schema/mutations/test_load_example_script.py b/tests/plugins/ctrl/schema/mutations/test_load_example_script.py index 90b15e4..ff02999 100644 --- a/tests/plugins/ctrl/schema/mutations/test_load_example_script.py +++ b/tests/plugins/ctrl/schema/mutations/test_load_example_script.py @@ -24,5 +24,5 @@ async def test_query() -> None: result = await schema.execute(MUTATE_LOAD_EXAMPLE_SCRIPT, context_value=context) assert not result.errors assert result.data - assert result.data['loadExampleScript'] is True + assert result.data['ctrl']['loadExampleScript'] is True assert nextline.statement == example_script diff --git a/tests/plugins/ctrl/schema/mutations/test_reset.py b/tests/plugins/ctrl/schema/mutations/test_reset.py index f3e7007..fd6ad27 100644 --- a/tests/plugins/ctrl/schema/mutations/test_reset.py +++ b/tests/plugins/ctrl/schema/mutations/test_reset.py @@ -34,10 +34,10 @@ async def test_schema(statement: str | None) -> None: MUTATE_RESET, context_value=context, variable_values=variables ) assert (data := result.data) - assert data['reset'] is True + assert data['ctrl']['reset'] is True result = await schema.execute(QUERY_SOURCE, context_value=context) assert (data := result.data) expected = statement or example_script - assert expected.split('\n') == data['source'] + assert expected.split('\n') == data['ctrl']['source'] diff --git a/tests/plugins/ctrl/schema/queries/__snapshots__/test_source.ambr b/tests/plugins/ctrl/schema/queries/__snapshots__/test_source.ambr index bd58e22..1ca780e 100644 --- a/tests/plugins/ctrl/schema/queries/__snapshots__/test_source.ambr +++ b/tests/plugins/ctrl/schema/queries/__snapshots__/test_source.ambr @@ -1,87 +1,93 @@ # serializer version: 1 # name: test_schema[default] dict({ - 'source': list([ - 'import time', - '', - 'time.sleep(0.3)', - '', - 'def f():', - ' for _ in range(10):', - ' pass', - ' return', - '', - 'f()', - 'f()', - '', - "print('here!')", - '', - 'import script_threading', - '', - 'script_threading.run()', - '', - '', - 'import script_asyncio', - '', - 'script_asyncio.run()', - '', - ]), + 'ctrl': dict({ + 'source': list([ + 'import time', + '', + 'time.sleep(0.3)', + '', + 'def f():', + ' for _ in range(10):', + ' pass', + ' return', + '', + 'f()', + 'f()', + '', + "print('here!')", + '', + 'import script_threading', + '', + 'script_threading.run()', + '', + '', + 'import script_asyncio', + '', + 'script_asyncio.run()', + '', + ]), + }), }) # --- # name: test_schema[path] dict({ - 'source': list([ - 'from threading import Thread', - '', - '', - 'def run():', - ' t1 = Thread(target=f1)', - ' t1.start()', - ' t2 = Thread(target=f2)', - ' t2.start()', - ' t2.join()', - ' t1.join()', - ' return', - '', - 'def f1():', - ' for _ in range(5):', - ' pass', - ' return', - '', - 'def f2():', - ' for _ in range(5):', - ' pass', - ' return', - '', - ]), + 'ctrl': dict({ + 'source': list([ + 'from threading import Thread', + '', + '', + 'def run():', + ' t1 = Thread(target=f1)', + ' t1.start()', + ' t2 = Thread(target=f2)', + ' t2.start()', + ' t2.join()', + ' t1.join()', + ' return', + '', + 'def f1():', + ' for _ in range(5):', + ' pass', + ' return', + '', + 'def f2():', + ' for _ in range(5):', + ' pass', + ' return', + '', + ]), + }), }) # --- # name: test_schema[string] dict({ - 'source': list([ - 'import time', - '', - 'time.sleep(0.3)', - '', - 'def f():', - ' for _ in range(10):', - ' pass', - ' return', - '', - 'f()', - 'f()', - '', - "print('here!')", - '', - 'import script_threading', - '', - 'script_threading.run()', - '', - '', - 'import script_asyncio', - '', - 'script_asyncio.run()', - '', - ]), + 'ctrl': dict({ + 'source': list([ + 'import time', + '', + 'time.sleep(0.3)', + '', + 'def f():', + ' for _ in range(10):', + ' pass', + ' return', + '', + 'f()', + 'f()', + '', + "print('here!')", + '', + 'import script_threading', + '', + 'script_threading.run()', + '', + '', + 'import script_asyncio', + '', + 'script_asyncio.run()', + '', + ]), + }), }) # --- diff --git a/tests/plugins/ctrl/schema/queries/test_exception.py b/tests/plugins/ctrl/schema/queries/test_exception.py index 4251dce..67e5859 100644 --- a/tests/plugins/ctrl/schema/queries/test_exception.py +++ b/tests/plugins/ctrl/schema/queries/test_exception.py @@ -21,4 +21,4 @@ async def test_schema() -> None: result = await schema.execute(QUERY_EXCEPTION, context_value=context) assert (data := result.data) - assert "Exception: ('foo', 'bar')" in data['exception'] + assert "Exception: ('foo', 'bar')" in data['ctrl']['exception'] diff --git a/tests/plugins/ctrl/schema/test_run.py b/tests/plugins/ctrl/schema/test_run.py index 9254488..94b9ea4 100644 --- a/tests/plugins/ctrl/schema/test_run.py +++ b/tests/plugins/ctrl/schema/test_run.py @@ -36,7 +36,7 @@ async def test_schema() -> None: result = await schema.execute(QUERY_STATE, context_value=context) assert (data := result.data) - assert 'initialized' == data['state'] + assert 'initialized' == data['ctrl']['state'] await asyncio.sleep(0.01) @@ -48,7 +48,7 @@ async def test_schema() -> None: result = await schema.execute(MUTATE_EXEC, context_value=context) assert (data := result.data) - assert data['exec'] + assert data['ctrl']['exec'] states, *_ = await asyncio.gather( task_subscribe_state, @@ -59,7 +59,7 @@ async def test_schema() -> None: result = await schema.execute(QUERY_STATE, context_value=context) assert (data := result.data) - assert 'finished' == data['state'] + assert 'finished' == data['ctrl']['state'] async def _subscribe_state(schema: Schema, context: Any) -> list[str]: @@ -68,7 +68,7 @@ async def _subscribe_state(schema: Schema, context: Any) -> list[str]: assert hasattr(sub, '__aiter__') async for result in sub: assert (data := result.data) - state = data['state'] + state = data['ctrlState'] ret.append(state) if state == 'finished': break @@ -85,7 +85,7 @@ async def _control_execution(schema: Schema, context: Any) -> None: async for result in agen: assert isinstance(result, GraphQLExecutionResult) assert (data := result.data) - trace_ids: list[int] = data['traceIds'] + trace_ids: list[int] = data['ctrlTraceIds'] if not (ids := set(trace_ids)): break new_ids, prev_ids = ids - prev_ids, ids @@ -112,7 +112,7 @@ async def _control_trace(schema: Schema, context: Any, trace_no: int) -> None: async for result in sub: assert (data := result.data) - state = data['prompting'] + state = data['ctrlPrompting'] # e.g. {'fileName': '', 'lineNo': 1, 'prompting': 1, 'traceEvent': 'line'} if not state['prompting']: continue @@ -127,7 +127,7 @@ async def _control_trace(schema: Schema, context: Any, trace_no: int) -> None: }, ) assert (data := query_result.data) - source_line = data['sourceLine'] + source_line = data['ctrl']['sourceLine'] if source_line in to_step: command = 'step' @@ -142,4 +142,4 @@ async def _control_trace(schema: Schema, context: Any, trace_no: int) -> None: }, ) assert (data := query_result.data) - assert data['sendPdbCommand'] + assert data['ctrl']['sendPdbCommand'] diff --git a/tests/plugins/ctrl/test_plugin.py b/tests/plugins/ctrl/test_plugin.py index 6c5eb91..5148031 100644 --- a/tests/plugins/ctrl/test_plugin.py +++ b/tests/plugins/ctrl/test_plugin.py @@ -10,12 +10,12 @@ async def test_plugin(client: TestClient): data = await gql_request(client, QUERY_STATE) - assert data['state'] == 'initialized' + assert data['ctrl']['state'] == 'initialized' task = asyncio.create_task(_subscribe_state(client)) data = await gql_request(client, MUTATE_RUN_AND_CONTINUE) - assert data['runAndContinue'] + assert data['ctrl']['runAndContinue'] states = await task assert states == ['initialized', 'running', 'finished'] @@ -24,7 +24,7 @@ async def test_plugin(client: TestClient): async def _subscribe_state(client: TestClient) -> list[str]: ret = [] async for data in gql_subscribe(client, SUBSCRIBE_STATE): - s = data['state'] + s = data['ctrlState'] ret.append(s) if s == 'finished': break