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
use anyhow::{Context, Result};
use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser)]
#[command(
name = "echoproof",
version,
about = "Verify behavior of code changes by replaying real traffic"
)]
pub struct Cli {
/// Configuration file (optional).
#[arg(long, global = true, default_value = "echoproof.toml")]
pub config: PathBuf,
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand)]
pub enum Command {
/// Write a commented echoproof.toml.
Init,
/// Run a recording reverse proxy in front of a service.
Record {
#[arg(long)]
upstream: Option<String>,
#[arg(long)]
listen: Option<String>,
#[arg(long, short)]
out: PathBuf,
/// Also record the service's outbound HTTP(S) calls through a proxy on this loopback
/// address. Start the service with the settings from `echoproof ca env`.
#[arg(long)]
outbound_listen: Option<String>,
},
/// Replay a snapshot against a target and save its responses.
Replay {
#[arg(long, short)]
snapshot: PathBuf,
#[arg(long, short)]
target: String,
#[arg(long, short)]
out: PathBuf,
#[command(flatten)]
replay: ReplayArgs,
},
/// Compare two snapshots and report behavior changes.
Diff {
baseline: PathBuf,
candidate: PathBuf,
#[command(flatten)]
report: ReportArgs,
},
/// Replay and diff in one step (for CI and agents).
Check {
#[arg(long, short)]
snapshot: PathBuf,
#[arg(long, short)]
target: String,
/// Also save the candidate snapshot here.
#[arg(long)]
save: Option<PathBuf>,
/// Base build to compare against on the same state, instead of the recording.
#[arg(long)]
base: Option<String>,
/// Shell command that restores state before every replay pass.
#[arg(long)]
reset: Option<String>,
/// Extra base replays used to learn noisy fields.
#[arg(long)]
noise_runs: Option<usize>,
#[command(flatten)]
replay: ReplayArgs,
#[command(flatten)]
report: ReportArgs,
},
/// Serve the Model Context Protocol over stdio for coding agents.
Mcp,
/// Manage the project's certificate authority for the outbound proxy.
Ca {
#[command(subcommand)]
action: CaAction,
},
/// Make a candidate's responses the new baseline.
Accept {
candidate: PathBuf,
#[arg(long)]
baseline: PathBuf,
},
}
#[derive(Subcommand)]
pub enum CaAction {
/// Create .echoproof/ca.pem and its key for this project.
Init,
/// Print the settings that point a test build at the outbound proxy.
Env {
#[arg(long, value_enum)]
runtime: Runtime,
#[arg(long, default_value = "127.0.0.1:8899")]
proxy: String,
},
}
#[derive(Clone, Copy, ValueEnum)]
pub enum Runtime {
Php,
Node,
Python,
Go,
}
#[derive(Args)]
pub struct ReplayArgs {
#[arg(long)]
pub concurrency: Option<usize>,
/// Endpoint whose write requests may be replayed ("POST /orders", "*"). Repeatable.
#[arg(long)]
pub allow_writes: Vec<String>,
/// Do not carry IDs created during the replay into later requests.
#[arg(long)]
pub no_id_mapping: bool,
/// Answer the builds' outbound HTTP(S) calls from the recording through a proxy on this
/// loopback address (see `echoproof ca init`).
#[arg(long)]
pub outbound_proxy: Option<String>,
}
#[derive(Args)]
pub struct ReportArgs {
/// Endpoint expected to change, e.g. "GET /products/*". Repeatable.
#[arg(long)]
pub expect: Vec<String>,
#[arg(long, value_enum, default_value_t = Format::Text)]
pub format: Format,
/// Also write the report to this file (.md for Markdown, .json for JSON).
#[arg(long)]
pub output: Option<PathBuf>,
#[arg(long, default_value_t = 2)]
pub max_examples: usize,
/// What the change is meant to do; changes are then judged against it by Claude.
#[arg(long, conflicts_with = "intent_file")]
pub intent: Option<String>,
#[arg(long)]
pub intent_file: Option<PathBuf>,
/// Code diff of the change, given to the judge.
#[arg(long)]
pub code_diff: Option<PathBuf>,
}
#[derive(Clone, Copy, ValueEnum)]
pub enum Format {
Text,
Markdown,
Json,
}
impl ReportArgs {
pub fn intent(&self) -> Result<Option<String>> {
match (&self.intent, &self.intent_file) {
(Some(text), _) => Ok(Some(text.clone())),
(None, Some(path)) => read(path).map(Some),
(None, None) => Ok(None),
}
}
pub fn code_diff(&self) -> Result<Option<String>> {
self.code_diff.as_deref().map(read).transpose()
}
}
fn read(path: &std::path::Path) -> Result<String> {
std::fs::read_to_string(path).with_context(|| format!("cannot read {}", path.display()))
}