Skip to content

feat: integrate asyncapi diff library using the diff command#135

Merged
asyncapi-bot merged 40 commits into
asyncapi:masterfrom
aayushmau5:asyncapi-diff-integration
Feb 7, 2022
Merged

feat: integrate asyncapi diff library using the diff command#135
asyncapi-bot merged 40 commits into
asyncapi:masterfrom
aayushmau5:asyncapi-diff-integration

Conversation

@aayushmau5

Copy link
Copy Markdown
Member

Description

This PR integrates the asyncapi-dff library using the diff command.

At the moment, the command looks something like this.

asyncapi diff <file-path/context-1> <file-path/context-2>

And it has two flags:

--format(default and only acceptable right now value: json) which determines the format of the output.
--type(all (default) , breaking, non-breaking, unclassified) which determines the type of the output we want.

At the moment, the output is being logged to stdout. The support for outputting data into files is to be added(which is most likely to be done by me, whether in this PR or another one depends on the review :) ).

Related issue(s)

See #58

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Comment thread src/commands/diff.ts Outdated
Souvikns
Souvikns previously approved these changes Nov 24, 2021

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome to see it comming!
Please have a look at some possible improvements to developer experience

Comment thread src/commands/diff.ts Outdated
Comment thread src/commands/diff.ts Outdated
Comment thread src/commands/diff.ts Outdated
Comment thread src/commands/diff.ts Outdated
Comment thread src/commands/diff.ts Outdated
Comment thread src/commands/diff.ts Outdated
@aayushmau5

Copy link
Copy Markdown
Member Author

Thanks for the reviews. Will make the changes ASAP.

@derberg

derberg commented Dec 13, 2021

Copy link
Copy Markdown
Member

@aayushmau5 hey, tests are failing because of linter.

@Souvikns

Copy link
Copy Markdown
Member

This is something new

image

@aayushmau5

Copy link
Copy Markdown
Member Author

Yeah, confused as to why this is happening. Let me check if this has something to do with the context I'm setting in the tests.

@derberg

derberg commented Dec 21, 2021

Copy link
Copy Markdown
Member

@aayushmau5 you need a hand? or two? 😄

@aayushmau5

Copy link
Copy Markdown
Member Author

Yeah 😅 Not sure why the test fails in windows even though I have not used any context in the tests for diff command 😕

@derberg

derberg commented Dec 21, 2021

Copy link
Copy Markdown
Member

looking at logs Error: EPERM: operation not permitted, open 'C:\Users\runneradmin\.test.asyncapi' looks like tests fail as there is no access to the config file that keeps context, and test that removes it, cannot do it because it has no rights to do it.

super strange that it is happening right now, they had to do some updates to VM or something.

The problem is I have no idea how to solve it, other than adding a NODE_ENV that you can use in tests to override default context location. This way you could provide location that can be easily modified by the workflow.

@Souvikns @boyney123 @magicmatatjahu thoughts?

to summarize, I'm thinking about modifying these 3 lines -> https://github.com/asyncapi/cli/blob/master/src/models/Context.ts#L8-L10

const isTestEnv = !!process.env.TEST;
const CONTEXT_FILENAME = isTestEnv ? '.test.asyncapi' : '.asyncapi';
export const DEFAULT_CONTEXT_FILE_PATH = path.resolve(os.homedir(), CONTEXT_FILENAME);

with something like

const CONTEXT_FILENAME = process.env.CONTEXT_FILENAME || '.asyncapi';
export const DEFAULT_CONTEXT_FILE_PATH = process.env.CONTEXT_FILE_PATH || path.resolve(os.homedir(), CONTEXT_FILENAME);

and then just update test script in package.json to provide custom name and path location

@Souvikns

Souvikns commented Dec 21, 2021

Copy link
Copy Markdown
Member
const isTestEnv = !!process.env.TEST;
const CONTEXT_FILENAME = isTestEnv ? '.test.asyncapi' : '.asyncapi';
export const DEFAULT_CONTEXT_FILE_PATH = path.resolve(os.homedir(), CONTEXT_FILENAME);

we have this so that while testing we don't overwrite the global config file. I think we should just check if it is test env then we should choose .test.asyncapi or choose something from the env variable.

maybe something like this

const CONTEXT_FILENAME = isTestEnv ? process.env.context_file_path || '.test.asyncapi' : '.asyncapi'

@derberg

derberg commented Dec 21, 2021

Copy link
Copy Markdown
Member

@Souvikns the thing is that we should have no test-related logic in library, this is why I propose that we have all customizable and we just override it in the test script, and we create context config in test dir during testing, and make sure the file is in gitignore

@Souvikns

Copy link
Copy Markdown
Member

@Souvikns the thing is that we should have no test-related logic in library, this is why I propose that we have all customizable and we just override it in the test script, and we create context config in test dir during testing, and make sure the file is in gitignore

Oh now I get it, yeah that would be better

@derberg

derberg commented Feb 1, 2022

Copy link
Copy Markdown
Member

@aayushmau5 your test still runs outside it function, have a look at the context tests and how I changed them

@aayushmau5

Copy link
Copy Markdown
Member Author

what did we agree on with another flag that is needed, to enable user to pass a path to custom standard?

Oops, I don't think we have discussed this 🤔 . I completely forgot about passing custom standard.

What flag should we go with? Also, I'm assuming this file will be a json file(or we should treat it as such)?

@derberg

derberg commented Feb 1, 2022

Copy link
Copy Markdown
Member

yeah, just enable what API of the diff library allows you to do. So definitely a json file, and I think --overrides is good, just provide good help description

Comment thread src/commands/diff.ts
Comment on lines +136 to +139
async function readOverrideFile(path: string): Promise<diff.OverrideObject> {
const overrideStringData = await readFile(path, { encoding: 'utf8' });
return JSON.parse(overrideStringData);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure where to put this function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

imho it is fine if it just stays here, just add js doc

most important is to have proper error handling, awaits should be wrapped in try/catch and we need test, what error goes out when user passed path to not existing file and what error goes out when user passed path to not json file and JSON.parse fails

@aayushmau5 aayushmau5 requested a review from derberg February 2, 2022 06:45
@aayushmau5

aayushmau5 commented Feb 3, 2022

Copy link
Copy Markdown
Member Author

@derberg It seems adding tests like

it(..., () => {
	it(..., () => {})
})

results in the tests passing no more whether it really fails or not.

But

describe(..., () => {
	it(..., () => {})
})

seems to work fine.

Found this bug when trying to test an error, but the test passed for the wrong error.

@derberg

derberg commented Feb 3, 2022

Copy link
Copy Markdown
Member

@aayushmau5 yes, go ahead with

describe(..., () => {
	it(..., () => {})
})

Comment thread src/errors/diff-error.ts Outdated
Comment thread test/commands/diff.test.ts Outdated
@sonarqubecloud

sonarqubecloud Bot commented Feb 5, 2022

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@derberg

derberg commented Feb 7, 2022

Copy link
Copy Markdown
Member

@aayushmau5 lgtm 🚀 I guess I can merge, right?

@aayushmau5

Copy link
Copy Markdown
Member Author

Yes! 🚀

@derberg

derberg commented Feb 7, 2022

Copy link
Copy Markdown
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit e5cd918 into asyncapi:master Feb 7, 2022
@asyncapi-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Souvikns Souvikns mentioned this pull request Mar 3, 2022
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants