Skip to content

Commit 2800162

Browse files
committed
Move files around
1 parent 73ccbb8 commit 2800162

17 files changed

+196
-35
lines changed
File renamed without changes.

src/api/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import { ProxyAgent } from "proxy-agent";
33
import { type WorkspaceConfiguration } from "vscode";
44

5-
import { getProxyForUrl } from "../proxy";
5+
import { getProxyForUrl } from "./proxy";
66
import { expandPath } from "../util";
77

88
/**

src/cliUtils.test.ts

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import fs from "fs/promises";
2+
import os from "os";
3+
import path from "path";
4+
import { beforeAll, describe, expect, it } from "vitest";
5+
import * as cli from "./core/cliUtils";
6+
7+
describe("cliUtils", () => {
8+
const tmp = path.join(os.tmpdir(), "vscode-coder-tests");
9+
10+
beforeAll(async () => {
11+
// Clean up from previous tests, if any.
12+
await fs.rm(tmp, { recursive: true, force: true });
13+
await fs.mkdir(tmp, { recursive: true });
14+
});
15+
16+
it("name", () => {
17+
expect(cli.name().startsWith("coder-")).toBeTruthy();
18+
});
19+
20+
it("stat", async () => {
21+
const binPath = path.join(tmp, "stat");
22+
expect(await cli.stat(binPath)).toBeUndefined();
23+
24+
await fs.writeFile(binPath, "test");
25+
expect((await cli.stat(binPath))?.size).toBe(4);
26+
});
27+
28+
// TODO: CI only runs on Linux but we should run it on Windows too.
29+
it("version", async () => {
30+
const binPath = path.join(tmp, "version");
31+
await expect(cli.version(binPath)).rejects.toThrow("ENOENT");
32+
33+
const binTmpl = await fs.readFile(
34+
path.join(__dirname, "../fixtures/bin.bash"),
35+
"utf8",
36+
);
37+
await fs.writeFile(binPath, binTmpl.replace("$ECHO", "hello"));
38+
await expect(cli.version(binPath)).rejects.toThrow("EACCES");
39+
40+
await fs.chmod(binPath, "755");
41+
await expect(cli.version(binPath)).rejects.toThrow("Unexpected token");
42+
43+
await fs.writeFile(binPath, binTmpl.replace("$ECHO", "{}"));
44+
await expect(cli.version(binPath)).rejects.toThrow(
45+
"No version found in output",
46+
);
47+
48+
await fs.writeFile(
49+
binPath,
50+
binTmpl.replace(
51+
"$ECHO",
52+
JSON.stringify({
53+
version: "v0.0.0",
54+
}),
55+
),
56+
);
57+
expect(await cli.version(binPath)).toBe("v0.0.0");
58+
59+
const oldTmpl = await fs.readFile(
60+
path.join(__dirname, "../fixtures/bin.old.bash"),
61+
"utf8",
62+
);
63+
const old = (stderr: string, stdout: string): string => {
64+
return oldTmpl.replace("$STDERR", stderr).replace("$STDOUT", stdout);
65+
};
66+
67+
// Should fall back only if it says "unknown flag".
68+
await fs.writeFile(binPath, old("foobar", "Coder v1.1.1"));
69+
await expect(cli.version(binPath)).rejects.toThrow("foobar");
70+
71+
await fs.writeFile(binPath, old("unknown flag: --output", "Coder v1.1.1"));
72+
expect(await cli.version(binPath)).toBe("v1.1.1");
73+
74+
// Should trim off the newline if necessary.
75+
await fs.writeFile(
76+
binPath,
77+
old("unknown flag: --output\n", "Coder v1.1.1\n"),
78+
);
79+
expect(await cli.version(binPath)).toBe("v1.1.1");
80+
81+
// Error with original error if it does not begin with "Coder".
82+
await fs.writeFile(binPath, old("unknown flag: --output", "Unrelated"));
83+
await expect(cli.version(binPath)).rejects.toThrow("unknown flag");
84+
85+
// Error if no version.
86+
await fs.writeFile(binPath, old("unknown flag: --output", "Coder"));
87+
await expect(cli.version(binPath)).rejects.toThrow("No version found");
88+
});
89+
90+
it("rmOld", async () => {
91+
const binDir = path.join(tmp, "bins");
92+
expect(await cli.rmOld(path.join(binDir, "bin1"))).toStrictEqual([]);
93+
94+
await fs.mkdir(binDir, { recursive: true });
95+
await fs.writeFile(path.join(binDir, "bin.old-1"), "echo hello");
96+
await fs.writeFile(path.join(binDir, "bin.old-2"), "echo hello");
97+
await fs.writeFile(path.join(binDir, "bin.temp-1"), "echo hello");
98+
await fs.writeFile(path.join(binDir, "bin.temp-2"), "echo hello");
99+
await fs.writeFile(path.join(binDir, "bin1"), "echo hello");
100+
await fs.writeFile(path.join(binDir, "bin2"), "echo hello");
101+
await fs.writeFile(path.join(binDir, "bin.asc"), "echo hello");
102+
await fs.writeFile(path.join(binDir, "bin.old-1.asc"), "echo hello");
103+
await fs.writeFile(path.join(binDir, "bin.temp-2.asc"), "echo hello");
104+
105+
expect(await cli.rmOld(path.join(binDir, "bin1"))).toStrictEqual([
106+
{
107+
fileName: "bin.asc",
108+
error: undefined,
109+
},
110+
{
111+
fileName: "bin.old-1",
112+
error: undefined,
113+
},
114+
{
115+
fileName: "bin.old-1.asc",
116+
error: undefined,
117+
},
118+
{
119+
fileName: "bin.old-2",
120+
error: undefined,
121+
},
122+
{
123+
fileName: "bin.temp-1",
124+
error: undefined,
125+
},
126+
{
127+
fileName: "bin.temp-2",
128+
error: undefined,
129+
},
130+
{
131+
fileName: "bin.temp-2.asc",
132+
error: undefined,
133+
},
134+
]);
135+
136+
expect(await fs.readdir(path.join(tmp, "bins"))).toStrictEqual([
137+
"bin1",
138+
"bin2",
139+
]);
140+
});
141+
142+
it("ETag", async () => {
143+
const binPath = path.join(tmp, "hash");
144+
145+
await fs.writeFile(binPath, "foobar");
146+
expect(await cli.eTag(binPath)).toBe(
147+
"8843d7f92416211de9ebb963ff4ce28125932878",
148+
);
149+
150+
await fs.writeFile(binPath, "test");
151+
expect(await cli.eTag(binPath)).toBe(
152+
"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
153+
);
154+
});
155+
});

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
AgentTreeItem,
2323
type OpenableTreeItem,
2424
WorkspaceTreeItem,
25-
} from "./workspacesProvider";
25+
} from "./workspace/workspacesProvider";
2626

2727
export class Commands {
2828
// These will only be populated when actively connected to a workspace and are

src/core/cliManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as semver from "semver";
1212
import * as vscode from "vscode";
1313

1414
import { errToStr } from "../api/api-helper";
15-
import * as cli from "../cliUtils";
15+
import * as cli from "./cliUtils";
1616
import { type Logger } from "../logging/logger";
1717
import * as pgp from "../pgp";
1818
import { type PathResolver } from "./pathResolver";
File renamed without changes.

src/core/container.ts

Whitespace-only changes.

src/extension.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ import { MementoManager } from "./core/mementoManager";
1313
import { PathResolver } from "./core/pathResolver";
1414
import { SecretsManager } from "./core/secretsManager";
1515
import { CertificateError, getErrorDetail } from "./error";
16-
import { Remote } from "./remote";
16+
import { Remote } from "./remote/remote";
1717
import { toSafeHost } from "./util";
18-
import { WorkspaceProvider, WorkspaceQuery } from "./workspacesProvider";
18+
import {
19+
WorkspaceProvider,
20+
WorkspaceQuery,
21+
} from "./workspace/workspacesProvider";
1922

2023
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
2124
// The Remote SSH extension's proposed APIs are used to override the SSH host

src/remote.ts renamed to src/remote/remote.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,32 @@ import {
1818
getEventValue,
1919
formatEventLabel,
2020
formatMetadataError,
21-
} from "./agentMetadataHelper";
22-
import { createWorkspaceIdentifier, extractAgents } from "./api/api-helper";
23-
import { CoderApi } from "./api/coderApi";
24-
import { needToken } from "./api/utils";
25-
import { startWorkspaceIfStoppedOrFailed, waitForBuild } from "./api/workspace";
26-
import * as cliUtils from "./cliUtils";
27-
import { type Commands } from "./commands";
28-
import { type CliManager } from "./core/cliManager";
29-
import { type PathResolver } from "./core/pathResolver";
30-
import { featureSetForVersion, type FeatureSet } from "./featureSet";
31-
import { getGlobalFlags } from "./globalFlags";
32-
import { Inbox } from "./inbox";
33-
import { type Logger } from "./logging/logger";
34-
import { SSHConfig, type SSHValues, mergeSSHConfigValues } from "./sshConfig";
21+
} from "../agentMetadataHelper";
3522
import { computeSSHProperties, sshSupportsSetEnv } from "./sshSupport";
23+
import { createWorkspaceIdentifier, extractAgents } from "../api/api-helper";
24+
import { CoderApi } from "../api/coderApi";
25+
import { needToken } from "../api/utils";
26+
import {
27+
startWorkspaceIfStoppedOrFailed,
28+
waitForBuild,
29+
} from "../api/workspace";
30+
import * as cliUtils from "../core/cliUtils";
31+
import { type Commands } from "../commands";
32+
import { type CliManager } from "../core/cliManager";
33+
import { type PathResolver } from "../core/pathResolver";
34+
import { featureSetForVersion, type FeatureSet } from "../featureSet";
35+
import { getGlobalFlags } from "../globalFlags";
36+
import { Inbox } from "../inbox";
37+
import { SSHConfig, type SSHValues, mergeSSHConfigValues } from "./sshConfig";
38+
import { type Logger } from "../logging/logger";
3639
import {
3740
AuthorityPrefix,
3841
escapeCommandArg,
3942
expandPath,
4043
findPort,
4144
parseRemoteAuthority,
42-
} from "./util";
43-
import { WorkspaceMonitor } from "./workspaceMonitor";
45+
} from "../util";
46+
import { WorkspaceMonitor } from "../workspace/workspaceMonitor";
4447

4548
export interface RemoteDetails extends vscode.Disposable {
4649
url: string;

src/sshConfig.ts renamed to src/remote/sshConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mkdir, readFile, rename, stat, writeFile } from "fs/promises";
22
import path from "path";
33

4-
import { countSubstring } from "./util";
4+
import { countSubstring } from "../util";
55

66
class SSHConfigBadFormat extends Error {}
77

0 commit comments

Comments
 (0)