Files
software-mansion__argent/packages/tool-server/test/temp-home.test.ts
Ignacy Łątka 3e5f198326 test(tool-server): scope the home the external-device suites discover against (#1093)
Fixes #1072

**Cause** - `external-devices.test.ts` deletes both
`ARGENT_DISABLE_DEVICE_PROVIDERS` and `ARGENT_DEVICE_PROVIDERS` in its
`beforeEach`, so any test that writes no descriptor of its own has
`discoverProviders()` read the developer's real `~/.argent/providers`.

**Fix** - call `scopeTempHome()` at file top level, so that fallback is
a fresh, run-owned directory. `external-attach.test.ts` has the
identical hook and gets the same guard.

**Verified** - planting a live provider descriptor claiming the suite's
`IOS_UDID` fails 3 tests before, passes after; the new test fails
deterministically with the `scopeTempHome` call removed, naming the real
home in its message. Full `@argent/tool-server` suite green (6164
passed).

No docs change: test-only, no tool, CLI, config key or user-facing
capability moves.

<details>
<summary>Repro and check output</summary>

Repro (a descriptor in `~/.argent/providers` claiming the udid the
fixtures use, plus a live server on its `apiUrl` so it survives the
discovery probe):

```
 × returns nothing when no provider is registered at all
 × is the identity for an ordinary device and performs no I/O
 × leaves an ordinary udid and the default set untouched
 Tests  3 failed | 104 passed (107)
```

Same planted home, after:

```
 Test Files  2 passed (2)
      Tests  119 passed (119)
```

The added test discriminates - with `scopeTempHome(HOME_PREFIX)` removed
and no descriptor planted at all:

```
 × discovers against a providers directory this run owns
AssertionError: expected '/Users/<me>/.argent/providers' to contain 'argent-external-devices-home-'
 Tests  1 failed | 107 passed (108)
```

Checks from the worktree root:

- `npx tsc --build` - clean
- `npm run typecheck:tests -w @argent/tool-server` - clean
- `npm test -w @argent/tool-server` - 433 files, 6164 passed, 1 skipped
- `npx prettier --write` on the three files - unchanged

Sibling suites left alone: the other nine tool-server files that delete
the discovery guard (`list-devices`, `metro-port`,
`external-js-debugger`, `external-native-devtools`,
`native-profiler-external-device`, `android-profiler-external-device`,
`launch-restart-external-claim`, `simulator-watcher-external-claim`,
`boot-device-external-refused`) set `ARGENT_DEVICE_PROVIDERS` in the
same hook, which replaces the directory scan outright. All nine stay
green under the planted home.
`argent-cli/test/providers-command.test.ts` and
`device-providers/test/read.test.ts` already stub `HOME`/`USERPROFILE`
themselves.

</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-09 20:17:37 +02:00

28 lines
1.1 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { homedir } from "node:os";
import { scopeTempHome } from "./helpers/temp-home";
// os.homedir() reads USERPROFILE on Windows and HOME elsewhere, so a helper that
// pins only one of them is inert on the other platform and the suites relying on
// it write into the developer's real home there. Nothing else asserts this: with
// the USERPROFILE line deleted every file that calls scopeTempHome stays
// green, which is what these tests exist to stop.
describe("scopeTempHome", () => {
const seen: string[] = [];
scopeTempHome("argent-scope-probe-");
it("pins both names os.homedir() consults, at the same directory", () => {
expect(process.env.HOME).toBeDefined();
expect(process.env.USERPROFILE).toBe(process.env.HOME);
expect(homedir()).toBe(process.env.HOME);
seen.push(process.env.HOME!);
});
it("hands each test its own directory rather than one shared path", () => {
expect(process.env.USERPROFILE).toBe(process.env.HOME);
seen.push(process.env.HOME!);
expect(new Set(seen).size).toBe(seen.length);
expect(seen[0]).toContain("argent-scope-probe-");
});
});