Skip to content

Commit 5a0fb25

Browse files
authored
fix(components): accept sessionfind command help (#372)
1 parent c60b1ef commit 5a0fb25

4 files changed

Lines changed: 34 additions & 8 deletions

File tree

docs/phase-355-pinned-component-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Prior path: `component_paths.installed_previous_state_path(data_root)` → `<dat
126126
| graphtrail | `<managed>/graphtrail --version` | exit 0, non-empty stdout |
127127
| graphtrail-mcp | `<managed>/graphtrail-mcp` JSON-RPC `initialize` on stdin | valid JSON-RPC response on stdout |
128128
| miseledger | `<managed>/miseledger version` | exit 0 |
129-
| sessionfind | `<managed>/sessionfind --help` | exit 0 with usage text in stdout or stderr |
129+
| sessionfind | `<managed>/sessionfind --help` | exit 0; command-syntax lines beginning with `sessionfind ` read from stdout, or legacy text containing `usage` read from stdout or stderr |
130130

131131
## File Map
132132

@@ -247,7 +247,7 @@ def smoke_stub_script(name: str) -> str:
247247
if name == "miseledger":
248248
return '#!/usr/bin/env python3\nimport sys\nif sys.argv[1:] == ["version"]:\n print("miseledger test 0.6.0")\n raise SystemExit(0)\nraise SystemExit(1)\n'
249249
if name == "sessionfind":
250-
return '#!/usr/bin/env python3\nimport sys\nif sys.argv[1:] == ["--help"]:\n print("usage: sessionfind [options]")\n raise SystemExit(2)\nraise SystemExit(1)\n'
250+
return '#!/usr/bin/env python3\nimport sys\nif sys.argv[1:] == ["--help"]:\n print("sessionfind list [--source KIND] ...")\n print("sessionfind search <query> ...")\n print("sessionfind <query> ...")\n raise SystemExit(0)\nraise SystemExit(1)\n'
251251
raise ValueError(name)
252252

253253

src/brigade/component_install.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ def _smoke_miseledger(
471471
raise ComponentInstallError(f"miseledger smoke failed: {path} version exited {completed.returncode}")
472472

473473

474+
def _sessionfind_help_is_valid(stdout: str, stderr: str) -> bool:
475+
combined = f"{stdout}{stderr}"
476+
if "usage" in combined.lower():
477+
return True
478+
return any(line.strip().startswith("sessionfind ") for line in stdout.splitlines())
479+
480+
474481
def _smoke_sessionfind(
475482
path: Path,
476483
run: Callable[..., subprocess.CompletedProcess[str]],
@@ -487,9 +494,10 @@ def _smoke_sessionfind(
487494
raise ComponentInstallError(
488495
f"sessionfind smoke failed: {path} --help exited {completed.returncode}, expected 0"
489496
)
490-
combined = f"{completed.stdout or ''}{completed.stderr or ''}"
491-
if "usage" not in combined.lower():
492-
raise ComponentInstallError(f"sessionfind smoke failed: {path} --help produced no usage text")
497+
stdout = completed.stdout or ""
498+
stderr = completed.stderr or ""
499+
if not _sessionfind_help_is_valid(stdout, stderr):
500+
raise ComponentInstallError(f"sessionfind smoke failed: {path} --help produced no help text")
493501

494502

495503
def run_post_install_smoke(

tests/component_install_helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def smoke_stub_script(name: str) -> str:
4646
if name == "sessionfind":
4747
return (
4848
'#!/usr/bin/env python3\nimport sys\nif sys.argv[1:] == ["--help"]:\n'
49-
' print("usage: sessionfind [options]")\n raise SystemExit(0)\nraise SystemExit(1)\n'
49+
' print("sessionfind list [--source KIND] ...")\n'
50+
' print("sessionfind search <query> ...")\n'
51+
' print("sessionfind <query> ...")\n'
52+
" raise SystemExit(0)\nraise SystemExit(1)\n"
5053
)
5154
raise ValueError(name)
5255

tests/test_component_install.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,11 +1096,26 @@ def test_run_post_install_smoke_rejects_miseledger_nonzero_exit(tmp_path):
10961096
run_post_install_smoke(managed)
10971097

10981098

1099+
SESSIONFIND_V060_HELP = (
1100+
"sessionfind list [--source KIND] ...\nsessionfind search <query> ...\nsessionfind <query> ...\n"
1101+
)
1102+
1103+
10991104
def test_run_post_install_smoke_accepts_sessionfind_help_exit_zero(tmp_path):
11001105
managed = _write_managed_smoke_stubs(tmp_path)
11011106
run_post_install_smoke(managed)
11021107

11031108

1109+
def test_run_post_install_smoke_accepts_sessionfind_v060_help_shape(tmp_path):
1110+
script = (
1111+
'#!/usr/bin/env python3\nimport sys\nif sys.argv[1:] == ["--help"]:\n'
1112+
f' print({SESSIONFIND_V060_HELP!r}, end="")\n raise SystemExit(0)\nraise SystemExit(1)\n'
1113+
)
1114+
managed = _write_managed_smoke_stubs(tmp_path)
1115+
managed["sessionfind"] = _write_managed_stub(tmp_path, "sessionfind", script=script)
1116+
run_post_install_smoke(managed)
1117+
1118+
11041119
def test_run_post_install_smoke_rejects_sessionfind_nonzero_exit(tmp_path):
11051120
managed = _write_managed_smoke_stubs(tmp_path)
11061121
script = smoke_stub_script("sessionfind").replace("raise SystemExit(0)", "raise SystemExit(2)", 1)
@@ -1109,14 +1124,14 @@ def test_run_post_install_smoke_rejects_sessionfind_nonzero_exit(tmp_path):
11091124
run_post_install_smoke(managed)
11101125

11111126

1112-
def test_run_post_install_smoke_rejects_sessionfind_missing_usage(tmp_path):
1127+
def test_run_post_install_smoke_rejects_sessionfind_missing_help(tmp_path):
11131128
script = (
11141129
'#!/usr/bin/env python3\nimport sys\nif sys.argv[1:] == ["--help"]:\n'
11151130
' print("options only")\n raise SystemExit(0)\nraise SystemExit(1)\n'
11161131
)
11171132
managed = _write_managed_smoke_stubs(tmp_path)
11181133
managed["sessionfind"] = _write_managed_stub(tmp_path, "sessionfind", script=script)
1119-
with pytest.raises(ComponentInstallError, match="sessionfind smoke failed.*no usage text"):
1134+
with pytest.raises(ComponentInstallError, match="sessionfind smoke failed.*no help text"):
11201135
run_post_install_smoke(managed)
11211136

11221137

0 commit comments

Comments
 (0)