Skip to content

Add package scripts and cli library, enable integration testing #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vitest.config.ts
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "22"

- run: yarn

Expand All @@ -36,7 +36,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "22"

- run: yarn

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "22"

- run: yarn

Expand Down
12 changes: 12 additions & 0 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from "@vscode/test-cli";

export default defineConfig({
files: "out/test/**/*.test.js",
extensionDevelopmentPath: ".",
extensionTestsPath: "./out/test",
launchArgs: ["--enable-proposed-api", "coder.coder-remote"],
mocha: {
ui: "tdd",
timeout: 20000,
},
});
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ node_modules/**
**/.editorconfig
**/*.map
**/*.ts
*.gif
*.gif
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Run all tests: `yarn test`
- Run specific test: `vitest ./src/filename.test.ts`
- CI test mode: `yarn test:ci`
- Integration tests: `yarn test:integration`

## Code Style Guidelines

Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,11 @@
"package:prerelease": "npx vsce package --pre-release",
"lint": "eslint . --ext ts,md",
"lint:fix": "yarn lint --fix",
"test": "vitest ./src",
"test:ci": "CI=true yarn test"
"test": "vitest",
"test:ci": "CI=true yarn test",
"test:integration": "vscode-test",
"pretest": "yarn run compile-tests && yarn run build && yarn run lint",
"compile-tests": "tsc -p . --outDir out"
},
"devDependencies": {
"@types/eventsource": "^3.0.0",
Expand Down Expand Up @@ -311,7 +314,8 @@
"vitest": "^0.34.6",
"vscode-test": "^1.5.0",
"webpack": "^5.99.6",
"webpack-cli": "^5.1.4"
"webpack-cli": "^5.1.4",
"@vscode/test-cli": "^0.0.10"
},
"dependencies": {
"axios": "1.8.4",
Expand All @@ -326,7 +330,7 @@
"semver": "^7.7.1",
"ua-parser-js": "1.0.40",
"ws": "^8.18.2",
"zod": "^3.25.1"
"zod": "^3.25.65"
},
"resolutions": {
"semver": "7.7.1",
Expand Down
34 changes: 23 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,31 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
//
// Cursor and VSCode are covered by ms remote, and the only other is windsurf for now
// Means that vscodium is not supported by this for now

const remoteSSHExtension =
vscode.extensions.getExtension("jeanp413.open-remote-ssh") ||
vscode.extensions.getExtension("codeium.windsurf-remote-openssh") ||
vscode.extensions.getExtension("anysphere.remote-ssh") ||
vscode.extensions.getExtension("ms-vscode-remote.remote-ssh");

let vscodeProposed: typeof vscode = vscode;

if (!remoteSSHExtension) {
vscode.window.showErrorMessage(
"Remote SSH extension not found, cannot activate Coder extension",
"Remote SSH extension not found, this may not work as expected.\n" +
// NB should we link to documentation or marketplace?
"Please install your choice of Remote SSH extension from the VS Code Marketplace.",
);
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
vscodeProposed = (module as any)._load(
"vscode",
{
filename: remoteSSHExtension.extensionPath,
},
false,
);
Comment on lines +40 to 47
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'module as any' bypasses type safety; consider a more type-safe approach or adding documentation to justify this workaround.

Copilot uses AI. Check for mistakes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I get it buddy I don't like it either but we're polymorphic on the SSH extensions.

throw new Error("Remote SSH extension not found");
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const vscodeProposed: typeof vscode = (module as any)._load(
"vscode",
{
filename: remoteSSHExtension?.extensionPath,
},
false,
);

const output = vscode.window.createOutputChannel("Coder");
const storage = new Storage(
Expand Down Expand Up @@ -278,7 +284,13 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
// Since the "onResolveRemoteAuthority:ssh-remote" activation event exists
// in package.json we're able to perform actions before the authority is
// resolved by the remote SSH extension.
if (vscodeProposed.env.remoteAuthority) {
//
// In addition, if we don't have a remote SSH extension, we skip this
// activation event. This may allow the user to install the extension
// after the Coder extension is installed, instead of throwing a fatal error
// (this would require the user to uninstall the Coder extension and
// reinstall after installing the remote SSH extension, which is annoying)
if (remoteSSHExtension && vscodeProposed.env.remoteAuthority) {
const remote = new Remote(
vscodeProposed,
storage,
Expand Down
6 changes: 3 additions & 3 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ export class Remote {
`${sshPid}.json`,
);

const updateStatus = (network: {
const updateStatus = async (network: {
p2p: boolean;
latency: number;
preferred_derp: string;
Expand Down Expand Up @@ -910,9 +910,9 @@ export class Remote {
.then((content) => {
return JSON.parse(content);
})
.then((parsed) => {
.then(async (parsed) => {
try {
updateStatus(parsed);
await updateStatus(parsed);
} catch (ex) {
// Ignore
}
Expand Down
56 changes: 56 additions & 0 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as assert from "assert";
import * as vscode from "vscode";

suite("Extension Test Suite", () => {
vscode.window.showInformationMessage("Start all tests.");

test("Extension should be present", () => {
assert.ok(vscode.extensions.getExtension("coder.coder-remote"));
});

test("Extension should activate", async () => {
const extension = vscode.extensions.getExtension("coder.coder-remote");
assert.ok(extension);

if (!extension.isActive) {
await extension.activate();
}

assert.ok(extension.isActive);
});

test("Extension should export activate function", async () => {
const extension = vscode.extensions.getExtension("coder.coder-remote");
assert.ok(extension);

await extension.activate();
// The extension doesn't export anything, which is fine
// The test was expecting exports.activate but the extension
// itself is the activate function
assert.ok(extension.isActive);
});

test("Commands should be registered", async () => {
const extension = vscode.extensions.getExtension("coder.coder-remote");
assert.ok(extension);

if (!extension.isActive) {
await extension.activate();
}

// Give a small delay for commands to register
await new Promise((resolve) => setTimeout(resolve, 100));

const commands = await vscode.commands.getCommands(true);
const coderCommands = commands.filter((cmd) => cmd.startsWith("coder."));

assert.ok(
coderCommands.length > 0,
"Should have registered Coder commands",
);
assert.ok(
coderCommands.includes("coder.login"),
"Should have coder.login command",
);
});
});
13 changes: 8 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"target": "ES2022",
"moduleResolution": "node",
"outDir": "out",
// "dom" is required for importing the API from coder/coder.
"lib": ["es6", "dom"],
"lib": ["ES2022", "dom"],
"sourceMap": true,
"rootDirs": ["node_modules", "src"],
"strict": true,
"esModuleInterop": true
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["node_modules", ".vscode-test"]
"exclude": ["node_modules", "vitest.config.ts"],
"include": ["src/**/*"]
}
17 changes: 17 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["src/**/*.test.ts"],
exclude: [
"**/node_modules/**",
"**/dist/**",
"**/build/**",
"**/out/**",
"**/src/test/**",
"src/test/**",
"./src/test/**",
],
environment: "node",
},
});
Loading