Validate graphs
Graph validation is essential for preventing runtime errors in TEN applications. Invalid graph configurations can cause extension connection failures, message routing errors, schema compatibility issues, and missing dependency problems.
Use the tman check graph
command to validate TEN app graphs and catch these issues before deployment. This command verifies that:
- All required nodes are defined
- Extension connections are valid
- Message schemas are compatible
- Required packages are installed
Validation helps ensure your TEN app graphs function correctly when deployed.
Command syntax
The basic syntax for the check graph
command is:
The command uses the following key parameters:
-
--app <APP_PATH>
: The absolute path to the app directory containing graph definitions -
--predefined-graph-name <GRAPH_NAME>
: Validate a specific predefined graph by name. If omitted, all predefined graphs in the app are validated. (Optional) -
--graph <JSON_STRING>
: Validate a JSON string representing astart_graph
command instead of predefined graphs from files. (Optional)
Follow these guidelines when using the command:
- Run the command from any directory—you don't need to be in the app's root directory
- Use the command to validate connections that span multiple apps in multi-app graphs
Usage examples
The following examples illustrate the use of the tman check graph
command:
-
Check all predefined graphs in
property.json
: -
Check a specific predefined graph:
-
Check a
start_graph
command:
Requirements and setup
Before using check graph
, ensure the following requirements are met:
-
Package installation: All extensions that the app depends on must be installed using
tman install
. The validation process requires information about each extension in the graph, such as APIs defined in theirmanifest.json
files. -
Predefined graph definition: If you specify a predefined graph name, the definition must exist in the
property.json
file of the app specified by the--app
parameter. -
Unique app URI: In multi-app graphs, each app's
property.json
must define a uniqueten::uri
. Theuri
value cannot be set to"localhost"
.
Validation rules
The tman check graph
command validates the following rules:
Nodes must be present
The nodes
array is required in any graph definition. If absent, an error is thrown.
-
Example: No nodes defined
Output:
Node names must be unique
Each node in the nodes
array represents an extension instance within a group of an app, created by a specified addon. Each extension instance must be uniquely represented by a single node. A node is uniquely identified by the combination of app
, extension_group
, and name
. Multiple entries for the same extension instance are not allowed.
-
Example: Duplicate nodes
Output:
Connection extensions must be defined in nodes
All extension instances referenced in the connections
field, whether as a source or destination, must be explicitly defined in the nodes
field. Any instance not defined in the nodes
array causes validation errors.
-
Example: Source extension not defined
Suppose that the
property.json
file of a TEN app is as follows.Output:
-
Example: Destination extension not defined
Suppose that the
property.json
file of a TEN app is as follows.Output:
Node addons must be installed
All node addons must be installed using tman install
and have matching app URIs for successful validation.
-
Example: The
ten::uri
inproperty.json
is not equal to theapp
field in nodes:Suppose that the
property.json
file of a TEN app is as follows.Output:
The problem is that all packages in the app are stored in a map for which the key is the
uri
of the app, and each node in the graph is retrieved by theapp
field (localhost
by default). Theapp
in node (localhost
) is a mismatch with theuri
of theapp
(<http://localhost:8001>
). -
Example: The
ten_packages
does not exist astman install
has not been executedSuppose that the
property.json
file of a TEN app is as follows and theten_packages
directory does NOT exist.Output:
Extension connections must be in one section
All messages sent from an extension must be defined within a single connection section. Multiple connection sections for the same extension are not allowed.
-
Example:
Suppose that all the packages have been installed.
Output:
Message names must be unique within each type
Each message sent from an extension must have a unique name within its message type (cmd, data, etc.). Duplicate message names within the same type are not allowed.
-
Example:
Suppose that all the packages have been installed.
Output:
Message schemas must be compatible
Messages are validated for schema compatibility based on the schema definitions in the manifest.json
files of extensions. Validation follows these compatibility rules:
-
If the message schema is not found in either the source or target extension, the message is compatible
-
If the message schema is only found in one extension, the message is incompatible
-
If schemas exist in both extensions, the message is compatible only when:
- Property types are compatible
- For object properties, all fields in both source and target schemas must have compatible types
- If the target schema defines
required
fields, the source schema must also definerequired
fields that include all target requirements
-
Example:
Suppose that all the packages have been installed.
The
manifest.json
file foraddon_a
is as follows.And, the
manifest.json
file foraddon_b
is as follows.Check the graph with the following command.
Output:
App fields must be unambiguous
The app
field in each node must follow specific rules to ensure proper app identification and routing.
App field requirements:
-
Must equal the
ten::uri
of the corresponding TEN app -
Either all nodes must have
app
declared, or none should -
Cannot be set to
localhost
-
Cannot be an empty string
-
Example: Some nodes specify the
app
fieldCheck the graph with the following command.
Output:
-
Example: Source extension specifies
app
in connections when nodes don'tCheck the graph using the following command.
Output:
-
Example: Target extension specifies
app
in connections when nodes don'tCheck the graph using the following command.
Output:
-
Example: App field doesn't match ten::uri
Same as the example for Node addons must be installed.
-
Example: App field is
localhost
in a single-app graphCheck the graph using the following command.
Output:
-
Example: App field is
localhost
in a multi-app graphCheck the graph using the following command.
Output: