generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 237
Agents #4324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Agents #4324
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # Smithy-rs AI Agent Guide | ||
|
|
||
| ## Package Layout | ||
|
|
||
| - **`codegen-core/`** - Shared codegen | ||
| - **`codegen-server/`** - Server codegen | ||
| - **`codegen-client/`** - Client codegen | ||
| - **`rust-runtime/`** - Runtime libraries | ||
| - **`codegen-server-test/`** - Server integration tests | ||
|
|
||
| Protocol files: `codegen-{core,server}/.../protocols/` | ||
|
|
||
| ## preludeScope: Rust Prelude Types | ||
|
|
||
| **Always use `preludeScope` for Rust prelude types:** | ||
|
|
||
| ```kotlin | ||
| rustTemplate( | ||
| "let result: #{Result}<#{String}, #{Error}> = #{Ok}(value);", | ||
| *preludeScope, // Provides Result, String, Ok | ||
| "Error" to myErrorType | ||
| ) | ||
| ``` | ||
|
|
||
| ❌ Wrong: `"let result: Result<String, Error> = Ok(value);"` | ||
| ✅ Correct: Use `*preludeScope` in templates | ||
|
|
||
| ## RuntimeType and Dependencies | ||
|
|
||
| `RuntimeType` objects contain: | ||
| - **`path`**: Rust path (e.g., `"::mime::Mime"`) | ||
| - **`dependency`**: `CargoDependency` or `InlineDependency` | ||
|
|
||
| Using a `RuntimeType` automatically adds its dependency to `Cargo.toml`. | ||
|
|
||
| ### Creating RuntimeTypes | ||
|
|
||
| ```kotlin | ||
| // Pre-defined dependencies | ||
| val Mime = CargoDependency.Mime.toType() | ||
| val Bytes = CargoDependency.Bytes.toType().resolve("Bytes") | ||
|
|
||
| // Runtime crates | ||
| val smithyTypes = RuntimeType.smithyTypes(runtimeConfig) | ||
| ``` | ||
|
|
||
| ### Always Use Symbols | ||
|
|
||
| ❌ Wrong: `rust("const MIME: ::mime::Mime = ::mime::APPLICATION_JSON;")` | ||
| ✅ Correct: `rustTemplate("const MIME: #{Mime}::Mime = #{Mime}::APPLICATION_JSON;", "Mime" to RuntimeType.Mime)` | ||
|
|
||
| ## RuntimeType.forInlineFun: Lazy Generation | ||
|
|
||
| Code is only generated if used. `forInlineFun` enables lazy generation: | ||
|
|
||
| ```kotlin | ||
| val mimeType = RuntimeType.forInlineFun("APPLICATION_JSON", module) { | ||
| rustTemplate( | ||
| "pub const APPLICATION_JSON: #{Mime}::Mime = #{Mime}::APPLICATION_JSON;", | ||
| "Mime" to RuntimeType.Mime | ||
| ) | ||
| } | ||
| ``` | ||
|
|
||
| ⚠️ **Footgun**: Name collisions mean only one implementation gets generated. | ||
|
|
||
| ## Testing | ||
|
|
||
| ### Integration Tests | ||
| Test actual generated code, not just codegen logic: | ||
|
|
||
| ```kotlin | ||
| serverIntegrationTest(model) { codegenContext, rustCrate -> | ||
| rustCrate.testModule { | ||
| tokioTest("test_accept_header") { | ||
| rustTemplate(""" | ||
| let request = ::http::Request::builder() | ||
| .header("Accept", "application/cbor") | ||
| .body(Body::empty()).unwrap(); | ||
| let result = MyInput::from_request(request).await; | ||
| result.expect("should accept valid header"); | ||
| """) | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Running Tests | ||
|
|
||
| **Codegen tests:** | ||
| ```bash | ||
| ./gradlew test --tests "*MyTest*" | ||
| ./gradlew codegen-server-test:assemble --quiet | ||
| ``` | ||
|
|
||
| **Debug failing tests:** | ||
| ```bash | ||
| # Remove --quiet to see failure details | ||
| ./gradlew :codegen-core:test --tests "*InlineDependencyTest*" | ||
| # Extract just the error from HTML report (avoid HTML markup pollution) | ||
| grep -A 5 "AssertionError\|Exception" codegen-core/build/reports/tests/test/classes/software.amazon.smithy.rust.codegen.core.rustlang.InlineDependencyTest.html | ||
| ``` | ||
|
|
||
| **Runtime tests:** | ||
| ```bash | ||
| cd rust-runtime && cargo test --quiet -p aws-smithy-types | ||
| ``` | ||
|
|
||
| **Protocol tests:** | ||
| ```bash | ||
| ./gradlew codegen-client-test:assemble --quiet | ||
| cd codegen-client-test/build/smithyprojections/codegen-client-test/rest_xml_extras/rust-client-codegen | ||
| cargo test --quiet | ||
| ``` | ||
|
|
||
| ## Viewing Generated Code | ||
|
|
||
| Generated code appears in: | ||
| ``` | ||
| codegen-server-test/build/smithyprojections/codegen-server-test/SERVICE_NAME/rust-server-codegen/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit |
||
| ``` | ||
|
|
||
| Enable debug comments: | ||
| ```kotlin | ||
| serverIntegrationTest(model, IntegrationTestParams( | ||
| additionalSettings = ServerAdditionalSettings.builder() | ||
| .generateCodegenComments() // Adds Kotlin source line comments | ||
| .toObjectNode() | ||
| )) { /* test code */ } | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably clarify this is about codegen, perhaps nesting all of these under a common
Codegenheader.