Skip to main content

bynk_emit/emitter/
ctx.rs

1//! The module-invariant lowering context and the per-body state structs
2//! that sit between it and `LowerCtx`.
3
4use super::*;
5
6/// Lowering state that is genuinely **module-invariant**: the same value at
7/// every body-lowering site within one emitted module, and never written by the
8/// recursive lowering itself. Grouped out of [`LowerCtx`] so a new lowering kind
9/// inherits the whole set wholesale instead of re-deriving each default.
10///
11/// Nothing the lowering mutates *per body* may move in here — see the
12/// scratch-state fields at the bottom of [`LowerCtx`]. A `ModuleCtx` is still
13/// built fresh alongside each `LowerCtx` today, but filing a per-body counter
14/// under a name that says "module" is exactly how such state starts leaking
15/// between handler bodies.
16pub(crate) struct ModuleCtx<'a> {
17    /// Typed-commons handle (used to look up receiver types for method-call
18    /// UFCS lowering).
19    pub(super) commons: &'a TypedCommons,
20    /// Cross-context info for v0.6 cross-context call lowering.
21    pub(super) cross_context: &'a bynk_check::resolver::CrossContextInfo,
22    /// The emitted module's conditional-runtime-helper accumulator.
23    ///
24    /// The `Bytes` lowerings (kernel, `==`, base64 codec) call
25    /// [`RuntimeUse::note_bytes`] through this, so the module's import line is
26    /// decided from what lowering actually emitted rather than by scanning the
27    /// generated text for the helper's own name.
28    ///
29    /// Required rather than optional: a missing accumulator would make
30    /// `note_bytes` a silent no-op, which is exactly the failure this replaces —
31    /// a module that references `__bynkBytesEqual` without importing it. A
32    /// lowering whose imports are decided elsewhere (the test scaffolds) owns a
33    /// throwaway one, which reads as the deliberate choice it is.
34    pub(super) runtime_use: &'a RuntimeUse,
35    /// v0.8 build target. In workers mode cross-context calls lower to
36    /// `callService(...)` instead of `deps.surface.<key>.<method>(...)`.
37    pub(crate) target: BuildTarget,
38    /// #527: agent → method → the method's `given` caps (mirrors
39    /// [`crate::emit_model::EmitProjectCtx::agent_method_givens`]). Consulted by
40    /// the agent-call lowering to record capability requirements.
41    pub(super) agent_method_givens: HashMap<String, HashMap<String, Vec<bynk_model::CapRefIr>>>,
42    /// Events slice 3b (#978): each locally-declared event's resolved
43    /// `@schema(N)` version (mirrors
44    /// [`crate::emit_model::EmitProjectCtx::event_schema_versions`]). Default-
45    /// empty like `agent_method_givens`, not a required constructor
46    /// parameter like `runtime_use` — a miss here degrades to `schemaVersion:
47    /// 1`, exactly every event's behaviour before this map existed, not a
48    /// hard failure the way a missing `runtime_use` would be.
49    pub(super) event_schema_versions: HashMap<String, i64>,
50    /// #2058: the namespace each consumed context's type is named under in
51    /// this module (mirrors [`crate::emitter::emit::consumed_type_ns`]).
52    /// Default-empty: a miss names the type bare, as before.
53    pub(super) consumed_type_ns: HashMap<String, String>,
54    /// #2887: a consumed type this module renames, alias → the name its
55    /// context declares and exports.
56    pub(super) consumed_type_declared: HashMap<String, String>,
57    /// The name of the unit being emitted. `bynk` is a reserved namespace, so a capability
58    /// declared *in the `bynk` unit* is bynk's own: read, alongside
59    /// `CrossContextInfo::flattened_caps` (the consumed-from-elsewhere case), by
60    /// [`bynk_check::firstparty::resolve`] (#934, 1A.33).
61    pub(super) unit_name: String,
62    /// #1961: [`crate::emit_model::EmitProjectCtx::agent_called_contexts`].
63    pub(super) agent_called_contexts: Vec<String>,
64    /// #2045: [`crate::emit_model::EmitProjectCtx::consumed_context_types`]. A
65    /// variant of one of these sums is built inline, not through the callee's
66    /// companion object, so the callee's module is never a value import.
67    pub(super) consumed_context_types: HashSet<String>,
68    /// #3580: [`crate::emit_model::EmitProjectCtx::trace`]. `None` (the default)
69    /// emits no trace recording.
70    pub(super) trace: Option<crate::emit_model::TraceLoc>,
71    /// The per-unit facts a lowering reads but the body does not carry: the
72    /// `.bynk` source of the unit (#2620) and its hidden-type spellings (#1927).
73    pub(super) unit: UnitFacts<'a>,
74}
75
76/// #2620 and #1927: the two per-unit facts lowering reads from the unit being
77/// emitted, both fields of its [`EmitProjectCtx`]. Every [`ModuleCtx`] is built
78/// with one, so a lowering cannot be reached without saying where they come
79/// from: [`UnitFacts::of`] for a unit of a project, [`UnitFacts::detached`] for
80/// a scaffold lowered outside one.
81#[derive(Clone, Copy)]
82pub(crate) struct UnitFacts<'a> {
83    source: Option<&'a crate::emit_model::UnitSource>,
84    spellings: &'a HashMap<String, String>,
85}
86
87impl<'a> UnitFacts<'a> {
88    /// The facts of the unit `ctx` describes.
89    pub(crate) fn of(ctx: &'a EmitProjectCtx) -> Self {
90        Self {
91            source: ctx.unit_source.as_ref(),
92            spellings: &ctx.type_spellings,
93        }
94    }
95
96    /// How the unit renders a checked `Ty` as TypeScript (#1927).
97    pub(crate) fn render(&self, commons: &'a TypedCommons) -> TyRender<'a> {
98        TyRender::new(commons.tys(), self.spellings)
99    }
100
101    /// No unit behind the lowering (a test or contract scaffold): faults name
102    /// `offset N`, and no type is respelled.
103    pub(crate) fn detached() -> Self {
104        Self {
105            source: None,
106            spellings: ts_types::no_spellings(),
107        }
108    }
109}
110
111impl<'a> ModuleCtx<'a> {
112    /// What the unit being emitted tells every body it lowers: whether it is the
113    /// reserved `bynk` adapter, and (#3580) where a traced build names call sites.
114    pub(super) fn note_unit(&mut self, ctx: &EmitProjectCtx) {
115        self.unit_name = ctx.commons_name.clone();
116        self.trace = ctx.trace.clone();
117    }
118
119    /// #2620: the `path:line:col` of a byte offset in the unit being emitted,
120    /// or `None` when no unit stands behind the lowering.
121    pub(super) fn fault_location(&self, offset: usize) -> Option<String> {
122        self.unit.source.map(|s| s.location(offset))
123    }
124
125    /// How this module renders a checked `Ty` as TypeScript.
126    pub(super) fn ty_render(&self) -> TyRender<'a> {
127        self.unit.render(self.commons)
128    }
129
130    /// A module of the project unit `ctx` describes: its cross-context facts,
131    /// runtime-use accumulator, source and spellings all come from `ctx`.
132    pub(super) fn for_unit(commons: &'a TypedCommons, ctx: &'a EmitProjectCtx) -> Self {
133        Self::new(
134            commons,
135            &ctx.cross_context,
136            &ctx.runtime_use,
137            UnitFacts::of(ctx),
138        )
139    }
140
141    pub(crate) fn new(
142        commons: &'a TypedCommons,
143        cross_context: &'a bynk_check::resolver::CrossContextInfo,
144        runtime_use: &'a RuntimeUse,
145        unit: UnitFacts<'a>,
146    ) -> Self {
147        Self {
148            unit,
149            commons,
150            cross_context,
151            runtime_use,
152            target: BuildTarget::Bundle,
153            agent_method_givens: HashMap::new(),
154            event_schema_versions: HashMap::new(),
155            consumed_type_ns: HashMap::new(),
156            consumed_type_declared: HashMap::new(),
157            unit_name: String::new(),
158            agent_called_contexts: Vec::new(),
159            consumed_context_types: HashSet::new(),
160            trace: None,
161        }
162    }
163}
164
165/// The lowering state shared by the four **capability-bearing** body kinds — a
166/// service handler, a composed provider op, an agent handler, and a websocket
167/// lifecycle DO method. Every other kind carries no `HandlerShared` at all, and
168/// the [`LowerCtx`] accessors below hand those kinds the same defaults the flat
169/// struct used to give them (an empty capability set, no scope, `deps`).
170#[derive(Default)]
171pub(crate) struct HandlerShared {
172    /// Names of capabilities in scope as `given C1, C2, ...`. Used to lower
173    /// `Capability.op(args)` calls to `deps.Capability.op(args)`.
174    pub(super) capabilities: HashSet<String>,
175    /// #934: the calling handler's own qualified name (`<unit>.<service or
176    /// agent>.<handler>`, e.g. `shop.reserve.ordering.call`). Read only by the
177    /// `Idempotency.dedup`/`remember` lowering, which prefixes the
178    /// developer-supplied key with it so two unrelated handlers using the same
179    /// literal key never collide (ADR 0283; the retired idempotency track's
180    /// §3.4 in `design/archive/retired-tracks.md`). `None` anywhere a
181    /// capability call cannot occur (a plain method, a free fn, an
182    /// invariant/transition predicate, a static field initialiser) — those
183    /// kinds carry no `HandlerShared`, and the accessor reports `None`.
184    pub(super) handler_scope: Option<String>,
185    /// Events track, slice 2 (spine #936): the qualified name of the unit
186    /// this body is emitted into (`ctx.commons_name`), read by the
187    /// `Events.emit[E](event)` lowering to mint the envelope's
188    /// `publisherId`. Context-scoped rather than agent-scoped: `Events.emit`
189    /// is legal from a plain, keyless service handler with no agent
190    /// instance to report, so this is the only identity available
191    /// uniformly at every legal emission site (an amendment to
192    /// design/bynk-design-notes.md §7's "the publisher is the emitting
193    /// agent" framing — see the events-envelope ADR). Always populated
194    /// alongside `handler_scope` at every construction site; never `None`
195    /// in practice for a body that could contain an `Events.emit` call.
196    pub(super) owning_context: String,
197    /// v0.12: whether the receiver expression a capability call resolves
198    /// against is `this.deps` (a composed provider body) rather than `deps` (a
199    /// handler body). The fact, not the string: `LowerCtx::cap_deps_expr` and
200    /// `cap_deps_node` both read it (1A.6).
201    pub(super) deps_on_this: bool,
202    /// The consumed contexts the current handler calls across the boundary.
203    /// Non-empty drives whether `deps` gets a `surface` field type; in
204    /// workers mode it is also exactly the Service Bindings the handler's
205    /// `deps.env` type names (#1961).
206    pub(super) cross_contexts_called: std::collections::BTreeSet<String>,
207    /// v0.9.2: set when the body instantiates a local agent. In workers mode
208    /// this drives `env` (carrying the DO namespaces) into the handler's deps
209    /// type so the agent factory can reach its Durable Object binding.
210    pub(super) agents_instantiated: bool,
211    /// #527: capabilities required by agent methods this body calls, keyed by
212    /// deps key. After body lowering these widen the handler's deps *type* to
213    /// match the runtime value compose builds (which always carried them).
214    pub(super) agent_given_caps_used: std::collections::BTreeMap<String, bynk_model::CapRefIr>,
215}
216
217/// The lowering state shared by the three **generated test-scaffold** body
218/// kinds — a `stub`/`where`/`requires` predicate value, a unit test case, and an
219/// integration test case.
220#[derive(Default)]
221pub(crate) struct TestShared {
222    /// True when lowering **any** generated test-scaffold body — distinct from
223    /// `assert_loc`, which is only ever `Some` for the two real `case` bodies
224    /// and carries an unrelated payload (a diagnostic location). Kept as its own
225    /// field (Locale capability track, slice 1, #844 review) rather than
226    /// overloading `assert_loc.is_some()`, since that conflated "has a location"
227    /// with "is test scaffolding" for a caller that has no location to give.
228    pub(crate) test_scaffold: bool,
229    /// v0.59: the source text and project-relative path of the file the body
230    /// came from, so an `assert` can emit a real `path:line:col` location (for
231    /// `--format json` click-through) rather than a bare byte offset. Stays
232    /// `None` for a predicate scaffold, which emits no `assert`.
233    pub(crate) assert_loc: Option<AssertLoc>,
234}
235
236/// The `store`-agent sub-state of an [`BodyMode::AgentHandler`] body: present
237/// only when the hosting agent is a `store` agent, absent for a plain
238/// state-record agent (whose handler reads `currentState`/`self.state` instead).
239pub(crate) struct AgentStoreState {
240    /// v0.81 (storage track): the name of the mutable working-state variable
241    /// (`__state`) and the set of `Cell` field names. A bare `Cell` read lowers
242    /// to `<var>.<cell>`, and a `cell := v` write lowers to `<var>.<cell> = <v>`
243    /// — read-your-writes via the in-memory record, flushed once at handler end
244    /// (ADR 0109).
245    pub(super) state: (String, HashSet<String>),
246    /// v0.82 (ADR 0110): the agent's `store` `Map` field names. A method call
247    /// whose receiver is one lowers to an entry operation over `__state.<map>`
248    /// (a JSON-serialisable `Record<string, V>`), staged in the working record
249    /// and flushed at commit like any other state field.
250    pub(super) maps: HashSet<String>,
251    /// v0.83: the agent's `store` `Set` field names. A method call whose
252    /// receiver is one lowers to an entry operation over `__state.<set>` (a
253    /// `Record<string, boolean>`), staged in the working record.
254    pub(super) sets: HashSet<String>,
255    /// v0.87 (ADR 0113): the agent's `store` `Cache` fields (name → ttl millis).
256    /// A method call whose receiver is one lowers to an entry op over
257    /// `__state.<cache>` (a `Record<string, { v, exp }>`), applying TTL expiry
258    /// against the injected `Clock`.
259    pub(super) caches: HashMap<String, i64>,
260    /// v0.95 (ADR 0121): the agent's `store` `Log` fields (name → optional
261    /// `@retain` millis). `<log>.append` pushes `{ t: now(), v }` to
262    /// `__state.<log>` (an array) and prunes past the retain horizon; the
263    /// time-window roots / builders lower to a query pipeline over the array.
264    pub(super) logs: HashMap<String, Option<i64>>,
265    /// v0.93 (ADR 0118): the agent's `@indexed` secondary indexes (map name →
266    /// the value-record fields indexed on). A mutating op on the map maintains a
267    /// sibling posting-list `Record<string, string[]>` per field (`<map>__idx_<f>`);
268    /// an equality `filter` on an indexed field routes to a posting lookup.
269    pub(super) indexes: HashMap<String, Vec<String>>,
270    /// v0.104/v0.105 (real-time track slice 3b): the agent's held `store Map[K,
271    /// Connection]` fields (name → the connection's **frame type** `F`, e.g.
272    /// `ServerFrame`). On Workers these persist `K → connId` in the durable state
273    /// record; a method call whose receiver is one lowers to an entry op over
274    /// `__state.<map>` (the connId record) with `connIdOf`/`resolveConnection<F>` —
275    /// not the plain `Record<string, V>` ops (held maps are excluded from
276    /// [`AgentStoreState::maps`]).
277    pub(super) held_maps: HashMap<String, bynk_ts::TsType>,
278    /// Review of #1460: a plain `store Map[K, V]` field's own value type `V`
279    /// (name → its rendered TS type), for `lower_query_method`'s own
280    /// collection-kernel sites (`distinctBy`/`joinOn`/`leftJoin`/`groupBy`)
281    /// when the receiver is a plain map's own value scan lifted into the
282    /// general query vocabulary — mirrors `held_maps`'s own construction
283    /// exactly, just for the non-held case.
284    pub(super) map_values: HashMap<String, bynk_ts::TsType>,
285    /// 1A.33: the plain `store Map` fields whose resolved value type is a `Connection`
286    /// (from the checker's `StoreKindIr::Map`), so a `put` that displaces one and a `remove`
287    /// that drops one close it (#3261, #3224). Decided on the model type, not on the text of
288    /// the rendered value type.
289    pub(super) connection_maps: HashSet<String>,
290    /// Review of #1460: a `store Log[T]` field's own element type `T` (name →
291    /// its rendered TS type), for the identical reason `map_values` exists —
292    /// a Log's value scan is also lifted into the general query vocabulary.
293    pub(super) log_values: HashMap<String, bynk_ts::TsType>,
294}
295
296/// What [`LowerCtx`] is lowering *right now*. One variant per real body-emission
297/// site; each carries exactly the state that site populates and nothing else, so
298/// "not applicable to this kind" is expressed in the type rather than left
299/// indistinguishable from "deliberately defaulted".
300pub(crate) enum BodyMode {
301    /// A type's method body (`emit_method`).
302    Method,
303    /// A free function body (`emit_free_fn`).
304    FreeFn,
305    /// #2868: a context function that declares `given`: a free function whose
306    /// hidden `deps` parameter carries exactly the capabilities it names, so a
307    /// capability call lowers as in a handler (`deps.Logger.error(…)`).
308    GivenFn { handler: HandlerShared },
309    /// An agent field's static initialiser expression (`emit_agent`).
310    StaticInit,
311    /// v0.80: an agent invariant predicate. Carries the name of the
312    /// proposed-state variable (the `commitState` parameter) and the set of
313    /// state field names — a bare ident matching a state field lowers to
314    /// `<var>.<field>`, since invariants read state fields directly (§14).
315    Invariant {
316        name: String,
317        fields: HashSet<String>,
318    },
319    /// v0.116 (testing track slice 4): a `transition` predicate. Carries the JS
320    /// names bound to the contextual `old` and `new` state records. The Bynk
321    /// identifiers `old`/`new` lower to these (`new` is a JS reserved word, so
322    /// both are renamed), and field access `old.<field>` reads off the `old`
323    /// record.
324    Transition { old: String, new: String },
325    /// A service handler body (`emit_service`).
326    ServiceHandler {
327        handler: HandlerShared,
328        /// v0.47: the `by` binder whose `.identity` is threaded through `deps`
329        /// (so `<binder>.identity` lowers to `deps.identity` rather than the
330        /// unit-value `undefined`).
331        deps_identity_binder: Option<String>,
332        /// v0.52: when lowering a multi-actor sum handler body, the `by` binder
333        /// that names the resolved-actor value (threaded through `deps`, so the
334        /// binder ident lowers to `deps.who` — the tagged union the body
335        /// `match`es).
336        actor_sum_binder: Option<String>,
337    },
338    /// A composed provider's operation body (`emit_provider`).
339    ProviderOp { handler: HandlerShared },
340    /// An agent handler body (`emit_agent`).
341    AgentHandler {
342        handler: HandlerShared,
343        /// True when lowering an agent handler body. Used to rewrite
344        /// `self.<keyField>` access into the appropriate local.
345        in_agent_handler: bool,
346        /// The name of the agent's `key id` field (so `self.<id>` resolves).
347        agent_key_field: Option<String>,
348        /// The `store`-agent working-record state, when the hosting agent is a
349        /// `store` agent. Boxed: it is by far the largest payload in this enum,
350        /// and every other body kind would otherwise pay for it.
351        store: Option<Box<AgentStoreState>>,
352    },
353    /// A websocket lifecycle method on the hosting Durable Object
354    /// (`emit_ws_do_method`).
355    WsDoMethod {
356        handler: HandlerShared,
357        /// v0.47: as [`BodyMode::ServiceHandler::deps_identity_binder`].
358        deps_identity_binder: Option<String>,
359        /// As [`BodyMode::ServiceHandler::actor_sum_binder`]: a `from websocket`
360        /// `on open` whose `by` is an actor sum reads the resolved actor from
361        /// `deps.who`, which the edge forwarded and the DO's `fetch` rebuilt.
362        actor_sum_binder: Option<String>,
363        /// v0.104 (real-time track slice 3b): when lowering a `from websocket`
364        /// `on open` body **into its hosting Durable Object** (the agent the
365        /// upgrade transfers the connection to), the name of that agent. A
366        /// transfer call `<Agent>(<key>).method(args)` whose `<Agent>` is this
367        /// self-agent lowers to a direct `this.method(args, deps)` self-call
368        /// rather than the cross-instance `__make<Agent>(key)` factory — the
369        /// connection is already in this DO, so it never crosses an RPC boundary
370        /// (DECISION A).
371        ws_self_agent: Option<String>,
372    },
373    /// A `stub`/`where`/`requires` predicate value lowered via
374    /// `lower_block_to_async_body` — test/property/contract scaffolding, never a
375    /// real production provider body.
376    PredicateScaffold { test: TestShared },
377    /// A unit test `case` body (`lower_test_case_body`).
378    TestCase {
379        test: TestShared,
380        /// v0.117 (testing track slice 5): the name of the recorded-call trace
381        /// object (`__obs`), over which an observation (`Cap.op called …`) and
382        /// `trace(Cap.op)` are lowered.
383        observation_trace: Option<String>,
384        /// v0.7: the target context's local service names. A `service.call(args)`
385        /// or `service(args)` invocation where `service` is in this set lowers to
386        /// `<service>.call(args, deps)` so the test wires its `deps` through.
387        test_services: HashSet<String>,
388        /// v0.182 (#664): the ordered handler kinds of each test service, so a
389        /// cron (`svc.schedule("…")`) or queue (`svc.message(m)`) address can
390        /// recover the position index the emitted key encodes (`cron_<svc>_<i>` /
391        /// `queue_…`). http keys are a pure function of verb + path and need no
392        /// lookup here. P6.37 (design/tracks/the-ir.md §6a): `IrHandlerKind`
393        /// (P6.24a's own pure, unconditional mirror), not the raw AST
394        /// `HandlerKind` this field used to store.
395        test_service_handlers: HashMap<String, Vec<bynk_model::IrHandlerKind>>,
396        /// I3 (#1971), #2020: the `(service, key)` handlers that bind an actor
397        /// sum, whose `deps.who` a call-site principal builds. `key` is
398        /// `"call"` for an `on call` handler and the emitted method name
399        /// (`http_handler_method_name_ir`) for an http route.
400        sum_handlers: HashSet<(String, String)>,
401        /// #1994: the target has a handler that sends with `detach`, so `deps`
402        /// carries the `__exec` double and each addressed service call is
403        /// wrapped in `__bynkSettle(deps, …)`.
404        settle_sends: bool,
405    },
406    /// An integration test `case` body (`lower_integration_case_body`).
407    IntegrationCase {
408        test: TestShared,
409        /// v0.182 (Slice B, #667): the target's http service names. An http
410        /// address on one of these lowers to a driver call
411        /// (`__sysdrive_<svc>_<key>(args, sub)`) that drives a real
412        /// `worker.fetch` with a signed credential, instead of the unit-tier
413        /// direct handler call. Empty at the unit tier.
414        system_http_services: std::collections::HashSet<String>,
415        /// #707: the declared `(service, method, path)` http routes of the system
416        /// target. A `(method, path)` call whose method is absent here but whose
417        /// path is present is a **wrong-method** call — it drives the `405`
418        /// fall-through through the generic `__sysdrive_wrongmethod_<svc>` driver.
419        system_http_routes: std::collections::HashSet<(String, String, String)>,
420        /// #708: for each declared `(service, method, path)` route that has a
421        /// body param, the body's zero-based position among the route's
422        /// positional call args (i.e. within `args[1..]`, matching handler-param
423        /// declaration order) and its declared type. The raw driver
424        /// (`__sysdrive_raw_*`, Slice C) forwards every slot as a `string`; a
425        /// `Wire(…)` arg already lowers to that raw string, but a *typed* arg
426        /// mixed into the same call must be converted: the body slot serialises
427        /// through the same wire codec the typed driver uses
428        /// (`JSON.stringify(serialise_expr_via(...))`), any other (path) slot
429        /// just coerces via `String(...)`. Absent for a bodyless route.
430        system_http_route_body:
431            HashMap<(String, String, String), (usize, bynk_syntax::ast::TypeRef)>,
432        /// #708: the type namespace (`<target>.`) `serialise_expr_via` needs to
433        /// resolve a body param's custom codec when converting a typed arg for
434        /// the raw driver. Mirrors the `type_ns` `emit_system_http_support`
435        /// computes from the same suite target.
436        system_http_type_ns: String,
437        /// #2019: the refinement-guarded routes and the claims each
438        /// refinement actor signs, for a call acting as a refinement.
439        system_http_claims: Box<SystemHttpClaims>,
440        /// #2136: the target's cron and queue services, driven at `system`
441        /// through the Worker's `scheduled` / `queue` entry points.
442        system_jobs: SystemJobServices,
443    },
444}
445
446/// #2136: the cron and queue services a `system`-tier case drives through the
447/// participant Worker's real `scheduled` and `queue` entry points. A
448/// `svc.schedule("<expr>", …)` address on a cron service here lowers to
449/// `__sysdrive_schedule_<svc>_<index>(…)`, and `q.message(m)` on a queue
450/// service to `__sysdrive_message_<q>(m)` (`tests_emit::emit_system_job_support`).
451#[derive(Debug, Clone, Default)]
452pub struct SystemJobServices {
453    /// Each cron service's schedule expressions, in declaration order (the
454    /// position is the handler's `cron_<svc>_<index>` index).
455    pub cron: HashMap<String, Vec<String>>,
456    /// The queue services.
457    pub queue: HashSet<String>,
458    /// #3328: the email services, driven as raw MIME through the Worker's
459    /// `email()` entry (`__sysdrive_message_<svc>(mail)`).
460    pub email: HashSet<String>,
461}
462
463/// #2019: what a `system`-tier call needs to sign the claims a refinement
464/// actor's predicate checks (`actor Admin = User where hasClaim("admin")`).
465/// A route guarded by a refinement has drivers that take a trailing claims
466/// object, signed into the JWT next to `sub`; a call acting as a refinement
467/// actor passes that actor's witness claims, and any other call passes `{}`,
468/// so the Worker's seam answers `403` exactly as it would a real token
469/// lacking the claim.
470#[derive(Debug, Clone, Default)]
471pub struct SystemHttpClaims {
472    /// The `(service, method, path)` routes whose `by` actor is a refinement.
473    pub routes: HashSet<(String, String, String)>,
474    /// Each refinement actor's witness claims, name and value in order
475    /// (`bynk_check::actors::claim_witness`), which the emitter builds into an object literal.
476    pub actors: HashMap<String, Vec<(String, bynk_check::actors::WitnessValue)>>,
477    /// #2155: each actor-sum route with a credentialed member, and its
478    /// primary member — the actor a call with no principal acts as. Its
479    /// signing drivers take the acting actor's name.
480    pub sum_routes: HashMap<(String, String, String), String>,
481    /// #3052: the `Oidc`-secured routes. Their valid-token drivers take the
482    /// claims to mint into the token, from the call-site principal's
483    /// `TokenClaims.of` lines (else none).
484    pub oidc_routes: HashSet<(String, String, String)>,
485}
486
487/// #1750: the slot and label a statement-form value expression's tails assign
488/// and break to. See [`LowerCtx::tail_slot`].
489#[derive(Clone)]
490pub(crate) struct TailSlot {
491    pub(crate) slot: String,
492    pub(crate) label: String,
493}
494
495/// v0.59: the source context an `assert` lowering needs to turn its span into a
496/// `path:line:col` location. Owned (cloned once per test-case body) to keep the
497/// lowering free of extra lifetime threading; test-file sources are small and
498/// this is compile-time only.
499#[derive(Clone)]
500pub(crate) struct AssertLoc {
501    pub source: String,
502    pub rel_path: String,
503}