Compare commits

..

1 Commits

Author SHA1 Message Date
Hermes Agent
46fa181646 fix: uni-wizard v2 harness import collision (#716)
Some checks failed
Smoke Test / smoke (pull_request) Failing after 16s
Resolves #716. 'from harness import' in v2 modules resolved to
uni-wizard/harness.py instead of uni-wizard/v2/harness.py.

Fix: use importlib.util.spec_from_file_location to explicitly
load from the v2 directory, bypassing sys.path ambiguity.

Fixed files:
- uni-wizard/v2/task_router_daemon.py
- uni-wizard/v2/router.py

Before: 4 integration tests failed (ImportError)
After:  24 passed, 0 failed
2026-04-15 11:18:27 -04:00
2 changed files with 23 additions and 31 deletions

View File

@@ -17,24 +17,16 @@ from typing import Dict, Any, Optional, List
from pathlib import Path
from dataclasses import dataclass
from enum import Enum
import importlib.util
def _load_local(module_name: str, filename: str):
"""Import a module from an explicit file path, bypassing sys.path resolution."""
spec = importlib.util.spec_from_file_location(
module_name,
str(Path(__file__).parent / filename),
)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
_harness = _load_local("v2_harness", "harness.py")
UniWizardHarness = _harness.UniWizardHarness
House = _harness.House
ExecutionResult = _harness.ExecutionResult
# Import from v2 harness to avoid collision with uni-wizard/harness.py
import importlib.util as _iutil
_v2_dir = Path(__file__).parent
_spec = _iutil.spec_from_file_location("harness", _v2_dir / "harness.py")
_mod = _iutil.module_from_spec(_spec)
_spec.loader.exec_module(_mod)
UniWizardHarness = _mod.UniWizardHarness
House = _mod.House
ExecutionResult = _mod.ExecutionResult
class TaskType(Enum):

View File

@@ -8,32 +8,32 @@ import time
import sys
import argparse
import os
import importlib.util
from pathlib import Path
from datetime import datetime
from typing import Dict, List, Optional
def _load_local(module_name: str, filename: str):
"""Import a module from an explicit file path, bypassing sys.path resolution.
# Explicit imports from v2 directory to avoid namespace collision
# with uni-wizard/harness.py at the repo root level
import importlib.util as _iutil
_v2_dir = Path(__file__).parent
Prevents namespace collisions when multiple directories contain modules
with the same name (e.g. uni-wizard/harness.py vs uni-wizard/v2/harness.py).
"""
spec = importlib.util.spec_from_file_location(
module_name,
str(Path(__file__).parent / filename),
)
mod = importlib.util.module_from_spec(spec)
def _load_mod(name):
spec = _iutil.spec_from_file_location(name, _v2_dir / f"{name}.py")
mod = _iutil.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
_harness = _load_local("v2_harness", "harness.py")
_harness = _load_mod("harness")
UniWizardHarness = _harness.UniWizardHarness
House = _harness.House
ExecutionResult = _harness.ExecutionResult
from router import HouseRouter, TaskType
from author_whitelist import AuthorWhitelist
_router = _load_mod("router")
HouseRouter = _router.HouseRouter
TaskType = _router.TaskType
_whitelist = _load_mod("author_whitelist")
AuthorWhitelist = _whitelist.AuthorWhitelist
class ThreeHouseTaskRouter: