Skip to content

fix: replace strcase library to fix module name transformation related issues - #8122

Closed
rajatjindal wants to merge 2 commits into
dagger:mainfrom
rajatjindal:strcase-lib
Closed

rajatjindal wants to merge 2 commits into
dagger:mainfrom
rajatjindal:strcase-lib

Conversation

@rajatjindal

Copy link
Copy Markdown
Contributor

This PR attempts to replace the existing strcase library with a different implementation to fix #7941

In addition to replacing the library, we are moving this implementation to a local dagger package (currently under dagql folder, more on this later), so that:

  1. We can customize the behavior as per our requirement
  2. If needed, we can easily replace the backing library in future.
  3. Add unit test coverage as this transformation is critical for dagger codegen and graph functionality.

Why is this under dagql folder?

I considered a few options e.g. core, internal or a new pkg under root and dagql seemed like the best option among those. Also dagql was a common dependency for most of the places where strcase is currently used.

Although, for sdk-runtime, it seems like there is no dependency on dagger's core/dagql package, so right now we are duplicating the code from strcase pkg into those files. But this mean, they can go out of sync quickly.

how do folks feel about adding a dependency from sdk-runtime onto dagger/dagql package? (one option could be to have a separate repo under dagger, but that seemed like an overkill).

i am open to suggestions here if folks think we can move the strcase package elsewhere.

@rajatjindal
rajatjindal requested review from a team as code owners August 8, 2024 06:58
Comment thread sdk/elixir/runtime/go.mod

go 1.22

require (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the go.mod changes were triggered by running go mod tidy in the runtime folder. I am trying to identify if there is a way to update the file without triggering these unwanted changes.

@rajatjindal
rajatjindal force-pushed the strcase-lib branch 3 times, most recently from 401b865 to 2aff1aa Compare August 8, 2024 17:16
@jpadams
jpadams requested review from helderco, marcosnils and vito August 9, 2024 03:20
@rajatjindal
rajatjindal force-pushed the strcase-lib branch 5 times, most recently from 906f8c3 to aa38802 Compare August 13, 2024 02:26
Comment thread sdk/typescript/runtime/main.go Outdated
strcase.SplitAfterNumber,
)

return strcase.NewCaser(false, nil, splitFn)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is done this way to avoid dependency on dagql in runtime. But can we add this to internal package and use it from there? what do you think @jedevc @marcosnils?

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.

Although, for sdk-runtime, it seems like there is no dependency on dagger's core/dagql package, so right now we are duplicating the code from strcase pkg into those files. But this mean, they can go out of sync quickly.

Yeah, the duplication is definitely not good 😢 I like the idea of adding a dependency onto the root module, that sounds fine to me - we can then have a replace directive in elixir/typescript/python to point it back to the top (though maybe this might require a bit of a chance to how the runtime gets built).

Another potential option would be to add this into the auto-generated internal package - but I'm not a huge fan of this - since it's kind of a work-around that only we're able to do - we should try and dogfood the other approach if we can.

@wingyplus wingyplus Aug 16, 2024 •

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.

Or copy strcase under the engine directory to internal package of each runtime module when calling a generate function (dagger call sdk <sdk> generate)? So we can keep in sync with the engine and runtime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I actually like this idea. this way we may be able to omit the manual copy step. but I am not entirely sure if there are any other downsides to it.

@rajatjindal

Copy link
Copy Markdown
Contributor Author

The CI is green (finally). and I think we can review the changes now. There is one question around configuring strcase in runtime (vs dependency on dagql or adding the configuration part to internal pkg).

@jedevc jedevc 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.

Nice 🎉 left some comments, but I think the shape is mostly right! I like having our own package in front of this, keeping all this centralized is good (and means it's importable by anyone else, like an external sdk author).

One very sad question - is this a breaking change? Does this change the casing of any args/function names/modules? If so... that's annoying.

We would have to decide to either:

  • Just break 💥 It's likely these cases were kinda broken already, and maybe they're uncommon enough.
  • Add version compatibility 🎉 This is trickier, but means that we can have older modules not break, but expose the newer behavior correctly.
    • This would probably work by somehow passing engineVersion to strcase, and then we would do a semver comparison - versions before v0.12.X get the old behavior, and versions after get the new behavior.
    • This seems like a total pain to plumb it all through correctly, propagating dagger.jsons engineVersion all the way through to all the places we call this function is not very fun.

Comment thread core/integration/module_test.go Resolved
Comment thread dagql/strcase/strcase_test.go Resolved
Comment thread dagql/strcase/strcase.go Resolved
Comment thread sdk/typescript/runtime/main.go Outdated
strcase.SplitAfterNumber,
)

return strcase.NewCaser(false, nil, splitFn)

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.

Although, for sdk-runtime, it seems like there is no dependency on dagger's core/dagql package, so right now we are duplicating the code from strcase pkg into those files. But this mean, they can go out of sync quickly.

Yeah, the duplication is definitely not good 😢 I like the idea of adding a dependency onto the root module, that sounds fine to me - we can then have a replace directive in elixir/typescript/python to point it back to the top (though maybe this might require a bit of a chance to how the runtime gets built).

Another potential option would be to add this into the auto-generated internal package - but I'm not a huge fan of this - since it's kind of a work-around that only we're able to do - we should try and dogfood the other approach if we can.

@jedevc jedevc added the kind/bug Something isn't working label Aug 13, 2024
@rajatjindal

Copy link
Copy Markdown
Contributor Author

One very sad question - is this a breaking change? Does this change the casing of any args/function names/modules? If so... that's annoying.

with these changes, I didn't had to change any arg/func/module-name etc in the testcases. and with the failures I was getting with other combination of these changes, it seems like we have pretty good coverage in terms of casing (indirectly though).

The major customization we had to do with new lib is to preserve initialism in ToPascal function, so :

  • JSON remains JSON
  • Json remains Json and
  • json becomes Json

which was the behavior with existing library as well (https://go.dev/play/p/HJrH5cuDW40), which was also the source of all our failures while I tried different permutations of strcase configs with our testcases.

Having said that, maybe we can write an automation script to list all modules from our daggerverse list, and try calling their functions with new engine. Maybe we can identify some edge cases using that. what do you think?

@jedevc

jedevc commented Aug 13, 2024

Copy link
Copy Markdown
Contributor

Having said that, maybe we can write an automation script to list all modules from our daggerverse list, and try calling their functions with new engine. Maybe we can identify some edge cases using that. what do you think

Perfect, yes, that's a good idea - cc @marcosnils @matipan who have a script for this already I think 🤔

@rajatjindal

Copy link
Copy Markdown
Contributor Author

Yeah, the duplication is definitely not good 😢 I like the idea of adding a dependency onto the root module, that sounds fine to me - we can then have a replace directive in elixir/typescript/python to point it back to the top (though maybe this might require a bit of a chance to how the runtime gets built).

Another potential option would be to add this into the auto-generated internal package - but I'm not a huge fan of this - since it's kind of a work-around that only we're able to do - we should try and dogfood the other approach if we can.

how do you feel about importing github.com/dagger/dagger/engine/strcase as a dependency in runtime? given that its a separate module (after the suggestion you made), maybe we could import it.

(if we do that, we may have to do the runtime change in next PR because right now go mod tidy fails to find that new dependency in dagger github repo).

@jedevc

jedevc commented Aug 13, 2024

Copy link
Copy Markdown
Contributor

(if we do that, we may have to do the runtime change in next PR because right now go mod tidy fails to find that new dependency in dagger github repo).

This shouldn't be an issue if we set the replace directive in go.mod. sdk/elixir/runtime/go.mod can have a replace github.com/dagger/dagger/engine/strcase => ../../../engine/strcase in them.

@rajatjindal

Copy link
Copy Markdown
Contributor Author

This shouldn't be an issue if we set the replace directive in go.mod. sdk/elixir/runtime/go.mod can have a replace github.com/dagger/dagger/engine/strcase => ../../../engine/strcase in them.

ah ok. i was not sure about that (I don't completely understand the concept of runtime in sdk yet). I will make that change 👍

@rajatjindal

Copy link
Copy Markdown
Contributor Author

(if we do that, we may have to do the runtime change in next PR because right now go mod tidy fails to find that new dependency in dagger github repo).

This shouldn't be an issue if we set the replace directive in go.mod. sdk/elixir/runtime/go.mod can have a replace github.com/dagger/dagger/engine/strcase => ../../../engine/strcase in them.

it seems like this may not work? when I run a test with this, i get following error:

github.com/dagger/dagger/engine/[email protected] (replaced by ../../../engine/strcase): reading /engine/strcase/go.mod: open /engine/strcase/go.mod: no such file or directory

which means during the dagger init execution, engine code may not be copied over to the container directly?

@jedevc jedevc 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.

Some notes, I wonder if we need to do this same thing in the SDKs as well, but I suggested writing a few tests to see if we need to - we might not.

Quick note - I really like the new core/compat package, I think this is a good approach to move forward with. I like the idea of being to attach more things in the future 😄

Comment thread core/schema/module.go
Comment on lines +1180 to +1182
func (s *moduleSchema) addCompatToCtx(ctx context.Context) context.Context {
return compat.AddCompatToContext(ctx, s.dag.View)
}

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.

nit: dead code.

}
}

func (ModuleSuite) TestModuleNamingCompatFuncName(ctx context.Context, t *testctx.T) {

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.

Hm, I suspect there's still something missing here 😢

Suppose:

  • We have a dep using "new dagger" that was one of these weird cases like WithDaggerCLIAlpine
  • We have a main module that's using an "old dagger" that install WithDaggerCLIAlpine
  • What does the codegen look like for the main module? I think it probably needs to generate with the "old dagger" form.

Maybe this "just works" as is, but I'd like a test to confirm that (and ideally for go/python/typescript consumers).

If this is an issue, then the fix will be to propagate the strcase.Caser code into cmd/codegen and each of the runtime modules. Thankfully we already propagate the engineVersion into there, so hopefully wouldn't be too bad with all the context plumbing you've already done 🎉

Comment thread core/module.go
return call.NewModule(mod.InstanceID, mod.Name(), ref)
}

func (mod *Module) addCompatToCtx(ctx context.Context) (context.Context, error) {

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.

I think this isn't needed? By calling this in the server, doesn't this propagate down everywhere to where it needs to go?

Might be just leftover, but can't quite tell.

Comment thread core/typedef.go
Comment on lines +69 to +72
//this is ugly, but lets try it
if fn.ctx != nil {
cp.ctx = fn.ctx
}

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.

nit: we can remove this now, WithArg should take a context arg, as with all the other typedef methods.

Comment thread core/compat/go.mod

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.

I don't think needs to be a separate module. strcase doesn't either now, since we're going with the copy-paste approach for now.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@TomChv

TomChv commented Sep 24, 2024

Copy link
Copy Markdown
Member

What's the status of this PR? I see a lot of conflict with main, I think this one should be rebase to have a change to be merged :D

@github-actions

github-actions Bot commented Oct 9, 2024

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Oct 16, 2024
@marcosnils marcosnils reopened this Oct 17, 2024
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Oct 25, 2024
@rajatjindal rajatjindal reopened this Oct 25, 2024
@rajatjindal

Copy link
Copy Markdown
Contributor Author

apologies for losing track of this PR updates here. but I do plan to pick this one up again sometime soon.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

github-actions Bot commented Dec 2, 2024

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Dec 2, 2024
@wingyplus wingyplus reopened this Dec 6, 2024
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🖐️ Quickstart issues with Go (dagger init + dagger call)

5 participants