Skip to content

refactor: sync remove ignore_header_params behavior from sdk-gen - #423

Closed
chyroc wants to merge 1 commit into
mainfrom
refactor/remove-ignore-header-params-config-sync
Closed

refactor: sync remove ignore_header_params behavior from sdk-gen#423
chyroc wants to merge 1 commit into
mainfrom
refactor/remove-ignore-header-params-config-sync

Conversation

@chyroc

@chyroc chyroc commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Sync upstream generator change from coze-sdk-gen PR: refactor(py): remove ignore_header_params config support coze-sdk-gen#62
  • Remove ignore_header_params-based behavior in generated Python SDK output.
  • datasets.process now follows swagger header definition and requires agw_js_conv in both sync/async clients.
  • Update tests/test_datasets.py call sites to pass agw_js_conv="str".

Behavior Changes

  • Coze.datasets.process(...) now requires keyword arg agw_js_conv.
  • AsyncCoze.datasets.process(...) now requires keyword arg agw_js_conv.
  • Request headers now include Agw-Js-Conv from the explicit method argument.

Validation

  • ./scripts/genpy.sh --output-sdk exist-repo/coze-py --ci-check
    • poetry install/build: passed
    • ruff check/format: passed
    • mypy: passed
    • pytest: 285 passed

Summary by CodeRabbit

  • New Features
    • Added agw_js_conv parameter to the dataset processing methods, enabling users to specify custom header values for dataset operations in both synchronous and asynchronous workflows.

@chyroc chyroc added the enhancement New feature or request label Feb 26, 2026
@coderabbitai

coderabbitai Bot commented Feb 26, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The changes add a new agw_js_conv string parameter to the DatasetsClient and AsyncDatasetsClient process methods, which is used to populate the Agw-Js-Conv header in requests. Corresponding test calls are updated to pass this parameter.

Changes

Cohort / File(s) Summary
Process Method Implementation
cozepy/datasets/__init__.py
Added agw_js_conv: str parameter to both DatasetsClient.process and AsyncDatasetsClient.process methods. Parameter is used to set the Agw-Js-Conv header in the request.
Test Updates
tests/test_datasets.py
Updated test calls to include the new agw_js_conv="str" argument in both synchronous and asynchronous test paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement

Poem

🐰 A header hops in, shiny and new,
Agw-Js-Conv, converting right through,
Sync and async both nod in delight,
Dataset processing takes flight! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title refers to removing ignore_header_params behavior from the SDK generator, which is the core intent. However, the changeset shows adding an explicit agw_js_conv parameter to method signatures and including the header in requests. The title is partially related—it describes the refactoring intent but doesn't clearly convey what was added to achieve the goal.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/remove-ignore-header-params-config-sync

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Feb 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.75%. Comparing base (a23676b) to head (fa04774).
⚠️ Report is 1 commits behind head on main.

@@           Coverage Diff           @@
##             main     #423   +/-   ##
=======================================
  Coverage   91.75%   91.75%           
=======================================
  Files         105      105           
  Lines        9542     9548    +6     
=======================================
+ Hits         8755     8761    +6     
  Misses        787      787           
Files with missing lines Coverage Δ
cozepy/datasets/__init__.py 100.00% <100.00%> (ø)
tests/test_datasets.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cozepy/datasets/__init__.py`:
- Around line 252-259: Add a docstring entry for the new required parameter
agw_js_conv in both the synchronous and asynchronous process methods so
generated API docs are accurate: update the docstrings for the process(...)
method and the async process(...) method to include a ":param agw_js_conv:
<short description>" line (describe that it is the AGW JS conversation
token/string used for X processing or routing), and if present add a ":type
agw_js_conv: str" line to match existing style; ensure the parameter name
matches exactly ("agw_js_conv") and place the entry alongside the other :param
lines for dataset_id and document_ids.

In `@tests/test_datasets.py`:
- Line 176: The tests call coze.datasets.process(..., agw_js_conv="str") but
never assert that the outbound request contains the Agw-Js-Conv header; update
the test helper mock_process_datasets to return the route (or response) object
and in both test functions (the one using res =
coze.datasets.process(dataset_id=dataset_id, document_ids=[document_id],
agw_js_conv="str") and the other at line ~250) add assertions that the
route/request headers include "Agw-Js-Conv" with value "str" (e.g., check
route.request.headers.get("Agw-Js-Conv") == "str" or equivalent), ensuring you
reference the returned route object from mock_process_datasets when making the
assertion.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a23676b and fa04774.

📒 Files selected for processing (2)
  • cozepy/datasets/__init__.py
  • tests/test_datasets.py

Comment thread cozepy/datasets/__init__.py
Comment thread tests/test_datasets.py
dataset_id, document_id, mock_logid = mock_process_datasets(respx_mock)

res = coze.datasets.process(dataset_id=dataset_id, document_ids=[document_id])
res = coze.datasets.process(dataset_id=dataset_id, document_ids=[document_id], agw_js_conv="str")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, let's find and examine the test file
rg -n -C5 'test_(sync|async)_datasets_process|agw_js_conv' tests/test_datasets.py | head -100

Repository: coze-dev/coze-py

Length of output: 1235


🏁 Script executed:

#!/bin/bash
# Check the mock_process_datasets function and respx setup
rg -n -B5 -A20 'def mock_process_datasets' tests/test_datasets.py

Repository: coze-dev/coze-py

Length of output: 937


🏁 Script executed:

#!/bin/bash
# Check imports and test class decorators
head -50 tests/test_datasets.py

Repository: coze-dev/coze-py

Length of output: 1587


🏁 Script executed:

#!/bin/bash
# Check if there are any existing header assertions using respx in the test file
rg -n 'respx_mock\.calls|\.request\.headers|\.headers\[' tests/test_datasets.py

Repository: coze-dev/coze-py

Length of output: 42


🏁 Script executed:

#!/bin/bash
# Check if respx is used with pytest decorator
rg -n '@pytest.mark.respx|respx' tests/test_datasets.py | head -20

Repository: coze-dev/coze-py

Length of output: 1141


🏁 Script executed:

#!/bin/bash
# Check the entire test class structure to see test decorators
sed -n '108,180p' tests/test_datasets.py

Repository: coze-dev/coze-py

Length of output: 2561


🏁 Script executed:

#!/bin/bash
# Check if respx_mock.calls pattern is used anywhere in the test suite
rg -r 'calls\[-?[0-9]\]\.request|\.request\.headers' --type py

Repository: coze-dev/coze-py

Length of output: 456


🏁 Script executed:

#!/bin/bash
# Check if respx_mock.calls pattern is used anywhere in the test suite
rg 'calls\[-?[0-9]\]\.request|\.request\.headers' --type py

Repository: coze-dev/coze-py

Length of output: 926


🏁 Script executed:

#!/bin/bash
# Check how headers are verified in existing tests
rg -B2 -A2 'calls\[0\]\.request\.headers|route\.calls' tests/test_connectors.py | head -40

Repository: coze-dev/coze-py

Length of output: 942


🏁 Script executed:

#!/bin/bash
# Check respx API documentation and how to access request headers
# First, let's see if respx provides .calls attribute on the mock object
rg -B5 -A5 'respx_mock\.' tests/test_workflows_chat.py | head -50

Repository: coze-dev/coze-py

Length of output: 1209


🏁 Script executed:

#!/bin/bash
# Get the full context of how route.calls is used
rg -B5 -A10 'route\.calls\[0\]\.request' tests/test_workflows_chat.py | head -60

Repository: coze-dev/coze-py

Length of output: 733


🏁 Script executed:

#!/bin/bash
# Check how mock_process_datasets is used and whether respx_mock.calls is available
# Let's look for documentation or examples of respx.calls in tests
rg 'respx_mock\.calls|respx_mock\.calls\[-?[0-9]\]' --type py

Repository: coze-dev/coze-py

Length of output: 42


🏁 Script executed:

#!/bin/bash
# Check if respx_mock itself has a calls attribute or if we need to store route
# Let's look at the complete mock_process_datasets implementation
sed -n '79,105p' tests/test_datasets.py

Repository: coze-dev/coze-py

Length of output: 945


🏁 Script executed:

#!/bin/bash
# Let's check how other tests that need to inspect requests handle it
# Look at test_workflows_chat.py to see how route is captured
sed -n '45,85p' tests/test_workflows_chat.py

Repository: coze-dev/coze-py

Length of output: 1419


🏁 Script executed:

#!/bin/bash
# Check if respx_mock object itself has .calls attribute
# by searching for any usage of respx_mock.calls
rg 'respx_mock\.calls' --type py -A2

Repository: coze-dev/coze-py

Length of output: 42


🏁 Script executed:

#!/bin/bash
# Let's verify the respx API by checking what respx returns
# and by looking at the pattern used in test_datasets_documents.py
rg -B10 -A10 'route\.calls\[0\]\.request' tests/test_datasets_documents.py | head -60

Repository: coze-dev/coze-py

Length of output: 942


Add assertions for the new Agw-Js-Conv header behavior in the process tests.

Lines 176 and 250 update the call signature with agw_js_conv="str", but the tests don't verify that this header is actually sent in the outbound request.

Update mock_process_datasets to return the route object, then add header assertions to both test functions:

Suggested test assertions
 def mock_process_datasets(respx_mock):
     dataset_id = random_hex(10)
     document_id = random_hex(10)
     logid = random_hex(10)
-    respx_mock.post(f"/v1/datasets/{dataset_id}/process").mock(
+    route = respx_mock.post(f"/v1/datasets/{dataset_id}/process").mock(
         httpx.Response(...)
     )
-    return dataset_id, document_id, logid
+    return dataset_id, document_id, logid, route
 def test_sync_datasets_process(self, respx_mock):
     coze = Coze(auth=TokenAuth(token="token"))
-    dataset_id, document_id, mock_logid = mock_process_datasets(respx_mock)
+    dataset_id, document_id, mock_logid, route = mock_process_datasets(respx_mock)
     res = coze.datasets.process(dataset_id=dataset_id, document_ids=[document_id], agw_js_conv="str")
     assert res
     assert res.response.logid == mock_logid
+    assert route.calls[0].request.headers["Agw-Js-Conv"] == "str"
 async def test_async_datasets_process(self, respx_mock):
     coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))
-    dataset_id, document_id, mock_logid = mock_process_datasets(respx_mock)
+    dataset_id, document_id, mock_logid, route = mock_process_datasets(respx_mock)
     res = await coze.datasets.process(dataset_id=dataset_id, document_ids=[document_id], agw_js_conv="str")
     assert res
     assert res.response.logid == mock_logid
+    assert route.calls[0].request.headers["Agw-Js-Conv"] == "str"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_datasets.py` at line 176, The tests call
coze.datasets.process(..., agw_js_conv="str") but never assert that the outbound
request contains the Agw-Js-Conv header; update the test helper
mock_process_datasets to return the route (or response) object and in both test
functions (the one using res = coze.datasets.process(dataset_id=dataset_id,
document_ids=[document_id], agw_js_conv="str") and the other at line ~250) add
assertions that the route/request headers include "Agw-Js-Conv" with value "str"
(e.g., check route.request.headers.get("Agw-Js-Conv") == "str" or equivalent),
ensuring you reference the returned route object from mock_process_datasets when
making the assertion.

@chyroc

chyroc commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator Author

Closing per request.

@chyroc chyroc closed this Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant