[codex] add scratch project source workflow#22
Closed
thepluck wants to merge 2 commits into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a “scratch project” workflow to the simulator, allowing the UI to create a new Foundry project via the backend and write Solidity sources into its src/ directory, with Docker persisting scratch projects in a dedicated volume.
Changes:
- Add backend endpoints to create scratch Foundry projects (
forge init) and write Solidity source files intosrc/. - Add frontend UI actions (“New Scratch”, “Add Source”) and an e2e browser test covering the workflow.
- Update configuration/docs and Docker Compose to persist scratch projects under a dedicated scratch-projects root/volume.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents scratch project root setting and Docker scratch workflow. |
| frontend/tests/simulation-ui.spec.ts | Adds browser test for creating scratch project + adding source and ensuring it’s not embedded in /simulation request. |
| frontend/src/styles/request.css | Adds styling for project action status and source panel; expands browse grid for extra button. |
| frontend/src/features/request/RequestForm.tsx | Adds “New Scratch” and “Add Source” UI controls and wires them to new API calls. |
| frontend/src/api/types.ts | Re-exports new scratch/source request/response types. |
| frontend/src/api/schemas.ts | Adds Zod schemas/types for scratch project and source file endpoints. |
| frontend/src/api/client.ts | Implements POST /projects/scratch and POST /projects/scratch/source client calls. |
| docker-compose.yml | Adds scratch-projects volume and removes host project mount. |
| config.example.yml | Adds scratch_project_root example setting. |
| config.docker.yml | Sets scratch_project_root to /data/scratch-projects and clears project_roots. |
| backend/README.md | Documents new scratch endpoints and scratch project storage behavior. |
| backend/internal/simulation/validation.go | Adds validation for “relative .sol path under src” and request validation for source writes. |
| backend/internal/simulation/service.go | Implements scratch project creation, source file writing, and conditional forge build src behavior. |
| backend/internal/simulation/service_test.go | Adds unit tests for scratch init directory cleanup and source write constraints. |
| backend/internal/model/types.go | Adds request/response models for scratch creation and source writing. |
| backend/internal/httpapi/server.go | Registers and implements the new HTTP endpoints. |
| backend/internal/httpapi/openapi.go | Exposes new schemas and operations in OpenAPI spec. |
| backend/internal/httpapi/openapi_test.go | Extends OpenAPI tests and adds endpoint tests for source writing. |
| backend/internal/config/config.go | Adds scratch_project_root to config with defaulting/normalization. |
| backend/internal/config/config_test.go | Adds coverage for scratch root defaulting and config-path resolution. |
| .env.example | Removes Docker host project mount environment variables from example env file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+689
to
+696
| sourcePath := filepath.Join(projectRoot, "src", filepath.FromSlash(relPath)) | ||
| if err := os.MkdirAll(filepath.Dir(sourcePath), 0o755); err != nil { | ||
| return "", err | ||
| } | ||
| if err := os.WriteFile(sourcePath, []byte(req.Source), 0o644); err != nil { | ||
| return "", err | ||
| } | ||
| return sourcePath, nil |
Comment on lines
+388
to
+395
| <button | ||
| className="secondary-button" | ||
| type="button" | ||
| disabled={isAddingSourceFile || !form.projectPath.trim()} | ||
| onClick={handleAddSourceFile} | ||
| > | ||
| {isAddingSourceFile ? "Adding..." : "Add Source"} | ||
| </button> |
Comment on lines
+724
to
+738
| func pathInsideRoot(root string, child string) bool { | ||
| rootAbs, err := filepath.Abs(root) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| childAbs, err := filepath.Abs(child) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| rel, err := filepath.Rel(rootAbs, childAbs) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| return rel == "." || (rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator)) && !filepath.IsAbs(rel)) | ||
| } |
Comment on lines
+659
to
+673
| func (s *Service) CreateScratchProject(ctx context.Context) (string, forge.Result, error) { | ||
| projectRoot := filepath.Join(s.scratchProjectRoot(), safeRunID(runid.New())) | ||
| if err := os.MkdirAll(projectRoot, 0o755); err != nil { | ||
| return "", forge.Result{}, err | ||
| } | ||
|
|
||
| initResult := s.forge.Run(ctx, "init", projectRoot, "--no-git") | ||
| if initResult.Err != nil { | ||
| return projectRoot, initResult, initResult.Err | ||
| } | ||
| if err := resetScratchProjectDirs(projectRoot); err != nil { | ||
| return projectRoot, initResult, err | ||
| } | ||
| return projectRoot, initResult, nil | ||
| } |
Owner
Author
|
Superseded by #24 for the default project workflow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tests