okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b247f4ecd
main
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 4is 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>` 6into `<<user>>`. Redacting twice now gives what redacting once gives. 7 8python -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 ): 26def test_a_key_beside_hyphens_is_replaced (self ): 27clean = bench_facts .redactor (KEY ) 28self .assertEqual (clean (f"pack- { KEY } " ),"pack-<key>" ) 29self .assertEqual (clean (f" { KEY } -1" ),"<key>-1" ) 30self .assertEqual (clean (f"a- { KEY } -b and { KEY } " ),"a-<key>-b and <key>" ) 31 32def test_a_key_inside_a_longer_token_is_not_the_key (self ): 33key = "a1b2c3d4" 34clean = bench_facts .redactor (key ) 35self .assertEqual (clean (f"sha { key } ff x_ { key } { key } _y { key } 9" ),f"sha { key } ff x_ { key } { key } _y { key } 9" ) 36 37def test_a_short_key_beside_a_hyphen_is_replaced_but_a_longer_word_is_not_shortened (self ): 38clean = bench_facts .redactor ("pass" ) 39self .assertEqual (clean ("the passage and the pass-word" ),"the passage and the <key>-word" ) 40 41def test_the_command_line_of_a_run_is_clean (self ): 42clean = bench_facts .redactor (KEY ) 43line = f"strata bench run --profile p --custom-pack /home/alice/pack- { KEY } --track-notes 'key { KEY } '" 44out = clean (line ) 45self .assertNotIn (KEY ,out ) 46self .assertNotIn ("alice" ,out ) 47 48 49class TwiceIsOnce (unittest .TestCase ): 50def test_a_user_called_user_is_not_labelled_twice (self ): 51with mock .patch .object (bench_facts .getpass ,"getuser" ,return_value = "user" ): 52clean = bench_facts .redactor (KEY ) 53for text in ("/home/alice/m" ,r"C:\Users\alice\m" ,"owner user wrote this" ,"/home/user/m" ): 54once = clean (text ) 55self .assertEqual (clean (once ),once ,text ) 56self .assertNotIn ("<<" ,clean (once )) 57 58def test_a_host_called_host_is_not_labelled_twice (self ): 59with mock .patch .object (bench_facts .socket ,"gethostname" ,return_value = "host" ): 60clean = bench_facts .redactor ("" ) 61once = clean ("running on host with 3 cards" ) 62self .assertEqual (clean (once ),once ) 63self .assertIn ("<host>" ,once ) 64 65def test_the_user_name_is_still_replaced_as_a_word (self ): 66with mock .patch .object (bench_facts .getpass ,"getuser" ,return_value = "alice9" ): 67clean = bench_facts .redactor ("" ) 68self .assertEqual (clean ("by alice9 at alice90" ),"by <user> at alice90" ) 69 70 71if __name__ == "__main__" : 72unittest .main ()