Skip to content

feat(binding): expose createSession, selectSession and dropSession - #964

Open
owjs3901 wants to merge 8 commits into
mainfrom
feat/engine-session-bindings
Open

owjs3901 wants to merge 8 commits into
mainfrom
feat/engine-session-bindings

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked PR: this branch was branched from feat/engine-sessions (#963). #963 must be merged first; until then this PR's diff also shows #963's commits.

NXT-07 step 2: exposes the engine sessions built in #963 as public API of the WASM and native (NAPI) engines.

  • createSession(): creates a new session with a clean state and returns its id (u32).
  • selectSession(id): makes that session live. All later calls work on that session's state (numbering, sheets, theme, config, module resolver).
  • dropSession(id): drops the session and its module resolver, and returns whether it existed (boolean). Dropping the live session makes session 0 live. Session 0 cannot be dropped.
  • The shared argument boundary (bindings/argument-validation.cjs) checks the id as an unsigned 32-bit integer before it reaches the engine. A violation throws TypeError; a nonexistent session or an attempt to drop session 0 throws Error.
  • The ABI grew from 29 to 32 names. The following were updated to match:
    • The WASM glue check (script.js)
    • The native adapter and typings (index.d.cts, index.mjs)
    • The e2e ABI list and consumer
    • Validation positions (47 positions across 20 functions, 283 invalid-input cases)
    • The parity corpus scenario sessions-keep-apart-until-dropped
    • plugin-utils ABI/structure tests
    • Both READMEs (a ## Sessions section added to WASM)

Expected conflicts

Test plan

  • cargo test -p devup-ui-binding-core -p devup-ui-wasm -p devup-ui-binding --tests -j 2
  • clippy (-D warnings) and cargo check --target wasm32-unknown-unknown
  • WASM pkg build (the 32-export check in script.js passes) and native build (x86_64-pc-windows-msvc)
  • bun test: 52 pass in wasm-abi.test.ts, wasm-reset.test.ts, compiler-types.test.ts
  • Ran the e2e host on both WASM and native: the 451 lines of records.jsonl are byte-identical, and the session scenario is included.
  • e2e/binding/validation.mjs: 283 cases / 47 positions / 20 functions / 566 runs, failed 0, missing 0, crash 0

스택 PR: 이 브랜치는 feat/engine-sessions (#963) 위에서 분기했습니다. #963이 먼저 머지되어야 하며, 그 전까지 이 PR의 diff에는 #963의 커밋이 함께 보입니다.

요약

NXT-07 2단계: #963에서 만든 엔진 세션을 WASM과 네이티브(NAPI) 엔진의 공개 API로 노출합니다.

  • createSession(): 깨끗한 상태의 새 세션을 만들고 id(u32)를 돌려줍니다.
  • selectSession(id): 해당 세션을 live로 만듭니다. 이후 모든 호출은 그 세션의 상태(번호 매김, 시트, 테마, 설정, 모듈 resolver)에서 동작합니다.
  • dropSession(id): 세션과 그 모듈 resolver를 버리고, 존재했는지 여부(boolean)를 돌려줍니다. live 세션을 버리면 세션 0이 live가 됩니다. 세션 0은 버릴 수 없습니다.
  • 공유 인자 경계(bindings/argument-validation.cjs)가 엔진에 들어가기 전에 id를 unsigned 32-bit 정수로 검사합니다. 위반하면 TypeError, 없는 세션이거나 세션 0을 버리려 하면 Error를 던집니다.
  • ABI가 29개에서 32개 이름으로 늘어났습니다. 이에 맞춰 다음을 갱신했습니다.
    • WASM glue 검사(script.js)
    • 네이티브 adapter와 typings(index.d.cts, index.mjs)
    • e2e ABI 목록과 consumer
    • validation 위치(20개 함수의 47개 위치, 283개 invalid-input 케이스)
    • parity corpus 시나리오 sessions-keep-apart-until-dropped
    • plugin-utils의 ABI/구조 테스트
    • 두 README(WASM에는 ## Sessions 섹션 추가)

충돌 예상

테스트 계획

  • cargo test -p devup-ui-binding-core -p devup-ui-wasm -p devup-ui-binding --tests -j 2
  • clippy(-D warnings)와 cargo check --target wasm32-unknown-unknown
  • WASM pkg 빌드(script.js의 32개 export 검사 통과)와 네이티브 빌드(x86_64-pc-windows-msvc)
  • bun test: wasm-abi.test.ts, wasm-reset.test.ts, compiler-types.test.ts 52개 통과
  • e2e host를 WASM과 네이티브 양쪽에서 실행: records.jsonl 451줄이 바이트 단위로 동일하고, 세션 시나리오도 포함됩니다.
  • e2e/binding/validation.mjs: 283 cases / 47 positions / 20 functions / 566 runs, failed 0, missing 0, crash 0

Refs #686

🤖 Generated with Claude Code

owjs3901 and others added 4 commits November 15, 2026 19:43
…bals

Two apps in one process shared the single process-wide engine state.
Gather the persistent state into values that can be exchanged with the
live globals:

- css::engine_state::CssState holds the prefix, debug flag, atom hoist
  threshold and plan, slot reservation, class map, file map, canonical
  map, file routes, custom shorthands, theme tokens and Tailwind
  definitions. css::test_state::TestStateGuard is now built on it.
- extractor::ExtractorCaches holds the vanilla-extract imported runs and
  stripped TypeScript of the calling thread.
- devup_ui_binding_core::session keeps session 0 live from the start and
  parks every other session's EngineState (CSS state + stylesheet).
  select_session swaps a parked state with the live globals,
  with_session runs a closure under the session lock and swaps back,
  also on unwind. Extractor caches are parked per thread and aligned on
  every switch, since they hold Rc values and session file numbers.
- PerSession<T> keys host values by the live session; the WASM and
  native module resolvers use it.

Existing call sites read the globals unchanged; until a host creates a
session the engine behaves as before.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the engine session calls to the WASM and native engines:

- createSession() returns the id of a new session with a clean state
- selectSession(id) makes it live; every later call works on its state
- dropSession(id) drops it with its module resolver, returning whether
  it existed; dropping the live session makes session 0 live

The shared argument boundary checks the id as an unsigned 32-bit
integer before engine entry. The ABI grows from 29 to 32 names: the
WASM glue check, the native adapter and typings, the e2e ABI list, the
validation positions (47 in 20 functions, 283 invalid-input cases) and
a parity corpus scenario follow it.

Refs #686

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

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #686

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

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
bindings/devup-ui-binding/index.mjs 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/host.rs 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/lib.rs 100.00% <ø> (ø)
bindings/devup-ui-wasm/src/lib.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/reservation.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/state.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/state/tests.rs 100.00% <ø> (ø)
libs/binding/src/lib.rs 100.00% <100.00%> (ø)
libs/binding/src/session.rs 100.00% <100.00%> (ø)
libs/css/src/engine_state.rs 100.00% <100.00%> (ø)
... and 6 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

owjs3901 and others added 2 commits November 16, 2026 08:04
Keep main's check_resolved_path/resolved_module re-exports beside the
session re-exports in libs/binding. removeFile (#951) only touches the
file map, canonical map, class map and global sheet, which CssState and
EngineState already swap per session; a new session test pins that
forgetting a file in one session leaves another session's styles alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in main through #963, including removeFile (#951). The ABI now
holds 33 names: main's 30 plus createSession, selectSession and
dropSession. Updated script.js, the native typings and README, the
e2e ABI list and consumer, and compiler-types (32 without Output).

Validation covers 48 positions in 21 functions (288 cases), and the
summary reports 21 functions. The corpus keeps both new scenarios and
adds remove-file-stays-in-its-session, which checks that removeFile
only forgets the file in the live session (28 scenarios).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
extractor/lib.rs keeps both this branch's ExtractorCaches export and
main's vanilla_extract_theme_import_tests module. Main added no binding
exports since the last merge, so the counts stay: 33 ABI names, 21
validated functions with 48 positions and 288 cases, and 28 parity
scenarios. #967's serialization cache needs no session state: a session
switch swaps the sheet through a tracked mutable borrow, which forgets
the cached serializations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
extractor/lib.rs keeps both this branch's ExtractorCaches export and
main's vanilla_extract_theme_import_tests module, as #964 resolved it.
Main's new state needs no session handling: the stylesheet-export
COMPILING stack is empty between calls, and the CSS serialization cache
is dropped when a session swap borrows the sheet mutably.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
extractor/lib.rs keeps both the ExtractorCaches export and main's
vanilla_extract_theme_import_tests module, as #963 and #964 resolved it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Takes #964's merge with main (33cf39c) into the stack. Its tree adds
nothing beyond the main merge before this one, so no file changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Takes #965's merges with main and #964 into the stack. Its tree adds
nothing beyond the main merge before this one, so no file changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks up #983's snapshot fix so CI runs against the current main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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