Skip to content

test(cli): e2e for init apns against the mock API and a mock of Apple - #2026

Merged
ArnabChatterjee20k merged 7 commits into
messaging-provider-cli-init-apnsfrom
messaging-provider-cli-init-apns-e2e
Oct 14, 2026
Merged

ArnabChatterjee20k merged 7 commits into
messaging-provider-cli-init-apnsfrom
messaging-provider-cli-init-apns-e2e

Conversation

@ArnabChatterjee20k

@ArnabChatterjee20k ArnabChatterjee20k commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Adds e2e coverage for appwrite init apns (#2015) to the CLI suite, Tests / CLIGo126. Stacked on #2015.

Mock API

mock-server/app/http.php gains the endpoints init apns calls:

Endpoint
GET /v1/messaging/providers Filtered by the provider query, as the CLI asks
POST /v1/messaging/providers/apns Creates a provider
PATCH /v1/messaging/providers/apns/:providerId Updates a provider
GET /v1/project/platforms Lists the project's platforms
POST /v1/project/platforms/apple Creates an Apple platform; refuses a request without bundleIdentifier

The state is kept per project (x-appwrite-project) in a file, because the Swoole workers share no memory and a rerun has to see what the first run created.

Mock Apple

The CLI gains a hidden APPWRITE_APPLE_HOST variable that points Apple's sign-in, App Store Connect and Developer portal at one base URL. When it's unset, the CLI uses Apple's servers. The mock API serves Apple under /apple, with state kept per Apple ID:

  • Sign-in: widget key, SRP init and complete, and the session. Any password is accepted and there's no two-factor step.
  • Teams: a single team, E2ETEAM123.
  • Keys: list, create (at most two per team) and a one-time download of a generated .p8.
  • App IDs: list, register, and turn on Push Notifications. An App ID ending in .nopush already exists with Push Notifications off.

Harness

tests/e2e/languages/cli/main.go runs the built binary in a temporary project folder holding an appwrite.config.json and a generated .p8 key. It checks what the binary prints and its exit status, then prints CLI_INIT_APNS:passed:

  1. First run (--key-path, --team-id, --bundle-id). It creates both APNs providers and the Apple platform, and prints the next steps (the Appwrite push provider, and the Notification Service Extension). The App ID check is skipped, since there's no terminal and no Apple sign-in.
  2. Rerun: "APNs is already set up". No provider is created and no platform added.
  3. Rejected before any request: a malformed --bundle-id, an unknown --provider, and an unknown --environment each fail.

Harness: Apple (CLI_INIT_APNS_APPLE:passed)

  1. Signs in with APPWRITE_APPLE_ID and APPWRITE_APPLE_PASSWORD, creates the key (saved into the project folder), creates both providers and registers the App ID with Push Notifications.
  2. A rerun reuses the saved sign-in and confirms the App ID is registered.
  3. --register-app-id turns on Push Notifications for an existing App ID.
  4. Creating keys until the team is full fails with the "no free slot" message.

Not covered

Apple's password check (SRP verification) and the two-factor prompt, which needs a terminal, are covered by the Go tests against a fake Apple server (internal/apns/appwrite/adapter_test.go). Expo and fastlane run Apple's own tools.

Test Plan

  • gofmt and go vet on the harness; php -l on the mock API; go build, go vet and go test ./internal/... on the generated CLI; Generation suite and Twig lint.
  • Tests / CLIGo126 on CI. Per the repository's practice, the Docker e2e runs on CI only.

Related PRs and Issues

The mock API keeps messaging providers and project platforms per
project, so the harness can run the built binary on a project folder:
the first run creates both APNs providers and the Apple platform and
prints the next steps, a rerun changes nothing, and a malformed bundle
ID, an unknown --provider and an unknown --environment fail.
The mock keeps providers and platforms in a volume that docker compose
down leaves in place, so a fixed project made every run after the first
see the earlier run's providers and fail its first-run checks.
@hansi-codes

hansi-codes Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Adds persistent mock Appwrite APNs and Apple endpoints and exercises appwrite init apns setup, reruns, invalid inputs, Apple key creation, and App ID registration in the CLI e2e suite. The Apple host override is now injected only into the generated CLI used by that test, leaving the normal generated CLI pointed at Apple's production endpoints.

Latest changes: The latest commit moves the Apple host override out of the CLI template and copies it into only the e2e-generated build, replacing the e2e-tag build with a standard build.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
mock-server/app/http.php Adds file-backed mock Appwrite APNs/platform endpoints and mock Apple sign-in, key, and App ID APIs.
templates/cli/internal/cmd/initpush.go Uses an optional Apple-host provider for mock Apple endpoints while retaining production hosts by default.
tests/e2e/CLIGo126Test.php Builds the CLI with a test-only Apple host override and expects APNs and Apple e2e pass markers.
tests/e2e/languages/cli/applehosts.go Defines the environment-driven Apple host override copied into the e2e-generated CLI.
tests/e2e/languages/cli/main.go Exercises APNs project setup, reruns and invalid inputs, plus mocked Apple key creation and App ID registration.

Reviewed the commits since cf97d07 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

Comment thread tests/e2e/languages/cli/main.go Outdated

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

…PLE_HOST

The e2e tests run init apns against a mock of Apple, so the sign-in,
App Store Connect and Developer portal hosts can all be set to one base
URL. Unset, they stay Apple's servers.
The mock API gains Apple's sign-in, session, team, key and App ID
endpoints under /apple, kept per Apple ID. The harness signs in with an
Apple ID and password, creates the key and registers the App ID, then
reuses the saved sign-in to check the App ID on a rerun, turn on Push
Notifications for an existing App ID, and create keys until the team has
no free slot.
…ns-apple-e2e

test(cli): e2e for init apns against a mock of Apple
@ArnabChatterjee20k ArnabChatterjee20k changed the title test(cli): e2e for init apns test(cli): e2e for init apns against the mock API and a mock of Apple Oct 14, 2026
hansi-codes[bot]
hansi-codes Bot previously requested changes Oct 14, 2026

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · 1 blocking finding to address. Summary

Comment thread templates/cli/internal/cmd/initpush.go Outdated
APPWRITE_APPLE_HOST could send an Apple ID and password to any server
from the shipped CLI. It now lives in a file built only with the e2e
tag, which the CLI e2e suite passes; release builds always talk to
Apple.
@hansi-codes
hansi-codes Bot dismissed their stale review October 14, 2026 11:20

The findings that requested changes are resolved. See the summary comment for what is still open.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@@ -0,0 +1,20 @@
//go:build e2e

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can this file be test only? meaning it only loads for local testing and not in the released sdk. i think we already have a pattern for this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, done in 869867e, following the same pattern as the conformance harness: the file moved to tests/e2e/languages/cli/applehosts.go, and CLIGo126Test copies it into the generated CLI's internal/cmd before go build. It's no longer in getFiles(), so the generated SDK doesn't contain it, and the build tag is gone. What's left in the SDK is the e2eAppleHosts hook, which is nil unless that file is present, so a released CLI always uses Apple's hosts.

The override is no longer generated into the SDK. Like the conformance
harness, it lives under tests/e2e/languages/cli and CLIGo126Test copies
it into the generated CLI before building, so released SDKs never
contain it.
@ArnabChatterjee20k
ArnabChatterjee20k merged commit dfaebd0 into messaging-provider-cli-init-apns Oct 14, 2026
61 checks passed
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