ffi-testing
Skill12 starsChanged 3 months agoMITView on GitHub
Test changes to the TAV C, C++, WASM, and C# FFI surfaces. Use when exported functions, handles, constants, ownership rules, errors, goldens, or consumer tests change under ffi/.
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 12 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Treat each consumer suite as an external user of its public surface.
- Distinctive: line 21
Use the same fixtures and expected values to compare shared behavior across bindings.
- Distinctive: line 26
Keep synchronization checks in the normal test or CI path.
- Distinctive: line 42
Test owned handles, borrowed byte views, null/error behavior, and out-parameter reset rules where applicable.
- Distinctive: line 44
Update goldens only alongside behavioral tests.
- Distinctive: line 56
Check borrowed raw getters, their empty-state behavior, and ownership after moves.
- Distinctive: line 61
Run the C++ consumer executable under AddressSanitizer with both shared and static linking.
- Distinctive: line 69
Keep explicit test mappings between compiled Rust constants and their C names.
- Distinctive: line 82
Use named Rust constants in runtime logic and tests.
- Distinctive: line 84
Keep function signatures, handle ownership, and boolean/layout checks outside constant-equivalence tests.
- Distinctive: line 86
When adding or changing a synchronization checker, temporarily add a member to its actual source declaration and run the normal test …
- Distinctive: line 94
Use half-machine concurrency for builds.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
FFI testing
Treat each consumer suite as an external user of its public surface.
Cross-language synchronization
For every changed function, constant, error, or ownership contract, trace its Rust implementation through C, C++, WASM, and C#. Identify which bindings expose it before editing. Update each affected binding, consumer suite, and reference document in the same change.
Use the same fixtures and expected values to compare shared behavior across bindings. Preserve intentional language differences, such as C error pointers versus C++ exceptions. Document unsupported surfaces and deliberate differences; do not invent a new binding solely to make the surfaces identical.
Keep synchronization checks in the normal test or CI path. A manual comparison is not a completeness guarantee. When declarations move between headers, update every checker that reads those declarations, including Rust and managed tests.
Required coverage
- Enumerate the complete changed public surface from its authoritative source:
- Rust: implementations and shared constants under
ffi/src - C:
ffi/include/tav/*.h - C++:
ffi/include/tav/*.hpp - WASM: exported items in
ffi/src/wasm_ffiand shared exports inffi/src/lib.rs - C#: public types and members under
ffi/csharp/TeeAttestationVerification
- Rust: implementations and shared constants under
- Exercise every matching function, property, enum member, and ownership operation in the corresponding consumer suite.
- Assert behavior with known values or negative cases; successful invocation alone is insufficient.
- Test owned handles, borrowed byte views, null/error behavior, and out-parameter reset rules where applicable.
- Update goldens only alongside behavioral tests.
C++ headers and ownership
- Compile each public C header independently as C and each C++ header
independently as C++ in the consumer build. Include each twice to check include
guards. Do not prepend
support.hor another umbrella header that can hide missing includes. Keep this coverage complete when headers are added or moved. - Cover move construction, self-move assignment, assignment over an owned value, moves from already-moved sources, and reuse of moved-from objects for every movable wrapper. Check destination values and the documented source state. Do not assume an unspecified moved-from exception message is preserved.
- Check borrowed raw getters, their empty-state behavior, and ownership after moves. Adoption tests must cover null and valid owned handles; document that adopting the same non-null pointer twice does not transfer ownership safely.
- Distinguish handle presence from payload length. Test default, moved-from, and live zero-length states where the API can produce them.
- Run the C++ consumer executable under AddressSanitizer with both shared and static linking. Do not describe this as instrumenting Rust unless the Rust library is also built with sanitizer instrumentation.
ABI constants
When constants change:
- Keep explicit test mappings between compiled Rust constants and their C names. Compare values and exact name sets in both directions.
- For C++, initialize members from the C constants and check exact member sets
and mappings in both directions. Equal values alone do not detect omitted
members. Keep
ffi/tests/cpp-consumer/check_error_codes.pypointed at the authoritative error headers. - For constants exposed in C#, keep explicit C-name-to-managed-name mappings. Parse the public C header and compare values and exact member sets with the reflected managed enum.
- For WASM, check the exported names and values against the shared Rust
constants. Include exports from
ffi/src/lib.rs, not onlywasm_ffi. - Reject missing, extra, duplicate, or mismatched members. Do not update only one side to make a test pass.
- Use named Rust constants in runtime logic and tests; do not repeat numeric literals in match arms and equivalence tests.
- Keep function signatures, handle ownership, and boolean/layout checks outside constant-equivalence tests.
- When adding or changing a synchronization checker, temporarily add a member to its actual source declaration and run the normal test command. Confirm failure, add the matching binding member, and confirm success. Remove both temporary edits and rerun. Also exercise missing, extra, duplicate, and incorrectly mapped cases.
Validation
Use half-machine concurrency for builds.
- Native Rust:
crypto_openssl - C consumer: shared and static
- C++ consumer: shared and static under ASan, standalone headers, and enum
completeness through
ffi/tests/cpp-consumer/CMakeLists.txt - WASM consumer:
crypto_webcrypto - C#:
python3 ffi/csharp/run_tests.py --configuration Release - Repository: formatting, version sync, license headers, and
git diff --check
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

