Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/main/wrapper/CxConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export enum CxConstants {
CMD_LEARN_MORE = "learn-more",
IDE_SCANS_KEY = "scan.config.plugins.ideScans",
AI_GUIDED_REMEDIATION_KEY = "scan.config.plugins.aiGuidedRemediation",
STANDALONE_KEY = "scan.config.plugins.standalone",
ASSIST_KEY = "scan.config.plugins.cxoneassist",
AI_MCP_SERVER_KEY = "scan.config.plugins.aiMcpServer",
TELEMETRY = "telemetry",
SUB_CMD_TELEMETRY_AI = "ai",
Expand Down
21 changes: 21 additions & 0 deletions src/main/wrapper/CxWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,27 @@ export class CxWrapper {
return value?.toLowerCase() === "true";
}

async standaloneEnabled(): Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
commands.push(...this.initializeCommands(false));

const exec = new ExecutionService();
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);

const value = getTrimmedMapValue(output, CxConstants.STANDALONE_KEY);
return value?.toLowerCase() === "true";
}

async cxOneAssistEnabled(): Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
commands.push(...this.initializeCommands(false));

const exec = new ExecutionService();
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);

const value = getTrimmedMapValue(output, CxConstants.ASSIST_KEY);
return value?.toLowerCase() === "true";
}

async aiMcpServerEnabled(): Promise<boolean> {
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
Expand Down
52 changes: 52 additions & 0 deletions src/tests/AssistEnabledTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { CxWrapper } from '../main/wrapper/CxWrapper';
import { BaseTest } from './BaseTest';
import { ExecutionService } from '../main/wrapper/ExecutionService';
import { CxConstants } from '../main/wrapper/CxConstants';

describe('cxOneAssistEnabled tenant setting', () => {
const baseConfig = new BaseTest();

afterEach(() => {
jest.restoreAllMocks();
});

it('returns true when assist key value is true (lowercase)', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.ASSIST_KEY, 'true']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.cxOneAssistEnabled();
expect(enabled).toBe(true);
});

it('returns true when assist key value is TRUE (uppercase)', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.ASSIST_KEY, 'TRUE']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.cxOneAssistEnabled();
expect(enabled).toBe(true);
});

it('returns false when assist key value is false', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.ASSIST_KEY, 'false']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.cxOneAssistEnabled();
expect(enabled).toBe(false);
});

it('returns false when assist key is missing', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.IDE_SCANS_KEY, 'true']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.cxOneAssistEnabled();
expect(enabled).toBe(false);
});

it('trims whitespace around key/value before evaluating', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[` ${CxConstants.ASSIST_KEY} `, ' true ']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.cxOneAssistEnabled();
expect(enabled).toBe(true);
});
});
53 changes: 53 additions & 0 deletions src/tests/StandaloneEnabledTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { CxWrapper } from '../main/wrapper/CxWrapper';
import { BaseTest } from './BaseTest';
import { ExecutionService } from '../main/wrapper/ExecutionService';
import { CxConstants } from '../main/wrapper/CxConstants';

describe('standaloneEnabled tenant setting', () => {
const baseConfig = new BaseTest();

afterEach(() => {
jest.restoreAllMocks();
});

it('returns true when standalone tenant flag is true (lowercase)', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.STANDALONE_KEY, 'true']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.standaloneEnabled();
expect(enabled).toBe(true);
});

it('returns true when standalone tenant flag is TRUE (uppercase)', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.STANDALONE_KEY, 'TRUE']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.standaloneEnabled();
expect(enabled).toBe(true);
});

it('returns false when standalone tenant flag is false', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.STANDALONE_KEY, 'false']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.standaloneEnabled();
expect(enabled).toBe(false);
});

it('returns false when standalone tenant flag key is missing', async () => {
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[CxConstants.IDE_SCANS_KEY, 'true']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.standaloneEnabled();
expect(enabled).toBe(false);
});

it('trims whitespace around key and value before evaluating', async () => {
// Simulate raw output map entries with leading/trailing spaces
jest.spyOn(ExecutionService.prototype, 'executeMapTenantOutputCommands')
.mockResolvedValue(new Map([[` ${CxConstants.STANDALONE_KEY} `, ' true ']]));
const wrapper = new CxWrapper(baseConfig);
const enabled = await wrapper.standaloneEnabled();
expect(enabled).toBe(true);
});
});