Skip to content

Commit

Permalink
feat(agent): Playwright Output (#3925)
Browse files Browse the repository at this point in the history
* feat(agent): Playwright Output

* fixing package
  • Loading branch information
xoscar authored Jul 8, 2024
1 parent 397b26b commit 90116ff
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 81 deletions.
139 changes: 74 additions & 65 deletions agent/proto/orchestrator.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agent/proto/orchestrator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,5 @@ message PlaywrightEngineRequest {

message PlaywrightEngineResponse {
bool success = 1;
string out = 2;
}
22 changes: 17 additions & 5 deletions agent/workers/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,12 @@ func convertResponseToProtoResponse(request *proto.TriggerRequest, response trig
TestID: request.TestID,
RunID: request.RunID,
TriggerResult: &proto.TriggerResult{
Type: string(response.Result.Type),
Http: convertHttpResponseToProto(response.Result.HTTP),
Grpc: convertGrpcResponseToProto(response.Result.GRPC),
TraceID: convertTraceIDResponseToProto(response.Result.TraceID),
Kafka: convertKafkaResponseToProto(response.Result.Kafka),
Type: string(response.Result.Type),
Http: convertHttpResponseToProto(response.Result.HTTP),
Grpc: convertGrpcResponseToProto(response.Result.GRPC),
TraceID: convertTraceIDResponseToProto(response.Result.TraceID),
Kafka: convertKafkaResponseToProto(response.Result.Kafka),
PlaywrightEngine: convertPlaywrightEngineResponseToProto(response.Result.PlaywrightEngine),
},
}
}
Expand Down Expand Up @@ -426,3 +427,14 @@ func convertKafkaResponseToProto(kafka *trigger.KafkaResponse) *proto.KafkaRespo
Offset: kafka.Offset,
}
}

func convertPlaywrightEngineResponseToProto(playwerightEngine *trigger.PlaywrightEngineResponse) *proto.PlaywrightEngineResponse {
if playwerightEngine == nil {
return nil
}

return &proto.PlaywrightEngineResponse{
Success: playwerightEngine.Success,
Out: playwerightEngine.Out,
}
}
23 changes: 13 additions & 10 deletions agent/workers/trigger/playwrightengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
)

var (
node = "node"
app = "npx"
node = "node"
app = "npx"
// libName = "../../tracetest-js/packages/tracetest-playwright-engine"
libName = "@tracetest/playwright-engine"
scriptPath = "script.js"
)
Expand Down Expand Up @@ -42,14 +43,15 @@ func (te *playwrightTriggerer) Trigger(ctx context.Context, triggerConfig Trigge
return response, err
}

err = start(opts.TraceID.String(), opts.SpanID.String(), triggerConfig.PlaywrightEngine.Target, triggerConfig.PlaywrightEngine.Method)
out, err := start(opts.TraceID.String(), opts.SpanID.String(), triggerConfig.PlaywrightEngine.Target, triggerConfig.PlaywrightEngine.Method)
if err != nil {
os.Remove(scriptPath)
return response, err
}

os.Remove(scriptPath)
response.Result.PlaywrightEngine.Success = true
response.Result.PlaywrightEngine.Out = out
return response, err
}

Expand All @@ -73,10 +75,10 @@ func validate() error {
return nil
}

func start(traceId, spanId, url, method string) error {
func start(traceId, spanId, url, method string) (string, error) {
wd, err := os.Getwd()
if err != nil {
return err
return "", err
}

res, err := execCommand(
Expand All @@ -86,12 +88,12 @@ func start(traceId, spanId, url, method string) error {
)

if err != nil {
return fmt.Errorf("error installing playwright: %s, %w", res, err)
return "", fmt.Errorf("error installing playwright: %s, %w", res, err)
}

path, err := filepath.Abs(fmt.Sprintf("%s/%s", wd, scriptPath))
if err != nil {
return err
return "", err
}

res, err = execCommand(
Expand All @@ -109,10 +111,10 @@ func start(traceId, spanId, url, method string) error {
method)

if err != nil {
return fmt.Errorf("error executing playwright engine: %s, %w", res, err)
return "", fmt.Errorf("error executing playwright engine: %s, %w", res, err)
}

return nil
return res, nil
}

func execCommand(name string, args ...string) (string, error) {
Expand All @@ -138,5 +140,6 @@ type PlaywrightEngineRequest struct {
}

type PlaywrightEngineResponse struct {
Success bool `json:"success"`
Success bool `json:"success"`
Out string `json:"out"`
}
2 changes: 2 additions & 0 deletions api/playwrightengine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ components:
properties:
success:
type: boolean
out:
type: string
38 changes: 37 additions & 1 deletion cli/openapi/model_playwright_engine_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 90116ff

Please sign in to comment.