#hello folks, when running tests for PR
1 messages ยท Page 1 of 1 (latest)
a special handling for "JSON" was added in this PR by using strcase.ConfigureAcronym https://github.com/dagger/dagger/commit/6637732be374c3bf13b8f22b624bd4a02af296e0
I am trying to add a corresponding override ability with the new library like this: https://github.com/dagger/dagger/pull/8122/files#diff-86f6f385aaa6e8ce4d4c8a4e096e6e35ce30fc42af38a27379a3b8d98880e0cb
while most of the tests work (I think I am down to last failure here: https://github.com/dagger/dagger/blob/64b952da1d8d253fa9191d48216d682f38cb8d49/core/integration/module_typescript_test.go#L83), this seems flaky (depending on the order of when the init() function gets called)
how do you feel about making the behavior of JSON consistent and the possibility of updating the testcases to reflect that?
to reproduce the error, we can checkout the PR branch, and run the following command:
dagger call -m dev --source=.:default test custom --pkg=./core/integration --run=^TestModule/TestTypescriptInit -vvv
@pallid bison ๐
Hi @pallid bison, apologies for tagging you directly, but I know you are going to be on vacation soon. if you have any inputs for this, kindly let me know.
FWIW, once I updated the test to use hasPkgJSON instead of hasPkgJson, the test passes (and the PR CI is green). The testcase itself is not specific to verifying the behavior with string JSON, it just happened to have one.
The thing is, the acronym thing is a convention only in Go. That test uses the convention of the API, which is correct for it to be hasPkgJson. That convention comes from Javascript, which TypeScript shares. Only the Go SDK needs the acronyms to follow Go's conventions.
that is helpful. so maybe we can configure that acronym from within the go sdk instead of configuring it in core?
Yes. Needs to be accessible from Go's codegen.
got it. let me try that. thank you so much for the pointer
is there a way to conditionally initialize this on core side (e.g. identify that requested sdk is go, and then initialize it?)
on codegen side, it does not seem to be making a difference
$ cat json.diff
diff --git a/core/json.go b/core/json.go
index 7541af5c4..3aabcbb46 100644
--- a/core/json.go
+++ b/core/json.go
@@ -8,15 +8,10 @@ import (
"github.com/dagger/dagger/dagql"
"github.com/dagger/dagger/dagql/call"
- "github.com/dagger/dagger/dagql/strcase"
)
type JSON json.RawMessage
-func init() {
- strcase.ConfigureAcronym("JSON")
-}
-
func (p JSON) Bytes() []byte {
return p
}
diff --git a/core/schema/module.go b/core/schema/module.go
index 29c9a4bf8..64ce2065a 100644
--- a/core/schema/module.go
+++ b/core/schema/module.go
@@ -12,6 +12,7 @@ import (
"github.com/dagger/dagger/core"
"github.com/dagger/dagger/core/modules"
"github.com/dagger/dagger/dagql"
+ "github.com/dagger/dagger/dagql/strcase"
"github.com/dagger/dagger/engine"
)
@@ -704,6 +705,9 @@ func (s *moduleSchema) moduleInitialize(
if inst.Self.NameField == "" || inst.Self.SDKConfig == "" {
return nil, fmt.Errorf("module name and SDK must be set")
}
+ if inst.Self.SDKConfig == "go" {
+ strcase.ConfigureAcronym("JSON")
+ }
mod, err := inst.Self.Initialize(ctx, inst.ID(), dagql.CurrentID(ctx))
if err != nil {
return nil, fmt.Errorf("failed to initialize module: %w", err)
the above patch fixes the issue. This needs to happen during module - Initialization on the engine. as otherwise query fails to find definition for type with right casing.
I will spend some time to understand why it triggered failure after replacing strcase library. it does seem like a "race condition" (if I may), on when this strcase lib gets loaded.
but otherwise how do you feel about adding a func configureAcronymForSDK(sdk string) to core, which can then configure language specific acronyms (if needed)
also cc @fleet rune to collect his opinion/feedback on this
interesting.. I'm wondering why the init order is relevant here since they should all run before the tests start ๐ค
I think the patch above LGTM. I wouldn't add a new function for now since we're only needing this for the Go SDK at this moment and the above 3 lines don't really justify creating a new func IMO. cc @severe widget @foggy cipher for ๐
^still curious about the flakiness in the test
(catching up, still loading context) - I really don't think we can/should add per-language conditionals in the core code paths. In principle someone could be using a custom SDK called banana that is a Go SDK. I also see @pallid bison's concern about different languages having different conventions, but I suppose we at least need to make sure that all the types in the GraphQL schema are following the same convention, regardless of what language they came from. So if I define a FooJson type in Python I'd expect that to become FooJSON in GraphQL. Is it possible to do that?
this makes sense for all languages to generate the same GraphQL convention
which takes us to the flake that @novel moon was observing above where sometimes the GraphQL API was correctly generated and the test failed, and sometimes it didn't
also somewhat low conviction on that last part, this whole problem space feels unfortunate, I'm not sure if case-conversion things are capable of recognizing that Json should be turned into JSON
- I guess so?
That's why we're adding the acronym exceptions?
it was originally added because tests failed without it; it wasn't possible to have a field of type dagger.JSON. But going back in the repo history I also found other times where we configured acronyms like that
it sounds like GraphQL doesn't really have a convention around this either
That's right, that's that idea. The engine should convert to GraphQL convention anything from the SDKs (during registration), each SDK's codegen should convert to their own conventions, the CLI too, etc...
I guess the question is what configuring an acronym does: does it merely say "preserve JSON when you see it", or does it also say "convert Json to JSON"?
oh maybe you can ConfigureAcronym("Json", "JSON")?
Yeah, acronyms is a convention in Go, not JavaScript or GraphQL. I'd do away with that complication if we could, but it's expected in Go. You need to manage a list with the supported acronyms too. We added a few, and I've seen users wanting to use more. There'll always be missing acronyms in this list for someone.
To be clear, I don't think there's an explicit convention to use or not use acronyms in JavaScript/GraphQL. Maybe there is, but I see both in the wild (in JS at least). So, if there's no convention not to use it in GraphQL, I'm not opposed to use it in our API, especially if it makes it easier given our Go codebase. However, I very much don't like how ambivalent the acronyms are, unless you have that list everywhere. Consider how a language like Python would know where to break the words, when you could have two one-letter words before another word. It's much clearer when you only use an uppercase when it's the start of a new word.
I actually made changes to this code taken from our codegen for formatting, in my experimental codegen module, to split words correctly: https://github.com/helderco/daggerverse/blob/main/codegen/lint_name.go
You'd be able to try it, with this fix:
dagger call -m github.com/helderco/daggerverse/codegen introspect get-type --name=Container fields name-words
But the idea there was for codegen to return my JSON response, so python wouldn't care about the casing, but those that do would still be able to preserve the casing if needed. For example: My + JSON + Response = MyJSONResponse; or My + Json + Response = MyJsonResponse. Since the words are already separate, there's no ambivalence.
Remember this? https://github.com/dagger/dagger/issues/6310
What is the issue? See https://hexdocs.pm/dagger/Dagger.Container.html#experimental_with_all_gp_us/1. The function name should be experimental_with_all_gpus, experimental_with_all_gp_us Dagger vers...
My function turns that into this:
^still curious about the flakiness in the test
I probably had wrong choice of words there in saying "race condition". What I meant instead is depending on where the strcase package is defined and imported (before and after the change), thatinitfunction is getting called and changes the behavior of howJSONis handled.
I guess the question is what configuring an acronym does: does it merely say "preserve JSON when you see it", or does it also say "convert Json to JSON"?
I guess this is a behavior difference in the new lib (notice the 3rd example)
(before acronym, existing) strcase.ToPascal(Json) -> Json
(before acronym, new lib ) strcase2.ToPascal(Json) -> Json
(before acronym, existing) strcase.ToPascal(JSON) -> Json
(before acronym, new lib ) strcase2.ToPascal(JSON) -> Json
(after acronym, existing) strcase.ToPascal(Json) -> Json
(after acronym, new lib ) strcase2.ToPascal(Json) -> JSON
(after acronym, existing) strcase.ToPascal(JSON) -> JSON
(after acronym, new lib ) strcase2.ToPascal(JSON) -> JSON
the playground link -> https://go.dev/play/p/dD3w64MkJDY