metaspn-store 0.1.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.
- metaspn_store-0.1.0/LICENSE +21 -0
- metaspn_store-0.1.0/PKG-INFO +56 -0
- metaspn_store-0.1.0/README.md +30 -0
- metaspn_store-0.1.0/pyproject.toml +39 -0
- metaspn_store-0.1.0/setup.cfg +4 -0
- metaspn_store-0.1.0/src/metaspn_store/__init__.py +3 -0
- metaspn_store-0.1.0/src/metaspn_store/store.py +147 -0
- metaspn_store-0.1.0/src/metaspn_store.egg-info/PKG-INFO +56 -0
- metaspn_store-0.1.0/src/metaspn_store.egg-info/SOURCES.txt +11 -0
- metaspn_store-0.1.0/src/metaspn_store.egg-info/dependency_links.txt +1 -0
- metaspn_store-0.1.0/src/metaspn_store.egg-info/requires.txt +7 -0
- metaspn_store-0.1.0/src/metaspn_store.egg-info/top_level.txt +1 -0
- metaspn_store-0.1.0/test/test_store.py +145 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MetaSPN
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: metaspn-store
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Minimal append-only durability layer and replay API for MetaSPN signals and emissions
|
|
5
|
+
Author: MetaSPN
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MetaSPN/metaspn-store
|
|
8
|
+
Project-URL: Repository, https://github.com/MetaSPN/metaspn-store
|
|
9
|
+
Project-URL: Issues, https://github.com/MetaSPN/metaspn-store/issues
|
|
10
|
+
Keywords: metaspn,event-store,replay,append-only,jsonl
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: metaspn-schemas>=0.1.0
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
22
|
+
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
23
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
24
|
+
Requires-Dist: wheel>=0.43.0; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# metaspn-store
|
|
28
|
+
|
|
29
|
+
`metaspn-store` provides a minimal append-only event store for MetaSPN signals and emissions.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
- Filesystem JSONL backend (partitioned by UTC date)
|
|
33
|
+
- Append-only writes for signals and emissions
|
|
34
|
+
- Snapshot writes for deterministic state rebuild checkpoints
|
|
35
|
+
- Streaming replay by time window, entity reference, and source
|
|
36
|
+
|
|
37
|
+
## Layout
|
|
38
|
+
```text
|
|
39
|
+
workspace/
|
|
40
|
+
store/
|
|
41
|
+
signals/
|
|
42
|
+
2026-02-05.jsonl
|
|
43
|
+
emissions/
|
|
44
|
+
2026-02-05.jsonl
|
|
45
|
+
snapshots/
|
|
46
|
+
system_state__2026-02-05T120000Z.json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Release
|
|
50
|
+
```bash
|
|
51
|
+
python -m pip install -e ".[dev]"
|
|
52
|
+
pytest -q
|
|
53
|
+
python -m build
|
|
54
|
+
python -m twine check dist/*
|
|
55
|
+
python -m twine upload dist/*
|
|
56
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# metaspn-store
|
|
2
|
+
|
|
3
|
+
`metaspn-store` provides a minimal append-only event store for MetaSPN signals and emissions.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
- Filesystem JSONL backend (partitioned by UTC date)
|
|
7
|
+
- Append-only writes for signals and emissions
|
|
8
|
+
- Snapshot writes for deterministic state rebuild checkpoints
|
|
9
|
+
- Streaming replay by time window, entity reference, and source
|
|
10
|
+
|
|
11
|
+
## Layout
|
|
12
|
+
```text
|
|
13
|
+
workspace/
|
|
14
|
+
store/
|
|
15
|
+
signals/
|
|
16
|
+
2026-02-05.jsonl
|
|
17
|
+
emissions/
|
|
18
|
+
2026-02-05.jsonl
|
|
19
|
+
snapshots/
|
|
20
|
+
system_state__2026-02-05T120000Z.json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Release
|
|
24
|
+
```bash
|
|
25
|
+
python -m pip install -e ".[dev]"
|
|
26
|
+
pytest -q
|
|
27
|
+
python -m build
|
|
28
|
+
python -m twine check dist/*
|
|
29
|
+
python -m twine upload dist/*
|
|
30
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "metaspn-store"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Minimal append-only durability layer and replay API for MetaSPN signals and emissions"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [{ name = "MetaSPN" }]
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
keywords = ["metaspn", "event-store", "replay", "append-only", "jsonl"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
]
|
|
22
|
+
dependencies = ["metaspn-schemas>=0.1.0"]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/MetaSPN/metaspn-store"
|
|
26
|
+
Repository = "https://github.com/MetaSPN/metaspn-store"
|
|
27
|
+
Issues = "https://github.com/MetaSPN/metaspn-store/issues"
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = ["pytest>=8", "build>=1.2.0", "twine>=5.0.0", "wheel>=0.43.0"]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
package-dir = { "" = "src" }
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["src"]
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["test"]
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from datetime import date, datetime, timedelta, timezone
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Iterator
|
|
7
|
+
|
|
8
|
+
from metaspn_schemas import EmissionEnvelope, EntityRef, SignalEnvelope
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _ensure_utc(value: datetime) -> datetime:
|
|
12
|
+
if value.tzinfo is None:
|
|
13
|
+
return value.replace(tzinfo=timezone.utc)
|
|
14
|
+
return value.astimezone(timezone.utc)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _iter_days(start_day: date, end_day: date) -> Iterator[date]:
|
|
18
|
+
current = start_day
|
|
19
|
+
while current <= end_day:
|
|
20
|
+
yield current
|
|
21
|
+
current += timedelta(days=1)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class FileSystemStore:
|
|
25
|
+
"""Append-only filesystem store for SignalEnvelope and EmissionEnvelope."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, workspace: str | Path) -> None:
|
|
28
|
+
self.workspace = Path(workspace)
|
|
29
|
+
self.store_root = self.workspace / "store"
|
|
30
|
+
self.signals_dir = self.store_root / "signals"
|
|
31
|
+
self.emissions_dir = self.store_root / "emissions"
|
|
32
|
+
self.snapshots_dir = self.store_root / "snapshots"
|
|
33
|
+
self._ensure_dirs()
|
|
34
|
+
|
|
35
|
+
def _ensure_dirs(self) -> None:
|
|
36
|
+
self.signals_dir.mkdir(parents=True, exist_ok=True)
|
|
37
|
+
self.emissions_dir.mkdir(parents=True, exist_ok=True)
|
|
38
|
+
self.snapshots_dir.mkdir(parents=True, exist_ok=True)
|
|
39
|
+
|
|
40
|
+
def write_signal(self, signal: SignalEnvelope) -> Path:
|
|
41
|
+
"""Append a signal to its UTC day partition and return written file path."""
|
|
42
|
+
if not signal.signal_id:
|
|
43
|
+
raise ValueError("signal_id is required for stable IDs")
|
|
44
|
+
if not signal.schema_version:
|
|
45
|
+
raise ValueError("schema_version is required")
|
|
46
|
+
|
|
47
|
+
signal_ts = _ensure_utc(signal.timestamp)
|
|
48
|
+
destination = self.signals_dir / f"{signal_ts.date().isoformat()}.jsonl"
|
|
49
|
+
with destination.open("a", encoding="utf-8") as handle:
|
|
50
|
+
handle.write(json.dumps(signal.to_dict(), sort_keys=True, separators=(",", ":")))
|
|
51
|
+
handle.write("\n")
|
|
52
|
+
return destination
|
|
53
|
+
|
|
54
|
+
def write_emission(self, emission: EmissionEnvelope) -> Path:
|
|
55
|
+
"""Append an emission to its UTC day partition and return written file path."""
|
|
56
|
+
if not emission.emission_id:
|
|
57
|
+
raise ValueError("emission_id is required for stable IDs")
|
|
58
|
+
if not emission.schema_version:
|
|
59
|
+
raise ValueError("schema_version is required")
|
|
60
|
+
|
|
61
|
+
emission_ts = _ensure_utc(emission.timestamp)
|
|
62
|
+
destination = self.emissions_dir / f"{emission_ts.date().isoformat()}.jsonl"
|
|
63
|
+
with destination.open("a", encoding="utf-8") as handle:
|
|
64
|
+
handle.write(json.dumps(emission.to_dict(), sort_keys=True, separators=(",", ":")))
|
|
65
|
+
handle.write("\n")
|
|
66
|
+
return destination
|
|
67
|
+
|
|
68
|
+
def write_snapshot(
|
|
69
|
+
self,
|
|
70
|
+
name: str,
|
|
71
|
+
snapshot_state: dict[str, Any],
|
|
72
|
+
snapshot_time: datetime | None = None,
|
|
73
|
+
) -> Path:
|
|
74
|
+
"""Write a point-in-time snapshot JSON document."""
|
|
75
|
+
ts = _ensure_utc(snapshot_time or datetime.now(timezone.utc))
|
|
76
|
+
timestamp_token = ts.strftime("%Y-%m-%dT%H%M%SZ")
|
|
77
|
+
destination = self.snapshots_dir / f"{name}__{timestamp_token}.json"
|
|
78
|
+
with destination.open("w", encoding="utf-8") as handle:
|
|
79
|
+
json.dump(snapshot_state, handle, sort_keys=True, separators=(",", ":"))
|
|
80
|
+
handle.write("\n")
|
|
81
|
+
return destination
|
|
82
|
+
|
|
83
|
+
def iter_signals(
|
|
84
|
+
self,
|
|
85
|
+
start: datetime,
|
|
86
|
+
end: datetime,
|
|
87
|
+
entity_ref: EntityRef | None = None,
|
|
88
|
+
sources: list[str] | None = None,
|
|
89
|
+
) -> Iterator[SignalEnvelope]:
|
|
90
|
+
"""Stream signals in [start, end], optionally filtered by entity_ref and source."""
|
|
91
|
+
start_utc = _ensure_utc(start)
|
|
92
|
+
end_utc = _ensure_utc(end)
|
|
93
|
+
if end_utc < start_utc:
|
|
94
|
+
raise ValueError("end must be greater than or equal to start")
|
|
95
|
+
|
|
96
|
+
source_set = set(sources) if sources else None
|
|
97
|
+
for day in _iter_days(start_utc.date(), end_utc.date()):
|
|
98
|
+
partition = self.signals_dir / f"{day.isoformat()}.jsonl"
|
|
99
|
+
if not partition.exists():
|
|
100
|
+
continue
|
|
101
|
+
with partition.open("r", encoding="utf-8") as handle:
|
|
102
|
+
for line in handle:
|
|
103
|
+
if not line.strip():
|
|
104
|
+
continue
|
|
105
|
+
record = json.loads(line)
|
|
106
|
+
signal = SignalEnvelope.from_dict(record)
|
|
107
|
+
signal_ts = _ensure_utc(signal.timestamp)
|
|
108
|
+
if signal_ts < start_utc or signal_ts > end_utc:
|
|
109
|
+
continue
|
|
110
|
+
if source_set is not None and signal.source not in source_set:
|
|
111
|
+
continue
|
|
112
|
+
if entity_ref is not None and entity_ref not in signal.entity_refs:
|
|
113
|
+
continue
|
|
114
|
+
yield signal
|
|
115
|
+
|
|
116
|
+
def iter_emissions(
|
|
117
|
+
self,
|
|
118
|
+
start: datetime,
|
|
119
|
+
end: datetime,
|
|
120
|
+
entity_ref: EntityRef | None = None,
|
|
121
|
+
emission_types: list[str] | None = None,
|
|
122
|
+
) -> Iterator[EmissionEnvelope]:
|
|
123
|
+
"""Stream emissions in [start, end], optionally filtered by entity_ref and type."""
|
|
124
|
+
start_utc = _ensure_utc(start)
|
|
125
|
+
end_utc = _ensure_utc(end)
|
|
126
|
+
if end_utc < start_utc:
|
|
127
|
+
raise ValueError("end must be greater than or equal to start")
|
|
128
|
+
|
|
129
|
+
emission_type_set = set(emission_types) if emission_types else None
|
|
130
|
+
for day in _iter_days(start_utc.date(), end_utc.date()):
|
|
131
|
+
partition = self.emissions_dir / f"{day.isoformat()}.jsonl"
|
|
132
|
+
if not partition.exists():
|
|
133
|
+
continue
|
|
134
|
+
with partition.open("r", encoding="utf-8") as handle:
|
|
135
|
+
for line in handle:
|
|
136
|
+
if not line.strip():
|
|
137
|
+
continue
|
|
138
|
+
record = json.loads(line)
|
|
139
|
+
emission = EmissionEnvelope.from_dict(record)
|
|
140
|
+
emission_ts = _ensure_utc(emission.timestamp)
|
|
141
|
+
if emission_ts < start_utc or emission_ts > end_utc:
|
|
142
|
+
continue
|
|
143
|
+
if emission_type_set is not None and emission.emission_type not in emission_type_set:
|
|
144
|
+
continue
|
|
145
|
+
if entity_ref is not None and entity_ref not in emission.entity_refs:
|
|
146
|
+
continue
|
|
147
|
+
yield emission
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: metaspn-store
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Minimal append-only durability layer and replay API for MetaSPN signals and emissions
|
|
5
|
+
Author: MetaSPN
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/MetaSPN/metaspn-store
|
|
8
|
+
Project-URL: Repository, https://github.com/MetaSPN/metaspn-store
|
|
9
|
+
Project-URL: Issues, https://github.com/MetaSPN/metaspn-store/issues
|
|
10
|
+
Keywords: metaspn,event-store,replay,append-only,jsonl
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: metaspn-schemas>=0.1.0
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
22
|
+
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
23
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
24
|
+
Requires-Dist: wheel>=0.43.0; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# metaspn-store
|
|
28
|
+
|
|
29
|
+
`metaspn-store` provides a minimal append-only event store for MetaSPN signals and emissions.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
- Filesystem JSONL backend (partitioned by UTC date)
|
|
33
|
+
- Append-only writes for signals and emissions
|
|
34
|
+
- Snapshot writes for deterministic state rebuild checkpoints
|
|
35
|
+
- Streaming replay by time window, entity reference, and source
|
|
36
|
+
|
|
37
|
+
## Layout
|
|
38
|
+
```text
|
|
39
|
+
workspace/
|
|
40
|
+
store/
|
|
41
|
+
signals/
|
|
42
|
+
2026-02-05.jsonl
|
|
43
|
+
emissions/
|
|
44
|
+
2026-02-05.jsonl
|
|
45
|
+
snapshots/
|
|
46
|
+
system_state__2026-02-05T120000Z.json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Release
|
|
50
|
+
```bash
|
|
51
|
+
python -m pip install -e ".[dev]"
|
|
52
|
+
pytest -q
|
|
53
|
+
python -m build
|
|
54
|
+
python -m twine check dist/*
|
|
55
|
+
python -m twine upload dist/*
|
|
56
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/metaspn_store/__init__.py
|
|
5
|
+
src/metaspn_store/store.py
|
|
6
|
+
src/metaspn_store.egg-info/PKG-INFO
|
|
7
|
+
src/metaspn_store.egg-info/SOURCES.txt
|
|
8
|
+
src/metaspn_store.egg-info/dependency_links.txt
|
|
9
|
+
src/metaspn_store.egg-info/requires.txt
|
|
10
|
+
src/metaspn_store.egg-info/top_level.txt
|
|
11
|
+
test/test_store.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
metaspn_store
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timedelta, timezone
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from metaspn_schemas import EmissionEnvelope, EntityRef, SignalEnvelope
|
|
7
|
+
|
|
8
|
+
from metaspn_store import FileSystemStore
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _ts(day: int, hour: int = 0, minute: int = 0) -> datetime:
|
|
12
|
+
return datetime(2026, 2, day, hour, minute, tzinfo=timezone.utc)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_round_trip_signal_and_emission(tmp_path: Path) -> None:
|
|
16
|
+
store = FileSystemStore(tmp_path)
|
|
17
|
+
ref = EntityRef(ref_type="entity_id", value="ent-1")
|
|
18
|
+
signal = SignalEnvelope(
|
|
19
|
+
signal_id="s-1",
|
|
20
|
+
timestamp=_ts(5, 10),
|
|
21
|
+
source="ingestor.a",
|
|
22
|
+
payload_type="SocialPostSeen",
|
|
23
|
+
payload={"post_id": "p1"},
|
|
24
|
+
entity_refs=(ref,),
|
|
25
|
+
)
|
|
26
|
+
emission = EmissionEnvelope(
|
|
27
|
+
emission_id="e-1",
|
|
28
|
+
timestamp=_ts(5, 11),
|
|
29
|
+
emission_type="ScoresComputed",
|
|
30
|
+
payload={"score": 0.8},
|
|
31
|
+
caused_by="s-1",
|
|
32
|
+
entity_refs=(ref,),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
store.write_signal(signal)
|
|
36
|
+
store.write_emission(emission)
|
|
37
|
+
|
|
38
|
+
read_signals = list(store.iter_signals(_ts(5, 0), _ts(5, 23, 59)))
|
|
39
|
+
read_emissions = list(store.iter_emissions(_ts(5, 0), _ts(5, 23, 59)))
|
|
40
|
+
|
|
41
|
+
assert read_signals == [signal]
|
|
42
|
+
assert read_emissions == [emission]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_replay_ordering_across_partitions(tmp_path: Path) -> None:
|
|
46
|
+
store = FileSystemStore(tmp_path)
|
|
47
|
+
|
|
48
|
+
signal_ids: list[str] = []
|
|
49
|
+
for idx, ts in enumerate([_ts(5, 23, 59), _ts(6, 0, 1), _ts(6, 12, 0)], start=1):
|
|
50
|
+
signal = SignalEnvelope(
|
|
51
|
+
signal_id=f"s-{idx}",
|
|
52
|
+
timestamp=ts,
|
|
53
|
+
source="ingestor.a",
|
|
54
|
+
payload_type="Synthetic",
|
|
55
|
+
payload={"idx": idx},
|
|
56
|
+
)
|
|
57
|
+
store.write_signal(signal)
|
|
58
|
+
signal_ids.append(signal.signal_id)
|
|
59
|
+
|
|
60
|
+
replayed_ids = [s.signal_id for s in store.iter_signals(_ts(5, 0), _ts(6, 23, 59))]
|
|
61
|
+
assert replayed_ids == signal_ids
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_time_window_entity_ref_and_source_filtering(tmp_path: Path) -> None:
|
|
65
|
+
store = FileSystemStore(tmp_path)
|
|
66
|
+
ref_a = EntityRef(ref_type="entity_id", value="ent-a")
|
|
67
|
+
ref_b = EntityRef(ref_type="entity_id", value="ent-b")
|
|
68
|
+
|
|
69
|
+
store.write_signal(
|
|
70
|
+
SignalEnvelope(
|
|
71
|
+
signal_id="s-1",
|
|
72
|
+
timestamp=_ts(5, 10, 0),
|
|
73
|
+
source="ingestor.a",
|
|
74
|
+
payload_type="Synthetic",
|
|
75
|
+
payload={},
|
|
76
|
+
entity_refs=(ref_a,),
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
store.write_signal(
|
|
80
|
+
SignalEnvelope(
|
|
81
|
+
signal_id="s-2",
|
|
82
|
+
timestamp=_ts(5, 10, 5),
|
|
83
|
+
source="ingestor.b",
|
|
84
|
+
payload_type="Synthetic",
|
|
85
|
+
payload={},
|
|
86
|
+
entity_refs=(ref_b,),
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
store.write_signal(
|
|
90
|
+
SignalEnvelope(
|
|
91
|
+
signal_id="s-3",
|
|
92
|
+
timestamp=_ts(5, 11, 0),
|
|
93
|
+
source="ingestor.a",
|
|
94
|
+
payload_type="Synthetic",
|
|
95
|
+
payload={},
|
|
96
|
+
entity_refs=(ref_a,),
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
windowed = list(
|
|
101
|
+
store.iter_signals(
|
|
102
|
+
start=_ts(5, 10, 1),
|
|
103
|
+
end=_ts(5, 11, 0),
|
|
104
|
+
entity_ref=ref_a,
|
|
105
|
+
sources=["ingestor.a"],
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
assert [s.signal_id for s in windowed] == ["s-3"]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_large_file_streaming_replay(tmp_path: Path) -> None:
|
|
112
|
+
store = FileSystemStore(tmp_path)
|
|
113
|
+
start = _ts(5, 0, 0)
|
|
114
|
+
total = 12000
|
|
115
|
+
|
|
116
|
+
for idx in range(total):
|
|
117
|
+
store.write_signal(
|
|
118
|
+
SignalEnvelope(
|
|
119
|
+
signal_id=f"s-{idx}",
|
|
120
|
+
timestamp=start + timedelta(seconds=idx),
|
|
121
|
+
source="ingestor.bulk",
|
|
122
|
+
payload_type="Bulk",
|
|
123
|
+
payload={"i": idx},
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
stream = store.iter_signals(start=start, end=start + timedelta(days=1))
|
|
128
|
+
first = next(stream)
|
|
129
|
+
second = next(stream)
|
|
130
|
+
assert first.signal_id == "s-0"
|
|
131
|
+
assert second.signal_id == "s-1"
|
|
132
|
+
|
|
133
|
+
count = 2 + sum(1 for _ in stream)
|
|
134
|
+
assert count == total
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_snapshot_write_creates_expected_file(tmp_path: Path) -> None:
|
|
138
|
+
store = FileSystemStore(tmp_path)
|
|
139
|
+
path = store.write_snapshot(
|
|
140
|
+
name="system_state",
|
|
141
|
+
snapshot_state={"entity_count": 3, "version": "v1"},
|
|
142
|
+
snapshot_time=_ts(5, 12, 0),
|
|
143
|
+
)
|
|
144
|
+
assert path.name == "system_state__2026-02-05T120000Z.json"
|
|
145
|
+
assert path.exists()
|