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
11 changes: 8 additions & 3 deletions src/trinity/fugu/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ def _list_candidates(text: str, names: tuple[str, ...]) -> list[tuple[int, list]
def _normalize_access(acc: object, step_index: int) -> object | None:
"""Validate/normalize one access entry. Returns ``None`` if invalid.

Valid forms: ``"all"``, ``[]``/``None`` (query only), or a list of integer
indices that strictly precede ``step_index`` (a forward reference is an
invalid DAG and rejects the whole workflow).
Valid forms: ``"all"``, ``[]``/``None`` (query only), a bare integer index,
or a list of integer indices, each of which must strictly precede
``step_index`` (a forward reference is an invalid DAG and rejects the whole
workflow).
"""
if acc is None:
return []
Expand All @@ -208,6 +209,10 @@ def _normalize_access(acc: object, step_index: int) -> object | None:
j = int(s)
return [j] if j < step_index else None
return None
if isinstance(acc, bool):
return None
if isinstance(acc, int):
return [acc] if 0 <= acc < step_index else None
if isinstance(acc, (list, tuple)):
if len(acc) == 1 and isinstance(acc[0], str) and acc[0].strip().lower() == "all":
return "all"
Expand Down
17 changes: 17 additions & 0 deletions tests/test_fugu_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ def test_parse_normalizes_common_access_shorthands():
assert [s.access for s in wf.steps] == [[], [0], [1]]


def test_parse_accepts_bare_int_access_index():
# A bare integer access entry (0) is the natural shorthand for [0] and must
# be accepted just like the string "0" and the list [0] already are.
txt = """
model_id = [0, 1, 2]
subtasks = ["solve", "check", "answer"]
access_list = ["none", 0, 1]
"""
wf, ok = parse_workflow(txt, n_workers=3)
assert ok and wf is not None
assert [s.access for s in wf.steps] == [[], [0], [1]]

# A bare-int forward reference is still an invalid DAG.
fwd = "model_id=[0,1]\nsubtasks=['a','b']\naccess_list=[0, 1]"
assert parse_workflow(fwd, 3)[1] is False


def test_parse_gate_rejects_bad_workflows():
# missing a list
assert parse_workflow("model_id=[0]\nsubtasks=['x']", 3)[1] is False
Expand Down
Loading