Skip to content

Commit 075c5c0

Browse files
committed
feat: enhance documentation on import rules and testing practices for Business Services
1 parent 754ce31 commit 075c5c0

12 files changed

Lines changed: 108 additions & 14 deletions

docs/agents-template.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ Update this list for the local project:
5353
- `tests/`: local test suite.
5454
- `data/` or `samples/`: example payloads.
5555

56+
## settings.py Import Rules
57+
58+
- Treat the directory containing `settings.py` as the project import root for
59+
migration.
60+
- Import production graph, message, and component modules from paths reachable
61+
relative to `settings.py`.
62+
- If `production.py` is next to `settings.py`, use
63+
`from production import prod`.
64+
- If the application is packaged under a directory next to `settings.py`, use
65+
package imports such as `from myapp.production import prod`.
66+
- Do not ask users to set `PYTHONPATH` to make migration imports work.
67+
- Do not patch `os.environ["PYTHONPATH"]` or global `sys.path` in application
68+
code to hide import problems.
69+
- Fix import errors by changing the project layout or import statements.
70+
5671
## IoP Rules
5772

5873
- Prefer a Python `Production` object exported through `PRODUCTIONS`.
@@ -115,6 +130,10 @@ iop --migrate settings.py --dry-run
115130
iop --migrate settings.py
116131
```
117132

133+
Do not use `iop --test` as the normal way to test Business Services. Test
134+
services through the runtime director or production runtime API so the deployed
135+
production context, component settings, and configured targets are used.
136+
118137
If this repository uses Docker or Compose, add the exact command here:
119138

120139
```bash

docs/ai-coding.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Ask the tool to read the project guidance before it writes code:
1010
```text
1111
You are helping me build an IoP application.
1212
Read these files first:
13-
- AGENTS.md
13+
- local AGENTS.md, if this application repository has one
1414
- docs/ai-coding.md
1515
- docs/cookbooks/index.md
1616
- docs/getting-started/first-steps.md
@@ -19,15 +19,16 @@ Read these files first:
1919
2020
Use the Python Production graph workflow for new applications.
2121
Do not put component startup logic in __init__(); use on_init().
22+
Treat the directory containing settings.py as the project import root.
23+
Import production modules relative to settings.py; do not modify PYTHONPATH.
24+
Do not use iop --test to test Business Services; use the runtime director.
2225
Use the relevant cookbook for the task.
2326
Show the migration and verification commands.
2427
```
2528

26-
On the published docs site, open
27-
[AGENTS.md](https://github.com/grongierisc/interoperability-embedded-python/blob/master/AGENTS.md)
28-
from the repository root.
29-
30-
For your own IoP application repository, copy the
29+
The IoP framework repository root `AGENTS.md` is for framework source
30+
development, not application guidance. For your own IoP application repository,
31+
copy the
3132
[reusable AGENTS.md template](agents-template.md) into the project root and
3233
adapt it to the local production. For healthcare projects, also read
3334
[Healthcare AI-assisted coding](healthcare-ai-coding.md).

docs/command-line.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,12 @@ python3 -m pip install "iris-persistence>=0.1.0"
377377
378378
## test
379379
380-
The test command allows testing IoP components. You can optionally specify a test name, classname, and body.
380+
The test command is a low-level helper for testing IoP components. You can
381+
optionally specify a test name, classname, and body.
382+
383+
Do not use `iop --test` as the normal way to test Business Services. Test
384+
services through the runtime director or production runtime API so the deployed
385+
production context, component settings, and configured targets are used.
381386
382387
Basic test:
383388
```bash

docs/cookbooks/add-polling-service.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Implementation requirements:
3131
- Do not put startup code in __init__(); use on_init() only if required.
3232
- Update settings.py to add the service and connect service.Output to the
3333
destination component.
34+
- Do not use iop --test to test the service; use the runtime director or
35+
production runtime API for service tests.
3436
- Include migration dry-run and verification commands.
3537
```
3638

@@ -68,12 +70,12 @@ iop --migrate settings.py
6870
- Dry-run migration shows the service, target setting, and destination
6971
component.
7072
- Unit tests cover any pure Python polling decisions or message construction.
71-
- Runtime verification confirms `on_poll()` emits the expected message.
73+
- Runtime verification confirms `on_poll()` emits the expected message through
74+
the deployed production context.
7275

7376
## Common Mistakes
7477

7578
- Polling healthcare HL7v2 files in Python instead of using native HL7 file
7679
services.
7780
- Forgetting to connect `service.Output` to the destination.
7881
- Putting long-lived connection setup in `__init__()` instead of `on_init()`.
79-

docs/cookbooks/code-index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ When starting from source code, build applications through public imports from
7070
`iop` and a `Production` graph. Do not copy internal runtime classes such as
7171
`_BusinessHost` into application code; use them only to understand behavior.
7272

73+
## settings.py Import Quick Reference
74+
75+
Treat the directory containing `settings.py` as the project import root for
76+
migration. Import the production graph, messages, and components from modules
77+
reachable relative to that file, such as `from production import prod` or
78+
`from myapp.production import prod`.
79+
80+
Do not set `PYTHONPATH`, patch `os.environ["PYTHONPATH"]`, or mutate global
81+
`sys.path` in application code to make migration imports pass. Fix the package
82+
layout or import statements instead.
83+
84+
## Runtime Test Quick Reference
85+
86+
Do not use `iop --test` as the normal way to test Business Services. Test
87+
services through the runtime director or production runtime API so the deployed
88+
production context, component settings, and configured targets are used.
89+
7390
## Healthcare Add-on
7491

7592
If the code or task mentions HL7v2, FHIR, Health Connect, FHIR bundles, MLLP,

docs/cookbooks/hello-world-production.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Requirements:
2828
the operation.
2929
- Export PRODUCTIONS = [prod].
3030
- Do not use __init__() for component startup.
31+
- Do not use iop --test to test HelloService; use the runtime director or
32+
production runtime API for service tests.
3133
- Show the migration dry-run command and the command to run the production
3234
migration.
3335
```
@@ -99,4 +101,3 @@ iop --migrate settings.py
99101
`Production` graph.
100102
- Calling `HelloOperation` directly from `HelloService` instead of sending a
101103
message through the production target.
102-

docs/cookbooks/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ Before using a cookbook, give the assistant this context:
77

88
```text
99
You are helping me build an IoP application.
10-
Read AGENTS.md, settings.py, and the relevant cookbook before changing code.
10+
Read local AGENTS.md if this application has one, settings.py, and the
11+
relevant cookbook before changing code.
1112
Use the Python Production graph workflow for new applications.
1213
Do not put component startup logic in __init__(); use on_init().
14+
Treat the directory containing settings.py as the project import root.
15+
Import production modules relative to settings.py; do not modify PYTHONPATH.
16+
Do not use iop --test to test Business Services; use the runtime director.
1317
Show the migration and verification commands.
1418
```
1519

docs/getting-started/first-steps.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,9 @@ iop --migrate settings.py
151151

152152
This command creates the IRIS proxy classes for the Python components and registers `HelloWorld.Production`.
153153

154+
When you need to test `HelloService` at runtime, do not use `iop --test`.
155+
Business Service tests should go through the runtime director or production
156+
runtime API so the deployed production context, component settings, and
157+
configured targets are used.
158+
154159
More information about registering components can be found [here](register-component.md).

docs/getting-started/register-component.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ Migration registers the generated IRIS proxy classes for `FileService` and
5858
class. `prod.connect(file.Output, orders)` sets that setting to the destination
5959
component and records the production graph edge.
6060

61+
When you need to test `FileService` at runtime, do not use `iop --test`.
62+
Business Service tests should go through the runtime director or production
63+
runtime API so the deployed production context, component settings, and
64+
configured targets are used.
65+
6166
## Settings File Sections
6267

6368
A migration file can define these sections:

docs/production-graph.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ object graph. It does not silently fall back to IRIS export. Existing deployed
7979
productions should be reconstructed explicitly with `Production.from_iris(...)`
8080
before testing by target setting path. Runtime status checks fail closed when the
8181
current production cannot be verified. `prod.test(...)` remains a compatibility
82-
alias.
82+
alias. For Business Services, use this production/director runtime path instead
83+
of `iop --test`.
8384

8485
`ComponentRef` exposes convenience methods that delegate to its owning
8586
production: `inspect()`, `start()`, `stop()`, `restart()`, and `test(...)`.

0 commit comments

Comments
 (0)