2026-01-26 08:36:29 +08:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEditor.SceneManagement;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.TestTools;
|
|
|
|
|
using MCPForUnity.Editor.Tools.Prefabs;
|
|
|
|
|
using static MCPForUnityTests.Editor.TestUtilities;
|
|
|
|
|
|
|
|
|
|
namespace MCPForUnityTests.Editor.Tools
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
/// Tests for Prefab CRUD operations: create_from_gameobject, get_info, get_hierarchy, modify_contents.
|
2026-01-26 08:36:29 +08:00
|
|
|
/// </summary>
|
|
|
|
|
public class ManagePrefabsCrudTests
|
|
|
|
|
{
|
|
|
|
|
private const string TempDirectory = "Assets/Temp/ManagePrefabsCrudTests";
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp()
|
|
|
|
|
{
|
|
|
|
|
StageUtility.GoToMainStage();
|
|
|
|
|
EnsureFolder(TempDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
|
|
|
|
StageUtility.GoToMainStage();
|
|
|
|
|
|
|
|
|
|
if (AssetDatabase.IsValidFolder(TempDirectory))
|
|
|
|
|
{
|
|
|
|
|
AssetDatabase.DeleteAsset(TempDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CleanupEmptyParentFolders(TempDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region CREATE Tests
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void CreateFromGameObject_CreatesNewPrefab()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
|
|
|
|
string prefabPath = Path.Combine(TempDirectory, "NewPrefab.prefab").Replace('\\', '/');
|
|
|
|
|
GameObject sceneObject = new GameObject("TestObject");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
|
|
|
|
["target"] = sceneObject.name,
|
|
|
|
|
["prefabPath"] = prefabPath
|
|
|
|
|
}));
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(result.Value<bool>("success"));
|
|
|
|
|
Assert.AreEqual(prefabPath, result["data"].Value<string>("prefabPath"));
|
|
|
|
|
Assert.IsNotNull(AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath));
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
if (sceneObject != null) UnityEngine.Object.DestroyImmediate(sceneObject, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void CreateFromGameObject_HandlesExistingPrefabsAndLinks()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Tests: unlinkIfInstance, allowOverwrite, unique path generation
|
|
|
|
|
string prefabPath = Path.Combine(TempDirectory, "Existing.prefab").Replace('\\', '/');
|
2026-01-26 08:36:29 +08:00
|
|
|
GameObject sourceObject = new GameObject("SourceObject");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Create initial prefab and link source object
|
|
|
|
|
PrefabUtility.SaveAsPrefabAssetAndConnect(sourceObject, prefabPath, InteractionMode.AutomatedAction);
|
|
|
|
|
Assert.IsTrue(PrefabUtility.IsAnyPrefabInstanceRoot(sourceObject));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Without unlink - should fail (already linked)
|
|
|
|
|
string newPath = Path.Combine(TempDirectory, "New.prefab").Replace('\\', '/');
|
|
|
|
|
var failResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
|
|
|
|
["target"] = sourceObject.name,
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["prefabPath"] = newPath
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsFalse(failResult.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(failResult.Value<string>("error").Contains("already linked"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// With unlinkIfInstance - should succeed
|
|
|
|
|
var unlinkResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
|
|
|
|
["target"] = sourceObject.name,
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["prefabPath"] = newPath,
|
|
|
|
|
["unlinkIfInstance"] = true
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(unlinkResult.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(unlinkResult["data"].Value<bool>("wasUnlinked"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// With allowOverwrite - should replace
|
|
|
|
|
GameObject anotherObject = new GameObject("AnotherObject");
|
|
|
|
|
var overwriteResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["target"] = anotherObject.name,
|
|
|
|
|
["prefabPath"] = newPath,
|
2026-01-26 08:36:29 +08:00
|
|
|
["allowOverwrite"] = true
|
|
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(overwriteResult.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(overwriteResult["data"].Value<bool>("wasReplaced"));
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(anotherObject, true);
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Without overwrite on existing - should generate unique path
|
|
|
|
|
GameObject thirdObject = new GameObject("ThirdObject");
|
|
|
|
|
var uniqueResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["target"] = thirdObject.name,
|
|
|
|
|
["prefabPath"] = newPath
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(uniqueResult.Value<bool>("success"));
|
|
|
|
|
Assert.AreNotEqual(newPath, uniqueResult["data"].Value<string>("prefabPath"));
|
|
|
|
|
SafeDeleteAsset(uniqueResult["data"].Value<string>("prefabPath"));
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(thirdObject, true);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
SafeDeleteAsset(Path.Combine(TempDirectory, "New.prefab").Replace('\\', '/'));
|
|
|
|
|
if (sourceObject != null) UnityEngine.Object.DestroyImmediate(sourceObject, true);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CreateFromGameObject_FindsInactiveObject_WhenSearchInactiveIsTrue()
|
|
|
|
|
{
|
|
|
|
|
string prefabPath = Path.Combine(TempDirectory, "InactiveTest.prefab").Replace('\\', '/');
|
|
|
|
|
GameObject inactiveObject = new GameObject("InactiveObject");
|
|
|
|
|
inactiveObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Without searchInactive - should fail to find inactive object
|
|
|
|
|
var failResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
|
|
|
|
["target"] = inactiveObject.name,
|
|
|
|
|
["prefabPath"] = prefabPath
|
|
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsFalse(failResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// With searchInactive - should succeed
|
|
|
|
|
var successResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
|
|
|
|
["target"] = inactiveObject.name,
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["searchInactive"] = true
|
|
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(successResult.Value<bool>("success"));
|
|
|
|
|
Assert.IsNotNull(AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath));
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
if (inactiveObject != null) UnityEngine.Object.DestroyImmediate(inactiveObject, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
#region READ Tests
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void GetInfo_ReturnsMetadata()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
string prefabPath = CreateTestPrefab("InfoTest");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
|
|
|
|
["action"] = "get_info",
|
|
|
|
|
["prefabPath"] = prefabPath
|
|
|
|
|
}));
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(result.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
var data = result["data"] as JObject;
|
|
|
|
|
Assert.AreEqual(prefabPath, data.Value<string>("assetPath"));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsNotNull(data.Value<string>("guid"));
|
|
|
|
|
Assert.AreEqual("Regular", data.Value<string>("prefabType"));
|
|
|
|
|
Assert.AreEqual("InfoTest", data.Value<string>("rootObjectName"));
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void GetHierarchy_ReturnsHierarchyWithNestingInfo()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Create a prefab with nested prefab instance
|
|
|
|
|
string childPrefabPath = CreateTestPrefab("ChildPrefab");
|
|
|
|
|
string containerPath = null;
|
|
|
|
|
|
|
|
|
|
try
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
GameObject container = new GameObject("Container");
|
|
|
|
|
GameObject child1 = new GameObject("Child1");
|
|
|
|
|
child1.transform.parent = container.transform;
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Add nested prefab instance
|
|
|
|
|
GameObject nestedInstance = PrefabUtility.InstantiatePrefab(
|
|
|
|
|
AssetDatabase.LoadAssetAtPath<GameObject>(childPrefabPath)) as GameObject;
|
|
|
|
|
nestedInstance.transform.parent = container.transform;
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
containerPath = Path.Combine(TempDirectory, "Container.prefab").Replace('\\', '/');
|
|
|
|
|
PrefabUtility.SaveAsPrefabAsset(container, containerPath, out bool _);
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(container);
|
|
|
|
|
AssetDatabase.Refresh();
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
|
|
|
|
["action"] = "get_hierarchy",
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["prefabPath"] = containerPath
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(result.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
var data = result["data"] as JObject;
|
|
|
|
|
var items = data["items"] as JArray;
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(data.Value<int>("total") >= 3); // Container, Child1, nested prefab
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Verify root and nested prefab info
|
2026-01-26 08:36:29 +08:00
|
|
|
var root = items.Cast<JObject>().FirstOrDefault(j => j["prefab"]["isRoot"].Value<bool>());
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsNotNull(root);
|
|
|
|
|
Assert.AreEqual("Container", root.Value<string>("name"));
|
|
|
|
|
|
|
|
|
|
var nested = items.Cast<JObject>().FirstOrDefault(j => j["prefab"]["isNestedRoot"].Value<bool>());
|
|
|
|
|
Assert.IsNotNull(nested);
|
|
|
|
|
Assert.AreEqual(1, nested["prefab"]["nestingDepth"].Value<int>());
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
if (containerPath != null) SafeDeleteAsset(containerPath);
|
|
|
|
|
SafeDeleteAsset(childPrefabPath);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region UPDATE Tests (ModifyContents)
|
|
|
|
|
|
2026-01-26 08:36:29 +08:00
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void ModifyContents_ModifiesTransformWithoutOpeningStage()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
string prefabPath = CreateTestPrefab("ModifyTest");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
StageUtility.GoToMainStage();
|
|
|
|
|
Assert.IsNull(PrefabStageUtility.GetCurrentPrefabStage());
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["position"] = new JArray(1f, 2f, 3f),
|
|
|
|
|
["rotation"] = new JArray(45f, 0f, 0f),
|
|
|
|
|
["scale"] = new JArray(2f, 2f, 2f)
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(result.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Verify no stage was opened (headless editing)
|
|
|
|
|
Assert.IsNull(PrefabStageUtility.GetCurrentPrefabStage());
|
|
|
|
|
|
|
|
|
|
// Verify changes persisted
|
|
|
|
|
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
|
|
|
|
Assert.AreEqual(new Vector3(1f, 2f, 3f), reloaded.transform.localPosition);
|
|
|
|
|
Assert.AreEqual(new Vector3(2f, 2f, 2f), reloaded.transform.localScale);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
SafeDeleteAsset(prefabPath);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void ModifyContents_TargetsChildrenByNameAndPath()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
string prefabPath = CreateNestedTestPrefab("TargetTest");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Target by name
|
|
|
|
|
var nameResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "Child1",
|
|
|
|
|
["position"] = new JArray(10f, 10f, 10f)
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(nameResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Target by path
|
|
|
|
|
var pathResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "Child1/Grandchild",
|
|
|
|
|
["scale"] = new JArray(3f, 3f, 3f)
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(pathResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Verify changes
|
|
|
|
|
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
|
|
|
|
Assert.AreEqual(new Vector3(10f, 10f, 10f), reloaded.transform.Find("Child1").localPosition);
|
|
|
|
|
Assert.AreEqual(new Vector3(3f, 3f, 3f), reloaded.transform.Find("Child1/Grandchild").localScale);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void ModifyContents_AddsAndRemovesComponents()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
string prefabPath = CreateTestPrefab("ComponentTest");
|
|
|
|
|
// Cube primitive has BoxCollider by default
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Add Rigidbody
|
|
|
|
|
var addResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["componentsToAdd"] = new JArray("Rigidbody")
|
|
|
|
|
}));
|
|
|
|
|
Assert.IsTrue(addResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Remove BoxCollider
|
|
|
|
|
var removeResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["componentsToRemove"] = new JArray("BoxCollider")
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(removeResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Verify
|
2026-01-26 08:36:29 +08:00
|
|
|
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsNotNull(reloaded.GetComponent<Rigidbody>());
|
|
|
|
|
Assert.IsNull(reloaded.GetComponent<BoxCollider>());
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void ModifyContents_SetsPropertiesAndRenames()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
string prefabPath = CreateNestedTestPrefab("PropertiesTest");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "Child1",
|
|
|
|
|
["name"] = "RenamedChild",
|
|
|
|
|
["tag"] = "MainCamera",
|
|
|
|
|
["layer"] = "UI",
|
|
|
|
|
["setActive"] = false
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(result.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Transform renamed = reloaded.transform.Find("RenamedChild");
|
|
|
|
|
Assert.IsNotNull(renamed);
|
|
|
|
|
Assert.IsNull(reloaded.transform.Find("Child1")); // Old name gone
|
|
|
|
|
Assert.AreEqual("MainCamera", renamed.gameObject.tag);
|
|
|
|
|
Assert.AreEqual(LayerMask.NameToLayer("UI"), renamed.gameObject.layer);
|
|
|
|
|
Assert.IsFalse(renamed.gameObject.activeSelf);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void ModifyContents_WorksOnComplexMultiComponentPrefab()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Create a complex prefab: Vehicle with multiple children, each with multiple components
|
|
|
|
|
string prefabPath = CreateComplexTestPrefab("Vehicle");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Modify root - add Rigidbody
|
|
|
|
|
var rootResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["componentsToAdd"] = new JArray("Rigidbody")
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(rootResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Modify child by name - reposition FrontWheel, add SphereCollider
|
|
|
|
|
var wheelResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
|
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "FrontWheel",
|
|
|
|
|
["position"] = new JArray(0f, 0.5f, 2f),
|
|
|
|
|
["componentsToAdd"] = new JArray("SphereCollider")
|
|
|
|
|
}));
|
|
|
|
|
Assert.IsTrue(wheelResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Modify nested child by path - scale Barrel inside Turret
|
|
|
|
|
var barrelResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "Turret/Barrel",
|
|
|
|
|
["scale"] = new JArray(0.5f, 0.5f, 3f),
|
|
|
|
|
["tag"] = "Player"
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(barrelResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Remove component from child
|
|
|
|
|
var removeResult = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "BackWheel",
|
|
|
|
|
["componentsToRemove"] = new JArray("BoxCollider")
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(removeResult.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Verify all changes persisted
|
2026-01-26 08:36:29 +08:00
|
|
|
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
|
|
|
|
|
// Root has Rigidbody
|
|
|
|
|
Assert.IsNotNull(reloaded.GetComponent<Rigidbody>(), "Root should have Rigidbody");
|
|
|
|
|
|
|
|
|
|
// FrontWheel repositioned and has SphereCollider
|
|
|
|
|
Transform frontWheel = reloaded.transform.Find("FrontWheel");
|
|
|
|
|
Assert.AreEqual(new Vector3(0f, 0.5f, 2f), frontWheel.localPosition);
|
|
|
|
|
Assert.IsNotNull(frontWheel.GetComponent<SphereCollider>(), "FrontWheel should have SphereCollider");
|
|
|
|
|
|
|
|
|
|
// Turret/Barrel scaled and tagged
|
|
|
|
|
Transform barrel = reloaded.transform.Find("Turret/Barrel");
|
|
|
|
|
Assert.AreEqual(new Vector3(0.5f, 0.5f, 3f), barrel.localScale);
|
|
|
|
|
Assert.AreEqual("Player", barrel.gameObject.tag);
|
|
|
|
|
|
|
|
|
|
// BackWheel BoxCollider removed
|
|
|
|
|
Transform backWheel = reloaded.transform.Find("BackWheel");
|
|
|
|
|
Assert.IsNull(backWheel.GetComponent<BoxCollider>(), "BackWheel BoxCollider should be removed");
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void ModifyContents_ReparentsChildWithinPrefab()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
string prefabPath = CreateNestedTestPrefab("ReparentTest");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
try
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Reparent Child2 under Child1
|
|
|
|
|
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
|
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "Child2",
|
|
|
|
|
["parent"] = "Child1"
|
|
|
|
|
}));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsTrue(result.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Verify Child2 is now under Child1
|
|
|
|
|
GameObject reloaded = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
|
|
|
|
Assert.IsNull(reloaded.transform.Find("Child2"), "Child2 should no longer be direct child of root");
|
|
|
|
|
Assert.IsNotNull(reloaded.transform.Find("Child1/Child2"), "Child2 should now be under Child1");
|
|
|
|
|
}
|
|
|
|
|
finally
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
SafeDeleteAsset(prefabPath);
|
|
|
|
|
}
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void ModifyContents_PreventsHierarchyLoops()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
string prefabPath = CreateNestedTestPrefab("HierarchyLoopTest");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Attempt to parent Child1 under its own descendant (Grandchild)
|
2026-01-26 08:36:29 +08:00
|
|
|
var result = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "Child1",
|
|
|
|
|
["parent"] = "Child1/Grandchild"
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsFalse(result.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(result.Value<string>("error").Contains("hierarchy loop") ||
|
|
|
|
|
result.Value<string>("error").Contains("would create"),
|
|
|
|
|
"Error should mention hierarchy loop prevention");
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
SafeDeleteAsset(prefabPath);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Error Handling
|
|
|
|
|
|
2026-01-26 08:36:29 +08:00
|
|
|
[Test]
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
public void HandleCommand_ValidatesParameters()
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Null params
|
|
|
|
|
var nullResult = ToJObject(ManagePrefabs.HandleCommand(null));
|
|
|
|
|
Assert.IsFalse(nullResult.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(nullResult.Value<string>("error").Contains("null"));
|
|
|
|
|
|
|
|
|
|
// Missing action
|
|
|
|
|
var missingAction = ToJObject(ManagePrefabs.HandleCommand(new JObject()));
|
|
|
|
|
Assert.IsFalse(missingAction.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(missingAction.Value<string>("error").Contains("Action parameter is required"));
|
|
|
|
|
|
|
|
|
|
// Unknown action
|
|
|
|
|
var unknownAction = ToJObject(ManagePrefabs.HandleCommand(new JObject { ["action"] = "invalid" }));
|
|
|
|
|
Assert.IsFalse(unknownAction.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(unknownAction.Value<string>("error").Contains("Unknown action"));
|
|
|
|
|
|
|
|
|
|
// Path traversal
|
|
|
|
|
GameObject testObj = new GameObject("Test");
|
|
|
|
|
var traversal = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
|
|
|
|
["action"] = "create_from_gameobject",
|
|
|
|
|
["target"] = "Test",
|
|
|
|
|
["prefabPath"] = "../../etc/passwd"
|
|
|
|
|
}));
|
|
|
|
|
Assert.IsFalse(traversal.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(traversal.Value<string>("error").Contains("path traversal") ||
|
|
|
|
|
traversal.Value<string>("error").Contains("Invalid"));
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(testObj, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void ModifyContents_ReturnsErrorsForInvalidInputs()
|
|
|
|
|
{
|
|
|
|
|
string prefabPath = CreateTestPrefab("ErrorTest");
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Invalid target
|
|
|
|
|
var invalidTarget = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
2026-01-26 08:36:29 +08:00
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = prefabPath,
|
|
|
|
|
["target"] = "NonexistentChild"
|
2026-01-26 08:36:29 +08:00
|
|
|
}));
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
Assert.IsFalse(invalidTarget.Value<bool>("success"));
|
|
|
|
|
Assert.IsTrue(invalidTarget.Value<string>("error").Contains("not found"));
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
// Invalid path
|
|
|
|
|
LogAssert.Expect(LogType.Error, new Regex(".*modify_contents.*does not exist.*"));
|
|
|
|
|
var invalidPath = ToJObject(ManagePrefabs.HandleCommand(new JObject
|
|
|
|
|
{
|
|
|
|
|
["action"] = "modify_contents",
|
|
|
|
|
["prefabPath"] = "Assets/Nonexistent.prefab"
|
|
|
|
|
}));
|
|
|
|
|
Assert.IsFalse(invalidPath.Value<bool>("success"));
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
SafeDeleteAsset(prefabPath);
|
2026-01-26 08:36:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Test Helpers
|
|
|
|
|
|
|
|
|
|
private static string CreateTestPrefab(string name)
|
|
|
|
|
{
|
|
|
|
|
EnsureFolder(TempDirectory);
|
|
|
|
|
GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
|
|
|
temp.name = name;
|
|
|
|
|
|
|
|
|
|
string path = Path.Combine(TempDirectory, name + ".prefab").Replace('\\', '/');
|
|
|
|
|
PrefabUtility.SaveAsPrefabAsset(temp, path, out bool success);
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(temp);
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
if (!success) throw new Exception($"Failed to create test prefab at {path}");
|
2026-01-26 08:36:29 +08:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string CreateNestedTestPrefab(string name)
|
|
|
|
|
{
|
|
|
|
|
EnsureFolder(TempDirectory);
|
|
|
|
|
GameObject root = new GameObject(name);
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
GameObject child1 = new GameObject("Child1") { transform = { parent = root.transform } };
|
|
|
|
|
GameObject child2 = new GameObject("Child2") { transform = { parent = root.transform } };
|
|
|
|
|
GameObject grandchild = new GameObject("Grandchild") { transform = { parent = child1.transform } };
|
|
|
|
|
|
|
|
|
|
string path = Path.Combine(TempDirectory, name + ".prefab").Replace('\\', '/');
|
|
|
|
|
PrefabUtility.SaveAsPrefabAsset(root, path, out bool success);
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(root);
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
|
|
|
|
if (!success) throw new Exception($"Failed to create nested test prefab at {path}");
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string CreateComplexTestPrefab(string name)
|
|
|
|
|
{
|
|
|
|
|
// Creates: Vehicle (root with BoxCollider)
|
|
|
|
|
// - FrontWheel (Cube with MeshRenderer, BoxCollider)
|
|
|
|
|
// - BackWheel (Cube with MeshRenderer, BoxCollider)
|
|
|
|
|
// - Turret (empty)
|
|
|
|
|
// - Barrel (Cylinder with MeshRenderer, CapsuleCollider)
|
|
|
|
|
EnsureFolder(TempDirectory);
|
|
|
|
|
|
|
|
|
|
GameObject root = new GameObject(name);
|
|
|
|
|
root.AddComponent<BoxCollider>();
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
GameObject frontWheel = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
|
|
|
frontWheel.name = "FrontWheel";
|
|
|
|
|
frontWheel.transform.parent = root.transform;
|
|
|
|
|
frontWheel.transform.localPosition = new Vector3(0, 0.5f, 1f);
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
GameObject backWheel = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
|
|
|
backWheel.name = "BackWheel";
|
|
|
|
|
backWheel.transform.parent = root.transform;
|
|
|
|
|
backWheel.transform.localPosition = new Vector3(0, 0.5f, -1f);
|
2026-01-26 08:36:29 +08:00
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
GameObject turret = new GameObject("Turret");
|
|
|
|
|
turret.transform.parent = root.transform;
|
|
|
|
|
turret.transform.localPosition = new Vector3(0, 1f, 0);
|
|
|
|
|
|
|
|
|
|
GameObject barrel = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
|
|
|
|
|
barrel.name = "Barrel";
|
|
|
|
|
barrel.transform.parent = turret.transform;
|
|
|
|
|
barrel.transform.localPosition = new Vector3(0, 0, 1f);
|
2026-01-26 08:36:29 +08:00
|
|
|
|
|
|
|
|
string path = Path.Combine(TempDirectory, name + ".prefab").Replace('\\', '/');
|
|
|
|
|
PrefabUtility.SaveAsPrefabAsset(root, path, out bool success);
|
|
|
|
|
UnityEngine.Object.DestroyImmediate(root);
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
feat: replace prefab stage actions with headless modify_contents (#635)
Removes stage-based prefab editing (open_stage, close_stage, save_open_stage)
in favor of headless modify_contents action that uses PrefabUtility.LoadPrefabContents
for reliable automated workflows without UI dialogs.
Changes:
- Remove open_stage, close_stage, save_open_stage actions
- Add modify_contents action for headless prefab editing
- Support targeting objects by name or path (e.g., "Turret/Barrel")
- Support transform, tag, layer, setActive, name, parent, components operations
- Skip saving when no modifications made (avoids unnecessary asset writes)
- Delete PrefabStage.cs resource (no longer needed)
- Update Python tool description to remove "stages" reference
- Consolidate tests from 29 to 14 (covers complex prefabs, reparenting, hierarchy loop guard)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 02:53:44 +08:00
|
|
|
if (!success) throw new Exception($"Failed to create complex test prefab at {path}");
|
2026-01-26 08:36:29 +08:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|