SharpNinja.aiUnit
0.5.0-beta.1
See the version list below for details.
dotnet add package SharpNinja.aiUnit --version 0.5.0-beta.1
NuGet\Install-Package SharpNinja.aiUnit -Version 0.5.0-beta.1
<PackageReference Include="SharpNinja.aiUnit" Version="0.5.0-beta.1" />
<PackageVersion Include="SharpNinja.aiUnit" Version="0.5.0-beta.1" />
<PackageReference Include="SharpNinja.aiUnit" />
paket add SharpNinja.aiUnit --version 0.5.0-beta.1
#r "nuget: SharpNinja.aiUnit, 0.5.0-beta.1"
#:package SharpNinja.aiUnit@0.5.0-beta.1
#addin nuget:?package=SharpNinja.aiUnit&version=0.5.0-beta.1&prerelease
#tool nuget:?package=SharpNinja.aiUnit&version=0.5.0-beta.1&prerelease
SharpNinja.aiUnit
xUnit extension for AI frontier-model regression testing, AI-assisted review tests, and workspace strategy management.
aiUnit provides:
- HTTP frontier adapters for Anthropic Claude, OpenAI-compatible APIs (OpenAI, xAI, MAF, and similar gateways), and Google Gemini.
- CLI strategies for local executable-backed agents such as Claude Code and OpenAI Codex.
- Strategy resolution from
appsettings.aiunit.jsonwithAIUNIT_*environment-variable overrides. [AiFact]and[AiTheory]xUnit attributes that auto-skip when no configured strategy can run.[CodeReview],[PlanReview], and[ProjectReview]xUnit data attributes that run AI reviews and pass the effective prompt plus result JSON to the decorated method.AiUnitJsonAssertionsfor validating model JSON output.aiunitREPL/TUI commands for scanning workspaces, listing projects, inspecting strategy catalogs, applying strategy config, restoring snapshots, and validating configuration.
Strategy Configuration
Add appsettings.aiunit.json to the test project output directory. The sample
file in samples/appsettings.aiunit.json contains ready-to-edit examples.
Strategy kinds:
cli: launches the configured executable fromCommand. The executable owns authentication.ApiKeyEnvVaris not used forclistrategies.anthropic: calls the Anthropic Messages API directly.openai-compatible: calls/v1/chat/completionson an OpenAI-compatible endpoint such as OpenAI, xAI, or MAF.gemini: calls the Google Gemini Generative Language API.
Environment overrides:
AIUNIT_STRATEGYAIUNIT_KINDAIUNIT_BASE_URLAIUNIT_MODELAIUNIT_COMMANDAIUNIT_API_KEYAIUNIT_TIMEOUT_SECONDSAIUNIT_TEMPERATURE
CLI-backed examples:
{
"AiUnit": {
"ActiveStrategy": "codex-subscription",
"Strategies": {
"codex-subscription": {
"Kind": "cli",
"Command": "codex",
"Model": "(cli-managed)",
"TimeoutSeconds": 900,
"Temperature": 0.0,
"Description": "Codex CLI using the logged-in subscription."
},
"claude-code-opus": {
"Kind": "cli",
"Command": "claude",
"Model": "claude-opus-4-5",
"TimeoutSeconds": 900,
"Temperature": 0.0,
"Description": "Claude Code CLI using Opus. Configure ANTHROPIC_API_KEY or Claude CLI auth in the process environment."
},
"copilot-gemini": {
"Kind": "cli",
"Command": "copilot",
"Model": "gemini-2.5-pro",
"TimeoutSeconds": 900,
"Temperature": 0.0,
"Description": "Copilot CLI configured for Gemini. Configure the required Copilot CLI auth or API key in the process environment."
},
"maf-grok": {
"Kind": "openai-compatible",
"BaseUrl": "https://api.x.ai",
"Model": "grok-4",
"ApiKeyEnvVar": "XAI_API_KEY",
"TimeoutSeconds": 1800,
"Temperature": 0.0,
"Description": "xAI Grok through the OpenAI-compatible API. Set XAI_API_KEY before activating."
}
}
}
}
For CLI strategies, configure the launched tool before running tests:
# Codex CLI reads the logged-in subscription.
codex login
# Claude Code can read Anthropic auth from the shell environment.
$env:ANTHROPIC_API_KEY = "<anthropic-api-key>"
# Copilot CLI auth depends on the installed executable.
$env:COPILOT_API_KEY = "<copilot-api-key>"
For HTTP strategies, set the configured API-key variable or use
AIUNIT_API_KEY as a shared fallback.
Review Attributes
Use review attributes on xUnit theory methods. Each decorated method receives two read-only parameters:
[Theory]
[CodeReview("Review this serializer for correctness.", Agent = "codex-subscription")]
public void ReviewSerializer(string prompt, string resultJson)
{
AiUnitJsonAssertions.AssertValidJson(resultJson);
}
Available review attributes:
[CodeReview][PlanReview][ProjectReview]
If the prompt argument is null or empty, aiUnit loads the canned YAML prompt for that review scope:
Review/Prompts/code-review.yamlReview/Prompts/plan-review.yamlReview/Prompts/project-review.yaml
The canned prompts include the JSON schema that agents must use for review findings. The same schema is also sent as a structured tool definition when the configured frontier client supports tools.
Process resultJson as immutable review evidence:
- Parse it as JSON and verify
schemaVersionisaiunit.review.findings.v1. - Read
status:passmeans no blocking findings,failmeans the review found actionable issues, anderrormeans the review could not complete cleanly. - Inspect
summary,reviewedScope, andfindingsfor assertion details. - Treat
agentReviewsas supporting evidence from individual agents when the review used multiple agents; the top-level object is the aggregated result.
[Theory]
[ProjectReview(Agent = "codex-subscription")]
public void ProjectReviewMustPass(string prompt, string resultJson)
{
using var doc = JsonDocument.Parse(resultJson);
var root = doc.RootElement;
Assert.Equal("aiunit.review.findings.v1", root.GetProperty("schemaVersion").GetString());
Assert.NotEqual("error", root.GetProperty("status").GetString());
var blocking = root
.GetProperty("findings")
.EnumerateArray()
.Where(f => f.GetProperty("severity").GetString() is "critical" or "high")
.Select(f => f.GetProperty("title").GetString())
.ToArray();
Assert.Empty(blocking);
}
Example resultJson:
{
"schemaVersion": "aiunit.review.findings.v1",
"reviewType": "code",
"status": "fail",
"summary": "One high-severity issue was found in the serializer changes.",
"reviewedScope": "src/SharpNinja.AiUnit/Serialization",
"agent": {
"name": "codex-subscription",
"provider": "codex-subscription:codex",
"model": "(cli-managed)"
},
"findings": [
{
"severity": "high",
"category": "correctness",
"title": "Missing null handling for optional payload",
"detail": "The serializer reads the optional payload without checking JsonValueKind.Null, so a valid null value throws instead of producing an empty result.",
"recommendation": "Handle JsonValueKind.Null before reading object properties and add a regression test for null payloads.",
"filePath": "src/SharpNinja.AiUnit/Serialization/ReviewResultReader.cs",
"line": 42,
"ruleId": "AIUNIT-CODE-NULL-001",
"confidence": 0.86,
"agent": "codex-subscription"
}
]
}
Agent configuration can come from a named strategy (Agent or Agents) or
inline attribute properties: Kind, BaseUrl, Model, ApiKeyEnvVar,
Command, TimeoutSeconds, Temperature, and MaxTokens. Attributes are
stackable. When multiple agents run for one review, the default active strategy
aggregates their findings into one result JSON payload.
CLI Usage
aiunit repl --workspace F:\GitHub\aiUnit
aiunit tui overview --workspace F:\GitHub\aiUnit
aiunit scan --workspace F:\GitHub\aiUnit
aiunit list --workspace F:\GitHub\aiUnit
aiunit catalog --workspace F:\GitHub\aiUnit
aiunit validate --workspace F:\GitHub\aiUnit
aiunit show <project> --workspace F:\GitHub\aiUnit
aiunit apply <strategy> --project <project> --dry-run --force --workspace F:\GitHub\aiUnit
aiunit apply-global <strategy> --dry-run --force --workspace F:\GitHub\aiUnit
aiunit restore <project> --snapshot <path> --workspace F:\GitHub\aiUnit
aiunit --version
aiunit --help
Validation
dotnet test
dotnet run --project src/SharpNinja.AiUnit.Repl -- --help
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Http (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- xunit.extensibility.core (>= 2.9.2)
- xunit.extensibility.execution (>= 2.9.2)
- Xunit.SkippableFact (>= 1.4.13)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 318 | 7/17/2026 |
| 2.1.3 | 216 | 7/7/2026 |
| 2.1.1 | 146 | 7/7/2026 |
| 2.1.0 | 151 | 7/7/2026 |
| 0.11.0 | 327 | 5/31/2026 |
| 0.10.0 | 151 | 5/29/2026 |
| 0.9.0 | 132 | 5/29/2026 |
| 0.5.0-beta.9 | 102 | 5/22/2026 |
| 0.5.0-beta.1 | 96 | 5/23/2026 |
| 0.1.0-preview.672 | 104 | 5/22/2026 |