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/test/test_manager.h
"
6
#include "
app/editor/agent/agent_chat_history_codec.h
"
7
#include "
app/editor/agent/agent_state.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 = std::filesystem::temp_directory_path() /
"yaze_test_config.json"
;
82
auto
save_status =
yaze::editor::AgentChatHistoryCodec::Save
(temp_path, snapshot);
83
84
if
(!save_status.ok()) {
85
result.
status
=
TestStatus::kFailed
;
86
result.
error_message
=
"Save failed: "
+ std::string(save_status.message());
87
}
else
{
88
// Load back
89
auto
load_result =
yaze::editor::AgentChatHistoryCodec::Load
(temp_path);
90
if
(load_result.ok()) {
91
if
(load_result->agent_config.has_value() &&
92
load_result->agent_config->tools.memory_inspector ==
true
) {
93
94
// Now test false
95
snapshot.
agent_config
->tools.memory_inspector =
false
;
96
yaze::editor::AgentChatHistoryCodec::Save
(temp_path, snapshot);
97
auto
load_result2 =
yaze::editor::AgentChatHistoryCodec::Load
(temp_path);
98
99
if
(load_result2.ok() &&
100
load_result2->agent_config.has_value() &&
101
load_result2->agent_config->tools.memory_inspector ==
false
) {
102
result.
status
=
TestStatus::kPassed
;
103
}
else
{
104
result.
status
=
TestStatus::kFailed
;
105
result.
error_message
=
"Failed to persist memory_inspector=false"
;
106
}
107
}
else
{
108
result.
status
=
TestStatus::kFailed
;
109
result.
error_message
=
"Failed to persist memory_inspector=true"
;
110
}
111
}
else
{
112
result.
status
=
TestStatus::kFailed
;
113
result.
error_message
=
"Load failed: "
+ std::string(load_result.status().message());
114
}
115
}
116
// Cleanup
117
std::error_code ec;
118
std::filesystem::remove(temp_path, ec);
119
#else
120
result.
status
=
TestStatus::kSkipped
;
121
result.
error_message
=
"JSON support disabled"
;
122
#endif
123
124
auto
end_time = std::chrono::steady_clock::now();
125
result.
duration
= std::chrono::duration_cast<std::chrono::milliseconds>(
126
end_time - start_time);
127
results.
AddResult
(result);
128
}
129
};
130
131
// Register the AgentToolsTestSuite with the TestManager.
132
void
RegisterAgentToolsTestSuite
();
133
134
}
// namespace test
135
}
// namespace yaze
136
137
#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:27
yaze::cli::agent::ToolDispatcher::ToolPreferences::memory_inspector
bool memory_inspector
Definition
tool_dispatcher.h:43
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
test
agent_tools_test.h
Generated by
1.10.0