Repository navigation
Feat: add new tests and tescases for restful api suite - #15208
Conversation
📝 WalkthroughWalkthroughAdds concurrency imports and ~20 dataset-creation contract tests covering naming semantics, avatar/description pass-through, chunk_method/permission/embedding_model validation, parser_config matrix/defaults/invalid inputs, scale (1k creations), and concurrent creation. ChangesDataset API Contract Testing
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/testcases/restful_api/test_datasets.py`:
- Around line 211-225: The test expectations in
test_dataset_create_parser_config_missing_raptor_and_graphrag (and the similar
block at lines ~382-404) are wrong given the defaulting behavior in
get_parser_config and create_with_name which return the "naive" parser config
that sets use_raptor and use_graphrag to True; update the assertions in
test/testcases/restful_api/test_datasets.py to assert that parser_config
contains "raptor" and "graphrag" and that parser_config["raptor"]["use_raptor"]
is True and parser_config["graphrag"]["use_graphrag"] is True (while keeping the
chunk_token_num assertion) so the test matches
api/utils/api_utils.py:get_parser_config and
api/db/services/knowledgebase_service.py:create_with_name behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e6e356fa-6a73-4269-82ae-40653abb37a4
📒 Files selected for processing (1)
test/testcases/restful_api/test_datasets.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15208 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
test/testcases/restful_api/test_datasets.py (1)
171-188:⚠️ Potential issue | 🟠 Major | ⚡ Quick winFix duplicate pytest test name and contract assertion issues in
test_datasets.py
- Duplicate test definition:
test_dataset_create_embedding_model_contractis defined at lines 180-187 and redefined at lines 551-578; pytest will only run the latter, dropping the parameterized embedding-model contract coverage (171-188).- Missing pytest priority marker:
test_dataset_create_name_invalid_and_duplicate_contract(431-455) has no@pytest.mark.p1/p2/p3.- Expected error string typo:
graphrag_entity_types_not_str_in_listexpects"nput should be a valid string"(673); should match the backend message (likely"Input ...").- Parser-config defaults assertions:
test_dataset_create_parser_config_missing_raptor_and_graphrag(around 213-227) assertsuse_raptoranduse_graphragdefault toFalse; update if backend defaults differ.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/testcases/restful_api/test_datasets.py` around lines 171 - 188, Rename or deduplicate the duplicated test function test_dataset_create_embedding_model_contract so the parameterized version (the one at the earlier block with `@pytest.mark.parametrize`) is the one executed (remove or rename the later redefinition), ensure the parameterized test posts to /datasets and asserts embedding_model contract as before; add an appropriate pytest priority marker (e.g., `@pytest.mark.p1` or p2) to test_dataset_create_name_invalid_and_duplicate_contract so it has a priority; fix the typo in the expected error string for graphrag_entity_types_not_str_in_list to match the backend message (correct "nput should be a valid string" to the actual "Input should be a valid string" or the exact backend text); and update assertions in test_dataset_create_parser_config_missing_raptor_and_graphrag (the test checking use_raptor/use_graphrag defaults) to reflect the backend defaults (flip to True if backend now defaults to True or adjust assertions to assert presence/absence accordingly).
♻️ Duplicate comments (1)
test/testcases/restful_api/test_datasets.py (1)
213-227:⚠️ Potential issue | 🟠 Major | ⚡ Quick winParser-config default flag expectations still look inverted.
These assertions expect missing
raptor/graphragdefaults toFalse; if the service still defaults to the naive parser config, these should beTrueand tests will fail.Proposed expectation update (if defaults are still naive)
- assert parser_config["raptor"]["use_raptor"] is False, body - assert parser_config["graphrag"]["use_graphrag"] is False, body + assert parser_config["raptor"]["use_raptor"] is True, body + assert parser_config["graphrag"]["use_graphrag"] is True, body- ("test_parser_config_only_raptor", {"chunk_token_num": 1024, "raptor": {"use_raptor": True}}, True, False), - ("test_parser_config_only_graphrag", {"chunk_token_num": 1024, "graphrag": {"use_graphrag": True}}, False, True), + ("test_parser_config_only_raptor", {"chunk_token_num": 1024, "raptor": {"use_raptor": True}}, True, True), + ("test_parser_config_only_graphrag", {"chunk_token_num": 1024, "graphrag": {"use_graphrag": True}}, True, True),- assert parser_config["raptor"]["use_raptor"] is False, body - assert parser_config["graphrag"]["use_graphrag"] is False, body + assert parser_config["raptor"]["use_raptor"] is True, body + assert parser_config["graphrag"]["use_graphrag"] is True, body#!/bin/bash set -euo pipefail # Verify defaults in parser config / creation path files=$(fd -i 'api_utils.py|knowledgebase_service.py' || true) if [ -z "${files}" ]; then echo "Could not locate api_utils.py or knowledgebase_service.py via fd." exit 1 fi echo "Inspecting files:" echo "${files}" # Show relevant definitions and default flags rg -n -C4 'def get_parser_config|def create_with_name|use_raptor|use_graphrag|naive|DEFAULT_PARSER_CONFIG' ${files} # Show current assertions in this test file rg -n -C2 'use_raptor|use_graphrag|test_dataset_create_parser_config_' test/testcases/restful_api/test_datasets.pyAlso applies to: 384-386, 429-430
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/testcases/restful_api/test_datasets.py` around lines 213 - 227, The test test_dataset_create_parser_config_missing_raptor_and_graphrag currently asserts that missing parser flags default to False but the service (or DEFAULT_PARSER_CONFIG) uses the naive parser default True; update the assertions to expect True for parser_config["raptor"]["use_raptor"] and parser_config["graphrag"]["use_graphrag"] (and any other similar assertions in this file — e.g., the other test_dataset_create_parser_config_* cases) or alternatively change the code paths that build the default parser config (functions like get_parser_config or create_with_name / DEFAULT_PARSER_CONFIG in api_utils.py / knowledgebase_service.py) to return False for those flags so the tests remain correct; pick one approach and make the assertions or defaults consistent across parser_config handling and the tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/testcases/restful_api/test_datasets.py`:
- Line 673: The expected-message string in the invalid-case matrix tuple
("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1,
2]}}, "nput should be a valid string") has a leading character missing; update
that third element to the correct message "Input should be a valid string" so
the test assertion compares against the correct expected error text (locate the
tuple in test_datasets.py near the invalid-case matrix).
- Around line 431-456: The test function
test_dataset_create_name_invalid_and_duplicate_contract is missing a pytest
priority marker; add an appropriate marker (e.g., `@pytest.mark.p1`) directly
above the function definition and ensure pytest is imported in the file (add
"import pytest" at the top if absent) so the test uses the required p1/p2/p3
priority convention.
---
Outside diff comments:
In `@test/testcases/restful_api/test_datasets.py`:
- Around line 171-188: Rename or deduplicate the duplicated test function
test_dataset_create_embedding_model_contract so the parameterized version (the
one at the earlier block with `@pytest.mark.parametrize`) is the one executed
(remove or rename the later redefinition), ensure the parameterized test posts
to /datasets and asserts embedding_model contract as before; add an appropriate
pytest priority marker (e.g., `@pytest.mark.p1` or p2) to
test_dataset_create_name_invalid_and_duplicate_contract so it has a priority;
fix the typo in the expected error string for
graphrag_entity_types_not_str_in_list to match the backend message (correct
"nput should be a valid string" to the actual "Input should be a valid string"
or the exact backend text); and update assertions in
test_dataset_create_parser_config_missing_raptor_and_graphrag (the test checking
use_raptor/use_graphrag defaults) to reflect the backend defaults (flip to True
if backend now defaults to True or adjust assertions to assert presence/absence
accordingly).
---
Duplicate comments:
In `@test/testcases/restful_api/test_datasets.py`:
- Around line 213-227: The test
test_dataset_create_parser_config_missing_raptor_and_graphrag currently asserts
that missing parser flags default to False but the service (or
DEFAULT_PARSER_CONFIG) uses the naive parser default True; update the assertions
to expect True for parser_config["raptor"]["use_raptor"] and
parser_config["graphrag"]["use_graphrag"] (and any other similar assertions in
this file — e.g., the other test_dataset_create_parser_config_* cases) or
alternatively change the code paths that build the default parser config
(functions like get_parser_config or create_with_name / DEFAULT_PARSER_CONFIG in
api_utils.py / knowledgebase_service.py) to return False for those flags so the
tests remain correct; pick one approach and make the assertions or defaults
consistent across parser_config handling and the tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b9747ffc-1401-41ad-977d-af35854df9ce
📒 Files selected for processing (1)
test/testcases/restful_api/test_datasets.py
| ("pages_not_int_list", {"pages": [["string1", "string2"]]}, "Input should be a valid integer"), | ||
| ("graphrag_type_invalid", {"graphrag": {"use_graphrag": "string"}}, "Input should be a valid boolean"), | ||
| ("graphrag_entity_types_not_list", {"graphrag": {"entity_types": "1,2"}}, "Input should be a valid list"), | ||
| ("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1, 2]}}, "nput should be a valid string"), |
There was a problem hiding this comment.
Fix expected-message typo in invalid-case matrix.
Line [673] uses "nput should be a valid string" (missing leading I), which can cause a false assertion failure.
Proposed fix
- ("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1, 2]}}, "nput should be a valid string"),
+ ("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1, 2]}}, "Input should be a valid string"),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1, 2]}}, "nput should be a valid string"), | |
| ("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1, 2]}}, "Input should be a valid string"), |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/testcases/restful_api/test_datasets.py` at line 673, The
expected-message string in the invalid-case matrix tuple
("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1,
2]}}, "nput should be a valid string") has a leading character missing; update
that third element to the correct message "Input should be a valid string" so
the test assertion compares against the correct expected error text (locate the
tuple in test_datasets.py near the invalid-case matrix).
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
test/testcases/restful_api/test_datasets.py (1)
552-552:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winResolve duplicate test function name to fix Ruff F811 and test shadowing.
test_dataset_create_embedding_model_contractis redefined at Line 552, which shadows the earlier definition at Line 180. This breaks linting and silently skips one contract test.Proposed fix
-@pytest.mark.p2 -def test_dataset_create_embedding_model_contract(rest_client, clear_datasets): +@pytest.mark.p2 +def test_dataset_create_embedding_model_default_and_invalid_contract(rest_client, clear_datasets):As per coding guidelines, "Use
ruff checkandruff formatcommands to lint and format Python code".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/testcases/restful_api/test_datasets.py` at line 552, Duplicate test function name test_dataset_create_embedding_model_contract is shadowing an earlier test and causing Ruff F811; rename one of the duplicate functions to a unique, descriptive name (e.g., test_dataset_create_embedding_model_contract_with_<scenario> or test_dataset_create_embedding_model_contract_duplicate) and update any references or fixtures that call it (keep the test logic identical if it's intended to be a different scenario). After renaming, run ruff check and ruff format to ensure linting and formatting pass and adjust any import/test selection patterns if they relied on the old name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@test/testcases/restful_api/test_datasets.py`:
- Line 552: Duplicate test function name
test_dataset_create_embedding_model_contract is shadowing an earlier test and
causing Ruff F811; rename one of the duplicate functions to a unique,
descriptive name (e.g.,
test_dataset_create_embedding_model_contract_with_<scenario> or
test_dataset_create_embedding_model_contract_duplicate) and update any
references or fixtures that call it (keep the test logic identical if it's
intended to be a different scenario). After renaming, run ruff check and ruff
format to ensure linting and formatting pass and adjust any import/test
selection patterns if they relied on the old name.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9fe92c66-ebb1-4cef-a55d-aa73b1456207
📒 Files selected for processing (1)
test/testcases/restful_api/test_datasets.py
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/testcases/restful_api/test_datasets.py`:
- Around line 211-217: The xfail gate is too broad: restrict the pytest.xfail
call so it only triggers when the error is the specific unauthorized-tenant case
(e.g., payload["code"] == 102 AND payload["message"] contains an
authorization-specific substring like "no authorized tenant" or similar),
instead of xfactoring every 102; update the condition that calls pytest.xfail to
check both unauthorized_is_xfail and an authorization-specific indicator in
payload["message"]; also make the message assertion less brittle by checking
containment (e.g., expected_message in payload["message"]) when expected_message
is provided rather than exact equality; keep existing checks for expected_code
and expected_embedding_model unchanged and reference the variables payload,
unauthorized_is_xfail, pytest.xfail, expected_message, expected_embedding_model,
and embedding_model when editing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 90a533ee-ef2e-40aa-a294-28523ee55922
📒 Files selected for processing (1)
test/testcases/restful_api/test_datasets.py
| if unauthorized_is_xfail and payload["code"] == 102: | ||
| pytest.xfail(f"Environment has no authorized tenant model for {embedding_model}: {payload}") | ||
| assert payload["code"] == expected_code, payload | ||
| if expected_embedding_model is not None: | ||
| assert payload["data"]["embedding_model"] == expected_embedding_model, payload | ||
| if expected_message is not None: | ||
| assert payload["message"] == expected_message, payload |
There was a problem hiding this comment.
Narrow the xfail gate so real regressions don’t get masked.
The current branch xfails any code == 102 for the tenant case, even when the 102 is unrelated to authorization. Also, exact message equality is brittle for API error text contracts.
Suggested adjustment
- if unauthorized_is_xfail and payload["code"] == 102:
- pytest.xfail(f"Environment has no authorized tenant model for {embedding_model}: {payload}")
+ if unauthorized_is_xfail and payload["code"] == 102:
+ message = payload.get("message", "")
+ if "Unauthorized model:" in message:
+ pytest.xfail(f"Environment has no authorized tenant model for {embedding_model}: {payload}")
assert payload["code"] == expected_code, payload
@@
- if expected_message is not None:
- assert payload["message"] == expected_message, payload
+ if expected_message is not None:
+ assert expected_message in payload.get("message", ""), payload📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if unauthorized_is_xfail and payload["code"] == 102: | |
| pytest.xfail(f"Environment has no authorized tenant model for {embedding_model}: {payload}") | |
| assert payload["code"] == expected_code, payload | |
| if expected_embedding_model is not None: | |
| assert payload["data"]["embedding_model"] == expected_embedding_model, payload | |
| if expected_message is not None: | |
| assert payload["message"] == expected_message, payload | |
| if unauthorized_is_xfail and payload["code"] == 102: | |
| message = payload.get("message", "") | |
| if "Unauthorized model:" in message: | |
| pytest.xfail(f"Environment has no authorized tenant model for {embedding_model}: {payload}") | |
| assert payload["code"] == expected_code, payload | |
| if expected_embedding_model is not None: | |
| assert payload["data"]["embedding_model"] == expected_embedding_model, payload | |
| if expected_message is not None: | |
| assert expected_message in payload.get("message", ""), payload |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/testcases/restful_api/test_datasets.py` around lines 211 - 217, The
xfail gate is too broad: restrict the pytest.xfail call so it only triggers when
the error is the specific unauthorized-tenant case (e.g., payload["code"] == 102
AND payload["message"] contains an authorization-specific substring like "no
authorized tenant" or similar), instead of xfactoring every 102; update the
condition that calls pytest.xfail to check both unauthorized_is_xfail and an
authorization-specific indicator in payload["message"]; also make the message
assertion less brittle by checking containment (e.g., expected_message in
payload["message"]) when expected_message is provided rather than exact
equality; keep existing checks for expected_code and expected_embedding_model
unchanged and reference the variables payload, unauthorized_is_xfail,
pytest.xfail, expected_message, expected_embedding_model, and embedding_model
when editing.
What problem does this PR solve?
extend restful api suite
Type of change