keyboard-claim-audit 0.1.0__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.
- keyboard_claim_audit-0.1.0/LICENSE +21 -0
- keyboard_claim_audit-0.1.0/MANIFEST.in +2 -0
- keyboard_claim_audit-0.1.0/PKG-INFO +55 -0
- keyboard_claim_audit-0.1.0/README.md +45 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit/__init__.py +2 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit/__main__.py +38 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit/audit.py +138 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit.egg-info/PKG-INFO +55 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit.egg-info/SOURCES.txt +19 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit.egg-info/dependency_links.txt +1 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit.egg-info/entry_points.txt +2 -0
- keyboard_claim_audit-0.1.0/keyboard_claim_audit.egg-info/top_level.txt +1 -0
- keyboard_claim_audit-0.1.0/pyproject.toml +17 -0
- keyboard_claim_audit-0.1.0/setup.cfg +4 -0
- keyboard_claim_audit-0.1.0/tests/__init__.py +0 -0
- keyboard_claim_audit-0.1.0/tests/fixtures/.env +1 -0
- keyboard_claim_audit-0.1.0/tests/fixtures/bad/README.md +1 -0
- keyboard_claim_audit-0.1.0/tests/fixtures/bad/app.py +1 -0
- keyboard_claim_audit-0.1.0/tests/fixtures/good/README.md +1 -0
- keyboard_claim_audit-0.1.0/tests/fixtures/good/app.py +2 -0
- keyboard_claim_audit-0.1.0/tests/test_audit.py +167 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 keyboard-claim-audit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keyboard-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Static audit of documented synthetic key input
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# keyboard-claim-audit
|
|
12
|
+
|
|
13
|
+
Version 0.1.0. Offline static audit of documented synthetic key input against
|
|
14
|
+
provider-resolved Python AST calls. Source is parsed, never executed.
|
|
15
|
+
|
|
16
|
+
Install and run:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
python3 -m pip install .
|
|
20
|
+
keyboard-claim-audit /path/to/project
|
|
21
|
+
python3 -m keyboard_claim_audit /path/to/project --json
|
|
22
|
+
python3 -m unittest discover
|
|
23
|
+
python3 -m build
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The positional root defaults to the current directory. Options: `--json` emits
|
|
27
|
+
valid JSON; `--verbose` lists evidence paths; repeatable `--ignore GLOB` excludes
|
|
28
|
+
relative paths; `--fail-on HIGH` is the default; `--fail-on MEDIUM` also fails
|
|
29
|
+
on test-only evidence; `--version` prints 0.1.0. Usage errors exit 1.
|
|
30
|
+
PASS exits 0; FAIL exits 2. Findings contain rule, severity, and message.
|
|
31
|
+
A positive assertion without production evidence produces the HIGH rule
|
|
32
|
+
`documented-keyboard-claim-false`; test-only evidence lowers it to MEDIUM.
|
|
33
|
+
A negative assertion contradicted by production evidence produces the HIGH rule
|
|
34
|
+
`documented-no-keyboard-claim-false`. Each family produces at most one finding.
|
|
35
|
+
|
|
36
|
+
## Limitations
|
|
37
|
+
|
|
38
|
+
Only the fixed phrase vocabulary encoded in the source constitutes a claim.
|
|
39
|
+
Bare nouns, user-facing shortcuts, instructions for the user to press a key,
|
|
40
|
+
and descriptions of mouse actions, screen capture, clipboard, voice, or network
|
|
41
|
+
activity are outside scope. The audited capability is synthetic key input.
|
|
42
|
+
Root README.md and Markdown beneath any docs path component supply assertions.
|
|
43
|
+
Fenced blocks are excluded; inline code counts. Case, hyphens, contractions,
|
|
44
|
+
and whitespace are normalized within blank-line-separated paragraphs.
|
|
45
|
+
|
|
46
|
+
Evidence requires recognized calls from pyautogui, pynput.keyboard Controller
|
|
47
|
+
instances, or the keyboard library. Imports, listeners, strings, and user prompts
|
|
48
|
+
alone provide no evidence. Controller bindings must occur in the same module.
|
|
49
|
+
Shell key helpers such as xdotool and xte are outside scope. Static analysis
|
|
50
|
+
cannot establish runtime reachability or successful delivery, and does not model
|
|
51
|
+
rebinding or dynamic imports. Invalid syntax provides no evidence.
|
|
52
|
+
Tests can supply only MEDIUM evidence. Fixtures, docs, examples, and symlinked
|
|
53
|
+
files are excluded from source evidence. Files named .env are never read.
|
|
54
|
+
A positive assertion without source fails; a negative assertion without source
|
|
55
|
+
passes. No assertion passes regardless of source evidence.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# keyboard-claim-audit
|
|
2
|
+
|
|
3
|
+
Version 0.1.0. Offline static audit of documented synthetic key input against
|
|
4
|
+
provider-resolved Python AST calls. Source is parsed, never executed.
|
|
5
|
+
|
|
6
|
+
Install and run:
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
python3 -m pip install .
|
|
10
|
+
keyboard-claim-audit /path/to/project
|
|
11
|
+
python3 -m keyboard_claim_audit /path/to/project --json
|
|
12
|
+
python3 -m unittest discover
|
|
13
|
+
python3 -m build
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The positional root defaults to the current directory. Options: `--json` emits
|
|
17
|
+
valid JSON; `--verbose` lists evidence paths; repeatable `--ignore GLOB` excludes
|
|
18
|
+
relative paths; `--fail-on HIGH` is the default; `--fail-on MEDIUM` also fails
|
|
19
|
+
on test-only evidence; `--version` prints 0.1.0. Usage errors exit 1.
|
|
20
|
+
PASS exits 0; FAIL exits 2. Findings contain rule, severity, and message.
|
|
21
|
+
A positive assertion without production evidence produces the HIGH rule
|
|
22
|
+
`documented-keyboard-claim-false`; test-only evidence lowers it to MEDIUM.
|
|
23
|
+
A negative assertion contradicted by production evidence produces the HIGH rule
|
|
24
|
+
`documented-no-keyboard-claim-false`. Each family produces at most one finding.
|
|
25
|
+
|
|
26
|
+
## Limitations
|
|
27
|
+
|
|
28
|
+
Only the fixed phrase vocabulary encoded in the source constitutes a claim.
|
|
29
|
+
Bare nouns, user-facing shortcuts, instructions for the user to press a key,
|
|
30
|
+
and descriptions of mouse actions, screen capture, clipboard, voice, or network
|
|
31
|
+
activity are outside scope. The audited capability is synthetic key input.
|
|
32
|
+
Root README.md and Markdown beneath any docs path component supply assertions.
|
|
33
|
+
Fenced blocks are excluded; inline code counts. Case, hyphens, contractions,
|
|
34
|
+
and whitespace are normalized within blank-line-separated paragraphs.
|
|
35
|
+
|
|
36
|
+
Evidence requires recognized calls from pyautogui, pynput.keyboard Controller
|
|
37
|
+
instances, or the keyboard library. Imports, listeners, strings, and user prompts
|
|
38
|
+
alone provide no evidence. Controller bindings must occur in the same module.
|
|
39
|
+
Shell key helpers such as xdotool and xte are outside scope. Static analysis
|
|
40
|
+
cannot establish runtime reachability or successful delivery, and does not model
|
|
41
|
+
rebinding or dynamic imports. Invalid syntax provides no evidence.
|
|
42
|
+
Tests can supply only MEDIUM evidence. Fixtures, docs, examples, and symlinked
|
|
43
|
+
files are excluded from source evidence. Files named .env are never read.
|
|
44
|
+
A positive assertion without source fails; a negative assertion without source
|
|
45
|
+
passes. No assertion passes regardless of source evidence.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from . import __version__
|
|
5
|
+
from .audit import audit
|
|
6
|
+
|
|
7
|
+
class Parser(argparse.ArgumentParser):
|
|
8
|
+
def error(self, message):
|
|
9
|
+
self.print_usage(sys.stderr)
|
|
10
|
+
self.exit(1, message + "\n")
|
|
11
|
+
|
|
12
|
+
def main(argv=None):
|
|
13
|
+
parser = Parser(description="Audit documented synthetic key input against source.")
|
|
14
|
+
parser.add_argument('root', nargs='?', default='.')
|
|
15
|
+
parser.add_argument('--json', action='store_true')
|
|
16
|
+
parser.add_argument('--verbose', action='store_true')
|
|
17
|
+
parser.add_argument('--ignore', action='append', default=[])
|
|
18
|
+
parser.add_argument('--fail-on', choices=['HIGH', 'MEDIUM'], default='HIGH')
|
|
19
|
+
parser.add_argument('--version', action='version', version=__version__)
|
|
20
|
+
args = parser.parse_args(argv)
|
|
21
|
+
try:
|
|
22
|
+
result = audit(args.root, args.ignore, args.fail_on)
|
|
23
|
+
except (OSError, UnicodeError, ValueError) as exc:
|
|
24
|
+
print(str(exc), file=sys.stderr)
|
|
25
|
+
return 1
|
|
26
|
+
if args.json:
|
|
27
|
+
print(json.dumps(result))
|
|
28
|
+
else:
|
|
29
|
+
print(result['verdict'])
|
|
30
|
+
for finding in result['findings']:
|
|
31
|
+
print("{severity} {rule}: {message}".format(**finding))
|
|
32
|
+
if args.verbose:
|
|
33
|
+
print('Evidence: ' + ', '.join(result['evidence']))
|
|
34
|
+
print('Test evidence: ' + ', '.join(result['test_evidence']))
|
|
35
|
+
return 2 if result['verdict'] == 'FAIL' else 0
|
|
36
|
+
|
|
37
|
+
if __name__ == '__main__':
|
|
38
|
+
sys.exit(main())
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import fnmatch
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
KEYBOARD = (
|
|
7
|
+
"automates keyboard input", "automate keyboard input", "simulates keyboard input",
|
|
8
|
+
"simulate keyboard input", "keyboard input automation", "presses keys automatically",
|
|
9
|
+
"press keys automatically", "types keys automatically", "type keys automatically",
|
|
10
|
+
"sends keystrokes", "send keystrokes", "simulates keystrokes", "simulate keystrokes",
|
|
11
|
+
"injects keystrokes", "inject keystrokes", "emulates keystrokes", "emulate keystrokes",
|
|
12
|
+
"keystroke simulation", "keystroke automation", "simulated keystrokes",
|
|
13
|
+
"automated keystrokes", "keyboard automation", "keyboard injection",
|
|
14
|
+
)
|
|
15
|
+
NOKEYBOARD = (
|
|
16
|
+
"does not send keystrokes", "does not simulate keystrokes",
|
|
17
|
+
"does not automate keyboard input", "does not simulate keyboard input",
|
|
18
|
+
"does not inject keystrokes", "keyboard automation not supported",
|
|
19
|
+
"keystroke simulation not supported", "no keyboard automation",
|
|
20
|
+
"no keystroke simulation", "without keyboard automation",
|
|
21
|
+
"without keystroke simulation", "no keyboard injection",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def normalize(text):
|
|
25
|
+
return re.sub(r"\s+", " ", text.lower().replace("n't", " not").replace("-", " ")).strip()
|
|
26
|
+
|
|
27
|
+
def pattern(phrases):
|
|
28
|
+
return re.compile(r"\b(?:" + "|".join(re.escape(p) for p in sorted(phrases, key=len, reverse=True)) + r")\b")
|
|
29
|
+
|
|
30
|
+
def claims(text):
|
|
31
|
+
lines = []
|
|
32
|
+
fence = None
|
|
33
|
+
for line in text.splitlines():
|
|
34
|
+
match = re.match(r"^\s{0,3}(`{3,}|~{3,})", line)
|
|
35
|
+
if match:
|
|
36
|
+
token = match.group(1)
|
|
37
|
+
if fence is None:
|
|
38
|
+
fence = token
|
|
39
|
+
elif token[0] == fence[0] and len(token) >= len(fence):
|
|
40
|
+
fence = None
|
|
41
|
+
continue
|
|
42
|
+
if fence is None:
|
|
43
|
+
lines.append(line)
|
|
44
|
+
positive = negative = False
|
|
45
|
+
for para in re.split(r"\n\s*\n", "\n".join(lines)):
|
|
46
|
+
para = normalize(para)
|
|
47
|
+
negative |= bool(pattern(NOKEYBOARD).search(para))
|
|
48
|
+
positive |= bool(pattern(KEYBOARD).search(pattern(NOKEYBOARD).sub(" ", para)))
|
|
49
|
+
return positive, negative
|
|
50
|
+
|
|
51
|
+
def dotted(node):
|
|
52
|
+
if isinstance(node, ast.Name):
|
|
53
|
+
return node.id
|
|
54
|
+
if isinstance(node, ast.Attribute):
|
|
55
|
+
base = dotted(node.value)
|
|
56
|
+
return base + "." + node.attr if base else ""
|
|
57
|
+
return ""
|
|
58
|
+
|
|
59
|
+
def evidence(text):
|
|
60
|
+
try:
|
|
61
|
+
tree = ast.parse(text)
|
|
62
|
+
except SyntaxError:
|
|
63
|
+
return False
|
|
64
|
+
aliases = {}
|
|
65
|
+
for node in ast.walk(tree):
|
|
66
|
+
if isinstance(node, ast.Import):
|
|
67
|
+
for a in node.names:
|
|
68
|
+
if a.name == "pyautogui" or a.name.startswith("pyautogui.") or a.name in ("keyboard", "pynput.keyboard") or a.name.startswith("pynput.keyboard."):
|
|
69
|
+
aliases[a.asname or a.name.split('.')[0]] = a.name if a.asname else a.name.split('.')[0]
|
|
70
|
+
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
71
|
+
m = node.module
|
|
72
|
+
if m == "pyautogui" or m.startswith("pyautogui.") or m == "keyboard" or m == "pynput.keyboard" or m.startswith("pynput.keyboard.") or m == "pynput":
|
|
73
|
+
for a in node.names:
|
|
74
|
+
if m != "pynput" or a.name == "keyboard":
|
|
75
|
+
aliases[a.asname or a.name] = m + "." + a.name
|
|
76
|
+
def resolve(node):
|
|
77
|
+
path = dotted(node)
|
|
78
|
+
head, sep, tail = path.partition('.')
|
|
79
|
+
return aliases.get(head, "") + (sep + tail if sep else "") if head in aliases else ""
|
|
80
|
+
def controller(node):
|
|
81
|
+
if not isinstance(node, ast.Call):
|
|
82
|
+
return False
|
|
83
|
+
path = resolve(node.func)
|
|
84
|
+
return path.startswith("pynput.keyboard.") and path.endswith(".Controller")
|
|
85
|
+
bound = set()
|
|
86
|
+
for node in ast.walk(tree):
|
|
87
|
+
if isinstance(node, ast.Assign) and controller(node.value):
|
|
88
|
+
for target in node.targets:
|
|
89
|
+
if isinstance(target, ast.Name) or (isinstance(target, ast.Attribute) and isinstance(target.value, ast.Name) and target.value.id == "self"):
|
|
90
|
+
bound.add(dotted(target))
|
|
91
|
+
for node in ast.walk(tree):
|
|
92
|
+
if not isinstance(node, ast.Call):
|
|
93
|
+
continue
|
|
94
|
+
path = resolve(node.func)
|
|
95
|
+
method = path.rsplit('.', 1)[-1]
|
|
96
|
+
if path.startswith("pyautogui.") and method in {"press", "hotkey", "typewrite", "write", "keyDown", "keyUp"}:
|
|
97
|
+
return True
|
|
98
|
+
if path.startswith("keyboard.") and path.count('.') == 1 and method in {"press", "release", "send", "write"}:
|
|
99
|
+
return True
|
|
100
|
+
if isinstance(node.func, ast.Attribute) and node.func.attr in {"press", "release", "type"}:
|
|
101
|
+
receiver = node.func.value
|
|
102
|
+
if (dotted(receiver) and dotted(receiver) in bound) or controller(receiver):
|
|
103
|
+
return True
|
|
104
|
+
return False
|
|
105
|
+
|
|
106
|
+
def audit(root, ignore=(), fail_on="HIGH"):
|
|
107
|
+
root = Path(root)
|
|
108
|
+
if not root.is_dir():
|
|
109
|
+
raise ValueError("root must be a readable directory")
|
|
110
|
+
if not root.stat().st_mode & 0o444:
|
|
111
|
+
raise ValueError("root must be a readable directory")
|
|
112
|
+
pos = neg = False
|
|
113
|
+
prod, tests = [], []
|
|
114
|
+
for path in sorted(root.rglob('*')):
|
|
115
|
+
rel = path.relative_to(root)
|
|
116
|
+
if path.is_symlink() or any(p.is_symlink() for p in path.parents if p != root) or not path.is_file():
|
|
117
|
+
continue
|
|
118
|
+
if any(fnmatch.fnmatch(rel.as_posix(), g) for g in ignore):
|
|
119
|
+
continue
|
|
120
|
+
parts = rel.parts
|
|
121
|
+
if rel.as_posix() == 'README.md' or ('docs' in parts[:-1] and path.suffix.lower() == '.md'):
|
|
122
|
+
p, n = claims(path.read_text(encoding='utf-8'))
|
|
123
|
+
pos |= p
|
|
124
|
+
neg |= n
|
|
125
|
+
if path.suffix != '.py':
|
|
126
|
+
continue
|
|
127
|
+
if any(p in {'fixtures', 'docs', 'examples'} for p in parts[:-1]):
|
|
128
|
+
continue
|
|
129
|
+
is_test = 'tests' in parts[:-1] or path.name.startswith('test_') or path.name.endswith('_test.py')
|
|
130
|
+
if evidence(path.read_text(encoding='utf-8')):
|
|
131
|
+
(tests if is_test else prod).append(rel.as_posix())
|
|
132
|
+
findings = []
|
|
133
|
+
if pos and not prod:
|
|
134
|
+
findings.append(dict(rule='documented-keyboard-claim-false', severity='MEDIUM' if tests else 'HIGH', message='Documented synthetic key input lacks production evidence.'))
|
|
135
|
+
if neg and prod:
|
|
136
|
+
findings.append(dict(rule='documented-no-keyboard-claim-false', severity='HIGH', message='Documented absence conflicts with production synthetic key input.'))
|
|
137
|
+
failed = any(f['severity'] == 'HIGH' or fail_on == 'MEDIUM' for f in findings)
|
|
138
|
+
return dict(verdict='FAIL' if failed else 'PASS', findings=findings, claims=dict(positive=pos, negative=neg), evidence=prod, test_evidence=tests)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keyboard-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Static audit of documented synthetic key input
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# keyboard-claim-audit
|
|
12
|
+
|
|
13
|
+
Version 0.1.0. Offline static audit of documented synthetic key input against
|
|
14
|
+
provider-resolved Python AST calls. Source is parsed, never executed.
|
|
15
|
+
|
|
16
|
+
Install and run:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
python3 -m pip install .
|
|
20
|
+
keyboard-claim-audit /path/to/project
|
|
21
|
+
python3 -m keyboard_claim_audit /path/to/project --json
|
|
22
|
+
python3 -m unittest discover
|
|
23
|
+
python3 -m build
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The positional root defaults to the current directory. Options: `--json` emits
|
|
27
|
+
valid JSON; `--verbose` lists evidence paths; repeatable `--ignore GLOB` excludes
|
|
28
|
+
relative paths; `--fail-on HIGH` is the default; `--fail-on MEDIUM` also fails
|
|
29
|
+
on test-only evidence; `--version` prints 0.1.0. Usage errors exit 1.
|
|
30
|
+
PASS exits 0; FAIL exits 2. Findings contain rule, severity, and message.
|
|
31
|
+
A positive assertion without production evidence produces the HIGH rule
|
|
32
|
+
`documented-keyboard-claim-false`; test-only evidence lowers it to MEDIUM.
|
|
33
|
+
A negative assertion contradicted by production evidence produces the HIGH rule
|
|
34
|
+
`documented-no-keyboard-claim-false`. Each family produces at most one finding.
|
|
35
|
+
|
|
36
|
+
## Limitations
|
|
37
|
+
|
|
38
|
+
Only the fixed phrase vocabulary encoded in the source constitutes a claim.
|
|
39
|
+
Bare nouns, user-facing shortcuts, instructions for the user to press a key,
|
|
40
|
+
and descriptions of mouse actions, screen capture, clipboard, voice, or network
|
|
41
|
+
activity are outside scope. The audited capability is synthetic key input.
|
|
42
|
+
Root README.md and Markdown beneath any docs path component supply assertions.
|
|
43
|
+
Fenced blocks are excluded; inline code counts. Case, hyphens, contractions,
|
|
44
|
+
and whitespace are normalized within blank-line-separated paragraphs.
|
|
45
|
+
|
|
46
|
+
Evidence requires recognized calls from pyautogui, pynput.keyboard Controller
|
|
47
|
+
instances, or the keyboard library. Imports, listeners, strings, and user prompts
|
|
48
|
+
alone provide no evidence. Controller bindings must occur in the same module.
|
|
49
|
+
Shell key helpers such as xdotool and xte are outside scope. Static analysis
|
|
50
|
+
cannot establish runtime reachability or successful delivery, and does not model
|
|
51
|
+
rebinding or dynamic imports. Invalid syntax provides no evidence.
|
|
52
|
+
Tests can supply only MEDIUM evidence. Fixtures, docs, examples, and symlinked
|
|
53
|
+
files are excluded from source evidence. Files named .env are never read.
|
|
54
|
+
A positive assertion without source fails; a negative assertion without source
|
|
55
|
+
passes. No assertion passes regardless of source evidence.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
keyboard_claim_audit/__init__.py
|
|
6
|
+
keyboard_claim_audit/__main__.py
|
|
7
|
+
keyboard_claim_audit/audit.py
|
|
8
|
+
keyboard_claim_audit.egg-info/PKG-INFO
|
|
9
|
+
keyboard_claim_audit.egg-info/SOURCES.txt
|
|
10
|
+
keyboard_claim_audit.egg-info/dependency_links.txt
|
|
11
|
+
keyboard_claim_audit.egg-info/entry_points.txt
|
|
12
|
+
keyboard_claim_audit.egg-info/top_level.txt
|
|
13
|
+
tests/__init__.py
|
|
14
|
+
tests/test_audit.py
|
|
15
|
+
tests/fixtures/.env
|
|
16
|
+
tests/fixtures/bad/README.md
|
|
17
|
+
tests/fixtures/bad/app.py
|
|
18
|
+
tests/fixtures/good/README.md
|
|
19
|
+
tests/fixtures/good/app.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
keyboard_claim_audit
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "keyboard-claim-audit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Static audit of documented synthetic key input"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
keyboard-claim-audit = "keyboard_claim_audit.__main__:main"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
include = ["keyboard_claim_audit*"]
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MARKER_ONLY_NOT_A_SECRET
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Sends keystrokes.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import pyautogui
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Sends keystrokes.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Required cases 1–29 below; generated phrase tests exhaust both families (case 30)."""
|
|
2
|
+
import contextlib
|
|
3
|
+
import io
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import re
|
|
7
|
+
import tempfile
|
|
8
|
+
import unittest
|
|
9
|
+
from unittest.mock import patch
|
|
10
|
+
|
|
11
|
+
from keyboard_claim_audit.audit import audit, claims, evidence, KEYBOARD, NOKEYBOARD, normalize, pattern
|
|
12
|
+
from keyboard_claim_audit.__main__ import main
|
|
13
|
+
|
|
14
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
15
|
+
GOOD = 'import pyautogui\npyautogui.press("a")'
|
|
16
|
+
|
|
17
|
+
class AuditTests(unittest.TestCase):
|
|
18
|
+
def run_case(self, source='', doc='sends keystrokes', path='app.py', **kwargs):
|
|
19
|
+
with tempfile.TemporaryDirectory() as temp:
|
|
20
|
+
root = Path(temp)
|
|
21
|
+
(root / 'README.md').write_text(doc)
|
|
22
|
+
if source:
|
|
23
|
+
target = root / path
|
|
24
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
25
|
+
target.write_text(source)
|
|
26
|
+
return audit(root, **kwargs)
|
|
27
|
+
|
|
28
|
+
def good(self, source):
|
|
29
|
+
result = self.run_case(source)
|
|
30
|
+
self.assertEqual(result['verdict'], 'PASS')
|
|
31
|
+
self.assertEqual(result['findings'], [])
|
|
32
|
+
self.assertTrue(result['evidence'])
|
|
33
|
+
|
|
34
|
+
def bad(self, source):
|
|
35
|
+
result = self.run_case(source)
|
|
36
|
+
self.assertEqual(result['verdict'], 'FAIL')
|
|
37
|
+
self.assertEqual([(f['rule'], f['severity']) for f in result['findings']], [('documented-keyboard-claim-false', 'HIGH')])
|
|
38
|
+
|
|
39
|
+
def test_01_plain(self): self.good(GOOD)
|
|
40
|
+
def test_02_alias(self): self.good('import pyautogui as pg\npg.typewrite("a")')
|
|
41
|
+
def test_03_from_alias(self): self.good('from pyautogui import hotkey as hk\nhk("a")')
|
|
42
|
+
def test_04_bound(self): self.good('from pynput.keyboard import Controller\nctl = Controller()\nctl.press("a")')
|
|
43
|
+
def test_05_self(self): self.good('from pynput.keyboard import Controller\nclass A:\n def f(self):\n self.ctl = Controller()\n self.ctl.type("a")')
|
|
44
|
+
def test_06_keyboard(self): self.good('import keyboard\nkeyboard.send("a")')
|
|
45
|
+
def test_07_keyboard_from(self): self.good('from keyboard import write\nwrite("a")')
|
|
46
|
+
def test_08_up_down(self): self.good('import pyautogui\npyautogui.keyDown("a")\npyautogui.keyUp("a")')
|
|
47
|
+
def test_09_import(self):
|
|
48
|
+
for source in ['import pyautogui', 'import keyboard', 'from pynput.keyboard import Controller']:
|
|
49
|
+
self.bad(source)
|
|
50
|
+
def test_10_string(self): self.bad('value = "keystroke"')
|
|
51
|
+
def test_11_mouse(self): self.bad('import pyautogui\npyautogui.click()\npyautogui.moveTo(1,2)')
|
|
52
|
+
def test_12_screenshot(self): self.bad('import pyautogui\npyautogui.screenshot()')
|
|
53
|
+
def test_13_input(self): self.bad('input("key")')
|
|
54
|
+
def test_14_listener(self): self.bad('from pynput.keyboard import Listener\nx=Listener()\nx.start()\nwidget.bind("a", callback)')
|
|
55
|
+
def test_15_hotkey(self):
|
|
56
|
+
for method in ['add_hotkey', 'on_press', 'on_release', 'wait', 'is_pressed', 'read_key']:
|
|
57
|
+
self.bad('import keyboard\nkeyboard.' + method + '()')
|
|
58
|
+
def test_16_unbound(self): self.bad('from pynput.keyboard import Controller\nctl.press("a")')
|
|
59
|
+
def test_17_negative(self):
|
|
60
|
+
result = self.run_case(GOOD, 'no keyboard automation')
|
|
61
|
+
self.assertEqual([(f['rule'], f['severity']) for f in result['findings']], [('documented-no-keyboard-claim-false', 'HIGH')])
|
|
62
|
+
self.assertEqual(result['verdict'], 'FAIL')
|
|
63
|
+
def test_18_no_claim(self): self.assertEqual(self.run_case(GOOD, 'Hello')['findings'], [])
|
|
64
|
+
def test_19_noun(self): self.assertEqual(self.run_case('import pyautogui', 'the keyboard chapter explains delivery')['findings'], [])
|
|
65
|
+
def test_20_shortcuts(self): self.assertEqual(self.run_case(GOOD, 'supports keyboard shortcuts')['findings'], [])
|
|
66
|
+
def test_21_user(self): self.assertEqual(self.run_case('import pyautogui', 'press any key to continue')['findings'], [])
|
|
67
|
+
def test_22_no_source(self):
|
|
68
|
+
self.bad('')
|
|
69
|
+
self.assertEqual(self.run_case('', 'no keyboard automation')['findings'], [])
|
|
70
|
+
def test_23_test_only(self):
|
|
71
|
+
for path in ['tests/app.py', 'test_app.py', 'app_test.py']:
|
|
72
|
+
result = self.run_case(GOOD, path=path)
|
|
73
|
+
self.assertEqual(result['findings'][0]['severity'], 'MEDIUM')
|
|
74
|
+
self.assertEqual(result['verdict'], 'PASS')
|
|
75
|
+
self.assertEqual(self.run_case(GOOD, path=path, fail_on='MEDIUM')['verdict'], 'FAIL')
|
|
76
|
+
def test_24_fence_inline(self):
|
|
77
|
+
self.assertEqual(self.run_case('', '```text\nsends keystrokes\n```')['findings'], [])
|
|
78
|
+
self.assertEqual(self.run_case('', '`sends keystrokes`')['verdict'], 'FAIL')
|
|
79
|
+
def test_25_span(self): self.assertEqual(claims('does not send keystrokes'), (False, True))
|
|
80
|
+
def test_26_self(self):
|
|
81
|
+
result = audit(ROOT)
|
|
82
|
+
self.assertEqual(result['verdict'], 'PASS')
|
|
83
|
+
self.assertEqual(result['claims'], dict(positive=False, negative=False))
|
|
84
|
+
text = normalize((ROOT / 'README.md').read_text())
|
|
85
|
+
self.assertIsNone(pattern(KEYBOARD + NOKEYBOARD).search(text))
|
|
86
|
+
self.assertIsNone(re.search(r'\b(using|uses|with|via|over|supports|sends|send) keyboard claim audit\b', text))
|
|
87
|
+
def cli(self, args):
|
|
88
|
+
output = io.StringIO()
|
|
89
|
+
with contextlib.redirect_stdout(output): code = main(args)
|
|
90
|
+
return code, output.getvalue()
|
|
91
|
+
def test_27_cli(self):
|
|
92
|
+
code, out = self.cli([str(ROOT / 'tests/fixtures/bad'), '--json'])
|
|
93
|
+
self.assertEqual(code, 2)
|
|
94
|
+
self.assertEqual(json.loads(out)['verdict'], 'FAIL')
|
|
95
|
+
code, out = self.cli([str(ROOT / 'tests/fixtures/good'), '--verbose'])
|
|
96
|
+
self.assertEqual(code, 0)
|
|
97
|
+
self.assertIn('app.py', out)
|
|
98
|
+
self.assertEqual(self.cli([str(ROOT / 'tests/fixtures/bad'), '--ignore', 'README.md'])[0], 0)
|
|
99
|
+
self.assertEqual(self.cli(['/nonexistent-audit-root'])[0], 1)
|
|
100
|
+
with contextlib.redirect_stdout(io.StringIO()) as out:
|
|
101
|
+
with self.assertRaises(SystemExit) as raised: main(['--version'])
|
|
102
|
+
self.assertEqual(raised.exception.code, 0)
|
|
103
|
+
self.assertEqual(out.getvalue().strip(), '0.1.0')
|
|
104
|
+
with contextlib.redirect_stderr(io.StringIO()):
|
|
105
|
+
with self.assertRaises(SystemExit) as raised: main(['--invalid'])
|
|
106
|
+
self.assertEqual(raised.exception.code, 1)
|
|
107
|
+
def test_28_env(self):
|
|
108
|
+
original = io.open
|
|
109
|
+
opened = []
|
|
110
|
+
def guarded(file, *args, **kwargs):
|
|
111
|
+
opened.append(str(file))
|
|
112
|
+
self.assertNotEqual(Path(file).name, '.env')
|
|
113
|
+
return original(file, *args, **kwargs)
|
|
114
|
+
with patch('io.open', guarded): audit(ROOT / 'tests/fixtures')
|
|
115
|
+
self.assertFalse(any(Path(p).name == '.env' for p in opened))
|
|
116
|
+
def test_29_packaging(self):
|
|
117
|
+
for path in list((ROOT / 'keyboard_claim_audit').glob('*.py')) + list((ROOT / 'tests').glob('*.py')) + [ROOT/'README.md', ROOT/'pyproject.toml']:
|
|
118
|
+
self.assertIsNone(re.search(r'(?<![\w-])py' + r'thon(?![\w-])', path.read_text()), str(path))
|
|
119
|
+
project = (ROOT/'pyproject.toml').read_text()
|
|
120
|
+
self.assertIn('setuptools>=77', project)
|
|
121
|
+
self.assertIn('license = "MIT"', project)
|
|
122
|
+
self.assertIn('recursive-include tests', (ROOT/'MANIFEST.in').read_text())
|
|
123
|
+
def test_provider_edges(self):
|
|
124
|
+
for source in ['from pynput import keyboard\nkeyboard.Controller().press("a")', 'import pynput.keyboard as kb\nc=kb.Controller()\nc.release("a")', 'import pynput.keyboard\npynput.keyboard.Controller().type("a")', 'from pynput.keyboard import Controller as C\nC().press("a")', 'import keyboard as kbd\nkbd.release("a")', 'from keyboard import send as s\ns("a")', 'from pyautogui.sub import press as p\np("a")']:
|
|
125
|
+
self.good(source)
|
|
126
|
+
for source in ['import pynput\npynput.keyboard.Controller().press("a")', 'from other import press\npress("a")', 'def key_action():\n print("a")', '@app.get("/")\ndef f():\n return "a"', 'import subprocess\nsubprocess.run(["xdotool", "key", "a"])']:
|
|
127
|
+
self.bad(source)
|
|
128
|
+
def test_scope(self):
|
|
129
|
+
for path in ['docs/app.py', 'fixtures/app.py', 'examples/app.py']:
|
|
130
|
+
self.assertEqual(self.run_case(GOOD, path=path)['findings'][0]['severity'], 'HIGH')
|
|
131
|
+
with tempfile.TemporaryDirectory() as temp:
|
|
132
|
+
root = Path(temp)
|
|
133
|
+
(root/'README.md').write_text('sends keystrokes')
|
|
134
|
+
(root/'app.py').symlink_to(ROOT/'tests/fixtures/good/app.py')
|
|
135
|
+
self.assertEqual(audit(root)['verdict'], 'FAIL')
|
|
136
|
+
(root/'docs').mkdir()
|
|
137
|
+
(root/'docs/a.md').write_text('no keyboard automation')
|
|
138
|
+
(root/'app.py').unlink()
|
|
139
|
+
(root/'app.py').write_text(GOOD)
|
|
140
|
+
self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')
|
|
141
|
+
self.assertEqual(audit(root, ['docs/*'])['verdict'], 'PASS')
|
|
142
|
+
def test_normalization(self):
|
|
143
|
+
self.assertEqual(claims('SENDS-\nKEYSTROKES'), (True, False))
|
|
144
|
+
self.assertEqual(claims("doesn't send keystrokes"), (False, True))
|
|
145
|
+
self.assertEqual(claims('sends\n\nkeystrokes'), (False, False))
|
|
146
|
+
self.assertEqual(claims('xsends keystrokesx'), (False, False))
|
|
147
|
+
def test_module_pairing(self):
|
|
148
|
+
with tempfile.TemporaryDirectory() as temp:
|
|
149
|
+
root=Path(temp)
|
|
150
|
+
(root/'README.md').write_text('sends keystrokes')
|
|
151
|
+
(root/'a.py').write_text('from pynput.keyboard import Controller\nc=Controller()')
|
|
152
|
+
(root/'b.py').write_text('c.press("a")')
|
|
153
|
+
self.assertEqual(audit(root)['verdict'], 'FAIL')
|
|
154
|
+
|
|
155
|
+
# Each generated test covers precisely the corresponding constant's phrase.
|
|
156
|
+
def phrase_test(phrase, negative):
|
|
157
|
+
def test(self):
|
|
158
|
+
self.assertEqual(claims(phrase), (not negative, negative))
|
|
159
|
+
result = self.run_case(GOOD if negative else '', phrase)
|
|
160
|
+
self.assertEqual(result['verdict'], 'FAIL')
|
|
161
|
+
self.assertEqual(len(result['findings']), 1)
|
|
162
|
+
self.assertEqual(result['findings'][0]['severity'], 'HIGH')
|
|
163
|
+
self.assertEqual(result['findings'][0]['rule'], 'documented-no-keyboard-claim-false' if negative else 'documented-keyboard-claim-false')
|
|
164
|
+
return test
|
|
165
|
+
for family, phrases, negative in [('positive', KEYBOARD, False), ('negative', NOKEYBOARD, True)]:
|
|
166
|
+
for index, phrase in enumerate(phrases):
|
|
167
|
+
setattr(AuditTests, 'test_phrase_%s_%02d' % (family, index), phrase_test(phrase, negative))
|