Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 bundle/config/mutator/configure_wsfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (m *configureWSFS) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagno
// Writing notebooks via FUSE is only supported for serverless client version 2+.
// Since we could only test v2.5, since the platform only allows selecting v2 (which is v2.5 internally),
// we restrict FUSE to only be used for v2.5+.
v := dbr.GetVersion(ctx)
v := dbr.RuntimeVersion(ctx)
if v.Type == dbr.ClusterTypeServerless && (v.Major > 2 || (v.Major == 2 && v.Minor >= 5)) {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Stack Trace:
Version: build.GetInfo().Version,
Command: commandStr,
OperatingSystem: runtime.GOOS,
DbrVersion: dbr.RuntimeVersion(ctx),
DbrVersion: dbr.RuntimeVersion(ctx).String(),
ExecutionTimeMs: time.Since(startTime).Milliseconds(),
ExitCode: int64(exitCode),
})
Expand Down
16 changes: 8 additions & 8 deletions libs/dbr/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type Version struct {
Raw string
}

func (v Version) String() string {
return v.Raw
}

// ParseVersion parses a DBR version string and returns structured version info.
// Examples:
// - "16.3" -> Interactive, Major=16, Minor=3
Expand Down Expand Up @@ -122,17 +126,13 @@ func RunsOnRuntime(ctx context.Context) bool {
return v.(Environment).IsDbr
}

func RuntimeVersion(ctx context.Context) string {
// RuntimeVersion returns the parsed runtime version from the context.
// It expects a context returned by [DetectRuntime] or [MockRuntime].
func RuntimeVersion(ctx context.Context) Version {
v := ctx.Value(dbrKey)
if v == nil {
panic("dbr.RuntimeVersion called without calling dbr.DetectRuntime first")
}

return v.(Environment).Version
}

// GetVersion returns the parsed runtime version from the context.
// It expects a context returned by [DetectRuntime] or [MockRuntime].
func GetVersion(ctx context.Context) Version {
return ParseVersion(RuntimeVersion(ctx))
return ParseVersion(v.(Environment).Version)
}
21 changes: 16 additions & 5 deletions libs/dbr/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func TestContext_RunsOnRuntimeWithMock(t *testing.T) {

func TestContext_RuntimeVersionWithMock(t *testing.T) {
ctx := context.Background()
assert.Equal(t, "15.4", RuntimeVersion(MockRuntime(ctx, Environment{IsDbr: true, Version: "15.4"})))
assert.Empty(t, RuntimeVersion(MockRuntime(ctx, Environment{})))
assert.Equal(t, "15.4", RuntimeVersion(MockRuntime(ctx, Environment{IsDbr: true, Version: "15.4"})).String())
assert.Empty(t, RuntimeVersion(MockRuntime(ctx, Environment{})).String())
}

func TestParseVersion_Serverless(t *testing.T) {
Expand Down Expand Up @@ -153,19 +153,30 @@ func TestClusterType_String(t *testing.T) {
assert.Equal(t, "unknown", ClusterTypeUnknown.String())
}

func TestContext_GetVersion(t *testing.T) {
func TestVersion_String(t *testing.T) {
v := ParseVersion("16.3")
assert.Equal(t, "16.3", v.String())

v = ParseVersion("client.4.9")
assert.Equal(t, "client.4.9", v.String())

v = ParseVersion("")
assert.Equal(t, "", v.String())
}

func TestContext_RuntimeVersionParsed(t *testing.T) {
ctx := context.Background()

// Test serverless version
serverlessCtx := MockRuntime(ctx, Environment{IsDbr: true, Version: "client.4.9"})
v := GetVersion(serverlessCtx)
v := RuntimeVersion(serverlessCtx)
assert.Equal(t, ClusterTypeServerless, v.Type)
assert.Equal(t, 4, v.Major)
assert.Equal(t, 9, v.Minor)

// Test interactive version
interactiveCtx := MockRuntime(ctx, Environment{IsDbr: true, Version: "17.3"})
v = GetVersion(interactiveCtx)
v = RuntimeVersion(interactiveCtx)
assert.Equal(t, ClusterTypeInteractive, v.Type)
assert.Equal(t, 17, v.Major)
assert.Equal(t, 3, v.Minor)
Expand Down