fix: ensure starter projects refreshed at startup (#3078)
* fix: ensure starter projects refreshed at startup * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
02ed87e8e0
commit
4b650152f7
11 changed files with 169 additions and 347 deletions
|
|
@ -4,7 +4,14 @@ from pathlib import Path
|
|||
import pytest
|
||||
from sqlmodel import select
|
||||
|
||||
from langflow.initial_setup.setup import STARTER_FOLDER_NAME, get_project_data, load_starter_projects
|
||||
from langflow.custom.directory_reader.utils import build_custom_component_list_from_path
|
||||
from langflow.initial_setup.setup import (
|
||||
STARTER_FOLDER_NAME,
|
||||
get_project_data,
|
||||
load_starter_projects,
|
||||
update_projects_components_with_latest_component_versions,
|
||||
)
|
||||
from langflow.interface.types import aget_all_types_dict
|
||||
from langflow.services.database.models.folder.model import Folder
|
||||
from langflow.services.deps import session_scope
|
||||
|
||||
|
|
@ -86,3 +93,50 @@ async def test_create_or_update_starter_projects():
|
|||
# )
|
||||
# assert all(isinstance(output, RunOutputs) for output in outputs), f"Project {name} error: {outputs}"
|
||||
# delete_messages(session_id="test")
|
||||
|
||||
|
||||
def find_componeny_by_name(components, name):
|
||||
for category, children in components.items():
|
||||
if name in children:
|
||||
return children[name]
|
||||
raise ValueError(f"Component {name} not found in components")
|
||||
|
||||
|
||||
def set_value(component, input_name, value):
|
||||
component["template"][input_name]["value"] = value
|
||||
|
||||
|
||||
def component_to_node(id, type, component):
|
||||
return {"id": type + id, "data": {"node": component, "type": type, "id": id}}
|
||||
|
||||
|
||||
def add_edge(input, output, from_output, to_input):
|
||||
return {
|
||||
"source": input,
|
||||
"target": output,
|
||||
"data": {
|
||||
"sourceHandle": {"dataType": "ChatInput", "id": input, "name": from_output, "output_types": ["Message"]},
|
||||
"targetHandle": {"fieldName": to_input, "id": output, "inputTypes": ["Message"], "type": "str"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_refresh_starter_projects():
|
||||
data_path = str(Path(__file__).parent.parent.parent.absolute() / "base" / "langflow" / "components")
|
||||
components = build_custom_component_list_from_path(data_path)
|
||||
|
||||
chat_input = find_componeny_by_name(components, "ChatInput")
|
||||
chat_output = find_componeny_by_name(components, "ChatOutput")
|
||||
chat_output["template"]["code"]["value"] = "changed !"
|
||||
graph_data = {
|
||||
"nodes": [
|
||||
component_to_node("chat-input-1", "ChatInput", chat_input),
|
||||
component_to_node("chat-output-1", "ChatOutput", chat_output),
|
||||
],
|
||||
"edges": [add_edge("ChatInput" + "chat-input-1", "ChatOutput" + "chat-output-1", "message", "input_value")],
|
||||
}
|
||||
all_types = await aget_all_types_dict([data_path])
|
||||
new_change = update_projects_components_with_latest_component_versions(graph_data, all_types)
|
||||
assert graph_data["nodes"][1]["data"]["node"]["template"]["code"]["value"] == "changed !"
|
||||
assert new_change["nodes"][1]["data"]["node"]["template"]["code"]["value"] != "changed !"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue