Skip to content

Conversation

@BenWalker01
Copy link

447341769-3b0152d7-a479-4fcd-9809-110e99e71aea

Fixes #571

@kristiankunc kristiankunc requested a review from Copilot October 21, 2025 18:22

This comment was marked as outdated.

Copy link
Contributor

@kristiankunc kristiankunc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd honestly love to see at least partial test coverage on this.

@BenWalker01
Copy link
Author

I'll write some in a bit

@kristiankunc
Copy link
Contributor

The copilot comments about the files also look sensible, we can just throw an error instantly (which can be surpressed as I assume we don't want to enforce it 100%) + the rest are some nitpicks

@kristiankunc kristiankunc changed the title Fixs #571 - Notify Users about out of date pack Fixes #571 - Notify Users about out of date pack Oct 27, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +102
#include "filestatus/FileStatusModule.h"
#include "bootstrap/PersistenceContainer.h"
#include "curl/CurlInterface.h"
#include "curl/CurlRequest.h"
#include "curl/CurlResponse.h"

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <fstream>
#include <filesystem>

using ::testing::NiceMock;
using ::testing::Return;
using ::testing::Test;

namespace UKControllerPluginTest {
namespace FileStatus {

// Mock Curl interface
class MockCurlInterface : public UKControllerPlugin::Curl::CurlInterface
{
public:
MOCK_METHOD(
UKControllerPlugin::Curl::CurlResponse,
MakeCurlRequest,
(const UKControllerPlugin::Curl::CurlRequest& request),
(override));
};

class FileStatusModuleTest : public Test
{
protected:
virtual void SetUp()
{
// Create temp directory for test files
testDir = std::filesystem::temp_directory_path() / "filestatus_test";
std::filesystem::create_directories(testDir);
}

virtual void TearDown()
{
// Clean up temp files
if (std::filesystem::exists(testDir)) {
std::filesystem::remove_all(testDir);
}
if (std::filesystem::exists("./UK")) {
std::filesystem::remove_all("./UK");
}
}

std::filesystem::path testDir;
};

// Test FetchPackVersion with successful response
TEST_F(FileStatusModuleTest, FetchPackVersionReturnsVersionOnSuccess)
{
NiceMock<MockCurlInterface> mockCurl;
UKControllerPlugin::Curl::CurlResponse response("abc123def456", false, 200);

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "abc123def456");
}

// Test FetchPackVersion with whitespace trimming
TEST_F(FileStatusModuleTest, FetchPackVersionTrimsWhitespace)
{
NiceMock<MockCurlInterface> mockCurl;
UKControllerPlugin::Curl::CurlResponse response(" abc123def456 \n\t", false, 200);

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "abc123def456");
}

// Test FetchPackVersion with non-200 status code
TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnBadStatusCode)
{
NiceMock<MockCurlInterface> mockCurl;
UKControllerPlugin::Curl::CurlResponse response("Not Found", false, 404);

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "");
}

// Test FetchPackVersion with exception
TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnException)
{
NiceMock<MockCurlInterface> mockCurl;

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(::testing::Throw(std::runtime_error("Network error")));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "");
}

} // namespace FileStatus
} // namespace UKControllerPluginTest No newline at end of file
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage for CheckSectorFileProviderFile function. This function contains complex logic for parsing the sector file provider configuration and URL extraction that should be tested, especially the edge case where the line is exactly "URL:" without any actual URL content.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +102
#include "filestatus/FileStatusModule.h"
#include "bootstrap/PersistenceContainer.h"
#include "curl/CurlInterface.h"
#include "curl/CurlRequest.h"
#include "curl/CurlResponse.h"

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <fstream>
#include <filesystem>

using ::testing::NiceMock;
using ::testing::Return;
using ::testing::Test;

namespace UKControllerPluginTest {
namespace FileStatus {

// Mock Curl interface
class MockCurlInterface : public UKControllerPlugin::Curl::CurlInterface
{
public:
MOCK_METHOD(
UKControllerPlugin::Curl::CurlResponse,
MakeCurlRequest,
(const UKControllerPlugin::Curl::CurlRequest& request),
(override));
};

class FileStatusModuleTest : public Test
{
protected:
virtual void SetUp()
{
// Create temp directory for test files
testDir = std::filesystem::temp_directory_path() / "filestatus_test";
std::filesystem::create_directories(testDir);
}

virtual void TearDown()
{
// Clean up temp files
if (std::filesystem::exists(testDir)) {
std::filesystem::remove_all(testDir);
}
if (std::filesystem::exists("./UK")) {
std::filesystem::remove_all("./UK");
}
}

std::filesystem::path testDir;
};

// Test FetchPackVersion with successful response
TEST_F(FileStatusModuleTest, FetchPackVersionReturnsVersionOnSuccess)
{
NiceMock<MockCurlInterface> mockCurl;
UKControllerPlugin::Curl::CurlResponse response("abc123def456", false, 200);

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "abc123def456");
}

// Test FetchPackVersion with whitespace trimming
TEST_F(FileStatusModuleTest, FetchPackVersionTrimsWhitespace)
{
NiceMock<MockCurlInterface> mockCurl;
UKControllerPlugin::Curl::CurlResponse response(" abc123def456 \n\t", false, 200);

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "abc123def456");
}

// Test FetchPackVersion with non-200 status code
TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnBadStatusCode)
{
NiceMock<MockCurlInterface> mockCurl;
UKControllerPlugin::Curl::CurlResponse response("Not Found", false, 404);

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(Return(response));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "");
}

// Test FetchPackVersion with exception
TEST_F(FileStatusModuleTest, FetchPackVersionReturnsEmptyOnException)
{
NiceMock<MockCurlInterface> mockCurl;

EXPECT_CALL(mockCurl, MakeCurlRequest).WillOnce(::testing::Throw(std::runtime_error("Network error")));

std::string result = UKControllerPlugin::FileStatus::FetchPackVersion(mockCurl);
EXPECT_EQ(result, "");
}

} // namespace FileStatus
} // namespace UKControllerPluginTest No newline at end of file
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage for CheckPackVersion function. The test file only covers FetchPackVersion, but CheckPackVersion contains critical logic including file reading, version comparison, and message box display that should be tested.

Copilot uses AI. Check for mistakes.
}

} catch (const std::exception& e) {
LogError("Exception when checking UK Controller Pack version");
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message lacks detail about what exception occurred. It should include the exception message using e.what() to aid in debugging, similar to the error handling in FetchPackVersion on line 42.

Suggested change
LogError("Exception when checking UK Controller Pack version");
LogError("Exception when checking UK Controller Pack version: " + std::string(e.what()));

Copilot uses AI. Check for mistakes.
LogError("Could not find URL in sector file provider");
}

if (extractedUrl != SECTOR_FILE_DOWNLOADER_LINK) {
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison should trim whitespace from extractedUrl before comparing it to SECTOR_FILE_DOWNLOADER_LINK. The current implementation will fail if the URL in the file has leading/trailing whitespace, even though it may be functionally correct.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UK Controller Pack Outdated Notification

2 participants