Skip to content
Open
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
8 changes: 6 additions & 2 deletions concore_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def validate(workflow_file, source, output_format):
def inspect(workflow_file, source, output_json):
"""Inspect a workflow file and show its structure"""
try:
inspect_workflow(workflow_file, source, output_json, console)
ok = inspect_workflow(workflow_file, source, output_json, console)
if not ok:
sys.exit(1)
except Exception as e:
console.print(f"[red]Error:[/red] {str(e)}")
sys.exit(1)
Expand Down Expand Up @@ -168,7 +170,9 @@ def stop():
def watch(study_dir, interval, once):
"""Watch a running simulation study for live monitoring"""
try:
watch_study(study_dir, interval, once, console)
ok = watch_study(study_dir, interval, once, console)
if not ok:
sys.exit(1)
except Exception as e:
console.print(f"[red]Error:[/red] {str(e)}")
sys.exit(1)
Expand Down
13 changes: 10 additions & 3 deletions concore_cli/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def inspect_workflow(workflow_file, source_dir, output_json, console):
if output_json:
return _inspect_json(workflow_path, source_dir)

_inspect_rich(workflow_path, source_dir, console)
return _inspect_rich(workflow_path, source_dir, console)


def _inspect_rich(workflow_path, source_dir, console):
Expand All @@ -28,7 +28,7 @@ def _inspect_rich(workflow_path, source_dir, console):

if not soup.find("graphml"):
console.print("[red]Not a valid GraphML file[/red]")
return
return False

nodes = soup.find_all("node")
edges = soup.find_all("edge")
Expand Down Expand Up @@ -172,8 +172,12 @@ def _inspect_rich(workflow_path, source_dir, console):

except FileNotFoundError:
console.print(f"[red]File not found:[/red] {workflow_path}")
return False
except Exception as e:
console.print(f"[red]Inspection failed:[/red] {str(e)}")
return False

return True


def _inspect_json(workflow_path, source_dir):
Expand All @@ -187,7 +191,7 @@ def _inspect_json(workflow_path, source_dir):

if not soup.find("graphml"):
print(json.dumps({"error": "Not a valid GraphML file"}, indent=2))
return
return False

nodes = soup.find_all("node")
edges = soup.find_all("edge")
Expand Down Expand Up @@ -269,3 +273,6 @@ def _inspect_json(workflow_path, source_dir):

except Exception as e:
print(json.dumps({"error": str(e)}, indent=2))
return False

return True
8 changes: 5 additions & 3 deletions concore_cli/commands/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def watch_study(study_dir, interval, once, console):
study_path = Path(study_dir).resolve()
if not study_path.is_dir():
console.print(f"[red]Error:[/red] '{study_dir}' is not a directory")
return
return False

nodes = _find_nodes(study_path)
edges = _find_edges(study_path, nodes)
Expand All @@ -28,12 +28,12 @@ def watch_study(study_dir, interval, once, console):
border_style="yellow",
)
)
return
return True

if once:
output = _build_display(study_path, nodes, edges)
console.print(output)
return
return True

console.print(f"[cyan]Watching:[/cyan] {study_path}")
console.print(f"[dim]Refresh every {interval}s — Ctrl+C to stop[/dim]\n")
Expand All @@ -48,6 +48,8 @@ def watch_study(study_dir, interval, once, console):
except KeyboardInterrupt:
console.print("\n[yellow]Watch stopped.[/yellow]")

return True


def _build_display(study_path, nodes, edges):
parts = []
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,22 @@ def test_inspect_missing_source_file(self):
self.assertEqual(result.exit_code, 0)
self.assertIn("Missing files", result.output)

def test_inspect_invalid_graphml_exits_nonzero(self):
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
Path("notes.txt").write_text("not graphml")
for args in (["inspect", "notes.txt"], ["inspect", "notes.txt", "--json"]):
with self.subTest(args=args):
result = self.runner.invoke(cli, args)
self.assertEqual(result.exit_code, 1)
self.assertIn("Not a valid GraphML file", result.output)

def test_watch_file_instead_of_dir_exits_nonzero(self):
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
Path("notes.txt").write_text("hi")
result = self.runner.invoke(cli, ["watch", "notes.txt", "--once"])
self.assertEqual(result.exit_code, 1)
self.assertIn("is not a directory", result.output)


if __name__ == "__main__":
unittest.main()
Loading