Skip to content

Commit 46a093c

Browse files
committed
fix: preserve telemetry failure isolation
1 parent 9d6c4a2 commit 46a093c

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

scripts/invocation_observation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def extract_command(
3939
if token == "--project-root":
4040
if index + 1 >= len(argv):
4141
return NO_COMMAND
42+
value = argv[index + 1]
43+
if value in {"-h", "--help"}:
44+
return NO_COMMAND
45+
if value.startswith("-"):
46+
return UNKNOWN_COMMAND
4247
index += 2
4348
continue
4449
if token.startswith("--project-root="):
@@ -108,8 +113,8 @@ def _connect(database: Path) -> sqlite3.Connection:
108113
def _begin(surface: str, command: str) -> tuple[Path, int] | None:
109114
if os.environ.get(DISABLE_ENV) == "0":
110115
return None
111-
database = _database_path()
112116
try:
117+
database = _database_path()
113118
with closing(_connect(database)) as connection:
114119
with connection:
115120
cursor = connection.execute(
@@ -121,7 +126,7 @@ def _begin(surface: str, command: str) -> tuple[Path, int] | None:
121126
)
122127
row_id = int(cursor.lastrowid)
123128
return database, row_id
124-
except (OSError, sqlite3.Error):
129+
except (OSError, RuntimeError, sqlite3.Error):
125130
return None
126131

127132

tests/test_invocation_observation.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def test_surface_aware_command_extraction_never_persists_option_values() -> None
5757
"orch", ["--project-root=/private/path", "doctor"], recognized
5858
) == "doctor"
5959
assert observation.extract_command("orch", ["--help", "doctor"], recognized) == "__no_command__"
60+
assert observation.extract_command(
61+
"orch", ["--project-root", "--help", "doctor"], recognized
62+
) == "__no_command__"
63+
assert observation.extract_command(
64+
"orch", ["--project-root", "--unknown", "doctor"], recognized
65+
) == "__unknown__"
6066
assert observation.extract_command("orch", ["--project", "/secret", "doctor"], recognized) == "__unknown__"
6167

6268

@@ -148,6 +154,17 @@ def test_database_failure_is_silent_and_does_not_change_dispatch(
148154
assert capsys.readouterr() == ("", "")
149155

150156

157+
def test_config_root_resolution_failure_is_silent_and_does_not_change_dispatch(
158+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
159+
) -> None:
160+
observation = load_observation()
161+
monkeypatch.setenv("WORK_BUNDLE_INVOCATION_LOG", "1")
162+
monkeypatch.setenv("WB_CONFIG_ROOT", "~workbundle-user-that-does-not-exist/usage")
163+
164+
assert observation.invoke_observed("wb", ["doctor"], {"doctor"}, lambda: 7) == 7
165+
assert capsys.readouterr() == ("", "")
166+
167+
151168
@pytest.mark.parametrize(("filename", "surface"), [("wb.py", "wb"), ("orch.py", "orch")])
152169
def test_public_wrappers_observe_once(
153170
enabled: Path, monkeypatch: pytest.MonkeyPatch, filename: str, surface: str

0 commit comments

Comments
 (0)