Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

tools/strata_bench.py: the redactor replaces a folder before the short user name inside it (#3619, #3326)

ctr-137800730103c67
diff --git a/tools/strata_bench.py b/tools/strata_bench.py
index 0bb0711d7..be0e39cfe 100644
--- a/tools/strata_bench.py
+++ b/tools/strata_bench.py
@@ -68,14 +68,14 @@ BURST_MAX_TOKENS = 128
def redactor(extra: list[str] = (), key: str = ""):
"""-> f(text) -> text with this machine's home folders, user and host names, the Strata folder, IP addresses and the
API key replaced. Applied to everything that is written or printed from the server's or the machine's own text."""
- subs: list[tuple[re.Pattern, str]] = []
+ subs: list[tuple[re.Pattern, str, int]] = []
def add(value, label, word=False):
if value and len(str(value)) >= 4:
v = str(value)
for form in sorted({v, v.replace("\\", "/"), v.replace("/", "\\")}, key=len, reverse=True):
pat = re.escape(form)
- subs.append((re.compile(r"(?<![\w-])" + pat + r"(?![\w-])" if word else pat, re.I), label))
+ subs.append((re.compile(r"(?<![\w-])" + pat + r"(?![\w-])" if word else pat, re.I), label, len(form)))
add(ROOT, "<strata>")
add(Path.home(), "<home>")
@@ -89,7 +89,7 @@ def redactor(extra: list[str] = (), key: str = ""):
for x in extra:
add(x, "<private>", True)
add(key, "<key>")
- subs.sort(key=lambda p: -len(p[0].pattern))
+ subs.sort(key=lambda s: -s[2]) # by the text that is replaced: the word wrappers would make a short user name outrank the folder holding it
path_user = re.compile(r"(?i)([A-Za-z]:)?([\\/])(Users|home)([\\/])(?!<)[^\\/\s\"':;,]+")
ip4 = re.compile(r"\b(?:192\.168|10\.\d{1,3}|172\.(?:1[6-9]|2\d|3[01])|100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])|169\.254)\.\d{1,3}\.\d{1,3}\b")
bearer = re.compile(r"(?i)(bearer\s+)[A-Za-z0-9._~+/=-]{8,}")
@@ -97,7 +97,7 @@ def redactor(extra: list[str] = (), key: str = ""):
def f(text):
if not isinstance(text, str):
return text
- for pat, label in subs:
+ for pat, label, _ in subs:
text = pat.sub(label, text)
text = path_user.sub(lambda m: f"{m.group(1) or ''}{m.group(2)}{m.group(3)}{m.group(4)}<user>", text)
text = bearer.sub(r"\1<key>", text)
diff --git a/tools/test_strata_bench.py b/tools/test_strata_bench.py
index 986ab1a3a..80babc65b 100644
--- a/tools/test_strata_bench.py
+++ b/tools/test_strata_bench.py
@@ -12,7 +12,7 @@ import threading
import unittest
from unittest import mock
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
-from pathlib import Path
+from pathlib import Path, PurePosixPath, PureWindowsPath
sys.path.insert(0, str(Path(__file__).resolve().parent))
import strata_bench as B # noqa: E402
@@ -186,6 +186,30 @@ class RedactionTests(unittest.TestCase):
if len(user) >= 4:
self.assertNotIn(user, red(f"hello {user} world"))
+ def test_a_folder_under_a_short_home_keeps_its_own_placeholder(self):
+ # issue #3326 with a fixed machine (user name "dgbox", the repository directly under the home folder):
+ # a name is wrapped in word bounds, which makes its pattern longer than the pattern of the folder
+ # holding it, so the name won and the report kept the folder layout instead of <strata> and <home>.
+ def red(root, home, user, host, tmp):
+ with mock.patch.object(B, "ROOT", root), mock.patch.object(B.Path, "home", return_value=home), \
+ mock.patch.object(B.getpass, "getuser", return_value=user), \
+ mock.patch.object(B.socket, "gethostname", return_value=host), \
+ mock.patch.object(B.platform, "node", return_value=host), \
+ mock.patch.object(B.tempfile, "gettempdir", return_value=tmp):
+ return B.redactor()
+
+ linux = red(PurePosixPath("/home/dgbox/Strata"), PurePosixPath("/home/dgbox"), "dgbox", "dgbox-ubuntu-server", "/tmp")
+ self.assertEqual(linux("loading /home/dgbox/Strata/strata-x.json"), "loading <strata>/strata-x.json")
+ self.assertEqual(linux("dgbox-ubuntu-server wrote /home/dgbox/Strata/bench/results/run/results.json"),
+ "<host> wrote <strata>/bench/results/run/results.json")
+ self.assertEqual(linux("in /home/dgbox/data"), "in <home>/data")
+ self.assertEqual(linux("hello dgbox world"), "hello <user> world")
+ self.assertEqual(linux("log /tmp/strata.log"), "log <tmp>/strata.log")
+ win = red(PureWindowsPath(r"C:\Users\dgbox\Strata"), PureWindowsPath(r"C:\Users\dgbox"), "dgbox", "dgbox-pc",
+ r"C:\Users\dgbox\AppData\Local\Temp")
+ self.assertEqual(win(r"in C:\Users\dgbox\data"), r"in <home>\data")
+ self.assertEqual(win(r"loading C:\Users\dgbox\Strata\strata-x.json"), r"loading <strata>\strata-x.json")
+
def test_objects_are_redacted_deeply(self):
red = B.redactor()
out = B.redact_obj({"a": [{"p": r"D:\Users\zed\x"}], "n": 3}, red)