New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS] Add generated content to repo to track future changes #7396
Conversation
bjornharrtell
commented
Jul 28, 2022
•
edited
edited
- allows to run code generation and/or typescript tests without ending up with modified or untracked content
- harmonizes code generation check and typescript tests to generate the same content
Strange.. CI complains with:
|
Looks like it was due to different gen options for tests vs ./scripts/generate_code.py. Hopefully fixed in additional commit. |
This may look like alot of redundant content but I do believe it provides value to be able to see/detect future changes affecting generation. And AFAIK for other langs we already have the generated content in repo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like @dbaileychess to review before it goes in
@@ -0,0 +1,12 @@ | |||
// automatically generated by the FlatBuffers compiler, do not modify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this and all other related files be in reflection
rather than tests
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have TS code that relies on reflection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does indeed seem confused between tests/reflection. I don't know anything about it and note that is was also added by #7161.
@@ -0,0 +1,5 @@ | |||
// automatically generated by the FlatBuffers compiler, do not modify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do these foobar
files come from? is this TS specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also seem related to #7161 and specifically this included schema - https://github.com/google/flatbuffers/blob/master/tests/test_dir/typescript_transitive_include.fbs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, these don't have to be saved in the repo. The tests/TypeScripttest.sh
should output them to a temp file, assert they exist, and then delete them. If we do that, we don't have to worry about checking them in.
@@ -0,0 +1,5 @@ | |||
export { Abc } from './foobar/abc'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these all sit directly in tests
which should be avoided.. what are they for anyway? these don't seem to come from the schemas we use with other languages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems it originates from #7161 with the purpose of testing typescript keyword clashes or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's messy that generated stuff ends up directly in tests. However, note that is also true for other langs fx. https://github.com/google/flatbuffers/blob/master/tests/monster_test_generated.h.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is from a language which generates all its code (including namespaces) into a single file. Languages that create a file per class and directories for namespaces should use directories in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the main reason for generated files not ending up in a subdir is that they do not have namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note that the _generated.ts
files are generating all their code in a single file (i.e., all the ones generated with --ts-flat-files
).
For the "normal" codegen'd files (e.g., the typescript_keywords.ts
), I'm not as familiar with the history of why this setup was chosen, but the non-folder'd file is serving as a sort of equivalent to an index.ts
where it doesn't contain any actual definitions, and just exports all the relevant types for a given schema file, and so it makes some logical sense to me that it would not be in a random sub-folder.
If all is generated by #7161 and we are not sure what for, we should not be adding these to the repo. We should only add to the repo files which are directly generated from the schemas we actually have test code written for, and which are shared with other languages. |
@aardappel I agree and I cannot find any evidence of them actually being exercised in tests but I assume there is a sensible reason for why they were added, perhaps @jkuszmaul can clarify? |
Those files are "tested" insofar as that the typescript compiler should be building them and type-checking and whatnot without generating errors. I didn't add any run-time logic exercising the modified files since it didn't feel too necessary for the code I was adding (since for the changes I was making, ensuring that the imports and types worked out was really the main concern). That's not to say that more tests wouldn't be good... It wouldn't really be hard to make it codegen the files in a subdirectory, but as mentioned I think some other languages do the same thing at the top level of the Edit: Replying from the wrong account, but the same person as @jkuszmaul :) |
Thanks @jameskuszmaul-brt, that makes sense to me. |
@aardappel are you ok with review comment answers and could we merge? |
@bjornharrtell well none of what I asked about has been resolved, right? "that other PR added them and we don't know why" doesn't seem a good reason to add a ton of files in sub-optimal locations.. like I said before, I'd prefer it if we only merged files that are directly under test by our TS testing code, and I'd prefer it if any new files don't unnecessarily land in the root test dir. Maybe I am wrong about some of this, but find it hard to ok this as-is without someone clearly stating that any of this is needed. I'll ping @dbaileychess |
@aardappel @bjornharrtell I'll take a look at this today. |
I agree with @aardappel, we should first figure out/clean up what files are being generated for TS and remove the ones that aren't being directly tested or at least not namespaced. |
I feel like there's a disconnect here. As I noted above, the |
@jkuszmaul Yeah, I understand that part of the test, but the actual output files are of no clear use and shouldn't be checked in. Can we write a test that |
I also feel there is a disconnect. I agree it's unfortunate that some generated end up in the tests root but it's the same for other langs. This only rectifies the incomplete state that when running code generation you otherwise get multiple untracked files in the tree and it's not clear why they are not added as the rest is. |
Then the test script should delete those files explicitly after verifying |
That could make sense. But my argument is that we do not primarily commit generated content for the purpose of runtime tests - for that purpose all it could in fact all be deleted after the test run. We commit it to track effects of code generation logic changes. |
I think it is a balance, and we do a poor job of it now. We dupe so much stuff in all of our generated code, that at this point just becomes noise. How many times do we need to see the generated output of an integer field for a given language? We probably have 100s of those in all of our generated files. Ideally we would have a |
I agree it is a bit messy and redundant but it is what it is. It's it not becoming less messy to make an exception for a subset of from TS generated source because it happens to not be exercised by test cases at this time. I would rather argue that it would make sense to add some trivial runtime tests for it bur why make that a requirement at this time? |
When I said "used by the tests", I mean there is human written code calling the functions in it. The fact that it gets "compiled" is in theory useful, but it is not necessary. Other languages are not creating files to this extent (and certainly not in the root dir), so I don't see why we should make things much worse now. I'd prefer this to be cleaned up to the minimum files actually needed. |
|
And yet another argument is that the generated code in question is of interest to reference and discuss in relation to #7395 which I'm currently still a bit confused about if there is a bug or if it is per design and sensible. |
As I already explained before, a file like Regardless of what there already is, we should not make things worse, and this PR seems to go much beyond what we have so far in the wrong direction. I am not sure why it is hard to determine what is needed, this PR is pulling in files which a) are not directly tested by test code and b) there's no equivalent in (most) other languages. It should be possible to figure out how to not generate them and/or not add them to this PR, and/or namespace things, surely. I get the sense we're arguing what is easiest, not what is good for the project. |
Let's pause this PR until we clean up what |
I'm sorry that we are in such disagreement here. |
Hmm, @dbaileychess and @aardappel what about if we create a dedicated folder structure (and/or subfolder in tests, I would suggest one per language) intended for and only for generated code? I could try to make that happen here for TS/JS if that is an acceptable middle ground. |
../flatc --ts --gen-name-strings --gen-mutable --gen-object-api -I include_test monster_test.fbs | ||
../flatc --gen-object-api -b -I include_test monster_test.fbs unicode_test.json | ||
../flatc --ts --gen-name-strings --gen-mutable --gen-object-api -o union_vector union_vector/union_vector.fbs | ||
../flatc --ts --reflect-names --gen-name-strings --gen-mutable --gen-object-api -I include_test monster_test.fbs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We first should check in the generate code before modifying the arguments, so we can see how it changes.
../flatc --ts --gen-name-strings optional_scalars.fbs | ||
../flatc --ts --gen-name-strings --gen-object-api --gen-mutable -I ../ ./typescript_keywords.fbs test_dir/typescript_include.fbs test_dir/typescript_transitive_include.fbs ../reflection/reflection.fbs | ||
../flatc --ts --gen-name-strings --gen-object-api --gen-mutable --ts-flat-files -I ../ ./typescript_keywords.fbs test_dir/typescript_include.fbs test_dir/typescript_transitive_include.fbs ../reflection/reflection.fbs | ||
../flatc --ts --reflect-names --gen-name-strings --gen-mutable --gen-object-api -I ../ ./typescript_keywords.fbs test_dir/typescript_include.fbs test_dir/typescript_transitive_include.fbs ../reflection/reflection.fbs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clean this part up to remove generating things that are not directly tested. If they are still valued, we should make sure they are put in an appropriate directory.
@@ -0,0 +1,5 @@ | |||
// automatically generated by the FlatBuffers compiler, do not modify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, these don't have to be saved in the repo. The tests/TypeScripttest.sh
should output them to a temp file, assert they exist, and then delete them. If we do that, we don't have to worry about checking them in.
I think this will be not needed if we move our lang-specific files to their own directories. At that point, we can check in the files? |
Agree. And as I see it doing that is actually resolving this issue. |
@bjornharrtell Can this be dropped? |
@dbaileychess yep, closing. |