@bbcsoftwarefactory/skills 0.1.1 → 1.1.3
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.
- package/dist/index.json +2 -3
- package/dist/skills/code-quality-gate/SKILL.md +4 -5
- package/dist/skills/code-quality-gate/references/gate-bigo.md +1 -1
- package/dist/skills/delivery-coordinator/SKILL.md +7 -8
- package/dist/skills/delivery-coordinator/references/hud-output.md +1 -1
- package/dist/skills/delivery-coordinator/references/issue-claim.md +5 -5
- package/dist/skills/delivery-coordinator/references/issue-dedup.md +1 -1
- package/dist/skills/delivery-coordinator/references/worktree-isolation.md +2 -2
- package/dist/skills/greptile-review-loop/SKILL.md +3 -4
- package/dist/skills/greptile-review-loop/references/review-protocol.md +1 -1
- package/dist/skills/issue-reviewer/SKILL.md +10 -13
- package/dist/skills/issue-reviewer/references/review-format.md +1 -1
- package/dist/skills/issue-reviewer/references/triage.md +6 -6
- package/dist/skills/question-gate/SKILL.md +6 -8
- package/dist/skills/question-gate/references/client-hooks.md +10 -10
- package/dist/skills/question-gate/references/diagram-routing.md +3 -3
- package/dist/skills/skill-clean-architecture/SKILL.md +2 -3
- package/dist/skills/skill-clean-architecture/references/source-headers.md +2 -3
- package/dist/skills/tool-depot/references/readonly-access.md +1 -1
- package/dist/skills/tool-depot/references/tool-catalog.json +2 -2
- package/dist/skills/watcher-observability/SKILL.md +3 -4
- package/dist/skills/watcher-observability/references/batch-protocol.md +6 -6
- package/dist/skills/watcher-observability/references/configuration.md +1 -1
- package/dist/skills/watcher-observability/references/error-scan.md +1 -1
- package/dist/skills/watcher-observability/references/live-protocol.md +8 -8
- package/dist/skills/watcher-observability/references/server-account.md +8 -8
- package/dist/skills/watcher-observability/server/watcher-gate.sh +1 -1
- package/dist/skills/watcher-observability/tests/watcher-gate.test.sh +10 -7
- package/dist/skills/workflow-auditor/SKILL.md +3 -5
- package/dist/skills/workflow-auditor/references/audit-protocol.md +3 -3
- package/dist/skills/workflow-auditor/references/ledger.md +1 -1
- package/package.json +26 -27
- package/dist/skills/code-quality-gate/scripts/extract-diff-scope.py +0 -225
- package/dist/skills/code-quality-gate/tests/extract-diff-scope.test.sh +0 -200
- package/dist/skills/delivery-coordinator/scripts/check-issue-claim.py +0 -363
- package/dist/skills/delivery-coordinator/scripts/check-worktree-guard.py +0 -220
- package/dist/skills/delivery-coordinator/scripts/classify-change-lane.py +0 -263
- package/dist/skills/delivery-coordinator/tests/check-issue-claim.test.sh +0 -221
- package/dist/skills/delivery-coordinator/tests/check-worktree-guard.test.sh +0 -123
- package/dist/skills/delivery-coordinator/tests/classify-change-lane.test.sh +0 -124
- package/dist/skills/greptile-review-loop/scripts/review-loop.py +0 -435
- package/dist/skills/greptile-review-loop/tests/review-loop.test.sh +0 -331
- package/dist/skills/issue-reviewer/scripts/fetch-issue-attachments.py +0 -239
- package/dist/skills/issue-reviewer/scripts/plan-issue-triage.py +0 -311
- package/dist/skills/issue-reviewer/tests/fetch-issue-attachments.test.sh +0 -90
- package/dist/skills/issue-reviewer/tests/plan-issue-triage.test.sh +0 -168
- package/dist/skills/question-gate/scripts/triage-question.py +0 -713
- package/dist/skills/question-gate/tests/question-corpus.test.sh +0 -32
- package/dist/skills/question-gate/tests/triage-question.test.sh +0 -441
- package/dist/skills/skill-clean-architecture/scripts/measure-bigo.py +0 -427
- package/dist/skills/skill-clean-architecture/tests/measure-bigo.test.sh +0 -222
- package/dist/skills/watcher-observability/scripts/error-scan.py +0 -318
- package/dist/skills/watcher-observability/scripts/resolve-containers.py +0 -155
- package/dist/skills/watcher-observability/scripts/save-counts.py +0 -381
- package/dist/skills/watcher-observability/scripts/summarize-logs.py +0 -113
- package/dist/skills/watcher-observability/scripts/watch-live.py +0 -606
- package/dist/skills/watcher-observability/tests/error-scan.test.sh +0 -257
- package/dist/skills/watcher-observability/tests/live-windows.test.sh +0 -177
- package/dist/skills/watcher-observability/tests/resolve-containers.test.sh +0 -87
- package/dist/skills/watcher-observability/tests/save-counts.test.sh +0 -338
- package/dist/skills/watcher-observability/tests/sleuth.test.sh +0 -176
- package/dist/skills/watcher-observability/tests/summarize-logs.test.sh +0 -105
- package/dist/skills/watcher-observability/tests/watcher-config.test.sh +0 -70
- package/dist/skills/workflow-auditor/scripts/audit-ledger.py +0 -624
- package/dist/skills/workflow-auditor/scripts/list-zed-commands.py +0 -183
- package/dist/skills/workflow-auditor/scripts/render-workflow.py +0 -201
- package/dist/skills/workflow-auditor/scripts/validate-skills.py +0 -444
- package/dist/skills/workflow-auditor/tests/audit-ledger.test.sh +0 -660
- package/dist/skills/workflow-auditor/tests/list-zed-commands.test.sh +0 -93
- package/dist/skills/workflow-auditor/tests/render-workflow.test.sh +0 -135
- package/dist/skills/workflow-auditor/tests/validate-skills.test.sh +0 -190
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -eu
|
|
3
|
-
cd -- "${BASH_SOURCE[0]%/*}/.."
|
|
4
|
-
python -I -B - <<'PY'
|
|
5
|
-
import contextlib
|
|
6
|
-
import io
|
|
7
|
-
import json
|
|
8
|
-
import os
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
import re
|
|
11
|
-
import runpy
|
|
12
|
-
import stat
|
|
13
|
-
import subprocess
|
|
14
|
-
import sys
|
|
15
|
-
import tempfile
|
|
16
|
-
from unittest.mock import patch
|
|
17
|
-
|
|
18
|
-
scripts = Path('scripts').resolve()
|
|
19
|
-
entry = scripts / 'save-counts.py'
|
|
20
|
-
if not entry.is_file():
|
|
21
|
-
sys.exit('Capture entry point is missing')
|
|
22
|
-
main = runpy.run_path(str(entry))['main']
|
|
23
|
-
watcher = runpy.run_path(str(scripts / 'watch-live.py'))
|
|
24
|
-
checks = 0
|
|
25
|
-
|
|
26
|
-
def check(project, mode, expected, container='approved-app', saved=None):
|
|
27
|
-
global checks
|
|
28
|
-
os.chdir(project / 'nested')
|
|
29
|
-
dest = project / 'tmp_logs'
|
|
30
|
-
def snapshot():
|
|
31
|
-
if not dest.is_dir() or dest.is_symlink():
|
|
32
|
-
return {}
|
|
33
|
-
return {path: path.read_bytes() for path in dest.glob('*/*') if path.is_file()}
|
|
34
|
-
before = snapshot()
|
|
35
|
-
existed = os.path.lexists(dest)
|
|
36
|
-
previous_dirs = set(dest.iterdir()) if dest.is_dir() and not dest.is_symlink() else set()
|
|
37
|
-
out, err = io.StringIO(), io.StringIO()
|
|
38
|
-
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
|
39
|
-
status = main([mode, 'bbc-test', container])
|
|
40
|
-
observed = status, out.getvalue(), err.getvalue()
|
|
41
|
-
assert observed == expected, (mode, observed, expected)
|
|
42
|
-
after = snapshot()
|
|
43
|
-
assert all(after[path] == data for path, data in before.items()), after
|
|
44
|
-
new = after.keys() - before.keys()
|
|
45
|
-
assert len(new) == int(saved is not None), new
|
|
46
|
-
if saved is not None:
|
|
47
|
-
path, = new
|
|
48
|
-
assert re.fullmatch(r'[0-9]{8}T[0-9]{6}Z-[a-f0-9]{32}', path.parent.name), path
|
|
49
|
-
assert path.name == 'report.json', path.name
|
|
50
|
-
report = json.loads(after[path])
|
|
51
|
-
assert report == dict(saved, mode=mode, source={'container': container}), report
|
|
52
|
-
for forbidden in (b'private-', b'raw-container-id', b'bbc-test', b'discarded-raw-record'):
|
|
53
|
-
assert forbidden not in after[path], after[path]
|
|
54
|
-
assert set(dest.iterdir()) - previous_dirs == {path.parent}
|
|
55
|
-
assert list(path.parent.iterdir()) == [path]
|
|
56
|
-
if os.name == 'posix':
|
|
57
|
-
assert stat.S_IMODE(path.parent.stat().st_mode) == 0o700
|
|
58
|
-
assert stat.S_IMODE(path.stat().st_mode) == 0o600
|
|
59
|
-
else:
|
|
60
|
-
assert os.path.lexists(dest) == existed
|
|
61
|
-
if dest.is_dir() and not dest.is_symlink():
|
|
62
|
-
assert set(dest.iterdir()) == previous_dirs
|
|
63
|
-
checks += 1
|
|
64
|
-
|
|
65
|
-
with tempfile.TemporaryDirectory() as scratch:
|
|
66
|
-
scratch = Path(scratch)
|
|
67
|
-
here = Path.cwd()
|
|
68
|
-
try:
|
|
69
|
-
project = scratch / 'consumer'
|
|
70
|
-
(project / 'nested').mkdir(parents=True)
|
|
71
|
-
subprocess.run(['git', 'init', '-q', str(project)], check=True)
|
|
72
|
-
rules = project / '.gitignore'
|
|
73
|
-
fake_bin = scratch / 'bin'
|
|
74
|
-
fake_bin.mkdir()
|
|
75
|
-
# Fake SSH is discovered by Bash, including on Git for Windows. GNU timeout
|
|
76
|
-
# statuses are simulated without waiting for a real wall-clock deadline.
|
|
77
|
-
for name, body in {
|
|
78
|
-
'ssh': '''printf '%s\\n' 'ERROR timeout raw-container-id'
|
|
79
|
-
printf '%s\\n' 'private-diagnostic' >&2
|
|
80
|
-
case ${FAKE_INPUT:-} in
|
|
81
|
-
partial) printf '%s' 'discarded-raw-record' ;;
|
|
82
|
-
cap) printf '%032768d' 0 ;;
|
|
83
|
-
esac
|
|
84
|
-
exit "${FAKE_STATUS:-0}"''',
|
|
85
|
-
'timeout': '''shift 2
|
|
86
|
-
bash -p "$(type -P "$1")" "${@:2}"''',
|
|
87
|
-
}.items():
|
|
88
|
-
script = fake_bin / name
|
|
89
|
-
script.write_text('#!/usr/bin/env bash\n' + body + '\n', encoding='ascii')
|
|
90
|
-
script.chmod(0o700)
|
|
91
|
-
destination_error = (1, '', 'Watcher counts destination unavailable; nothing saved.\n')
|
|
92
|
-
failure = (1, '', 'Watcher counts capture failed; nothing saved.\n')
|
|
93
|
-
invalid = (1, '', 'Watcher counts capture requires a valid SSH alias and exact container name or ID.\n')
|
|
94
|
-
summary = ('severity error=1 warn=0 info=0 debug=0 unknown=1\n'
|
|
95
|
-
'category timeout=1 connection=0 auth=0 other=1\n'
|
|
96
|
-
'input cap=no partial=no\n')
|
|
97
|
-
no_evidence = {'status': 'not_observed', 'message': 'No detailed evidence observed.', 'events': []}
|
|
98
|
-
|
|
99
|
-
def batch_report(status, cap=False, partial=False, deadline=False):
|
|
100
|
-
return {'status': status, 'counts': {
|
|
101
|
-
'severity': {'error': 1, 'warn': 0, 'info': 0, 'debug': 0, 'unknown': 1},
|
|
102
|
-
'category': {'timeout': 1, 'connection': 0, 'auth': 0, 'other': 1}},
|
|
103
|
-
'coverage': {'cap': cap, 'partial': partial, 'deadline': deadline},
|
|
104
|
-
'evidence': no_evidence}
|
|
105
|
-
|
|
106
|
-
with patch.dict(os.environ, {'PATH': str(fake_bin) + os.pathsep + os.environ['PATH']}):
|
|
107
|
-
check(project, 'historical', destination_error)
|
|
108
|
-
exclude = project / '.git' / 'info' / 'exclude'
|
|
109
|
-
globals_ = main.__globals__
|
|
110
|
-
capture_batch = globals_['historical']
|
|
111
|
-
gate_failures = []
|
|
112
|
-
for label, local, fallback in [('exclude-only', b'', b'/tmp_logs/\n'),
|
|
113
|
-
('unanchored', b'tmp_logs/\n', b'')]:
|
|
114
|
-
rules.write_bytes(local)
|
|
115
|
-
exclude.write_bytes(fallback)
|
|
116
|
-
with patch.dict(globals_, {'historical': lambda *_: gate_failures.append(label)}):
|
|
117
|
-
try:
|
|
118
|
-
check(project, 'historical', destination_error)
|
|
119
|
-
except AssertionError as failure_detail:
|
|
120
|
-
gate_failures.append((label, failure_detail.args))
|
|
121
|
-
assert not gate_failures, gate_failures
|
|
122
|
-
|
|
123
|
-
exclude.write_bytes(b'/tmp_logs/\n')
|
|
124
|
-
if os.name == 'posix':
|
|
125
|
-
linked_rules = scratch / 'external-ignore'
|
|
126
|
-
linked_rules.write_bytes(b'/tmp_logs/\n')
|
|
127
|
-
rules.rename(project / 'old-ignore')
|
|
128
|
-
rules.symlink_to(linked_rules)
|
|
129
|
-
check(project, 'historical', destination_error)
|
|
130
|
-
rules.rename(project / 'linked-ignore')
|
|
131
|
-
rules.write_bytes(b'/tmp_logs/\r\n')
|
|
132
|
-
check(project, 'historical', (0, 'historical status=finished\n' + summary, ''),
|
|
133
|
-
saved=batch_report('finished'))
|
|
134
|
-
rules.write_bytes(b'/tmp_logs/\n!tmp_logs/\n')
|
|
135
|
-
check(project, 'historical', destination_error)
|
|
136
|
-
rules.write_bytes(b'/tmp_logs/\n')
|
|
137
|
-
|
|
138
|
-
def change_rule_after_capture(*args):
|
|
139
|
-
result = capture_batch(*args)
|
|
140
|
-
assert result is not None
|
|
141
|
-
rules.write_bytes(b'tmp_logs/\n')
|
|
142
|
-
return result
|
|
143
|
-
|
|
144
|
-
with patch.dict(globals_, {'historical': change_rule_after_capture}):
|
|
145
|
-
check(project, 'historical', destination_error)
|
|
146
|
-
exclude.write_bytes(b'')
|
|
147
|
-
rules.write_bytes(b'/tmp_logs/\n')
|
|
148
|
-
check(project, 'historical', invalid, container='app*')
|
|
149
|
-
for status in ('255', '137', '141'):
|
|
150
|
-
with patch.dict(os.environ, {'FAKE_STATUS': status}):
|
|
151
|
-
check(project, 'historical', failure)
|
|
152
|
-
check(project, 'historical', (0, 'historical status=finished\n' + summary, ''),
|
|
153
|
-
saved=batch_report('finished'))
|
|
154
|
-
with patch.dict(os.environ, {'FAKE_STATUS': '124'}):
|
|
155
|
-
check(project, 'historical', (0, 'historical status=incomplete\n' + summary, ''),
|
|
156
|
-
saved=batch_report('incomplete', deadline=True))
|
|
157
|
-
for input_kind, cap in [('partial', 'no'), ('cap', 'yes')]:
|
|
158
|
-
with patch.dict(os.environ, {'FAKE_INPUT': input_kind}):
|
|
159
|
-
bounded = summary.replace('cap=no partial=no', f'cap={cap} partial=yes')
|
|
160
|
-
check(project, 'historical', (0, 'historical status=incomplete\n' + bounded, ''),
|
|
161
|
-
saved=batch_report('incomplete', cap=cap == 'yes', partial=True))
|
|
162
|
-
assert rules.read_bytes() == b'/tmp_logs/\n'
|
|
163
|
-
|
|
164
|
-
unsafe = scratch / 'unsafe'
|
|
165
|
-
(unsafe / 'nested').mkdir(parents=True)
|
|
166
|
-
subprocess.run(['git', 'init', '-q', str(unsafe)], check=True)
|
|
167
|
-
(unsafe / '.gitignore').write_text('/tmp_logs/\n', encoding='ascii')
|
|
168
|
-
(unsafe / 'tmp_logs').touch()
|
|
169
|
-
check(unsafe, 'historical', destination_error)
|
|
170
|
-
external = scratch / 'external'
|
|
171
|
-
external.mkdir()
|
|
172
|
-
if os.name == 'nt':
|
|
173
|
-
subprocess.run(['cmd.exe', '/d', '/c', 'mklink', '/J',
|
|
174
|
-
str(unsafe / 'linked'), str(external)],
|
|
175
|
-
stdout=subprocess.DEVNULL, check=True)
|
|
176
|
-
else:
|
|
177
|
-
(unsafe / 'linked').symlink_to(external, target_is_directory=True)
|
|
178
|
-
(unsafe / 'tmp_logs').rename(unsafe / 'not-a-directory')
|
|
179
|
-
(unsafe / 'linked').rename(unsafe / 'tmp_logs')
|
|
180
|
-
check(unsafe, 'historical', destination_error)
|
|
181
|
-
assert list(external.iterdir()) == []
|
|
182
|
-
|
|
183
|
-
now = 100.0
|
|
184
|
-
captures = []
|
|
185
|
-
class FakeStream:
|
|
186
|
-
def __init__(self):
|
|
187
|
-
self.sent = set()
|
|
188
|
-
def read_until(self, deadline):
|
|
189
|
-
global now
|
|
190
|
-
if deadline == 115 and deadline not in self.sent:
|
|
191
|
-
self.sent.add(deadline)
|
|
192
|
-
return (b'{"level":"error","traceId":"private-raw-id",'
|
|
193
|
-
b'"error":{"name":"TypeError","code":"ECONNREFUSED",'
|
|
194
|
-
b'"cause":{"name":"TimeoutError","code":"ETIMEDOUT"},'
|
|
195
|
-
b'"stack":"File \\"/private-source/app.py\\", line 42"},'
|
|
196
|
-
b'"message":"connection refused private-message"}\n'
|
|
197
|
-
b'private-tail')
|
|
198
|
-
if deadline == 130 and deadline not in self.sent:
|
|
199
|
-
self.sent.add(deadline)
|
|
200
|
-
return (b'\n{"level":"info","traceId":"private-raw-id",'
|
|
201
|
-
b'"message":"private-followup"}\n')
|
|
202
|
-
now = deadline
|
|
203
|
-
return None
|
|
204
|
-
def stop(self):
|
|
205
|
-
return True
|
|
206
|
-
|
|
207
|
-
def live_summary():
|
|
208
|
-
lines = ['live status=deadline']
|
|
209
|
-
for i in range(1, 5):
|
|
210
|
-
n = int(i == 1)
|
|
211
|
-
lines.append(f'window={i} error={n} warn=0 info={int(i == 2)} debug=0 unclassified=0 frames=0 '
|
|
212
|
-
f'dropped_bytes={12 * n + int(i == 2)} top=TypeError:{n},'
|
|
213
|
-
'UnhandledPromiseRejection:0,ECONNREFUSED:0,ETIMEDOUT:0,ECONNRESET:0,'
|
|
214
|
-
'EPIPE:0,ENOTFOUND:0,HTTP_5xx:0,OutOfMemory:0')
|
|
215
|
-
return '\n'.join(lines) + '\n'
|
|
216
|
-
|
|
217
|
-
def start(argv):
|
|
218
|
-
captures.append(argv)
|
|
219
|
-
return FakeStream()
|
|
220
|
-
|
|
221
|
-
live = watcher['main'].__globals__
|
|
222
|
-
with patch.object(runpy, 'run_path', return_value=watcher), \
|
|
223
|
-
patch.dict(live, {'start': start, 'monotonic': lambda: now}):
|
|
224
|
-
counts = live_summary()
|
|
225
|
-
windows = [{'window': i, 'error': int(i == 1), 'warn': 0, 'info': int(i == 2),
|
|
226
|
-
'debug': 0, 'unclassified': 0, 'frames': 0,
|
|
227
|
-
'dropped_bytes': 12 * int(i == 1) + int(i == 2),
|
|
228
|
-
'top': {'TypeError': int(i == 1), 'UnhandledPromiseRejection': 0,
|
|
229
|
-
'ECONNREFUSED': 0, 'ETIMEDOUT': 0, 'ECONNRESET': 0,
|
|
230
|
-
'EPIPE': 0, 'ENOTFOUND': 0, 'HTTP_5xx': 0, 'OutOfMemory': 0}}
|
|
231
|
-
for i in range(1, 5)]
|
|
232
|
-
report = {'status': 'deadline', 'counts': {'windows': windows},
|
|
233
|
-
'coverage': {'window_seconds': 15, 'byte_limit_per_window': 32768,
|
|
234
|
-
'dropped_bytes': 13}, 'evidence': no_evidence}
|
|
235
|
-
check(project, 'live', (0, counts, ''), saved=report)
|
|
236
|
-
captures.clear()
|
|
237
|
-
now = 100.0
|
|
238
|
-
# The second record is an INFO line with only a request id: linkage,
|
|
239
|
-
# not evidence, so no sleuth row is emitted for it (SKILL.md
|
|
240
|
-
# "Parsing Notes"). It counts as unselected instead.
|
|
241
|
-
events = [{'window': 1, 'seq': 1, 'ids': {'trace': 'id1'}, 'level': 'error',
|
|
242
|
-
'exception': 'TypeError', 'cause': 'TimeoutError', 'code': 'ECONNREFUSED',
|
|
243
|
-
'cause_code': 'ETIMEDOUT', 'frames': [{'kind': 'python', 'line': 42}],
|
|
244
|
-
'excerpt': 'connection refused [redacted]'}]
|
|
245
|
-
coverage = dict(records=2, unselected_records=1, invalid_records=0, event_drops=0,
|
|
246
|
-
id_drops=0, frame_drops=0, excerpt_drops=0, excerpt_truncations=0,
|
|
247
|
-
dropped_bytes=13, coverage='incomplete')
|
|
248
|
-
evidence = ''.join('sleuth ' + json.dumps(row, separators=(',', ':')) + '\n'
|
|
249
|
-
for row in [*events, coverage])
|
|
250
|
-
check(project, 'sleuth', (0, counts + evidence, ''),
|
|
251
|
-
saved=dict(report, evidence={'status': 'authorized_sleuth',
|
|
252
|
-
'events': events, 'coverage': coverage}))
|
|
253
|
-
assert len(captures) == 1, captures
|
|
254
|
-
assert captures[0][-5:] == ['logs', '-f', '--tail=0', '--', 'approved-app'], captures
|
|
255
|
-
with patch.dict(live, {'start': lambda _: None, 'observe': lambda *_: None}):
|
|
256
|
-
check(project, 'sleuth', failure)
|
|
257
|
-
finally:
|
|
258
|
-
os.chdir(here)
|
|
259
|
-
|
|
260
|
-
# ADR 0001: the historical batch runs in Python. These checks use a fake SSH written
|
|
261
|
-
# in Python and a PATH that holds nothing else, so no bash, timeout, head, od or awk.
|
|
262
|
-
import sys as _sys
|
|
263
|
-
from time import monotonic
|
|
264
|
-
with tempfile.TemporaryDirectory() as scratch:
|
|
265
|
-
scratch = Path(scratch)
|
|
266
|
-
bare = scratch / 'bare-bin'
|
|
267
|
-
bare.mkdir()
|
|
268
|
-
fake = bare / 'ssh'
|
|
269
|
-
fake.write_text(f'''#!{_sys.executable}
|
|
270
|
-
import os, signal, sys, time
|
|
271
|
-
expected = ['-nT', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=yes', '-o', 'UpdateHostKeys=no',
|
|
272
|
-
'-o', 'ClearAllForwardings=yes', '-o', 'PermitLocalCommand=no', '-o', 'ControlPath=none',
|
|
273
|
-
'bbc-test', 'docker', 'logs', '-f', '--tail=1000', '--', 'app.test']
|
|
274
|
-
if sys.argv[1:] != expected:
|
|
275
|
-
sys.exit(90)
|
|
276
|
-
mode = os.environ.get('FAKE_MODE', '')
|
|
277
|
-
out = sys.stdout.buffer
|
|
278
|
-
out.write(b'ERROR timeout raw\\n'); out.flush()
|
|
279
|
-
if mode == 'hang':
|
|
280
|
-
time.sleep(30)
|
|
281
|
-
elif mode == 'stubborn':
|
|
282
|
-
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
|
283
|
-
time.sleep(30)
|
|
284
|
-
elif mode == 'flood':
|
|
285
|
-
for _ in range(64):
|
|
286
|
-
out.write(b'info x\\n' * 4096)
|
|
287
|
-
''', encoding='ascii')
|
|
288
|
-
fake.chmod(0o700)
|
|
289
|
-
capture = main.__globals__
|
|
290
|
-
project = scratch / 'project'
|
|
291
|
-
project.mkdir()
|
|
292
|
-
subprocess.run(['git', 'init', '-q', str(project)], check=True)
|
|
293
|
-
(project / '.gitignore').write_bytes(b'/tmp_logs/\n')
|
|
294
|
-
|
|
295
|
-
def run_bare(args, mode='', deadline=None, grace=None):
|
|
296
|
-
env = {'PATH': str(bare), 'FAKE_MODE': mode, 'HOME': os.environ.get('HOME', '')}
|
|
297
|
-
patched = {k: v for k, v in (('DEADLINE', deadline), ('KILL_GRACE', grace)) if v is not None}
|
|
298
|
-
out, err = io.StringIO(), io.StringIO()
|
|
299
|
-
with patch.dict(os.environ, env, clear=True), patch.dict(capture, patched), \
|
|
300
|
-
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
|
301
|
-
code = main(args)
|
|
302
|
-
return code, out.getvalue(), err.getvalue()
|
|
303
|
-
|
|
304
|
-
one = ('severity error=1 warn=0 info=0 debug=0 unknown=0\n'
|
|
305
|
-
'category timeout=1 connection=0 auth=0 other=0\n')
|
|
306
|
-
old_cwd = os.getcwd()
|
|
307
|
-
os.chdir(project)
|
|
308
|
-
try:
|
|
309
|
-
# 1. Clean exit with only SSH on PATH: finished, and --no-save writes nothing.
|
|
310
|
-
code, out, err = run_bare(['--no-save', 'historical', 'bbc-test', 'app.test'])
|
|
311
|
-
assert (code, out, err) == (0, 'historical status=finished\n' + one + 'input cap=no partial=no\n', ''), (code, out, err)
|
|
312
|
-
assert not (project / 'tmp_logs').exists(), 'no-save must not create tmp_logs'
|
|
313
|
-
checks += 1
|
|
314
|
-
# 2. A real deadline (shortened): SSH is terminated, status 124 -> incomplete.
|
|
315
|
-
started = monotonic()
|
|
316
|
-
code, out, _ = run_bare(['--no-save', 'historical', 'bbc-test', 'app.test'], 'hang', 1, 1)
|
|
317
|
-
assert code == 0 and out.startswith('historical status=incomplete\n'), (code, out)
|
|
318
|
-
assert monotonic() - started < 5, 'deadline not enforced'
|
|
319
|
-
checks += 1
|
|
320
|
-
# 3. SSH ignores SIGTERM: a forced kill (137) is ambiguous, so nothing is reported.
|
|
321
|
-
if os.name == 'posix':
|
|
322
|
-
code, out, err = run_bare(['--no-save', 'historical', 'bbc-test', 'app.test'], 'stubborn', 1, 0.5)
|
|
323
|
-
assert (code, out) == (1, ''), (code, out, err)
|
|
324
|
-
checks += 1
|
|
325
|
-
# 4. Output beyond the 32 KiB cap is drained, not kept: cap=yes and bounded counts.
|
|
326
|
-
code, out, _ = run_bare(['--no-save', 'historical', 'bbc-test', 'app.test'], 'flood')
|
|
327
|
-
assert code == 0 and 'input cap=yes' in out and 'status=incomplete' in out, (code, out)
|
|
328
|
-
info = int(out.split('info=')[1].split()[0])
|
|
329
|
-
assert info < 32768 // len(b'info x\n') + 1, info
|
|
330
|
-
checks += 1
|
|
331
|
-
# 5. --no-save is for historical only.
|
|
332
|
-
code, _, err = run_bare(['--no-save', 'live', 'bbc-test', 'app.test'])
|
|
333
|
-
assert code == 1 and 'valid SSH alias' in err, (code, err)
|
|
334
|
-
checks += 1
|
|
335
|
-
finally:
|
|
336
|
-
os.chdir(old_cwd)
|
|
337
|
-
print(f'{checks} checks, 0 failed')
|
|
338
|
-
PY
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -eu
|
|
3
|
-
cd -- "${BASH_SOURCE[0]%/*}/.."
|
|
4
|
-
python -I -B - "$BASH" <<'PY'
|
|
5
|
-
import contextlib
|
|
6
|
-
import io
|
|
7
|
-
import json
|
|
8
|
-
import runpy
|
|
9
|
-
import sys
|
|
10
|
-
import traceback
|
|
11
|
-
from unittest.mock import patch
|
|
12
|
-
|
|
13
|
-
main = runpy.run_path('scripts/watch-live.py')['main']
|
|
14
|
-
controls = main.__globals__
|
|
15
|
-
argv = ['fake-ssh', '-nT', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=yes',
|
|
16
|
-
'-o', 'UpdateHostKeys=no', '-o', 'ClearAllForwardings=yes', '-o',
|
|
17
|
-
'PermitLocalCommand=no', '-o', 'ControlPath=none', 'bbc-test',
|
|
18
|
-
'docker', 'logs', '-f', '--tail=0', '--', 'app.test']
|
|
19
|
-
failures = 0
|
|
20
|
-
checks = 0
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def capture(events, args):
|
|
24
|
-
now = 0
|
|
25
|
-
launches = []
|
|
26
|
-
stops = []
|
|
27
|
-
pending = iter(events)
|
|
28
|
-
next_read = next(pending, None)
|
|
29
|
-
|
|
30
|
-
class Fake:
|
|
31
|
-
def read_until(self, deadline):
|
|
32
|
-
nonlocal now, next_read
|
|
33
|
-
if next_read is None or next_read[0] >= deadline:
|
|
34
|
-
now = deadline
|
|
35
|
-
return None
|
|
36
|
-
now, data = next_read
|
|
37
|
-
next_read = next(pending, None)
|
|
38
|
-
return data
|
|
39
|
-
|
|
40
|
-
def stop(self):
|
|
41
|
-
stops.append(now)
|
|
42
|
-
return True
|
|
43
|
-
|
|
44
|
-
def start(command):
|
|
45
|
-
launches.append(command)
|
|
46
|
-
return Fake()
|
|
47
|
-
|
|
48
|
-
out, err = io.StringIO(), io.StringIO()
|
|
49
|
-
with patch.dict(controls, start=start, monotonic=lambda: now), \
|
|
50
|
-
patch.object(controls['shutil'], 'which', {'bash': sys.argv[1], 'ssh': 'fake-ssh'}.get), \
|
|
51
|
-
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
|
|
52
|
-
status = main(args)
|
|
53
|
-
return status, out.getvalue(), err.getvalue(), launches, stops
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def check(label, actual, expected):
|
|
57
|
-
global checks, failures
|
|
58
|
-
checks += 1
|
|
59
|
-
if actual != expected:
|
|
60
|
-
failures += 1
|
|
61
|
-
print(f'FAIL {label}: observed={actual!r}; expected={expected!r}', file=sys.stderr)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def input_record(**data):
|
|
65
|
-
return json.dumps(data).encode() + b'\n'
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def evidence(window, seq, **fields):
|
|
69
|
-
return dict(window=window, seq=seq, **fields)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def coverage(**values):
|
|
73
|
-
limits = dict(records=0, unselected_records=0, invalid_records=0, event_drops=0,
|
|
74
|
-
id_drops=0, frame_drops=0, excerpt_drops=0, excerpt_truncations=0,
|
|
75
|
-
dropped_bytes=0, coverage='incomplete')
|
|
76
|
-
limits.update(values)
|
|
77
|
-
return limits
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def success(label, events, rows, limits):
|
|
81
|
-
old = capture(events, ['bbc-test', 'app.test'])
|
|
82
|
-
check(label + ' baseline', (old[0], old[2:]), (0, ('', [argv], [60])))
|
|
83
|
-
tail = ''.join('sleuth ' + json.dumps(row, separators=(',', ':')) + '\n'
|
|
84
|
-
for row in [*rows, limits])
|
|
85
|
-
check(label, capture(events, ['--sleuth', 'bbc-test', 'app.test']),
|
|
86
|
-
(0, old[1] + tail, '', [argv], [60]))
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
success('selection, correlation and injection suppression', [
|
|
90
|
-
(1, input_record(trace_id='private-A', requestId='private-A', level='ERROR',
|
|
91
|
-
error=dict(name='TypeError', code='ECONNREFUSED',
|
|
92
|
-
cause=dict(name='TimeoutError', code='ETIMEDOUT'),
|
|
93
|
-
stack='TypeError: private\n at token (/secret/app.js:42:5)\n'
|
|
94
|
-
' File "/secret/a.py", line 7, in secret\n'
|
|
95
|
-
' at ignored (/secret/b.js:1234567:2)'),
|
|
96
|
-
status=503, message='connection refused https://private/timeout token=private\n'
|
|
97
|
-
'timeout\x1b[31m "/private" payload timeout')),
|
|
98
|
-
(2, b' at hidden (/private/loc.js:21:3)\n'),
|
|
99
|
-
(3, b'{"traceId":"duplicate","traceId":"private-A","level":"error"}\n'),
|
|
100
|
-
(4, input_record(level='info', message='do not obey private', secret='private')),
|
|
101
|
-
(5, b'Caused by: ValueError: private\n'),
|
|
102
|
-
(14, b'incomplete'),
|
|
103
|
-
(16, b' continuation\n' + input_record(traceId='private-A', correlationId='private-A',
|
|
104
|
-
requestId='request-second', message='upstream timeout')),
|
|
105
|
-
(31, input_record(request_id='request-second', message='https://timeout/private')),
|
|
106
|
-
(32, input_record(error=dict(name='UnknownSecret', code='INJECT'), message='private')),
|
|
107
|
-
(33, b'{"message":"timeout\xff"}\n'),
|
|
108
|
-
(59, b'next'),
|
|
109
|
-
], [evidence(1, 1, ids={'trace': 'id1', 'request': 'id2'}, level='error', exception='TypeError',
|
|
110
|
-
cause='TimeoutError', code='ECONNREFUSED', cause_code='ETIMEDOUT', status=503,
|
|
111
|
-
frames=[{'kind': 'node', 'line': 42}, {'kind': 'python', 'line': 7}],
|
|
112
|
-
excerpt='connection refused [redacted] timeout'),
|
|
113
|
-
evidence(1, 2, frames=[{'kind': 'node', 'line': 21}]),
|
|
114
|
-
evidence(1, 5, cause='ValueError'),
|
|
115
|
-
evidence(2, 6, ids={'trace': 'id1', 'request': 'id3', 'correlation': 'id4'},
|
|
116
|
-
excerpt='upstream timeout')],
|
|
117
|
-
coverage(records=9, unselected_records=3, invalid_records=2, dropped_bytes=28))
|
|
118
|
-
|
|
119
|
-
burst = b''.join(input_record(traceId=f'secret-{i}', message='timeout ' + 'private ' * 100,
|
|
120
|
-
error={'stack': '\n'.join(' at f (/p:9:1)' for _ in range(4))})
|
|
121
|
-
for i in range(25))
|
|
122
|
-
limited_rows = []
|
|
123
|
-
for i in range(1, 25):
|
|
124
|
-
fields = {'ids': {'trace': f'id{i}'}} if i <= 16 else {}
|
|
125
|
-
fields['frames'] = [{'kind': 'node', 'line': 9}] * 3
|
|
126
|
-
if i <= 4:
|
|
127
|
-
fields['excerpt'] = 'timeout [redacted]'
|
|
128
|
-
limited_rows.append(evidence(1, i, **fields))
|
|
129
|
-
success('all evidence caps and byte cap', [(1, burst + b'x' * (32768 - len(burst)) + b'secret\n')],
|
|
130
|
-
limited_rows, coverage(records=25, event_drops=1, id_drops=8, frame_drops=24,
|
|
131
|
-
excerpt_drops=20, excerpt_truncations=4,
|
|
132
|
-
dropped_bytes=32768 - len(burst) + 7))
|
|
133
|
-
success('labels reset', [(2, input_record(requestId='new-secret'))],
|
|
134
|
-
[], coverage(records=1, unselected_records=1))
|
|
135
|
-
success('strict IDs, plain evidence and Python source exclusion', [
|
|
136
|
-
(2, input_record(traceId='A', trace_id='B', correlationId=['private'], requestId='x' * 129)),
|
|
137
|
-
(3, input_record(traceId='A', trace_id='A', status='503')),
|
|
138
|
-
(4, b'{"traceId":"private","status":NaN}\n'),
|
|
139
|
-
(5, b'TypeError: token=private timeout\nECONNRESET: connection reset\n'
|
|
140
|
-
b' at hidden.Class.method(Hidden.java:123456)\n'
|
|
141
|
-
b' File "private.py", line 1, in hidden\n'
|
|
142
|
-
b' {"traceId":"source-only","message":"timeout"}\n'
|
|
143
|
-
b' at hidden.Class.method(Hidden.java:1234567)\n'),
|
|
144
|
-
], [evidence(1, 4, exception='TypeError', excerpt='[redacted] timeout'),
|
|
145
|
-
evidence(1, 5, code='ECONNRESET', excerpt='connection reset'),
|
|
146
|
-
evidence(1, 6, frames=[{'kind': 'java', 'line': 123456}]),
|
|
147
|
-
evidence(1, 7, frames=[{'kind': 'python', 'line': 1}])],
|
|
148
|
-
coverage(records=9, unselected_records=4, invalid_records=1, id_drops=3))
|
|
149
|
-
try:
|
|
150
|
-
compile('at private (secret.js:314159:1)', 'private.py', 'exec')
|
|
151
|
-
except SyntaxError as error:
|
|
152
|
-
syntax_stack = ''.join(traceback.format_exception_only(type(error), error))
|
|
153
|
-
else:
|
|
154
|
-
raise AssertionError('fixture must produce a Python SyntaxError')
|
|
155
|
-
assert ' at private (secret.js:314159:1)\n' in syntax_stack
|
|
156
|
-
python_frame = {'kind': 'python', 'line': 1}
|
|
157
|
-
success('SyntaxError source is not a frame in JSON or plain input', [
|
|
158
|
-
(1, input_record(error={'stack': syntax_stack})),
|
|
159
|
-
(2, syntax_stack.encode()),
|
|
160
|
-
(3, b' at real (other.js:27:1)\n'),
|
|
161
|
-
], [evidence(1, 1, frames=[python_frame]), evidence(1, 2, frames=[python_frame]),
|
|
162
|
-
evidence(1, 2 + len(syntax_stack.splitlines()), frames=[{'kind': 'node', 'line': 27}])],
|
|
163
|
-
coverage(records=2 + len(syntax_stack.splitlines()),
|
|
164
|
-
unselected_records=len(syntax_stack.splitlines()) - 1))
|
|
165
|
-
for target in ['app*', 'app\n']:
|
|
166
|
-
check('invalid exact target', capture([], ['--sleuth', 'bbc-test', target]),
|
|
167
|
-
(1, '', 'Watcher live mode requires a valid SSH alias and exact container name or ID.\n', [], []))
|
|
168
|
-
check('early EOF', capture([(1, input_record(traceId='private')), (2, b'')],
|
|
169
|
-
['--sleuth', 'bbc-test', 'app.test']),
|
|
170
|
-
(1, '', 'Watcher live capture failed; no counts.\n', [argv], [2]))
|
|
171
|
-
check('sleuth help', capture([], ['--sleuth', '--help']),
|
|
172
|
-
(0, 'Usage: python -I -B scripts/watch-live.py --sleuth <ssh-alias> <exact-container>\n'
|
|
173
|
-
'Add bounded, redacted evidence to the live summary; no raw IDs or logs.\n', '', [], []))
|
|
174
|
-
print(f'{checks} checks, {failures} failed')
|
|
175
|
-
sys.exit(bool(failures))
|
|
176
|
-
PY
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -eu
|
|
3
|
-
cd -- "${BASH_SOURCE[0]%/*}/.."
|
|
4
|
-
|
|
5
|
-
scratch=$(mktemp -d)
|
|
6
|
-
trap 'rm -rf -- "$scratch"' EXIT
|
|
7
|
-
failures=0
|
|
8
|
-
tests=0
|
|
9
|
-
PYTHON_BIN=$(command -v python3 || command -v python)
|
|
10
|
-
PYTHON_BIN=$("$PYTHON_BIN" -c 'import sys; print(sys.executable)')
|
|
11
|
-
check() {
|
|
12
|
-
local name=$1 want_status=$2 want_output=$3 status=0 output
|
|
13
|
-
shift 3
|
|
14
|
-
# Keep trailing newlines through command substitution and check them too.
|
|
15
|
-
local end=$'\037'
|
|
16
|
-
output=$(rc=0; "$@" 2>"$scratch/stderr" || rc=$?; printf '%s' "$end"; exit "$rc") || status=$?
|
|
17
|
-
[[ -z $want_output ]] || want_output+=$'\n'
|
|
18
|
-
output=${output%"$end"}
|
|
19
|
-
tests=$((tests + 1))
|
|
20
|
-
local error_output
|
|
21
|
-
IFS= read -r -d '' error_output <"$scratch/stderr" || :
|
|
22
|
-
if [[ $status != "$want_status" || $output != "$want_output" || $error_output != "${expected_stderr:-}" ]]; then
|
|
23
|
-
printf 'FAIL %s: exit=%s stdout=%q stderr=%q\n' "$name" "$status" "$output" "$error_output" >&2
|
|
24
|
-
failures=$((failures + 1))
|
|
25
|
-
fi
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
summarize() { "$PYTHON_BIN" -I -B scripts/summarize-logs.py; }
|
|
29
|
-
empty_counts=$'severity error=0 warn=0 info=0 debug=0 unknown=0\ncategory timeout=0 connection=0 auth=0 other=0'
|
|
30
|
-
unknown_counts=$'severity error=0 warn=0 info=0 debug=0 unknown=1\ncategory timeout=0 connection=0 auth=0 other=1'
|
|
31
|
-
info_counts=$'severity error=0 warn=0 info=1 debug=0 unknown=0\ncategory timeout=0 connection=0 auth=0 other=1'
|
|
32
|
-
check empty 0 "$empty_counts"$'\ninput cap=no partial=no' summarize </dev/null
|
|
33
|
-
# The first recognised level token within the first 12 tokens wins
|
|
34
|
-
# (SKILL.md "Parsing Notes"), so "INFO error TIMEOUT ..." is info: a severity
|
|
35
|
-
# word in the message body must not flip the record.
|
|
36
|
-
check classification 0 $'severity error=0 warn=1 info=2 debug=1 unknown=2\ncategory timeout=1 connection=1 auth=1 other=3\ninput cap=no partial=no' summarize < <(
|
|
37
|
-
printf 'INFO error TIMEOUT connection auth secret=do-not-print\r\nwarning connection auth\ninfo authentication\ndebug timeout_ms\nterror disconnecting\n\000\n'
|
|
38
|
-
)
|
|
39
|
-
check partial 4 "$info_counts"$'\ninput cap=no partial=yes' summarize < <(printf 'info\nERROR TIMEOUT')
|
|
40
|
-
check below-cap 0 "$unknown_counts"$'\ninput cap=no partial=no' summarize < <(printf '%32766s\n' '')
|
|
41
|
-
check exact-cap 3 "$unknown_counts"$'\ninput cap=yes partial=no' summarize < <(printf '%32767s\n' '')
|
|
42
|
-
check oversized 3 "$info_counts"$'\ninput cap=yes partial=yes' summarize < <(printf 'info\n%32768s\nerror timeout\n' '')
|
|
43
|
-
check usage 1 '' "$PYTHON_BIN" -I -B scripts/summarize-logs.py unexpected-argument </dev/null
|
|
44
|
-
# ADR 0001: the summarizer needs no external tool (the awk version needed head, od, awk).
|
|
45
|
-
check empty-path 0 "$empty_counts"$'\ninput cap=no partial=no' env -i PATH=/nonexistent "$PYTHON_BIN" -I -B scripts/summarize-logs.py </dev/null
|
|
46
|
-
|
|
47
|
-
# The test extracts the documented no-save command so it cannot silently drift.
|
|
48
|
-
# Never run it unless the fake executable is the SSH that the PATH resolves.
|
|
49
|
-
printf '#!%s -p\n' "$BASH" >"$scratch/ssh"
|
|
50
|
-
printf '%s\n' '
|
|
51
|
-
if [[ -n ${FAKE_SSH_MARKER:-} ]]; then
|
|
52
|
-
printf "invoked\n" >"$FAKE_SSH_MARKER"
|
|
53
|
-
fi
|
|
54
|
-
expected=(-nT -o BatchMode=yes -o StrictHostKeyChecking=yes -o UpdateHostKeys=no
|
|
55
|
-
-o ClearAllForwardings=yes -o PermitLocalCommand=no -o ControlPath=none
|
|
56
|
-
bbc-test docker logs -f --tail=1000 -- app.test)
|
|
57
|
-
[[ $# == ${#expected[@]} ]] || exit 90
|
|
58
|
-
for word in "${expected[@]}"; do
|
|
59
|
-
[[ $1 == "$word" ]] || exit 91
|
|
60
|
-
shift
|
|
61
|
-
done
|
|
62
|
-
printf "INFO synthetic-secret\n"
|
|
63
|
-
printf "synthetic-diagnostic\n" >&2
|
|
64
|
-
exit "${FAKE_SSH_STATUS:-0}"
|
|
65
|
-
' >>"$scratch/ssh"
|
|
66
|
-
chmod +x "$scratch/ssh"
|
|
67
|
-
ln -s "$PYTHON_BIN" "$scratch/python3"
|
|
68
|
-
command=$(awk '/^ ```bash$/ { emit=1; next } /^ ```$/ && emit { exit } emit { sub(/^ /, ""); print }' references/batch-protocol.md)
|
|
69
|
-
[[ $command == *'save-counts.py" --no-save historical'* ]]
|
|
70
|
-
run_protocol() {
|
|
71
|
-
local bin=${2:-$scratch} rc=0
|
|
72
|
-
(cd "$scratch" && PATH="$bin" FAKE_SSH_STATUS="${1:-0}" FAKE_SSH_MARKER="${3:-}" \
|
|
73
|
-
PYTHONPATH="${4:-}" PYTHONSTARTUP="${4:+$4/startup.py}" \
|
|
74
|
-
watcher_skill="$OLDPWD" alias_name=bbc-test container=app.test "$BASH" -p -c 'eval "$1"' bash "$command") || rc=$?
|
|
75
|
-
if [[ -n ${3:-} && -e $3 ]]; then
|
|
76
|
-
printf 'fake SSH was invoked\n' >&2
|
|
77
|
-
return 94
|
|
78
|
-
fi
|
|
79
|
-
return "$rc"
|
|
80
|
-
}
|
|
81
|
-
merged_counts=$'severity error=0 warn=0 info=1 debug=0 unknown=1\ncategory timeout=0 connection=0 auth=0 other=2\ninput cap=no partial=no'
|
|
82
|
-
check fake-ssh 0 $'historical status=finished\n'"$merged_counts" run_protocol
|
|
83
|
-
check fake-ssh-timeout-status 0 $'historical status=incomplete\n'"$merged_counts" run_protocol 124
|
|
84
|
-
expected_stderr=$'Watcher counts capture failed.\n' check fake-ssh-error-status 1 '' run_protocol 255
|
|
85
|
-
|
|
86
|
-
# python -I ignores PYTHONPATH and PYTHONSTARTUP: a planted module must not run.
|
|
87
|
-
mkdir -p "$scratch/planted"
|
|
88
|
-
# Built-in open() only: importing anything here would recurse into this fake re.
|
|
89
|
-
printf 'open(%s, "w").write("ran")\n' "'$scratch/planted-ran'" >"$scratch/planted/re.py"
|
|
90
|
-
cp "$scratch/planted/re.py" "$scratch/planted/startup.py"
|
|
91
|
-
check ignore-python-env 0 $'historical status=finished\n'"$merged_counts" run_protocol 0 '' '' "$scratch/planted"
|
|
92
|
-
tests=$((tests + 1))
|
|
93
|
-
if [[ -e $scratch/planted-ran ]]; then
|
|
94
|
-
printf 'FAIL planted module executed\n' >&2
|
|
95
|
-
failures=$((failures + 1))
|
|
96
|
-
fi
|
|
97
|
-
|
|
98
|
-
# Without ssh on the PATH there is no connection and no fallback.
|
|
99
|
-
mkdir -p "$scratch/no-ssh"
|
|
100
|
-
ln -s "$PYTHON_BIN" "$scratch/no-ssh/python3"
|
|
101
|
-
expected_stderr=$'Watcher counts capture failed.\n' \
|
|
102
|
-
check missing-ssh-no-connection 1 '' run_protocol 0 "$scratch/no-ssh" "$scratch/ssh-invoked"
|
|
103
|
-
|
|
104
|
-
printf '%s checks, %s failed\n' "$tests" "$failures"
|
|
105
|
-
[[ $failures == 0 ]]
|