microphone-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.
Files changed (26) hide show
  1. microphone_claim_audit-0.1.0/LICENSE +21 -0
  2. microphone_claim_audit-0.1.0/MANIFEST.in +2 -0
  3. microphone_claim_audit-0.1.0/PKG-INFO +67 -0
  4. microphone_claim_audit-0.1.0/README.md +57 -0
  5. microphone_claim_audit-0.1.0/microphone_claim_audit/__init__.py +2 -0
  6. microphone_claim_audit-0.1.0/microphone_claim_audit/__main__.py +41 -0
  7. microphone_claim_audit-0.1.0/microphone_claim_audit/audit.py +150 -0
  8. microphone_claim_audit-0.1.0/microphone_claim_audit/phrases.py +2 -0
  9. microphone_claim_audit-0.1.0/microphone_claim_audit.egg-info/PKG-INFO +67 -0
  10. microphone_claim_audit-0.1.0/microphone_claim_audit.egg-info/SOURCES.txt +24 -0
  11. microphone_claim_audit-0.1.0/microphone_claim_audit.egg-info/dependency_links.txt +1 -0
  12. microphone_claim_audit-0.1.0/microphone_claim_audit.egg-info/entry_points.txt +2 -0
  13. microphone_claim_audit-0.1.0/microphone_claim_audit.egg-info/top_level.txt +1 -0
  14. microphone_claim_audit-0.1.0/pyproject.toml +17 -0
  15. microphone_claim_audit-0.1.0/setup.cfg +4 -0
  16. microphone_claim_audit-0.1.0/tests/__init__.py +0 -0
  17. microphone_claim_audit-0.1.0/tests/fixtures/.env +1 -0
  18. microphone_claim_audit-0.1.0/tests/fixtures/bad/README.md +1 -0
  19. microphone_claim_audit-0.1.0/tests/fixtures/bad/app.py +1 -0
  20. microphone_claim_audit-0.1.0/tests/fixtures/good/README.md +1 -0
  21. microphone_claim_audit-0.1.0/tests/fixtures/good/app.py +2 -0
  22. microphone_claim_audit-0.1.0/tests/fixtures/no_microphone/README.md +1 -0
  23. microphone_claim_audit-0.1.0/tests/fixtures/no_microphone/app.py +2 -0
  24. microphone_claim_audit-0.1.0/tests/fixtures/tests_only/README.md +1 -0
  25. microphone_claim_audit-0.1.0/tests/fixtures/tests_only/tests/capture.py +2 -0
  26. microphone_claim_audit-0.1.0/tests/test_audit.py +194 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 microphone-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,2 @@
1
+ include LICENSE
2
+ recursive-include tests *.py *.md .env
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: microphone-claim-audit
3
+ Version: 0.1.0
4
+ Summary: Offline static audit of documented local audio input capture
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
+ # microphone-claim-audit
12
+
13
+ An offline static audit comparing documentation about local audio input capture
14
+ with provider-resolved calls in Python source. Source is parsed, never executed.
15
+ There are no runtime dependencies.
16
+
17
+ Install and run:
18
+
19
+ ```sh
20
+ python3 -m pip install .
21
+ microphone-claim-audit /path/to/project --json
22
+ python3 -m microphone_claim_audit /path/to/project --verbose
23
+ python3 -m unittest discover
24
+ python3 -m build
25
+ ```
26
+
27
+ The positional root must be a readable directory. `--json` emits a JSON object
28
+ with verdict, findings, claim flags, and evidence locations. `--verbose` shows
29
+ evidence in human output. Repeat `--ignore <glob>` to exclude relative paths.
30
+ `--version` prints 0.1.0. `--fail-on HIGH` is the default; `--fail-on MEDIUM`
31
+ also fails on evidence confined to tests. Exit status is 0 for PASS, 2 for FAIL,
32
+ and 1 for usage or file-access errors. A MEDIUM finding can accompany PASS.
33
+
34
+ Root README.md and Markdown files beneath any docs path component supply claims.
35
+ Fenced blocks are excluded; inline code counts. Matching lowercases, expands
36
+ negative contractions, replaces hyphens with spaces, and joins paragraph lines.
37
+ Negative spans are removed before positive matching. Each family yields at most
38
+ one finding. Positive promises without production evidence are HIGH, or MEDIUM
39
+ when only tests contain evidence. Negative promises contradicted by production
40
+ calls are HIGH, including promises in docs. No claim yields PASS. Without source,
41
+ a positive promise fails and a negative promise passes.
42
+
43
+ Source analysis resolves imports and aliases for sounddevice, pyaudio, and
44
+ speech_recognition. It accepts rec calls, bound InputStream reads, reads from
45
+ streams opened by bound PyAudio instances, and bound Recognizer listen/record
46
+ calls, including supported self attributes and chained calls. Imports alone,
47
+ playback, file loading, transcription, synthesis, and object construction alone
48
+ do not establish evidence. Tests are assessed separately. Files beneath fixtures,
49
+ docs, and examples, plus symlinked source, are excluded. Environment files are
50
+ never opened.
51
+
52
+ ## Limitations
53
+
54
+ Only the exact templates stored in the package's phrases module are claims.
55
+ Bare device nouns, chapter titles, dependency lists, user instructions to speak
56
+ or plug in a device, and promises about spoken transcription, synthesis, keys,
57
+ screens, clipboard operations, or network delivery are outside this audit.
58
+
59
+ This is a module-local syntactic check, not a runtime or data-flow proof. It does
60
+ not validate hardware, arguments, reachability, callback capture, cross-module
61
+ bindings, reassignment, or lexical scope. Invalid syntax supplies no evidence.
62
+ Shell audio helpers such as arecord, ffmpeg, and sox are outside the supported
63
+ routes. Command names in strings do not establish evidence.
64
+
65
+ The related voice-claim-audit requires a recognize call paired with a Recognizer.
66
+ This audit requires only a capture call: listen without recognize can pass here
67
+ and fail there, because the tools judge different promises.
@@ -0,0 +1,57 @@
1
+ # microphone-claim-audit
2
+
3
+ An offline static audit comparing documentation about local audio input capture
4
+ with provider-resolved calls in Python source. Source is parsed, never executed.
5
+ There are no runtime dependencies.
6
+
7
+ Install and run:
8
+
9
+ ```sh
10
+ python3 -m pip install .
11
+ microphone-claim-audit /path/to/project --json
12
+ python3 -m microphone_claim_audit /path/to/project --verbose
13
+ python3 -m unittest discover
14
+ python3 -m build
15
+ ```
16
+
17
+ The positional root must be a readable directory. `--json` emits a JSON object
18
+ with verdict, findings, claim flags, and evidence locations. `--verbose` shows
19
+ evidence in human output. Repeat `--ignore <glob>` to exclude relative paths.
20
+ `--version` prints 0.1.0. `--fail-on HIGH` is the default; `--fail-on MEDIUM`
21
+ also fails on evidence confined to tests. Exit status is 0 for PASS, 2 for FAIL,
22
+ and 1 for usage or file-access errors. A MEDIUM finding can accompany PASS.
23
+
24
+ Root README.md and Markdown files beneath any docs path component supply claims.
25
+ Fenced blocks are excluded; inline code counts. Matching lowercases, expands
26
+ negative contractions, replaces hyphens with spaces, and joins paragraph lines.
27
+ Negative spans are removed before positive matching. Each family yields at most
28
+ one finding. Positive promises without production evidence are HIGH, or MEDIUM
29
+ when only tests contain evidence. Negative promises contradicted by production
30
+ calls are HIGH, including promises in docs. No claim yields PASS. Without source,
31
+ a positive promise fails and a negative promise passes.
32
+
33
+ Source analysis resolves imports and aliases for sounddevice, pyaudio, and
34
+ speech_recognition. It accepts rec calls, bound InputStream reads, reads from
35
+ streams opened by bound PyAudio instances, and bound Recognizer listen/record
36
+ calls, including supported self attributes and chained calls. Imports alone,
37
+ playback, file loading, transcription, synthesis, and object construction alone
38
+ do not establish evidence. Tests are assessed separately. Files beneath fixtures,
39
+ docs, and examples, plus symlinked source, are excluded. Environment files are
40
+ never opened.
41
+
42
+ ## Limitations
43
+
44
+ Only the exact templates stored in the package's phrases module are claims.
45
+ Bare device nouns, chapter titles, dependency lists, user instructions to speak
46
+ or plug in a device, and promises about spoken transcription, synthesis, keys,
47
+ screens, clipboard operations, or network delivery are outside this audit.
48
+
49
+ This is a module-local syntactic check, not a runtime or data-flow proof. It does
50
+ not validate hardware, arguments, reachability, callback capture, cross-module
51
+ bindings, reassignment, or lexical scope. Invalid syntax supplies no evidence.
52
+ Shell audio helpers such as arecord, ffmpeg, and sox are outside the supported
53
+ routes. Command names in strings do not establish evidence.
54
+
55
+ The related voice-claim-audit requires a recognize call paired with a Recognizer.
56
+ This audit requires only a capture call: listen without recognize can pass here
57
+ and fail there, because the tools judge different promises.
@@ -0,0 +1,2 @@
1
+ """Offline documentation and source audit."""
2
+ __version__ = '0.1.0'
@@ -0,0 +1,41 @@
1
+ import argparse
2
+ import json
3
+ import sys
4
+ from . import __version__
5
+ from .audit import audit
6
+
7
+
8
+ class Parser(argparse.ArgumentParser):
9
+ def error(self, message):
10
+ self.print_usage(sys.stderr)
11
+ self.exit(1, self.prog + ': error: ' + message + '\n')
12
+
13
+
14
+ def main(argv=None):
15
+ parser = Parser(description='Audit documented local audio input capture against static source evidence.')
16
+ parser.add_argument('root')
17
+ parser.add_argument('--version', action='version', version=__version__)
18
+ parser.add_argument('--json', action='store_true')
19
+ parser.add_argument('--verbose', action='store_true')
20
+ parser.add_argument('--ignore', action='append', default=[])
21
+ parser.add_argument('--fail-on', choices=('HIGH', 'MEDIUM'), default='HIGH')
22
+ args = parser.parse_args(argv)
23
+ try:
24
+ result = audit(args.root, args.ignore, args.fail_on)
25
+ except (OSError, ValueError, UnicodeError) as exc:
26
+ parser.exit(1, 'error: ' + str(exc) + '\n')
27
+ if args.json:
28
+ print(json.dumps(result))
29
+ else:
30
+ print(result['verdict'])
31
+ for finding in result['findings']:
32
+ print('{severity} {rule}: {message}'.format(**finding))
33
+ if args.verbose:
34
+ for key in ('evidence', 'test_evidence'):
35
+ for location in result[key]:
36
+ print(key + ': ' + location)
37
+ return 2 if result['verdict'] == 'FAIL' else 0
38
+
39
+
40
+ if __name__ == '__main__':
41
+ sys.exit(main())
@@ -0,0 +1,150 @@
1
+ """Static analysis; audited source is never imported or executed."""
2
+ import ast
3
+ import fnmatch
4
+ import re
5
+ from pathlib import Path
6
+ from .phrases import MICROPHONE, NOMICROPHONE
7
+
8
+
9
+ def normalize(text):
10
+ return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' ')).strip()
11
+
12
+
13
+ def pattern(phrases):
14
+ return re.compile(r'\b(?:' + '|'.join(re.escape(p) for p in sorted(phrases, key=len, reverse=True)) + r')\b')
15
+
16
+
17
+ def claims(text):
18
+ lines = []
19
+ fence = None
20
+ for line in text.splitlines():
21
+ match = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
22
+ if match:
23
+ token = match.group(1)
24
+ if fence is None:
25
+ fence = token
26
+ elif token[0] == fence[0] and len(token) >= len(fence):
27
+ fence = None
28
+ lines.append('')
29
+ elif fence is None:
30
+ lines.append(line)
31
+ yes = no = False
32
+ for paragraph in re.split(r'\n\s*\n', '\n'.join(lines)):
33
+ value = normalize(paragraph)
34
+ no = no or bool(pattern(NOMICROPHONE).search(value))
35
+ value = pattern(NOMICROPHONE).sub(' ', value)
36
+ yes = yes or bool(pattern(MICROPHONE).search(value))
37
+ return yes, no
38
+
39
+
40
+ def dotted(node):
41
+ if isinstance(node, ast.Name):
42
+ return node.id
43
+ if isinstance(node, ast.Attribute):
44
+ base = dotted(node.value)
45
+ return base + '.' + node.attr if base else None
46
+ return None
47
+
48
+
49
+ def evidence(text):
50
+ try:
51
+ tree = ast.parse(text)
52
+ except SyntaxError:
53
+ return []
54
+ aliases = {}
55
+ providers = ('sounddevice', 'pyaudio', 'speech_recognition')
56
+ for node in ast.walk(tree):
57
+ if isinstance(node, ast.Import):
58
+ for item in node.names:
59
+ if item.name.split('.')[0] in providers:
60
+ aliases[item.asname or item.name.split('.')[0]] = item.name if item.asname else item.name.split('.')[0]
61
+ elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module and node.module.split('.')[0] in providers:
62
+ for item in node.names:
63
+ if item.name != '*':
64
+ aliases[item.asname or item.name] = node.module + '.' + item.name
65
+
66
+ def resolved(node):
67
+ name = dotted(node)
68
+ if not name:
69
+ return ''
70
+ first, *tail = name.split('.')
71
+ return '.'.join([aliases.get(first, ''), *tail]) if first in aliases else ''
72
+
73
+ def creation(node, provider, symbol):
74
+ name = resolved(node.func) if isinstance(node, ast.Call) else ''
75
+ return name.startswith(provider + '.') and name.split('.')[-1] == symbol
76
+
77
+ bound = {}
78
+
79
+ def kind(node):
80
+ if creation(node, 'sounddevice', 'InputStream'):
81
+ return 'input'
82
+ if creation(node, 'pyaudio', 'PyAudio'):
83
+ return 'pa'
84
+ if creation(node, 'speech_recognition', 'Recognizer'):
85
+ return 'recognizer'
86
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr == 'open' and bound.get(dotted(node.func.value)) == 'pa':
87
+ return 'stream'
88
+ return bound.get(dotted(node))
89
+
90
+ assignments = [n for n in ast.walk(tree) if isinstance(n, ast.Assign)]
91
+ for _ in range(len(assignments) + 1):
92
+ changed = False
93
+ for node in assignments:
94
+ value = kind(node.value)
95
+ for target in node.targets:
96
+ name = dotted(target)
97
+ if name and (isinstance(target, ast.Name) or name.startswith('self.')) and value and bound.get(name) != value:
98
+ bound[name] = value
99
+ changed = True
100
+ if not changed:
101
+ break
102
+ found = []
103
+ for node in ast.walk(tree):
104
+ if not isinstance(node, ast.Call):
105
+ continue
106
+ name = resolved(node.func)
107
+ hit = name.startswith('sounddevice.') and name.split('.')[-1] == 'rec'
108
+ if isinstance(node.func, ast.Attribute):
109
+ receiver = kind(node.func.value)
110
+ hit = hit or (node.func.attr == 'read' and receiver in ('input', 'stream')) or (node.func.attr in ('listen', 'record') and receiver == 'recognizer')
111
+ if hit:
112
+ found.append(node.lineno)
113
+ return sorted(set(found))
114
+
115
+
116
+ def audit(root, ignores=(), fail_on='HIGH'):
117
+ root = Path(root)
118
+ if not root.is_dir():
119
+ raise ValueError('root must be a readable directory')
120
+ # Explicitly probe listing so unreadable roots produce a usage error.
121
+ list(root.iterdir())
122
+ positive = negative = False
123
+ prod = []
124
+ test = []
125
+ for path in sorted(root.rglob('*')):
126
+ relative = path.relative_to(root)
127
+ parts = relative.parts
128
+ if path.is_symlink() or any((root.joinpath(*parts[:i])).is_symlink() for i in range(1, len(parts))) or not path.is_file():
129
+ continue
130
+ name = relative.as_posix()
131
+ if any(fnmatch.fnmatchcase(name, glob) for glob in ignores):
132
+ continue
133
+ if path.suffix.lower() == '.md' and (name == 'README.md' or 'docs' in parts[:-1]):
134
+ yes, no = claims(path.read_text(encoding='utf-8'))
135
+ positive |= yes
136
+ negative |= no
137
+ if path.suffix != '.py':
138
+ continue
139
+ if any(p in ('fixtures', 'docs', 'examples') for p in parts[:-1]):
140
+ continue
141
+ is_test = 'tests' in parts[:-1] or path.name.startswith('test_') or path.name.endswith('_test.py')
142
+ for line in evidence(path.read_text(encoding='utf-8')):
143
+ (test if is_test else prod).append(f'{name}:{line}')
144
+ findings = []
145
+ if positive and not prod:
146
+ findings.append(dict(rule='documented-microphone-claim-false', severity='MEDIUM' if test else 'HIGH', message='Documented local audio input capture lacks production source evidence.'))
147
+ if negative and prod:
148
+ findings.append(dict(rule='documented-no-microphone-claim-false', severity='HIGH', message='Documented absence conflicts with production source evidence.'))
149
+ failed = any(f['severity'] == 'HIGH' or fail_on == 'MEDIUM' for f in findings)
150
+ return dict(verdict='FAIL' if failed else 'PASS', findings=findings, claims={'positive': positive, 'negative': negative}, evidence=prod, test_evidence=test)
@@ -0,0 +1,2 @@
1
+ MICROPHONE = ('records audio from your microphone', 'record audio from your microphone', 'captures audio from your microphone', 'capture audio from your microphone', 'records audio using your microphone', 'record audio using your microphone', 'captures audio using your microphone', 'capture audio using your microphone', 'records from your microphone', 'record from your microphone', 'captures from your microphone', 'capture from your microphone', 'captures microphone audio', 'capture microphone audio', 'records microphone audio', 'record microphone audio', 'records your microphone', 'record your microphone', 'listens through your microphone', 'listen through your microphone', 'listens to your microphone', 'listen to your microphone', 'supports microphone input', 'microphone input support', 'microphone audio recording', 'microphone audio capture', 'microphone recording')
2
+ NOMICROPHONE = ('does not record audio from your microphone', 'does not capture audio from your microphone', 'does not record from your microphone', 'does not capture from your microphone', 'does not capture microphone audio', 'does not record microphone audio', 'does not listen through your microphone', 'does not listen to your microphone', 'does not use your microphone', 'does not access your microphone', 'microphone recording not supported', 'microphone input not supported', 'no microphone audio recording', 'no microphone audio capture', 'no microphone recording', 'no microphone access', 'without microphone recording', 'without microphone input')
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: microphone-claim-audit
3
+ Version: 0.1.0
4
+ Summary: Offline static audit of documented local audio input capture
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
+ # microphone-claim-audit
12
+
13
+ An offline static audit comparing documentation about local audio input capture
14
+ with provider-resolved calls in Python source. Source is parsed, never executed.
15
+ There are no runtime dependencies.
16
+
17
+ Install and run:
18
+
19
+ ```sh
20
+ python3 -m pip install .
21
+ microphone-claim-audit /path/to/project --json
22
+ python3 -m microphone_claim_audit /path/to/project --verbose
23
+ python3 -m unittest discover
24
+ python3 -m build
25
+ ```
26
+
27
+ The positional root must be a readable directory. `--json` emits a JSON object
28
+ with verdict, findings, claim flags, and evidence locations. `--verbose` shows
29
+ evidence in human output. Repeat `--ignore <glob>` to exclude relative paths.
30
+ `--version` prints 0.1.0. `--fail-on HIGH` is the default; `--fail-on MEDIUM`
31
+ also fails on evidence confined to tests. Exit status is 0 for PASS, 2 for FAIL,
32
+ and 1 for usage or file-access errors. A MEDIUM finding can accompany PASS.
33
+
34
+ Root README.md and Markdown files beneath any docs path component supply claims.
35
+ Fenced blocks are excluded; inline code counts. Matching lowercases, expands
36
+ negative contractions, replaces hyphens with spaces, and joins paragraph lines.
37
+ Negative spans are removed before positive matching. Each family yields at most
38
+ one finding. Positive promises without production evidence are HIGH, or MEDIUM
39
+ when only tests contain evidence. Negative promises contradicted by production
40
+ calls are HIGH, including promises in docs. No claim yields PASS. Without source,
41
+ a positive promise fails and a negative promise passes.
42
+
43
+ Source analysis resolves imports and aliases for sounddevice, pyaudio, and
44
+ speech_recognition. It accepts rec calls, bound InputStream reads, reads from
45
+ streams opened by bound PyAudio instances, and bound Recognizer listen/record
46
+ calls, including supported self attributes and chained calls. Imports alone,
47
+ playback, file loading, transcription, synthesis, and object construction alone
48
+ do not establish evidence. Tests are assessed separately. Files beneath fixtures,
49
+ docs, and examples, plus symlinked source, are excluded. Environment files are
50
+ never opened.
51
+
52
+ ## Limitations
53
+
54
+ Only the exact templates stored in the package's phrases module are claims.
55
+ Bare device nouns, chapter titles, dependency lists, user instructions to speak
56
+ or plug in a device, and promises about spoken transcription, synthesis, keys,
57
+ screens, clipboard operations, or network delivery are outside this audit.
58
+
59
+ This is a module-local syntactic check, not a runtime or data-flow proof. It does
60
+ not validate hardware, arguments, reachability, callback capture, cross-module
61
+ bindings, reassignment, or lexical scope. Invalid syntax supplies no evidence.
62
+ Shell audio helpers such as arecord, ffmpeg, and sox are outside the supported
63
+ routes. Command names in strings do not establish evidence.
64
+
65
+ The related voice-claim-audit requires a recognize call paired with a Recognizer.
66
+ This audit requires only a capture call: listen without recognize can pass here
67
+ and fail there, because the tools judge different promises.
@@ -0,0 +1,24 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ microphone_claim_audit/__init__.py
6
+ microphone_claim_audit/__main__.py
7
+ microphone_claim_audit/audit.py
8
+ microphone_claim_audit/phrases.py
9
+ microphone_claim_audit.egg-info/PKG-INFO
10
+ microphone_claim_audit.egg-info/SOURCES.txt
11
+ microphone_claim_audit.egg-info/dependency_links.txt
12
+ microphone_claim_audit.egg-info/entry_points.txt
13
+ microphone_claim_audit.egg-info/top_level.txt
14
+ tests/__init__.py
15
+ tests/test_audit.py
16
+ tests/fixtures/.env
17
+ tests/fixtures/bad/README.md
18
+ tests/fixtures/bad/app.py
19
+ tests/fixtures/good/README.md
20
+ tests/fixtures/good/app.py
21
+ tests/fixtures/no_microphone/README.md
22
+ tests/fixtures/no_microphone/app.py
23
+ tests/fixtures/tests_only/README.md
24
+ tests/fixtures/tests_only/tests/capture.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ microphone-claim-audit = microphone_claim_audit.__main__:main
@@ -0,0 +1 @@
1
+ microphone_claim_audit
@@ -0,0 +1,17 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "microphone-claim-audit"
7
+ version = "0.1.0"
8
+ description = "Offline static audit of documented local audio input capture"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+
13
+ [project.scripts]
14
+ microphone-claim-audit = "microphone_claim_audit.__main__:main"
15
+
16
+ [tool.setuptools.packages.find]
17
+ include = ["microphone_claim_audit*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1 @@
1
+ ENV_GUARD_MARKER_ONLY
@@ -0,0 +1 @@
1
+ records audio from your microphone
@@ -0,0 +1 @@
1
+ import sounddevice
@@ -0,0 +1 @@
1
+ records audio from your microphone
@@ -0,0 +1,2 @@
1
+ import sounddevice
2
+ sounddevice.rec(10)
@@ -0,0 +1 @@
1
+ no microphone recording
@@ -0,0 +1,2 @@
1
+ import sounddevice
2
+ sounddevice.rec(10)
@@ -0,0 +1 @@
1
+ records audio from your microphone
@@ -0,0 +1,2 @@
1
+ import sounddevice
2
+ sounddevice.rec(10)
@@ -0,0 +1,194 @@
1
+ """Numbered spec cases 1–32; generated exhaustion cases name every template."""
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
+ from microphone_claim_audit.audit import audit, claims, evidence, normalize
11
+ from microphone_claim_audit.phrases import MICROPHONE, NOMICROPHONE
12
+ from microphone_claim_audit.__main__ import main
13
+
14
+ ROOT = Path(__file__).resolve().parents[1]
15
+ REC = 'import sounddevice\nsounddevice.rec(10)'
16
+
17
+
18
+ class AuditTests(unittest.TestCase):
19
+ def check_case(self, code='', doc=MICROPHONE[0], severity=None, filename='app.py'):
20
+ with tempfile.TemporaryDirectory() as directory:
21
+ root = Path(directory)
22
+ (root / 'README.md').write_text(doc)
23
+ if code:
24
+ path = root / filename
25
+ path.parent.mkdir(parents=True, exist_ok=True)
26
+ path.write_text(code)
27
+ result = audit(root)
28
+ self.assertEqual([f['severity'] for f in result['findings']], [severity] if severity else [])
29
+ self.assertEqual(result['verdict'], 'FAIL' if severity == 'HIGH' else 'PASS')
30
+ return result
31
+
32
+ def cli(self, *args):
33
+ out = io.StringIO()
34
+ with contextlib.redirect_stdout(out), contextlib.redirect_stderr(io.StringIO()):
35
+ try:
36
+ status = main(list(args))
37
+ except SystemExit as exc:
38
+ status = exc.code
39
+ return status, out.getvalue()
40
+
41
+ def test_01_plain(self): self.check_case(REC)
42
+ def test_02_alias(self): self.check_case('import sounddevice as sd\nsd.rec(1)')
43
+ def test_03_from_alias(self): self.check_case('from sounddevice import rec as capture\ncapture(1)')
44
+ def test_04_input_stream(self): self.check_case('import sounddevice as sd\nstream=sd.InputStream()\nstream.read(1)')
45
+ def test_05_pyaudio(self): self.check_case('import pyaudio\np=pyaudio.PyAudio()\nstream=p.open()\nstream.read(1)')
46
+ def test_06_pyaudio_chain(self): self.check_case('import pyaudio\np=pyaudio.PyAudio()\np.open().read(1)')
47
+ def test_07_listen(self): self.check_case('from speech_recognition import Recognizer\nr=Recognizer()\nr.listen(source)')
48
+ def test_08_self(self): self.check_case('import speech_recognition as sr\nself.r=sr.Recognizer()\nself.r.record(source)')
49
+ def test_09_chain(self): self.check_case('from speech_recognition import Recognizer\nRecognizer().listen(source)')
50
+ def test_10_import(self):
51
+ self.check_case('import sounddevice', severity='HIGH')
52
+ status, output = self.cli(str(ROOT/'tests/fixtures/bad'), '--json')
53
+ self.assertEqual(status, 2)
54
+ self.assertEqual([f['severity'] for f in json.loads(output)['findings']], ['HIGH'])
55
+ def test_11_string(self): self.check_case('value="microphone"', severity='HIGH')
56
+ def test_12_playback(self): self.check_case('import sounddevice\nfrom playsound import playsound\nsounddevice.play(data)\nplaysound("a.wav")', severity='HIGH')
57
+ def test_13_loading(self): self.check_case('import soundfile, librosa\nsoundfile.read("a.wav")\nlibrosa.load("a.wav")', severity='HIGH')
58
+ def test_14_transcription(self): self.check_case('import whisper\nwhisper.transcribe("a.wav")', severity='HIGH')
59
+ def test_15_microphone_object(self): self.check_case('import speech_recognition as sr\nsr.Microphone()', severity='HIGH')
60
+ def test_16_recognizer_only(self): self.check_case('from speech_recognition import Recognizer\nr=Recognizer()', severity='HIGH')
61
+ def test_17_unbound_listen(self): self.check_case('r.listen(source)', severity='HIGH')
62
+ def test_18_unbound_read(self): self.check_case('stream.read(10)', severity='HIGH')
63
+ def test_19_negative(self):
64
+ result=self.check_case(REC, NOMICROPHONE[14], 'HIGH')
65
+ self.assertEqual(result['findings'][0]['rule'], 'documented-no-microphone-claim-false')
66
+ self.assertEqual(self.cli(str(ROOT/'tests/fixtures/no_microphone'))[0], 2)
67
+ def test_20_no_claim(self): self.check_case(REC, 'Utility')
68
+ def test_21_noun(self): self.check_case('import sounddevice', 'the microphone chapter explains delivery')
69
+ def test_22_user(self):
70
+ for doc in ('speak into your microphone to continue', 'plug in your microphone before starting'):
71
+ self.check_case('import sounddevice', doc)
72
+ def test_23_voice(self): self.check_case('import whisper\nwhisper.transcribe("a.wav")', 'transcribes spoken commands')
73
+ def test_24_no_source(self):
74
+ self.check_case(severity='HIGH')
75
+ self.check_case(doc=NOMICROPHONE[14])
76
+ def test_25_test_only(self):
77
+ self.check_case(REC, severity='MEDIUM', filename='tests/capture.py')
78
+ root=str(ROOT/'tests/fixtures/tests_only')
79
+ self.assertEqual(self.cli(root)[0], 0)
80
+ self.assertEqual(self.cli(root, '--fail-on', 'MEDIUM')[0], 2)
81
+ def test_26_fences(self):
82
+ for marker in ('```', '~~~~'):
83
+ self.check_case(doc=marker+'\n'+MICROPHONE[0]+'\n'+marker)
84
+ self.check_case(doc='`'+MICROPHONE[0]+'`', severity='HIGH')
85
+ def test_27_negation(self):
86
+ self.assertEqual(claims(NOMICROPHONE[0]), (False, True))
87
+ self.assertEqual(claims("doesn't record audio from your microphone"), (False, True))
88
+ def test_28_self_audit(self):
89
+ result=audit(ROOT)
90
+ self.assertEqual(result['verdict'], 'PASS')
91
+ self.assertEqual(result['claims'], {'positive':False, 'negative':False})
92
+ text=normalize((ROOT/'README.md').read_text())
93
+ for phrase in MICROPHONE + NOMICROPHONE:
94
+ self.assertIsNone(re.search(r'\b'+re.escape(phrase)+r'\b', text))
95
+ def test_29_cli(self):
96
+ root=str(ROOT/'tests/fixtures/good')
97
+ self.assertEqual(self.cli('--version'), (0, '0.1.0\n'))
98
+ status, output=self.cli(root, '--json')
99
+ self.assertEqual(status, 0)
100
+ self.assertEqual(json.loads(output)['verdict'], 'PASS')
101
+ self.assertIn('app.py:2', self.cli(root, '--verbose')[1])
102
+ self.assertEqual(self.cli(str(ROOT/'tests/fixtures/bad'), '--ignore', 'README.md')[0], 0)
103
+ self.assertEqual(self.cli('/nonexistent/mca')[0], 1)
104
+ self.assertEqual(self.cli('--unknown')[0], 1)
105
+ def test_30_env_guard(self):
106
+ original=Path.open
107
+ def guarded(path, *args, **kwargs):
108
+ self.assertNotEqual(path.name, '.env')
109
+ return original(path, *args, **kwargs)
110
+ with patch.object(Path, 'open', guarded):
111
+ audit(ROOT)
112
+ def test_31_packaging(self):
113
+ for path in list((ROOT/'microphone_claim_audit').glob('*.py')) + list((ROOT/'tests').glob('*.py')) + [ROOT/'README.md']:
114
+ self.assertIsNone(re.search(r'\b'+'py'+'thon'+r'\b', path.read_text()))
115
+ config=(ROOT/'pyproject.toml').read_text()
116
+ self.assertIn('setuptools>=77', config)
117
+ self.assertIn('license = "MIT"', config)
118
+ self.assertIn('recursive-include tests', (ROOT/'MANIFEST.in').read_text())
119
+ def test_32_phrase_inventory(self):
120
+ self.assertEqual(len(MICROPHONE), 27)
121
+ self.assertEqual(len(NOMICROPHONE), 18)
122
+ self.assertEqual(len(set(MICROPHONE+NOMICROPHONE)),45)
123
+
124
+ def test_additional_provider_routes(self):
125
+ for code in (
126
+ 'from sounddevice.streams import InputStream as I\nI().read(1)',
127
+ 'import sounddevice\nself.s=sounddevice.InputStream()\nself.s.read(1)',
128
+ 'from pyaudio import PyAudio as P\nself.p=P()\nself.s=self.p.open()\nself.s.read(1)',
129
+ 'import speech_recognition as sr\nsr.Recognizer().record(src)',
130
+ 'from speech_recognition.audio import Recognizer as R\nr=R()\nr.record(src)',
131
+ ): self.check_case(code)
132
+
133
+ def test_explicit_non_evidence(self):
134
+ for code in (
135
+ 'input("speak")',
136
+ 'import sounddevice as sd\nsd.query_devices()\nsd.wait()\nsd.sleep(1)',
137
+ 'import pyaudio\np=pyaudio.PyAudio()\np.open()',
138
+ 'import wave, torchaudio\nwave.open("a.wav", "rb")\ntorchaudio.load("a.wav")',
139
+ 'import speech_recognition as sr\nr=sr.Recognizer()\nr.recognize_google(data)',
140
+ 'import pyttsx3\npyttsx3.init().say("hello")',
141
+ 'from gtts import gTTS\ngTTS("hello").save("a.mp3")',
142
+ 'from other import InputStream\ns=InputStream()\ns.read(1)',
143
+ 'def record_audio():\n print("record")\n return 1',
144
+ '@app.get("/audio")\ndef route():\n return "audio"',
145
+ 'import subprocess\nsubprocess.run(["arecord"])',
146
+ '# sounddevice.rec(1)\n"""sd.rec(1)"""',
147
+ 'from other import rec\nrec(1)',
148
+ ): self.check_case(code, severity='HIGH')
149
+
150
+ def test_scopes_and_symlinks(self):
151
+ for filename in ('fixtures/a.py','docs/a.py','examples/a.py'):
152
+ self.check_case(REC, severity='HIGH', filename=filename)
153
+ for filename in ('test_capture.py','capture_test.py'):
154
+ self.check_case(REC, severity='MEDIUM', filename=filename)
155
+ with tempfile.TemporaryDirectory() as directory:
156
+ root=Path(directory)
157
+ (root/'README.md').write_text(MICROPHONE[0])
158
+ (root/'link.py').symlink_to(ROOT/'tests/fixtures/good/app.py')
159
+ self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')
160
+ (root/'README.md').write_text('Utility')
161
+ (root/'nested/docs').mkdir(parents=True)
162
+ (root/'nested/docs/a.md').write_text(NOMICROPHONE[14])
163
+ (root/'app.py').write_text(REC)
164
+ self.assertEqual(audit(root)['findings'][0]['severity'], 'HIGH')
165
+
166
+ def test_normalization_and_family_limit(self):
167
+ self.assertEqual(claims('RECORDS-AUDIO\nFROM YOUR MICROPHONE'), (True,False))
168
+ self.assertEqual(claims('xrecords audio from your microphonex'), (False,False))
169
+ result=self.check_case(doc='\n\n'.join(MICROPHONE), severity='HIGH')
170
+ self.assertEqual(len(result['findings']), 1)
171
+ self.assertEqual(claims(MICROPHONE[0]+'\n\n'+NOMICROPHONE[0]), (True, True))
172
+
173
+
174
+ def positive_case(phrase):
175
+ def test(self):
176
+ self.assertEqual(claims(phrase), (True, False))
177
+ self.check_case(doc=phrase, severity='HIGH')
178
+ self.check_case(REC, phrase)
179
+ return test
180
+
181
+
182
+ def negative_case(phrase):
183
+ def test(self):
184
+ self.assertEqual(claims(phrase), (False, True))
185
+ result=self.check_case(REC, phrase, 'HIGH')
186
+ self.assertEqual(result['findings'][0]['rule'], 'documented-no-microphone-claim-false')
187
+ self.check_case(doc=phrase)
188
+ return test
189
+
190
+
191
+ # Each generated test covers the exact phrase included in its method name.
192
+ for family, phrases, factory in (('positive', MICROPHONE, positive_case), ('negative', NOMICROPHONE, negative_case)):
193
+ for phrase in phrases:
194
+ setattr(AuditTests, 'test_32_exhaustion_'+family+'_'+phrase.replace(' ', '_'), factory(phrase))