Skip to content

Commit 6705dc6

Browse files
committed
Code review agent: AutoCleanupExtension
1 parent f62dbe6 commit 6705dc6

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

.github/agents/code-review-and-fix.agent.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ Auto-fix boundaries:
212212
to avoid allocating on every invocation. Only convert singletons used at
213213
registration/initialization time (e.g., `Instrumenter` builder chains, `Singletons`
214214
setup)
215+
- try-with-resources wrapping most of a test body for an `AutoCloseable` that only
216+
needs cleanup at test end — convert to `AutoCleanupExtension` with `deferCleanup(...)`.
217+
Add a `@RegisterExtension static final AutoCleanupExtension cleanup =
218+
AutoCleanupExtension.create();` field if one does not already exist, then replace
219+
the try-with-resources with `cleanup.deferCleanup(resource);` and un-indent the body.
220+
Keep try-with-resources for semantically scoped resources whose lifetime must end
221+
mid-test (e.g., `Scope` / `Context.makeCurrent()`, `MockedStatic`, short-lived
222+
readers/writers/streams/response bodies).
223+
Do not apply this conversion in non-JUnit helper methods, `@BeforeAll`, or shared
224+
setup code.
215225
- `hasAttributesSatisfying(...)` calls in test assertions — replace with
216226
`hasAttributesSatisfyingExactly(...)` because it is more precise (the non-exact
217227
variant silently ignores unexpected attributes)

.github/agents/knowledge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Load only files relevant to the current scope to reduce noise and avoid over-con
1616
| `javaagent-module-patterns.md` | `InstrumentationModule`, `TypeInstrumentation`, `Singletons`, `VirtualField`, `CallDepth` |
1717
| `library-patterns.md` | Library instrumentation telemetry, builder, getter, or setter pattern changes |
1818
| `module-naming.md` | New or renamed modules or packages; settings includes |
19-
| `testing-general-patterns.md` | Test files in scope — assertion style, attribute assertion patterns, `satisfies()` lambda usage |
19+
| `testing-general-patterns.md` | Test files in scope — assertion style, resource cleanup patterns, attribute assertion patterns, `satisfies()` lambda usage |
2020
| `testing-experimental-flags.md` | `testExperimental` task or experimental span-attribute assertions |
2121
| `testing-semconv-stability.md` | Semconv opt-in modes, `emitOld*`/`emitStable*`, `maybeStable`, Semconv test tasks |
2222

.github/agents/knowledge/general-rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ When a "Knowledge File" is listed, load it from `knowledge/` before reviewing th
2323
| Javaagent | Incorrect `classLoaderMatcher()` | `classLoaderMatcher()` override that is redundant (muzzle already handles it) or missing when needed (muzzle cannot distinguish version range) | `javaagent-module-patterns.md` |
2424
| Semconv | Library vs javaagent semconv constant usage | Semconv constants/assertions ||
2525
| Semconv | Dual semconv testing | `SemconvStability`, `maybeStable`, semconv Gradle tasks | `testing-semconv-stability.md` |
26-
| Testing | General test patterns | Test files in scope | `testing-general-patterns.md` |
26+
| Testing | General test patterns | Test files in scope — assertion style, resource cleanup, attribute assertions | `testing-general-patterns.md` |
2727
| Testing | Experimental flag tests | `testExperimental`, experimental attribute assertions, `experimental` flags in JVM args or system properties | `testing-experimental-flags.md` |
2828
| Library | TelemetryBuilder/getter/setter patterns | Library instrumentation classes | `library-patterns.md` |
2929
| API | Deprecation and breaking-change policy | Public API changes | `api-deprecation-policy.md` |

0 commit comments

Comments
 (0)