requirements.integration.live_bedrock_test
Requirements index · View definition
Requirement
The Habeas crate MUST have a Cargo integration test that exercises evidence authoring against a real configured Bedrock model when AWS credentials can be loaded. It MUST skip before reading configuration or resolving credentials when the
CIenvironment variable is present. Outside CI, it MUST fail when no Bedrock authoring configuration exists, and MUST skip with a visible warning when the AWS SDK cannot load credentials. Skip warnings MUST be visible under ordinarycargo testoutput.
HABEAS_LIVE_CONFIG, when set, MUST select a named authoring configuration for the test. Otherwise the test MUST use the configuration that authoring would select for the checkout underwhen it is a Bedrock configuration, falling back to the first Bedrock configuration in name order among the user and workspace configurations. The fixture project MUST resolve the selected name against the same workspace authoring configurations as the checkout. Malformed configuration and invalid explicit selections MUST fail the test. The selected profile, region, model, and options MUST come from that configuration; credential resolution MUST use the AWS SDK.
Once credentials load, model-request and authoring failures MUST fail the test rather than be treated as skips. The test MUST exercise an additional source read and judgment submission using a temporary project and stdout evidence output, without changing the checkout’s evidence. It MUST retain ordinary usage history and check the returned evidence and recorded usage. Deterministic tests MUST verify the CI and missing-credential skip paths and the missing-configuration failure without calling a model.
![]()
![]()
![]()
![]()
Rationale
The three tests in tests/live_bedrock.rs cover each obligation of requirements.integration.live_bedrock_test, and their assertions enforce the expected outcomes. I read the test bodies and the helpers skip_probe, select_config, selected_config, credentials_available and report.
Deterministic skip and failure paths (live_test_prerequisites_are_checked_without_inference). Each case re-runs the live_bedrock_authoring test in a child process through skip_probe. That helper clears every AWS_* variable and CI, and points the config and state directories and AWS files at a temp directory. It also points the Bedrock endpoint at an unusable local address, so no model is called.
- CI skip before reading configuration: The user config is deliberately malformed (
invalid TOML [) andCI=trueis set. The probe must exit successfully and print “skipping live Bedrock test: CI is set”. The same malformed config withoutCImust fail with “cannot select live Bedrock configuration”. Together these show that CI skips before the config is read. - Missing configuration fails outside CI: Three cases are covered: no config file, a config with no authoring section, and a config with only an Ollama configuration. Each must exit non-zero and print “no Bedrock authoring configuration”. None may print the skip warning.
- Invalid explicit selection fails:
HABEAS_LIVE_CONFIG=missingmust fail. - Missing credentials skip with a visible warning: A Bedrock configuration points at an AWS profile with empty credentials. The probe must exit successfully, and its stderr must contain “AWS credentials unavailable” and no “Usage:” line, so no authoring ran.
reportwrites straight to stderr, and the assertion reads the child’s stderr while the child test passes. That shows the warning is visible under ordinary libtest capture. - Failures after credentials load are not skips: Fake static AWS keys let credentials load. The probe must then fail with “live Bedrock authoring failed” and no skip message.
Selection and precedence (live_configuration_selection_follows_authoring_precedence). This test calls select_config directly. It covers these cases:
- The first Bedrock configuration in name order is chosen, skipping an earlier Ollama one.
- The profile, region, model and options come from the selected record.
- A Bedrock user default is used, and an Ollama default falls back.
- The per-project user selection beats the workspace default, which beats the user default.
- Workspace-only configuration works, and a workspace configuration overrides a same-named user one as a whole record.
- An explicit name wins over the other selections.
- A non-Bedrock explicit name and an unknown explicit name both fail.
- Malformed user config and malformed workspace config both fail.
- No Bedrock configuration at all returns
None. - The
workspacetext handed to the fixture project contains the authoring configurations but not the[evidence]section.
The selected_config wrapper only reads HABEAS_LIVE_CONFIG and passes it through, and the probe exercises it with the env var set to a missing name.
Live path (live_bedrock_authoring). It builds a temporary fixture project whose src/parity.rs no initial input cites. It runs author-evidence ... --config <name> --stdout and asserts the following:
- The command succeeds.
- The stdout evidence JSON has the right requirement text, a valid determination and a nonempty rationale.
- The inputs include a
src/parity.rsitem with a hash, which shows an additional source read. - The fixture has no
evidencedirectory, and a before/after snapshot shows the checkout’sevidenceis unchanged. - The usage record, found through the reported
Usage:path, has backendbedrock, the configured model, outcomecompleted,evidence_outputofstdoutandevidence_writtenof true. request_countis at least 2,submit_judgmentwas called at least once, and at least one read tool (habeasorripgrep) was called.
The test does not override the state directory, so it retains ordinary usage history. Credential resolution goes through the AWS SDK in credentials_available, using the configured profile, region and static credentials.
I found no obligation of the subject that is untested or only executed without an assertion. The cited requirements are context and were not reassessed.
Inputs
Implementation
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
);
}
Tests
Input 9: outline tests/live_bedrock.rs fn[live_test_prerequisites_are_checked_without_inference]
- File:
tests/live_bedrock.rs - Selector:
fn[live_test_prerequisites_are_checked_without_inference] - Kind:
fn tests/live_bedrock.rs:325–413
// {test}`requirements.integration.live_bedrock_test`
#[test]
fn live_test_prerequisites_are_checked_without_inference() {
let temp = tempfile::tempdir().unwrap();
let root = temp.path();
fs::create_dir_all(root.join("config/habeas")).unwrap();
let config_path = root.join("config/habeas/config.toml");
fs::write(&config_path, "invalid TOML [").unwrap();
let ci = skip_probe(root).env("CI", "true").output().unwrap();
assert!(
ci.status.success(),
"{}",
String::from_utf8_lossy(&ci.stderr)
);
assert!(String::from_utf8_lossy(&ci.stderr).contains("skipping live Bedrock test: CI is set"));
let malformed = skip_probe(root).output().unwrap();
assert!(!malformed.status.success());
assert!(
String::from_utf8_lossy(&malformed.stdout)
.contains("cannot select live Bedrock configuration")
);
fs::remove_file(&config_path).unwrap();
for contents in [
None,
Some("version = 1\n"),
Some(
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'fixture-model'\n",
),
] {
if let Some(contents) = contents {
fs::write(&config_path, contents).unwrap();
}
let missing_config = skip_probe(root).output().unwrap();
assert!(!missing_config.status.success());
assert!(
String::from_utf8_lossy(&missing_config.stdout)
.contains("no Bedrock authoring configuration")
);
assert!(
!String::from_utf8_lossy(&missing_config.stderr).contains("skipping live Bedrock test")
);
}
fs::remove_file(&config_path).unwrap();
let explicit_missing = skip_probe(root)
.env("HABEAS_LIVE_CONFIG", "missing")
.output()
.unwrap();
assert!(!explicit_missing.status.success());
assert!(
String::from_utf8_lossy(&explicit_missing.stdout)
.contains("cannot select live Bedrock configuration")
);
fs::write(&config_path, "version = 1\n[authoring.configs.cloud]\nbackend = 'bedrock'\nmodel = 'fixture-model'\naws_profile = 'missing-credentials'\nregion = 'us-east-1'\n").unwrap();
fs::write(
root.join("aws-config"),
"[profile missing-credentials]\nregion = us-east-1\n",
)
.unwrap();
fs::write(root.join("aws-credentials"), "").unwrap();
let missing_credentials = skip_probe(root).output().unwrap();
assert!(
missing_credentials.status.success(),
"{}",
String::from_utf8_lossy(&missing_credentials.stderr)
);
assert!(
String::from_utf8_lossy(&missing_credentials.stderr)
.contains("AWS credentials unavailable")
);
assert!(!String::from_utf8_lossy(&missing_credentials.stderr).contains("Usage:"));
let provider_failure = skip_probe(root)
.env("AWS_ACCESS_KEY_ID", "FAKE_LIVE_TEST_ACCESS_KEY")
.env("AWS_SECRET_ACCESS_KEY", "fake-live-test-secret")
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&provider_failure.stderr);
assert!(!provider_failure.status.success(), "{stderr}");
assert!(
stderr.contains("live Bedrock test: configuration"),
"{stderr}"
);
assert!(
String::from_utf8_lossy(&provider_failure.stdout).contains("live Bedrock authoring failed")
);
assert!(!stderr.contains("skipping live Bedrock test"), "{stderr}");
}
Input 10: outline tests/live_bedrock.rs fn[live_configuration_selection_follows_authoring_precedence]
- File:
tests/live_bedrock.rs - Selector:
fn[live_configuration_selection_follows_authoring_precedence] - Kind:
fn tests/live_bedrock.rs:415–537
// {test}`requirements.integration.live_bedrock_test`
#[test]
fn live_configuration_selection_follows_authoring_precedence() {
let temp = tempfile::tempdir().unwrap();
let user_path = temp.path().join("config.toml");
let root = temp.path().join("checkout");
fs::create_dir_all(&root).unwrap();
let root = fs::canonicalize(root).unwrap();
let configs = "[authoring.configs.alpha]\nbackend = 'bedrock'\nmodel = 'model-alpha'\naws_profile = 'profile-alpha'\nregion = 'us-west-2'\noptions = { temperature = 0.5 }\n\
[authoring.configs.beta]\nbackend = 'bedrock'\nmodel = 'model-beta'\naws_profile = 'profile-beta'\nregion = 'eu-west-1'\n\
[authoring.configs.aaa-local]\nbackend = 'ollama'\nmodel = 'model-local'\n";
let project = toml::Value::String(root.display().to_string());
let select = |user: Option<&str>, workspace: Option<&str>, explicit: Option<&str>| {
match user {
Some(user) => fs::write(&user_path, format!("version = 1\n{user}")).unwrap(),
None => {
let _ = fs::remove_file(&user_path);
}
}
match workspace {
Some(workspace) => fs::write(root.join("habeas.toml"), workspace).unwrap(),
None => {
let _ = fs::remove_file(root.join("habeas.toml"));
}
}
select_config(&user_path, &root, explicit)
};
let name = |user: Option<&str>, workspace: Option<&str>, explicit: Option<&str>| {
select(user, workspace, explicit)
.unwrap_or_else(|error| panic!("{user:?} {workspace:?} {explicit:?}: {error}"))
.map(|selection| selection.config.name)
};
let with = |head: &str| format!("[authoring]\n{head}\n{configs}");
// Without a selection, the first Bedrock configuration in name order,
// skipping the earlier Ollama one; its profile, region, model, and options
// come from that record.
let selection = select(Some(configs), None, None).unwrap().unwrap();
assert_eq!(selection.config.name, "alpha");
assert!(selection.workspace.is_none());
let BackendConfig::Bedrock(alpha) = &selection.config.backend else {
panic!("alpha is Bedrock");
};
assert_eq!(alpha.model, "model-alpha");
assert_eq!(alpha.aws_profile.as_deref(), Some("profile-alpha"));
assert_eq!(alpha.region.as_deref(), Some("us-west-2"));
assert_eq!(alpha.options.len(), 1);
// A Bedrock user default is used; an Ollama default falls back.
assert_eq!(
name(Some(&with("default = 'beta'")), None, None).unwrap(),
"beta"
);
assert_eq!(
name(Some(&with("default = 'aaa-local'")), None, None).unwrap(),
"alpha"
);
// The user's selection for this project wins over the default.
let projects = format!(
"[authoring]\ndefault = 'alpha'\n[authoring.projects.{project}]\nconfig = 'beta'\n{configs}"
);
assert_eq!(name(Some(&projects), None, None).unwrap(), "beta");
// The workspace default sits between the project selection and the user
// default, and workspace configurations are candidates.
let workspace = "version = 1\n[authoring]\ndefault = 'gamma'\n[authoring.configs.gamma]\nbackend = 'bedrock'\nmodel = 'model-gamma'\n[evidence]\ndisallow = ['src']\n";
let selection = select(Some(&with("default = 'alpha'")), Some(workspace), None)
.unwrap()
.unwrap();
assert_eq!(selection.config.name, "gamma");
// The fixture project receives the workspace authoring configurations but
// not its other settings.
let fixture: toml::Table = toml::from_str(selection.workspace.as_deref().unwrap()).unwrap();
assert_eq!(
fixture["authoring"]["configs"]["gamma"]["model"].as_str(),
Some("model-gamma")
);
assert!(fixture.get("evidence").is_none(), "{fixture:?}");
assert_eq!(
name(Some(&projects), Some(workspace), None).unwrap(),
"beta"
);
let workspace_only =
"version = 1\n[authoring.configs.gamma]\nbackend = 'bedrock'\nmodel = 'model-gamma'\n";
assert_eq!(name(None, Some(workspace_only), None).unwrap(), "gamma");
let merged_user = "[authoring.configs.beta]\nbackend = 'bedrock'\nmodel = 'user-beta'\n";
let merged_workspace =
"version = 1\n[authoring.configs.aaa]\nbackend = 'bedrock'\nmodel = 'workspace-aaa'\n";
assert_eq!(
name(Some(merged_user), Some(merged_workspace), None).unwrap(),
"aaa"
);
// An explicit name wins over every other selection.
assert_eq!(
name(Some(&projects), Some(workspace), Some("alpha")).unwrap(),
"alpha"
);
// Invalid explicit selections and malformed configuration fail.
let error = select(Some(configs), None, Some("aaa-local"))
.err()
.unwrap();
assert!(
error
.to_string()
.contains("must select a Bedrock configuration"),
"{error}"
);
let error = select(Some(configs), None, Some("missing")).err().unwrap();
assert!(
error.to_string().contains("unknown configuration"),
"{error}"
);
assert!(select(Some("[authoring"), None, None).is_err());
assert!(select(Some(configs), Some("version = ["), None).is_err());
// Without a Bedrock configuration there is nothing to select.
assert!(
name(
Some("[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\n"),
None,
None
)
.is_none()
);
assert!(name(None, None, None).is_none());
}
Referenced definitions
Input 2: requirements selection requirements.authoring.configuration_precedence
requirements.authoring.configuration_precedence:md/requirements/authoring.md:1775–1793
:::{req} configuration_precedence
{impl}`requirements.configuration.feature_sections`
`--config <name>` MUST select a configuration for that invocation. Otherwise,
authoring MUST use the user's selection for the canonical project root, then the
workspace default, then the user's default. Named workspace configurations MUST
override same-named user configurations as complete records. Backend, model,
connection settings, and options MUST come from the selected record as a unit;
fields MUST NOT be merged between records. Workspace-only authoring MUST work
without a user configuration file. Missing configuration or an unknown selection
MUST identify the relevant configuration file and point to documented examples.
An explicit Bedrock AWS profile or region MUST override the corresponding SDK
default; omitted values MUST use standard AWS SDK resolution. Ollama MUST use
its configured endpoint or `http://localhost:11434`. If `api_key_env` is set, its
named variable MUST supply the credential; a missing or empty value MUST produce
an error before a model request. OpenAI MUST use its configured endpoint or
`https://api.openai.com/v1`, and MUST resolve `OPENAI_API_KEY` when neither
`api_key` nor `api_key_env` is supplied.
:::
Input 3: 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 4: requirements selection requirements.authoring.source_tools
requirements.authoring.source_tools:md/requirements/authoring.md:637–699
:::{req} source_tools
The harness MUST expose a `habeas` tool accepting exactly one of these request
forms. Each form MUST correspond to one existing evidence-input kind:
| Request fields | Evidence input returned | Definition |
| --- | --- | --- |
| `file: String`, `line_start: Integer`, optional `line_end: Integer` | Outline inputs for the innermost outline nodes covering the range | {cite}`requirements.ci.outline_inputs` |
| `file: String`, `item: String` | Outline input | {cite}`requirements.ci.outline_inputs` |
| `requirements: String` | Requirements input, including its matching names | {cite}`requirements.ci.requirements_inputs` |
| `definition: String` | Definition input | {cite}`requirements.definitions.inputs` |
Selector arguments MUST use the syntax defined by
{cite}`requirements.references.outline_selectors`. Reads MUST use the current
project working tree, including unstaged changes to tracked files and staged new
files. By default, source inputs MUST stay within the project root after
resolving symlinks; in a Git worktree, both the requested file and its resolved
target MUST be present in the Git index. Projects outside Git MUST use the same
containment rules without requiring an index. Failure to read an existing
repository's index MUST be reported as an error.
The project-root `evidence/` directory MUST be excluded from model reads by
default, including symlink aliases. Every source the harness supplies to the
model MUST be redacted under {cite}`requirements.authoring.redaction`. Generated build outputs MUST follow
{cite}`requirements.authoring.generated_inputs`. Workspace path overrides MUST
follow {cite}`requirements.configuration.evidence_paths`, including explicit
permission for otherwise excluded inputs. A denied mandatory input MUST abort
under {cite}`requirements.authoring.read_denial.mandatory`, and a denied model
read MUST return a tool error under {cite}`requirements.authoring.read_denial`.
Line numbers are only a way to request sources; recorded evidence MUST identify
sources by outline selector and structural hash, never by line number. Request
line numbers MUST be one-based and inclusive, and omitting `line_end` MUST read
through EOF. A line-range request MUST be resolved to the innermost outline
nodes covering the requested lines, which are `line` nodes in a file using the
plain-text profile; the result MUST show the model each node's selector and
source text, without line numbers, and the harness MUST record those nodes as
outline inputs. The model-facing tool description MUST include the argument conventions
from the cited requirements, including outline selector syntax, definition
selections, and full definition names, with a short request example for each form.
A successful call MUST return the requested evidence input, populated by the
harness with the selected source text, using the existing evidence schema.
{cite}`requirements.ci.schema`
Required terminology dependencies MUST be returned alongside it as additional
definition inputs under {cite}`requirements.definitions.authoring_inputs`.
For item, requirement, and definition selections, the result MUST have this shape:
```text
HabeasResult {
input: EvidenceInput,
definitions: Array<DefinitionInput>,
}
```
Line-range selections can contain multiple outline nodes. Their result MUST use
`inputs: Array<EvidenceInput>` instead of the singular `input` field, including
when only one node is selected.
`definitions` MUST be empty when no additional terminology is required. The
harness MUST record inputs supplied to the model in the assessment's evidence.
A failed read MUST add no evidence input. Access-policy denials MUST be handled
under {cite}`requirements.authoring.read_denial`; other failed reads MUST return
an explanatory tool error.
:::
Input 5: requirements selection requirements.authoring.submission
requirements.authoring.submission:md/requirements/authoring.md:1213–1245
:::{req} submission
The harness MUST expose a `submit_judgment` tool accepting exactly these fields:
```text
submit_judgment({ determination: Judgment, rationale: String })
Judgment = Boolean | { FIXME: Array<String> }
```
The judgment MUST use the three outcomes and nonempty FIXME entries defined by
{cite}`requirements.ci.outcomes`.
`rationale` MUST be nonempty Markdown. This tool call MUST supply the final
assessment result. The model MUST obtain exactly one accepted submission over the entire
assessment. Rejected attempts under
{cite}`requirements.authoring.submission.searches.recovery` and
{cite}`requirements.authoring.line_numbers.rejection` do not count as accepted
submissions. If a response ends without invoking it, and the assessment has
not already been reminded, the harness MUST continue the conversation with one
user message, `Reminder: you MUST submit your result with the submit_judgment
tool.`, naming the assessment's submission tool. If a later response also ends
without invoking it, or a response contains multiple submission calls, the harness MUST
report an error and leave existing evidence unchanged. The reminder MUST be
counted in usage like any other turn.
The harness MUST check the complete model response for multiple submissions
before accepting one. Invalid submission arguments MUST also fail the assessment.
A valid single submission MUST finish the assessment; there is no submission
repair or resubmission loop, except the one continuation after a response cut
off at its output limit under {cite}`requirements.authoring.output_limit`, the
one reminder above, and the one resubmission after a rejection under
{cite}`requirements.authoring.line_numbers.rejection`, and recovery under
{cite}`requirements.authoring.submission.searches.recovery`. An assessment that fails before accepting a valid
judgment MUST emit no evidence JSON to stdout.
:::
Input 6: requirements selection requirements.authoring.persistence
requirements.authoring.persistence:md/requirements/authoring.md:2152–2161
:::{req} persistence
After one valid judgment, the harness MUST write the subject text, submitted
determination and rationale, and recorded inputs using the existing evidence
schema. {cite}`requirements.ci.schema`
By default, it MUST write the subject's evidence file. With `--stdout`, it MUST
emit a single evidence JSON object followed by a newline to stdout and MUST NOT
create or change evidence files or directories. All three outcomes MUST be
written to the selected destination as completed assessments; their validation
status MUST follow {cite}`requirements.ci.determination`.
:::
Input 7: requirements selection requirements.authoring.usage_storage
requirements.authoring.usage_storage:md/requirements/authoring.md:2165–2179
:::{req} usage_storage
Each assessment MUST have a separate JSON usage record under
`<state-root>/authoring/usage/<run-id>.json` using
{cite}`requirements.configuration.state_location`.
It MUST identify its format version, run, project root, subject kind and full
name, start time, backend and model when known, end time when finished, outcome,
accepted determination kind (`true`, `false`, or `FIXME`) when present, and
whether evidence was written. It MUST record the selected output destination in
`evidence_output` as `file` or `stdout`; a successful write to either destination
MUST set `evidence_written` to true. Usage recording MUST remain outside the
project in stdout mode. FIXME entry text MUST NOT be stored in usage records.
Failed, cancelled, or unfinished
runs MUST remain distinguishable from completed judgments. Records MUST persist
for later review without storing source text, prompts, responses, or rationale.
:::
Other sources
Input 1: requirements selection requirements.integration.live_bedrock_test
requirements.integration.live_bedrock_test:md/requirements/integration.md:15–46
:::{req} live_bedrock_test
The Habeas crate MUST have a Cargo integration test that exercises evidence
authoring against a real configured Bedrock model when AWS credentials can be
loaded. It MUST skip before reading configuration or resolving credentials when
the `CI` environment variable is present. Outside CI, it MUST fail when no
Bedrock authoring configuration exists, and MUST skip with a visible warning when
the AWS SDK cannot load credentials. Skip warnings MUST be visible under ordinary
`cargo test` output.
`HABEAS_LIVE_CONFIG`, when set, MUST select a named authoring configuration for
the test. Otherwise the test MUST use the configuration that authoring would
select for the checkout under {cite}`requirements.authoring.configuration_precedence`
when it is a Bedrock configuration, falling back to the first Bedrock
configuration in name order among the user and workspace configurations. The
fixture project MUST resolve the selected name against the same workspace
authoring configurations as the checkout. Malformed configuration and invalid explicit
selections MUST fail the test. The selected profile, region, model, and options
MUST come from that configuration; credential resolution MUST use the AWS SDK.
Once credentials load, model-request and authoring failures MUST fail the test
rather than be treated as skips. The test MUST exercise an additional source read
and judgment submission using a temporary project and stdout evidence output,
without changing the checkout's evidence. It MUST retain ordinary usage history
and check the returned evidence and recorded usage. Deterministic tests MUST
verify the CI and missing-credential skip paths and the missing-configuration
failure without calling a model.
{cite}`requirements.authoring.provider`
{cite}`requirements.authoring.source_tools`
{cite}`requirements.authoring.submission`
{cite}`requirements.authoring.persistence`
{cite}`requirements.authoring.usage_storage`
:::
Input 11: outline tests/live_bedrock.rs use@a552f69c94db
- File:
tests/live_bedrock.rs - Selector:
use@a552f69c94db - Kind:
use tests/live_bedrock.rs:1–1
use std::error::Error;
Input 12: outline tests/live_bedrock.rs use@0aa5aad345a4
- File:
tests/live_bedrock.rs - Selector:
use@0aa5aad345a4 - Kind:
use tests/live_bedrock.rs:2–2
use std::fs;
Input 13: outline tests/live_bedrock.rs use@b9ad51f029df
- File:
tests/live_bedrock.rs - Selector:
use@b9ad51f029df - Kind:
use tests/live_bedrock.rs:3–3
use std::io::{self, Write};
Input 14: outline tests/live_bedrock.rs use@e843693d3cbe
- File:
tests/live_bedrock.rs - Selector:
use@e843693d3cbe - Kind:
use tests/live_bedrock.rs:4–4
use std::path::Path;
Input 15: outline tests/live_bedrock.rs use@005abb79b847
- File:
tests/live_bedrock.rs - Selector:
use@005abb79b847 - Kind:
use tests/live_bedrock.rs:5–5
use std::process::Command;
Input 16: outline tests/live_bedrock.rs use@8e54b45306f5
- File:
tests/live_bedrock.rs - Selector:
use@8e54b45306f5 - Kind:
use tests/live_bedrock.rs:7–7
use aws_sdk_bedrockruntime::config::ProvideCredentials;
Input 17: outline tests/live_bedrock.rs use@abb3fccb24f6
- File:
tests/live_bedrock.rs - Selector:
use@abb3fccb24f6 - Kind:
use tests/live_bedrock.rs:8–8
use habeas::config::{self, BackendConfig, BedrockConfig, ResolvedAuthoringConfig};
Input 18: outline tests/live_bedrock.rs use@ae28650edb42
- File:
tests/live_bedrock.rs - Selector:
use@ae28650edb42 - Kind:
use tests/live_bedrock.rs:9–9
use serde_json::Value;
Input 19: outline tests/live_bedrock.rs const[SUBJECT]
- File:
tests/live_bedrock.rs - Selector:
const[SUBJECT] - Kind:
const tests/live_bedrock.rs:11–11
const SUBJECT: &str = "requirements.parity";
Input 20: outline tests/live_bedrock.rs const[REQUIREMENT]
- File:
tests/live_bedrock.rs - Selector:
const[REQUIREMENT] - Kind:
const tests/live_bedrock.rs:12–12
const REQUIREMENT: &str = "The is_even function in src/parity.rs MUST return true exactly when its unsigned integer argument is even. Its implementation and tests are in that file.";
Input 21: outline tests/live_bedrock.rs fn[report]
- File:
tests/live_bedrock.rs - Selector:
fn[report] - Kind:
fn tests/live_bedrock.rs:14–17
fn report(message: impl std::fmt::Display) {
// Direct stderr writes remain visible when libtest captures passing tests.
let _ = writeln!(io::stderr().lock(), "{message}");
}
Input 22: outline tests/live_bedrock.rs struct[LiveSelection]
- File:
tests/live_bedrock.rs - Selector:
struct[LiveSelection] - Kind:
struct tests/live_bedrock.rs:19–24
/// The configuration the live test uses, and the `habeas.toml` text that gives
/// the fixture project the checkout's workspace authoring configurations.
struct LiveSelection {
config: ResolvedAuthoringConfig,
workspace: Option<String>,
}
Input 23: outline tests/live_bedrock.rs fn[selected_config]
- File:
tests/live_bedrock.rs - Selector:
fn[selected_config] - Kind:
fn tests/live_bedrock.rs:26–35
// {test}`requirements.authoring.configuration_precedence`
fn selected_config() -> Result<Option<LiveSelection>, Box<dyn Error>> {
let root = fs::canonicalize(env!("CARGO_MANIFEST_DIR"))?;
let explicit = match std::env::var("HABEAS_LIVE_CONFIG") {
Ok(name) => Some(name),
Err(std::env::VarError::NotPresent) => None,
Err(error) => return Err(error.into()),
};
select_config(&config::user_config_path()?, &root, explicit.as_deref())
}
Input 24: outline tests/live_bedrock.rs fn[select_config]
- File:
tests/live_bedrock.rs - Selector:
fn[select_config] - Kind:
fn tests/live_bedrock.rs:37–123
/// Selects a Bedrock configuration from the user file at `path` and the
/// workspace configuration of `root`: an explicit name, else the selection
/// authoring would make for `root` when it is Bedrock, else the first Bedrock
/// configuration in name order.
// {test}`requirements.authoring.configuration_precedence`
fn select_config(
path: &Path,
root: &Path,
explicit: Option<&str>,
) -> Result<Option<LiveSelection>, Box<dyn Error>> {
let user = config::load_user_config(path)?;
let workspace = config::load_workspace_config(root)?;
let resolve = |name: &str| {
config::resolve_authoring_with_workspace_from(
path,
user.as_ref(),
workspace.as_ref(),
root,
Some(name),
)
};
let bedrock =
|selected: &ResolvedAuthoringConfig| matches!(selected.backend, BackendConfig::Bedrock(_));
let authoring = user.as_ref().and_then(|user| user.authoring.as_ref());
let local = workspace
.as_ref()
.and_then(|workspace| workspace.config.authoring.as_ref());
let selected = if let Some(name) = explicit {
let selected = resolve(name)?;
if !bedrock(&selected) {
return Err(
format!("HABEAS_LIVE_CONFIG={name:?} must select a Bedrock configuration").into(),
);
}
Some(selected)
} else {
// The same precedence as authoring: the user's selection for this
// project, then the workspace default, then the user default.
let preferred = authoring
.and_then(|authoring| authoring.projects.get(root))
.map(|selection| selection.config.as_str())
.or_else(|| local.and_then(|local| local.default.as_deref()))
.or_else(|| authoring.and_then(|authoring| authoring.default.as_deref()));
let preferred = preferred
.map(resolve)
.transpose()?
.filter(|selected| bedrock(selected));
match preferred {
Some(selected) => Some(selected),
None => {
let names = local
.into_iter()
.flat_map(|local| local.configs.keys())
.chain(
authoring
.into_iter()
.flat_map(|authoring| authoring.configs.keys()),
)
.collect::<std::collections::BTreeSet<_>>();
let mut first = None;
for name in names {
let selected = resolve(name)?;
if bedrock(&selected) {
first = Some(selected);
break;
}
}
first
}
}
};
let Some(config) = selected else {
return Ok(None);
};
// The fixture project resolves `--config` against the same workspace
// configurations as the checkout; other workspace settings stay behind.
let workspace = match &workspace {
Some(workspace) if workspace.config.authoring.is_some() => {
let text = fs::read_to_string(&workspace.path)?;
let mut table: toml::Table = toml::from_str(&text)?;
table.retain(|key, _| key == "version" || key == "authoring");
Some(toml::to_string(&table)?)
}
_ => None,
};
Ok(Some(LiveSelection { config, workspace }))
}
Input 25: outline tests/live_bedrock.rs fn[credentials_available]
- File:
tests/live_bedrock.rs - Selector:
fn[credentials_available] - Kind:
fn tests/live_bedrock.rs:125–162
// {test}`requirements.authoring.configuration_precedence`
// {test}`requirements.authoring.credentials`
fn credentials_available(config: &BedrockConfig) -> bool {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let mut loader = aws_config::defaults(aws_config::BehaviorVersion::latest());
if let Some(profile) = &config.aws_profile {
loader = loader.profile_name(profile);
}
if let Some(region) = &config.region {
loader = loader.region(aws_config::Region::new(region.clone()));
}
if let Some(credentials) = &config.credentials {
loader = loader.credentials_provider(aws_sdk_bedrockruntime::config::Credentials::new(
credentials.access_key_id.expose_secret(),
credentials.secret_access_key.expose_secret(),
credentials.session_token.as_ref().map(|value| value.expose_secret().to_owned()),
None,
"Habeas configuration",
));
}
let sdk = loader.load().await;
let Some(provider) = sdk.credentials_provider() else {
report("warning: skipping live Bedrock test: no AWS credential provider");
return false;
};
if let Err(error) = provider.provide_credentials().await {
report(format!(
"warning: skipping live Bedrock test: AWS credentials unavailable: {error}"
));
return false;
}
assert!(
sdk.region().is_some(),
"live Bedrock test has credentials but no AWS region; set a profile region or the authoring configuration's region"
);
true
})
}
Input 26: outline tests/live_bedrock.rs fn[evidence_snapshot]
- File:
tests/live_bedrock.rs - Selector:
fn[evidence_snapshot] - Kind:
fn tests/live_bedrock.rs:164–186
// {cite}`habeas:util`
fn evidence_snapshot(root: &Path) -> std::collections::BTreeMap<std::path::PathBuf, Vec<u8>> {
let mut files = std::collections::BTreeMap::new();
let mut pending = vec![root.to_owned()];
while let Some(path) = pending.pop() {
if !path.exists() {
continue;
}
if path.is_dir() {
pending.extend(
fs::read_dir(&path)
.unwrap()
.map(|entry| entry.unwrap().path()),
);
} else {
files.insert(
path.strip_prefix(root).unwrap().to_owned(),
fs::read(path).unwrap(),
);
}
}
files
}
Input 27: outline tests/live_bedrock.rs fn[skip_probe]
- File:
tests/live_bedrock.rs - Selector:
fn[skip_probe] - Kind:
fn tests/live_bedrock.rs:303–323
fn skip_probe(root: &Path) -> Command {
let mut command = Command::new(std::env::current_exe().unwrap());
command.args(["--exact", "live_bedrock_authoring"]);
for (key, _) in std::env::vars_os() {
if key.to_string_lossy().starts_with("AWS_") {
command.env_remove(key);
}
}
command
.env_remove("CI")
.env_remove("HABEAS_LIVE_CONFIG")
.env("XDG_CONFIG_HOME", root.join("config"))
.env("APPDATA", root.join("config"))
.env("XDG_STATE_HOME", root.join("state"))
.env("LOCALAPPDATA", root.join("state"))
.env("AWS_CONFIG_FILE", root.join("aws-config"))
.env("AWS_SHARED_CREDENTIALS_FILE", root.join("aws-credentials"))
.env("AWS_EC2_METADATA_DISABLED", "true")
.env("AWS_ENDPOINT_URL_BEDROCK_RUNTIME", "http://127.0.0.1:9");
command
}