Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/boxcli/midcobra/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ func getPackagesAndCommitHash(c *cobra.Command) ([]string, string) {
}

return box.AllPackageNamesIncludingRemovedTriggerPackages(),
box.Config().NixPkgsCommitHash()
box.Lockfile().Stdenv().Rev
}
47 changes: 47 additions & 0 deletions internal/boxcli/midcobra/telemetry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package midcobra

import (
"testing"

"github.com/spf13/cobra"
"go.jetify.com/devbox/internal/devbox"
"go.jetify.com/devbox/internal/devbox/devopt"
)

func TestGetPackagesAndCommitHash(t *testing.T) {
dir := t.TempDir()
err := devbox.InitConfig(dir)
if err != nil {
t.Errorf("Expected no error, got %s", err)
}
box, err := devbox.Open(&devopt.Opts{
Dir: dir,
})
// Create a mock cobra command
cmd := &cobra.Command{
Use: "test",
Run: func(cmd *cobra.Command, args []string) {},
}

// Add a mock flag to the command
cmd.Flags().String("config", "", "config file")
if err := cmd.Flags().Set("config", dir); err != nil {
t.Errorf("Expected no error, got %s", err)
}

// Call the function with the mock command
packages, commitHash := getPackagesAndCommitHash(cmd)

// Check if the returned packages and commitHash are as expected
if len(packages) != 0 {
t.Errorf("Expected no packages, got %d", len(packages))
}

if err != nil {
t.Errorf("Expected no error, got %s", err)
}

if commitHash != box.Lockfile().Stdenv().Rev {
t.Errorf("Expected commitHash %s, got %s", box.Lockfile().Stdenv().Rev, commitHash)
}
}
4 changes: 2 additions & 2 deletions internal/shellgen/flake_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ type glibcPatchFlake struct {
Dependencies []string
}

func newGlibcPatchFlake(nixpkgsGlibcRev string, packages []*devpkg.Package) (glibcPatchFlake, error) {
func newGlibcPatchFlake(nixpkgs flake.Ref, packages []*devpkg.Package) (glibcPatchFlake, error) {
patchFlake := glibcPatchFlake{
DevboxFlake: flake.Ref{
Type: flake.TypeGitHub,
Owner: "jetify-com",
Repo: "devbox",
Ref: build.Version,
},
NixpkgsGlibcFlakeRef: "flake:nixpkgs/" + nixpkgsGlibcRev,
NixpkgsGlibcFlakeRef: nixpkgs.String(),
}

// In dev builds, use the local Devbox flake for patching packages
Expand Down
57 changes: 57 additions & 0 deletions internal/shellgen/flake_plan_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package shellgen

import (
"testing"

"go.jetify.com/devbox/internal/devbox/devopt"
"go.jetify.com/devbox/internal/devconfig/configfile"
"go.jetify.com/devbox/internal/devpkg"
"go.jetify.com/devbox/internal/lock"
"go.jetify.com/devbox/nix/flake"
)

type lockMock struct{}

func (l *lockMock) Get(key string) *lock.Package {
return nil
}

func (l *lockMock) Stdenv() flake.Ref {
return flake.Ref{}
}

func (l *lockMock) ProjectDir() string {
return ""
}

func (l *lockMock) Resolve(key string) (*lock.Package, error) {
return &lock.Package{
Resolved: "github:NixOS/nixpkgs/10b813040df67c4039086db0f6eaf65c536886c6#python312",
}, nil
}

func TestNewGlibcPatchFlake(t *testing.T) {
stdenv := flake.Ref{
Type: flake.TypeGitHub,
URL: "https://github.com/NixOS/nixpkgs",
Ref: "nixpkgs-unstable",
}

packages := devpkg.PackagesFromStringsWithOptions([]string{"python@latest"}, &lockMock{}, devopt.AddOpts{
Patch: string(configfile.PatchAlways),
})

patchFlake, err := newGlibcPatchFlake(stdenv, packages)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}

if patchFlake.NixpkgsGlibcFlakeRef != stdenv.String() {
t.Errorf("expected NixpkgsGlibcFlakeRef to be %s, got %s", stdenv.String(), patchFlake.NixpkgsGlibcFlakeRef)
}

if len(patchFlake.Outputs.Packages) != 1 {
t.Errorf("expected 1 package in Outputs, got %d", len(patchFlake.Outputs.Packages))
}

}
2 changes: 1 addition & 1 deletion internal/shellgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GenerateForPrintEnv(ctx context.Context, devbox devboxer) error {
}

if plan.needsGlibcPatch() {
patch, err := newGlibcPatchFlake(devbox.Config().NixPkgsCommitHash(), plan.Packages)
patch, err := newGlibcPatchFlake(devbox.Lockfile().Stdenv(), plan.Packages)
if err != nil {
return redact.Errorf("generate glibc patch flake: %v", err)
}
Expand Down
Loading