yaze
0.3.2
Link to the Past ROM Editor
Loading...
Searching...
No Matches
agent_tools_test.h
Go to the documentation of this file.
1
#ifndef YAZE_APP_TEST_AGENT_TOOLS_TEST_H_
2
#define YAZE_APP_TEST_AGENT_TOOLS_TEST_H_
3
4
#include <filesystem>
5
#include "
app/editor/agent/agent_chat_history_codec.h
"
6
#include "
app/editor/agent/agent_state.h
"
7
#include "
app/testing/test_manager.h
"
8
#include "
cli/service/agent/tool_dispatcher.h
"
9
10
namespace
yaze
{
11
namespace
test {
12
13
void
RegisterAgentToolsTestSuite
();
14
15
class
AgentToolsTestSuite
:
public
TestSuite
{
16
public
:
17
AgentToolsTestSuite
() =
default
;
18
~AgentToolsTestSuite
()
override
=
default
;
19
20
std::string
GetName
()
const override
{
return
"Agent Tools & Config"
; }
21
TestCategory
GetCategory
()
const override
{
return
TestCategory::kUnit
; }
22
23
absl::Status
RunTests
(
TestResults
& results)
override
{
24
RunToolPreferencesTest
(results);
25
RunConfigPersistenceTest
(results);
26
return
absl::OkStatus();
27
}
28
29
private
:
30
void
RunToolPreferencesTest
(
TestResults
& results) {
31
auto
start_time = std::chrono::steady_clock::now();
32
TestResult
result;
33
result.
name
=
"ToolPreferences_MemoryInspector"
;
34
result.
suite_name
=
GetName
();
35
result.
category
=
GetCategory
();
36
result.
timestamp
= start_time;
37
38
yaze::cli::agent::ToolDispatcher::ToolPreferences
prefs;
39
// Verify default matches expectation (I set it to true in header)
40
if
(prefs.
memory_inspector
) {
41
prefs.
memory_inspector
=
false
;
42
if
(!prefs.
memory_inspector
) {
43
result.
status
=
TestStatus::kPassed
;
44
}
else
{
45
result.
status
=
TestStatus::kFailed
;
46
result.
error_message
=
"Failed to toggle memory_inspector preference"
;
47
}
48
}
else
{
49
// If default changed, just verify we can toggle it
50
prefs.
memory_inspector
=
true
;
51
if
(prefs.
memory_inspector
) {
52
result.
status
=
TestStatus::kPassed
;
53
}
else
{
54
result.
status
=
TestStatus::kFailed
;
55
result.
error_message
=
"Failed to enable memory_inspector"
;
56
}
57
}
58
59
auto
end_time = std::chrono::steady_clock::now();
60
result.
duration
= std::chrono::duration_cast<std::chrono::milliseconds>(
61
end_time - start_time);
62
results.
AddResult
(result);
63
}
64
65
void
RunConfigPersistenceTest
(
TestResults
& results) {
66
auto
start_time = std::chrono::steady_clock::now();
67
TestResult
result;
68
result.
name
=
"ConfigPersistence_MemoryInspector"
;
69
result.
suite_name
=
GetName
();
70
result.
category
=
GetCategory
();
71
result.
timestamp
= start_time;
72
73
#if defined(YAZE_WITH_JSON)
74
// Create a snapshot with memory_inspector = true
75
yaze::editor::AgentChatHistoryCodec::Snapshot
snapshot;
76
yaze::editor::AgentChatHistoryCodec::AgentConfigSnapshot
config;
77
config.
tools
.
memory_inspector
=
true
;
78
snapshot.
agent_config
= config;
79
80
// Save to temp file
81
std::filesystem::path temp_path =
82
std::filesystem::temp_directory_path() /
"yaze_test_config.json"
;
83
auto
save_status =
84
yaze::editor::AgentChatHistoryCodec::Save
(temp_path, snapshot);
85
86
if
(!save_status.ok()) {
87
result.
status
=
TestStatus::kFailed
;
88
result.
error_message
=
89
"Save failed: "
+ std::string(save_status.message());
90
}
else
{
91
// Load back
92
auto
load_result =
yaze::editor::AgentChatHistoryCodec::Load
(temp_path);
93
if
(load_result.ok()) {
94
if
(load_result->agent_config.has_value() &&
95
load_result->agent_config->tools.memory_inspector ==
true
) {
96
97
// Now test false
98
snapshot.
agent_config
->tools.memory_inspector =
false
;
99
yaze::editor::AgentChatHistoryCodec::Save
(temp_path, snapshot);
100
auto
load_result2 =
101
yaze::editor::AgentChatHistoryCodec::Load
(temp_path);
102
103
if
(load_result2.ok() && load_result2->agent_config.has_value() &&
104
load_result2->agent_config->tools.memory_inspector ==
false
) {
105
result.
status
=
TestStatus::kPassed
;
106
}
else
{
107
result.
status
=
TestStatus::kFailed
;
108
result.
error_message
=
"Failed to persist memory_inspector=false"
;
109
}
110
}
else
{
111
result.
status
=
TestStatus::kFailed
;
112
result.
error_message
=
"Failed to persist memory_inspector=true"
;
113
}
114
}
else
{
115
result.
status
=
TestStatus::kFailed
;
116
result.
error_message
=
117
"Load failed: "
+ std::string(load_result.status().message());
118
}
119
}
120
// Cleanup
121
std::error_code ec;
122
std::filesystem::remove(temp_path, ec);
123
#else
124
result.
status
=
TestStatus::kSkipped
;
125
result.
error_message
=
"JSON support disabled"
;
126
#endif
127
128
auto
end_time = std::chrono::steady_clock::now();
129
result.
duration
= std::chrono::duration_cast<std::chrono::milliseconds>(
130
end_time - start_time);
131
results.
AddResult
(result);
132
}
133
};
134
135
// Register the AgentToolsTestSuite with the TestManager.
136
void
RegisterAgentToolsTestSuite
();
137
138
}
// namespace test
139
}
// namespace yaze
140
141
#endif
// YAZE_APP_TEST_AGENT_TOOLS_TEST_H_
agent_chat_history_codec.h
agent_state.h
yaze::editor::AgentChatHistoryCodec::Save
static absl::Status Save(const std::filesystem::path &path, const Snapshot &snapshot)
Definition
agent_chat_history_codec.cc:362
yaze::editor::AgentChatHistoryCodec::Load
static absl::StatusOr< Snapshot > Load(const std::filesystem::path &path)
Definition
agent_chat_history_codec.cc:130
yaze::test::AgentToolsTestSuite
Definition
agent_tools_test.h:15
yaze::test::AgentToolsTestSuite::RunConfigPersistenceTest
void RunConfigPersistenceTest(TestResults &results)
Definition
agent_tools_test.h:65
yaze::test::AgentToolsTestSuite::GetName
std::string GetName() const override
Definition
agent_tools_test.h:20
yaze::test::AgentToolsTestSuite::RunToolPreferencesTest
void RunToolPreferencesTest(TestResults &results)
Definition
agent_tools_test.h:30
yaze::test::AgentToolsTestSuite::GetCategory
TestCategory GetCategory() const override
Definition
agent_tools_test.h:21
yaze::test::AgentToolsTestSuite::AgentToolsTestSuite
AgentToolsTestSuite()=default
yaze::test::AgentToolsTestSuite::RunTests
absl::Status RunTests(TestResults &results) override
Definition
agent_tools_test.h:23
yaze::test::AgentToolsTestSuite::~AgentToolsTestSuite
~AgentToolsTestSuite() override=default
yaze::test::TestSuite
Definition
test_manager.h:105
yaze::test::TestCategory
TestCategory
Definition
test_manager.h:51
yaze::test::TestCategory::kUnit
@ kUnit
yaze::test::TestStatus::kPassed
@ kPassed
yaze::test::TestStatus::kFailed
@ kFailed
yaze::test::TestStatus::kSkipped
@ kSkipped
yaze::test::RegisterAgentToolsTestSuite
void RegisterAgentToolsTestSuite()
Definition
agent_tools_test.cc:7
yaze
Definition
patch_export_usage.cc:8
yaze::cli::agent::ToolDispatcher::ToolPreferences
Definition
tool_dispatcher.h:28
yaze::cli::agent::ToolDispatcher::ToolPreferences::memory_inspector
bool memory_inspector
Definition
tool_dispatcher.h:44
yaze::editor::AgentChatHistoryCodec::AgentConfigSnapshot::ToolFlags::memory_inspector
bool memory_inspector
Definition
agent_chat_history_codec.h:48
yaze::editor::AgentChatHistoryCodec::AgentConfigSnapshot
Definition
agent_chat_history_codec.h:37
yaze::editor::AgentChatHistoryCodec::AgentConfigSnapshot::tools
ToolFlags tools
Definition
agent_chat_history_codec.h:81
yaze::editor::AgentChatHistoryCodec::Snapshot
Definition
agent_chat_history_codec.h:84
yaze::editor::AgentChatHistoryCodec::Snapshot::agent_config
std::optional< AgentConfigSnapshot > agent_config
Definition
agent_chat_history_codec.h:88
yaze::test::TestResult
Definition
test_manager.h:54
yaze::test::TestResult::status
TestStatus status
Definition
test_manager.h:58
yaze::test::TestResult::duration
std::chrono::milliseconds duration
Definition
test_manager.h:60
yaze::test::TestResult::error_message
std::string error_message
Definition
test_manager.h:59
yaze::test::TestResult::suite_name
std::string suite_name
Definition
test_manager.h:56
yaze::test::TestResult::name
std::string name
Definition
test_manager.h:55
yaze::test::TestResult::timestamp
std::chrono::time_point< std::chrono::steady_clock > timestamp
Definition
test_manager.h:61
yaze::test::TestResult::category
TestCategory category
Definition
test_manager.h:57
yaze::test::TestResults
Definition
test_manager.h:65
yaze::test::TestResults::AddResult
void AddResult(const TestResult &result)
Definition
test_manager.h:73
test_manager.h
tool_dispatcher.h
src
app
testing
agent_tools_test.h
Generated by
1.10.0