(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestNamespaceSourceMap(t *testing.T) { |
| 13 | mod := &Module{NameField: "mymod"} |
| 14 | |
| 15 | t.Run("synthesizes module-name-only source map when SDK provides none", func(t *testing.T) { |
| 16 | ctx := t.Context() |
| 17 | |
| 18 | cache, err := dagql.NewCache(ctx, "", nil, nil) |
| 19 | require.NoError(t, err) |
| 20 | ctx = dagql.ContextWithCache(ctx, cache) |
| 21 | |
| 22 | root := &Query{} |
| 23 | testSrv := &moduleObjectTestServer{ |
| 24 | mockServer: &mockServer{}, |
| 25 | cache: cache, |
| 26 | root: root, |
| 27 | } |
| 28 | root.Server = testSrv |
| 29 | dag := newCoreDagqlServerForTest(t, root) |
| 30 | testSrv.dag = dag |
| 31 | |
| 32 | dag.InstallObject(dagql.NewClass(dag, dagql.ClassOpts[*SourceMap]{Typed: &SourceMap{}})) |
| 33 | dagql.Fields[*Query]{ |
| 34 | dagql.Func("sourceMap", func(_ context.Context, _ *Query, args struct { |
| 35 | Module dagql.Optional[dagql.String] `internal:"true"` |
| 36 | Filename string |
| 37 | Line int |
| 38 | Column int |
| 39 | URL dagql.Optional[dagql.String] `internal:"true"` |
| 40 | }) (*SourceMap, error) { |
| 41 | var module string |
| 42 | if args.Module.Valid { |
| 43 | module = string(args.Module.Value) |
| 44 | } |
| 45 | var url string |
| 46 | if args.URL.Valid { |
| 47 | url = string(args.URL.Value) |
| 48 | } |
| 49 | return &SourceMap{ |
| 50 | Module: module, |
| 51 | Filename: args.Filename, |
| 52 | Line: args.Line, |
| 53 | Column: args.Column, |
| 54 | URL: url, |
| 55 | }, nil |
| 56 | }), |
| 57 | }.Install(dag) |
| 58 | |
| 59 | ctx = ContextWithQuery(ctx, root) |
| 60 | ctx = engine.ContextWithClientMetadata(ctx, &engine.ClientMetadata{ |
| 61 | ClientID: "namespace-source-map-test-client", |
| 62 | SessionID: "namespace-source-map-test-session", |
| 63 | }) |
| 64 | |
| 65 | result, err := mod.namespaceSourceMap(ctx, "sub", dagql.Null[dagql.ObjectResult[*SourceMap]]()) |
| 66 | require.NoError(t, err) |
| 67 | require.True(t, result.Valid) |
| 68 | require.NotNil(t, result.Value.Self()) |
| 69 | require.Equal(t, "mymod", result.Value.Self().Module) |
nothing calls this directly
no test coverage detected