tx Test Context (tctx)
v0.1.5 · Rust 2024 Edition Python · Rust · Frontend · C/C++ · C# · Protobuf · GraphQL Companion to code-context (cctx)

Instant Polyglot AST Test Cache for AI Coding Agents

tctx maintains a live in-memory reverse dependency graph, computes semantic SHA-256 Merkle hashes (dep_hash), pre-checks modified files with Ruff / ESLint / Biome / Clippy, adapts concurrency to live CPU/memory/I/O pressure, and runs affected tests speculatively in the background — turning second-long test waits into <1 ms verified cache hits inside VS Code and GitHub Copilot.

0.81 ms
Median warm cache hit (957× mean speedup vs pytest)
0.65 ms
Median AST impact + Ruff query (1,274× vs pytest --collect-only)
39.80×
Mixed 320-pair mean speedup (1,132.7× median: 1,014 ms → 0.89 ms)
92.7%
Copilot context token reduction (inline < 8 KB, zero /tmp offload)

Built for Speed, Soundness & Production Resilience

Every cache hit is cryptographically bound to transitive source semantics, environment fingerprints, runtime audit dependencies, and config files — with fail-closed guards against stale or partial states.

Polyglot AST & 2-Hop Barrel Tree-Shaking

  • Python: import / relative imports, conftest.py fixture scoping, TYPE_CHECKING exclusion, zero-alloc PyAliasSet.
  • Rust: mod / #[path], nested use trees, 2-hop pub use barrel tree-shaking, include_str!/build.rs.
  • Frontend: ES/CJS/dynamic imports, tsconfig paths/extends, package.json #imports/exports, Vite ?raw/?worker, SIMD CSS/SCSS, Next.js App Router.
  • Bridges: O(1) PyO3/Maturin, WebAssembly, Full-Stack /api/... routes, React Context, C/C++, C#, Protobuf (public/weak), GraphQL.

Adaptive 4-Tier Pressure Control

  • Live Linux PSI (cpu/io/memory), /proc/loadavg, /proc/meminfo, and cgroup v2 sampling via singleflight lock.
  • Dynamic scaling of CARGO_BUILD_JOBS, parallel test workers, watcher debounce, and child niceness across Normal → Elevated → High → Critical.
  • Edit-churn quiescence protects multi-agent Cargo builds without adding latency to single-file saves.

Hardened Warm Pytest Zygote

  • Pre-imports safe heavy libraries (fastapi, pydantic, numpy, sqlalchemy) in a fork-verified single-threaded parent (/proc/self/status fail-closed).
  • Content-addressed per-UID 0600 script bootstrap permanently eliminates Linux 128 KiB MAX_ARG_STRLEN (E2BIG) failures.
  • Reusable select.poll() IPC, PR_SET_PDEATHSIG, pid > 1 killpg safety, non-finite/circular JSON sanitization, and POSIX 8-bit exit-code preservation.

Fail-Closed Cache, WAL & Streaming Snapshots

  • 64 KiB streaming bincode AST snapshots with full u32 adjacency ID bounds verification on load.
  • O_NOFOLLOW regular-file WAL/snapshot/metrics/.gitignore handling and stack-hex SHA-256 WAL checksums.
  • Automatic flaky-test quarantine, bounded import_bundle path/hash validation, and portable CI cache bundles (cache-export / cache-import).

Pre-Flight Lints & Auto-Remediation

  • Background content-addressed ruff, eslint, biome, and cargo clippy --no-deps diagnostics.
  • Boundary-safe, ambiguity-aware diagnostic file resolution across monorepos and nested sub-crates.
  • Pass ruff_fix: true (or --ruff-fix) to auto-remediate safe lint/import issues before running tests.

VS Code Native & WSL Zero-Config UX

  • 7 Native Language Model Tools with revision-cached Markdown status-bar hover dashboard and live daemon polling.
  • Automatic workspace root inference from target hints, vscode-remote:// URIs, and Windows WSL UNC paths.
  • Smart git-dirty scoping in large repos (> 64 tests), culprit attribution, and JUnit XML / SARIF v2.1.0 export.

System Architecture

A single shared Rust daemon serves VS Code Native tools, MCP clients, and drop-in CLI wrappers over a framed Unix socket (or Windows WSL native bridge).

VS Code Native LM Tools #tctxNativeRun · Affected · Graph · Status Shared MCP Server tctx shared-mcp (13 allowlisted tools) Drop-In CLI Wrappers tctx pytest · cargo-test · vitest · jest tctx Shared Rust Daemon · Unix Socket / WSL Native Bridge · 4-Tier Adaptive Pressure Controller Polyglot AST Graph (u32) SIMD lexers · 2-hop barrel shake semantic_sha256 · dep_hash 64 KiB streaming AST snapshot Speculative Runner & Zygote Singleflight · Fail-First delta Warm Fork Zygote · cargo demux Ruff · Clippy · ESLint · Biome WAL-Backed Merkle Cache O_NOFOLLOW · stack-hex SHA-256 Flaky quarantine · O(1) memory JUnit · SARIF · CI cache bundles

Measured Performance

8 independent daemon sessions (320 paired observations) on AKS Store Demo (src/ai-service) verified against the current release source-tree hash. Raw artifacts: results.json · summary.csv · Full methodology.

Task (Python FastAPI Suite) Pairs TCTX Off Mean TCTX On Mean On Median Speedup [95% CI]
Warm suite (warm_suite) 64 1,125.77 ms 1.18 ms 0.81 ms 957.44× [613.12, 1362.80]
Post-edit background pre-run (bg_speculative) 64 1,168.57 ms 1.19 ms 0.86 ms 980.98× [812.85, 1171.15]
Reverted edit Merkle hit (merkle_revert) 64 1,141.21 ms 4.27 ms 1.04 ms 267.21× [141.37, 627.02]
Immediate 0ms-delay leaf edit (leaf_delta) 64 1,156.31 ms 135.45 ms 108.38 ms 8.54× [6.88, 9.89]
Impact query + Ruff pre-check (affected_graph) 64 1,096.90 ms 0.86 ms 0.65 ms 1,274.04× [1054.57, 1506.24]
Fixed mixed suite (all) 320 1,137.75 ms 28.59 ms 0.89 ms 39.80× [32.22, 45.46]
Rust (cargo test) & Enterprise Monorepo (9,042 files / 3,434 tests) Baseline With tctx Improvement
Enterprise monorepo cold AST load 6,047.38 ms 670.33 ms 9.0× faster (-88.9%)
Core module reverse impact query (67 affected tests) 256.80 ms 5.17 ms 49.7× faster
Large impact response payload (2,363 affected tests) 1,400,000 B 5,320 B 263× smaller inline
4 Rust modules cold batch (cargo test --lib demux) ~5,800 ms 1,254.64 ms 4.6× faster
6 Rust files (53 unit tests) warm cache hit 6,606.00 ms 0.87 ms 7,593× speedup
Single Rust test node cached lookup 1,254.64 ms 0.23 ms 5,455× speedup
Test execution and query latency and paired-session speedup with 95% confidence intervals
Paired-session latency and speedup across 320 observations on aks-store-demo (95% bootstrap CI).
Cold initial suite run latency comparison
Cold initial suite run (mean 1,144.48 ms vs 1,034.04 ms direct pytest; +110 ms one-time startup amortized on call #2).

VS Code Native Language Model Tools

Installed via dotnetpower.test-context-native with automatic agent instructions (applyTo: "**") and seamless MCP fallback (tctx shared-mcp) for headless and subagent sessions.

Native Tool MCP Equivalent Role
#tctxNativeRun test_run Incremental pytest / cargo test / vitest / jest / node --test with language_filter, ruff_fix, and <1ms cache hits.
#tctxNativeAffected test_affected Transitive impact discovery from modified files or git diff, ranked by dependency hops with live lint diagnostics.
#tctxNativeGraph test_graph Inspect direct imports, reverse importers, transitive dependencies, conftest/setup chains, bridges, and dep_hash.
#tctxNativeStatus test_status Non-blocking daemon health, pressure tier, indexed counts, cache telemetry, background queue, and Zygote RSS.
#tctxNativeSync test_sync Synchronize the AST dependency graph with disk and schedule background verification.
#tctxNativeInvalidate test_invalidate Invalidate cached test results for specific files or an entire workspace.
#tctxNativeWorkspaces test_workspaces List explicitly registered workspace roots, scopes, globs, and detected test commands.

Quick Start & CLI Reference

Build once, start the local user daemon, register your repository, and accelerate both AI agents and local CLI workflows.

# 1. Build and install tctx + user systemd service (or macOS LaunchAgent)
git clone https://github.com/dotnetpower/test-context.git
cd test-context
./scripts/install.sh

# 2. Register a Python, Rust, Frontend, or Polyglot workspace
tctx --root /path/to/repo register

# 3. Inspect daemon health, AST graph, affected tests, or lint diagnostics
tctx --root /path/to/repo doctor
tctx --root /path/to/repo status
tctx --root /path/to/repo affected --file src/my_pkg/core.py
tctx --root /path/to/repo graph src/my_pkg/core.py
tctx --root /path/to/repo ruff --fix

# 4. Run tests incrementally or via drop-in wrappers
tctx --root /path/to/repo run --ruff-fix
tctx --root /path/to/repo pytest -q
tctx --root /path/to/repo cargo-test
tctx --root /path/to/repo vitest
tctx --root /path/to/repo jest

# 5. Export JUnit/SARIF reports or share CI cache bundles
tctx --root /path/to/repo run --report-format=sarif --report-out=results.sarif
tctx --root /path/to/repo cache-export --out=tctx-cache.json
tctx --root /path/to/repo cache-import --input=tctx-cache.json

# 6. Install the VS Code Native Extension (Linux & Windows WSL)
./scripts/install-vscode-extension.sh