Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/hubspot-auth-api-receipt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Synthetic auth/API test receipt for packages/v1-ready/hubspot.
# Never contacts the live provider, never reads secrets, never emits
# authorized/live, fails closed on HUBSPOT_* or MATTERS_ACCESS_TOKEN.
#
# The receipt command MUST NOT be passed via a HUBSPOT_* env var
# (that prefix is on the PROVIDER_ENV abort list). Use AML_RECEIPT_COMMAND
# or the CLI --command argument only.
name: HubSpot auth/API test receipt

on:
push:
paths:
- 'packages/v1-ready/hubspot/**'
- 'scripts/ci/**'
- '.github/workflows/hubspot-auth-api-receipt.yml'
- 'package-lock.json'
pull_request:
paths:
- 'packages/v1-ready/hubspot/**'
- 'scripts/ci/**'
- '.github/workflows/hubspot-auth-api-receipt.yml'
- 'package-lock.json'
workflow_dispatch:

permissions:
contents: read

jobs:
hubspot-auth-api-receipt:
name: Synthetic auth/API receipt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Fail closed if provider token env is present (PROVIDER_ENV)
run: node scripts/ci/hubspot-auth-api-receipt.cjs --assert-offline-env

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: npm

# Full lock-exact install. A workspace-filtered ci would miss
# @aws-sdk/client-scheduler, which @friggframework/core@2.0.0-next.89
# requires (but does not declare) when loading the HubSpot Api.
- name: Install (npm ci, lock exact)
run: npm ci --ignore-scripts

- name: Receipt script checks
run: node --test scripts/ci/hubspot-auth-api-receipt.test.cjs

- name: Run HubSpot auth/API contract tests (JSON report)
id: tests
working-directory: packages/v1-ready/hubspot
continue-on-error: true
run: |
mkdir -p "${GITHUB_WORKSPACE}/artifacts"
npx jest --config jest.receipt.config.js --ci --watchman=false --forceExit \
--json --outputFile=../../../artifacts/jest-results.json

- 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
run: |
node scripts/ci/hubspot-auth-api-receipt.cjs \
--jest-json "${GITHUB_WORKSPACE}/artifacts/jest-results.json" \
--out "${GITHUB_WORKSPACE}/artifacts/hubspot-auth-api-receipt.json" \
--command "${AML_RECEIPT_COMMAND}" \
--classification synthetic \
--expect-classification synthetic \
--module-ref-branch next \
--module-ref-sha 9f5e5c627a0be42cd25cf28339142891e71eba07

- name: Classification must byte-equal the CI artifact (CLASSIFICATION)
run: |
python3 - <<'PY'
from pathlib import Path
artifact = Path("artifacts/classification").read_bytes()
receipt = Path("artifacts/hubspot-auth-api-receipt.json").read_text()
import json
classify = json.loads(receipt)["classification"].encode("utf-8")
if artifact != classify or artifact != b"synthetic":
raise SystemExit(f"CLASSIFICATION mismatch: file={artifact!r} receipt={classify!r}")
print("CLASSIFICATION: classification bytes equal", artifact)
PY

- name: Upload receipt artifact
# Only run (and therefore only claim success) when both files exist.
# hashFiles is empty when a path is missing; if: always() alone would
# still start the step and if-no-files-found: error would fail it,
# but a skipped upload must not be reported as a successful publish.
if: ${{ always() && hashFiles('artifacts/hubspot-auth-api-receipt.json') != '' && hashFiles('artifacts/classification') != '' }}
uses: actions/upload-artifact@v4
with:
name: hubspot-auth-api-receipt
path: |
artifacts/hubspot-auth-api-receipt.json
artifacts/classification
if-no-files-found: error

- name: Fail the job if tests or receipt failed
if: always()
run: |
if [ "${{ steps.tests.outcome }}" != "success" ]; then
echo "Auth/API contract tests did not succeed (outcome=${{ steps.tests.outcome }})."
exit 1
fi
if [ ! -f artifacts/hubspot-auth-api-receipt.json ] || [ ! -f artifacts/classification ]; then
echo "Receipt or classification file missing."
exit 1
fi
22 changes: 22 additions & 0 deletions packages/v1-ready/hubspot/jest.receipt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Jest config for the HubSpot auth/API synthetic receipt job.
*
* Omits the package's MongoMemoryServer globalSetup/Teardown: these tests
* exercise Definition.requiredAuthMethods and Api against nock, and do not
* need a database. Full `npm test` (jest.config.js) still uses mongo and is
* excluded from this command (see the receipt exclusions).
*/
module.exports = {
testMatch: [
'<rootDir>/tests/auth-api-synthetic.test.js',
'<rootDir>/tests/definition.test.js',
'<rootDir>/tests/listContacts.test.js',
'<rootDir>/tests/oauth.test.js',
],
testPathIgnorePatterns: [
'/node_modules/',
'/tests/api.test.js',
'/tests/auther.test.js',
'/tests/extensions/',
],
};
3 changes: 2 additions & 1 deletion packages/v1-ready/hubspot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"main": "index.js",
"scripts": {
"lint:fix": "prettier --write --loglevel error . && eslint . --fix",
"test": "jest"
"test": "jest",
"test:receipt": "jest --config jest.receipt.config.js"
},
"author": "",
"license": "MIT",
Expand Down
8 changes: 7 additions & 1 deletion packages/v1-ready/hubspot/tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const parsedBody = async function async(resp) {
return body;
}

describe(`${config.label} API tests`, () => {
// Live interactive OAuth suite (Authenticator.oauth2). Not part of the
// synthetic receipt job. That job never sets HUBSPOT_LIVE_API and does
// not wire tokens or secrets. The suite is reported as skipped/excluded
// on the receipt. It is not an authorized live path.
const describeLiveApi = process.env.HUBSPOT_LIVE_API === '1' ? describe : describe.skip;

describeLiveApi(`${config.label} API tests`, () => {
const apiParams = {
client_id: process.env.HUBSPOT_CLIENT_ID,
client_secret: process.env.HUBSPOT_CLIENT_SECRET,
Expand Down
Loading
Loading