docs(comments): rewrite comments across all crates to the guidelines
Sweep every first-party crate source (1956 .rs files) to the project comment guidelines: delete redundant restatements, decorative banners, change narration, and end-of-line comments; keep and tighten the crucial ones (invariants, bug rationale, SAFETY blocks, ported-source attribution). No functional code changed. Every edit is proven comment-only against the prior tree by a comment-stripping lexer (string/char/raw-string aware) plus a separate doctest-fence check. Where removing a comment made rustfmt or clippy want to re-lay-out adjacent code, the minimal triggering comment is restored so code tokens stay byte-identical. Gates green: cargo fmt --all --check (0 diffs), cargo check and cargo clippy --workspace --all-targets (0 warnings). Adds scripts/check_codegen_comment_guidelines.py — the enforcement gate for these guidelines (flags banners, end-of-line comments, change narration, and commented-out code).
This commit is contained in:
@@ -88,8 +88,7 @@ fn remove_returns_value_then_none() {
|
||||
|
||||
#[test]
|
||||
fn insert_arc_shares_allocation() {
|
||||
// Inserting an existing Arc means the stored value and the original
|
||||
// share strong-count.
|
||||
// insert_arc shares the Arc (strong-count rises).
|
||||
let arc = Arc::new(Config {
|
||||
base_url: "shared".into(),
|
||||
timeout_ms: 9,
|
||||
@@ -97,10 +96,7 @@ fn insert_arc_shares_allocation() {
|
||||
let mut ctx = ToolCallContext::default();
|
||||
ctx.extensions.insert_arc(arc.clone());
|
||||
let from_ctx = ctx.extensions.get::<Config>().unwrap();
|
||||
// Strong-count on the original Arc should reflect at least:
|
||||
// - the original `arc` binding
|
||||
// - the value stored in the extension map
|
||||
// - the clone returned from `get`
|
||||
// Strong-count: original binding + map entry + get() clone.
|
||||
assert!(Arc::strong_count(&arc) >= 3);
|
||||
assert_eq!(*from_ctx, *arc);
|
||||
}
|
||||
@@ -152,13 +148,10 @@ fn clone_preserves_call_id_and_extensions() {
|
||||
assert_eq!(copy.call_id, ctx.call_id);
|
||||
assert_eq!(copy.extensions.len(), 1);
|
||||
|
||||
// Both clones see the same Arc-backed extension value.
|
||||
let from_orig = ctx.extensions.get::<AuthToken>().unwrap();
|
||||
let from_copy = copy.extensions.get::<AuthToken>().unwrap();
|
||||
assert_eq!(from_orig.0, from_copy.0);
|
||||
// The Arc allocation is shared; mutating via one path is impossible
|
||||
// (extensions are immutable through `get`), but strong-count rises
|
||||
// because of the clone.
|
||||
// Arc is shared; get() only clones the handle (immutable).
|
||||
assert!(Arc::strong_count(&from_orig) >= 3);
|
||||
}
|
||||
|
||||
@@ -176,21 +169,12 @@ fn clone_extension_map_is_independent_after_remove() {
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Per-concept client/SDK-side extensions.
|
||||
//
|
||||
// These exist as separate extensions (one per concept) rather than a
|
||||
// single bundle. The tests below pin three contracts:
|
||||
//
|
||||
// 1. Each extension round-trips through the typed-extension store
|
||||
// independently of the others.
|
||||
// 2. A dispatcher with only some of the concepts can install them
|
||||
// individually — installing `Cwd` MUST NOT make `BehaviorVersion`
|
||||
// look "present" with a default value, and vice versa.
|
||||
// 3. Absence of every well-known extension is the legitimate "backend
|
||||
// dispatcher" shape; tools that require one MUST treat absence as
|
||||
// a hard error rather than fall back to a process-wide default.
|
||||
// ---------------------------------------------------------------------------
|
||||
// Per-concept client/SDK-side extensions (one type per concept, not a bundle).
|
||||
// Pins three contracts:
|
||||
// 1. Each extension round-trips independently.
|
||||
// 2. Installing one MUST NOT make another look "present" with a default.
|
||||
// 3. Absence is the legitimate backend-dispatcher shape; tools that need
|
||||
// an extension MUST treat absence as a hard error.
|
||||
|
||||
#[test]
|
||||
fn each_well_known_extension_round_trips_independently() {
|
||||
@@ -217,9 +201,7 @@ fn each_well_known_extension_round_trips_independently() {
|
||||
|
||||
#[test]
|
||||
fn dispatcher_can_install_only_what_it_has() {
|
||||
// A dispatcher that knows the cwd but not the trace context installs
|
||||
// only `Cwd`. The other extensions stay absent (not "default"),
|
||||
// which is the discriminator a tool can rely on.
|
||||
// Only Cwd installed — other extensions stay absent (not defaulted).
|
||||
let mut ctx = ToolCallContext::default();
|
||||
ctx.extensions
|
||||
.insert(Cwd(std::path::PathBuf::from("/work")));
|
||||
@@ -229,8 +211,7 @@ fn dispatcher_can_install_only_what_it_has() {
|
||||
assert!(!ctx.extensions.contains::<TraceContext>());
|
||||
assert_eq!(ctx.extensions.len(), 1);
|
||||
|
||||
// Adding `TraceContext` later does not implicitly conjure a
|
||||
// `BehaviorVersion` — extensions are independent.
|
||||
// Installing TraceContext does not conjure BehaviorVersion.
|
||||
ctx.extensions.insert(TraceContext("tp".into()));
|
||||
assert!(ctx.extensions.contains::<TraceContext>());
|
||||
assert!(!ctx.extensions.contains::<BehaviorVersion>());
|
||||
@@ -239,9 +220,7 @@ fn dispatcher_can_install_only_what_it_has() {
|
||||
|
||||
#[test]
|
||||
fn absence_signals_backend_or_other_mode() {
|
||||
// A backend dispatcher installs none of the client-side extensions.
|
||||
// Tools that require any of them must treat absence as a hard error
|
||||
// — this test pins the contract.
|
||||
// Backend dispatcher: no client-side extensions present.
|
||||
let ctx = ToolCallContext::default();
|
||||
assert!(ctx.extensions.get::<Cwd>().is_none());
|
||||
assert!(ctx.extensions.get::<BehaviorVersion>().is_none());
|
||||
|
||||
Reference in New Issue
Block a user