okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0213-qatui (final d33d45ade) into f-0213-intb247f4ecd

main
3.1 KiB72 linesraw
1"""Round 0213 QATUI: the benchmark redaction (found on l620 in a real results.json).
2
3- A key written next to a hyphen (`--custom-pack /home/x/pack-<key>`) stayed in results.json: the whole-word rule treated the hyphen as part of the word. Now a hyphen
4  is a boundary; letters, digits and the underscore still are not (a key inside `sha<key>ff` is not the key).
5- `run.command` is redacted when it is built and the whole document again when it is written. For a user called "user" the second pass turned the label `<user>`
6  into `<<user>>`. Redacting twice now gives what redacting once gives.
7
8    python -m pytest tests/terminal/test_bench_redaction_0213_qatui.py
9"""
10from __future__ import annotations
11
12import sys
13import unittest
14from pathlib import Path
15from unittest import mock
16
17ROOT = Path(__file__).resolve().parents[2]
18sys.path.insert(0, str(ROOT))
19
20from strata_cli import bench_facts  # noqa: E402
21
22KEY = "qatui-bench-key-0213-xyz"
23
24
25class KeyNextToHyphens(unittest.TestCase):
26    def test_a_key_beside_hyphens_is_replaced(self):
27        clean = bench_facts.redactor(KEY)
28        self.assertEqual(clean(f"pack-{KEY}"), "pack-<key>")
29        self.assertEqual(clean(f"{KEY}-1"), "<key>-1")
30        self.assertEqual(clean(f"a-{KEY}-b and {KEY}"), "a-<key>-b and <key>")
31
32    def test_a_key_inside_a_longer_token_is_not_the_key(self):
33        key = "a1b2c3d4"
34        clean = bench_facts.redactor(key)
35        self.assertEqual(clean(f"sha{key}ff x_{key} {key}_y {key}9"), f"sha{key}ff x_{key} {key}_y {key}9")
36
37    def test_a_short_key_beside_a_hyphen_is_replaced_but_a_longer_word_is_not_shortened(self):
38        clean = bench_facts.redactor("pass")
39        self.assertEqual(clean("the passage and the pass-word"), "the passage and the <key>-word")
40
41    def test_the_command_line_of_a_run_is_clean(self):
42        clean = bench_facts.redactor(KEY)
43        line = f"strata bench run --profile p --custom-pack /home/alice/pack-{KEY} --track-notes 'key {KEY}'"
44        out = clean(line)
45        self.assertNotIn(KEY, out)
46        self.assertNotIn("alice", out)
47
48
49class TwiceIsOnce(unittest.TestCase):
50    def test_a_user_called_user_is_not_labelled_twice(self):
51        with mock.patch.object(bench_facts.getpass, "getuser", return_value="user"):
52            clean = bench_facts.redactor(KEY)
53        for text in ("/home/alice/m", r"C:\Users\alice\m", "owner user wrote this", "/home/user/m"):
54            once = clean(text)
55            self.assertEqual(clean(once), once, text)
56            self.assertNotIn("<<", clean(once))
57
58    def test_a_host_called_host_is_not_labelled_twice(self):
59        with mock.patch.object(bench_facts.socket, "gethostname", return_value="host"):
60            clean = bench_facts.redactor("")
61        once = clean("running on host with 3 cards")
62        self.assertEqual(clean(once), once)
63        self.assertIn("<host>", once)
64
65    def test_the_user_name_is_still_replaced_as_a_word(self):
66        with mock.patch.object(bench_facts.getpass, "getuser", return_value="alice9"):
67            clean = bench_facts.redactor("")
68        self.assertEqual(clean("by alice9 at alice90"), "by <user> at alice90")
69
70
71if __name__ == "__main__":
72    unittest.main()