Skip to main content

alef_core/config/
e2e.rs

1//! E2E test generation configuration types.
2
3use serde::{Deserialize, Serialize};
4use std::collections::{HashMap, HashSet};
5
6/// Controls whether generated e2e test projects reference the package under
7/// test via a local path (for development) or a registry version string
8/// (for standalone `test_apps` that consumers can run without the monorepo).
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
10#[serde(rename_all = "lowercase")]
11pub enum DependencyMode {
12    /// Local path dependency (default) — used during normal e2e development.
13    #[default]
14    Local,
15    /// Registry dependency — generates standalone test apps that pull the
16    /// package from its published registry (PyPI, npm, crates.io, etc.).
17    Registry,
18}
19
20/// Configuration for registry-mode e2e generation (`alef e2e generate --registry`).
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct RegistryConfig {
23    /// Output directory for registry-mode test apps (default: "test_apps").
24    #[serde(default = "default_test_apps_dir")]
25    pub output: String,
26    /// Per-language package overrides used only in registry mode.
27    /// Merged on top of the base `[e2e.packages]` entries.
28    #[serde(default)]
29    pub packages: HashMap<String, PackageRef>,
30    /// When non-empty, only fixture categories in this list are included in
31    /// registry-mode generation (useful for shipping a curated subset).
32    #[serde(default)]
33    pub categories: Vec<String>,
34    /// GitHub repository URL for downloading prebuilt artifacts (e.g., FFI
35    /// shared libraries) from GitHub Releases.
36    ///
37    /// Falls back to `[scaffold] repository` when not set, then to
38    /// `https://github.com/kreuzberg-dev/{crate.name}`.
39    #[serde(default)]
40    pub github_repo: Option<String>,
41}
42
43impl Default for RegistryConfig {
44    fn default() -> Self {
45        Self {
46            output: default_test_apps_dir(),
47            packages: HashMap::new(),
48            categories: Vec::new(),
49            github_repo: None,
50        }
51    }
52}
53
54fn default_test_apps_dir() -> String {
55    "test_apps".to_string()
56}
57
58/// Root e2e configuration from `[e2e]` section of alef.toml.
59#[derive(Debug, Clone, Serialize, Deserialize, Default)]
60pub struct E2eConfig {
61    /// Directory containing fixture JSON files (default: "fixtures").
62    #[serde(default = "default_fixtures_dir")]
63    pub fixtures: String,
64    /// Output directory for generated e2e test projects (default: "e2e").
65    #[serde(default = "default_output_dir")]
66    pub output: String,
67    /// Languages to generate e2e tests for. Defaults to top-level `languages` list.
68    #[serde(default)]
69    pub languages: Vec<String>,
70    /// Default function call configuration.
71    pub call: CallConfig,
72    /// Named additional call configurations for multi-function testing.
73    /// Fixtures reference these via the `call` field, e.g. `"call": "embed"`.
74    #[serde(default)]
75    pub calls: HashMap<String, CallConfig>,
76    /// Per-language package reference overrides.
77    #[serde(default)]
78    pub packages: HashMap<String, PackageRef>,
79    /// Per-language formatter commands.
80    #[serde(default)]
81    pub format: HashMap<String, String>,
82    /// Field path aliases: maps fixture field paths to actual API struct paths.
83    /// E.g., "metadata.title" -> "metadata.document.title"
84    /// Supports struct access (foo.bar), map access (foo[key]), direct fields.
85    #[serde(default)]
86    pub fields: HashMap<String, String>,
87    /// Fields that are Optional/nullable in the return type.
88    /// Rust generators use .as_deref().unwrap_or("") for strings, .is_some() for structs.
89    #[serde(default)]
90    pub fields_optional: HashSet<String>,
91    /// Fields that are arrays/Vecs on the result type.
92    /// When a fixture path like `json_ld.name` traverses an array field, the
93    /// accessor adds `[0]` (or language equivalent) to index into the first element.
94    #[serde(default)]
95    pub fields_array: HashSet<String>,
96    /// Fields where the accessor is a method call (appends `()`) rather than a field access.
97    /// Rust-specific: Java always uses `()`, Python/PHP use field access.
98    /// Listed as the full resolved field path (after alias resolution).
99    /// E.g., `"metadata.format.excel"` means `.excel` should be emitted as `.excel()`.
100    #[serde(default)]
101    pub fields_method_calls: HashSet<String>,
102    /// Known top-level fields on the result type.
103    ///
104    /// When non-empty, assertions whose resolved field path starts with a
105    /// segment that is NOT in this set are emitted as comments (skipped)
106    /// instead of executable assertions.  This prevents broken assertions
107    /// when fixtures reference fields from a different operation (e.g.,
108    /// `batch.completed_count` on a `ScrapeResult`).
109    #[serde(default)]
110    pub result_fields: HashSet<String>,
111    /// C FFI accessor type chain: maps `"{parent_snake_type}.{field}"` to the
112    /// PascalCase return type name (without prefix).
113    ///
114    /// Used by the C e2e generator to emit chained FFI accessor calls for
115    /// nested field paths. The root type is always `conversion_result`.
116    ///
117    /// Example:
118    /// ```toml
119    /// [e2e.fields_c_types]
120    /// "conversion_result.metadata" = "HtmlMetadata"
121    /// "html_metadata.document" = "DocumentMetadata"
122    /// ```
123    #[serde(default)]
124    pub fields_c_types: HashMap<String, String>,
125    /// Fields whose resolved type is an enum in the generated bindings.
126    ///
127    /// When a `contains` / `contains_all` / etc. assertion targets one of these
128    /// fields, language generators that cannot call `.contains()` directly on an
129    /// enum (e.g., Java) will emit a string-conversion call first.  For Java,
130    /// the generated assertion calls `.getValue()` on the enum — the `@JsonValue`
131    /// method that all alef-generated Java enums expose — to obtain the lowercase
132    /// serde string before performing the string comparison.
133    ///
134    /// Both the raw fixture field path (before alias resolution) and the resolved
135    /// path (after alias resolution via `[e2e.fields]`) are accepted, so you can
136    /// use either form:
137    ///
138    /// ```toml
139    /// # Raw fixture field:
140    /// fields_enum = ["links[].link_type", "assets[].category"]
141    /// # …or the resolved (aliased) field name:
142    /// fields_enum = ["links[].link_type", "assets[].asset_category"]
143    /// ```
144    #[serde(default)]
145    pub fields_enum: HashSet<String>,
146    /// Dependency mode: `Local` (default) or `Registry`.
147    /// Set at runtime via `--registry` CLI flag; not serialized from TOML.
148    #[serde(skip)]
149    pub dep_mode: DependencyMode,
150    /// Registry-mode configuration from `[e2e.registry]`.
151    #[serde(default)]
152    pub registry: RegistryConfig,
153}
154
155impl E2eConfig {
156    /// Resolve the call config for a fixture. Uses the named call if specified,
157    /// otherwise falls back to the default `[e2e.call]`.
158    pub fn resolve_call(&self, call_name: Option<&str>) -> &CallConfig {
159        match call_name {
160            Some(name) => self.calls.get(name).unwrap_or(&self.call),
161            None => &self.call,
162        }
163    }
164
165    /// Resolve the effective package reference for a language.
166    ///
167    /// In registry mode, entries from `[e2e.registry.packages]` are merged on
168    /// top of the base `[e2e.packages]` — registry overrides win for any field
169    /// that is `Some`.
170    pub fn resolve_package(&self, lang: &str) -> Option<PackageRef> {
171        let base = self.packages.get(lang);
172        if self.dep_mode == DependencyMode::Registry {
173            let reg = self.registry.packages.get(lang);
174            match (base, reg) {
175                (Some(b), Some(r)) => Some(PackageRef {
176                    name: r.name.clone().or_else(|| b.name.clone()),
177                    path: r.path.clone().or_else(|| b.path.clone()),
178                    module: r.module.clone().or_else(|| b.module.clone()),
179                    version: r.version.clone().or_else(|| b.version.clone()),
180                }),
181                (None, Some(r)) => Some(r.clone()),
182                (Some(b), None) => Some(b.clone()),
183                (None, None) => None,
184            }
185        } else {
186            base.cloned()
187        }
188    }
189
190    /// Return the effective output directory: `registry.output` in registry
191    /// mode, `output` otherwise.
192    pub fn effective_output(&self) -> &str {
193        if self.dep_mode == DependencyMode::Registry {
194            &self.registry.output
195        } else {
196            &self.output
197        }
198    }
199}
200
201fn default_fixtures_dir() -> String {
202    "fixtures".to_string()
203}
204
205fn default_output_dir() -> String {
206    "e2e".to_string()
207}
208
209/// Configuration for the function call in each test.
210#[derive(Debug, Clone, Serialize, Deserialize, Default)]
211pub struct CallConfig {
212    /// The function name (alef applies language naming conventions).
213    #[serde(default)]
214    pub function: String,
215    /// The module/package where the function lives.
216    #[serde(default)]
217    pub module: String,
218    /// Variable name for the return value (default: "result").
219    #[serde(default = "default_result_var")]
220    pub result_var: String,
221    /// Whether the function is async.
222    #[serde(default)]
223    pub r#async: bool,
224    /// HTTP endpoint path for mock server routing (e.g., `"/v1/chat/completions"`).
225    ///
226    /// Required when fixtures use `mock_response`. The Rust e2e generator uses
227    /// this to build the `MockRoute` that the mock server matches against.
228    #[serde(default)]
229    pub path: Option<String>,
230    /// HTTP method for mock server routing (default: `"POST"`).
231    ///
232    /// Used together with `path` when building `MockRoute` entries.
233    #[serde(default)]
234    pub method: Option<String>,
235    /// How fixture `input` fields map to function arguments.
236    #[serde(default)]
237    pub args: Vec<ArgMapping>,
238    /// Per-language overrides for module/function/etc.
239    #[serde(default)]
240    pub overrides: HashMap<String, CallOverride>,
241    /// Whether the function returns `Result<T, E>` in its native binding.
242    /// Defaults to `true`. When `false`, generators that distinguish Result-returning
243    /// from non-Result-returning calls (currently Rust) will skip the
244    /// `.expect("should succeed")` unwrap and bind the raw return value directly.
245    #[serde(default = "default_returns_result")]
246    pub returns_result: bool,
247    /// Whether the function returns only an error/unit — i.e., `Result<(), E>`.
248    ///
249    /// When combined with `returns_result = true`, Go generators emit `err := func()`
250    /// (single return value) rather than `_, err := func()` (two return values).
251    /// This is needed for functions like `validate_host` that return only `error` in Go.
252    #[serde(default)]
253    pub returns_void: bool,
254    /// skip_languages
255    #[serde(default)]
256    pub skip_languages: Vec<String>,
257    /// When `true`, the function returns a primitive (e.g. `String`, `bool`,
258    /// `i32`) rather than a struct.  Generators that would otherwise emit
259    /// `result.<field>` will fall back to the bare result variable.
260    ///
261    /// This is a property of the Rust core's return type and therefore identical
262    /// across every binding — set it on the call, not in per-language overrides.
263    /// The same flag is also accepted under `[e2e.calls.<name>.overrides.<lang>]`
264    /// for backwards compatibility, but the call-level value takes precedence.
265    #[serde(default)]
266    pub result_is_simple: bool,
267    /// When `true`, the function returns `Vec<T>` / `Array<T>`.  Generators that
268    /// support per-element field assertions (rust, csharp) iterate or index into
269    /// the result; the typescript codegen indexes `[0]` to mirror csharp.
270    ///
271    /// As with `result_is_simple`, this is a Rust-side property — set it on the
272    /// call, not on per-language overrides. Per-language overrides remain
273    /// supported for backwards compatibility.
274    #[serde(default)]
275    pub result_is_vec: bool,
276    /// When `true` (combined with `result_is_simple`), the simple return is a
277    /// slice/array (e.g., `Vec<String>` → `string[]` in TS).
278    #[serde(default)]
279    pub result_is_array: bool,
280    /// When `true`, the function returns a raw byte array (`Vec<u8>` →
281    /// `Uint8Array` / `[]byte` / `byte[]`).
282    #[serde(default)]
283    pub result_is_bytes: bool,
284    /// When `true`, the function returns `Option<T>`.
285    #[serde(default)]
286    pub result_is_option: bool,
287}
288
289fn default_result_var() -> String {
290    "result".to_string()
291}
292
293fn default_returns_result() -> bool {
294    false
295}
296
297/// Maps a fixture input field to a function argument.
298#[derive(Debug, Clone, Serialize, Deserialize)]
299pub struct ArgMapping {
300    /// Argument name in the function signature.
301    pub name: String,
302    /// JSON field path in the fixture's `input` object.
303    pub field: String,
304    /// Type hint for code generation.
305    #[serde(rename = "type", default = "default_arg_type")]
306    pub arg_type: String,
307    /// Whether this argument is optional.
308    #[serde(default)]
309    pub optional: bool,
310    /// When `true`, the Rust codegen passes this argument by value (owned) rather than
311    /// by reference. Use for `Vec<T>` parameters that do not accept `&Vec<T>`.
312    #[serde(default)]
313    pub owned: bool,
314    /// For `json_object` args targeting `&[T]` Rust parameters, set to the element type
315    /// (e.g. `"f32"`, `"String"`) so the codegen emits `Vec<element_type>` annotation.
316    #[serde(default)]
317    pub element_type: Option<String>,
318    /// Override the Go slice element type for `json_object` array args.
319    ///
320    /// When set, the Go e2e codegen uses this as the element type instead of the default
321    /// derived from `element_type`. Use Go-idiomatic type names including the import alias
322    /// prefix where needed, e.g. `"kreuzberg.BatchBytesItem"` or `"string"`.
323    #[serde(default)]
324    pub go_type: Option<String>,
325}
326
327fn default_arg_type() -> String {
328    "string".to_string()
329}
330
331/// Per-language override for function call configuration.
332#[derive(Debug, Clone, Serialize, Deserialize, Default)]
333pub struct CallOverride {
334    /// Override the module/import path.
335    #[serde(default)]
336    pub module: Option<String>,
337    /// Override the function name.
338    #[serde(default)]
339    pub function: Option<String>,
340    /// Maps canonical argument names to language-specific argument names.
341    ///
342    /// Used when a language binding uses a different parameter name than the
343    /// canonical `args` list in `CallConfig`. For example, if the canonical
344    /// arg name is `doc` but the Python binding uses `html`, specify:
345    ///
346    /// ```toml
347    /// [e2e.call.overrides.python]
348    /// arg_name_map = { doc = "html" }
349    /// ```
350    ///
351    /// The key is the canonical name (from `args[].name`) and the value is the
352    /// name to use when emitting the keyword argument in generated tests.
353    #[serde(default)]
354    pub arg_name_map: HashMap<String, String>,
355    /// Override the crate name (Rust only).
356    #[serde(default)]
357    pub crate_name: Option<String>,
358    /// Override the class name (Java/C# only).
359    #[serde(default)]
360    pub class: Option<String>,
361    /// Import alias (Go only, e.g., `htmd`).
362    #[serde(default)]
363    pub alias: Option<String>,
364    /// C header file name (C only).
365    #[serde(default)]
366    pub header: Option<String>,
367    /// FFI symbol prefix (C only).
368    #[serde(default)]
369    pub prefix: Option<String>,
370    /// For json_object args: the constructor to use instead of raw dict/object.
371    /// E.g., "ConversionOptions" — generates `ConversionOptions(**options)` in Python,
372    /// `new ConversionOptions(options)` in TypeScript.
373    #[serde(default)]
374    pub options_type: Option<String>,
375    /// How to pass json_object args: "kwargs" (default), "dict", "json", or "from_json".
376    ///
377    /// - `"kwargs"`: construct `OptionsType(key=val, ...)` (requires `options_type`).
378    /// - `"dict"`: pass as a plain dict/object literal `{"key": "val"}`.
379    /// - `"json"`: pass via `json.loads('...')` / `JSON.parse('...')`.
380    /// - `"from_json"`: call `OptionsType.from_json('...')` (Python only, PyO3 native types).
381    #[serde(default)]
382    pub options_via: Option<String>,
383    /// Module to import `options_type` from when `options_via = "from_json"`.
384    ///
385    /// When set, a separate `from {from_json_module} import {options_type}` line
386    /// is emitted instead of including the type in the main module import.
387    /// E.g., `"liter_llm._internal_bindings"` for PyO3 native types.
388    #[serde(default)]
389    pub from_json_module: Option<String>,
390    /// Override whether the call is async for this language.
391    ///
392    /// When set, takes precedence over the call-level `async` flag.
393    /// Useful when a language binding uses a different async model — for example,
394    /// a Python binding that returns a sync iterator from a function marked
395    /// `async = true` at the call level.
396    #[serde(default, rename = "async")]
397    pub r#async: Option<bool>,
398    /// Maps fixture option field names to their enum type names.
399    /// E.g., `{"headingStyle": "HeadingStyle", "codeBlockStyle": "CodeBlockStyle"}`.
400    /// The generator imports these types and maps string values to enum constants.
401    #[serde(default)]
402    pub enum_fields: HashMap<String, String>,
403    /// Module to import enum types from (if different from the main module).
404    /// E.g., "html_to_markdown._html_to_markdown" for PyO3 native enums.
405    #[serde(default)]
406    pub enum_module: Option<String>,
407    /// Maps nested fixture object field names to their C# type names.
408    /// Used to generate `JsonSerializer.Deserialize<NestedType>(...)` for nested objects.
409    /// E.g., `{"preprocessing": "PreprocessingOptions"}`.
410    #[serde(default)]
411    pub nested_types: HashMap<String, String>,
412    /// When `false`, nested config builder results are passed directly to builder methods
413    /// without wrapping in `Optional.of(...)`. Set to `false` for bindings where nested
414    /// option types are non-optional (e.g., html-to-markdown Java).
415    /// Defaults to `true` for backward compatibility.
416    #[serde(default = "default_true")]
417    pub nested_types_optional: bool,
418    /// When `true`, the function returns a simple type (e.g., `String`) rather
419    /// than a struct.  Generators that would normally emit `result.content`
420    /// (or equivalent field access) will use the result variable directly.
421    #[serde(default)]
422    pub result_is_simple: bool,
423    /// When `true` (and combined with `result_is_simple`), the simple result is
424    /// a slice/array type (e.g., `[]string` in Go, `Vec<String>` in Rust).
425    /// The Go generator uses `strings.Join(value, " ")` for `contains` assertions
426    /// instead of `string(value)`.
427    #[serde(default)]
428    pub result_is_array: bool,
429    /// When `true`, the function returns `Vec<T>` rather than a single value.
430    /// Field-path assertions are emitted as `.iter().all(|r| <accessor>)` so
431    /// every element is checked. (Rust generator.)
432    #[serde(default)]
433    pub result_is_vec: bool,
434    /// When `true`, the function returns a raw byte array (e.g., `byte[]` in Java,
435    /// `[]byte` in Go). Used by generators to select the correct length accessor
436    /// (field `.length` vs method `.length()`).
437    #[serde(default)]
438    pub result_is_bytes: bool,
439    /// When `true`, the function returns `Option<T>`. The result is unwrapped
440    /// before any non-`is_none`/`is_some` assertion runs; `is_empty`/`not_empty`
441    /// assertions map to `is_none()`/`is_some()`. (Rust generator.)
442    #[serde(default)]
443    pub result_is_option: bool,
444    /// When `true`, the R generator emits the call result directly without wrapping
445    /// in `jsonlite::fromJSON()`. Use when the R binding already returns a native
446    /// R list (`Robj`) rather than a JSON string. Field-path assertions still use
447    /// `result$field` accessor syntax (i.e. `result_is_simple` behaviour is NOT
448    /// implied — only the JSON parse wrapper is suppressed). (R generator only.)
449    #[serde(default)]
450    pub result_is_r_list: bool,
451    /// When `true`, the Rust generator wraps the `json_object` argument expression
452    /// in `Some(...).clone()` to match an owned `Option<T>` parameter slot rather
453    /// than passing `&options`. (Rust generator only.)
454    #[serde(default)]
455    pub wrap_options_in_some: bool,
456    /// Trailing positional arguments appended verbatim after the configured
457    /// `args`. Used when the target function takes additional positional slots
458    /// (e.g. visitor) the fixture cannot supply directly. (Rust generator only.)
459    #[serde(default)]
460    pub extra_args: Vec<String>,
461    /// Per-rust override of the call-level `returns_result`. When set, takes
462    /// precedence over `CallConfig.returns_result` for the Rust generator only.
463    /// Useful when one binding is fallible while others are not.
464    #[serde(default)]
465    pub returns_result: Option<bool>,
466    /// Maps handle config field names to their Python type constructor names.
467    ///
468    /// When the handle config object contains a nested dict-valued field, the
469    /// generator will wrap it in the specified type using keyword arguments.
470    /// E.g., `{"browser": "BrowserConfig"}` generates `BrowserConfig(mode="auto")`
471    /// instead of `{"mode": "auto"}`.
472    #[serde(default)]
473    pub handle_nested_types: HashMap<String, String>,
474    /// Handle config fields whose type constructor takes a single dict argument
475    /// instead of keyword arguments.
476    ///
477    /// E.g., `["auth"]` means `AuthConfig({"type": "basic", ...})` instead of
478    /// `AuthConfig(type="basic", ...)`.
479    #[serde(default)]
480    pub handle_dict_types: HashSet<String>,
481    /// Elixir struct module name for the handle config argument.
482    ///
483    /// When set, the generated Elixir handle config uses struct literal syntax
484    /// (`%Module.StructType{key: val}`) instead of a plain string-keyed map.
485    /// Rustler `NifStruct` requires a proper Elixir struct — plain maps are rejected.
486    ///
487    /// E.g., `"CrawlConfig"` generates `%Kreuzcrawl.CrawlConfig{download_assets: true}`.
488    #[serde(default)]
489    pub handle_struct_type: Option<String>,
490    /// Handle config fields whose list values are Elixir atoms (Rustler NifUnitEnum).
491    ///
492    /// When a config field is a `Vec<EnumType>` in Rust, the Elixir side must pass
493    /// a list of atoms (e.g., `[:image, :document]`) not strings (`["image"]`).
494    /// List the field names here so the generator emits atom literals instead of strings.
495    ///
496    /// E.g., `["asset_types"]` generates `asset_types: [:image]` instead of `["image"]`.
497    #[serde(default)]
498    pub handle_atom_list_fields: HashSet<String>,
499    /// WASM config class name for handle args (WASM generator only).
500    ///
501    /// When set, handle args are constructed using `ConfigType.default()` + setters
502    /// instead of passing a plain JS object (which fails `_assertClass` validation).
503    ///
504    /// E.g., `"WasmCrawlConfig"` generates:
505    /// ```js
506    /// const engineConfig = WasmCrawlConfig.default();
507    /// engineConfig.maxDepth = 1;
508    /// const engine = createEngine(engineConfig);
509    /// ```
510    #[serde(default)]
511    pub handle_config_type: Option<String>,
512    /// PHP client factory method name (PHP generator only).
513    ///
514    /// When set, the generated PHP test instantiates a client via
515    /// `ClassName::factory_method('test-key')` and calls methods on the instance
516    /// instead of using static facade calls.
517    ///
518    /// E.g., `"createClient"` generates:
519    /// ```php
520    /// $client = LiterLlm::createClient('test-key');
521    /// $result = $client->chat($request);
522    /// ```
523    #[serde(default)]
524    pub php_client_factory: Option<String>,
525    /// Client factory function name for instance-method languages (WASM, etc.).
526    ///
527    /// When set, the generated test imports this function, creates a client,
528    /// and calls API methods on the instance instead of as top-level functions.
529    ///
530    /// E.g., `"createClient"` generates:
531    /// ```typescript
532    /// import { createClient } from 'pkg';
533    /// const client = createClient('test-key');
534    /// const result = await client.chat(request);
535    /// ```
536    #[serde(default)]
537    pub client_factory: Option<String>,
538    /// Fields on the options object that require `BigInt()` wrapping (WASM only).
539    ///
540    /// `wasm_bindgen` maps Rust `u64`/`i64` to JavaScript `BigInt`. Numeric
541    /// values assigned to these setters must be wrapped with `BigInt(n)`.
542    ///
543    /// List camelCase field names, e.g.:
544    /// ```toml
545    /// [e2e.call.overrides.wasm]
546    /// bigint_fields = ["maxTokens", "seed"]
547    /// ```
548    #[serde(default)]
549    pub bigint_fields: Vec<String>,
550    /// Static CLI arguments appended to every invocation (brew/CLI generator only).
551    ///
552    /// E.g., `["--format", "json"]` appends `--format json` to every CLI call.
553    #[serde(default)]
554    pub cli_args: Vec<String>,
555    /// Maps fixture config field names to CLI flag names (brew/CLI generator only).
556    ///
557    /// E.g., `{"output_format": "--format"}` generates `--format <value>` from
558    /// the fixture's `output_format` input field.
559    #[serde(default)]
560    pub cli_flags: HashMap<String, String>,
561    /// C FFI opaque result type name (C only).
562    ///
563    /// The PascalCase name of the result struct, without the prefix.
564    /// E.g., `"ChatCompletionResponse"` for `LiterllmChatCompletionResponse*`.
565    /// If not set, defaults to the function name in PascalCase.
566    #[serde(default)]
567    pub result_type: Option<String>,
568    /// Override the argument order for this language binding.
569    ///
570    /// Lists argument names from `args` in the order they should be passed
571    /// to the target function. Useful when a language binding reorders parameters
572    /// relative to the canonical `args` list in `CallConfig`.
573    ///
574    /// E.g., if `args = [path, mime_type, config]` but the Node.js binding
575    /// takes `(path, config, mime_type?)`, specify:
576    /// ```toml
577    /// [e2e.call.overrides.node]
578    /// arg_order = ["path", "config", "mime_type"]
579    /// ```
580    #[serde(default)]
581    pub arg_order: Vec<String>,
582    /// When `true`, `json_object` args with an `options_type` are passed as a
583    /// pointer (`*OptionsType`) rather than a value.  Use for Go bindings where
584    /// the options parameter is `*ConversionOptions` (nil-able pointer) rather
585    /// than a plain struct.
586    ///
587    /// Absent options are passed as `nil`; present options are unmarshalled into
588    /// a local variable and passed as `&optionsVar`.
589    #[serde(default)]
590    pub options_ptr: bool,
591    /// Alternative function name to use when the fixture includes a `visitor`.
592    ///
593    /// Some bindings expose two entry points: `Convert(html, opts)` for the
594    /// plain case and `ConvertWithVisitor(html, opts, visitor)` when a visitor
595    /// is involved.  Set this to the visitor-accepting function name so the
596    /// generator can pick the right symbol automatically.
597    ///
598    /// E.g., `"ConvertWithVisitor"` makes the Go generator emit:
599    /// ```go
600    /// result, err := htmd.ConvertWithVisitor(html, nil, visitor)
601    /// ```
602    /// instead of `htmd.Convert(html, nil, visitor)` (which would not compile).
603    #[serde(default)]
604    pub visitor_function: Option<String>,
605    /// Rust trait names to import when `client_factory` is set (Rust generator only).
606    ///
607    /// When `client_factory` is set, the generated test creates a client object and
608    /// calls methods on it. Those methods are defined on traits (e.g. `LlmClient`,
609    /// `FileClient`) that must be in scope. List the trait names here and the Rust
610    /// generator will emit `use {module}::{trait_name};` for each.
611    ///
612    /// E.g.:
613    /// ```toml
614    /// [e2e.call.overrides.rust]
615    /// client_factory = "create_client"
616    /// trait_imports = ["LlmClient", "FileClient", "BatchClient", "ResponseClient"]
617    /// ```
618    #[serde(default)]
619    pub trait_imports: Vec<String>,
620    /// Raw C return type, used verbatim instead of `{PREFIX}Type*` (C only).
621    ///
622    /// Valid values: `"char*"`, `"int32_t"`, `"uintptr_t"`.
623    /// When set, the C generator skips options handle construction and uses the
624    /// raw type directly. Free logic is adjusted accordingly.
625    #[serde(default)]
626    pub raw_c_result_type: Option<String>,
627    /// Free function for raw `char*` C results (C only).
628    ///
629    /// Defaults to `{prefix}_free_string` when unset and `raw_c_result_type == "char*"`.
630    #[serde(default)]
631    pub c_free_fn: Option<String>,
632    /// Fields in a `json_object` arg that must be wrapped in `java.nio.file.Path.of()`
633    /// (Java generator only).
634    ///
635    /// E.g., `["cache_dir"]` wraps the string value of `cache_dir` so the builder
636    /// receives `java.nio.file.Path.of("/tmp/dir")` instead of a plain string.
637    #[serde(default)]
638    pub path_fields: Vec<String>,
639}
640
641fn default_true() -> bool {
642    true
643}
644
645/// Per-language package reference configuration.
646#[derive(Debug, Clone, Serialize, Deserialize, Default)]
647pub struct PackageRef {
648    /// Package/crate/gem/module name.
649    #[serde(default)]
650    pub name: Option<String>,
651    /// Relative path from e2e/{lang}/ to the package.
652    #[serde(default)]
653    pub path: Option<String>,
654    /// Go module path.
655    #[serde(default)]
656    pub module: Option<String>,
657    /// Package version (e.g., for go.mod require directives).
658    #[serde(default)]
659    pub version: Option<String>,
660}