Skip to content

[codex] add scratch project source workflow#22

Closed
thepluck wants to merge 2 commits into
masterfrom
codex/scratch-project-source-workflow
Closed

[codex] add scratch project source workflow#22
thepluck wants to merge 2 commits into
masterfrom
codex/scratch-project-source-workflow

Conversation

@thepluck

@thepluck thepluck commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • add scratch project endpoints for forge init and Solidity source writes under src
  • add UI actions for New Scratch and Add Source
  • store Docker scratch projects in a dedicated scratch-projects volume

Tests

  • go test ./...
  • yarn build
  • yarn lint
  • yarn test:browser
  • docker compose config

Copilot AI review requested due to automatic review settings June 5, 2026 10:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 into src/.
  • 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
}
@thepluck

thepluck commented Jun 5, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #24 for the default project workflow.

@thepluck thepluck closed this Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants