mssql-rs
Copilot instructions55 starsChanged 2 months agoMITView on GitHub
Rust implementation of the TDS (Tabular Data Stream) protocol for SQL Server. Cargo workspace with multi-language FFI bindings. Or use the scripts that also cover mssql-py-core: Every .rs file must start with:
- Reads credentials
In this repositoryOne other file it gives its agents.
- code-reviewSkill
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
25 rules. About 0 are common, 10 are distinctive, and 15 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
15
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 65
Every .rs file must start with:
- Very specific: line 83
Visibility: Use pub(crate) for internal APIs, deliberate public surface
- Distinctive: line 118
No verbose comments restating what the code does — Rust is expressive enough
- Distinctive: line 119
No filler phrases: "This ensures that...", "In order to...", "It's worth noting..."
- Distinctive: line 120
No redundant validation or duplicate logic
- Distinctive: line 121
No multi-line explanations of obvious test steps
- Distinctive: line 122
No excessive blank lines or formatting noise
- Very specific: line 128
Don't use cargo test directly — use cargo btest or cargo nextest
- Very specific: line 129
Don't add dependencies without --frozen working (update Cargo.lock explicitly)
- Very specific: line 130
Don't skip clippy — -D warnings means any warning is a build failure
- Very specific: line 131
Don't forget mssql-py-core when running fmt/clippy — it's excluded from the workspace and needs separate runs
- Very specific: line 132
Don't add cfg(test) modules for integration tests — use the tests/ directory
- Very specific: line 133
Don't invent new test patterns — follow existing fixtures, helpers, and env-loading conventions from conftest.py and sibling test files
- Very specific: line 134
Don't add guards, rejections, or platform checks without grepping the codebase first — check CI configs, test infrastructure …
- Distinctive: line 141
When processing rows, tokens, packets, parameters, or FFI buffers:
- Very specific: line 143
Prefer borrowing existing data with &T, &[T], &str, or Cow over cloning, copying, or materializing temporary owned values.
- Very specific: line 145
Prefer slices and views over copied sub-Vecs, and reuse existing buffers and capacity where possible.
- Very specific: line 147
Avoid clone(), to_owned(), to_vec(), collect::<Vec<_>>(), and temporary wrapper objects in per-row, per-column, per-token, and per-packet …
- Very specific: line 151
Use lifetime parameters when they express that a returned reference is tied to an input snapshot, such as &'a [ColumnBinding] -> &'a …
- Distinctive: line 153
Use direct typed delivery when source and destination representations match.
- Distinctive: line 155
Do not replace a borrow with a copy solely to satisfy the borrow checker.
- Very specific: line 159
Do not use unsafe to avoid a copy unless the safety invariant is explicit, narrow, and reviewed.
- Distinctive: line 164
Start from a measured hot path or workload.
- Distinctive: line 169
Treat async continuation state, lock ordering, cancellation, timeout accounting, and packet synchronization as part of correctness when …
- Very specific: line 172
Do not add #[inline] or other hints by habit.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions 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
Copilot Instructions — mssql-rs
Project Overview
Rust implementation of the TDS (Tabular Data Stream) protocol for SQL Server. Cargo workspace with multi-language FFI bindings.
| Crate | Purpose | Edition |
mssql-tds | Core TDS protocol library | 2024 |
mssql-js | Node.js bindings (NAPI-RS) | 2024 |
mssql-tds-cli | Interactive CLI client | 2024 |
mssql-mock-tds | Mock TDS server for testing | 2024 |
mssql-py-core | Python bindings (PyO3/maturin) — excluded from workspace | 2021 |
mssql-odbc | ODBC driver (msodbcsql18) | 2026 |
Build / Test / Lint
Pre-Push Checklist (Windows)
cargo bfmt # format check (workspace only)
cargo bclippy # lint — warnings are errors
cargo btest # test with coverage via nextestOr use the scripts that also cover mssql-py-core:
.\scripts\bfmt.ps1 # fmt check: workspace + mssql-py-core
.\scripts\bclippy.ps1 # clippy: workspace + mssql-py-coreCargo Aliases (defined in .cargo/config.toml)
cargo bfmt→cargo fmt -- --checkcargo bclippy→cargo clippy --workspace --frozen --all-features --all-targets -- -D warningscargo btest→cargo llvm-cov nextest --workspace --frozen --no-report --all-targets --no-fail-fast --profile ci --success-output immediate
JS (mssql-js)
cd mssql-js
yarn install
yarn build # NAPI-RS native addon
yarn test # tsc + AVA
yarn lint # ESLint, zero warnings
yarn format:check # PrettierTest Infrastructure
- Test runner:
cargo nextest(notcargo test) - Coverage:
cargo-llvm-cov, 85% diff coverage target in CI - CI profile:
.config/nextest.toml— 5 retries, JUnit XML output - Mock server:
mssql-mock-tdscrate for unit/integration tests without a live SQL Server - Integration tests require a
.envfile with connection details (usesdotenvcrate) - Rust tests: Unit tests in
#[cfg(test)]inline modules for pure logic; integration tests intests/directory - Python tests: Shared fixtures and env helpers in
conftest.py— always reuse existing patterns from sibling test files - Kerberos tests: Gated by
KERBEROS_TEST=1env var; CI uses Docker-based Kerberos setup inkerberos-test/
Code Conventions
File Header
Every .rs file must start with:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.Naming
Tdsprefix for core public types:TdsClient,TdsTransport,TdsResult,TdsConnectionProvider,TdsTokenStreamReader- Standard Rust conventions:
snake_casefunctions,PascalCasetypes,SCREAMING_SNAKE_CASEconstants
Architecture Patterns
- Layered: Transport → IO (packet reader/writer) → Token stream → Message → Client API
- Module organization: File
foo.rsdeclarespub moditems, implementations live infoo/subdirectory - Error handling:
thiserrorderive macros,TdsResult<T>type alias incore.rs - Async: Tokio runtime,
async-traitfor async trait methods - Visibility: Use
pub(crate)for internal APIs, deliberate public surface - Tracing:
tracingcrate (debug!,error!,info!,trace!,#[instrument]) - Cancellation:
CancelHandlewrappingtokio_util::CancellationToken - Authentication: Two-phase resolution (validate inputs → resolve method) in
connection/. Kerberos/GSSAPI for integrated auth cross-platform. - Async state size: Box new non-primitive fields in long-lived client-context structs when it keeps async state smaller.
FFI Patterns
- JS:
#[napi]attributes,Arc<Mutex<TdsClient>>for thread safety - Python:
#[pymodule],#[pyclass]via PyO3 - ODBC:
#[unsafe(no_mangle)] pub extern "C"functions
Git Conventions
Commits
- Imperative tense: "Add", "Fix", "Refactor" (not "Added", "Fixes")
- Short subject lines, no body unless needed
- This repo does not use conventional commit prefixes (
feat:,fix:, etc.)
Branches
- Feature branches:
dev/<developer>/<feature-name> - Default branch:
main
Pre-Commit Hook
The hook at dev/hooks/pre-commit auto-runs cargo fmt on workspace + mssql-py-core and blocks the commit if formatting changes are detected. Install with:
./setup-hooks.shCode Quality — No AI Slop
- No verbose comments restating what the code does — Rust is expressive enough
- No filler phrases: "This ensures that...", "In order to...", "It's worth noting..."
- No redundant validation or duplicate logic
- No multi-line explanations of obvious test steps
- No excessive blank lines or formatting noise
- Doc comments (
///) should add value — explain why, not what - Would a senior Rust engineer roll their eyes at this? Then don't write it.
What NOT to Do
- Don't use
cargo testdirectly — usecargo btestorcargo nextest - Don't add dependencies without
--frozenworking (updateCargo.lockexplicitly) - Don't skip clippy —
-D warningsmeans any warning is a build failure - Don't forget
mssql-py-corewhen running fmt/clippy — it's excluded from the workspace and needs separate runs - Don't add
cfg(test)modules for integration tests — use thetests/directory - Don't invent new test patterns — follow existing fixtures, helpers, and env-loading conventions from
conftest.pyand sibling test files - Don't add guards, rejections, or platform checks without grepping the codebase first — check CI configs, test infrastructure (
kerberos-test/,tests/), and README for existing support. A spec saying "X is platform-specific" doesn't mean this codebase hasn't already solved it cross-platform.
Performance and Data Movement
Performance is a primary design constraint. Treat copies, allocations, conversions, locks, and network round trips as costs that require justification on hot paths.
When processing rows, tokens, packets, parameters, or FFI buffers:
- Prefer borrowing existing data with
&T,&[T],&str, orCowover cloning, copying, or materializing temporary owned values. - Prefer slices and views over copied sub-
Vecs, and reuse existing buffers and capacity where possible. - Avoid
clone(),to_owned(),to_vec(),collect::<Vec<_>>(), and temporary wrapper objects in per-row, per-column, per-token, and per-packet loops. - Preserve borrowed data through helper boundaries; do not force ownership merely because a helper currently accepts an owned value.
- Use lifetime parameters when they express that a returned reference is tied to an
input snapshot, such as
&'a [ColumnBinding] -> &'a ColumnBinding. - Use direct typed delivery when source and destination representations match. Defer conversion and allocation until the fast path cannot be used.
- Do not replace a borrow with a copy solely to satisfy the borrow checker. First consider narrowing scopes or restructuring the API.
- A copy is acceptable when it is required for ownership, concurrency, safety, or a measured improvement. State the reason in the change or review.
- Do not use
unsafeto avoid a copy unless the safety invariant is explicit, narrow, and reviewed.
For performance-sensitive changes:
- Start from a measured hot path or workload. Prefer a benchmark, profile, allocation measurement, or before/after workload over source-level intuition.
- Preserve the existing behavior on fallback paths. A fast path must be guarded by an exact representation or state invariant, and unsupported or boundary cases must continue through the established conversion or error path.
- Treat async continuation state, lock ordering, cancellation, timeout accounting, and packet synchronization as part of correctness when removing awaits or moving work between synchronous and asynchronous paths.
- Do not add
#[inline]or other hints by habit. Use them for small, profiled dispatch or conversion boundaries and let the compiler decide for larger code. - Make conditional snapshots and metadata work lazy when the common path does not need them.
- Record user-visible performance behavior and intentional trade-offs in the nearest component README when the optimization changes architecture or buffering.
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.

