(ctx context.Context, sessionID string, cwd string, language string, code string)
| 1379 | } |
| 1380 | |
| 1381 | func preflightSandboxClientCode(ctx context.Context, sessionID string, cwd string, language string, code string) error { |
| 1382 | if strings.TrimSpace(sessionID) == "" || strings.TrimSpace(code) == "" { |
| 1383 | return nil |
| 1384 | } |
| 1385 | spec, ok := sandboxRuntimeSyntaxCheckSpecForLanguage(language) |
| 1386 | if !ok { |
| 1387 | return nil |
| 1388 | } |
| 1389 | code = normalizeSandboxTextContentForLanguage(language, code) |
| 1390 | |
| 1391 | tempPath := filepath.ToSlash(filepath.Join("tmp", "preflight", fmt.Sprintf("snippet-%d%s", time.Now().UnixNano(), spec.extension))) |
| 1392 | if _, err := getSandboxClient().WriteFile(ctx, sandboxclient.FileWriteRequest{ |
| 1393 | Path: tempPath, |
| 1394 | Content: code, |
| 1395 | SessionID: sessionID, |
| 1396 | Cwd: cwd, |
| 1397 | }); err != nil { |
| 1398 | return wrapSandboxServiceError(err) |
| 1399 | } |
| 1400 | defer cleanupSandboxClientTempFile(ctx, sessionID, cwd, tempPath) |
| 1401 | |
| 1402 | if err := formatSandboxClientWrittenFile(ctx, sessionID, cwd, tempPath); err != nil { |
| 1403 | return err |
| 1404 | } |
| 1405 | if err := validateSandboxClientWrittenFile(ctx, sessionID, cwd, tempPath); err != nil { |
| 1406 | return err |
| 1407 | } |
| 1408 | return nil |
| 1409 | } |
| 1410 | |
| 1411 | func cleanupSandboxClientTempFile(ctx context.Context, sessionID string, cwd string, path string) { |
| 1412 | if strings.TrimSpace(sessionID) == "" || strings.TrimSpace(path) == "" { |
no test coverage detected