troupekit-macros 0.3.2

Attribute macros #[tool] and #[agent] for the Troupekit LLM agent framework, built on the compiler proc_macro crate only.
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
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
use crate::args::{parse_args, split_top_level, Arg};
use crate::doc::doc_text;
use crate::item::{parse_fn, Attr};
use crate::lit::quote_str;
use crate::tokens::{Delim, Error, Piece, SpanId, Tok};
use crate::tool::crate_path;

const WHAT: &str = "#[agent]";
const KEYS: [&str; 25] = [
    "model",
    "tools",
    "evals",
    "limits",
    "checkpoints",
    "max_turns",
    "max_tokens",
    "retries",
    "role",
    "goal",
    "display_name",
    "instructions",
    "laws",
    "auto_laws",
    "memory",
    "knowledge",
    "name",
    "crate",
    "trace",
    "trace_content",
    "local",
    "download",
    "route",
    "private",
    "tier",
];
const TRACE_MESSAGE: &str = "trace = takes all or a list like [Tools, Laws]";
const DEFAULT_CRATE: &str = "::troupekit";

/// One builder call the `#[agent]` expansion makes: the method name and
/// the value pieces passed to it, original tokens keeping their spans.
/// Calls run in attribute order, after `new` and `instructions`.
#[derive(Clone, Debug)]
pub struct Call {
    pub method: &'static str,
    pub value: Vec<Piece>,
}

/// A validated `#[agent]` fn, ready for code generation.
/// `name` is the persona name, `instructions` the doc comment unless an
/// `instructions` key replaces it. `calls` holds every other key.
#[derive(Clone, Debug)]
pub struct AgentFn {
    pub attrs: Vec<Attr>,
    pub vis: Vec<SpanId>,
    pub ident_span: SpanId,
    pub name: String,
    pub instructions: Option<String>,
    pub calls: Vec<Call>,
    pub krate: String,
}

/// Parses `#[agent(attr)]` on `item` into an `AgentFn`.
/// The fn must be `fn name() {}`; every key is checked for its value
/// shape and every unsupported input fails with its documented message.
pub fn parse_agent(attr: &[Tok], item: &[Tok]) -> Result<AgentFn, Error> {
    let args = parse_args(attr, WHAT)?;
    for arg in &args {
        if !KEYS.contains(&arg.key.as_str()) {
            return Err(Error::new(
                arg.key_span,
                format!(
                    "unknown {WHAT} key `{}`; known keys: {}",
                    arg.key,
                    KEYS.join(", ")
                ),
            ));
        }
    }
    let f = parse_fn(item, WHAT)?;
    if let Some((word, span)) = f.quals.first() {
        let message = if word == "async" {
            format!("{WHAT} fn cannot be async")
        } else {
            format!("{WHAT} fn cannot be const, unsafe or extern")
        };
        return Err(Error::new(*span, message));
    }
    if let Some(span) = f.generics.or(f.where_span) {
        return Err(Error::new(span, format!("{WHAT} fn cannot be generic")));
    }
    let extra = f
        .params
        .first()
        .or(f.ret.first())
        .map(Tok::span)
        .or_else(|| (!f.body.is_empty()).then_some(f.body_span));
    if let Some(span) = extra {
        return Err(Error::new(
            span,
            format!("{WHAT} fn must take no arguments, return nothing and have an empty body {{}}; configure it with attribute keys or use Agent::new"),
        ));
    }
    let ident = f.ident.strip_prefix("r#").unwrap_or(&f.ident);
    let valid_ident = ident
        .chars()
        .next()
        .is_some_and(|c| c.is_ascii_lowercase() || c.is_ascii_digit())
        && ident
            .chars()
            .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_');
    let mut name = ident.replace('_', "-");
    let mut instructions = None;
    let mut krate = DEFAULT_CRATE.to_string();
    let mut name_set = false;
    let mut calls = Vec::new();
    let mut trace_at = None;
    for arg in &args {
        let spans = || orig(&arg.value);
        match arg.key.as_str() {
            "name" => {
                name = arg.string(WHAT)?;
                name_set = true;
            }
            "crate" => krate = crate_path(arg, WHAT)?,
            "instructions" => instructions = Some(arg.string(WHAT)?),
            "model" | "role" | "goal" | "display_name" => {
                arg.string(WHAT)?;
                calls.push(Call {
                    method: method(&arg.key),
                    value: spans(),
                });
            }
            "tools" => {
                for path in list(arg, "tools = takes a list like [add, math::mul]")? {
                    if !is_path(&path) {
                        return Err(Error::new(
                            path[0].span(),
                            "tools = takes a list like [add, math::mul]",
                        ));
                    }
                    calls.push(Call {
                        method: "tool",
                        value: orig(&path),
                    });
                }
            }
            "evals" => {
                let message = "evals = takes a list of string literals";
                for entry in list(arg, message)? {
                    if !matches!(entry.as_slice(), [Tok::Lit(l, _)] if l.starts_with('"') || l.starts_with('r'))
                    {
                        return Err(Error::new(entry[0].span(), message));
                    }
                    calls.push(Call {
                        method: "eval",
                        value: orig(&entry[..1]),
                    });
                }
            }
            "laws" => {
                let entries = match arg.value.as_slice() {
                    [Tok::Group(Delim::Bracket, ..)] => list(arg, "")?,
                    _ => vec![arg.value.clone()],
                };
                for entry in entries {
                    let one = Arg {
                        key: arg.key.clone(),
                        key_span: arg.key_span,
                        value: entry,
                    };
                    one.string(WHAT)?;
                    calls.push(Call {
                        method: "laws",
                        value: orig(&one.value),
                    });
                }
            }
            "auto_laws" => {
                if !matches!(arg.value.as_slice(), [t] if t.is_ident("true") || t.is_ident("false"))
                {
                    return Err(Error::new(
                        arg.value_span(),
                        "auto_laws = takes true or false",
                    ));
                }
                calls.push(Call {
                    method: "auto_laws",
                    value: spans(),
                });
            }
            "trace" => {
                trace_at = Some((calls.len(), arg));
                calls.push(Call {
                    method: "trace",
                    value: Vec::new(),
                });
            }
            "trace_content" | "private" | "download" => {
                if !is_bool(&arg.value) {
                    return Err(Error::new(
                        arg.value_span(),
                        format!("{} = takes true or false", arg.key),
                    ));
                }
                calls.push(Call {
                    method: method(&arg.key),
                    value: spans(),
                });
            }
            "route" => calls.push(Call {
                method: if is_string(&arg.value) { "route_file" } else { "route" },
                value: spans(),
            }),
            "tier" => {
                arg.string(WHAT)?;
                calls.push(Call {
                    method: "tier",
                    value: spans(),
                });
            }
            _ => calls.push(Call {
                method: method(&arg.key),
                value: spans(),
            }),
        }
    }
    if let Some((at, arg)) = trace_at {
        assert_eq!(calls[at].method, "trace", "the placeholder is in place");
        calls[at] = trace_call(arg, &krate)?;
    }
    if !name_set && !valid_ident {
        return Err(Error::new(
            f.ident_span,
            "agent name must be lowercase ASCII letters, digits and _",
        ));
    }
    if instructions.is_none() {
        let attrs: Vec<Vec<Tok>> = f.attrs.iter().map(|a| a.inner.clone()).collect();
        instructions = doc_text(&attrs, "#[agent] instructions")?;
    }
    if instructions.is_none() {
        return Err(Error::new(
            f.ident_span,
            format!("{WHAT} needs a /// doc comment or instructions = \"...\"; it becomes the instructions"),
        ));
    }
    Ok(AgentFn {
        attrs: f.attrs,
        vis: f.vis,
        ident_span: f.ident_span,
        name,
        instructions,
        calls,
        krate,
    })
}

/// Generates `vis fn name() -> Agent { Agent::new(..).instructions(..)... }`
/// for a parsed `#[agent]` fn. Attributes, doc comments included, stay
/// on the fn. Returns the pieces in output order.
pub fn expand_agent(a: &AgentFn) -> Vec<Piece> {
    let p = format!("{}::__private", a.krate);
    let mut out: Vec<Piece> = a
        .attrs
        .iter()
        .flat_map(|at| [Piece::Orig(at.hash), Piece::Orig(at.group)])
        .collect();
    out.extend(a.vis.iter().map(|s| Piece::Orig(*s)));
    out.push(Piece::Code("fn".into()));
    out.push(Piece::Orig(a.ident_span));
    out.push(Piece::Code(format!("() -> {p}::Agent")));
    let instructions = a
        .instructions
        .as_deref()
        .expect("parse_agent sets instructions");
    let mut body = vec![Piece::Code(format!(
        "{p}::Agent::new({}).instructions({})",
        quote_str(&a.name),
        quote_str(instructions)
    ))];
    for call in &a.calls {
        body.push(Piece::Code(format!(".{}", call.method)));
        body.push(Piece::Group(Delim::Paren, call.value.clone()));
    }
    out.push(Piece::Group(Delim::Brace, body));
    out
}

fn orig(toks: &[Tok]) -> Vec<Piece> {
    toks.iter().map(|t| Piece::Orig(t.span())).collect()
}

fn is_bool(toks: &[Tok]) -> bool {
    matches!(toks, [t] if t.is_ident("true") || t.is_ident("false"))
}

fn is_string(toks: &[Tok]) -> bool {
    matches!(toks, [Tok::Lit(l, _)] if l.starts_with('"') || l.starts_with('r'))
}

fn trace_call(arg: &Arg, krate: &str) -> Result<Call, Error> {
    if matches!(arg.value.as_slice(), [t] if t.is_ident("all")) {
        return Ok(Call {
            method: "tracing",
            value: vec![Piece::Code("true".into())],
        });
    }
    let mut inner = Vec::new();
    for (i, entry) in list(arg, TRACE_MESSAGE)?.iter().enumerate() {
        if !is_path(entry) {
            return Err(Error::new(entry[0].span(), TRACE_MESSAGE));
        }
        if i > 0 {
            inner.push(Piece::Code(",".into()));
        }
        if entry.len() == 1 {
            inner.push(Piece::Code(format!("{krate}::__private::trace::Trace::")));
        }
        inner.extend(orig(entry));
    }
    assert!(inner.iter().all(|p| !matches!(p, Piece::Group(..))));
    Ok(Call {
        method: "trace",
        value: vec![Piece::Group(Delim::Bracket, inner)],
    })
}

fn method(key: &str) -> &'static str {
    KEYS.iter()
        .copied()
        .find(|k| *k == key)
        .expect("keys are checked before methods are named")
}

fn list(arg: &Arg, message: &str) -> Result<Vec<Vec<Tok>>, Error> {
    let message = if message.is_empty() {
        format!("{WHAT} key `{}` takes a string literal", arg.key)
    } else {
        message.to_string()
    };
    match arg.value.as_slice() {
        [Tok::Group(Delim::Bracket, inner, _)] => Ok(split_top_level(inner)
            .into_iter()
            .filter(|e| !e.is_empty())
            .collect()),
        _ => Err(Error::new(arg.value_span(), message)),
    }
}

fn is_path(toks: &[Tok]) -> bool {
    let mut expect_ident = true;
    let mut i = 0usize;
    if toks.first().is_some_and(|t| t.is_punct(':')) {
        expect_ident = false;
    }
    while i < toks.len() {
        if expect_ident {
            if !matches!(toks[i], Tok::Ident(..)) {
                return false;
            }
            i += 1;
        } else {
            if !(toks[i].is_punct(':') && toks.get(i + 1).is_some_and(|t| t.is_punct(':'))) {
                return false;
            }
            i += 2;
        }
        expect_ident = !expect_ident;
    }
    !toks.is_empty() && !expect_ident
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::lex::lex;

    const DOC: &str = "/// Adds numbers.\n";

    fn parse(attr: &str, item: &str) -> Result<AgentFn, Error> {
        parse_agent(&lex(attr), &lex(item))
    }

    fn methods(a: &AgentFn) -> Vec<&'static str> {
        a.calls.iter().map(|c| c.method).collect()
    }

    #[test]
    fn memory_and_knowledge_keys_become_builder_calls() {
        let a = parse(
            "model = \"m/x\", memory = mem(1), knowledge = \"docs\"",
            &format!("{DOC}fn calc() {{}}"),
        )
        .unwrap();
        assert_eq!(methods(&a), ["model", "memory", "knowledge"]);
        assert_eq!(a.calls[1].value.len(), 2);
    }

    fn rejects(attr: &str, item: &str, message: &str) -> Error {
        let err = parse(attr, item).unwrap_err();
        assert_eq!(err.message, message, "{attr} {item}");
        err
    }

    #[test]
    fn parses_every_key() {
        let attr = "model = \"openai/gpt-6-luna\", tools = [add], evals = [\"min_items(x, 1)\"], \
            limits = Limits::default(), checkpoints = Storage::memory(), max_turns = 4, \
            max_tokens = 100, retries = 1, role = \"R\", goal = \"G\", display_name = \"D\", \
            instructions = \"I\", laws = [\"a.bend\", \"b.bend\"], auto_laws = false, \
            name = \"adder\", crate = \"::kit\", trace = all, trace_content = true, \
            local = \"qwen\", download = true, route = \"route.toml\", private = true, \
            tier = \"small\",";
        let a = parse(attr, "fn calc() {}").unwrap();
        assert_eq!(a.name, "adder");
        assert_eq!(a.instructions.as_deref(), Some("I"));
        assert_eq!(a.krate, "::kit");
        assert_eq!(
            methods(&a),
            [
                "model",
                "tool",
                "eval",
                "limits",
                "checkpoints",
                "max_turns",
                "max_tokens",
                "retries",
                "role",
                "goal",
                "display_name",
                "laws",
                "laws",
                "auto_laws",
                "tracing",
                "trace_content",
                "local",
                "download",
                "route_file",
                "private",
                "tier"
            ]
        );
        assert_eq!(a.calls[3].value.len(), 5);
    }

    #[test]
    fn tools_list_keeps_paths() {
        let a = parse(
            "tools = [add, math::mul, ::ext::div,]",
            &format!("{DOC}fn calc() {{}}"),
        )
        .unwrap();
        let lens: Vec<usize> = a.calls.iter().map(|c| c.value.len()).collect();
        assert_eq!(lens, [1, 4, 6]);
        rejects(
            "tools = add",
            &format!("{DOC}fn calc() {{}}"),
            "tools = takes a list like [add, math::mul]",
        );
        rejects(
            "tools = [add()]",
            &format!("{DOC}fn calc() {{}}"),
            "tools = takes a list like [add, math::mul]",
        );
        rejects(
            "tools = [\"add\"]",
            &format!("{DOC}fn calc() {{}}"),
            "tools = takes a list like [add, math::mul]",
        );
    }

    #[test]
    fn evals_must_be_string_literals() {
        let a = parse(
            "evals = [\"a(1)\", r\"b(2)\"]",
            &format!("{DOC}fn calc() {{}}"),
        )
        .unwrap();
        assert_eq!(methods(&a), ["eval", "eval"]);
        rejects(
            "evals = [a]",
            &format!("{DOC}fn calc() {{}}"),
            "evals = takes a list of string literals",
        );
        rejects(
            "evals = \"a\"",
            &format!("{DOC}fn calc() {{}}"),
            "evals = takes a list of string literals",
        );
    }

    #[test]
    fn fn_name_maps_underscore_to_dash() {
        let a = parse("", &format!("{DOC}pub fn web_researcher_2() {{}}")).unwrap();
        assert_eq!(a.name, "web-researcher-2");
        assert_eq!(a.instructions.as_deref(), Some("Adds numbers."));
        assert_eq!(a.krate, "::troupekit");
    }

    #[test]
    fn expansion_builds_on_agent_new() {
        let item = lex(&format!("{DOC}pub fn calc() {{}}"));
        let attr = lex("model = \"m/x\", tools = [add]");
        let a = parse_agent(&attr, &item).unwrap();
        let pieces = expand_agent(&a);
        let code: Vec<String> = pieces
            .iter()
            .filter_map(|p| match p {
                Piece::Code(s) => Some(s.clone()),
                Piece::Group(_, inner) => Some(
                    inner
                        .iter()
                        .filter_map(|q| match q {
                            Piece::Code(s) => Some(s.clone()),
                            _ => None,
                        })
                        .collect::<Vec<_>>()
                        .join(""),
                ),
                Piece::Orig(_) => None,
            })
            .collect();
        assert_eq!(code[0], "fn");
        assert_eq!(code[1], "() -> ::troupekit::__private::Agent");
        assert_eq!(
            code[2],
            "::troupekit::__private::Agent::new(\"calc\").instructions(\"Adds numbers.\").model.tool"
        );
    }

    #[test]
    fn rejects_non_fn() {
        rejects("", "struct S;", "#[agent] goes on a fn");
    }

    #[test]
    fn rejects_arguments_return_and_body() {
        let message = "#[agent] fn must take no arguments, return nothing and have an empty body {}; configure it with attribute keys or use Agent::new";
        let item = lex(&format!("{DOC}fn calc(a: i64) {{}}"));
        let err = parse_agent(&[], &item).unwrap_err();
        assert_eq!(err.message, message);
        rejects("", &format!("{DOC}fn calc() -> Agent {{}}"), message);
        rejects("", &format!("{DOC}fn calc() {{ todo!() }}"), message);
    }

    #[test]
    fn rejects_async() {
        rejects(
            "",
            &format!("{DOC}async fn calc() {{}}"),
            "#[agent] fn cannot be async",
        );
    }

    #[test]
    fn rejects_generic() {
        rejects(
            "",
            &format!("{DOC}fn calc<T>() {{}}"),
            "#[agent] fn cannot be generic",
        );
        rejects(
            "",
            &format!("{DOC}fn calc() where u8: Copy {{}}"),
            "#[agent] fn cannot be generic",
        );
    }

    #[test]
    fn rejects_missing_doc() {
        let item = lex("fn calc() {}");
        let err = parse_agent(&[], &item).unwrap_err();
        assert_eq!(err.message, "#[agent] needs a /// doc comment or instructions = \"...\"; it becomes the instructions");
        assert_eq!(err.span, item[1].span());
    }

    #[test]
    fn rejects_bad_name() {
        let item = lex(&format!("{DOC}fn Calc() {{}}"));
        let err = parse_agent(&[], &item).unwrap_err();
        assert_eq!(
            err.message,
            "agent name must be lowercase ASCII letters, digits and _"
        );
        assert_eq!(err.span, item[3].span());
        rejects(
            "",
            &format!("{DOC}fn _calc() {{}}"),
            "agent name must be lowercase ASCII letters, digits and _",
        );
        assert!(parse("name = \"calc\"", &format!("{DOC}fn Calc() {{}}")).is_ok());
    }

    #[test]
    fn rejects_unknown_key() {
        rejects("x = 1", &format!("{DOC}fn calc() {{}}"), "unknown #[agent] key `x`; known keys: model, tools, evals, limits, checkpoints, max_turns, max_tokens, retries, role, goal, display_name, instructions, laws, auto_laws, memory, knowledge, name, crate, trace, trace_content, local, download, route, private, tier");
    }

    #[test]
    fn rejects_duplicate_key() {
        rejects(
            "model = \"a/b\", model = \"a/c\"",
            &format!("{DOC}fn calc() {{}}"),
            "#[agent] key `model` is set twice",
        );
    }

    #[test]
    fn rejects_non_string_value() {
        rejects(
            "model = gpt",
            &format!("{DOC}fn calc() {{}}"),
            "#[agent] key `model` takes a string literal",
        );
        rejects(
            "laws = [rules]",
            &format!("{DOC}fn calc() {{}}"),
            "#[agent] key `laws` takes a string literal",
        );
    }

    fn code_of(pieces: &[Piece]) -> String {
        pieces
            .iter()
            .map(|p| match p {
                Piece::Code(s) => s.clone(),
                Piece::Orig(_) => "#".into(),
                Piece::Group(_, inner) => format!("[{}]", code_of(inner)),
            })
            .collect()
    }

    #[test]
    fn trace_all_and_list_become_builder_calls() {
        let item = format!("{DOC}fn calc() {{}}");
        let all = parse("trace = all", &item).unwrap();
        assert_eq!(methods(&all), ["tracing"]);
        assert_eq!(code_of(&all.calls[0].value), "true");
        let list = parse(
            "trace = [Tools, Trace::Laws, ::x::Trace::Agents], crate = \"::kit\"",
            &item,
        )
        .unwrap();
        assert_eq!(methods(&list), ["trace"]);
        assert_eq!(
            code_of(&list.calls[0].value),
            "[::kit::__private::trace::Trace::#,####,#########]"
        );
        let empty = parse("trace = []", &item).unwrap();
        assert_eq!(code_of(&empty.calls[0].value), "[]");
        for bad in ["trace = true", "trace = \"all\"", "trace = [1]", "trace = none"] {
            rejects(bad, &item, TRACE_MESSAGE);
        }
    }

    #[test]
    fn local_and_route_accept_literal_or_expression() {
        let item = format!("{DOC}fn calc() {{}}");
        let a = parse(
            "local = \"qwen\", route = \"route.toml\", tier = \"small\"",
            &item,
        )
        .unwrap();
        assert_eq!(methods(&a), ["local", "route_file", "tier"]);
        let b = parse("local = my_model(), route = office_policy()", &item).unwrap();
        assert_eq!(methods(&b), ["local", "route"]);
        assert_eq!(b.calls[0].value.len(), 2);
        rejects("tier = small", &item, "#[agent] key `tier` takes a string literal");
        for key in ["private", "trace_content", "download"] {
            rejects(
                &format!("{key} = maybe"),
                &item,
                &format!("{key} = takes true or false"),
            );
        }
        let flags = parse("private = false, download = false", &item).unwrap();
        assert_eq!(methods(&flags), ["private", "download"]);
    }

    #[test]
    fn rejects_bad_auto_laws() {
        rejects(
            "auto_laws = yes",
            &format!("{DOC}fn calc() {{}}"),
            "auto_laws = takes true or false",
        );
    }
}