Skip to content
TypeScript

fix(ssh): host discovery skips hidden Include matches (#30910)

Simone948f6b55d0d7
diff --git a/packages/ssh/src/config.test.ts b/packages/ssh/src/config.test.ts
index 82a6319aefd..53fda1340aa 100644
--- a/packages/ssh/src/config.test.ts
+++ b/packages/ssh/src/config.test.ts
@@ -56,7 +56,7 @@ describe("ssh config", () => {
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
);
- it.effect("skips directory Include matches without losing file aliases or known hosts", () =>
+ it.effect("skips directories and implicit dotfile Include matches but keeps explicit ones", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
@@ -66,12 +66,24 @@ describe("ssh config", () => {
yield* fs.makeDirectory(path.join(sshDir, "explicit-directory"));
yield* fs.writeFileString(
path.join(sshDir, "config"),
- "Include config.d/*\nInclude explicit-directory\nHost real\n HostName real.example.com\n",
+ "Include config.d/*\nInclude config.d/.literal.conf\nInclude config.d/.enabled-*.conf\nInclude explicit-directory\nHost real\n HostName real.example.com\n",
);
yield* fs.writeFileString(
path.join(sshDir, "config.d", "team.conf"),
"Host team\n HostName team.example.com\n",
);
+ yield* fs.writeFileString(
+ path.join(sshDir, "config.d", ".backup.conf"),
+ "Host *\n HostName obsolete.example.com\n",
+ );
+ yield* fs.writeFileString(
+ path.join(sshDir, "config.d", ".literal.conf"),
+ "Host literal\n HostName literal.example.com\n",
+ );
+ yield* fs.writeFileString(
+ path.join(sshDir, "config.d", ".enabled-one.conf"),
+ "Host enabled\n HostName enabled.example.com\n",
+ );
yield* fs.writeFileString(
path.join(sshDir, "known_hosts"),
"known.example.com ssh-ed25519 AAAA\n",
@@ -81,7 +93,9 @@ describe("ssh config", () => {
assert.deepEqual(
hosts.map((host) => [host.alias, host.hostname, host.source]),
[
+ ["enabled", "enabled.example.com", "ssh-config"],
["known.example.com", "known.example.com", "known-hosts"],
+ ["literal", "literal.example.com", "ssh-config"],
["real", "real.example.com", "ssh-config"],
["team", "team.example.com", "ssh-config"],
],
diff --git a/packages/ssh/src/config.ts b/packages/ssh/src/config.ts
index 8b6683a968a..e87acd578de 100644
--- a/packages/ssh/src/config.ts
+++ b/packages/ssh/src/config.ts
@@ -112,6 +112,7 @@ const expandGlob = Effect.fnUntraced(function* (pattern: string) {
const entries = yield* fs.readDirectory(directory);
const matchedPaths: string[] = [];
for (const entry of entries) {
+ if (entry.startsWith(".") && !basePattern.startsWith(".")) continue;
if (!matcher.test(entry)) {
continue;
}