licos-platform-cli 0.8.10__tar.gz → 0.8.11__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.
Files changed (25) hide show
  1. licos_platform_cli-0.8.10/README.md → licos_platform_cli-0.8.11/PKG-INFO +24 -0
  2. licos_platform_cli-0.8.10/PKG-INFO → licos_platform_cli-0.8.11/README.md +16 -8
  3. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/pyproject.toml +2 -2
  4. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/help_commands.py +16 -2
  5. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/knowledge_commands.py +36 -1
  6. licos_platform_cli-0.8.11/tests/test_knowledge_download.py +165 -0
  7. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/.gitignore +0 -0
  8. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/__init__.py +0 -0
  9. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/database_commands.py +0 -0
  10. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/enterprise_project_commands.py +0 -0
  11. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/enterprise_project_help.py +0 -0
  12. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/identity.py +0 -0
  13. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/main.py +0 -0
  14. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/oauth_commands.py +0 -0
  15. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/ontology_commands.py +0 -0
  16. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/ontology_package_commands.py +0 -0
  17. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/project_config_commands.py +0 -0
  18. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/storage_commands.py +0 -0
  19. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/src/licos_platform_cli/user_commands.py +0 -0
  20. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/tests/test_cli.py +0 -0
  21. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/tests/test_enterprise_projects.py +0 -0
  22. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/tests/test_identity.py +0 -0
  23. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/tests/test_ontology_packages.py +0 -0
  24. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/tests/test_project_config.py +0 -0
  25. {licos_platform_cli-0.8.10 → licos_platform_cli-0.8.11}/tests/test_user.py +0 -0
@@ -1,7 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: licos-platform-cli
3
+ Version: 0.8.11
4
+ Summary: LICOS platform CLI
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: licos-platform-sdk>=0.9.10
7
+ Description-Content-Type: text/markdown
8
+
1
9
  # licos-platform-cli
2
10
 
3
11
  LICOS 平台命令行工具。`licos-platform help` 返回结构化 JSON 帮助。
4
12
 
13
+ ## 企业知识库原文件下载
14
+
15
+ 此命令从 `licos-platform-cli==0.8.11` 起提供,需要 `licos-platform-sdk>=0.9.10`。
16
+
17
+ ```bash
18
+ licos-platform help knowledge enterprise-document-download
19
+ licos-platform knowledge enterprise document-download DOCUMENT_ID --out "attachments/会议纪要.docx"
20
+ licos-platform knowledge enterprise document-download LEGACY_DOCUMENT_ID --api-version legacy --out "attachments/旧版原文件.docx"
21
+ ```
22
+
23
+ 命令复用 Platform SDK 的 `enterprise_knowledge.download_document`,默认使用新版文档 ID,旧接口 ID 显式指定 `--api-version legacy`。只传真实文档 ID 和保存路径,程序内部取得并直接使用原始签名链接,输出 `document_id/path/size_bytes/sha256`,不输出票据。
24
+
25
+ `--out` 相对路径按当前进程工作目录解析,沿用业务进程和沙箱写入权限,不改变已有任务目录。自动创建父目录,已有文件、目录或链接均不覆盖,下载失败不留下半份文件。`--timeout` 是每次网络操作超时,默认 120 秒;`--max-bytes` 默认 1073741824(1 GiB)。下载请求不携带平台凭据,不跟随重定向,可信内网 HTTP 入口由平台校验。
26
+
27
+ 身份规则与其他企业知识库命令相同。网页项目替用户执行时加 `--token-stdin`,将本次请求用户 Token 写入子进程标准输入;不通过命令行参数或共享环境变量传 Token。权限、下载、覆盖冲突和本地文件错误均返回非零退出码。原 `document-url`、`document-download-link` 命令继续可用。
28
+
5
29
  ## 企业项目(0.8.1 起)
6
30
 
7
31
  ```bash
@@ -1,15 +1,23 @@
1
- Metadata-Version: 2.5
2
- Name: licos-platform-cli
3
- Version: 0.8.10
4
- Summary: LICOS platform CLI
5
- Requires-Python: >=3.10
6
- Requires-Dist: licos-platform-sdk>=0.9.9
7
- Description-Content-Type: text/markdown
8
-
9
1
  # licos-platform-cli
10
2
 
11
3
  LICOS 平台命令行工具。`licos-platform help` 返回结构化 JSON 帮助。
12
4
 
5
+ ## 企业知识库原文件下载
6
+
7
+ 此命令从 `licos-platform-cli==0.8.11` 起提供,需要 `licos-platform-sdk>=0.9.10`。
8
+
9
+ ```bash
10
+ licos-platform help knowledge enterprise-document-download
11
+ licos-platform knowledge enterprise document-download DOCUMENT_ID --out "attachments/会议纪要.docx"
12
+ licos-platform knowledge enterprise document-download LEGACY_DOCUMENT_ID --api-version legacy --out "attachments/旧版原文件.docx"
13
+ ```
14
+
15
+ 命令复用 Platform SDK 的 `enterprise_knowledge.download_document`,默认使用新版文档 ID,旧接口 ID 显式指定 `--api-version legacy`。只传真实文档 ID 和保存路径,程序内部取得并直接使用原始签名链接,输出 `document_id/path/size_bytes/sha256`,不输出票据。
16
+
17
+ `--out` 相对路径按当前进程工作目录解析,沿用业务进程和沙箱写入权限,不改变已有任务目录。自动创建父目录,已有文件、目录或链接均不覆盖,下载失败不留下半份文件。`--timeout` 是每次网络操作超时,默认 120 秒;`--max-bytes` 默认 1073741824(1 GiB)。下载请求不携带平台凭据,不跟随重定向,可信内网 HTTP 入口由平台校验。
18
+
19
+ 身份规则与其他企业知识库命令相同。网页项目替用户执行时加 `--token-stdin`,将本次请求用户 Token 写入子进程标准输入;不通过命令行参数或共享环境变量传 Token。权限、下载、覆盖冲突和本地文件错误均返回非零退出码。原 `document-url`、`document-download-link` 命令继续可用。
20
+
13
21
  ## 企业项目(0.8.1 起)
14
22
 
15
23
  ```bash
@@ -4,12 +4,12 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "licos-platform-cli"
7
- version = "0.8.10"
7
+ version = "0.8.11"
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.9.9",
12
+ "licos-platform-sdk>=0.9.10",
13
13
  ]
14
14
 
15
15
  [project.scripts]
@@ -373,7 +373,7 @@ DATABASE_HELP = {
373
373
 
374
374
  KNOWLEDGE_HELP = {
375
375
  "topic": "knowledge",
376
- "description": "Personal/project knowledge datasets plus read-only enterprise knowledge discovery, documents, retrieval, and download links.",
376
+ "description": "Personal/project knowledge datasets plus read-only enterprise knowledge discovery, documents, retrieval, original file downloads, and download links.",
377
377
  "runtime": RUNTIME_ENV,
378
378
  "rules": [
379
379
  "Use SDK from server/runtime code; do not call from browser bundles.",
@@ -384,7 +384,8 @@ KNOWLEDGE_HELP = {
384
384
  "Enterprise commands use --token-stdin or the standalone CLI user LICOS_CURRENT_USER_ID. Tenant scope and permissions come from the current user token; never pass or invent tenant IDs.",
385
385
  "Enterprise tree supports STANDARD, GRAPH, and OBJECT_STORAGE type filters. Current enterprise APIs support retrieve and list_files only.",
386
386
  "Validate enterprise knowledge references before retrieval or listing when an Agent receives IDs from conversation context. Manage enterprise resources through the platform knowledge IFrame.",
387
- "Use document-url/document-download-link for temporary access URLs; do not construct storage URLs.",
387
+ "Use document-download to save original files by document ID. It consumes the signed URL internally; never copy or reconstruct tickets. document-url/document-download-link remain available for temporary access URLs.",
388
+ "document-download defaults to v2 IDs; explicitly select --api-version legacy for IDs from the old document APIs. Relative --out paths use the process cwd and existing sandbox permissions; no file or link is overwritten.",
388
389
  ],
389
390
  "sdk": {
390
391
  "python": "from licos_platform_sdk import knowledge\nknowledge.add_text('FAQ content', dataset_name='project_docs')\nresults = knowledge.search('How to reset password?')",
@@ -525,6 +526,19 @@ KNOWLEDGE_HELP = {
525
526
  'enterprise-document-download-link': {'description': '获取临时下载短链及文件 ID。',
526
527
  'parameters': [{'name': 'document-id', 'required': True}],
527
528
  'example': 'licos-platform knowledge enterprise document-download-link document-id'},
529
+ 'enterprise-document-download': {
530
+ 'description': '按文档 ID 下载原文件到本地,程序内部使用原始签名链接,不覆盖已有文件。',
531
+ 'parameters': [
532
+ {'name': 'document-id', 'type': 'string', 'required': True, 'description': '真实文档 ID,不能使用知识库 ID。'},
533
+ {'name': '--out', 'type': 'string', 'required': True, 'description': '本地保存路径;相对路径按调用进程 cwd 解析,沿用现有写入权限。'},
534
+ {'name': '--api-version', 'type': 'string', 'required': False, 'description': 'v2(默认)或 legacy;旧接口取得的 ID 显式选择 legacy,不自动切换。'},
535
+ {'name': '--timeout', 'type': 'number', 'required': False, 'description': '正数,每次网络操作超时秒数,默认 120。'},
536
+ {'name': '--max-bytes', 'type': 'integer', 'required': False, 'description': '正整数,最大下载字节数,默认 1073741824(1 GiB)。'},
537
+ ],
538
+ 'returns': 'JSON: document_id, path(本地绝对路径), size_bytes, sha256;不返回签名 URL。',
539
+ 'errors': '权限、下载、覆盖冲突或本地文件失败返回非零退出码,失败时清理下载临时文件。',
540
+ 'example': 'licos-platform knowledge enterprise document-download document-id --out "attachments/会议纪要.docx" --token-stdin',
541
+ },
528
542
  'enterprise-folder-knowledge-bases': {'description': '列出目录下的知识库。',
529
543
  'parameters': [{'name': 'folder-id', 'required': True},
530
544
  {'name': '--include-children', 'required': False},
@@ -1,9 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import argparse
4
+ import math
4
5
  from typing import Any, Callable
5
6
 
6
- from licos_platform_sdk import enterprise_knowledge, knowledge
7
+ from licos_platform_sdk import PlatformSdkError, enterprise_knowledge, knowledge
7
8
  from .identity import add_user_token_option, user_token
8
9
 
9
10
  Handler = Callable[[argparse.Namespace], Any]
@@ -223,6 +224,32 @@ def _cmd_enterprise_document_download_link(args: argparse.Namespace) -> Any:
223
224
  return enterprise_knowledge.document_download_link(args.document_id, user_token=user_token(args))
224
225
 
225
226
 
227
+ def _cmd_enterprise_document_download(args: argparse.Namespace) -> Any:
228
+ if not args.document_id.strip() or not args.out.strip():
229
+ raise argparse.ArgumentTypeError("document_id and --out must not be empty")
230
+ try:
231
+ return enterprise_knowledge.download_document(
232
+ args.document_id, args.out, user_token=user_token(args), api_version=args.api_version,
233
+ timeout=args.timeout, max_bytes=args.max_bytes,
234
+ )
235
+ except OSError as exc:
236
+ raise PlatformSdkError(f"Cannot save enterprise knowledge document: {exc}") from exc
237
+
238
+
239
+ def _positive_timeout(value: str) -> float:
240
+ seconds = float(value)
241
+ if not math.isfinite(seconds) or seconds <= 0:
242
+ raise argparse.ArgumentTypeError("timeout must be positive and finite")
243
+ return seconds
244
+
245
+
246
+ def _positive_bytes(value: str) -> int:
247
+ size = int(value)
248
+ if size <= 0:
249
+ raise argparse.ArgumentTypeError("max-bytes must be a positive integer")
250
+ return size
251
+
252
+
226
253
  def _add_dataset_selector(parser: argparse.ArgumentParser) -> None:
227
254
  dataset = parser.add_mutually_exclusive_group(required=True)
228
255
  dataset.add_argument("--dataset-id", default=None, help="Knowledge dataset ID")
@@ -335,6 +362,14 @@ def _add_enterprise_parser(
335
362
  download_link.add_argument("document_id")
336
363
  _set_user_handler(download_link, _cmd_enterprise_document_download_link)
337
364
 
365
+ download = commands.add_parser("document-download", help="Download an original document by ID and save it without overwriting")
366
+ download.add_argument("document_id", help="Document ID, not a knowledge base ID")
367
+ download.add_argument("--out", required=True, help="Local destination path, relative to the process cwd")
368
+ download.add_argument("--api-version", choices=["v2", "legacy"], default="v2", help="Document API version; default v2")
369
+ download.add_argument("--timeout", type=_positive_timeout, default=120, help="Network operation timeout in seconds; default 120")
370
+ download.add_argument("--max-bytes", type=_positive_bytes, default=1024 ** 3, help="Maximum download size in bytes; default 1 GiB")
371
+ _set_user_handler(download, _cmd_enterprise_document_download)
372
+
338
373
 
339
374
  def add_knowledge_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
340
375
  knowledge_parser = subparsers.add_parser("knowledge", help="Call LICOS Knowledge APIs")
@@ -0,0 +1,165 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
5
+ import io
6
+ import json
7
+ import os
8
+ from pathlib import Path
9
+ import subprocess
10
+ import sys
11
+ import tempfile
12
+ import threading
13
+ import unittest
14
+ from unittest import mock
15
+
16
+ from test_cli import run_cli
17
+ from licos_platform_cli import knowledge_commands
18
+ from licos_platform_sdk import ApiError
19
+
20
+
21
+ CLI_ROOT = Path(__file__).resolve().parents[1]
22
+ SDK_SOURCE = CLI_ROOT.parent / "licos-platform-sdk" / "src"
23
+ TEMP_ROOT = CLI_ROOT.parents[2] / ".tmp"
24
+
25
+
26
+ class KnowledgeDownloadCommandTests(unittest.TestCase):
27
+ def setUp(self):
28
+ environment = mock.patch.dict(os.environ, {"LICOS_CURRENT_USER_ID": "cli-test-user"})
29
+ environment.start()
30
+ self.addCleanup(environment.stop)
31
+
32
+ def test_default_parameters_and_current_cli_identity_are_forwarded_to_sdk(self):
33
+ result = {"document_id": "doc-1", "path": "/project/attachments/manual.pdf", "size_bytes": 10, "sha256": "hash"}
34
+ with mock.patch("licos_platform_cli.identity.runtime_user_token", return_value="cli-user-token"), \
35
+ mock.patch.object(knowledge_commands.enterprise_knowledge, "download_document", return_value=result) as download:
36
+ code, output, error = run_cli("knowledge", "enterprise", "document-download", "doc-1", "--out", "attachments/manual.pdf")
37
+ self.assertEqual((code, error), (0, ""))
38
+ self.assertEqual(json.loads(output), result)
39
+ download.assert_called_once_with("doc-1", "attachments/manual.pdf", user_token="cli-user-token", api_version="v2", timeout=120, max_bytes=1024 ** 3)
40
+
41
+ def test_explicit_token_and_legacy_limits_are_forwarded_without_identity_exchange(self):
42
+ with mock.patch("sys.stdin", io.StringIO("request-user-token\n")), \
43
+ mock.patch("licos_platform_cli.identity.runtime_user_token") as exchange, \
44
+ mock.patch.object(knowledge_commands.enterprise_knowledge, "download_document", return_value={}) as download:
45
+ code, _, error = run_cli("knowledge", "enterprise", "document-download", "old-doc", "--out", "附件/原件.docx",
46
+ "--api-version", "legacy", "--timeout", "2.5", "--max-bytes", "12345", "--token-stdin")
47
+ self.assertEqual((code, error), (0, ""))
48
+ exchange.assert_not_called()
49
+ download.assert_called_once_with("old-doc", "附件/原件.docx", user_token="request-user-token", api_version="legacy", timeout=2.5, max_bytes=12345)
50
+
51
+ def test_invalid_arguments_never_call_the_sdk(self):
52
+ invalid = [[], ["--api-version", "auto"], ["--timeout", "0"], ["--timeout", "nan"],
53
+ ["--timeout", "inf"], ["--timeout", "bad"], ["--max-bytes", "-1"], ["--max-bytes", "2.5"]]
54
+ with mock.patch.object(knowledge_commands.enterprise_knowledge, "download_document") as download:
55
+ for extra in invalid:
56
+ with self.subTest(extra=extra):
57
+ args = ["knowledge", "enterprise", "document-download", "doc-1"]
58
+ if extra:
59
+ args.extend(["--out", "file.pdf", *extra])
60
+ code, _, error = run_cli(*args)
61
+ self.assertEqual(code, 2)
62
+ self.assertIn("error:", error)
63
+ code, _, _ = run_cli("knowledge", "enterprise", "document-download", "doc-1", "--out", "")
64
+ self.assertEqual(code, 2)
65
+ download.assert_not_called()
66
+
67
+ def test_empty_stdin_token_does_not_fall_back_to_container_identity(self):
68
+ with mock.patch("sys.stdin", io.StringIO("\n")), \
69
+ mock.patch("licos_platform_cli.identity.runtime_user_token") as exchange, \
70
+ mock.patch.object(knowledge_commands.enterprise_knowledge, "download_document") as download:
71
+ code, output, error = run_cli("knowledge", "enterprise", "document-download", "doc-1", "--out", "file.pdf", "--token-stdin")
72
+ self.assertEqual(code, 1)
73
+ self.assertEqual(output, "")
74
+ self.assertIn("error:", error)
75
+ exchange.assert_not_called()
76
+ download.assert_not_called()
77
+
78
+ def test_sdk_and_local_filesystem_failures_return_nonzero_without_success_output(self):
79
+ with mock.patch("licos_platform_cli.identity.runtime_user_token", return_value="cli-token"):
80
+ for failure in (ApiError("Download denied", status=403), PermissionError("Output directory is read-only")):
81
+ with self.subTest(failure=failure), \
82
+ mock.patch.object(knowledge_commands.enterprise_knowledge, "download_document", side_effect=failure):
83
+ code, output, error = run_cli("knowledge", "enterprise", "document-download", "doc-1", "--out", "file.pdf")
84
+ self.assertEqual(code, 1)
85
+ self.assertEqual(output, "")
86
+ self.assertIn(str(failure), error)
87
+ self.assertNotIn("Traceback", error)
88
+
89
+ def test_structured_and_argparse_help_expose_the_download_contract(self):
90
+ code, output, error = run_cli("help", "knowledge", "enterprise-document-download")
91
+ self.assertEqual((code, error), (0, ""))
92
+ document = json.loads(output)
93
+ self.assertEqual(document["command"], "enterprise-document-download")
94
+ self.assertEqual({item["name"] for item in document["parameters"]},
95
+ {"document-id", "--out", "--api-version", "--timeout", "--max-bytes", "--token-stdin"})
96
+ self.assertIn("sha256", document["returns"])
97
+ code, output, error = run_cli("knowledge", "enterprise", "document-download", "--help")
98
+ self.assertEqual((code, error), (0, ""))
99
+ self.assertIn("--out", output)
100
+ self.assertIn("{v2,legacy}", output)
101
+
102
+
103
+ class KnowledgeDownloadCliIntegrationTests(unittest.TestCase):
104
+ def test_real_cli_sdk_http_and_files_with_token_stdin(self):
105
+ calls = []
106
+ content = "知识库原文件\0完整性校验".encode()
107
+ ticket = "original%2B+%2F" + "x" * 8000
108
+
109
+ class Handler(BaseHTTPRequestHandler):
110
+ def log_message(self, *_args):
111
+ pass
112
+
113
+ def do_GET(self):
114
+ calls.append((self.path, self.headers.get("Authorization")))
115
+ self.send_response(200)
116
+ self.end_headers()
117
+ if self.path.startswith("/api/v1/knowledge/enterprise/"):
118
+ link = {"documentId": "doc/1", "downloadUrl": f"http://127.0.0.1:{self.server.server_port}/original?ticket={ticket}"}
119
+ self.wfile.write(json.dumps({"code": 0, "data": link}).encode())
120
+ else:
121
+ self.wfile.write(content)
122
+
123
+ TEMP_ROOT.mkdir(exist_ok=True)
124
+ server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
125
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
126
+ thread.start()
127
+ try:
128
+ with tempfile.TemporaryDirectory(dir=TEMP_ROOT, prefix="platform-cli-download-") as directory:
129
+ environment = {**os.environ, "PYTHONPATH": os.pathsep.join([str(CLI_ROOT / "src"), str(SDK_SOURCE)]),
130
+ "LICOS_PLATFORM_API_BASE_URL": f"http://127.0.0.1:{server.server_port}",
131
+ "AGENT_PROJECT_ID": "test-project", "NO_PROXY": "127.0.0.1", "PYTHONIOENCODING": "utf-8"}
132
+ for version in ("v2", "legacy"):
133
+ with self.subTest(version=version):
134
+ destination = f"附件/原文件-{version}.pdf"
135
+ command = [sys.executable, "-m", "licos_platform_cli.main", "knowledge", "enterprise", "document-download", "doc/1",
136
+ "--out", destination, "--api-version", version, "--token-stdin"]
137
+ result = subprocess.run(command, input="actual-request-token\n", text=True, encoding="utf-8",
138
+ capture_output=True, timeout=15, cwd=directory, env=environment)
139
+ self.assertEqual((result.returncode, result.stderr), (0, ""))
140
+ payload = json.loads(result.stdout)
141
+ target = Path(directory) / destination
142
+ self.assertEqual(payload, {"document_id": "doc/1", "path": str(target), "size_bytes": len(content),
143
+ "sha256": hashlib.sha256(content).hexdigest()})
144
+ self.assertEqual(target.read_bytes(), content)
145
+ prefix = "/v2" if version == "v2" else ""
146
+ self.assertEqual(calls[-2], (f"/api/v1/knowledge/enterprise{prefix}/documents/doc%2F1/download-link", "Bearer actual-request-token"))
147
+ self.assertEqual(calls[-1], (f"/original?ticket={ticket}", None))
148
+ self.assertNotIn(ticket, result.stdout + result.stderr)
149
+ before = len(calls)
150
+ repeated = subprocess.run(command, input="actual-request-token\n", text=True, encoding="utf-8",
151
+ capture_output=True, timeout=15, cwd=directory, env=environment)
152
+ self.assertEqual(repeated.returncode, 1)
153
+ self.assertEqual(repeated.stdout, "")
154
+ self.assertIn("already exists", repeated.stderr)
155
+ self.assertEqual(len(calls), before)
156
+ self.assertEqual(target.read_bytes(), content)
157
+ self.assertEqual(len(list(Path(directory).rglob("*"))), 3) # Folder and two completed files, no temporary output.
158
+ finally:
159
+ server.shutdown()
160
+ server.server_close()
161
+ thread.join()
162
+
163
+
164
+ if __name__ == "__main__":
165
+ unittest.main()