requirements.authoring.provider
Requirements index · View definition
Requirement
The authoring harness MUST use Rig and support Bedrock, Ollama, and OpenAI. Users MUST be able to select a backend and model through configuration without changing the assessment tools, prompt, or evidence format.
Rationale
The reviewed tests adequately check requirements.authoring.provider.
Obligations derived
- The harness supports Bedrock, Ollama and OpenAI, built on Rig.
- A user can select the backend and model through configuration.
- Changing the backend or model leaves the assessment tools, the prompt and the evidence format unchanged.
Mapping to tests
- All three backends, each selected by configuration:
tests/authoring_cli.rs#fn[all_adapters_preserve_prompt_tools_and_evidence_with_default_connections]writes three separate config files. Each setsbackendtoollama,bedrockoropenaiand sets amodel. The test runsauthoragainst a mock server for each and checks the following.- The Ollama request carries the configured model and sends no authorization header.
- The Bedrock request goes to
/model/default-chain-model/converseand is signed with the default-chain credentials and region. - The OpenAI request goes to
/responseswith a Bearer token and the configured model.
- Prompt, tools and evidence unchanged across backends: the same test compares
prompt_and_toolsoutput for the three backends and assertsollama == bedrockandollama == openai. The helpertests/authoring_cli.rs#fn[prompt_and_tools]strips only the provider envelopes, and the test asserts 10 tools. It also asserts the whole evidence documents are equal across the three backends, including inputs and hashes. - Bedrock in depth:
bedrock_cli_uses_selected_profile_region_and_converse_toolscovers the following.- The configured profile, region and model are used.
- The tool list, the schemas and the prompt content are present.
- The Bedrock tool history is replayed correctly, in both the untyped and the typed
tool_useforms. - The evidence records the selected backend and model.
- OpenAI in depth:
openai_responses_replays_tool_calls_and_records_usagecovers the following.- The model is the configured one on every request.
- The tools and instructions are identical across the turns.
- The tool-call history is replayed.
- The usage records
backendasopenai.
- Model and backend from workspace configuration:
authoring_uses_nearest_workspace_configuration_without_a_user_fileselects an Ollama config and model from workspace configuration and asserts the request’smodelfield is that model. - Rig integration: the unit tests
typed_client_calls_preserve_order_and_native_historyandmalformed_typed_client_calls_are_reportedinsrc/authoring/providers.rsexercise Rig response and content types directly. They check Bedrock tool-call normalization and that malformed typed calls produce errors. - Live Bedrock:
tests/live_bedrock.rs#fn[live_bedrock_authoring]adds a real Bedrock run, which is skipped whenCIis set.
Gaps considered
- “Using Rig” is an implementation property. The unit tests that build Rig types are the only direct evidence, and the CLI tests exercise it end to end. Nothing more is testable here.
- I found no unaddressed input class that affects an obligation, and no missing assertion.
Inputs
Tests
Input 2: outline src/authoring/providers.rs mod[tests]/fn[typed_client_calls_preserve_order_and_native_history]
- File:
src/authoring/providers.rs - Selector:
mod[tests]/fn[typed_client_calls_preserve_order_and_native_history] - Kind:
fn src/authoring/providers.rs:868–943
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.rig_configuration_mapping`
#[test]
fn typed_client_calls_preserve_order_and_native_history() {
let typed = json!({"toolUse":{
"type":"tool_use", "toolUseId":"client-1", "name":"habeas",
"input":{"file":"src/lib.rs","line_start":1}
}});
let reasoning = AssistantContent::Reasoning(Reasoning::new("Inspect the source."))
.with_native(json!({"reasoningContent":{"reasoningText":{
"text":"Inspect the source.","signature":"original-signature"
}}}));
let content = vec![
reasoning,
AssistantContent::Opaque(Opaque {
item: typed.clone(),
replay: true,
}),
AssistantContent::Text(Text::new("Then submit the judgment.")),
AssistantContent::Opaque(Opaque {
item: json!({"toolUse":{"type":"server_tool_use","toolUseId":"server-1","name":"server","input":{}}}),
replay: true,
}),
AssistantContent::Opaque(Opaque {
item: json!({"toolUse":{"type":"future_tool_use","toolUseId":"future-1","name":"future","input":{}}}),
replay: true,
}),
AssistantContent::ToolCall(ToolCall::from_wire(
"client-2",
ToolFunction::new(ToolName::new("list_files").unwrap(), json!({})),
)),
];
let origin = Origin::new(
"bedrock.converse",
"aws_bedrock",
"us.anthropic.claude-sonnet-5-5",
);
let raw = json!({"original":"provider response"});
let mut response = CompletionResponse::new(
content.clone(),
Usage::default(),
origin.clone(),
raw.clone(),
)
.with_finish_reason(FinishReason::ToolCalls);
response.provider_request_id = Some("request-1".into());
normalize_bedrock_client_calls(&mut response).unwrap();
assert_eq!(response.choice.len(), content.len());
for index in [0, 2, 3, 4, 5] {
assert_eq!(response.choice[index], content[index]);
}
let calls = response.tool_calls().collect::<Vec<_>>();
assert_eq!(calls.len(), 2);
assert_eq!(
calls[0].id,
rig_core::message::CallId::from_wire("client-1")
);
assert_eq!(calls[0].function.name.as_str(), "habeas");
assert_eq!(
calls[0].function.arguments,
typed["toolUse"]["input"].as_object().unwrap().clone()
);
assert_eq!(response.choice[1].native_item(), Some(&typed));
assert_eq!(
calls[1].id,
rig_core::message::CallId::from_wire("client-2")
);
assert_eq!(response.raw, raw);
assert_eq!(response.origin, origin);
assert_eq!(response.provider_request_id.as_deref(), Some("request-1"));
assert_eq!(response.finish_reason(), Some(FinishReason::ToolCalls));
let normalized = response.clone();
normalize_bedrock_client_calls(&mut response).unwrap();
assert_eq!(response, normalized);
}
Input 3: outline src/authoring/providers.rs mod[tests]/fn[malformed_typed_client_calls_are_reported]
- File:
src/authoring/providers.rs - Selector:
mod[tests]/fn[malformed_typed_client_calls_are_reported] - Kind:
fn src/authoring/providers.rs:945–965
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.rig_configuration_mapping`
#[test]
fn malformed_typed_client_calls_are_reported() {
for call in [
json!({"type":"tool_use","name":"habeas","input":{}}),
json!({"type":"tool_use","toolUseId":"id","input":{}}),
json!({"type":"tool_use","toolUseId":"id","name":"habeas","input":[]}),
] {
let mut response = CompletionResponse::new(
vec![AssistantContent::Opaque(Opaque {
item: json!({"toolUse":call}),
replay: true,
})],
Usage::default(),
Origin::new("bedrock.converse", "aws_bedrock", "model"),
Value::Null,
);
assert!(normalize_bedrock_client_calls(&mut response).is_err());
}
}
Input 4: outline tests/authoring_cli.rs fn[authoring_uses_nearest_workspace_configuration_without_a_user_file]
- File:
tests/authoring_cli.rs - Selector:
fn[authoring_uses_nearest_workspace_configuration_without_a_user_file] - Kind:
fn tests/authoring_cli.rs:724–797
// {test}`requirements.configuration.workspace_location`
// {test}`requirements.authoring.configuration`
// {test}`requirements.configuration.workspace_structure`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.credentials`
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.invocation`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.configuration.serialization`
#[test]
// {test}`requirements.configuration.documentation`
fn authoring_uses_nearest_workspace_configuration_without_a_user_file() {
let server = Server::start(vec![reply(vec![call(
"submit",
"submit_judgment",
json!({"determination":true,"rationale":"The supplied sources support the subject."}),
)])]);
let fixture = Fixture::new(&server.endpoint);
fs::remove_file(fixture.config.join("habeas/config.toml")).unwrap();
fs::write(
fixture.project.join("habeas.toml"),
"version = 1\n[authoring]\ndefault = 'missing-parent-choice'\n",
)
.unwrap();
let nested = fixture.project.join("src/nested");
fs::create_dir(&nested).unwrap();
let workspace = nested.join("habeas.toml");
fs::write(
&workspace,
format!(
"version = 1\n[authoring]\ndefault = 'workspace'\n[authoring.configs.workspace]\npolicy = 'once'\nbackend = 'ollama'\nmodel = 'workspace-model'\nendpoint = '{}'\napi_key = 'WORKSPACE_LITERAL_KEY'\n",
server.endpoint
),
)
.unwrap();
let configurations = [fixture.project.join("habeas.toml"), workspace.clone()];
let before = configurations
.iter()
.map(|path| fs::read(path).unwrap())
.collect::<Vec<_>>();
let output = fixture
.command()
.current_dir(&nested)
.args(["author", SUBJECT])
.output()
.unwrap();
assert!(output.status.success(), "{output:?}");
// Running the configured feature rewrites neither configuration file,
// and creates no user configuration.
for (path, before) in configurations.iter().zip(&before) {
assert_eq!(&fs::read(path).unwrap(), before, "{}", path.display());
}
assert!(!fixture.config.join("habeas/config.toml").exists());
let requests = server.finish();
assert_eq!(requests.len(), 1);
assert_eq!(requests[0].body["model"], "workspace-model");
assert!(requests[0].headers.contains("WORKSPACE_LITERAL_KEY"));
assert!(
!requests[0]
.body
.to_string()
.contains("WORKSPACE_LITERAL_KEY")
);
let usage = fixture.usage();
assert_eq!(usage["model"], "workspace-model");
for text in [
usage.to_string(),
String::from_utf8_lossy(&output.stdout).into_owned(),
String::from_utf8_lossy(&output.stderr).into_owned(),
] {
assert!(!text.contains("WORKSPACE_LITERAL_KEY"), "{text}");
}
}
Input 5: outline tests/authoring_cli.rs fn[bedrock_cli_uses_selected_profile_region_and_converse_tools]
- File:
tests/authoring_cli.rs - Selector:
fn[bedrock_cli_uses_selected_profile_region_and_converse_tools] - Kind:
fn tests/authoring_cli.rs:1727–1920
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.initial_prompt`
// {test}`requirements.authoring.usage_requests`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.submission`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.output_limit`
#[test]
fn bedrock_cli_uses_selected_profile_region_and_converse_tools() {
for typed in [false, true] {
let mut read_call = json!({"toolUseId":"bedrock-read","name":"habeas",
"input":{"file":"extra.txt","line_start":1,"line_end":2}});
let mut submit_call = json!({"toolUseId":"bedrock-submit","name":"submit_judgment",
"input":{"determination":true,"rationale":"The supplied sources support the subject."}});
if typed {
read_call["type"] = json!("tool_use");
submit_call["type"] = json!("tool_use");
}
let first_message = json!({"role":"assistant","content":[
{"text":"Reading source."},{"toolUse":read_call}
]});
let server = Server::start(vec![
json!({
"output":{"message":first_message.clone()},
"stopReason":"tool_use",
"usage":{"inputTokens":19,"outputTokens":5,"totalTokens":24},
"metrics":{"latencyMs":1}
}),
json!({
"output":{"message":{"role":"assistant","content":[{"toolUse":submit_call}]}},
"stopReason":"tool_use",
"usage":{"inputTokens":19,"outputTokens":5,"totalTokens":24},
"metrics":{"latencyMs":1}
}),
]);
let fixture = Fixture::new(&server.endpoint);
let credentials = fixture.temp.path().join("aws-credentials");
let aws_config = fixture.temp.path().join("aws-config");
fs::write(&credentials, "[default]\naws_access_key_id = WRONG_DEFAULT_ACCESS_KEY\naws_secret_access_key = wrong-default-secret\n[habeas-test]\naws_access_key_id = FAKE_PROFILE_ACCESS_KEY\naws_secret_access_key = fake-profile-secret-for-local-test-only\n").unwrap();
fs::write(&aws_config, "[profile habeas-test]\nregion = eu-west-1\n").unwrap();
fs::write(fixture.config.join("habeas/config.toml"), "version = 1\n[authoring]\ndefault = 'cloud'\n[authoring.configs.cloud]\npolicy = 'once'\nbackend = 'bedrock'\nmodel = 'fixture-bedrock-model'\naws_profile = 'habeas-test'\nregion = 'us-west-2'\n[authoring.configs.cloud.options]\ntemperature = 0.25\nmaxTokens = 321\ntopP = 0.75\nstopSequences = ['END']\ntop_k = 12\n").unwrap();
let mut command = fixture.command();
for key in [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"AWS_SESSION_TOKEN",
"AWS_SECURITY_TOKEN",
"AWS_PROFILE",
"AWS_DEFAULT_PROFILE",
"AWS_REGION",
"AWS_DEFAULT_REGION",
"AWS_ENDPOINT_URL",
"AWS_IGNORE_CONFIGURED_ENDPOINT_URLS",
"AWS_BEARER_TOKEN_BEDROCK",
] {
command.env_remove(key);
}
let output = command
.env("AWS_CONFIG_FILE", aws_config)
.env("AWS_SHARED_CREDENTIALS_FILE", credentials)
.env("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", &server.endpoint)
.env("AWS_EC2_METADATA_DISABLED", "true")
.args(["author-evidence", SUBJECT])
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(requests.len(), 2);
assert_eq!(requests[1].body["messages"][1], first_message);
let result = &requests[1].body["messages"][2]["content"][0]["toolResult"];
assert_eq!(result["toolUseId"], "bedrock-read");
let delivered = result["content"][0]["text"].as_str().unwrap();
assert!(delivered.contains("extra.txt") && delivered.contains("context line 1"));
assert!(
requests[0]
.headers
.starts_with("POST /model/fixture-bedrock-model/converse HTTP/1.1\r\n")
);
assert!(
requests[0]
.headers
.contains("Credential=FAKE_PROFILE_ACCESS_KEY/")
);
assert!(
requests[0]
.headers
.contains("/us-west-2/bedrock/aws4_request")
);
assert!(!requests[0].headers.contains("WRONG_DEFAULT_ACCESS_KEY"));
let body = &requests[0].body;
assert_eq!(
body["inferenceConfig"],
json!({"temperature":0.25,"maxTokens":321,"topP":0.75,"stopSequences":["END"]})
);
// A configured maxTokens is used as given on every request.
assert_eq!(requests[1].body["inferenceConfig"]["maxTokens"], 321);
assert_eq!(body["additionalModelRequestFields"], json!({"top_k":12}));
let prompt = prompt_text(body);
assert!(
prompt.contains("Assess whether a project's tests adequately check")
&& prompt.contains(REQUIREMENT)
);
let tool_specs = body["toolConfig"]["tools"].as_array().unwrap();
for tool in tool_specs {
let schema = &tool["toolSpec"]["inputSchema"]["json"];
assert_eq!(schema["type"], "object");
for unsupported in ["oneOf", "allOf", "anyOf"] {
assert!(
schema.get(unsupported).is_none(),
"Bedrock rejects {unsupported} at the root of {}'s input schema",
tool["toolSpec"]["name"]
);
}
}
let habeas_schema = &tool_specs
.iter()
.find(|tool| tool["toolSpec"]["name"] == "habeas")
.unwrap()["toolSpec"]["inputSchema"]["json"];
assert_eq!(habeas_schema["additionalProperties"], false);
for field in ["file", "item", "requirements", "definition"] {
assert_eq!(habeas_schema["properties"][field]["type"], "string");
}
for field in ["line_start", "line_end"] {
assert_eq!(habeas_schema["properties"][field]["type"], "integer");
assert_eq!(habeas_schema["properties"][field]["minimum"], 1);
}
let judgment_schema = &tool_specs
.iter()
.find(|tool| tool["toolSpec"]["name"] == "submit_judgment")
.unwrap()["toolSpec"]["inputSchema"]["json"]["properties"]["determination"];
let outcomes = judgment_schema["oneOf"].as_array().unwrap();
assert!(outcomes.iter().any(|outcome| outcome["type"] == "boolean"));
let fixme = &outcomes
.iter()
.find(|outcome| outcome["type"] == "object")
.unwrap()["properties"]["FIXME"];
assert_eq!(fixme["type"], "array");
assert_eq!(fixme["minItems"], 1);
assert_eq!(fixme["items"]["type"], "string");
assert_eq!(fixme["items"]["minLength"], 1);
let mut tools = tool_specs
.iter()
.map(|tool| tool["toolSpec"]["name"].as_str().unwrap())
.collect::<Vec<_>>();
tools.sort();
assert_eq!(
tools,
[
"ast_grep",
"finish_search",
"github",
"habeas",
"list_files",
"next_page",
"outline",
"references",
"ripgrep",
"submit_judgment"
]
);
let evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
assert_eq!(evidence["determination"], true);
assert!(
evidence["inputs"]
.as_array()
.unwrap()
.iter()
.filter(|input| input["file"] == "extra.txt")
.collect::<Vec<_>>()
== habeas::outline_inputs_for_lines(&fixture.project, "extra.txt", 1, 2)
.unwrap()
.iter()
.collect::<Vec<_>>()
);
let usage = fixture.usage();
assert_eq!(usage["backend"], "bedrock");
assert_eq!(usage["model"], "fixture-bedrock-model");
assert_eq!(usage["tokens"]["input"], 38);
assert_eq!(usage["tokens"]["output"], 10);
assert_eq!(usage["request_count"], 2);
assert_eq!(usage["tool_calls"]["habeas"], 1);
assert_eq!(usage["tool_calls"]["submit_judgment"], 1);
assert_eq!(usage["outcome"], "completed");
}
}
Input 6: outline tests/authoring_cli.rs fn[all_adapters_preserve_prompt_tools_and_evidence_with_default_connections]
- File:
tests/authoring_cli.rs - Selector:
fn[all_adapters_preserve_prompt_tools_and_evidence_with_default_connections] - Kind:
fn tests/authoring_cli.rs:2481–2628
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.configuration_precedence`
#[test]
fn all_adapters_preserve_prompt_tools_and_evidence_with_default_connections() {
let submit =
json!({"determination":true,"rationale":"The supplied sources support the subject."});
// Ollama with no authentication configured sends no credential.
let server = Server::start(vec![reply(vec![call(
"submit",
"submit_judgment",
submit.clone(),
)])]);
let fixture = Fixture::new(&server.endpoint);
fs::write(
fixture.config.join("habeas/config.toml"),
format!(
"version = 1\n[authoring]\ndefault = 'local'\n[authoring.configs.local]\npolicy = 'once'\nbackend = 'ollama'\nmodel = '{MODEL}'\nendpoint = '{}'\n",
server.endpoint
),
)
.unwrap();
let output = fixture.run(&["author", SUBJECT]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(requests.len(), 1);
assert!(
!requests[0]
.headers
.to_ascii_lowercase()
.contains("authorization:")
);
assert_eq!(requests[0].body["model"], MODEL);
let ollama = prompt_and_tools(&requests[0].body);
let ollama_evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
// Bedrock without a profile or region uses the SDK default chain.
let server = Server::start(vec![json!({
"output":{"message":{"role":"assistant","content":[{"toolUse":
{"toolUseId":"submit","name":"submit_judgment","input":submit.clone()}}]}},
"stopReason":"tool_use",
"usage":{"inputTokens":1,"outputTokens":1,"totalTokens":2},
"metrics":{"latencyMs":1}
})]);
let fixture = Fixture::new(&server.endpoint);
fs::write(
fixture.config.join("habeas/config.toml"),
"version = 1\n[authoring]\ndefault = 'cloud'\n[authoring.configs.cloud]\npolicy = 'once'\nbackend = 'bedrock'\nmodel = 'default-chain-model'\n",
)
.unwrap();
let mut command = fixture.command();
for key in [
"AWS_SESSION_TOKEN",
"AWS_SECURITY_TOKEN",
"AWS_PROFILE",
"AWS_DEFAULT_PROFILE",
"AWS_DEFAULT_REGION",
"AWS_ENDPOINT_URL",
"AWS_IGNORE_CONFIGURED_ENDPOINT_URLS",
"AWS_BEARER_TOKEN_BEDROCK",
] {
command.env_remove(key);
}
let output = command
.env("AWS_CONFIG_FILE", fixture.temp.path().join("no-aws-config"))
.env(
"AWS_SHARED_CREDENTIALS_FILE",
fixture.temp.path().join("no-aws-credentials"),
)
.env("AWS_ACCESS_KEY_ID", "DEFAULT_CHAIN_ACCESS_KEY")
.env("AWS_SECRET_ACCESS_KEY", "default-chain-secret")
.env("AWS_REGION", "ap-south-1")
.env("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", &server.endpoint)
.env("AWS_EC2_METADATA_DISABLED", "true")
.args(["author", SUBJECT])
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(requests.len(), 1);
let headers = &requests[0].headers;
assert!(headers.starts_with("POST /model/default-chain-model/converse HTTP/1.1\r\n"));
assert!(headers.contains("Credential=DEFAULT_CHAIN_ACCESS_KEY/"));
assert!(headers.contains("/ap-south-1/bedrock/aws4_request"));
let bedrock = prompt_and_tools(&requests[0].body);
let bedrock_evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
// OpenAI uses its default credential environment variable.
let server = Server::start(vec![json!({
"id":"resp_submit", "object":"response", "status":"completed",
"model":"fixture-openai", "output":[{
"type":"function_call", "id":"fc_submit", "call_id":"submit",
"name":"submit_judgment", "arguments":submit.to_string(), "status":"completed"
}],
"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}
})]);
let fixture = Fixture::new(&server.endpoint);
fs::write(
fixture.config.join("habeas/config.toml"),
format!("version = 1\n[authoring]\ndefault = 'api'\n[authoring.configs.api]\npolicy = 'once'\nbackend = 'openai'\nmodel = 'fixture-openai'\nendpoint = '{}'\n", server.endpoint),
).unwrap();
let output = fixture
.command()
.env("OPENAI_API_KEY", AUTH)
.args(["author", SUBJECT])
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(requests.len(), 1);
assert!(
requests[0]
.headers
.starts_with("POST /responses HTTP/1.1\r\n")
);
assert!(requests[0].headers.contains(&format!("Bearer {AUTH}")));
assert_eq!(requests[0].body["model"], "fixture-openai");
let openai = prompt_and_tools(&requests[0].body);
let openai_evidence: Value =
serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
// Identical projects and submissions must preserve both request semantics
// and the entire evidence document, including inputs and reference hashes.
assert_eq!(ollama, bedrock);
assert_eq!(ollama, openai);
assert_eq!(ollama.1.len(), 10);
assert_eq!(ollama_evidence["requirement"], REQUIREMENT);
assert_eq!(ollama_evidence["determination"], true);
assert_eq!(ollama_evidence["rationale"], submit["rationale"]);
assert_eq!(ollama_evidence, bedrock_evidence);
assert_eq!(ollama_evidence, openai_evidence);
}
Input 7: outline tests/authoring_cli.rs fn[openai_responses_replays_tool_calls_and_records_usage]
- File:
tests/authoring_cli.rs - Selector:
fn[openai_responses_replays_tool_calls_and_records_usage] - Kind:
fn tests/authoring_cli.rs:5173–5284
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.rig_configuration_mapping`
// {test}`requirements.authoring.usage_requests`
// {test}`requirements.authoring.configuration_storage`
// {test}`requirements.authoring.usage_storage`
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.cache_checkpoints`
#[test]
// {test}`requirements.authoring.usage_storage`
fn openai_responses_replays_tool_calls_and_records_usage() {
fn assert_no_checkpoints(value: &Value) {
match value {
Value::Object(fields) => {
for (key, value) in fields {
assert!(
!matches!(key.as_str(), "cachePoint" | "cache_control"),
"explicit cache checkpoint: {key}"
);
if key == "type" {
assert!(
!matches!(value.as_str(), Some("cache_point" | "cache_checkpoint")),
"explicit cache checkpoint block: {value}"
);
}
assert_no_checkpoints(value);
}
}
Value::Array(values) => {
for value in values {
assert_no_checkpoints(value);
}
}
_ => {}
}
}
let response = |id: &str, name: &str, arguments: Value| {
json!({
"id": format!("resp_{id}"), "object":"response", "status":"completed",
"model":"fixture-openai", "output":[{
"type":"function_call", "id":format!("fc_{id}"), "call_id":id,
"name":name, "arguments":arguments.to_string(), "status":"completed"
}],
"usage":{"input_tokens":11,"output_tokens":7,"total_tokens":18,
"input_tokens_details":{"cached_tokens":3},
"output_tokens_details":{"reasoning_tokens":2}}
})
};
let server = Server::start(vec![
response(
"read",
"habeas",
json!({"file":"extra.txt","line_start":10}),
),
response(
"submit",
"submit_judgment",
json!({"determination":false,"rationale":"Missing implementation."}),
),
]);
let fixture = Fixture::new(&server.endpoint);
fs::write(fixture.config.join("habeas/config.toml"), format!(
"version = 1\n[authoring]\ndefault = 'mock'\n[authoring.configs.mock]\nbackend = 'openai'\nmodel = 'fixture-openai'\npolicy = 'once'\nendpoint = '{}'\napi_key_env = 'HABEAS_TEST_MODEL_KEY'\n[authoring.configs.mock.options]\nmax_output_tokens = 1024\nreasoning = {{ effort = 'low' }}\n", server.endpoint)).unwrap();
let output = fixture.run(&["author-evidence", SUBJECT]);
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let requests = server.finish();
assert_eq!(requests.len(), 2);
for request in &requests {
assert!(request.headers.starts_with("POST /responses HTTP/1.1\r\n"));
assert!(request.headers.contains(&format!("Bearer {AUTH}")));
assert_eq!(request.body["model"], "fixture-openai");
assert_eq!(request.body["max_output_tokens"], 1024);
assert_eq!(request.body["reasoning"]["effort"], "low");
assert_eq!(request.body["tools"].as_array().unwrap().len(), 10);
assert_no_checkpoints(&request.body);
}
assert!(
!requests[0].body["instructions"]
.as_str()
.unwrap()
.is_empty()
);
assert_eq!(
requests[0].body["instructions"],
requests[1].body["instructions"]
);
assert_eq!(requests[0].body["tools"], requests[1].body["tools"]);
let initial_input = requests[0].body["input"].as_array().unwrap();
let history = requests[1].body["input"].as_array().unwrap();
assert_eq!(history.len(), initial_input.len() + 2);
assert_eq!(&history[..initial_input.len()], initial_input.as_slice());
assert_eq!(history[initial_input.len()]["type"], "function_call");
assert_eq!(history[initial_input.len()]["call_id"], "read");
assert_eq!(
history[initial_input.len() + 1]["type"],
"function_call_output"
);
assert_eq!(history[initial_input.len() + 1]["call_id"], "read");
let usage = fixture.usage();
assert_eq!(usage["backend"], "openai");
assert_eq!(usage["outcome"], "completed");
assert_eq!(usage["request_count"], 2);
assert_eq!(usage["tokens"]["input"], 22);
assert_eq!(usage["tokens"]["output"], 14);
assert_eq!(usage["tokens"]["cached_input"], 6);
assert_eq!(usage["tokens"]["reasoning"], 4);
assert!(!usage.to_string().contains(AUTH));
}
Input 8: outline tests/live_bedrock.rs fn[live_bedrock_authoring]
- File:
tests/live_bedrock.rs - Selector:
fn[live_bedrock_authoring] - Kind:
fn tests/live_bedrock.rs:188–301
// {test}`requirements.integration.live_bedrock_test`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.provider`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.submission`
// {test}`requirements.authoring.persistence`
// {test}`requirements.authoring.usage_storage`
// {impl}`requirements.integration.live_bedrock_test`
#[test]
fn live_bedrock_authoring() {
if std::env::var_os("CI").is_some() {
report("warning: skipping live Bedrock test: CI is set");
return;
}
let LiveSelection {
config: selected,
workspace,
} = selected_config()
.expect("cannot select live Bedrock configuration")
.expect("no Bedrock authoring configuration; add one to your Habeas user config (see md/reference.md), or set CI=1 to disable live testing");
let BackendConfig::Bedrock(backend) = &selected.backend else {
unreachable!("selection only returns Bedrock configurations");
};
if !credentials_available(backend) {
return;
}
report(format!(
"live Bedrock test: configuration {:?}, model {:?}",
selected.name, backend.model
));
let temp = tempfile::tempdir().unwrap();
let project = temp.path().join("project");
for directory in [project.join("md"), project.join("src")] {
fs::create_dir_all(directory).unwrap();
}
fs::write(
project.join("Cargo.toml"),
"[package]\nname = 'live-fixture'\nversion = '0.1.0'\nedition = '2024'\n",
)
.unwrap();
fs::write(project.join("book.toml"), "[book]\nsrc = 'md'\n").unwrap();
if let Some(workspace) = &workspace {
fs::write(project.join("habeas.toml"), workspace).unwrap();
}
fs::write(
project.join("md/SUMMARY.md"),
"# Summary\n\n- [Requirements](requirements.md)\n",
)
.unwrap();
fs::write(
project.join("md/requirements.md"),
format!(":::{{req}} parity\n{REQUIREMENT}\n:::\n"),
)
.unwrap();
// No citation points to this file, so assessing its implementation requires
// an additional source read instead of only the mandatory initial inputs.
fs::write(project.join("src/parity.rs"), "pub fn is_even(value: u32) -> bool {\n value % 2 == 0\n}\n\n#[test]\nfn parity_cases() {\n assert!(is_even(0));\n assert!(!is_even(1));\n assert!(is_even(2));\n assert!(!is_even(u32::MAX));\n}\n").unwrap();
let checkout_evidence = Path::new(env!("CARGO_MANIFEST_DIR")).join("evidence");
let before = evidence_snapshot(&checkout_evidence);
let output = Command::new(env!("CARGO_BIN_EXE_habeas"))
.current_dir(&project)
.args([
"author-evidence",
SUBJECT,
"--config",
&selected.name,
"--stdout",
])
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&output.stderr);
report(&stderr);
assert!(
output.status.success(),
"live Bedrock authoring failed: {stderr}"
);
let evidence: Value = serde_json::from_slice(&output.stdout).expect("stdout is evidence JSON");
assert_eq!(evidence["requirement"], REQUIREMENT);
habeas::judgment::Judgment::from_value(&evidence["determination"]).unwrap();
assert!(!evidence["rationale"].as_str().unwrap().trim().is_empty());
assert!(
evidence["inputs"].as_array().unwrap().iter().any(|input| {
input["file"] == "src/parity.rs"
&& input["item"].is_string()
&& input["hash"].is_string()
&& input.get("text").is_none()
}),
"model must inspect the fixture's source through a read tool"
);
assert!(!project.join("evidence").exists());
assert_eq!(
evidence_snapshot(&checkout_evidence),
before,
"checkout evidence changed"
);
let usage_path = stderr
.lines()
.find_map(|line| line.strip_prefix("Usage: "))
.expect("reported usage path");
let usage: Value = serde_json::from_slice(&fs::read(usage_path).unwrap()).unwrap();
assert_eq!(usage["backend"], "bedrock");
assert_eq!(usage["model"], backend.model);
assert_eq!(usage["outcome"], "completed");
assert_eq!(usage["evidence_output"], "stdout");
assert_eq!(usage["evidence_written"], true);
assert!(usage["request_count"].as_u64().unwrap() >= 2);
assert!(usage["tool_calls"]["submit_judgment"].as_u64().unwrap() >= 1);
assert!(
usage["tool_calls"]["habeas"].as_u64().unwrap_or(0)
+ usage["tool_calls"]["ripgrep"].as_u64().unwrap_or(0)
> 0
);
}
Other sources
Input 1: requirements selection requirements.authoring.provider
requirements.authoring.provider:md/requirements/authoring.md:1573–1577
:::{req} provider
The authoring harness MUST use Rig and support Bedrock, Ollama, and OpenAI. Users MUST be
able to select a backend and model through configuration without changing the
assessment tools, prompt, or evidence format.
:::
Input 9: outline tests/authoring_cli.rs fn[prompt_and_tools]
- File:
tests/authoring_cli.rs - Selector:
fn[prompt_and_tools] - Kind:
fn tests/authoring_cli.rs:2451–2479
/// Returns the first request's prompt and sorted tool definitions, removing
/// only the provider-specific envelopes around each definition.
// {test}`requirements.authoring.prompt_parts`
fn prompt_and_tools(body: &Value) -> (String, Vec<(String, String, Value)>) {
let tools = body
.get("toolConfig")
.map_or(&body["tools"], |config| &config["tools"]);
let mut tools = tools
.as_array()
.unwrap()
.iter()
.map(|tool| {
let spec = tool
.get("toolSpec")
.or_else(|| tool.get("function"))
.unwrap_or(tool);
let parameters = spec
.get("inputSchema")
.map_or(&spec["parameters"], |schema| &schema["json"]);
(
spec["name"].as_str().unwrap().to_owned(),
spec["description"].as_str().unwrap().to_owned(),
parameters.clone(),
)
})
.collect::<Vec<_>>();
tools.sort_by(|left, right| left.0.cmp(&right.0));
(prompt_text(body), tools)
}