Skip to content

feat: add ensure_basin and ensure_stream ops #56

Merged
quettabit merged 2 commits into
mainfrom
qb/ensure
May 21, 2026
Merged

feat: add ensure_basin and ensure_stream ops #56
quettabit merged 2 commits into
mainfrom
qb/ensure

Conversation

@quettabit

Copy link
Copy Markdown
Member

No description provided.

@quettabit quettabit force-pushed the qb/ensure branch 3 times, most recently from 4077c89 to 646a1db Compare May 21, 2026 02:31
@quettabit

Copy link
Copy Markdown
Member Author

@greptileai review pls

@quettabit quettabit changed the title [WIP] feat: add ensure_basin and ensure_stream ops May 21, 2026
@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds ensure_basin (on S2) and ensure_stream (on S2Basin) idempotent upsert operations, mirroring the PUT endpoints on the S2 API. It also extends the Response class to carry response headers so that the s2-provision-result header can be surfaced to callers as the new EnsureStatus enum.

  • New typesEnsureStatus, EnsuredBasinInfo, and EnsuredStreamInfo are added to _types.py and exported from the package.
  • Header parsing_ensure_status_from_headers in _mappers.py iterates over the response header tuple and raises descriptive ValueErrors for missing or unrecognized header values.
  • Response refactor — the private _content slot and its property are replaced with a public content attribute, and a new headers slot stores the raw response headers as an immutable tuple.

Confidence Score: 5/5

The changes are well-scoped idempotent upsert methods with a small Response refactor and full integration test coverage.

The header-parsing logic correctly handles missing and unrecognized s2-provision-result values with descriptive errors, the Response refactor preserves the existing public interface, and both operations delegate JSON serialisation to already-tested mapper functions.

No files require special attention.

Important Files Changed

Filename Overview
src/s2_sdk/_ops.py Adds ensure_basin (with validate_basin name check) and ensure_stream methods, each delegating to the respective PUT endpoint and mapping the response through the new ensured_*_info_from_response helpers.
src/s2_sdk/_mappers.py Adds _ensure_status_from_headers, ensured_basin_info_from_response, and ensured_stream_info_from_response; header lookup uses .get() with explicit ValueError for missing/unknown values.
src/s2_sdk/_client.py Extends Response to store headers as an immutable tuple; converts _content private slot to a public content attribute; renames h to headers in _build_headers.
src/s2_sdk/_types.py Adds EnsureStatus enum and EnsuredBasinInfo/EnsuredStreamInfo dataclasses; all correctly use _DocEnum and @dataclass(slots=True).
tests/test_account_ops.py Three new integration tests covering CREATED, CONFIG_UPDATED, and CONFIG_UNCHANGED outcomes for ensure_basin; all clean up after themselves in finally blocks.
tests/test_basin_ops.py Three new integration tests covering the same three outcomes for ensure_stream, with proper cleanup.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant S2/S2Basin
    participant HttpClient
    participant S2API

    Caller->>S2/S2Basin: ensure_basin(name, config?) / ensure_stream(name, config?)
    S2/S2Basin->>HttpClient: "PUT /v1/basins/{name} or PUT stream path"
    note over HttpClient,S2API: body is config dict or empty
    S2API-->>HttpClient: 200 OK + s2-provision-result header
    HttpClient-->>S2/S2Basin: Response(status_code, content, headers)
    S2/S2Basin->>S2/S2Basin: _ensure_status_from_headers(response.headers)
    S2/S2Basin-->>Caller: EnsuredBasinInfo or EnsuredStreamInfo
Loading

Reviews (3): Last reviewed commit: "initial commit" | Re-trigger Greptile

Comment thread src/s2_sdk/_ops.py
Comment thread src/s2_sdk/_mappers.py Outdated
Comment thread src/s2_sdk/_mappers.py Outdated
@quettabit

Copy link
Copy Markdown
Member Author

@greptileai addressed your comments. pls review again and update your score.

@quettabit quettabit marked this pull request as ready for review May 21, 2026 03:27
@quettabit quettabit requested a review from a team as a code owner May 21, 2026 03:27
@quettabit quettabit merged commit b57079c into main May 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant