Skip to content

ModuleSource.withDependencies rejects directory-backed module sources #13152

Open

Description

@shykes

Summary

ModuleSource.withDependencies fails when the target module source is created with Directory.asModuleSource.

This is not specific to module execution. It reproduces from a normal Dagger client. A nested helper does not avoid the bug if it constructs module sources with Directory.asModuleSource, because the resulting source kind is DIR_SOURCE.

Repro

Requirements: Go and the Dagger CLI.

tmp="$(mktemp -d)"
cd "$tmp"

mkdir -p app lib

cat > app/dagger.json <<EOF
{
  "name": "app",
  "engineVersion": "latest",
  "sdk": { "source": "go" }
}
EOF

cat > app/main.go <<EOF
package main

type App struct{}
EOF

cat > lib/dagger.json <<EOF
{
  "name": "lib",
  "engineVersion": "latest",
  "sdk": { "source": "go" }
}
EOF

cat > lib/main.go <<EOF
package main

type Lib struct{}
EOF

cat > repro.go <<EOF
package main

import (
	"context"
	"fmt"
	"os"

	"dagger.io/dagger"
)

func main() {
	ctx := context.Background()

	client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
	if err != nil {
		panic(err)
	}
	defer client.Close()

	src := client.Host().Directory(".", dagger.HostDirectoryOpts{
		Include: []string{"app/**", "lib/**"},
	})

	app := src.AsModuleSource(dagger.DirectoryAsModuleSourceOpts{
		SourceRootPath: "app",
	})

	lib := src.AsModuleSource(dagger.DirectoryAsModuleSourceOpts{
		SourceRootPath: "lib",
	}).WithName("lib")

	updated := app.WithDependencies([]*dagger.ModuleSource{lib})

	id, err := updated.ID(ctx)
	if err != nil {
		fmt.Fprintf(os.Stderr, "withDependencies failed: %v\n", err)
		os.Exit(1)
	}

	fmt.Println(id)
}
EOF

go mod init repro
go get dagger.io/dagger
go run .

Expected

withDependencies accepts the local directory-backed dependency and returns an updated module source.

Actual

withDependencies failed: unhandled module source kind: DIR_SOURCE

Notes

This appears to be a validation gap. moduleConfigDependencyForRelatedSource already handles DIR_SOURCE -> DIR_SOURCE and can compute the relative dependency source path. The failure happens earlier, in validateAndCollectRelatedModules, which rejects DIR_SOURCE.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions