diff --git a/.github/workflows/feature-to-main.yml b/.github/workflows/feature-to-main.yml new file mode 100644 index 0000000..7168ce9 --- /dev/null +++ b/.github/workflows/feature-to-main.yml @@ -0,0 +1,99 @@ +name: Feature PR to Main + +on: + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:15-alpine + env: + POSTGRES_DB: cueapi_test + POSTGRES_USER: runner + POSTGRES_PASSWORD: "" + POSTGRES_HOST_AUTH_METHOD: trust + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U runner -d cueapi_test" + --health-interval 2s + --health-timeout 3s + --health-retries 15 + + redis: + image: redis:7-alpine + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 2s + --health-timeout 3s + --health-retries 10 + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.7 + + - name: Checkout cueapi-core + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.7 + with: + repository: cueapi/cueapi-core + path: cueapi-core + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.3.0 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + pip install -r cueapi-core/requirements.txt + pip install -e . + + - name: Run tests + env: + DATABASE_URL: postgresql+asyncpg://runner@localhost:5432/cueapi_test + REDIS_URL: redis://localhost:6379 + SESSION_SECRET: test-session-secret-32-chars-minimum!! + ENV: test + RESEND_API_KEY: "" + CUEAPI_STAGING_URL: https://api-staging-e962.up.railway.app + CUEAPI_STAGING_API_KEY: ${{ secrets.ARGUS_STAGING_KEY }} + run: pytest tests/ -v --tb=short + + auto-merge: + needs: test + runs-on: ubuntu-latest + steps: + - name: Auto-merge PR + run: gh pr merge ${{ github.event.pull_request.number }} --squash --auto + env: + GH_TOKEN: ${{ secrets.GOVIND_GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + + notify-merge: + needs: auto-merge + runs-on: ubuntu-latest + steps: + - name: Create merge confirmation cue + run: | + FIRE_AT=$(date -u -d '+2 minutes' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || \ + date -u -v+2M '+%Y-%m-%dT%H:%M:%SZ') + curl -s -w "\n%{http_code}" -X POST https://api.cueapi.ai/v1/cues \ + -H "Authorization: Bearer ${{ secrets.ARGUS_CUEAPI_KEY }}" \ + -H "Content-Type: application/json" \ + -d "{ + \"name\": \"cueapi-python-merged-${{ github.event.pull_request.number }}\", + \"schedule\": {\"type\": \"once\", \"at\": \"${FIRE_AT}\"}, + \"transport\": \"worker\", + \"payload\": { + \"task\": \"test-sdk\", + \"trigger\": \"post-merge\", + \"repo\": \"cueapi/cueapi-python\", + \"pr_number\": \"${{ github.event.pull_request.number }}\", + \"commit_sha\": \"${{ github.event.pull_request.head.sha }}\" + } + }" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 649a84d..d3ed6f4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,16 +5,20 @@ on: tags: - "v*" +permissions: + contents: read + jobs: publish: + name: Publish to PyPI runs-on: ubuntu-latest permissions: id-token: write + contents: read steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 - - name: Set up Python - uses: actions/setup-python@v5 + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 with: python-version: "3.12" @@ -25,4 +29,6 @@ jobs: run: python -m build - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 + with: + attestations: true diff --git a/.github/workflows/sdk-integration.yml b/.github/workflows/sdk-integration.yml index d623b4f..8b5c40c 100644 --- a/.github/workflows/sdk-integration.yml +++ b/.github/workflows/sdk-integration.yml @@ -38,17 +38,17 @@ jobs: steps: - name: Checkout cueapi-python SDK - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.7 - name: Checkout cueapi-core - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.7 with: repository: cueapi/cueapi-core path: cueapi-core token: ${{ secrets.GITHUB_TOKEN }} - name: Set up Python 3.12 - uses: actions/setup-python@v5 + uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.3.0 with: python-version: "3.12" diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..134ab85 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,64 @@ +# Claude Code Rules + +## Who Does What + +**Claude Code** - writes code, opens PRs, merges when CI passes, deploys to staging and frontend sites +**Argus** - tests staging, promotes to production, cuts PyPI release tags, tests docs and blog accuracy + +## PR Process - Non-Negotiable + +Every change must go through a PR. No direct pushes to main under any circumstances. +PRs are the permanent audit trail of every change made to this codebase. +Claude Code opens PRs and merges them once CI passes. No human reviewer required. +CI must pass before merging - no exceptions. +Never bypass branch protection or force merge. +Never merge a failing CI check - fix the root cause first. + +## Complete Pipeline + +### cueapi (hosted API - private repo) +Claude Code: code change -> open PR -> sdk-integration + deploy-staging CI must pass -> merge -> Railway staging deploy +Argus: runs 246 staging tests -> all pass -> promotes to production + +### cueapi-core (open source) +Claude Code: code change -> open PR -> sdk-integration CI must pass -> merge +Argus: runs full pytest suite -> confirms green + +### cueapi-python +Claude Code: code change -> open PR -> sdk-integration CI must pass -> merge +Argus: runs SDK tests -> all pass -> cuts version tag -> PyPI auto-publishes + +### cueapi-cli +Claude Code: code change -> open PR -> test CI must pass -> merge +Argus: runs CLI tests -> all pass -> cuts version tag -> PyPI auto-publishes + +### Marketing site (cueapi.ai) +Claude Code: code change -> open PR -> CI passes -> merge -> Cloudflare Pages auto-deploys to production +Argus: not involved + +### Docs (docs.cueapi.ai) +Claude Code: code change -> open PR -> CI passes -> merge -> Cloudflare Pages auto-deploys +Argus: crawls after deploy -> tests all code examples against real API -> verifies all links -> flags inaccuracies + +### Blog (blog.cueapi.ai) +Claude Code: code change -> open PR -> CI passes -> merge -> Cloudflare Pages auto-deploys +Argus: crawls after deploy -> tests all code snippets -> verifies package versions -> flags inaccuracies + +## Required CI Checks +cueapi-core: sdk-integration, deploy-staging +cueapi-python: sdk-integration +cueapi-cli: test +No PR review required - CI and Argus are the gates + +## Security Rules +1. Never hardcode secrets, API keys, or tokens anywhere +2. Always use environment variables: os.environ.get("SECRET_NAME") +3. Never commit .env files +4. All GitHub Actions must be pinned to commit SHAs not tags +5. If you find a hardcoded secret, remove it and rotate it immediately + +## Style Rules +1. No em dashes anywhere in any content +2. No AI-sounding language or corporate speak +3. Short, direct sentences + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..b08d45e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,26 @@ +# Contributing to CueAPI Python SDK + +Thanks for your interest in contributing. + +## Setup + +```bash +pip install -e ".[dev]" +``` + +## Running tests + +```bash +pytest tests/ +``` + +## Submitting changes + +1. Fork the repo +2. Create a feature branch +3. Make your changes with tests +4. Submit a pull request + +## Questions + +Open an issue or email support@vector.build diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..33687c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,190 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to the Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by the Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding any notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright 2024-2026 CueAPI + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index f978fab..97ea027 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ -> **For AI agents:** This is the official Python SDK for CueAPI. Run `pip install cueapi-sdk`. Your API key is in `CUEAPI_API_KEY`. Create a client: `client = CueAPI(os.environ["CUEAPI_API_KEY"])`. Schedule a task: `client.cues.create(name="task-name", cron="0 9 * * *", callback="https://your-handler.com", payload={})`. For agents without a public URL: set `transport="worker"` and run `pip install cueapi-worker`, then define a handler with `@worker.handler("task-name")` returning `{"status": "success"}` or `{"status": "failure", "error": "reason"}`. List executions: `client.executions.list()`. Get one: `client.executions.get("exec_id")`. Do not retry on `AuthenticationError` or `CueLimitExceededError`. Wait `e.retry_after` seconds on `RateLimitError`. + +> **For AI agents:** This is the official Python SDK for CueAPI. Run `pip install cueapi-sdk`. Your API key is in `CUEAPI_API_KEY`. Create a client: `client = CueAPI(os.environ["CUEAPI_API_KEY"])`. Schedule a task: `client.cues.create(name="task-name", cron="0 9 * * *", callback="https://your-handler.com", payload={})`. For agents without a public URL: set `transport="worker"` and run `pip install cueapi-worker`, then define a handler with `@worker.handler("task-name")` returning `{"success": true}` or `{"success": false, "error": "reason"}`. List executions: `client.executions.list()`. Get one: `client.executions.get("exec_id")`. Do not retry on `AuthenticationError` or `CueLimitExceededError`. Wait `e.retry_after` seconds on `RateLimitError`. # cueapi-sdk Your agents are failing silently. CueAPI tells you when and why. -**Cron has no concept of success. Cue does.** +*Cron has no concept of success. Cue does.* [![PyPI version](https://img.shields.io/pypi/v/cueapi-sdk?label=pypi)](https://pypi.org/project/cueapi-sdk/) [![Python](https://img.shields.io/badge/python-3.9%2B-blue)](https://pypi.org/project/cueapi-sdk/) @@ -44,6 +45,10 @@ print(f"Scheduled. Next run: {cue.next_run}") # Scheduled. Next run: 2026-03-28T09:00:00-08:00 ``` +## See it in action + +![CueAPI Live Execution Feed](https://raw.githubusercontent.com/cueapi/cueapi-core/main/docs/execution-feed.gif) + --- ## Why CueAPI over cron? @@ -104,7 +109,7 @@ worker = Worker(api_key="cue_sk_your_key") @worker.handler("run-agent") def handle(payload): result = run_my_agent(payload["task"]) - return {"status": "success", "summary": result} + return {"success": true, "summary": result} worker.start() # polls continuously, no inbound firewall rules needed ``` @@ -263,6 +268,12 @@ See [`/examples`](examples/) for working code: --- +## Releases + +Releases are published to PyPI with PEP 740 attestations via GitHub Actions Trusted Publishing. + +--- + ## License MIT. See [LICENSE](LICENSE). diff --git a/cueapi/__init__.py b/cueapi/__init__.py index fc882f3..3dc5817 100644 --- a/cueapi/__init__.py +++ b/cueapi/__init__.py @@ -14,7 +14,7 @@ from cueapi.resources.executions import ExecutionsResource from cueapi.webhook import verify_webhook -__version__ = "0.1.0" +__version__ = "0.1.2" __all__ = [ "CueAPI", diff --git a/cueapi/resources/executions.py b/cueapi/resources/executions.py index 4a4d017..713a28d 100644 --- a/cueapi/resources/executions.py +++ b/cueapi/resources/executions.py @@ -58,6 +58,7 @@ def report_outcome( metadata: Optional[dict] = None, external_id: Optional[str] = None, result_url: Optional[str] = None, + result_ref: Optional[str] = None, result_type: Optional[str] = None, summary: Optional[str] = None, artifacts: Optional[list] = None, @@ -74,6 +75,8 @@ def report_outcome( body["external_id"] = external_id if result_url is not None: body["result_url"] = result_url + if result_ref is not None: + body["result_ref"] = result_ref if result_type is not None: body["result_type"] = result_type if summary is not None: diff --git a/pyproject.toml b/pyproject.toml index 1a598ac..c5cce87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,24 +4,51 @@ build-backend = "hatchling.build" [project] name = "cueapi-sdk" -version = "0.1.0" -description = "The official Python SDK for CueAPI — scheduling infrastructure for agents" +version = "0.1.3" +description = "Official Python SDK for CueAPI — open-source execution accountability primitive for AI agents. Schedule agent work, require evidence-backed outcomes, and gate execution with write-once verification." readme = "README.md" -license = { text = "MIT" } +license = { text = "Apache-2.0" } requires-python = ">=3.9" -authors = [{ name = "CueAPI", email = "support@cueapi.ai" }] -keywords = ["cueapi", "scheduling", "ai-agents", "cron", "webhooks", "sdk"] +authors = [{ name = "Vector Apps", email = "support@cueapi.ai" }] +maintainers = [{ name = "Vector Apps", email = "support@cueapi.ai" }] +keywords = [ + "cueapi", + "ai-agents", + "agent-infrastructure", + "scheduling", + "cron", + "webhooks", + "sdk", + "llm", + "llm-observability", + "accountability", + "verification", + "outcome-reporting", + "claude", + "gpt", + "gemini", +] classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", + "Intended Audience :: System Administrators", + "Intended Audience :: Information Technology", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: System :: Monitoring", + "Topic :: System :: Distributed Computing", + "Topic :: Internet :: WWW/HTTP", + "Typing :: Typed", ] dependencies = [ "httpx>=0.24.0", @@ -32,6 +59,10 @@ dependencies = [ Homepage = "https://cueapi.ai" Documentation = "https://docs.cueapi.ai" Repository = "https://github.com/cueapi/cueapi-python" +"Bug Tracker" = "https://github.com/cueapi/cueapi-python/issues" +Changelog = "https://github.com/cueapi/cueapi-python/blob/main/CHANGELOG.md" +"Source Code" = "https://github.com/cueapi/cueapi-python" +"Status Page" = "https://status.cueapi.ai" [tool.pytest.ini_options] testpaths = ["tests"] diff --git a/tests/conftest.py b/tests/conftest.py index a253721..5a4078f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,8 +6,8 @@ from cueapi import CueAPI -STAGING_URL = "https://api-staging-e962.up.railway.app" -STAGING_KEY = os.environ.get("CUEAPI_TEST_KEY", "cue_sk_f22857d8225de1b862995e2baa2ccdd8") +STAGING_URL = os.environ.get("CUEAPI_STAGING_URL", "https://api-staging.cueapi.ai") +STAGING_KEY = os.environ.get("CUEAPI_STAGING_API_KEY", "") @pytest.fixture diff --git a/tests/test_client_init.py b/tests/test_client_init.py new file mode 100644 index 0000000..f14aebc --- /dev/null +++ b/tests/test_client_init.py @@ -0,0 +1,36 @@ +"""Tests for CueAPI client initialization and error handling.""" + +import pytest + +from cueapi import CueAPI +from cueapi.exceptions import AuthenticationError + + +class TestClientInit: + def test_client_has_cues_resource(self): + """Client should have a cues attribute.""" + client = CueAPI("test-key", base_url="https://example.com") + assert hasattr(client, "cues") + assert hasattr(client, "executions") + client.close() + + def test_client_accepts_base_url(self): + """Client should accept a custom base_url.""" + client = CueAPI("test-key", base_url="https://custom.example.com") + assert client._base_url == "https://custom.example.com" + client.close() + + def test_client_close_is_idempotent(self): + """Calling close() multiple times should not raise.""" + client = CueAPI("test-key", base_url="https://example.com") + client.close() + client.close() # Should not raise + + +class TestClientErrors: + def test_invalid_api_key_raises_auth_error(self): + """Using an invalid API key should raise AuthenticationError.""" + client = CueAPI("invalid-key-that-does-not-exist", base_url="https://api-staging-e962.up.railway.app") + with pytest.raises((AuthenticationError, Exception)): + client.cues.list() + client.close()