-
Notifications
You must be signed in to change notification settings - Fork 597
Automigration pretty print #3121
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
Conversation
364e617
to
633285f
Compare
c9ab3a3
to
f63f2b6
Compare
633285f
to
e046c41
Compare
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 seems like a good opportunity to use insta
for snapshot testing. I'd like to see three tests:
- Going from an empty schema to a populated schema (perhaps that of the
module-test
module, but perhaps just one that you write out yourself). - Going from that populated schema to a different one that requires approval before migrating (I continue to think we should call this a "supervised migration" to distinguish it from a no-oversight automigration).
- Pretty-printing any schema with terminal colors disabled via
NO_COLOR
, to prove that we aren't going to fill peoples' logfiles with a bunch of horrible ANSI escape sequences in non-tty invocations. This test probably has to be marked#[serial]
via theserial_test
crate and run in a test target (i.e. file undercrates/foo/tests/
) that only has explicitly marked tests due toset_var
being unsafe in multithreaded contexts.
Makes sense to add snapshot tests. I will do that.
umm, I think using
So test for disabling ANSI escapes based on the passed argument should be enough? |
Sure, if you set it up that way, that'd work fine. It would be unsafe if you relied on the |
bdab37c
to
6a2e18e
Compare
6a2e18e
to
566573f
Compare
I stole one from James draft PR - https://github.com/clockworklabs/SpacetimeDB/pull/2065/files#diff-8150155bc61f819c6f1e3b414e728839462b5421657e2393304e4d050fd69cbdR18. Regex wrapper over ANSI formmater. It gets the job done. |
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.
Tests seem to be failing in CI. I wonder if our CI runs with NO_COLOR
set, or something, and so colored
is not printing the colors in that environment.
I can't say I'm super jazzed about writing the colors and then stripping them out again with regexes, but I also don't really care enough to complain.
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 don't think this is a correct use of the colored
crate. Honestly, I don't know of colored
is correct for what we're trying to do here. If we do use it, though, I don't think this is the right way. set_override
, perhaps obviously, sets a global flag, and so setting it and then never unsetting it the way you do here will break any other uses of the crate in the same process which rely on the environment-checking behavior. We already have a dependency on and uses of colored
prior to this PR, so that doesn't seem like a great idea. It would probably be fine to just make sure we unset that flag after finishing formatting, since our CLI is effectively single-threaded, but that still makes me pretty unhappy. I think I would prefer either:
- Having only a single formatter which uses
colored
's machinery for inspecting the environment and does not override, and then having#[serial]
tests which manipulate the environment or use the override to test the output. - Using a different library which is focused on expressiveness rather than on being "The most simple way to add colors in your terminal," like
termcolor
, which allows locally overwriting the color choice.
I didn't quite understand why the environment matters here. Isn't the schema crate internal and intended to be used on the server side only? Here, we're basically specifying that the code colors the plan as requested, rather than depending on the local environment — which seems right to me. Local env setting should matter where the CLI running not at the server code. NO?
I can't think of any potential use case that this would break. If you can provide one, I may get convinced. |
Is your intention that we pretty-print and colorize the schema on the server, and then send the text, including ANSI escapes, over HTTP? That seems wrong to me; I had assumed we would send the plan as JSON, and then have the CLI pretty-print it as desired. Note that ANSI coloring is not the only standard for coloring in terminals - some Windows terminals use something else, and alternative user agents would have entirely other mechanisms for colorizing output (e.g. a web client like our website or this unofficial one would use HTTP and CSS; a native GUI system would just draw colored text or pixels).
Assuming we do go ahead with pretty-printing on the server (which I object to, but let's set that aside for the time being), we later decide that some other thing should be colorized, e.g. something in SpacetimeDB's log output. This printing should actually respect |
Yes, I intended to do it at the Server and send over HTTP. I beleive James took similar #2065 approach in previous attempt due to same reason. I have also mentioned about this subtly here -#2962 (comment), Though, I should have mentioned more clearly (I mistakenly assumed it a common knowledge and agreed-upon approach). I agree, sending JSON and prettify-ing at client is Correct and should have done, its just an extra effort. |
If that is indeed the plan, then I feel strongly that using I am comfortable deferring sending a structured format like JSON over the wire as future work and using this design as a stop-gap solution, but please make a ticket so we can track this. Note that we do not need to (and indeed should not) serialize the actual auto-migration plans directly into JSON (that would expose them and require that we stabilize them, which we don't want to do), instead we would serialize to a semi-structured intermediate format which clients can then pretty-print as appropriate. |
165df33
to
4bd8ce7
Compare
Checking out termcolor, ColorChoice looks great. It will also let us implement |
a792b32
to
608efaf
Compare
f959cec
to
88c86e4
Compare
88c86e4
to
b98e342
Compare
Description of Changes
Pretty print for Auto migration.
API and ABI breaking changes
NA
Expected complexity level and risk
1
Testing