unity-mcp/tests/test_find_in_file_minimal.py

81 lines
2.4 KiB
Python
Raw Normal View History

Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
import sys
import pathlib
import importlib.util
import types
import asyncio
import pytest
test: Consolidate pytest suite to MCPForUnity and improve test infrastructure (#332) * Update github-repo-stats.yml * pytest: make harness MCPForUnity-only; remove UnityMcpBridge paths from tests; route tools.manage_script via unity_connection for reliable monkeypatching; fix ctx usage; all tests green (39 pass, 5 skip, 7 xpass) * Add missing meta for MaterialMeshInstantiationTests.cs (Assets) * bridge/tools/manage_script: fix missing unity_connection prefix in validate_script; tests: tidy manage_script_uri unused symbols and arg names * tests: rename to script_apply_edits_module; extract DummyContext to tests/test_helpers and import; add telemetry stubs in tests to avoid pyproject I/O * tests: import cleanup and helper extraction; telemetry: prefer plain config and opt-in env override; test stubs and CWD fixes; exclude Bridge from pytest discovery * chore: remove unintended .wt-origin-main gitlink and ignore folder * tests: nit fixes (unused-arg stubs, import order, path-normalized ignore hook); telemetry: validate config endpoint; read_console: action optional * Add development dependencies to pyproject.toml - Add [project.optional-dependencies] section with dev group - Include pytest>=8.0.0 and pytest-anyio>=0.6.0 - Add Development Setup section to README-DEV.md with installation and testing instructions * Revert "Update github-repo-stats.yml" This reverts commit 8ae595d2f4f2525b0e44ece948883ea37138add4. * test: improve test clarity and modernize asyncio usage - Add explanation for 200ms timeout in backpressure test - Replace manual event loop creation with asyncio.run() - Add assertion message with actual elapsed time for easier debugging * refactor: remove duplicate DummyContext definitions across test files Replace 7 duplicate DummyContext class definitions with imports from tests.test_helpers. This follows DRY principles and ensures consistency across the test suite. * chore: remove unused _load function from test_edit_strict_and_warnings.py Dead code cleanup - function was no longer used after refactoring to dynamic tool registration. * docs: add comment explaining CWD manipulation in telemetry test Clarify why os.chdir() is necessary: telemetry.py calls get_package_version() at module load time, which reads pyproject.toml using a relative path. Acknowledges the fragility while explaining why it's currently required.
2025-10-22 01:42:55 +08:00
from tests.test_helpers import DummyContext
Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
ROOT = pathlib.Path(__file__).resolve().parents[1]
SRC = ROOT / "MCPForUnity" / "UnityMcpServer~" / "src"
Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
sys.path.insert(0, str(SRC))
test: Consolidate pytest suite to MCPForUnity and improve test infrastructure (#332) * Update github-repo-stats.yml * pytest: make harness MCPForUnity-only; remove UnityMcpBridge paths from tests; route tools.manage_script via unity_connection for reliable monkeypatching; fix ctx usage; all tests green (39 pass, 5 skip, 7 xpass) * Add missing meta for MaterialMeshInstantiationTests.cs (Assets) * bridge/tools/manage_script: fix missing unity_connection prefix in validate_script; tests: tidy manage_script_uri unused symbols and arg names * tests: rename to script_apply_edits_module; extract DummyContext to tests/test_helpers and import; add telemetry stubs in tests to avoid pyproject I/O * tests: import cleanup and helper extraction; telemetry: prefer plain config and opt-in env override; test stubs and CWD fixes; exclude Bridge from pytest discovery * chore: remove unintended .wt-origin-main gitlink and ignore folder * tests: nit fixes (unused-arg stubs, import order, path-normalized ignore hook); telemetry: validate config endpoint; read_console: action optional * Add development dependencies to pyproject.toml - Add [project.optional-dependencies] section with dev group - Include pytest>=8.0.0 and pytest-anyio>=0.6.0 - Add Development Setup section to README-DEV.md with installation and testing instructions * Revert "Update github-repo-stats.yml" This reverts commit 8ae595d2f4f2525b0e44ece948883ea37138add4. * test: improve test clarity and modernize asyncio usage - Add explanation for 200ms timeout in backpressure test - Replace manual event loop creation with asyncio.run() - Add assertion message with actual elapsed time for easier debugging * refactor: remove duplicate DummyContext definitions across test files Replace 7 duplicate DummyContext class definitions with imports from tests.test_helpers. This follows DRY principles and ensures consistency across the test suite. * chore: remove unused _load function from test_edit_strict_and_warnings.py Dead code cleanup - function was no longer used after refactoring to dynamic tool registration. * docs: add comment explaining CWD manipulation in telemetry test Clarify why os.chdir() is necessary: telemetry.py calls get_package_version() at module load time, which reads pyproject.toml using a relative path. Acknowledges the fragility while explaining why it's currently required.
2025-10-22 01:42:55 +08:00
# Stub telemetry modules to avoid file I/O during import of tools package
telemetry = types.ModuleType("telemetry")
def _noop(*args, **kwargs):
pass
class MilestoneType:
pass
telemetry.record_resource_usage = _noop
telemetry.record_tool_usage = _noop
telemetry.record_milestone = _noop
telemetry.MilestoneType = MilestoneType
telemetry.get_package_version = lambda: "0.0.0"
sys.modules.setdefault("telemetry", telemetry)
telemetry_decorator = types.ModuleType("telemetry_decorator")
def telemetry_tool(*dargs, **dkwargs):
def _wrap(fn):
return fn
return _wrap
telemetry_decorator.telemetry_tool = telemetry_tool
sys.modules.setdefault("telemetry_decorator", telemetry_decorator)
Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
class DummyMCP:
def __init__(self):
self.tools = {}
def tool(self, *args, **kwargs):
def deco(fn):
self.tools[fn.__name__] = fn
return fn
return deco
2025-10-01 04:25:33 +08:00
Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
@pytest.fixture()
def resource_tools():
mcp = DummyMCP()
test: Consolidate pytest suite to MCPForUnity and improve test infrastructure (#332) * Update github-repo-stats.yml * pytest: make harness MCPForUnity-only; remove UnityMcpBridge paths from tests; route tools.manage_script via unity_connection for reliable monkeypatching; fix ctx usage; all tests green (39 pass, 5 skip, 7 xpass) * Add missing meta for MaterialMeshInstantiationTests.cs (Assets) * bridge/tools/manage_script: fix missing unity_connection prefix in validate_script; tests: tidy manage_script_uri unused symbols and arg names * tests: rename to script_apply_edits_module; extract DummyContext to tests/test_helpers and import; add telemetry stubs in tests to avoid pyproject I/O * tests: import cleanup and helper extraction; telemetry: prefer plain config and opt-in env override; test stubs and CWD fixes; exclude Bridge from pytest discovery * chore: remove unintended .wt-origin-main gitlink and ignore folder * tests: nit fixes (unused-arg stubs, import order, path-normalized ignore hook); telemetry: validate config endpoint; read_console: action optional * Add development dependencies to pyproject.toml - Add [project.optional-dependencies] section with dev group - Include pytest>=8.0.0 and pytest-anyio>=0.6.0 - Add Development Setup section to README-DEV.md with installation and testing instructions * Revert "Update github-repo-stats.yml" This reverts commit 8ae595d2f4f2525b0e44ece948883ea37138add4. * test: improve test clarity and modernize asyncio usage - Add explanation for 200ms timeout in backpressure test - Replace manual event loop creation with asyncio.run() - Add assertion message with actual elapsed time for easier debugging * refactor: remove duplicate DummyContext definitions across test files Replace 7 duplicate DummyContext class definitions with imports from tests.test_helpers. This follows DRY principles and ensures consistency across the test suite. * chore: remove unused _load function from test_edit_strict_and_warnings.py Dead code cleanup - function was no longer used after refactoring to dynamic tool registration. * docs: add comment explaining CWD manipulation in telemetry test Clarify why os.chdir() is necessary: telemetry.py calls get_package_version() at module load time, which reads pyproject.toml using a relative path. Acknowledges the fragility while explaining why it's currently required.
2025-10-22 01:42:55 +08:00
# Import the tools module to trigger decorator registration
import tools.resource_tools
# Get the registered tools from the registry
from registry import get_registered_tools
tools = get_registered_tools()
# Add all resource-related tools to our dummy MCP
for tool_info in tools:
tool_name = tool_info['name']
if any(keyword in tool_name for keyword in ['find_in_file', 'list_resources', 'read_resource']):
mcp.tools[tool_name] = tool_info['func']
Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
return mcp.tools
2025-10-01 04:25:33 +08:00
Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
def test_find_in_file_returns_positions(resource_tools, tmp_path):
proj = tmp_path
assets = proj / "Assets"
assets.mkdir()
f = assets / "A.txt"
f.write_text("hello world", encoding="utf-8")
find_in_file = resource_tools["find_in_file"]
loop = asyncio.new_event_loop()
try:
resp = loop.run_until_complete(
2025-10-01 04:25:33 +08:00
find_in_file(uri="unity://path/Assets/A.txt",
test: Consolidate pytest suite to MCPForUnity and improve test infrastructure (#332) * Update github-repo-stats.yml * pytest: make harness MCPForUnity-only; remove UnityMcpBridge paths from tests; route tools.manage_script via unity_connection for reliable monkeypatching; fix ctx usage; all tests green (39 pass, 5 skip, 7 xpass) * Add missing meta for MaterialMeshInstantiationTests.cs (Assets) * bridge/tools/manage_script: fix missing unity_connection prefix in validate_script; tests: tidy manage_script_uri unused symbols and arg names * tests: rename to script_apply_edits_module; extract DummyContext to tests/test_helpers and import; add telemetry stubs in tests to avoid pyproject I/O * tests: import cleanup and helper extraction; telemetry: prefer plain config and opt-in env override; test stubs and CWD fixes; exclude Bridge from pytest discovery * chore: remove unintended .wt-origin-main gitlink and ignore folder * tests: nit fixes (unused-arg stubs, import order, path-normalized ignore hook); telemetry: validate config endpoint; read_console: action optional * Add development dependencies to pyproject.toml - Add [project.optional-dependencies] section with dev group - Include pytest>=8.0.0 and pytest-anyio>=0.6.0 - Add Development Setup section to README-DEV.md with installation and testing instructions * Revert "Update github-repo-stats.yml" This reverts commit 8ae595d2f4f2525b0e44ece948883ea37138add4. * test: improve test clarity and modernize asyncio usage - Add explanation for 200ms timeout in backpressure test - Replace manual event loop creation with asyncio.run() - Add assertion message with actual elapsed time for easier debugging * refactor: remove duplicate DummyContext definitions across test files Replace 7 duplicate DummyContext class definitions with imports from tests.test_helpers. This follows DRY principles and ensures consistency across the test suite. * chore: remove unused _load function from test_edit_strict_and_warnings.py Dead code cleanup - function was no longer used after refactoring to dynamic tool registration. * docs: add comment explaining CWD manipulation in telemetry test Clarify why os.chdir() is necessary: telemetry.py calls get_package_version() at module load time, which reads pyproject.toml using a relative path. Acknowledges the fragility while explaining why it's currently required.
2025-10-22 01:42:55 +08:00
pattern="world", ctx=DummyContext(), project_root=str(proj))
Improved ci prompt testing suite (#270) * CI: streamline Unity licensing (ULF/EBL); drop cache mounts & EBL-in-container; NL suite: clarify T-E/T-J, anchor positions, EOF brace targeting, SHA preconditions * CI: support both ULF + EBL; validate ULF before -manualLicenseFile; robust readiness wait; use game-ci @v2 actions * CI: activate EBL via container using UNITY_IMAGE; fix readiness regex grouping * CI: minimal patch — guard manualLicenseFile by ulf.ok, expand error patterns, keep return-license @v2 for linter * CI: harden ULF staging (printf+chmod); pass ULF_OK via env; use manual_args array for -manualLicenseFile * CI: assert EBL activation writes entitlement to host mount; fail fast if missing * CI: use heredoc in wait step to avoid nested-quote issues; remove redundant EBL artifact copy; drop job-level if and unused UNITY_VERSION * CI: harden wait step (container status check, broader ready patterns, longer timeout); make license return non-blocking * CI: wait step — confirm bridge readiness via status JSON (unity_port) + host socket probe * CI: YAML-safe readiness fallback (grep/sed unity_port + bash TCP probe); workflow_dispatch trigger + ASCII step names * CI: refine license error pattern to ignore benign LicensingClient channel startup; only match true activation/return failures * Improve Unity bridge wait logic in CI workflow - Increase timeout from 600s to 900s for Unity startup - Add 'bound' to readiness pattern to catch more bridge signals - Refine error detection to focus only on license failures - Remove non-license error patterns that could cause false failures - Improve error reporting with descriptive messages - Fix regex escaping for unity port parsing - Fix case sensitivity in sed commands * Add comprehensive Unity workflow improvements - Add project warm-up step to pre-import Library before bridge startup - Expand license mounts to capture full Unity config and local-share directories - Update bridge container to use expanded directory mounts instead of narrow license paths - Provide ULF licenses in both legacy and standard local-share paths - Improve EBL activation to capture complete Unity authentication context - Update verification logic to check full config directories for entitlements These changes eliminate cold import delays during bridge startup and provide Unity with all necessary authentication data, reducing edge cases and improving overall workflow reliability. * Refine Unity workflow licensing and permissions - Make EBL verification conditional on ULF presence to allow ULF-only runs - Remove read-only mounts from warm-up container for Unity user directories - Align secrets gate with actual licensing requirements (remove UNITY_SERIAL only) - Keep return-license action at v2 (latest available version) These changes prevent workflow failures when EBL has issues but ULF is valid, allow Unity to write preferences during warm-up, and ensure secrets detection matches the actual licensing logic used by the workflow steps. * fix workflow YAML parse * Normalize NL/T JUnit names and robust summary * Fix Python import syntax in workflow debug step * Improve prompt clarity for XML test fragment format - Add detailed XML format requirements with exact specifications - Emphasize NO prologue, epilogue, code fences, or extra characters - Add specific instructions for T-D and T-J tests to write fragments immediately - Include exact XML template and TESTID requirements - Should fix T-D and T-J test failures in CI by ensuring proper fragment format * Fix problematic regex substitution in test name canonicalization - Replace unsafe regex substitution that could create malformed names - New approach: preserve correctly formatted names, extract titles safely - Prevents edge cases where double processing could corrupt test names - Uses proper em dash (—) separator consistently - More robust handling of various input formats * CI: NL/T hardening — enforce filename-derived IDs, robust backfill, single-testcase guard; tighten prompt emissions; disallow Bash * fix: keep file ID when canonicalizing test names * CI: move Unity Pro license return to teardown after stopping Unity; keep placeholder at original site * CI: remove revert helper & baseline snapshot; stop creating scripts dir; prompt: standardize T-B validation to level=standard * CI: remove mini workflow and obsolete NL prompts; redact email in all Unity log dumps * NL/T prompt: enforce allowed ops, require per-test fragment emission (incl. failures), add T-F..T-J XML templates * NL suite: enforce strict NL-4 emission; remove brittle relabeling; keep canonicalization + backfill * NL/T: minimize transcript; tighten NL-4 console reads; add final errors scan in T-J * ci: add local validate-nlt-coverage helper * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: add staged report fragment promotion step (reports/_staging -> reports/) to support multi-edit reporting * CI: minor polish and guardrails; keep staged reports promotion and placeholder detection * read_console: default count=50; normalize types str->list; tolerate legacy payload shapes * read_console: harden response parsing for legacy shapes (data as list, tuple entries) * Docs: refresh CI workflow and prompts (remove mini suite refs; per-test emissions, staging, guard) * CI: move T coverage check after staged promotion; accept _staging as present; dedupe promotion step * CI: make T retry conditional on explicit coverage probe (not failure()); respect _staging in probe
2025-09-08 06:47:56 +08:00
)
finally:
loop.close()
assert resp["success"] is True
2025-10-01 04:25:33 +08:00
assert resp["data"]["matches"] == [
{"startLine": 1, "startCol": 7, "endLine": 1, "endCol": 12}]