Skip to content

Commit 45a5acd

Browse files
authored
fix: remove assert during resolving properties (#1059)
1 parent 542834c commit 45a5acd

File tree

14 files changed

+430
-3
lines changed

14 files changed

+430
-3
lines changed

core/src/ten_runtime/extension/internal/metadata.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ static bool ten_extension_graph_property_resolve_placeholders(
197197
ten_placeholder_init(&placeholder);
198198

199199
if (!ten_placeholder_parse(&placeholder, str_value, err)) {
200+
ten_placeholder_deinit(&placeholder);
200201
return false;
201202
}
202203

203204
if (!ten_placeholder_resolve(&placeholder, curr_value, err)) {
205+
ten_placeholder_deinit(&placeholder);
204206
return false;
205207
}
206208

core/src/ten_runtime/extension/ten_env/on_xxx.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ bool ten_extension_on_configure_done(ten_env_t *self) {
137137
}
138138

139139
rc = ten_extension_resolve_properties_in_graph(extension, &err);
140-
TEN_ASSERT(rc, "Failed to resolve properties in graph.");
140+
if (!rc) {
141+
TEN_LOGW(
142+
"Failed to resolve properties in graph: %s, use the raw property data "
143+
"instead.",
144+
ten_error_message(&err));
145+
}
141146

142147
ten_extension_merge_properties_from_graph(extension);
143148

core/src/ten_utils/lib/sys/general/placeholder.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ static TEN_PLACEHOLDER_SCOPE ten_placeholder_scope_from_string(
8686
if (!strcmp(scope_str, TEN_STR_ENV)) {
8787
return TEN_PLACEHOLDER_SCOPE_ENV;
8888
} else {
89-
TEN_ASSERT(0, "Should not happen.");
9089
return TEN_PLACEHOLDER_SCOPE_INVALID;
9190
}
9291
}
@@ -130,6 +129,11 @@ bool ten_placeholder_parse(ten_placeholder_t *self, const char *input,
130129
char *scope_end = strchr(content, TEN_STR_PLACEHOLDER_SCOPE_DELIMITER);
131130
if (!scope_end) {
132131
TEN_FREE(content);
132+
if (err) {
133+
ten_error_set(err, TEN_ERROR_CODE_GENERIC,
134+
"Invalid placeholder format: %s, missing scope delimiter.",
135+
input);
136+
}
133137
return false;
134138
}
135139

@@ -215,7 +219,6 @@ bool ten_placeholder_resolve(ten_placeholder_t *self,
215219
ten_error_set(err, TEN_ERROR_CODE_GENERIC,
216220
"Unsupported placeholder scope: %d", self->scope);
217221
}
218-
TEN_ASSERT(0, "Should not happen.");
219222
return false;
220223
}
221224

tests/ten_runtime/integration/cpp/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ group("cpp") {
1212
"graph_env_var_1",
1313
"graph_env_var_2",
1414
"graph_env_var_3",
15+
"graph_env_var_4",
1516
"hello_world",
1617
"large_result",
1718
"restful",
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#
2+
# Copyright © 2025 Agora
3+
# This file is part of TEN Framework, an open source project.
4+
# Licensed under the Apache License, Version 2.0, with certain conditions.
5+
# Refer to the "LICENSE" file in the root directory for more information.
6+
#
7+
import("//build/ten_runtime/feature/test.gni")
8+
import("//build/ten_runtime/ten.gni")
9+
10+
ten_package_test_prepare_app("graph_env_var_4_app") {
11+
src_app = "default_app_cpp"
12+
src_app_language = "cpp"
13+
generated_app_src_root_dir_name = "graph_env_var_4_app"
14+
15+
replace_paths_after_install_app = [
16+
"graph_env_var_4_app/manifest.json",
17+
"graph_env_var_4_app/property.json",
18+
]
19+
20+
replace_paths_after_install_all = [
21+
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/manifest.json",
22+
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/property.json",
23+
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/src/main.cc",
24+
"graph_env_var_4_app/ten_packages/extension/default_extension_cpp/BUILD.gn",
25+
]
26+
27+
if (ten_enable_ten_manager) {
28+
deps = [
29+
"//core/src/ten_manager",
30+
"//core/src/ten_runtime:upload_ten_runtime_system_package_to_server",
31+
"//packages/core_apps/default_app_cpp:upload_default_app_cpp_to_server",
32+
"//packages/core_extensions/default_extension_cpp:upload_default_extension_cpp_to_server",
33+
"//packages/core_protocols/msgpack:upload_protocol_msgpack_to_server",
34+
]
35+
}
36+
}
37+
38+
ten_package_test_prepare_client("graph_env_var_4_app_client") {
39+
sources = [ "client/client.cc" ]
40+
include_dirs = [
41+
"//core/src",
42+
"//core",
43+
"//packages",
44+
"//tests",
45+
]
46+
deps = [
47+
"//core/src/ten_runtime",
48+
"//packages/core_protocols/msgpack:msgpack_files",
49+
"//tests/common/client:msgpack_client",
50+
"//third_party/msgpack:msgpackc",
51+
"//third_party/nlohmann_json",
52+
]
53+
}
54+
55+
ten_package_test_prepare_auxiliary_resources("graph_env_var_4_app_test_files") {
56+
resources = [
57+
"__init__.py",
58+
"test_case.py",
59+
]
60+
61+
common_files =
62+
exec_script("//.gnfiles/build/scripts/glob_file.py",
63+
[
64+
"--dir",
65+
rebase_path("//tests/ten_runtime/integration/common/**/*"),
66+
"--dir-base",
67+
rebase_path("//tests/ten_runtime/integration/common"),
68+
"--recursive",
69+
"--only-output-file",
70+
],
71+
"json")
72+
73+
foreach(common_file, common_files) {
74+
common_file_rel_path = common_file.relative_path
75+
resources += [ "//tests/ten_runtime/integration/common/${common_file_rel_path}=>common/${common_file_rel_path}" ]
76+
}
77+
}
78+
79+
group("graph_env_var_4") {
80+
deps = [
81+
":graph_env_var_4_app",
82+
":graph_env_var_4_app_client",
83+
":graph_env_var_4_app_test_files",
84+
]
85+
}

tests/ten_runtime/integration/cpp/graph_env_var_4/__init__.py

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Copyright © 2025 Agora
3+
// This file is part of TEN Framework, an open source project.
4+
// Licensed under the Apache License, Version 2.0, with certain conditions.
5+
// Refer to the "LICENSE" file in the root directory for more information.
6+
//
7+
#include <nlohmann/json.hpp>
8+
9+
#include "tests/common/client/cpp/msgpack_tcp.h"
10+
11+
int main(int argc, char **argv) {
12+
// Create a client and connect to the app.
13+
auto *client = new ten::msgpack_tcp_client_t("msgpack://127.0.0.1:8001/");
14+
15+
// Send graph.
16+
auto start_graph_cmd = ten::cmd_start_graph_t::create();
17+
start_graph_cmd->set_graph_from_json(R"({
18+
"nodes": [{
19+
"type": "extension",
20+
"name": "test_extension",
21+
"addon": "default_extension_cpp",
22+
"app": "msgpack://127.0.0.1:8001/",
23+
"extension_group": "test_extension_group",
24+
"property": {
25+
"prop": "${abc}"
26+
}
27+
}]
28+
})");
29+
auto cmd_result =
30+
client->send_cmd_and_recv_result(std::move(start_graph_cmd));
31+
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
32+
"Should not happen.");
33+
34+
// Send a user-defined 'hello world' command.
35+
auto hello_world_cmd = ten::cmd_t::create("hello_world");
36+
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
37+
"test_extension_group", "test_extension");
38+
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
39+
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
40+
"Should not happen.");
41+
TEN_ASSERT(static_cast<std::string>("hello world, too") ==
42+
cmd_result->get_property_string("detail"),
43+
"Should not happen.");
44+
45+
delete client;
46+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"type": "app",
3+
"name": "default_app_cpp",
4+
"version": "0.8.18",
5+
"dependencies": [
6+
{
7+
"type": "system",
8+
"name": "ten_runtime",
9+
"version": "0.8.18"
10+
},
11+
{
12+
"type": "extension",
13+
"name": "default_extension_cpp",
14+
"version": "0.8.18"
15+
},
16+
{
17+
"type": "protocol",
18+
"name": "msgpack",
19+
"version": "0.8.18"
20+
}
21+
]
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"_ten": {
3+
"uri": "msgpack://127.0.0.1:8001/"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright © 2025 Agora
3+
# This file is part of TEN Framework, an open source project.
4+
# Licensed under the Apache License, Version 2.0, with certain conditions.
5+
# Refer to the "LICENSE" file in the root directory for more information.
6+
#
7+
import("//build/feature/ten_package.gni")
8+
9+
ten_package("default_extension_cpp") {
10+
package_kind = "extension"
11+
enable_build = true
12+
13+
resources = [
14+
"manifest.json",
15+
"property.json",
16+
]
17+
18+
sources = [ "src/main.cc" ]
19+
include_dirs = [ "//core/include" ]
20+
}

0 commit comments

Comments
 (0)