Skip to content

Preserve Mockito initialization for unmanaged targets and shared handles - #1249

Merged
jkschneider merged 12 commits into
mainfrom
factory/testing1211-f7-managed-mockito-targets
Oct 26, 2026
Merged

jkschneider merged 12 commits into
mainfrom
factory/testing1211-f7-managed-mockito-targets

Conversation

@jkschneider

@jkschneider jkschneider commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

RemoveInitMocksIfRunnersSpecified can remove initialization of a helper or another object that the enclosing Mockito runner/extension does not initialize. Restrict removal to an attributed literal this belonging to a managed test instance. Preserve unmanaged nested/anonymous owners, aliases, casts, null targets, and shared or escaping handles.

Keep declarations and cleanup consistent with retained initialization. Scan resolved field references across sources, including inherited reads and explicit static imports. Preserve formal parameters and resources consumed by other resource initializers. Track only field types that could receive the declared AutoCloseable result, retaining Object, incomplete, and generic types conservatively; apply that admission rule equally to declarations, references, and imports.

Validation:

  • Normally attributed regressions reproduce unsafe cleanup on the original recipe. Actual original helper fixtures compile and pass, while old emitted sources leave mocks uninitialized and fail at runtime. Controls cover managed/unmanaged owners, formal parameters, dependent resources, cross-source/inherited reads, imports, Object/generic fields, and both source orders.
  • All 50 focused tests pass without skips, including replay of the native compiled tests against the actual uploaded candidate JAR. The clean exact-head native module check reports 2,349 tests, zero failures/errors, and nine existing skips on ed2cf94. Independent review approves this source.
  • Both uploaded artifacts use identical ordered byte hashes for all 71 runtime dependencies. All nine candidate production classes match the tested native bytes and load from the uploaded JAR; 709 other main class files are identical. Credential scans are clear.
  • Twelve original/emitted fixture pairs compile, pass real JUnit/Mockito runtime checks on the captured JDK 21, and are idempotent, with zero candidate recipe errors. This uses the actual uploaded JAR with no production class-directory overrides; no JDK 8 runtime or full consumer application build is claimed.
  • A bounded synthetic comparison preserves identical compiling/idempotent output across three input sizes. With 2,048 unrelated fields, recorded references decrease from 2,068 to 14. Single-observation scan time improves; requested-GC measurements are mixed and do not establish peak heap savings or the cause of the earlier remote heap failure.
  • Complete paired comparison covers all 1,283 repository identities, with equal source-file counts for each. Changed-file rows decrease from 297 to 288, retaining nine whole files; every candidate changed-file key is a subset of baseline. Both runs have zero source errors. The final candidate completes without the earlier heap failure in this execution; its cause and peak-memory benefit remain unestablished. Final-head CGP CI passes (20261026212830-69sQ1), and the combined native integration check passes all 2,392 tests with zero failures/errors and nine existing skips.

This deliberately retains uncertain cases; it does not infer alias ownership or redesign unrelated lifecycle timing and integration discovery.

Addresses item F7 of #1211. The aggregate issue remains open.

Co-authored-by: Moderne Factory factory@moderne.io

jkschneider and others added 10 commits October 26, 2026 13:30
Prove unmanaged helper initialization and close bookkeeping, and ordinary static fixture constructor initialization, survive Mockito cleanup.

Co-authored-by: Moderne Factory <factory@moderne.io>
Co-authored-by: Moderne Factory <factory@moderne.io>
Only remove literal this initialization in runner or extension-managed classes. Keep shared and escaping handles intact and preserve foreign resources and declaration siblings.

Co-authored-by: Moderne Factory <factory@moderne.io>
Preserve all 32 existing expectations. Both peer controls fail on unchanged production, and actual interim 246 emitted code fails javac for arity and unresolved-resource errors.

Co-authored-by: Moderne Factory <factory@moderne.io>
Keep non-block variable declarations, including method parameters, when redundant managed initialization is removed. Check other resource declarations before dropping a managed resource referenced by their initializers.

Co-authored-by: Moderne Factory <factory@moderne.io>
Cover sibling and enclosing private reads, other-source reads and declarations, and a distinct same-name symbol positive. Preserve all 34 prior expectations.

Co-authored-by: Moderne Factory <factory@moderne.io>
Correct only the new expected blank line. Native 39-case baseline now has exactly four semantic scope failures; all prior 34 and the new distinct-owner positive pass.

Co-authored-by: Moderne Factory <factory@moderne.io>
Classify uses across the full source file. Index resolved field declarations and references across input files, retaining externally observed handles and declarations unavailable in the current file. Keep method-local handling and the existing 34 controls.

Co-authored-by: Moderne Factory <factory@moderne.io>
Co-authored-by: Moderne Factory <factory@moderne.io>
Co-authored-by: Moderne Factory <factory@moderne.io>
@jkschneider jkschneider added the mod-factory Recipe fixes developed and verified by Moderne Factory label Oct 26, 2026
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 26, 2026
jkschneider and others added 2 commits October 26, 2026 16:30
Add nonregression controls for cleanup and external/inherited/imported handles,
including source order and different declaring owners. Unchanged f52 production
passes all 50 focused tests; no RED is claimed for these admission controls.

Co-authored-by: Moderne Factory <factory@moderne.io>
Apply the same conservative admission predicate to declarations, references and
explicit static imports. Keep Object, incomplete types and generic variables;
leave resolved-symbol, cross-source and escaping-use guards unchanged.

This bounds irrelevant field bookkeeping; remote OOM causality is unestablished.
All 50 focused controls pass, including 43 unchanged expectations.

Co-authored-by: Moderne Factory <factory@moderne.io>
@jkschneider
jkschneider merged commit c13714f into main Oct 26, 2026
1 check passed
@jkschneider
jkschneider deleted the factory/testing1211-f7-managed-mockito-targets branch October 26, 2026 21:55
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod-factory Recipe fixes developed and verified by Moderne Factory

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant