Skip to content

Adding tests - #212

Merged
nefarius merged 8 commits into
masterfrom
tests
May 13, 2026
Merged

nefarius merged 8 commits into
masterfrom
tests

Conversation

@nefarius

@nefarius nefarius commented May 10, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Reusable CLI parsing module exposing public parsing helpers.
    • Shared IOCTL contract centralizing driver/user-mode IOCTL definitions.
  • Tests

    • Unit tests added for CLI parsing and IOCTL contract.
    • CI/build now acquires GoogleTest and runs unit tests on Windows x64.
  • Chores

    • Added a Tests project to the solution and updated include paths and IDE project views.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 10, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 57657b5b-f848-4cdf-ba2d-38fec522a2b9

📥 Commits

Reviewing files that changed from the base of the PR and between 662834d and 01d93a2.

📒 Files selected for processing (1)
  • build/Build.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • build/Build.cs

📝 Walkthrough

Walkthrough

Adds Shared/HidHideIoctlContract.h and a reusable HidHide::CliParsing module, refactors code to use the shared IOCTL and parsing APIs, introduces a GoogleTest C++ test project that compiles CLI and IOCTL tests, and updates solution and build scripts to include Shared and run unit tests in CI.

Changes

Testing Infrastructure and Contract Extraction

Layer / File(s) Summary
IOCTL Contract Definition
Shared/HidHideIoctlContract.h
New shared header defines device type (32769) and IOCTL control code macros for whitelist, blacklist, active, inverse, and session blacklist operations; supports kernel-mode (wdm.h) and user-mode (winioctl.h).
CLI Parsing Interface
HidHideCLI/src/CliParsing.h
New header declares Args alias and functions (Trim, ExtractKeyword, ExtractString, ExtractCommand, ExtractCommands) for tokenization and command parsing.
CLI Parsing Implementation
HidHideCLI/src/CliParsing.cpp
Implements trimming, keyword/quoted-string extraction, single-command parsing (optional -- prefix stripping), and repeated command parsing.
CommandInterpreter Delegation
HidHideCLI/src/CommandInterpreter.cpp
CommandInterpreter now includes CliParsing.h and delegates local parsing wrapper functions to HidHide::CliParsing.
FilterDriverProxy IOCTL Adoption
HidHideCLI/src/FilterDriverProxy.cpp
Remove file-local IOCTL constants, include HidHideIoctlContract.h, and update DeviceIoControl calls to use static_cast<DWORD>(IOCTL_*).
Logic Header Update
HidHide/src/Logic.h
Replace in-header IOCTL macro definitions with an #include "HidHideIoctlContract.h".
Project Include Paths & Compile Items
HidHide/HidHide.vcxproj, HidHideCLI/HidHideCLI.vcxproj, HidHideClient/HidHideClient.vcxproj
Add $(SolutionDir)Shared to AdditionalIncludeDirectories across configurations; add src\CliParsing.cpp to CLI project and set PrecompiledHeader to NotUsing.
Project Filters
HidHide.Tests/HidHide.Tests.vcxproj.filters, HidHideCLI/HidHideCLI.vcxproj.filters
Add Visual Studio filters mapping CLI parsing and test sources into "Source Files" and "Header Files".
Test Project Configuration
HidHide.Tests/HidHide.Tests.vcxproj
New C++ test project for x64 and ARM64 (Debug/Release/Production Release); compiles test sources and CliParsing.cpp, imports GoogleTest MSBuild targets and ARM64-specific libs/includes; includes a pre-build check for the pinned GoogleTest targets file.
Unit Tests
HidHide.Tests/cli_parsing_tests.cpp, HidHide.Tests/ioctl_contract_tests.cpp
GoogleTest cases validate CLI parsing (keyword/string/command/edge cases) and assert IOCTL constants match golden ABI control-code values.
Solution & Build Integration
HidHide.sln, build/Build.cs
Add HidHide.Tests to solution under Tests folder with configuration mappings; build/Build.cs ensures GoogleTest NuGet package availability, adds UnitTest target that runs HidHide.Tests.exe on Windows x64, and makes Ci depend on UnitTest.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐇 Hopping through contracts and tests so neat,
Shared headers tidy every duplicate feat,
Parsers nibble tokens, quotes unwind,
Tests hum the ABI into line,
CI winks — green lights repeat.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title 'Adding tests' is vague and generic; it does not specify what tests are being added or what functionality they cover. Provide a more descriptive title that specifies the test coverage, such as 'Add CLI parsing and IOCTL contract tests' or 'Add unit tests for CLI parsing and IOCTL ABI validation'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
build/Build.cs (1)

290-292: ⚡ Quick win

Add retry/backoff around GoogleTest package download.

At line 291, a single transient HTTP failure will fail the whole restore. A small bounded retry loop with exponential backoff materially improves CI reliability.

🔧 Proposed refactor
-        using var http = new HttpClient();
-        File.WriteAllBytes(tempZip, http.GetByteArrayAsync(url).GetAwaiter().GetResult());
+        using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
+        byte[] payload = Array.Empty<byte>();
+        Exception? last = null;
+        for (var attempt = 1; attempt <= 3; attempt++)
+        {
+            try
+            {
+                payload = http.GetByteArrayAsync(url).GetAwaiter().GetResult();
+                last = null;
+                break;
+            }
+            catch (Exception ex) when (attempt < 3)
+            {
+                last = ex;
+                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(attempt * 2));
+            }
+        }
+        if (last != null) throw last;
+        File.WriteAllBytes(tempZip, payload);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build/Build.cs` around lines 290 - 292, Replace the single synchronous
download call (using HttpClient and GetByteArrayAsync then File.WriteAllBytes
with tempZip) with a bounded retry loop that catches transient failures
(HttpRequestException, TaskCanceledException and other network errors), retries
e.g., 3 attempts with exponential backoff and small jitter (e.g., 200ms *
2^attempt + jitter) between attempts, and only throws after the final failed
attempt; ensure the HttpClient is disposed correctly and that the successful
response bytes are written to tempZip via File.WriteAllBytes after a successful
download (keep the same tempZip, HttpClient and GetByteArrayAsync symbols to
locate the code).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@HidHide.Tests/HidHide.Tests.vcxproj`:
- Around line 222-223: The Import for the Microsoft.googletest...targets is
currently wrapped in an Exists condition and silently skips when missing; add an
explicit pre-build check that fails fast with a clear error when that targets
file is absent. Implement a target (e.g., CheckGoogleTestTargets) that runs
BeforeTargets="Build" and uses the same Exists(...) path but emits an MSBuild
<Error> with a message referencing the missing Google.Test package and the
required targets file so the build stops immediately rather than later failing
on missing gtest/gtest.h; reference the existing Import target name/identifier
from the diff when locating where to add this check.

In `@HidHideCLI/HidHideCLI.vcxproj`:
- Line 168: In the AdditionalIncludeDirectories XML entries the MSBuild variable
is mistyped as (SolutionDir)HidHide\src; update each occurrence of the token
"(SolutionDir)HidHide\src" to "$(SolutionDir)HidHide\src" so the variable
expands correctly (these appear in the AdditionalIncludeDirectories elements
such as the one shown and its other repeated entries).

In `@HidHideCLI/src/CliParsing.cpp`:
- Line 14: Replace narrow-character classification with wide-character
classification: add `#include` <cwctype> and change the lambdas that call
std::isspace to use std::iswspace instead (e.g., in the value trimming call
inside ExtractValue, the similar lambda inside ExtractKeyword, and the one in
ExtractString). Update each occurrence of std::isspace(character) to
std::iswspace(character) to correctly handle wchar_t inputs and ensure the
proper header is included.

---

Nitpick comments:
In `@build/Build.cs`:
- Around line 290-292: Replace the single synchronous download call (using
HttpClient and GetByteArrayAsync then File.WriteAllBytes with tempZip) with a
bounded retry loop that catches transient failures (HttpRequestException,
TaskCanceledException and other network errors), retries e.g., 3 attempts with
exponential backoff and small jitter (e.g., 200ms * 2^attempt + jitter) between
attempts, and only throws after the final failed attempt; ensure the HttpClient
is disposed correctly and that the successful response bytes are written to
tempZip via File.WriteAllBytes after a successful download (keep the same
tempZip, HttpClient and GetByteArrayAsync symbols to locate the code).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 07d8a432-d920-40d9-8e28-ccc81f0a1b2c

📥 Commits

Reviewing files that changed from the base of the PR and between a2bf28b and 3a0ec41.

📒 Files selected for processing (15)
  • HidHide.Tests/HidHide.Tests.vcxproj
  • HidHide.Tests/HidHide.Tests.vcxproj.filters
  • HidHide.Tests/cli_parsing_tests.cpp
  • HidHide.Tests/ioctl_contract_tests.cpp
  • HidHide.sln
  • HidHide/HidHide.vcxproj
  • HidHide/src/Logic.h
  • HidHideCLI/HidHideCLI.vcxproj
  • HidHideCLI/HidHideCLI.vcxproj.filters
  • HidHideCLI/src/CliParsing.cpp
  • HidHideCLI/src/CliParsing.h
  • HidHideCLI/src/CommandInterpreter.cpp
  • HidHideCLI/src/FilterDriverProxy.cpp
  • Shared/HidHideIoctlContract.h
  • build/Build.cs

Comment thread HidHide.Tests/HidHide.Tests.vcxproj Resolved
Comment thread HidHideCLI/HidHideCLI.vcxproj Resolved
Comment thread HidHideCLI/src/CliParsing.cpp Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
build/Build.cs (1)

293-313: ⚡ Quick win

Preserve the last download exception for actionable CI failures.

After retries, the thrown InvalidOperationException loses the underlying network/root-cause details, which makes incident triage slower.

Proposed patch
         const int maxAttempts = 3;
         byte[]? payload = null;
+        Exception? lastDownloadError = null;
         for (var attempt = 0; attempt < maxAttempts; attempt++)
         {
             try
             {
                 using var http = new HttpClient();
                 payload = http.GetByteArrayAsync(url).GetAwaiter().GetResult();
                 break;
             }
             catch (Exception ex) when (attempt < maxAttempts - 1 && IsTransientNuGetDownloadFailure(ex))
             {
+                lastDownloadError = ex;
                 var jitter = Random.Shared.Next(0, 101);
                 var delayMs = 200 * (1 << attempt) + jitter;
                 Thread.Sleep(delayMs);
             }
+            catch (Exception ex)
+            {
+                lastDownloadError = ex;
+                break;
+            }
         }

         if (payload == null)
-            throw new InvalidOperationException($"Failed to download Google Test NuGet package after {maxAttempts} attempts from {url}");
+            throw new InvalidOperationException(
+                $"Failed to download Google Test NuGet package after {maxAttempts} attempts from {url}",
+                lastDownloadError);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build/Build.cs` around lines 293 - 313, The retry loop for downloading the
Google Test NuGet package currently discards the last exception, so modify the
code around the for-loop (which uses maxAttempts, payload, attempt,
IsTransientNuGetDownloadFailure and url) to capture the last caught Exception
(e.g., store it in a local Exception? lastException inside the catch) and after
the loop, when payload == null throw the InvalidOperationException including
that captured exception as the innerException (or include its message in the
thrown message) so CI logs retain the original network/root-cause details for
triage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@build/Build.cs`:
- Around line 293-313: The retry loop for downloading the Google Test NuGet
package currently discards the last exception, so modify the code around the
for-loop (which uses maxAttempts, payload, attempt,
IsTransientNuGetDownloadFailure and url) to capture the last caught Exception
(e.g., store it in a local Exception? lastException inside the catch) and after
the loop, when payload == null throw the InvalidOperationException including
that captured exception as the innerException (or include its message in the
thrown message) so CI logs retain the original network/root-cause details for
triage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c06cc240-286a-429e-aafd-b3f7ea65e030

📥 Commits

Reviewing files that changed from the base of the PR and between 59bc755 and 8553490.

📒 Files selected for processing (4)
  • HidHide.Tests/HidHide.Tests.vcxproj
  • HidHideCLI/HidHideCLI.vcxproj
  • HidHideCLI/src/CliParsing.cpp
  • build/Build.cs
🚧 Files skipped from review as they are similar to previous changes (3)
  • HidHideCLI/HidHideCLI.vcxproj
  • HidHide.Tests/HidHide.Tests.vcxproj
  • HidHideCLI/src/CliParsing.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build/Build.cs`:
- Around line 277-327: The EnsureGoogleTestNuGetPackage method currently writes
and extracts remote bytes (tempZip/payload) without integrity checks; add a
verification step before extraction: perform an HTTP HEAD to the same url to
read the Content-MD5 (or Content-MD5 base64/Content-MD5-like header) and compare
it to the downloaded payload (payload) after GetByteArrayAsync and before
File.WriteAllBytes, retrying/failing with lastException if mismatch, or
alternatively after extracting tempZip run a CLI verification using "dotnet
nuget verify" (or "nuget verify") against tempZip and throw an
InvalidOperationException if verification fails; keep this logic inside
EnsureGoogleTestNuGetPackage so marker/temp cleanup/error messages remain
consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e70af688-04e5-4ae1-9976-99dc4b75d22f

📥 Commits

Reviewing files that changed from the base of the PR and between 8553490 and 7c50812.

📒 Files selected for processing (1)
  • build/Build.cs

Comment thread build/Build.cs Resolved
@nefarius
nefarius merged commit 725c58a into master May 13, 2026
2 checks passed
@nefarius
nefarius deleted the tests branch May 13, 2026 18:13
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.

1 participant