quality-loop 0.5.0__tar.gz → 0.5.1__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 (62) hide show
  1. {quality_loop-0.5.0/quality_loop.egg-info → quality_loop-0.5.1}/PKG-INFO +1 -1
  2. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/__init__.py +1 -1
  3. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/guest/suite.py +71 -12
  4. {quality_loop-0.5.0 → quality_loop-0.5.1/quality_loop.egg-info}/PKG-INFO +1 -1
  5. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_guest.py +45 -0
  6. {quality_loop-0.5.0 → quality_loop-0.5.1}/LICENSE +0 -0
  7. {quality_loop-0.5.0 → quality_loop-0.5.1}/README.md +0 -0
  8. {quality_loop-0.5.0 → quality_loop-0.5.1}/pyproject.toml +0 -0
  9. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/OPERATOR.md +0 -0
  10. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/__main__.py +0 -0
  11. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/adapter.py +0 -0
  12. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/audit.py +0 -0
  13. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/awake.py +0 -0
  14. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/cli.py +0 -0
  15. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/compare.py +0 -0
  16. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/config.py +0 -0
  17. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/drive/__init__.py +0 -0
  18. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/drive/_mac.py +0 -0
  19. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/drive/_windows.py +0 -0
  20. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/drive/keys.py +0 -0
  21. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/drive/terminal.py +0 -0
  22. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/guest/__init__.py +0 -0
  23. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/guest/boot/__init__.py +0 -0
  24. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/guest/boot/launch.py +0 -0
  25. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/guest/boot/pytest_main.py +0 -0
  26. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/guest/boot/screen_agent.py +0 -0
  27. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/guest/screens.py +0 -0
  28. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/install.py +0 -0
  29. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/mcp.py +0 -0
  30. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/operator.py +0 -0
  31. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/pages.py +0 -0
  32. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/processes.py +0 -0
  33. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/progress.py +0 -0
  34. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/pytest_plugin.py +0 -0
  35. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/report.py +0 -0
  36. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/room.py +0 -0
  37. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/runner.py +0 -0
  38. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/scenario.py +0 -0
  39. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/screens/__init__.py +0 -0
  40. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/screens/_mac.py +0 -0
  41. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/screens/_windows.py +0 -0
  42. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/session.py +0 -0
  43. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/skill/SKILL.md +0 -0
  44. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/skill/references/filing.md +0 -0
  45. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/skill/references/setup.md +0 -0
  46. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/standin.py +0 -0
  47. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop/transcript.py +0 -0
  48. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop.egg-info/SOURCES.txt +0 -0
  49. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop.egg-info/dependency_links.txt +0 -0
  50. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop.egg-info/entry_points.txt +0 -0
  51. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop.egg-info/requires.txt +0 -0
  52. {quality_loop-0.5.0 → quality_loop-0.5.1}/quality_loop.egg-info/top_level.txt +0 -0
  53. {quality_loop-0.5.0 → quality_loop-0.5.1}/setup.cfg +0 -0
  54. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_awake.py +0 -0
  55. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_core.py +0 -0
  56. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_drive.py +0 -0
  57. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_loop.py +0 -0
  58. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_mcp.py +0 -0
  59. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_operator.py +0 -0
  60. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_pytest_plugin.py +0 -0
  61. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_scenario_report.py +0 -0
  62. {quality_loop-0.5.0 → quality_loop-0.5.1}/tests/test_screens.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quality-loop
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Measure what a product teaches - its skill, tools or manual - with isolated agent runs of real tasks, reported by an operator agent
5
5
  Author: craftware
6
6
  License-Expression: MIT
@@ -12,4 +12,4 @@ room is handed, putting the user's machine back - is code here, not an
12
12
  agent's discretion.
13
13
  """
14
14
 
15
- __version__ = "0.5.0"
15
+ __version__ = "0.5.1"
@@ -21,34 +21,93 @@ are copied to ``results``. :data:`IN_GUEST` is set for the suite, which is how
21
21
 
22
22
  from __future__ import annotations
23
23
 
24
+ import codecs
25
+ import os
24
26
  import pathlib
25
27
  import shutil
26
28
  import subprocess
27
29
  import sys
28
30
  import time
29
31
 
32
+ try:
33
+ import fcntl
34
+ except ImportError: # a Windows host
35
+ fcntl = None
36
+
30
37
  from quality_loop.guest import IN_GUEST, Guest, sh_quote
31
38
 
32
39
 
40
+ #: How long a run of NUL bytes in the log may stay before it is taken as
41
+ #: written: one the guest really wrote would otherwise stop the reading.
42
+ _NUL_PATIENCE = 30.0
43
+
44
+
45
+ def read_uncached(path: pathlib.Path, position: int = 0) -> bytes:
46
+ """``path`` from ``position`` on, past this machine's file cache.
47
+
48
+ A Windows guest's share is the guest's own folder, mounted here by
49
+ ``mount_smbfs``. Read while the guest was writing it, macOS's SMB client
50
+ handed back NUL bytes for a stretch it had the new size of but not yet
51
+ the data, and kept handing them back from its cache - copying the log at
52
+ the end too: XeFM's suite logs had lost a stretch in about one Windows
53
+ run in six, once the very lines that said why a worker died (xefm#1056).
54
+ ``F_NOCACHE`` (macOS) has each read go to the server."""
55
+ fd = os.open(path, os.O_RDONLY)
56
+ try:
57
+ if fcntl is not None and hasattr(fcntl, "F_NOCACHE"):
58
+ fcntl.fcntl(fd, fcntl.F_NOCACHE, 1)
59
+ os.lseek(fd, position, os.SEEK_SET)
60
+ chunks = []
61
+ while True:
62
+ chunk = os.read(fd, 1 << 20)
63
+ if not chunk:
64
+ return b"".join(chunks)
65
+ chunks.append(chunk)
66
+ finally:
67
+ os.close(fd)
68
+
69
+
70
+ def copy_uncached(source: pathlib.Path, target: pathlib.Path) -> None:
71
+ """:func:`shutil.copy2` with the data read by :func:`read_uncached`."""
72
+ data = read_uncached(source)
73
+ for _ in range(5):
74
+ if b"\0" not in data:
75
+ break
76
+ time.sleep(1)
77
+ data = read_uncached(source)
78
+ target.write_bytes(data)
79
+ shutil.copystat(source, target)
80
+
81
+
33
82
  def follow(log: pathlib.Path, done: pathlib.Path, patience: float) -> int:
34
83
  """Print ``log`` as it grows until ``done`` holds an exit code; 3 when
35
- nothing ends within ``patience`` seconds."""
84
+ nothing ends within ``patience`` seconds.
85
+
86
+ A run of NUL bytes is taken for data not here yet (:func:`read_uncached`)
87
+ and read again, up to :data:`_NUL_PATIENCE`."""
36
88
  position, deadline, finished_at = 0, time.monotonic() + patience, None
89
+ decoder = codecs.getincrementaldecoder("utf-8")(errors="replace")
90
+ nul_since: float | None = None
37
91
  while True:
38
92
  finished = done.exists()
39
- chunk = ""
40
- if log.exists():
41
- with log.open("r", encoding="utf-8", errors="replace") as f:
42
- f.seek(position)
43
- chunk = f.read()
44
- position = f.tell()
45
- if chunk:
46
- sys.stdout.write(chunk)
47
- sys.stdout.flush()
93
+ data = read_uncached(log, position) if log.exists() else b""
94
+ hole = data.find(b"\0")
95
+ if hole >= 0:
96
+ nul_since = nul_since or time.monotonic()
97
+ if time.monotonic() - nul_since < _NUL_PATIENCE:
98
+ data = data[:hole]
99
+ else:
100
+ nul_since = None
101
+ else:
102
+ nul_since = None
103
+ if data:
104
+ position += len(data)
105
+ sys.stdout.write(decoder.decode(data))
106
+ sys.stdout.flush()
48
107
  if finished:
49
108
  # Over SMB the log's last writes can show up after the exit code
50
109
  # does: read on until it has stopped growing.
51
- if chunk or (time.monotonic() - finished_at if finished_at else 0) < 3:
110
+ if data or nul_since or (time.monotonic() - finished_at if finished_at else 0) < 3:
52
111
  finished_at = finished_at or time.monotonic()
53
112
  time.sleep(1)
54
113
  continue
@@ -100,7 +159,7 @@ def run_pytest(guest: Guest, stage: pathlib.Path, python: str, args: list[str],
100
159
  results.mkdir(parents=True, exist_ok=True)
101
160
  for kept in (log, junit):
102
161
  if kept.exists():
103
- shutil.copy2(kept, results / kept.name)
162
+ copy_uncached(kept, results / kept.name)
104
163
  if guest.windows:
105
164
  guest.forget_task(task)
106
165
  return code
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quality-loop
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Measure what a product teaches - its skill, tools or manual - with isolated agent runs of real tasks, reported by an operator agent
5
5
  Author: craftware
6
6
  License-Expression: MIT
@@ -322,3 +322,48 @@ def test_run_pytest_answers_3_when_the_runner_never_reports(share, tmp_path):
322
322
  assert suite.run_pytest(guest, stage, sys.executable, [], cwd=str(stage),
323
323
  results=tmp_path / "r") == 3
324
324
  assert "gone" in (tmp_path / "r" / "pytest.log").read_text()
325
+
326
+
327
+ def test_follow_reads_a_run_of_nuls_again_until_the_data_is_there(tmp_path, capsys, monkeypatch):
328
+ """macOS's SMB client hands back NULs for data not there yet (xefm#1056):
329
+ the follower waits for them to fill in instead of printing them."""
330
+ from quality_loop.guest import suite
331
+ log, done = tmp_path / "pytest.log", tmp_path / "exit-code"
332
+ log.write_bytes(b"one\n" + b"\0" * 4 + b"three\n")
333
+ reads = []
334
+ real = suite.read_uncached
335
+
336
+ def reading(path, position=0):
337
+ reads.append(position)
338
+ if len(reads) == 2: # the second read: the stretch has arrived
339
+ log.write_bytes(b"one\ntwo\nthree\n")
340
+ done.write_text("0")
341
+ return real(path, position)
342
+
343
+ monkeypatch.setattr(suite, "read_uncached", reading)
344
+ monkeypatch.setattr(suite.time, "sleep", lambda s: None)
345
+ assert suite.follow(log, done, patience=60) == 0
346
+ out = capsys.readouterr().out
347
+ assert out == "one\ntwo\nthree\n"
348
+ assert "\0" not in out
349
+
350
+
351
+ def test_follow_takes_a_nul_run_that_stays_as_written(tmp_path, capsys, monkeypatch):
352
+ from quality_loop.guest import suite
353
+ log, done = tmp_path / "pytest.log", tmp_path / "exit-code"
354
+ log.write_bytes(b"a\0b\n")
355
+ done.write_text("0")
356
+ clock = iter(range(0, 10000, 10))
357
+ monkeypatch.setattr(suite.time, "monotonic", lambda: next(clock))
358
+ monkeypatch.setattr(suite.time, "sleep", lambda s: None)
359
+ assert suite.follow(log, done, patience=100000) == 0
360
+ assert capsys.readouterr().out == "a\0b\n"
361
+
362
+
363
+ def test_copy_uncached_keeps_the_bytes_and_the_times(tmp_path):
364
+ from quality_loop.guest import suite
365
+ source, target = tmp_path / "s.log", tmp_path / "t.log"
366
+ source.write_bytes("héllo\n".encode())
367
+ suite.copy_uncached(source, target)
368
+ assert target.read_bytes() == source.read_bytes()
369
+ assert abs(target.stat().st_mtime - source.stat().st_mtime) < 1
File without changes
File without changes
File without changes