Skip to content

Conversation

@cmeisl
Copy link
Member

@cmeisl cmeisl commented Jan 21, 2026

Add Mock Collector

Adds a mock collector service for local development and testing of the gas agent.

Changes

  • New crate: mock-collector - A lightweight HTTP server that receives and logs agent submissions at POST /v0/agents. Useful for testing the agent without connecting to a real collector.

  • New library target - Exposes AgentPayload from src/lib.rs so the mock-collector (and other crates) can deserialize agent submissions.

Additional Changes

  • Fixed test compilation - Tests in src/chain/encode.rs previously relied on crate::logs::init_logs() which isn't available from the library crate root. Replaced with a self-contained test logger using tracing_subscriber::fmt().with_test_writer().

  • Suppressed dead code warnings - Added #[allow(dead_code)] to ModelKind, AgentKind, and SystemNetworkKey::to_block_time() since these are only used by the binary, not the library.

Usage

# Run the mock collector
cargo run -p mock-collector

# Listens on http://localhost:3000/v0/agents

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a mock collector service for local development and testing of the gas agent. It introduces a new workspace structure, exposes AgentPayload as a library type, and provides a lightweight HTTP server for receiving agent submissions.

Changes:

  • Created a workspace with the main package and a new mock-collector crate
  • Added src/lib.rs to expose AgentPayload from the agent as a library
  • Added #[allow(dead_code)] to to_block_time() since it's only used by the binary

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Cargo.toml Workspace configuration adding mock-collector as a member
Cargo.lock Dependency updates for axum and related crates
src/lib.rs New library target exposing AgentPayload type
src/types.rs Added dead_code annotation to to_block_time()
crates/mock-collector/Cargo.toml Dependencies for mock collector service
crates/mock-collector/src/main.rs HTTP server implementation for receiving and logging agent submissions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mod chain;
mod types;

pub use types::AgentPayload;
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library exports only AgentPayload, but this struct has public fields of types Settlement, System, Network, and PriceUnit. These types must also be exported from the library for consumers (like the mock-collector) to deserialize AgentPayload instances. Without these exports, the mock-collector won't be able to compile and use the AgentPayload type properly.

Suggested change
pub use types::AgentPayload;
pub use types::{AgentPayload, Settlement, System, Network, PriceUnit};

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lnbc1QWFyb24 The collector seems to work without these since it only imports AgentPayload. Is the collector able to use those elements of the payload because it's just treating them as strings written to console?

            info!("System:         {:?}", submission.payload.system);
            info!("Network:        {:?}", submission.payload.network);
            info!("From Block:     {}", submission.payload.from_block);
            info!("Settlement:     {:?}", submission.payload.settlement);
            info!(
                "Price:          {} {:?}",
                submission.payload.price, submission.payload.unit
            );
            info!("Timestamp:      {}", submission.payload.timestamp);
            info!("Schema Version: {}", submission.payload.schema_version);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this co-pilot recommendation does not make a lot of sense in this context. If you needed to create an AgentPayload then you would need those enums, but since you are just logging public fields on the struct it is fine as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants