mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-07 03:00:29 +00:00
parent
5878cfd04a
commit
95d887b025
6 changed files with 3325 additions and 24 deletions
529
run.json
529
run.json
File diff suppressed because one or more lines are too long
2574
stages/005-implement@1/diff.patch
Normal file
2574
stages/005-implement@1/diff.patch
Normal file
File diff suppressed because it is too large
Load diff
6
stages/005-implement@1/status.json
Normal file
6
stages/005-implement@1/status.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"outcome": "succeeded",
|
||||
"notes": "Stage completed: implement",
|
||||
"failure_reason": null,
|
||||
"timestamp": "2026-05-29T18:29:49.348261Z"
|
||||
}
|
||||
207
stages/006-simplify_opus@1/prompt.md
Normal file
207
stages/006-simplify_opus@1/prompt.md
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
Goal: ---
|
||||
title: "feat: Add Environment REST CRUD API"
|
||||
type: feat
|
||||
status: active
|
||||
date: 2026-05-28
|
||||
---
|
||||
|
||||
# feat: Add Environment REST CRUD API
|
||||
|
||||
## Summary
|
||||
|
||||
Add server-owned Environment CRUD under `/api/v1/environments`, modeled after
|
||||
Automations and backed by the existing `EnvironmentStore`. The API manages only
|
||||
the server-side environment catalog in `environments/*.toml`; client-side
|
||||
environment definitions in `workflow.toml`, `.fabro/project.toml`, or run inputs
|
||||
continue to work and are not managed by this API.
|
||||
|
||||
## API Contract
|
||||
|
||||
- Add OpenAPI paths:
|
||||
- `GET /api/v1/environments`
|
||||
- `POST /api/v1/environments`
|
||||
- `GET /api/v1/environments/{id}`
|
||||
- `PUT /api/v1/environments/{id}`
|
||||
- `DELETE /api/v1/environments/{id}`
|
||||
- Mirror Automations semantics:
|
||||
- List returns `{ data: Environment[], meta: { total } }`, sorted by id.
|
||||
- Create body includes `id`; replace body omits `id`; path id is authoritative.
|
||||
- `GET` and `PUT` return `ETag: "<revision>"`.
|
||||
- `PUT` and `DELETE` require `If-Match`.
|
||||
- Use existing Automation-style statuses: `400`, `404`, `409`, `422`, `428`, `500`.
|
||||
- Stale revisions return `409` to match Automations.
|
||||
- Add API-specific Environment request/response schemas so REST `image.dockerfile`
|
||||
accepts only inline content or `null`.
|
||||
- Existing workflow/settings schemas keep supporting Dockerfile `path`.
|
||||
- REST requests with Dockerfile `path` return `422` and must not read
|
||||
server-local files.
|
||||
- Do not add `PATCH` in v1.
|
||||
|
||||
## Implementation Changes
|
||||
|
||||
- OpenAPI and generated clients:
|
||||
- Update `docs/public/api-reference/fabro-api.yaml` with an `Environments` tag,
|
||||
an `EnvironmentId` parameter, CRUD paths, list envelope, and inline-only API
|
||||
image schema.
|
||||
- Regenerate Rust API types and the TypeScript Axios client.
|
||||
- Keep the existing `EnvironmentSettings` schema intact for workflow settings.
|
||||
- Server:
|
||||
- Add `lib/crates/fabro-server/src/server/handler/environments.rs`, following
|
||||
`automations.rs` for routes, auth, ETag parsing, and error mapping.
|
||||
- Merge the routes into real API routes; do not add demo routes unless an
|
||||
existing convention requires it.
|
||||
- Convert API request DTOs into `EnvironmentDraft` / `EnvironmentSettings` only
|
||||
after rejecting Dockerfile path sources.
|
||||
- Map `EnvironmentStoreError` similarly to Automations: duplicate, protected,
|
||||
and stale as `409`; missing as `404`; validation as `422`; internal
|
||||
storage/parse/io as curated `500`.
|
||||
- After successful create, replace, or delete, refresh cached manifest run
|
||||
settings from the current `EnvironmentStore` catalog so `/system/info` and
|
||||
default run settings reflect the updated catalog.
|
||||
- Domain and API types:
|
||||
- Use a meaningful API DTO boundary rather than treating REST and TOML as
|
||||
identical Dockerfile-source surfaces.
|
||||
- Reuse `fabro-environment::Environment` for persisted domain behavior where
|
||||
the wire shape matches; keep API-only request schemas distinct where
|
||||
inline-only Dockerfile behavior differs.
|
||||
|
||||
## Implementation Units
|
||||
|
||||
- [ ] **Unit 1: Define the OpenAPI contract**
|
||||
- Add the environment CRUD paths, schemas, and path parameter.
|
||||
- Ensure the spec distinguishes REST-safe inline Dockerfile sources from the
|
||||
existing workflow/settings Dockerfile source schema.
|
||||
- Verification: OpenAPI route conformance can see the new paths and generated
|
||||
clients expose an `EnvironmentsApi`.
|
||||
|
||||
- [ ] **Unit 2: Add server environment handlers**
|
||||
- Implement a new handler module mirroring the Automation CRUD handler shape.
|
||||
- Enforce authentication, id parsing, ETag/If-Match behavior, and error mapping.
|
||||
- Reject REST Dockerfile path sources before calling `EnvironmentStore`.
|
||||
- Verification: server API tests prove CRUD behavior and failure responses.
|
||||
|
||||
- [ ] **Unit 3: Refresh derived server state after mutations**
|
||||
- Ensure successful environment create, replace, and delete refresh any cached
|
||||
manifest run settings derived from `EnvironmentStore::catalog_layer()`.
|
||||
- Preserve existing client-side environment precedence and behavior.
|
||||
- Verification: a test proves newly created server environments affect the
|
||||
resolved server default run environment where applicable.
|
||||
|
||||
- [ ] **Unit 4: Regenerate clients and add contract tests**
|
||||
- Regenerate `fabro-api` and `lib/packages/fabro-api-client`.
|
||||
- Add Rust server integration tests and keep OpenAPI conformance passing.
|
||||
- Verification: generated Rust and TypeScript surfaces compile and expose the
|
||||
new environment operations.
|
||||
|
||||
## Test Plan
|
||||
|
||||
- Add server API tests in
|
||||
`lib/crates/fabro-server/tests/it/api/environments.rs` and register the module.
|
||||
- Cover:
|
||||
- List returns seeded environments and correct total.
|
||||
- Create persists `environments/{id}.toml`, returns `201`, and is visible via
|
||||
list/get.
|
||||
- Get returns current `ETag` matching `revision`.
|
||||
- Replace with valid `If-Match` updates the file, returns a new revision, and
|
||||
updates the `ETag`.
|
||||
- Replace/delete without `If-Match` return `428`.
|
||||
- Stale replace/delete return `409`.
|
||||
- Duplicate create returns `409`.
|
||||
- Invalid id/header returns `400`.
|
||||
- Domain validation failures return `422`.
|
||||
- Dockerfile `path` over REST returns `422` and does not persist or expose file
|
||||
contents.
|
||||
- Delete removes a non-default environment; deleting `default` returns a
|
||||
protected conflict.
|
||||
- Unauthenticated environment routes return `401`.
|
||||
- Creating an environment referenced by server default run settings refreshes
|
||||
cached manifest run settings.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- This API manages server-owned environments only; client-defined catalogs remain
|
||||
file/request scoped.
|
||||
- Built-in seed behavior follows the current store: seeded environments are
|
||||
listed, create conflicts with existing ids, and `default` is protected from
|
||||
delete.
|
||||
- Create responses match Automations and do not need an `ETag`; clients can use
|
||||
the returned `revision` or call `GET`.
|
||||
- Inline-only Dockerfile policy applies only to REST CRUD, not local TOML
|
||||
configuration.
|
||||
|
||||
## Sources
|
||||
|
||||
- `docs/public/api-reference/fabro-api.yaml`
|
||||
- `lib/crates/fabro-server/src/server/handler/automations.rs`
|
||||
- `lib/crates/fabro-environment/src/store.rs`
|
||||
- `lib/crates/fabro-environment/src/model.rs`
|
||||
- `docs/public/execution/environments.mdx`
|
||||
|
||||
|
||||
## Completed stages
|
||||
- **toolchain**: succeeded
|
||||
- Script: `command -v cargo >/dev/null || { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && sudo ln -sf $HOME/.cargo/bin/* /usr/local/bin/; }; cargo --version 2>&1`
|
||||
- Output:
|
||||
```
|
||||
cargo 1.95.0 (f2d3ce0bd 2026-03-21)
|
||||
```
|
||||
- **preflight_compile**: succeeded
|
||||
- Script: `cargo check -q --workspace 2>&1`
|
||||
- Output: (empty)
|
||||
- **preflight_lint**: succeeded
|
||||
- Script: `cargo +nightly-2026-04-14 clippy -q --workspace --all-targets -- -D warnings 2>&1`
|
||||
- Output: (empty)
|
||||
- **implement**: succeeded
|
||||
- Model: gpt-5.5, 2.2m tokens in / 38.1k out
|
||||
|
||||
|
||||
# Simplify: Code Review and Cleanup
|
||||
|
||||
Review changes vs. origin for reuse, quality, and efficiency. Fix any issues found.
|
||||
|
||||
## Phase 1: Identify Changes
|
||||
|
||||
Run git diff (or git diff HEAD if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files that the user mentioned or that you edited earlier in this conversation.
|
||||
|
||||
## Phase 2: Launch Three Review Agents in Parallel
|
||||
|
||||
Use the Agent tool to launch all three agents concurrently in a single message. Pass each agent the full diff so it has the complete context.
|
||||
|
||||
### Agent 1: Code Reuse Review
|
||||
|
||||
For each change:
|
||||
|
||||
1. Search for existing utilities and helpers that could replace newly written code. Use Grep to find similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones.
|
||||
2. Flag any new function that duplicates existing functionality. Suggest the existing function to use instead.
|
||||
3. Flag any inline logic that could use an existing utility — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates.
|
||||
|
||||
Note: This is a greenfield app, so focus on maximizing simplicity and don't worry about changing things to achieve it.
|
||||
|
||||
### Agent 2: Code Quality Review
|
||||
|
||||
Review the same changes for hacky patterns:
|
||||
|
||||
1. Redundant state: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
|
||||
2. Parameter sprawl: adding new parameters to a function instead of generalizing or restructuring existing ones
|
||||
3. Copy-paste with slight variation: near-duplicate code blocks that should be unified with a shared abstraction
|
||||
4. Leaky abstractions: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
|
||||
5. Stringly-typed code: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
|
||||
|
||||
Note: This is a greenfield app, so be aggressive in optimizing quality.
|
||||
|
||||
### Agent 3: Efficiency Review
|
||||
|
||||
Review the same changes for efficiency:
|
||||
|
||||
1. Unnecessary work: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
|
||||
2. Missed concurrency: independent operations run sequentially when they could run in parallel
|
||||
3. Hot-path bloat: new blocking work added to startup or per-request/per-render hot paths
|
||||
4. Unnecessary existence checks: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
|
||||
5. Memory: unbounded data structures, missing cleanup, event listener leaks
|
||||
6. Overly broad operations: reading entire files when only a portion is needed, loading all items when filtering for one
|
||||
|
||||
## Phase 3: Fix Issues
|
||||
|
||||
Wait for all three agents to complete. Aggregate their findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it.
|
||||
|
||||
When done, briefly summarize what was fixed (or confirm the code was already clean).
|
||||
5
stages/006-simplify_opus@1/provider_used.json
Normal file
5
stages/006-simplify_opus@1/provider_used.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"mode": "agent",
|
||||
"provider": "anthropic",
|
||||
"model": "claude-opus-4-7"
|
||||
}
|
||||
28
stages/006-simplify_opus@1/response.md
Normal file
28
stages/006-simplify_opus@1/response.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
## Summary
|
||||
|
||||
Reviewed the Environment REST CRUD API diff (2,574 lines) with three parallel agents covering code reuse, code quality, and efficiency.
|
||||
|
||||
### Fixed
|
||||
|
||||
**Collapsed API DTO duplication in `lib/crates/fabro-server/src/server/handler/environments.rs`** (-27 net lines):
|
||||
- Removed the redundant `ApiEnvironmentSettings` middleman struct (an exact field-by-field clone of `CreateEnvironmentRequest`/`ReplaceEnvironmentRequest`).
|
||||
- Removed both `into_settings`/`into_draft` trampoline impls that constructed `ApiEnvironmentSettings` only to shell out to a shared converter.
|
||||
- `CreateEnvironmentRequest::into_draft` and `ReplaceEnvironmentRequest::into_settings` now build `EnvironmentSettings` directly.
|
||||
- Replaced `ApiDockerfileSource::Path { _path: String }` with `_path: IgnoredAny`, removing the per-request `String` allocation for a payload that's parsed and discarded.
|
||||
|
||||
### Verified
|
||||
|
||||
- `cargo +nightly clippy --workspace --all-targets -- -D warnings` ✅
|
||||
- 13/13 `api::environments` tests pass
|
||||
- 4/4 `openapi_conformance` tests pass
|
||||
- 170/170 `fabro-api` tests pass (including round-trip)
|
||||
- 16/16 `fabro-environment` tests pass
|
||||
|
||||
### Reviewed but not fixed (with rationale)
|
||||
|
||||
- **Shared etag/parse helpers across automations.rs and environments.rs** (High priority from reuse review): The five helpers (`parse_path_id`, `parse_required_if_match`, `unquote_etag`, `*_with_etag_response`, `From<*StoreError> for ApiError`) are byte-twins with the automations versions. Extracting them requires changes to both modules and adds trait machinery; better tackled when a third resource lands.
|
||||
- **Catalog deep clone in `resolve_manifest_run_settings_with_catalog`** (Medium efficiency): Would require restructuring `SettingsLayer.environments` from owned `MergeMap` to `Arc<MergeMap>` across fabro-config. Environment writes are admin-only on small catalogs; deferred.
|
||||
- **`Environment::from_settings` extra resolve round-trip** (Medium efficiency): The added `resolve_environment(&persisted)` call is intentional — it's the validation step that powers the new `create_invalid_settings_is_rejected` test. Correct as-is.
|
||||
- **List pagination** (Medium efficiency): Out of scope; would require an OpenAPI spec change.
|
||||
- **`EnvironmentListResponse`/`EnvironmentListMeta` generalization** (Medium reuse): Same pattern as `AutomationListResponse`; cross-cutting refactor worth doing later.
|
||||
- **OpenAPI YAML repeats every 4xx/5xx response body** (Low quality): Pre-existing pattern across automations and other paths; systemic, not introduced by this PR.
|
||||
Loading…
Add table
Reference in a new issue