Expand description
SDK for building intake adapters that convert sensor outputs to buildfix receipts.
This crate provides the Adapter trait and utilities for implementing new sensor
intake adapters. An adapter transforms a sensor’s native output format into the
standardized ReceiptEnvelope format that buildfix expects.
§Creating a New Adapter
To create a new adapter, implement the Adapter trait for your sensor-specific
adapter struct. The adapter is responsible for:
-
Identifying the sensor via
sensor_id()- returns a unique string like"cargo-deny"or"clippy" -
Loading sensor output via
load()- reads and parses the sensor’s output file into aReceiptEnvelope
§Example
ⓘ
use buildfix_adapter_sdk::{Adapter, AdapterError, ReceiptBuilder};
use buildfix_types::receipt::{ReceiptEnvelope, Severity, VerdictStatus};
use std::path::Path;
pub struct MySensorAdapter {
sensor_id: String,
}
impl MySensorAdapter {
pub fn new() -> Self {
Self {
sensor_id: "my-sensor".to_string(),
}
}
}
impl Adapter for MySensorAdapter {
fn sensor_id(&self) -> &str {
&self.sensor_id
}
fn load(&self, path: &Path) -> Result<ReceiptEnvelope, AdapterError> {
// Parse your sensor's output format and convert to ReceiptEnvelope
let output = std::fs::read_to_string(path)
.map_err(AdapterError::Io)?;
let parsed = serde_json::from_str::<serde_json::Value>(&output)
.map_err(AdapterError::Json)?;
// Convert to ReceiptEnvelope using ReceiptBuilder
let envelope = ReceiptBuilder::new("my-sensor")
.with_status(VerdictStatus::Fail)
.build();
Ok(envelope)
}
}§Testing Adapters
Use AdapterTestHarness to validate your adapter implementation:
ⓘ
use buildfix_adapter_sdk::AdapterTestHarness;
use my_adapter::MySensorAdapter;
#[test]
fn test_adapter_loads_receipt() {
let harness = AdapterTestHarness::new(MySensorAdapter::new());
harness.validate_receipt_fixture("tests/fixtures/my-sensor/report.json")
.expect("receipt should load correctly");
}Re-exports§
pub use receipt_builder::ReceiptBuilder;
Modules§
- receipt_
builder - Helper utilities for building receipt envelopes in tests and adapters.
Structs§
- Adapter
Test Harness - Metadata
Validation Error - Error returned when adapter metadata validation fails.
- Validation
Result
Enums§
Traits§
- Adapter
- Adapter
Ext - Extension trait for adapters with metadata.
- Adapter
Metadata - Metadata trait for adapter self-description.