Server: a picture reader written into an older engine folder follows the engine in use after an update (#4658)
This commit is contained in:
1 parent
68718c33fa
commit
e66a445892
2 files changed
+62
-3
No files matched your search
+9
-3
@@ -8653,10 +8653,16 @@ def with_current_reader(cfg: dict, package: Path) -> dict:
|
||||
fixed = dict(vision)
|
||||
for key in ("exe", "cpu_exe"):
|
||||
old = fixed.get(key)
|
||||
if isinstance(old, str) and old and not engine_component.is_reference(old) and os.path.isabs(old) and not os.path.exists(old):
|
||||
if isinstance(old, str) and old and not engine_component.is_reference(old) and os.path.isabs(old):
|
||||
new = package / old.replace("\\", "/").rsplit("/", 1)[-1]
|
||||
if new.is_file():
|
||||
print(f"[strata] the picture reader {old} is not there any more; using {new} from the engine package in use", flush=True)
|
||||
gone = not os.path.exists(old)
|
||||
# #4658: the old engine folder is kept after `strata update`, so the old reader still exists; one in a SIBLING engine folder
|
||||
# (components/engine/<version>-...) is the engine's reader from before the update, and the engine in use has its own
|
||||
older = (not gone and Path(old).parent != package and Path(old).parent.parent == package.parent
|
||||
and package.parent.name.lower() == "engine")
|
||||
if (gone or older) and new.is_file():
|
||||
print(f"[strata] the picture reader {old} " + ("is not there any more" if gone else "belongs to an older engine")
|
||||
+ f"; using {new} from the engine package in use", flush=True)
|
||||
fixed[key] = str(new)
|
||||
if fixed == vision:
|
||||
return cfg
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
"""#4658: after `strata update` the old engine folder stays, so a picture reader written into it kept starting beside the new engine.
|
||||
|
||||
python -m serve.test_reader_follows_engine
|
||||
"""
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import serve.server as server
|
||||
|
||||
|
||||
class ReaderFollowsEngine(unittest.TestCase):
|
||||
def make(self, root: Path, *folders: str):
|
||||
for name in folders:
|
||||
d = root / "components" / "engine" / name
|
||||
d.mkdir(parents=True)
|
||||
(d / "strata.exe").write_bytes(b"x")
|
||||
(d / "strata-vision.exe").write_bytes(b"x")
|
||||
return root / "components" / "engine"
|
||||
|
||||
def test_a_reader_in_the_older_engine_folder_moves_to_the_engine_in_use(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
engine = self.make(Path(tmp), "0.1.52-x", "0.1.54-x")
|
||||
cfg = {"vision": {"exe": str(engine / "0.1.52-x" / "strata-vision.exe"), "mmproj": "m.gguf"}}
|
||||
fixed = server.with_current_reader(cfg, engine / "0.1.54-x")
|
||||
self.assertEqual(fixed["vision"]["exe"], str(engine / "0.1.54-x" / "strata-vision.exe"))
|
||||
self.assertEqual(fixed["vision"]["mmproj"], "m.gguf")
|
||||
|
||||
def test_a_reader_already_in_the_engine_folder_stays(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
engine = self.make(Path(tmp), "0.1.54-x")
|
||||
cfg = {"vision": {"exe": str(engine / "0.1.54-x" / "strata-vision.exe")}}
|
||||
self.assertIs(server.with_current_reader(cfg, engine / "0.1.54-x"), cfg)
|
||||
|
||||
def test_a_reader_somewhere_else_is_the_persons_choice_and_stays(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
engine = self.make(Path(tmp), "0.1.54-x")
|
||||
mine = Path(tmp) / "mine"
|
||||
mine.mkdir()
|
||||
(mine / "strata-vision.exe").write_bytes(b"x")
|
||||
cfg = {"vision": {"exe": str(mine / "strata-vision.exe")}}
|
||||
self.assertIs(server.with_current_reader(cfg, engine / "0.1.54-x"), cfg)
|
||||
|
||||
def test_a_missing_reader_is_still_replaced(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
engine = self.make(Path(tmp), "0.1.54-x")
|
||||
cfg = {"vision": {"exe": str(engine / "0.1.40-x" / "strata-vision.exe")}}
|
||||
fixed = server.with_current_reader(cfg, engine / "0.1.54-x")
|
||||
self.assertEqual(fixed["vision"]["exe"], str(engine / "0.1.54-x" / "strata-vision.exe"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user