Skip to content

Commit 2b6d587

Browse files
willosbornejpgough-msrocketstack-matt
authored
Rework calm hub commands to work with new $id-driven API structure (finos#2662)
* feat(cli): rework push commands * feat(shared): mapping endpoints in calm-hub-client * feat(cli): rework pull commands to focus on mappings * feat(cli): rewrite of calm hub commands v1 * docs: TEMP TODO * fix(cli): sort versions returned from calmhub * fix(cli): update document before pushing to handle version changes * fix(cli): rework non-control list commands and improve validation * fix(cli): dead code and tests * feat(cli): rework to support controls * fix(shared): domain tests * fix(cli): lint * fix(cli): pull in latest package lock from main * fix(cli): remove old semver file * fix: clean up TODOs * fix: cleanup document-id-utils * refactor(cli): remove redundant method * docs(cli): rewrite of cli docs for new hub commands * fix(cli): fix issue with version bumps * test(cli): improve coverage * test(cli): coverage * test(cli): cover auth plugin loading branches in parseDocumentLoaderConfig CI was getting 84.86% branch coverage (below 85% threshold) because the auth plugin loading code was only covered locally by accidentally reading ~/.calm.json. Add proper unit tests for both the success and error paths. * fix(cli): fix output bug * fix(cli): pr feedback --------- Co-authored-by: jpgough-ms <152306432+jpgough-ms@users.noreply.github.com> Co-authored-by: Matthew Bain <66839492+rocketstack-matt@users.noreply.github.com>
1 parent 6c2a646 commit 2b6d587

15 files changed

Lines changed: 2500 additions & 3810 deletions

cli/src/cli.spec.ts

Lines changed: 289 additions & 108 deletions
Large diffs are not rendered by default.

cli/src/cli.ts

Lines changed: 78 additions & 149 deletions
Large diffs are not rendered by default.

cli/src/command-helpers/diff.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,15 @@ describe('runTimelineDiffCommand', () => {
246246

247247
expect(mocks.processExit).toHaveBeenCalledWith(1);
248248
});
249+
250+
it('does not append a trailing newline when summary output already ends with one', async () => {
251+
(runTimelineDiff as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
252+
diffs: [{ from: 'm1', to: 'm2', diff: emptyDiff }],
253+
});
254+
255+
await runTimelineDiffCommand({ ...timelineBaseOptions, outputFormat: 'summary' as const });
256+
257+
// formatDiff in 'summary' mode ends with '\n', so the extra write should NOT occur
258+
expect(mocks.stdoutWrite).toHaveBeenCalledTimes(1);
259+
});
249260
});

cli/src/command-helpers/hub-commands.spec.ts

Lines changed: 519 additions & 1272 deletions
Large diffs are not rendered by default.

cli/src/command-helpers/hub-commands.ts

Lines changed: 353 additions & 841 deletions
Large diffs are not rendered by default.

cli/src/command-helpers/timeline.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ describe('buildImpliedTimeline', () => {
102102

103103
expect(timeline.moments[0].name).toBe('broken');
104104
});
105+
106+
it('returns timeline without current-moment when given no architectures', () => {
107+
const timeline = buildImpliedTimeline([]);
108+
109+
expect(timeline.moments).toHaveLength(0);
110+
expect(timeline['current-moment']).toBeUndefined();
111+
});
105112
});
106113

107114
describe('runTimelineGenerate', () => {
@@ -135,4 +142,14 @@ describe('runTimelineGenerate', () => {
135142
expect(exitSpy).toHaveBeenCalledWith(1);
136143
});
137144

145+
it('handles non-Error thrown values in the catch block', () => {
146+
const a = writeArch('a.json', { name: 'A' });
147+
const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as never);
148+
vi.spyOn(process.stdout, 'write').mockImplementation(() => { throw 'non-error string'; });
149+
150+
runTimelineGenerate({ architecturePaths: [a], verbose: false });
151+
152+
expect(exitSpy).toHaveBeenCalledWith(1);
153+
});
154+
138155
});

cli/src/command-helpers/validate.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ describe('runValidate', () => {
247247
expect(writeFileSync).toHaveBeenCalledWith('out.json', 'formatted output');
248248
});
249249

250+
it('should exit 1 when neither architecture, pattern, nor timeline is resolved', async () => {
251+
await runValidate({
252+
architecturePath: undefined,
253+
patternPath: undefined,
254+
timelinePath: undefined,
255+
metaSchemaPath: 'schemas',
256+
verbose: false,
257+
outputFormat: 'json',
258+
outputPath: '',
259+
strict: false,
260+
});
261+
262+
expect(mocks.processExit).toHaveBeenCalledWith(1);
263+
});
264+
250265
it('should call process.exit(1) when an error occurs', async () => {
251266
const options: ValidateOptions = {
252267
architecturePath: 'arch.json',

0 commit comments

Comments
 (0)