Skip to content

WIP: 1.5.0 row 6 — §5.3 state views + WP-6 inspection rendering - #1883

Merged
caomengxuan666 merged 5 commits into
masterfrom
feat150/state-views
Oct 27, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
feat150/state-views

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

PLAN row 6 (S3 views part + WP-6) from the 1.5.0 program (designs: rubash#595 API / rubash#497 debugger, docs PR #1535).

What lands

  • §5.3 state views, in-tree (src/api/, pub(crate) until the workspace split moves the module wholesale — 150-c precedent; no split long-branch in this cluster, rationale in the cluster REPORT): live StateViews (variables / options / environment / cwd / positional / aliases / functions / last_status) + owned snapshots (VariableSnapshot / FrameSnapshot / DynamicStateSnapshot / InspectionSnapshot).
  • One rendering path: dynamic views (FUNCNAME / BASH_SOURCE / BASH_LINENO / PIPESTATUS / GROUPS …) and the declare -p printer are the single source for both the API and the debugger's inspection. The declare printer is widened (pub(crate)) plus a single-name entry declaration_line(); captures snapshot the printer's bytes at capture time, so a snapshot and declare -p cannot disagree.
  • WP-6 inspection rendering (src/debugger/inspect.rs): where / caller / partitioned variable listings / info-args / dynamic state, rendered purely from the snapshots. render_caller reproduces caller.def's arithmetic + the environment source presentation. The funnel consult captures the snapshot into the session before the stop loop runs (one minimal seam in debugger_serve_stop).
  • No shadow bookkeeping: captures read the engine's own stores/dynamic views; writes delegate to set_env, the array state stores, cd's execute_with_io + sync_cd_variables, and the unset builtin's leaf sequence.

Exit gate (in-tree, green)

src/api/consumer_tests.rs — a niu-sized consumer test in two acts:

  1. Host act: a session driven line-by-line touching state ONLY through the views; the shell observes every write (variables, sparse/assoc arrays with byte-matched declare -p, options, $?, positional, cwd, aliases, functions, unset, PIPESTATUS).
  2. Debugger act: stops at two breakpoints; the snapshot is checked item by item against the debuggee's own declare -p (12-name battery incl. locals, declared-unset, nameref, FUNCNAME, PIPESTATUS) and caller 0/1 output printed at the same stops.

Gates

  • lib: 789 passed / 1 failed / 1 ignored — failure set identical to the bb360a9 baseline (ownership_unary_operators_check_existing_file).
  • cargo check --lib with -D warnings: clean.
  • diffcorpus 306: 306 pass / 0 fail.
  • Debugger-off contract untouched (no gate/session → no capture runs).

Not in this PR

  • Variable dual-store → single-store: EVALUATION ONLY, in the cluster REPORT (census + options + migration cost), for the main session to rule. No construction.
  • Recorded divergences found along the way (bare declare -p listing omits declared-unset names vs GNU; $BASH_COMMAND at a funnel stop reads the last-begun command; BASH_ARGC/ARGV omit the bottom frame + sourced-file arg vs GNU) — evidence in the cluster REPORT; the views report engine state faithfully rather than papering over them.

Draft: do not merge — cluster delivery for main-session review.

DeclarationAttrs and the print_declaration/print_unset_declaration
printers go pub(crate), and print.rs gains declaration_line(): the
single-name entry to the same printer the declare builtin's loop
uses. The 1.5.0 state views (PLAN row 6) render variable snapshots
through here so an inspection snapshot and declare -p NAME can
never drift into two formatters. No behavior change: the builtin
keeps its own loop (it prebuilds the mark sets once per listing).
New in-tree api module (pub(crate) until the workspace split moves
it wholesale, 150-c precedent): live StateViews (variables /
options / environment / cwd / positional / aliases / functions /
last_status) plus owned snapshots for inspection. Every capture
reads the engine's own stores and dynamic views — dynamic
declaration view for dynamic parameters, the composed stack views
for FUNCNAME/BASH_SOURCE/BASH_LINENO, pipestatus_entries for
PIPESTATUS — and every write delegates to the machinery the shell
itself uses: set_env, the array state stores, cd's execute_with_io
+ sync_cd_variables, the unset builtin's leaf sequence. No shadow
bookkeeping anywhere.

Executor helpers live in executor/state_views.rs (capture_variable
resolves as the debuggee does: dynamics, then the visible binding
in the global stores — a live local's value sits there while its
scope maps hold the saved outer binding for restore — with the
declared-unset guard of the read path, rubash#409).

Exit gate in api/consumer_tests.rs: a niu-sized consumer act
drives a session through the views only, and a debugger act stops
a real debuggee and checks the snapshot item by item against the
debuggee's own declare -p / caller output at the same stop.
DebugSession gains an inspection slot; the funnel consult
(debugger_serve_stop) captures an InspectionSnapshot from the live
engine state and installs it before the stop loop runs — the one
minimal executor seam, so frontends render exactly the state the
debuggee stopped in. debugger/inspect.rs renders where / caller /
variables (partitioned) / info-args / dynamic state purely from
the §5.3 snapshots: render_caller reproduces caller.def's frame
arithmetic and the environment source presentation, and variable
listings join the snapshot's shared-printer declaration lines
instead of re-rendering anything.
Three CI-only reds on PR #1883, all in test shape, none in product:

- act1 compared the shell's pwd output byte-for-byte against the
  native canonical path. pwd prints the shell spelling (shell
  namespace + 8.3 short names on Windows, the logical path
  through the /private symlink on macOS); compare filesystem
  identity instead — canonicalize the printed spelling and
  require the same directory the view set.
- act2 interpolated the debuggee's native Windows path into
  shell source unquoted; a backslash in a bare word is an escape,
  so the separators were eaten and the source failed (status 1)
  before anything ran. Quote the path.
- gate::session_active_global_roundtrip was the only consumer
  of GATE_TEST_LOCK acquiring it with unwrap(): any GateTestSpan
  holder panicking mid-span (the known goldens wiring failures)
  poisons the mutex and this test exploded on the poison.
  Acquire poison-tolerantly like every GateTestSpan; the flag
  itself is restored by the span's Drop disarm.
The Rust tests job runs scripts/check-utf8-boundary-hygiene.sh,
which rejects every unreviewed byte->char widening (niubash#92
class). shell_spelling_to_native widened the drive byte with
`as char`; parse the spelling with chars() instead — the drive
letter is a real char by then, no widening and no byte slicing,
and the hygiene scan stays clean without an allowlist entry.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 27, 2026 18:51
@caomengxuan666
caomengxuan666 merged commit 03a7518 into master Oct 27, 2026
8 of 9 checks passed
SpookyWaste pushed a commit to SpookyWaste/rubash that referenced this pull request Oct 29, 2026
The 8 debugger::wiring_tests that have failed only in the
Windows goldens job since unixwin#1878 all drive the debuggee through
sourced_script(), which interpolated the temp script's native
path into the driver input unquoted: `. C:\Users\...`. In a
bare word the lexer treats `\` as an escape, every separator
was eaten, `.` never found the file, and each debuggee exited
status 1 having executed nothing (de01's status assertion at
wiring_tests.rs:142 — left 1, right 0).

Quote the path at the helper, the single interpolation point
all nine call sites share — the same harness shape the api
consumer tests were fixed with in unixwin#1883. No product code
changes; the debuggee scripts and their status semantics are
untouched.
@caomengxuan666
caomengxuan666 deleted the feat150/state-views branch October 30, 2026 01:41
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