Skip to content

Commit

Permalink
ora: update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Palaniappan R <[email protected]>
  • Loading branch information
palaniappan-r committed Jan 16, 2025
1 parent 642ec40 commit 1b60fc4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 32 deletions.
40 changes: 20 additions & 20 deletions src/ora/src/Ora.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void Ora::init(Tcl_Interp* tcl_interp, odb::dbDatabase* db, utl::Logger* logger)
}
} catch (const std::exception& e) {
logger_->warn(utl::ORA,
122,
101,
"Failed to read ORAssistant local host. Exception: {}",
e.what());
}
Expand All @@ -158,12 +158,12 @@ void Ora::checkLocalDir()
std::ifstream localDir(localDirPath);

if (!localDir) {
logger_->info(utl::ORA, 112, "Creating ~/.local/share/openroad directory.");
logger_->info(utl::ORA, 102, "Creating ~/.local/share/openroad directory.");
try {
std::filesystem::create_directories(localDirPath);
} catch (const std::exception& e) {
logger_->warn(
utl::ORA, 113, "Failed to create ~/.local/share/openroad directory.");
utl::ORA, 103, "Failed to create ~/.local/share/openroad directory.");
}
}
}
Expand All @@ -173,7 +173,7 @@ void Ora::askbot(const char* query)
if (!checkConsent()) {
logger_->warn(
utl::ORA,
197,
104,
"To use the ORAssistant, please provide consent by running the "
"`ora_init {consent} {hostURL}` command."
"Only the query you type in will be sent outside the application—no "
Expand All @@ -195,7 +195,7 @@ void Ora::askbot(const char* query)
hostUrl = localHostUrl;
}

logger_->info(utl::ORA, 101, "Sending POST request to {}", hostUrl);
logger_->info(utl::ORA, 105, "Sending POST request to {}", hostUrl);

std::stringstream jsonDataStream;
jsonDataStream << R"({
Expand All @@ -210,7 +210,7 @@ void Ora::askbot(const char* query)
std::string postResponse = sendPostRequest(hostUrl, jsonData);

if (postResponse.empty()) {
logger_->warn(utl::ORA, 102, "No response received from API.");
logger_->warn(utl::ORA, 106, "No response received from API.");
return;
}

Expand All @@ -229,24 +229,24 @@ void Ora::askbot(const char* query)
sources += "\n";
}
logger_->info(utl::ORA,
103,
107,
"ORAssistant Response: \n\n{}\nSources:\n{}",
response,
sources);
} else {
logger_->info(
utl::ORA, 104, "ORAssistant Response: \n\n{}\n", response);
utl::ORA, 108, "ORAssistant Response: \n\n{}\n", response);
}
} else {
logger_->warn(utl::ORA,
106,
109,
"API response does not contain 'response' field or it is "
"not a string.");
logger_->warn(utl::ORA, 107, "API response: {}", postResponse);
logger_->warn(utl::ORA, 110, "API response: {}", postResponse);
}
} catch (const boost::json::system_error& e) {
logger_->warn(utl::ORA,
105,
111,
"JSON Parsing Error: {}\nPlease check if you have access to "
"ORAssistant's API.",
e.what());
Expand All @@ -260,8 +260,8 @@ void Ora::setSourceFlag(bool sourceFlag)

void Ora::setBotHost(const char* host)
{
localHostUrl = host;
logger_->info(utl::ORA, 116, "Setting ORAssistant host to {}", hostUrl);
hostUrl = host;
logger_->info(utl::ORA, 112, "Setting ORAssistant host to {}", localHostUrl);

checkLocalDir();
std::string hostFilePath = localDirPath + "/orassistant_host.txt";
Expand All @@ -271,11 +271,11 @@ void Ora::setBotHost(const char* host)
hostUrlFile << hostUrl;
hostUrlFile.close();
logger_->info(utl::ORA,
109,
113,
"ORAssistant host saved to "
"~/.local/share/openroad/orassistant_host.txt");
} else {
logger_->warn(utl::ORA, 108, "Failed to write ORAssistant host to file.");
logger_->warn(utl::ORA, 114, "Failed to write ORAssistant host to file.");
}
}

Expand All @@ -288,7 +288,7 @@ void Ora::setConsent(const char* consent)
// check if consent is y or n
if (std::string(consent) != "y" && std::string(consent) != "n") {
logger_->error(
utl::ORA, 117, "{} : Invalid consent value. Use 'y' or 'n'.", consent);
utl::ORA, 115, "{} : Invalid consent value. Use 'y' or 'n'.", consent);
return;
}

Expand All @@ -297,23 +297,23 @@ void Ora::setConsent(const char* consent)
consentFile.close();
logger_->info(
utl::ORA,
114,
116,
"Consent saved to ~/.local/share/openroad/orassistant_consent.txt");
} else {
logger_->warn(utl::ORA, 115, "Failed to write consent to file.");
logger_->warn(utl::ORA, 117, "Failed to write consent to file.");
}

if (std::string(consent) == "y") {
cloudConsent_ = true;
logger_->info(utl::ORA,
198,
118,
"{}\nConsent granted for using a cloud hosted ORAssistant. "
"Please run `ora_init n` to remove your consent.",
consentMessage);
} else if (std::string(consent) == "n") {
cloudConsent_ = false;
logger_->info(
utl::ORA, 199, "Consent removed for using a cloud hosted ORAssistant.");
utl::ORA, 119, "Consent removed for using a cloud hosted ORAssistant.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ora/test/askbot1.ok
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[INFO ORA-0101] Sending POST request to http://0.0.0.0:8080/mock
[INFO ORA-0104] ORAssistant Response:
[INFO ORA-0105] Sending POST request to http://0.0.0.0:8080/mock
[INFO ORA-0108] ORAssistant Response:

Sent Message: testmsg

7 changes: 7 additions & 0 deletions src/ora/test/ora_init1.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Setting ORAssistant consent to n
[INFO ORA-0102] Creating ~/.local/share/openroad directory.
[INFO ORA-0116] Consent saved to ~/.local/share/openroad/orassistant_consent.txt
[INFO ORA-0119] Consent removed for using a cloud hosted ORAssistant.
Setting ORAssistant host to http://0.0.0.0:8080/mock
[INFO ORA-0112] Setting ORAssistant host to
[INFO ORA-0113] ORAssistant host saved to ~/.local/share/openroad/orassistant_host.txt
1 change: 1 addition & 0 deletions src/ora/test/ora_init1.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ora_init n "http://0.0.0.0:8080/mock"
3 changes: 1 addition & 2 deletions src/ora/test/regression_tests.tcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
record_tests {
set_bothost1
set_consent1
ora_init1
askbot1
}
4 changes: 0 additions & 4 deletions src/ora/test/set_bothost1.ok

This file was deleted.

1 change: 0 additions & 1 deletion src/ora/test/set_bothost1.tcl

This file was deleted.

2 changes: 0 additions & 2 deletions src/ora/test/set_consent1.ok

This file was deleted.

1 change: 0 additions & 1 deletion src/ora/test/set_consent1.tcl

This file was deleted.

0 comments on commit 1b60fc4

Please sign in to comment.