checkpoint

⚒️ Generated with [Fabro](https://fabro.sh)
This commit is contained in:
Fabro 2026-05-29 14:49:13 -04:00
parent 95d887b025
commit a71b6882cf
6 changed files with 865 additions and 29 deletions

561
run.json

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,96 @@
diff --git a/lib/crates/fabro-server/src/server/handler/environments.rs b/lib/crates/fabro-server/src/server/handler/environments.rs
index 147425800..d0bf0bf55 100644
--- a/lib/crates/fabro-server/src/server/handler/environments.rs
+++ b/lib/crates/fabro-server/src/server/handler/environments.rs
@@ -11,6 +11,7 @@ use fabro_types::settings::run::{
EnvironmentNetworkSettings, EnvironmentProvider, EnvironmentResourcesSettings,
EnvironmentSettings, EnvironmentVolumeSettings,
};
+use serde::de::IgnoredAny;
use serde::{Deserialize, Serialize};
use super::super::{
@@ -56,17 +57,6 @@ struct ReplaceEnvironmentRequest {
env: HashMap<String, InterpString>,
}
-struct ApiEnvironmentSettings {
- provider: EnvironmentProvider,
- image: ApiEnvironmentImageSettings,
- resources: EnvironmentResourcesSettings,
- network: EnvironmentNetworkSettings,
- lifecycle: EnvironmentLifecycleSettings,
- labels: HashMap<String, String>,
- volumes: Vec<EnvironmentVolumeSettings>,
- env: HashMap<String, InterpString>,
-}
-
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct ApiEnvironmentImageSettings {
@@ -77,51 +67,34 @@ struct ApiEnvironmentImageSettings {
#[derive(Deserialize)]
#[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)]
enum ApiDockerfileSource {
- Inline {
- value: String,
- },
+ Inline { value: String },
+ // Recognized so the handler can return a 422 with bespoke guidance.
+ // The `path` payload is parsed and discarded — never read from disk.
Path {
#[serde(rename = "path")]
- _path: String,
+ _path: IgnoredAny,
},
}
impl CreateEnvironmentRequest {
fn into_draft(self) -> Result<EnvironmentDraft, ApiError> {
- let settings = ApiEnvironmentSettings {
- provider: self.provider,
- image: self.image,
- resources: self.resources,
- network: self.network,
- lifecycle: self.lifecycle,
- labels: self.labels,
- volumes: self.volumes,
- env: self.env,
- };
Ok(EnvironmentDraft {
id: self.id,
- settings: settings.into_settings()?,
+ settings: EnvironmentSettings {
+ provider: self.provider,
+ image: self.image.into_settings()?,
+ resources: self.resources,
+ network: self.network,
+ lifecycle: self.lifecycle,
+ labels: self.labels,
+ volumes: self.volumes,
+ env: self.env,
+ },
})
}
}
impl ReplaceEnvironmentRequest {
- fn into_settings(self) -> Result<EnvironmentSettings, ApiError> {
- ApiEnvironmentSettings {
- provider: self.provider,
- image: self.image,
- resources: self.resources,
- network: self.network,
- lifecycle: self.lifecycle,
- labels: self.labels,
- volumes: self.volumes,
- env: self.env,
- }
- .into_settings()
- }
-}
-
-impl ApiEnvironmentSettings {
fn into_settings(self) -> Result<EnvironmentSettings, ApiError> {
Ok(EnvironmentSettings {
provider: self.provider,

View file

@ -0,0 +1,6 @@
{
"outcome": "succeeded",
"notes": "Stage completed: simplify_opus",
"failure_reason": null,
"timestamp": "2026-05-29T18:44:28.965406Z"
}

View file

@ -0,0 +1,210 @@
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_opus**: succeeded
- Model: claude-opus-4-7, 116.5k tokens in / 33.0k out
- Files: /home/daytona/workspace/fabro/lib/crates/fabro-server/src/server/handler/environments.rs
# 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).

View file

@ -0,0 +1,5 @@
{
"mode": "agent",
"provider": "openai",
"model": "gpt-5.5"
}

View file

@ -0,0 +1,16 @@
Reviewed the branch diff and applied one cleanup:
- Deduplicated shared `If-Match` parsing, ETag quoting, and JSON-with-ETag response construction between Automations and Environments.
- Added shared helpers in `lib/crates/fabro-server/src/server/handler/mod.rs`.
- Updated:
- `lib/crates/fabro-server/src/server/handler/automations.rs`
- `lib/crates/fabro-server/src/server/handler/environments.rs`
Validation run:
- `cargo +nightly-2026-04-14 fmt --check --all`
- `cargo check -q -p fabro-server -p fabro-api`
- `cargo nextest run -p fabro-server --features test-support --test it api::environments`
- `cargo +nightly-2026-04-14 clippy -q -p fabro-server --features test-support --test it -- -D warnings`
All passed.