alef_e2e/codegen/client/ws_script.rs
1//! Shared WebSocket-test driver.
2//!
3//! Drives a [`WebSocketScriptRenderer`] through the canonical sequence a scripted
4//! WebSocket fixture takes:
5//!
6//! 1. `render_test_open` — language-native test header.
7//! 2. `render_connect` — open WS connection (`let conn = client.connect_websocket(path)`).
8//! 3. For each scripted message:
9//! - `direction = send` → `render_send_text` / `render_send_json` / `render_send_binary`.
10//! - `direction = receive` → `render_expect_text` / `render_expect_json` / `render_expect_binary`.
11//! 4. `render_close` — close the connection with the expected close code.
12//! 5. `render_test_close` — closing brace / `end`.
13//!
14//! The fixture schema for WebSocket scripts lives in `fixtures/websocket*.json` —
15//! see the SSE/WS subset in `crate::fixture::HttpFixture` (currently the WS
16//! schema is loaded as raw JSON; a typed schema will be introduced in a follow-up
17//! once the language renderers are in place and we know exactly which fields
18//! they consume).
19
20use crate::fixture::Fixture;
21
22/// Per-language WebSocket script renderer.
23///
24/// Implementations live next to the per-language codegen module
25/// (`crates/alef-e2e/src/codegen/<lang>/ws.rs`).
26///
27/// This is currently a stub: the trait methods will be filled in alongside
28/// Phase 2B/2C of the e2e flip, when each language's WebSocket assertions are
29/// migrated to drive the binding's `TestClient.connect_websocket()` API.
30pub trait WebSocketScriptRenderer {
31 /// Identifier used in fixture skip directives (e.g. `"python"`).
32 fn language_name(&self) -> &'static str;
33}
34
35/// Render a WebSocket script test for `fixture` to `out` using `renderer`.
36///
37/// Currently returns `false` (no test emitted) because the WS schema and
38/// per-language renderers are not yet wired up; per-language codegen still
39/// uses its monolithic WebSocket renderer until Phase 2B lands. This function
40/// exists as the integration point so the per-language modules can begin
41/// migrating one at a time.
42pub fn render_ws_test<R: WebSocketScriptRenderer + ?Sized>(
43 _out: &mut String,
44 _renderer: &R,
45 _fixture: &Fixture,
46) -> bool {
47 false
48}
49
50#[cfg(test)]
51mod tests {
52 use super::{WebSocketScriptRenderer, render_ws_test};
53 use crate::fixture::Fixture;
54
55 struct StubRenderer;
56 impl WebSocketScriptRenderer for StubRenderer {
57 fn language_name(&self) -> &'static str {
58 "stub"
59 }
60 }
61
62 #[test]
63 fn stub_driver_emits_no_test() {
64 let fixture = Fixture {
65 id: "ws_stub".into(),
66 description: "stub".into(),
67 category: None,
68 tags: vec![],
69 skip: None,
70 call: None,
71 input: serde_json::Value::Null,
72 mock_response: None,
73 visitor: None,
74 assertions: vec![],
75 source: String::new(),
76 http: None,
77 };
78 let mut out = String::new();
79 let emitted = render_ws_test(&mut out, &StubRenderer, &fixture);
80 assert!(!emitted);
81 assert!(out.is_empty());
82 }
83}