MCPcopy Create free account
hub / github.com/circlefin/arc-node / run

Method run

scripts/md-exec.py:370–567  ·  view source on GitHub ↗
(self, tests, file_path)

Source from the content-addressed store, hash-verified

368 self.last_exit_code = 0
369
370 def run(self, tests, file_path):
371 passed = 0
372 failed = 0
373
374 print(f"Running {len(tests)} code snippets...\n")
375
376 for test in tests:
377 print(f"▶️ {file_path}:{test.line_number}: {test.command} ... ", end='', flush=True)
378
379 with tempfile.NamedTemporaryFile(mode='w+', delete=False) as env_dump:
380 env_dump_path = env_dump.name
381
382 state_dumper = (
383 f"{sys.executable} -c "
384 f"'import os, json; "
385 f"d=dict(os.environ); "
386 f"d[\"__CWD__\"]=os.getcwd(); "
387 f"d[\"__EXIT__\"]=os.getenv(\"__RET\", \"0\"); "
388 f"print(json.dumps(d))' > {env_dump_path}"
389 )
390
391 # Set OLDPWD for 'cd -' support
392 self.env["OLDPWD"] = self.oldpwd
393
394 # Handle pushd/popd specially since each command runs in a fresh shell
395 command = test.command
396 command_stripped = command.strip()
397
398 if command_stripped.startswith("pushd "):
399 # pushd: save current dir to stack, then cd
400 target_dir = command_stripped[6:].strip()
401 self.dirstack.append(self.cwd)
402 # Let the shell do the pushd, but we track the stack ourselves
403 elif command_stripped == "popd":
404 if self.dirstack:
405 # Replace popd with cd to the popped directory
406 popped = self.dirstack.pop()
407 command = f"cd {popped}"
408
409 # Export OLDPWD for 'cd -' support (must be shell variable, not just env)
410 full_command = (
411 f"export OLDPWD='{self.oldpwd}'\n"
412 f"(exit {self.last_exit_code})\n"
413 f"{command}\n"
414 f"export __RET=$?\n"
415 f"{state_dumper}"
416 )
417
418 stream_output = test.options.get("print_command_output", False)
419 if stream_output:
420 print() # Start output on new line if streaming
421
422 start_time = time.time()
423 try:
424 # Use Popen to allow streaming, use bash for better OLDPWD/pushd/popd support
425 with subprocess.Popen(
426 full_command,
427 shell=True,

Callers 1

md-exec.pyFile · 0.45

Calls 6

check_matchMethod · 0.95
appendMethod · 0.80
loadMethod · 0.80
getMethod · 0.45
killMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected