Skip to content

fix(console,eval): truthful console totals/hint; eval text prints object values - #402

Merged
ractive merged 4 commits into
mainfrom
fix/console-totals-eval-grip
Nov 27, 2026
Merged

ractive merged 4 commits into
mainfrom
fix/console-totals-eval-grip

Conversation

@ractive

@ractive ractive commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Fixes two kb/backlog.md lines (both ticked in this PR).

Cause

  • console: --help documented both summary.total and the top-level total as N, but the top-level total is the --level/--pattern match count. The empty-result hint fired whenever total == 0, however many messages had been captured, so 0-of-3 matched said "No console messages captured".
  • eval: with --format text, an object result printed as its raw grip (actor id, preview, propertyNames), followed by the generic -> ff-rdp console --level error tip. A default JSON object result gave no pointer to --stringify.

Fix

console

  • console.rs: empty_result_hint(raw_total, level, pattern) says "N console message(s) captured, none matched --level X --pattern '…'. Run without the filter to see them."
    • The pattern is always POSIX single-quoted (' becomes '\''). --level is quoted unless it is a non-empty alphanumeric word, so --level '' stays visible.
    • When nothing was captured at all, the old "No console messages captured" hint is kept.
  • args.rs, console Output: line only: the shape now reads summary.total: ALL, total: M, with a legend for ALL, M and Z. JSON field names are unchanged.

eval

  • --format text (without --jq) does not change what runs: the script goes out exactly as in JSON mode.
  • An Object or Array grip is read through prototypeAndProperties and printed as pretty JSON of its own enumerable properties, in Firefox's order. This is not JSON.stringify, and neither the help nor the code claims it is.
    • Non-JSON values print as "[Kind]" placeholders: "[Function]", "[Date]", "[HTMLBodyElement]", "[BigInt 10]", "[Symbol k]". Grip or actor metadata never reaches the output.
    • An accessor property, at an object key or an array index, prints as "[Getter]".
    • undefined drops out of objects; NaN and ±Infinity print as null.
    • Arrays are padded with null up to length.
  • Caps: 6 levels deep, 200 object reads and 100 000 array items. A value cut at a cap ends in "[Object]", "[Array]" or "[truncated]", and stderr gets a warning that names the caps and suggests --stringify.
  • Any other top-level result (a DOM node, a BigInt, window) prints as before.
  • No generic hint line is printed in text mode.
  • The JSON hint naming --stringify appears only on an Object/Array grip result. It is never added under --stringify, --no-hints, --jq (so existing --jq filters see the same envelope as before) or --format text.
  • args.rs, eval: one sentence after Output:, stating the caps and placeholders and pointing to --stringify for exact JSON.stringify output. I did not restructure any prose.

ff-rdp-core (outside my file set; the smallest change that works)

  • actors/object.rs: PrototypeAndProperties::own_properties is now a Vec<(String, PropertyDescriptor)> in Firefox's order, instead of a BTreeMap that sorted keys alphabetically.
  • inspect re-sorts into its own BTreeMap, so its output does not change.
  • eval's propertyNames now follows Firefox's order.

Proofs (headless Firefox 161.0, isolated FF_RDP_HOME, --port 6271, sandbox off; launched pid 73543, stopped by ff-rdp stop)

$ ff-rdp --allow-unsafe-urls navigate 'data:text/html,<!DOCTYPE html><title>E</title><p>x</p>'
$ ff-rdp console
  "results": [], "total": 0, "summary": {"total": 0, "matched": 0, "shown": 0, "by_level": {}},
  "hint": "No console messages captured. Use --follow to stream live messages, or generate some with: ff-rdp eval 'console.log(\"test\")'"
$ ff-rdp eval 'console.log("a"); console.warn("b"); console.error("c"); 1'
$ ff-rdp console --pattern nomatch
  "results": [], "total": 0, "summary": {"total": 3, "matched": 0, "shown": 0, "by_level": {}},
  "hint": "3 console messages captured, none matched --pattern 'nomatch'. Run without the filter to see them."
$ ff-rdp console --pattern "it's" --level '' --jq .hint
"3 console messages captured, none matched --level '' --pattern 'it'\\''s'. Run without the filter to see them."

$ ff-rdp eval '({a:[1,2]})'
  "results": {"type": "object", "class": "Object", "actor": "server1.conn8.child9/obj19", "preview": {...}, "propertyNames": ["a"]},
  "total": 1,
  "hint": "results is a Firefox object grip (actor metadata, not the value); re-run with --stringify to get the value as JSON"
$ ff-rdp --no-hints eval '({a:[1,2]})' --jq 'has("hint")'      -> false
$ ff-rdp eval '({a:[1,2]})' --jq 'has("hint")'                 -> false   (no hint under --jq)
$ ff-rdp eval 'document.body' --jq 'has("hint")'               -> false

$ ff-rdp eval --format text '({a:[1,2]})'
{
  "a": [
    1,
    2
  ]
}
$ ff-rdp eval --format text '({n: 10n, s: Symbol("k"), d: new Date(0), f(){}, h: new Array(2)})'
{ "n": "[BigInt 10]", "s": "[Symbol k]", "d": "[Date]", "f": "[Function]", "h": [null, null] }   (pretty-printed; condensed here)
$ ff-rdp eval --format text '({a:{a:{a:{a:{a:{a:{a:1}}}}}}})'
warning: --format text stopped reading the value at its caps (6 levels deep, 200 objects, 100000 array items); values past them print as "[Object]"/"[Array]"/"[truncated]" — use --stringify for the full value   (stderr)
{"a": {"a": {"a": {"a": {"a": {"a": "[Object]"}}}}}}   (pretty-printed; condensed here)
$ ff-rdp eval --format text '1+1'                               -> 2
$ ff-rdp eval --format text 'if (1) { 2 }'                      -> 2
$ ff-rdp eval --no-isolate --format text 'let k402 = 7; k402'   -> 7
$ ff-rdp eval --no-isolate --format text 'k402'                 -> 7
$ ff-rdp eval --format text 'document.body'
{ "type": "object", "class": "HTMLBodyElement", "actor": "...", "preview": {"kind": "DOMNode", "nodeName": "body", ...}, "propertyNames": [] }
$ ff-rdp eval --format text '10n'
type  BigInt
text  10
$ ff-rdp eval --format text 'window' --jq .results.class        -> "Window"
$ ff-rdp eval --format text --jq '.results.class' '({a:1})'      -> "Object"

Every command exited 0, and none of the text-mode runs printed a -> hint line.

Tests

  • Unit:
    • plain_value_reads_nested_objects_and_arrays_in_order: key order, non-enumerable keys, undefined, NaN, the DOM, BigInt and Symbol placeholders, getters at a key and at an index, padding to length.
    • plain_value_stops_at_the_depth_cap_on_a_cycle and plain_value_reports_an_exhausted_read_budget: both assert that truncated is set.
    • plain_array_caps_a_far_sparse_index_and_a_huge_length.
    • grip_hint_only_for_plain_containers_when_not_suppressed.
    • empty_result_hint_distinguishes_filtered_out_from_nothing_captured: also covers quoting and an empty --level.
    • parse_prototype_and_properties_keeps_firefox_order.
  • e2e:
    • eval_text_object_prints_json_value: replays the recorded nested fixtures and asserts that no --stringify wrap is sent.
    • eval_text_with_jq_keeps_the_grip, eval_object_no_hints_drops_grip_hint, eval_text_scalar_has_no_hint_line and eval_stringify_json_has_no_grip_hint.
    • eval_object_result now also checks the grip hint.
    • console_pattern_no_match_hint_names_the_filter and console_nothing_captured_hint.
  • Live: live_eval_text_values covers:
    • placeholders, padding and the depth-cap warning;
    • --no-isolate across two calls and if (1) { 2 };
    • document.body, 10n and window;
    • --format text --jq and --no-hints;
    • a DOM node getting no hint.
  • Fixtures: eval_{immediate,result}_object_nested.json and prototype_and_properties_{object,array,inner}_nested.json. They were recorded against Firefox 161 by the new live_eval_object_nested_properties recorder. The e2e test re-addresses the recorded evaluationResult's from to the console actor in get_target_response.json, the same replay adaptation the mock already applies to replies.
  • Gates: fmt, clippy -D warnings, skill_drift bless (no files changed) and cargo test --workspace -q are all green. The live eval and console modules pass with FF_RDP_LIVE_TESTS=1.

Trade-offs / not done

  • Top-level non-plain results in text mode are unchanged. window still prints its full grip, including a long propertyNames list.
  • Strings in text mode still print JSON-quoted, as they already did before this PR.
  • Symbol keys are not shown, because ownSymbols is not read.
  • new Array(200000) prints as ["[truncated]"] plus the warning; holes past the cap are not padded.
  • hints_eval is unchanged, so passing --hints explicitly in JSON mode still shows the console tip.
  • supply-chain is red on RUSTSEC-2026-0592 (url 2.5.8). It fails on main too and is fixed separately in fix(deps): bump url to 2.5.9 for RUSTSEC-2026-0592 #404; this branch will merge origin/main once fix(deps): bump url to 2.5.9 for RUSTSEC-2026-0592 #404 lands.

🤖 Generated with Claude Code

ractive and others added 2 commits November 27, 2026 00:25
console: `--help`'s Output shape now names `summary.total` as every captured
message and the top-level `total` as the --level/--pattern match count. A
read that matched none of N captured messages gets its own hint
("N console messages captured, none matched --pattern '…'") instead of the
false "No console messages captured", which stays for an empty cache.

eval: `--format text` evaluates the way --stringify does, so an object prints
as its JSON value instead of grip metadata, and no generic
`-> ff-rdp console --level error` hint line follows the value. A default
JSON result that is an object grip carries a top-level `hint` naming
--stringify. One sentence after eval's `Output:` line documents text mode.

Ticks both kb/backlog.md lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…stringify

Review of the first commit: forcing --stringify under --format text re-wrapped
the script (breaking --no-isolate scope sharing and statement completion
values like `if (1) { 2 }`) and turned DOM nodes, functions, BigInt and
`window` into `{}`, undefined or an error.

Now --format text (without --jq) sends the script exactly as JSON mode does.
A plain Object/Array grip is read through its object actors
(prototypeAndProperties, depth 6, at most 200 reads) and printed as pretty
JSON; any other result prints as before. The generic hint line stays off in
text mode. The object-grip `hint` is limited to Object/Array grips and
honours --no-hints. The console zero-match hint shell-quotes the pattern.

PrototypeAndProperties::own_properties is now a Vec in Firefox's order
(was a BTreeMap, which sorted keys alphabetically), so text output keeps
JSON.stringify's key order; inspect re-sorts into its own map and is
unchanged. New fixtures recorded from Firefox 161 by
live_eval_object_nested_properties; new live test live_eval_text_values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ractive ractive changed the title fix(console,eval): truthful console totals/hint; eval text prints values fix(console,eval): truthful console totals/hint; eval text prints object values Nov 26, 2026
ractive and others added 2 commits November 27, 2026 00:52
…adata

Second review of #402. --format text no longer claims JSON.stringify
semantics:
- a value cut at a cap (6 levels, 200 object reads, 100000 array items)
  prints a stderr warning naming the caps and --stringify;
- nested BigInt/Symbol print as "[BigInt 10]"/"[Symbol k]" instead of raw
  grip metadata; functions, Date and DOM nodes stay "[Kind]";
- arrays pad with null up to `length` (capped), an accessor index is
  "[Getter]";
- the object-grip hint is skipped under --format text (also on the read
  fallback) and --jq, so existing --jq filters see the old envelope;
- the console hint single-quotes an empty --level.
The eval help sentence now states the caps and the placeholders and points
to --stringify for exact JSON.stringify output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ractive
ractive merged commit 4f4b8f6 into main Nov 27, 2026
13 checks passed
@ractive
ractive deleted the fix/console-totals-eval-grip branch November 27, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant