Running tests on a Windows machine over SSH with an AI agent

 
 
  • Gérald Barré

This post is part of the series 'Debugging .NET with an AI agent'. Be sure to check out the rest of the blog posts of the series!

The previous posts of this series gave the agent a dump, a debugger, or the telemetry of a running application. This one gives it something more basic: another machine.

The situation is common. You work on a Mac or on Linux, every test passes, you push, and the Windows job of the CI fails. The usual loop is to read the log, guess a fix, push again, and wait ten minutes for the next result. An agent does not make that loop faster. What makes it faster is running the tests on Windows before pushing, and that only takes an SSH server on a Windows machine.

ssh runs one command on another machine and returns its output and its exit code. For an agent, that is just another command line tool, like dotnet-dump in the first post. The whole difficulty is elsewhere: the code must be on the other machine, in the state it has now, before every run.

This post does the whole thing, step by step:

  1. prepare the Windows machine,
  2. check that the connection works without a human,
  3. run the tests on Windows once, yourself,
  4. write the script that copies the working tree and runs a command,
  5. write the skill,
  6. ask the question,
  7. follow the agent, and check what it changed.

The sample contains the library, its tests, the script and the skill. Every output below comes from it, run from macOS against a Windows 11 machine with the .NET 10 SDK.

#The library

ReportExport writes orders to CSV files, and archives them:

C#
public static class CsvReportWriter
{
    public static void Write(TextWriter writer, IEnumerable<Order> orders)
    {
        writer.WriteLine("id,customer,amount");
        foreach (var order in orders)
        {
            writer.WriteLine(string.Create(CultureInfo.InvariantCulture, $"{order.Id},{order.Customer},{order.Amount}"));
        }
    }
}

public sealed class ReportArchive(string directory)
{
    // One file per export: orders-2026-12-23T09:30:00.csv
    public static string GetFileName(DateTimeOffset exportedAt)
        => "orders-" + exportedAt.UtcDateTime.ToString("s", CultureInfo.InvariantCulture) + ".csv";

    // Moves the current export to the "sent" folder, and returns its SHA-256
    public string MarkAsSent(string path)
    {
        var sentDirectory = Path.Combine(Directory, "sent");
        System.IO.Directory.CreateDirectory(sentDirectory);

        using var stream = File.OpenRead(path);
        var hash = Convert.ToHexString(SHA256.HashData(stream));
        File.Move(path, Path.Combine(sentDirectory, Path.GetFileName(path)));
        return hash;
    }
}

It has four tests, and they all pass on macOS:

Test run summary: Passed!
  total: 4
  failed: 0
  succeeded: 4

There are three Windows bugs in this code. If you see them all by reading it, good; in a real code base they are spread over forty files, and reading is not how you find them.

#How an agent can run tests on another machine

The agent edits files here, and the tests run there. So between every edit and every run, the files have to travel. There are several ways to move them, and most of them are wrong for this job:

MethodProblem
git push, then git pullNeeds a commit for every attempt, and a remote both machines can reach
scp -rCopies bin and obj, which are useless on the other OS and heavy
rsyncNot available on Windows
A shared folderBuilds on a network drive are slow, and file locking behaves differently on it
tar over sshWorks: Windows has tar.exe since Windows 10, and git gives the list of files

The last one is one pipe. git ls-files lists the files of the working tree, including the ones that are not committed yet, and excluding what .gitignore excludes. tar packs them on stdout, ssh carries stdout to the other machine, and tar unpacks it there:

Shell
git ls-files -z --cached --others --exclude-standard \
    | tar --null -T - -cf - \
    | ssh me@windows-dev "tar -xf - -C agent-work\ReportExport"

Nothing is committed and nothing is pushed. The Windows machine receives exactly what the agent sees, at the moment of the run.

#Step 1: Prepare the Windows machine

Windows includes an OpenSSH server. It is not installed by default on client editions. In an elevated PowerShell:

PowerShell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic

Then install the tools the tests need: the .NET SDK and Git, like on any build machine.

Add your public key to the authorized keys. There is a trap here: if the account is a member of the Administrators group, sshd ignores %USERPROFILE%\.ssh\authorized_keys and reads C:\ProgramData\ssh\administrators_authorized_keys instead. That file must only be accessible to SYSTEM and Administrators, or sshd ignores it too:

PowerShell
icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"

The default shell of the SSH server is cmd.exe. It can be changed to PowerShell with the DefaultShell registry value, but this post keeps cmd.exe: it is what you get on a machine you did not configure, and the skill has to deal with it anyway.

#Step 2: Check the connection without a human

An agent cannot type a password, accept a host key, or click a prompt. Every one of these makes the command hang, or fail. So test the connection the way the agent will use it, with BatchMode, which turns every prompt into an immediate error:

Shell
ssh -o BatchMode=yes me@windows-dev "ver"
Microsoft Windows [Version 10.0.28000.2956]

Accept the host key during this manual test as well. With BatchMode, an unknown host key is an error, not a question.

#Step 3: Run the tests on Windows yourself

Before handing anything over, run the tests once by hand. The first attempt did not reach the tests:

Welcome to .NET 11.0!
---------------------
SDK Version: 11.0.100-rc.1.26425.128
...
error : Testing with VSTest target is no longer supported by Microsoft.Testing.Platform on .NET 10 SDK and later.
If you use dotnet test, you should opt-in to the new dotnet test experience.

Two problems, and neither is about the code:

  • The Windows machine has a preview of .NET 11 installed, and without a global.json the newest SDK wins. Each machine picks its own newest SDK, and two machines rarely have the same one: they do not even build with the same compiler.
  • xUnit v3 runs on Microsoft.Testing.Platform, and the .NET 10 dotnet test must be told so.

Both are fixed by a global.json at the root of the repository:

JSON
{
  "sdk": {
    "version": "10.0.300",
    "rollForward": "latestFeature"
  },
  "test": {
    "runner": "Microsoft.Testing.Platform"
  }
}

The Welcome to .NET banner is also worth removing. It appears once per SDK on a machine, it is a dozen lines of noise in the context of the model, and it disappears with DOTNET_NOLOGO=1.

The second attempt reached the tests, and gave the result to compare with the agent's later:

Test run summary: Failed!
  total: 4
  failed: 3
  succeeded: 1

This is the reason to do this step yourself every time: an agent that meets the SDK error first would fix it, and you would not know whether it fixed the machine, the repository, or the tests.

#Step 4: The script

Each run needs the same three things: copy the files, go to the copy, run the command. Leaving that to the agent means it rewrites the tar pipe every time, and gets the quoting wrong once in a while. So it is a script, next to the skill:

Shell
#!/usr/bin/env bash
set -euo pipefail

host="${WINDOWS_TEST_HOST:?Set WINDOWS_TEST_HOST to user@machine}"
root="$(git rev-parse --show-toplevel)"
remote_dir="agent-work\\$(basename "$root")"
cd "$root"

# Tracked and untracked files, without what .gitignore excludes (bin, obj, ...): the working tree as it is
# now, including the changes that are not committed. Deleted files are still in the index: skip them.
list_files() {
    git ls-files -z --cached --others --exclude-standard | while IFS= read -r -d '' file; do
        [[ -f "$file" ]] && printf '%s\0' "$file"
    done
}

# COPYFILE_DISABLE stops macOS tar from adding a ._file with the extended attributes of every file.
list_files | COPYFILE_DISABLE=1 tar --null -T - -cf - \
    | ssh -o BatchMode=yes "$host" "(if exist $remote_dir rmdir /s /q $remote_dir) && mkdir $remote_dir && tar -xf - -C $remote_dir"

# DOTNET_NOLOGO: no first-run banner in the output of the first dotnet command.
ssh -o BatchMode=yes "$host" "set DOTNET_NOLOGO=1&& set DOTNET_CLI_TELEMETRY_OPTOUT=1&& cd /d $remote_dir && $*"

Each line is there because something went wrong without it:

  • The previous copy is deleted first. Otherwise a file deleted here still exists there, and a .cs file that no longer exists keeps being compiled on Windows. It costs a restore and a full build on every run, about 15 seconds for this sample.
  • Deleted files are filtered out. git ls-files --cached lists what is in the index, and a file deleted but not yet staged is still in it. tar fails on the missing file, and the whole copy fails.
  • COPYFILE_DISABLE=1. macOS tar stores extended attributes as extra ._ files, which then appear on Windows next to every source file.
  • set DOTNET_NOLOGO=1&&, with no space before &&. In cmd.exe, set NAME=value && puts the space in the value.
  • The exit code goes through. ssh returns the exit code of the remote command, so the script fails when the tests fail, and the agent can rely on it.

The host comes from an environment variable, so the script and the skill can be committed without the name of your machine in them:

Shell
export WINDOWS_TEST_HOST=me@windows-dev
.claude/skills/testing-on-windows-over-ssh/run-on-windows.sh dotnet test

#Step 5: The skill

As in the rest of the series, the knowledge the agent lacks goes into a SKILL.md file, in .claude/skills/testing-on-windows-over-ssh/. A model knows ssh, cmd.exe and .NET very well. What it does not know is how this setup works, and which of its habits are wrong here. The skill is mostly that:

Markdown
---
name: testing-on-windows-over-ssh
description: Build and run the tests of this repository on a Windows machine over SSH, from a macOS or Linux machine, and fix the failures that only happen on Windows. Use when asked to test on Windows, when a test fails on the Windows CI but passes locally, or when a change touches file paths, file names, line endings, file sharing, processes, the registry, or anything else that behaves differently on Windows.
---

# Testing on Windows over SSH

You work on a macOS or Linux machine. A Windows machine is reachable over SSH, with the same .NET SDK. You
cannot see its screen, and you do not edit files on it: you edit the files here, copy the working tree there,
and run commands there.

## Running a command on Windows

Always go through the script. It copies the working tree, then runs the command in the copy:

    .claude/skills/testing-on-windows-over-ssh/run-on-windows.sh dotnet test

- Every call copies the files again. Never run `ssh` directly to rerun a test after an edit: the remote copy
  would still have the old code, and you would read the result of a test that did not run your change
- A run takes about 15 seconds, most of it the restore and the build. Filter the tests when you iterate on one
  failure: `dotnet test --filter-class "Namespace.ClassName"` or `dotnet test --filter-method "*Name*"`

## The remote shell is cmd.exe

- Quote with double quotes. Single quotes are not quotes in `cmd.exe`
- `&&` and `||` work, `;` does not separate commands, and `%NAME%` is a variable, even inside double quotes
- For anything longer than one command, use PowerShell: `pwsh -NoProfile -Command "..."`
...

The full skill also has a table of the usual Windows symptoms and their causes, and the rules. Three of them matter most:

  • Run the tests locally first. A failure on Windows only means something if the same test passes here.
  • One failure can hide another one. After a fix, run the tests again and read the new failures, instead of assuming the remaining ones have the same cause.
  • Never skip, disable, or add a platform condition to make a test pass. if (OperatingSystem.IsWindows()) return; is the fastest way to a green run, and a model that is asked to make the CI green will find it.

Finally, the script must be allowed to run without a confirmation, or every run stops on a prompt. That is one line in .claude/settings.json, committed with the sample:

JSON
{
  "permissions": {
    "allow": [
      "Bash(.claude/skills/testing-on-windows-over-ssh/run-on-windows.sh:*)"
    ]
  }
}

#Step 6: Ask the question

The Windows CI fails on this repository, and all the tests pass on my Mac. Run the tests on Windows and fix
what fails.

The agent is Claude Code with Claude Opus 5. The run took 28 turns and 2 minutes 44 seconds, 4 of the turns on the Windows machine.

#Step 7: Follow the agent

##Before touching anything

The agent loaded the skill, read the script and the code, and ran the tests locally:

Test run summary: Passed!
  total: 4
  failed: 0
  succeeded: 4

Then it compared the SDKs, through the script:

Shell
.claude/skills/testing-on-windows-over-ssh/run-on-windows.sh "dotnet --list-sdks && ver"
10.0.401 [C:\Program Files\dotnet\sdk]
11.0.100-rc.1.26425.128 [C:\Program Files\dotnet\sdk]

Microsoft Windows [Version 10.0.28000.2956]

The agent: "SDKs match (local 10.0.400 / remote 10.0.401, same major+band)." It had tried ssh "$WINDOWS_TEST_HOST" first, and the command was refused: a command that expands a variable needs an approval, and there was nobody to give it. Going through the script, which is allowed, was the right workaround. It copies the files for nothing, and that is now what the skill recommends.

##The first run on Windows

failed ReportExport.Tests.ReportArchiveTests.Save_WritesTheCsvFile (211ms)
  Xunit.MicrosoftTestingPlatform.XunitException: System.IO.IOException : The filename, directory name, or volume
  label syntax is incorrect. : 'C:\Users\meziantou\AppData\Local\Temp\report-export-tests\d6d5650b...\orders-2026-12-23T09:30:00.csv'.
    at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(...)
    at ReportExport.ReportArchive.Save(...) in C:\Users\meziantou\agent-work\ReportExport\src\ReportExport\ReportArchive.cs:18
failed ReportExport.Tests.CsvReportWriterTests.ToCsv_WritesHeaderAndOneLinePerOrder (216ms)
  Assert.Equal() Failure: Strings differ
                               ↓ (pos 18)
  Expected: "id,customer,amount\n1001,alice,12.5\n1002,bob,7\n"
  Actual:   "id,customer,amount\r\n1001,alice,12.5\r\n1002,bob,7\r\n"
                               ↑ (pos 18)
failed ReportExport.Tests.ReportArchiveTests.MarkAsSent_MovesTheFileToTheSentFolder (2ms)
  Xunit.MicrosoftTestingPlatform.XunitException: System.IO.IOException : The filename, directory name, or volume
  label syntax is incorrect. : '...\orders-2026-12-23T09:30:00.csv'.
    at ReportExport.ReportArchive.Save(...) in C:\Users\meziantou\agent-work\ReportExport\src\ReportExport\ReportArchive.cs:18

Test run summary: Failed!
  total: 4
  failed: 3
  succeeded: 1

Two causes for three failures:

  • The "s" format writes the time as 09:30:00, and : is not allowed in a Windows file name. Save fails, and so does every test that calls it.
  • WriteLine writes Environment.NewLine, which is \r\n on Windows, and the expected string in the test has \n, because the source file has \n line endings.

The agent: "Three failures on Windows. Fixing the two confirmed causes first (CRLF in the CSV, : in the file name)." Confirmed is the right word: MarkAsSent never reached its own code, so nothing was known about it yet.

##The failure behind the failure

After the first two fixes, the second run on Windows:

failed ReportExport.Tests.ReportArchiveTests.MarkAsSent_MovesTheFileToTheSentFolder (11ms)
  Xunit.MicrosoftTestingPlatform.XunitException: System.IO.IOException : The process cannot access the file
  because it is being used by another process.
    at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite)
    at ReportExport.ReportArchive.MarkAsSent(String path) in C:\Users\meziantou\agent-work\ReportExport\src\ReportExport\ReportArchive.cs:32

Test run summary: Failed!
  total: 4
  failed: 1
  succeeded: 3

This is the third bug, and it was invisible until Save worked. using var stream keeps the stream open until the end of the method, so the file is still open when File.Move runs. On macOS and Linux, moving an open file is allowed. On Windows, File.OpenRead opens the file with FileShare.Read only, and renaming or moving a file requires every open handle to allow FileShare.Delete.

This is what the Windows CI would have shown on the second push, after the first two fixes. Here it cost 15 seconds.

##The fixes

The agent fixed the three bugs in the product, and changed one test. The CSV writer ends every line with \n explicitly:

C#
// The file must be identical on every platform, so the lines end with "\n" everywhere:
// WriteLine would write Environment.NewLine, which is "\r\n" on Windows.
public static void Write(TextWriter writer, IEnumerable<Order> orders)
{
    writer.Write("id,customer,amount\n");
    foreach (var order in orders)
    {
        writer.Write(string.Create(CultureInfo.InvariantCulture, $"{order.Id},{order.Customer},{order.Amount}\n"));
    }
}

The file name uses - instead of : in the time:

C#
// One file per export: orders-2026-12-23T09-30-00.csv
// The time uses "-" and not ":", which is not allowed in a file name on Windows.
public static string GetFileName(DateTimeOffset exportedAt)
    => "orders-" + exportedAt.UtcDateTime.ToString("yyyy-MM-dd'T'HH-mm-ss", CultureInfo.InvariantCulture) + ".csv";

And the stream is closed before the move:

C#
// The stream must be closed before the move: Windows does not move a file that is still open.
string hash;
using (var stream = File.OpenRead(path))
{
    hash = Convert.ToHexString(SHA256.HashData(stream));
}

File.Move(path, Path.Combine(sentDirectory, Path.GetFileName(path)));
return hash;

The test change is the expected file name in GetFileName_UsesTheExportTime, which follows the product change. Then the last run on Windows, and the last run on macOS, as the skill requires:

Test run summary: Passed!
  total: 4
  failed: 0
  succeeded: 4

#Check the answer

The report quoted every failure, and the run that showed each fix working. The three fixes are correct. Two of them are also decisions, and the report presented them as facts.

The line endings. There were two possible fixes: make the test independent of the line endings, or make the product write the same bytes everywhere. The agent chose the product, with a good argument: MarkAsSent hashes the file, and "the same orders produced a different SHA-256 depending on the machine". But it also chose \n, and RFC 4180 says that CSV lines end with \r\n. A CSV consumed by Excel or by a partner does not care; one validated against the RFC does. Both answers are defensible, and neither is the agent's to pick silently.

The file name. orders-2026-12-23T09-30-00.csv is a new name on every platform. Any code that lists the archive folder with a pattern, parses the date out of the name, or looks for the files exported last week, is now broken on Linux too, where the old names were valid and still exist on disk. The agent said the name changed, and nothing about the files already in production.

Neither is a mistake in the Windows sense: the tests pass, and the code is better than it was. They are the kind of change a reviewer has to see, and the skill now has a rule for it: when a fix changes something another program can see, say so, and say what it changes for the files and the callers that already exist.

#What the agent gets wrong, and how to fix it

It tries to call ssh itself. Every command with $WINDOWS_TEST_HOST in it needs an approval, and in a session without a user, it is refused. This agent found the workaround; another one could have asked the user for the host name, or tried ssh with a guessed one.

Fix: the skill says to use the script for everything, including dotnet --list-sdks.

It would rerun a test without copying the files. ssh host "cd agent-work\ReportExport && dotnet test" is a perfectly reasonable command, and it runs the code of the previous copy. The result is real, the tests are real, and the conclusion is wrong.

Fix: the script always copies, and the skill says why in one sentence. It is the most important line of the skill.

It decides the contract. CRLF or LF, : or -: a test does not say which one is right, and the agent picks one.

Fix: rule 7, and a prompt that says what must not change ("the file names are read by another service").

It could make the CI green instead of correct. A platform condition, a skip, or a line ending normalized in the assertion, and the three tests pass. This agent did none of it, and the rule that forbids it is the reason I would trust the next run as well.

Fix: rule 4. Check the diff of the tests before the diff of the code.

#The Windows machine is a real machine

The agent gets a shell on another computer, with your account. Everything the series said about dumps and telemetry containing secrets applies, plus a few things of its own:

  • The copy includes the untracked files. --others is what makes uncommitted work testable, and it also copies the appsettings.Development.json with a real connection string that nobody added to .gitignore. Look at git status before the first run.
  • The copy stays there. %USERPROFILE%\agent-work keeps the last version of every repository you tested. On a shared machine, that is a copy of your source code in a folder you forget about.
  • The key opens more than the tests. An agent that can run dotnet test over SSH can run anything, as you, with the rights of your account. That account should be a dedicated one, on a machine or a VM that exists for this, not an administrator on your gaming PC.
  • The agent reads what the tests print. Paths, user names, machine names, and whatever the tests log, go into the context of the model.

The previous posts of this series gave the agent a better view of one process. This one gave it a second machine, and the pattern did not change: a command line tool the agent can run, a skill that says where the traps are, and a report that quotes what the tool printed. The tool here is ssh, and the trap is the one no model would guess alone: the code on the other machine is not the code you just wrote, unless something copies it every time.

#Additional resources

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?