licos-platform-cli 0.6.6__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- licos_platform_cli-0.6.6/README.md → licos_platform_cli-0.8.0/PKG-INFO +13 -1
- licos_platform_cli-0.6.6/PKG-INFO → licos_platform_cli-0.8.0/README.md +5 -9
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/pyproject.toml +2 -2
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/help_commands.py +5 -1
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/ontology_commands.py +2 -0
- licos_platform_cli-0.8.0/src/licos_platform_cli/ontology_package_commands.py +147 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/tests/test_cli.py +1 -1
- licos_platform_cli-0.8.0/tests/test_ontology_packages.py +65 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/.gitignore +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/__init__.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/database_commands.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/identity.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/knowledge_commands.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/main.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/oauth_commands.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/project_config_commands.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/storage_commands.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/user_commands.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/tests/test_identity.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/tests/test_project_config.py +0 -0
- {licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/tests/test_user.py +0 -0
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: licos-platform-cli
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: LICOS platform CLI
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: licos-platform-sdk>=0.9.0
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
1
9
|
# licos-platform-cli
|
|
2
10
|
|
|
3
11
|
LICOS 平台命令行工具。`licos-platform help` 返回结构化 JSON 帮助。
|
|
@@ -34,7 +42,7 @@ licos-platform user me --token-stdin
|
|
|
34
42
|
| --- | --- | --- |
|
|
35
43
|
| `user me` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
|
|
36
44
|
| `knowledge enterprise …` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin`,企业范围和权限由平台认证结果确定 |
|
|
37
|
-
| `ontology
|
|
45
|
+
| 所有 `ontology` 命令 | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
|
|
38
46
|
| 普通 `knowledge …` | 项目身份 | 需要用户权限时使用 `--token-stdin` |
|
|
39
47
|
| 数据库、对象存储、OAuth 应用管理 | 项目身份 | 保持项目身份 |
|
|
40
48
|
|
|
@@ -57,6 +65,10 @@ result = subprocess.run(
|
|
|
57
65
|
|
|
58
66
|
显式传入的 Token 鉴权失败时返回非零退出码,由调用方更新登录凭证,不切换到容器用户或项目所有者。项目所有者和工作空间等资源归属字段单独保留,不用它们冒充调用用户。
|
|
59
67
|
|
|
68
|
+
## 本体正式版本
|
|
69
|
+
|
|
70
|
+
0.8.0 起,`ontology package/bind --root-object-id <id>` 自动选择最新正式版;使用显式 release_id 固定版本。`ontology resolve --configuration-file ontology.json` 解析 `{versionPolicy, rootObjectId, binding}`,省略策略保持固定版本。新运行开始解析并保存输出绑定,query/function 及恢复执行复用它,不在每次查询时重新解析。新版缺少已选对象、属性或函数时直接失败。
|
|
71
|
+
|
|
60
72
|
## 编程项目登录身份
|
|
61
73
|
|
|
62
74
|
- 有内置登录时使用内置登录会话;没有内置登录时使用当前 LICOS 网页登录。内置登录未登录或过期时不能切换成平台用户。
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: licos-platform-cli
|
|
3
|
-
Version: 0.6.6
|
|
4
|
-
Summary: LICOS platform CLI
|
|
5
|
-
Requires-Python: >=3.10
|
|
6
|
-
Requires-Dist: licos-platform-sdk>=0.7.6
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
|
|
9
1
|
# licos-platform-cli
|
|
10
2
|
|
|
11
3
|
LICOS 平台命令行工具。`licos-platform help` 返回结构化 JSON 帮助。
|
|
@@ -42,7 +34,7 @@ licos-platform user me --token-stdin
|
|
|
42
34
|
| --- | --- | --- |
|
|
43
35
|
| `user me` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
|
|
44
36
|
| `knowledge enterprise …` | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin`,企业范围和权限由平台认证结果确定 |
|
|
45
|
-
| `ontology
|
|
37
|
+
| 所有 `ontology` 命令 | 按 `LICOS_CURRENT_USER_ID` 换 Token | 使用 `--token-stdin` |
|
|
46
38
|
| 普通 `knowledge …` | 项目身份 | 需要用户权限时使用 `--token-stdin` |
|
|
47
39
|
| 数据库、对象存储、OAuth 应用管理 | 项目身份 | 保持项目身份 |
|
|
48
40
|
|
|
@@ -65,6 +57,10 @@ result = subprocess.run(
|
|
|
65
57
|
|
|
66
58
|
显式传入的 Token 鉴权失败时返回非零退出码,由调用方更新登录凭证,不切换到容器用户或项目所有者。项目所有者和工作空间等资源归属字段单独保留,不用它们冒充调用用户。
|
|
67
59
|
|
|
60
|
+
## 本体正式版本
|
|
61
|
+
|
|
62
|
+
0.8.0 起,`ontology package/bind --root-object-id <id>` 自动选择最新正式版;使用显式 release_id 固定版本。`ontology resolve --configuration-file ontology.json` 解析 `{versionPolicy, rootObjectId, binding}`,省略策略保持固定版本。新运行开始解析并保存输出绑定,query/function 及恢复执行复用它,不在每次查询时重新解析。新版缺少已选对象、属性或函数时直接失败。
|
|
63
|
+
|
|
68
64
|
## 编程项目登录身份
|
|
69
65
|
|
|
70
66
|
- 有内置登录时使用内置登录会话;没有内置登录时使用当前 LICOS 网页登录。内置登录未登录或过期时不能切换成平台用户。
|
|
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "licos-platform-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.8.0"
|
|
8
8
|
description = "LICOS platform CLI"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"licos-platform-sdk>=0.
|
|
12
|
+
"licos-platform-sdk>=0.9.0",
|
|
13
13
|
]
|
|
14
14
|
|
|
15
15
|
[project.scripts]
|
{licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/help_commands.py
RENAMED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import argparse
|
|
4
4
|
from typing import Any, Callable
|
|
5
5
|
from .user_commands import USER_HELP
|
|
6
|
+
from .ontology_package_commands import PACKAGE_HELP
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
Handler = Callable[[argparse.Namespace], Any]
|
|
@@ -797,7 +798,8 @@ ONTOLOGY_HELP = {
|
|
|
797
798
|
"Search the catalog before invoking a tool; the catalog is filtered by the current user's permissions.",
|
|
798
799
|
"Resolve elements by stable IDs before querying context, model checks, or mapped data.",
|
|
799
800
|
"elementId/objectElementId 是部署实例 ID;objectTypeId 从实例上下文读取,是对象模板 ID。",
|
|
800
|
-
"
|
|
801
|
+
"函数使用目录中的 apiName 和 version,input 满足 inputSchema;objects 传对象导入描述,每组需明确部署实例。动作仍使用列表 id 作为 actionTypeId。",
|
|
802
|
+
"正式应用默认用 ontology package/bind --root-object-id 选择最新正式版;显式 release_id 固定版本。ontology resolve 在新运行开始解析配置,保存绑定供整轮及恢复复用。函数版本仍显式固定,不能调用 CURRENT 或包外函数。",
|
|
801
803
|
"动作预览明确传入 objectElementId 和真实 objectKey;用户确认后用同一草稿的 confirmationId 执行。实例参数必须已在当前工具 schema 中声明,缺失时报告上游目录问题。",
|
|
802
804
|
"READ tools query state, PREPARE tools validate a change draft, and PERSIST tools apply an explicitly confirmed draft.",
|
|
803
805
|
"PERSIST commands require --confirm. Never reuse a catalog result after its catalogVersion changes.",
|
|
@@ -844,6 +846,8 @@ ONTOLOGY_HELP = {
|
|
|
844
846
|
}
|
|
845
847
|
|
|
846
848
|
|
|
849
|
+
ONTOLOGY_HELP["commands"].update(PACKAGE_HELP)
|
|
850
|
+
|
|
847
851
|
HELP_TOPICS = {
|
|
848
852
|
"user": USER_HELP,
|
|
849
853
|
"storage": STORAGE_HELP,
|
{licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/ontology_commands.py
RENAMED
|
@@ -7,6 +7,7 @@ from typing import Any, Callable
|
|
|
7
7
|
|
|
8
8
|
from licos_platform_sdk import ontology
|
|
9
9
|
from .identity import add_user_token_option, user_token
|
|
10
|
+
from .ontology_package_commands import add_package_commands
|
|
10
11
|
|
|
11
12
|
Handler = Callable[[argparse.Namespace], Any]
|
|
12
13
|
|
|
@@ -60,6 +61,7 @@ def add_ontology_parser(
|
|
|
60
61
|
help="Discover and invoke authorized ontology and Data Factory AI tools",
|
|
61
62
|
)
|
|
62
63
|
commands = parser.add_subparsers(dest="ontology_command", required=True)
|
|
64
|
+
add_package_commands(commands)
|
|
63
65
|
|
|
64
66
|
search = commands.add_parser("search", help="Search the authorized AI tool catalog")
|
|
65
67
|
search.add_argument("query")
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
from copy import deepcopy
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from licos_platform_sdk import ontology
|
|
10
|
+
from .identity import add_user_token_option, user_token
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
PACKAGE_HELP = {
|
|
14
|
+
"resolve": {"description": "Resolve a latestPublished/pinned selection once at run start. Persist the returned binding for all queries and resume.",
|
|
15
|
+
"parameters": [{"name": "--configuration-file", "required": True, "description": "JSON containing binding, versionPolicy and rootObjectId."}],
|
|
16
|
+
"example": "licos-platform ontology resolve --configuration-file ontology.json"},
|
|
17
|
+
"releases": {"description": "List visible published releases using the current execution identity.", "parameters": [],
|
|
18
|
+
"example": "licos-platform ontology releases"},
|
|
19
|
+
"package": {"description": "Inspect semantic metadata of a specific release; excludes physical mappings and implementation DSL.",
|
|
20
|
+
"parameters": [{"name": "release_id", "required": False, "description": "Pinned release; mutually exclusive with --root-object-id."},
|
|
21
|
+
{"name": "--root-object-id", "required": False, "description": "Inspect the latest formally published release of this ontology root."}],
|
|
22
|
+
"example": "licos-platform ontology package <release_id>"},
|
|
23
|
+
"bind": {"description": "Create a binding JSON for a published release; save the output in trusted application configuration.",
|
|
24
|
+
"parameters": [{"name": "release_id", "required": False, "description": "Pinned release; mutually exclusive with --root-object-id."},
|
|
25
|
+
{"name": "--root-object-id", "required": False, "description": "Resolve latest formally published model once for this run."},
|
|
26
|
+
{"name": "--objects-file", "required": True, "description": "JSON array of elementId and attributeIds selections."},
|
|
27
|
+
{"name": "--functions-file", "required": False, "description": "JSON array of apiName/version selections. Omitted selects no functions."}],
|
|
28
|
+
"example": "licos-platform ontology bind <release_id> --objects-file objects.json --functions-file functions.json"},
|
|
29
|
+
"validate": {"description": "Re-read the published artifact and validate binding identity, hash metadata and selected scope.",
|
|
30
|
+
"parameters": [{"name": "--binding-file", "required": True, "description": "Trusted binding JSON file."}],
|
|
31
|
+
"example": "licos-platform ontology validate --binding-file binding.json"},
|
|
32
|
+
"query": {"description": "Query bound business records; preserve primary keys and pagination metadata.",
|
|
33
|
+
"parameters": [{"name": "--binding-file", "required": True, "description": "Binding JSON file."},
|
|
34
|
+
{"name": "--element-id", "required": True, "description": "Deployment ID in the binding."},
|
|
35
|
+
{"name": "--query-file", "required": True, "description": "JSON with attributeIds and explicit pagination; optional conditionGroup/sorts/includeTotalCount."}],
|
|
36
|
+
"example": "licos-platform ontology query --binding-file binding.json --element-id <id> --query-file query.json"},
|
|
37
|
+
"function": {"description": "Invoke an explicitly selected published function through its package runtime; no automatic latest-version fallback.",
|
|
38
|
+
"parameters": [{"name": "--binding-file", "required": True, "description": "Binding JSON file."},
|
|
39
|
+
{"name": "--api-name", "required": True, "description": "Bound function API name."},
|
|
40
|
+
{"name": "--version", "required": True, "description": "Function version, distinct from package version."},
|
|
41
|
+
{"name": "--input-file", "required": True, "description": "Business input JSON satisfying inputSchema."},
|
|
42
|
+
{"name": "--objects-file", "required": False, "description": "JSON import descriptors alias/objectTypeId/objectElementId; at most 8 groups."}],
|
|
43
|
+
"example": "licos-platform ontology function --binding-file binding.json --api-name <name> --version <function_version> --input-file input.json"},
|
|
44
|
+
"diff": {"description": "Compare semantic object, attribute and function changes between two releases.",
|
|
45
|
+
"parameters": [{"name": "before", "required": True, "description": "Previous release ID."},
|
|
46
|
+
{"name": "after", "required": True, "description": "Proposed release ID."}],
|
|
47
|
+
"example": "licos-platform ontology diff <before_release_id> <after_release_id>"},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _file(path: str) -> Any:
|
|
52
|
+
try:
|
|
53
|
+
return json.loads(Path(path).read_text(encoding="utf-8"))
|
|
54
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
55
|
+
raise argparse.ArgumentTypeError(f"cannot read ontology JSON file: {exc}") from exc
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _diff(before: Any, after: Any, path: str = "") -> list[dict[str, Any]]:
|
|
59
|
+
if before == after:
|
|
60
|
+
return []
|
|
61
|
+
if isinstance(before, dict) and isinstance(after, dict):
|
|
62
|
+
changes = []
|
|
63
|
+
for key in sorted(before.keys() | after.keys()):
|
|
64
|
+
location = f"{path}/{key}"
|
|
65
|
+
if key not in before:
|
|
66
|
+
changes.append({"path": location, "change": "added", "after": after[key]})
|
|
67
|
+
elif key not in after:
|
|
68
|
+
changes.append({"path": location, "change": "removed", "before": before[key]})
|
|
69
|
+
else:
|
|
70
|
+
changes.extend(_diff(before[key], after[key], location))
|
|
71
|
+
return changes
|
|
72
|
+
return [{"path": path, "change": "changed", "before": before, "after": after}]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _indexed(context: dict[str, Any]) -> dict[str, Any]:
|
|
76
|
+
result = deepcopy(context)
|
|
77
|
+
for key in ("types", "instances", "relations"):
|
|
78
|
+
result[key] = {item["id"]: item for item in result[key]}
|
|
79
|
+
result["functions"] = {f"{item['apiName']}@{item.get('functionVersion', 'historical')}": item for item in result["functions"]}
|
|
80
|
+
for instance in result["instances"].values():
|
|
81
|
+
instance["attributes"] = {item["id"]: item for item in instance["attributes"]}
|
|
82
|
+
return result
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _run(args: argparse.Namespace) -> Any:
|
|
86
|
+
token = user_token(args)
|
|
87
|
+
operation = args.ontology_command
|
|
88
|
+
if operation == "releases":
|
|
89
|
+
return ontology.list_releases(user_token=token)
|
|
90
|
+
if operation == "package":
|
|
91
|
+
return (ontology.get_latest_package(args.root_object_id, user_token=token) if args.root_object_id
|
|
92
|
+
else ontology.get_package(args.release_id, user_token=token))
|
|
93
|
+
if operation == "bind":
|
|
94
|
+
bind = ontology.create_latest_binding if args.root_object_id else ontology.create_binding
|
|
95
|
+
return bind(args.root_object_id or args.release_id, _file(args.objects_file),
|
|
96
|
+
_file(args.functions_file) if args.functions_file else [], user_token=token)
|
|
97
|
+
if operation == "resolve":
|
|
98
|
+
return ontology.resolve_binding(_file(args.configuration_file), user_token=token)
|
|
99
|
+
if operation == "diff":
|
|
100
|
+
before = ontology.get_package(args.before, user_token=token)
|
|
101
|
+
after = ontology.get_package(args.after, user_token=token)
|
|
102
|
+
return {"before": before["package"], "after": after["package"], "changes": _diff(_indexed(before), _indexed(after))}
|
|
103
|
+
binding = _file(args.binding_file)
|
|
104
|
+
if operation == "validate":
|
|
105
|
+
return ontology.validate_binding(binding, user_token=token)
|
|
106
|
+
if operation == "query":
|
|
107
|
+
return ontology.query_package_objects(binding, args.element_id, _file(args.query_file), user_token=token)
|
|
108
|
+
return ontology.invoke_package_function(binding, args.api_name, args.version, _file(args.input_file), user_token=token,
|
|
109
|
+
objects=_file(args.objects_file) if args.objects_file else [])
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def add_package_commands(commands: argparse._SubParsersAction) -> None:
|
|
113
|
+
for name, description in (
|
|
114
|
+
("releases", "List visible published ontology releases"),
|
|
115
|
+
("package", "Inspect semantic metadata of one release"),
|
|
116
|
+
("bind", "Create an explicit release and capability binding"),
|
|
117
|
+
("resolve", "Resolve a saved version policy once at run start"),
|
|
118
|
+
("validate", "Verify a binding against its published artifact"),
|
|
119
|
+
("query", "Query business objects within a binding"),
|
|
120
|
+
("function", "Invoke a versioned read-only function within a binding"),
|
|
121
|
+
("diff", "Compare semantic metadata of two releases"),
|
|
122
|
+
):
|
|
123
|
+
parser = commands.add_parser(name, help=description)
|
|
124
|
+
add_user_token_option(parser)
|
|
125
|
+
parser.set_defaults(handler=_run)
|
|
126
|
+
if name in {"package", "bind"}:
|
|
127
|
+
selection = parser.add_mutually_exclusive_group(required=True)
|
|
128
|
+
selection.add_argument("release_id", nargs="?")
|
|
129
|
+
selection.add_argument("--root-object-id", help="Use the latest formally published release of this stable ontology root")
|
|
130
|
+
if name == "resolve":
|
|
131
|
+
parser.add_argument("--configuration-file", required=True)
|
|
132
|
+
if name in {"validate", "query", "function"}:
|
|
133
|
+
parser.add_argument("--binding-file", required=True)
|
|
134
|
+
if name == "bind":
|
|
135
|
+
parser.add_argument("--objects-file", required=True, help="JSON array of elementId/attributeIds selections")
|
|
136
|
+
parser.add_argument("--functions-file", help="JSON array of apiName/version selections; omitted selects no functions")
|
|
137
|
+
if name == "query":
|
|
138
|
+
parser.add_argument("--element-id", required=True)
|
|
139
|
+
parser.add_argument("--query-file", required=True)
|
|
140
|
+
if name == "function":
|
|
141
|
+
parser.add_argument("--api-name", required=True)
|
|
142
|
+
parser.add_argument("--version", required=True)
|
|
143
|
+
parser.add_argument("--input-file", required=True)
|
|
144
|
+
parser.add_argument("--objects-file")
|
|
145
|
+
if name == "diff":
|
|
146
|
+
parser.add_argument("before")
|
|
147
|
+
parser.add_argument("after")
|
|
@@ -136,7 +136,7 @@ class PlatformCliTests(unittest.TestCase):
|
|
|
136
136
|
self.assertEqual(stderr, "")
|
|
137
137
|
payload = json.loads(stdout)
|
|
138
138
|
self.assertEqual(payload["topic"], "ontology")
|
|
139
|
-
self.assertEqual(set(payload["commands"]), {"search", "invoke"})
|
|
139
|
+
self.assertEqual(set(payload["commands"]), {"search", "invoke", "releases", "package", "bind", "validate", "query", "function", "diff"})
|
|
140
140
|
self.assertTrue(any("catalogVersion" in rule for rule in payload["rules"]))
|
|
141
141
|
sdk_help = "\n".join(payload["sdk"].values())
|
|
142
142
|
self.assertNotIn("items[0]", sdk_help)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
import unittest
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from unittest.mock import patch
|
|
10
|
+
|
|
11
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "licos-platform-sdk" / "src"))
|
|
12
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
13
|
+
from licos_platform_cli.ontology_package_commands import _indexed, _diff
|
|
14
|
+
from test_cli import run_cli
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class OntologyPackageCliTests(unittest.TestCase):
|
|
18
|
+
def test_package_commands_have_structured_help(self):
|
|
19
|
+
for command in ("releases", "package", "bind", "resolve", "validate", "query", "function", "diff"):
|
|
20
|
+
code, output, error = run_cli("help", "ontology", command)
|
|
21
|
+
self.assertEqual((code, error), (0, ""))
|
|
22
|
+
self.assertIn("parameters", json.loads(output))
|
|
23
|
+
|
|
24
|
+
def setUp(self):
|
|
25
|
+
identity = patch.dict(os.environ, {"LICOS_CURRENT_USER_ID": "caller"})
|
|
26
|
+
identity.start()
|
|
27
|
+
self.addCleanup(identity.stop)
|
|
28
|
+
|
|
29
|
+
@patch("licos_platform_cli.identity.runtime_user_token", return_value="caller-token")
|
|
30
|
+
@patch("licos_platform_cli.ontology_package_commands.ontology.get_latest_package", return_value={"version": "V2"})
|
|
31
|
+
def test_latest_package_selects_by_root_and_rejects_ambiguous_input(self, latest, _identity):
|
|
32
|
+
code, _, error = run_cli("ontology", "package", "--root-object-id", "root-1")
|
|
33
|
+
self.assertEqual((code, error), (0, ""))
|
|
34
|
+
latest.assert_called_once_with("root-1", user_token="caller-token")
|
|
35
|
+
code, _, _ = run_cli("ontology", "package", "release-1", "--root-object-id", "root-1")
|
|
36
|
+
self.assertNotEqual(code, 0)
|
|
37
|
+
|
|
38
|
+
@patch("licos_platform_cli.identity.runtime_user_token", return_value="caller-token")
|
|
39
|
+
@patch("licos_platform_cli.ontology_package_commands.ontology.list_releases", return_value=[])
|
|
40
|
+
def test_releases_forwards_runtime_identity(self, releases, _identity):
|
|
41
|
+
code, output, error = run_cli("ontology", "releases")
|
|
42
|
+
self.assertEqual((code, error), (0, ""))
|
|
43
|
+
releases.assert_called_once_with(user_token="caller-token")
|
|
44
|
+
|
|
45
|
+
@patch("licos_platform_cli.identity.runtime_user_token", return_value="caller-token")
|
|
46
|
+
@patch("licos_platform_cli.ontology_package_commands.ontology.invoke_package_function", return_value={"result": 42})
|
|
47
|
+
def test_function_preserves_binding_version_and_structured_input(self, invoke, _identity):
|
|
48
|
+
with tempfile.TemporaryDirectory() as root:
|
|
49
|
+
binding, inputs = Path(root)/"binding.json", Path(root)/"input.json"
|
|
50
|
+
binding.write_text(json.dumps({"releaseId": "release-1"}), encoding="utf-8")
|
|
51
|
+
inputs.write_text(json.dumps({"value": 3}), encoding="utf-8")
|
|
52
|
+
code, _, error = run_cli("ontology", "function", "--binding-file", str(binding),
|
|
53
|
+
"--api-name", "readStatus", "--version", "1.0.1", "--input-file", str(inputs))
|
|
54
|
+
self.assertEqual((code, error), (0, ""))
|
|
55
|
+
invoke.assert_called_once_with({"releaseId": "release-1"}, "readStatus", "1.0.1", {"value": 3}, user_token="caller-token", objects=[])
|
|
56
|
+
|
|
57
|
+
def test_diff_preserves_multiple_versions_and_does_not_mutate_input(self):
|
|
58
|
+
context = {"types": [], "relations": [], "instances": [{"id": "pump", "attributes": [{"id": "pressure"}]}],
|
|
59
|
+
"functions": [{"apiName": "read", "functionVersion": "1"}, {"apiName": "read", "functionVersion": "2"}]}
|
|
60
|
+
indexed = _indexed(context)
|
|
61
|
+
self.assertEqual(len(indexed["functions"]), 2)
|
|
62
|
+
self.assertIsInstance(context["instances"][0]["attributes"], list)
|
|
63
|
+
updated = json.loads(json.dumps(indexed))
|
|
64
|
+
updated["instances"]["pump"]["attributes"]["pressure"]["valueType"] = "Double"
|
|
65
|
+
self.assertEqual(_diff(indexed, updated)[0]["path"], "/instances/pump/attributes/pressure/valueType")
|
|
File without changes
|
|
File without changes
|
{licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/database_commands.py
RENAMED
|
File without changes
|
|
File without changes
|
{licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/knowledge_commands.py
RENAMED
|
File without changes
|
|
File without changes
|
{licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/oauth_commands.py
RENAMED
|
File without changes
|
|
File without changes
|
{licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/storage_commands.py
RENAMED
|
File without changes
|
{licos_platform_cli-0.6.6 → licos_platform_cli-0.8.0}/src/licos_platform_cli/user_commands.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|