feat(substack): upgrade to SDK 2.0.0 with unit + integration tests#384
Conversation
Migrate the Substack integration to autohive-integrations-sdk 2.0.0. Source: - Unwrap FetchResponse: access response body via .data at all 5 fetch call sites (get_publication_posts, get_post, search_publications, search_posts, get_post_comments). - No ActionError conversion needed — the integration has no error-signalling returns and relies on context.fetch raising on non-2xx (consistent with the 1.x source). config.json: - Bump version 1.0.0 -> 2.0.0. - Make raw-passthrough comment item fields nullable (body, date, author_name, author_id, like_count, id). Comments are returned unmodified (not via _drop_none like posts), and the live API returns null body on deleted comments — without this, SDK v2 output validation recurses into array items and raises VALIDATION_ERROR on a 200. requirements.txt: - Pin autohive-integrations-sdk~=2.0.0. Tests: - Replace the old unittest suite with pytest unit + integration suites. - Unit (38): all actions, FetchResponse mocks, null-field handling, validation errors; includes a regression test for null comment fields. - Integration (14, live, no auth): all actions against a real public publication, plus a bad-slug test asserting HTTPError propagates. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🔍 Integration Validation ResultsCommit: Changed directories:
✅ Structure Check output✅ Code Check output✅ Tests Check output✅ README Check output✅ Version Check output |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efbbf029bf
ℹ️ 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".
tests/conftest.py prepended the substack/ directory to sys.path, which made substack.py importable as a top-level module and shadowed the substack package. Under that path ordering, the package-style imports in the test modules (from substack import substack / from substack.substack import _normalise_url) fail at collection with "substack is not a package" — flagged in review and reproducible when the repo root is not resolved first. Drop the path manipulation and rely on repo-root package resolution (the root conftest.py puts the repo root on sys.path, and import-mode=importlib does not re-insert test dirs). This matches the circle integration, which uses the same __init__ re-export and package imports with no path hack. The conftest is kept (validate_integration.py requires tests/conftest.py) but now only documents the import strategy. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
confirmed and fixed in 4c8360f.
Fix: removed the Verified after the fix: unit 38 passed, integration 14 passed / 1 skipped (live), |
TheRealAgentK
left a comment
There was a problem hiding this comment.
Requesting one small should-fix before merge:
substack/tests/test_substack_integration.py reads SUBSTACK_TEST_PUBLICATION_URL and SUBSTACK_TEST_POST_SLUG, but this PR does not add blank template entries for them in the root .env.example. Even though both are optional, the integration-test checklist asks that every env var read by integration tests is documented there.
Suggested addition:
# -- Substack --
# Optional: publication URL used by Substack live integration tests.
# SUBSTACK_TEST_PUBLICATION_URL=
# Optional: post slug used by Substack get_post live integration tests.
# SUBSTACK_TEST_POST_SLUG=Everything else in the SDK v2 migration, tests, and validation looked good.
Documents SUBSTACK_TEST_PUBLICATION_URL and SUBSTACK_TEST_POST_SLUG in the root .env.example as requested in PR review. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Migrates the Substack integration to
autohive-integrations-sdk~=2.0.0.Substack's public API requires no authentication, so this integration has no credentials, no auth config, and no error-signalling action returns — it relies on
context.fetchraisingHTTPError/RateLimitErroron non-2xx (the SDK v2 behaviour).Changes
Source (
substack.py).dataat all 5context.fetchcall sites:get_publication_posts,get_post,search_publications,search_posts,get_post_comments. The two dict-guarded sites assignbody = response.datafirst soisinstance(...)checks the body, not theFetchResponse.ActionErrorconversion — the integration has noActionResult(data={"error": ...})patterns; the 1.x source had notry/excepteither, so the no-error-handling stance is unchanged and consistent. Hardening is out of pure-migration scope.config.json1.0.0→2.0.0.body,date,author_name,author_id,like_count,id). Comments are returned as raw API passthrough (unlike posts/publications, which_drop_nonecleans). The live API returnsbody: nullon deleted comments — without nullable types, SDK v2 output validation recurses into the array items and raisesVALIDATION_ERRORon a successful 200. Confirmed against the live API, not speculative.requirements.txtautohive-integrations-sdk~=2.0.0.Tests
unittestsuite (tests/context.py,tests/test_substack.py).test_substack_unit.py) — 38 tests: every action,FetchResponsemocks,_drop_nonenull-field handling, validation errors, and a regression test (test_null_comment_fields_pass_output_validation) reproducing the null-body case the schema fix addresses.test_substack_integration.py) — 14 tests, live, no auth: every action against a real public publication (defaulthttps://www.astralcodexten.com, overridable viaSUBSTACK_TEST_PUBLICATION_URL), plus a bad-slug test assertingHTTPErrorpropagates so thereal_fetchraise path is actually exercised.real_fetchreturnsFetchResponseand raisesHTTPError/RateLimitErroron non-ok per repo convention.Verification (run on the final commit,
efbbf02)validate_integration.pycheck_code.py(lint, format, bandit, pip-audit, config-sync, fetch patterns)Self-review
Reviewed against the
upgrading-sdk-v2,writing-unit-tests, andwriting-integration-testsskills, plus an independent fresh-context review of the branch diff. The comment-nullability bug and the missing error-path test coverage were both found and fixed pre-emptively during that review rather than left for a reviewer to flag. The 1 skip is expected (get_post_commentsskips when a post has no numeric id).