Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion calm-models/src/canonical/template-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type CalmFlowCanonicalModel = {
name: string;
description: string;
transitions: CalmFlowTransitionCanonicalModel[];
'requirement-url': string;
'requirement-url'?: string;
controls?: CalmControlsCanonicalModel;
metadata?: CalmMetadataCanonicalModel;
};
Expand Down
2 changes: 1 addition & 1 deletion calm-models/src/model/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CalmMoment extends CalmNode implements CalmAdaptable<CalmMomentSche
name,
description,
validFrom,
CalmNodeDetails.fromSchema(details),
details ? CalmNodeDetails.fromSchema(details) : undefined,
controls ? CalmControls.fromSchema(controls) : undefined,
metadata ? CalmMetadata.fromSchema(metadata) : undefined,
adrs,
Expand Down
2 changes: 1 addition & 1 deletion calm-models/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"strict": true,
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
Expand All @@ -17,4 +18,3 @@
"**/*.test.ts"
]
}

4 changes: 2 additions & 2 deletions cli/src/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export async function loadCliConfig(): Promise<CLIConfig | null> {
return parsed;
}
catch (err) {
if (err.code === 'ENOENT') {
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
logger.debug('No config file found at ' + configFilePath);
return null;
}
logger.error('Unexpected error loading user config: ', err);
logger.error('Unexpected error loading user config: ' + String(err));
return null;
}
}
27 changes: 14 additions & 13 deletions cli/src/cli.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ describe('CLI Integration Tests', () => {
try {
await run(calm(), ['validate', '-p', patternPath, '-a', archPath]);
expect.fail('Expected validation to fail');
} catch (error) {
const result = JSON.parse(error.stdout);
} catch (error: unknown) {
const result = JSON.parse((error as { stdout: string }).stdout);
expect(result.hasErrors).toBe(true);
expect(JSON.stringify(result)).toContain('owner');
}
Expand All @@ -410,8 +410,8 @@ describe('CLI Integration Tests', () => {
try {
await run(calm(), ['validate', '-p', patternPath, '-a', archPath, '-u', mappingPath]);
expect.fail('Expected validation to fail');
} catch (error) {
const result = JSON.parse(error.stdout);
} catch (error: unknown) {
const result = JSON.parse((error as { stdout: string }).stdout);
expect(result.hasErrors).toBe(true);
expect(JSON.stringify(result)).toContain('owner');
}
Expand Down Expand Up @@ -452,7 +452,7 @@ describe('CLI Integration Tests', () => {
expect(res.status).toBe(200);
expect(res.data.status).toBe('OK');
} finally {
process.kill(-serverProcess.pid);
if (serverProcess.pid) process.kill(-serverProcess.pid);
}
});

Expand Down Expand Up @@ -486,7 +486,7 @@ describe('CLI Integration Tests', () => {
expect(JSON.stringify(res.data)).toContain('hasErrors');
expect(JSON.stringify(res.data)).toContain('hasWarnings');
} finally {
process.kill(-serverProcess.pid);
if (serverProcess.pid) process.kill(-serverProcess.pid);
}
});

Expand Down Expand Up @@ -834,18 +834,18 @@ describe('CLI Integration Tests', () => {
fs.writeFileSync(filePath, JSON.stringify(obj, null, 2));
}

function readJson(filePath: string) {
function readJson(filePath: string): Record<string, unknown> {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
}

function patchJson(filePath: string, patchFn: (o: object) => void) {
function patchJson(filePath: string, patchFn: (o: Record<string, unknown>) => void) {
const obj = readJson(filePath);
patchFn(obj);
writeJson(filePath, obj);
}

// Utility to recursively remove specific line/character fields from JSON
function removeLineNumbers(obj: object) {
function removeLineNumbers(obj: unknown): void {
const fieldsToRemove = [
'line_start',
'line_end',
Expand All @@ -854,12 +854,13 @@ describe('CLI Integration Tests', () => {
];
if (Array.isArray(obj)) {
obj.forEach(removeLineNumbers);
} else if (obj && typeof obj === 'object') {
for (const key of Object.keys(obj)) {
} else if (obj !== null && typeof obj === 'object') {
const record = obj as Record<string, unknown>;
for (const key of Object.keys(record)) {
if (fieldsToRemove.includes(key)) {
delete obj[key];
delete record[key];
} else {
removeLineNumbers(obj[key]);
removeLineNumbers(record[key]);
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CalmChoice } from '@finos/calm-shared/dist/commands/generate/components
import { buildDocumentLoader, DocumentLoader, DocumentLoaderOptions } from '@finos/calm-shared/dist/document-loader/document-loader';
import { loadCliConfig } from './cli-config';
import path from 'path';
import inquirer from 'inquirer';
import { select } from '@inquirer/prompts';

// Shared options used across multiple commands
const ARCHITECTURE_OPTION = '-a, --architecture <file>';
Expand Down Expand Up @@ -242,13 +242,10 @@ Validation requires:
const providers = AI_PROVIDER_CHOICES;
let selectedProvider: string = options.provider;
if (!selectedProvider) {
const answer = await inquirer.prompt({
type: 'list',
name: 'provider',
selectedProvider = await select({
message: 'Select an AI provider:',
choices: providers.map((p) => ({ name: p, value: p })),
choices: providers.map((p: string) => ({ name: p, value: p })),
});
selectedProvider = answer.provider;
}
console.log(`Selected AI provider: ${selectedProvider}`);

Expand All @@ -268,7 +265,7 @@ export async function parseDocumentLoaderConfig(
urlToLocalMap?: Map<string, string>,
basePath?: string
): Promise<DocumentLoaderOptions> {
const logger = initLogger(options.verbose, 'calm-cli');
const logger = initLogger(options.verbose ?? false, 'calm-cli');
const docLoaderOpts: DocumentLoaderOptions = {
calmHubUrl: options.calmHubUrl,
schemaDirectoryPath: options.schemaDirectory,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command-helpers/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('getUrlToLocalFileMap', () => {
});
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});

const processExitSpy = vi.spyOn(process, 'exit').mockImplementation((code?: number) => {
const processExitSpy = vi.spyOn(process, 'exit').mockImplementation((code?: string | number | null) => {
throw new Error(`process.exit: ${code}`);
});

Expand Down
19 changes: 11 additions & 8 deletions cli/src/command-helpers/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export async function runValidate(options: ValidateOptions) {
const schemaDirectory = await buildSchemaDirectory(docLoader, options.verbose);
await schemaDirectory.loadSchemas();

let architecture: object;
let pattern: object;
let timeline: object;
let architecture: object | undefined;
let pattern: object | undefined;
let timeline: object | undefined;

if (options.timelinePath) {
const result = await loadTimeline(
Expand All @@ -50,8 +50,8 @@ export async function runValidate(options: ValidateOptions) {
}
else {
const result = await loadArchitectureAndPattern(
options.architecturePath,
options.patternPath,
options.architecturePath ?? '',
options.patternPath ?? '',
docLoader,
schemaDirectory,
logger
Expand All @@ -60,15 +60,18 @@ export async function runValidate(options: ValidateOptions) {
pattern = result.pattern;
}
const documentContexts = buildDocumentContexts(options, logger);
const outcome = await validate(architecture, pattern, timeline, schemaDirectory, options.verbose);
// validate() handles undefined architecture/pattern internally depending on the validation mode
const outcome = await validate(architecture as object, pattern as object, timeline, schemaDirectory, options.verbose);
enrichWithDocumentPositions(outcome, documentContexts);
const content = getFormattedOutput(outcome, options.outputFormat, toFormattingOptions(documentContexts));
writeOutputFile(options.outputPath, content);
exitBasedOffOfValidationOutcome(outcome, options.strict);
}
catch (err) {
logger.error('An error occurred while validating: ' + err.message);
logger.debug(err.stack);
const message = err instanceof Error ? err.message : String(err);
const stack = err instanceof Error ? err.stack : undefined;
logger.error('An error occurred while validating: ' + message);
if (stack) logger.debug(stack);
process.exit(1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/server/routes/routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vi.mock('@finos/calm-shared', () =>{
};
});
describe('CLIServerRoutes', () => {
let schemaDirectory: SchemaDirectory;
const schemaDirectory = {} as SchemaDirectory;
let cliServerRoutes: CLIServerRoutes;
let mockRouter: Router;

Expand Down
5 changes: 3 additions & 2 deletions cli/src/server/routes/validation-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export class ValidationRouter {
const outcome = await validate(architecture, foundSchema, undefined, this.schemaDirectory, true);
return res.status(201).type('json').send(outcome);
} catch (error) {
return res.status(500).type('json').send(new ErrorResponse(error.message));
const message = error instanceof Error ? error.message : String(error);
return res.status(500).type('json').send(new ErrorResponse(message));
}
};
}
Expand All @@ -72,6 +73,6 @@ class ErrorResponse {
}
};

class ValidationRequest {
interface ValidationRequest {
architecture: string;
}
1 change: 1 addition & 0 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"module": "Preserve",
"moduleResolution": "bundler",
"compilerOptions": {
"strict": true,
"outDir": "dist",
},
"include": ["src", "../vitest-globals.d.ts"],
Expand Down
Loading