Skip to main content

JS Agent / Admin Backend Communication

Messages#

Admin#

Admin backend sends messages in the following format:

{
"type": "MESSAGE",
"destination": "/agent/change-header-name",
"text": ""
}

"text" field is stringified.

Admin backend expects to get a response for each message, called "delivery confirmation" in the following format:

{
"type": "MESSAGE_DELIVERED",
"destination": "/agent/change-header-name"
}

Some messages aren't used in JS agent initialization, so no actions are performed on JS agent side, but delivery confirmation is still sent:

  • /agent/change-header-name
  • /agent/set-packages-prefixes
  • /agent/load-classes-data

Plugin#

{
"type": "PLUGIN_DATA",
"text": {
"pluginId": "test2code",
"drillMessage": {
"content": "" // set to stringified plugin message
}
}
}

"content" field is stringified.

Agent Registration & Test2Code Plugin Initialization#

  1. Open WS connection to Admin backend API on the /agent/attach route (e.g. http://localhost:8090/agent/attach) with the following headers specified:

    {
    "AgentConfig": {
    "id": "sample-agent-id",
    "serviceGroupId": "sample-group-id",
    "buildVersion": "0.0.1",
    "agentType": "NODEJS",
    "instanceId": ""
    },
    "needSync": true // is set to "true" during the initial connect ("false" if the agent establishes connection after a restart)
    }

At that point, agent should appear in Admin Panel. Register it, make sure to enable Test2Code plugin at step 3.

  1. Wait for the following message:

    {
    "type": "MESSAGE",
    "destination": "/agent/load",
    "text": {
    "meta": {
    "id": "test2code",
    "name": "Test2Code",
    "description": "Test2Code plugin minimizes your regression suite via Test Impact Analytics by suggesting only affected subset of tests to run, and highlight untested areas via Test Gap Analysis, providing evidence of how changes are tested and which areas and not tested at all.",
    "type": "Custom",
    "family": "INSTRUMENTATION",
    "enabled": true,
    "config": "{\"message\": \"hello from default plugin config... This is 'plugin_config.json file\"}",
    "checkSum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "isNative": false
    },
    "data": []
    }
    }
  2. In response to that particular message JS agent sends 2 delivery confirmations:

    send that first:

    {
    "type": "MESSAGE_DELIVERED",
    "destination": "/agent/plugin/test2code/loaded"
    }

    send delivery confirmation for the original destination:

    {
    "type": "MESSAGE_DELIVERED",
    "destination": "/agent/load"
    }

"AST" data (metadata on packages, classes, methods) are sent during the next steps.

  1. Wait for the following message:

    {
    "destination": "/plugin/togglePlugin",
    "data": {
    "text": {
    "pluginId": "test2code"
    }
    }
    }
  2. Send containing "AST" data:

    {
    // this is a plugin message, wrap it into plugin message format (stringify, set result to "content" field, see "Messages/Plugin" above)
    "type": "INIT_DATA_PART",
    "astEntities": [
    // each array entry represents a class
    {
    "path": "js/directives", // admin groups classes into packages based on that value
    "name": "TodoBlur.ts",
    "methods": [
    {
    "name": "GLOBAL",
    "params": [],
    "returnType": "void",
    "probes": [3, 4, 17],
    "count": 3
    },
    {
    "name": "todoBlur",
    "params": [],
    "returnType": "void",
    "probes": [9, 10, 15, 16],
    "count": 4,
    "checksum": "9381a3cce26fc23fbbe4e5650486ee0d5454af9792b51cfdfe4361436d2ecfc5"
    }
    ]
    },
    {
    /* next class entry */
    }
    ]
    }
  3. Send delivery confirmation for /plugin/togglePlugin:

    {
    "type": "MESSAGE_DELIVERED",
    "destination": "/plugin/togglePlugin"
    }

At that point, test2code plugin dashboard should be available in the Admin Panel. Check that methods table reflects actual packages, classes and methods.

Start Session#

  1. Wait for the "Start agent session" message:

    {
    "type": "MESSAGE",
    "destination": "/plugin/action",
    "text": {
    "id": "test2code",
    "message": {
    "type": "START_AGENT_SESSION", // "STOP" in case of stop session action
    "payload": {
    "sessionId": "4867e838-51ca-4999-83c6-f68a7c7f279a",
    "testType": "MANUAL",
    "testName": "add1",
    "isRealtime": true,
    "isGlobal": false
    }
    }
    }
    }
  2. Send "Session started" message:

    // this is a plugin message, wrap it into plugin message format (stringify, set result to "content" field, see "Messages/Plugin" above)
    {
    "type": "SESSION_STARTED",
    "sessionId": "4867e838-51ca-4999-83c6-f68a7c7f279a",
    "testType": "MANUAL",
    "ts": "1616679452533"
    }
  3. Send delivery confirmation:

    {
    "type": "MESSAGE_DELIVERED",
    "destination": "/plugin/action"
    }

Send Coverage#

That might be better to implement it differently for the .NET agent, we've got to discuss that.

  1. Send coverage data part message:

    // this is a plugin message, wrap it into plugin message format (stringify, set result to "content" field, see "Messages/Plugin" above)
    {
    "type": "COVERAGE_DATA_PART",
    "sessionId": "4867e838-51ca-4999-83c6-f68a7c7f279a",
    "data": [
    {
    "className": "js/controllers/TodoCtrl.ts",
    // concatenated array of all class probes (from all methods)
    "probes": [true, true, true, false, false, false, true, false, false, true],
    "testName": "Add todo item"
    },
    {
    "className": "js/directives/TodoBlur.ts",
    // concatenated array of all class probes (from all methods)
    "probes": [false, false, true, true, true, false, false, false, true, false, false, true],
    "testName": "Add todo item"
    },
    {
    /*next class coverage entry*/
    }
    ]
    }

Stop/Cancel Session#

  1. Wait for the "Stop agent session" message:

    {
    "type": "MESSAGE",
    "destination": "/plugin/action",
    "text": {
    "id": "test2code",
    "message": {
    "type": "STOP", // "CANCEL"
    "payload": {
    "sessionId": "4867e838-51ca-4999-83c6-f68a7c7f279a"
    }
    }
    }
    }
  2. Send "Session finished" message:

    // this is a plugin message, wrap it into plugin message format (stringify, set result to "content" field, see "Messages/Plugin" above)
    {
    "type": "SESSION_FINISHED", // "SESSION_CANCELLED"
    "sessionId": "4867e838-51ca-4999-83c6-f68a7c7f279a",
    "ts": "1616679452533"
    }
  3. Send delivery confirmation:

    {
    "type": "MESSAGE_DELIVERED",
    "destination": "/plugin/action"
    }

Init Active Scope#

  1. Wait for the "Init active scope" message:

    {
    "type": "MESSAGE",
    "destination": "/plugin/action",
    "message": {
    "id": "test2code",
    "message": {
    "type": "INIT_ACTIVE_SCOPE",
    "payload": {
    "id": "d525c728-eccb-4eaf-b0a9-be4a2281cafd",
    "name": "New Scope 2",
    "prevId": "97bfc5dc-d09d-4240-bf35-dbd999103818"
    }
    }
    }
    }
  2. Send the "Scope initialized" message:

    // this is a plugin message, wrap it into plugin message format (stringify, set result to "content" field, see "Messages/Plugin" above)
    {
    "type": "SCOPE_INITIALIZED",
    "id": "d525c728-eccb-4eaf-b0a9-be4a2281cafd",
    "name": "New Scope 2",
    "prevId": "97bfc5dc-d09d-4240-bf35-dbd999103818",
    "ts": "1616680302751"
    }
  3. Send delivery confirmation:

    {
    "type": "MESSAGE_DELIVERED",
    "destination": "/plugin/action"
    }