boxferry-model 0.1.1

Format-independent application model for BoxFerry
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
//! Provenance-aware image acquisition and build resources.
//!
//! These types describe application artifacts, not any one source or target format. A service's
//! runtime image remains distinct from the acquisition/build resources that produce or obtain it.

use crate::{Identifier, ProtectedString, Provenance, ResourceLimit, Sourced};

/// The generic syntax family that supplied a build declaration or per-key value collection.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum BuildSyntax {
    /// One short scalar declaration.
    Scalar,
    /// A structured declaration object.
    Structured,
    /// Mapping syntax for named values.
    Mapping,
    /// Sequence syntax for ordered values.
    Sequence,
    /// Repeated native assignment syntax.
    Repeated,
}

/// One typed collection belonging to one explicitly present image-artifact key.
///
/// The enclosing setting establishes that its key was present. Consequently, `values: []` is an
/// explicit empty/reset value, while omission is represented by the absence of that setting.
/// Repeated settings and values retain their declaration order and duplicate occurrences.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BuildSettingValues<T> {
    syntax: BuildSyntax,
    values: Vec<Sourced<T>>,
}

impl<T> BuildSettingValues<T> {
    /// Creates values for one explicitly present key.
    #[must_use]
    pub const fn new(syntax: BuildSyntax, values: Vec<Sourced<T>>) -> Self {
        Self { syntax, values }
    }

    /// Returns the source syntax family.
    #[must_use]
    pub const fn syntax(&self) -> BuildSyntax {
        self.syntax
    }

    /// Returns values in source order, including duplicates.
    #[must_use]
    pub fn values(&self) -> &[Sourced<T>] {
        &self.values
    }
}

/// One source-preserving assignment used by image artifact settings.
///
/// Empty and key-only assignments are retained for adapters to diagnose rather than discarded by
/// the neutral model. `ProtectedString` prevents interpolated names and values from leaking into
/// debug output.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ImageArtifactAssignment {
    name: ProtectedString,
    value: Option<ProtectedString>,
}

impl ImageArtifactAssignment {
    /// Creates a key-only or key/value assignment without applying native naming rules.
    #[must_use]
    pub const fn new(name: ProtectedString, value: Option<ProtectedString>) -> Self {
        Self { name, value }
    }

    /// Returns the preserved assignment name.
    #[must_use]
    pub const fn name(&self) -> &ProtectedString {
        &self.name
    }

    /// Returns the explicit value, if the source supplied one.
    #[must_use]
    pub const fn value(&self) -> Option<&ProtectedString> {
        self.value.as_ref()
    }
}

/// One named additional context in a structured source build declaration.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BuildContext {
    name: ProtectedString,
    value: ProtectedString,
}

impl BuildContext {
    /// Creates a named additional build context without applying native rules.
    #[must_use]
    pub const fn new(name: ProtectedString, value: ProtectedString) -> Self {
        Self { name, value }
    }

    /// Returns the declared context name.
    #[must_use]
    pub const fn name(&self) -> &ProtectedString {
        &self.name
    }

    /// Returns the raw-preserving context value.
    #[must_use]
    pub const fn value(&self) -> &ProtectedString {
        &self.value
    }
}

/// A source build-secret declaration whose options remain distinct from target build-secret text.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SourceBuildSecret {
    source: ProtectedString,
    target: Option<ProtectedString>,
    uid: Option<ProtectedString>,
    gid: Option<ProtectedString>,
    mode: Option<ProtectedString>,
}

impl SourceBuildSecret {
    /// Creates a source build-secret declaration without applying native validation.
    #[must_use]
    pub const fn new(source: ProtectedString) -> Self {
        Self {
            source,
            target: None,
            uid: None,
            gid: None,
            mode: None,
        }
    }

    /// Returns the preserved source name.
    #[must_use]
    pub const fn source(&self) -> &ProtectedString {
        &self.source
    }

    /// Sets the optional target name.
    pub fn set_target(&mut self, target: ProtectedString) {
        self.target = Some(target);
    }

    /// Returns the optional target name.
    #[must_use]
    pub const fn target(&self) -> Option<&ProtectedString> {
        self.target.as_ref()
    }

    /// Sets the optional UID spelling.
    pub fn set_uid(&mut self, uid: ProtectedString) {
        self.uid = Some(uid);
    }

    /// Returns the optional UID spelling.
    #[must_use]
    pub const fn uid(&self) -> Option<&ProtectedString> {
        self.uid.as_ref()
    }

    /// Sets the optional GID spelling.
    pub fn set_gid(&mut self, gid: ProtectedString) {
        self.gid = Some(gid);
    }

    /// Returns the optional GID spelling.
    #[must_use]
    pub const fn gid(&self) -> Option<&ProtectedString> {
        self.gid.as_ref()
    }

    /// Sets the optional mode spelling.
    pub fn set_mode(&mut self, mode: ProtectedString) {
        self.mode = Some(mode);
    }

    /// Returns the optional mode spelling.
    #[must_use]
    pub const fn mode(&self) -> Option<&ProtectedString> {
        self.mode.as_ref()
    }
}

/// A source build attestation value.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum BuildAttestation {
    /// Boolean form.
    Boolean(bool),
    /// Raw parameterized form.
    Value(ProtectedString),
}

/// One field from a structured source build declaration.
///
/// These concepts deliberately describe source declaration intent. They do not claim equivalence
/// to similarly named acquisition/build settings.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum SourceBuildSetting {
    /// Additional named contexts.
    AdditionalContexts(BuildSettingValues<BuildContext>),
    /// Build arguments.
    Arguments(BuildSettingValues<ImageArtifactAssignment>),
    /// Cache import locations.
    CacheFrom(BuildSettingValues<ProtectedString>),
    /// Cache export locations.
    CacheTo(BuildSettingValues<ProtectedString>),
    /// Build context.
    Context(ProtectedString),
    /// Build recipe path.
    RecipeFile(ProtectedString),
    /// Inline build recipe.
    InlineRecipe(ProtectedString),
    /// Build entitlements.
    Entitlements(BuildSettingValues<ProtectedString>),
    /// Extra host mappings.
    ExtraHosts(BuildSettingValues<ImageArtifactAssignment>),
    /// Isolation selection.
    Isolation(ProtectedString),
    /// Build metadata labels.
    Labels(BuildSettingValues<ImageArtifactAssignment>),
    /// Build network selection.
    Network(ProtectedString),
    /// Explicit no-cache choice.
    NoCache(bool),
    /// No-cache filters.
    NoCacheFilters(BuildSettingValues<ProtectedString>),
    /// Build platforms.
    Platforms(BuildSettingValues<ProtectedString>),
    /// Explicit privileged choice.
    Privileged(bool),
    /// Provenance attestation.
    Provenance(BuildAttestation),
    /// Explicit source-side pull choice.
    Pull(bool),
    /// SBOM attestation.
    Sbom(BuildAttestation),
    /// Source build secrets.
    Secrets(BuildSettingValues<SourceBuildSecret>),
    /// Shared-memory size spelling.
    ShmSize(ProtectedString),
    /// SSH declarations.
    Ssh(BuildSettingValues<ProtectedString>),
    /// Image tags.
    Tags(BuildSettingValues<ProtectedString>),
    /// Recipe target.
    Target(ProtectedString),
    /// Resource limits.
    Ulimits(BuildSettingValues<ResourceLimit>),
}

/// One source declaration for an image build.
///
/// A scalar context is not silently expanded into a structured declaration. Structured declarations
/// retain field order, duplicate fields, and explicitly present empty per-key collections.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum BuildSourceDeclaration {
    /// Short scalar context syntax.
    Scalar(ProtectedString),
    /// Structured declaration syntax.
    Structured(Vec<Sourced<SourceBuildSetting>>),
}

impl BuildSourceDeclaration {
    /// Returns the preserved source syntax family.
    #[must_use]
    pub const fn syntax(&self) -> BuildSyntax {
        match self {
            Self::Scalar(_) => BuildSyntax::Scalar,
            Self::Structured(_) => BuildSyntax::Structured,
        }
    }

    /// Returns structured settings in source order when this is a structured declaration.
    #[must_use]
    pub fn structured_settings(&self) -> Option<&[Sourced<SourceBuildSetting>]> {
        match self {
            Self::Scalar(_) => None,
            Self::Structured(settings) => Some(settings),
        }
    }
}

/// One image-acquisition setting.
///
/// The variants cover the full currently supported acquisition surface while keeping every value
/// target-independent: adapters decide which native key can encode a given setting.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ImageAcquisitionSetting {
    /// Artifact image source.
    Image(ProtectedString),
    /// Produced/acquired image tags.
    ImageTags(BuildSettingValues<ProtectedString>),
    /// Service-manager unit name.
    ServiceName(ProtectedString),
    /// Fetch all tags choice.
    AllTags(bool),
    /// Architecture selection.
    Architecture(ProtectedString),
    /// Authentication file.
    AuthFile(ProtectedString),
    /// Certificate directory.
    CertificateDirectory(ProtectedString),
    /// Containers configuration modules.
    ContainersConfigModules(BuildSettingValues<ProtectedString>),
    /// Credential text.
    Credentials(ProtectedString),
    /// Image decryption key.
    DecryptionKey(ProtectedString),
    /// Global runtime arguments.
    GlobalArguments(BuildSettingValues<ProtectedString>),
    /// Operating-system selection.
    OperatingSystem(ProtectedString),
}

/// An image-acquisition resource.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ImageAcquisition {
    name: Identifier,
    settings: Option<Vec<Sourced<ImageAcquisitionSetting>>>,
    settings_origins: Vec<Provenance>,
}

impl ImageAcquisition {
    /// Creates an empty acquisition resource.
    #[must_use]
    pub const fn new(name: Identifier) -> Self {
        Self {
            name,
            settings: None,
            settings_origins: Vec::new(),
        }
    }

    /// Returns the neutral resource name.
    #[must_use]
    pub const fn name(&self) -> &Identifier {
        &self.name
    }

    /// Sets acquisition settings, retaining explicit emptiness separately from omission.
    pub fn set_settings(&mut self, settings: Vec<Sourced<ImageAcquisitionSetting>>) {
        self.settings = Some(settings);
        self.settings_origins.clear();
    }

    /// Sets acquisition settings and their collection-level provenance.
    pub fn set_settings_with_origins(
        &mut self,
        settings: Vec<Sourced<ImageAcquisitionSetting>>,
        origins: Vec<Provenance>,
    ) {
        self.settings = Some(settings);
        self.settings_origins = origins;
    }

    /// Returns settings in source order, if explicitly present.
    #[must_use]
    pub fn settings(&self) -> Option<&[Sourced<ImageAcquisitionSetting>]> {
        self.settings.as_deref()
    }

    /// Returns acquisition collection provenance.
    #[must_use]
    pub fn settings_origins(&self) -> &[Provenance] {
        &self.settings_origins
    }
}

/// One image-build setting.
///
/// Fields that look similar to [`SourceBuildSetting`] remain separate: only an adapter with
/// target evidence may establish an exact or non-exact mapping between them.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ImageBuildSetting {
    /// Produced image tags.
    ImageTags(BuildSettingValues<ProtectedString>),
    /// Build network selection.
    Network(ProtectedString),
    /// Build labels.
    Labels(BuildSettingValues<ImageArtifactAssignment>),
    /// Build recipe file.
    RecipeFile(ProtectedString),
    /// Working-directory behavior spelling.
    SetWorkingDirectory(ProtectedString),
    /// Build recipe target.
    Target(ProtectedString),
    /// Native build arguments.
    BuildArguments(BuildSettingValues<ImageArtifactAssignment>),
    /// Native build-secret declarations.
    Secrets(BuildSettingValues<ProtectedString>),
    /// Architecture selection.
    Architecture(ProtectedString),
    /// Architecture variant selection.
    Variant(ProtectedString),
    /// Native pull-policy spelling.
    PullPolicy(ProtectedString),
    /// Retry-count spelling.
    Retry(ProtectedString),
    /// Retry-delay spelling.
    RetryDelay(ProtectedString),
    /// TLS verification choice.
    TlsVerify(bool),
    /// Remove intermediate artifacts choice.
    ForceRemove(bool),
    /// Authentication file.
    AuthFile(ProtectedString),
    /// Ignore-file spelling.
    IgnoreFile(ProtectedString),
    /// Service-manager unit name.
    ServiceName(ProtectedString),
    /// Supplemental group additions.
    GroupAdd(BuildSettingValues<ProtectedString>),
    /// DNS servers.
    DnsServers(BuildSettingValues<ProtectedString>),
    /// DNS resolver options.
    DnsOptions(BuildSettingValues<ProtectedString>),
    /// DNS search domains.
    DnsSearchDomains(BuildSettingValues<ProtectedString>),
    /// Build annotations.
    Annotations(BuildSettingValues<ImageArtifactAssignment>),
    /// Build environment assignments.
    Environment(BuildSettingValues<ImageArtifactAssignment>),
    /// Containers configuration modules.
    ContainersConfigModules(BuildSettingValues<ProtectedString>),
    /// Global runtime arguments.
    GlobalArguments(BuildSettingValues<ProtectedString>),
    /// Build volume declarations.
    Volumes(BuildSettingValues<ProtectedString>),
    /// Runtime-specific build arguments.
    RuntimeArguments(BuildSettingValues<ProtectedString>),
}

/// An image-build resource with independently retained source declaration and artifact settings.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ImageBuild {
    name: Identifier,
    source_declaration: Option<Sourced<BuildSourceDeclaration>>,
    settings: Option<Vec<Sourced<ImageBuildSetting>>>,
    settings_origins: Vec<Provenance>,
}

impl ImageBuild {
    /// Creates an empty image-build resource.
    #[must_use]
    pub const fn new(name: Identifier) -> Self {
        Self {
            name,
            source_declaration: None,
            settings: None,
            settings_origins: Vec::new(),
        }
    }

    /// Returns the neutral build-resource name.
    #[must_use]
    pub const fn name(&self) -> &Identifier {
        &self.name
    }

    /// Sets the source declaration without conflating scalar and structured syntax.
    pub fn set_source_declaration(&mut self, declaration: Sourced<BuildSourceDeclaration>) {
        self.source_declaration = Some(declaration);
    }

    /// Returns the optional source declaration.
    #[must_use]
    pub const fn source_declaration(&self) -> Option<&Sourced<BuildSourceDeclaration>> {
        self.source_declaration.as_ref()
    }

    /// Sets artifact settings, retaining explicit emptiness separately from omission.
    pub fn set_settings(&mut self, settings: Vec<Sourced<ImageBuildSetting>>) {
        self.settings = Some(settings);
        self.settings_origins.clear();
    }

    /// Sets artifact settings and their collection-level provenance.
    pub fn set_settings_with_origins(&mut self, settings: Vec<Sourced<ImageBuildSetting>>, origins: Vec<Provenance>) {
        self.settings = Some(settings);
        self.settings_origins = origins;
    }

    /// Returns artifact settings in source order, if explicitly present.
    #[must_use]
    pub fn settings(&self) -> Option<&[Sourced<ImageBuildSetting>]> {
        self.settings.as_deref()
    }

    /// Returns artifact-setting collection provenance.
    #[must_use]
    pub fn settings_origins(&self) -> &[Provenance] {
        &self.settings_origins
    }
}

#[cfg(test)]
mod tests {
    use super::{
        BuildSettingValues, BuildSourceDeclaration, BuildSyntax, ImageAcquisition, ImageAcquisitionSetting,
        ImageArtifactAssignment, ImageBuild, ImageBuildSetting, SourceBuildSetting,
    };
    use crate::{Identifier, ProtectedString, Provenance, SourceId, Sourced};

    fn origin() -> Result<Provenance, String> {
        SourceId::new("build.yaml")
            .map(Provenance::source)
            .map_err(|error| error.to_string())
    }

    #[test]
    fn native_text_settings_preserve_working_directory_and_pull_policy() -> Result<(), String> {
        let origin = origin()?;
        let mut build = ImageBuild::new(Identifier::new("web-build").map_err(|error| error.to_string())?);
        build.set_settings(vec![
            Sourced::from_source(
                ImageBuildSetting::SetWorkingDirectory(ProtectedString::plain("unit")),
                origin.clone(),
            ),
            Sourced::from_source(ImageBuildSetting::PullPolicy(ProtectedString::plain("newer")), origin),
        ]);
        let settings = build.settings().ok_or("explicit settings")?;
        assert!(matches!(
            settings[0].value(),
            ImageBuildSetting::SetWorkingDirectory(value) if value.expose() == "unit"
        ));
        assert!(matches!(
            settings[1].value(),
            ImageBuildSetting::PullPolicy(value) if value.expose() == "newer"
        ));
        Ok(())
    }

    #[test]
    fn per_key_empty_reset_is_distinct_from_omission_and_retains_order_and_provenance() -> Result<(), String> {
        let origin = origin()?;
        let mut build = ImageBuild::new(Identifier::new("web-build").map_err(|error| error.to_string())?);
        assert_eq!(build.source_declaration(), None);
        build.set_source_declaration(Sourced::from_source(
            BuildSourceDeclaration::Structured(vec![
                Sourced::from_source(
                    SourceBuildSetting::Tags(BuildSettingValues::new(BuildSyntax::Sequence, Vec::new())),
                    origin.clone(),
                ),
                Sourced::from_source(
                    SourceBuildSetting::Arguments(BuildSettingValues::new(BuildSyntax::Mapping, Vec::new())),
                    origin.clone(),
                ),
            ]),
            origin.clone(),
        ));
        let declaration = build.source_declaration().ok_or("structured declaration")?;
        let settings = declaration.value().structured_settings().ok_or("structured settings")?;
        assert_eq!(settings.len(), 2);
        assert!(matches!(
            settings[0].value(),
            SourceBuildSetting::Tags(values) if values.values().is_empty() && values.syntax() == BuildSyntax::Sequence
        ));
        assert!(matches!(
            settings[1].value(),
            SourceBuildSetting::Arguments(values) if values.values().is_empty() && values.syntax() == BuildSyntax::Mapping
        ));
        assert_eq!(settings[0].origins(), std::slice::from_ref(&origin));
        Ok(())
    }

    #[test]
    fn scalar_and_structured_source_declarations_remain_distinct() -> Result<(), String> {
        let origin = origin()?;
        let mut build = ImageBuild::new(Identifier::new("web-build").map_err(|error| error.to_string())?);
        build.set_source_declaration(Sourced::from_source(
            BuildSourceDeclaration::Scalar(ProtectedString::plain("./web")),
            origin,
        ));
        assert_eq!(
            build
                .source_declaration()
                .map(|declaration| declaration.value().syntax()),
            Some(BuildSyntax::Scalar)
        );
        assert_eq!(
            build
                .source_declaration()
                .and_then(|declaration| declaration.value().structured_settings()),
            None
        );
        Ok(())
    }

    #[test]
    fn repeated_acquisition_values_and_sensitive_settings_retain_duplicates_and_redact() -> Result<(), String> {
        let origin = origin()?;
        let mut acquisition = ImageAcquisition::new(Identifier::new("base-image").map_err(|error| error.to_string())?);
        acquisition.set_settings_with_origins(
            vec![
                Sourced::from_source(
                    ImageAcquisitionSetting::ImageTags(BuildSettingValues::new(
                        BuildSyntax::Repeated,
                        vec![
                            Sourced::from_source(ProtectedString::plain("web:one"), origin.clone()),
                            Sourced::from_source(ProtectedString::plain("web:one"), origin.clone()),
                        ],
                    )),
                    origin.clone(),
                ),
                Sourced::from_source(
                    ImageAcquisitionSetting::Credentials(ProtectedString::sensitive("operator:secret")),
                    origin.clone(),
                ),
            ],
            vec![origin.clone()],
        );
        let settings = acquisition.settings().ok_or("explicit settings")?;
        assert!(matches!(
            settings[0].value(),
            ImageAcquisitionSetting::ImageTags(values) if values.values().len() == 2 && values.values()[0] == values.values()[1]
        ));
        assert_eq!(acquisition.settings_origins(), std::slice::from_ref(&origin));
        let assignment = ImageArtifactAssignment::new(
            ProtectedString::plain("TOKEN"),
            Some(ProtectedString::sensitive("build-secret")),
        );
        let target_secrets = ImageBuildSetting::Secrets(BuildSettingValues::new(
            BuildSyntax::Repeated,
            vec![Sourced::from_source(
                ProtectedString::sensitive("target-build-secret"),
                origin.clone(),
            )],
        ));
        let source_ssh = SourceBuildSetting::Ssh(BuildSettingValues::new(
            BuildSyntax::Sequence,
            vec![Sourced::from_source(
                ProtectedString::sensitive("ssh-agent-secret"),
                origin.clone(),
            )],
        ));
        let auth = ImageAcquisitionSetting::AuthFile(ProtectedString::sensitive("auth-file-secret"));
        let decryption = ImageAcquisitionSetting::DecryptionKey(ProtectedString::sensitive("decryption-secret"));
        let debug = format!("{acquisition:?} {assignment:?} {target_secrets:?} {source_ssh:?} {auth:?} {decryption:?}");
        for secret in [
            "operator:secret",
            "build-secret",
            "target-build-secret",
            "ssh-agent-secret",
            "auth-file-secret",
            "decryption-secret",
        ] {
            assert!(!debug.contains(secret));
        }
        assert!(debug.contains("[REDACTED]"));
        Ok(())
    }

    #[test]
    fn malformed_or_empty_assignments_are_retained_for_adapter_diagnostics() {
        let assignment = ImageArtifactAssignment::new(ProtectedString::plain(""), Some(ProtectedString::plain("")));
        assert_eq!(assignment.name().expose(), "");
        assert_eq!(assignment.value().map(ProtectedString::expose), Some(""));
    }
}