Skip to content

Commit

Permalink
Merge pull request #33 from gjsjohnmurray/magenta-snake
Browse files Browse the repository at this point in the history
Fix overprompting during authentication
  • Loading branch information
gjsjohnmurray authored Nov 13, 2024
2 parents b9b2ea9 + 7f70825 commit d3beee2
Show file tree
Hide file tree
Showing 11 changed files with 1,293 additions and 735 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
- run: npm install
- name: lint
if: runner.os == 'Linux-NOSUCH'
Expand All @@ -80,12 +80,12 @@ jobs:
if: runner.os == 'Linux'
run: |
npx vsce package -o ${{ steps.set-version.outputs.name }}.vsix
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4.4.2
if: (runner.os == 'Linux') && (github.event_name != 'release')
with:
name: ${{ steps.set-version.outputs.name }}.vsix
path: ${{ steps.set-version.outputs.name }}.vsix
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4.4.2
if: runner.os == 'Linux'
with:
name: meta
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
- name: Prepare build
id: set-version
run: |
Expand Down
1,915 changes: 1,239 additions & 676 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"objectscript"
],
"engines": {
"vscode": "^1.76.0"
"vscode": "^1.93.0"
},
"icon": "images/logo.png",
"categories": [
Expand Down Expand Up @@ -49,17 +49,17 @@
"tough-cookie": "^4.0.0"
},
"devDependencies": {
"@intersystems-community/intersystems-servermanager": "latest",
"@intersystems-community/intersystems-servermanager": "^3.8.0",
"@types/glob": "^7.1.1",
"@types/mocha": "^9.0.0",
"@types/node": "^8.10.60",
"@types/vscode": "^1.76.0",
"@vscode/test-electron": "^2.3.2",
"@types/vscode": "^1.93.0",
"@vscode/test-electron": "^2.3.8",
"glob": "^7.1.6",
"mocha": "^9.2.2",
"ts-loader": "^9.4.2",
"tslint": "^5.20.1",
"typescript": "^4.4.3"
"typescript": "^5.5.4"
},
"main": "./out/extension",
"activationEvents": [
Expand Down
5 changes: 3 additions & 2 deletions src/commonRunTestsHandler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as vscode from 'vscode';
import { allTestRuns, extensionId, IServerSpec, osAPI } from './extension';
import { IServerSpec } from "@intersystems-community/intersystems-servermanager";
import { allTestRuns, extensionId, osAPI } from './extension';
import { relativeTestRoot } from './localTests';
import logger from './logger';
import { makeRESTRequest } from './makeRESTRequest';

export async function commonRunTestsHandler(controller: vscode.TestController, resolveItemChildren: (item: vscode.TestItem) => Promise<void>, request: vscode.TestRunRequest, cancellation: vscode.CancellationToken) {
logger.info(`commonRunTestsHandler invoked by controller id=${controller.id}`);
logger.debug(`commonRunTestsHandler invoked by controller id=${controller.id}`);

const isResolvedMap = new WeakMap<vscode.TestItem, boolean>();

Expand Down
27 changes: 3 additions & 24 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

import * as vscode from "vscode";
import * as serverManager from "@intersystems-community/intersystems-servermanager";
import { setupHistoryExplorerController } from "./historyExplorer";
import { setupServerTestsController } from "./serverTests";
import { setupLocalTestsController } from "./localTests";
Expand All @@ -11,36 +12,14 @@ export let localTestController: vscode.TestController;
export let loadedTestController: vscode.TestController;
export let historyBrowserController: vscode.TestController;
export let osAPI: any;
export let smAPI: any;
export let smAPI: serverManager.ServerManagerAPI | undefined;

export interface TestRun extends vscode.TestRun {
debugSession?: vscode.DebugSession
}
export const allTestRuns: (TestRun | undefined)[] = [];

export interface IWebServerSpec {
scheme?: string;
host: string;
port: number;
pathPrefix?: string;
}

export interface IServerSpec {
name: string;
webServer: IWebServerSpec;
username?: string;
password?: string;
description?: string;
}

export interface IJSONServerSpec {
webServer: IWebServerSpec;
username?: string;
password?: string;
description?: string;
}

async function getServerManagerAPI(): Promise<any> {
async function getServerManagerAPI(): Promise<serverManager.ServerManagerAPI | undefined> {
const targetExtension = vscode.extensions.getExtension("intersystems-community.servermanager");
if (!targetExtension) {
return undefined;
Expand Down
8 changes: 6 additions & 2 deletions src/historyExplorer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { historyBrowserController, IServerSpec, osAPI, smAPI } from './extension';
import { IServerSpec } from "@intersystems-community/intersystems-servermanager";
import { historyBrowserController, osAPI, smAPI } from './extension';
import logger from './logger';
import { makeRESTRequest } from './makeRESTRequest';

Expand All @@ -11,7 +12,7 @@ interface IResult {
const resultMap = new WeakMap<vscode.TestItem, IResult>();

export async function setupHistoryExplorerController() {
logger.info('setupHistoryExplorerController invoked');
logger.debug('setupHistoryExplorerController invoked');

historyBrowserController.resolveHandler = async (item) => {
if (item) {
Expand Down Expand Up @@ -48,6 +49,9 @@ export async function setupHistoryExplorerController() {
export async function serverSpec(item: vscode.TestItem): Promise<IServerSpec | undefined> {
const serverName = item.id.split(':')[0];
if (serverName) {
if (!smAPI) {
return undefined;
}
return await smAPI.getServerSpec(serverName);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/localTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function runTestsHandler(request: vscode.TestRunRequest, cancellation: vsc
}

export async function setupLocalTestsController(): Promise<vscode.Disposable> {
logger.info('setupLocalTestsController invoked');
logger.debug('setupLocalTestsController invoked');

function showLoadingMessage() {
localTestController.items.replace([localTestController.createTestItem('-', 'loading...')]);
Expand Down
13 changes: 8 additions & 5 deletions src/makeRESTRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import axios, { AxiosResponse } from "axios";
import axiosCookieJarSupport from "axios-cookiejar-support";
import tough = require("tough-cookie");
import * as vscode from "vscode";
import { IServerSpec } from "./extension";
import { IServerSpec } from "@intersystems-community/intersystems-servermanager";
import { smAPI } from "./extension";
import * as https from 'https';

const AUTHENTICATION_PROVIDER = "intersystems-server-credentials";
Expand Down Expand Up @@ -137,19 +138,21 @@ export async function makeRESTRequest(
}

export async function resolveCredentials(serverSpec: IServerSpec) {
// This arises if setting says to use authentication provider
if (typeof serverSpec.password === "undefined") {
if (typeof serverSpec.password === "undefined" && smAPI) {
const scopes = [serverSpec.name, serverSpec.username || ""];

// Handle Server Manager extension version < 3.8.0
const account = smAPI.getAccount ? smAPI.getAccount(serverSpec) : undefined;
let session = await vscode.authentication.getSession(
AUTHENTICATION_PROVIDER,
scopes,
{ silent: true },
{ silent: true, account },
);
if (!session) {
session = await vscode.authentication.getSession(
AUTHENTICATION_PROVIDER,
scopes,
{ createIfNone: true },
{ createIfNone: true, account },
);
}
if (session) {
Expand Down
2 changes: 1 addition & 1 deletion src/serverTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function runTestsHandler(request: vscode.TestRunRequest, cancellation: vsc
}

export async function setupServerTestsController() {
logger.info('setupServerTestsController invoked');
logger.debug('setupServerTestsController invoked');

function showLoadingMessage() {
loadedTestController.items.replace([loadedTestController.createTestItem('-', 'loading...')]);
Expand Down
36 changes: 22 additions & 14 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import * as cp from 'child_process';
import * as path from 'path';
import * as cp from "child_process";
import * as path from "path";

import {
downloadAndUnzipVSCode,
resolveCliArgsFromVSCodeExecutablePath,
runTests
} from '@vscode/test-electron';
downloadAndUnzipVSCode,
resolveCliArgsFromVSCodeExecutablePath,
runTests
} from "@vscode/test-electron";

async function main() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
const extensionTestsPath = path.resolve(__dirname, './suite/index');
const vscodeExecutablePath = await downloadAndUnzipVSCode();
const [cliPath, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, "../../");

// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, "./suite/index");
const vscodeExecutablePath = await downloadAndUnzipVSCode("stable");
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);

// Install dependent extensions
// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(
cliPath,
cli,
[...args, '--install-extension', 'intersystems-community.servermanager', '--install-extension', 'intersystems-community.vscode-objectscript'],
{
encoding: 'utf-8',
stdio: 'inherit'
stdio: 'inherit',
shell: process.platform === 'win32'
}
);

Expand All @@ -30,8 +38,8 @@ async function main() {
extensionDevelopmentPath,
extensionTestsPath
});
} catch (err) {
console.error('Failed to run tests');
} catch (err) {
console.error("Failed to run tests", err);
process.exit(1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2016",
"target": "es2019",
"noImplicitAny": false,
"removeComments": false,
"noUnusedLocals": true,
Expand Down

0 comments on commit d3beee2

Please sign in to comment.