Skip to content

Commit

Permalink
chore: add more test cases for local dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Jan 6, 2025
1 parent b8cb884 commit db9a659
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/ten_manager/bin/tman",
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_manager/install/mock_app/mock_app",
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_manager/install_all/local_dependency_link_in_extension/test_app",
"args": [
"--config-file=${workspaceFolder}/out/linux/x64/tests/local_registry/config.json",
"install",
Expand Down
18 changes: 13 additions & 5 deletions core/src/ten_rust/src/pkg_info/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,27 @@ impl TryFrom<&ManifestDependency> for PkgDependency {

ManifestDependency::LocalDependency { path, base_dir } => {
// Check if there is a manifest.json file under the path.
let manifest_path = std::path::Path::new(base_dir)
.join(path)
.join(MANIFEST_JSON_FILENAME);
let dep_folder_path = std::path::Path::new(base_dir).join(path);

if !manifest_path.exists() {
if !dep_folder_path.exists() {
return Err(anyhow!(
"Local dependency path '{}' does not exist",
path
));
}

let dep_manifest_path =
dep_folder_path.join(MANIFEST_JSON_FILENAME);

if !dep_manifest_path.exists() {
return Err(anyhow!("Local dependency path '{}' does not contain manifest.json", path));
}

// Parse the `manifest.json` file to retrieve the `type`,
// `name`, and `version`.
let local_manifest =
crate::pkg_info::manifest::parse_manifest_from_file(
&manifest_path,
&dep_manifest_path,
)?;

Ok(PkgDependency {
Expand Down
1 change: 1 addition & 0 deletions tests/ten_manager/install_all/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ group("install_all") {
"install_locked_pkg_same_version",
"install_under_the_guidance_of_lock",
"local_dependency_link",
"local_dependency_link_in_extension",
"not_install_again_for_installed_extension",
"update_pkgs_that_local_pkgs_depend_on",
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# 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")

ten_package_test_prepare_auxiliary_resources(
"local_dependency_link_in_extension") {
resources = [
"//.gnfiles/build/scripts/cmd_exec.py=>common/cmd_exec.py",
"__init__.py",
"test_app",
"test_case.py",
]
deps = [
"//core/src/ten_manager",
"//tests/local_registry",
]
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "extension",
"name": "ext_c",
"version": "3.0.0",
"dependencies": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "app",
"name": "test_app",
"version": "1.0.0",
"dependencies": [
{
"type": "extension",
"name": "ext_1",
"version": "3.0.0"
},
{
"type": "extension",
"name": "local_d",
"version": "3.0.0"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "extension",
"name": "local_d",
"version": "3.0.0",
"dependencies": [
{
"path": "../../../local_c"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#
# 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 os
import sys
from .common import cmd_exec


def get_installed_extensions_count(app_dir: str):
extension_dir = os.path.join(app_dir, "ten_packages/extension/")
extensions = os.listdir(extension_dir)

return len(extensions)


def normalize_path(path):
if path.startswith("\\\\?\\"):
return path[4:]
return path


def test_tman_dependency_resolve():
base_path = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.join(base_path, "../../../../")

if sys.platform == "win32":
os.environ["PATH"] = (
os.path.join(root_dir, "ten_manager/lib") + ";" + os.getenv("PATH")
)
tman_bin = os.path.join(root_dir, "ten_manager/bin/tman.exe")
else:
tman_bin = os.path.join(root_dir, "ten_manager/bin/tman")

app_dir = os.path.join(base_path, "test_app")

config_file = os.path.join(
root_dir,
"tests/local_registry/config.json",
)

returncode, output_text = cmd_exec.run_cmd_realtime(
[
tman_bin,
f"--config-file={config_file}",
"install",
],
cwd=app_dir,
)
if returncode != 0:
print(output_text)
assert False

installed_count = get_installed_extensions_count(app_dir)
assert (
installed_count == 3
), f"Expected 2 extensions, found {installed_count}."

ext_c_path = os.path.join(app_dir, "ten_packages/extension/ext_c")
local_c_path = os.path.join(app_dir, "local_c")

# Check if `ext_c_path` exists.
assert os.path.exists(
ext_c_path
), f"Expected ext_c path '{ext_c_path}' does not exist."

# Check if `ext_c_path` is a symbolic link.
is_symlink = os.path.islink(ext_c_path)
assert is_symlink, f"Expected '{ext_c_path}' to be a symbolic link."

# Retrieve the target path of the symbolic link.
try:
symlink_target = os.readlink(ext_c_path)
except OSError as e:
assert False, f"Failed to read symbolic link '{ext_c_path}': {e}"

# If `symlink_target` is a relative path, it needs to be converted to an
# absolute path.
if not os.path.isabs(symlink_target):
symlink_target = os.path.normpath(
os.path.join(os.path.dirname(ext_c_path), symlink_target)
)

# Normalize the path to eliminate any redundancies (e.g., `./`).
symlink_target = os.path.normpath(symlink_target)
expected_target = os.path.normpath(local_c_path)

# On Windows, `os.readlink` may return paths with backslashes, so it's
# necessary to standardize the path separators.
symlink_target = os.path.abspath(symlink_target)
expected_target = os.path.abspath(expected_target)

# Normalize paths by removing '\\?\' prefix if present
symlink_target = normalize_path(symlink_target)
expected_target = normalize_path(expected_target)

assert symlink_target == expected_target, (
f"Symbolic link target mismatch for '{ext_c_path}'. "
f"Expected: '{expected_target}', Found: '{symlink_target}'."
)

print(
f"Symbolic link '{ext_c_path}' correctly points to '{symlink_target}'."
)


if __name__ == "__main__":
test_tman_dependency_resolve()

0 comments on commit db9a659

Please sign in to comment.