Skip to content

ci(hubspot): add offline auth and API contract tests - #243

Open
seanspeaks wants to merge 4 commits into
nextfrom
ci/hubspot-auth-receipt
Open

seanspeaks wants to merge 4 commits into
nextfrom
ci/hubspot-auth-receipt

Conversation

@seanspeaks

@seanspeaks seanspeaks commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

The HubSpot module's live API tests need credentials, so they are skipped in ordinary CI. A change can therefore break token exchange, token refresh, or auth headers without the pull request checks noticing. This PR adds an offline CI job that runs the module's real auth and API code against documented HubSpot request shapes, with HTTP mocked, and publishes a JSON summary of the run.

What

  • Adds .github/workflows/hubspot-auth-api-receipt.yml. It runs on changes to packages/v1-ready/hubspot/**, scripts/ci/**, the workflow file, or package-lock.json, and can also be started manually.
  • Adds packages/v1-ready/hubspot/jest.receipt.config.js and an npm run test:receipt script. That job runs the new synthetic auth tests plus the existing oauth, definition, and listContacts suites. The live api.test.js and auther.test.js suites are not part of this job. api.test.js now runs only when HUBSPOT_LIVE_API=1.
  • Adds fixtures under packages/v1-ready/hubspot/tests/fixtures/, transcribed from official HubSpot docs (OAuth 2026-03, GET /integrations/v1/me, GET /crm/v3/objects/contacts). Token values are synthetic-* placeholders, with source notes in GENERATOR.md and provenance.json.
  • The tests call the module's real token, refresh, header, and contacts code. Mocked success responses are returned only when the outbound request matches the expected method, URL, and form fields. Failures covered include a bad authorization code, 401, inactive token, tampered fixture, and expired refresh token.
  • The job is fail-closed and offline: it errors if the tests try to open a network connection, or if provider credential environment variables are set. It does not read GitHub secrets and does not contact HubSpot.
  • On success it uploads a workflow artifact, hubspot-auth-api-receipt, that records the command, pass/fail counts, fixture provenance, and a hash of the api.js file that ran. The summary is labeled synthetic (mocked). This PR does not add a live, credentialed run.

How to test

From the repository root:

node --test scripts/ci/hubspot-auth-api-receipt.test.cjs

From packages/v1-ready/hubspot:

npm run test:receipt

The existing npm test script is unchanged and still uses the package's default Jest config, including MongoMemoryServer. The new job uses jest.receipt.config.js so it can run without that database setup.

Closes #245

Frigg Module Builder added 3 commits November 9, 2026 18:20
Emit a Binding C item 4a synthetic receipt for packages/v1-ready/hubspot.
Run real getToken, refreshAccessToken, addAuthHeaders, and testAuthRequest
against nock, with outbound request-shape assertions and fail-closed
network-deny plus a closed token-env list. Do not wire secrets or emit
an authorized label.
The receipt step in CI run 42673233531 failed after 33/33 tests because
the workflow passed the jest command via HUBSPOT_RECEIPT_COMMAND, which
matches the T-C4-8 HUBSPOT_ prefix. Rename to AML_RECEIPT_COMMAND, keep
the CLI --command argument, and add a regression that invokes the
emitter with the same env and argv the workflow uses.

Also align the 4a receipt with erratum rev2:
- adopt the Architect-pinned 90-day recorded freshness bound
- keep synthetic fixtures off the 90-day clock
- name T-C4-9 a-d (stale-but-pinned, fresh-but-unpinned, non-90 bound,
  API-version mismatch)
- pin deny+spy hosts to api.hubapi.com and app.hubspot.com
- treat set-but-empty provider env as present
- install a distinct spy (nock.emitter no-match) beside disableNetConnect
- exclude the unexercised hapikey / api_key path
- upload the receipt artifact only when both files exist

Local only; does not push.
… receipt; mark 90-day freshness adopted in docs

- name: Write receipt and classification bytes
env:
AML_RECEIPT_COMMAND: npx jest --config jest.receipt.config.js --ci --watchman=false --forceExit --json --outputFile=artifacts/jest-results.json

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The command field in the receipt is not the command that actually ran.

  • The test step runs in packages/v1-ready/hubspot with --outputFile="${GITHUB_WORKSPACE}/artifacts/jest-results.json".
  • AML_RECEIPT_COMMAND records --outputFile=artifacts/jest-results.json, which resolves to packages/v1-ready/hubspot/artifacts/... if someone replays it.
  • The receipt exists to record the exact command and result. Replaying the recorded command writes the JSON to a different location, and the receipt does not mention the working directory. T-C4-8 regression tests also pin this string as WORKFLOW_RECEIPT_COMMAND, so the mismatch is locked in.

Fix: make the executed command and the recorded command identical, for example by running the same string from the same directory and recording the working directory in the receipt:

env:
  AML_RECEIPT_COMMAND: npx jest --config jest.receipt.config.js --ci --watchman=false --forceExit --json --outputFile=../../../artifacts/jest-results.json

In that case, also update WORKFLOW_RECEIPT_COMMAND to match.

Suggested change
AML_RECEIPT_COMMAND: npx jest --config jest.receipt.config.js --ci --watchman=false --forceExit --json --outputFile=artifacts/jest-results.json
AML_RECEIPT_COMMAND: npx jest --config jest.receipt.config.js --ci --watchman=false --forceExit --json --outputFile=../../../artifacts/jest-results.json

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Rewrite HubSpot offline receipt comments, schema, and error labels into
neutral open-source wording; rename hubspot-4a-policy to
hubspot-auth-api-policy; align recorded Jest outputFile with the path
the workflow test step actually writes.

Co-authored-by: Sean Matthews <sean.matthews@lefthook.co>
@cursor cursor Bot changed the title ci(hubspot): add auth/API test receipt job ci(hubspot): add offline auth and API contract tests Nov 15, 2026
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