@aibyzero/cm-workflow 0.10.5 → 0.10.6
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/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +1 -0
- package/CONTRIBUTING.md +12 -1
- package/README.md +20 -4
- package/VERSION +1 -1
- package/docs/installation.md +19 -9
- package/install-codex.sh +1 -1
- package/package.json +1 -1
- package/scripts/cm-check-runtime.sh +1 -0
- package/scripts/cm-evolution-analyze.py +576 -0
- package/scripts/cm-release-smoke.sh +73 -0
- package/scripts/scan-public-safety.py +5 -5
- package/scripts/test-cm-evolution-analyze.py +870 -0
- package/scripts/test-scan-public-safety.py +59 -1
- package/scripts/validate-public-repo.py +25 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Read-only, deterministic analyzer for repeated CM Workflow failure signals."""
|
|
3
|
+
|
|
4
|
+
from collections import Counter, defaultdict
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
import hashlib
|
|
7
|
+
import json
|
|
8
|
+
import math
|
|
9
|
+
import os
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
import re
|
|
12
|
+
import stat
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
MAX_FILES = 32
|
|
17
|
+
MAX_TOTAL_BYTES = 64 * 1024 * 1024
|
|
18
|
+
MAX_LINES = 200_000
|
|
19
|
+
MAX_LINE_BYTES = 65_536
|
|
20
|
+
MAX_FINGERPRINTS = 1_000
|
|
21
|
+
MAX_RUN_REFS = 128
|
|
22
|
+
|
|
23
|
+
IDENTIFIER = re.compile(r"^[A-Za-z][A-Za-z0-9._-]{0,63}$")
|
|
24
|
+
ENTITY_ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$")
|
|
25
|
+
RUN_ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{7,127}$")
|
|
26
|
+
SECRET_SHAPED = re.compile(
|
|
27
|
+
r"api[_-]?key|authorization|cookie|password|passwd|private[_-]?key|"
|
|
28
|
+
r"recovery[_-]?code|secret|token",
|
|
29
|
+
re.IGNORECASE,
|
|
30
|
+
)
|
|
31
|
+
CREDENTIAL_SHAPED = re.compile(
|
|
32
|
+
r"(?:AKIA|ASIA)[A-Z0-9]{16}|gh[pousr]_[A-Za-z0-9]{20,}|"
|
|
33
|
+
r"github_pat_[A-Za-z0-9_]{20,}|AIza[0-9A-Za-z_-]{20,}|"
|
|
34
|
+
r"xox[baprs]-[A-Za-z0-9-]{20,}"
|
|
35
|
+
)
|
|
36
|
+
HIGH_RISK_IMPACTS = {
|
|
37
|
+
"security",
|
|
38
|
+
"data_integrity",
|
|
39
|
+
"state_integrity",
|
|
40
|
+
"completion_integrity",
|
|
41
|
+
}
|
|
42
|
+
RESOURCE_PHASES = {"acquired", "released", "cleanup_failed"}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class InputBoundaryError(Exception):
|
|
46
|
+
def __init__(self, code, input_index=None):
|
|
47
|
+
super().__init__(code)
|
|
48
|
+
self.code = code
|
|
49
|
+
self.input_index = input_index
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def hash_ref(value):
|
|
53
|
+
return "sha256:" + hashlib.sha256(value.encode("utf-8")).hexdigest()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def parse_cli(arguments):
|
|
57
|
+
if not arguments or len(arguments) % 2:
|
|
58
|
+
raise InputBoundaryError("invalid_arguments")
|
|
59
|
+
paths = []
|
|
60
|
+
for offset in range(0, len(arguments), 2):
|
|
61
|
+
if arguments[offset] != "--log" or not arguments[offset + 1]:
|
|
62
|
+
raise InputBoundaryError("invalid_arguments", offset // 2 + 1)
|
|
63
|
+
paths.append(Path(arguments[offset + 1]))
|
|
64
|
+
if len(paths) > MAX_FILES:
|
|
65
|
+
raise InputBoundaryError("too_many_files")
|
|
66
|
+
return paths
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def open_regular_file(path, input_index):
|
|
70
|
+
try:
|
|
71
|
+
if path.is_symlink():
|
|
72
|
+
raise InputBoundaryError("invalid_input", input_index)
|
|
73
|
+
flags = os.O_RDONLY | getattr(os, "O_CLOEXEC", 0) | getattr(os, "O_NONBLOCK", 0)
|
|
74
|
+
flags |= getattr(os, "O_NOFOLLOW", 0)
|
|
75
|
+
descriptor = os.open(str(path), flags)
|
|
76
|
+
except InputBoundaryError:
|
|
77
|
+
raise
|
|
78
|
+
except (OSError, ValueError):
|
|
79
|
+
raise InputBoundaryError("unreadable_input", input_index)
|
|
80
|
+
try:
|
|
81
|
+
metadata = os.fstat(descriptor)
|
|
82
|
+
if not stat.S_ISREG(metadata.st_mode):
|
|
83
|
+
raise InputBoundaryError("invalid_input", input_index)
|
|
84
|
+
return os.fdopen(descriptor, "rb"), metadata.st_size
|
|
85
|
+
except InputBoundaryError:
|
|
86
|
+
os.close(descriptor)
|
|
87
|
+
raise
|
|
88
|
+
except OSError:
|
|
89
|
+
os.close(descriptor)
|
|
90
|
+
raise InputBoundaryError("unreadable_input", input_index)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def reject_non_standard_constant(_value):
|
|
94
|
+
raise ValueError("non-standard JSON constant")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def parse_finite_float(value):
|
|
98
|
+
parsed = float(value)
|
|
99
|
+
if not math.isfinite(parsed):
|
|
100
|
+
raise ValueError("non-finite JSON number")
|
|
101
|
+
return parsed
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Analyzer:
|
|
105
|
+
def __init__(self):
|
|
106
|
+
self.summary = {
|
|
107
|
+
"files": 0,
|
|
108
|
+
"lines": 0,
|
|
109
|
+
"valid_events": 0,
|
|
110
|
+
"signal_events": 0,
|
|
111
|
+
"malformed_lines": 0,
|
|
112
|
+
}
|
|
113
|
+
self.diagnostics = Counter()
|
|
114
|
+
self.aggregates = {}
|
|
115
|
+
self.resource_events = defaultdict(list)
|
|
116
|
+
self.invalid_resource_groups = set()
|
|
117
|
+
self.unknown_resource_runs = 0
|
|
118
|
+
self.total_bytes = 0
|
|
119
|
+
|
|
120
|
+
def diagnose(self, code, malformed=False):
|
|
121
|
+
self.diagnostics[code] += 1
|
|
122
|
+
if malformed:
|
|
123
|
+
self.summary["malformed_lines"] += 1
|
|
124
|
+
|
|
125
|
+
def read(self, paths):
|
|
126
|
+
self.summary["files"] = len(paths)
|
|
127
|
+
declared_size = 0
|
|
128
|
+
for input_index, path in enumerate(paths, start=1):
|
|
129
|
+
handle, file_size = open_regular_file(path, input_index)
|
|
130
|
+
declared_size += file_size
|
|
131
|
+
if declared_size > MAX_TOTAL_BYTES:
|
|
132
|
+
handle.close()
|
|
133
|
+
raise InputBoundaryError("input_too_large", input_index)
|
|
134
|
+
try:
|
|
135
|
+
with handle:
|
|
136
|
+
while True:
|
|
137
|
+
try:
|
|
138
|
+
raw_line = handle.readline(MAX_LINE_BYTES + 1)
|
|
139
|
+
except OSError:
|
|
140
|
+
raise InputBoundaryError("unreadable_input", input_index)
|
|
141
|
+
if not raw_line:
|
|
142
|
+
break
|
|
143
|
+
if len(raw_line) > MAX_LINE_BYTES:
|
|
144
|
+
raise InputBoundaryError("line_too_long", input_index)
|
|
145
|
+
self.total_bytes += len(raw_line)
|
|
146
|
+
if self.total_bytes > MAX_TOTAL_BYTES:
|
|
147
|
+
raise InputBoundaryError("input_too_large", input_index)
|
|
148
|
+
self.summary["lines"] += 1
|
|
149
|
+
if self.summary["lines"] > MAX_LINES:
|
|
150
|
+
raise InputBoundaryError("too_many_lines", input_index)
|
|
151
|
+
self.process_line(raw_line)
|
|
152
|
+
except InputBoundaryError:
|
|
153
|
+
raise
|
|
154
|
+
except OSError:
|
|
155
|
+
raise InputBoundaryError("unreadable_input", input_index)
|
|
156
|
+
self.finish_resources()
|
|
157
|
+
|
|
158
|
+
def process_line(self, raw_line):
|
|
159
|
+
try:
|
|
160
|
+
text = raw_line.decode("utf-8")
|
|
161
|
+
except UnicodeDecodeError:
|
|
162
|
+
self.diagnose("invalid_utf8", malformed=True)
|
|
163
|
+
return
|
|
164
|
+
try:
|
|
165
|
+
row = json.loads(
|
|
166
|
+
text,
|
|
167
|
+
parse_constant=reject_non_standard_constant,
|
|
168
|
+
parse_float=parse_finite_float,
|
|
169
|
+
)
|
|
170
|
+
except (json.JSONDecodeError, RecursionError, ValueError):
|
|
171
|
+
self.diagnose("malformed_json", malformed=True)
|
|
172
|
+
return
|
|
173
|
+
if not isinstance(row, dict):
|
|
174
|
+
self.diagnose("non_object", malformed=True)
|
|
175
|
+
return
|
|
176
|
+
self.summary["valid_events"] += 1
|
|
177
|
+
self.process_event(row)
|
|
178
|
+
|
|
179
|
+
def process_event(self, row):
|
|
180
|
+
event_name = row.get("event")
|
|
181
|
+
if not isinstance(event_name, str):
|
|
182
|
+
if "event" in row:
|
|
183
|
+
self.diagnose("invalid_field_type")
|
|
184
|
+
return
|
|
185
|
+
|
|
186
|
+
if event_name == "resource":
|
|
187
|
+
self.collect_resource(row)
|
|
188
|
+
return
|
|
189
|
+
if event_name == "error":
|
|
190
|
+
signal_kind = self.error_signal_kind(row)
|
|
191
|
+
if signal_kind is not None:
|
|
192
|
+
self.summary["signal_events"] += 1
|
|
193
|
+
self.add_event_signal(signal_kind, row)
|
|
194
|
+
return
|
|
195
|
+
if event_name == "degrade":
|
|
196
|
+
self.summary["signal_events"] += 1
|
|
197
|
+
self.add_event_signal("degrade", row)
|
|
198
|
+
return
|
|
199
|
+
if event_name == "warning":
|
|
200
|
+
recovered = row.get("recovered")
|
|
201
|
+
if not isinstance(recovered, bool):
|
|
202
|
+
self.diagnose("invalid_field_type")
|
|
203
|
+
return
|
|
204
|
+
if recovered is False:
|
|
205
|
+
self.summary["signal_events"] += 1
|
|
206
|
+
self.add_event_signal("unrecovered_warning", row)
|
|
207
|
+
return
|
|
208
|
+
if event_name in {"review", "task_review"}:
|
|
209
|
+
state = self.normalized_state(
|
|
210
|
+
row, {"retry": "retry", "changes_requested": "changes_requested"}
|
|
211
|
+
)
|
|
212
|
+
if state is not None:
|
|
213
|
+
self.summary["signal_events"] += 1
|
|
214
|
+
if state:
|
|
215
|
+
self.add_event_signal("review_retry", row, normalized_state=state)
|
|
216
|
+
return
|
|
217
|
+
if event_name in {"qa", "test_run"}:
|
|
218
|
+
state = self.normalized_state(
|
|
219
|
+
row, {"blocked": "blocked", "case_blocked": "case_blocked"}
|
|
220
|
+
)
|
|
221
|
+
if state is not None:
|
|
222
|
+
self.summary["signal_events"] += 1
|
|
223
|
+
if state:
|
|
224
|
+
self.add_event_signal("qa_blocked", row, normalized_state=state)
|
|
225
|
+
|
|
226
|
+
def normalized_state(self, row, allowed):
|
|
227
|
+
found = []
|
|
228
|
+
saw_relevant_field = False
|
|
229
|
+
for name in ("phase", "outcome"):
|
|
230
|
+
if name not in row:
|
|
231
|
+
continue
|
|
232
|
+
saw_relevant_field = True
|
|
233
|
+
value = row[name]
|
|
234
|
+
if not isinstance(value, str):
|
|
235
|
+
self.diagnose("invalid_field_type")
|
|
236
|
+
return ""
|
|
237
|
+
if value in allowed:
|
|
238
|
+
found.append(allowed[value])
|
|
239
|
+
if not found:
|
|
240
|
+
return None if saw_relevant_field else None
|
|
241
|
+
if len(set(found)) > 1:
|
|
242
|
+
self.diagnose("conflicting_signal_state")
|
|
243
|
+
return ""
|
|
244
|
+
return found[0]
|
|
245
|
+
|
|
246
|
+
def error_signal_kind(self, row):
|
|
247
|
+
recovered = row.get("recovered")
|
|
248
|
+
if "recovered" in row and not isinstance(recovered, bool):
|
|
249
|
+
self.diagnose("invalid_field_type")
|
|
250
|
+
return None
|
|
251
|
+
for name in ("outcome", "impact"):
|
|
252
|
+
if name in row and not isinstance(row[name], str):
|
|
253
|
+
self.diagnose("invalid_field_type")
|
|
254
|
+
return None
|
|
255
|
+
high_risk = (
|
|
256
|
+
recovered is False
|
|
257
|
+
and row.get("outcome") == "blocked"
|
|
258
|
+
and row.get("impact") in HIGH_RISK_IMPACTS
|
|
259
|
+
)
|
|
260
|
+
return "high_risk_error" if high_risk else "error"
|
|
261
|
+
|
|
262
|
+
def common_signature(self, row, signal_kind):
|
|
263
|
+
schema_version = row.get("schema_version")
|
|
264
|
+
if isinstance(schema_version, bool) or not isinstance(schema_version, int):
|
|
265
|
+
self.diagnose(
|
|
266
|
+
"invalid_field_type" if "schema_version" in row else "insufficient_signature"
|
|
267
|
+
)
|
|
268
|
+
return None
|
|
269
|
+
if schema_version != 1:
|
|
270
|
+
self.diagnose("unsupported_schema_version")
|
|
271
|
+
return None
|
|
272
|
+
workflow = self.identifier(row, "workflow")
|
|
273
|
+
if workflow is None:
|
|
274
|
+
return None
|
|
275
|
+
return {
|
|
276
|
+
"fingerprint_version": 1,
|
|
277
|
+
"schema_version": 1,
|
|
278
|
+
"workflow": workflow,
|
|
279
|
+
"signal_kind": signal_kind,
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
def identifier(self, row, name, pattern=IDENTIFIER):
|
|
283
|
+
if name not in row:
|
|
284
|
+
self.diagnose("insufficient_signature")
|
|
285
|
+
return None
|
|
286
|
+
value = row[name]
|
|
287
|
+
if not isinstance(value, str):
|
|
288
|
+
self.diagnose("invalid_field_type")
|
|
289
|
+
return None
|
|
290
|
+
if SECRET_SHAPED.search(value) or CREDENTIAL_SHAPED.search(value):
|
|
291
|
+
self.diagnose("secret_shaped_token")
|
|
292
|
+
return None
|
|
293
|
+
if not pattern.fullmatch(value):
|
|
294
|
+
self.diagnose("invalid_identifier")
|
|
295
|
+
return None
|
|
296
|
+
return value
|
|
297
|
+
|
|
298
|
+
def scope_ref(self, row, preferred, fallback):
|
|
299
|
+
name = preferred if preferred in row else fallback
|
|
300
|
+
pattern = IDENTIFIER if name == "node" else ENTITY_ID
|
|
301
|
+
value = self.identifier(row, name, pattern)
|
|
302
|
+
return None if value is None else hash_ref(value)
|
|
303
|
+
|
|
304
|
+
def valid_run_id(self, row):
|
|
305
|
+
if "run_id" not in row:
|
|
306
|
+
self.diagnose("invalid_run_id")
|
|
307
|
+
return None
|
|
308
|
+
value = row["run_id"]
|
|
309
|
+
if not isinstance(value, str):
|
|
310
|
+
self.diagnose("invalid_field_type")
|
|
311
|
+
return None
|
|
312
|
+
if SECRET_SHAPED.search(value) or CREDENTIAL_SHAPED.search(value):
|
|
313
|
+
self.diagnose("secret_shaped_token")
|
|
314
|
+
return None
|
|
315
|
+
if not RUN_ID.fullmatch(value):
|
|
316
|
+
self.diagnose("invalid_run_id")
|
|
317
|
+
return None
|
|
318
|
+
return value
|
|
319
|
+
|
|
320
|
+
def resource_run_identity(self, row):
|
|
321
|
+
if "run_id" not in row:
|
|
322
|
+
self.diagnose("invalid_run_id")
|
|
323
|
+
self.unknown_resource_runs += 1
|
|
324
|
+
return f"unknown:{self.unknown_resource_runs}", None
|
|
325
|
+
value = row["run_id"]
|
|
326
|
+
if not isinstance(value, str):
|
|
327
|
+
self.diagnose("invalid_field_type")
|
|
328
|
+
self.unknown_resource_runs += 1
|
|
329
|
+
return f"unknown:{self.unknown_resource_runs}", None
|
|
330
|
+
if SECRET_SHAPED.search(value) or CREDENTIAL_SHAPED.search(value):
|
|
331
|
+
self.diagnose("secret_shaped_token")
|
|
332
|
+
return None, None
|
|
333
|
+
if not RUN_ID.fullmatch(value):
|
|
334
|
+
self.diagnose("invalid_run_id")
|
|
335
|
+
try:
|
|
336
|
+
return "invalid:" + hash_ref(value), None
|
|
337
|
+
except UnicodeEncodeError:
|
|
338
|
+
return None, None
|
|
339
|
+
return "valid:" + value, value
|
|
340
|
+
|
|
341
|
+
def add_event_signal(self, signal_kind, row, normalized_state=None):
|
|
342
|
+
raw_run_id = row.get("run_id")
|
|
343
|
+
if isinstance(raw_run_id, str) and (
|
|
344
|
+
SECRET_SHAPED.search(raw_run_id) or CREDENTIAL_SHAPED.search(raw_run_id)
|
|
345
|
+
):
|
|
346
|
+
self.diagnose("secret_shaped_token")
|
|
347
|
+
return
|
|
348
|
+
signature = self.common_signature(row, signal_kind)
|
|
349
|
+
if signature is None:
|
|
350
|
+
return
|
|
351
|
+
|
|
352
|
+
if signal_kind == "error":
|
|
353
|
+
scope_ref = self.scope_ref(row, "node", "task")
|
|
354
|
+
phase = self.identifier(row, "phase")
|
|
355
|
+
error_type = self.identifier(row, "error_type")
|
|
356
|
+
if None in (scope_ref, phase, error_type):
|
|
357
|
+
return
|
|
358
|
+
signature.update(
|
|
359
|
+
{"scope_ref": scope_ref, "phase": phase, "error_type": error_type}
|
|
360
|
+
)
|
|
361
|
+
elif signal_kind == "high_risk_error":
|
|
362
|
+
scope_ref = self.scope_ref(row, "node", "task")
|
|
363
|
+
phase = self.identifier(row, "phase")
|
|
364
|
+
outcome = self.identifier(row, "outcome")
|
|
365
|
+
error_type = self.identifier(row, "error_type")
|
|
366
|
+
impact = self.identifier(row, "impact")
|
|
367
|
+
if None in (scope_ref, phase, outcome, error_type, impact):
|
|
368
|
+
return
|
|
369
|
+
signature.update(
|
|
370
|
+
{
|
|
371
|
+
"scope_ref": scope_ref,
|
|
372
|
+
"phase": phase,
|
|
373
|
+
"outcome": outcome,
|
|
374
|
+
"error_type": error_type,
|
|
375
|
+
"impact": impact,
|
|
376
|
+
}
|
|
377
|
+
)
|
|
378
|
+
elif signal_kind == "degrade":
|
|
379
|
+
phase = self.identifier(row, "phase")
|
|
380
|
+
error_type = self.identifier(row, "error_type")
|
|
381
|
+
if None in (phase, error_type):
|
|
382
|
+
return
|
|
383
|
+
signature.update({"phase": phase, "error_type": error_type})
|
|
384
|
+
elif signal_kind == "unrecovered_warning":
|
|
385
|
+
scope_ref = self.scope_ref(row, "node", "task")
|
|
386
|
+
phase = self.identifier(row, "phase")
|
|
387
|
+
error_type = self.identifier(row, "error_type")
|
|
388
|
+
if None in (scope_ref, phase, error_type):
|
|
389
|
+
return
|
|
390
|
+
signature.update(
|
|
391
|
+
{"scope_ref": scope_ref, "phase": phase, "error_type": error_type}
|
|
392
|
+
)
|
|
393
|
+
elif signal_kind == "review_retry":
|
|
394
|
+
scope_ref = self.scope_ref(row, "task", "node")
|
|
395
|
+
if scope_ref is None:
|
|
396
|
+
return
|
|
397
|
+
signature.update(
|
|
398
|
+
{"scope_ref": scope_ref, "review_state": normalized_state}
|
|
399
|
+
)
|
|
400
|
+
elif signal_kind == "qa_blocked":
|
|
401
|
+
case_id = self.identifier(row, "case_id", ENTITY_ID)
|
|
402
|
+
if case_id is None:
|
|
403
|
+
return
|
|
404
|
+
signature.update(
|
|
405
|
+
{"case_ref": hash_ref(case_id), "qa_state": normalized_state}
|
|
406
|
+
)
|
|
407
|
+
run_id = self.valid_run_id(row)
|
|
408
|
+
self.aggregate(signature, run_id, signal_kind == "high_risk_error")
|
|
409
|
+
|
|
410
|
+
def collect_resource(self, row):
|
|
411
|
+
phase = row.get("phase")
|
|
412
|
+
if not isinstance(phase, str):
|
|
413
|
+
self.diagnose("invalid_field_type")
|
|
414
|
+
return
|
|
415
|
+
if phase not in RESOURCE_PHASES:
|
|
416
|
+
return
|
|
417
|
+
run_key, run_id = self.resource_run_identity(row)
|
|
418
|
+
resource_id = self.identifier(row, "resource_id", ENTITY_ID)
|
|
419
|
+
resource_kind = self.identifier(row, "resource_kind")
|
|
420
|
+
if None in (run_key, resource_id, resource_kind):
|
|
421
|
+
return
|
|
422
|
+
key = (run_key, resource_id, resource_kind)
|
|
423
|
+
at_value = row.get("at")
|
|
424
|
+
if not isinstance(at_value, str) or SECRET_SHAPED.search(at_value) or CREDENTIAL_SHAPED.search(at_value):
|
|
425
|
+
self.diagnose(
|
|
426
|
+
"invalid_field_type" if not isinstance(at_value, str) else "secret_shaped_token"
|
|
427
|
+
)
|
|
428
|
+
self.diagnose("ambiguous_resource_terminal")
|
|
429
|
+
self.invalid_resource_groups.add(key)
|
|
430
|
+
return
|
|
431
|
+
try:
|
|
432
|
+
parsed_at = datetime.fromisoformat(at_value.replace("Z", "+00:00"))
|
|
433
|
+
if parsed_at.tzinfo is None:
|
|
434
|
+
raise ValueError
|
|
435
|
+
except (ValueError, OverflowError):
|
|
436
|
+
self.diagnose("ambiguous_resource_terminal")
|
|
437
|
+
self.invalid_resource_groups.add(key)
|
|
438
|
+
return
|
|
439
|
+
common = self.common_signature(row, "resource_cleanup_failed")
|
|
440
|
+
self.resource_events[key].append((parsed_at, phase, common, run_id))
|
|
441
|
+
|
|
442
|
+
def finish_resources(self):
|
|
443
|
+
for key in sorted(self.resource_events):
|
|
444
|
+
if key in self.invalid_resource_groups:
|
|
445
|
+
continue
|
|
446
|
+
rows = self.resource_events[key]
|
|
447
|
+
by_time = defaultdict(set)
|
|
448
|
+
for at_value, phase, _, _ in rows:
|
|
449
|
+
by_time[at_value].add(phase)
|
|
450
|
+
if any(len(states) > 1 for states in by_time.values()):
|
|
451
|
+
self.diagnose("ambiguous_resource_terminal")
|
|
452
|
+
continue
|
|
453
|
+
final_at = max(by_time)
|
|
454
|
+
final_phase = next(iter(by_time[final_at]))
|
|
455
|
+
if final_phase != "cleanup_failed":
|
|
456
|
+
continue
|
|
457
|
+
_, _, resource_kind = key
|
|
458
|
+
final_common = [
|
|
459
|
+
common
|
|
460
|
+
for at_value, _, common, _ in rows
|
|
461
|
+
if at_value == final_at and common is not None
|
|
462
|
+
]
|
|
463
|
+
if not final_common:
|
|
464
|
+
continue
|
|
465
|
+
common = min(final_common, key=lambda value: value["workflow"])
|
|
466
|
+
run_id = next(
|
|
467
|
+
(
|
|
468
|
+
candidate
|
|
469
|
+
for at_value, _, _, candidate in rows
|
|
470
|
+
if at_value == final_at and candidate is not None
|
|
471
|
+
),
|
|
472
|
+
None,
|
|
473
|
+
)
|
|
474
|
+
signature = dict(common)
|
|
475
|
+
signature.update(
|
|
476
|
+
{
|
|
477
|
+
"resource_kind": resource_kind,
|
|
478
|
+
"resource_state": "cleanup_failed_unreleased",
|
|
479
|
+
}
|
|
480
|
+
)
|
|
481
|
+
self.summary["signal_events"] += 1
|
|
482
|
+
self.aggregate(signature, run_id, True)
|
|
483
|
+
|
|
484
|
+
def aggregate(self, signature, run_id, high_risk):
|
|
485
|
+
canonical = json.dumps(
|
|
486
|
+
signature, ensure_ascii=True, separators=(",", ":"), sort_keys=False
|
|
487
|
+
).encode("utf-8")
|
|
488
|
+
fingerprint = "sha256:" + hashlib.sha256(canonical).hexdigest()
|
|
489
|
+
if fingerprint not in self.aggregates:
|
|
490
|
+
if len(self.aggregates) >= MAX_FINGERPRINTS:
|
|
491
|
+
raise InputBoundaryError("too_many_fingerprints")
|
|
492
|
+
self.aggregates[fingerprint] = {
|
|
493
|
+
"signal_kind": signature["signal_kind"],
|
|
494
|
+
"signature": signature,
|
|
495
|
+
"occurrences": 0,
|
|
496
|
+
"run_ids": set(),
|
|
497
|
+
"high_risk": high_risk,
|
|
498
|
+
}
|
|
499
|
+
aggregate = self.aggregates[fingerprint]
|
|
500
|
+
aggregate["occurrences"] += 1
|
|
501
|
+
if run_id is not None:
|
|
502
|
+
aggregate["run_ids"].add(run_id)
|
|
503
|
+
|
|
504
|
+
def output(self):
|
|
505
|
+
signals = []
|
|
506
|
+
for fingerprint in sorted(self.aggregates):
|
|
507
|
+
aggregate = self.aggregates[fingerprint]
|
|
508
|
+
run_ids = aggregate["run_ids"]
|
|
509
|
+
if aggregate["high_risk"]:
|
|
510
|
+
classification = "candidate"
|
|
511
|
+
reason = "high_risk_invariant"
|
|
512
|
+
elif len(run_ids) >= 2:
|
|
513
|
+
classification = "candidate"
|
|
514
|
+
reason = "repeated_across_runs"
|
|
515
|
+
else:
|
|
516
|
+
classification = "observe"
|
|
517
|
+
reason = "single_run"
|
|
518
|
+
run_refs = sorted(hash_ref(run_id) for run_id in run_ids)
|
|
519
|
+
signals.append(
|
|
520
|
+
{
|
|
521
|
+
"fingerprint": fingerprint,
|
|
522
|
+
"classification": classification,
|
|
523
|
+
"reason": reason,
|
|
524
|
+
"signal_kind": aggregate["signal_kind"],
|
|
525
|
+
"occurrences": aggregate["occurrences"],
|
|
526
|
+
"distinct_runs": len(run_ids),
|
|
527
|
+
"run_refs": run_refs[:MAX_RUN_REFS],
|
|
528
|
+
"run_refs_truncated": len(run_refs) > MAX_RUN_REFS,
|
|
529
|
+
"signature": aggregate["signature"],
|
|
530
|
+
}
|
|
531
|
+
)
|
|
532
|
+
if any(item["classification"] == "candidate" for item in signals):
|
|
533
|
+
status_value = "candidate"
|
|
534
|
+
elif signals or self.diagnostics:
|
|
535
|
+
status_value = "observe"
|
|
536
|
+
else:
|
|
537
|
+
status_value = "no_signal"
|
|
538
|
+
diagnostics = [
|
|
539
|
+
{"code": code, "count": self.diagnostics[code]}
|
|
540
|
+
for code in sorted(self.diagnostics)
|
|
541
|
+
]
|
|
542
|
+
return {
|
|
543
|
+
"schema_version": 1,
|
|
544
|
+
"status": status_value,
|
|
545
|
+
"summary": self.summary,
|
|
546
|
+
"signals": signals,
|
|
547
|
+
"diagnostics": diagnostics,
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
def run(arguments):
|
|
552
|
+
paths = parse_cli(arguments)
|
|
553
|
+
analyzer = Analyzer()
|
|
554
|
+
analyzer.read(paths)
|
|
555
|
+
payload = analyzer.output()
|
|
556
|
+
sys.stdout.write(json.dumps(payload, ensure_ascii=False, separators=(",", ":")))
|
|
557
|
+
sys.stdout.write("\n")
|
|
558
|
+
return 0
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def main():
|
|
562
|
+
try:
|
|
563
|
+
return run(sys.argv[1:])
|
|
564
|
+
except InputBoundaryError as error:
|
|
565
|
+
message = "cm-evolution-analyze:error=" + error.code
|
|
566
|
+
if error.input_index is not None:
|
|
567
|
+
message += " input=" + str(error.input_index)
|
|
568
|
+
sys.stderr.write(message + "\n")
|
|
569
|
+
return 2
|
|
570
|
+
except (MemoryError, RecursionError):
|
|
571
|
+
sys.stderr.write("cm-evolution-analyze:error=resource_limit\n")
|
|
572
|
+
return 2
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
if __name__ == "__main__":
|
|
576
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Release-only smoke for the BYZ-managed package and Codex plugin surfaces.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
6
|
+
SOURCE_CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
|
|
7
|
+
SOURCE_CREATOR="$SOURCE_CODEX_HOME/skills/.system/plugin-creator"
|
|
8
|
+
TMP_ROOT=""
|
|
9
|
+
PYTHON_BIN=""
|
|
10
|
+
|
|
11
|
+
blocked() {
|
|
12
|
+
echo "cm release surface smoke: BLOCKED ($1)" >&2
|
|
13
|
+
exit 2
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fail() {
|
|
17
|
+
echo "cm release surface smoke: FAILED ($1)" >&2
|
|
18
|
+
exit 1
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
cleanup() {
|
|
22
|
+
status=$?
|
|
23
|
+
trap - EXIT HUP INT TERM
|
|
24
|
+
if [ -n "$TMP_ROOT" ] && [ -d "$TMP_ROOT" ]; then
|
|
25
|
+
rm -rf "$TMP_ROOT"
|
|
26
|
+
fi
|
|
27
|
+
exit "$status"
|
|
28
|
+
}
|
|
29
|
+
trap cleanup EXIT
|
|
30
|
+
trap 'exit 129' HUP
|
|
31
|
+
trap 'exit 130' INT
|
|
32
|
+
trap 'exit 143' TERM
|
|
33
|
+
|
|
34
|
+
command -v byz >/dev/null 2>&1 || blocked "byz command not found"
|
|
35
|
+
command -v codex >/dev/null 2>&1 || blocked "codex command not found"
|
|
36
|
+
[ -d "$SOURCE_CREATOR" ] || blocked "Codex plugin creator not found at $SOURCE_CREATOR"
|
|
37
|
+
for candidate in python3 python; do
|
|
38
|
+
if command -v "$candidate" >/dev/null 2>&1 &&
|
|
39
|
+
"$candidate" -c 'import sys; raise SystemExit(sys.version_info < (3, 9))' >/dev/null 2>&1; then
|
|
40
|
+
PYTHON_BIN="$(command -v "$candidate")"
|
|
41
|
+
break
|
|
42
|
+
fi
|
|
43
|
+
done
|
|
44
|
+
[ -n "$PYTHON_BIN" ] || blocked "Python 3.9+ not found"
|
|
45
|
+
|
|
46
|
+
printf '%s\n' '==> Validating the public Pi/BYZ package manifest'
|
|
47
|
+
"$PYTHON_BIN" "$ROOT/scripts/validate-public-repo.py"
|
|
48
|
+
|
|
49
|
+
printf '%s\n' '==> Checking the local workflow root through BYZ'
|
|
50
|
+
BYZ_CM_WORKFLOW_ROOT="$ROOT" byz workflow check cm
|
|
51
|
+
|
|
52
|
+
TMP_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/cm-release-smoke.XXXXXX")"
|
|
53
|
+
TEMP_HOME="$TMP_ROOT/home"
|
|
54
|
+
TEMP_CODEX_HOME="$TEMP_HOME/.codex"
|
|
55
|
+
mkdir -p "$TEMP_CODEX_HOME/skills/.system"
|
|
56
|
+
cp -R "$SOURCE_CREATOR" "$TEMP_CODEX_HOME/skills/.system/plugin-creator"
|
|
57
|
+
|
|
58
|
+
printf '%s\n' '==> Installing the Codex plugin in a disposable home'
|
|
59
|
+
HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" \
|
|
60
|
+
"$ROOT/install-codex.sh" --yes
|
|
61
|
+
|
|
62
|
+
PLUGIN_LIST="$(HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" codex plugin list)"
|
|
63
|
+
printf '%s\n' "$PLUGIN_LIST"
|
|
64
|
+
printf '%s\n' "$PLUGIN_LIST" |
|
|
65
|
+
grep -Eq '^cm-workflow@personal[[:space:]]+installed, enabled' ||
|
|
66
|
+
fail "Codex did not report cm-workflow@personal as installed and enabled"
|
|
67
|
+
|
|
68
|
+
HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" \
|
|
69
|
+
"$TEMP_HOME/plugins/cm-workflow/scripts/cm-check-runtime.sh" \
|
|
70
|
+
--project "$TEMP_HOME/plugins/cm-workflow"
|
|
71
|
+
|
|
72
|
+
VERSION="$(tr -d '[:space:]' < "$ROOT/VERSION")"
|
|
73
|
+
echo "cm release surface smoke: PASSED (v${VERSION})"
|
|
@@ -11,10 +11,10 @@ from pathlib import Path
|
|
|
11
11
|
|
|
12
12
|
ROOT = Path(__file__).resolve().parent.parent
|
|
13
13
|
SELF = Path(__file__).resolve()
|
|
14
|
-
SKIP_DIRS = {".git"
|
|
14
|
+
SKIP_DIRS = {".git"}
|
|
15
15
|
SKIP_SUFFIXES = {".png", ".gif", ".jpg", ".jpeg", ".mp4", ".woff", ".woff2"}
|
|
16
16
|
PATTERNS = {
|
|
17
|
-
"private key": re.compile(r"-----BEGIN (?:RSA|EC|OPENSSH|DSA|PGP) PRIVATE KEY-----"),
|
|
17
|
+
"private key": re.compile(r"-----BEGIN (?:(?:RSA|EC|OPENSSH|DSA|PGP|ENCRYPTED) )?PRIVATE KEY-----"),
|
|
18
18
|
"AWS access key": re.compile(r"\bAKIA[0-9A-Z]{16}\b"),
|
|
19
19
|
"GitHub token": re.compile(r"\b(?:gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,})\b"),
|
|
20
20
|
"OpenAI-style key": re.compile(r"\bsk-[A-Za-z0-9_-]{20,}\b"),
|
|
@@ -66,7 +66,7 @@ def reviewed_loopback(relative: Path, text: str, offset: int) -> bool:
|
|
|
66
66
|
def main() -> int:
|
|
67
67
|
findings: list[str] = []
|
|
68
68
|
tracked_result = subprocess.run(
|
|
69
|
-
["git", "ls-files", "-z"
|
|
69
|
+
["git", "ls-files", "-z"],
|
|
70
70
|
cwd=ROOT,
|
|
71
71
|
stdout=subprocess.PIPE,
|
|
72
72
|
stderr=subprocess.DEVNULL,
|
|
@@ -81,9 +81,9 @@ def main() -> int:
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
for path in sorted(ROOT.rglob("*")):
|
|
84
|
-
if path == SELF or not path.is_file() or any(part in SKIP_DIRS for part in path.parts):
|
|
85
|
-
continue
|
|
86
84
|
relative = path.relative_to(ROOT)
|
|
85
|
+
if path == SELF or not path.is_file() or any(part in SKIP_DIRS for part in relative.parts):
|
|
86
|
+
continue
|
|
87
87
|
# OMX execution state is machine-local and normally ignored. Skip only
|
|
88
88
|
# untracked state; an accidentally tracked `.omx` file remains public
|
|
89
89
|
# package content and must still be scanned. If Git lookup fails, scan
|