Skip to content

Commit 651eda6

Browse files
test(server): reproduce repeated tailscale spawns from remote-open targets (#11929)
These tests reproduce #11929: resolving remote-open targets repeatedly from one RemoteOpenTargets service, with no network change between calls, spawns `tailscale status --json` and `tailscale debug prefs` on every call, and each spawn can raise a macOS "access data from other apps" prompt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d0b81ce commit 651eda6

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

‎apps/server/src/environment/RemoteOpenTargets.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ interface CommandResult {
2929
readonly stdout: string;
3030
}
3131

32-
const layerSpawner = (input: { readonly status: CommandResult; readonly prefs: CommandResult }) =>
32+
const layerSpawner = (
33+
input: { readonly status: CommandResult; readonly prefs: CommandResult },
34+
spawnedArgs?: Array<ReadonlyArray<string>>,
35+
) =>
3336
Layer.succeed(
3437
ChildProcessSpawner.ChildProcessSpawner,
3538
ChildProcessSpawner.make((command) => {
3639
const args = ChildProcess.isStandardCommand(command) ? command.args : [];
40+
spawnedArgs?.push(args);
3741
const result = args[0] === "debug" ? input.prefs : input.status;
3842
return Effect.succeed(
3943
ChildProcessSpawner.makeHandle({
@@ -137,6 +141,35 @@ describe("RemoteOpenTargets", () => {
137141
}),
138142
);
139143

144+
it.effect("reads Tailscale once across repeated resolves while nothing changes", () => {
145+
const spawnedArgs: Array<ReadonlyArray<string>> = [];
146+
return Effect.gen(function* () {
147+
const service = yield* RemoteOpenTargets.RemoteOpenTargets;
148+
for (let connect = 0; connect < 3; connect++) {
149+
expect(yield* service.resolveTargets()).toEqual([
150+
{ kind: "tailscale", host: "bb-1.tail1234.ts.net", username: "t3-user" },
151+
]);
152+
}
153+
expect({
154+
status: spawnedArgs.filter((args) => args[0] === "status").length,
155+
debugPrefs: spawnedArgs.filter((args) => args[0] === "debug").length,
156+
}).toEqual({ status: 1, debugPrefs: 1 });
157+
}).pipe(
158+
Effect.provideService(HostProcess.Hostname, "bb-1"),
159+
Effect.provideService(HostProcess.Username, "t3-user"),
160+
Effect.provide(
161+
RemoteOpenTargets.layer.pipe(
162+
Layer.provide(
163+
Layer.mergeAll(
164+
layerNet({ ipv4: false, ipv6: false }),
165+
layerSpawner(TAILSCALE_SSH, spawnedArgs),
166+
),
167+
),
168+
),
169+
),
170+
);
171+
});
172+
140173
it.effect("accepts an sshd bound to IPv6 loopback only", () =>
141174
Effect.gen(function* () {
142175
const targets = yield* resolveTargets({

0 commit comments

Comments
 (0)