mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
update: the engine of a model shape (Inkling-2-Mini) in --check, the notice and the summary; no Strata engine for an Inkling-only PC (PLAN-0224 items 26-29)
Found by the 0.1.71 client checks on an Inkling-only PC, reproduced here with failing tests first (10 of the new tests failed on main).
- 26 `strata update --check` lists each installed model-shape engine (installed, offered, size, status) and points to `strata update`; the JSON report has `shape_engines`.
- 27 an Inkling-only PC (no Strata engine, at least one shape engine) has no Strata-engine step: the check says "not-used", the consent question no longer names an engine that would be installed (the Monitor's `u` asked to stop the model for "engine 0.1.69" and installed 920 MB the person never had), and an update installs none. A PC with a Strata engine, or with no engine at all, is as before.
- 28 the last check keeps the newer shape engines it found; the start screen's quiet line, the monitor's note and `strata components engine` offer them ("A new engine 0.1.71 for Inkling-2-Mini (you have 0.1.70) is available"). The offer is dropped when the installed shape engine changes.
- 29 after an update the summary names the model, not the component id, and when a model was serving during the update it says "Restart the model to use it: the one that is running keeps the old engine."
Tests: terminal/tests/terminal/test_update_shape_engines_0225.py (new); the update, shape engine, notice, library and launch engine tests pass (227 + 157).
This commit is contained in:
1 parent
03bb4f48ba
commit
3fe4a1c7a7
6 files changed
+322
-23
No files matched your search
@@ -223,8 +223,14 @@ def _print_check(report: dict) -> None:
|
||||
if eng.get("installed_locally") else f"update available: {installed} -> {offered} ({_mib(eng['download_bytes'])})"),
|
||||
"install": f"no engine installed yet; {offered} is the one for this PC ({_mib(eng['download_bytes'])})",
|
||||
"current": f"{installed} is up to date", "none-for-this-pc": eng.get("note") or "the feed has no engine for this PC", "wrong-make": eng.get("note") or "nothing was changed",
|
||||
"not-in-feed": "the feed lists no engines"}.get(eng["status"], eng.get("note") or eng["status"])
|
||||
"not-in-feed": "the feed lists no engines", "not-used": eng.get("note") or "not needed on this PC"}.get(eng["status"], eng.get("note") or eng["status"])
|
||||
print(f" Engine {text}")
|
||||
shapes = report.get("shape_engines") or []
|
||||
for row in shapes: # the engine of a model of its own (Inkling-2-Mini's), installed beside the Strata engine
|
||||
have, new = row.get("installed"), row.get("offered")
|
||||
what = {"available": f"update available: {have} -> {new} ({_mib(row.get('download_bytes'))})", "current": f"{have} is up to date"}.get(
|
||||
row["status"], row.get("note") or row["status"])
|
||||
print(f" Engine for {row.get('title') or row['shape']} {what}")
|
||||
pick = eng.get("offered")
|
||||
if pick and eng["status"] in ("available", "install", "current"):
|
||||
# round 8, N9: the list below names only the packages that were NOT chosen; say which one was
|
||||
@@ -249,7 +255,7 @@ def _print_check(report: dict) -> None:
|
||||
from strata_control import engine_update
|
||||
names = ", ".join(m.label for m in engine_update.running_models(report["serving"]))
|
||||
print(f" {names} is running. An update asks before it stops it, downloads while it keeps serving, and asks whether to start it again.")
|
||||
if eng.get("status") in ("available", "install") and not report.get("serving"):
|
||||
if (eng.get("status") in ("available", "install") or any(r.get("status") == "available" for r in shapes)) and not report.get("serving"):
|
||||
print(" To update: strata update")
|
||||
|
||||
|
||||
@@ -482,6 +488,8 @@ def _engines_command(a, ctx, machine: bool, fail) -> int:
|
||||
print(f"Engine {out['to']} is now in use. Models you start from now on run on it.")
|
||||
print(f"The engine for {ec.MAKE_NAMES[out['backend_saved']]} cards is used, now and next time. "
|
||||
"`strata launch --backend auto` goes back to the PC's own choice.")
|
||||
elif out.get("from") == out["to"]: # the pin sat on the newest engine itself (after `components rollback` twice): no switch, the pin is gone
|
||||
print(f"Engine {out['to']} was pinned; it is the newest, so it is chosen by itself now and follows updates again.")
|
||||
else:
|
||||
print(f"Engine {out['to']} is now in use (was {out.get('from') or 'none'}). Models you start from now on run on it.")
|
||||
if out.get("backend_saved"):
|
||||
|
||||
@@ -209,7 +209,9 @@ def cached_notice(root: Path | None = None) -> str | None:
|
||||
The notice belongs to the versions the check was made for: it is dropped when Control or the installed engine is not the one
|
||||
recorded then (an app install, an update, a rollback), and an engine that is not newer than the installed one is never offered."""
|
||||
offers = cached_offers(root)
|
||||
parts = ([f"engine {offers['engine']}"] if offers.get("engine") else []) + ([f"app {offers['app']}"] if offers.get("app") else [])
|
||||
parts = ([f"engine {offers['engine']}"] if offers.get("engine") else []) + \
|
||||
[f"engine {row['version']} for {row.get('title') or shape}" for shape, row in (offers.get("shapes") or {}).items()] + \
|
||||
([f"app {offers['app']}"] if offers.get("app") else [])
|
||||
return f"update available ({', '.join(parts)}): run `strata update`" if parts else None
|
||||
|
||||
|
||||
@@ -218,7 +220,7 @@ def cached_offers(root: Path | None = None) -> dict:
|
||||
check, the installed packages), never the network. The same rules as `cached_notice`: it belongs to the Control and the packages it was made for,
|
||||
and a package that is not newer than the installed one is never offered."""
|
||||
base = root or components_dir()
|
||||
none = {"engine": None, "app": None}
|
||||
none = {"engine": None, "app": None, "shapes": {}}
|
||||
try:
|
||||
last = (json.loads((base / UPDATE_STATE).read_text(encoding="utf-8-sig")).get("last_check") or {})
|
||||
except (OSError, ValueError, AttributeError):
|
||||
@@ -234,7 +236,28 @@ def cached_offers(root: Path | None = None) -> dict:
|
||||
engine = None
|
||||
if engine and installed and _version_key(str(engine)) <= _version_key(installed):
|
||||
engine = None
|
||||
return {"engine": engine or None, "app": app or None}
|
||||
return {"engine": engine or None, "app": app or None, "shapes": _cached_shape_offers(last, base)}
|
||||
|
||||
|
||||
def _cached_shape_offers(last: dict, base: Path) -> dict:
|
||||
"""The engines of model shapes (Inkling-2-Mini's) the last check found newer: {shape: {"version", "title", "installed"}}. Same rules as the Strata engine's: a shape
|
||||
engine that is installed now at another version than the one the check was made for, or that is not older than the offer, is not offered."""
|
||||
out: dict = {}
|
||||
shapes = last.get("shapes")
|
||||
if not isinstance(shapes, dict):
|
||||
return out
|
||||
try:
|
||||
from strata_control import shape_engine
|
||||
except Exception: # noqa: BLE001 - informational only
|
||||
return out
|
||||
for shape, row in shapes.items():
|
||||
if not isinstance(row, dict) or not shape_engine.valid(shape) or not row.get("version"):
|
||||
continue
|
||||
have = shape_engine.newest_version(shape, base)
|
||||
if not have or have != row.get("installed") or _version_key(str(row["version"])) <= _version_key(have):
|
||||
continue
|
||||
out[shape] = {"version": str(row["version"]), "title": str(row.get("title") or shape), "installed": have}
|
||||
return out
|
||||
|
||||
|
||||
def previous_folder(root: Path | None = None) -> str | None:
|
||||
|
||||
@@ -45,13 +45,16 @@ def notice(root=None) -> dict | None:
|
||||
"""What the last check found newer, as {"engine": v, "have": {...}, "line": plain sentence}, or None. Local files only."""
|
||||
offers = ec.cached_offers(root)
|
||||
engine = offers.get("engine")
|
||||
if not engine:
|
||||
return None
|
||||
shapes = offers.get("shapes") or {}
|
||||
have = _installed_words(root)
|
||||
if not have["engine"]: # no engine yet: the launch installs the newest one itself, so there is nothing to update first
|
||||
if engine and not have["engine"]: # no engine yet: the launch installs the newest one itself, so there is nothing to update first
|
||||
engine = None
|
||||
if not engine and not shapes:
|
||||
return None
|
||||
head ="A new " + f"engine {engine}" + (f" (you have {have['engine']})" if have["engine"] else "") + " is available"
|
||||
return {"engine": engine, "have": have, "line": head}
|
||||
parts = ([f"engine {engine} (you have {have['engine']})"] if engine else []) + \
|
||||
[f"engine {row['version']} for {row.get('title') or shape} (you have {row.get('installed')})" for shape, row in shapes.items()] # 0.2.25: the engine of an Inkling-2-Mini or other model-shape install
|
||||
head = "A new " + " and a new ".join(parts) + (" is" if len(parts) == 1 else " are") + " available"
|
||||
return {"engine": engine, "shapes": shapes, "have": have, "line": head}
|
||||
|
||||
|
||||
def notice_line(root=None, how: str = f"Update with {NEXT_STEP}.") -> str | None:
|
||||
@@ -138,7 +141,11 @@ def monitor_note(root=None) -> str | None:
|
||||
found = notice(root)
|
||||
if found is None:
|
||||
return None
|
||||
return f"New engine {found['engine']} is available. Press u to update."
|
||||
if not found.get("shapes"):
|
||||
return f"New engine {found['engine']} is available. Press u to update."
|
||||
parts = ([f"engine {found['engine']}"] if found.get("engine") else []) + \
|
||||
[f"engine {row['version']} for {row.get('title') or shape}" for shape, row in found["shapes"].items()]
|
||||
return "New " + " and ".join(parts) + (" is" if len(parts) == 1 else " are") + " available. Press u to update."
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------- models that are loaded
|
||||
@@ -438,14 +445,26 @@ def build_context(root=None, feed: str | None = None, emit: Callable[[dict], Non
|
||||
def summary(out: dict) -> str:
|
||||
"""One plain sentence for what an update did, for a screen that has one line (the monitor)."""
|
||||
parts = []
|
||||
restart = False
|
||||
for r in out.get("results", []):
|
||||
name = {"engine": "Engine", "control": "Control"}.get(r.get("component"), str(r.get("component")))
|
||||
status = r.get("status")
|
||||
if r.get("shape"): # the engine of a model shape (Inkling-2-Mini's): named by the model, never by its component id
|
||||
who = f"The engine for {r.get('title') or r.get('shape')}"
|
||||
if status in ("updated", "installed"):
|
||||
parts.append(f"{who} is now {r.get('installed_after') if isinstance(r.get('installed_after'), str) else 'new'}")
|
||||
restart = restart or bool(r.get("restart_needed"))
|
||||
elif status == "failed":
|
||||
parts.append(f"{who} was not changed: {str(r.get('error', '')).rstrip('.')}")
|
||||
continue
|
||||
name = {"engine": "Engine", "control": "Control"}.get(r.get("component"), str(r.get("component")))
|
||||
if status == "updated":
|
||||
parts.append(f"{name} is now {r.get('installed_after') if isinstance(r.get('installed_after'), str) else (r.get('installed_after') or {}).get('version', 'new')}")
|
||||
elif status == "failed":
|
||||
parts.append(f"{name} was not changed: {str(r.get('error', '')).rstrip('.')}")
|
||||
text = "; ".join(parts) or "Nothing needed updating."
|
||||
if restart: # the new engine is beside the old one: a model that was serving during the update keeps the old one
|
||||
from strata_control import shape_engine
|
||||
text += ". " + shape_engine.WORDS["restart"]
|
||||
for r in (out.get("models") or {}).get("restarts", []):
|
||||
text += " " + (r.get("message") or (f"{r['name']} is stopped." if not r.get("restarted") else f"{r['name']} is serving again."))
|
||||
return text
|
||||
|
||||
@@ -63,6 +63,8 @@ WORDS = {
|
||||
"setup_ok": "engine for {model}: {version} in {folder}",
|
||||
"setup_skip": "no engine for {model} is installed: the model is downloaded and prepared now; set it up again when the engine can be fetched",
|
||||
"update_label": "Model engine",
|
||||
# 0.2.25 (LIVE-TEST-0171): the new engine is placed beside the old one; a model that is running keeps the old one until it is started again
|
||||
"restart": "Restart the model to use it: the one that is running keeps the old engine.",
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +290,25 @@ def _prune(shape_root: Path, shape: str, keep_name: str) -> list[str]:
|
||||
return removed
|
||||
|
||||
|
||||
def decide_one(feed, ctx, shape: str, title: str | None = None) -> dict:
|
||||
"""What an update would do for the engine of `shape`, from the feed alone (nothing is downloaded): ``status`` available, current or none-for-this-pc, with the
|
||||
installed and the offered version, the title a person reads and the download size. The same choice ``update_one`` makes."""
|
||||
from strata_control import feed as feedmod
|
||||
name = shown(shape, title or title_from_feed(feed, shape))
|
||||
have = newest_version(shape, ctx.components)
|
||||
row = {"shape": shape, "component": component_id(shape), "title": name, "installed": have, "offered": None, "status": "none-for-this-pc", "download_bytes": 0}
|
||||
pkg, reasons = choose(feed, shape, ctx.hardware, title=name if name != shape else None)
|
||||
if pkg is None:
|
||||
row.update(note=WORDS["not_in_feed"].format(model=name), reasons=reasons)
|
||||
return row
|
||||
row["offered"] = pkg.version
|
||||
if have and feedmod.version_key(pkg.version) <= feedmod.version_key(have):
|
||||
row["status"] = "current"
|
||||
return row
|
||||
row.update(status="available", download_bytes=pkg.size)
|
||||
return row
|
||||
|
||||
|
||||
def update_one(ctx, feed, shape: str, *, install_missing: bool = True, title: str | None = None) -> dict:
|
||||
"""Bring the engine of `shape` up to the feed's: fetch the newest package that fits this PC (resumable download, archive SHA-256, the manifest hash the signed feed names,
|
||||
the package signature, every file's hash, the shape named in the manifest), put it NEXT TO the older ones, start it once (`--version`) and only then keep it. The Strata engine is
|
||||
@@ -297,7 +318,7 @@ def update_one(ctx, feed, shape: str, *, install_missing: bool = True, title: st
|
||||
comp = component_id(shape)
|
||||
name = shown(shape, title or title_from_feed(feed, shape)) # what a person reads; `shape` and `comp` stay the keys
|
||||
have = newest_version(shape, ctx.components)
|
||||
result = {"component": comp, "shape": shape, "status": "current" if have else "none-installed", "changed": False, "installed_before": have}
|
||||
result = {"component": comp, "shape": shape, "title": name, "status": "current" if have else "none-installed", "changed": False, "installed_before": have}
|
||||
if not have and not install_missing:
|
||||
return result
|
||||
pkg, reasons = choose(feed, shape, ctx.hardware, title=name if name != shape else None)
|
||||
@@ -396,12 +417,12 @@ LOCK_POLL_S = 1.0
|
||||
|
||||
|
||||
def ensure(shape: str, source: str, *, components: Path | None = None, hardware: dict | None = None, emit: Callable[[str], None] = print, cancel=None,
|
||||
quiet_when_current: bool = True, title: str | None = None, automatic: bool = False) -> Path | None:
|
||||
quiet_when_current: bool = True, title: str | None = None, automatic: bool = False, progress: Callable[[int], None] | None = None) -> Path | None:
|
||||
"""The engine of `shape` is installed and up to date, from the signed feed at `source` (a URL or a folder). Returns its program, or None with one plain line through `emit` when
|
||||
there is none (not in the feed, nothing for this PC, the feed cannot be read). A newer package is fetched only when the feed can be read; an installed one keeps running when it
|
||||
cannot. This is what setup and `strata launch` call when a model of that shape is chosen. `automatic` (`strata launch`): with an engine installed,
|
||||
the check for a newer one is a read nobody asked for, so a feed host that refused within the last hours is not asked again (netpolicy rule 4b);
|
||||
without one the feed is always read."""
|
||||
without one the feed is always read. ``progress(percent)``: the download of the package, for a screen with a bar (0.2.25: the launch's bar stayed at 0% for the whole download)."""
|
||||
from strata_control import acquisition, feed as feedmod, signing, updater
|
||||
components = Path(components) if components else ec.components_dir()
|
||||
hw = hardware or updater.detect_hardware()
|
||||
@@ -412,7 +433,8 @@ def ensure(shape: str, source: str, *, components: Path | None = None, hardware:
|
||||
ctx = updater.Context(components=components, source=source, trusted=signing.load_trusted_keys(), hardware=hw, cancel=cancel,
|
||||
feed_timeout=5.0 if have else 30.0, # an installed engine: a launch must not wait long for a feed that is not there
|
||||
automatic=bool(automatic and have),
|
||||
emit=lambda event: emit(event["message"]) if event.get("event") == "phase" and event.get("message") and event.get("phase") != "feed" else None)
|
||||
emit=lambda event: (progress(int(event.get("percent") or 0)) if progress is not None else None) if event.get("event") == "progress" else
|
||||
(emit(event["message"]) if event.get("event") == "phase" and event.get("message") and event.get("phase") != "feed" else None))
|
||||
try:
|
||||
deadline = time.monotonic() + (0.0 if automatic else LOCK_WAIT_S)
|
||||
while True:
|
||||
|
||||
@@ -626,9 +626,32 @@ def _engine_view(component: ec.EngineComponent | None) -> dict | None:
|
||||
"signed": bool(component.signature)}
|
||||
|
||||
|
||||
def qwen_engine_wanted(ctx: Context) -> bool:
|
||||
"""Is the Strata engine (the one that runs the Qwen models) part of this PC's update? Not on a PC whose only engine is a model shape's (an
|
||||
Inkling-only PC: LIVE-TEST-0171 item 27, the Monitor's `u` asked to stop the model for, and installed, a 920 MB engine the person never had).
|
||||
A PC with a Strata engine, or with no engine at all, keeps it: `strata launch` of a Qwen model installs it on the first start."""
|
||||
from strata_control import shape_engine
|
||||
if ec.newest_installed_version(ctx.components):
|
||||
return True
|
||||
return not shape_engine.installed_shapes(ctx.components)
|
||||
|
||||
|
||||
def shape_decisions(feed: feedmod.Feed, ctx: Context) -> list[dict]:
|
||||
"""What an update would do for each model-shape engine installed here (strata_control/shape_engine.py), from the feed alone; a PC with none has an empty list."""
|
||||
from strata_control import shape_engine
|
||||
return [shape_engine.decide_one(feed, ctx, shape) for shape in shape_engine.installed_shapes(ctx.components)]
|
||||
|
||||
|
||||
NOT_USED_NOTE = ("not installed: this PC has only the engine of a model of its own (see below); the Strata engine, which runs the Qwen models, "
|
||||
"is installed when you start one")
|
||||
|
||||
|
||||
def decide_engine(feed: feedmod.Feed, ctx: Context, state: State) -> dict:
|
||||
"""What an update would do for the engine, without downloading anything."""
|
||||
return _choose_engine(feed, ctx, state)[0]
|
||||
"""What an update would do for the engine, without downloading anything. Status ``not-used``: no Strata engine here and none wanted (an Inkling-only PC)."""
|
||||
report = _choose_engine(feed, ctx, state)[0]
|
||||
if report["installed"] is None and not qwen_engine_wanted(ctx):
|
||||
report = {**report, "status": "not-used", "download_bytes": 0, "note": NOT_USED_NOTE}
|
||||
return report
|
||||
|
||||
|
||||
GPU_MAKES = ("cuda", "hip", "sycl")
|
||||
@@ -817,7 +840,7 @@ def check(ctx: Context) -> dict:
|
||||
feed = open_feed(ctx, state)
|
||||
report = {"feed": {"source": ctx.source, "sequence": feed.sequence, "channel": feed.channel, "key_id": feed.key_id,
|
||||
"generated_at": feed.generated_at, "trusted_by": "test key file" if signing.extra_keys_in_effect(ctx.environ) else "built-in keys"},
|
||||
"engine": decide_engine(feed, ctx, state), "control": decide_control(feed, ctx, state),
|
||||
"engine": decide_engine(feed, ctx, state), "shape_engines": shape_decisions(feed, ctx), "control": decide_control(feed, ctx, state),
|
||||
"app": decide_app(feed, ctx), "serving": _serving_or_empty(ctx), "hardware": ctx.hardware}
|
||||
state.data["last_check"] = _last_check(ctx, report)
|
||||
state.save()
|
||||
@@ -831,6 +854,9 @@ def _last_check(ctx: Context, report: dict, control_version: str | None = None)
|
||||
"at": (ctx.now or dt.datetime.now(dt.timezone.utc)).isoformat(),
|
||||
"engine": report["engine"]["offered"]["version"] if report["engine"]["status"] in ("available", "install") and report["engine"]["offered"] else None,
|
||||
"app": report["app"]["offered"] if report["app"]["status"] == "available" else None,
|
||||
# the engines of model shapes (Inkling-2-Mini's): what the feed offers that is newer, with the installed version it was for (the notice is dropped when that changes)
|
||||
"shapes": {row["shape"]: {"version": row["offered"], "installed": row["installed"], "title": row["title"]}
|
||||
for row in report.get("shape_engines") or [] if row["status"] == "available" and row["offered"]},
|
||||
# the versions this result is for, so a later Control, engine or app change drops the cached notice
|
||||
"control": control_version or ec.runtime_version(), "engine_installed": ec.newest_installed_version(ctx.components)}
|
||||
|
||||
@@ -2351,8 +2377,17 @@ def _shape_steps(ctx: Context, feed: feedmod.Feed, engine: bool) -> list:
|
||||
if not engine:
|
||||
return []
|
||||
from strata_control import shape_engine
|
||||
return [(shape_engine.component_id(shape), (lambda shape=shape: shape_engine.update_one(ctx, feed, shape, install_missing=False)))
|
||||
for shape in shape_engine.installed_shapes(ctx.components)]
|
||||
def step(shape: str) -> dict:
|
||||
result = shape_engine.update_one(ctx, feed, shape, install_missing=False)
|
||||
if result.get("changed"): # the new engine sits beside the old one: a model that is running keeps the old one until it is started again
|
||||
try:
|
||||
if ctx.serving():
|
||||
result["restart_needed"] = True
|
||||
result["note"] = f"{result.get('note') or ''} {shape_engine.WORDS['restart']}".strip()
|
||||
except Exception: # noqa: BLE001 - not knowing is not a reason to fail the update
|
||||
pass
|
||||
return result
|
||||
return [(shape_engine.component_id(shape), (lambda shape=shape: step(shape))) for shape in shape_engine.installed_shapes(ctx.components)]
|
||||
|
||||
|
||||
def run_update(ctx: Context, *, engine: bool = True, control: bool = True, app: bool = False) -> dict:
|
||||
@@ -2366,7 +2401,7 @@ def run_update(ctx: Context, *, engine: bool = True, control: bool = True, app:
|
||||
feed = open_feed(ctx, state)
|
||||
state.save()
|
||||
_model_check(ctx, feed, state, engine=engine, control=control)
|
||||
steps = ([("engine", lambda: update_engine(ctx, feed, state))] if engine else []) + \
|
||||
steps = ([("engine", lambda: update_engine(ctx, feed, state))] if engine and qwen_engine_wanted(ctx) else []) + \
|
||||
_shape_steps(ctx, feed, engine) + \
|
||||
([("control", lambda: update_control(ctx, feed, state))] if control else []) + \
|
||||
([("app", lambda: update_app(ctx, feed))] if app else [])
|
||||
@@ -2381,7 +2416,8 @@ def run_update(ctx: Context, *, engine: bool = True, control: bool = True, app:
|
||||
state.data.get("last_check", {}).pop("engine", None)
|
||||
try: # the feed was read for this update: what it offers that is still newer is kept for the app's one card
|
||||
now_control = next((r.get("installed_after") for r in results if r.get("component") == "control" and r.get("status") == "updated"), None)
|
||||
state.data["last_check"] = _last_check(ctx, {"engine": decide_engine(feed, ctx, state), "app": decide_app(feed, ctx)}, now_control)
|
||||
state.data["last_check"] = _last_check(ctx, {"engine": decide_engine(feed, ctx, state), "app": decide_app(feed, ctx),
|
||||
"shape_engines": shape_decisions(feed, ctx)}, now_control)
|
||||
except Exception: # noqa: BLE001 - only a hint for the app
|
||||
pass
|
||||
state.save()
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
"""0.2.25 (PLAN-0224 items 26-29): the engine of a model shape (Inkling-2-Mini's strata-inkling, here the test shape q4_lite) in the update's reports.
|
||||
|
||||
Found by the 0.1.71 client checks (LIVE-TEST-0171, REL-0171) on an Inkling-only PC:
|
||||
* 26 `strata update --check` never listed the shape engine (only `strata update` brought it up to date);
|
||||
* 27 the Monitor's `u` offered "to update the engine 0.1.69" and installed the Strata (Qwen) engine the person never had;
|
||||
* 28 the start screen and the monitor knew a newer Strata engine only: no notice for an Inkling engine;
|
||||
* 29 after `u` while the model was serving: "strata-inkling is now 0.1.71", though the running server keeps the old engine until it is restarted.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import shutil
|
||||
import sys
|
||||
from contextlib import redirect_stdout
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from strata_cli import update_cmd # noqa: E402
|
||||
from strata_control import engine_component as ec, engine_update, shape_engine, signing, updater # noqa: E402
|
||||
from tests.terminal.test_shape_engine import SHAPE, Base, model_entry # noqa: E402
|
||||
|
||||
|
||||
class Case(Base):
|
||||
def installed(self, *versions):
|
||||
for i, v in enumerate(versions):
|
||||
self.publish(*versions[: i + 1], sequence=i + 1)
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
self.assertIsNotNone(self.ensure(), v)
|
||||
|
||||
def ctx(self, **kw):
|
||||
return updater.Context(components=self.comp, source=self.url, trusted=signing.load_trusted_keys(), hardware=self.hw, **kw)
|
||||
|
||||
def with_old_engine_and_newer_in_feed(self, title_model=True):
|
||||
self.installed("0.1.59")
|
||||
self.publish("0.1.59", "0.1.60", sequence=5, models=[model_entry()] if title_model else None)
|
||||
|
||||
def only_a_shape_engine_here(self):
|
||||
shutil.rmtree(self.comp / "engine") # an Inkling-only PC: the Strata engine was never installed
|
||||
|
||||
|
||||
class Check(Case):
|
||||
def test_check_lists_the_installed_shape_engine_and_the_newer_one(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
report = updater.check(self.ctx())
|
||||
rows = report["shape_engines"]
|
||||
self.assertEqual(len(rows), 1, rows)
|
||||
row = rows[0]
|
||||
self.assertEqual((row["shape"], row["installed"], row["offered"], row["status"]), (SHAPE, "0.1.59", "0.1.60", "available"))
|
||||
self.assertEqual(row["title"], "Qwen4 Lite Test")
|
||||
self.assertGreater(row["download_bytes"], 0)
|
||||
|
||||
def test_the_printed_check_says_it_in_a_line_and_points_to_the_update(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
report = updater.check(self.ctx())
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
update_cmd._print_check(report)
|
||||
text = out.getvalue()
|
||||
self.assertIn("Qwen4 Lite Test", text)
|
||||
self.assertIn("0.1.59 -> 0.1.60", text)
|
||||
self.assertIn("To update: strata update", text)
|
||||
|
||||
def test_a_current_shape_engine_is_listed_as_up_to_date_and_no_update_is_pointed_to(self):
|
||||
self.installed("0.1.60")
|
||||
self.publish("0.1.60", sequence=5)
|
||||
report = updater.check(self.ctx())
|
||||
self.assertEqual(report["shape_engines"][0]["status"], "current")
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
update_cmd._print_check(report)
|
||||
self.assertIn("0.1.60 is up to date", out.getvalue())
|
||||
|
||||
def test_a_pc_without_a_shape_engine_has_an_empty_list(self):
|
||||
self.publish("0.1.60", sequence=5)
|
||||
self.assertEqual(updater.check(self.ctx())["shape_engines"], [])
|
||||
|
||||
|
||||
class InklingOnly(Case):
|
||||
def test_check_does_not_offer_to_install_the_strata_engine(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
self.only_a_shape_engine_here()
|
||||
report = updater.check(self.ctx())
|
||||
self.assertEqual(report["engine"]["status"], "not-used", report["engine"])
|
||||
self.assertEqual(report["shape_engines"][0]["status"], "available")
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
update_cmd._print_check(report)
|
||||
self.assertNotIn("no engine installed yet", out.getvalue())
|
||||
|
||||
def test_the_update_brings_the_shape_engine_up_and_installs_no_strata_engine(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
self.only_a_shape_engine_here()
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
out = updater.run_update(self.ctx(), control=False)
|
||||
components = [r.get("component") for r in out["results"]]
|
||||
self.assertNotIn("engine", components, out["results"])
|
||||
self.assertIn(shape_engine.component_id(SHAPE), components)
|
||||
self.assertEqual(shape_engine.newest_version(SHAPE, self.comp), "0.1.60")
|
||||
self.assertFalse((self.comp / "engine").exists() and any((self.comp / "engine").iterdir()), "the Strata engine must not be installed")
|
||||
|
||||
def test_the_consent_question_is_not_asked_for_an_engine_that_would_not_be_installed(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
self.only_a_shape_engine_here()
|
||||
feed = updater.open_feed(self.ctx(), updater.State(self.comp))
|
||||
self.assertEqual(updater.pending_changes(feed, self.ctx(), updater.State(self.comp), control=False), [])
|
||||
|
||||
def test_a_pc_with_nothing_installed_still_gets_the_strata_engine_from_an_update(self):
|
||||
shutil.rmtree(self.comp / "engine")
|
||||
self.publish("0.1.60", sequence=5)
|
||||
feed = updater.open_feed(self.ctx(), updater.State(self.comp))
|
||||
self.assertTrue(updater.qwen_engine_wanted(self.ctx()))
|
||||
self.assertNotEqual(updater.decide_engine(feed, self.ctx(), updater.State(self.comp))["status"], "not-used")
|
||||
|
||||
|
||||
class Notice(Case):
|
||||
def test_the_cached_check_offers_the_shape_engine_to_the_start_screen_and_the_monitor(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
self.only_a_shape_engine_here()
|
||||
updater.check(self.ctx())
|
||||
offers = ec.cached_offers(self.comp)
|
||||
self.assertEqual(offers["shapes"][SHAPE]["version"], "0.1.60")
|
||||
found = engine_update.notice(self.comp)
|
||||
self.assertIsNotNone(found)
|
||||
self.assertIn("0.1.60", found["line"])
|
||||
self.assertIn("Qwen4 Lite Test", found["line"])
|
||||
note = engine_update.monitor_note(self.comp)
|
||||
self.assertIn("0.1.60", note)
|
||||
self.assertIn("Press u to update", note)
|
||||
self.assertNotIn("strata-engine", note)
|
||||
self.assertIn("update available", ec.cached_notice(self.comp))
|
||||
|
||||
def test_the_notice_goes_away_when_the_engine_is_current(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
updater.check(self.ctx())
|
||||
self.assertIsNotNone(engine_update.notice(self.comp))
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
updater.run_update(self.ctx(), control=False)
|
||||
self.assertIsNone(engine_update.notice(self.comp))
|
||||
self.assertEqual(ec.cached_offers(self.comp).get("shapes") or {}, {})
|
||||
|
||||
def test_a_shape_engine_installed_after_the_check_that_is_not_older_drops_the_offer(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
updater.check(self.ctx())
|
||||
self.publish("0.1.59", "0.1.60", sequence=6)
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
self.assertIsNotNone(self.ensure())
|
||||
self.assertEqual(ec.cached_offers(self.comp).get("shapes") or {}, {})
|
||||
|
||||
|
||||
class Bar(Case):
|
||||
def test_the_download_of_a_shape_engine_reports_its_percent_to_a_screen_with_a_bar(self):
|
||||
self.publish("0.1.59")
|
||||
calls = []
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
exe = self.ensure(progress=calls.append)
|
||||
self.assertIsNotNone(exe)
|
||||
self.assertTrue(calls, "the bar was told nothing: it stays at 0% for the whole download (LIVE-TEST-0171)")
|
||||
self.assertEqual(calls[-1], 100)
|
||||
self.assertEqual(calls, sorted(calls))
|
||||
|
||||
def test_without_a_progress_callback_nothing_changes(self):
|
||||
self.publish("0.1.59")
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
self.assertIsNotNone(self.ensure())
|
||||
|
||||
|
||||
class AfterTheUpdate(Case):
|
||||
def test_a_model_that_keeps_serving_is_told_to_restart(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
serving = [{"profile": "launch-inkling", "state": "ready"}]
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
out = updater.run_update(self.ctx(serving=lambda: serving), control=False)
|
||||
row = [r for r in out["results"] if r.get("shape") == SHAPE][0]
|
||||
self.assertEqual(row["status"], "updated")
|
||||
self.assertTrue(row.get("restart_needed"))
|
||||
text = engine_update.summary(out)
|
||||
self.assertIn("0.1.60", text)
|
||||
self.assertIn("Qwen4 Lite Test", text)
|
||||
self.assertIn("Restart the model to use it", text)
|
||||
self.assertNotIn("strata-q4-lite", text)
|
||||
|
||||
def test_nothing_serving_no_restart_words(self):
|
||||
self.with_old_engine_and_newer_in_feed()
|
||||
with mock.patch.object(shape_engine, "_test_start", return_value=(True, "x")):
|
||||
out = updater.run_update(self.ctx(serving=lambda: []), control=False)
|
||||
text = engine_update.summary(out)
|
||||
self.assertIn("0.1.60", text)
|
||||
self.assertNotIn("Restart the model", text)
|
||||
Reference in new issue
Block a user