diff --git a/.github/workflows/rpc-response-id-correlation.yml b/.github/workflows/rpc-response-id-correlation.yml new file mode 100644 index 00000000..3941e110 --- /dev/null +++ b/.github/workflows/rpc-response-id-correlation.yml @@ -0,0 +1,51 @@ +name: RPC response ID correlation + +on: + pull_request: + paths: + - 'experiments/Apply-RpcResponseIdFix.ps1' + - '.github/workflows/rpc-response-id-correlation.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + verify: + strategy: + fail-fast: false + matrix: + include: + - name: x64-server2025 + runner: windows-2025 + arch: x64 + - name: arm64-win11 + runner: windows-11-vs2026-arm + arch: ARM64 + name: ${{ matrix.name }} + runs-on: ${{ matrix.runner }} + timeout-minutes: 20 + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + - name: Apply fail-closed correlation fix + shell: pwsh + run: | + ./experiments/Apply-RpcResponseIdFix.ps1 + git diff --check + if ($LASTEXITCODE -ne 0) { throw 'Correlation candidate introduced whitespace errors.' } + - name: Configure + shell: pwsh + run: | + cmake -S source -B build -A '${{ matrix.arch }}' -DWININSPECT_BUILD_TESTS=ON -DWININSPECT_USE_OPENSSL=OFF + if ($LASTEXITCODE -ne 0) { throw 'Configure failed.' } + - name: Build focused correlation test + shell: pwsh + run: | + cmake --build build --config Release --target test_response_id --parallel 2 + if ($LASTEXITCODE -ne 0) { throw 'Response-id test build failed.' } + - name: Verify handler-return correlation + shell: pwsh + run: | + & ./build/Release/test_response_id.exe + if ($LASTEXITCODE -ne 0) { throw 'RPC response ID was not preserved.' } diff --git a/experiments/Apply-RpcResponseIdFix.ps1 b/experiments/Apply-RpcResponseIdFix.ps1 new file mode 100644 index 00000000..cb87c5e6 --- /dev/null +++ b/experiments/Apply-RpcResponseIdFix.ps1 @@ -0,0 +1,71 @@ +$ErrorActionPreference = 'Stop' + +function Replace-Exactly { + param([string]$Path,[string]$Old,[string]$New) + $text = [IO.File]::ReadAllText($Path).Replace("`r`n", "`n") + $oldNorm = $Old.Replace("`r`n", "`n") + $newNorm = $New.Replace("`r`n", "`n") + $first = $text.IndexOf($oldNorm,[StringComparison]::Ordinal) + if ($first -lt 0) { throw "Expected response-id block not found in $Path" } + if ($text.IndexOf($oldNorm,$first + $oldNorm.Length,[StringComparison]::Ordinal) -ge 0) { throw "Response-id block is not unique in $Path" } + $updated = $text.Substring(0,$first) + $newNorm + $text.Substring($first + $oldNorm.Length) + [IO.File]::WriteAllText($Path,$updated,[Text.UTF8Encoding]::new($false)) +} + +$core = 'source/core/src/core.cpp' +Replace-Exactly $core @' + after_dispatch: + auto end_time = std::chrono::steady_clock::now(); +'@ @' + after_dispatch: + // Every protocol response is correlated to the request even when a dispatch + // handler constructs and returns a fresh CoreResponse. + resp.id = req.id; + auto end_time = std::chrono::steady_clock::now(); +'@ + +New-Item -ItemType Directory -Force -Path source/tests | Out-Null +$test = @' +#include "wininspect/core.hpp" +#include "wininspect/fake_backend.hpp" +#include + +int main() +{ + using namespace wininspect; + FakeBackend backend({}); + CoreEngine core(&backend); + CoreRequest req; + req.id = "correlation-sentinel"; + req.method = "daemon.metrics"; + req.params = json::Object{}; + auto snapshot = backend.capture_snapshot(); + auto resp = core.handle(req, snapshot, nullptr); + if (!resp.ok) { + std::cerr << "daemon.metrics unexpectedly failed\n"; + return 1; + } + if (resp.id != req.id) { + std::cerr << "response id mismatch: expected '" << req.id << "', got '" << resp.id << "'\n"; + return 2; + } + return 0; +} +'@ +[IO.File]::WriteAllText('source/tests/test_response_id.cpp',$test.Replace("`r`n","`n"),[Text.UTF8Encoding]::new($false)) + +$cmake = 'source/CMakeLists.txt' +Replace-Exactly $cmake @' + add_executable(test_discovery +'@ @' + add_executable(test_response_id + tests/test_response_id.cpp + ) + target_include_directories(test_response_id PRIVATE core/include third_party) + target_link_libraries(test_response_id PRIVATE wininspect_core) + add_test(NAME test_response_id COMMAND test_response_id WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + + add_executable(test_discovery +'@ + +Write-Host 'RPC response-id correlation candidate applied.'