Skip to content

Fix env var config roundtrip through build.rs TOML serialization #363

Description

@aram356

Summary

Environment variables set via TRUSTED_SERVER__INTEGRATIONS__* lose their types when roundtripped through the build.rs → TOML → runtime pipeline. String values like "true" and "123" are not converted back to their expected bool/number types, causing runtime deserialization failures.

Root Cause

  1. Type loss in TOML roundtrip: config crate delivers env vars as JsonValue::String. When serialized to TOML and deserialized back, values like "true" stay as strings instead of becoming bools.
  2. Build.rs doesn't detect env var changes: cargo:rerun-if-env-changed can't track integration env vars because Settings::default() has an empty HashMap — the keys aren't known ahead of time.
  3. from_toml() redundantly scanned env vars at runtime: The old implementation re-ran the config crate pipeline on every call, even though the embedded TOML already contains the final resolved values.

Fix (PR #362)

  • Eager type normalization: IntegrationSettings::normalize() converts string values to native types before TOML serialization
  • Always-rerun sentinel: cargo:rerun-if-changed=_always_rebuild_sentinel_ forces rebuild on every cargo build, with conditional file write to avoid unnecessary recompilation
  • Split from_toml / from_toml_and_env: Runtime path uses fast toml::from_str(); build-time path uses config crate for env var merging
  • Trailing slash validation: Replaced Publisher::normalize() with #[validate] on origin_url

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions