ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
//! What a declaration's `write` grants become: ONE CONTEXT PER CLOCK, their write sockets, the
//! lending that holds them, the sweep trait they seat, and the launch's table.
//!
//! Read off the EMISSION rather than off the model, for the poll suite's reason: what an author
//! writes against is the emitted text, and a socket that is named right in the model and spelled
//! wrong in the tokens is exactly the bug this suite exists to see.

use quote::{ToTokens as _, format_ident};

use crate::{
  model::{
    Grant, Grants, PollBody, PollCadence, PollEntry, PollMode, Polls, RecordModel,
    default_polling_name, default_sweeps_name, poll_grants_name,
  },
  name::RustSafeName,
  tests::{emission, model, struct_named},
};

/// A reaper with two clocks, each granted its own store — the shape 路 A exists for.
fn granting() -> RecordModel {
  let mut model = model("Reaper", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![
      entry("hourly", &["media::Media", "media::KeyframeVec"]),
      entry("nightly", &["media::Transcript"]),
    ],
  });
  model
}

/// One entry, as the front end would have settled it — the variant and the folded mounts included,
/// since those are the front end's to decide and this suite's to read back.
fn entry(name: &str, granted: &[&str]) -> PollEntry {
  use heck::ToUpperCamelCase as _;

  PollEntry {
    name: format_ident!("{name}"),
    variant: format_ident!("{}", name.to_upper_camel_case()),
    cadence: PollCadence::Every(core::time::Duration::new(600, 0)),
    grants: (!granted.is_empty()).then(|| Grants {
      grants: granted.iter().copied().map(grant).collect(),
    }),
    body: PollBody::Light,
    mode: PollMode::AsyncInline,
    concurrent: false,
  }
}

/// The same entry with its EXECUTION words settled — the mode it runs in, the citizen it mounts, and
/// whether its detached ticks may overlap.
///
/// Beside [`entry`] rather than folded into it, because the grant suite's own fixtures say nothing
/// about execution and should keep reading as they did: an entry with no mount, run inline, is what
/// every one of them has always been.
fn running(name: &str, granted: &[&str], mode: PollMode, mounted: Option<&str>) -> PollEntry {
  PollEntry {
    body: mounted.map_or(PollBody::Light, |path| {
      PollBody::Citizen(syn::parse_str(path).expect("a type path"))
    }),
    mode,
    ..entry(name, granted)
  }
}

/// One grant, as the front end would have settled it — the mount included, since folding the path's
/// last segment is the front end's job and reading it back is this suite's.
fn grant(path: &str) -> Grant {
  let node: syn::Path = syn::parse_str(path).expect("a type path");
  let segment = &node
    .segments
    .last()
    .expect("a path has at least one segment")
    .ident;
  let mount = RustSafeName::new(segment.to_string(), proc_macro2::Span::call_site());
  Grant { node, mount }
}

/// The emission, as one string with its spaces gone — the poll suite's own reader, for assertions
/// where the tokens matter and their layout does not.
fn tight(model: &RecordModel) -> String {
  model.emit().to_string().replace(' ', "")
}

/// One CONTEXT PER CLOCK, named `<Node><Poll>Grants`, holding that clock's grants and no others.
///
/// This is 路 A itself, read off the tokens: `nightly` holds one field and `hourly` holds two, and
/// neither type mentions the other's store — which is why reaching past a clock is a bound nothing
/// satisfies rather than a check somebody runs.
#[test]
fn each_granting_clock_gets_its_own_context() {
  let model = granting();
  let file = emission(&model);

  for (clock, mounts, handles) in [
    (
      "Hourly",
      &["media", "keyframe_vec"][..],
      &["MediaHandle", "KeyframeVecHandle"][..],
    ),
    ("Nightly", &["transcript"][..], &["TranscriptHandle"][..]),
  ] {
    let named = poll_grants_name(&model.record, &format_ident!("{clock}")).to_string();
    let context = struct_named(&file, &named);
    assert_eq!(
      context
        .fields
        .iter()
        .map(|field| field.ident.as_ref().expect("a named field").to_string())
        .collect::<Vec<_>>(),
      mounts,
      "{named}",
    );
    assert_eq!(
      context
        .generics
        .type_params()
        .map(|param| param.ident.to_string())
        .collect::<Vec<_>>(),
      handles,
      "{named}",
    );
    // The STRUCT states no bound on a handle. The `AsyncLands` bound lives on the forwarding impl, which
    // is the one place it buys anything: a context is built, moved and printed by parties that never
    // write through it.
    assert!(
      context.generics.where_clause.is_none()
        && context
          .generics
          .type_params()
          .all(|param| param.bounds.is_empty()),
      "{}",
      context.to_token_stream(),
    );
  }
}

/// ONE `AsyncLands<Granted>` forward per grant, hanging off THAT CLOCK's context — unchanged in kind by
/// the ruling, re-keyed by it.
///
/// The E0277 teeth are an absent impl, so what a clock's context can land is exactly what that
/// clock's entry granted: the walk below asserts the socket exists on the granting clock, and the
/// walk after it asserts it exists nowhere else.
#[test]
fn each_grant_mints_its_own_write_socket_on_its_own_clock() {
  let emitted = tight(&granting());
  for (context, params, node, handle, mount) in [
    (
      "ReaperHourlyGrants",
      "MediaHandle,KeyframeVecHandle",
      "media::Media",
      "MediaHandle",
      "media",
    ),
    (
      "ReaperHourlyGrants",
      "MediaHandle,KeyframeVecHandle",
      "media::KeyframeVec",
      "KeyframeVecHandle",
      "keyframe_vec",
    ),
    (
      "ReaperNightlyGrants",
      "TranscriptHandle",
      "media::Transcript",
      "TranscriptHandle",
      "transcript",
    ),
  ] {
    let lands = format!("::ingraph::__private::drive::AsyncLands<{node}>");
    // The bound is on the ONE handle this grant holds, and on no other: a clock landing two stores
    // is two impls, each asking only what it spends.
    assert!(
      emitted.contains(&format!(
        "impl<{params}>{lands}for{context}<{params}>where{handle}:{lands},"
      )),
      "the `{node}` socket is emitted on `{context}`, bounding `{handle}` alone: {emitted}"
    );
    // It FORWARDS: the handle's own error, the handle's own call, one field in. Nothing is wrapped,
    // because nothing is added.
    assert!(
      emitted.contains(&format!("typeError=<{handle}as{lands}>::Error;")),
      "the `{node}` socket carries the handle's own error: {emitted}"
    );
    assert!(
      emitted.contains(&format!(
        "<{handle}as{lands}>::land(&mutself.{mount},items)"
      )),
      "the `{node}` socket forwards to the handle it holds: {emitted}"
    );
  }
  // And NO accessor. A grant hands the socket through rather than handing the handle out, so there
  // is one door per grant and not two.
  for gone in ["media_write", "keyframe_vec_write", "transcript_write"] {
    assert!(
      !emitted.contains(gone),
      "`{gone}` is not emitted: {emitted}"
    );
  }
}

/// **THE TEETH, as an absence in the tokens.** No clock's context lands a store some OTHER clock was
/// granted.
///
/// This is the half that cannot be asserted by looking for something: the refusal 路 A buys is an
/// impl that was never written, so the assertion is that the text does not contain it. The compile
/// half — the `E0277` a sweep earns at the line that reached — is pinned from outside the crate, in
/// `ingraph-derive`'s `tests/write_grant/`.
#[test]
fn no_clock_lands_a_sibling_clocks_store() {
  let emitted = tight(&granting());
  for (context, forbidden) in [
    ("ReaperHourlyGrants", "media::Transcript"),
    ("ReaperNightlyGrants", "media::Media"),
    ("ReaperNightlyGrants", "media::KeyframeVec"),
  ] {
    let lands = format!("::ingraph::__private::drive::AsyncLands<{forbidden}>");
    assert!(
      !emitted.contains(&format!("{lands}for{context}<")),
      "`{context}` mints no socket for `{forbidden}`: {emitted}"
    );
  }
}

/// Each clock's constructor takes that clock's handles in the order its entry granted them, which is
/// what makes the word's order the author's own to read back.
#[test]
fn each_context_takes_its_own_handles_in_declaration_order() {
  let emitted = tight(&granting());
  for expected in [
    "constfnnew(media:MediaHandle,keyframe_vec:KeyframeVecHandle)->Self",
    "constfnnew(transcript:TranscriptHandle)->Self",
  ] {
    assert!(emitted.contains(expected), "{expected}: {emitted}");
  }
}

/// The LENDING holds one field per granting clock, named by the word that clock minted, and its
/// constructor takes the clocks' contexts in declaration order.
#[test]
fn the_lending_holds_one_context_per_granting_clock() {
  let model = granting();
  let file = emission(&model);
  let lending = struct_named(&file, &default_polling_name(&model.record).to_string());

  assert_eq!(
    lending
      .fields
      .iter()
      .map(|field| field.ident.as_ref().expect("a named field").to_string())
      .collect::<Vec<_>>(),
    ["hourly", "nightly"],
  );
  // Its parameters are every clock's, in declaration order — which is what makes the lending's own
  // `new` read as the declaration reads.
  assert_eq!(
    lending
      .generics
      .type_params()
      .map(|param| param.ident.to_string())
      .collect::<Vec<_>>(),
    ["MediaHandle", "KeyframeVecHandle", "TranscriptHandle"],
  );
  assert!(
    tight(&model).contains(
      "constfnnew(hourly:ReaperHourlyGrants<MediaHandle,KeyframeVecHandle>,nightly:\
       ReaperNightlyGrants<TranscriptHandle>)->Self"
    ),
    "{}",
    tight(&model),
  );
}

/// The SWEEP TRAIT: **one entry per CLOCK**, named by that clock's own word, each taking that
/// clock's context and NO position — the entry IS the clock, so there is nothing left to tell apart.
///
/// A clock that granted nothing still has an entry, taking no context: once a node has any grant the
/// lending is its WHOLE sweep seam, so a clock without an entry would be a tick with nowhere to go.
#[test]
fn the_sweep_trait_seats_one_entry_per_clock() {
  let mut model = granting();
  // An UNGRANTED clock, declared FIRST — the shape that has to have an entry and be lent nothing.
  let Some(polls) = model.polls.as_mut() else {
    panic!("the fixture declares clocks");
  };
  polls.entries.insert(0, entry("watch", &[]));
  let emitted = tight(&model);
  let named = default_sweeps_name(&model.record).to_string();

  assert!(
    emitted.contains(&format!(
      "trait{named}<MediaHandle,KeyframeVecHandle,TranscriptHandle>"
    )),
    "{emitted}"
  );
  for expected in [
    // The GRANTED clocks take their own context…
    "fnhourly(&mutself,grants:&mutReaperHourlyGrants<MediaHandle,KeyframeVecHandle>)->",
    "fnnightly(&mutself,grants:&mutReaperNightlyGrants<TranscriptHandle>)->",
    // …and the ungranted one takes nothing, which is what it was lent.
    "fnwatch(&mutself)->",
  ] {
    assert!(emitted.contains(expected), "{expected}: {emitted}");
  }
  // ONE `Info` and ONE `Error` for the node, because the resident has one observation stream: two
  // clocks answering in two types is not a thing that can be true, so it is not a thing that can be
  // written.
  assert_eq!(emitted.matches("typeInfo;").count(), 1, "{emitted}");
  assert_eq!(emitted.matches("typeError;").count(), 1, "{emitted}");
  // And no position reaches an entry — the argument that used to tell the clocks apart is gone.
  assert!(
    !emitted.contains("PollUpstream,)->impl::core::future"),
    "{emitted}"
  );
}

/// The RUNTIME SEAM: the LENDING implements `Seats`, routing a tick's position to the entry that owns
/// it — **every clock has an arm**, and the positions are the WHOLE SCHEDULE's.
///
/// The ungranted clock is declared FIRST on purpose, and it is two claims at once: a route keyed on
/// the granting subset would send `hourly`'s tick to position 0, and a route that arms only the
/// granting clocks would leave position 0 to fall through to the catch-all — a panic on a tick the
/// declaration plainly asked for.
#[test]
fn the_lending_routes_every_clocks_position_to_its_entry() {
  let mut model = granting();
  let Some(polls) = model.polls.as_mut() else {
    panic!("the fixture declares clocks");
  };
  polls.entries.insert(0, entry("watch", &[]));
  let emitted = tight(&model);

  assert!(
    emitted.contains(
      "impl<O,MediaHandle,KeyframeVecHandle,TranscriptHandle>::ingraph::__private::drive::Seats<O>\
       forReaperPolling<MediaHandle,KeyframeVecHandle,TranscriptHandle>"
    ),
    "{emitted}"
  );
  // Every arm answers `Swept::Ran`, which is what an INLINE mode means at this seam: the body ran
  // here, so its own answer is the seat's.
  let sweeps = "<Oas ReaperSweeps<MediaHandle,KeyframeVecHandle,TranscriptHandle>>";
  let ran = ".map(::ingraph::__private::drive::Swept::Ran),";
  // The UNGRANTED clock keeps position 0 and is called with no context.
  // The granting clocks sit at 1 and 2, each handed its own field.
  for expected in [
    format!("matchsource.index(){{0usize=>{sweeps}::watch(operator).await{ran}"),
    format!("1usize=>{sweeps}::hourly(operator,&mutself.hourly).await{ran}"),
    format!("2usize=>{sweeps}::nightly(operator,&mutself.nightly).await{ran}"),
  ] {
    let expected = expected.replace(' ', "");
    assert!(emitted.contains(&expected), "{expected}: {emitted}");
  }
  // The lending holds only the GRANTING clocks — an ungranted one has nothing to be lent.
  assert!(
    emitted.contains("structReaperPolling<MediaHandle,KeyframeVecHandle,TranscriptHandle>"),
    "{emitted}"
  );
  assert!(!emitted.contains("watch:ReaperWatchGrants"), "{emitted}");
  // The answers are the sweep trait's, projected — one `Info` and one `Error` for the node.
  assert!(
    emitted.contains(
      "typeError=<Oas ReaperSweeps<MediaHandle,KeyframeVecHandle,TranscriptHandle>>::Error;"
        .replace(' ', "")
        .as_str()
    ),
    "{emitted}"
  );
}

/// The launch's half: one `Grant::of::<Node>` per grant, carrying the CLOCK that holds it and the
/// path the declaration wrote — the diagnostic names, the join running on the identity.
#[test]
fn the_facts_impl_carries_one_grant_per_granted_store_naming_its_clock() {
  let emitted = tight(&granting());
  assert!(
    emitted.contains(
      "constGRANTS:&'static[::ingraph::__private::drive::Grant]=&[::ingraph::__private::drive::Grant::of::<media::Media>\
       (\"hourly\",\"media::Media\"),::ingraph::__private::drive::Grant::of::<media::KeyframeVec>(\"hourly\",\
       \"media::KeyframeVec\"),::ingraph::__private::drive::Grant::of::<media::Transcript>(\"nightly\",\
       \"media::Transcript\"),]"
    ),
    "{emitted}"
  );
}

/// TWO CLOCKS GRANTED ONE STORE is legal — the ruling's explicit repetition — and mints two
/// contexts, each with its own handle parameter.
///
/// The second clock's parameter is QUALIFIED by that clock's word, because both end up on the
/// lending and two parameters cannot share a name. Nothing about the first one changes, so the
/// common declaration keeps reading as it did.
#[test]
fn one_store_granted_by_two_clocks_mints_two_contexts_and_two_handles() {
  let mut model = model("Reaper", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![
      entry("hourly", &["media::Media"]),
      entry("nightly", &["media::Media"]),
    ],
  });
  let emitted = tight(&model);

  assert!(
    emitted.contains("structReaperHourlyGrants<MediaHandle>")
      && emitted.contains("structReaperNightlyGrants<NightlyMediaHandle>"),
    "{emitted}"
  );
  assert!(
    emitted.contains("structReaperPolling<MediaHandle,NightlyMediaHandle>"),
    "{emitted}"
  );
  // Two grants and two rows on the launch's table, told apart by the clock that wrote each.
  assert!(
    emitted.contains("Grant::of::<media::Media>(\"hourly\",\"media::Media\")")
      && emitted.contains("Grant::of::<media::Media>(\"nightly\",\"media::Media\")"),
    "{emitted}"
  );
}

/// A node whose clocks granted nothing emits NO CONTEXT and a SEALED lending — the threshold the
/// mode words widened, and the empty-struct law at the bottom of it.
///
/// The lending is what changed. It used to be conditional on a grant; every polling node has one
/// now, because every clock declares where it runs and something has to route that. With nothing to
/// hold it is `Plain Polling(())` — a value a deployment can build and hand over, so
/// `Resident::polling` takes the same kind of thing from every polling node and a later `write` or
/// `handler` word is a field rather than a new type.
///
/// The sweep trait IS emitted, because this clock mounted nothing: the presence split is about
/// mounts, and an unmounted clock is a method an author writes.
#[test]
fn a_node_with_no_grant_lends_the_sealed_empty_struct() {
  let mut model = model("Plain", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![entry("watch", &[])],
  });
  let file = emission(&model);
  let absent = poll_grants_name(&model.record, &format_ident!("Watch")).to_string();
  assert!(
    !file.items.iter().any(|item| matches!(
      item,
      syn::Item::Struct(item) if item.ident == absent
    )),
    "`{absent}` is not emitted for a clock that was granted nothing"
  );
  let emitted = tight(&model);
  assert!(
    emitted.contains("pubstructPlainPolling(());"),
    "the sealed lending: {emitted}"
  );
  assert!(
    emitted.contains("pubconstfnnew()->Self{Self(())}"),
    "the empty-struct law's constructor: {emitted}"
  );
  assert!(
    emitted.contains(&default_sweeps_name(&model.record).to_string()),
    "an unmounted clock is still a sweep entry: {emitted}"
  );
  assert!(
    emitted.contains("constGRANTS:&'static[::ingraph::__private::drive::Grant]=&[];"),
    "{emitted}",
  );
}

/// A node whose EVERY clock mounts a citizen emits NO SWEEP TRAIT — the presence law at its edge.
///
/// Not tidiness. An empty trait is a seam an author is invited to implement and can say nothing
/// through, and a trait carrying only `Info` and `Error` for bodies that live somewhere else is
/// exactly that. What the node still gets is the lending and its route, which is where the mounted
/// bodies are reached.
#[test]
fn an_all_mounted_node_emits_no_sweep_trait() {
  let mut model = model("Exporter", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![
      running("scrape", &[], PollMode::AsyncInline, Some("app::Scraper")),
      running("push", &[], PollMode::Block, Some("app::Pusher")),
    ],
  });
  let emitted = tight(&model);

  assert!(
    !emitted.contains(&default_sweeps_name(&model.record).to_string()),
    "{emitted}"
  );
  // The apparatus is still there, and it holds the two citizens.
  assert!(
    emitted.contains("pubstructExporterPolling{"),
    "the lending: {emitted}"
  );
  assert!(
    emitted.contains("scrape_handler:app::Scraper,")
      && emitted.contains("push_handler:app::Pusher,"),
    "the citizens: {emitted}"
  );
  // The node's ONE pair is anchored on the first INLINE citizen, which is what makes the arms
  // unify: a concrete citizen's `Info` normalizes to what its impl said, and a projection over the
  // operator's own trait does not.
  assert!(
    emitted.contains("typeInfo=<app::Scraperas::ingraph::__private::drive::AsyncTick<()>>::Info;"),
    "the anchor: {emitted}"
  );
}

/// A MIXED node keeps its sweep trait, and the trait holds the unmounted clock alone.
#[test]
fn a_mounted_clock_leaves_the_sweep_trait() {
  let mut model = model("Exporter", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![
      running("scrape", &[], PollMode::AsyncInline, Some("app::Scraper")),
      entry("watch", &[]),
    ],
  });
  let emitted = tight(&model);

  assert!(emitted.contains("pubtraitExporterSweeps{"), "{emitted}");
  assert!(emitted.contains("fnwatch(&mutself)->"), "{emitted}");
  assert!(
    !emitted.contains("fnscrape("),
    "a mounted clock is not a sweep entry: {emitted}"
  );
  // And the operator's own pair is bound to the citizen's, which is the one-answer law reaching
  // across the split.
  assert!(
    emitted.contains(
      "O:ExporterSweeps<Info=<app::Scraperas::ingraph::__private::drive::AsyncTick<()>>::Info,\
       Error=<app::Scraperas::ingraph::__private::drive::AsyncTick<()>>::Error>"
    ),
    "{emitted}"
  );
}

/// The DETACHED words select the shipped citizens as DEFAULTS, and a deployment displaces one by
/// naming another type — no vocabulary word per engine.
///
/// The parameter ORDER is the other claim: `async(spawn)` names a runtime the framework cannot
/// guess, so its parameter carries no default and has to stand before the two that do.
#[test]
fn the_detached_words_default_to_the_shipped_citizens() {
  let mut model = model("Exporter", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![
      running("threaded", &[], PollMode::Spawn, Some("app::Scraper")),
      running("pooled", &[], PollMode::Rayon, Some("app::Scraper")),
      running("tasked", &[], PollMode::AsyncSpawn, Some("app::Scraper")),
    ],
  });
  let emitted = tight(&model);

  assert!(
    emitted.contains(
      "pubstructExporterPolling<TaskedExecutor,ThreadedExecutor=::ingraph::__private::drive::Thread,\
       PooledExecutor=::ingraph::__private::drive::Rayon>"
    ),
    "{emitted}"
  );
  // Each executor is a FIELD, so naming a third-party pool in `new` is the whole of installing one.
  for held in [
    "threaded_executor:ThreadedExecutor,",
    "pooled_executor:PooledExecutor,",
    "tasked_executor:TaskedExecutor,",
  ] {
    assert!(emitted.contains(held), "{held}: {emitted}");
  }
  // The two seams are told apart by the bound the route states, not by the word.
  assert!(
    emitted.contains("ThreadedExecutor:::ingraph::__private::drive::Spawn+::core::marker::Send")
      && emitted
        .contains("TaskedExecutor:::ingraph::__private::drive::AsyncSpawn+::core::marker::Send"),
    "{emitted}"
  );
}

/// AT MOST ONE IN FLIGHT is a FIELD, and `concurrent` is what removes it.
///
/// The cell is also what costs the constructor its `const`: an `Arc` is not a thing a const context
/// allocates. A node whose clocks all overlap freely keeps the plain constructor, which is why the
/// decision is per node rather than dropped everywhere.
#[test]
fn the_at_most_one_cell_is_the_default_and_concurrent_removes_it() {
  let mut model = model("Exporter", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![running(
      "threaded",
      &[],
      PollMode::Spawn,
      Some("app::Scraper"),
    )],
  });
  let guarded = tight(&model);
  assert!(
    guarded.contains("threaded_in_flight:::ingraph::__private::drive::AtMostOne,"),
    "{guarded}"
  );
  assert!(
    guarded.contains("pubfnnew(threaded_handler:app::Scraper,threaded_executor:ThreadedExecutor)"),
    "the cell is not an argument, and the constructor is no longer const: {guarded}"
  );

  let Some(polls) = model.polls.as_mut() else {
    panic!("the fixture declares a clock");
  };
  polls.entries[0].concurrent = true;
  let free = tight(&model);
  assert!(!free.contains("threaded_in_flight"), "{free}");
  assert!(
    free
      .contains("pubconstfnnew(threaded_handler:app::Scraper,threaded_executor:ThreadedExecutor)"),
    "with no cell the constructor is const again: {free}"
  );
}

/// A BLOCKING sweep entry is a plain `fn`, and an inline async one answers a future — the dual-mode
/// law reaching the trait an author implements.
#[test]
fn the_mode_word_decides_the_sweep_entrys_face() {
  let mut model = model("Exporter", &["media_id"], "id");
  model.polls = Some(Polls {
    entries: vec![
      running("here", &[], PollMode::Block, None),
      running("awaited", &[], PollMode::AsyncInline, None),
    ],
  });
  let emitted = tight(&model);

  assert!(
    emitted.contains("fnhere(&mutself)->::core::result::Result<Self::Info,Self::Error>;"),
    "{emitted}"
  );
  assert!(
    emitted.contains("fnawaited(&mutself)->impl::core::future::Future<"),
    "{emitted}"
  );
  // And the route awaits exactly the one that answers a future.
  assert!(
    emitted.contains("0usize=><OasExporterSweeps>::here(operator).map("),
    "{emitted}"
  );
  assert!(
    emitted.contains("1usize=><OasExporterSweeps>::awaited(operator).await.map("),
    "{emitted}"
  );
}