Skip to content

spec(030): verification and closure - #420

Merged
bartekus merged 1 commit into
mainfrom
spec/030-closure
Oct 30, 2026
Merged

bartekus merged 1 commit into
mainfrom
spec/030-closure

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Summary

Spec 030 (AWS Bedrock backend): verification and closure, after #416 recorded the Responses exchange.

  • implementation: complete: every acceptance item is met. The implementation record gains a closing entry mapping each acceptance item and section 5 row to its tests, and notes that increment 2's "blocked on the owner" paragraph is resolved (live probe and smoke ran on both wires within R-29's cap; recorded fixtures exist; 030 is already in VERIFIED_SPECS).
  • Adds integrations/rustev-bedrock/tests/environment.rs for the one acceptance item with no test: without the aws-config feature, aws-config is an optional dependency only that feature enables, and no compiled source (own modules, the #[path] sources, the binary, the example) outside the feature module and the smoke example touches std::env. Checked to fail when an std::env read is planted in src/mapping.rs.
  • The summary no longer says implementation is pending.
  • status: is unchanged. No contract text changes.

This unblocks spec 039's Bedrock rank items (A-49): its offline fixtures and swap test, then the optional paid live rank smoke (Decision 18).

Verification

  • spec-spine verify 030: passed (3 commands).
  • cargo clippy -p rustev-bedrock --all-targets -- -D warnings, with and without aws-config; cargo fmt --all --check.
  • make gate: passed after make refresh.
  • scripts/check-authored-content.sh: clean.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the two changed files.

integrations/rustev-bedrock/tests/environment.rs

The compiled_sources() helper iterates over ["src/bin", "examples"] and calls std::fs::read_dir(root.join(dir)).unwrap() for each. If src/bin/ does not exist in the crate (which is the normal case for a library integration that exposes only an example, as the ALLOWED list implies — it lists examples/smoke.rs but no binary), this unwrap panics and the test hard-fails with an unhelpful "No such file or directory" rather than passing or giving a meaningful message. The examples/ path is evidenced by the ALLOWED constant; src/bin/ is not evidenced anywhere in the diff or the repo context for this crate.

No other concrete defects found in either file. The module-discovery loop only matches pub mod name; and misses mod name; (private modules), but the feature-gated file (aws_config_provider.rs) is explicitly listed in ALLOWED, so that gap does not create a false-negative for the env-access check in practice.

specs/030-bedrock-backend/spec.md

Lifecycle transition from in-progress to complete under an already-approved spec is consistent with the contract table. The closure section is documentation only and contains no governance contradiction.

{"head": "b312586bd514e4cd28a8ee394ec8cc455d38f08d", "verdict": "findings", "findings": [{"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 65, "summary": "`std::fs::read_dir(root.join(\"src/bin\")).unwrap()` panics if the `src/bin/` directory does not exist, which is the expected layout for a library crate with no binary — causing the test to hard-fail rather than pass."}]}

Subject: 90dcc79...b312586, diff digest 11d55186d97d363c479553f3b405b88367c0d785fb808762286eb1b6fd304999, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 20:48 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reading the diff closely: the spec advances 030-bedrock-backend from in-progress to complete and adds a closure narrative; the second file is a brand-new acceptance test.


specs/030-bedrock-backend/spec.md

The lifecycle transition from approved + in-progress to approved + complete is a valid terminal state per the contract table. The closure text is self-consistent and makes no quality or residency-compliance claim. No issue here.


integrations/rustev-bedrock/tests/environment.rs

compiled_sources() does not recursively follow module declarations.

The function reads lib.rs and extracts module names declared there, adding one file per mod name; line. It does not repeat the scan for the files it discovers. Any sub-module declared inside a non-lib.rs source file (e.g., src/signing.rs declaring mod helpers;) is never added to the list. The function's own doc comment claims to enumerate "every source file compiled into the crate," but it only reaches one level of depth.

Concretely: if any non-allowed, non-lib.rs module file contains a nested mod x; whose body accesses std::env, the test no_environment_access_outside_the_feature_module_and_the_smoke would not scan that nested file and would not detect the violation. For a crate with more than a handful of source files (assert!(files.len() > 20) confirms there are at least that many), this is a meaningful coverage gap.

No other concrete defects are present. The aws_config_is_optional_and_enabled_only_by_its_feature test's per-line TOML parsing and the post-loop default = guard are each consistent with the spec's intent; the #[cfg(test)] split in no_environment_access_outside_the_feature_module_and_the_smoke is an accepted simplification; and the lifetime usage in the section-tracking loop is sound.

{"head": "77b661bda607c7c7565d44ead1cd90db75d723c6", "verdict": "findings", "findings": [{"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 44, "summary": "compiled_sources() only reads module declarations from lib.rs and does not recurse into the discovered files, so sub-modules declared in non-lib.rs source files are never scanned and any std::env access inside them silently escapes the no_environment_access test."}]}

Subject: 90dcc79...77b661b, diff digest d1b0a93dfa4be0f9fac875214d6bb2baacda2cee2e189088fc67f6837a80fa2c, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 20:52 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the two changed files.

specs/030-bedrock-backend/spec.md — The status change from in-progress to complete is well-supported by the closure section. Under the contract table, approved + complete = settled, unresolved units are errors. The closure lists every acceptance item and its test. The narrative is internally consistent.

integrations/rustev-bedrock/tests/environment.rs — Two concrete defects:

1. declared_modules silently drops module declarations that have trailing inline comments (false negative in the env-access scan).

Lines 62–68:

} else if let Some(name) = line
    .split_once("mod ")
    .filter(|(vis, _)| vis.is_empty() || vis.starts_with("pub"))
    .and_then(|(_, l)| l.strip_suffix(';'))

l.strip_suffix(';') returns None for mod foo; // any comment, so the module is not discovered and its file is never added to the scan queue. The test then silently passes without checking that file for std::env use. Because declared_modules is recursive, one such annotation at any depth causes all files reachable through that subtree to escape the scan.

2. compiled_sources feeds every entry from src/bin and examples into declared_modules, which unconditionally calls std::fs::read_to_string(file).unwrap() — this panics on any subdirectory or non-text file in those directories.

Lines 78–83: read_dir is called on src/bin and examples and all returned entries (including potential subdirectories or non-.rs files) are enqueued. declared_modules immediately does std::fs::read_to_string(file).unwrap() with no file-type guard. A subdirectory, a .gitkeep, or a data file causes a panic rather than a graceful skip. The test asserts specific files exist but does not assert the directory contains only those files, so the guard is incomplete.

{"head": "9e3d1a30e411c5beb5bdc731e1ad948a3d3f150c", "verdict": "findings", "findings": [{"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 66, "summary": "`strip_suffix(';')` silently misses `mod name; // comment` declarations, causing those files to be excluded from the environment-access scan without any error or warning."}, {"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 80, "summary": "`compiled_sources` enqueues all `read_dir` entries from `src/bin` and `examples` without filtering to `.rs` files, so any subdirectory or non-text file causes `declared_modules` to panic via `read_to_string(...).unwrap()`."}]}

Subject: 90dcc79...9e3d1a3, diff digest 07334b3726e73578d40865d4fccfc89284d56aa3761c2998e35b662707b17285, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 20:55 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at the two changed files: the spec lifecycle update (in-progress → complete) and the new environment.rs test file.

Spec changes — the lifecycle transition (approved + complete) is the correct settled state per the contract. The summary and closure prose are consistent. No governance defect.

integrations/rustev-bedrock/tests/environment.rs

The enforcement logic in no_environment_access_outside_the_feature_module_and_the_smoke has a concrete false-negative gap:

let shipped = text.split("#[cfg(test)]").next().unwrap();

split(...).next() yields only the substring before the first "#[cfg(test)]" occurrence. Any production (non-test) code that appears after the first test block is silently excluded from the scan. A Rust source file can legally have multiple #[cfg(test)]-annotated items interspersed with non-test code; only the portion before the very first such attribute is checked. The acceptance criterion this test covers (spec 030 §3.5) requires that no compiled source outside the feature module and the smoke example reads std::env. A file structured as:

fn a() { … }            // scanned ✓
#[cfg(test)] mod t1 { … }
fn b() { std::env::var("X"); … }   // not scanned ✗
#[cfg(test)] mod t2 { … }

would pass the test despite b reading the environment. The spec closure adds this test as the primary coverage for criterion 3.5, so the gap is load-bearing.

A secondary robustness issue: root.join(a).canonicalize().unwrap() in the ALLOWED check panics rather than producing a meaningful assertion failure if either listed path does not exist (line ~95). This does not affect correctness when the files are present, but is worth noting.

{"head": "8155fdc2b068754b4ed18ddab5322f561a6af38e", "verdict": "findings", "findings": [{"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 91, "summary": "split(\"#[cfg(test)]\").next() only examines code before the first test attribute, silently omitting production code that follows any earlier #[cfg(test)] block, yielding false negatives for the spec 030 §3.5 acceptance criterion."}]}

Subject: 90dcc79...8155fdc, diff digest 6bb970cd5f8a027bcf185e63fb095ab15e83c07c63bc0fcc99cdd9bd853189ca, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 20:58 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at both changed files.

specs/030-bedrock-backend/spec.md — The frontmatter transition from implementation: in-progress to implementation: complete under status: approved is correct per the contract's lifecycle table (approved + complete = settled). The closure prose is informational and internally consistent with the preceding increment narrative.

integrations/rustev-bedrock/tests/environment.rs — I see one concrete defect and one theoretical concern.

Concrete defect — overly broad default = assertion (line 36):

assert!(!manifest.lines().any(|l| l.trim().starts_with("default =")));

This rejects any Cargo.toml that contains a default = [...] line anywhere in the file, even default = [] (an explicit empty feature set). The actual requirement is that aws-config is not among the default features. That is already enforced by the match section loop inside: any line containing "aws-config" that is in [features] must equal exactly r#"aws-config = ["dep:aws-config"]"#, so a default = ["aws-config"] line would already be caught there. The outer assertion adds no protection against the aws-config-in-defaults scenario, but does incorrectly reject valid manifests that explicitly declare default = []. A future maintainer adding default = [] to document the crate's no-default-features intent would get a spurious test failure.

Theoretical concern — usize underflow in without_test_items (line 93):

'}' => depth -= 1,

In debug builds usize subtraction panics on underflow. Because the iteration always starts at the { character (so depth reaches 1 before any } can appear), and valid Rust source has balanced braces, this is harmless for the intended inputs. Not reporting as a finding.

{"head": "e84ffd720f2a55f1cc09b79af893fcd3c27629ce", "verdict": "findings", "findings": [{"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 36, "summary": "The assertion `!manifest.lines().any(|l| l.trim().starts_with(\"default =\"))` is broader than the acceptance criterion: it fails on any Cargo.toml with a `default = []` entry (valid, explicit no-default-features) even though the loop already catches aws-config appearing in a default feature list."}]}

Subject: 90dcc79...e84ffd7, diff digest 18b91227782c1175cd6e81bc938164f595eda4ac4e2a56eeed7d2466cf0ba0a7, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 21:02 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the two changed files: a new test file and a spec lifecycle update.

specs/030-bedrock-backend/spec.md

The transition from implementation: in-progress to implementation: complete is a valid lifecycle move under the contract table (approved + complete = settled, unresolved units become errors). The closure section's claim that tests/environment.rs is "added by this closure" is consistent with the diff. No governance inconsistency found.

integrations/rustev-bedrock/tests/environment.rs

The without_test_items brace-depth logic is correct: item[open..] always starts with the first {, which increments depth from 0 to 1, so underflow of the usize is not possible in valid Rust source.

One concrete bug: in no_environment_access_outside_the_feature_module_and_the_smoke, the allowed binding calls canonicalize().unwrap() on every entry of ALLOWED unconditionally for every file scanned — not only when a file is found to use std::env. If either allowed path (specifically src/aws_config_provider.rs, which compiled_sources does not verify exists, unlike examples/smoke.rs) is absent or renamed, the test panics with an opaque std::io::Error on the very first source file processed, with no indication which allowed path is missing or what invariant was violated. The fix is to canonicalize the ALLOWED paths once before the loop (with a clear error message), or to use canonicalize().ok() in the closure.

{"head": "4e12b48550d471119bf351fd1cc7c5e4467db1ee", "verdict": "findings", "findings": [{"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 117, "summary": "canonicalize().unwrap() is called on every ALLOWED entry for every scanned file unconditionally, so a missing allowed path (e.g. src/aws_config_provider.rs) panics with an opaque IO error for the first file in the scan rather than a clear assertion failure."}]}

Subject: 90dcc79...4e12b48, diff digest 367f0614ad6a0ea197790d4ba8ed5abad5f9ce8264f30a7d6dc250ec7eef7ad9, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 21:06 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the two changed files: a new acceptance test (environment.rs) and the spec closure marking implementation: complete.

Spec (specs/030-bedrock-backend/spec.md): The lifecycle transition from in-progress → complete on an approved spec is a valid terminal state per the contract table. The closure section enumerates each acceptance item with the test that covers it. No governance defect found here.

Test file (integrations/rustev-bedrock/tests/environment.rs):

Finding 1 — #[path] search hits comments and string literals (line 74)

text.match_indices("#[path = \"") is a plain substring scan over the full text of each source file. It matches the literal byte sequence anywhere, including inside // comments, /* */ blocks, and string literals. The extracted target is then pushed onto queue unconditionally, and on the next loop iteration std::fs::read_to_string(&file).unwrap() (line 72) is called on the resolved path. If a source file contains a comment such as // e.g. #[path = "custom/mod.rs"] and that path does not exist on disk, the test panics with an I/O error rather than passing or failing gracefully. This turns a documentation comment into a spurious test crash.

Finding 2 — without_test_items over-strips when #[cfg(test)] precedes a brace-less item (line 94)

item.find('{') searches the slice that starts at #[cfg(test)] for the first { anywhere after the attribute. If the annotated item is brace-less (use, type, const, static, or a bare extern crate), the { found belongs to the next item in the file (a function, impl, mod, etc.). The depth-balancing loop then consumes that next item, setting rest past its closing } and silently removing production code from the text that is subsequently scanned for std::env/env::var. This creates a false negative: an env::var call inside a production function that immediately follows a brace-less #[cfg(test)] item would be omitted from the check. The comment ("which only makes the check stricter") describes the None branch (no { found at all), not this Some-but-wrong branch.

{"head": "3c6d2fc3c180a349d1588b9f744638ce3bd247e4", "verdict": "findings", "findings": [{"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 74, "summary": "match_indices searches raw bytes and matches #[path = \"] inside comments and string literals, causing read_to_string().unwrap() to panic when the extracted path does not exist on disk."}, {"path": "integrations/rustev-bedrock/tests/environment.rs", "line": 94, "summary": "item.find('{') finds the first brace anywhere after #[cfg(test)], so when the annotated item is brace-less (use, const, etc.) the following production block is consumed and stripped, creating a false negative in the env-access scan."}]}

Subject: 90dcc79...3c6d2fc, diff digest 9fd126788a96c49f340a08d661292b0c15afe9b01b89c1fea17493cfd5a089e6, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 21:10 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the two changed files.

integrations/rustev-bedrock/tests/environment.rs

The new test has two parts:

  1. aws_config_is_optional_and_enabled_only_by_its_feature — parses Cargo.toml line-by-line and asserts aws-config appears exactly once in [dependencies] as optional = true, and in [features] as exactly aws-config = ["dep:aws-config"]. The logic is sound; [dev-dependencies] or other sections would trigger the panic arm, which is appropriate.

  2. no_environment_access_outside_the_feature_module_and_the_smoke — walks compiled sources via src/ and examples/, follows #[path = "…"] attributes, and then checks each file for "std::env" or "env::var". The #[path] parsing (split_at(i + 10) then split('"').next()) correctly extracts the path for ordinary string literals (the 10-character prefix #[path = " is correct). The TEST_ONLY stripping replaces the exact call string "std::env::temp_dir()" before the scan; since that substring contains "std::env", removing it also strips that occurrence — a theoretical gap only for that one exact call in evidence.rs, and the allowlist/feature-module exemption is the real guard. No concrete defect.

The sanity assert files.len() > 20 and the three required-file assertions provide good coverage guards.

specs/030-bedrock-backend/spec.md

  • implementation: in-progress → implementation: complete is the correct lifecycle transition per the contract table (approved + complete → settled, no schedulable work remaining).
  • The summary text and the new "Closure" section are authored content documenting that each acceptance item (3.5 env isolation, Fact 11 signing, both-wires replay, identity, policy/residency, live probe/smoke, boundary check, Section 5 rows) is covered by a named test. The section correctly notes it makes no quality, residency-compliance, or production claim.
  • No governance-document fields are violated; the spec was already approved (A-26), so moving implementation to complete requires no further ratification act under the contract rules.

No concrete defects found in either file.

{"head": "23bc19c826b15475b5fa2106a10d33293021597b", "verdict": "no-findings", "findings": []}

Subject: 90dcc79...23bc19c, diff digest 8a5a0b1e18a6793379f771cd9bf139dc252b6075a0e5f3ec02df868ee61457e2, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus enabled auto-merge October 30, 2026 21:13
@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit d1cef66 Oct 30, 2026
30 checks passed
@bartekus
bartekus deleted the spec/030-closure branch October 30, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant