# This workflow should behave the same as if 3/foo is not force-triggered.

# Force-triggering 3/foo to put a running no-flow task in the way of the main flow.
# When 2/foo tries to spawn its successor 3/foo, we merge its flow number into
# the running 3/foo. Once 3/foo belongs to the flow its successor 4/foo and
# child 3/bar must be spawned retroactively.

[scheduling]
    cycling mode = integer
    initial cycle point = 1
    final cycle point = 4
    runahead limit = P0
    [[graph]]
        P1 = "foo:start => bar"
[runtime]
    [[foo]]
        script = """
            if ((CYLC_TASK_CYCLE_POINT == 1)); then
                # Force trigger 3/foo while 2/foo is runahead limited.
                expected="foo, 2, waiting, not-held, not-queued, runahead"
                diff <(cylc dump -l -t "${CYLC_WORKFLOW_ID}" | grep 'foo, 2') \
                     <(echo "$expected")
                cylc trigger --flow=none $CYLC_WORKFLOW_ID//3/foo
            elif ((CYLC_TASK_CYCLE_POINT == 3)); then
                # Run until I get merged.
                cylc__job__poll_grep_workflow_log -E "3/foo.* merged in flow\(s\) 1"
            fi
         """
    [[bar]]
