Skip to content

docs(skills): test-skill cleanups and gotchas surfaced from supadata PR#40

Merged
TheRealAgentK merged 4 commits into
masterfrom
feat/skills-update-from-supadata-pr
May 4, 2026
Merged

docs(skills): test-skill cleanups and gotchas surfaced from supadata PR#40
TheRealAgentK merged 4 commits into
masterfrom
feat/skills-update-from-supadata-pr

Conversation

@TheRealAgentK
Copy link
Copy Markdown
Collaborator

Summary

Three skills get updates based on lessons learned while reviewing autohive-ai/autohive-integrations#280 (Supadata SDK 2.0 upgrade) and the production crash that prompted it (autohive-ai/autohive-integrations#316).

Each commit is independently reviewable.

Commits

b02b631 writing-unit-tests

  • Promote plain imports as the default test-file boilerplate; keep importlib.util.spec_from_file_location as a documented fallback for unusual layouts. Most integrations don't need the heavy form when tests/conftest.py does a 2-line sys.path.insert.
  • Replace the "every file declares its own mock_context" guidance with the override-in-conftest pattern. The repo-wide conftest.py already provides mock_context, make_context, and env_credentials — tests should reuse them.
  • Add a @pytest.mark.parametrize example to "Testing Helper Functions" for collapsing tabular helper tests.
  • New "Common Gotchas" entry: PyPI package name collision (the supadata case). When the integration folder is named after a PyPI package the source imports, the empty __init__.py shadows the real package; the fix is to drop it.

641e54b writing-integration-tests

  • Same boilerplate simplification as the unit-tests skill (cross-references the unit-tests skill for the importlib fallback rather than duplicating it).
  • Promote env_credentials from the repo-wide conftest.py as the recommended way to handle API-key / token env vars; module-level os.environ.get stays for object IDs which env_credentials doesn't model.
  • Add Variant 4: External Python SDK (no context.fetch) — for integrations that call a third-party Python SDK directly rather than context.fetch. The aiohttp wrapper is irrelevant for these; the variant is a 4-line make_context(auth=...) fixture. The "How to choose" guidance is now a decision table covering all four variants.

5e1346b upgrading-sdk-v2

Two new "Common Gotchas" entries:

  • Audit auth lookup defaults during the upgrade. 1.0.x integrations sometimes shipped with .get("api_key", {}) — a dict default for a string field. Empty credentials then crash the upstream SDK with TypeError, which surfaces as a Lambda 500 / crash report instead of a user-facing auth error. The 2.0.0 upgrade is the right moment to fix because the auth path is being touched anyway to add ActionError.
  • PyPI package name collision — same content as the unit-tests gotcha, surfaced at upgrade time so it's caught before the upgrade PR is opened.

Why now

The supadata PR review made it clear that:

  1. The current heavy importlib boilerplate is overkill for the common case and obscures cleaner alternatives.
  2. New contributors keep redeclaring mock_context / env-var lookups instead of using the repo-wide fixtures because the skills don't mention them.
  3. The PyPI-name-collision case is a real footgun (it caused PR #280's first round of complications) and deserves explicit gotcha entries on both sides.
  4. The bug behind issue #316 — the {} auth default — is exactly the kind of thing a 2.0 upgrade should catch in passing, but the skill didn't flag it.

Out of scope

  • Migrating existing tests in autohive-integrations to the simpler boilerplate. The skill change applies forward to new tests; existing files (perplexity, hubspot, bitly, etc.) all use the heavy form and that's fine — no need to churn them.
  • The validator-rule update (__init__.py should be optional when the folder name collides with a PyPI dependency) — filed separately as autohive-ai/autohive-integrations-tooling#39.
  • The "fail when missing unit or integration tests" tooling check — filed separately as autohive-ai/autohive-integrations-tooling#40.

Test plan

The skills are markdown documentation; no code or tests are affected. Sanity-checked:

  • git diff --stat shows only the three skills touched.
  • No SDK source changes → no pdoc regen required per AGENTS.md.

…tures (writing-unit-tests)

Test files in autohive-integrations don't need the heavy
`importlib.util.spec_from_file_location` boilerplate when the
integration source can be imported as a normal module. With a
2-line `sys.path.insert` in `tests/conftest.py`, plain
`from <integration> import ...` works fine. The repo-wide
`conftest.py` also already provides three fixtures every test
should reuse instead of redeclaring locally:

- `mock_context` — minimal ExecutionContext
- `make_context` — factory for arbitrary auth shapes
- `env_credentials` — `.env`-aware env-var lookup with skip support

Changes:

- Promote plain imports as the default boilerplate; keep the
  `importlib` form as a documented fallback for unusual layouts.
- Replace the 'every file declares its own mock_context' guidance
  with the override-in-conftest pattern, so credential shapes are
  set once per integration and inherited by all tests.
- Add a parametrize example to 'Testing Helper Functions' for
  collapsing tabular helper tests (e.g. ms_to_timestamp boundaries).
- New 'Common Gotchas' entry: PyPI package name collision. When the
  integration folder name matches a PyPI package the source imports
  (e.g. supadata, dropbox), the empty `__init__.py` shadows the
  real package. The fix is to drop `__init__.py` — the validator
  treats it as optional, the Lambda runtime is unaffected, and tests
  no longer need `site.getsitepackages()` / `importlib` shims.

Surfaced while reviewing Autohive-AI/autohive-integrations#280
(Supadata SDK 2.0 upgrade).
…DK-call variant (writing-integration-tests)

Three updates aligned with the writing-unit-tests skill changes:

1. Replace the heavy `importlib` boilerplate with plain imports
   (matching the unit-tests skill). Cross-reference the unit-tests
   skill for the `importlib` fallback rather than duplicating it.

2. Promote `env_credentials` from the repo-wide `conftest.py` as
   the recommended way to handle API-key / token env vars. The
   fixture auto-loads `.env` and integrates with `pytest.skip`
   when a key is missing. Module-level `os.environ.get(...)` is
   still useful for object IDs (which env_credentials doesn't model
   directly), so the require_* helpers stay — but credentials should
   be read via env_credentials.

3. Add Variant 4: 'External Python SDK (no `context.fetch`)'.
   Some integrations (e.g. supadata) call a third-party Python SDK
   directly rather than going through `context.fetch`. For these,
   the aiohttp-wrapping fixture is irrelevant — the SDK does its
   own networking. The new variant is a 4-line fixture that just
   injects credentials via `make_context(auth=...)`. Updated the
   'How to choose' guidance to a decision table covering all four
   variants by auth shape and networking pattern.

Surfaced while reviewing Autohive-AI/autohive-integrations#280.
…sdk-v2)

Two new entries in the 'Common Gotchas' section, both surfaced
while reviewing Autohive-AI/autohive-integrations#280 (Supadata
1.0.0 → 2.0.0 upgrade) and the underlying production crash report
in Autohive-AI/autohive-integrations#316:

1. Audit auth lookup defaults during the upgrade. Several 1.0.x
   integrations shipped with the wrong default *type* in their
   auth lookup, e.g.:

       context.auth.get('credentials', {}).get('api_key', {})

   The `{}` default returns a dict when the field is empty, which
   crashes the upstream SDK that expects a string with TypeError —
   surfacing as a Lambda 500 / Raygun crash instead of the
   user-facing auth error it actually is. The 2.0.0 upgrade is the
   right moment to fix this because the auth path is being touched
   anyway to convert error returns to ActionError.

2. PyPI package name collision. When the integration folder is
   named after a PyPI package the source imports
   (e.g. `from supadata import Supadata` inside `supadata/`),
   the empty `__init__.py` shadows the real PyPI package and
   every test fails with ImportError. Drop the `__init__.py` —
   the validator treats it as optional, the Lambda runtime is
   unaffected, and tests can use plain imports. Cross-references
   the writing-unit-tests skill where the matching test-side
   gotcha now lives.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Coverage — eb1eef2 (docs(skills): add missing os import in module-level constants snippet) by @TheRealAgentK

Total coverage: 100%

File Stmts Miss Cover Missing
src/autohive_integrations_sdk/__init__.py 2 0 100%
src/autohive_integrations_sdk/integration.py 358 0 100%

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e1346b185

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread skills/writing-integration-tests/SKILL.md
The new file-header boilerplate dropped `import os` (it's no longer
needed once the importlib path-juggling is gone), but the
'Module-level constants' snippet a few sections later still uses
`os.environ.get(...)`. Readers who copy both sections verbatim
would hit `NameError` at import time.

Add `import os` directly to the constants snippet and call out in
prose that it should join the file-header imports. Keeps each
snippet self-contained and executable.

Caught by the codex review bot on PR #40.
@TheRealAgentK TheRealAgentK merged commit 9d1b48a into master May 4, 2026
1 check passed
@TheRealAgentK TheRealAgentK deleted the feat/skills-update-from-supadata-pr branch May 4, 2026 03:08
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.

2 participants