chap-analytics 0.2.1__tar.gz → 0.2.3__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.
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/CHANGELOG.md +24 -1
- {chap_analytics-0.2.1/chap_analytics.egg-info → chap_analytics-0.2.3}/PKG-INFO +1 -1
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/__init__.py +1 -1
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/load.py +78 -25
- {chap_analytics-0.2.1 → chap_analytics-0.2.3/chap_analytics.egg-info}/PKG-INFO +1 -1
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics.egg-info/SOURCES.txt +1 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/pyproject.toml +1 -1
- chap_analytics-0.2.3/tests/test_typescript_store.py +135 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/LICENSE +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/MANIFEST.in +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/README.md +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_patch.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_report/report.css +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_report/report.html +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_report/report.js +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_report/stats.js +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/LICENSE.vega +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/LICENSE.vega-embed +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/LICENSE.vega-lite +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/README.md +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/render.js +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/vega-embed.min.js +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/vega-lite.min.js +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/_vendor/vega.min.js +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/briefs.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/charts.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/export.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/frames.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/graph.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/models.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/py.typed +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/report.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/sample.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/schema.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/stats.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics/watch.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics.egg-info/dependency_links.txt +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics.egg-info/requires.txt +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/chap_analytics.egg-info/top_level.txt +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/examples/build_notebook.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/examples/chap_analytics_walkthrough.ipynb +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/examples/support_desk.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/setup.cfg +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/conftest.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/js_stats_runner.js +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_charts_and_briefs.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_differential.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_example.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_from_url_scheme.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_graph.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_handoff_and_routing.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_identity.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_notebook.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_projection.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_redaction_and_malformed.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_refusals.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_report.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_review_passes.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_sample_and_export.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_stats.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_successors.py +0 -0
- {chap_analytics-0.2.1 → chap_analytics-0.2.3}/tests/test_watch_export_models.py +0 -0
|
@@ -4,7 +4,30 @@
|
|
|
4
4
|
so a protocol release moves the coordinator packages together and leaves this
|
|
5
5
|
one where it is until the tables or the analyses change.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 0.2.3
|
|
8
|
+
|
|
9
|
+
Reads the store of `chap-coordinator` 0.3.2 and later.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **The 0.3.2 store.** `from_sqlite` reads the tables `chap-coordinator`
|
|
14
|
+
0.3.2 and later write, one row for each audit entry and each object. A
|
|
15
|
+
file an earlier release wrote reads as before.
|
|
16
|
+
|
|
17
|
+
## 0.2.2
|
|
18
|
+
|
|
19
|
+
Reads the store of the TypeScript coordinator, which the Node templates of
|
|
20
|
+
`create-chap-app` run. Install it with `chap-coordinator` 0.3.0 or later where
|
|
21
|
+
the `coordinator` extra drives a live coordinator.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **A TypeScript coordinator's store.** `from_sqlite` and `from_json` read a
|
|
26
|
+
workspace snapshot the TypeScript coordinator wrote, which holds its tasks,
|
|
27
|
+
members, overrides and the other collections as lists where the Python
|
|
28
|
+
coordinator holds them as objects keyed by id. Reading one stopped with an
|
|
29
|
+
`AttributeError`; the collections are now keyed on load, and both
|
|
30
|
+
coordinators' stores project to the same tables.
|
|
8
31
|
|
|
9
32
|
## 0.2.1
|
|
10
33
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chap-analytics
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report
|
|
5
5
|
Author-email: Brightbeam AI <oss@brightbeam.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -41,7 +41,7 @@ The layers, bottom up:
|
|
|
41
41
|
"""
|
|
42
42
|
from __future__ import annotations
|
|
43
43
|
|
|
44
|
-
__version__ = "0.2.
|
|
44
|
+
__version__ = "0.2.3"
|
|
45
45
|
|
|
46
46
|
from . import briefs, charts, export, graph, models, sample, stats, watch # noqa: E402
|
|
47
47
|
from .frames import Frames, frames # noqa: E402
|
|
@@ -217,12 +217,33 @@ def _redact_state(state: dict | None, redact: Redactor | None) -> dict | None:
|
|
|
217
217
|
return state
|
|
218
218
|
|
|
219
219
|
|
|
220
|
+
# The collections a workspace snapshot holds, and the field each is keyed by.
|
|
221
|
+
# The Python coordinator writes them as objects keyed by that field; the
|
|
222
|
+
# TypeScript coordinator writes them as lists. The projection reads objects.
|
|
223
|
+
_KEYED_COLLECTIONS = {
|
|
224
|
+
"tasks": "id", "overrides": "id", "whispers": "id", "deliberations": "id",
|
|
225
|
+
"handoffs": "id", "snapshots": "id", "route_decisions": "id", "members": "uri",
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _keyed_state(state: dict | None) -> dict | None:
|
|
230
|
+
"""A snapshot with every collection keyed by id, whichever coordinator wrote it."""
|
|
231
|
+
if not isinstance(state, dict):
|
|
232
|
+
return state
|
|
233
|
+
out = dict(state)
|
|
234
|
+
for name, key in _KEYED_COLLECTIONS.items():
|
|
235
|
+
value = out.get(name)
|
|
236
|
+
if isinstance(value, list):
|
|
237
|
+
out[name] = {item[key]: item for item in value if isinstance(item, dict) and isinstance(item.get(key), str)}
|
|
238
|
+
return out
|
|
239
|
+
|
|
240
|
+
|
|
220
241
|
def _chain(workspace: str, events: Iterable[dict], state: dict | None,
|
|
221
242
|
source: str, redact: Redactor | None) -> Chain:
|
|
222
243
|
evs = _apply_redaction(list(events), redact)
|
|
223
244
|
evs.sort(key=lambda e: e.get("seq", 0) if isinstance(e, dict) else 0)
|
|
224
245
|
return Chain(workspace=workspace, events=evs,
|
|
225
|
-
state=_redact_state(state, redact), source=source)
|
|
246
|
+
state=_redact_state(_keyed_state(state), redact), source=source)
|
|
226
247
|
|
|
227
248
|
|
|
228
249
|
def from_json(path: str, *, workspace: str | None = None, redact: Redactor | None = None) -> Chain:
|
|
@@ -250,41 +271,73 @@ def from_json(path: str, *, workspace: str | None = None, redact: Redactor | Non
|
|
|
250
271
|
)
|
|
251
272
|
|
|
252
273
|
|
|
274
|
+
def _store_snapshot(con: sqlite3.Connection, workspace: str) -> dict:
|
|
275
|
+
"""One workspace from the tables chap-coordinator 0.3.2 and later write.
|
|
276
|
+
|
|
277
|
+
The workspace's own fields, its log in seq order, and each collection as
|
|
278
|
+
objects keyed by id.
|
|
279
|
+
"""
|
|
280
|
+
row = con.execute("SELECT data FROM chap_meta WHERE workspace = ?", (workspace,)).fetchone()
|
|
281
|
+
snap = json.loads(row[0])
|
|
282
|
+
for name in (*_KEYED_COLLECTIONS, "idempotency_keys"):
|
|
283
|
+
snap[name] = {}
|
|
284
|
+
snap["audit"] = [json.loads(d) for (d,) in con.execute(
|
|
285
|
+
"SELECT data FROM chap_entries WHERE workspace = ? ORDER BY seq", (workspace,))]
|
|
286
|
+
for collection, key, data in con.execute(
|
|
287
|
+
"SELECT collection, id, data FROM chap_objects WHERE workspace = ? ORDER BY rowid",
|
|
288
|
+
(workspace,)):
|
|
289
|
+
snap.setdefault(collection, {})[key] = json.loads(data)
|
|
290
|
+
return snap
|
|
291
|
+
|
|
292
|
+
|
|
253
293
|
def from_sqlite(path: str, *, workspace: str | None = None, redact: Redactor | None = None) -> Chain:
|
|
254
294
|
"""
|
|
255
295
|
Load from a SqliteStore file.
|
|
256
296
|
|
|
257
|
-
The richest source: the store holds the whole workspace
|
|
258
|
-
|
|
297
|
+
The richest source: the store holds the whole workspace, so server-computed
|
|
298
|
+
values are available alongside the envelopes. Reads the tables
|
|
299
|
+
chap-coordinator 0.3.2 and later write, one row per audit entry and per
|
|
300
|
+
object, and the single snapshot table earlier releases wrote. Opens the
|
|
259
301
|
file read-only, so it is safe against a database a coordinator is using.
|
|
260
302
|
"""
|
|
261
303
|
uri = f"file:{path}?mode=ro"
|
|
262
304
|
con = sqlite3.connect(uri, uri=True)
|
|
263
305
|
try:
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if workspace is None:
|
|
276
|
-
if len(rows) > 1:
|
|
306
|
+
# One read transaction, so a coordinator writing the file meanwhile
|
|
307
|
+
# cannot leave the log and the objects out of step.
|
|
308
|
+
con.execute("BEGIN")
|
|
309
|
+
tables = {r[0] for r in con.execute("SELECT name FROM sqlite_master WHERE type = 'table'")}
|
|
310
|
+
if "chap_meta" in tables:
|
|
311
|
+
available = [r[0] for r in con.execute("SELECT workspace FROM chap_meta ORDER BY rowid")]
|
|
312
|
+
rows = None
|
|
313
|
+
elif "chap_workspaces" in tables:
|
|
314
|
+
rows = con.execute("SELECT id, data FROM chap_workspaces").fetchall()
|
|
315
|
+
available = [r[0] for r in rows]
|
|
316
|
+
else:
|
|
277
317
|
raise ValueError(
|
|
278
|
-
f"{path}
|
|
279
|
-
|
|
318
|
+
f"{path} lacks the tables a CHAP SqliteStore writes: chap_meta, or "
|
|
319
|
+
"chap_workspaces before chap-coordinator 0.3.2."
|
|
280
320
|
)
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
321
|
+
|
|
322
|
+
if not available:
|
|
323
|
+
raise ValueError(f"{path} holds an empty workspace table.")
|
|
324
|
+
if workspace is None:
|
|
325
|
+
if len(available) > 1:
|
|
326
|
+
raise ValueError(
|
|
327
|
+
f"{path} holds {len(available)} workspaces; name one with "
|
|
328
|
+
f"workspace=. Available: {', '.join(available)}"
|
|
329
|
+
)
|
|
330
|
+
workspace = available[0]
|
|
331
|
+
if workspace not in available:
|
|
332
|
+
raise ValueError(f"{path} holds {', '.join(available)}. Pass one of those as workspace= "
|
|
333
|
+
f"({workspace!r} was given).")
|
|
334
|
+
if rows is None:
|
|
335
|
+
snap = _store_snapshot(con, workspace)
|
|
336
|
+
else:
|
|
337
|
+
snap = json.loads(next(data for ws_id, data in rows if ws_id == workspace))
|
|
338
|
+
finally:
|
|
339
|
+
con.close()
|
|
340
|
+
return _chain(workspace, snap.get("audit", []), snap, f"sqlite:{path}", redact)
|
|
288
341
|
|
|
289
342
|
|
|
290
343
|
def from_url(url: str, workspace: str, *, actor: str = "service:analytics",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chap-analytics
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report
|
|
5
5
|
Author-email: Brightbeam AI <oss@brightbeam.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "chap-analytics"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.3"
|
|
8
8
|
description = "The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""A store the TypeScript coordinator wrote reads like one the Python coordinator wrote.
|
|
2
|
+
|
|
3
|
+
The TypeScript snapshot holds its collections as lists; the Python one holds
|
|
4
|
+
them as objects keyed by id. The same workspace, written both ways, has to
|
|
5
|
+
project to the same tables. So does a store from chap-coordinator 0.3.2 and
|
|
6
|
+
later, which writes a row per audit entry and per object.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import sqlite3
|
|
12
|
+
|
|
13
|
+
import pandas as pd
|
|
14
|
+
|
|
15
|
+
from chap_analytics import frames, from_json, from_sqlite
|
|
16
|
+
from chap_analytics.sample import support_desk
|
|
17
|
+
|
|
18
|
+
KEYS = {"tasks": "id", "overrides": "id", "whispers": "id", "deliberations": "id",
|
|
19
|
+
"handoffs": "id", "snapshots": "id", "route_decisions": "id", "members": "uri"}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def as_typescript(state: dict) -> dict:
|
|
23
|
+
"""The snapshot as the TypeScript coordinator writes it: collections as lists."""
|
|
24
|
+
out = dict(state)
|
|
25
|
+
for name in KEYS:
|
|
26
|
+
if isinstance(out.get(name), dict):
|
|
27
|
+
out[name] = list(out[name].values())
|
|
28
|
+
return out
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def write_store(path, snapshot: dict) -> None:
|
|
32
|
+
"""The single snapshot table chap-coordinator wrote before 0.3.2."""
|
|
33
|
+
con = sqlite3.connect(path)
|
|
34
|
+
con.execute("CREATE TABLE chap_workspaces (id TEXT PRIMARY KEY, version INTEGER NOT NULL, "
|
|
35
|
+
"data TEXT NOT NULL, updated_at TEXT NOT NULL)")
|
|
36
|
+
con.execute("INSERT INTO chap_workspaces VALUES (?, 1, ?, '2026-01-01T00:00:00Z')",
|
|
37
|
+
(snapshot["id"], json.dumps(snapshot)))
|
|
38
|
+
con.commit()
|
|
39
|
+
con.close()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_a_typescript_snapshot_projects_to_the_same_tables(tmp_path):
|
|
43
|
+
chain = support_desk()
|
|
44
|
+
snapshot = {**chain.state, "id": chain.workspace, "audit": chain.events}
|
|
45
|
+
python_store, ts_store = tmp_path / "py.db", tmp_path / "ts.db"
|
|
46
|
+
write_store(python_store, snapshot)
|
|
47
|
+
write_store(ts_store, as_typescript(snapshot))
|
|
48
|
+
assert isinstance(json.loads(sqlite3.connect(ts_store).execute("SELECT data FROM chap_workspaces").fetchone()[0])["tasks"], list)
|
|
49
|
+
a = frames(from_sqlite(str(python_store)))
|
|
50
|
+
b = frames(from_sqlite(str(ts_store)))
|
|
51
|
+
for name in ("tasks", "decisions", "overrides", "events"):
|
|
52
|
+
pd.testing.assert_frame_equal(getattr(a, name), getattr(b, name), check_like=True)
|
|
53
|
+
assert len(b.tasks) == len(a.tasks) > 0
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_from_json_reads_a_typescript_snapshot(tmp_path):
|
|
57
|
+
chain = support_desk()
|
|
58
|
+
path = tmp_path / "ts.json"
|
|
59
|
+
path.write_text(json.dumps(as_typescript({**chain.state, "id": chain.workspace, "audit": chain.events})))
|
|
60
|
+
b = frames(from_json(str(path)))
|
|
61
|
+
a = frames(chain)
|
|
62
|
+
pd.testing.assert_frame_equal(a.tasks, b.tasks, check_like=True)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def write_rows(path, snapshot: dict) -> None:
|
|
66
|
+
"""The tables chap-coordinator 0.3.2 and later write, one row per entry and object."""
|
|
67
|
+
con = sqlite3.connect(path)
|
|
68
|
+
con.executescript(
|
|
69
|
+
"CREATE TABLE chap_meta (workspace TEXT PRIMARY KEY, data TEXT NOT NULL, "
|
|
70
|
+
"version INTEGER NOT NULL, updated_at TEXT NOT NULL);"
|
|
71
|
+
"CREATE TABLE chap_entries (workspace TEXT NOT NULL, seq INTEGER NOT NULL, "
|
|
72
|
+
"data TEXT NOT NULL, PRIMARY KEY (workspace, seq));"
|
|
73
|
+
"CREATE TABLE chap_objects (workspace TEXT NOT NULL, collection TEXT NOT NULL, "
|
|
74
|
+
"id TEXT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (workspace, collection, id));")
|
|
75
|
+
ws = snapshot["id"]
|
|
76
|
+
meta = {k: v for k, v in snapshot.items() if k not in KEYS and k not in ("audit", "idempotency_keys")}
|
|
77
|
+
con.execute("INSERT INTO chap_meta VALUES (?, ?, ?, '2026-01-01T00:00:00Z')",
|
|
78
|
+
(ws, json.dumps(meta), len(snapshot["audit"])))
|
|
79
|
+
# Out of order on purpose: the reader orders the log by seq.
|
|
80
|
+
for e in reversed(snapshot["audit"]):
|
|
81
|
+
con.execute("INSERT INTO chap_entries VALUES (?, ?, ?)", (ws, e["seq"], json.dumps(e)))
|
|
82
|
+
for name, key in KEYS.items():
|
|
83
|
+
items = snapshot.get(name) or {}
|
|
84
|
+
for item in (items.values() if isinstance(items, dict) else items):
|
|
85
|
+
con.execute("INSERT INTO chap_objects VALUES (?, ?, ?, ?)", (ws, name, item[key], json.dumps(item)))
|
|
86
|
+
con.commit()
|
|
87
|
+
con.close()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_a_store_with_a_row_per_entry_projects_to_the_same_tables(tmp_path):
|
|
91
|
+
chain = support_desk()
|
|
92
|
+
snapshot = {**chain.state, "id": chain.workspace, "audit": chain.events}
|
|
93
|
+
single, rows = tmp_path / "single.db", tmp_path / "rows.db"
|
|
94
|
+
write_store(single, snapshot)
|
|
95
|
+
write_rows(rows, snapshot)
|
|
96
|
+
a = frames(from_sqlite(str(single)))
|
|
97
|
+
b = frames(from_sqlite(str(rows)))
|
|
98
|
+
for name in ("tasks", "decisions", "overrides", "events"):
|
|
99
|
+
pd.testing.assert_frame_equal(getattr(a, name), getattr(b, name), check_like=True)
|
|
100
|
+
assert len(b.events) == len(chain.events) > 0
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_the_coordinator_store_reads_back(tmp_path):
|
|
104
|
+
"""A file the Python coordinator's own SqliteStore wrote, end to end."""
|
|
105
|
+
from chap_coordinator.storage.sqlite import SqliteStore
|
|
106
|
+
from chap_coordinator.storage.store import WorkspaceRecord
|
|
107
|
+
|
|
108
|
+
chain = support_desk()
|
|
109
|
+
snapshot = {**chain.state, "id": chain.workspace, "audit": chain.events}
|
|
110
|
+
path = tmp_path / "store.db"
|
|
111
|
+
store = SqliteStore(str(path))
|
|
112
|
+
store.save(WorkspaceRecord(id=chain.workspace, data=snapshot, version=1, updated_at="t"))
|
|
113
|
+
store.close()
|
|
114
|
+
a = frames(chain)
|
|
115
|
+
b = frames(from_sqlite(str(path)))
|
|
116
|
+
for name in ("tasks", "decisions", "overrides", "events"):
|
|
117
|
+
pd.testing.assert_frame_equal(getattr(a, name), getattr(b, name), check_like=True)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_naming_a_workspace_in_a_store_with_rows(tmp_path):
|
|
121
|
+
chain = support_desk()
|
|
122
|
+
snapshot = {**chain.state, "id": chain.workspace, "audit": chain.events}
|
|
123
|
+
path = tmp_path / "rows.db"
|
|
124
|
+
write_rows(path, snapshot)
|
|
125
|
+
con = sqlite3.connect(path)
|
|
126
|
+
con.execute("INSERT INTO chap_meta VALUES ('wsp_other', '{\"id\": \"wsp_other\"}', 0, 't')")
|
|
127
|
+
con.commit()
|
|
128
|
+
con.close()
|
|
129
|
+
try:
|
|
130
|
+
from_sqlite(str(path))
|
|
131
|
+
except ValueError as exc:
|
|
132
|
+
assert "2 workspaces" in str(exc) and chain.workspace in str(exc)
|
|
133
|
+
else:
|
|
134
|
+
raise AssertionError("two workspaces need a name")
|
|
135
|
+
assert from_sqlite(str(path), workspace="wsp_other").events == []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|