/rust-skills:rust-java-migration-testingfrom rust-skills
Designs and audits lossless Java-to-Rust migration tests, enforcing 100% JUnit porting, SHA-256 fixture verification, golden/live differential matching, and file-size limits.
Ships in rust-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Prove observable compatibility and Rust safety properties, not test volume. Treat the complete source test suite as a non-negotiable compatibility floor: migrate 100% of its test cases without weakening inputs or assertions, copy every test fixture/data/script byte-for-byte into the target repository, and make both implementations produce the same per-case observable result. Build three explicit test ledgers in this order:
MISPLACED or missing file-map.csv target blocks completion..rs files from 501–800 lines for cohesion, and block files above 800 lines; split suites by contract or behavior family rather than arbitrary ranges.#[cfg(test)] modules beside their implementation. Put public-boundary, cross-module, differential, host, load, and whole-project tests in tests/ or a non-published test/testkit crate.Read Directory parity verification and Migration verification SOP.
SOURCE_PARITY — map every source test/case and every source test asset; no
missing, blocked, or not-applicable row permits a completion claim.RUST_OBLIGATION — test risks introduced by the Rust implementation and replacement components.VALUE_ADD — add tests justified by uncovered behavior, plausible defects, incidents, mutation survivors, or hostile inputs.SOURCE_PARITY has two mandatory sections: TEST_CASE and TEST_ASSET.
TEST_CASE preserves the source inputs, assertions, exception/error category,
ordering, state, side effects, and cleanup. TEST_ASSET preserves the source
relative path, target path, and SHA-256 of every copied fixture, script, corpus,
golden file, and data file. Coverage should rise because meaningful contracts are
exercised. A percentage is not the design input and 100% is not migration proof.
Use this skill for migration-specific test planning, implementation, audit, and acceptance.
This is the Rust testing adapter of the shared target-language migration
profile. Keep source-test dispositions, exact-asset rules, full differential
outcomes, and completion semantics equivalent to zig-java-migration-testing
and future Kotlin/Swift adapters; vary only Rust test/build syntax and Rust risks.
Route:
rust-java-migration;rust-testing;rust-concurrency;rust-performance;rust-unsafe-ffi;rust-web-security.An audit-only request does not authorize deleting or rewriting tests. Preserve existing behavior and unrelated dirty work. Treat heuristic findings as review candidates.
Resolve or mark unknown:
<project>-test packages; do not assume a crates/ directory;Never use an unpinned remote artifact as the compatibility oracle.
Use these labels without promotion:
| Level | Evidence | Claim allowed |
|---|---|---|
V0_STATIC | source/test inventory, call trace, no-stub scan | structural disposition only |
V1_RUST_LOCAL | Rust unit/integration/doc/compile tests | Rust-local behavior passes |
V2_MIRRORED | Rust test preserves a named Java test's inputs and assertions | source test represented; not differential |
V3_GOLDEN_DIFF | pinned Java-generated fixtures compared by Rust | recorded outputs match; completion requires the full source denominator |
V4_LIVE_DIFF | pinned Java and Rust execute identical cases | recorded live behavior matches; completion requires every source case |
V5_HOST | real framework/process/database/network/filesystem | named integration boundary works |
V6_NONFUNCTIONAL | model, mutation, property, fuzz, load, soak, security | named non-functional claim holds |
V7_ROLLBACK | gray rollout and rollback rehearsal | stated recovery path works |
A copied test name, green Rust suite, or 100% line report does not prove V3_GOLDEN_DIFF.
Evidence levels never replace object states. A green V1_RUST_LOCAL suite does
not turn MISSING, MISPLACED, STUB, PARTIAL, or UNVERIFIED into
IMPLEMENTED. DEPENDENCY_REUSED additionally requires an exact pinned
upstream symbol and local integration test; PLATFORM_NA requires platform
evidence rather than a passing test that skips the behavior.
Record exact SHAs, commands, tools, profiles, features, targets, test counts, ignored/flaky tests, coverage exclusions, and existing evidence artifacts. Record Java and Rust coverage separately before comparing them.
Read the current fact region of the authoritative object table before designing
tests. Stop at historical-design-appendix-start; old appendix statuses are
context only. Record counts for all strict object states. If any incomplete
state remains, the acceptance report must say “module migration incomplete”
regardless of test results.
Use CodeGraph when indexed to trace each source test through its production entry, collaborators, side effects, and Rust counterpart. Text similarity is insufficient for overloaded methods, registries, interceptors, dynamic dispatch, cleanup, and async paths.
Create one row per Java test method and one row per concrete parameterized,
repeated, template, or dynamic case. Include disabled tests; a disabled source
test remains a required migrated test and its disabled reason is preserved
separately. Create one TEST_ASSET row per file in every source test resource,
fixture, script, corpus, and data root. Copy source assets without editing them;
place target-generated or normalized derivatives beside the immutable copy.
Use dispositions:
| Disposition | Meaning |
|---|---|
MIRRORED | same contract represented in one Rust test |
ADAPTED | same observable contract using a Rust-native fixture/oracle |
SPLIT | one Java test becomes several focused Rust tests |
MERGED_APPROVED | several Java tests share one parameterized Rust test without losing cases/assertions |
NOT_APPLICABLE | JVM-only claim recorded for analysis; blocks 100% lossless source-test completion |
BLOCKED | named dependency or oracle prevents the test; blocks completion |
MISSING | no Rust implementation; blocks completion |
MIRRORED, ADAPTED, SPLIT, and MERGED_APPROVED are complete only when
every source case remains identifiable, all preservation flags are true, every
target test exists, and golden/live comparison records MATCH. ADAPTED permits
Rust-native harness mechanics, not a weaker contract. SPLIT and
MERGED_APPROVED may reorganize tests but may not remove a case or assertion.
Do not map by test name alone.
Resolve SKILL_DIR to this skill directory and run from the migration repository:
python3 "$SKILL_DIR/scripts/audit_migration_tests.py" \
--java-root ../java-project/source-module \
--rust-root <selected-target-crate-or-workspace> \
--object-ledger docs/source-module/对象级对照表.md \
--parity-manifest docs/source-module/source-test-parity.json \
--java-test-assets-root src/test/resources \
--fail-on-incomplete
The report inventories tests, flags weak signals, verifies every source-test
manifest row, checks target test files, hashes exact asset copies, and refuses a
completion gate for any object, test, asset, run, or differential gap. Additional
non-standard asset roots must be passed with repeated
--java-test-assets-root. The script validates recorded preservation evidence;
it cannot infer semantic mappings or authorize deletion. It warns on authored
files above 500 physical lines and blocks those above 800; inline unit tests are
valid Rust organization and are not reported as structural violations.
SOURCE_PARITY ledgerFor every source row:
MATCH, zero harness failures, and zero not-run cases.Missing, blocked, or not-applicable source tests remain visible and block a migration-complete conclusion. Source tests are a compatibility floor, not the complete Rust plan.
For every repository/product-level migration completion claim, create one
non-published workspace package as the whole-project acceptance authority. It
is especially important for multiple crates, bindings/adapters, or a source
system/templatesuite. Name it
<project>-test by default; keep the final directory name and Cargo package name
identical, set publish = false, and run it explicitly in CI. Its parent path
follows the recorded workspace topology: a small root-flat workspace uses
<project>-test/; a hybrid may keep it at root or in a real test family; a
contained workspace may use crates/<project>-test/ or
crates/tests/<project>-test/. Local tests inside production
crates prove their own parser/type/API/binding behavior; they do not replace the
whole-project module's source-suite replay, cross-crate workflows, real copied
assets, golden/live differential comparison, or aggregate result artifact.
For FreeMarker use this boundary:
freemarker/ # Rust engine local unit/integration tests
freemarker-pyo3/ # Python binding local/packaging tests
freemarker-test/ # complete Java templatesuite + cross-component acceptance
The freemarker-test package must be a workspace member, depend on public
surfaces under test, and remain outside crates.io publication. Its complete gate
is every source case MATCH, with no threshold pass count, skipped capability,
or ignored case. Read Migration verification SOP
for naming, ownership, layout, and CI rules.
The test package's semantic role is mandatory; one physical parent directory is not. Never relocate it solely to imitate the Java test-module tree or a generic Rust example.
Do not use one test per object as a substitute for one real file per source
object. A test that reaches a re-export, compatibility facade, or merged type
does not cure MISPLACED/MISSING. Tests validate semantics only after the
layout and object boundary are factually present.
Treat 500 physical lines as the suite-cohesion review threshold and 800 as the
authored-file blocker. Split by contract, behavior family, fixture family,
adapter, or verification layer while preserving every source case ID and
assertion. Keep compact private-behavior unit tests in #[cfg(test)] modules;
put reusable integration support in tests/common/ or a dedicated testkit crate.
Enable clippy::too_many_lines to review functions over its 100-line default.
RUST_OBLIGATION ledgerAdd applicable tests created by the target design:
| Rust mechanism | Mandatory questions |
|---|---|
Ownership / Drop | exactly-once cleanup, partial initialization, early return, panic/cancel boundary |
| Async / Tokio | cancellation, timeout ownership, orphan tasks, shutdown, bounded queues, slow consumers |
| Shared state | atomicity, poison/recovery policy, no lock held across .await, deadlock/interleaving risks |
Send / Sync | intended compile contract and supported executor/thread boundary |
| Typed errors | exact variant, context, retryability, Error::source, public redaction surfaces |
| serde / wire/storage | rename/default/unknown fields, round trip, bytes, compatibility window |
| Traits / registries | selection, duplicate registration, missing provider, dynamic dispatch |
| Procedural macros | compile-pass/fail, generics, visibility, renamed dependencies, diagnostics |
| Feature/platform/MSRV | supported combinations compile and behave as promised |
| Unsafe / FFI | invariants, Miri/sanitizer where applicable, ownership across boundary |
| Replacement crate | risky semantic path, lifecycle, real dependency, upgrade/rollback boundary |
| Framework adapters | one shared contract suite plus adapter-native routing/body/service behavior |
These tests need not exist in Java because they protect the Rust implementation's correctness.
For a DEPENDENCY_REUSED row, execute the local adapter against the exact
declared upstream symbol/version or commit. The dependency's own unit tests,
documentation examples, or a similar capability name are not local integration
evidence. Assert the source contract's ordering, errors, lifecycle, cancellation,
and metadata that cross the adapter.
VALUE_ADD ledgerAdd a test only when it has a reason such as:
For each test, record the concrete bug it should catch. Prefer a small parameter/branch matrix over “one test per type/token/method” count targets.
Strong tests observe exact public behavior:
Display, Debug, serialized error report, logs/tracing fields, transport body, and Error::source() independently where exposed;Weak patterns requiring review:
let _ = result, unused parsed AST, or a test that accepts success and failure;
note that during cleanup, converting a genuinely dropped Result to
let _ = expr; preserves semantics and is not itself weak evidence — it only
becomes weak when let _ = is the sole observation of the behavior under test;is_ok() or is_err() when value/error category matters;Clone, Debug, constants, constructors, or type existence without a public contract;todo!() or unimplemented!() panics.Read Vernal case study and test-value rubric before cleanup.
Use a versioned case format such as JSON Lines:
{"schema":1,"case_id":"empty-name","input":{"name":""},"expected":{"kind":"error","code":"INVALID_NAME"}}
Retain Java and Rust raw outputs separately. Pin exporter and implementation SHAs, seeds, environment, and normalizer version. Compare success values, error categories, side effects, order, and wire bytes as applicable. Do not normalize unexpected fields away.
Differential comparison is a full source-suite gate, not a representative
sample. The final manifest must record one MATCH per concrete source case and
suite-level Java, Rust, and differential runs with PASS, zero mismatches, zero
harness failures, and zero not-run cases. A temporary subset may guide
development but must be labeled partial and cannot satisfy completion.
Put shared assertions and failure fixtures in a testkit. Each adapter must provide real native observations. Run the same identity, scope, lifecycle, error, cancellation, streaming, and cleanup contracts for every implementation, then add adapter-native tests.
Prefer event-driven synchronization and bounded timeouts over fixed sleeps. Assert the resource is open while a stream is active and closed after completion, disconnect, timeout, cancellation, or panic.
Coverage comparison is valid only when scopes are documented and reasonably comparable:
Acceptance order:
MATCH;Do not weaken assertions, duplicate tests, exclude difficult files, or add trivial getters to reach a number. A user-mandated 100% gate may be enforced, but report what it proves and what it does not.
Score each test manually:
| Question | Pass signal |
|---|---|
| Traceable? | source test, contract, risk, bug, or incident is named |
| Observable? | assertion checks externally meaningful behavior |
| Mutation-sensitive? | a plausible defect would make it fail |
| Production path? | exercises real production logic at the right boundary |
| Deterministic? | synchronization/seed/environment are controlled |
| Distinct? | adds a branch, case, platform, failure, or invariant |
| Right level? | unit/integration/host/load test matches the boundary |
Classify KEEP, IMPROVE, MERGE, or REMOVE_PROPOSED; require review before deletion. Coverage loss alone may justify replacement but not retention of a meaningless assertion.
Run applicable gates from cheapest to most diagnostic:
cargo fmt --all -- --check
cargo check --workspace --all-targets --all-features
cargo test --workspace --all-features
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo test --doc --workspace
Then run targeted compile-fail, platform/MSRV, differential, real-dependency, real-host, model/Loom, Miri/sanitizer, mutation, property/fuzz, load/soak, security, and rollback gates. Record exact command, environment, result, and artifact.
Run every gate at the workspace MSRV: a default rustc older than the workspace
rust-version fails with rustc X is not supported by the following packages
rather than testing your code — use rustup run <ver> cargo ... and never
silently lower the manifest. Use --keep-going so one failing crate does not
hide the remaining errors (errors surface in layers; fix the first layer and
re-run). Require both default and --all-features check runs to reach zero
warnings: feature-gated crates and code paths only compile under
--all-features, and a check gate with warnings must be reported as a gap, not
a pass.
Use the project-specific coverage command. For mutation candidates:
"$SKILL_DIR/scripts/run_mutation_test.sh" <selected-target-crate>
Interpret survivors individually; do not impose one universal mutation score.
Report separately:
V0–V4;MISSING/MISPLACED/STUB/PARTIAL/UNVERIFIED blockers;<project>-test whole-project acceptance package, and do not
use pass thresholds, skips, or ignored cases as its completion gate.<project>-test under crates/ or at repository root without
checking the migration roadmap's project-driven workspace topology..rs file above 800 physical lines; review every file above 500 and split weakly cohesive suites.is_err() when the error contract is observable.MATCH results, harness
failures, or not-run cases all block completion.cargo check (default or
--all-features) still emits warnings, or when the run used an unsupported
toolchain instead of the workspace MSRV.scripts/audit_migration_tests.py — Java/Rust test inventory and weak-signal auditscripts/run_mutation_test.sh — mutation-test wrapperMATCH with zero harness failures and zero
not-run cases.<project>-test package is a workspace member with publish = false,
lives at the path selected by the recorded workspace topology, exercises
public component surfaces, and owns the complete suite/differential
command plus aggregate artifact; local crate tests remain subsystem evidence..rs file is at most 800 physical lines; files above 500 and functions above the Clippy 100-line signal have recorded cohesion reviews.#[cfg(test)] modules; integration, differential, host, load, and whole-project suites live under tests/ or a non-published test package.agents/openai.yaml (opens in a new tab)assets/templates/source-test-parity.json (opens in a new tab)assets/templates/迁移测试对照表.md (opens in a new tab)examples/audit-report.md (opens in a new tab)examples/golden-migration-tests/Cargo.toml (opens in a new tab)examples/golden-migration-tests/src/lib.rs (opens in a new tab)examples/golden-migration-tests/tests/migration_evidence.rs (opens in a new tab)references/cross-language-migration-profile.md (opens in a new tab)references/directory-parity-verification.md (opens in a new tab)references/migration-verification-sop.md (opens in a new tab)references/test-categories.md (opens in a new tab)references/test-value-rubric.md (opens in a new tab)references/vernal-testing-case-study.md (opens in a new tab)scripts/audit_migration_tests.py (opens in a new tab)scripts/run_mutation_test.sh (opens in a new tab)scripts/tests/test_audit_migration_tests.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (full-stack-skills/rust-skills) — no native marketplace selected
npx claudepluginhub p/full-stack-skills-rust-skills29 skills in this plugin
/rust-api-designDesign Rust library APIs that follow the Rust API Guidelines — naming (C-CASE, C-CONV, C-GETTER), interop traits (C-COMMON-TRAITS, C-CONVERT, C-ITER, C-SERDE), predictability (C-INTUITIVE, C-CONST), flexibility (C-GENERIC, C-NEWTYPE, C-EXT), type safety (C-BOOL, C-NONZERO, C-WRAPPER, C-STR), dependability (C-PANIC, C-UNWRAP), debuggability (C-DEBUG), and future-proofing (C-SEALED, C-STRUCT-FIELD, C-NON-EXHAUSTIVE). Use when users design a public crate API, choose between generics/concrete/newtype, decide trait bounds, hide implementation, avoid breakage, or ask "what is idiomatic Rust API design"; hand semver and publish workflow to rust-semver, lint config to rust-style-clippy, and in-crate layout to rust-module-layout./rust-by-exampleShow Rust patterns through short compilable examples — type conversions (From/Into/TryFrom/as/Deref), flow control (if let/while let/match/loop), functions and closures (Fn/FnMut/FnOnce, captures), modules (mod/use/pub/super/self), generics and traits (bounds/associated types/trait objects), error handling (?/Result/thiserror/anyhow), attributes (derive/cfg/inline/allow), unsafe (raw pointers/unions/ABI), procedural macros (derive/attribute/function-like), and inline asm. Use when users ask "how do I write X in Rust", need a concrete pattern with copy-pasteable code, or are migrating from Java/Python/Go/C++ and want the Rust equivalent; hand architecture decisions to rust-api-design/rust-workspace, std API selection to rust-stdlib, and async runtime to rust-concurrency./rust-cargo-buildConfigure, operate, diagnose, and automate Cargo for Rust packages and workspaces. Cover manifests and targets, commands, dependency resolution and features, profiles, build scripts, configuration and environment variables, caches and build diagnostics, cross-compilation, registries, packaging, publishing, metadata, CI reproducibility, and stable-versus-nightly feature gates. Use for Cargo.toml, Cargo.lock, .cargo/config.toml, cargo build/check/run/tree/metadata/package/publish, resolver or feature problems, build output and performance, private registries, and beginner Cargo workflows. Route crate selection and supply-chain audits to rust-dependencies, workspace topology to rust-workspace, test design to rust-testing, documentation design to rust-documentation, lint policy to rust-style-clippy, and API compatibility decisions to rust-semver./rust-cliDesign, implement, test, and release production Rust command-line applications, including command contracts, subcommands, configuration precedence, stdin/stdout/stderr, exit codes, file safety, daemon IPC, terminal handling, packaging, and process-level tests. Use when users ask for a Rust CLI, command parser, clap integration, Unix-style pipelines, daemon clients, PTY/TUI behavior, shell completion, or CLI release engineering./rust-code-reviewReview Rust changes for correctness, memory and thread safety, error semantics, unnecessary allocation or cloning, lock scope, API compatibility, test gaps, documentation, and dependency risk, applying the Rust API Guidelines checklist (C-PANIC, C-UNWRAP, C-TRANSMUTE, C-BOOL, C-NEWTYPE, C-COMMON-TRAITS, C-CONVERT, C-SEALED, C-NON-EXHAUSTIVE). Use when reviewing Rust diffs, pull requests, libraries, unsafe boundaries, or production incidents; report actionable findings by severity before summaries, route automated formatting or lint policy to rust-style-clippy, and route API shape decisions (trait sealing, error taxonomy, newtype design, builder patterns) to rust-api-design./rust-concurrencyDesign, implement, diagnose, and test Rust concurrency and parallelism with threads, Send and Sync, locks, atomics, channels, Tokio, Rayon, Crossbeam, bounded backpressure, actor ownership, task supervision, graceful shutdown, runtime diagnostics, and Loom model tests. Use when users ask about shared state, deadlocks, async tasks, CPU parallelism, high concurrency, daemon resource budgets, slow consumers, worker pools, lock-free structures, or concurrent correctness.Other plugins' skills for the same job