Skip to content

WIP: api: Session::call_function_with_env — env channel on the contract surface (Refs #2001) - #2357

Merged
caomengxuan666 merged 6 commits into
masterfrom
fix/2001-callfn-env
Oct 31, 2026
Merged

caomengxuan666 merged 6 commits into
masterfrom
fix/2001-callfn-env

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2001 (contract batch, post-release; lands if clean, gates nothing).

What

Adds Session::call_function_with_env — the twin of Session::call_function carrying Executor::call_function_with_env's exact generic shape and bind-and-rollback semantics — so a host injecting per-call variables (niubash's compdef NIU_COMP_WORDS/NIU_COMP_CWORD, two call sites in niubash-runtime shell.rs) no longer has to drop to the Tier-C seam Session::executor(). This is the issue's option A (contract gains the env form); §8 of the design doc promised this pair under one mapping row.

  • src/api/session.rs: the method (pure delegation; error mapped through the same SessionError::from_execute_error as call_function). Each channel name is saved (unset is a distinct saved state), bound for the call, restored in reverse; the function's other side effects persist. No shell semantics changed — the behavior is the executor's existing one, re-homed.
  • src/api/mod.rs: surface listing names the pair.
  • tests/session_api.rs: six issue2001_* tests through rubash::api only — bind/rollback incl. mid-call reassignment, previously-unset rollback to unset, set-but-empty vs unmentioned, nested-call composition, the compdef round-trip shape, missing-function applies nothing.
  • docs/design/1.5.0-session-api.md: §13 post-final successor note (frozen text untouched) recording the §8 inaccuracy and this resolution.
  • docs/api-ledger.md: §6 symbol line + §2.2 mapping-row correction.

Verification (finisher, on the merged tree)

  • cargo check --test session_api — clean, both pre-merge (base d758fd0) and post-merge with current master 711ad72 (merge was conflict-free; PR diff vs master = exactly the 5 intended files, +223/−2).
  • python3 scripts/check-api-ledger.py — all 188 ledger symbols present, rc 0.
  • Full test execution is the collector's gate, per compile rationing.

⚠️ Pairing required (collector)

docs/api-ledger.md must stay byte-identical across rubash/niubash. This PR edits only the rubash copy; the identical ledger change needs the niubash-side backfill PR, or this PR's canary (ledger-matches job) will red on the mismatch. Until niubash consumes the new method, the checker's completeness half reports it recorded-but-not-consumed (warning class). Follow-up after this lands: migrate niu's two seam call sites (run_compdef_function/run_widget_function) to Session::call_function_with_env.

…in was wrong)

The pin asserted resolved_value(SEEN_ABSENT) == None, but the probe
assigns SEEN_ABSENT=${CH_ABSENT+set}: with CH_ABSENT unbound the
expansion is empty and the assignment binds the marker set-but-empty
(GNU 5.3.20: M=${A+set} with A unset gives declare -- M="" and -v
true). resolved_value documents None only when the read is unset, so
the marker reads Some(""). The channel contract point of the test
(SEEN_EMPTY == "set": a "" channel value is set-but-empty during the
call, and CH_EMPTY is unbound again after rollback) is unchanged and
was already passing. Test-only; no product change.

Refs #2001
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 16:54
@caomengxuan666
caomengxuan666 merged commit 5727567 into master Oct 31, 2026
10 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2001-callfn-env branch November 2, 2026 01:08
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