MCPcopy Create free account
hub / github.com/atripati/ark / executeJavaScript

Function executeJavaScript

pkg/runtime/verify.go:465–501  ·  view source on GitHub ↗
(code string)

Source from the content-addressed store, hash-verified

463 result := &CodeExecResult{Language: "javascript"}
464 start := time.Now()
465
466 if _, err := exec.LookPath("node"); err != nil {
467 return nil
468 }
469
470 dir, err := os.MkdirTemp("", "ark-verify-*")
471 if err != nil {
472 return nil
473 }
474 defer os.RemoveAll(dir)
475
476 filePath := filepath.Join(dir, "verify.js")
477 if err := os.WriteFile(filePath, []byte(code), 0644); err != nil {
478 return nil
479 }
480
481 // Syntax check
482 syntaxCmd := exec.Command("node", "--check", filePath)
483 syntaxOutput, syntaxErr := syntaxCmd.CombinedOutput()
484 result.Duration = time.Since(start)
485
486 if syntaxErr != nil {
487 result.Compiled = false
488 result.Error = cleanCompilerError(string(syntaxOutput))
489 return result
490 }
491 result.Compiled = true
492
493 // Run
494 result.Ran = runWithTimeout(dir, "node", []string{filePath}, result, 10*time.Second)
495 result.Linted = true
496
497 return result
498}
499
500type testResult struct {
501 passed bool
502 output string
503}
504

Callers 1

executeAndTestFunction · 0.85

Calls 2

cleanCompilerErrorFunction · 0.85
runWithTimeoutFunction · 0.85

Tested by

no test coverage detected