repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

fix(harness): runtime config carries the auth store directory; tests never read a developer's credentials

85675a83c3e8439c782285ad7c24c46c1c0b19f6

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (3)

+25 / −9 text lines

Diff layout

smith-cli/src/main.rs

Modified

+2 / −0 text lines

346346 workdir: dir.clone(),
347347 session_path: dir.join("eval.smh"),
348348 api_key: None,
349 auth_dir: smith::config::auth_dir(),
349350 };
350351 let mut agent = build_agent(&config)?;
351352 let outcome = {
387388 workdir: dir.clone(),
388389 session_path: dir.join("rpc.smh"),
389390 api_key: None,
391 auth_dir: smith::config::auth_dir(),
390392 };
391393 let mut state = RpcState::new(build_agent(&config)?);
392394 let (input_tx, input_rx) = std::sync::mpsc::channel();

smith-harness/src/runtime.rs

Modified

+21 / −9 text lines

7777 pub session_path: PathBuf,
7878 /// Explicit credential override; the highest-precedence source.
7979 pub api_key: Option<String>,
80 /// Credential store directory; the binary passes the XDG default, tests
81 /// an isolated one so a developer's own credentials never leak in.
82 pub auth_dir: PathBuf,
8285impl RuntimeConfig {
8588 pub fn mock(workdir: impl Into<PathBuf>, script: Vec<Vec<smith::stream::StreamEvent>>) -> Self {
8689 let workdir = workdir.into();
8790 let session_path = workdir.join("session.smh");
91 let auth_dir = workdir_auth(&workdir);
8892 Self {
8993 provider: RuntimeProvider::Mock(script),
9094 workdir,
9195 session_path,
9296 api_key: None,
97 auth_dir,
9398 }
9499 }
102/// An auth store beside the session, for isolated runtimes.
103fn workdir_auth(workdir: &Path) -> PathBuf {
104 workdir.join("auth")
105}
97107impl RuntimeProvider {
98108 /// A real provider endpoint with an explicit model; the base URL falls
99109 /// back to the vendor default.
122132 let opened = open_session(Path::new(&config.session_path), smith_config)?;
123133 let tools = ToolSession::with_session(config.workdir.clone(), opened.session, opened.writer);
124134 let (sink, drain) = smith::provider::record_channel();
125 let stream = resolve_stream(&config.provider, config.api_key.clone(), sink)?;
135 let stream = resolve_stream(
136 &config.provider,
137 config.api_key.clone(),
138 &AuthStore::at(&config.auth_dir),
139 sink,
140 )?;
126141 Ok(Agent::with_provider_records(
127142 stream,
128143 tools,
134149fn resolve_stream(
135150 provider: &RuntimeProvider,
136151 api_key: Option<String>,
152 store: &AuthStore,
137153 records: RecordSink,
138154) -> Result<StreamFn> {
139155 match provider {
144160 let kind = provider.vendor_kind();
145161 let api_key = match api_key {
146162 Some(explicit) => explicit,
147 None => resolve_credential(kind)?,
163 None => resolve_credential_from(store, kind)?,
148164 };
149165 Ok(transport(VendorEndpoint {
150166 kind,
158174 }
161/// Credentials resolve the auth store first, then the provider environment
177/// Credentials resolve `store` first, then the provider environment
162178/// variable; a miss names both sources and fails before dispatch.
163179///
164180/// # Errors
165181///
166182/// Returns an authentication fault naming the provider and every source
167183/// tried, without network access.
168pub fn resolve_credential(kind: ProviderKind) -> Result<String> {
169 resolve_credential_from(&AuthStore::at_default(), kind)
170}
172/// Credential resolution against one store, separated for tests.
173fn resolve_credential_from(store: &AuthStore, kind: ProviderKind) -> Result<String> {
184pub fn resolve_credential_from(store: &AuthStore, kind: ProviderKind) -> Result<String> {
174185 match store.load(kind) {
175186 Ok(Some(secret)) => Ok(secret),
176187 Ok(None) => {
224235 workdir: dir.clone(),
225236 session_path: dir.join("s.smh"),
226237 api_key: None,
238 auth_dir: dir.join("auth"),
227239 };
228240 let Err(err) = build_agent(&config) else {
229241 unreachable!("no credential must fail assembly");

smith-harness/tests/http_effect.rs

Modified

+2 / −0 text lines

6464 workdir: dir.clone(),
6565 session_path: session_path.clone(),
6666 api_key: Some("sk-integration-secret".to_string()),
67 auth_dir: dir.join("auth"),
6768 };
6869 let mut agent = build_agent(&config).unwrap();
6970 let outcome = agent.run_turn("say it").unwrap();
120121 workdir: dir.clone(),
121122 session_path: dir.join("s.smh"),
122123 api_key: Some("sk-explicit".to_string()),
124 auth_dir: dir.join("auth"),
123125 };
124126 let _agent = build_agent(&config).unwrap();
125127 let _ = std::fs::remove_dir_all(&dir);