Skip to content

Commit 5386867

Browse files
committed
refactor(supportBundle): share Remote-SSH layout predicates
Address PR #971 CRF-8: extract the Remote-SSH log layout knowledge (extension exthost dirs, `output_logging_` prefix, `Remote - SSH` filename fragment) into `sshExtension.ts` as predicates and consume them from both `sshProcess.ts` and `supportBundle/logFiles.ts`. A future VS Code log layout change now touches one place.
1 parent 3690c44 commit 5386867

4 files changed

Lines changed: 36 additions & 11 deletions

File tree

src/remote/sshExtension.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ export const REMOTE_SSH_EXTENSION_IDS = [
1010

1111
export type RemoteSshExtensionId = (typeof REMOTE_SSH_EXTENSION_IDS)[number];
1212

13+
/**
14+
* VS Code Remote-SSH log layout, shared by the live SSH monitor and the
15+
* support-bundle collector so a future layout change updates one place.
16+
*/
17+
const OUTPUT_LOGGING_DIR_PREFIX = "output_logging_";
18+
const REMOTE_SSH_LOG_NAME_FRAGMENT = "Remote - SSH";
19+
20+
/** True if `dirName` is the exthost dir of a known Remote-SSH extension. */
21+
export function isRemoteSshExtensionDir(dirName: string): boolean {
22+
return (REMOTE_SSH_EXTENSION_IDS as readonly string[]).includes(dirName);
23+
}
24+
25+
/** True if `dirName` is a VS Code shared output channel dir. */
26+
export function isOutputLoggingDir(dirName: string): boolean {
27+
return dirName.startsWith(OUTPUT_LOGGING_DIR_PREFIX);
28+
}
29+
30+
/** True if `fileName` is the Remote-SSH log inside a shared output channel. */
31+
export function isSharedChannelRemoteSshLog(fileName: string): boolean {
32+
return fileName.includes(REMOTE_SSH_LOG_NAME_FRAGMENT);
33+
}
34+
1335
type RemoteSshExtension = vscode.Extension<unknown> & {
1436
id: RemoteSshExtensionId;
1537
};

src/remote/sshProcess.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { findPort } from "../util";
88
import { cleanupFiles } from "../util/fileCleanup";
99

1010
import { NetworkStatusReporter } from "./networkStatus";
11+
import {
12+
isOutputLoggingDir,
13+
isSharedChannelRemoteSshLog,
14+
} from "./sshExtension";
1115

1216
import type { Logger } from "../logging/logger";
1317
import type { TelemetryReporter } from "../telemetry/reporter";
@@ -514,7 +518,7 @@ async function findRemoteSshLogPath(
514518
try {
515519
const dirs = await fs.readdir(logsParentDir);
516520
const outputDirs = dirs
517-
.filter((d) => d.startsWith("output_logging_"))
521+
.filter(isOutputLoggingDir)
518522
.sort((a, b) => a.localeCompare(b))
519523
.reverse();
520524

@@ -541,6 +545,6 @@ async function findRemoteSshLogPath(
541545

542546
async function findSshLogInDir(dirPath: string): Promise<string | undefined> {
543547
const files = await fs.readdir(dirPath);
544-
const remoteSshLog = files.find((f) => f.includes("Remote - SSH"));
548+
const remoteSshLog = files.find(isSharedChannelRemoteSshLog);
545549
return remoteSshLog ? path.join(dirPath, remoteSshLog) : undefined;
546550
}

src/supportBundle/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function isEnoent(error: unknown): boolean {
4646
);
4747
}
4848

49-
// lstat rejects symlinks so a planted link can't pull host files in.
49+
/** Read a file with an lstat guard that rejects symlinks. */
5050
export async function readLogFile(
5151
filePath: string,
5252
logger: Logger,

src/supportBundle/logFiles.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import * as path from "node:path";
22

33
import { type Logger } from "../logging/logger";
4-
import { REMOTE_SSH_EXTENSION_IDS } from "../remote/sshExtension";
4+
import {
5+
isOutputLoggingDir,
6+
isRemoteSshExtensionDir,
7+
isSharedChannelRemoteSshLog,
8+
} from "../remote/sshExtension";
59

610
import {
711
addFiles,
@@ -42,16 +46,11 @@ function isRemoteSshLog(relativePath: string, fileName: string): boolean {
4246
}
4347
const parts = normalizeZipPath(relativePath).split("/");
4448
// Whole exthost dir belongs to one extension; output_logging_* is shared.
45-
if (
46-
parts.some((part) =>
47-
(REMOTE_SSH_EXTENSION_IDS as readonly string[]).includes(part),
48-
)
49-
) {
49+
if (parts.some(isRemoteSshExtensionDir)) {
5050
return true;
5151
}
5252
return (
53-
parts.some((part) => part.startsWith("output_logging_")) &&
54-
fileName.includes("Remote - SSH")
53+
parts.some(isOutputLoggingDir) && isSharedChannelRemoteSshLog(fileName)
5554
);
5655
}
5756

0 commit comments

Comments
 (0)