tickflow-py 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/PKG-INFO +25 -12
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/README.md +24 -11
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/pyproject.toml +31 -31
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_async.py +11 -5
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_audit_switch.py +2 -2
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_checkpoints.py +21 -16
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_persistence.py +42 -11
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_remap.py +3 -5
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_storage_window.py +2 -2
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/persistence.py +601 -597
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/runner.py +25 -2
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/state.py +16 -3
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow_py.egg-info/PKG-INFO +25 -12
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/LICENSE +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/setup.cfg +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_async_bind.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_bind.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_bind_validation.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_checker.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_dispatch.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_engine.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_failed_terminal.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_failure.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_fireable.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_guard_view.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_hooks.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_loop.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_node_state.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_node_view.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_parser.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_registry_sig.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_snapshot.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_status.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tests/test_visualization.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/__init__.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/__main__.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/async_runner.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/checker.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/cli.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/engine.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/ir.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/parser.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/registry.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow/views.py +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow_py.egg-info/SOURCES.txt +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow_py.egg-info/dependency_links.txt +0 -0
- {tickflow_py-0.3.0 → tickflow_py-0.4.0}/tickflow_py.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tickflow-py
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: A small Petri-style workflow control framework
|
|
5
5
|
Author: MountLynx
|
|
6
6
|
License: MIT
|
|
@@ -109,7 +109,8 @@ RunState
|
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
- **`_edges`** — windowed fast-lookup index for `resolve()`: only the last two
|
|
112
|
-
firings per node stay in memory; older firings live in
|
|
112
|
+
firings per node stay in memory; older firings live in a persistent
|
|
113
|
+
backend (NullBackend discards them). Memory
|
|
113
114
|
usage is O(nodes × 2 × output size), independent of how many times a node fired.
|
|
114
115
|
- **`_fire_counts`** — per-node firing counters; they map window entries back
|
|
115
116
|
to their `A[k]` ordinals, so index reads stay correct with a windowed index.
|
|
@@ -167,10 +168,15 @@ the system temp dir, auto-generates a `session_id`, and removes the database
|
|
|
167
168
|
file when the Runner is garbage-collected — so persistence, audit, checkpoints
|
|
168
169
|
and `A[k]` index reads work out of the box. Pass `NullBackend()` explicitly
|
|
169
170
|
for a zero-I/O in-memory run, or a concrete backend for a persistent one.
|
|
170
|
-
`NullBackend` also enables **fast mode**:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
`NullBackend` also enables **fast mode**: every backend write is discarded —
|
|
172
|
+
no per-tick snapshots, no firing history, no named checkpoints. Runner state
|
|
173
|
+
is window-bounded only with `keep_records=False`; with the default
|
|
174
|
+
`keep_records=True`, the in-memory audit (`_records`) still grows with firing
|
|
175
|
+
count. Note that `run_until_idle()` returns every firing (including outputs)
|
|
176
|
+
and therefore retains the whole run; drive long runs with `tick()` or discard
|
|
177
|
+
the returned list. `A[k]` reads outside the window and full `firings_of()`
|
|
178
|
+
degrade to `Missing` / the 2-entry window. Named checkpoints require a
|
|
179
|
+
persistent backend (`JsonBackend` / `SqliteBackend`).
|
|
174
180
|
|
|
175
181
|
## Semantics
|
|
176
182
|
|
|
@@ -403,8 +409,9 @@ at the end of every tick: each `NodeState` (the process record, batch-flushed
|
|
|
403
409
|
once per tick) and a lightweight snapshot at the new tick index. The persisted
|
|
404
410
|
snapshot strips `records` (they live in the backend's firings table) but keeps
|
|
405
411
|
`edges`/`state` — it stays self-contained — and adds a `fired` trace listing
|
|
406
|
-
the nodes that fired that tick. Fast mode (`NullBackend`)
|
|
407
|
-
|
|
412
|
+
the nodes that fired that tick. Fast mode (`NullBackend`) discards every
|
|
413
|
+
backend write entirely: no per-tick snapshots, no firings, no named
|
|
414
|
+
checkpoints.
|
|
408
415
|
|
|
409
416
|
```python
|
|
410
417
|
from tickflow import JsonBackend
|
|
@@ -429,9 +436,11 @@ rn2.restore(snap)
|
|
|
429
436
|
`firings` / `checkpoints` tables. Better for high tick-throughput; writes
|
|
430
437
|
are serialized behind an internal lock, so one instance is safe to share
|
|
431
438
|
across threads. This is the default (temp file, auto-cleaned).
|
|
432
|
-
- **`NullBackend`**:
|
|
433
|
-
snapshots, no cold history (`A[k]` outside
|
|
434
|
-
`Missing`). Good for
|
|
439
|
+
- **`NullBackend`**: stateless fast mode — no disk I/O, no per-tick
|
|
440
|
+
snapshots, no firings, no checkpoints, no cold history (`A[k]` outside
|
|
441
|
+
the window degrades to `Missing`). Good for hot loops and zero-I/O runs;
|
|
442
|
+
use `JsonBackend` / `SqliteBackend` when history or checkpoints are
|
|
443
|
+
required.
|
|
435
444
|
|
|
436
445
|
### Named checkpoints
|
|
437
446
|
|
|
@@ -443,6 +452,10 @@ rn.list_checkpoints() # [(label, tick), ...]
|
|
|
443
452
|
rn.rollback_to("after_prep") # restore to that checkpoint
|
|
444
453
|
```
|
|
445
454
|
|
|
455
|
+
Named checkpoints require a backend that stores snapshots: `JsonBackend` or
|
|
456
|
+
`SqliteBackend`. `NullBackend` raises `RuntimeError` for `checkpoint()` /
|
|
457
|
+
`rollback_to()`.
|
|
458
|
+
|
|
446
459
|
### Graph remap (hot-swap graph structure)
|
|
447
460
|
|
|
448
461
|
After a rollback, you can replace the graph structure and/or registry before
|
|
@@ -598,7 +611,7 @@ tickflow/
|
|
|
598
611
|
views.py DictView, Resolved, Missing
|
|
599
612
|
persistence.py Backend protocol, JsonBackend, SqliteBackend, NullBackend
|
|
600
613
|
cli.py python -m tickflow ...
|
|
601
|
-
tests/ 25 files,
|
|
614
|
+
tests/ 25 files, 293 tests
|
|
602
615
|
examples/ 8 examples (6 graph + 2 Python scripts)
|
|
603
616
|
```
|
|
604
617
|
|
|
@@ -87,7 +87,8 @@ RunState
|
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
- **`_edges`** — windowed fast-lookup index for `resolve()`: only the last two
|
|
90
|
-
firings per node stay in memory; older firings live in
|
|
90
|
+
firings per node stay in memory; older firings live in a persistent
|
|
91
|
+
backend (NullBackend discards them). Memory
|
|
91
92
|
usage is O(nodes × 2 × output size), independent of how many times a node fired.
|
|
92
93
|
- **`_fire_counts`** — per-node firing counters; they map window entries back
|
|
93
94
|
to their `A[k]` ordinals, so index reads stay correct with a windowed index.
|
|
@@ -145,10 +146,15 @@ the system temp dir, auto-generates a `session_id`, and removes the database
|
|
|
145
146
|
file when the Runner is garbage-collected — so persistence, audit, checkpoints
|
|
146
147
|
and `A[k]` index reads work out of the box. Pass `NullBackend()` explicitly
|
|
147
148
|
for a zero-I/O in-memory run, or a concrete backend for a persistent one.
|
|
148
|
-
`NullBackend` also enables **fast mode**:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
`NullBackend` also enables **fast mode**: every backend write is discarded —
|
|
150
|
+
no per-tick snapshots, no firing history, no named checkpoints. Runner state
|
|
151
|
+
is window-bounded only with `keep_records=False`; with the default
|
|
152
|
+
`keep_records=True`, the in-memory audit (`_records`) still grows with firing
|
|
153
|
+
count. Note that `run_until_idle()` returns every firing (including outputs)
|
|
154
|
+
and therefore retains the whole run; drive long runs with `tick()` or discard
|
|
155
|
+
the returned list. `A[k]` reads outside the window and full `firings_of()`
|
|
156
|
+
degrade to `Missing` / the 2-entry window. Named checkpoints require a
|
|
157
|
+
persistent backend (`JsonBackend` / `SqliteBackend`).
|
|
152
158
|
|
|
153
159
|
## Semantics
|
|
154
160
|
|
|
@@ -381,8 +387,9 @@ at the end of every tick: each `NodeState` (the process record, batch-flushed
|
|
|
381
387
|
once per tick) and a lightweight snapshot at the new tick index. The persisted
|
|
382
388
|
snapshot strips `records` (they live in the backend's firings table) but keeps
|
|
383
389
|
`edges`/`state` — it stays self-contained — and adds a `fired` trace listing
|
|
384
|
-
the nodes that fired that tick. Fast mode (`NullBackend`)
|
|
385
|
-
|
|
390
|
+
the nodes that fired that tick. Fast mode (`NullBackend`) discards every
|
|
391
|
+
backend write entirely: no per-tick snapshots, no firings, no named
|
|
392
|
+
checkpoints.
|
|
386
393
|
|
|
387
394
|
```python
|
|
388
395
|
from tickflow import JsonBackend
|
|
@@ -407,9 +414,11 @@ rn2.restore(snap)
|
|
|
407
414
|
`firings` / `checkpoints` tables. Better for high tick-throughput; writes
|
|
408
415
|
are serialized behind an internal lock, so one instance is safe to share
|
|
409
416
|
across threads. This is the default (temp file, auto-cleaned).
|
|
410
|
-
- **`NullBackend`**:
|
|
411
|
-
snapshots, no cold history (`A[k]` outside
|
|
412
|
-
`Missing`). Good for
|
|
417
|
+
- **`NullBackend`**: stateless fast mode — no disk I/O, no per-tick
|
|
418
|
+
snapshots, no firings, no checkpoints, no cold history (`A[k]` outside
|
|
419
|
+
the window degrades to `Missing`). Good for hot loops and zero-I/O runs;
|
|
420
|
+
use `JsonBackend` / `SqliteBackend` when history or checkpoints are
|
|
421
|
+
required.
|
|
413
422
|
|
|
414
423
|
### Named checkpoints
|
|
415
424
|
|
|
@@ -421,6 +430,10 @@ rn.list_checkpoints() # [(label, tick), ...]
|
|
|
421
430
|
rn.rollback_to("after_prep") # restore to that checkpoint
|
|
422
431
|
```
|
|
423
432
|
|
|
433
|
+
Named checkpoints require a backend that stores snapshots: `JsonBackend` or
|
|
434
|
+
`SqliteBackend`. `NullBackend` raises `RuntimeError` for `checkpoint()` /
|
|
435
|
+
`rollback_to()`.
|
|
436
|
+
|
|
424
437
|
### Graph remap (hot-swap graph structure)
|
|
425
438
|
|
|
426
439
|
After a rollback, you can replace the graph structure and/or registry before
|
|
@@ -576,7 +589,7 @@ tickflow/
|
|
|
576
589
|
views.py DictView, Resolved, Missing
|
|
577
590
|
persistence.py Backend protocol, JsonBackend, SqliteBackend, NullBackend
|
|
578
591
|
cli.py python -m tickflow ...
|
|
579
|
-
tests/ 25 files,
|
|
592
|
+
tests/ 25 files, 293 tests
|
|
580
593
|
examples/ 8 examples (6 graph + 2 Python scripts)
|
|
581
594
|
```
|
|
582
595
|
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=68"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "tickflow-py"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "A small Petri-style workflow control framework"
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.10"
|
|
11
|
-
license = { text = "MIT" }
|
|
12
|
-
authors = [{ name = "MountLynx" }]
|
|
13
|
-
keywords = ["petri", "workflow", "graph", "state-machine", "flow"]
|
|
14
|
-
classifiers = [
|
|
15
|
-
"Development Status :: 4 - Beta",
|
|
16
|
-
"Intended Audience :: Developers",
|
|
17
|
-
"License :: OSI Approved :: MIT License",
|
|
18
|
-
"Programming Language :: Python :: 3",
|
|
19
|
-
"Programming Language :: Python :: 3.10",
|
|
20
|
-
"Programming Language :: Python :: 3.11",
|
|
21
|
-
"Programming Language :: Python :: 3.12",
|
|
22
|
-
"Programming Language :: Python :: 3.13",
|
|
23
|
-
"Topic :: Software Development :: Libraries",
|
|
24
|
-
]
|
|
25
|
-
dependencies = []
|
|
26
|
-
|
|
27
|
-
[project.urls]
|
|
28
|
-
Homepage = "https://github.com/MountLynx/tickflow-"
|
|
29
|
-
|
|
30
|
-
[tool.setuptools]
|
|
31
|
-
packages = ["tickflow"]
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tickflow-py"
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
description = "A small Petri-style workflow control framework"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "MountLynx" }]
|
|
13
|
+
keywords = ["petri", "workflow", "graph", "state-machine", "flow"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Libraries",
|
|
24
|
+
]
|
|
25
|
+
dependencies = []
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/MountLynx/tickflow-"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools]
|
|
31
|
+
packages = ["tickflow"]
|
|
@@ -6,7 +6,7 @@ import asyncio
|
|
|
6
6
|
|
|
7
7
|
import pytest
|
|
8
8
|
|
|
9
|
-
from tickflow import parse, Registry, Failure, JsonBackend, RunStatus
|
|
9
|
+
from tickflow import parse, Registry, Failure, JsonBackend, RunStatus, SqliteBackend
|
|
10
10
|
from tickflow.async_runner import AsyncRunner
|
|
11
11
|
from tickflow.views import Missing
|
|
12
12
|
|
|
@@ -146,19 +146,25 @@ def test_async_persistence(tmp_path):
|
|
|
146
146
|
assert len(be.list_firings("s1")) == len(rn.audit_log())
|
|
147
147
|
|
|
148
148
|
|
|
149
|
-
def test_async_checkpoint_rollback():
|
|
149
|
+
def test_async_checkpoint_rollback(tmp_path):
|
|
150
150
|
r = _reg()
|
|
151
|
-
|
|
152
|
-
be = NullBackend()
|
|
151
|
+
be = SqliteBackend(tmp_path / "checkpoints.db")
|
|
153
152
|
rn = AsyncRunner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
154
153
|
_run(rn.run_until_idle(max_ticks=20, pause_at={3}))
|
|
155
154
|
rn.checkpoint("cp3")
|
|
156
155
|
_run(rn.run_until_idle(max_ticks=20))
|
|
157
156
|
final = [(f.tick, f.node, f.output) for f in rn.audit_log()]
|
|
157
|
+
# Persistent audit() dedupes replayed (tick, node) rows keep-first, so
|
|
158
|
+
# compare the raw appended tail instead.
|
|
158
159
|
rn.rollback_to("cp3")
|
|
159
160
|
assert rn.tick_count == 3
|
|
161
|
+
before = len(be.list_firings("s1"))
|
|
160
162
|
_run(rn.run_until_idle(max_ticks=20))
|
|
161
|
-
|
|
163
|
+
tail = [
|
|
164
|
+
(d["tick"], d["node"], d["output"])
|
|
165
|
+
for d in be.list_firings("s1")[before:]
|
|
166
|
+
]
|
|
167
|
+
assert tail == [row for row in final if row[0] >= 3]
|
|
162
168
|
|
|
163
169
|
|
|
164
170
|
def test_async_snapshot_restore_matches_sync():
|
|
@@ -96,8 +96,8 @@ def test_async_runner_keep_records_false():
|
|
|
96
96
|
rn = AsyncRunner(_loop_graph(r), r, backend=be, session_id="s1", keep_records=False)
|
|
97
97
|
asyncio.run(rn.run_until_idle(max_ticks=50))
|
|
98
98
|
assert rn.audit_log() == []
|
|
99
|
-
#
|
|
100
|
-
assert
|
|
99
|
+
# NullBackend is stateless: no backend firing history either.
|
|
100
|
+
assert be.list_firings("s1") == []
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
def test_async_runner_to_json_roundtrip():
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
-
from tickflow import parse, Runner, Registry, JsonBackend
|
|
6
|
+
from tickflow import parse, Runner, Registry, JsonBackend, SqliteBackend
|
|
7
7
|
from tickflow.persistence import NullBackend
|
|
8
8
|
from tickflow.views import Missing
|
|
9
9
|
|
|
@@ -47,9 +47,9 @@ def test_checkpoint_works_with_default_backend():
|
|
|
47
47
|
assert rn.tick_count == 3
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
def test_checkpoint_save_and_list():
|
|
50
|
+
def test_checkpoint_save_and_list(tmp_path):
|
|
51
51
|
r = _reg()
|
|
52
|
-
be =
|
|
52
|
+
be = SqliteBackend(tmp_path / "checkpoints.db")
|
|
53
53
|
rn = Runner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
54
54
|
rn.run_until_idle(max_ticks=20, pause_at={3})
|
|
55
55
|
rn.checkpoint("after_3")
|
|
@@ -60,25 +60,30 @@ def test_checkpoint_save_and_list():
|
|
|
60
60
|
assert ("after_5", 5) in cps
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def test_rollback_to_checkpoint_restores_state():
|
|
63
|
+
def test_rollback_to_checkpoint_restores_state(tmp_path):
|
|
64
64
|
r = _reg()
|
|
65
|
-
be =
|
|
65
|
+
be = SqliteBackend(tmp_path / "checkpoints.db")
|
|
66
66
|
rn = Runner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
67
67
|
rn.run_until_idle(max_ticks=20, pause_at={3})
|
|
68
68
|
rn.checkpoint("cp3")
|
|
69
69
|
rn.run_until_idle(max_ticks=20) # finish
|
|
70
70
|
final_audit = [(f.tick, f.node, f.output) for f in rn.audit_log()]
|
|
71
|
-
# Rollback to cp3 and replay.
|
|
71
|
+
# Rollback to cp3 and replay. Persistent audit() dedupes replayed
|
|
72
|
+
# (tick, node) rows keep-first, so compare the raw appended tail instead.
|
|
72
73
|
rn.rollback_to("cp3")
|
|
73
74
|
assert rn.tick_count == 3
|
|
75
|
+
before = len(be.list_firings("s1"))
|
|
74
76
|
rn.run_until_idle(max_ticks=20)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
tail = [
|
|
78
|
+
(d["tick"], d["node"], d["output"])
|
|
79
|
+
for d in be.list_firings("s1")[before:]
|
|
80
|
+
]
|
|
81
|
+
assert tail == [row for row in final_audit if row[0] >= 3]
|
|
77
82
|
|
|
78
83
|
|
|
79
|
-
def test_rollback_to_missing_label_raises():
|
|
84
|
+
def test_rollback_to_missing_label_raises(tmp_path):
|
|
80
85
|
r = _reg()
|
|
81
|
-
be =
|
|
86
|
+
be = SqliteBackend(tmp_path / "checkpoints.db")
|
|
82
87
|
rn = Runner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
83
88
|
rn.run_until_idle(max_ticks=5, pause_at={3})
|
|
84
89
|
with pytest.raises(KeyError):
|
|
@@ -105,9 +110,9 @@ def test_json_backend_checkpoints(tmp_path):
|
|
|
105
110
|
assert snap["tick"] == 3
|
|
106
111
|
|
|
107
112
|
|
|
108
|
-
def test_checkpoint_overwrites_same_label():
|
|
113
|
+
def test_checkpoint_overwrites_same_label(tmp_path):
|
|
109
114
|
r = _reg()
|
|
110
|
-
be =
|
|
115
|
+
be = SqliteBackend(tmp_path / "checkpoints.db")
|
|
111
116
|
rn = Runner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
112
117
|
rn.run_until_idle(max_ticks=20, pause_at={2})
|
|
113
118
|
rn.checkpoint("cp")
|
|
@@ -197,11 +202,11 @@ def test_set_registry_missing_guard_raises():
|
|
|
197
202
|
rn.set_registry(bad)
|
|
198
203
|
|
|
199
204
|
|
|
200
|
-
def test_rollback_to_then_set_registry():
|
|
205
|
+
def test_rollback_to_then_set_registry(tmp_path):
|
|
201
206
|
"""rollback_to rewinds state; set_registry swaps the body separately.
|
|
202
207
|
The two-step flow replaces the old one-call ``registry=`` argument."""
|
|
203
208
|
r = _reg()
|
|
204
|
-
be =
|
|
209
|
+
be = SqliteBackend(tmp_path / "checkpoints.db")
|
|
205
210
|
rn = Runner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
206
211
|
rn.run_until_idle(max_ticks=20, pause_at={3})
|
|
207
212
|
rn.checkpoint("cp3")
|
|
@@ -244,14 +249,14 @@ def test_async_set_registry():
|
|
|
244
249
|
asyncio.run(_run())
|
|
245
250
|
|
|
246
251
|
|
|
247
|
-
def test_async_rollback_to_then_set_registry():
|
|
252
|
+
def test_async_rollback_to_then_set_registry(tmp_path):
|
|
248
253
|
"""AsyncRunner.rollback_to + set_registry two-step flow."""
|
|
249
254
|
import asyncio
|
|
250
255
|
from tickflow.async_runner import AsyncRunner
|
|
251
256
|
|
|
252
257
|
async def _run():
|
|
253
258
|
r = _reg()
|
|
254
|
-
be =
|
|
259
|
+
be = SqliteBackend(tmp_path / "checkpoints.db")
|
|
255
260
|
rn = AsyncRunner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
256
261
|
await rn.run_until_idle(max_ticks=20, pause_at={3})
|
|
257
262
|
rn.checkpoint("cp3")
|
|
@@ -37,24 +37,55 @@ def _loop_graph(r):
|
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
def
|
|
41
|
-
"""Fast mode
|
|
40
|
+
def test_null_backend_keeps_no_state():
|
|
41
|
+
"""Fast mode: NullBackend discards firings/snapshots/checkpoints.
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
checkpoints still work via explicit save_checkpoint.
|
|
43
|
+
Audit still works through RunState._records when keep_records=True;
|
|
44
|
+
NullBackend itself is stateless.
|
|
46
45
|
"""
|
|
47
46
|
r = _reg()
|
|
48
47
|
g = _loop_graph(r)
|
|
49
48
|
be = NullBackend()
|
|
50
49
|
rn = Runner(g, r, backend=be, session_id="s1")
|
|
51
50
|
rn.run_until_idle(max_ticks=20)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
assert
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
assert
|
|
51
|
+
assert be.list_firings("s1") == []
|
|
52
|
+
assert be.list_snapshots("s1") == []
|
|
53
|
+
assert be.list_checkpoints("s1") == []
|
|
54
|
+
assert be.latest_tick("s1") is None
|
|
55
|
+
# keep_records=True: audit comes from the in-memory _records, not backend.
|
|
56
|
+
assert rn.audit_log()
|
|
57
|
+
# No hidden storage dictionaries (regression guard).
|
|
58
|
+
assert not hasattr(be, "_firings")
|
|
59
|
+
assert not hasattr(be, "_snapshots")
|
|
60
|
+
assert not hasattr(be, "_checkpoints")
|
|
61
|
+
# Writes are discarded; reads return empty.
|
|
62
|
+
be.save_snapshot("s1", 1, {"tick": 1})
|
|
63
|
+
be.save_firing("s1", {"tick": 1, "node": "A"})
|
|
64
|
+
be.save_firings("s1", [{"tick": 2, "node": "B"}])
|
|
65
|
+
be.save_checkpoint("s1", "cp", {"tick": 1})
|
|
66
|
+
assert be.load_snapshot("s1", 1) is None
|
|
67
|
+
assert be.load_checkpoint("s1", "cp") is None
|
|
68
|
+
assert be.list_firings("s1") == []
|
|
69
|
+
assert be.list_snapshots("s1") == []
|
|
70
|
+
assert be.list_checkpoints("s1") == []
|
|
71
|
+
assert be.latest_tick("s1") is None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_run_state_persistent_requires_stateful_backend():
|
|
75
|
+
from tickflow.state import RunState
|
|
76
|
+
|
|
77
|
+
with pytest.raises(ValueError, match="stateful backend"):
|
|
78
|
+
RunState(backend=NullBackend(), session_id="s1", persistent=True)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_null_backend_checkpoint_raises():
|
|
82
|
+
r = _reg()
|
|
83
|
+
rn = Runner(_loop_graph(r), r, backend=NullBackend(), session_id="s1")
|
|
84
|
+
rn.run_until_idle(max_ticks=5)
|
|
85
|
+
with pytest.raises(RuntimeError, match="persistent backend"):
|
|
86
|
+
rn.checkpoint("cp")
|
|
87
|
+
with pytest.raises(RuntimeError, match="persistent backend"):
|
|
88
|
+
rn.rollback_to("cp")
|
|
58
89
|
|
|
59
90
|
|
|
60
91
|
def test_null_backend_latest_tick_none():
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
-
from tickflow import parse, Runner, Registry
|
|
6
|
+
from tickflow import parse, Runner, Registry, SqliteBackend
|
|
7
7
|
from tickflow.ir import Graph, Node, Edge, InputPolicy
|
|
8
8
|
from tickflow.views import Missing
|
|
9
9
|
|
|
@@ -263,12 +263,10 @@ def test_remap_add_edge_source_refires():
|
|
|
263
263
|
assert b_fired
|
|
264
264
|
|
|
265
265
|
|
|
266
|
-
def test_rollback_remap_resume():
|
|
266
|
+
def test_rollback_remap_resume(tmp_path):
|
|
267
267
|
"""Full workflow: run→checkpoint→rollback→remap→resume with new edge."""
|
|
268
|
-
from tickflow.persistence import NullBackend
|
|
269
|
-
|
|
270
268
|
r = _loop_reg()
|
|
271
|
-
be =
|
|
269
|
+
be = SqliteBackend(tmp_path / "remap.db")
|
|
272
270
|
rn = Runner(_loop_graph(r), r, backend=be, session_id="s1")
|
|
273
271
|
rn.run_until_idle(max_ticks=20, pause_at={2})
|
|
274
272
|
rn.checkpoint("safe")
|
|
@@ -156,10 +156,10 @@ def test_big_output_not_retained_in_memory(tmp_path):
|
|
|
156
156
|
assert len(fs) == 20 # 全量在库(D3)
|
|
157
157
|
|
|
158
158
|
|
|
159
|
-
def test_pending_queue_batches_per_tick_and_flushes():
|
|
159
|
+
def test_pending_queue_batches_per_tick_and_flushes(tmp_path):
|
|
160
160
|
from tickflow.state import RunState, NodeState
|
|
161
161
|
|
|
162
|
-
be =
|
|
162
|
+
be = SqliteBackend(tmp_path / "batching.db")
|
|
163
163
|
rs = RunState(backend=be, session_id="s1", persistent=True)
|
|
164
164
|
rs.record(NodeState(tick=1, node="A", output="a1"))
|
|
165
165
|
rs.record(NodeState(tick=1, node="B", output="b1"))
|