Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/fi/alk/harness/framework_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@
"archive",
}
)
_OTHER_SOURCE_SUFFIXES = (".ts", ".tsx", ".ipynb")
_OTHER_SOURCE_SUFFIXES = (
".ts",
".tsx",
".mts",
".cts",
".js",
".jsx",
".mjs",
".cjs",
".ipynb",
)
_OTHER_SOURCE_NAME = "root_agent.yaml"

_VERSION_PATTERN = re.compile(
Expand Down Expand Up @@ -911,9 +921,12 @@ def _decide(found: FolderFindings) -> tuple[str, str | None]:
return "other", next(iter(labels))
if labels:
return "unknown", None
# A chat model names LangChain only when nothing unseen could be building the agent.
if found.blockers:
return "unknown", None
if any(f.strength == "model" for f in found.findings):
return "langchain", "langchain"
if any(f.strength == "import" for f in found.findings) or found.blockers:
if any(f.strength == "import" for f in found.findings):
return "unknown", None
return "none", None

Expand Down Expand Up @@ -1004,7 +1017,9 @@ def framework_folders_for(
elif control_service:
for process in manifest.processes:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not caused by this PR, but it now depends on it: framework_folders_for takes manifest: Any (and job: Any), so process.source_origin and process.working_directory are read with no type to check them against. A typo or a renamed field would only show up at runtime.

The manifest is an EnvironmentBundleV2, so typing the parameter as that would let a type checker see these reads. The tests pass SimpleNamespace fakes, so they would need the real model or a cast. Fine as a follow-up.

@khushalsonawat khushalsonawat Nov 6, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'd do this as a follow-up, together with the shared SourceProcess method from the other comment, since both need the tests' fakes replaced by the real model. No change in this PR. I'm leaving the thread open until that's settled.

if process.name == control_service:
folder = bundle_dir / process.working_directory
# The same base the runtime builds the process from.
base = bundle_dir if process.source_origin == "bundle" else source

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now the same rule as build_process_trees in process_runtime.py (context.bundle_dir if process.source_origin == "bundle" else source_root). The comment above it exists because the two copies have to stay in step, and nothing enforces that. If a third origin is added, or the rule changes in the runtime, this copy will drift without a failing test.

Optional, since two copies is still within the rule of three: a small method on SourceProcess, for example def root(self, *, source: Path, bundle_dir: Path) -> Path, would let both call sites use one rule, and the comment could go.

@khushalsonawat khushalsonawat Nov 6, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that the two copies can drift. I'd do this as a follow-up together with the typing comment: the method needs the tests' SimpleNamespace processes replaced by real SourceProcess models, which is that change. I'm leaving this thread open until that's settled.

folder = base / process.working_directory
break
package_dir = (
work_directory / "build" / control_service if control_service else None
Expand Down
69 changes: 66 additions & 3 deletions tests/harness/test_framework_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,12 @@ def test_a_use_of_a_long_target_allocates_nothing_of_its_size() -> None:
),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/ui.ts": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/ui.tsx": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/x.mts": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/x.cts": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/x.js": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/x.jsx": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/x.mjs": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/x.cjs": ""}, "agent", ""),
(fd._OTHER_SOURCE, {"agent/main.py": PLAIN, "agent/n.ipynb": ""}, "agent", ""),
(
fd._OTHER_SOURCE,
Expand All @@ -950,6 +956,12 @@ def test_a_use_of_a_long_target_allocates_nothing_of_its_size() -> None:
"outside_import_from_and_comma",
"other_source_ts",
"other_source_tsx",
"other_source_mts",
"other_source_cts",
"other_source_js",
"other_source_jsx",
"other_source_mjs",
"other_source_cjs",
"other_source_ipynb",
"other_source_root_agent",
"no_python",
Expand All @@ -964,7 +976,14 @@ def test_blockers_stop_none(
assert blocker in folder_findings(tmp_path / folder, repo_root=root).blockers
assert detect_framework(tmp_path / folder, repo_root=root) == UNKNOWN

# A blocker stops `none` and nothing else.
# Anything that blocks may hide what builds the agent, so a chat model names nothing.
if blocker != fd._NO_PYTHON:
_write(tmp_path, {f"{folder}/model.py": CHAT_OPENAI})
found = folder_findings(tmp_path / folder, repo_root=root)
assert any(f.strength == "model" for f in found.findings)
assert detect_framework(tmp_path / folder, repo_root=root) == UNKNOWN

# What the scan saw being built still names the framework.
_write(tmp_path, {f"{folder}/crew.py": CREW})
assert detect_framework(tmp_path / folder, repo_root=root) == _named("crewai")

Expand Down Expand Up @@ -1011,6 +1030,39 @@ def test_blockers_stop_none_no_outside_import_when_folder_is_the_root(
assert detect_framework(tmp_path, repo_root=tmp_path) == NONE


AGENT_JS = (
"import { Agent, run } from '@openai/agents';\n"
"const agent = new Agent({ name: 'x' });\n"
"await run(agent, 'hi');\n"
)
HEALTHCHECK = "import urllib.request\n"


@pytest.mark.parametrize(
"files",
[
{"tests/index.js": AGENT_JS, "healthcheck.py": HEALTHCHECK},
{"tests/x.jsx": AGENT_JS, "healthcheck.py": HEALTHCHECK},
{"examples/node/x.mjs": AGENT_JS, "healthcheck.py": HEALTHCHECK},
],
ids=["js_in_tests", "jsx_in_tests", "mjs_in_examples"],
)
def test_javascript_in_test_and_example_folders_does_not_block(
tmp_path: Path, files: dict[str, str]
) -> None:
_write(tmp_path, files)

assert fd._OTHER_SOURCE not in folder_findings(tmp_path).blockers
assert detect_framework(tmp_path) == NONE


def test_a_label_beside_a_blocker_stays_other(tmp_path: Path) -> None:
_write(tmp_path, {"main.py": AUTOGEN, "ui.js": ""})

assert fd._OTHER_SOURCE in folder_findings(tmp_path).blockers
assert detect_framework(tmp_path) == _named("other", "autogen")


SIDE_WORDS = [
"tests",
"test",
Expand Down Expand Up @@ -1350,12 +1402,16 @@ def test_metadata_read_stops_at_64_kib(tmp_path: Path) -> None:
assert detect_framework(folder, package_dir=package_dir) == _named("crewai")


def _process_manifest() -> SimpleNamespace:
def _process_manifest(source_origin: str = "bundle") -> SimpleNamespace:
return SimpleNamespace(
runtime=SimpleNamespace(kind="process", control_service="agent"),
processes=[
SimpleNamespace(name="postgres", working_directory=None),
SimpleNamespace(name="agent", working_directory="generated/source/agent"),
SimpleNamespace(
name="agent",
working_directory="generated/source/agent",
source_origin=source_origin,
),
],
)

Expand Down Expand Up @@ -1405,6 +1461,12 @@ def _compose_manifest() -> SimpleNamespace:
(None, None, _process_manifest(), "bundle/generated/source/agent"),
(None, "{not json", _process_manifest(), "bundle/generated/source/agent"),
(None, ["a", "list"], _process_manifest(), "bundle/generated/source/agent"),
(
None,
None,
_process_manifest("repository"),
"source/generated/source/agent",
),
(None, None, _compose_manifest(), "source"),
],
ids=[
Expand All @@ -1419,6 +1481,7 @@ def _compose_manifest() -> SimpleNamespace:
"missing_contract",
"corrupt_contract",
"contract_not_an_object",
"repository_origin_process",
"compose_falls_to_source",
],
)
Expand Down
26 changes: 26 additions & 0 deletions tests/harness/test_hosted_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5093,12 +5093,14 @@ def test_bad_subfolder_fails_terminal_before_compose(monkeypatch):

def _harness_with_a_packaged_agent(
packaged_main: bytes = b"from crewai import Crew\nCrew()\n",
source_origin: str = "bundle",
) -> Harness:
real_body = _base_manifest_body

def packaged_body() -> dict[str, Any]:
body = real_body()
body["processes"][1]["working_directory"] = "generated/source/agent"
body["processes"][1]["source_origin"] = source_origin
return body

files = {
Expand Down Expand Up @@ -5178,6 +5180,30 @@ async def scenario() -> None:
asyncio.run(scenario())


def test_run_job_gives_repository_source_its_folders(caplog) -> None:
async def scenario() -> None:
# The crew only in `source`: scanning the bundle's copy would find none.
harness = _harness_with_a_packaged_agent(
packaged_main=b"print('plain')\n", source_origin="repository"
)
agent = harness.source / "generated" / "source" / "agent"
agent.mkdir(parents=True)
(agent / "main.py").write_text(
"from crewai import Crew\nCrew()\n", encoding="utf-8"
)
_install_crewai(harness.work / "build" / "agent")

code = await he.run_job(
harness.job_path, harness.source, harness.output, deps=harness.deps
)

assert code == he.EXIT_OK
assert _posted_framework(harness) == {"name": "crewai", "version": "0.86.0"}

with caplog.at_level("INFO", logger="fi.alk.harness"):
asyncio.run(scenario())


def test_folder_step_failure_keeps_the_run_going(caplog) -> None:
secret = "/customer/private/path"

Expand Down
Loading