fix(templates): make End output variable names unique in built-in templates (#38293)

This commit is contained in:
Manan Bansal 2026-07-02 11:36:07 +05:30 committed by GitHub
parent 41fb484491
commit 6c08a43af1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
import yaml
from services.recommend_app.buildin.buildin_retrieval import BuildInRecommendAppRetrieval
from services.recommend_app.recommend_app_type import RecommendAppType
@ -100,3 +101,29 @@ class TestBuildInRecommendAppRetrieval:
BuildInRecommendAppRetrieval.builtin_data = SAMPLE_BUILTIN_DATA
result = BuildInRecommendAppRetrieval.fetch_recommended_app_detail_from_builtin("nonexistent")
assert result is None
def test_builtin_workflow_templates_have_unique_end_output_variables():
"""Workflow publish validation rejects duplicate End output variable names, so the bundled
templates must not ship with duplicates or users cannot publish them (see issue #38278)."""
data_path = Path(__file__).resolve().parents[4] / "constants" / "recommended_apps.json"
data = json.loads(data_path.read_text(encoding="utf-8"))
offenders: dict[str, list[str]] = {}
for app_id, detail in data.get("app_details", {}).items():
export_data = detail.get("export_data")
if not export_data:
continue
dsl = yaml.safe_load(export_data)
nodes = (dsl or {}).get("workflow", {}).get("graph", {}).get("nodes", [])
output_names = [
output.get("variable")
for node in nodes
if node.get("data", {}).get("type") == "end"
for output in (node.get("data", {}).get("outputs") or [])
]
duplicates = sorted({name for name in output_names if output_names.count(name) > 1})
if duplicates:
offenders[detail.get("name", app_id).strip()] = duplicates
assert offenders == {}, f"templates with duplicate End output variable names: {offenders}"