Files
orca/internal/jobspec/spec_test.go
T
Jon Chery f9a9873341 feat(P03): task execution engine with HCL specs, jobs, tasks, WaitDelay
Implements Phase 3 of v0.1 Foundation:
- internal/model/job.go: Job + Task models with status state machines
- internal/store/migrations/0002_jobs_tasks.sql: jobs + tasks tables with FK
- internal/store/job_task_repo.go: JobRepo + TaskRepo with CRUD and lifecycle updates
- internal/jobspec/spec.go: HCL parser using hashicorp/hcl/v2 hclsimple
- internal/jobspec/spec_test.go: 4 tests for parser
- internal/engine/executor.go: parallel task executor using os/exec with Go 1.25
  WaitDelay for clean process shutdown
- internal/cli/job.go: orca job {run,list,stop,logs} wired to executor
- testdata/hello.hcl, testdata/fail.hcl: smoke test fixtures

Verified: job run executes commands, captures stdout/stderr, persists state,
job stop transitions status, job logs displays captured output. All tests
pass with -race.

---ci---
project: orca
phase: 3
milestone: v0.1
status: execute
req_covered:
  - REQ-004
  - REQ-006
  - REQ-009
  - REQ-018
  - REQ-020
  - REQ-021
---/ci---
2026-06-03 12:45:20 +00:00

61 lines
1.2 KiB
Go

package jobspec
import (
"testing"
)
func TestParseValid(t *testing.T) {
hcl := `
job "demo" {
}
task "build" {
command = "/bin/echo"
args = ["hello", "world"]
}
`
spec, err := Parse([]byte(hcl), "test.hcl")
if err != nil {
t.Fatalf("parse: %v", err)
}
if spec.Job.Name != "demo" {
t.Errorf("expected job name 'demo', got %q", spec.Job.Name)
}
if len(spec.Tasks) != 1 {
t.Fatalf("expected 1 task, got %d", len(spec.Tasks))
}
if spec.Tasks[0].Command != "/bin/echo" {
t.Errorf("expected command '/bin/echo', got %q", spec.Tasks[0].Command)
}
if len(spec.Tasks[0].Args) != 2 {
t.Errorf("expected 2 args, got %d", len(spec.Tasks[0].Args))
}
}
func TestParseMissingJob(t *testing.T) {
hcl := `task "x" { command = "/bin/echo" }`
_, err := Parse([]byte(hcl), "test.hcl")
if err == nil {
t.Fatal("expected error for missing job name")
}
}
func TestParseNoTasks(t *testing.T) {
hcl := `job "empty" {}`
_, err := Parse([]byte(hcl), "test.hcl")
if err == nil {
t.Fatal("expected error for no tasks")
}
}
func TestParseTaskMissingCommand(t *testing.T) {
hcl := `
job "x" {}
task "no-cmd" {}
`
_, err := Parse([]byte(hcl), "test.hcl")
if err == nil {
t.Fatal("expected error for missing command")
}
}