strata-python 0.2.7__tar.gz → 0.2.8__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.
Files changed (85) hide show
  1. {strata_python-0.2.7 → strata_python-0.2.8}/CHANGELOG.md +6 -0
  2. {strata_python-0.2.7 → strata_python-0.2.8}/PKG-INFO +3 -2
  3. {strata_python-0.2.7 → strata_python-0.2.8}/README.md +2 -1
  4. {strata_python-0.2.7 → strata_python-0.2.8}/pyproject.toml +1 -1
  5. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/clients/models.py +54 -0
  6. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/testing.py +40 -4
  7. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_clients_models.py +29 -0
  8. {strata_python-0.2.7 → strata_python-0.2.8}/.gitignore +0 -0
  9. {strata_python-0.2.7 → strata_python-0.2.8}/LICENSE +0 -0
  10. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/__init__.py +0 -0
  11. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/check.py +0 -0
  12. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/cli.py +0 -0
  13. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/client.py +0 -0
  14. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/clients/__init__.py +0 -0
  15. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/contracts.py +0 -0
  16. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/__init__.py +0 -0
  17. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/__main__.py +0 -0
  18. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/_alembic/env.py +0 -0
  19. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/_alembic/script.py.mako +0 -0
  20. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/cli.py +0 -0
  21. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/config.py +0 -0
  22. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/engine.py +0 -0
  23. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/guard.py +0 -0
  24. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/migrations.py +0 -0
  25. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/models.py +0 -0
  26. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/project.py +0 -0
  27. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/pytest_plugin.py +0 -0
  28. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/scratch.py +0 -0
  29. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/settings.py +0 -0
  30. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/testing.py +0 -0
  31. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/testserver.py +0 -0
  32. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/db/web.py +0 -0
  33. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/files.py +0 -0
  34. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/http.py +0 -0
  35. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/http_server.py +0 -0
  36. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/images.py +0 -0
  37. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/live.py +0 -0
  38. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/media.py +0 -0
  39. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/mediatime.py +0 -0
  40. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/oslib.py +0 -0
  41. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/pages/__init__.py +0 -0
  42. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/pages/model.py +0 -0
  43. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/pages/render.py +0 -0
  44. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/public_check.py +0 -0
  45. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/py.typed +0 -0
  46. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/pytest_plugin.py +0 -0
  47. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/settings.py +0 -0
  48. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/stats.py +0 -0
  49. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/__init__.py +0 -0
  50. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/child.py +0 -0
  51. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/flight.py +0 -0
  52. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/progress.py +0 -0
  53. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/queue.py +0 -0
  54. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/retry.py +0 -0
  55. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/status.py +0 -0
  56. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/tasks/ticker.py +0 -0
  57. {strata_python-0.2.7 → strata_python-0.2.8}/src/strata_python/web.py +0 -0
  58. {strata_python-0.2.7 → strata_python-0.2.8}/tests/conftest.py +0 -0
  59. {strata_python-0.2.7 → strata_python-0.2.8}/tests/integration/test_db_cli.py +0 -0
  60. {strata_python-0.2.7 → strata_python-0.2.8}/tests/integration/test_serve.py +0 -0
  61. {strata_python-0.2.7 → strata_python-0.2.8}/tests/integration/test_strata_check.py +0 -0
  62. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/job_handlers.py +0 -0
  63. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_check.py +0 -0
  64. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_cli.py +0 -0
  65. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_client.py +0 -0
  66. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_contracts.py +0 -0
  67. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_db.py +0 -0
  68. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_files.py +0 -0
  69. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_http.py +0 -0
  70. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_http_server.py +0 -0
  71. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_images.py +0 -0
  72. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_live.py +0 -0
  73. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_media.py +0 -0
  74. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_mediatime.py +0 -0
  75. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_oslib.py +0 -0
  76. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_package.py +0 -0
  77. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_pages.py +0 -0
  78. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_plugin.py +0 -0
  79. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_public_check.py +0 -0
  80. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_queue.py +0 -0
  81. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_settings.py +0 -0
  82. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_stats.py +0 -0
  83. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_tasks.py +0 -0
  84. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_testing.py +0 -0
  85. {strata_python-0.2.7 → strata_python-0.2.8}/tests/unit/test_web.py +0 -0
@@ -4,6 +4,12 @@ What each release adds or changes for an app that depends on strata-python, newe
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.2.8 (2026-11-23)
8
+
9
+ ### Added
10
+
11
+ - `clients.models.run_with_provenance(...)` returns `(result, Provenance)`: the job's `model`, the load `options` it ran with, its `settings_hash` and `job_id`; `Provenance.from_job(row)` reads the same from any job row. `clients.models.role_settings(role)` returns `RoleSettings(model, settings_hash)`. Key a result cache on `(model, settings_hash)` so it is made again when strata-models changes a model's options under the same key (strata-models #103; the hash and options are None from a service older than that). `FakeModels.options[role]` sets the stand-in's load options, and its jobs and registry carry the same fields.
12
+
7
13
  ## 0.2.7 (2026-11-23)
8
14
 
9
15
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: strata-python
3
- Version: 0.2.7
3
+ Version: 0.2.8
4
4
  Summary: Common code for Python web server apps: OS helpers, settings, FastAPI serving, CLI commands, test fixtures and the strata-check gate
5
5
  Project-URL: Homepage, https://github.com/jburnhams/strata-python
6
6
  Project-URL: Source, https://github.com/jburnhams/strata-python
@@ -64,7 +64,7 @@ Common code for the strata Python web server apps (FastAPI + CLI), the Python co
64
64
  | `strata_python.mediatime` | Exact time for media: `rational` seconds (Fraction), `Rate` (`frame_at`, `time_of`, `snap`), half-open `Span`, and `TimeMap` from an edit's output time to its sources and back, with exact JSON |
65
65
  | `strata_python.images` (extra `[images]`) | `thumbnail(src, px, cache_dir=...)` (an upright JPEG, made once, keyed on the file, never enlarged, the app's own reader through `make=`), `open_upright`, `flatten` (alpha and 16-bit greys to 8-bit RGB), `jpeg_bytes` |
66
66
  | `strata_python.stats` | Pairwise rankings and eval statistics in pure Python: `bradley_terry` (ties, an optional side advantage, Elo-scale `ratings()`), `intervals` (bootstrap), `head_to_head`, `votes_from(judgments)`, `wilson`, `mcnemar`, `holm` |
67
- | `strata_python.clients.models` | The strata-models client, standard library only: `run`, `submit`, `wait`, `role_model`, `gpu_lease`, a shortcut for every role the service runs (`faces`, `face_kind`, `transcribe`, `ocr`, `speak`, `denoise_audio`, `audio_quality`, `generate_image`, `embed`, `enhance_video`, and `ask` for the language models) and a typed result for each |
67
+ | `strata_python.clients.models` | The strata-models client, standard library only: `run`, `submit`, `wait`, `role_model`, `run_with_provenance` and `role_settings` (the model and settings a result was made with, for cache keys), `gpu_lease`, a shortcut for every role the service runs (`faces`, `face_kind`, `transcribe`, `ocr`, `speak`, `denoise_audio`, `audio_quality`, `generate_image`, `embed`, `enhance_video`, and `ask` for the language models) and a typed result for each |
68
68
  | `strata_python.http_server` / `live` | A real scripted HTTP server and a real uvicorn server on loopback, for tests that make actual requests |
69
69
  | pytest plugin | Loaded automatically: hermetic home and data folders (`strata_env` adds the app's own variables), a no-network guard, `http_server` and `live_app`, the `fake_urlopen`, `fake_popen`, `fake_run` and `no_sleep` fixtures, `fake_models` (a stand-in strata-models), and the `integration` marker on everything under `tests/integration` |
70
70
  | `strata_python.testing` | The fakes behind those fixtures (`FakeResponse`, `http_error`, `FakeUrlopen`, `FakePopen`, `FakeRun`, `Sleeper`) `FakeModels`, the CLI runners `run_cli(main, *args)` and `run_module("myapp", *args, src=...)`, and `assert_openapi_current(create_app, path)` |
@@ -406,6 +406,7 @@ migrations = "migrations" # the app's Alembic revisions, unchanged
406
406
 
407
407
  add_database(app, Project.load(__file__), default=lambda: local_url(SETTINGS))
408
408
 
409
+
409
410
  @app.get("/api/notes")
410
411
  def notes(db: DbSession) -> list[NoteOut]: ...
411
412
  ```
@@ -17,7 +17,7 @@ Common code for the strata Python web server apps (FastAPI + CLI), the Python co
17
17
  | `strata_python.mediatime` | Exact time for media: `rational` seconds (Fraction), `Rate` (`frame_at`, `time_of`, `snap`), half-open `Span`, and `TimeMap` from an edit's output time to its sources and back, with exact JSON |
18
18
  | `strata_python.images` (extra `[images]`) | `thumbnail(src, px, cache_dir=...)` (an upright JPEG, made once, keyed on the file, never enlarged, the app's own reader through `make=`), `open_upright`, `flatten` (alpha and 16-bit greys to 8-bit RGB), `jpeg_bytes` |
19
19
  | `strata_python.stats` | Pairwise rankings and eval statistics in pure Python: `bradley_terry` (ties, an optional side advantage, Elo-scale `ratings()`), `intervals` (bootstrap), `head_to_head`, `votes_from(judgments)`, `wilson`, `mcnemar`, `holm` |
20
- | `strata_python.clients.models` | The strata-models client, standard library only: `run`, `submit`, `wait`, `role_model`, `gpu_lease`, a shortcut for every role the service runs (`faces`, `face_kind`, `transcribe`, `ocr`, `speak`, `denoise_audio`, `audio_quality`, `generate_image`, `embed`, `enhance_video`, and `ask` for the language models) and a typed result for each |
20
+ | `strata_python.clients.models` | The strata-models client, standard library only: `run`, `submit`, `wait`, `role_model`, `run_with_provenance` and `role_settings` (the model and settings a result was made with, for cache keys), `gpu_lease`, a shortcut for every role the service runs (`faces`, `face_kind`, `transcribe`, `ocr`, `speak`, `denoise_audio`, `audio_quality`, `generate_image`, `embed`, `enhance_video`, and `ask` for the language models) and a typed result for each |
21
21
  | `strata_python.http_server` / `live` | A real scripted HTTP server and a real uvicorn server on loopback, for tests that make actual requests |
22
22
  | pytest plugin | Loaded automatically: hermetic home and data folders (`strata_env` adds the app's own variables), a no-network guard, `http_server` and `live_app`, the `fake_urlopen`, `fake_popen`, `fake_run` and `no_sleep` fixtures, `fake_models` (a stand-in strata-models), and the `integration` marker on everything under `tests/integration` |
23
23
  | `strata_python.testing` | The fakes behind those fixtures (`FakeResponse`, `http_error`, `FakeUrlopen`, `FakePopen`, `FakeRun`, `Sleeper`) `FakeModels`, the CLI runners `run_cli(main, *args)` and `run_module("myapp", *args, src=...)`, and `assert_openapi_current(create_app, path)` |
@@ -359,6 +359,7 @@ migrations = "migrations" # the app's Alembic revisions, unchanged
359
359
 
360
360
  add_database(app, Project.load(__file__), default=lambda: local_url(SETTINGS))
361
361
 
362
+
362
363
  @app.get("/api/notes")
363
364
  def notes(db: DbSession) -> list[NoteOut]: ...
364
365
  ```
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "strata-python"
7
- version = "0.2.7" # the single source of truth: `strata_python.__version__` reads it back with importlib.metadata
7
+ version = "0.2.8" # the single source of truth: `strata_python.__version__` reads it back with importlib.metadata
8
8
  description = "Common code for Python web server apps: OS helpers, settings, FastAPI serving, CLI commands, test fixtures and the strata-check gate"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -142,6 +142,42 @@ def run(
142
142
  return wait(int(submit(role, params, app, priority, model)["id"]), timeout)
143
143
 
144
144
 
145
+ @dataclass(frozen=True)
146
+ class Provenance:
147
+ """What a run job's output was made with, from its row: the model key, its load options as the job ran (the
148
+ service's models.toml options merged with the job's own) and `settings_hash`, which changes when the model's
149
+ runtime, file or options do even under the same key. Key a cache on (model, settings_hash). The options and hash
150
+ are None on rows from a service older than the one that records them."""
151
+
152
+ model: str | None
153
+ options: Json | None
154
+ settings_hash: str | None
155
+ job_id: int
156
+
157
+ @classmethod
158
+ def from_job(cls, job: Json) -> Provenance:
159
+ options = job.get("options")
160
+ return cls(
161
+ _opt_str(job, "model"), cast("Json", options) if isinstance(options, dict) else None,
162
+ _opt_str(job, "settings_hash"), int(job["id"]),
163
+ ) # fmt: skip
164
+
165
+
166
+ def run_with_provenance(
167
+ role: str,
168
+ params: Mapping[str, Any] | None,
169
+ app: str,
170
+ priority: Priority = "normal",
171
+ model: str | None = None,
172
+ timeout: float | None = None,
173
+ ) -> tuple[Json, Provenance]:
174
+ """`run`, plus what the result was made with (`Provenance`): for an app that stores each result with its model
175
+ and settings, and keys its cache on them."""
176
+ job_id = int(submit(role, params, app, priority, model)["id"])
177
+ result = wait(job_id, timeout)
178
+ return result, Provenance.from_job(_call("GET", f"/api/jobs/{job_id}"))
179
+
180
+
145
181
  ROLES = (
146
182
  "faces",
147
183
  "face-kind",
@@ -338,6 +374,24 @@ def role_model(role: str) -> str | None:
338
374
  return next((cast("str", r["model"]) for r in roles if r["key"] == role), None)
339
375
 
340
376
 
377
+ @dataclass(frozen=True)
378
+ class RoleSettings:
379
+ """The model that serves a role now and its `settings_hash` (see `Provenance`); the hash is None from a service
380
+ older than the one that reports it."""
381
+
382
+ model: str
383
+ settings_hash: str | None
384
+
385
+
386
+ def role_settings(role: str) -> RoleSettings | None:
387
+ """`role_model` with the settings hash: a cache keyed on both is made again when the role's model changes, and
388
+ also when that model's options change under the same key (a threshold in the service's models.toml). None for an
389
+ unknown role."""
390
+ roles = cast("list[Json]", _call("GET", "/api/registry").get("roles", []))
391
+ r = next((r for r in roles if r["key"] == role), None)
392
+ return None if r is None else RoleSettings(str(r["model"]), _opt_str(r, "settings_hash"))
393
+
394
+
341
395
  class Lease:
342
396
  """A held lease: `.id`, `.job` (the row when granted). Heartbeats run on a daemon thread until `release()`."""
343
397
 
@@ -34,7 +34,7 @@ from collections.abc import Callable, Mapping, Sequence
34
34
  from dataclasses import dataclass, field
35
35
  from email.message import Message
36
36
  from pathlib import Path
37
- from typing import Any, ClassVar
37
+ from typing import Any, ClassVar, cast
38
38
 
39
39
  Body = bytes | str | Any # bytes and str are sent as they are; anything else as JSON
40
40
 
@@ -328,13 +328,17 @@ class FakeModels:
328
328
 
329
329
  `running_polls` is how many polls a job answers `running` before it finishes (default 1, as the real service
330
330
  usually is when the first poll arrives). A role with no result is refused with a 422, as the service refuses a role
331
- it does not know. The registry answers each role's model from `.models` (role -> model name)."""
331
+ it does not know. The registry answers each role's model from `.models` (role -> model name). A job records the
332
+ settings it ran with when it starts, as the service does: `options` (`.options[role]`, the role's load options,
333
+ merged with the job's own) and `settings_hash` (a hash of the model and those options, also on the registry's roles),
334
+ so changing `.options` mid-test shows what an app's cache does when the service's settings change."""
332
335
 
333
336
  def __init__(self, results: Mapping[str, Result] | None = None, *, running_polls: int = 1) -> None:
334
337
  from fastapi import FastAPI, HTTPException, Request # here, so importing the fakes does not load FastAPI
335
338
 
336
339
  self.results: dict[str, Result] = dict(MODELS_RESULTS if results is None else results)
337
340
  self.models: dict[str, str] = {}
341
+ self.options: dict[str, Json] = {} # role -> the model's load options (the service's models.toml)
338
342
  self.running_polls = running_polls
339
343
  self.jobs: list[Json] = [] # every job submitted, in order, as the service stored it
340
344
  self.leases: list[Json] = []
@@ -345,6 +349,7 @@ class FakeModels:
345
349
  self.down = False
346
350
  self._failures: list[tuple[str | None, str]] = []
347
351
  self._polls: dict[int, int] = {}
352
+ self._asked: dict[int, Json] = {} # job id -> the load options its submit asked for
348
353
  app = FastAPI()
349
354
  self.app = app
350
355
 
@@ -362,14 +367,25 @@ class FakeModels:
362
367
 
363
368
  @app.get("/api/registry")
364
369
  def registry() -> Json: # pyright: ignore[reportUnusedFunction]
365
- return {"roles": [{"key": r, "model": self.models.get(r, f"fake-{r}")} for r in self.results]}
370
+ return {
371
+ "roles": [{"key": r, "model": self._model(r), "settings_hash": self._hash(r)} for r in self.results]
372
+ }
366
373
 
367
374
  @app.post("/api/jobs")
368
375
  def submit(body: Json) -> Json: # pyright: ignore[reportUnusedFunction]
369
376
  role = str(body.get("role"))
370
377
  if role not in self.results:
371
378
  raise HTTPException(422, f"unknown role {role!r}")
372
- job: Json = {**body, "id": len(self.jobs) + 1, "status": "queued", "result": None, "error": None}
379
+ job: Json = {
380
+ **body,
381
+ "id": len(self.jobs) + 1,
382
+ "status": "queued",
383
+ "result": None,
384
+ "error": None,
385
+ "options": None, # what it runs with, recorded when it starts; the variant asked for is kept apart
386
+ "settings_hash": None,
387
+ }
388
+ self._asked[job["id"]] = cast("Json", body.get("options") or {})
373
389
  self.jobs.append(job)
374
390
  return dict(job)
375
391
 
@@ -378,6 +394,8 @@ class FakeModels:
378
394
  job = self._job(job_id, HTTPException)
379
395
  if job["status"] in ("queued", "running"):
380
396
  n = self._polls[job_id] = self._polls.get(job_id, 0) + 1
397
+ if job["status"] == "queued":
398
+ self._start(job)
381
399
  if n <= self.running_polls:
382
400
  job["status"] = "running"
383
401
  else:
@@ -414,6 +432,24 @@ class FakeModels:
414
432
  self._failures.append((role, error))
415
433
  return self
416
434
 
435
+ def _model(self, role: str, model: object = None) -> str:
436
+ return str(model) if model else self.models.get(role, f"fake-{role}")
437
+
438
+ def _hash(self, role: str, model: object = None, asked: Json | None = None) -> str:
439
+ import hashlib
440
+
441
+ options = {**self.options.get(role, {}), **(asked or {})}
442
+ text = json.dumps([self._model(role, model), options], sort_keys=True, default=str)
443
+ return hashlib.sha256(text.encode()).hexdigest()[:12]
444
+
445
+ def _start(self, job: Json) -> None:
446
+ role, asked = str(job["role"]), self._asked.get(int(job["id"]), {})
447
+ job.update(
448
+ model=self._model(role, job.get("model")),
449
+ options={**self.options.get(role, {}), **asked},
450
+ settings_hash=self._hash(role, job.get("model"), asked),
451
+ )
452
+
417
453
  def _finish(self, job: Json) -> None:
418
454
  for i, (role, error) in enumerate(self._failures):
419
455
  if role is None or role == job["role"]:
@@ -186,3 +186,32 @@ def test_the_other_typed_results():
186
186
  assert (v.fps, v.frames, v.crops[0].box, v.crops[0].stills, v.quality["skipped"]) == (
187
187
  50.0, 400, (100, 50, 80, 80), ["/out/v-face-3.png"], "no numpy",
188
188
  ) # fmt: skip
189
+
190
+
191
+ def test_a_result_with_what_made_it_and_the_settings_a_cache_keys_on(service):
192
+ service.models["shot-boundaries"] = "scene-score"
193
+ service.results["shot-boundaries"] = {"cuts": []}
194
+ service.options["shot-boundaries"] = {"threshold": 0.3}
195
+ now = sm.role_settings("shot-boundaries")
196
+ assert now is not None
197
+ assert (now.model, len(now.settings_hash or "")) == ("scene-score", 12)
198
+ result, p = sm.run_with_provenance("shot-boundaries", {"path": "/v.mp4"}, app="strata-reels")
199
+ assert result == {"cuts": []}
200
+ assert p == sm.Provenance("scene-score", {"threshold": 0.3}, now.settings_hash, p.job_id)
201
+ assert service.jobs[p.job_id - 1]["settings_hash"] == now.settings_hash
202
+ service.options["shot-boundaries"] = {"threshold": 0.4} # the service's models.toml changed, the key did not
203
+ later = sm.role_settings("shot-boundaries")
204
+ assert later is not None
205
+ assert later.model == now.model
206
+ assert later.settings_hash != now.settings_hash
207
+ _, q = sm.run_with_provenance("shot-boundaries", {"path": "/v.mp4"}, app="strata-reels")
208
+ assert (q.options, q.settings_hash) == ({"threshold": 0.4}, later.settings_hash)
209
+ job = sm.submit("shot-boundaries", {}, app="evals", options={"width": 320})
210
+ assert (job["options"], job["settings_hash"]) == (None, None) # recorded when it starts
211
+ assert sm.Provenance.from_job(sm.wait_job(job["id"])).options == {"threshold": 0.4, "width": 320}
212
+ assert sm.role_settings("nope") is None
213
+
214
+
215
+ def test_provenance_from_a_row_of_an_older_service():
216
+ p = sm.Provenance.from_job({"id": 7, "model": "buffalo_l", "status": "done"})
217
+ assert p == sm.Provenance("buffalo_l", None, None, 7)
File without changes
File without changes