Skip to content

Commit d8709b6

Browse files
authored
refactor: remove additionalProperties from JSON schemas and update integration tests (#783)
1 parent 2d5309f commit d8709b6

File tree

15 files changed

+546
-10
lines changed

15 files changed

+546
-10
lines changed

core/src/ten_rust/src/json_schema/data/manifest.schema.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@
473473
"name",
474474
"version"
475475
],
476-
"additionalProperties": false,
477476
"if": {
478477
"anyOf": [
479478
{

core/src/ten_rust/src/json_schema/data/property.schema.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@
499499
},
500500
"tenConfiguration": {
501501
"type": "object",
502-
"additionalProperties": false,
503502
"properties": {
504503
"uri": {
505504
"$ref": "#/$defs/non_empty_non_localhost_uri"

tests/ten_runtime/integration/cpp/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ group("cpp") {
1515
"hello_world",
1616
"large_result",
1717
"long_running",
18+
"metadata_additional_field",
1819
"restful",
1920
]
2021

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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("metadata_additional_field_app") {
11+
src_app = "default_app_cpp"
12+
src_app_language = "cpp"
13+
generated_app_src_root_dir_name = "metadata_additional_field_app"
14+
15+
replace_paths_after_install_app = [
16+
"metadata_additional_field_app/manifest.json",
17+
"metadata_additional_field_app/property.json",
18+
]
19+
20+
replace_paths_after_install_all = [
21+
"metadata_additional_field_app/ten_packages/extension/default_extension_cpp/manifest.json",
22+
"metadata_additional_field_app/ten_packages/extension/default_extension_cpp/property.json",
23+
"metadata_additional_field_app/ten_packages/extension/default_extension_cpp/src/main.cc",
24+
"metadata_additional_field_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("metadata_additional_field_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(
56+
"metadata_additional_field_app_test_files") {
57+
resources = [
58+
"__init__.py",
59+
"test_case.py",
60+
]
61+
62+
utils_files = exec_script("//.gnfiles/build/scripts/glob_file.py",
63+
[
64+
"--dir",
65+
rebase_path("//tests/utils/**/*"),
66+
"--dir-base",
67+
rebase_path("//tests/utils"),
68+
"--recursive",
69+
"--only-output-file",
70+
],
71+
"json")
72+
73+
foreach(utils_file, utils_files) {
74+
utils_file_rel_path = utils_file.relative_path
75+
resources +=
76+
[ "//tests/utils/${utils_file_rel_path}=>utils/${utils_file_rel_path}" ]
77+
}
78+
}
79+
80+
group("metadata_additional_field") {
81+
deps = [
82+
":metadata_additional_field_app",
83+
":metadata_additional_field_app_client",
84+
":metadata_additional_field_app_test_files",
85+
]
86+
}

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

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}]
25+
})");
26+
auto cmd_result =
27+
client->send_cmd_and_recv_result(std::move(start_graph_cmd));
28+
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
29+
"Should not happen.");
30+
31+
// Send a user-defined 'hello world' command.
32+
auto hello_world_cmd = ten::cmd_t::create("hello_world");
33+
hello_world_cmd->set_dest("msgpack://127.0.0.1:8001/", nullptr,
34+
"test_extension");
35+
cmd_result = client->send_cmd_and_recv_result(std::move(hello_world_cmd));
36+
TEN_ASSERT(TEN_STATUS_CODE_OK == cmd_result->get_status_code(),
37+
"Should not happen.");
38+
TEN_ASSERT(static_cast<std::string>("hello world, too") ==
39+
cmd_result->get_property_string("detail"),
40+
"Should not happen.");
41+
42+
delete client;
43+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"type": "app",
3+
"name": "default_app_cpp",
4+
"version": "0.10.2",
5+
"dependencies": [
6+
{
7+
"type": "system",
8+
"name": "ten_runtime",
9+
"version": "0.10.2"
10+
},
11+
{
12+
"type": "extension",
13+
"name": "default_extension_cpp",
14+
"version": "0.10.2"
15+
},
16+
{
17+
"type": "protocol",
18+
"name": "msgpack",
19+
"version": "0.10.2"
20+
}
21+
],
22+
"api": {
23+
"property": {
24+
"hello": {
25+
"type": "string"
26+
}
27+
}
28+
}
29+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"ten": {
3+
"uri": "msgpack://127.0.0.1:8001/",
4+
"predefined_graphs": [
5+
{
6+
"name": "default",
7+
"auto_start": false,
8+
"nodes": [
9+
{
10+
"type": "extension",
11+
"name": "default_extension_cpp",
12+
"addon": "default_extension_cpp",
13+
"extension_group": "default_extension_group"
14+
}
15+
]
16+
}
17+
]
18+
},
19+
"hello": "world"
20+
}
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"type": "extension",
3+
"name": "default_extension_cpp",
4+
"version": "0.10.2",
5+
"dependencies": [
6+
{
7+
"type": "system",
8+
"name": "ten_runtime",
9+
"version": "0.10.2"
10+
}
11+
],
12+
"package": {
13+
"include": [
14+
"**"
15+
]
16+
},
17+
"api": {
18+
"cmd_in": [
19+
{
20+
"name": "hello_world"
21+
}
22+
],
23+
"cmd_out": [],
24+
"data_in": [],
25+
"data_out": [],
26+
"video_frame_in": [],
27+
"video_frame_out": [],
28+
"audio_frame_in": [],
29+
"audio_frame_out": []
30+
},
31+
"unknown_field": "unknown_value"
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"hello": "world",
3+
"ten": {
4+
"unknown_field": "unknown_value"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 <cassert>
8+
#include <cstdlib>
9+
10+
#include "ten_runtime/binding/cpp/ten.h"
11+
12+
class test_extension : public ten::extension_t {
13+
public:
14+
explicit test_extension(const char *name) : ten::extension_t(name) {}
15+
16+
void on_init(ten::ten_env_t &ten_env) override { ten_env.on_init_done(); }
17+
18+
void on_start(ten::ten_env_t &ten_env) override {
19+
// The property.json will be loaded by default during `on_init` phase, so
20+
// the property `hello` should be available here.
21+
auto prop = ten_env.get_property_string("hello");
22+
if (prop != "world") {
23+
assert(0 && "Should not happen.");
24+
}
25+
26+
ten_env.on_start_done();
27+
}
28+
29+
void on_cmd(ten::ten_env_t &ten_env,
30+
std::unique_ptr<ten::cmd_t> cmd) override {
31+
if (cmd->get_name() == "hello_world") {
32+
auto cmd_result = ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *cmd);
33+
cmd_result->set_property("detail", "hello world, too");
34+
ten_env.return_result(std::move(cmd_result));
35+
}
36+
}
37+
};
38+
39+
TEN_CPP_REGISTER_ADDON_AS_EXTENSION(default_extension_cpp, test_extension);

0 commit comments

Comments
 (0)