Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/ten_runtime/extension/internal/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@ static bool ten_extension_graph_property_resolve_placeholders(
ten_placeholder_init(&placeholder);

if (!ten_placeholder_parse(&placeholder, str_value, err)) {
ten_placeholder_deinit(&placeholder);
return false;
}

if (!ten_placeholder_resolve(&placeholder, curr_value, err)) {
ten_placeholder_deinit(&placeholder);
return false;
}

Expand Down
7 changes: 6 additions & 1 deletion core/src/ten_runtime/extension/ten_env/on_xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ bool ten_extension_on_configure_done(ten_env_t *self) {
}

rc = ten_extension_resolve_properties_in_graph(extension, &err);
TEN_ASSERT(rc, "Failed to resolve properties in graph.");
if (!rc) {
TEN_LOGW(
"Failed to resolve properties in graph: %s, use the raw property data "
"instead.",
ten_error_message(&err));
}

ten_extension_merge_properties_from_graph(extension);

Expand Down
7 changes: 5 additions & 2 deletions core/src/ten_utils/lib/sys/general/placeholder.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ static TEN_PLACEHOLDER_SCOPE ten_placeholder_scope_from_string(
if (!strcmp(scope_str, TEN_STR_ENV)) {
return TEN_PLACEHOLDER_SCOPE_ENV;
} else {
TEN_ASSERT(0, "Should not happen.");
return TEN_PLACEHOLDER_SCOPE_INVALID;
}
}
Expand Down Expand Up @@ -130,6 +129,11 @@ bool ten_placeholder_parse(ten_placeholder_t *self, const char *input,
char *scope_end = strchr(content, TEN_STR_PLACEHOLDER_SCOPE_DELIMITER);
if (!scope_end) {
TEN_FREE(content);
if (err) {
ten_error_set(err, TEN_ERROR_CODE_GENERIC,
"Invalid placeholder format: %s, missing scope delimiter.",
input);
}
return false;
}

Expand Down Expand Up @@ -215,7 +219,6 @@ bool ten_placeholder_resolve(ten_placeholder_t *self,
ten_error_set(err, TEN_ERROR_CODE_GENERIC,
"Unsupported placeholder scope: %d", self->scope);
}
TEN_ASSERT(0, "Should not happen.");
return false;
}

Expand Down
1 change: 1 addition & 0 deletions tests/ten_runtime/integration/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ group("cpp") {
"graph_env_var_1",
"graph_env_var_2",
"graph_env_var_3",
"graph_env_var_4",
"hello_world",
"large_result",
"restful",
Expand Down
85 changes: 85 additions & 0 deletions tests/ten_runtime/integration/cpp/graph_env_var_4/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#
# Copyright © 2025 Agora
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/feature/test.gni")
import("//build/ten_runtime/ten.gni")

ten_package_test_prepare_app("graph_env_var_4_app") {
src_app = "default_app_cpp"
src_app_language = "cpp"
generated_app_src_root_dir_name = "graph_env_var_4_app"

replace_paths_after_install_app = [
"graph_env_var_4_app/manifest.json",
"graph_env_var_4_app/property.json",
]

replace_paths_after_install_all = [
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/manifest.json",
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/property.json",
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/src/main.cc",
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/BUILD.gn",
]

if (ten_enable_ten_manager) {
deps = [
"//core/src/ten_manager",
"//core/src/ten_runtime:upload_ten_runtime_system_package_to_server",
"//packages/core_apps/default_app_cpp:upload_default_app_cpp_to_server",
"//packages/core_extensions/default_extension_cpp:upload_default_extension_cpp_to_server",
"//packages/core_protocols/msgpack:upload_protocol_msgpack_to_server",
]
}
}

ten_package_test_prepare_client("graph_env_var_4_app_client") {
sources = [ "client/client.cc" ]
include_dirs = [
"//core/src",
"//core",
"//packages",
"//tests",
]
deps = [
"//core/src/ten_runtime",
"//packages/core_protocols/msgpack:msgpack_files",
"//tests/common/client:msgpack_client",
"//third_party/msgpack:msgpackc",
"//third_party/nlohmann_json",
]
}

ten_package_test_prepare_auxiliary_resources("graph_env_var_4_app_test_files") {
resources = [
"__init__.py",
"test_case.py",
]

common_files =
exec_script("//.gnfiles/build/scripts/glob_file.py",
[
"--dir",
rebase_path("//tests/ten_runtime/integration/common/**/*"),
"--dir-base",
rebase_path("//tests/ten_runtime/integration/common"),
"--recursive",
"--only-output-file",
],
"json")

foreach(common_file, common_files) {
common_file_rel_path = common_file.relative_path
resources += [ "//tests/ten_runtime/integration/common/${common_file_rel_path}=>common/${common_file_rel_path}" ]
}
}

group("graph_env_var_4") {
deps = [
":graph_env_var_4_app",
":graph_env_var_4_app_client",
":graph_env_var_4_app_test_files",
]
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright © 2025 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#include <nlohmann/json.hpp>

#include "tests/common/client/cpp/msgpack_tcp.h"

int main(int argc, char **argv) {
// Create a client and connect to the app.
auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/");

// Send graph.
auto start_graph_cmd = ten::cmd_start_graph_t::create();
start_graph_cmd->set_graph_from_json(R"({
"nodes": [{
"type": "extension",
"name": "test_extension",
"addon": "default_extension_cpp",
"app": "msgpack://127.0.0.1:8001/",
"extension_group": "test_extension_group",
"property": {
"prop": "${abc}"
}
}]
})");
auto cmd_result =
client->send_cmd_and_recv_result(std::move(start_graph_cmd));
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
"Should not happen.");

// Send a user-defined 'hello world' command.
auto hello_world_cmd = ten::cmd_t::create("hello_world");
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
"test_extension_group", "test_extension");
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
"Should not happen.");
TEN_ASSERT(static_cast<std::string>("hello world, too") ==
cmd_result->get_property_string("detail"),
"Should not happen.");

delete client;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "app",
"name": "default_app_cpp",
"version": "0.8.18",
"dependencies": [
{
"type": "system",
"name": "ten_runtime",
"version": "0.8.18"
},
{
"type": "extension",
"name": "default_extension_cpp",
"version": "0.8.18"
},
{
"type": "protocol",
"name": "msgpack",
"version": "0.8.18"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"_ten": {
"uri": "msgpack://127.0.0.1:8001/"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright © 2025 Agora
# This file is part of TEN Framework, an open source project.
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/feature/ten_package.gni")

ten_package("default_extension_cpp") {
package_kind = "extension"
enable_build = true

resources = [
"manifest.json",
"property.json",
]

sources = [ "src/main.cc" ]
include_dirs = [ "//core/include" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "extension",
"name": "default_extension_cpp",
"version": "0.8.18",
"dependencies": [
{
"type": "system",
"name": "ten_runtime",
"version": "0.8.18"
}
],
"package": {
"include": [
"**"
]
},
"api": {
"cmd_in": [
{
"name": "hello_world"
}
],
"cmd_out": [],
"data_in": [],
"data_out": [],
"video_frame_in": [],
"video_frame_out": [],
"audio_frame_in": [],
"audio_frame_out": [],
"interface_in": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prop": "default_value"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright © 2025 Agora
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0, with certain conditions.
// Refer to the "LICENSE" file in the root directory for more information.
//
#include <cassert>
#include <cstdlib>

#include "ten_runtime/binding/cpp/ten.h"

class test_extension : public ten::extension_t {
public:
explicit test_extension(const char *name) : ten::extension_t(name) {}

void on_init(ten::ten_env_t &ten_env) override { ten_env.on_init_done(); }

void on_start(ten::ten_env_t &ten_env) override {
// The property.json will be loaded by default during `on_init` phase, so
// the property `prop` should be available here.
auto prop = ten_env.get_property_string("prop");
if (prop != "${abc}") {
assert(0 && "Should not happen.");
}

ten_env.on_start_done();
}

void on_cmd(ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_t> cmd) override {
if (cmd->get_name() == "hello_world") {
auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK);
cmd_result->set_property("detail", "hello world, too");
ten_env.return_result(std::move(cmd_result), std::move(cmd));
}
}
};

TEN_CPP_REGISTER_ADDON_AS_EXTENSION(default_extension_cpp, test_extension);
Loading
Loading