(example: ExampleScript)
| 664 | write_main_log_line(main_log, line) |
| 665 | |
| 666 | def run_single(example: ExampleScript) -> ExampleResult: |
| 667 | relpath = example.relpath |
| 668 | log_filename = f"{relpath.replace('/', '__')}.log" |
| 669 | log_path = logs_dir / log_filename |
| 670 | ensure_dirs(log_path, is_file=True) |
| 671 | |
| 672 | env = os.environ.copy() |
| 673 | env["PATH"] = command_path |
| 674 | env["PYTHONPATH"] = build_python_path(env.get("PYTHONPATH")) |
| 675 | env["EXAMPLES_ARTIFACTS_DIR"] = str(artifact_dir_for_example(relpath, artifacts_dir)) |
| 676 | if auto_mode: |
| 677 | env["EXAMPLES_INTERACTIVE_MODE"] = "auto" |
| 678 | env["APPLY_PATCH_AUTO_APPROVE"] = "1" |
| 679 | env.setdefault("SHELL_AUTO_APPROVE", "1") |
| 680 | env.setdefault("AUTO_APPROVE_MCP", "1") |
| 681 | |
| 682 | force_prompt_stream = (not auto_mode) and ("interactive" in example.tags) |
| 683 | buffer_output_local = buffer_output and not force_prompt_stream |
| 684 | buffer_lines: list[str] = [] |
| 685 | redis_server: TemporaryRedisServer | None = None |
| 686 | service_messages: list[str] = [] |
| 687 | |
| 688 | with log_path.open("w", encoding="utf-8") as per_log: |
| 689 | redis_server, service_messages = prepare_redis_for_example(relpath, env) |
| 690 | for message in service_messages: |
| 691 | per_log.write(f"[runner] {message}\n") |
| 692 | if not buffer_output_local: |
| 693 | with output_lock: |
| 694 | sys.stdout.write(f"[{relpath}] [runner] {message}\n") |
| 695 | |
| 696 | try: |
| 697 | proc = subprocess.Popen( |
| 698 | example.command, |
| 699 | cwd=ROOT_DIR, |
| 700 | stdout=subprocess.PIPE, |
| 701 | stderr=subprocess.STDOUT, |
| 702 | text=True, |
| 703 | env=env, |
| 704 | ) |
| 705 | assert proc.stdout is not None |
| 706 | |
| 707 | if force_prompt_stream: |
| 708 | at_line_start = True |
| 709 | while True: |
| 710 | char = proc.stdout.read(1) |
| 711 | if char == "": |
| 712 | break |
| 713 | per_log.write(char) |
| 714 | with output_lock: |
| 715 | if at_line_start: |
| 716 | sys.stdout.write(f"[{relpath}] ") |
| 717 | sys.stdout.write(char) |
| 718 | sys.stdout.flush() |
| 719 | at_line_start = char == "\n" |
| 720 | else: |
| 721 | for line in proc.stdout: |
| 722 | per_log.write(line) |
| 723 | if buffer_output_local: |
nothing calls this directly
no test coverage detected