-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add option to control tool detail card collapsed/expanded state #137
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
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9a1b6a0
feat: add option to control tool detail card collapsed/expanded state
gadenbuie f9ac4da
refactor: simplify tool open state logic
gadenbuie 7fa4c9b
chore: py-format
gadenbuie b3e1cd1
refactor: rename resolve_tool_open_state to querychat_tool_starts_open
gadenbuie 59f49dc
refactor: move validation logic and reorganize functions
gadenbuie 1b56261
style: remove unnecessary comments from new functions
gadenbuie 0f34878
chore: small edits
gadenbuie 3269abc
chore(py): Better typing
gadenbuie c39f8e9
docs: add NEWS/CHANGELOG entries for tool details feature
gadenbuie 4d78b5d
chore(pkg-py): fix types
gadenbuie 78b31bf
chore: fix changelog
gadenbuie b4f52d9
chore: remove changes to duplicate changelog
gadenbuie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Tests for tool functions and utilities.""" | ||
|
|
||
| import warnings | ||
|
|
||
| from querychat._utils import querychat_tool_starts_open | ||
|
|
||
|
|
||
| def test_querychat_tool_starts_open_default_behavior(monkeypatch): | ||
| """Test default behavior when no setting is provided.""" | ||
| monkeypatch.delenv("QUERYCHAT_TOOL_DETAILS", raising=False) | ||
|
|
||
| assert querychat_tool_starts_open("query") is True | ||
| assert querychat_tool_starts_open("update") is True | ||
| assert querychat_tool_starts_open("reset") is False | ||
|
|
||
|
|
||
| def test_querychat_tool_starts_open_expanded(monkeypatch): | ||
| """Test 'expanded' setting.""" | ||
| monkeypatch.setenv("QUERYCHAT_TOOL_DETAILS", "expanded") | ||
|
|
||
| assert querychat_tool_starts_open("query") is True | ||
| assert querychat_tool_starts_open("update") is True | ||
| assert querychat_tool_starts_open("reset") is True | ||
|
|
||
|
|
||
| def test_querychat_tool_starts_open_collapsed(monkeypatch): | ||
| """Test 'collapsed' setting.""" | ||
| monkeypatch.setenv("QUERYCHAT_TOOL_DETAILS", "collapsed") | ||
|
|
||
| assert querychat_tool_starts_open("query") is False | ||
| assert querychat_tool_starts_open("update") is False | ||
| assert querychat_tool_starts_open("reset") is False | ||
|
|
||
|
|
||
| def test_querychat_tool_starts_open_default_setting(monkeypatch): | ||
| """Test 'default' setting.""" | ||
| monkeypatch.setenv("QUERYCHAT_TOOL_DETAILS", "default") | ||
|
|
||
| assert querychat_tool_starts_open("query") is True | ||
| assert querychat_tool_starts_open("update") is True | ||
| assert querychat_tool_starts_open("reset") is False | ||
|
|
||
|
|
||
| def test_querychat_tool_starts_open_case_insensitive(monkeypatch): | ||
| """Test that setting is case-insensitive.""" | ||
| monkeypatch.setenv("QUERYCHAT_TOOL_DETAILS", "EXPANDED") | ||
| assert querychat_tool_starts_open("query") is True | ||
|
|
||
| monkeypatch.setenv("QUERYCHAT_TOOL_DETAILS", "Collapsed") | ||
| assert querychat_tool_starts_open("query") is False | ||
|
|
||
| monkeypatch.setenv("QUERYCHAT_TOOL_DETAILS", "DeFaUlT") | ||
| assert querychat_tool_starts_open("query") is True | ||
|
|
||
|
|
||
| def test_querychat_tool_starts_open_invalid_setting(monkeypatch): | ||
| """Test warning on invalid setting.""" | ||
| monkeypatch.setenv("QUERYCHAT_TOOL_DETAILS", "invalid") | ||
|
|
||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| result = querychat_tool_starts_open("query") | ||
|
|
||
| assert len(w) == 1 | ||
| assert "Invalid value" in str(w[0].message) | ||
| assert result is True # Falls back to default behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| test_that("querychat_tool_starts_open respects default behavior", { | ||
| withr::local_options(querychat.tool_details = NULL) | ||
| withr::local_envvar(QUERYCHAT_TOOL_DETAILS = NA) | ||
|
|
||
| expect_true(querychat_tool_starts_open("query")) | ||
| expect_true(querychat_tool_starts_open("update")) | ||
| expect_false(querychat_tool_starts_open("reset")) | ||
| }) | ||
|
|
||
| test_that("querychat_tool_starts_open respects 'expanded' setting via option", { | ||
| withr::local_options(querychat.tool_details = "expanded") | ||
|
|
||
| expect_true(querychat_tool_starts_open("query")) | ||
| expect_true(querychat_tool_starts_open("update")) | ||
| expect_true(querychat_tool_starts_open("reset")) | ||
| }) | ||
|
|
||
| test_that("querychat_tool_starts_open respects 'collapsed' setting via option", { | ||
| withr::local_options(querychat.tool_details = "collapsed") | ||
|
|
||
| expect_false(querychat_tool_starts_open("query")) | ||
| expect_false(querychat_tool_starts_open("update")) | ||
| expect_false(querychat_tool_starts_open("reset")) | ||
| }) | ||
|
|
||
| test_that("querychat_tool_starts_open respects 'default' setting via option", { | ||
| withr::local_options(querychat.tool_details = "default") | ||
|
|
||
| expect_true(querychat_tool_starts_open("query")) | ||
| expect_true(querychat_tool_starts_open("update")) | ||
| expect_false(querychat_tool_starts_open("reset")) | ||
| }) | ||
|
|
||
| test_that("querychat_tool_starts_open respects 'expanded' setting via envvar", { | ||
| withr::local_options(querychat.tool_details = NULL) | ||
| withr::local_envvar(QUERYCHAT_TOOL_DETAILS = "expanded") | ||
|
|
||
| expect_true(querychat_tool_starts_open("query")) | ||
| expect_true(querychat_tool_starts_open("update")) | ||
| expect_true(querychat_tool_starts_open("reset")) | ||
| }) | ||
|
|
||
| test_that("querychat_tool_starts_open respects 'collapsed' setting via envvar", { | ||
| withr::local_options(querychat.tool_details = NULL) | ||
| withr::local_envvar(QUERYCHAT_TOOL_DETAILS = "collapsed") | ||
|
|
||
| expect_false(querychat_tool_starts_open("query")) | ||
| expect_false(querychat_tool_starts_open("update")) | ||
| expect_false(querychat_tool_starts_open("reset")) | ||
| }) | ||
|
|
||
| test_that("querychat_tool_starts_open is case-insensitive", { | ||
| withr::local_options(querychat.tool_details = "EXPANDED") | ||
| expect_true(querychat_tool_starts_open("query")) | ||
|
|
||
| withr::local_options(querychat.tool_details = "Collapsed") | ||
| expect_false(querychat_tool_starts_open("query")) | ||
| }) | ||
|
|
||
| test_that("querychat_tool_starts_open warns on invalid setting", { | ||
| withr::local_options(querychat.tool_details = "invalid") | ||
|
|
||
| expect_warning( | ||
| querychat_tool_starts_open("query"), | ||
| "Invalid value for" | ||
| ) | ||
| }) | ||
|
|
||
| test_that("option takes precedence over environment variable", { | ||
| withr::local_options(querychat.tool_details = "collapsed") | ||
| withr::local_envvar(QUERYCHAT_TOOL_DETAILS = "expanded") | ||
|
|
||
| expect_false(querychat_tool_starts_open("query")) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.