diff --git a/docs/prds/state-store-contract.md b/docs/prds/state-store-contract.md
index a864f068c..00ad8a305 100644
--- a/docs/prds/state-store-contract.md
+++ b/docs/prds/state-store-contract.md
@@ -20,14 +20,12 @@ split `archie.db`. It records method ownership, DTO/wire representation, error s
limits, mode/config shape, local-adapter compatibility, and cutover/deletion rules so that
`.4.2` and `.4.3` have exactly one authoritative surface to build against.
-> **Current state (before implementation) — read before `.4.2` starts.** The acceptance
-> criterion ("`internal/domain/workflow` … no longer import `internal/store`") is **not yet
-> met** and is **not implied to be met by this document**. Today, production workflow files
-> and tests import `internal/store` (`internal/domain/workflow/{workflow,steps,triage,review,
-> feasibility,implement}.go`), `store.WorkflowStore` remains in `TaskContext`, and the NATS
-> `storerpc` path is still wired. Those are the **current, pre-implementation outliers** that §12
-> step 2 (relocation) and `.4.2` remove. Nothing in this document describes code that already
-> exists; it describes what `.4.2`/`.4.3` build and what the prerequisite changes are.
+> **Current state — read before `.4.2` starts.** The §12 step 2 relocation (`archie-core-8cda.
+> 4.8`) has landed: `Task`/`Status*`/`Source*` and the 3-method `workflow.Store` now live in
+> `internal/domain/workflow`, the six production workflow files import no `internal/store`
+> symbol, and `storerpc`/the NATS transport assert against `workflow.Store` instead of
+> `store.WorkflowStore`. The broader Phase 2 acceptance criterion (State Store as its own
+> service behind gRPC) is still open — that is what `.4.2`/`.4.3` build next.
> **Relationship to migration-decisions §4 — not replaced.** `docs/architecture/
> migration-decisions.md` §4 (`store.Task → WorkflowExecution`, `mutable Stage →
@@ -191,10 +189,12 @@ The Phase 2 acceptance criterion ("`internal/domain/workflow` … no longer impo
reads and writes (infrastructure → domain). **NOTE: `internal/store` is a transitional
compatibility location only** — its long-term home is `internal/infrastructure/store` (see
the callout in §1). Do not treat `internal/store` as the final infrastructure boundary.
-- `TestRecordDispatchViaExplicitTx` and every store test that constructs `store.Task{…}` are
- updated to the relocated type as part of this prerequisite. This is a mechanical rename
- across ~6 workflow production files (`workflow.go`, `steps.go`, `triage.go`, `review.go`,
- `feasibility.go`, `implement.go`) and their tests plus the store tests.
+- Every store test that constructs `store.Task{…}` is updated to the relocated type as part of
+ this prerequisite. This is a mechanical rename across ~6 workflow production files
+ (`workflow.go`, `steps.go`, `triage.go`, `review.go`, `feasibility.go`, `implement.go`) and
+ their tests plus the store tests. `TestRecordDispatchViaExplicitTx` is removed rather than
+ updated — its non-nil `*sql.Tx` path has no production consumer (see §5's `RecordDispatch`
+ blocker).
**What this does NOT do:** it does not implement the full §4 Workflow migration
(`mutable Stage → StepExecution history`, `RetryCount/Attempt → Attempt records`,
@@ -594,10 +594,10 @@ an explicit operator decision.
`containerEnv`. Token is per-incumbence (task + container grace period) and validated by a
gRPC interceptor → `codes.Unauthenticated` on missing/unknown/expired. Non-loopback targets
fail closed without TLS or a token.
-- **Acceptance criterion is NOT yet met.** `internal/domain/workflow` still imports
- `internal/store` (workflow files + tests), `store.WorkflowStore` is still in `TaskContext`,
- and the NATS `storerpc` path is still wired. §12 step 2 and `.4.2` remove these; this
- document does not imply the criterion is already satisfied.
+- **§12 step 2 (domain type + interface relocation) is done** — `internal/domain/workflow`
+ imports no `internal/store` symbol and `store.WorkflowStore` is gone from `TaskContext`. The
+ broader Phase 2 acceptance criterion (State Store as its own gRPC service) is still open;
+ `.4.2` picks up from here.
- **Ownership split:** domain-facing workflow contract is **consumer-owned** in the domain
(`workflow.Store` + `workflow.Task`/`Status`/`Source`, per dependency rules #2 and #7);
daemon/webui store surfaces stay **producer-owned** in `internal/store`. `store.WorkflowStore`
diff --git a/go.sum b/go.sum
index fcf604c64..9bcd555ab 100644
--- a/go.sum
+++ b/go.sum
@@ -2,16 +2,21 @@ cel.dev/cel-go v0.32.0 h1:irvpFKr5EuGPyxeME03ERh0rii1TX+BDAnB9eL3IvNk=
cel.dev/cel-go v0.32.0/go.mod h1:DnVip7tpJSsgZymwfT+m1tnEVy3ivAjSMXPx12YrMkU=
cel.dev/expr v0.25.3 h1:A2jO8jwOugrrovveCWfj0KEZOfqiLgAcwjpHPhzIGw0=
cel.dev/expr v0.25.3/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4=
+cloud.google.com/go/auth v0.18.2/go.mod h1:xD+oY7gcahcu7G2SG2DsBerfFxgPAJz17zz2joOFF3M=
+cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
code.gitea.io/sdk/gitea v0.25.1 h1:yywxWwoV+SdjHtbC6unBiXojWdZOtoHuGhEazEXeWuE=
code.gitea.io/sdk/gitea v0.25.1/go.mod h1:uDFWYBU8dgZsgOHwe6C/6olxvf8FHguNB3wW1i83fgg=
github.com/42wim/httpsig v1.2.4 h1:mI5bH0nm4xn7K18fo1K3okNDRq8CCJ0KbBYWyA6r8lU=
github.com/42wim/httpsig v1.2.4/go.mod h1:yKsYfSyTBEohkPik224QPFylmzEBtda/kjyIAJjh3ps=
+github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
+github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.33.0/go.mod h1:pJTkW8hEUIIi3Pf65lPZOnn4Y81yCllX6IWk2jNXdkM=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM=
github.com/ProtonMail/go-crypto v1.4.1/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo=
+github.com/a-h/templ v0.3.1020/go.mod h1:A2DlK61v+K+NRoGnhmYbNYVmtYHcFO5/AisMvBdDxTM=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/antithesishq/antithesis-sdk-go v0.8.0 h1:bVV5ZAuwaREn4klRSJusYaA+A7NXq8Qi9C/knCaQ2N4=
@@ -20,14 +25,18 @@ github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYW
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
+github.com/bwesterb/go-ristretto v1.2.4/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudflare/circl v1.6.5 h1:O64F26HEqNhznd/hrC5KZXVKYuKM2rx4deZDTc4ihQA=
github.com/cloudflare/circl v1.6.5/go.mod h1:h5LNyxAc5nTue9DS5jT+48en2PSDYt3zdGnz5OstK6c=
+github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2/go.mod h1:qwXFYgsP6T7XnJtbKlf1HP8AjxZZyzxMmc+Lq5GjlU4=
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
+github.com/containerd/typeurl/v2 v2.2.0/go.mod h1:8XOOxnyatxSWuG8OfsZXVnAF4iZfedjS/8UHSPJnX4g=
+github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
@@ -42,6 +51,10 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
+github.com/envoyproxy/go-control-plane v0.14.0/go.mod h1:NcS5X47pLl/hfqxU70yPwL9ZMkUlwlKxtAohpi2wBEU=
+github.com/envoyproxy/go-control-plane/envoy v1.37.0/go.mod h1:DReE9MMrmecPy+YvQOAOHNYMALuowAnbjjEMkkWOi6A=
+github.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJPzVVHnPgRKdUdwW/KdbRt94AzgRee4=
+github.com/envoyproxy/protoc-gen-validate v1.3.3/go.mod h1:TsndJ/ngyIdQRhMcVVGDDHINPLWB7C82oDArY51KfB0=
github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc=
github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
@@ -56,13 +69,17 @@ github.com/go-git/go-git-fixtures/v6 v6.0.0-alpha.1 h1:gmqi2jvsreu0s8JMLylYDFq4s
github.com/go-git/go-git-fixtures/v6 v6.0.0-alpha.1/go.mod h1:ECf1MqJlBdYpKggBrOXjo/0EnvRZx6D++I86UYjPgAQ=
github.com/go-git/go-git/v6 v6.0.0-alpha.5 h1:sE+OlkHgYWNMVmN1s9sR7uyFgsWLtxcNWse/vBYKxRE=
github.com/go-git/go-git/v6 v6.0.0-alpha.5/go.mod h1:3IjhiZnM+uBmUrOGSeqrJpsmi4Vd0H2NZO/uK2a7d0s=
+github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
+github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/go-telegram/bot v1.25.0 h1:C072msZtr+GjJiQsX/UJLirz+jzSNZVWkckxWufR7Ww=
github.com/go-telegram/bot v1.25.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM=
+github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
+github.com/golang/glog v1.2.5/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/codesearch v1.3.0-rc.1 h1:vSFGuF5wS3sjimuLzqPG+PGjWQ9VvEtPFbxdZD7YuuQ=
@@ -76,10 +93,14 @@ github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfh
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
+github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba/go.mod h1:EFYHy8/1y2KfgTAsx7Luu7NGhoxtuVHnNo8jE7FikKc=
github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3 h1:LMLX+LgTNWpfvCBdFebv6EsYotImrt/Ppc5cXIriCSo=
github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3/go.mod h1:jl5iWTm0/hd5PjEYEOuwAJ57L/CibdZfrqZ5XA5GrCk=
+github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/googleapis/enterprise-certificate-proxy v0.3.11/go.mod h1:RFV7MUdlb7AgEq2v7FmMCfeSMCllAzWxFgRdusoGks8=
+github.com/googleapis/gax-go/v2 v2.17.0/go.mod h1:mzaqghpQp4JDh3HvADwrat+6M3MOIDp5YKHhb9PAgDY=
github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA=
github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
@@ -107,6 +128,7 @@ github.com/moby/moby/api v1.56.0 h1:GQzua3NA599ASSIICx0iFgiJeO9YkdDARvQsm23ZZuQ=
github.com/moby/moby/api v1.56.0/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk=
github.com/moby/moby/client v0.6.0 h1:AJjEB21QPbXSXjDsZorFBoDZPhMrfbpaPLgSMAW9Bgs=
github.com/moby/moby/client v0.6.0/go.mod h1:OCo00wNRyA3m4lmJ228W3JbyCN4ZNNYjpOXiJydBdcQ=
+github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
github.com/nats-io/jwt/v2 v2.8.2 h1:XXRgB60MSTnqsRwejQurVDs/hcv2dkt+86GjI+I/bMc=
github.com/nats-io/jwt/v2 v2.8.2/go.mod h1:Ag/56sq9OblL4JgdYufDd16Egb17Kr/8WwwuO/forVc=
github.com/nats-io/nats-server/v2 v2.14.6 h1:dHjEHa49lUTxIb5jrsk5kz/AmOyOQ4T9ti8djcBumDQ=
@@ -127,15 +149,20 @@ github.com/pjbgf/sha1cd v0.6.0 h1:3WJ8Wz8gvDz29quX1OcEmkAlUg9diU4GxJHqs0/XiwU=
github.com/pjbgf/sha1cd v0.6.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
+github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
+github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/samcharles93/ai-sdk v0.1.32 h1:rfBpWUOADuRTaq2kyCnMjdhtlFfaqUbsyL5DbIluqmA=
github.com/samcharles93/ai-sdk v0.1.32/go.mod h1:u4zrQ9/Q58L5mNEut4bNQ1ks+RCKq71LN5EDz2N/0Zk=
+github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
+github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
+github.com/spiffe/go-spiffe/v2 v2.7.0/go.mod h1:47Q0Q9/AqGha8QLHp+kxpH4Wca7X7EnOtlIJy3mxZ3U=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
@@ -144,6 +171,7 @@ github.com/traefik/yaegi v0.16.1 h1:f1De3DVJqIDKmnasUF6MwmWv1dSEEat0wcpXhD2On3E=
github.com/traefik/yaegi v0.16.1/go.mod h1:4eVhbPb3LnD2VigQjhYbEJ69vDRFdT2HQNrXx8eEwUY=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
+go.opentelemetry.io/contrib/detectors/gcp v1.44.0/go.mod h1:tNAsgd8avTGke1+MndXlU5Cru4PQ9Ai/cCNWQv/ZJ/s=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0 h1:3g7B90UzBltIDKq1/5mrTGxTnOFDV0ICOhLoxiZ8jlg=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0/go.mod h1:Ef8SuTh59BT7+ofpDxN9z+yOlc4t2GjLmKDgYNJL/NU=
go.opentelemetry.io/otel v1.46.0 h1:FHt5/CDyVxi/8IM1CH7VE/rRgq3kLHa2mSTVMO8AWyc=
@@ -171,6 +199,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
+golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -192,6 +221,8 @@ golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
+golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
+golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20260904194346-d0f1323225a4 h1:NCe/UiklGd/9xjT+ROBVhJ1kf6TRQaFedsR+z7u1gvo=
diff --git a/internal/app/agentworker/task_execution.go b/internal/app/agentworker/task_execution.go
index 4ee9e8486..23f0d715f 100644
--- a/internal/app/agentworker/task_execution.go
+++ b/internal/app/agentworker/task_execution.go
@@ -17,7 +17,6 @@ import (
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/installtype"
"github.com/samcharles93/archie-core/internal/storage"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/taskrun"
"github.com/samcharles93/archie-core/internal/worktree"
)
@@ -128,7 +127,7 @@ func worktreeOwnerID(env string) int {
type taskDependencies struct {
forge workflow.Forger
- store store.WorkflowStore
+ store workflow.Store
trees remoteTrees
events agentexec.EventPublisher
}
diff --git a/internal/app/agentworker/task_execution_test.go b/internal/app/agentworker/task_execution_test.go
index bd10329e5..614f3804e 100644
--- a/internal/app/agentworker/task_execution_test.go
+++ b/internal/app/agentworker/task_execution_test.go
@@ -19,6 +19,7 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
"github.com/samcharles93/archie-core/internal/forgerpc"
@@ -348,11 +349,11 @@ func TestRunTaskExecutesBootstrapWorkflowEndToEnd(t *testing.T) {
if err != nil {
t.Fatalf("runTask: %v", err)
}
- if response.Status != store.StatusPROpen || len(fg.prs) != 1 {
- t.Fatalf("response status/PRs = (%q, %d), want (%q, 1)", response.Status, len(fg.prs), store.StatusPROpen)
+ if response.Status != workflow.StatusPROpen || len(fg.prs) != 1 {
+ t.Fatalf("response status/PRs = (%q, %d), want (%q, 1)", response.Status, len(fg.prs), workflow.StatusPROpen)
}
stored, err := st.TaskByIssue(ctx, "acme", "widget", 1)
- if err != nil || stored == nil || stored.Status != store.StatusPROpen || stored.PRNumber != 5 {
+ if err != nil || stored == nil || stored.Status != workflow.StatusPROpen || stored.PRNumber != 5 {
t.Fatalf("stored task = (%+v, %v), want PR-open task #5", stored, err)
}
if _, err := os.Stat(filepath.Join(hostDir, ".archie", "bootstrap.md")); err != nil {
@@ -449,8 +450,8 @@ func TestExecuteTaskRequestUsesInfrastructureRPCDependencies(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if response.Status != store.StatusPROpen || len(forge.prs) != 1 {
- t.Fatalf("response status/PRs = (%q, %d), want (%q, 1)", response.Status, len(forge.prs), store.StatusPROpen)
+ if response.Status != workflow.StatusPROpen || len(forge.prs) != 1 {
+ t.Fatalf("response status/PRs = (%q, %d), want (%q, 1)", response.Status, len(forge.prs), workflow.StatusPROpen)
}
// archie-core-1786751948782-3-837a8fd0 point 4: every response reports
// what this worker actually is, since it's the only channel the daemon
@@ -462,7 +463,7 @@ func TestExecuteTaskRequestUsesInfrastructureRPCDependencies(t *testing.T) {
t.Errorf("response.AgentInstallType = %q, want installtype.Type() = %q", response.AgentInstallType, installtype.Type())
}
stored, err := st.TaskByIssue(ctx, "acme", "rpc-widget", 2)
- if err != nil || stored == nil || stored.Status != store.StatusPROpen || stored.PRNumber != 5 {
+ if err != nil || stored == nil || stored.Status != workflow.StatusPROpen || stored.PRNumber != 5 {
t.Fatalf("stored task = (%+v, %v), want RPC-persisted PR-open task #5", stored, err)
}
if _, err := os.Stat(filepath.Join(hostDir, ".archie", "bootstrap.md")); err != nil {
@@ -572,8 +573,8 @@ func TestExecuteTaskRequestForwardsWorkflowEventsOverNATS(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if response.Status != store.StatusPROpen {
- t.Fatalf("response status = %q, want %q", response.Status, store.StatusPROpen)
+ if response.Status != workflow.StatusPROpen {
+ t.Fatalf("response status = %q, want %q", response.Status, workflow.StatusPROpen)
}
deadline := time.After(2 * time.Second)
diff --git a/internal/app/agentworker/worker.go b/internal/app/agentworker/worker.go
index 991f22ebb..25691e224 100644
--- a/internal/app/agentworker/worker.go
+++ b/internal/app/agentworker/worker.go
@@ -12,7 +12,6 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/agentgit"
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
"github.com/samcharles93/archie-core/internal/storage"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/taskrun"
)
@@ -41,7 +40,7 @@ type workerTransport interface {
EventPublisher() agentexec.EventPublisher
SubscribeTasks(context.Context, int64, agentnats.TaskHandler, *slog.Logger) (agentnats.Subscription, error)
Forger(string, time.Duration) workflow.Forger
- Store(time.Duration) store.WorkflowStore
+ Store(time.Duration) workflow.Store
Trees(string, string, time.Duration) agentnats.RemoteTrees
}
@@ -122,7 +121,7 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
type taskServiceTransport interface {
Forger(string, time.Duration) workflow.Forger
- Store(time.Duration) store.WorkflowStore
+ Store(time.Duration) workflow.Store
Trees(string, string, time.Duration) agentnats.RemoteTrees
EventPublisher() agentexec.EventPublisher
}
diff --git a/internal/app/agentworker/worker_test.go b/internal/app/agentworker/worker_test.go
index 39c0ba904..a50063fb6 100644
--- a/internal/app/agentworker/worker_test.go
+++ b/internal/app/agentworker/worker_test.go
@@ -12,7 +12,6 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/domain/workflow"
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
- "github.com/samcharles93/archie-core/internal/store"
)
type workerPublisher struct{ messages *[][]byte }
@@ -74,7 +73,7 @@ func (t *workerTransportStub) SubscribeTasks(_ context.Context, taskID int64, _
func (*workerTransportStub) Forger(string, time.Duration) workflow.Forger { return nil }
-func (*workerTransportStub) Store(time.Duration) store.WorkflowStore { return nil }
+func (*workerTransportStub) Store(time.Duration) workflow.Store { return nil }
func (*workerTransportStub) Trees(string, string, time.Duration) agentnats.RemoteTrees { return nil }
diff --git a/internal/app/archied/main.go b/internal/app/archied/main.go
index 78651d8e6..9c271e142 100644
--- a/internal/app/archied/main.go
+++ b/internal/app/archied/main.go
@@ -31,6 +31,7 @@ import (
"github.com/samcharles93/archie-core/internal/container"
"github.com/samcharles93/archie-core/internal/daemon"
"github.com/samcharles93/archie-core/internal/domain/curator"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
"github.com/samcharles93/archie-core/internal/forgerpc"
@@ -145,7 +146,7 @@ const taskListOverRead = 5
// gateway deliberately does not import internal/store, so the projection
// happens here, as it does for the writer and controller adapters below.
type chatTaskListerAdapter struct {
- tasks func(context.Context, int) ([]store.Task, error)
+ tasks func(context.Context, int) ([]workflow.Task, error)
}
func (a chatTaskListerAdapter) ListChatTasks(ctx context.Context, identity string, limit int) ([]gateway.ChatTaskSummary, error) {
@@ -313,7 +314,7 @@ func manualRequeueTask(ctx context.Context, st store.TaskStore, taskID int64) er
return fmt.Errorf("task %d not found", taskID)
}
switch task.Status {
- case store.StatusParked, store.StatusWaitingHuman:
+ case workflow.StatusParked, workflow.StatusWaitingHuman:
return st.Requeue(ctx, taskID, task.Status, "")
default:
return fmt.Errorf("task %d has status %q; only parked or waiting_human tasks can be requeued", taskID, task.Status)
@@ -529,7 +530,7 @@ type chatTaskWriterAdapter struct {
enqueue func(
ctx context.Context,
owner, repo, title, body, workflow, identity string,
- ) (*store.Task, error)
+ ) (*workflow.Task, error)
}
func (a chatTaskWriterAdapter) EnqueueChatTask(
@@ -547,7 +548,7 @@ func (a chatTaskWriterAdapter) EnqueueChatTask(
}
type chatTaskControllerAdapter struct {
- taskByID func(context.Context, int64) (*store.Task, error)
+ taskByID func(context.Context, int64) (*workflow.Task, error)
requeue func(context.Context, int64, string, string) error
transition func(context.Context, int64, string, string, string) error
}
@@ -567,7 +568,7 @@ func (a chatTaskControllerAdapter) ChatTaskStatus(ctx context.Context, taskID in
}
func (a chatTaskControllerAdapter) ApproveChatTask(ctx context.Context, taskID int64) error {
- return a.requeue(ctx, taskID, store.StatusWaitingHuman, "implement")
+ return a.requeue(ctx, taskID, workflow.StatusWaitingHuman, "implement")
}
func (a chatTaskControllerAdapter) CancelChatTask(ctx context.Context, taskID int64, reason string) error {
@@ -587,7 +588,7 @@ func (a chatTaskControllerAdapter) CancelChatTask(ctx context.Context, taskID in
// different states -- and StatusRejected, which the PR reconciler uses
// for "the pull request was closed without merging", stopped meaning one
// thing.
- return a.transition(ctx, taskID, task.Status, store.StatusClosedWontDo, reason)
+ return a.transition(ctx, taskID, task.Status, workflow.StatusClosedWontDo, reason)
}
// chatTaskLogReaderAdapter gives the gateway a read view of a task's
@@ -597,7 +598,7 @@ func (a chatTaskControllerAdapter) CancelChatTask(ctx context.Context, taskID in
// model cannot read another identity's task logs by passing a different
// identity through the tool input.
type chatTaskLogReaderAdapter struct {
- tasks func(context.Context, int64) (*store.Task, error)
+ tasks func(context.Context, int64) (*workflow.Task, error)
taskLogs *logging.TaskRegistry
}
diff --git a/internal/app/archied/main_test.go b/internal/app/archied/main_test.go
index 207d56876..f8e26463d 100644
--- a/internal/app/archied/main_test.go
+++ b/internal/app/archied/main_test.go
@@ -22,6 +22,7 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/daemon"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
"github.com/samcharles93/archie-core/internal/forgerpc"
@@ -496,7 +497,7 @@ func TestNpmCacheServerEnvPersistsCacheAcrossRestarts(t *testing.T) {
}
func TestManualRequeueTaskUsesPersistedStatus(t *testing.T) {
- tests := []string{store.StatusParked, store.StatusWaitingHuman}
+ tests := []string{workflow.StatusParked, workflow.StatusWaitingHuman}
for index, status := range tests {
t.Run(status, func(t *testing.T) {
st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "tasks.db"))
@@ -511,14 +512,14 @@ func TestManualRequeueTaskUsesPersistedStatus(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
- if err := st.Transition(t.Context(), task.ID, store.StatusQueued, status, ""); err != nil {
+ if err := st.Transition(t.Context(), task.ID, workflow.StatusQueued, status, ""); err != nil {
t.Fatal(err)
}
if err := manualRequeueTask(t.Context(), st, task.ID); err != nil {
t.Fatal(err)
}
got, err := st.TaskByID(t.Context(), task.ID)
- if err != nil || got == nil || got.Status != store.StatusQueued {
+ if err != nil || got == nil || got.Status != workflow.StatusQueued {
t.Fatalf("TaskByID after requeue = (%+v, %v), want queued", got, err)
}
})
@@ -577,12 +578,12 @@ func TestChatTaskWriterAdapter(t *testing.T) {
sentinel := errors.New("enqueue failed")
tests := []struct {
name string
- result *store.Task
+ result *workflow.Task
err error
wantID int64
wantErr bool
}{
- {name: "returns task id", result: &store.Task{ID: 42}, wantID: 42},
+ {name: "returns task id", result: &workflow.Task{ID: 42}, wantID: 42},
{name: "propagates error", err: sentinel, wantErr: true},
{name: "rejects nil task", wantErr: true},
}
@@ -592,7 +593,7 @@ func TestChatTaskWriterAdapter(t *testing.T) {
enqueue: func(
context.Context,
string, string, string, string, string, string,
- ) (*store.Task, error) {
+ ) (*workflow.Task, error) {
return tt.result, tt.err
},
}
@@ -638,8 +639,8 @@ func TestChatTaskProfilesUsesIdentityRepositories(t *testing.T) {
func TestChatTaskControllerAdapterRejectsForgeTask(t *testing.T) {
adapter := chatTaskControllerAdapter{
- taskByID: func(context.Context, int64) (*store.Task, error) {
- return &store.Task{ID: 42, Source: store.SourceForge}, nil
+ taskByID: func(context.Context, int64) (*workflow.Task, error) {
+ return &workflow.Task{ID: 42, Source: workflow.SourceForge}, nil
},
}
@@ -650,10 +651,10 @@ func TestChatTaskControllerAdapterRejectsForgeTask(t *testing.T) {
}
func TestChatTaskControllerAdapterTransitions(t *testing.T) {
- task := &store.Task{ID: 42, Source: store.SourceChat, Status: store.StatusWaitingHuman}
+ task := &workflow.Task{ID: 42, Source: workflow.SourceChat, Status: workflow.StatusWaitingHuman}
var requeueFrom, requeueWorkflow, transitionFrom, transitionTo, transitionDetail string
adapter := chatTaskControllerAdapter{
- taskByID: func(context.Context, int64) (*store.Task, error) { return task, nil },
+ taskByID: func(context.Context, int64) (*workflow.Task, error) { return task, nil },
requeue: func(_ context.Context, _ int64, from, workflow string) error {
requeueFrom, requeueWorkflow = from, workflow
return nil
@@ -667,7 +668,7 @@ func TestChatTaskControllerAdapterTransitions(t *testing.T) {
if err := adapter.ApproveChatTask(context.Background(), task.ID); err != nil {
t.Fatalf("ApproveChatTask(): %v", err)
}
- if requeueFrom != store.StatusWaitingHuman || requeueWorkflow != "implement" {
+ if requeueFrom != workflow.StatusWaitingHuman || requeueWorkflow != "implement" {
t.Errorf("requeue = %q/%q, want waiting_human/implement", requeueFrom, requeueWorkflow)
}
if err := adapter.CancelChatTask(context.Background(), task.ID, "cancelled by test"); err != nil {
@@ -677,7 +678,7 @@ func TestChatTaskControllerAdapterTransitions(t *testing.T) {
// dashboard. It used to record StatusRejected, which the PR reconciler
// also uses for "the pull request was closed without merging", so the
// state could not tell an operator's decision from a forge outcome.
- if transitionFrom != store.StatusWaitingHuman || transitionTo != store.StatusClosedWontDo ||
+ if transitionFrom != workflow.StatusWaitingHuman || transitionTo != workflow.StatusClosedWontDo ||
transitionDetail != "cancelled by test" {
t.Errorf("transition = %q/%q/%q", transitionFrom, transitionTo, transitionDetail)
}
@@ -689,25 +690,25 @@ func TestChatTaskLogReaderAdapterIdentityEnforcement(t *testing.T) {
tests := []struct {
name string
identity string
- task *store.Task
+ task *workflow.Task
wantErr bool
}{
{
name: "own chat task allowed",
identity: "archie",
- task: &store.Task{ID: 42, Identity: "archie", Attempt: 1, Source: store.SourceChat},
+ task: &workflow.Task{ID: 42, Identity: "archie", Attempt: 1, Source: workflow.SourceChat},
wantErr: false,
},
{
name: "other identity chat task denied",
identity: "archie",
- task: &store.Task{ID: 42, Identity: "other-bot", Attempt: 1, Source: store.SourceChat},
+ task: &workflow.Task{ID: 42, Identity: "other-bot", Attempt: 1, Source: workflow.SourceChat},
wantErr: true,
},
{
name: "forge task (empty identity) denied",
identity: "archie",
- task: &store.Task{ID: 42, Identity: "", Attempt: 1, Source: store.SourceForge},
+ task: &workflow.Task{ID: 42, Identity: "", Attempt: 1, Source: workflow.SourceForge},
wantErr: true,
},
}
@@ -715,7 +716,7 @@ func TestChatTaskLogReaderAdapterIdentityEnforcement(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
adapter := chatTaskLogReaderAdapter{
- tasks: func(_ context.Context, _ int64) (*store.Task, error) { return tt.task, nil },
+ tasks: func(_ context.Context, _ int64) (*workflow.Task, error) { return tt.task, nil },
}
_, err := adapter.ReadChatTaskLogs(context.Background(), tt.identity, tt.task.ID, 0, gateway.ChatTaskLogQuery{})
if tt.wantErr && err == nil {
@@ -729,9 +730,9 @@ func TestChatTaskLogReaderAdapterIdentityEnforcement(t *testing.T) {
}
func TestChatTaskLogReaderAdapterDefaultAttempt(t *testing.T) {
- task := &store.Task{ID: 42, Identity: "archie", Attempt: 3, Source: store.SourceChat}
+ task := &workflow.Task{ID: 42, Identity: "archie", Attempt: 3, Source: workflow.SourceChat}
adapter := chatTaskLogReaderAdapter{
- tasks: func(_ context.Context, _ int64) (*store.Task, error) { return task, nil },
+ tasks: func(_ context.Context, _ int64) (*workflow.Task, error) { return task, nil },
}
result, err := adapter.ReadChatTaskLogs(context.Background(), "archie", task.ID, 0, gateway.ChatTaskLogQuery{})
@@ -744,9 +745,9 @@ func TestChatTaskLogReaderAdapterDefaultAttempt(t *testing.T) {
}
func TestChatTaskLogReaderAdapterEmptyResultWhenNoRegistry(t *testing.T) {
- task := &store.Task{ID: 42, Identity: "archie", Attempt: 1, Source: store.SourceChat}
+ task := &workflow.Task{ID: 42, Identity: "archie", Attempt: 1, Source: workflow.SourceChat}
adapter := chatTaskLogReaderAdapter{
- tasks: func(_ context.Context, _ int64) (*store.Task, error) { return task, nil },
+ tasks: func(_ context.Context, _ int64) (*workflow.Task, error) { return task, nil },
taskLogs: nil,
}
@@ -767,9 +768,9 @@ func TestChatTaskLogReaderAdapterRoundTrip(t *testing.T) {
taskLogs := logging.NewTaskRegistry(baseDir, logging.NewFeed(10), logging.TaskSinkOptions{})
t.Cleanup(func() { _ = taskLogs.Remove(42) })
- task := &store.Task{ID: 42, Identity: "archie", Attempt: 1, Source: store.SourceChat}
+ task := &workflow.Task{ID: 42, Identity: "archie", Attempt: 1, Source: workflow.SourceChat}
adapter := chatTaskLogReaderAdapter{
- tasks: func(_ context.Context, _ int64) (*store.Task, error) { return task, nil },
+ tasks: func(_ context.Context, _ int64) (*workflow.Task, error) { return task, nil },
taskLogs: taskLogs,
}
@@ -840,17 +841,17 @@ func TestChatTaskCommandsEndToEnd(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if task == nil || task.Source != store.SourceChat || task.Identity != "reviewer" ||
+ if task == nil || task.Source != workflow.SourceChat || task.Identity != "reviewer" ||
task.Owner != "acme" || task.Repo != "archie-core" ||
task.Workflow != "feasibility" {
t.Fatalf("spawned task = %+v", task)
}
- if err := st.Transition(ctx, taskID, store.StatusQueued, store.StatusWaitingHuman, "await approval"); err != nil {
+ if err := st.Transition(ctx, taskID, workflow.StatusQueued, workflow.StatusWaitingHuman, "await approval"); err != nil {
t.Fatal(err)
}
task, err = st.TaskByID(ctx, taskID)
- if err != nil || task == nil || task.Status != store.StatusWaitingHuman {
+ if err != nil || task == nil || task.Status != workflow.StatusWaitingHuman {
t.Fatalf("waiting task = (%+v, %v)", task, err)
}
reply, err = router.Route(ctx, gateway.Message{Text: fmt.Sprintf("/approve identity=reviewer %d", taskID)})
@@ -858,7 +859,7 @@ func TestChatTaskCommandsEndToEnd(t *testing.T) {
t.Fatalf("approve = (%q, %v)", reply, err)
}
task, err = st.TaskByID(ctx, taskID)
- if err != nil || task == nil || task.Status != store.StatusQueued || task.Workflow != "implement" {
+ if err != nil || task == nil || task.Status != workflow.StatusQueued || task.Workflow != "implement" {
t.Fatalf("approved task = (%+v, %v)", task, err)
}
@@ -880,7 +881,7 @@ func TestChatTaskCommandsEndToEnd(t *testing.T) {
}
// Same terminal state as the dashboard's Reject: one decision, one state.
cancelled, err := st.TaskByID(ctx, cancelID)
- if err != nil || cancelled == nil || cancelled.Status != store.StatusClosedWontDo {
+ if err != nil || cancelled == nil || cancelled.Status != workflow.StatusClosedWontDo {
t.Fatalf("cancelled task = (%+v, %v)", cancelled, err)
}
}
@@ -967,7 +968,7 @@ func TestRegisterTaskRPCServersReachableFromClient(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("claim: (%v, %v)", task, err)
}
- if err := storeClient.Transition(ctx, task.ID, store.StatusRunning, store.StatusPROpen, "opened"); err != nil {
+ if err := storeClient.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusPROpen, "opened"); err != nil {
t.Fatalf("storerpc Transition unreachable: %v", err)
}
diff --git a/internal/app/archied/task_action_adapter_test.go b/internal/app/archied/task_action_adapter_test.go
index 0fa5b35cf..07e81774d 100644
--- a/internal/app/archied/task_action_adapter_test.go
+++ b/internal/app/archied/task_action_adapter_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/taskstate"
@@ -55,7 +56,7 @@ func TestChatTaskActorAdapterCrossIdentityRefused(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if err := st.Transition(ctx, task.ID, store.StatusQueued, store.StatusParked, "needs help"); err != nil {
+ if err := st.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusParked, "needs help"); err != nil {
t.Fatal(err)
}
@@ -99,7 +100,7 @@ func TestChatTaskActorAdapterCrossIdentityRefused(t *testing.T) {
if err != nil || current == nil {
t.Fatalf("TaskByID = (%+v, %v)", current, err)
}
- if current.Status != store.StatusParked {
+ if current.Status != workflow.StatusParked {
t.Errorf("task status mutated to %q despite cross-identity refusal", current.Status)
}
})
@@ -123,27 +124,27 @@ func TestChatTaskActorAdapterRefusesDisallowedStateAction(t *testing.T) {
}{
{
name: "cannot abandon running task",
- initialStatus: store.StatusRunning,
+ initialStatus: workflow.StatusRunning,
attemptAction: taskstate.ActionAbandon,
},
{
name: "cannot archive parked task",
- initialStatus: store.StatusParked,
+ initialStatus: workflow.StatusParked,
attemptAction: taskstate.ActionArchive,
},
{
name: "cannot retry queued task",
- initialStatus: store.StatusQueued,
+ initialStatus: workflow.StatusQueued,
attemptAction: taskstate.ActionRetry,
},
{
name: "cannot approve running task",
- initialStatus: store.StatusRunning,
+ initialStatus: workflow.StatusRunning,
attemptAction: taskstate.ActionApprove,
},
{
name: "cannot reject merged task",
- initialStatus: store.StatusMerged,
+ initialStatus: workflow.StatusMerged,
attemptAction: taskstate.ActionReject,
},
}
@@ -154,8 +155,8 @@ func TestChatTaskActorAdapterRefusesDisallowedStateAction(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if tc.initialStatus != store.StatusQueued {
- if err := st.Transition(ctx, task.ID, store.StatusQueued, tc.initialStatus, "setup"); err != nil {
+ if tc.initialStatus != workflow.StatusQueued {
+ if err := st.Transition(ctx, task.ID, workflow.StatusQueued, tc.initialStatus, "setup"); err != nil {
t.Fatal(err)
}
}
@@ -212,43 +213,43 @@ func TestChatTaskActorAdapterAppliesActionsToStore(t *testing.T) {
}{
{
name: "abandon parked task closes it won't do",
- initialStatus: store.StatusParked,
+ initialStatus: workflow.StatusParked,
action: taskstate.ActionAbandon,
- wantStatus: store.StatusClosedWontDo,
+ wantStatus: workflow.StatusClosedWontDo,
},
{
name: "retry parked task requeues it",
- initialStatus: store.StatusParked,
+ initialStatus: workflow.StatusParked,
action: taskstate.ActionRetry,
- wantStatus: store.StatusQueued,
+ wantStatus: workflow.StatusQueued,
},
{
name: "cancel queued task closes it",
- initialStatus: store.StatusQueued,
+ initialStatus: workflow.StatusQueued,
action: taskstate.ActionCancel,
- wantStatus: store.StatusClosedWontDo,
+ wantStatus: workflow.StatusClosedWontDo,
},
{
name: "approve waiting_human task queues it",
- initialStatus: store.StatusWaitingHuman,
+ initialStatus: workflow.StatusWaitingHuman,
action: taskstate.ActionApprove,
- wantStatus: store.StatusQueued,
+ wantStatus: workflow.StatusQueued,
},
{
name: "reject waiting_human task closes it",
- initialStatus: store.StatusWaitingHuman,
+ initialStatus: workflow.StatusWaitingHuman,
action: taskstate.ActionReject,
- wantStatus: store.StatusClosedWontDo,
+ wantStatus: workflow.StatusClosedWontDo,
},
{
name: "archive dead task removes it from store",
- initialStatus: store.StatusDead,
+ initialStatus: workflow.StatusDead,
action: taskstate.ActionArchive,
wantArchived: true,
},
{
name: "archive closed_wont_do task removes it from store",
- initialStatus: store.StatusClosedWontDo,
+ initialStatus: workflow.StatusClosedWontDo,
action: taskstate.ActionArchive,
wantArchived: true,
},
@@ -269,8 +270,8 @@ func TestChatTaskActorAdapterAppliesActionsToStore(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if tc.initialStatus != store.StatusQueued {
- if err := st.Transition(ctx, task.ID, store.StatusQueued, tc.initialStatus, "setup"); err != nil {
+ if tc.initialStatus != workflow.StatusQueued {
+ if err := st.Transition(ctx, task.ID, workflow.StatusQueued, tc.initialStatus, "setup"); err != nil {
t.Fatal(err)
}
}
diff --git a/internal/app/archied/task_actions_test.go b/internal/app/archied/task_actions_test.go
index dada7987f..98b5aca9f 100644
--- a/internal/app/archied/task_actions_test.go
+++ b/internal/app/archied/task_actions_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/gateway"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/webui"
@@ -33,10 +34,10 @@ func TestDashboardAndChatAgreeOnTerminalStates(t *testing.T) {
action string
want string
}{
- {name: "dashboard reject", action: "reject", want: store.StatusClosedWontDo},
- {name: "chat cancel", viaChat: true, action: "cancel", want: store.StatusClosedWontDo},
- {name: "dashboard approve", action: "approve", want: store.StatusQueued},
- {name: "chat approve", viaChat: true, action: "approve", want: store.StatusQueued},
+ {name: "dashboard reject", action: "reject", want: workflow.StatusClosedWontDo},
+ {name: "chat cancel", viaChat: true, action: "cancel", want: workflow.StatusClosedWontDo},
+ {name: "dashboard approve", action: "approve", want: workflow.StatusQueued},
+ {name: "chat approve", viaChat: true, action: "approve", want: workflow.StatusQueued},
}
for _, tc := range tests {
@@ -52,7 +53,7 @@ func TestDashboardAndChatAgreeOnTerminalStates(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if err := st.Transition(ctx, task.ID, store.StatusQueued, store.StatusWaitingHuman, "await"); err != nil {
+ if err := st.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusWaitingHuman, "await"); err != nil {
t.Fatal(err)
}
diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go
index 3a8db12bb..ae37080b4 100644
--- a/internal/daemon/daemon.go
+++ b/internal/daemon/daemon.go
@@ -20,6 +20,7 @@ import (
"github.com/samcharles93/archie-core/internal/domain/binding"
"github.com/samcharles93/archie-core/internal/domain/curator"
"github.com/samcharles93/archie-core/internal/domain/mapping"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/domain/workintake"
"github.com/samcharles93/archie-core/internal/eventbus"
"github.com/samcharles93/archie-core/internal/events"
@@ -50,7 +51,7 @@ type TaskBus interface {
// publish its already-prepared branch. The daemon owns grant lifetime; the
// transport implementation owns token mechanics.
type WorktreeGrantIssuer interface {
- Issue(task *store.Task) (token string, revoke func(), err error)
+ Issue(task *workflow.Task) (token string, revoke func(), err error)
}
// NATSEndpoint is the broker address and credential archied connected with at
@@ -707,8 +708,8 @@ func (d *Daemon) submitNATSTask(ctx context.Context, dispatcher *taskDispatcher,
_ = msg.Ack()
return
}
- task := &store.Task{Owner: envelope.Owner, Repo: envelope.Repo, Identity: envelope.Identity}
- dispatcher.Submit(ctx, task, func(ctx context.Context, _ *store.Task) {
+ task := &workflow.Task{Owner: envelope.Owner, Repo: envelope.Repo, Identity: envelope.Identity}
+ dispatcher.Submit(ctx, task, func(ctx context.Context, _ *workflow.Task) {
d.processNATSTask(ctx, msg)
})
}
@@ -720,20 +721,20 @@ func (d *Daemon) submitNATSTask(ctx context.Context, dispatcher *taskDispatcher,
// entirely -- the global slot limit is the only bound on their concurrency.
type taskDispatcher struct {
slots chan struct{}
- allowConcurrent func(task *store.Task) bool
+ allowConcurrent func(task *workflow.Task) bool
mu sync.Mutex
repoTail map[string]chan struct{}
wg sync.WaitGroup
}
-func newTaskDispatcher(maxConcurrency int, allowConcurrent func(task *store.Task) bool) *taskDispatcher {
+func newTaskDispatcher(maxConcurrency int, allowConcurrent func(task *workflow.Task) bool) *taskDispatcher {
var slots chan struct{}
if maxConcurrency > 0 {
slots = make(chan struct{}, maxConcurrency)
}
if allowConcurrent == nil {
- allowConcurrent = func(*store.Task) bool { return false }
+ allowConcurrent = func(*workflow.Task) bool { return false }
}
return &taskDispatcher{
slots: slots,
@@ -744,8 +745,8 @@ func newTaskDispatcher(maxConcurrency int, allowConcurrent func(task *store.Task
func (d *taskDispatcher) Submit(
ctx context.Context,
- task *store.Task,
- process func(context.Context, *store.Task),
+ task *workflow.Task,
+ process func(context.Context, *workflow.Task),
) {
repo := task.Owner + "/" + task.Repo
@@ -950,7 +951,7 @@ func (d *Daemon) pollIssues(ctx context.Context, repo config.Repo) []forge.Issue
// is skipped. Failure is logged rather than returned: the task's own state is
// already correct, and the next reconcile pass will not retry, so a warning
// is the honest outcome -- the issue simply stays open.
-func (d *Daemon) closeResolvedIssue(ctx context.Context, fg forge.Forge, task *store.Task, comment string) {
+func (d *Daemon) closeResolvedIssue(ctx context.Context, fg forge.Forge, task *workflow.Task, comment string) {
if !task.IsForgeBacked() {
return
}
@@ -982,7 +983,7 @@ func (d *Daemon) reconcilePRs(ctx context.Context) {
}
switch state {
case "merged":
- _ = d.Store.Transition(ctx, t.ID, store.StatusPROpen, store.StatusMerged, "")
+ _ = d.Store.Transition(ctx, t.ID, workflow.StatusPROpen, workflow.StatusMerged, "")
_ = trees.Cleanup(t.Owner, t.Repo, t.IssueNumber)
// Close the issue ourselves rather than relying on the forge
// noticing a "Closes #N" in the PR body. Nothing else closes it:
@@ -1001,7 +1002,7 @@ func (d *Daemon) reconcilePRs(ctx context.Context) {
Data: map[string]any{"pr": t.PRNumber},
})
case "closed":
- _ = d.Store.Transition(ctx, t.ID, store.StatusPROpen, store.StatusRejected, "PR closed without merge")
+ _ = d.Store.Transition(ctx, t.ID, workflow.StatusPROpen, workflow.StatusRejected, "PR closed without merge")
_ = trees.Cleanup(t.Owner, t.Repo, t.IssueNumber)
d.Log.Info("PR rejected", "repo", t.Owner+"/"+t.Repo, "pr", t.PRNumber)
d.emit(events.Event{
@@ -1013,7 +1014,7 @@ func (d *Daemon) reconcilePRs(ctx context.Context) {
}
}
-func (d *Daemon) process(ctx context.Context, task *store.Task) {
+func (d *Daemon) process(ctx context.Context, task *workflow.Task) {
// Register before any work starts so the task is stoppable for its
// whole life, including the slow setup -- clone, worktree prepare,
// image pull -- which is exactly when someone realises they asked for
@@ -1033,7 +1034,7 @@ func (d *Daemon) process(ctx context.Context, task *store.Task) {
const reason = "managed agent container pool is unavailable; refusing to run this task on the host"
d.Log.Error("task parked: managed worker unavailable", "task", task.ID,
"hint", "enable containers and make the archie-agent image available, then retry the task")
- if err := d.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusParked, reason); err != nil {
+ if err := d.Store.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusParked, reason); err != nil {
d.Log.Warn("managed worker park transition failed", "task", task.ID, "err", err)
return
}
@@ -1046,7 +1047,7 @@ func (d *Daemon) process(ctx context.Context, task *store.Task) {
if d.Tasks == nil {
const reason = "agent task transport is unavailable; refusing to run this task on the host"
d.Log.Error("task parked: agent task transport unavailable", "task", task.ID)
- if err := d.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusParked, reason); err != nil {
+ if err := d.Store.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusParked, reason); err != nil {
d.Log.Warn("agent task transport park transition failed", "task", task.ID, "err", err)
return
}
@@ -1112,7 +1113,7 @@ func (d *Daemon) process(ctx context.Context, task *store.Task) {
d.cleanupTerminalTaskWorktree(ctx, task, trees)
}
-func (d *Daemon) cleanupTerminalTaskWorktree(ctx context.Context, task *store.Task, trees *worktree.Manager) {
+func (d *Daemon) cleanupTerminalTaskWorktree(ctx context.Context, task *workflow.Task, trees *worktree.Manager) {
if d.Store == nil || trees == nil || task == nil {
return
}
@@ -1128,7 +1129,7 @@ func (d *Daemon) cleanupTerminalTaskWorktree(ctx context.Context, task *store.Ta
return
}
switch latest.Status {
- case store.StatusMerged, store.StatusRejected, store.StatusClosedWontDo:
+ case workflow.StatusMerged, workflow.StatusRejected, workflow.StatusClosedWontDo:
if latest.PRNumber == 0 {
if err := trees.Cleanup(task.Owner, task.Repo, task.IssueNumber); err != nil {
d.Log.Warn("terminal worktree cleanup failed", "task", task.ID, "err", err)
@@ -1144,7 +1145,7 @@ func (d *Daemon) cleanupTerminalTaskWorktree(ctx context.Context, task *store.Ta
// attempt's own output won't be recoverable if something goes wrong, which
// is worse than the pre-existing state, not equal to it, so the run
// proceeds rather than parking over a logging problem.
-func (d *Daemon) openTaskLog(task *store.Task) func() {
+func (d *Daemon) openTaskLog(task *workflow.Task) func() {
if err := d.TaskLogs.Open(task.ID, task.Attempt); err != nil {
d.Log.Warn("task log sink unavailable", "task", task.ID, "attempt", task.Attempt, "err", err)
}
@@ -1160,7 +1161,7 @@ func (d *Daemon) openTaskLog(task *store.Task) func() {
// task and logged why. The caller releases the container it returns.
func (d *Daemon) acquireTaskContainer(
ctx context.Context,
- task *store.Task,
+ task *workflow.Task,
repo config.Repo,
workDir string,
) (*container.Container, bool) {
@@ -1241,7 +1242,7 @@ func (d *Daemon) parkRunningTask(ctx context.Context, taskID int64, reason strin
writeCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
defer cancel()
- if err := d.Store.Transition(writeCtx, taskID, store.StatusRunning, store.StatusParked, reason); err != nil {
+ if err := d.Store.Transition(writeCtx, taskID, workflow.StatusRunning, workflow.StatusParked, reason); err != nil {
if !errors.Is(err, store.ErrStaleTransition) {
d.Log.Warn("terminal park transition failed", "task", taskID, "reason", reason, "err", err)
}
@@ -1258,7 +1259,7 @@ func (d *Daemon) parkRunningTask(ctx context.Context, taskID int64, reason strin
// itself when nothing else could have: the request never reached (or was
// never answered by) an archie-agent, or archie-agent failed before its
// own workflow.Run got a chance to record an outcome.
-func (d *Daemon) runViaAgent(ctx context.Context, task *store.Task, repo config.Repo) {
+func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo config.Repo) {
if d.WorktreeGrants == nil {
const reason = "worktree publication grants are unavailable"
d.Log.Error(reason, "task", task.ID)
@@ -1374,7 +1375,7 @@ func (d *Daemon) requestTaskRun(ctx context.Context, taskID int64, data []byte)
}
}
-func (d *Daemon) containerEnv(task *store.Task) []string {
+func (d *Daemon) containerEnv(task *workflow.Task) []string {
var env []string
// The endpoint the daemon's own client connected with at startup, not
// the live config: a reloaded [nats] section must not point new
@@ -1402,7 +1403,7 @@ func (d *Daemon) containerEnv(task *store.Task) []string {
return env
}
-func (d *Daemon) configFor(task *store.Task) config.Config {
+func (d *Daemon) configFor(task *workflow.Task) config.Config {
if id := d.identityFor(task); id != nil {
return configForIdentity(d.Cfg.Get(), id.Cfg)
}
@@ -1427,7 +1428,7 @@ func configForIdentity(root config.Config, identity config.IdentityConfig) confi
// single-identity deployments and forge-sourced tasks recorded
// before multi-identity routing existed (task.Identity == ""). Callers
// must fall back to the root d.Forge/d.Trees/d.Cfg when this returns nil.
-func (d *Daemon) identityFor(task *store.Task) *IdentityRunner {
+func (d *Daemon) identityFor(task *workflow.Task) *IdentityRunner {
if task == nil || task.Identity == "" {
return nil
}
@@ -1443,7 +1444,7 @@ func (d *Daemon) identityFor(task *store.Task) *IdentityRunner {
// client when task.Identity names a configured identity, else the root
// d.Forge. This is the safety boundary that keeps one identity's forge
// token from being used against another identity's repos.
-func (d *Daemon) forgeFor(task *store.Task) forge.Forge {
+func (d *Daemon) forgeFor(task *workflow.Task) forge.Forge {
if id := d.identityFor(task); id != nil {
return id.Forge
}
@@ -1451,7 +1452,7 @@ func (d *Daemon) forgeFor(task *store.Task) forge.Forge {
}
// treesFor returns the worktree manager that owns task, mirroring forgeFor.
-func (d *Daemon) treesFor(task *store.Task) *worktree.Manager {
+func (d *Daemon) treesFor(task *workflow.Task) *worktree.Manager {
if id := d.identityFor(task); id != nil {
return id.Trees
}
@@ -1460,7 +1461,7 @@ func (d *Daemon) treesFor(task *store.Task) *worktree.Manager {
// repoFor resolves task's repo config from the owning identity's repo
// list when task.Identity is set, else the root Cfg.Repos.
-func (d *Daemon) repoFor(t *store.Task) (config.Repo, bool) {
+func (d *Daemon) repoFor(t *workflow.Task) (config.Repo, bool) {
repos := d.Cfg.Get().Repos
if id := d.identityFor(t); id != nil {
repos = id.Repos
@@ -1479,7 +1480,7 @@ func (d *Daemon) repoFor(t *store.Task) (config.Repo, bool) {
// task.Identity names a configured identity -- so multi-identity concurrency
// policy comes from the identity's own config, not the root daemon's.
// Unknown repos default to the safe, serialized behavior.
-func (d *Daemon) allowConcurrentForTask(task *store.Task) bool {
+func (d *Daemon) allowConcurrentForTask(task *workflow.Task) bool {
repo, ok := d.repoFor(task)
return ok && repo.AllowConcurrent
}
diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go
index 7a2f03f92..920e2a3e4 100644
--- a/internal/daemon/daemon_test.go
+++ b/internal/daemon/daemon_test.go
@@ -18,6 +18,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/container"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/domain/workintake"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
@@ -76,7 +77,7 @@ func TestCleanupExpiredStorageUsesConfiguredTTL(t *testing.T) {
func TestOpenTaskLogOpensAndClosesTheRightSink(t *testing.T) {
reg := logging.NewTaskRegistry(t.TempDir(), logging.NewFeed(10), logging.TaskSinkOptions{})
d := &Daemon{TaskLogs: reg, Log: slog.New(slog.DiscardHandler)}
- task := &store.Task{ID: 5, Attempt: 2}
+ task := &workflow.Task{ID: 5, Attempt: 2}
closeFn := d.openTaskLog(task)
if ok := reg.Write(5, logging.Entry{Message: "x"}); !ok {
@@ -134,7 +135,7 @@ func TestProcessParksWhenManagedWorkerCapabilityIsUnavailable(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if got.Status != store.StatusParked {
+ if got.Status != workflow.StatusParked {
t.Fatalf("task status = %q, want parked", got.Status)
}
if got.ParkReason != tt.wantReason {
@@ -184,8 +185,8 @@ func TestTaskDispatcherEnforcesMaxConcurrency(t *testing.T) {
var peak atomic.Int32
for i := 1; i <= 3; i++ {
- task := &store.Task{Owner: "acme", Repo: "repo-" + string(rune('0'+i))}
- dispatcher.Submit(context.Background(), task, func(context.Context, *store.Task) {
+ task := &workflow.Task{Owner: "acme", Repo: "repo-" + string(rune('0'+i))}
+ dispatcher.Submit(context.Background(), task, func(context.Context, *workflow.Task) {
n := active.Add(1)
for {
old := peak.Load()
@@ -234,14 +235,14 @@ func TestTaskDispatcherSerializesTasksForSameRepo(t *testing.T) {
secondStarted := make(chan struct{})
otherRepoStarted := make(chan struct{})
- dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
+ dispatcher.Submit(context.Background(), &workflow.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *workflow.Task) {
close(firstStarted)
<-releaseFirst
})
- dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
+ dispatcher.Submit(context.Background(), &workflow.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *workflow.Task) {
close(secondStarted)
})
- dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "gizmo"}, func(context.Context, *store.Task) {
+ dispatcher.Submit(context.Background(), &workflow.Task{Owner: "acme", Repo: "gizmo"}, func(context.Context, *workflow.Task) {
close(otherRepoStarted)
})
@@ -274,18 +275,18 @@ func TestTaskDispatcherSerializesTasksForSameRepo(t *testing.T) {
func TestTaskDispatcherRunsConcurrentReposInParallel(t *testing.T) {
t.Parallel()
- dispatcher := newTaskDispatcher(3, func(task *store.Task) bool {
+ dispatcher := newTaskDispatcher(3, func(task *workflow.Task) bool {
return task.Owner == "acme" && task.Repo == "widget"
})
releaseFirst := make(chan struct{})
firstStarted := make(chan struct{})
secondStarted := make(chan struct{})
- dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
+ dispatcher.Submit(context.Background(), &workflow.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *workflow.Task) {
close(firstStarted)
<-releaseFirst
})
- dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
+ dispatcher.Submit(context.Background(), &workflow.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *workflow.Task) {
close(secondStarted)
})
@@ -309,7 +310,7 @@ func TestTaskDispatcherWaitsForRunningTasks(t *testing.T) {
dispatcher := newTaskDispatcher(1, nil)
release := make(chan struct{})
- dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
+ dispatcher.Submit(context.Background(), &workflow.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *workflow.Task) {
<-release
})
@@ -342,13 +343,13 @@ func TestDaemonAllowConcurrentForReadsRepoConfig(t *testing.T) {
}),
}
- if !d.allowConcurrentForTask(&store.Task{Owner: "acme", Repo: "widget"}) {
+ if !d.allowConcurrentForTask(&workflow.Task{Owner: "acme", Repo: "widget"}) {
t.Fatal("expected allow_concurrent=true repo to report concurrent-allowed")
}
- if d.allowConcurrentForTask(&store.Task{Owner: "acme", Repo: "todo"}) {
+ if d.allowConcurrentForTask(&workflow.Task{Owner: "acme", Repo: "todo"}) {
t.Fatal("expected repo without allow_concurrent to report false")
}
- if d.allowConcurrentForTask(&store.Task{Owner: "acme", Repo: "unknown"}) {
+ if d.allowConcurrentForTask(&workflow.Task{Owner: "acme", Repo: "unknown"}) {
t.Fatal("expected unknown repo to report false")
}
}
@@ -374,12 +375,12 @@ func TestAllowConcurrentForTaskPrefersOwningIdentityRepo(t *testing.T) {
},
}
- if !d.allowConcurrentForTask(&store.Task{Owner: "acme", Repo: "shared", Identity: "archie"}) {
+ if !d.allowConcurrentForTask(&workflow.Task{Owner: "acme", Repo: "shared", Identity: "archie"}) {
t.Fatal("identity-owned task must use the identity's repo allow_concurrent")
}
// A root-owned (identity-less) task must NOT inherit the identity's
// opt-in: it resolves through the root repo list.
- if d.allowConcurrentForTask(&store.Task{Owner: "acme", Repo: "shared"}) {
+ if d.allowConcurrentForTask(&workflow.Task{Owner: "acme", Repo: "shared"}) {
t.Fatal("identity-less task leaked the identity's allow_concurrent")
}
}
@@ -447,7 +448,7 @@ func TestContainerEnvUsesOnlyOwningIdentityProviderCredential(t *testing.T) {
}},
}
- got := d.containerEnv(&store.Task{Identity: "worker"})
+ got := d.containerEnv(&workflow.Task{Identity: "worker"})
if !slices.Contains(got, "WORKER_PROVIDER_KEY=worker-secret") {
t.Fatalf("identity credential missing from container env: %q", got)
}
@@ -495,7 +496,7 @@ func daemonWithNATS(t *testing.T) (*Daemon, *store.Store, *arnats.Client) {
type fixedGrantIssuer struct{ token string }
-func (g fixedGrantIssuer) Issue(*store.Task) (string, func(), error) {
+func (g fixedGrantIssuer) Issue(*workflow.Task) (string, func(), error) {
return g.token, func() {}, nil
}
@@ -541,8 +542,8 @@ func TestRunViaAgentParksOnRequestFailure(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
- if got.Status != store.StatusParked {
- t.Fatalf("status = %q, want %q", got.Status, store.StatusParked)
+ if got.Status != workflow.StatusParked {
+ t.Fatalf("status = %q, want %q", got.Status, workflow.StatusParked)
}
if !strings.Contains(got.ParkReason, "taskrun request failed") {
t.Errorf("ParkReason = %q, want taskrun request failure", got.ParkReason)
@@ -585,7 +586,7 @@ func TestRunViaAgentRetriesUntilResponderAppears(t *testing.T) {
return
}
sub, err := coreConn.Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
- data, _ := json.Marshal(taskrun.Response{Status: store.StatusPROpen})
+ data, _ := json.Marshal(taskrun.Response{Status: workflow.StatusPROpen})
_ = msg.Respond(data)
})
if err != nil {
@@ -601,7 +602,7 @@ func TestRunViaAgentRetriesUntilResponderAppears(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
- if got.Status == store.StatusParked {
+ if got.Status == workflow.StatusParked {
t.Fatal("runViaAgent parked a task whose responder appeared within the retry window")
}
}
@@ -660,8 +661,8 @@ func TestRunViaAgentParksOnRunError(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
- if got.Status != store.StatusParked {
- t.Fatalf("status = %q, want %q", got.Status, store.StatusParked)
+ if got.Status != workflow.StatusParked {
+ t.Fatalf("status = %q, want %q", got.Status, workflow.StatusParked)
}
if got.ParkReason != "taskrun run failed: registry build failed" {
t.Errorf("ParkReason = %q, want worker run failure", got.ParkReason)
@@ -690,7 +691,7 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
var req taskrun.Request
_ = json.Unmarshal(msg.Data, &req)
received <- req
- data, _ := json.Marshal(taskrun.Response{Status: store.StatusPROpen})
+ data, _ := json.Marshal(taskrun.Response{Status: workflow.StatusPROpen})
_ = msg.Respond(data)
})
if err != nil {
@@ -728,7 +729,7 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
- if got.Status == store.StatusParked {
+ if got.Status == workflow.StatusParked {
t.Fatal("runViaAgent parked a task that succeeded")
}
}
@@ -755,7 +756,7 @@ func TestRunViaAgentObservesReportedAgentVersion(t *testing.T) {
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
data, _ := json.Marshal(taskrun.Response{
- Status: store.StatusPROpen, AgentVersion: "1.9.11", AgentInstallType: "container",
+ Status: workflow.StatusPROpen, AgentVersion: "1.9.11", AgentInstallType: "container",
})
_ = msg.Respond(data)
})
@@ -791,7 +792,7 @@ func TestRunViaAgentIgnoresEmptyAgentVersion(t *testing.T) {
}
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
- data, _ := json.Marshal(taskrun.Response{Status: store.StatusPROpen})
+ data, _ := json.Marshal(taskrun.Response{Status: workflow.StatusPROpen})
_ = msg.Respond(data)
})
if err != nil {
@@ -1035,7 +1036,7 @@ func TestConfigForUsesIdentityConfigAndProvider(t *testing.T) {
}},
}
- cfg := d.configFor(&store.Task{Identity: "worker"})
+ cfg := d.configFor(&workflow.Task{Identity: "worker"})
if cfg.Models["builder"] != "worker/model" {
t.Fatalf("builder model = %q", cfg.Models["builder"])
}
@@ -1100,16 +1101,16 @@ func twoIdentityDaemon(t *testing.T) (d *Daemon, s *store.Store, rootFg, archieF
func TestIdentityForResolvesOwningRunner(t *testing.T) {
d, _, _, _, _ := twoIdentityDaemon(t)
- if id := d.identityFor(&store.Task{Identity: "archie"}); id == nil || id.Name != "archie" {
+ if id := d.identityFor(&workflow.Task{Identity: "archie"}); id == nil || id.Name != "archie" {
t.Fatalf("identityFor(archie) = %v, want archie runner", id)
}
- if id := d.identityFor(&store.Task{Identity: "winter"}); id == nil || id.Name != "winter" {
+ if id := d.identityFor(&workflow.Task{Identity: "winter"}); id == nil || id.Name != "winter" {
t.Fatalf("identityFor(winter) = %v, want winter runner", id)
}
- if id := d.identityFor(&store.Task{Identity: ""}); id != nil {
+ if id := d.identityFor(&workflow.Task{Identity: ""}); id != nil {
t.Fatalf("identityFor(\"\") = %v, want nil (legacy single-identity path)", id)
}
- if id := d.identityFor(&store.Task{Identity: "nonexistent"}); id != nil {
+ if id := d.identityFor(&workflow.Task{Identity: "nonexistent"}); id != nil {
t.Fatalf("identityFor(nonexistent) = %v, want nil", id)
}
}
@@ -1137,7 +1138,7 @@ func TestRepoForPrefersOwningIdentityRepoList(t *testing.T) {
identityOnlyRepo := config.Repo{Owner: "acme", Name: "identity-only"}
d.Identities[0].Repos = append(d.Identities[0].Repos, identityOnlyRepo)
- got, ok := d.repoFor(&store.Task{Owner: "acme", Repo: "identity-only", Identity: "archie"})
+ got, ok := d.repoFor(&workflow.Task{Owner: "acme", Repo: "identity-only", Identity: "archie"})
if !ok {
t.Fatal("repoFor did not find an identity-only repo via the owning identity's repo list")
}
@@ -1146,7 +1147,7 @@ func TestRepoForPrefersOwningIdentityRepoList(t *testing.T) {
}
// The same repo name must NOT resolve for an unrelated identity.
- if _, ok := d.repoFor(&store.Task{Owner: "acme", Repo: "identity-only", Identity: "winter"}); ok {
+ if _, ok := d.repoFor(&workflow.Task{Owner: "acme", Repo: "identity-only", Identity: "winter"}); ok {
t.Fatal("repoFor leaked archie's identity-only repo to winter")
}
}
@@ -1183,7 +1184,7 @@ func TestMaintainAndDrainReconcilesPRsInMultiIdentityMode(t *testing.T) {
if err := s.Update(ctx, task); err != nil {
t.Fatal(err)
}
- if err := s.Transition(ctx, task.ID, store.StatusRunning, store.StatusPROpen, ""); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusPROpen, ""); err != nil {
t.Fatal(err)
}
archieFg.prStates = map[int]string{42: "merged"}
@@ -1194,8 +1195,8 @@ func TestMaintainAndDrainReconcilesPRsInMultiIdentityMode(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != store.StatusMerged {
- t.Fatalf("status = %q, want %q (multi-identity reconcile never ran)", got.Status, store.StatusMerged)
+ if got.Status != workflow.StatusMerged {
+ t.Fatalf("status = %q, want %q (multi-identity reconcile never ran)", got.Status, workflow.StatusMerged)
}
if len(archieFg.closedIssues) != 1 {
t.Fatalf("CloseIssue calls = %d, want 1 (issue must be closed on merge)", len(archieFg.closedIssues))
@@ -1372,7 +1373,7 @@ func TestReconcilePRsClosesTheIssueOnMerge(t *testing.T) {
if err := s.Update(ctx, task); err != nil {
t.Fatal(err)
}
- if err := s.Transition(ctx, task.ID, store.StatusRunning, store.StatusPROpen, ""); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusPROpen, ""); err != nil {
t.Fatal(err)
}
fg.prStates = map[int]string{7: tc.prState}
@@ -1418,7 +1419,7 @@ func TestReconcilePRsSkipsChatTasks(t *testing.T) {
if err := s.Update(ctx, task); err != nil {
t.Fatal(err)
}
- if err := s.Transition(ctx, task.ID, store.StatusRunning, store.StatusPROpen, ""); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusPROpen, ""); err != nil {
t.Fatal(err)
}
fg.prStates = map[int]string{8: "merged"}
diff --git a/internal/daemon/dispatch_bindings_test.go b/internal/daemon/dispatch_bindings_test.go
index 2a8b896a7..c0ae262bf 100644
--- a/internal/daemon/dispatch_bindings_test.go
+++ b/internal/daemon/dispatch_bindings_test.go
@@ -10,6 +10,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/binding"
"github.com/samcharles93/archie-core/internal/domain/mapping"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/store"
)
@@ -39,11 +40,11 @@ func TestDispatchBindingsCreatesTaskFromArmedCapture(t *testing.T) {
if got.BindingVersion != bindingVersion {
t.Errorf("task.BindingVersion = %d, want %d", got.BindingVersion, bindingVersion)
}
- if got.Source != store.SourceChat {
- t.Errorf("task.Source = %q, want %q", got.Source, store.SourceChat)
+ if got.Source != workflow.SourceChat {
+ t.Errorf("task.Source = %q, want %q", got.Source, workflow.SourceChat)
}
- if got.Status != store.StatusQueued {
- t.Errorf("task.Status = %q, want %q", got.Status, store.StatusQueued)
+ if got.Status != workflow.StatusQueued {
+ t.Errorf("task.Status = %q, want %q", got.Status, workflow.StatusQueued)
}
assertDispatchRecorded(t, s, bindingID, got.ID)
diff --git a/internal/daemon/task_cancellation_test.go b/internal/daemon/task_cancellation_test.go
index e196760f9..780bb51a4 100644
--- a/internal/daemon/task_cancellation_test.go
+++ b/internal/daemon/task_cancellation_test.go
@@ -20,6 +20,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
archiecontainer "github.com/samcharles93/archie-core/internal/container"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
"github.com/samcharles93/archie-core/internal/storage"
"github.com/samcharles93/archie-core/internal/store"
@@ -46,7 +47,7 @@ func (l *logBuffer) String() string {
type errGrantIssuer struct{}
-func (errGrantIssuer) Issue(*store.Task) (string, func(), error) {
+func (errGrantIssuer) Issue(*workflow.Task) (string, func(), error) {
return "", nil, errors.New("simulated grant issue error")
}
@@ -84,37 +85,37 @@ func TestCancelledTaskTransitionsToParked(t *testing.T) {
{
name: "task cancelled during requestTaskRun",
cancelDuring: true,
- wantStatus: store.StatusParked,
+ wantStatus: workflow.StatusParked,
wantParkSubstr: "context canceled",
},
{
name: "task cancelled before runViaAgent",
cancelBefore: true,
- wantStatus: store.StatusParked,
+ wantStatus: workflow.StatusParked,
wantParkSubstr: "context canceled",
},
{
name: "worktree grants unavailable",
nilGrants: true,
- wantStatus: store.StatusParked,
+ wantStatus: workflow.StatusParked,
wantParkSubstr: "worktree publication grants are unavailable",
},
{
name: "worktree grant issue failed",
errGrants: true,
- wantStatus: store.StatusParked,
+ wantStatus: workflow.StatusParked,
wantParkSubstr: "worktree publication grant failed",
},
{
name: "taskrun decode response failed",
decodeErr: true,
- wantStatus: store.StatusParked,
+ wantStatus: workflow.StatusParked,
wantParkSubstr: "taskrun decode response failed",
},
{
name: "taskrun agent returned error",
agentErr: "simulated agent execution failure",
- wantStatus: store.StatusParked,
+ wantStatus: workflow.StatusParked,
wantParkSubstr: "taskrun run failed: simulated agent execution failure",
},
}
@@ -203,31 +204,31 @@ func TestCleanupTerminalTaskWorktreeWithCancelledContext(t *testing.T) {
}{
{
name: "merged task with cancelled context cleans worktree",
- taskStatus: store.StatusMerged,
+ taskStatus: workflow.StatusMerged,
prNumber: 0,
wantTreeExists: false,
},
{
name: "rejected task with cancelled context cleans worktree",
- taskStatus: store.StatusRejected,
+ taskStatus: workflow.StatusRejected,
prNumber: 0,
wantTreeExists: false,
},
{
name: "closed wont do task with cancelled context cleans worktree",
- taskStatus: store.StatusClosedWontDo,
+ taskStatus: workflow.StatusClosedWontDo,
prNumber: 0,
wantTreeExists: false,
},
{
name: "parked task with cancelled context preserves worktree",
- taskStatus: store.StatusParked,
+ taskStatus: workflow.StatusParked,
prNumber: 0,
wantTreeExists: true,
},
{
name: "open PR task with cancelled context preserves worktree",
- taskStatus: store.StatusPROpen,
+ taskStatus: workflow.StatusPROpen,
prNumber: 12,
wantTreeExists: true,
},
@@ -257,7 +258,7 @@ func TestCleanupTerminalTaskWorktreeWithCancelledContext(t *testing.T) {
t.Fatalf("ClaimNext: (%v, %v)", task, err)
}
- if err := st.Transition(context.Background(), task.ID, store.StatusRunning, tt.taskStatus, "setup"); err != nil {
+ if err := st.Transition(context.Background(), task.ID, workflow.StatusRunning, tt.taskStatus, "setup"); err != nil {
t.Fatalf("Transition: %v", err)
}
if tt.prNumber > 0 {
@@ -362,8 +363,8 @@ func TestProcessStopRunningTransitionsToParked(t *testing.T) {
if err != nil {
t.Fatalf("TaskByID: %v", err)
}
- if got.Status != store.StatusParked {
- t.Fatalf("stopped task status = %q, want %q", got.Status, store.StatusParked)
+ if got.Status != workflow.StatusParked {
+ t.Fatalf("stopped task status = %q, want %q", got.Status, workflow.StatusParked)
}
if !strings.Contains(got.ParkReason, "context canceled") {
t.Errorf("park reason = %q, want substring 'context canceled'", got.ParkReason)
@@ -383,22 +384,22 @@ func TestParkRunningTaskGuardedAndLogging(t *testing.T) {
}{
{
name: "successful park on cancelled context transitions row to parked without warning",
- initialStatus: store.StatusRunning,
+ initialStatus: workflow.StatusRunning,
cancelContext: true,
- wantStatus: store.StatusParked,
+ wantStatus: workflow.StatusParked,
wantWarning: false,
},
{
name: "stale transition preserves worker status and logs no warning",
- initialStatus: store.StatusRunning,
- workerStatus: store.StatusMerged,
+ initialStatus: workflow.StatusRunning,
+ workerStatus: workflow.StatusMerged,
cancelContext: true,
- wantStatus: store.StatusMerged,
+ wantStatus: workflow.StatusMerged,
wantWarning: false,
},
{
name: "store write failure logs warning",
- initialStatus: store.StatusRunning,
+ initialStatus: workflow.StatusRunning,
closeStore: true,
wantWarning: true,
wantLogSubstr: "terminal park transition failed",
@@ -428,7 +429,7 @@ func TestParkRunningTaskGuardedAndLogging(t *testing.T) {
}
if tt.workerStatus != "" {
- if err := s.Transition(ctx, task.ID, store.StatusRunning, tt.workerStatus, "worker completion"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, tt.workerStatus, "worker completion"); err != nil {
t.Fatalf("Transition to workerStatus: %v", err)
}
}
@@ -526,8 +527,8 @@ func TestAcquireTaskContainerFailureParksTaskOnCancelledContext(t *testing.T) {
if err != nil {
t.Fatalf("TaskByID: %v", err)
}
- if got.Status != store.StatusParked {
- t.Fatalf("task status = %q, want %q", got.Status, store.StatusParked)
+ if got.Status != workflow.StatusParked {
+ t.Fatalf("task status = %q, want %q", got.Status, workflow.StatusParked)
}
if !strings.Contains(got.ParkReason, tt.wantParkSubstr) {
t.Errorf("park reason = %q, want substring %q", got.ParkReason, tt.wantParkSubstr)
diff --git a/internal/daemon/terminal_cleanup_test.go b/internal/daemon/terminal_cleanup_test.go
index e5d726334..263774824 100644
--- a/internal/daemon/terminal_cleanup_test.go
+++ b/internal/daemon/terminal_cleanup_test.go
@@ -22,6 +22,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
archiecontainer "github.com/samcharles93/archie-core/internal/container"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
"github.com/samcharles93/archie-core/internal/storage"
"github.com/samcharles93/archie-core/internal/store"
@@ -110,35 +111,35 @@ func TestCleanupTerminalTaskWorktreeLifecycle(t *testing.T) {
{
name: "root no-change merged task cleans worktree",
taskIdentity: "",
- setupStatus: store.StatusMerged,
+ setupStatus: workflow.StatusMerged,
prNumber: 0,
wantTreeExists: false,
},
{
name: "multi-identity no-change merged task cleans identity worktree",
taskIdentity: "winter",
- setupStatus: store.StatusMerged,
+ setupStatus: workflow.StatusMerged,
prNumber: 0,
wantTreeExists: false,
},
{
name: "parked task preserves worktree for post-mortem",
taskIdentity: "",
- setupStatus: store.StatusParked,
+ setupStatus: workflow.StatusParked,
prNumber: 0,
wantTreeExists: true,
},
{
name: "open PR task preserves worktree for PR reconciliation",
taskIdentity: "",
- setupStatus: store.StatusPROpen,
+ setupStatus: workflow.StatusPROpen,
prNumber: 42,
wantTreeExists: true,
},
{
name: "waiting human task preserves worktree",
taskIdentity: "",
- setupStatus: store.StatusWaitingHuman,
+ setupStatus: workflow.StatusWaitingHuman,
prNumber: 0,
wantTreeExists: true,
},
@@ -180,8 +181,8 @@ func TestCleanupTerminalTaskWorktreeLifecycle(t *testing.T) {
t.Fatalf("ClaimNext: (%v, %v)", claimed, err)
}
- if tt.setupStatus != store.StatusRunning {
- if err := st.Transition(ctx, claimed.ID, store.StatusRunning, tt.setupStatus, "status update"); err != nil {
+ if tt.setupStatus != workflow.StatusRunning {
+ if err := st.Transition(ctx, claimed.ID, workflow.StatusRunning, tt.setupStatus, "status update"); err != nil {
t.Fatalf("Transition to %s: %v", tt.setupStatus, err)
}
}
@@ -219,19 +220,19 @@ func TestProcessCleansWorktreeOnTerminalNoChange(t *testing.T) {
}{
{
name: "process removes worktree when worker reports merged without PR",
- workerStatus: store.StatusMerged,
+ workerStatus: workflow.StatusMerged,
taskIdentity: "",
wantTreeExists: false,
},
{
name: "process removes identity worktree when worker reports merged without PR",
- workerStatus: store.StatusMerged,
+ workerStatus: workflow.StatusMerged,
taskIdentity: "winter",
wantTreeExists: false,
},
{
name: "process keeps worktree when worker parks task",
- workerStatus: store.StatusParked,
+ workerStatus: workflow.StatusParked,
taskIdentity: "",
wantTreeExists: true,
},
@@ -319,7 +320,7 @@ func TestProcessCleansWorktreeOnTerminalNoChange(t *testing.T) {
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
// Transition task in store as archie-agent would do over storerpc
- _ = s.Transition(ctx, task.ID, store.StatusRunning, tt.workerStatus, "worker completion")
+ _ = s.Transition(ctx, task.ID, workflow.StatusRunning, tt.workerStatus, "worker completion")
resp, _ := json.Marshal(taskrun.Response{
Status: tt.workerStatus,
})
diff --git a/internal/domain/eda/playbook/playbook.go b/internal/domain/eda/playbook/playbook.go
index 28148eb39..929890c4a 100644
--- a/internal/domain/eda/playbook/playbook.go
+++ b/internal/domain/eda/playbook/playbook.go
@@ -217,8 +217,8 @@ type DispatchInput struct {
// TaskEnvelope.IdempotencyKey() value ("archie:owner/repo/number"), the
// stable identity available at the discovery/dispatch point (pollNATS and
// the webhook receiver both compute kind/labels from a TaskEnvelope before
- // any store.Task row exists). It is NOT a store.Task.ID int64, which does
- // not exist until the task is persisted.
+ // any workflow.Task row exists). It is NOT a workflow.Task.ID int64, which
+ // does not exist until the task is persisted.
TaskID string
// Event is the event payload exposed as `event` in CEL expressions. For
// a workflow-kind dispatch this carries the label/kind fields cheaply
diff --git a/internal/domain/eda/playbook/playbook_test.go b/internal/domain/eda/playbook/playbook_test.go
index 398c39b25..9119adbd4 100644
--- a/internal/domain/eda/playbook/playbook_test.go
+++ b/internal/domain/eda/playbook/playbook_test.go
@@ -339,7 +339,7 @@ actions:
// the TaskEnvelope.IdempotencyKey() string ("archie:owner/repo/number") --
// the value available at the discovery/dispatch point (pollNATS + webhook
// receiver both compute kind/labels from a TaskEnvelope before any
-// store.Task row exists), NOT a store.Task.ID int64.
+// workflow.Task row exists), NOT a workflow.Task.ID int64.
func TestDispatchInputCarriesTaskIdentity(t *testing.T) {
dir := t.TempDir()
writeFile(t, dir, "pb.yaml", `
diff --git a/internal/domain/workflow/agent_test.go b/internal/domain/workflow/agent_test.go
index d3b966bb2..e0f6ac970 100644
--- a/internal/domain/workflow/agent_test.go
+++ b/internal/domain/workflow/agent_test.go
@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"log/slog"
- "path/filepath"
"reflect"
"strings"
"testing"
@@ -14,7 +13,6 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/events"
- "github.com/samcharles93/archie-core/internal/store"
)
type fakeAgentRunner struct {
@@ -64,7 +62,7 @@ func TestAgentStageBuildsExecutionRequestAndAppliesResult(t *testing.T) {
return nil
},
}.Stage()
- task := &store.Task{ID: 9, Attempt: 2}
+ task := &Task{ID: 9, Attempt: 2}
tc := &TaskContext{
Task: task, Agent: runner, Dir: "/tmp/workspace", Log: slog.New(slog.DiscardHandler),
Cfg: config.Config{
@@ -113,7 +111,7 @@ func TestAgentStageReportsToolCallsOnTheTaskBus(t *testing.T) {
sub := bus.Subscribe(8)
t.Cleanup(sub.Close)
- task := &store.Task{ID: 9, Owner: "acme", Repo: "widget", Attempt: 1}
+ task := &Task{ID: 9, Owner: "acme", Repo: "widget", Attempt: 1}
tc := &TaskContext{
Task: task, Agent: runner, Dir: "/tmp/workspace", Bus: bus, Log: slog.New(slog.DiscardHandler),
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
@@ -148,45 +146,8 @@ func TestAgentStageReportsToolCallsOnTheTaskBus(t *testing.T) {
}
}
-func TestAgentStagePersistsReturnedNotes(t *testing.T) {
- st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db"))
- if err != nil {
- t.Fatal(err)
- }
- t.Cleanup(func() {
- if err := st.Close(); err != nil {
- t.Errorf("close store: %v", err)
- }
- })
- ctx := context.Background()
- if _, err := st.EnqueueIssue(ctx, "owner", "repo", 1, "title", "body", "", ""); err != nil {
- t.Fatal(err)
- }
- task, err := st.ClaimNext(ctx)
- if err != nil {
- t.Fatal(err)
- }
- runner := &fakeAgentRunner{result: agentexec.Result{
- Version: agentexec.ProtocolVersion, Status: agentexec.StatusPassed,
- AppendedNotes: []string{"checked with go test"},
- }}
- stage := AgentStage{
- Name: "build", Role: "builder", Mission: func(*TaskContext) string { return "build" },
- }.Stage()
- tc := &TaskContext{
- Task: task, Store: st, Agent: runner, Log: slog.New(slog.DiscardHandler),
- Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
- }
- if err := stage.Run(ctx, tc); err != nil {
- t.Fatal(err)
- }
- if task.Notes != "- checked with go test\n" {
- t.Fatalf("task notes = %q", task.Notes)
- }
-}
-
func TestAgentStageDiscardsUnstampedErrorResult(t *testing.T) {
- task := &store.Task{ID: 1, Attempt: 1, Notes: "existing\n"}
+ task := &Task{ID: 1, Attempt: 1, Notes: "existing\n"}
runner := agentRunnerFunc(func(context.Context, string, agentexec.Request, agentexec.ToolCallReporter) (agentexec.Result, error) {
return agentexec.Result{AppendedNotes: []string{"untrusted"}}, errors.New("worker exited")
})
@@ -211,7 +172,7 @@ func TestFeasibilityDecisionCrossesAsCapturedData(t *testing.T) {
Captures: map[string][]json.RawMessage{"decide": {json.RawMessage(`{"fit":true,"reasons":"aligned"}`)}},
}}
tc := &TaskContext{
- Task: &store.Task{ID: 1}, Agent: runner, Log: slog.New(slog.DiscardHandler),
+ Task: &Task{ID: 1}, Agent: runner, Log: slog.New(slog.DiscardHandler),
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
Repo: config.Repo{Owner: "owner", Name: "repo"},
}
@@ -229,8 +190,8 @@ func TestImplementPlanTreatsChatSourceAsNativeTask(t *testing.T) {
}}
forgeClient := &fakeForge{}
tc := &TaskContext{
- Task: &store.Task{
- ID: 1, IssueNumber: 999_001, Title: "Fix chat task", Source: store.SourceChat,
+ Task: &Task{
+ ID: 1, IssueNumber: 999_001, Title: "Fix chat task", Source: SourceChat,
},
Agent: runner,
Forge: forgeClient,
@@ -261,8 +222,8 @@ func TestFeasibilityChatTaskAvoidsIssueOperations(t *testing.T) {
}}
forgeClient := &fakeForge{}
tc := &TaskContext{
- Task: &store.Task{
- ID: 1, IssueNumber: 999_001, Title: "Feature", Source: store.SourceChat,
+ Task: &Task{
+ ID: 1, IssueNumber: 999_001, Title: "Feature", Source: SourceChat,
},
Agent: runner,
Forge: forgeClient,
@@ -274,7 +235,7 @@ func TestFeasibilityChatTaskAvoidsIssueOperations(t *testing.T) {
if err := Feasibility().Stages[1].Run(context.Background(), tc); err != nil {
t.Fatal(err)
}
- if forgeClient.closed != 0 || tc.Outcome.Status != store.StatusClosedWontDo {
+ if forgeClient.closed != 0 || tc.Outcome.Status != StatusClosedWontDo {
t.Fatalf("close calls/outcome = %d/%q", forgeClient.closed, tc.Outcome.Status)
}
})
@@ -282,8 +243,8 @@ func TestFeasibilityChatTaskAvoidsIssueOperations(t *testing.T) {
t.Run("await approval", func(t *testing.T) {
forgeClient := &fakeForge{}
tc := &TaskContext{
- Task: &store.Task{
- ID: 1, IssueNumber: 999_001, Plan: "PRD", Source: store.SourceChat,
+ Task: &Task{
+ ID: 1, IssueNumber: 999_001, Plan: "PRD", Source: SourceChat,
},
Forge: forgeClient,
Log: slog.New(slog.DiscardHandler),
@@ -293,7 +254,7 @@ func TestFeasibilityChatTaskAvoidsIssueOperations(t *testing.T) {
t.Fatal(err)
}
if len(forgeClient.commented) != 0 || tc.Task.WatchCommentID != 0 ||
- tc.Outcome.Status != store.StatusWaitingHuman {
+ tc.Outcome.Status != StatusWaitingHuman {
t.Fatalf("comments/watch/outcome = %d/%d/%q",
len(forgeClient.commented), tc.Task.WatchCommentID, tc.Outcome.Status)
}
@@ -306,7 +267,7 @@ func TestFeasibilityRejectsNullFitValue(t *testing.T) {
Captures: map[string][]json.RawMessage{"decide": {json.RawMessage(`{"fit":null,"reasons":"not valid"}`)}},
}}
tc := &TaskContext{
- Task: &store.Task{ID: 1}, Agent: runner, Log: slog.New(slog.DiscardHandler),
+ Task: &Task{ID: 1}, Agent: runner, Log: slog.New(slog.DiscardHandler),
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
Repo: config.Repo{Owner: "owner", Name: "repo"},
}
@@ -347,7 +308,7 @@ func TestReviewResultBlocksOnResultWhenRejected(t *testing.T) {
},
}.Stage()
tc := &TaskContext{
- Task: &store.Task{ID: 1, Attempt: 1},
+ Task: &Task{ID: 1, Attempt: 1},
Agent: runner, Log: slog.New(slog.DiscardHandler),
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
}
@@ -383,37 +344,3 @@ func TestReviewResultBlocksOnResultWhenRejected(t *testing.T) {
"Approved output must flow through to human channels.")
}
}
-
-func TestRunLeavesInterruptedTaskForCrashRecovery(t *testing.T) {
- st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db"))
- if err != nil {
- t.Fatal(err)
- }
- t.Cleanup(func() {
- if err := st.Close(); err != nil {
- t.Errorf("close store: %v", err)
- }
- })
- if _, err := st.EnqueueIssue(context.Background(), "owner", "repo", 2, "title", "body", "", ""); err != nil {
- t.Fatal(err)
- }
- task, err := st.ClaimNext(context.Background())
- if err != nil {
- t.Fatal(err)
- }
- ctx, cancel := context.WithCancel(context.Background())
- cancel()
- Run(ctx, Workflow{Name: "test", Stages: []Stage{{
- Name: "agent", Run: func(ctx context.Context, _ *TaskContext) error { return ctx.Err() },
- }}}, &TaskContext{
- Task: task, Store: st, Repo: config.Repo{Owner: "owner", Name: "repo"},
- Log: slog.New(slog.DiscardHandler),
- })
- got, err := st.TaskByIssue(context.Background(), "owner", "repo", 2)
- if err != nil {
- t.Fatal(err)
- }
- if got.Status != store.StatusRunning || got.ParkReason != "" {
- t.Fatalf("interrupted task status=%q park_reason=%q, want running with no park reason", got.Status, got.ParkReason)
- }
-}
diff --git a/internal/domain/workflow/feasibility.go b/internal/domain/workflow/feasibility.go
index a33985a62..4f21409a4 100644
--- a/internal/domain/workflow/feasibility.go
+++ b/internal/domain/workflow/feasibility.go
@@ -9,7 +9,6 @@ import (
"time"
"github.com/samcharles93/archie-core/internal/agentexec"
- "github.com/samcharles93/archie-core/internal/store"
)
// Feasibility is the feature-request workflow: assess the request
@@ -66,7 +65,7 @@ func Feasibility() Workflow {
return err
}
}
- tc.Outcome = Outcome{Status: store.StatusClosedWontDo, Detail: tc.decision.Reasons}
+ tc.Outcome = Outcome{Status: StatusClosedWontDo, Detail: tc.decision.Reasons}
}
return nil
},
@@ -97,7 +96,7 @@ func Feasibility() Workflow {
// the decision surfaces; the forge issue is not a chat log.
{Name: "deliver", Run: func(ctx context.Context, tc *TaskContext) error {
notify(ctx, tc, "feasibility_prd")
- tc.Outcome = Outcome{Status: store.StatusWaitingHuman, Detail: "PRD delivered, awaiting go/no-go"}
+ tc.Outcome = Outcome{Status: StatusWaitingHuman, Detail: "PRD delivered, awaiting go/no-go"}
return nil
}},
},
diff --git a/internal/domain/workflow/implement.go b/internal/domain/workflow/implement.go
index c2a982b3b..4871bce7c 100644
--- a/internal/domain/workflow/implement.go
+++ b/internal/domain/workflow/implement.go
@@ -23,7 +23,7 @@ import (
// be zero: the returned error carried only a status string, so a park
// reason like "go build ./... fails ... (status: failed)" gave no way to
// see the actual compiler error. It stays comfortably under the store's
-// own park-reason cap (see internal/store's Task.ParkReason clip).
+// own park-reason cap (see this package's Task.ParkReason clip).
const (
baselineWarnLogBytes = 2048
baselineMissionBytes = 3000
diff --git a/internal/domain/workflow/implement_test.go b/internal/domain/workflow/implement_test.go
index 6f33a288c..edf3bd4a5 100644
--- a/internal/domain/workflow/implement_test.go
+++ b/internal/domain/workflow/implement_test.go
@@ -15,7 +15,6 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/worktree"
)
@@ -33,7 +32,7 @@ func TestStageBaselineGateAccountsForRepairAgentUsage(t *testing.T) {
Usage: agentexec.Usage{PromptTokens: 100, CompletionTokens: 20, TotalTokens: 120, CachedTokens: 80},
}, nil
})
- task := &store.Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r"}
+ task := &Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r"}
tc := &TaskContext{
Task: task, Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
@@ -56,7 +55,7 @@ func TestStageBaselineGateAccountsForRepairAgentUsage(t *testing.T) {
// prompt-token sum was a cache hit, not read as the full-price total.
func TestImplementPRBodyShowsFreshVsCachedTokens(t *testing.T) {
tc := &TaskContext{
- Task: &store.Task{Iterations: 14, TokensUsed: 405004},
+ Task: &Task{Iterations: 14, TokensUsed: 405004},
BuildSummary: "did the thing",
RunUsage: agentexec.Usage{
PromptTokens: 400021, CompletionTokens: 4983, CachedTokens: 360018,
@@ -81,7 +80,7 @@ func TestImplementPRBodyShowsFreshVsCachedTokens(t *testing.T) {
// billed usage was known and zero.
func TestImplementPRBodyFallsBackWithoutUsageBreakdown(t *testing.T) {
tc := &TaskContext{
- Task: &store.Task{Iterations: 1, TokensUsed: 500},
+ Task: &Task{Iterations: 1, TokensUsed: 500},
BuildSummary: "did the thing",
}
body := implementPRBody(tc)
@@ -152,7 +151,7 @@ func TestStageBaselineGateMissionOmitsPassingPackageOutput(t *testing.T) {
return agentexec.Result{Version: agentexec.ProtocolVersion, Status: agentexec.StatusPassed}, nil
})
tc := &TaskContext{
- Task: &store.Task{ID: 1, Owner: "o", Repo: "r"},
+ Task: &Task{ID: 1, Owner: "o", Repo: "r"},
Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
Agent: runner, Trees: &worktree.Manager{BotUser: "archie", BotEmail: "archie@example.com"},
@@ -190,7 +189,7 @@ func TestStageBaselineGateSetsBaselineFixedWhenItCommits(t *testing.T) {
}
return agentexec.Result{Version: agentexec.ProtocolVersion, Status: agentexec.StatusPassed}, nil
})
- task := &store.Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r"}
+ task := &Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r"}
tc := &TaskContext{
Task: task, Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
@@ -218,7 +217,7 @@ func TestStageBaselineGateWarningIncludesFailureTail(t *testing.T) {
}
var logs bytes.Buffer
tc := &TaskContext{
- Task: &store.Task{ID: 1, Owner: "o", Repo: "r"},
+ Task: &Task{ID: 1, Owner: "o", Repo: "r"},
Repo: config.Repo{Gate: [][]string{{"sh", script}}},
Agent: alwaysFailingRunner,
Dir: dir,
@@ -253,7 +252,7 @@ func TestStageBaselineGateAgentRunErrorSkipsAgentFinish(t *testing.T) {
runner := agentRunnerFunc(func(context.Context, string, agentexec.Request, agentexec.ToolCallReporter) (agentexec.Result, error) {
return agentexec.Result{}, errors.New("simulated transport failure")
})
- task := &store.Task{ID: 1, Owner: "o", Repo: "r"}
+ task := &Task{ID: 1, Owner: "o", Repo: "r"}
tc := &TaskContext{
Task: task,
Repo: config.Repo{Owner: "o", Name: "r", Gate: [][]string{{"sh", script}}},
@@ -356,7 +355,7 @@ func TestStageCommitPushClosesIssueWhenBuildNoChanges(t *testing.T) {
BuildNoChanges: true,
Dir: "/tmp/test",
Branch: "archie/issue-1",
- Task: &store.Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 1},
+ Task: &Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 1},
}
err := stage.Run(context.Background(), tc)
@@ -369,7 +368,7 @@ func TestStageCommitPushClosesIssueWhenBuildNoChanges(t *testing.T) {
} else {
t.Log("CloseIssue called (no changes needed)")
}
- if tc.Outcome.Status != store.StatusMerged {
+ if tc.Outcome.Status != StatusMerged {
t.Errorf("expected Outcome=Merged, got %s", tc.Outcome.Status)
} else {
t.Log("Outcome set to Merged (workflow stops)")
@@ -384,7 +383,7 @@ func TestOpenPRLinksSourceBranchBeforeCreatingPR(t *testing.T) {
f := &fakeForge{}
tc := &TaskContext{
Forge: f,
- Task: &store.Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 42, Title: "Fix bug"},
+ Task: &Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 42, Title: "Fix bug"},
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
Branch: "fix/42-bug",
}
@@ -403,12 +402,12 @@ func TestStageCommitPushDoesNotUseSyntheticIssueForChatNoOp(t *testing.T) {
Forge: f,
BuildSummary: "already fixed",
BuildNoChanges: true,
- Task: &store.Task{
+ Task: &Task{
ID: 1,
Owner: "o",
Repo: "r",
IssueNumber: 999_001,
- Source: store.SourceChat,
+ Source: SourceChat,
},
}
@@ -418,8 +417,8 @@ func TestStageCommitPushDoesNotUseSyntheticIssueForChatNoOp(t *testing.T) {
if f.closed != 0 || len(f.commented) != 0 {
t.Fatalf("chat no-op used synthetic issue: close=%d comments=%d", f.closed, len(f.commented))
}
- if tc.Outcome.Status != store.StatusMerged {
- t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, store.StatusMerged)
+ if tc.Outcome.Status != StatusMerged {
+ t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, StatusMerged)
}
}
@@ -468,7 +467,7 @@ func TestStageCommitPushPushesBaselineFixEvenWithNothingNewToCommit(t *testing.T
BaselineFixed: true,
Dir: "/tmp/test",
Branch: "archie/issue-1",
- Task: &store.Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 1},
+ Task: &Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 1},
}
if err := stage.Run(context.Background(), tc); err != nil {
@@ -492,7 +491,7 @@ func TestStageCommitPushStillErrorsOnEmptyTreeWithoutBaselineFix(t *testing.T) {
Trees: trees,
Dir: "/tmp/test",
Branch: "archie/issue-1",
- Task: &store.Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 1},
+ Task: &Task{ID: 1, Owner: "o", Repo: "r", IssueNumber: 1},
}
if err := stage.Run(context.Background(), tc); err == nil {
@@ -552,7 +551,7 @@ func TestStageBaselineGateParkErrorCarriesGateOutput(t *testing.T) {
}
tc := &TaskContext{
- Task: &store.Task{ID: 1, Owner: "o", Repo: "r"},
+ Task: &Task{ID: 1, Owner: "o", Repo: "r"},
Repo: config.Repo{Gate: [][]string{{"sh", script}}},
Cfg: config.Config{},
Agent: alwaysFailingRunner,
@@ -597,7 +596,7 @@ func TestOpenPRSurvivesALinkBranchFailure(t *testing.T) {
f := &fakeForge{linkErr: tc.linkErr}
taskCtx := &TaskContext{
Forge: f,
- Task: &store.Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 42, Title: "Fix bug"},
+ Task: &Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 42, Title: "Fix bug"},
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
Branch: "fix/42-bug",
}
@@ -606,8 +605,8 @@ func TestOpenPRSurvivesALinkBranchFailure(t *testing.T) {
t.Fatalf("OpenPR: %v\nthe PR is the load-bearing step; cosmetic "+
"linkage must not stop it", err)
}
- if taskCtx.Outcome.Status != store.StatusPROpen {
- t.Errorf("Outcome.Status = %q, want %q", taskCtx.Outcome.Status, store.StatusPROpen)
+ if taskCtx.Outcome.Status != StatusPROpen {
+ t.Errorf("Outcome.Status = %q, want %q", taskCtx.Outcome.Status, StatusPROpen)
}
if taskCtx.Task.PRNumber == 0 {
t.Error("PRNumber is 0: the pull request was never opened")
diff --git a/internal/domain/workflow/plugin_test.go b/internal/domain/workflow/plugin_test.go
index be3f29624..024c0ad9c 100644
--- a/internal/domain/workflow/plugin_test.go
+++ b/internal/domain/workflow/plugin_test.go
@@ -8,7 +8,6 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
- "github.com/samcharles93/archie-core/internal/store"
)
// ── regression: Gap 7 -- plugins discovered but not executed ─────────
@@ -79,7 +78,7 @@ func Run(input string) string {
}}
tc := &TaskContext{
- Task: &store.Task{ID: 1, Attempt: 1, Workflow: "tdd"},
+ Task: &Task{ID: 1, Attempt: 1, Workflow: "tdd"},
Dir: dir,
Agent: runner,
Log: slog.New(slog.DiscardHandler),
diff --git a/internal/domain/workflow/review.go b/internal/domain/workflow/review.go
index 1f386ce38..636631b2f 100644
--- a/internal/domain/workflow/review.go
+++ b/internal/domain/workflow/review.go
@@ -6,8 +6,6 @@ import (
"os"
"path/filepath"
"strings"
-
- "github.com/samcharles93/archie-core/internal/store"
)
// Reviewer runs an adversarial review of a code snapshot in its own
@@ -45,7 +43,7 @@ const reviewDetailBytes = 4000
// StageReview runs the adversarial self-review stage. It is a no-op unless
// Repo.ReviewEnabled is true. A surviving confirmed error-level finding, or
-// a review that failed to run at all, parks the task (store.StatusParked)
+// a review that failed to run at all, parks the task (StatusParked)
// with the findings in Detail and stops the workflow before StageOpenPR;
// a clean pass, or only warn/plausible findings, leaves Outcome unset so
// the workflow proceeds.
@@ -56,7 +54,7 @@ func StageReview() Stage {
}
if tc.Reviewer == nil {
tc.Outcome = Outcome{
- Status: store.StatusParked,
+ Status: StatusParked,
Detail: "adversarial review is enabled (review_enabled) but no reviewer is configured",
}
return nil
@@ -67,7 +65,7 @@ func StageReview() Stage {
return fmt.Errorf("review: %w", err)
}
if !report.Passed() {
- tc.Outcome = Outcome{Status: store.StatusParked, Detail: renderReviewDetail(report)}
+ tc.Outcome = Outcome{Status: StatusParked, Detail: renderReviewDetail(report)}
}
return nil
}}
diff --git a/internal/domain/workflow/review_test.go b/internal/domain/workflow/review_test.go
index 74fefe057..f8d3950b2 100644
--- a/internal/domain/workflow/review_test.go
+++ b/internal/domain/workflow/review_test.go
@@ -9,7 +9,6 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/worktree"
)
@@ -52,7 +51,7 @@ func reviewTaskContext(t *testing.T, enabled bool) (*TaskContext, string) {
runGit(t, dir, "commit", "-m", "feat: add feature.go")
tc := &TaskContext{
- Task: &store.Task{ID: 1, Owner: "acme", Repo: "todo", IssueNumber: 42, Title: "Add feature", Body: "Please add it."},
+ Task: &Task{ID: 1, Owner: "acme", Repo: "todo", IssueNumber: 42, Title: "Add feature", Body: "Please add it."},
Repo: config.Repo{Owner: "acme", Name: "todo", Base: "main", ReviewEnabled: enabled},
Cfg: config.Config{},
Trees: &worktree.Manager{WorkDir: t.TempDir()},
@@ -85,8 +84,8 @@ func TestStageReviewParksWhenEnabledWithNoReviewerWired(t *testing.T) {
if err := StageReview().Run(t.Context(), tc); err != nil {
t.Fatalf("StageReview().Run() error = %v", err)
}
- if tc.Outcome.Status != store.StatusParked {
- t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, store.StatusParked)
+ if tc.Outcome.Status != StatusParked {
+ t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, StatusParked)
}
}
@@ -101,8 +100,8 @@ func TestStageReviewParksFailClosedWhenReviewDidNotRun(t *testing.T) {
if !reviewer.called {
t.Fatal("reviewer was not called")
}
- if tc.Outcome.Status != store.StatusParked {
- t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, store.StatusParked)
+ if tc.Outcome.Status != StatusParked {
+ t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, StatusParked)
}
if got := tc.Outcome.Detail; !containsAll(got, "did not run", "provider outage") {
t.Errorf("Outcome.Detail = %q, want it to say the review did not run and why", got)
@@ -122,8 +121,8 @@ func TestStageReviewParksOnConfirmedErrorFinding(t *testing.T) {
if err := StageReview().Run(t.Context(), tc); err != nil {
t.Fatalf("StageReview().Run() error = %v", err)
}
- if tc.Outcome.Status != store.StatusParked {
- t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, store.StatusParked)
+ if tc.Outcome.Status != StatusParked {
+ t.Errorf("Outcome.Status = %q, want %q", tc.Outcome.Status, StatusParked)
}
if got := tc.Outcome.Detail; !containsAll(got, "feature.go", "nil deref") {
t.Errorf("Outcome.Detail = %q, want the blocking finding rendered", got)
diff --git a/internal/domain/workflow/routing_test.go b/internal/domain/workflow/routing_test.go
index 4b9f22206..f40a30755 100644
--- a/internal/domain/workflow/routing_test.go
+++ b/internal/domain/workflow/routing_test.go
@@ -7,11 +7,10 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/domain/workintake"
- "github.com/samcharles93/archie-core/internal/store"
)
func TestRouteDoesNotSilentlyReplaceAnAdmittedWorkflow(t *testing.T) {
- task := &store.Task{Workflow: "skill-review"}
+ task := &Task{Workflow: "skill-review"}
wf := Route(task, Registry{"implement": Implement()})
if wf.Name != "none" || len(wf.Stages) != 1 || wf.Stages[0].Name != "fail" {
t.Fatalf("Route() = %#v, want explicit failure workflow", wf)
@@ -23,7 +22,7 @@ func TestRouteDoesNotSilentlyReplaceAnAdmittedWorkflow(t *testing.T) {
// chat-spawned task) with no explicit workflow must reach triage, not the
// heaviest workflow, when triage is registered.
func TestRoutePrefersTriageOverImplementWhenNoLabelMatches(t *testing.T) {
- task := &store.Task{}
+ task := &Task{}
wf := Route(task, Registry{"implement": Implement(), "triage": Triage()})
if wf.Name != "triage" {
t.Fatalf("Route() = %q, want %q", wf.Name, "triage")
@@ -34,7 +33,7 @@ func TestRoutePrefersTriageOverImplementWhenNoLabelMatches(t *testing.T) {
// compatibility: a registry without a "triage" entry must behave exactly
// as it did before triage existed.
func TestRouteFallsBackToImplementWhenTriageIsNotRegistered(t *testing.T) {
- task := &store.Task{}
+ task := &Task{}
wf := Route(task, Registry{"implement": Implement()})
if wf.Name != "implement" {
t.Fatalf("Route() = %q, want %q", wf.Name, "implement")
@@ -45,7 +44,7 @@ func TestRouteFallsBackToImplementWhenTriageIsNotRegistered(t *testing.T) {
// preferred, free signal: a labeled task never pays for a triage
// classification call even when triage is registered.
func TestRouteLabelMatchStillWinsOverTriage(t *testing.T) {
- task := &store.Task{Labels: "bug"}
+ task := &Task{Labels: "bug"}
wf := Route(task, Registry{"tdd": TDD(), "triage": Triage(), "implement": Implement()})
if wf.Name != "tdd" {
t.Fatalf("Route() = %q, want %q", wf.Name, "tdd")
@@ -68,7 +67,7 @@ func TestLoadKindWorkflowsYAMLOverridesDefaultBinding(t *testing.T) {
SetKindWorkflows(kw)
t.Cleanup(func() { SetKindWorkflows(nil) })
- task := &store.Task{Labels: "bug"}
+ task := &Task{Labels: "bug"}
wf := Route(task, Registry{"tdd": TDD(), "feasibility": Feasibility()})
if wf.Name != "feasibility" {
t.Fatalf("Route() = %q, want %q (YAML override not applied)", wf.Name, "feasibility")
@@ -82,7 +81,7 @@ func TestSetKindWorkflowsNilRestoresDefaults(t *testing.T) {
SetKindWorkflows(KindWorkflows{workintake.KindBug: "feasibility"})
SetKindWorkflows(nil)
- task := &store.Task{Labels: "bug"}
+ task := &Task{Labels: "bug"}
wf := Route(task, Registry{"tdd": TDD(), "feasibility": Feasibility()})
if wf.Name != "tdd" {
t.Fatalf("Route() = %q, want %q (default binding not restored)", wf.Name, "tdd")
@@ -134,7 +133,7 @@ func TestRouteWithArbitraryLabelDispatch(t *testing.T) {
SetLabelWorkflows(LabelWorkflows{"security": "security-review"})
t.Cleanup(func() { SetLabelWorkflows(nil) })
- task := &store.Task{Labels: "security"}
+ task := &Task{Labels: "security"}
wf := Route(task, Registry{
"implement": Implement(),
"security-review": Workflow{Name: "security-review", Stages: []Stage{{Name: "review", Run: func(_ context.Context, _ *TaskContext) error { return nil }}}},
@@ -219,7 +218,7 @@ func TestSetLabelWorkflowsNilRestoresDefaults(t *testing.T) {
SetLabelWorkflows(LabelWorkflows{"security": "security-review"})
SetLabelWorkflows(nil)
- task := &store.Task{Labels: "security"}
+ task := &Task{Labels: "security"}
wf := Route(task, Registry{"implement": Implement(), "security-review": Workflow{Name: "security-review", Stages: []Stage{{Name: "review", Run: func(_ context.Context, _ *TaskContext) error { return nil }}}}})
if wf.Name != "implement" {
t.Fatalf("Route() = %q, want %q (label map not restored to empty)", wf.Name, "implement")
@@ -235,7 +234,7 @@ func TestRoutePrefersArbitraryLabelOverKind(t *testing.T) {
SetKindWorkflows(nil) // ensure defaults
t.Cleanup(func() { SetKindWorkflows(nil) })
- task := &store.Task{Labels: "bug,security"}
+ task := &Task{Labels: "bug,security"}
wf := Route(task, Registry{
"tdd": TDD(),
"implement": Implement(),
@@ -271,7 +270,7 @@ func TestLoadPlaybookDirsMergesCleanBindings(t *testing.T) {
t.Fatalf("label binding not merged: %#v", lw)
}
- task := &store.Task{Labels: "security"}
+ task := &Task{Labels: "security"}
wf := Route(task, Registry{
"implement": Implement(),
"security-review": Workflow{Name: "security-review", Stages: []Stage{{Name: "review", Run: func(_ context.Context, _ *TaskContext) error { return nil }}}},
diff --git a/internal/domain/workflow/steps.go b/internal/domain/workflow/steps.go
index 363e019f0..b5eea498d 100644
--- a/internal/domain/workflow/steps.go
+++ b/internal/domain/workflow/steps.go
@@ -10,7 +10,6 @@ import (
"github.com/samcharles93/archie-core/internal/gate"
"github.com/samcharles93/archie-core/internal/gate/gateeval"
- "github.com/samcharles93/archie-core/internal/store"
)
// Shared step library. Every workflow composes these; workflow-specific
@@ -76,13 +75,13 @@ func StageCommitPush(message func(*TaskContext) string) Stage {
func closeNoChangesIssue(ctx context.Context, tc *TaskContext) error {
if !tc.Task.IsForgeBacked() {
- tc.Outcome = Outcome{Status: store.StatusMerged, Detail: "completed -- no changes required"}
+ tc.Outcome = Outcome{Status: StatusMerged, Detail: "completed -- no changes required"}
return nil
}
if err := tc.Forge.CloseIssue(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, ""); err != nil {
return err
}
- tc.Outcome = Outcome{Status: store.StatusMerged, Detail: "completed -- no changes required"}
+ tc.Outcome = Outcome{Status: StatusMerged, Detail: "completed -- no changes required"}
return nil
}
@@ -99,7 +98,7 @@ func StageDiffCap() Stage {
}
if lines > tc.Cfg.DiffCapLines {
tc.Outcome = Outcome{
- Status: store.StatusParked,
+ Status: StatusParked,
Detail: fmt.Sprintf("diff is %d changed lines (cap %d) -- split the issue or approve manually", lines, tc.Cfg.DiffCapLines),
}
}
@@ -208,7 +207,7 @@ func OpenPR(ctx context.Context, tc *TaskContext, body string) error {
return err
}
t.PRNumber = num
- tc.Outcome = Outcome{Status: store.StatusPROpen, Detail: fmt.Sprintf("PR #%d", num)}
+ tc.Outcome = Outcome{Status: StatusPROpen, Detail: fmt.Sprintf("PR #%d", num)}
return nil
}
@@ -219,7 +218,7 @@ func StageOpenPR(body func(*TaskContext) string) Stage {
}}
}
-func taskPromptBlock(task *store.Task) string {
+func taskPromptBlock(task *Task) string {
if task.IsForgeBacked() {
return fmt.Sprintf("\n# %s\n\n%s\n",
task.IssueNumber, task.Title, task.Body)
@@ -227,14 +226,14 @@ func taskPromptBlock(task *store.Task) string {
return fmt.Sprintf("\n# %s\n\n%s\n", task.Title, task.Body)
}
-func taskKind(task *store.Task) string {
+func taskKind(task *Task) string {
if task.IsForgeBacked() {
return "GitHub issue"
}
return "chat-originated task"
}
-func commitIssueReference(verb string, task *store.Task) string {
+func commitIssueReference(verb string, task *Task) string {
if !task.IsForgeBacked() {
return ""
}
diff --git a/internal/domain/workflow/steps_test.go b/internal/domain/workflow/steps_test.go
index 6ad0b5cb5..1d5a51745 100644
--- a/internal/domain/workflow/steps_test.go
+++ b/internal/domain/workflow/steps_test.go
@@ -10,7 +10,6 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/worktree"
)
@@ -48,7 +47,7 @@ func gitRepoWithOriginRef(t *testing.T, base string) string {
func newYaegiGateTaskContext(t *testing.T, dir string) *TaskContext {
t.Helper()
return &TaskContext{
- Task: &store.Task{ID: 1, Owner: "acme", Repo: "todo", IssueNumber: 42},
+ Task: &Task{ID: 1, Owner: "acme", Repo: "todo", IssueNumber: 42},
Repo: config.Repo{Owner: "acme", Name: "todo", Base: "main"},
Trees: &worktree.Manager{WorkDir: t.TempDir()},
Dir: dir,
diff --git a/internal/domain/workflow/store_integration_test.go b/internal/domain/workflow/store_integration_test.go
new file mode 100644
index 000000000..3928e3693
--- /dev/null
+++ b/internal/domain/workflow/store_integration_test.go
@@ -0,0 +1,107 @@
+package workflow_test
+
+import (
+ "context"
+ "log/slog"
+ "path/filepath"
+ "testing"
+
+ "github.com/samcharles93/archie-core/internal/agentexec"
+ "github.com/samcharles93/archie-core/internal/config"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
+ "github.com/samcharles93/archie-core/internal/store"
+)
+
+// storeIntegrationRunner is a minimal agentexec.Runner stub, duplicated
+// here (rather than reused from the in-package tests) because this file
+// lives in the external workflow_test package: it needs the real
+// *store.Store as a workflow.Store, and the package under test now owns
+// workflow.Task/Status/Source, which would otherwise cycle back through
+// internal/store's dependency on internal/domain/workflow.
+type storeIntegrationRunner struct {
+ result agentexec.Result
+}
+
+func (r *storeIntegrationRunner) Run(
+ _ context.Context, _ string, req agentexec.Request, _ agentexec.ToolCallReporter,
+) (agentexec.Result, error) {
+ res := r.result
+ if res.Version == 0 {
+ res.Version = agentexec.ProtocolVersion
+ }
+ res.TaskID = req.TaskID
+ res.Attempt = req.Attempt
+ res.Stage = req.Stage
+ return res, nil
+}
+
+func TestAgentStagePersistsReturnedNotes(t *testing.T) {
+ st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() {
+ if err := st.Close(); err != nil {
+ t.Errorf("close store: %v", err)
+ }
+ })
+ ctx := context.Background()
+ if _, err := st.EnqueueIssue(ctx, "owner", "repo", 1, "title", "body", "", ""); err != nil {
+ t.Fatal(err)
+ }
+ task, err := st.ClaimNext(ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ runner := &storeIntegrationRunner{result: agentexec.Result{
+ Version: agentexec.ProtocolVersion, Status: agentexec.StatusPassed,
+ AppendedNotes: []string{"checked with go test"},
+ }}
+ stage := workflow.AgentStage{
+ Name: "build", Role: "builder", Mission: func(*workflow.TaskContext) string { return "build" },
+ }.Stage()
+ tc := &workflow.TaskContext{
+ Task: task, Store: st, Agent: runner, Log: slog.New(slog.DiscardHandler),
+ Cfg: config.Config{Models: map[string]string{"builder": "provider/model"}},
+ }
+ if err := stage.Run(ctx, tc); err != nil {
+ t.Fatal(err)
+ }
+ if task.Notes != "- checked with go test\n" {
+ t.Fatalf("task notes = %q", task.Notes)
+ }
+}
+
+func TestRunLeavesInterruptedTaskForCrashRecovery(t *testing.T) {
+ st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() {
+ if err := st.Close(); err != nil {
+ t.Errorf("close store: %v", err)
+ }
+ })
+ if _, err := st.EnqueueIssue(context.Background(), "owner", "repo", 2, "title", "body", "", ""); err != nil {
+ t.Fatal(err)
+ }
+ task, err := st.ClaimNext(context.Background())
+ if err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+ workflow.Run(ctx, workflow.Workflow{Name: "test", Stages: []workflow.Stage{{
+ Name: "agent", Run: func(ctx context.Context, _ *workflow.TaskContext) error { return ctx.Err() },
+ }}}, &workflow.TaskContext{
+ Task: task, Store: st, Repo: config.Repo{Owner: "owner", Name: "repo"},
+ Log: slog.New(slog.DiscardHandler),
+ })
+ got, err := st.TaskByIssue(context.Background(), "owner", "repo", 2)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got.Status != workflow.StatusRunning || got.ParkReason != "" {
+ t.Fatalf("interrupted task status=%q park_reason=%q, want running with no park reason", got.Status, got.ParkReason)
+ }
+}
diff --git a/internal/domain/workflow/task.go b/internal/domain/workflow/task.go
new file mode 100644
index 000000000..5aa52c616
--- /dev/null
+++ b/internal/domain/workflow/task.go
@@ -0,0 +1,103 @@
+package workflow
+
+import (
+ "context"
+ "time"
+
+ "github.com/samcharles93/archie-core/internal/events"
+ "github.com/samcharles93/archie-core/internal/taskstate"
+)
+
+// Task lifecycle statuses. Workflows move tasks between them; the
+// daemon owns queued→running claims and crash recovery.
+const (
+ // Defined in internal/taskstate so the dashboard, chat and the store
+ // share one vocabulary. These names are kept as the workflow domain's
+ // public spelling; the values live in one place.
+ StatusQueued = taskstate.Queued
+ StatusRunning = taskstate.Running
+ StatusWaitingHuman = taskstate.WaitingHuman
+ StatusPROpen = taskstate.PROpen
+ StatusMerged = taskstate.Merged
+ StatusParked = taskstate.Parked
+ StatusDead = taskstate.Dead
+ StatusRejected = taskstate.Rejected
+ StatusClosedWontDo = taskstate.Declined
+)
+
+// Task is the task-execution record the workflow domain operates on.
+// internal/store persists this type (persistence -> domain).
+type Task struct {
+ ID int64 `json:"id"`
+ Owner string `json:"owner"`
+ Repo string `json:"repo"`
+ IssueNumber int `json:"issue_number"`
+ Title string `json:"title"`
+ Body string `json:"body"`
+ Labels string `json:"labels"` // comma-separated, as seen at enqueue time
+ Status string `json:"status"`
+ Workflow string `json:"workflow"`
+ Stage string `json:"stage"`
+ Branch string `json:"branch"`
+ Plan string `json:"plan"`
+ Notes string `json:"notes"`
+ PRNumber int `json:"pr_number"`
+ TokensUsed int `json:"tokens_used"`
+ Iterations int `json:"iterations"`
+ Attempt int `json:"attempt"`
+ ParkReason string `json:"park_reason"`
+ // RetryCount tracks how many times a parked task has been retried
+ // (parking-to-queued transitions). When it reaches the configured
+ // max_retries the daemon moves the task to StatusDead.
+ RetryCount int `json:"retry_count"`
+ // WatchCommentID: replies to the issue after this comment are the
+ // human input a waiting_human task is blocked on.
+ WatchCommentID int64 `json:"watch_comment_id"`
+ // Source is "forge" (default; a real forge issue backs this task) or
+ // "chat" (created via /spawn with no forge issue). Workflow stages
+ // and daemon reconciliation must skip forge-only operations (issue
+ // labels, comments, replies) for chat-sourced tasks; IssueNumber on
+ // a chat task is a synthetic value, not a real forge issue.
+ Source string `json:"source"`
+ // Identity is the archie identity that owns this task (chat-spawned
+ // tasks only; empty for forge-sourced tasks and single-identity
+ // deployments). Used to scope /approve and /cancel authorization so
+ // one identity cannot control another's chat-spawned tasks.
+ Identity string `json:"identity"`
+ // BindingID and BindingVersion are stamped when a task was created
+ // from a playbook binding dispatch (t2db.4 Phase B). They record
+ // provenance: which binding fired this task and at what version, so
+ // later edits to the binding cannot silently rewrite history.
+ BindingID int64 `json:"binding_id"`
+ BindingVersion int `json:"binding_version"`
+ // CreatedAt and UpdatedAt are the SQLite row timestamps, exposed so
+ // callers can show a task's age and last activity. They are written by
+ // column defaults and the UPDATE statements, never by the caller.
+ CreatedAt time.Time `json:"created_at"`
+ UpdatedAt time.Time `json:"updated_at"`
+}
+
+// SourceForge and SourceChat are the valid values for Task.Source.
+// Legacy rows and forge-polled tasks have Source == SourceForge (the
+// zero value defaults there via the SQLite column default).
+const (
+ SourceForge = "forge"
+ SourceChat = "chat"
+)
+
+// IsForgeBacked reports whether t corresponds to a real forge issue.
+// Chat-spawned tasks (Source == SourceChat) have a synthetic
+// IssueNumber and must not be used in forge label/comment/reply calls.
+func (t Task) IsForgeBacked() bool {
+ return t.Source != SourceChat
+}
+
+// Store is the narrow, consumer-owned subset of the State Store contract
+// that workflow stages call mid-run. *store.Store and staterpc.Client
+// satisfy it; this is the interface archie-agent uses via the storerpc
+// proxy. It supersedes store.WorkflowStore.
+type Store interface {
+ Update(ctx context.Context, t *Task) error
+ Transition(ctx context.Context, taskID int64, from, to, detail string) error
+ InsertEvent(ctx context.Context, e events.Event) (int64, error)
+}
diff --git a/internal/domain/workflow/triage.go b/internal/domain/workflow/triage.go
index ee31130f4..3a95d4f40 100644
--- a/internal/domain/workflow/triage.go
+++ b/internal/domain/workflow/triage.go
@@ -6,7 +6,6 @@ import (
"fmt"
"github.com/samcharles93/archie-core/internal/agentexec"
- "github.com/samcharles93/archie-core/internal/store"
)
// triageWorkflowNames is the set of workflows triage may hand a task to.
@@ -83,7 +82,7 @@ func Triage() Workflow {
return err
}
}
- tc.Outcome = Outcome{Status: store.StatusMerged, Detail: "triaged: no code change needed -- " + captured.Reasons}
+ tc.Outcome = Outcome{Status: StatusMerged, Detail: "triaged: no code change needed -- " + captured.Reasons}
return nil
}
target := captured.Workflow
@@ -92,7 +91,7 @@ func Triage() Workflow {
}
tc.Task.Workflow = target
tc.Outcome = Outcome{
- Status: store.StatusQueued,
+ Status: StatusQueued,
Detail: fmt.Sprintf("triaged to %s: %s", target, captured.Reasons),
}
return nil
diff --git a/internal/domain/workflow/triage_test.go b/internal/domain/workflow/triage_test.go
index 8e5b3c5db..ab014310d 100644
--- a/internal/domain/workflow/triage_test.go
+++ b/internal/domain/workflow/triage_test.go
@@ -8,7 +8,6 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
- "github.com/samcharles93/archie-core/internal/store"
)
func triageDecision(t *testing.T, needsCodeChange bool, workflow, reasons string) []json.RawMessage {
@@ -50,7 +49,7 @@ func TestTriageClosesWithoutCodeChange(t *testing.T) {
}, nil
})
tc := &TaskContext{
- Task: &store.Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
+ Task: &Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
Repo: config.Repo{Owner: "o", Name: "r"},
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
Agent: runner,
@@ -64,8 +63,8 @@ func TestTriageClosesWithoutCodeChange(t *testing.T) {
if f.closed != 1 {
t.Fatalf("CloseIssue calls = %d, want 1", f.closed)
}
- if tc.Outcome.Status != store.StatusMerged {
- t.Fatalf("Outcome.Status = %q, want %q", tc.Outcome.Status, store.StatusMerged)
+ if tc.Outcome.Status != StatusMerged {
+ t.Fatalf("Outcome.Status = %q, want %q", tc.Outcome.Status, StatusMerged)
}
if tc.Task.Workflow != "" {
t.Fatalf("Task.Workflow = %q, want unset (no requeue on the close path)", tc.Task.Workflow)
@@ -89,7 +88,7 @@ func TestTriageClosesChatTaskWithoutForgeCall(t *testing.T) {
}, nil
})
tc := &TaskContext{
- Task: &store.Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1_000_000_000_000_001, Source: store.SourceChat},
+ Task: &Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1_000_000_000_000_001, Source: SourceChat},
Repo: config.Repo{Owner: "o", Name: "r"},
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
Agent: runner,
@@ -103,8 +102,8 @@ func TestTriageClosesChatTaskWithoutForgeCall(t *testing.T) {
if f.closed != 0 {
t.Fatalf("CloseIssue calls = %d, want 0 for a chat-spawned (non-forge-backed) task", f.closed)
}
- if tc.Outcome.Status != store.StatusMerged {
- t.Fatalf("Outcome.Status = %q, want %q", tc.Outcome.Status, store.StatusMerged)
+ if tc.Outcome.Status != StatusMerged {
+ t.Fatalf("Outcome.Status = %q, want %q", tc.Outcome.Status, StatusMerged)
}
}
@@ -123,7 +122,7 @@ func TestTriageRequeuesUnderChosenWorkflow(t *testing.T) {
}, nil
})
tc := &TaskContext{
- Task: &store.Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
+ Task: &Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
Repo: config.Repo{Owner: "o", Name: "r"},
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
Agent: runner,
@@ -136,8 +135,8 @@ func TestTriageRequeuesUnderChosenWorkflow(t *testing.T) {
if tc.Task.Workflow != "tdd" {
t.Fatalf("Task.Workflow = %q, want %q", tc.Task.Workflow, "tdd")
}
- if tc.Outcome.Status != store.StatusQueued {
- t.Fatalf("Outcome.Status = %q, want %q", tc.Outcome.Status, store.StatusQueued)
+ if tc.Outcome.Status != StatusQueued {
+ t.Fatalf("Outcome.Status = %q, want %q", tc.Outcome.Status, StatusQueued)
}
}
@@ -156,7 +155,7 @@ func TestTriageDefaultsToImplementForUnrecognizedWorkflow(t *testing.T) {
}, nil
})
tc := &TaskContext{
- Task: &store.Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
+ Task: &Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
Repo: config.Repo{Owner: "o", Name: "r"},
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
Agent: runner,
@@ -178,7 +177,7 @@ func TestTriageRejectsMissingDecideCall(t *testing.T) {
return agentexec.Result{Version: agentexec.ProtocolVersion, TaskID: req.TaskID, Attempt: req.Attempt, Stage: req.Stage, Status: agentexec.StatusPassed}, nil
})
tc := &TaskContext{
- Task: &store.Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
+ Task: &Task{ID: 1, Attempt: 1, Owner: "o", Repo: "r", IssueNumber: 1},
Repo: config.Repo{Owner: "o", Name: "r"},
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
Agent: runner,
diff --git a/internal/domain/workflow/workflow.go b/internal/domain/workflow/workflow.go
index 36af15af9..2335a0f13 100644
--- a/internal/domain/workflow/workflow.go
+++ b/internal/domain/workflow/workflow.go
@@ -20,7 +20,6 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/skill"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/tools"
)
@@ -55,11 +54,11 @@ type Trees interface {
// forward by mutating Task (persisted after every stage) and the
// scratch fields below.
type TaskContext struct {
- Task *store.Task
+ Task *Task
Repo config.Repo
Cfg config.Config
Forge Forger
- Store store.WorkflowStore
+ Store Store
Trees Trees
Agent agentexec.Runner
// Reviewer runs the adversarial self-review stage (StageReview). Nil
@@ -187,7 +186,7 @@ func (tc *TaskContext) toolCallReporter(stage string) agentexec.ToolCallReporter
// Outcome is a stage's terminal decision for the whole workflow. Stages
// that don't end the workflow leave it zero.
type Outcome struct {
- Status string // store.Status* value; empty = continue to next stage
+ Status string // Status* value; empty = continue to next stage
Detail string // park reason / close rationale / PR body context
}
@@ -251,7 +250,7 @@ func DefinitionsWithOrigins(reg Registry, origins map[string]string) []Definitio
// Route picks the workflow for a task. A pre-assigned workflow wins
// (the waiting_human → approved handoff requeues under "implement");
// otherwise labels decide, then the default.
-func Route(t *store.Task, reg Registry) Workflow {
+func Route(t *Task, reg Registry) Workflow {
if t.Workflow != "" {
if wf, ok := reg[t.Workflow]; ok {
return wf
@@ -338,12 +337,12 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
func finish(ctx context.Context, tc *TaskContext, log *slog.Logger) {
t := tc.Task
- if tc.Outcome.Status == store.StatusParked {
+ if tc.Outcome.Status == StatusParked {
park(ctx, tc, tc.Outcome.Detail)
return
}
_ = tc.Store.Update(ctx, t)
- _ = tc.Store.Transition(ctx, t.ID, store.StatusRunning, tc.Outcome.Status, tc.Outcome.Detail)
+ _ = tc.Store.Transition(ctx, t.ID, StatusRunning, tc.Outcome.Status, tc.Outcome.Detail)
tc.Emit(events.KindOutcome, t.Stage, tc.Outcome.Detail, map[string]any{"status": tc.Outcome.Status})
log.Info("workflow finished", "status", tc.Outcome.Status)
}
@@ -352,7 +351,7 @@ func park(ctx context.Context, tc *TaskContext, reason string) {
t := tc.Task
t.ParkReason = reason
_ = tc.Store.Update(ctx, t)
- _ = tc.Store.Transition(ctx, t.ID, store.StatusRunning, store.StatusParked, reason)
+ _ = tc.Store.Transition(ctx, t.ID, StatusRunning, StatusParked, reason)
tc.Emit(events.KindParked, t.Stage, reason, nil)
}
diff --git a/internal/gateway/tasks.go b/internal/gateway/tasks.go
index 8cb3f5f36..8be724c23 100644
--- a/internal/gateway/tasks.go
+++ b/internal/gateway/tasks.go
@@ -40,10 +40,10 @@ type taskProfile struct {
}
// chatTaskWriter is the write surface StoreTaskCreator needs. It
-// returns the created task's real database ID, not a *store.Task --
-// gateway deliberately has no dependency on internal/store; the daemon
-// supplies an adapter closure over the store.TaskStore method of the
-// same name.
+// returns the created task's real database ID, not a *workflow.Task --
+// gateway deliberately has no dependency on internal/store or
+// internal/domain/workflow; the daemon supplies an adapter closure over
+// the store.TaskStore method of the same name.
type chatTaskWriter interface {
EnqueueChatTask(ctx context.Context, owner, repo, title, body, workflow, identity string) (taskID int64, err error)
}
diff --git a/internal/infrastructure/agenttransport/nats/transport.go b/internal/infrastructure/agenttransport/nats/transport.go
index 21154b706..259cc46d0 100644
--- a/internal/infrastructure/agenttransport/nats/transport.go
+++ b/internal/infrastructure/agenttransport/nats/transport.go
@@ -16,7 +16,6 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/forgerpc"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/storerpc"
"github.com/samcharles93/archie-core/internal/taskrun"
"github.com/samcharles93/archie-core/internal/worktreerpc"
@@ -102,7 +101,7 @@ func (t *Transport) Forger(identity string, timeout time.Duration) workflow.Forg
}
// Store constructs the workflow store RPC client.
-func (t *Transport) Store(timeout time.Duration) store.WorkflowStore {
+func (t *Transport) Store(timeout time.Duration) workflow.Store {
return &storerpc.Client{Conn: t.conn, Timeout: timeout}
}
diff --git a/internal/infrastructure/agenttransport/nats/transport_test.go b/internal/infrastructure/agenttransport/nats/transport_test.go
index 69ffa25b2..06ad53c3d 100644
--- a/internal/infrastructure/agenttransport/nats/transport_test.go
+++ b/internal/infrastructure/agenttransport/nats/transport_test.go
@@ -15,8 +15,8 @@ import (
natstest "github.com/nats-io/nats-server/v2/test"
natsio "github.com/nats-io/nats.go"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/forgerpc"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/storerpc"
"github.com/samcharles93/archie-core/internal/taskrun"
"github.com/samcharles93/archie-core/internal/worktreerpc"
@@ -110,7 +110,7 @@ func TestSubscribeTasksServesOnlyBootTaskSubject(t *testing.T) {
}
t.Cleanup(func() { _ = subscription.Close() })
- payload, err := json.Marshal(taskrun.Request{Task: &store.Task{ID: 42}, WorktreeGrant: "grant"})
+ payload, err := json.Marshal(taskrun.Request{Task: &workflow.Task{ID: 42}, WorktreeGrant: "grant"})
if err != nil {
t.Fatal(err)
}
@@ -212,7 +212,7 @@ func TestHandleTaskRejectsSubjectCorrelationErrors(t *testing.T) {
t.Fatal(err)
}
- payload, err := json.Marshal(taskrun.Request{Task: &store.Task{ID: test.requestID}, WorktreeGrant: "grant"})
+ payload, err := json.Marshal(taskrun.Request{Task: &workflow.Task{ID: test.requestID}, WorktreeGrant: "grant"})
if err != nil {
t.Fatal(err)
}
diff --git a/internal/store/bindings_test.go b/internal/store/bindings_test.go
index 3ded8df38..ddbf10200 100644
--- a/internal/store/bindings_test.go
+++ b/internal/store/bindings_test.go
@@ -1,7 +1,6 @@
package store
import (
- "context"
"database/sql"
"errors"
"path/filepath"
@@ -509,27 +508,3 @@ func TestListUndispatchedCapturesEmptySourcesReturnsNil(t *testing.T) {
t.Fatalf("ListUndispatchedCaptures(nil sources) = %+v, want nil", got)
}
}
-
-// TestRecordDispatchViaExplicitTx confirms RecordDispatch accepts an
-// external *sql.Tx (its primary contract: caller-owned transaction).
-// Without this signature the dispatch ledger and the tasks row created
-// from a binding could not commit atomically.
-func TestRecordDispatchViaExplicitTx(t *testing.T) {
- s := openTest(t)
- id, err := s.InsertBinding(t.Context(), testBinding("sentry"))
- if err != nil {
- t.Fatalf("InsertBinding: %v", err)
- }
-
- ctx := context.Background()
- tx, err := s.db.BeginTx(ctx, nil)
- if err != nil {
- t.Fatalf("BeginTx: %v", err)
- }
- if err := s.RecordDispatch(ctx, tx, id, 1, 1, 1); err != nil {
- t.Fatalf("RecordDispatch via *sql.Tx: %v", err)
- }
- if err := tx.Commit(); err != nil {
- t.Fatalf("Commit: %v", err)
- }
-}
diff --git a/internal/store/events.go b/internal/store/events.go
index 54cfbdf33..46a39214e 100644
--- a/internal/store/events.go
+++ b/internal/store/events.go
@@ -8,6 +8,7 @@ import (
"fmt"
"time"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
)
@@ -98,7 +99,7 @@ func (s *Store) TaskEvents(ctx context.Context, taskID int64) ([]events.Event, e
}
// Tasks returns all tasks, newest first (dashboard listing).
-func (s *Store) Tasks(ctx context.Context, limit int) (tasks []Task, retErr error) {
+func (s *Store) Tasks(ctx context.Context, limit int) (tasks []workflow.Task, retErr error) {
rows, err := s.db.QueryContext(ctx, `
SELECT id, owner, repo, issue_number, title, status, workflow, stage,
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
@@ -111,7 +112,7 @@ func (s *Store) Tasks(ctx context.Context, limit int) (tasks []Task, retErr erro
retErr = errors.Join(retErr, rows.Close())
}()
for rows.Next() {
- var t Task
+ var t workflow.Task
// Plan and Source are read by the dashboard: Plan gates the
// "Decision required" panel on a waiting_human task, and Source
// decides whether an issue link is rendered at all -- a chat task's
diff --git a/internal/store/interface.go b/internal/store/interface.go
index 1c904e914..97c2c647c 100644
--- a/internal/store/interface.go
+++ b/internal/store/interface.go
@@ -10,6 +10,7 @@ import (
"github.com/samcharles93/archie-core/internal/domain/binding"
"github.com/samcharles93/archie-core/internal/domain/mapping"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
)
@@ -29,11 +30,11 @@ type TaskStore interface {
// poll, chat spawn, drain loop) do not acquire a binding-specific shape.
type TaskLifecycle interface {
EnqueueIssue(ctx context.Context, owner, repo string, number int, title, body, labels, identity string) (bool, error)
- EnqueueChatTask(ctx context.Context, owner, repo, title, body, workflow, identity string) (*Task, error)
- ClaimNext(ctx context.Context) (*Task, error)
- ClaimByIssue(ctx context.Context, owner, repo string, number int) (*Task, error)
+ EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*workflow.Task, error)
+ ClaimNext(ctx context.Context) (*workflow.Task, error)
+ ClaimByIssue(ctx context.Context, owner, repo string, number int) (*workflow.Task, error)
Transition(ctx context.Context, taskID int64, from, to, detail string) error
- Update(ctx context.Context, t *Task) error
+ Update(ctx context.Context, t *workflow.Task) error
Requeue(ctx context.Context, taskID int64, fromStatus, workflow string) error
RecoverStale(ctx context.Context) (int64, error)
}
@@ -53,11 +54,11 @@ type TaskRetryer interface {
// TaskQueries groups read-only task accessors.
type TaskQueries interface {
- TaskByIssue(ctx context.Context, owner, repo string, number int) (*Task, error)
- TaskByID(ctx context.Context, taskID int64) (*Task, error)
- OpenPRs(ctx context.Context) ([]Task, error)
+ TaskByIssue(ctx context.Context, owner, repo string, number int) (*workflow.Task, error)
+ TaskByID(ctx context.Context, taskID int64) (*workflow.Task, error)
+ OpenPRs(ctx context.Context) ([]workflow.Task, error)
ClearTerminalTasks(ctx context.Context) (int64, error)
- Tasks(ctx context.Context, limit int) ([]Task, error)
+ Tasks(ctx context.Context, limit int) ([]workflow.Task, error)
StatusCounts(ctx context.Context) (map[string]int, error)
IncrementRetryCount(ctx context.Context, taskID int64) error
}
@@ -73,15 +74,6 @@ type TaskEvents interface {
Close() error
}
-// WorkflowStore is the narrow subset of TaskStore that workflow stages call
-// mid-run. *Store and storerpc.Client satisfy it.
-// This is the interface archie-agent uses via storerpc NATS proxy.
-type WorkflowStore interface {
- Update(ctx context.Context, t *Task) error
- Transition(ctx context.Context, taskID int64, from, to, detail string) error
- InsertEvent(ctx context.Context, e events.Event) (int64, error)
-}
-
// CaptureStore persists unbound inbound webhook captures -- events with no
// workflow binding and no task association. Deliberately separate from
// TaskStore: a consumer that only needs capture (the intake HTTP handler)
@@ -144,14 +136,14 @@ type BindingDispatcher interface {
// keeps the lifecycle surface narrow (8 methods, the interfacebloat limit)
// and keeps the binding-specific shape on the binding interfaces.
type BindingTaskCreator interface {
- EnqueueBindingTask(ctx context.Context, owner, repo, title, body, workflow, identity string, bindingID int64, bindingVersion int) (*Task, error)
+ EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity string, bindingID int64, bindingVersion int) (*workflow.Task, error)
}
// Compile-time check: *Store satisfies TaskStore.
var _ TaskStore = (*Store)(nil)
-// Compile-time check: *Store satisfies WorkflowStore.
-var _ WorkflowStore = (*Store)(nil)
+// Compile-time check: *Store satisfies workflow.Store.
+var _ workflow.Store = (*Store)(nil)
// Compile-time check: *Store satisfies CaptureStore.
var _ CaptureStore = (*Store)(nil)
diff --git a/internal/store/queries_test.go b/internal/store/queries_test.go
index e926f907b..13bfa97cc 100644
--- a/internal/store/queries_test.go
+++ b/internal/store/queries_test.go
@@ -6,6 +6,7 @@ import (
"testing"
"time"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
)
@@ -45,20 +46,20 @@ func TestRequeueFromWaitingHuman(t *testing.T) {
t.Fatalf("claim = (%v, %v)", task, err)
}
- if err := s.Transition(ctx, task.ID, StatusRunning, StatusWaitingHuman, "needs input"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusWaitingHuman, "needs input"); err != nil {
t.Fatal(err)
}
waiting, err := s.TaskByID(ctx, task.ID)
- if err != nil || waiting == nil || waiting.Status != StatusWaitingHuman {
+ if err != nil || waiting == nil || waiting.Status != workflow.StatusWaitingHuman {
t.Fatalf("after transition = (%+v, %v), want waiting_human", waiting, err)
}
// Requeue with a workflow forces it (waiting_human -> approved -> implement).
- if err := s.Requeue(ctx, task.ID, StatusWaitingHuman, "implement"); err != nil {
+ if err := s.Requeue(ctx, task.ID, workflow.StatusWaitingHuman, "implement"); err != nil {
t.Fatal(err)
}
requeued, err := s.TaskByIssue(ctx, "acme", "widget", 1)
- if err != nil || requeued == nil || requeued.Status != StatusQueued || requeued.Workflow != "implement" {
+ if err != nil || requeued == nil || requeued.Status != workflow.StatusQueued || requeued.Workflow != "implement" {
t.Fatalf("after forced requeue = %+v, %v", requeued, err)
}
@@ -72,14 +73,14 @@ func TestRequeueFromWaitingHuman(t *testing.T) {
if err := s.Update(ctx, task2); err != nil {
t.Fatal(err)
}
- if err := s.Transition(ctx, task2.ID, StatusRunning, StatusParked, "parked"); err != nil {
+ if err := s.Transition(ctx, task2.ID, workflow.StatusRunning, workflow.StatusParked, "parked"); err != nil {
t.Fatal(err)
}
- if err := s.Requeue(ctx, task2.ID, StatusParked, ""); err != nil {
+ if err := s.Requeue(ctx, task2.ID, workflow.StatusParked, ""); err != nil {
t.Fatal(err)
}
retried, err := s.TaskByIssue(ctx, "acme", "widget", 1)
- if err != nil || retried == nil || retried.Status != StatusQueued || retried.Workflow != "feasibility" {
+ if err != nil || retried == nil || retried.Status != workflow.StatusQueued || retried.Workflow != "feasibility" {
t.Fatalf("after empty-workflow requeue = %+v, %v", retried, err)
}
if retried.ParkReason != "" {
@@ -94,10 +95,10 @@ func TestRequeueFromWaitingHuman(t *testing.T) {
t.Fatal(err)
}
// Park again and requeue.
- if err := s.Transition(ctx, task2.ID, StatusQueued, StatusParked, "parked again"); err != nil {
+ if err := s.Transition(ctx, task2.ID, workflow.StatusQueued, workflow.StatusParked, "parked again"); err != nil {
t.Fatal(err)
}
- if err := s.Requeue(ctx, task2.ID, StatusParked, ""); err != nil {
+ if err := s.Requeue(ctx, task2.ID, workflow.StatusParked, ""); err != nil {
t.Fatal(err)
}
afterRequeue, err := s.TaskByIssue(ctx, "acme", "widget", 1)
@@ -113,7 +114,7 @@ func TestTasksListingAndStatusCounts(t *testing.T) {
s := openTest(t)
ctx := context.Background()
- for i, status := range []string{StatusQueued, StatusRunning, StatusPROpen} {
+ for i, status := range []string{workflow.StatusQueued, workflow.StatusRunning, workflow.StatusPROpen} {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", i+1, "t", "b", "", ""); err != nil {
t.Fatal(err)
}
@@ -121,8 +122,8 @@ func TestTasksListingAndStatusCounts(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("TaskByIssue(%d) = (%+v, %v)", i+1, task, err)
}
- if status != StatusQueued {
- if err := s.Transition(ctx, task.ID, StatusQueued, status, ""); err != nil {
+ if status != workflow.StatusQueued {
+ if err := s.Transition(ctx, task.ID, workflow.StatusQueued, status, ""); err != nil {
t.Fatal(err)
}
}
@@ -142,7 +143,7 @@ func TestTasksListingAndStatusCounts(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- want := map[string]int{StatusQueued: 1, StatusRunning: 1, StatusPROpen: 1}
+ want := map[string]int{workflow.StatusQueued: 1, workflow.StatusRunning: 1, workflow.StatusPROpen: 1}
for status, n := range want {
if counts[status] != n {
t.Fatalf("StatusCounts[%s] = %d, want %d (all: %+v)", status, counts[status], n, counts)
@@ -167,7 +168,7 @@ func TestWorkflowStats(t *testing.T) {
if err := s.Update(ctx, task); err != nil {
t.Fatal(err)
}
- if err := s.Transition(ctx, task.ID, StatusRunning, StatusMerged, "merged"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusMerged, "merged"); err != nil {
t.Fatal(err)
}
diff --git a/internal/store/store.go b/internal/store/store.go
index b8554504a..b4eae7a07 100644
--- a/internal/store/store.go
+++ b/internal/store/store.go
@@ -15,92 +15,10 @@ import (
_ "modernc.org/sqlite"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
- "github.com/samcharles93/archie-core/internal/taskstate"
)
-// Task lifecycle statuses. Workflows move tasks between them; the
-// daemon owns queued→running claims and crash recovery.
-const (
- // Defined in internal/taskstate so the dashboard, chat and the store
- // share one vocabulary. These names are kept as the store's public
- // spelling; the values live in one place.
- StatusQueued = taskstate.Queued
- StatusRunning = taskstate.Running
- StatusWaitingHuman = taskstate.WaitingHuman
- StatusPROpen = taskstate.PROpen
- StatusMerged = taskstate.Merged
- StatusParked = taskstate.Parked
- StatusDead = taskstate.Dead
- StatusRejected = taskstate.Rejected
- StatusClosedWontDo = taskstate.Declined
-)
-
-type Task struct {
- ID int64 `json:"id"`
- Owner string `json:"owner"`
- Repo string `json:"repo"`
- IssueNumber int `json:"issue_number"`
- Title string `json:"title"`
- Body string `json:"body"`
- Labels string `json:"labels"` // comma-separated, as seen at enqueue time
- Status string `json:"status"`
- Workflow string `json:"workflow"`
- Stage string `json:"stage"`
- Branch string `json:"branch"`
- Plan string `json:"plan"`
- Notes string `json:"notes"`
- PRNumber int `json:"pr_number"`
- TokensUsed int `json:"tokens_used"`
- Iterations int `json:"iterations"`
- Attempt int `json:"attempt"`
- ParkReason string `json:"park_reason"`
- // RetryCount tracks how many times a parked task has been retried
- // (parking-to-queued transitions). When it reaches the configured
- // max_retries the daemon moves the task to StatusDead.
- RetryCount int `json:"retry_count"`
- // WatchCommentID: replies to the issue after this comment are the
- // human input a waiting_human task is blocked on.
- WatchCommentID int64 `json:"watch_comment_id"`
- // Source is "forge" (default; a real forge issue backs this task) or
- // "chat" (created via /spawn with no forge issue). Workflow stages
- // and daemon reconciliation must skip forge-only operations (issue
- // labels, comments, replies) for chat-sourced tasks; IssueNumber on
- // a chat task is a synthetic value, not a real forge issue.
- Source string `json:"source"`
- // Identity is the archie identity that owns this task (chat-spawned
- // tasks only; empty for forge-sourced tasks and single-identity
- // deployments). Used to scope /approve and /cancel authorization so
- // one identity cannot control another's chat-spawned tasks.
- Identity string `json:"identity"`
- // BindingID and BindingVersion are stamped when a task was created
- // from a playbook binding dispatch (t2db.4 Phase B). They record
- // provenance: which binding fired this task and at what version, so
- // later edits to the binding cannot silently rewrite history.
- BindingID int64 `json:"binding_id"`
- BindingVersion int `json:"binding_version"`
- // CreatedAt and UpdatedAt are the SQLite row timestamps, exposed so
- // callers can show a task's age and last activity. They are written by
- // column defaults and the UPDATE statements, never by the caller.
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
-}
-
-// SourceForge and SourceChat are the valid values for Task.Source.
-// Legacy rows and forge-polled tasks have Source == SourceForge (the
-// zero value defaults there via the SQLite column default).
-const (
- SourceForge = "forge"
- SourceChat = "chat"
-)
-
-// IsForgeBacked reports whether t corresponds to a real forge issue.
-// Chat-spawned tasks (Source == SourceChat) have a synthetic
-// IssueNumber and must not be used in forge label/comment/reply calls.
-func (t Task) IsForgeBacked() bool {
- return t.Source != SourceChat
-}
-
type Store struct {
db *sql.DB
bindingsCipher BindingCipher
@@ -327,9 +245,9 @@ func (s *Store) EnqueueIssue(ctx context.Context, owner, repo string, number int
// backing forge issue, returning the full created row (with its real
// database ID). The store allocates the synthetic issue number durably so
// multiple processes sharing the database cannot generate the same value.
-// Workflow stages and daemon reconciliation must check Task.IsForgeBacked()
+// Workflow stages and daemon reconciliation must check workflow.Task.IsForgeBacked()
// before treating it as a real forge issue number.
-func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, workflow, identity string) (*Task, error) {
+func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*workflow.Task, error) {
const syntheticIssueNumberBase = 1_000_000_000_000_000
row := s.db.QueryRowContext(ctx, `
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity)
@@ -341,7 +259,7 @@ func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, w
workflow, stage, branch, plan, notes, pr_number, tokens_used,
iterations, attempt, park_reason, watch_comment_id, retry_count,
source, identity, binding_id, binding_version, created_at, updated_at`,
- owner, repo, owner, repo, syntheticIssueNumberBase-1, title, body, workflow, identity)
+ owner, repo, owner, repo, syntheticIssueNumberBase-1, title, body, wf, identity)
return scanTask(row)
}
@@ -357,8 +275,8 @@ func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, w
// a future repair pass could backfill. This is the same
// best-effort-provenance pattern the rest of the task lifecycle uses
// for fields added after the row's primary insert.
-func (s *Store) EnqueueBindingTask(ctx context.Context, owner, repo, title, body, workflow, identity string, bindingID int64, bindingVersion int) (*Task, error) {
- t, err := s.EnqueueChatTask(ctx, owner, repo, title, body, workflow, identity)
+func (s *Store) EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity string, bindingID int64, bindingVersion int) (*workflow.Task, error) {
+ t, err := s.EnqueueChatTask(ctx, owner, repo, title, body, wf, identity)
if err != nil {
return nil, err
}
@@ -374,7 +292,7 @@ func (s *Store) EnqueueBindingTask(ctx context.Context, owner, repo, title, body
// ClaimNext atomically moves the oldest queued task to running and
// returns it; nil when the queue is empty.
-func (s *Store) ClaimNext(ctx context.Context) (*Task, error) {
+func (s *Store) ClaimNext(ctx context.Context) (*workflow.Task, error) {
row := s.db.QueryRowContext(ctx, `
UPDATE tasks SET status='running', attempt=attempt+1, updated_at=datetime('now')
WHERE id = (SELECT id FROM tasks WHERE status='queued' ORDER BY id LIMIT 1)
@@ -389,8 +307,8 @@ func (s *Store) ClaimNext(ctx context.Context) (*Task, error) {
return t, err
}
-func scanTask(row *sql.Row) (*Task, error) {
- var t Task
+func scanTask(row *sql.Row) (*workflow.Task, error) {
+ var t workflow.Task
err := row.Scan(&t.ID, &t.Owner, &t.Repo, &t.IssueNumber, &t.Title, &t.Body,
&t.Labels, &t.Status, &t.Workflow, &t.Stage, &t.Branch, &t.Plan, &t.Notes,
&t.PRNumber, &t.TokensUsed, &t.Iterations, &t.Attempt, &t.ParkReason,
@@ -407,7 +325,7 @@ func scanTask(row *sql.Row) (*Task, error) {
// Returns nil if the task is not in queued state (already claimed, parked,
// or terminal). Used by the NATS consumer path where the task was just
// inserted via EnqueueIssue and needs an immediate targeted claim.
-func (s *Store) ClaimByIssue(ctx context.Context, owner, repo string, number int) (*Task, error) {
+func (s *Store) ClaimByIssue(ctx context.Context, owner, repo string, number int) (*workflow.Task, error) {
row := s.db.QueryRowContext(ctx, `
UPDATE tasks SET status='running', attempt=attempt+1, updated_at=datetime('now')
WHERE owner=? AND repo=? AND issue_number=? AND status='queued'
@@ -445,7 +363,7 @@ func (s *Store) Transition(ctx context.Context, taskID int64, from, to, detail s
park_reason=CASE WHEN ?=? THEN ? ELSE park_reason END,
updated_at=datetime('now')
WHERE id=? AND status=?`,
- to, to, StatusParked, clip(detail, 4000), taskID, from)
+ to, to, workflow.StatusParked, clip(detail, 4000), taskID, from)
if err != nil {
return err
}
@@ -468,7 +386,7 @@ func (s *Store) Transition(ctx context.Context, taskID int64, from, to, detail s
}
// Update persists mutable task fields written by workflows.
-func (s *Store) Update(ctx context.Context, t *Task) error {
+func (s *Store) Update(ctx context.Context, t *workflow.Task) error {
_, err := s.db.ExecContext(ctx, `
UPDATE tasks SET workflow=?, stage=?, branch=?, plan=?, notes=?,
pr_number=?, tokens_used=?, iterations=?, park_reason=?,
@@ -481,7 +399,7 @@ func (s *Store) Update(ctx context.Context, t *Task) error {
}
// TaskByIssue returns the task tracking an issue, or nil.
-func (s *Store) TaskByIssue(ctx context.Context, owner, repo string, number int) (*Task, error) {
+func (s *Store) TaskByIssue(ctx context.Context, owner, repo string, number int) (*workflow.Task, error) {
row := s.db.QueryRowContext(ctx, `
SELECT id, owner, repo, issue_number, title, body, labels, status,
workflow, stage, branch, plan, notes, pr_number, tokens_used,
@@ -498,7 +416,7 @@ func (s *Store) TaskByIssue(ctx context.Context, owner, repo string, number int)
// TaskByID returns the task with the given database ID, or nil. Used by
// chat controls (/approve, /cancel) that reference a task by its real
// ID rather than a forge issue number.
-func (s *Store) TaskByID(ctx context.Context, taskID int64) (*Task, error) {
+func (s *Store) TaskByID(ctx context.Context, taskID int64) (*workflow.Task, error) {
row := s.db.QueryRowContext(ctx, `
SELECT id, owner, repo, issue_number, title, body, labels, status,
workflow, stage, branch, plan, notes, pr_number, tokens_used,
@@ -633,7 +551,7 @@ func (s *Store) RecoverStale(ctx context.Context) (int64, error) {
}
// OpenPRs returns tasks whose PR state should be reconciled with GitHub.
-func (s *Store) OpenPRs(ctx context.Context) (tasks []Task, retErr error) {
+func (s *Store) OpenPRs(ctx context.Context) (tasks []workflow.Task, retErr error) {
rows, err := s.db.QueryContext(ctx, `
SELECT id, owner, repo, issue_number, pr_number, status, source, identity
FROM tasks WHERE status='pr_open'`)
@@ -644,7 +562,7 @@ func (s *Store) OpenPRs(ctx context.Context) (tasks []Task, retErr error) {
retErr = errors.Join(retErr, rows.Close())
}()
for rows.Next() {
- var t Task
+ var t workflow.Task
if err := rows.Scan(&t.ID, &t.Owner, &t.Repo, &t.IssueNumber, &t.PRNumber,
&t.Status, &t.Source, &t.Identity); err != nil {
return nil, err
diff --git a/internal/store/store_test.go b/internal/store/store_test.go
index 867cb7daa..2f9ae928d 100644
--- a/internal/store/store_test.go
+++ b/internal/store/store_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"unicode/utf8"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
)
@@ -330,9 +331,9 @@ func TestTasksBindingColumnsRoundTrip(t *testing.T) {
t.Fatalf("UPDATE binding provenance: %v", err)
}
- for name, read := range map[string]func() (*Task, error){
- "scanTask-via-TaskByIssue": func() (*Task, error) { return s.TaskByIssue(ctx, "acme", "widget", task.IssueNumber) },
- "TaskByID": func() (*Task, error) { return s.TaskByID(ctx, task.ID) },
+ for name, read := range map[string]func() (*workflow.Task, error){
+ "scanTask-via-TaskByIssue": func() (*workflow.Task, error) { return s.TaskByIssue(ctx, "acme", "widget", task.IssueNumber) },
+ "TaskByID": func() (*workflow.Task, error) { return s.TaskByID(ctx, task.ID) },
} {
got, err := read()
if err != nil {
@@ -398,7 +399,7 @@ func TestClearTerminalTasks(t *testing.T) {
s := openTest(t)
ctx := context.Background()
- statuses := []string{StatusMerged, StatusParked, StatusRejected, StatusClosedWontDo, StatusQueued}
+ statuses := []string{workflow.StatusMerged, workflow.StatusParked, workflow.StatusRejected, workflow.StatusClosedWontDo, workflow.StatusQueued}
for i, status := range statuses {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", i+1, "t", "b", "", ""); err != nil {
t.Fatal(err)
@@ -407,8 +408,8 @@ func TestClearTerminalTasks(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("TaskByIssue(%d) = (%+v, %v)", i+1, task, err)
}
- if status != StatusQueued {
- if err := s.Transition(ctx, task.ID, StatusQueued, status, ""); err != nil {
+ if status != workflow.StatusQueued {
+ if err := s.Transition(ctx, task.ID, workflow.StatusQueued, status, ""); err != nil {
t.Fatal(err)
}
}
@@ -423,13 +424,13 @@ func TestClearTerminalTasks(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if counts[StatusQueued] != 1 {
- t.Fatalf("expected 1 queued, got %d", counts[StatusQueued])
+ if counts[workflow.StatusQueued] != 1 {
+ t.Fatalf("expected 1 queued, got %d", counts[workflow.StatusQueued])
}
- if counts[StatusParked] != 1 {
- t.Fatalf("recoverable parked task was cleared: count = %d", counts[StatusParked])
+ if counts[workflow.StatusParked] != 1 {
+ t.Fatalf("recoverable parked task was cleared: count = %d", counts[workflow.StatusParked])
}
- for _, status := range []string{StatusMerged, StatusRejected, StatusClosedWontDo} {
+ for _, status := range []string{workflow.StatusMerged, workflow.StatusRejected, workflow.StatusClosedWontDo} {
if counts[status] != 0 {
t.Fatalf("expected 0 for %s, got %d", status, counts[status])
}
@@ -454,18 +455,18 @@ func TestArchiveTaskIsGuardedAndScoped(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
- if err := s.Transition(ctx, task.ID, StatusQueued, StatusMerged, "done"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusMerged, "done"); err != nil {
t.Fatal(err)
}
audit := events.Event{Kind: events.KindTaskArchiveRequested, TaskID: task.ID}
- if _, err := s.ArchiveTask(ctx, task.ID, StatusQueued, audit); !errors.Is(err, ErrStaleTransition) {
+ if _, err := s.ArchiveTask(ctx, task.ID, workflow.StatusQueued, audit); !errors.Is(err, ErrStaleTransition) {
t.Fatalf("ArchiveTask stale guard = %v, want ErrStaleTransition", err)
}
if got, err := s.TaskByID(ctx, task.ID); err != nil || got == nil {
t.Fatalf("stale archive removed task: (%+v, %v)", got, err)
}
- eventID, err := s.ArchiveTask(ctx, task.ID, StatusMerged, audit)
+ eventID, err := s.ArchiveTask(ctx, task.ID, workflow.StatusMerged, audit)
if err != nil {
t.Fatalf("ArchiveTask = %v", err)
}
@@ -487,7 +488,7 @@ func TestArchiveAuditFailurePreservesTask(t *testing.T) {
t.Fatal(err)
}
task, _ := s.TaskByIssue(ctx, "acme", "widget", 1)
- if err := s.Transition(ctx, task.ID, StatusQueued, StatusMerged, "done"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusMerged, "done"); err != nil {
t.Fatal(err)
}
if _, err := s.db.ExecContext(ctx, `
@@ -497,7 +498,7 @@ func TestArchiveAuditFailurePreservesTask(t *testing.T) {
t.Fatal(err)
}
- if _, err := s.ArchiveTask(ctx, task.ID, StatusMerged, events.Event{
+ if _, err := s.ArchiveTask(ctx, task.ID, workflow.StatusMerged, events.Event{
Kind: events.KindTaskArchiveRequested, TaskID: task.ID,
}); err == nil {
t.Fatal("ArchiveTask succeeded despite forced audit failure")
@@ -571,11 +572,11 @@ func TestTransitionRejectsStaleFrom(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("claim = (%v, %v)", task, err)
}
- // Task is now StatusRunning. Transition with from=StatusQueued
+ // Task is now workflow.StatusRunning. Transition with from=workflow.StatusQueued
// must fail because the task is not queued.
- err = s.Transition(ctx, task.ID, StatusQueued, StatusPROpen, "stale from")
+ err = s.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusPROpen, "stale from")
if err == nil {
- t.Fatal("Transition with stale 'from' (StatusQueued) on a running task must return an error, but got nil")
+ t.Fatal("Transition with stale 'from' (workflow.StatusQueued) on a running task must return an error, but got nil")
}
// Verify the task was NOT changed.
@@ -583,8 +584,8 @@ func TestTransitionRejectsStaleFrom(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != StatusRunning {
- t.Fatalf("task status changed to %q despite stale from guard; want %q", got.Status, StatusRunning)
+ if got.Status != workflow.StatusRunning {
+ t.Fatalf("task status changed to %q despite stale from guard; want %q", got.Status, workflow.StatusRunning)
}
}
@@ -605,15 +606,15 @@ func TestTransitionPreventsDoubleTransition(t *testing.T) {
}
// First transition: running → pr_open should succeed.
- if err := s.Transition(ctx, task.ID, StatusRunning, StatusPROpen, "first"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusPROpen, "first"); err != nil {
t.Fatalf("first transition = %v", err)
}
- // Second transition: the task is now StatusPROpen, so
- // from=StatusRunning must fail.
- err = s.Transition(ctx, task.ID, StatusRunning, StatusMerged, "second")
+ // Second transition: the task is now workflow.StatusPROpen, so
+ // from=workflow.StatusRunning must fail.
+ err = s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusMerged, "second")
if err == nil {
- t.Fatal("second Transition with stale 'from' (StatusRunning) on a pr_open task must return an error, but got nil")
+ t.Fatal("second Transition with stale 'from' (workflow.StatusRunning) on a pr_open task must return an error, but got nil")
}
// Verify the task kept the first transition's status.
@@ -621,8 +622,8 @@ func TestTransitionPreventsDoubleTransition(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != StatusPROpen {
- t.Fatalf("task status = %q, want %q (second transition must not overwrite)", got.Status, StatusPROpen)
+ if got.Status != workflow.StatusPROpen {
+ t.Fatalf("task status = %q, want %q (second transition must not overwrite)", got.Status, workflow.StatusPROpen)
}
}
@@ -638,7 +639,7 @@ func TestTransitionToParkedPersistsReasonOnTask(t *testing.T) {
t.Fatalf("ClaimNext = (%+v, %v)", task, err)
}
const reason = "managed worker unavailable"
- if err := s.Transition(ctx, task.ID, StatusRunning, StatusParked, reason); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusParked, reason); err != nil {
t.Fatal(err)
}
@@ -664,11 +665,11 @@ func TestRequeueRejectsStaleFrom(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("claim = (%v, %v)", task, err)
}
- // Task is StatusRunning. Requeue with fromStatus=StatusParked must
+ // Task is workflow.StatusRunning. Requeue with fromStatus=workflow.StatusParked must
// fail because the task is not parked.
- err = s.Requeue(ctx, task.ID, StatusParked, "implement")
+ err = s.Requeue(ctx, task.ID, workflow.StatusParked, "implement")
if err == nil {
- t.Fatal("Requeue with stale fromStatus (StatusParked) on a running task must return an error, but got nil")
+ t.Fatal("Requeue with stale fromStatus (workflow.StatusParked) on a running task must return an error, but got nil")
}
// Verify the task was NOT changed.
@@ -676,8 +677,8 @@ func TestRequeueRejectsStaleFrom(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != StatusRunning {
- t.Fatalf("task status changed to %q despite stale fromStatus guard; want %q", got.Status, StatusRunning)
+ if got.Status != workflow.StatusRunning {
+ t.Fatalf("task status changed to %q despite stale fromStatus guard; want %q", got.Status, workflow.StatusRunning)
}
}
@@ -724,21 +725,21 @@ func TestRetryTaskAtomicallyRequeuesAndIncrements(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("ClaimNext = (%+v, %v)", task, err)
}
- if err := s.Transition(ctx, task.ID, StatusRunning, StatusParked, "failed"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusParked, "failed"); err != nil {
t.Fatal(err)
}
- if err := s.RetryTask(ctx, task.ID, StatusParked, ""); err != nil {
+ if err := s.RetryTask(ctx, task.ID, workflow.StatusParked, ""); err != nil {
t.Fatal(err)
}
got, err := s.TaskByID(ctx, task.ID)
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != StatusQueued || got.RetryCount != 1 {
+ if got.Status != workflow.StatusQueued || got.RetryCount != 1 {
t.Fatalf("task = status %q retry_count %d, want queued/1", got.Status, got.RetryCount)
}
- if err := s.RetryTask(ctx, task.ID, StatusParked, ""); !errors.Is(err, ErrStaleTransition) {
+ if err := s.RetryTask(ctx, task.ID, workflow.StatusParked, ""); !errors.Is(err, ErrStaleTransition) {
t.Fatalf("stale RetryTask error = %v, want ErrStaleTransition", err)
}
}
@@ -750,7 +751,7 @@ func TestRetryTaskWriteFailureLeavesParkedCountUnchanged(t *testing.T) {
t.Fatal(err)
}
task, _ := s.ClaimNext(ctx)
- if err := s.Transition(ctx, task.ID, StatusRunning, StatusParked, "failed"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusParked, "failed"); err != nil {
t.Fatal(err)
}
if _, err := s.db.ExecContext(ctx, `
@@ -759,14 +760,14 @@ func TestRetryTaskWriteFailureLeavesParkedCountUnchanged(t *testing.T) {
t.Fatal(err)
}
- if err := s.RetryTask(ctx, task.ID, StatusParked, ""); err == nil {
+ if err := s.RetryTask(ctx, task.ID, workflow.StatusParked, ""); err == nil {
t.Fatal("RetryTask succeeded despite forced write failure")
}
got, err := s.TaskByID(ctx, task.ID)
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != StatusParked || got.RetryCount != 0 {
+ if got.Status != workflow.StatusParked || got.RetryCount != 0 {
t.Fatalf("partial retry write: status %q retry_count %d", got.Status, got.RetryCount)
}
}
@@ -801,7 +802,7 @@ func TestClaimTransitionAndRecovery(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("claim = (%v, %v)", task, err)
}
- if task.Status != StatusRunning || task.Attempt != 1 || task.Labels != "archie,bug" {
+ if task.Status != workflow.StatusRunning || task.Attempt != 1 || task.Labels != "archie,bug" {
t.Fatalf("claimed task = %+v", task)
}
if next, _ := s.ClaimNext(ctx); next != nil {
@@ -818,7 +819,7 @@ func TestClaimTransitionAndRecovery(t *testing.T) {
t.Fatalf("re-claim after recovery = (%+v, %v)", task, err)
}
- if err := s.Transition(ctx, task.ID, StatusRunning, StatusPROpen, "PR #3"); err != nil {
+ if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusPROpen, "PR #3"); err != nil {
t.Fatal(err)
}
task.PRNumber = 3
@@ -853,7 +854,7 @@ func TestRecoverStalePreservesChatTaskRouting(t *testing.T) {
if recovered == nil {
t.Fatal("TaskByID() returned nil after recovery")
}
- if recovered.Status != StatusQueued || recovered.Source != SourceChat ||
+ if recovered.Status != workflow.StatusQueued || recovered.Source != workflow.SourceChat ||
recovered.Identity != "reviewer" || recovered.Workflow != "tdd" {
t.Errorf("recovered task = %+v, want queued chat task routed to reviewer/tdd", recovered)
}
@@ -867,7 +868,7 @@ func TestLifecycleQueriesPreserveChatTaskRouting(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if err := s.Transition(ctx, waiting.ID, StatusQueued, StatusWaitingHuman, "await approval"); err != nil {
+ if err := s.Transition(ctx, waiting.ID, workflow.StatusQueued, workflow.StatusWaitingHuman, "await approval"); err != nil {
t.Fatal(err)
}
// Routing metadata must survive a status transition: a chat task that
@@ -876,7 +877,7 @@ func TestLifecycleQueriesPreserveChatTaskRouting(t *testing.T) {
if err != nil || waitingTask == nil {
t.Fatalf("TaskByID = (%+v, %v)", waitingTask, err)
}
- if waitingTask.Status != StatusWaitingHuman || waitingTask.Source != SourceChat ||
+ if waitingTask.Status != workflow.StatusWaitingHuman || waitingTask.Source != workflow.SourceChat ||
waitingTask.Identity != "reviewer" {
t.Fatalf("waiting task = %+v, want waiting_human chat/reviewer routing", waitingTask)
}
@@ -889,14 +890,14 @@ func TestLifecycleQueriesPreserveChatTaskRouting(t *testing.T) {
if err := s.Update(ctx, pr); err != nil {
t.Fatal(err)
}
- if err := s.Transition(ctx, pr.ID, StatusQueued, StatusPROpen, "PR #7"); err != nil {
+ if err := s.Transition(ctx, pr.ID, workflow.StatusQueued, workflow.StatusPROpen, "PR #7"); err != nil {
t.Fatal(err)
}
openPRs, err := s.OpenPRs(ctx)
if err != nil {
t.Fatal(err)
}
- if len(openPRs) != 1 || openPRs[0].Source != SourceChat ||
+ if len(openPRs) != 1 || openPRs[0].Source != workflow.SourceChat ||
openPRs[0].Identity != "builder" {
t.Fatalf("OpenPRs() = %+v, want chat/builder routing", openPRs)
}
diff --git a/internal/store/tasks_fields_test.go b/internal/store/tasks_fields_test.go
index ce2dc4718..d7705a11d 100644
--- a/internal/store/tasks_fields_test.go
+++ b/internal/store/tasks_fields_test.go
@@ -3,6 +3,8 @@ package store
import (
"context"
"testing"
+
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
)
// Tasks() is what the dashboard's task list is built from, and the UI reads
@@ -47,7 +49,7 @@ func TestTasksSelectsFieldsTheUIReads(t *testing.T) {
t.Fatalf("Tasks: %v", err)
}
- byID := make(map[int64]Task, len(tasks))
+ byID := make(map[int64]workflow.Task, len(tasks))
for _, task := range tasks {
byID[task.ID] = task
}
@@ -60,18 +62,18 @@ func TestTasksSelectsFieldsTheUIReads(t *testing.T) {
t.Errorf("Plan = %q, want %q: the approval panel is gated on this and "+
"can never render while it is empty", forgeTask.Plan, plan)
}
- if forgeTask.Source != SourceForge {
- t.Errorf("Source = %q, want %q", forgeTask.Source, SourceForge)
+ if forgeTask.Source != workflow.SourceForge {
+ t.Errorf("Source = %q, want %q", forgeTask.Source, workflow.SourceForge)
}
chatTask, ok := byID[chatID]
if !ok {
t.Fatalf("chat task %d missing from Tasks()", chatID)
}
- if chatTask.Source != SourceChat {
+ if chatTask.Source != workflow.SourceChat {
t.Errorf("Source = %q, want %q: without it the UI links a synthetic "+
"issue number to a forge issue that does not exist",
- chatTask.Source, SourceChat)
+ chatTask.Source, workflow.SourceChat)
}
if chatTask.IsForgeBacked() {
t.Error("IsForgeBacked() is true for a chat task read through Tasks()")
diff --git a/internal/storerpc/storerpc.go b/internal/storerpc/storerpc.go
index 34555ea0c..cf1578283 100644
--- a/internal/storerpc/storerpc.go
+++ b/internal/storerpc/storerpc.go
@@ -12,6 +12,7 @@ import (
"github.com/nats-io/nats.go"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/natsrpc"
"github.com/samcharles93/archie-core/internal/store"
@@ -26,7 +27,7 @@ const (
// UpdateRequest mirrors store.TaskStore.Update's argument.
type UpdateRequest struct {
- Task *store.Task `json:"task"`
+ Task *workflow.Task `json:"task"`
}
// TransitionRequest mirrors store.TaskStore.Transition's arguments.
@@ -96,7 +97,7 @@ func (s *Server) reply(msg *nats.Msg, err error) {
}
// Client calls the storerpc Server from archie-agent's process.
-// It implements store.WorkflowStore (the narrow interface workflow stages
+// It implements workflow.Store (the narrow interface workflow stages
// need -- just Update + Transition), not the full store.TaskStore.
type Client struct {
Conn *nats.Conn
@@ -106,7 +107,7 @@ type Client struct {
func (c *Client) rpc() *natsrpc.Client { return &natsrpc.Client{Conn: c.Conn, Timeout: c.Timeout} }
// Update calls store.TaskStore.Update on the daemon over NATS request/reply.
-func (c *Client) Update(ctx context.Context, task *store.Task) error {
+func (c *Client) Update(ctx context.Context, task *workflow.Task) error {
resp, err := natsrpc.Call[Response](ctx, c.rpc(), SubjectUpdate, UpdateRequest{Task: task})
if err != nil {
return err
@@ -132,5 +133,5 @@ func (c *Client) InsertEvent(ctx context.Context, event events.Event) (int64, er
return resp.ID, resp.Err()
}
-// Compile-time check: Client satisfies WorkflowStore.
-var _ store.WorkflowStore = (*Client)(nil)
+// Compile-time check: Client satisfies workflow.Store.
+var _ workflow.Store = (*Client)(nil)
diff --git a/internal/storerpc/storerpc_test.go b/internal/storerpc/storerpc_test.go
index 28b4e81da..d4d206973 100644
--- a/internal/storerpc/storerpc_test.go
+++ b/internal/storerpc/storerpc_test.go
@@ -10,6 +10,7 @@ import (
natssrv "github.com/nats-io/nats-server/v2/test"
"github.com/nats-io/nats.go"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/store"
)
@@ -51,7 +52,7 @@ func newTestServer(t *testing.T) (*store.Store, *nats.Conn, *Client) {
return s, serverConn, client
}
-func enqueueTask(t *testing.T, s *store.Store) *store.Task {
+func enqueueTask(t *testing.T, s *store.Store) *workflow.Task {
t.Helper()
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 1, "title", "body", "", ""); err != nil {
@@ -96,7 +97,7 @@ func TestClientTransitionPersistsViaServer(t *testing.T) {
s, _, client := newTestServer(t)
task := enqueueTask(t, s)
- if err := client.Transition(context.Background(), task.ID, store.StatusRunning, store.StatusPROpen, "opened PR"); err != nil {
+ if err := client.Transition(context.Background(), task.ID, workflow.StatusRunning, workflow.StatusPROpen, "opened PR"); err != nil {
t.Fatalf("Transition: %v", err)
}
@@ -104,8 +105,8 @@ func TestClientTransitionPersistsViaServer(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
- if got.Status != store.StatusPROpen {
- t.Fatalf("expected status %s, got %s", store.StatusPROpen, got.Status)
+ if got.Status != workflow.StatusPROpen {
+ t.Fatalf("expected status %s, got %s", workflow.StatusPROpen, got.Status)
}
}
@@ -145,7 +146,7 @@ func TestClientUpdateTimesOutWithNoResponder(t *testing.T) {
clientConn := connect(t, srv.ClientURL())
client := &Client{Conn: clientConn, Timeout: 100 * time.Millisecond}
- err := client.Update(context.Background(), &store.Task{ID: 1})
+ err := client.Update(context.Background(), &workflow.Task{ID: 1})
if err == nil {
t.Fatal("expected Update to time out with no server registered")
}
diff --git a/internal/taskrun/taskrun.go b/internal/taskrun/taskrun.go
index e49d46119..ec4be26a6 100644
--- a/internal/taskrun/taskrun.go
+++ b/internal/taskrun/taskrun.go
@@ -11,7 +11,7 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
- "github.com/samcharles93/archie-core/internal/store"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
)
// Request carries everything archie-agent needs to run a task's entire
@@ -20,7 +20,7 @@ import (
// config (API keys are injected into the container's environment
// separately -- Providers only carries class/env-var-name/base-URL).
type Request struct {
- Task *store.Task `json:"task"`
+ Task *workflow.Task `json:"task"`
Repo config.Repo `json:"repo"`
Cfg config.TaskConfig `json:"cfg"`
Providers map[string]agentexec.Provider `json:"providers"`
@@ -54,9 +54,9 @@ func (r Request) Validate() error {
// authoritative state already landed in archied's store via storerpc
// calls made during the run.
type Response struct {
- Task *store.Task `json:"task"`
- Status string `json:"status"`
- Error string `json:"error,omitempty"`
+ Task *workflow.Task `json:"task"`
+ Status string `json:"status"`
+ Error string `json:"error,omitempty"`
// AgentVersion and AgentInstallType report the build of archie-agent
// that actually ran this task -- self-reported by the worker, not the
// version archied's release pipeline expected to be running. Every
diff --git a/internal/taskrun/taskrun_test.go b/internal/taskrun/taskrun_test.go
index fadcea5cb..a24da62a8 100644
--- a/internal/taskrun/taskrun_test.go
+++ b/internal/taskrun/taskrun_test.go
@@ -6,18 +6,18 @@ import (
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
- "github.com/samcharles93/archie-core/internal/store"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
)
func TestRequestJSONRoundTrip(t *testing.T) {
req := Request{
- Task: &store.Task{
+ Task: &workflow.Task{
ID: 1,
Owner: "acme",
Repo: "widget",
IssueNumber: 42,
Title: "feat: thing",
- Status: store.StatusRunning,
+ Status: workflow.StatusRunning,
},
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
Cfg: config.Config{DiffCapLines: 500}.ForTask(),
@@ -61,10 +61,10 @@ func TestRequestValidateRequiresPositiveTaskID(t *testing.T) {
wantErr bool
}{
{name: "missing task", wantErr: true},
- {name: "zero ID", request: Request{Task: &store.Task{}}, wantErr: true},
- {name: "negative ID", request: Request{Task: &store.Task{ID: -1}}, wantErr: true},
- {name: "missing worktree grant", request: Request{Task: &store.Task{ID: 1}}, wantErr: true},
- {name: "valid request", request: Request{Task: &store.Task{ID: 1}, WorktreeGrant: "grant"}},
+ {name: "zero ID", request: Request{Task: &workflow.Task{}}, wantErr: true},
+ {name: "negative ID", request: Request{Task: &workflow.Task{ID: -1}}, wantErr: true},
+ {name: "missing worktree grant", request: Request{Task: &workflow.Task{ID: 1}}, wantErr: true},
+ {name: "valid request", request: Request{Task: &workflow.Task{ID: 1}, WorktreeGrant: "grant"}},
} {
t.Run(test.name, func(t *testing.T) {
err := test.request.Validate()
@@ -77,7 +77,7 @@ func TestRequestValidateRequiresPositiveTaskID(t *testing.T) {
func TestResponseJSONRoundTrip(t *testing.T) {
resp := Response{
- Task: &store.Task{ID: 1, Status: store.StatusPROpen},
+ Task: &workflow.Task{ID: 1, Status: workflow.StatusPROpen},
Status: "passed",
}
data, err := json.Marshal(resp)
@@ -88,7 +88,7 @@ func TestResponseJSONRoundTrip(t *testing.T) {
if err := json.Unmarshal(data, &got); err != nil {
t.Fatalf("unmarshal: %v", err)
}
- if got.Task == nil || got.Task.Status != store.StatusPROpen || got.Status != "passed" {
+ if got.Task == nil || got.Task.Status != workflow.StatusPROpen || got.Status != "passed" {
t.Fatalf("Response did not round-trip: %+v", got)
}
}
diff --git a/internal/webui/api_tasks.go b/internal/webui/api_tasks.go
index e11e5fb73..945e0a5e7 100644
--- a/internal/webui/api_tasks.go
+++ b/internal/webui/api_tasks.go
@@ -13,6 +13,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/taskactions"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
taskactionstore "github.com/samcharles93/archie-core/internal/infrastructure/taskactions"
"github.com/samcharles93/archie-core/internal/store"
@@ -62,14 +63,14 @@ func (s *Server) handleTasks(w http.ResponseWriter, r *http.Request) {
}
type taskView struct {
- store.Task
+ workflow.Task
Actions []taskstate.Action `json:"actions"`
RepoURL string `json:"repo_url,omitempty"`
IssueURL string `json:"issue_url,omitempty"`
PRURL string `json:"pr_url,omitempty"`
}
-func (s *Server) taskURLs(task store.Task) (repoURL, issueURL, prURL string) {
+func (s *Server) taskURLs(task workflow.Task) (repoURL, issueURL, prURL string) {
if s.Cfg == nil {
return "", "", ""
}
@@ -91,7 +92,7 @@ func (s *Server) taskURLs(task store.Task) (repoURL, issueURL, prURL string) {
return repoURL, issueURL, prURL
}
-func forgeConfigForTask(cfg config.Config, task store.Task) config.Forge {
+func forgeConfigForTask(cfg config.Config, task workflow.Task) config.Forge {
for _, identity := range cfg.Identities {
if task.Identity != "" && identity.Name == task.Identity {
return identity.Forge
diff --git a/internal/webui/api_tasks_actions_test.go b/internal/webui/api_tasks_actions_test.go
index e9c13151c..f462fe112 100644
--- a/internal/webui/api_tasks_actions_test.go
+++ b/internal/webui/api_tasks_actions_test.go
@@ -15,6 +15,7 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/store"
@@ -39,7 +40,7 @@ func (r *recordingCloser) CloseIssue(_ context.Context, owner, repo string, numb
// actionServer builds a dashboard server with a task in the given state, plus
// the collaborators the action path needs.
-func actionServer(t *testing.T, status, parkReason string) (*Server, *store.Task, *recordingCloser, *events.Bus, *events.Sub) {
+func actionServer(t *testing.T, status, parkReason string) (*Server, *workflow.Task, *recordingCloser, *events.Bus, *events.Sub) {
t.Helper()
srv := newTestServer(t)
ctx := t.Context()
@@ -51,7 +52,7 @@ func actionServer(t *testing.T, status, parkReason string) (*Server, *store.Task
if err != nil || task == nil {
t.Fatalf("ClaimNext = (%+v, %v)", task, err)
}
- if err := srv.Store.Transition(ctx, task.ID, store.StatusRunning, status, parkReason); err != nil {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusRunning, status, parkReason); err != nil {
t.Fatal(err)
}
@@ -119,15 +120,15 @@ func TestRetryEnforcesMaxRetries(t *testing.T) {
wantStatus int
wantTask string
}{
- {name: "under the cap", priorCount: 0, maxRetries: 3, wantStatus: http.StatusOK, wantTask: store.StatusQueued},
- {name: "one below the cap", priorCount: 2, maxRetries: 3, wantStatus: http.StatusOK, wantTask: store.StatusQueued},
- {name: "at the cap", priorCount: 3, maxRetries: 3, wantStatus: http.StatusConflict, wantTask: store.StatusDead},
- {name: "past the cap", priorCount: 5, maxRetries: 3, wantStatus: http.StatusConflict, wantTask: store.StatusDead},
+ {name: "under the cap", priorCount: 0, maxRetries: 3, wantStatus: http.StatusOK, wantTask: workflow.StatusQueued},
+ {name: "one below the cap", priorCount: 2, maxRetries: 3, wantStatus: http.StatusOK, wantTask: workflow.StatusQueued},
+ {name: "at the cap", priorCount: 3, maxRetries: 3, wantStatus: http.StatusConflict, wantTask: workflow.StatusDead},
+ {name: "past the cap", priorCount: 5, maxRetries: 3, wantStatus: http.StatusConflict, wantTask: workflow.StatusDead},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- srv, task, _, _, _ := actionServer(t, store.StatusParked, "it broke")
+ srv, task, _, _, _ := actionServer(t, workflow.StatusParked, "it broke")
srv.Cfg = config.NewHolder(config.Config{MaxRetries: tc.maxRetries})
ctx := t.Context()
for range tc.priorCount {
@@ -157,7 +158,7 @@ func TestRetryEnforcesMaxRetries(t *testing.T) {
// the operator has used the dashboard's Clear, which deletes the row, that is
// a second implementation and a second PR for work already declined.
func TestRejectClosesTheForgeIssue(t *testing.T) {
- srv, task, closer, _, _ := actionServer(t, store.StatusWaitingHuman, "review")
+ srv, task, closer, _, _ := actionServer(t, workflow.StatusWaitingHuman, "review")
if w := postAction(t, srv, task.ID, "reject"); w.Code != http.StatusOK {
t.Fatalf("reject status = %d, body %s", w.Code, w.Body)
@@ -180,8 +181,8 @@ func TestRejectClosesTheForgeIssue(t *testing.T) {
// Approve and retry put the task back to work, so the issue must stay open.
func TestApproveAndRetryDoNotCloseTheIssue(t *testing.T) {
for _, tc := range []struct{ action, status, reason string }{
- {"approve", store.StatusWaitingHuman, "review"},
- {"retry", store.StatusParked, "it broke"},
+ {"approve", workflow.StatusWaitingHuman, "review"},
+ {"retry", workflow.StatusParked, "it broke"},
} {
t.Run(tc.action, func(t *testing.T) {
srv, task, closer, _, _ := actionServer(t, tc.status, tc.reason)
@@ -212,7 +213,7 @@ func TestRejectDoesNotCloseAChatTaskIssue(t *testing.T) {
if _, err := srv.Store.ClaimNext(ctx); err != nil {
t.Fatal(err)
}
- if err := srv.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusWaitingHuman, "review"); err != nil {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusWaitingHuman, "review"); err != nil {
t.Fatal(err)
}
@@ -229,7 +230,7 @@ func TestRejectDoesNotCloseAChatTaskIssue(t *testing.T) {
// decision is already recorded in the store, and reporting failure would
// invite them to click again.
func TestRejectSurvivesAForgeFailure(t *testing.T) {
- srv, task, closer, _, _ := actionServer(t, store.StatusWaitingHuman, "review")
+ srv, task, closer, _, _ := actionServer(t, workflow.StatusWaitingHuman, "review")
closer.err = errors.New("forge unreachable")
if w := postAction(t, srv, task.ID, "reject"); w.Code != http.StatusOK {
@@ -239,8 +240,8 @@ func TestRejectSurvivesAForgeFailure(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != store.StatusClosedWontDo {
- t.Errorf("status = %q, want %q", got.Status, store.StatusClosedWontDo)
+ if got.Status != workflow.StatusClosedWontDo {
+ t.Errorf("status = %q, want %q", got.Status, workflow.StatusClosedWontDo)
}
}
@@ -255,9 +256,9 @@ func TestActionsEmitEvents(t *testing.T) {
reason string
wantMsg string
}{
- {name: "approve", action: "approve", status: store.StatusWaitingHuman, reason: "review", wantMsg: "approve"},
- {name: "retry", action: "retry", status: store.StatusParked, reason: "it broke", wantMsg: "retry"},
- {name: "reject", action: "reject", status: store.StatusWaitingHuman, reason: "review", wantMsg: "reject"},
+ {name: "approve", action: "approve", status: workflow.StatusWaitingHuman, reason: "review", wantMsg: "approve"},
+ {name: "retry", action: "retry", status: workflow.StatusParked, reason: "it broke", wantMsg: "retry"},
+ {name: "reject", action: "reject", status: workflow.StatusWaitingHuman, reason: "review", wantMsg: "reject"},
}
for _, tc := range tests {
@@ -341,7 +342,7 @@ func TestTaskActionErrorMapping(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- srv, task, _, _, _ := actionServer(t, store.StatusWaitingHuman, "review")
+ srv, task, _, _, _ := actionServer(t, workflow.StatusWaitingHuman, "review")
if tc.setup != nil {
tc.setup(t, srv, task.ID)
}
@@ -378,7 +379,7 @@ func TestTaskActionStoreFailureIs500(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("ClaimNext = (%+v, %v)", task, err)
}
- if err := base.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusWaitingHuman, "review"); err != nil {
+ if err := base.Store.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusWaitingHuman, "review"); err != nil {
t.Fatal(err)
}
@@ -397,15 +398,15 @@ func TestTaskListExposesLifecycleActions(t *testing.T) {
srv := newTestServer(t)
ctx := t.Context()
want := map[string][]string{
- store.StatusQueued: {"cancel", "reject"},
- store.StatusRunning: {"stop", "reject"},
- store.StatusWaitingHuman: {"approve", "reject"},
- store.StatusParked: {"retry", "abandon", "reject"},
- store.StatusPROpen: {"open_pr", "open_issue", "reject"},
- store.StatusMerged: {"archive"},
- store.StatusRejected: {"archive"},
- store.StatusDead: {"archive"},
- store.StatusClosedWontDo: {"archive"},
+ workflow.StatusQueued: {"cancel", "reject"},
+ workflow.StatusRunning: {"stop", "reject"},
+ workflow.StatusWaitingHuman: {"approve", "reject"},
+ workflow.StatusParked: {"retry", "abandon", "reject"},
+ workflow.StatusPROpen: {"open_pr", "open_issue", "reject"},
+ workflow.StatusMerged: {"archive"},
+ workflow.StatusRejected: {"archive"},
+ workflow.StatusDead: {"archive"},
+ workflow.StatusClosedWontDo: {"archive"},
}
number := 1
@@ -417,8 +418,8 @@ func TestTaskListExposesLifecycleActions(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("TaskByIssue(%s) = (%+v, %v)", status, task, err)
}
- if status != store.StatusQueued {
- if err := srv.Store.Transition(ctx, task.ID, store.StatusQueued, status, "test"); err != nil {
+ if status != workflow.StatusQueued {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusQueued, status, "test"); err != nil {
t.Fatal(err)
}
}
@@ -451,17 +452,17 @@ func TestLifecycleSpecificTaskActions(t *testing.T) {
stopperResult bool
closesIssue bool
}{
- {name: "cancel queued", from: store.StatusQueued, action: "cancel", want: store.StatusClosedWontDo, closesIssue: true},
- {name: "stop running", from: store.StatusRunning, action: "stop", want: store.StatusParked, stopperResult: true},
- {name: "park stale running row", from: store.StatusRunning, action: "stop", want: store.StatusParked},
- {name: "abandon parked", from: store.StatusParked, action: "abandon", want: store.StatusClosedWontDo, closesIssue: true},
+ {name: "cancel queued", from: workflow.StatusQueued, action: "cancel", want: workflow.StatusClosedWontDo, closesIssue: true},
+ {name: "stop running", from: workflow.StatusRunning, action: "stop", want: workflow.StatusParked, stopperResult: true},
+ {name: "park stale running row", from: workflow.StatusRunning, action: "stop", want: workflow.StatusParked},
+ {name: "abandon parked", from: workflow.StatusParked, action: "abandon", want: workflow.StatusClosedWontDo, closesIssue: true},
// Reject is available from every non-terminal state and always lands in
// the terminal Declined state, closing the forge issue.
- {name: "reject queued", from: store.StatusQueued, action: "reject", want: store.StatusClosedWontDo, closesIssue: true},
- {name: "reject running stops execution", from: store.StatusRunning, action: "reject", want: store.StatusClosedWontDo, closesIssue: true, stopperResult: true},
- {name: "reject waiting_human", from: store.StatusWaitingHuman, action: "reject", want: store.StatusClosedWontDo, closesIssue: true},
- {name: "reject parked", from: store.StatusParked, action: "reject", want: store.StatusClosedWontDo, closesIssue: true},
- {name: "reject pr_open", from: store.StatusPROpen, action: "reject", want: store.StatusClosedWontDo, closesIssue: true},
+ {name: "reject queued", from: workflow.StatusQueued, action: "reject", want: workflow.StatusClosedWontDo, closesIssue: true},
+ {name: "reject running stops execution", from: workflow.StatusRunning, action: "reject", want: workflow.StatusClosedWontDo, closesIssue: true, stopperResult: true},
+ {name: "reject waiting_human", from: workflow.StatusWaitingHuman, action: "reject", want: workflow.StatusClosedWontDo, closesIssue: true},
+ {name: "reject parked", from: workflow.StatusParked, action: "reject", want: workflow.StatusClosedWontDo, closesIssue: true},
+ {name: "reject pr_open", from: workflow.StatusPROpen, action: "reject", want: workflow.StatusClosedWontDo, closesIssue: true},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
@@ -474,8 +475,8 @@ func TestLifecycleSpecificTaskActions(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
- if tc.from != store.StatusQueued {
- if err := srv.Store.Transition(ctx, task.ID, store.StatusQueued, tc.from, "test"); err != nil {
+ if tc.from != workflow.StatusQueued {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusQueued, tc.from, "test"); err != nil {
t.Fatal(err)
}
}
@@ -485,7 +486,7 @@ func TestLifecycleSpecificTaskActions(t *testing.T) {
t.Cleanup(bus.Close)
srv.Events = bus
sub := bus.Subscribe(1)
- if tc.action == "stop" || (tc.action == "reject" && tc.from == store.StatusRunning) {
+ if tc.action == "stop" || (tc.action == "reject" && tc.from == workflow.StatusRunning) {
setTaskStopper(t, srv, &recordingTaskStopper{result: tc.stopperResult})
}
if w := postAction(t, srv, task.ID, tc.action); w.Code != http.StatusOK {
@@ -521,7 +522,7 @@ func TestArchiveRemovesOnlyOneTerminalTask(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
- if err := srv.Store.Transition(ctx, task.ID, store.StatusQueued, store.StatusMerged, "done"); err != nil {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusMerged, "done"); err != nil {
t.Fatal(err)
}
}
@@ -570,7 +571,7 @@ func TestArchiveRemovesTheTaskLogDirectory(t *testing.T) {
t.Fatal(err)
}
task, _ := srv.Store.TaskByIssue(ctx, "acme", "widget", 1)
- if err := srv.Store.Transition(ctx, task.ID, store.StatusQueued, store.StatusMerged, "done"); err != nil {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusMerged, "done"); err != nil {
t.Fatal(err)
}
@@ -601,7 +602,7 @@ func TestArchiveAuditFailurePreservesTaskAndFailsRequest(t *testing.T) {
t.Fatal(err)
}
task, _ := srv.Store.TaskByIssue(ctx, "acme", "widget", 1)
- if err := srv.Store.Transition(ctx, task.ID, store.StatusQueued, store.StatusMerged, "done"); err != nil {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusQueued, workflow.StatusMerged, "done"); err != nil {
t.Fatal(err)
}
base := srv.Store
diff --git a/internal/webui/api_tasks_test.go b/internal/webui/api_tasks_test.go
index 362c96b83..ee2945f24 100644
--- a/internal/webui/api_tasks_test.go
+++ b/internal/webui/api_tasks_test.go
@@ -16,8 +16,8 @@ import (
"testing"
"github.com/samcharles93/archie-core/internal/config"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
- "github.com/samcharles93/archie-core/internal/store"
)
func TestTaskURLsUseOwningForgeRoutes(t *testing.T) {
@@ -28,7 +28,7 @@ func TestTaskURLsUseOwningForgeRoutes(t *testing.T) {
Repos: []config.Repo{{Owner: "acme", Name: "widget"}},
}},
})}
- task := store.Task{Owner: "acme", Repo: "widget", IssueNumber: 12, PRNumber: 34, Identity: "gitea"}
+ task := workflow.Task{Owner: "acme", Repo: "widget", IssueNumber: 12, PRNumber: 34, Identity: "gitea"}
repoURL, issueURL, prURL := srv.taskURLs(task)
if repoURL != "https://gitea.example/acme/widget" || issueURL != repoURL+"/issues/12" || prURL != repoURL+"/pulls/34" {
@@ -55,7 +55,7 @@ func TestHandleTaskActionApproveUsesRecordedState(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("claim = (%+v, %v)", task, err)
}
- if err := srv.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusWaitingHuman, "review"); err != nil {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusWaitingHuman, "review"); err != nil {
t.Fatal(err)
}
@@ -71,7 +71,7 @@ func TestHandleTaskActionApproveUsesRecordedState(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != store.StatusQueued || got.Workflow != "implement" {
+ if got.Status != workflow.StatusQueued || got.Workflow != "implement" {
t.Fatalf("approved task = %+v, want queued/implement", got)
}
}
@@ -86,7 +86,7 @@ func TestHandleTaskActionRetriesParkedTask(t *testing.T) {
if err != nil || task == nil {
t.Fatalf("claim = (%+v, %v)", task, err)
}
- if err := srv.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusParked, "failed"); err != nil {
+ if err := srv.Store.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusParked, "failed"); err != nil {
t.Fatal(err)
}
@@ -102,7 +102,7 @@ func TestHandleTaskActionRetriesParkedTask(t *testing.T) {
if err != nil || got == nil {
t.Fatalf("TaskByID = (%+v, %v)", got, err)
}
- if got.Status != store.StatusQueued || got.RetryCount != 1 {
+ if got.Status != workflow.StatusQueued || got.RetryCount != 1 {
t.Fatalf("retried task = %+v, want queued/retry_count=1", got)
}
}
diff --git a/internal/webui/webui_test.go b/internal/webui/webui_test.go
index 8f43f5c14..360be516e 100644
--- a/internal/webui/webui_test.go
+++ b/internal/webui/webui_test.go
@@ -26,6 +26,7 @@ import (
"testing"
"time"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/store"
)
@@ -54,7 +55,7 @@ type stubStore struct {
requeueErr error
}
-func (s *stubStore) TaskByID(ctx context.Context, id int64) (*store.Task, error) {
+func (s *stubStore) TaskByID(ctx context.Context, id int64) (*workflow.Task, error) {
if s.taskByIDErr != nil {
return nil, s.taskByIDErr
}
@@ -210,7 +211,7 @@ func TestHandleTasks(t *testing.T) {
if w.Code != http.StatusOK {
t.Fatalf("status = %d, body = %s", w.Code, w.Body)
}
- var got []store.Task
+ var got []workflow.Task
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
t.Fatal(err)
}
diff --git a/internal/worktreerpc/worktreerpc.go b/internal/worktreerpc/worktreerpc.go
index 03bb992c6..6abf3a621 100644
--- a/internal/worktreerpc/worktreerpc.go
+++ b/internal/worktreerpc/worktreerpc.go
@@ -22,8 +22,8 @@ import (
"github.com/nats-io/nats.go"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/natsrpc"
- "github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/worktree"
)
@@ -69,7 +69,7 @@ type Grants struct {
func NewGrants() *Grants { return &Grants{grants: make(map[string]grant)} }
// Issue creates a per-dispatch grant and a revocation function.
-func (g *Grants) Issue(task *store.Task) (string, func(), error) {
+func (g *Grants) Issue(task *workflow.Task) (string, func(), error) {
if task == nil || task.ID <= 0 || task.Branch == "" ||
!worktree.ValidCoordinates(task.Owner, task.Repo, task.IssueNumber) {
return "", nil, errors.New("task is not ready for worktree publication")
diff --git a/internal/worktreerpc/worktreerpc_test.go b/internal/worktreerpc/worktreerpc_test.go
index 553563629..472a71cef 100644
--- a/internal/worktreerpc/worktreerpc_test.go
+++ b/internal/worktreerpc/worktreerpc_test.go
@@ -16,7 +16,7 @@ import (
natssrv "github.com/nats-io/nats-server/v2/test"
"github.com/nats-io/nats.go"
- "github.com/samcharles93/archie-core/internal/store"
+ "github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/worktree"
)
@@ -196,7 +196,7 @@ func TestClientPushPublishesViaServer(t *testing.T) {
url := srv.ClientURL()
grants := NewGrants()
- token, revoke, err := grants.Issue(&store.Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 1, Branch: branch})
+ token, revoke, err := grants.Issue(&workflow.Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 1, Branch: branch})
if err != nil {
t.Fatal(err)
}
@@ -261,7 +261,7 @@ func TestSubjectFor(t *testing.T) {
func TestGrantIsScopedAndRevocable(t *testing.T) {
grants := NewGrants()
- token, revoke, err := grants.Issue(&store.Task{
+ token, revoke, err := grants.Issue(&workflow.Task{
ID: 1, Identity: "winter", Owner: "acme", Repo: "widget",
IssueNumber: 7, Branch: "feat/7-widget",
})
@@ -282,7 +282,7 @@ func TestGrantIsScopedAndRevocable(t *testing.T) {
func TestGrantRejectsIncompleteTask(t *testing.T) {
grants := NewGrants()
- for _, task := range []*store.Task{
+ for _, task := range []*workflow.Task{
nil,
{ID: 1, Owner: "../escape", Repo: "widget", IssueNumber: 7, Branch: "feat/7-widget"},
{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 7},