9.8 KiB
Unity NL Editing Suite — Additive Test Design
You are running inside CI for the unity-mcp repo. Use only the tools allowed by the workflow. Work autonomously; do not prompt the user. Do NOT spawn subagents.
Print this once, verbatim, early in the run: AllowedTools: Write,mcp__UnityMCP__apply_text_edits,mcp__UnityMCP__script_apply_edits,mcp__UnityMCP__validate_script,mcp__UnityMCP__find_in_file,mcp__UnityMCP__read_console,mcp__UnityMCP__get_sha
Mission
- Pick target file (prefer):
unity://path/Assets/Scripts/LongUnityScriptClaudeTest.cs
- Execute NL tests NL-0..NL-4 in order using minimal, precise edits that build on each other.
- Validate each edit with
mcp__UnityMCP__validate_script(level:"standard"). - Report: write one
<testcase>XML fragment per test toreports/<TESTID>_results.xml. Do not read or edit$JUNIT_OUT.
CRITICAL XML FORMAT REQUIREMENTS:
- Each file must contain EXACTLY one
<testcase>root element - NO prologue, epilogue, code fences, or extra characters
- NO markdown formatting or explanations outside the XML
- Use this exact shape (write the XML directly into the file; do not wrap it in ``` fences):
-
Must end with the closing tag
</testcase>(well‑formed XML only). -
If test fails, include:
<failure message="reason"/> -
TESTID must be one of: NL-0, NL-1, NL-2, NL-3, NL-4
- NO RESTORATION - tests build additively on previous state.
- STRICT FRAGMENT EMISSION - After each test, immediately emit a clean XML file under
reports/<TESTID>_results.xmlwith exactly one<testcase>whosenamebegins with the exact test id. No prologue/epilogue or fences. If the test fails, include a<failure message="..."/>and still emit.
Environment & Paths (CI)
- Always pass:
project_root: "TestProjects/UnityMCPTests"andctx: {}on list/read/edit/validate. - Canonical URIs only:
- Primary:
unity://path/Assets/...(never embedproject_rootin the URI) - Relative (when supported):
Assets/...
- Primary:
CI provides:
$JUNIT_OUT=reports/junit-nl-suite.xml(pre‑created; leave alone)$MD_OUT=reports/junit-nl-suite.md(synthesized from JUnit)
Transcript Minimization Rules
- Do not restate tool JSON; summarize in ≤ 2 short lines.
- Never paste full file contents. For matches, include only the matched line and ±1 line.
- Prefer
mcp__UnityMCP__find_in_filefor targeting to minimize transcript size. - Per‑test
system-out≤ 400 chars: brief status only (no SHA). - Console evidence: fetch the last 10 lines with
include_stacktrace:falseand include ≤ 3 lines in the fragment. - Avoid quoting multi‑line diffs; reference markers instead.
— Console scans: perform two reads — last 10
log/infolines and up to 3errorentries (useinclude_stacktrace:false); include ≤ 3 lines total in the fragment; if no errors, state "no errors".
Tool Mapping
-
Anchors/regex/structured:
mcp__UnityMCP__script_apply_edits- Allowed ops:
anchor_insert,replace_method,insert_method,delete_method,regex_replace - For
anchor_insert, always set"position": "before"or"after".
- Allowed ops:
-
Precise ranges / atomic batch:
mcp__UnityMCP__apply_text_edits(non‑overlapping ranges) STRICT OP GUARDRAILS -
Do not use
anchor_replace. Structured edits must be one of:anchor_insert,replace_method,insert_method,delete_method,regex_replace. -
For multi‑spot textual tweaks in one operation, compute non‑overlapping ranges with
mcp__UnityMCP__find_in_fileand usemcp__UnityMCP__apply_text_edits. -
Hash-only:
mcp__UnityMCP__get_sha— returns{sha256,lengthBytes,lastModifiedUtc}without file body -
Validation:
mcp__UnityMCP__validate_script(level:"standard") -
Dynamic targeting: Use
mcp__UnityMCP__find_in_fileto locate current positions of methods/markers
Additive Test Design Principles
Key Changes from Reset-Based:
- Dynamic Targeting: Use
find_in_fileto locate methods/content, never hardcode line numbers - State Awareness: Each test expects the file state left by the previous test
- Content-Based Operations: Target methods by signature, classes by name, not coordinates
- Cumulative Validation: Ensure the file remains structurally sound throughout the sequence
- Composability: Tests demonstrate how operations work together in real workflows
State Tracking:
- Track file SHA after each test (
mcp__UnityMCP__get_sha) for potential preconditions in later passes. Do not include SHA values in report fragments. - Use content signatures (method names, comment markers) to verify expected state
- Validate structural integrity after each major change
Execution Order & Additive Test Specs
NL-0. Baseline State Capture
Goal: Establish initial file state and verify accessibility Actions:
- Read file head and tail to confirm structure
- Locate key methods:
HasTarget(),GetCurrentTarget(),Update(),ApplyBlend() - Record initial SHA for tracking
- Expected final state: Unchanged baseline file
NL-1. Core Method Operations (Additive State A)
Goal: Demonstrate method replacement operations Actions:
- Replace
HasTarget()method body:public bool HasTarget() { return currentTarget != null; } - Validate.
- Insert
PrintSeries()method after a unique anchor method. PreferGetCurrentTarget()if unique; otherwise use another unique method such asApplyBlend. Insert:public void PrintSeries() { Debug.Log("1,2,3"); } - Validate that both methods exist and are properly formatted.
- Delete
PrintSeries()method (cleanup for next test) - Expected final state:
HasTarget()modified, file structure intact, no temporary methods
NL-2. Anchor Comment Insertion (Additive State B)
Goal: Demonstrate anchor-based insertions above methods Actions:
- Use
find_in_filewith a tolerant anchor to locate theUpdate()method, e.g.(?m)^\\s*(?:public|private|protected|internal)?\\s*void\\s+Update\\s*\\(\\s*\\) - Expect exactly one match; if multiple, fail clearly rather than guessing.
- Insert
// Build marker OKcomment line aboveUpdate()method - Verify comment exists and
Update()still functions - Expected final state: State A + build marker comment above
Update()
NL-3. End-of-Class Content (Additive State C)
Goal: Demonstrate end-of-class insertions without ambiguous anchors Actions:
- Use
find_in_fileto locate brace-only lines (e.g.,(?m)^\\s*}\\s*$). Select the last such line (preferably indentation 0 if multiples). - Compute an exact insertion point immediately before that last brace using
apply_text_edits(do not useanchor_insertfor this step). - Insert three comment lines before the final class brace:
// Tail test A // Tail test B // Tail test C - Expected final state: State B + tail comments before class closing brace
NL-4. Console State Verification (No State Change)
Goal: Verify Unity console integration without file modification Actions:
- Read last 10 Unity console lines (log/info)
- Perform a targeted scan for errors/exceptions (type: errors), up to 3 entries
- Validate no compilation errors from previous operations
- Expected final state: State C (unchanged)
- IMMEDIATELY write clean XML fragment to
reports/NL-4_results.xml(no extra text). The<testcase name>must start withNL-4. Include at most 3 lines total across both reads, or simply state "no errors; console OK" (≤ 400 chars).
Dynamic Targeting Examples
Instead of hardcoded coordinates:
{"startLine": 31, "startCol": 26, "endLine": 31, "endCol": 58}
Use content-aware targeting:
# Find current method location
find_in_file(pattern: "public bool HasTarget\\(\\)")
# Then compute edit ranges from found position
Method targeting by signature:
{"op": "replace_method", "className": "LongUnityScriptClaudeTest", "methodName": "HasTarget"}
Anchor-based insertions:
{"op": "anchor_insert", "anchor": "(?m)^\\s*(?:public|private|protected|internal)?\\s*void\\s+Update\\s*\\(\\s*\\)", "position": "before", "text": "// comment"}
State Verification Patterns
After each test:
- Verify expected content exists:
find_in_filefor key markers - Check structural integrity:
validate_script(level:"standard") - Update SHA tracking for next test's preconditions
- Emit a per‑test fragment to
reports/<TESTID>_results.xmlimmediately. If the test failed, still write a single<testcase>with a<failure message="..."/>and evidence insystem-out. - Log cumulative changes in test evidence (keep concise per Transcript Minimization Rules; never paste raw tool JSON)
Error Recovery:
- If test fails, log current state but continue (don't restore)
- Next test adapts to actual current state, not expected state
- Demonstrates resilience of operations on varied file conditions
Benefits of Additive Design
- Realistic Workflows: Tests mirror actual development patterns
- Robust Operations: Proves edits work on evolving files, not just pristine baselines
- Composability Validation: Shows operations coordinate well together
- Simplified Infrastructure: No restore scripts or snapshots needed
- Better Failure Analysis: Failures don't cascade - each test adapts to current reality
- State Evolution Testing: Validates SDK handles cumulative file modifications correctly
This additive approach produces a more realistic and maintainable test suite that better represents actual SDK usage patterns.
BAN ON EXTRA TOOLS AND DIRS
- Do not use any tools outside
AllowedTools. Do not create directories; assumereports/exists.