Skip to content

Commit 09b8a10

Browse files
committed
Create AGENTS guidance doc
1 parent 7e12e56 commit 09b8a10

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

AGENTS.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# AGENTS.md
2+
3+
## Project Scope
4+
5+
This repository is the `php-opencloud/openstack` SDK: a PHP client for multiple OpenStack services. The public entry point is `src/OpenStack.php`, which creates versioned service objects through shared builder logic in `src/Common/`.
6+
7+
The project follows semantic versioning and still supports PHP `^7.2.5 || ^8.0`. Keep changes narrowly scoped and avoid API breaks unless the task explicitly requires them.
8+
9+
## Repository Layout
10+
11+
- `src/`
12+
- `Common/`: shared API, resource, service, auth, error, JSON-schema, and transport infrastructure.
13+
- `<Service>/<version>/`: versioned SDK surface for each OpenStack service. Most service folders contain:
14+
- `Api.php`: declarative operation definitions (`method`, `path`, `params`, optional `jsonKey`)
15+
- `Params.php`: parameter schemas and wire-format metadata
16+
- `Service.php`: top-level user-facing service methods
17+
- `Models/`: resource classes with behavior and hydration rules
18+
- `tests/unit/`: mocked unit tests, usually mirroring the `src/` namespace layout.
19+
- `tests/sample/`: integration-style tests that execute files from `samples/`.
20+
- `samples/`: runnable examples; these double as integration-test inputs.
21+
- `doc/`: Sphinx/reStructuredText documentation.
22+
- `.github/workflows/`: CI definitions for formatting, unit tests, and integration tests.
23+
24+
## Architecture Conventions
25+
26+
When adding or changing SDK functionality, preserve the existing layering:
27+
28+
1. Define or update the REST operation in `Api.php`.
29+
2. Add or reuse parameter definitions in `Params.php`.
30+
3. Expose the behavior from `Service.php` if it is part of the top-level service API.
31+
4. Implement resource behavior in `Models/*` when the operation belongs on a model instance.
32+
5. Add unit tests and, for user-facing flows, a sample plus sample test when practical.
33+
34+
Specific patterns used throughout the codebase:
35+
36+
- `Service.php` methods are intentionally thin. They usually create a model, populate it, or delegate to `enumerate(...)`.
37+
- Resource classes commonly extend `OpenStack\Common\Resource\OperatorResource`, set `$resourceKey`, `$resourcesKey`, and `$markerKey`, and use `execute(...)` plus `populateFromResponse(...)`.
38+
- API field renames are handled with `$aliases` and `Alias` objects instead of ad hoc mapping code.
39+
- Operation option arrays are documented with `{@see \Namespace\Api::methodName}` docblocks. Keep those references accurate when signatures change.
40+
- Reuse shared abstractions in `src/Common/` before introducing service-specific helpers.
41+
42+
## PHP Compatibility Rules
43+
44+
The SDK is tested against PHP `7.2` through `8.4` in CI. Do not introduce syntax or standard-library dependencies that require newer PHP versions than `7.2.5`.
45+
46+
In practice, avoid:
47+
48+
- union types
49+
- attributes
50+
- constructor property promotion
51+
- enums
52+
- `match`
53+
- `readonly`
54+
- typed properties
55+
- named arguments in code examples or tests
56+
57+
Follow the surrounding file for `declare(strict_types=1);`. Many `src/` files use it, but not every file in the repository does.
58+
59+
## Testing Expectations
60+
61+
There are no Composer scripts in this repository; run tools directly from `vendor/bin`.
62+
63+
Primary local checks:
64+
65+
```bash
66+
composer install
67+
vendor/bin/parallel-lint --exclude vendor .
68+
vendor/bin/phpunit --configuration phpunit.xml.dist
69+
vendor/bin/php-cs-fixer fix --dry-run --diff
70+
```
71+
72+
Additional checks when relevant:
73+
74+
```bash
75+
composer normalize
76+
vendor/bin/phpunit --configuration phpunit.sample.xml.dist
77+
```
78+
79+
Notes:
80+
81+
- CI runs unit tests against both lowest and highest dependency sets, so avoid relying on the latest transitive behavior only.
82+
- Integration tests require a live OpenStack environment, the environment variables from `env_test.sh.dist`, and an image named `cirros`.
83+
- `php-cs-fixer` is configured for `src/`, `samples/`, and `.php-cs-fixer.dist.php`; tests are not auto-formatted by that config, so keep test edits manually consistent with surrounding code.
84+
85+
## Unit Test Patterns
86+
87+
Unit tests usually extend `tests/unit/TestCase.php`.
88+
89+
Follow the existing test style:
90+
91+
- set `rootFixturesDir` in `setUp()` when the test uses fixture responses
92+
- use `mockRequest(...)` to assert HTTP method, path, body, headers, and returned response
93+
- store larger or realistic HTTP responses as `.resp` files under a nearby `Fixtures/` directory
94+
- mirror the production namespace and folder layout where possible
95+
96+
Prefer adding focused tests around the exact operation being changed instead of broad cross-service rewrites.
97+
98+
## Samples And Integration Coverage
99+
100+
`samples/` are executable examples and are also exercised by `tests/sample/`. When you add a new user-facing capability, consider whether it should have:
101+
102+
- a sample under the matching service/version folder in `samples/`
103+
- a corresponding sample test under `tests/sample/`
104+
- documentation in `doc/services/` if the feature is part of the supported public workflow
105+
106+
Sample tests typically create a temporary PHP file from a template and `require_once` it, so keep samples self-contained and readable.
107+
108+
## Documentation
109+
110+
User docs live in `doc/` and use Sphinx plus reStructuredText. If a change affects public behavior, examples, or supported options, update docs as needed.
111+
112+
Typical doc build:
113+
114+
```bash
115+
pip install -r doc/requirements.txt
116+
make -C doc html
117+
```
118+
119+
## Change Heuristics
120+
121+
- Prefer small, service-scoped changes over broad refactors.
122+
- Preserve public method names and option shapes unless the task explicitly calls for a breaking change.
123+
- Keep docblocks accurate for public APIs and option arrays.
124+
- Reuse existing fixtures, sample patterns, and helper methods before inventing new ones.
125+
- If `composer.json` changes, run `composer normalize` because CI auto-normalizes that file.

0 commit comments

Comments
 (0)