sensorium-trace 0.18.2__py3-none-any.whl
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.
- sensorium/__init__.py +0 -0
- sensorium/__main__.py +4 -0
- sensorium/_c/rt/sensorium_c_rt.c +1446 -0
- sensorium/_typescript/package-lock.json +68 -0
- sensorium/_typescript/package.json +39 -0
- sensorium/_typescript/src/bindings.mjs +792 -0
- sensorium/_typescript/src/cap.mjs +227 -0
- sensorium/_typescript/src/capabilities.mjs +40 -0
- sensorium/_typescript/src/dbg.mjs +348 -0
- sensorium/_typescript/src/escape.mjs +351 -0
- sensorium/_typescript/src/focus.mjs +135 -0
- sensorium/_typescript/src/hook.mjs +127 -0
- sensorium/_typescript/src/index.mjs +1 -0
- sensorium/_typescript/src/naming.mjs +63 -0
- sensorium/_typescript/src/positions.mjs +37 -0
- sensorium/_typescript/src/probe.mjs +246 -0
- sensorium/_typescript/src/qualname.mjs +236 -0
- sensorium/_typescript/src/redact.mjs +711 -0
- sensorium/_typescript/src/register.mjs +15 -0
- sensorium/_typescript/src/resolve.mjs +260 -0
- sensorium/_typescript/src/rt.mjs +798 -0
- sensorium/_typescript/src/setup.mjs +11 -0
- sensorium/_typescript/src/tally.mjs +164 -0
- sensorium/_typescript/src/tasks.mjs +175 -0
- sensorium/_typescript/src/transform.mjs +800 -0
- sensorium/_typescript/src/vite.mjs +99 -0
- sensorium/c/__init__.py +8 -0
- sensorium/c/cc.py +612 -0
- sensorium/c/cli.py +60 -0
- sensorium/c/convert.py +669 -0
- sensorium/c/decode.py +300 -0
- sensorium/c/driver.py +365 -0
- sensorium/c/dwarf.py +706 -0
- sensorium/c/format.py +271 -0
- sensorium/c/pkg.py +187 -0
- sensorium/c/plan.py +277 -0
- sensorium/cli.py +140 -0
- sensorium/driver.py +47 -0
- sensorium/exit.py +33 -0
- sensorium/invocations.py +83 -0
- sensorium/limits.py +253 -0
- sensorium/mcp/__init__.py +0 -0
- sensorium/mcp/audit.py +162 -0
- sensorium/mcp/child.py +240 -0
- sensorium/mcp/cmd.py +101 -0
- sensorium/mcp/jsonrpc.py +172 -0
- sensorium/mcp/result.py +187 -0
- sensorium/mcp/schema.py +390 -0
- sensorium/mcp/server.py +493 -0
- sensorium/mcp/tools.py +299 -0
- sensorium/paths.py +80 -0
- sensorium/query/__init__.py +0 -0
- sensorium/query/caps.py +150 -0
- sensorium/query/dbg_dialects.py +64 -0
- sensorium/query/diff_cmd.py +748 -0
- sensorium/query/diff_notes.py +117 -0
- sensorium/query/exceptions_c.py +263 -0
- sensorium/query/exceptions_cmd.py +788 -0
- sensorium/query/exceptions_group.py +571 -0
- sensorium/query/exceptions_invocation.py +487 -0
- sensorium/query/exceptions_rust.py +683 -0
- sensorium/query/exceptions_typescript.py +688 -0
- sensorium/query/expr.py +606 -0
- sensorium/query/failures_cmd.py +306 -0
- sensorium/query/flow_cmd.py +778 -0
- sensorium/query/flow_report.py +128 -0
- sensorium/query/flow_values.py +195 -0
- sensorium/query/fmt.py +280 -0
- sensorium/query/frame_cmd.py +237 -0
- sensorium/query/grep_cmd.py +156 -0
- sensorium/query/help.py +18 -0
- sensorium/query/info_cmd.py +527 -0
- sensorium/query/info_rust.py +214 -0
- sensorium/query/info_typescript.py +261 -0
- sensorium/query/js_inspect.py +394 -0
- sensorium/query/moves.py +254 -0
- sensorium/query/redact_cmd.py +304 -0
- sensorium/query/refocus_cmd.py +661 -0
- sensorium/query/refocus_env.py +493 -0
- sensorium/query/refocus_facts.py +269 -0
- sensorium/query/refocus_licence.py +187 -0
- sensorium/query/refocus_report.py +327 -0
- sensorium/query/refocus_rust.py +537 -0
- sensorium/query/refocus_threads.py +197 -0
- sensorium/query/refocus_typescript.py +756 -0
- sensorium/query/refocus_world.py +666 -0
- sensorium/query/runs_cmd.py +213 -0
- sensorium/query/rust_debug.py +176 -0
- sensorium/query/sites.py +171 -0
- sensorium/query/tree_cmd.py +511 -0
- sensorium/query/tree_threads.py +168 -0
- sensorium/query/vocab.py +723 -0
- sensorium/query/watch_cmd.py +657 -0
- sensorium/record/__init__.py +0 -0
- sensorium/record/boot.py +797 -0
- sensorium/record/boot_io.py +141 -0
- sensorium/record/budget.py +135 -0
- sensorium/record/capture.py +433 -0
- sensorium/record/children.py +755 -0
- sensorium/record/children_merge.py +179 -0
- sensorium/record/elide.py +55 -0
- sensorium/record/fingerprint.py +26 -0
- sensorium/record/thread_starts.py +261 -0
- sensorium/record/tracer.py +798 -0
- sensorium/record/tracer_exc.py +199 -0
- sensorium/record/tracer_frames.py +618 -0
- sensorium/redact.py +304 -0
- sensorium/redact_content.py +156 -0
- sensorium/redact_key.py +317 -0
- sensorium/redact_store.py +502 -0
- sensorium/redact_values.py +433 -0
- sensorium/store/__init__.py +0 -0
- sensorium/store/db.py +284 -0
- sensorium/store/gc.py +360 -0
- sensorium/store/payloads.py +69 -0
- sensorium/store/reader.py +438 -0
- sensorium/store/writer.py +283 -0
- sensorium/ts/__init__.py +10 -0
- sensorium/ts/build.py +783 -0
- sensorium/ts/cli.py +130 -0
- sensorium/ts/driver.py +472 -0
- sensorium/ts/focus.py +146 -0
- sensorium/ts/harness.py +314 -0
- sensorium/ts/ingest.py +380 -0
- sensorium/ts/invocation.py +252 -0
- sensorium/ts/pkg.py +167 -0
- sensorium/ts/redaction.py +64 -0
- sensorium/ts/spool.py +168 -0
- sensorium/ts/truncation.py +81 -0
- sensorium/ts/wrapper.py +255 -0
- sensorium_trace-0.18.2.dist-info/METADATA +245 -0
- sensorium_trace-0.18.2.dist-info/RECORD +135 -0
- sensorium_trace-0.18.2.dist-info/WHEEL +4 -0
- sensorium_trace-0.18.2.dist-info/entry_points.txt +3 -0
- sensorium_trace-0.18.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"""Failed tests, and the frame each one failed in.
|
|
2
|
+
|
|
3
|
+
`exceptions` judges throw and Err flow. A vitest `expect` throws inside
|
|
4
|
+
the harness and writes no RAISE, and a Rust `assert!` is a panic, which
|
|
5
|
+
that command counts and does not list. Both are already on the trace:
|
|
6
|
+
the test's frame closed by unwind, and the panic's message is on that
|
|
7
|
+
unwind (and on a RAISE when the panic fired inside a frame). This
|
|
8
|
+
command reads that record. It does not invent a RAISE the recorder did
|
|
9
|
+
not write, and a test that caught its exception and returned is not a
|
|
10
|
+
failure.
|
|
11
|
+
"""
|
|
12
|
+
import shlex
|
|
13
|
+
|
|
14
|
+
from sensorium import paths
|
|
15
|
+
from sensorium.exit import ANSWERED, BAD_CALL
|
|
16
|
+
from sensorium.query.caps import none_status, print_incomplete
|
|
17
|
+
from sensorium.query.exceptions_rust import _marks
|
|
18
|
+
from sensorium.query.fmt import fmt_exc, more_note
|
|
19
|
+
from sensorium.query.help import LIMIT_HELP, RUN_HELP
|
|
20
|
+
from sensorium.store.reader import Trace
|
|
21
|
+
|
|
22
|
+
_INCOMPLETE = ("a failure recorded after the cut is not below, and its "
|
|
23
|
+
"absence here is not evidence it had none")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def add_parser(sub) -> None:
|
|
27
|
+
p = sub.add_parser(
|
|
28
|
+
"failures", help="failed tests and the frame they failed in",
|
|
29
|
+
description="Each failed test mapped to the frame and the "
|
|
30
|
+
"assertion, panic or exception recorded there. A "
|
|
31
|
+
"vitest expect, a Rust panic, and a C crash or "
|
|
32
|
+
"assert in a test_ frame are listed here; "
|
|
33
|
+
"exceptions still judges throw and Err flow and "
|
|
34
|
+
"does not list them.",
|
|
35
|
+
epilog="exit: 0 yes, 1 no, 2 fix the call, 3 change the recording")
|
|
36
|
+
p.add_argument("run", help=RUN_HELP)
|
|
37
|
+
p.add_argument("--limit", type=int, default=50, help=LIMIT_HELP)
|
|
38
|
+
p.set_defaults(func=run)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def run(args) -> int:
|
|
42
|
+
if args.limit < 1:
|
|
43
|
+
print(f"--limit must be >= 1 (got {args.limit}); "
|
|
44
|
+
"there is no useful zero-row page")
|
|
45
|
+
return BAD_CALL
|
|
46
|
+
trace = Trace.open(paths.find_trace(args.run))
|
|
47
|
+
lang = trace.lang
|
|
48
|
+
if lang == "rust":
|
|
49
|
+
rows, empty = _rust(trace)
|
|
50
|
+
elif lang == "typescript":
|
|
51
|
+
rows, empty = _typescript(trace)
|
|
52
|
+
elif lang == "c":
|
|
53
|
+
rows, empty = _c(trace)
|
|
54
|
+
else:
|
|
55
|
+
rows, empty = _python(trace)
|
|
56
|
+
print_incomplete(trace, _INCOMPLETE)
|
|
57
|
+
if not rows:
|
|
58
|
+
print(empty)
|
|
59
|
+
return none_status(trace)
|
|
60
|
+
_print(args, rows)
|
|
61
|
+
return ANSWERED
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _print(args, rows) -> None:
|
|
65
|
+
shown = rows[:args.limit]
|
|
66
|
+
print(f"failed ({len(rows)}):")
|
|
67
|
+
for row in shown:
|
|
68
|
+
print(f" {row[0]} {row[1]}")
|
|
69
|
+
at = f" at {row[2]}"
|
|
70
|
+
if row[3] is not None:
|
|
71
|
+
at += f" L{row[3]}"
|
|
72
|
+
print(at)
|
|
73
|
+
print(f" {row[4]}")
|
|
74
|
+
note = more_note(
|
|
75
|
+
len(rows), len(shown),
|
|
76
|
+
"sensorium failures "
|
|
77
|
+
+ shlex.quote(args.run)
|
|
78
|
+
+ f" --limit {len(rows)}")
|
|
79
|
+
if note:
|
|
80
|
+
print(note)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _same(a, b) -> bool:
|
|
84
|
+
"""One escaping exception. Serial when both rows have one; otherwise
|
|
85
|
+
the legacy (type, msg, oid) triple, which is all an older trace holds."""
|
|
86
|
+
if not a or not b:
|
|
87
|
+
return False
|
|
88
|
+
sa, sb = a.get("serial"), b.get("serial")
|
|
89
|
+
if sa is not None and sb is not None:
|
|
90
|
+
return sa == sb
|
|
91
|
+
return ((a.get("type"), a.get("msg"), a.get("oid"))
|
|
92
|
+
== (b.get("type"), b.get("msg"), b.get("oid")))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _text(exc, loc=None) -> str:
|
|
96
|
+
if not exc or "type" not in exc:
|
|
97
|
+
text = "?"
|
|
98
|
+
else:
|
|
99
|
+
text = fmt_exc(exc)
|
|
100
|
+
if loc:
|
|
101
|
+
text += f" at {loc}"
|
|
102
|
+
return text
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _place(trace, frame) -> str:
|
|
106
|
+
code = trace.code(frame.code_id)
|
|
107
|
+
return f"f{frame.id} {code.file}:{code.qualname}"
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _title(trace, frame) -> str:
|
|
111
|
+
return trace.code(frame.code_id).qualname.rsplit(".", 1)[-1]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _is_test_name(qualname: str) -> bool:
|
|
115
|
+
return qualname.rsplit(".", 1)[-1].startswith("test_")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _descendants(trace, root_id: int):
|
|
119
|
+
"""`root_id` and every frame under it, parents before children."""
|
|
120
|
+
out = []
|
|
121
|
+
stack = [root_id]
|
|
122
|
+
while stack:
|
|
123
|
+
fid = stack.pop()
|
|
124
|
+
frame = trace.frame(fid)
|
|
125
|
+
if frame is None:
|
|
126
|
+
continue
|
|
127
|
+
out.append(frame)
|
|
128
|
+
stack.extend(reversed([c.id for c in trace.children(fid)]))
|
|
129
|
+
return out
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _origin(trace, root, frames):
|
|
133
|
+
"""The deepest frame under `root` whose unwind is the exception that
|
|
134
|
+
escaped `root`, and the RAISE of that exception in that frame if the
|
|
135
|
+
recorder wrote one. No RAISE means the failure was born in untraced
|
|
136
|
+
code: the frame is still named, and the line is absent."""
|
|
137
|
+
unwind = root.unwind_exc or {}
|
|
138
|
+
raised = [f for f in frames
|
|
139
|
+
if trace.frame_state(f).state == "raised"
|
|
140
|
+
and _same(f.unwind_exc or {}, unwind)]
|
|
141
|
+
origin = max(raised, key=lambda f: (f.depth, f.id)) if raised else root
|
|
142
|
+
match = [e for e in trace.events(kind="RAISE", frame_id=origin.id)
|
|
143
|
+
if _same((e.payload or {}).get("exc") or {}, unwind)]
|
|
144
|
+
event = match[-1] if match else None
|
|
145
|
+
return origin, (event.line if event is not None else None)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _python(trace):
|
|
149
|
+
tests = [f for f in trace.frames()
|
|
150
|
+
if f.code_id is not None
|
|
151
|
+
and _is_test_name(trace.code(f.code_id).qualname)]
|
|
152
|
+
if not tests:
|
|
153
|
+
return [], "no test frames recorded"
|
|
154
|
+
rows = []
|
|
155
|
+
for test in tests:
|
|
156
|
+
if trace.frame_state(test).state != "raised":
|
|
157
|
+
continue
|
|
158
|
+
origin, line = _origin(trace, test, _descendants(trace, test.id))
|
|
159
|
+
rows.append((_title(trace, test), _place(trace, test),
|
|
160
|
+
_place(trace, origin), line,
|
|
161
|
+
_text(test.unwind_exc)))
|
|
162
|
+
if not rows:
|
|
163
|
+
return [], "no test failures recorded"
|
|
164
|
+
return rows, None
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _panic_loc(event, exc) -> str | None:
|
|
168
|
+
if event is not None:
|
|
169
|
+
payload = event.payload or {}
|
|
170
|
+
return payload.get("loc") or (payload.get("exc") or {}).get("loc")
|
|
171
|
+
return (exc or {}).get("loc")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _rust(trace):
|
|
175
|
+
sites = trace.meta.get("sites") or []
|
|
176
|
+
if not any(r.get("test") for r in sites if isinstance(r, dict)):
|
|
177
|
+
return [], "no test functions recorded"
|
|
178
|
+
marks = _marks(trace.meta)
|
|
179
|
+
# A test failed when ITS frame closed raised by a panic. A panic a
|
|
180
|
+
# test caught (the frame then returned) is not a failure. The RAISE,
|
|
181
|
+
# when one was written, supplies the line and the message.
|
|
182
|
+
failed = []
|
|
183
|
+
for frame in trace.frames():
|
|
184
|
+
if frame.code_id is None:
|
|
185
|
+
continue
|
|
186
|
+
code = trace.code(frame.code_id)
|
|
187
|
+
if marks.get((code.qualname, code.file)) != "test":
|
|
188
|
+
continue
|
|
189
|
+
exc = frame.unwind_exc or {}
|
|
190
|
+
if (trace.frame_state(frame).state != "raised"
|
|
191
|
+
or exc.get("kind") != "panic"):
|
|
192
|
+
continue
|
|
193
|
+
failed.append(frame)
|
|
194
|
+
if not failed:
|
|
195
|
+
return [], "no test failures recorded"
|
|
196
|
+
rows = []
|
|
197
|
+
for holder in failed:
|
|
198
|
+
best = None
|
|
199
|
+
for frame in _descendants(trace, holder.id):
|
|
200
|
+
for event in trace.events(kind="RAISE", frame_id=frame.id):
|
|
201
|
+
exc = (event.payload or {}).get("exc") or {}
|
|
202
|
+
if exc.get("kind") != "panic":
|
|
203
|
+
continue
|
|
204
|
+
rank = (frame.depth, event.id)
|
|
205
|
+
if best is None or rank > best[0]:
|
|
206
|
+
best = (rank, frame, event)
|
|
207
|
+
if best is None:
|
|
208
|
+
rows.append((
|
|
209
|
+
trace.code(holder.code_id).qualname,
|
|
210
|
+
_place(trace, holder), _place(trace, holder), None,
|
|
211
|
+
_text(holder.unwind_exc, _panic_loc(None, holder.unwind_exc)),
|
|
212
|
+
))
|
|
213
|
+
continue
|
|
214
|
+
_rank, origin, event = best
|
|
215
|
+
exc = (event.payload or {}).get("exc") or holder.unwind_exc or {}
|
|
216
|
+
rows.append((
|
|
217
|
+
trace.code(holder.code_id).qualname,
|
|
218
|
+
_place(trace, holder), _place(trace, origin), event.line,
|
|
219
|
+
_text(exc, _panic_loc(event, exc)),
|
|
220
|
+
))
|
|
221
|
+
return rows, None
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _call_task(trace, frame):
|
|
225
|
+
event = (trace.event(frame.call_event_id)
|
|
226
|
+
if frame.call_event_id is not None else None)
|
|
227
|
+
return event.task_id if event is not None else None
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _task_root(trace, frame, task_id) -> bool:
|
|
231
|
+
if _call_task(trace, frame) != task_id:
|
|
232
|
+
return False
|
|
233
|
+
if frame.parent_id is None:
|
|
234
|
+
return True
|
|
235
|
+
parent = trace.frame(frame.parent_id)
|
|
236
|
+
if parent is None:
|
|
237
|
+
return True
|
|
238
|
+
return _call_task(trace, parent) != task_id
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _typescript(trace):
|
|
242
|
+
tasks = trace.tasks()
|
|
243
|
+
if not tasks:
|
|
244
|
+
return [], "no tests recorded"
|
|
245
|
+
rows = []
|
|
246
|
+
for task in tasks:
|
|
247
|
+
roots = [f for f in trace.frames()
|
|
248
|
+
if _task_root(trace, f, task.id)
|
|
249
|
+
and trace.frame_state(f).state == "raised"]
|
|
250
|
+
for root in roots:
|
|
251
|
+
origin, line = _origin(trace, root, _descendants(trace, root.id))
|
|
252
|
+
name = task.name if task.name else "(unnamed)"
|
|
253
|
+
rows.append((name, f"task t{task.id}", _place(trace, origin),
|
|
254
|
+
line, _text(root.unwind_exc)))
|
|
255
|
+
if not rows:
|
|
256
|
+
return [], "no test failures recorded"
|
|
257
|
+
return rows, None
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _c_test_name(qualname: str) -> bool:
|
|
261
|
+
"""The qualname itself, not a dotted suffix: `test_foo` and `TestFoo`."""
|
|
262
|
+
return qualname.startswith("test_") or qualname.startswith("Test")
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _c(trace):
|
|
266
|
+
"""A C test fails when its frame closed raised by a signal or a
|
|
267
|
+
longjmp. The deepest RAISE of that unwind under the test supplies the
|
|
268
|
+
line; a longjmp, which writes no RAISE, names the test frame and no
|
|
269
|
+
line."""
|
|
270
|
+
tests = []
|
|
271
|
+
for frame in trace.frames():
|
|
272
|
+
if frame.code_id is None:
|
|
273
|
+
continue
|
|
274
|
+
name = trace.code(frame.code_id).qualname
|
|
275
|
+
if _c_test_name(name):
|
|
276
|
+
tests.append(frame)
|
|
277
|
+
if not tests:
|
|
278
|
+
return [], "no test functions recorded"
|
|
279
|
+
rows = []
|
|
280
|
+
for test in tests:
|
|
281
|
+
exc = test.unwind_exc or {}
|
|
282
|
+
if (trace.frame_state(test).state != "raised"
|
|
283
|
+
or exc.get("kind") not in ("signal", "longjmp")):
|
|
284
|
+
continue
|
|
285
|
+
best = None
|
|
286
|
+
want = (exc.get("kind"), exc.get("type"))
|
|
287
|
+
for frame in _descendants(trace, test.id):
|
|
288
|
+
for event in trace.events(kind="RAISE", frame_id=frame.id):
|
|
289
|
+
got = (event.payload or {}).get("exc") or {}
|
|
290
|
+
if (got.get("kind"), got.get("type")) != want:
|
|
291
|
+
continue
|
|
292
|
+
rank = (frame.depth, event.id)
|
|
293
|
+
if best is None or rank > best[0]:
|
|
294
|
+
best = (rank, frame, event)
|
|
295
|
+
title = trace.code(test.code_id).qualname
|
|
296
|
+
if best is None:
|
|
297
|
+
rows.append((title, _place(trace, test), _place(trace, test),
|
|
298
|
+
None, _text(exc)))
|
|
299
|
+
continue
|
|
300
|
+
_rank, origin, event = best
|
|
301
|
+
got = (event.payload or {}).get("exc") or exc
|
|
302
|
+
rows.append((title, _place(trace, test), _place(trace, origin),
|
|
303
|
+
event.line, _text(got)))
|
|
304
|
+
if not rows:
|
|
305
|
+
return [], "no test failures recorded"
|
|
306
|
+
return rows, None
|