microsoft / microsoft/vscode

agentHost: three CopilotAgent tests fail when COPILOT_HOME is set

Open
#335,887 1 comment 0 reactions 1 assignee Claimed by @meganrogge View on GitHub
triage-needed
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Type: Bug

VS Code Version: built from source, `main` at `186b59be7f75`
OS Version: Windows 11 x64

### Summary

Three tests in `copilotAgent.test.ts` fail when `COPILOT_HOME` is set. CI never sets it, so CI stays green.

Found while working on #334849.

### Steps to Reproduce

1. `set COPILOT_HOME=%USERPROFILE%\.copilot`
2. `.\scripts\test.bat --runGlob "**/agentHost/test/node/copilotAgent.test.js"`
3. Unset it and run again.

### Actual Behaviour

381 passing, 3 failing:

| Test | Line |
| --- | --- |
| `resolves state files from the default and peer chat SDK backings` | 1323 |
| `a marker written after an initial read miss is picked up without a restart` | 8549 |
| `collectDebugLogs includes persisted events for a closed session` | 11419 |

```
- "defaultChat": "[undefined]"
+ "defaultChat": "file:///home/test/.copilot/session-state/sdk-conversation-id/events.jsonl"
```

The tests inject `userHome: URI.file('/home/test')`, but `copilotHome.ts:10` prefers the ambient value:

```ts
return environment['COPILOT_HOME'] || join(userHomePath, '.copilot');
```

Callers pass the real `process.env` (`copilotAgent.ts:2661`, `3516`, `3548`), so the path leaves the in-memory filesystem, `exists()` fails, and the lookup returns `undefined`.

### Expected Behaviour

384 passing, 0 failing, whatever the environment has set.

### Notes

The same hazard is already handled in three other places, so only these tests are missing the guard:

| Location | Guard |
| --- | --- |
| `copilotAgent.test.ts:7576` | Saves, deletes and restores `COPILOT_HOME` — one test |
| `copilotAgentSession.test.ts` | Same, six places |
| `providerTestEnvironment.ts:17` | Pins `COPILOT_HOME` for the E2E harness |

Moving the guard to a suite-level `setup`/`teardown` would cover all 41 `writeExtensionHostMarker` call sites instead of three.

Not a flake — deterministic in both directions.

### Impact

Three failures on a clean checkout for anyone with `COPILOT_HOME` set: users who relocate the Copilot home (#314806, #331073), and anyone running the tests from a Copilot CLI session, which sets it at process scope.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.