Repository navigation
fix(apps): close six review defects in host, compare, delivery and views #605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ | |
| from .codex_tool_returns import _output_lines, _path, correlate_window | ||
|
|
||
| _SHELLS = ("sh", "bash", "zsh", "dash") | ||
| # Interpreters whose inline code this reader does not tokenize. | ||
| _OPAQUE_SHELLS = ("pwsh", "powershell", "cmd", "fish") | ||
| _TOOLS = ("rg", "cat", "sed", "nl") | ||
| _SHELL_OPERATORS = {"|", "||", "&&", ";", ">", ">>", "<"} | ||
| _MAX_PASSAGES = 12 | ||
|
|
@@ -196,17 +198,55 @@ def _rg_hits(output, cwd, corpus, scopes, mode, with_filename): | |
| return [{"ref": ref, "match_line": line} for ref, line in hits.items()], complete | ||
|
|
||
|
|
||
| def _program(word): | ||
| """Program name of a recorded argv word from either OS, lower-cased, without .exe.""" | ||
| return re.split(r"[\\/]", word)[-1].lower().removesuffix(".exe") | ||
|
|
||
|
|
||
| def _without_env(argv): | ||
| """Drop a leading `env` and its NAME=value words; None for env options it cannot read.""" | ||
| if _program(argv[0]) != "env": | ||
| return argv | ||
| rest = argv[1:] | ||
| while rest and "=" in rest[0] and not rest[0].startswith("-"): | ||
| rest = rest[1:] | ||
| return rest if rest and not rest[0].startswith("-") else None | ||
|
|
||
|
|
||
| def _shell_script(options): | ||
| """Return a shell's inline `-c` script, or None when it runs no inline script.""" | ||
| words = iter(options) | ||
| for word in words: | ||
| if word == "--": | ||
| return None # What follows is a script file, even if it looks like -c. | ||
| if word in ("-o", "+o"): | ||
| next(words, None) | ||
| elif word.startswith("-") and not word.startswith("--") and "c" in word[1:]: | ||
| return next(words, None) | ||
| elif not word.startswith(("-", "+")): | ||
| return None # A script file or another operand. | ||
| return None | ||
|
|
||
|
|
||
| def _recorded_argv(item): | ||
| original_argv = item.get("command") | ||
| if (not isinstance(original_argv, list) or not original_argv | ||
| or not all(isinstance(arg, str) for arg in original_argv)): | ||
| return None, False | ||
| argv = original_argv | ||
| argv = _without_env(original_argv) | ||
| if not argv: | ||
| return None, False | ||
| multiline = False | ||
| if (Path(argv[0]).name in _SHELLS and len(argv) == 3 | ||
| and argv[1] in ("-c", "-lc", "-ic", "-ilc")): | ||
| shell = _program(argv[0]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could a shell still present after one unwrap remain opaque? A direct shell that runs an unread script is now incomplete, but wrapping that same shell command in an outer shell can leave the inner shell in argv; the caller then reports complete/no retrieval without reading the script. Please mark an undecoded inner shell incomplete and test direct vs wrapped parity. |
||
| if shell in _OPAQUE_SHELLS: | ||
| return None, False | ||
| if shell in _SHELLS: | ||
| script = _shell_script(argv[1:]) | ||
| if script is None: | ||
| # Code this reader cannot see may still have searched. | ||
| return None, False | ||
| try: | ||
| argv, multiline = _shell_argv(argv[2]) | ||
| argv, multiline = _shell_argv(script) | ||
| except ValueError: | ||
| return None, False | ||
| compound = multiline or any(word in _SHELL_OPERATORS for word in argv) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import pytest | ||
|
|
||
| from inferrsi.apps.views.codex_search import _command, _recorded_argv | ||
|
|
||
| PLAIN = ["bash", "-lc", "rg -n needle docs"] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("wrapped", [ | ||
| ["bash", "-o", "pipefail", "-lc", "rg -n needle docs"], | ||
| ["/usr/bin/env", "bash", "-lc", "rg -n needle docs"], | ||
| ["env", "LC_ALL=C", "bash", "-e", "-lc", "rg -n needle docs"], | ||
| # Recorded on Windows, read on any OS. | ||
| ["C:\\Program Files\\Git\\bin\\bash.exe", "-lc", "rg -n needle docs"], | ||
| ["C:\\Program Files\\Git\\usr\\bin\\env.exe", "bash", "-lc", "rg -n needle docs"], | ||
| ]) | ||
| def test_wrapped_shell_forms_decode_like_the_plain_form(wrapped): | ||
| assert _recorded_argv({"command": PLAIN}) == (["rg", "-n", "needle", "docs"], False) | ||
| assert _recorded_argv({"command": wrapped}) == _recorded_argv({"command": PLAIN}) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("command", [ | ||
| ["pwsh", "-Command", "rg -n needle docs"], | ||
| ["bash", "search.sh"], | ||
| ["env", "-i", "bash", "-lc", "rg -n needle docs"], | ||
| # After --, -c is a script file name, not inline code. | ||
| ["bash", "--", "-c", "rg -n needle docs"], | ||
| # Recorded on Windows, read on any OS. | ||
| ["C:\\Program Files\\PowerShell\\7\\pwsh.exe", "-Command", "rg -n needle docs"], | ||
| ["C:\\Tools\\env.exe", "C:\\Program Files\\PowerShell\\7\\pwsh.exe", "-Command", | ||
| "rg -n needle docs"], | ||
| ]) | ||
| def test_unreadable_shell_forms_stay_incomplete(tmp_path, command): | ||
| # A search this reader cannot decode must not count as complete coverage. | ||
| item = {"command": command, "exit_code": 0, "aggregated_output": ""} | ||
| assert _command(item, tmp_path) == (None, False, None) | ||
|
|
||
|
|
||
| def test_dash_c_after_double_dash_names_a_script_file(): | ||
| # bash -- -c runs a script file named -c, so no inline code is visible. | ||
| assert _recorded_argv({"command": ["bash", "--", "-c", "rg -n needle docs"]}) == (None, False) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from inferrsi.apps.views.dashboard import _write_view_document, render_dashboard | ||
|
|
||
|
|
||
| def test_service_reuse_page_can_be_rewritten_by_the_dashboard_writer(tmp_path): | ||
| # write_dashboard renders this page and replaces only pages it recognizes as its own. | ||
| snapshot = {"data": {"evaluation_mode": "service_reuse"}, "chart": "<svg></svg>"} | ||
| page = render_dashboard(snapshot) | ||
| output = tmp_path / "dashboard.html" | ||
| assert _write_view_document(output, page, generator="InferRSI dashboard") == output | ||
| assert _write_view_document(output, page, generator="InferRSI dashboard") == output | ||
| assert output.read_text(encoding="utf-8") == page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please stop scanning shell options at
--. A later-ccan be a script filename rather than an inline-code flag. The current loop can read the following argument as inline code and report complete provenance even though it never saw the script. Please retain the incomplete status for this form and add a regression.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
ef8cda3._shell_script()now stops at--and returns no inline script, sobash -- -c ...is recorded as incomplete.Two regressions cover it:
test_dash_c_after_double_dash_names_a_script_filechecks_recorded_argvdirectly. It failed against the previous source on H200: that source decodedrg -n needle docsas inline code.test_unreadable_shell_forms_stay_incompletealso covers this form.