Skip to content

feat(servers): add hybrid org context + Servers reads#18

Merged
fbarrento merged 1 commit into
mainfrom
feat/5a-org-context-and-servers-reads
May 15, 2026
Merged

feat(servers): add hybrid org context + Servers reads#18
fbarrento merged 1 commit into
mainfrom
feat/5a-org-context-and-servers-reads

Conversation

@fbarrento
Copy link
Copy Markdown
Contributor

Summary

  • $forge->org($slug) returns an immutable clone bound to the chained org slug (preserves attached MockClient so chained calls don't escape mocks in tests).
  • OrganizationNotSetException guards $forge->servers() / $forge->server($id) when no org has been bound via constructor, env, config, or chain.
  • Read side of Servers: Data\Server, Data\ListServersOptions, Enums\ServerType, GetServer / GetServers requests, ServerResource / ServersResource.
  • tests/Pest.php now leaves Saloon's auto-record default in place (matches ortto-sdk). Missing fixtures are recorded from the live API on first run.
  • New Tests\Utils\ServerFixture extends ForgeFixture to redact server-specific PII: IPs, SSH public key, timezone, ssh_port, identifier, credential_id, and pagination cursors (which embed timestamps).
  • Splits the now-too-large ForgeTest.php into tests/Unit/Forge/<Method>Test.php per the established convention.

Partial closure of #5 (write side — create / update / delete / /actions — lands in a follow-up).

Test plan

  • composer test — pint, rector, phpstan, 202 tests / 407 assertions, 100% coverage.
  • All four tests/Fixtures/Saloon/servers/*.json fixtures recorded against the real Forge API and verified redacted (no real IPs, SSH keys, timezones, or cursor tokens).
  • Cursor-walk test breaks out of iteration after the second yielded server so it doesn't fire a non-existent third call.

🤖 Generated with Claude Code

Introduces the org-context layer:
- `$forge->org($slug)` returns an immutable clone bound to the given org,
  carrying any attached MockClient over so test chains stay mocked
- `OrganizationNotSetException` (extends ForgeException, not ApiException —
  it's a client-side guard, not an HTTP error)
- `servers()` and `server($id)` accessors throw the guard when no org is
  bound via constructor, env, config, or chain

Adds the read side of Servers:
- `Data\Server` DTO (26 fields, dates → DateTimeImmutable)
- `Data\ListServersOptions` (pagination + sort + 8 filter fields)
- `Enums\ServerType` (constants for the spec-enumerated server roles)
- `Requests\Servers\GetServer` / `GetServers`
- `Resources\ServerResource` / `ServersResource` (uses `ParsesPage` trait)

Tests + fixtures:
- ForgeTest split per-method into `tests/Unit/Forge/<Method>Test.php`
  (constructor, fromEnvironment, fromConfig, accessors)
- `Tests\Utils\ServerFixture` extends `ForgeFixture` with server-specific
  redactions (IPs, SSH key, timezone, ssh_port, identifier, credential_id,
  stable pagination cursors)
- `tests/Pest.php` no longer disables Saloon's auto-record default — match
  ortto-sdk; missing fixtures are recorded from the live API
- 4 fixtures recorded: servers/list, servers/get, servers/list-page-1,
  servers/list-page-2 (the last pair drives the cursor-walk test, which
  breaks out of iteration after 2 yields so no third call is made)

Read-side of issue #5; write side (create/update/delete + /actions) lands
in a follow-up PR.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@fbarrento fbarrento self-assigned this May 15, 2026
@fbarrento fbarrento merged commit bc9c6e5 into main May 15, 2026
26 checks passed
fbarrento added a commit that referenced this pull request May 15, 2026
#19)

Completes the Servers slice for #5. The read side landed in #18; this PR
adds the mutating surface:

- `CreateServerData` (top-level required: name/provider/type/ubuntuVersion;
  optional: credentialId/phpVersion/databaseType + provider sub-config)
- `UpdateServerData` (all optional; `toArray()` strips nulls so partial
  updates only send the keys that changed)
- `HetznerServerConfig` — first provider sub-config DTO; AWS/Akamai/etc.
  follow the same shape when needed
- Input enums for spec-closed sets: `PhpVersion`, `DatabaseType`,
  `UbuntuVersion`, `ServerAction`
- Requests: `CreateServer` (POST), `UpdateServer` (PUT), `DeleteServer`
  (DELETE), `SendServerAction` (POST /actions)
- Resource methods: `ServersResource::create()`,
  `ServerResource::update()` / `delete()` / `reboot()` / `powerCycle()`

`Server` DTO loosened: `revoked` and `connection_status` are now nullable
because freshly-created (202 async) responses return them as null —
contrary to the OpenAPI spec but matching observed runtime behavior.

Recording / cleanup:
- One end-to-end `ServerWriteLifecycleTest` creates a real Hetzner cax11
  server, exercises update/reboot, then deletes it. A try/finally
  safety-net delete catches any partway-through failure so we don't leak
  billed infra.
- Recorded four fixtures (`create.json`, `update.json`,
  `action-reboot.json`, `delete.json`) against the live Forge API.
- `ServerFixture` extended to redact the freshly-leaking
  `meta.sudo_password` (Forge returns this on create — it's the
  generated server SSH password).

`tests/Pest.php` already auto-records via Saloon's native default (set up
in #18). Recording requires `.env` with FORGE_TEST_TOKEN,
FORGE_TEST_ORG_SLUG, FORGE_TEST_HETZNER_CREDENTIAL_ID,
FORGE_TEST_HETZNER_REGION (Forge id/code/alt all accepted),
FORGE_TEST_HETZNER_SIZE (must be the size *code* like `cax11`, not the
numeric Forge id), FORGE_TEST_HETZNER_NETWORK_ID. Replay needs nothing.

241 tests / 469 assertions / 100% coverage.

Closes #5.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
fbarrento added a commit that referenced this pull request May 19, 2026
Captures the four spec mismatches surfaced while building the Servers
slice (#18 + #19) plus the open-strings-not-enums decision from the
Providers slice (#16 + #17). Append future findings here so the next
debugging session can find the answer without re-running live-fire
investigations.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
@fbarrento fbarrento mentioned this pull request May 24, 2026
2 tasks
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.

1 participant