chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动

演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-18 13:59:25 +08:00
1 parent 60158935f4
commit 6519682885
15831 files changed
+3063428

No files matched your search

@@ -0,0 +1,60 @@
import pytest
from pydantic import ValidationError
import dify_agent.layers.shell as shell_exports
from dify_agent.layers.shell import (
DifyShellCliToolConfig,
DifyShellEnvVarConfig,
DifyShellLayerConfig,
DifyShellSecretRefConfig,
)
def test_shell_package_exports_client_safe_config_symbols_only() -> None:
assert shell_exports.__all__ == [
"DifyShellCliToolConfig",
"DifyShellEnvVarConfig",
"DifyShellLayerConfig",
"DifyShellSecretRefConfig",
]
assert not hasattr(shell_exports, "DifyShellLayer")
def test_shell_layer_config_defaults_and_forbids_unknown_fields() -> None:
config = DifyShellLayerConfig()
assert config.model_dump() == {
"runtime": "runtime",
"execution_context": "execution_context",
"cli_tools": [],
"env": [],
"secret_refs": [],
"redact_patterns": [],
}
with pytest.raises(ValidationError):
_ = DifyShellLayerConfig.model_validate({"entrypoint": "http://shellctl"})
def test_shell_layer_config_accepts_agent_soul_shell_settings() -> None:
config = DifyShellLayerConfig(
cli_tools=[
DifyShellCliToolConfig(
name="ripgrep",
install_commands=[" apt-get update ", "", "apt-get install -y ripgrep"],
env=[DifyShellEnvVarConfig(name="RG_CONFIG_PATH", value="/workspace/.ripgreprc")],
secret_refs=[DifyShellSecretRefConfig(name="GITHUB_TOKEN", ref="credential-2")],
)
],
env=[DifyShellEnvVarConfig(name="PROJECT_NAME", value="demo")],
secret_refs=[DifyShellSecretRefConfig(name="OPENAI_API_KEY", ref="credential-1")],
)
assert config.cli_tools[0].install_commands == ["apt-get update", "apt-get install -y ripgrep"]
assert config.cli_tools[0].env[0].name == "RG_CONFIG_PATH"
assert config.cli_tools[0].secret_refs[0].ref == "credential-2"
assert config.env[0].name == "PROJECT_NAME"
assert config.secret_refs[0].ref == "credential-1"
def test_shell_layer_config_rejects_invalid_env_names() -> None:
with pytest.raises(ValidationError):
_ = DifyShellEnvVarConfig(name="1_BAD", value="x")
with pytest.raises(ValidationError):
_ = DifyShellSecretRefConfig(name="BAD-NAME", ref="secret")
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,77 @@
from dify_agent.layers.shell.output_text import normalized_output_text, utf8_prefix, utf8_suffix
def test_normalized_output_text_includes_marker_and_log_guidance() -> None:
assert normalized_output_text(
"head",
tail="tail",
output_path="/tmp/output.log",
max_output_size_bytes=16,
) == (
"head\n"
"... (truncated in middle because the max output size is limited to 16 bytes) ...\n"
"tail\n"
"(check the /tmp/output.log for full output)"
)
def test_normalized_output_text_avoids_duplicate_tail_for_short_output() -> None:
assert (
normalized_output_text(
"short output",
tail="short output",
output_path="/tmp/output.log",
max_output_size_bytes=16,
)
== "short output"
)
def test_normalized_output_text_can_force_middle_truncation_when_head_matches_tail() -> None:
assert normalized_output_text(
"repeat",
tail="repeat",
output_path="/tmp/output.log",
max_output_size_bytes=16,
truncated_in_middle=True,
) == (
"repeat\n"
"... (truncated in middle because the max output size is limited to 16 bytes) ...\n"
"repeat\n"
"(check the /tmp/output.log for full output)"
)
def test_utf8_helpers_do_not_split_multibyte_characters() -> None:
text = "A🙂B"
assert utf8_prefix(text, 1) == "A"
assert utf8_prefix(text, 2) == "A"
assert utf8_prefix(text, 5) == "A🙂"
assert utf8_suffix(text, 1) == "B"
assert utf8_suffix(text, 2) == "B"
assert utf8_suffix(text, 5) == "🙂B"
def test_normalized_output_text_omits_log_guidance_without_output_path() -> None:
assert normalized_output_text(
"head",
tail="tail",
output_path=None,
max_output_size_bytes=16,
) == ("head\n... (truncated in middle because the max output size is limited to 16 bytes) ...\ntail")
def test_normalized_output_text_can_use_custom_truncation_message() -> None:
assert normalized_output_text(
"head",
tail="tail",
output_path="/tmp/output.log",
max_output_size_bytes=16,
truncation_message="command timed out before full output was captured",
) == (
"head\n"
"... (command timed out before full output was captured) ...\n"
"tail\n"
"(check the /tmp/output.log for full output)"
)