gemini-code-assist[bot] commented on code in PR #37673:
URL: https://github.com/apache/beam/pull/37673#discussion_r2880927308


##########
sdks/go/pkg/beam/runners/dot/dot.go:
##########
@@ -42,14 +47,74 @@ func Execute(ctx context.Context, p *beam.Pipeline) 
(beam.PipelineResult, error)
                return nil, errors.New("must supply dot_file argument")
        }
 
-       edges, nodes, err := p.Build()
+       edges, _, err := p.Build()
        if err != nil {
                return nil, errors.New("can't get data to render")
        }
 
-       var buf bytes.Buffer
-       if err := dotlib.Render(edges, nodes, &buf); err != nil {
+       pipeline, err := graphx.Marshal(edges, &graphx.Options{})
+       if err != nil {
                return nil, err
        }
+
+       var buf bytes.Buffer
+       buf.WriteString("digraph G {\n")
+
+       components := pipeline.GetComponents()
+       if components == nil {
+               return nil, errNoComponents
+       }
+
+       transforms := components.GetTransforms()
+

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   If `pipeline.GetComponents()` returns a non-nil `Components` but with a nil 
or empty `Transforms` map, `pipelinex.TopologicalSort` could panic if 
`pipeline.GetRootTransformIds()` returns a non-empty slice. It's safer to 
handle the case of no transforms explicitly to prevent a potential panic.
   
   ```go
        transforms := components.GetTransforms()
        if len(transforms) == 0 {
                buf.WriteString("}\n")
                return nil, os.WriteFile(*dotFile, buf.Bytes(), 0644)
        }
   
   ```



##########
sdks/go/pkg/beam/runners/dot/dot_test.go:
##########
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package dot
+
+import (
+       "context"
+       "os"
+       "strings"
+       "testing"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert"
+)
+
+func TestDotRunner_GeneratesDeterministicOutput(t *testing.T) {
+       ctx := context.Background()
+
+       // Create temporary DOT file
+       tmpFile, err := os.CreateTemp("", "dot_test_*.dot")
+       if err != nil {
+               t.Fatalf("failed to create temp file: %v", err)
+       }
+       defer os.Remove(tmpFile.Name())
+
+       // Set flag manually
+       *dotFile = tmpFile.Name()
+
+       // Build simple pipeline
+       p, s := beam.NewPipelineWithRoot()
+
+       col := beam.Create(s, "a", "b", "c")
+       passert.Count(s, col, "", 3)
+
+       // Run with dot runner
+       _, err = Execute(ctx, p)
+       if err != nil {
+               t.Fatalf("Execute failed: %v", err)
+       }
+
+       // Read generated file
+       data, err := os.ReadFile(tmpFile.Name())
+       if err != nil {
+               t.Fatalf("failed to read dot file: %v", err)
+       }
+
+       content := string(data)
+
+       if !strings.HasPrefix(content, "digraph G {") {
+               t.Fatalf("dot output missing header")
+       }
+
+       if !strings.Contains(content, "->") {
+               t.Fatalf("dot output contains no edges")
+       }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The test name is `TestDotRunner_GeneratesDeterministicOutput`, but it 
doesn't actually verify determinism. It only performs a basic smoke test. To 
properly test for determinism, you could run the generation twice with 
identical pipelines and assert that the outputs are identical. This would make 
the test more aligned with its name and more robust.
   
   ```go
        // Run with dot runner
        _, err = Execute(ctx, p)
        if err != nil {
                t.Fatalf("Execute failed: %v", err)
        }
   
        // Read generated file
        data1, err := os.ReadFile(tmpFile.Name())
        if err != nil {
                t.Fatalf("failed to read dot file: %v", err)
        }
   
        content1 := string(data1)
   
        if !strings.HasPrefix(content1, "digraph G {") {
                t.Fatalf("dot output missing header")
        }
   
        if !strings.Contains(content1, "->") {
                t.Fatalf("dot output contains no edges")
        }
   
        // Run again on a new identical pipeline to check for determinism.
        p2, s2 := beam.NewPipelineWithRoot()
        col2 := beam.Create(s2, "a", "b", "c")
        passert.Count(s2, col2, "", 3)
   
        _, err = Execute(ctx, p2)
        if err != nil {
                t.Fatalf("Execute on second pipeline failed: %v", err)
        }
        data2, err := os.ReadFile(tmpFile.Name())
        if err != nil {
                t.Fatalf("failed to read dot file on second run: %v", err)
        }
   
        if content1 != string(data2) {
                t.Errorf("output is not deterministic. Run 1:\n%s\nRun 2:\n%s", 
content1, string(data2))
        }
   ```



##########
sdks/go/pkg/beam/core/util/dot/dot.go:
##########
@@ -14,6 +14,9 @@
 // limitations under the License.
 
 // Package dot produces DOT graphs from Beam graph representations.
+//
+// Deprecated:This package is no longer used by the Beam Go SDK.

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   According to Go's style guide for comments, there should be a space after 
the colon in a `Deprecated:` notice. This improves readability.
   
   ```suggestion
   // Deprecated: This package is no longer used by the Beam Go SDK.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to