repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

test(arch): every test file cites its spec; gate in cargo x arch

fbc47ab4710a623c4baaa5901fc9db627868ca22

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (26)

+154 / −25 text lines

Diff layout

smith-ai/src/anthropic.rs

Modified

+1 / −1 text lines

1//! Anthropic Messages stream adapter.
1//! Anthropic Messages stream adapter (`SMH-SPEC-SPEC0001`, Providers).
22//!
33//! Translates typed server-sent events, block-indexed content, and partial
44//! JSON tool arguments into the normalized vocabulary. Event types, block

smith-ai/src/auth.rs

Modified

+2 / −1 text lines

1//! Credential resolution without context exposure.
1//! Credential resolution without context exposure (`SMH-SPEC-SPEC0001`,
2//! Providers: authentication).
23//!
34//! Credentials come from environment variables or explicit values, resolve
45//! without any network access, and can be checked for readiness

smith-ai/src/gemini.rs

Modified

+1 / −1 text lines

1//! Google Gemini stream adapter.
1//! Google Gemini stream adapter (`SMH-SPEC-SPEC0001`, Providers).
22//!
33//! Translates `streamGenerateContent` server-sent chunks, where function
44//! calls arrive complete in one part, into the normalized vocabulary.

smith-ai/src/models.rs

Modified

+2 / −1 text lines

1//! Offline model catalog, capabilities, and deterministic resolution.
1//! Offline model catalog, capabilities, and deterministic resolution
2//! (`SMH-SPEC-SPEC0001`, Providers).
23//!
34//! The reviewed catalog ships as checked-in JSON. Resolution is pure data
45//! navigation with no network: aliases recurse, groups expand to ordered

smith-ai/src/mux.rs

Modified

+2 / −1 text lines

1//! Endpoint routing with bounded retry and failover.
1//! Endpoint routing with bounded retry and failover (`SMH-SPEC-SPEC0001`,
2//! Providers).
23//!
34//! Resolution produces an ordered plan; routing walks it. Rate limits and
45//! overloaded endpoints fail over immediately, transient faults get a bounded

smith-ai/src/openai.rs

Modified

+2 / −1 text lines

1//! OpenAI-compatible chat-completions stream adapter.
1//! OpenAI-compatible chat-completions stream adapter (`SMH-SPEC-SPEC0001`,
2//! Providers).
23//!
34//! Translates untyped server-sent-event chunks with fragmented tool-call
45//! argument strings into the normalized vocabulary. All vendor structure,

smith-ai/src/refresh.rs

Modified

+2 / −1 text lines

1//! Cancellable catalog refresh with generation-checked publication.
1//! Cancellable catalog refresh with generation-checked publication
2//! (`SMH-SPEC-SPEC0001`, Providers: catalogs).
23//!
34//! Refresh is a pure state machine over an injected fetch closure, so the
45//! semantics hold without a network: a cancelled fetch keeps the cached

smith-ai/src/transport.rs

Modified

+2 / −1 text lines

1//! Vendor HTTP transport: request bodies, posting, and SSE decoding.
1//! Vendor HTTP transport: request bodies, posting, and SSE decoding
2//! (`SMH-SPEC-SPEC0001`, Network transport).
23//!
34//! Body builders are pure functions over [`smith::provider::ProviderRequest`] so their vendor
45//! shapes are unit-tested without network. The transport posts and feeds the

smith-alloc/src/lib.rs

Modified

+1 / −1 text lines

1//! Scope-tagged counting allocator.
1//! Scope-tagged counting allocator (`SMH-SPEC-SPEC0001`, Memory accounting).
22//!
33//! [`Counting`] wraps [`System`] and attributes every allocation, including
44//! third-party ones, to the innermost [`Scope`] entered on the allocating

smith-cli/tests/architecture.rs

Modified

+3 / −1 text lines

1//! Workspace architecture law, expressed as source-level tests.
1//! Workspace architecture law, expressed as source-level tests
2//! (`SMH-SPEC-SPEC0001`, acceptance: quality, architecture, documentation
3//! gates).
24//!
35//! Mirrors the manifest gate in xtask and adds what manifests cannot see:
46//! source dependency graphs and engine-ownership boundaries.

smith-cli/tests/e2e_auth.rs

Modified

+2 / −1 text lines

1//! End-to-end credential store behavior through the `smith auth` CLI.
1//! End-to-end credential store behavior through the `smith auth` CLI
2//! (`SMH-SPEC-SPEC0001`, Providers: authentication).
34use assert_cmd::Command;
45use std::path::PathBuf;

smith-cli/tests/e2e_selection.rs

Modified

+2 / −1 text lines

1//! Provider selection and provenance behavior through the `smith` CLI.
1//! Provider selection and provenance behavior through the `smith` CLI
2//! (`SMH-SPEC-SPEC0001`, Providers).
34//! CLI tests assert on outcomes.

smith-core/src/agent.rs

Modified

+2 / −1 text lines

1//! The provider-independent agent loop.
1//! The provider-independent agent loop (`SMH-SPEC-SPEC0001`, Tools and
2//! Compaction cost and secrets).
23//!
34//! One runtime drives every interface mode: it sends provider-neutral
45//! requests, streams normalized events, executes tool calls through the

smith-core/src/bash.rs

Modified

+2 / −1 text lines

1//! Bounded, cancellable shell execution with owned-process-tree termination.
1//! Bounded, cancellable shell execution with owned-process-tree termination
2//! (`SMH-SPEC-SPEC0001`, Tools).
23//!
34//! Pipes are drained by dedicated threads so the deadline loop is never
45//! blocked by a silent child; per-stream caps keep the fitting prefix and

smith-core/src/frame.rs

Modified

+2 / −1 text lines

1//! Length-prefixed, checksummed CBOR session framing.
1//! Length-prefixed, checksummed CBOR session framing (`SMH-SPEC-SPEC0001`,
2//! Sessions).
23//!
34//! Wire format, little endian:
45//!

smith-core/src/lib.rs

Modified

+1 / −1 text lines

1//! Provider-independent Smith agent core.
1//! Provider-independent Smith agent core (`SMH-SPEC-SPEC0001`, Sessions).
22//!
33//! Session persistence, CBOR framing, configurable runtime, replay traces,
44//! and tool lifecycle events.

smith-core/src/session.rs

Modified

+2 / −1 text lines

11//! Branching session state: an index arena of fixed-size entry records over
2//! one contiguous payload arena, plus restoration from durable frames.
2//! one contiguous payload arena, plus restoration from durable frames
3//! (`SMH-SPEC-SPEC0001`, Sessions).
34//!
45//! Entry content lives as canonical CBOR bytes, at rest and in memory. A
56//! record carries what traversal needs ([`EntryKind`]); anything else is a

smith-core/src/store.rs

Modified

+1 / −1 text lines

11//! Durable session storage: append-only writer, incremental bounded loader,
2//! and atomic repair publication.
2//! and atomic repair publication (`SMH-SPEC-SPEC0001`, Sessions).
44use crate::frame::{Frame, Recovery, encode_entry, read_frames, write_frame};
55use crate::session::{Entry, Session};

smith-core/src/tools.rs

Modified

+2 / −0 text lines

11//! Tool registry, validation, built-in file effects, and the durable
22//! outcome boundary between successful effects and recorded session frames.
3//!
4//! (`SMH-SPEC-SPEC0001`, Tools).
46use crate::session::{Entry, EntryContentRef, Session};
57use crate::store::SessionWriter;

smith-core/src/trace.rs

Modified

+2 / −1 text lines

1//! Replay evidence derived from durable session state.
1//! Replay evidence derived from durable session state (`SMH-SPEC-SPEC0001`,
2//! Sessions).
23//!
34//! A trace is an ordered, provider-free reconstruction of what a session
45//! recorded. It is derived only from persisted entry records, never from

smith-harness/src/runtime.rs

Modified

+2 / −1 text lines

1//! Runtime assembly: configuration to agent.
1//! Runtime assembly: configuration to agent (`SMH-SPEC-SPEC0001`,
2//! Providers).
23//!
34//! One shape serves eval and RPC. Mock providers run scripted responses for
45//! offline use; real providers post through the vendor transport with

smith-harness/tests/http_effect.rs

Modified

+2 / −1 text lines

1//! End-to-end provider traffic through the typed HTTP effect.
1//! End-to-end provider traffic through the typed HTTP effect
2//! (`SMH-SPEC-SPEC0001`, Network transport).
34//! Integration tests drive a real socket, a real executor, and the
45//! durable session store.

smith-harness/tests/wasm_host.rs

Modified

+2 / −1 text lines

1//! Wasm host lifecycle: validate, instantiate, declare, invoke, fuel.
1//! Wasm host lifecycle: validate, instantiate, declare, invoke, fuel
2//! (`SMH-SPEC-WASM0001`).
34use smith_harness::wasm::{PluginEngine, PluginInstance};

smith-rpc/src/lib.rs

Modified

+2 / −1 text lines

1//! LF-delimited JSON-RPC over standard input and output.
1//! LF-delimited JSON-RPC over standard input and output (`SMH-SPEC-SPEC0001`,
2//! Interface modes).
23//!
34//! Standard output carries protocol records only. Request IDs are preserved
45//! on every response. Agent work runs on one worker, leaving control requests

smith/src/lib.rs

Modified

+2 / −1 text lines

1//! Shared Smith foundation types.
1//! Shared Smith foundation types (`SMH-SPEC-SPEC0001`, Sessions, Providers,
2//! and Tools).
23//!
34//! Provider-neutral values, errors, cancellation, and tool contracts.

xtask/src/main.rs

Modified

+108 / −1 text lines

11#![forbid(unsafe_code)]
22#![warn(missing_docs)]
4//! Cargo-only Smith project automation.
4//! Cargo-only Smith project automation (`SMH-SPEC-SPEC0001`, acceptance:
5//! quality, architecture, documentation gates).
56//!
67//! Gate tools follow one rule: install immutable artifacts or pinned
78//! versions with `--locked`, never live dependency resolution, so upstream
713714 ));
714715 }
715716 }
717 if let Some(offender) = missing_spec_reference() {
718 return fail(&format!(
719 "{}: test code without an SMH-SPEC- citation in its first 20 lines or `//!` header (RULES.md Testing)\n",
720 offender.display()
721 ));
722 }
716723 ExitCode::SUCCESS
726/// The first `.rs` file under any workspace crate that carries test code
727/// (`#[test]` or a `tests/` directory) but cites no `SMH-SPEC-…` id in its
728/// first 20 lines or its `//!` header block.
729fn missing_spec_reference() -> Option<PathBuf> {
730 for crate_name in CRATES {
731 let mut files = Vec::new();
732 collect_rs_files(Path::new(crate_name), &mut files);
733 for path in files {
734 let Ok(source) = fs::read_to_string(&path) else {
735 continue;
736 };
737 if is_test_bearing(&path, &source) && !cites_a_spec(&source) {
738 return Some(path);
739 }
740 }
741 }
742 None
743}
745/// `.rs` files under `dir`, deterministically ordered, skipping `target`.
746fn collect_rs_files(dir: &Path, out: &mut Vec<PathBuf>) {
747 let Ok(entries) = fs::read_dir(dir) else {
748 return;
749 };
750 let mut entries: Vec<PathBuf> = entries.flatten().map(|entry| entry.path()).collect();
751 entries.sort();
752 for path in entries {
753 if path.is_dir() {
754 if path.file_name().is_some_and(|name| name == "target") {
755 continue;
756 }
757 collect_rs_files(&path, out);
758 } else if path.extension().is_some_and(|ext| ext == "rs") {
759 out.push(path);
760 }
761 }
762}
764/// A file carries test code when it literally declares `#[test]` or lives
765/// under a `tests/` directory (integration test crates have no attribute).
766fn is_test_bearing(path: &Path, source: &str) -> bool {
767 source.contains("#[test]") || path.components().any(|part| part.as_os_str() == "tests")
768}
770/// Whether `SMH-SPEC-` appears in the first 20 lines or the leading `//!`
771/// doc-comment block, whichever the file has.
772fn cites_a_spec(source: &str) -> bool {
773 let first_twenty: Vec<&str> = source.lines().take(20).collect();
774 first_twenty.iter().any(|line| line.contains("SMH-SPEC-"))
775 || leading_doc_block(source).contains("SMH-SPEC-")
776}
778/// The contiguous run of `//!` lines starting the file, attributes and
779/// blank lines before it skipped, concatenated.
780fn leading_doc_block(source: &str) -> String {
781 let mut block = String::new();
782 for line in source.lines() {
783 let trimmed = line.trim_start();
784 if trimmed.starts_with("//!") {
785 block.push_str(trimmed);
786 block.push('\n');
787 } else if !block.is_empty() {
788 break;
789 }
790 }
791 block
792}
719794/// Crates under the "no Mutex in library crates" law; binaries are exempt.
720795const LIBRARY_CRATES: &[&str] = &[
721796 "smith",
834909 assert!(super::production_slice("static M: Mutex<u8>;").contains("Mutex"));
835910 }
912 use super::{cites_a_spec, is_test_bearing};
913 use std::path::Path;
915 #[test]
916 fn test_bearing_by_attribute_or_by_directory() {
917 assert!(is_test_bearing(
918 Path::new("smith-core/src/agent.rs"),
919 "mod tests {\n#[test]\nfn it_works() {}\n}"
920 ));
921 assert!(is_test_bearing(
922 Path::new("smith-cli/tests/e2e_eval.rs"),
923 "fn helper() {}"
924 ));
925 assert!(!is_test_bearing(
926 Path::new("smith-core/src/lib.rs"),
927 "fn helper() {}"
928 ));
929 }
931 #[test]
932 fn spec_citation_in_first_twenty_lines_or_doc_block() {
933 assert!(cites_a_spec("//! docs (`SMH-SPEC-SPEC0001`, Tools).\n"));
934 let padded = format!("{}fn f() {{}}\n", "//! line\n".repeat(19));
935 assert!(!cites_a_spec(&padded));
936 let past_twenty = format!(
937 "{}//! cites `SMH-SPEC-SPEC0001` here\nfn f() {{}}\n",
938 "//! line\n".repeat(25)
939 );
940 assert!(cites_a_spec(&past_twenty));
941 assert!(!cites_a_spec("// no doc block\nfn f() {}\n"));
942 }
837944 use super::{CRATES, DEPENDENCY_RULES, binary_name, dev_home_dirs, has_dependency, target_dir};
838945 use std::path::PathBuf;