Commit 9d1b48a
authored
docs(skills): test-skill cleanups and gotchas surfaced from supadata PR (#40)
* docs(skills): simplify test boilerplate and surface root conftest fixtures (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).
* docs(skills): simplify boilerplate, prefer env_credentials, and add SDK-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.
* docs(skills): add auth-default and PyPI-collision gotchas (upgrading-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.
* docs(skills): add missing os import in module-level constants snippet
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.1 parent 21c96bb commit 9d1b48a
3 files changed
Lines changed: 137 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
70 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 75 | + | |
| 76 | + | |
76 | 77 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 78 | + | |
80 | 79 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 80 | + | |
84 | 81 | | |
85 | | - | |
| 82 | + | |
86 | 83 | | |
87 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
88 | 93 | | |
89 | 94 | | |
90 | | - | |
| 95 | + | |
91 | 96 | | |
92 | | - | |
| 97 | + | |
93 | 98 | | |
94 | | - | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
97 | | - | |
| 102 | + | |
| 103 | + | |
98 | 104 | | |
| 105 | + | |
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
103 | | - | |
| 110 | + | |
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| |||
215 | 222 | | |
216 | 223 | | |
217 | 224 | | |
218 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
219 | 248 | | |
220 | 249 | | |
221 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
50 | 56 | | |
51 | | - | |
52 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
53 | 70 | | |
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
57 | 74 | | |
58 | 75 | | |
59 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
60 | 94 | | |
61 | 95 | | |
62 | 96 | | |
| |||
77 | 111 | | |
78 | 112 | | |
79 | 113 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 114 | + | |
84 | 115 | | |
85 | 116 | | |
86 | 117 | | |
87 | 118 | | |
88 | | - | |
| 119 | + | |
89 | 120 | | |
90 | 121 | | |
91 | 122 | | |
92 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
93 | 132 | | |
94 | 133 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
101 | 137 | | |
102 | 138 | | |
103 | | - | |
104 | | - | |
105 | 139 | | |
106 | 140 | | |
107 | 141 | | |
| |||
361 | 395 | | |
362 | 396 | | |
363 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
364 | 415 | | |
365 | 416 | | |
366 | 417 | | |
| |||
448 | 499 | | |
449 | 500 | | |
450 | 501 | | |
| 502 | + | |
| 503 | + | |
451 | 504 | | |
452 | 505 | | |
453 | 506 | | |
| |||
0 commit comments