Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fde29d0
Convert skipped tests to xfail and improve framing robustness
dsarno Aug 18, 2025
5386b23
clarify stdout test failure messaging
dsarno Aug 18, 2025
63b070b
Add handshake fallback and logging checks
dsarno Aug 18, 2025
6cedb80
Claude Desktop: write BOM-free config to macOS path; dual-path fallba…
dsarno Aug 17, 2025
3bc9cd0
MCP: natural-language edit defaults; header guard + precondition for …
dsarno Aug 18, 2025
3cc1acd
MCP: add anchor_delete/anchor_replace structured ops; normalize NL/te…
dsarno Aug 18, 2025
22f55ce
Convert skipped tests to xfail and improve framing robustness
dsarno Aug 18, 2025
f3e94db
clarify stdout test failure messaging
dsarno Aug 18, 2025
d1362ac
Add handshake fallback and logging checks
dsarno Aug 18, 2025
e4e89e4
Claude Desktop: write BOM-free config to macOS path; dual-path fallba…
dsarno Aug 17, 2025
f1d773b
MCP: resolve merge conflicts; unify NL parsing and text-edit guards; …
dsarno Aug 18, 2025
c26ee13
MCP: add spec resource (script-edits); tighten script_apply_edits des…
dsarno Aug 18, 2025
3962cad
MCP: add script-edits spec resource; route all-structured edits via '…
dsarno Aug 18, 2025
c28bb38
CI: gate Unity compile steps behind secrets.UNITY_LICENSE to avoid 'C…
dsarno Aug 19, 2025
3943abd
CI: add Claude NL/T prompt at .claude/prompts/nl-unity-suite.md
dsarno Aug 19, 2025
77c841b
Tests: switch NL suite to ClaudeTests/longUnityScript-claudeTest.cs; …
dsarno Aug 19, 2025
b9eb430
fix: check UNITY_LICENSE via env in workflow
dsarno Aug 19, 2025
e9206a9
Merge pull request #22 from dsarno/codex/fix-workflow-file-unrecogniz…
dsarno Aug 19, 2025
69073c9
fix: allow manual run and env license check
dsarno Aug 19, 2025
54389a2
Merge pull request #23 from dsarno/codex/fix-workflow-file-unrecogniz…
dsarno Aug 19, 2025
543e2c5
fix: detect Unity mode and secrets
dsarno Aug 19, 2025
428328e
Merge pull request #24 from dsarno/codex/fix-unity-workflow-secret-ha…
dsarno Aug 19, 2025
528f603
Add debug print in mcp_source
dsarno Aug 19, 2025
0655f65
Merge pull request #25 from dsarno/codex/add-debug-statement-for-work…
dsarno Aug 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .claude/prompts/nl-unity-suite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# CLAUDE TASK: Run NL/T editing tests for Unity MCP repo and emit JUnit

You are running in CI at the repository root. Use only the tools that are allowed by the workflow:
- View, GlobTool, GrepTool for reading.
- Bash for local shell (git is allowed).
- BatchTool for grouping.
- MCP tools from server "unity" (exposed as mcp__unity__*).

## Test target
- Primary file: `ClaudeTests/longUnityScript-claudeTest.cs`
- For each operation, prefer structured edit tools (`replace_method`, `insert_method`, `delete_method`, `anchor_insert`, `apply_text_edits`, `regex_replace`) via the MCP server.
- Include `precondition_sha256` for any text path write.

## Output requirements
- Create a JUnit XML at `reports/claude-nl-tests.xml`.
- Each test = one `<testcase>` with `classname="UnityMCP.NL"` or `UnityMCP.T`.
- On failure, include a `<failure>` node with a concise message and the last evidence snippet (10–20 lines).
- Also write a human summary at `reports/claude-nl-tests.md` with checkboxes and the windowed reads.

## Safety & hygiene
- Make edits in-place, then revert them at the end (`git stash -u`/`git reset --hard` or balanced counter-edits) so the workspace is clean for subsequent steps.
- Never push commits from CI.
- If a write fails midway, ensure the file is restored before proceeding.

## NL-0. Sanity Reads (windowed)
- Tail 120 lines of `ClaudeTests/longUnityScript-claudeTest.cs`.
- Show 40 lines around method `Update`.
- **Pass** if both windows render with expected anchors present.

## NL-1. Method replace/insert/delete (natural-language)
- Replace `HasTarget` with block-bodied version returning `currentTarget != null`.
- Insert `PrintSeries()` after `GetCurrentTarget` logging `1,2,3`.
- Verify by reading 20 lines around the anchor.
- Delete `PrintSeries()` and verify removal.
- **Pass** if diffs match and verification windows show expected content.

## NL-2. Anchor comment insertion
- Add a comment `Build marker OK` immediately above the `Update` method.
- **Pass** if the comment appears directly above the `public void Update()` line.

## NL-3. End-of-class insertion
- Insert a 3-line comment `Tail test A/B/C` before the last method or immediately before the final class brace (preview, then apply).
- **Pass** if windowed read shows the three lines at the intended location.

## NL-4. Compile trigger
- After any NL edit, ensure no stale compiler errors:
- Write a short marker edit, then **revert** after validating.
- The CI job will run Unity compile separately; record your local check (e.g., file parity and syntax sanity) as INFO, but do not attempt to invoke Unity here.

## T-A. Anchor insert (text path)
- Insert after `GetCurrentTarget`: `private int __TempHelper(int a, int b) => a + b;`
- Verify via read; then delete with a `regex_replace` targeting only that helper block.
- **Pass** if round-trip leaves the file exactly as before.

## T-B. Replace method body with minimal range
- Identify `HasTarget` body lines; single `replace_range` to change only inside braces; then revert.
- **Pass** on exact-range change + revert.

## T-C. Header/region preservation
- For `ApplyBlend`, change only interior lines via `replace_range`; the method signature and surrounding `#region`/`#endregion` markers must remain untouched.
- **Pass** if signature and region markers unchanged.

## T-D. End-of-class insertion (anchor)
- Find final class brace; `position: before` to append a temporary helper; then remove.
- **Pass** if insert/remove verified.

## T-E. Temporary method lifecycle
- Insert helper (T-A), update helper implementation via `apply_text_edits`, then delete with `regex_replace`.
- **Pass** if lifecycle completes and file returns to original checksum.

## T-F. Multi-edit atomic batch
- In one call, perform two `replace_range` tweaks and one comment insert at the class end; verify all-or-nothing behavior.
- **Pass** if either all 3 apply or none.

## T-G. Path normalization
- Run the same edit once with `unity://path/ClaudeTests/longUnityScript-claudeTest.cs` and once with `ClaudeTests/longUnityScript-claudeTest.cs` (if supported).
- **Pass** if both target the same file and no path duplication.

## T-H. Validation levels
- After edits, run `validate` with `level: "standard"`, then `"basic"` for temporarily unbalanced text ops; final state must be valid.
- **Pass** if validation OK and final file compiles in CI step.

## T-I. Failure surfaces (expected)
- Too large payload: `apply_text_edits` with >15 KB aggregate → expect `{status:"too_large"}`.
- Stale file: change externally, then resend with old `precondition_sha256` → expect `{status:"stale_file"}` with hashes.
- Overlap: two overlapping ranges → expect rejection.
- Unbalanced braces: remove a closing `}` → expect validation failure and **no write**.
- Header guard: attempt insert before the first `using` → expect `{status:"header_guard"}`.
- Anchor aliasing: `insert`/`content` alias → expect success (aliased to `text`).
- Auto-upgrade: try a text edit overwriting a method header → prefer structured `replace_method` or return a clear error.
- **Pass** when each negative case returns the expected failure without persisting changes.

## T-J. Idempotency & no-op
- Re-run the same `replace_range` with identical content → expect success with no change.
- Re-run a delete of an already-removed helper via `regex_replace` → clean no-op.
- **Pass** if both behave idempotently.

### Implementation notes
- Always capture pre- and post‑windows (±20–40 lines) as evidence in the JUnit `<failure>` or as `<system-out>`.
- For any file write, include `precondition_sha256` and verify the post‑hash in your log.
- At the end, restore the repository to its original state (`git status` must be clean).

# Emit the JUnit file to reports/claude-nl-tests.xml and a summary markdown to reports/claude-nl-tests.md.
133 changes: 133 additions & 0 deletions .github/workflows/claude-nl-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Claude NL suite + (optional) Unity compile

on:
workflow_dispatch:



permissions:
contents: write # allow Claude to write test artifacts
pull-requests: write # allow annotations / comments
issues: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
nl-suite:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }

# If your MCP server needs Python deps (adjust to your repo layout)
- name: Install Python + uv
uses: astral-sh/setup-uv@v4
with:
python-version: '3.11'

- name: Prepare Unity MCP server deps (adjust path or remove if N/A)
run: |
if [ -f UnityMcpServer/requirements.txt ]; then
uv pip install -r UnityMcpServer/requirements.txt
fi
Comment on lines +34 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Path 'UnityMcpServer/requirements.txt' doesn't exist in repository. Should likely be 'UnityMcpBridge/UnityMcpServer~/requirements.txt' or similar


- name: Run Claude NL/T test suite
id: claude
uses: anthropics/claude-code-base-action@beta
with:
# All the test instructions live here (see next file)
prompt_file: .claude/prompts/nl-unity-suite.md

# Keep tools tight: read, grep, glob, run shell, orchestrate batches,
# and call your MCP server tools. (Adjust the mcp__ prefix to match.)
allowed_tools: "Bash(git:*),View,GlobTool,GrepTool,BatchTool,mcp__unity__*"

# Inline MCP config (or put this JSON in .claude/mcp.json)
mcp_config: |
{
"mcpServers": {
"unity": {
"command": "python",
"args": ["UnityMcpServer/src/server.py"]
Comment on lines +54 to +55
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Path 'UnityMcpServer/src/server.py' is invalid. The actual server path appears to be different based on repository structure

}
}
}

# Model + guardrails
model: "claude-3-7-sonnet-20250219"
max_turns: "10"
timeout_minutes: "20"
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

- name: Upload JUnit (Claude NL/T)
if: always()
uses: actions/upload-artifact@v4
with:
name: claude-nl-tests
path: reports/claude-nl-tests.xml

- name: Annotate PR with test results (Claude NL/T)
if: always()
uses: dorny/test-reporter@v1
with:
name: Claude NL/T
path: reports/claude-nl-tests.xml
reporter: java-junit
fail-on-empty: false

- name: Detect Unity mode & secrets
id: detect
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
run: |
if [ -n "$UNITY_LICENSE" ]; then echo "has_license=true" >> $GITHUB_OUTPUT; else echo "has_license=false" >> $GITHUB_OUTPUT; fi
if [ -f ProjectSettings/ProjectVersion.txt ]; then
echo "is_project=true" >> $GITHUB_OUTPUT
else
echo "is_project=false" >> $GITHUB_OUTPUT
fi
if [ -f Packages/manifest.json ] && [ ! -f ProjectSettings/ProjectVersion.txt ]; then
echo "is_package=true" >> $GITHUB_OUTPUT
else
echo "is_package=false" >> $GITHUB_OUTPUT
fi

# --- Optional: Unity compile after Claude’s edits (satisfies NL-4) ---
# If your repo is a *Unity project*:
- name: Unity compile (Project)
if: always() && steps.detect.outputs.has_license == 'true' && steps.detect.outputs.is_project == 'true'
uses: game-ci/unity-test-runner@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
projectPath: .
githubToken: ${{ secrets.GITHUB_TOKEN }}
# Even with no tests, this compiles; add EditMode/PlayMode tests later.
testMode: EditMode

# If your repo is primarily a *Unity package*, prefer packageMode:
- name: Unity compile (Package)
if: always() && steps.detect.outputs.has_license == 'true' && steps.detect.outputs.is_package == 'true'
uses: game-ci/unity-test-runner@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
packageMode: true
unityVersion: 2022.3.45f1 # <-- set explicitly for packages
projectPath: . # or a small sample project path
githubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Clean working tree (discard temp edits)
if: always()
run: |
git restore -SW :/
git clean -fd

Loading