739b67856a
Build / build (push) Successful in 10m39s
The clean-break delete that closes the workload-first refactor arc.
Net diff: ~30 backend files deleted, ~20 modified, ~12k LOC removed
on the Go side; entire /projects /stacks /sites /deploy frontend
trees gone; ~6.7k LOC removed on the Svelte/TypeScript side.
Backend
- API handlers gone: internal/api/{projects,stages,stage_env,stacks,
static_sites,deploys,instances,volume_browser}.go
- Store CRUD + tests gone: internal/store/{projects,stages,stage_env,
stacks,static_sites,static_site_secrets,deploys,poll_state,volumes,
workload_sync}.go (+ _test.go siblings)
- Legacy deployer pipeline gone: internal/deployer/{bluegreen,promote,
rollback,subdomain,resolver_test}.go; deployer.go trimmed to just the
dispatch surface used by the plugin pipeline
- internal/staticsite/{manager,healthcheck}.go and
internal/stack/manager.go gone (the rest of those packages stay as
helpers imported by the static + compose plugins)
- internal/registry/poller.go gone (legacy registry poller)
- internal/volume.ResolvePath gone; ResolveWorkloadPath stays
- internal/webhook: handleWebhook (project) + handleSiteWebhook (site)
gone; only POST /api/webhook/triggers/{secret} remains
- workload-side webhook URL handlers (getWorkloadWebhook +
regenerateWorkloadWebhook + EnsureWorkloadWebhookSecret +
SetWorkloadWebhookSecret + GetWorkloadByWebhookSecret) gone — they
minted URLs that would 404 against the new trigger-only ingress
- cmd/server/main.go: dropped staticsite.Manager, stack.Manager,
staticsite.HealthChecker, registry poller, SetSiteSyncTriggerer,
SetStaticSiteManager, SetStackManager, wireStaticBackend
- store/store.go: idempotent DROP TABLE IF EXISTS for every legacy
table (projects, stages, stage_env, volumes, deploys, deploy_logs,
poll_states, stacks, stack_revisions, stack_deploys, static_sites,
static_site_secrets); FK order children-then-parents
- store/models.go: dropped Project, Stage, Deploy, DeployLog, StageEnv,
Volume, StaticSite, StaticSiteSecret, Stack, StackRevision,
StackDeploy types; kept WorkloadKind constants as documented strings
- internal/store/helpers.go (new): BoolToInt, rowScanner,
GenerateWebhookSecret extracted from deleted CRUD files
- internal/api/secrets.go (new): forwards to store.GenerateWebhookSecret
so api + store paths share one secret-generation impl (no
panic-vs-UUID-fallback divergence)
- internal/reconciler/reconciler.go: dropped legacy stack-by-compose
+ static-site label paths; only canonical tinyforge.workload.id
dispatch remains
- providers (gitea_content/github_provider/gitlab_provider) gained
path-traversal rejection on every tree entry
- internal/webhook ParsedImage / ParseImageRef demoted to package-
private (no external callers)
Frontend
- /projects /stacks /sites /deploy routes deleted (entire trees)
- ProjectCard / InstanceCard / StaleContainerCard components deleted
- api.ts: dropped every project/stage/stack/site/deploy/instance
helper + types (Project, Stage, Stack, StaticSite, Deploy,
Instance, Volume, etc.); kept Workload, Container, App, Settings,
Registry, EventTrigger, LogScanRule, webhook envelopes
- WorkloadWebhook type + getWorkloadWebhook/regenerateWorkloadWebhook
api functions gone (mirror of the backend deletion above)
- web/src/routes/+layout.svelte: dropped /projects /sites /stacks
/deploy nav entries, trimmed quick-nav keymap
- web/src/routes/+page.svelte: dashboard rewrite — reads
listWorkloads + listContainers only; 4-card stat grid
(workloads/running/failed/stale) + recent workloads strip
- navCounts.ts, SystemHealthCard.svelte, ContainerLogs.svelte,
ContainerStats.svelte, StatusBadge.svelte, TagCombobox.svelte,
proxies/+page.svelte, containers/+page.svelte all rewired to the
workload-first surface
- AbortController plumbing on dashboard, nav-counts, stale page,
SystemHealthCard so navigation doesn't leave dangling fetches
- i18n: dropped projects.*, projectDetail.*, envEditor.*,
volumeEditor.*, volumeBrowser.*, quickDeploy.*, sites.*, stacks.*,
instance.*, confirm.* namespaces; en/ru parity preserved (1042
keys each)
Hardening from go-reviewer + security-reviewer + typescript-reviewer
subagent passes (0 CRITICAL across all three; 1 HIGH + ~12 MEDIUM
addressed inline before commit):
- Sec H1: dead-end workload webhook URL handlers (would mint URLs
that 404 the new trigger-only ingress) deleted across backend +
frontend
- Go M1: IsTerminalDeployStatus dropped (no production callers)
- Go M2: ParsedImage/ParseImageRef lowercased (in-package only)
- Go M6: generateWebhookSecret unified — api shim forwards to
store.GenerateWebhookSecret
- Doc/comment freshness: stage_id (no longer FK), ProxyRoute legacy
field names, workloadIDRow rationale, webhook_deliveries.target_type
enum, WebhookDeliveryLog component header
Doc
- WORKLOAD_REFACTOR_TODO: cutover marked DONE; all three Priority 1
items are now shipped. Next focus is Priority 3 polish (apps.* i18n
+ codemap entries) and Priority 4 tests.
Behavioral notes for operators upgrading from a pre-cutover build
- Existing rows in the dropped tables disappear on first boot.
- Legacy webhook URLs at /api/webhook/{secret} and
/api/webhook/sites/{secret} return 404; CI configs must repoint to
/api/webhook/triggers/{secret} (the trigger-split boot backfill
lifted any embedded workload secret onto a Trigger row, so the
secret value itself carries over).
- Frontend routes /projects /stacks /sites /deploy are gone; nav
links replaced with /apps and /triggers.
132 lines
3.6 KiB
Go
132 lines
3.6 KiB
Go
package store
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestCreateAndGetWorkload(t *testing.T) {
|
|
s := newTestStore(t)
|
|
|
|
w, err := s.CreateWorkload(Workload{
|
|
Kind: string(WorkloadKindProject), RefID: "proj-1", Name: "test-workload",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateWorkload: %v", err)
|
|
}
|
|
if w.ID == "" {
|
|
t.Fatal("workload ID should be set")
|
|
}
|
|
|
|
got, err := s.GetWorkloadByID(w.ID)
|
|
if err != nil {
|
|
t.Fatalf("GetWorkloadByID: %v", err)
|
|
}
|
|
if got.Name != "test-workload" || got.Kind != "project" || got.RefID != "proj-1" {
|
|
t.Fatalf("got %+v, want kind=project ref=proj-1 name=test-workload", got)
|
|
}
|
|
}
|
|
|
|
func TestGetWorkloadByRef(t *testing.T) {
|
|
s := newTestStore(t)
|
|
|
|
_, err := s.CreateWorkload(Workload{
|
|
Kind: string(WorkloadKindStack), RefID: "stack-42", Name: "compose-app",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateWorkload: %v", err)
|
|
}
|
|
|
|
got, err := s.GetWorkloadByRef(WorkloadKindStack, "stack-42")
|
|
if err != nil {
|
|
t.Fatalf("GetWorkloadByRef: %v", err)
|
|
}
|
|
if got.Name != "compose-app" {
|
|
t.Fatalf("got name %q, want compose-app", got.Name)
|
|
}
|
|
|
|
if _, err := s.GetWorkloadByRef(WorkloadKindProject, "stack-42"); !errors.Is(err, ErrNotFound) {
|
|
t.Fatalf("wrong-kind lookup should be NotFound, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestUniqueKindRefID(t *testing.T) {
|
|
s := newTestStore(t)
|
|
|
|
if _, err := s.CreateWorkload(Workload{Kind: "project", RefID: "p1", Name: "a"}); err != nil {
|
|
t.Fatalf("first insert: %v", err)
|
|
}
|
|
if _, err := s.CreateWorkload(Workload{Kind: "project", RefID: "p1", Name: "dupe"}); err == nil {
|
|
t.Fatal("expected UNIQUE(kind, ref_id) violation, got nil")
|
|
}
|
|
}
|
|
|
|
func TestUpdateWorkload(t *testing.T) {
|
|
s := newTestStore(t)
|
|
|
|
w, _ := s.CreateWorkload(Workload{Kind: "project", RefID: "p1", Name: "original"})
|
|
w.Name = "renamed"
|
|
w.AppID = "app-1"
|
|
w.WebhookRequireSignature = true
|
|
if err := s.UpdateWorkload(w); err != nil {
|
|
t.Fatalf("UpdateWorkload: %v", err)
|
|
}
|
|
|
|
got, _ := s.GetWorkloadByID(w.ID)
|
|
if got.Name != "renamed" {
|
|
t.Fatalf("name not updated: got %q", got.Name)
|
|
}
|
|
if got.AppID != "app-1" {
|
|
t.Fatalf("app_id not updated: got %q", got.AppID)
|
|
}
|
|
if !got.WebhookRequireSignature {
|
|
t.Fatalf("webhook_require_signature not updated")
|
|
}
|
|
}
|
|
|
|
// GetWorkloadByWebhookSecret was deleted with the legacy
|
|
// `/api/webhook/workloads/{secret}` route in the hard cutover; the
|
|
// inbound webhook surface is now first-class Triggers.
|
|
|
|
func TestListWorkloads(t *testing.T) {
|
|
s := newTestStore(t)
|
|
|
|
s.CreateWorkload(Workload{Kind: "project", RefID: "p1", Name: "alpha"})
|
|
s.CreateWorkload(Workload{Kind: "stack", RefID: "s1", Name: "bravo"})
|
|
s.CreateWorkload(Workload{Kind: "project", RefID: "p2", Name: "charlie"})
|
|
|
|
all, err := s.ListWorkloads("")
|
|
if err != nil {
|
|
t.Fatalf("ListWorkloads all: %v", err)
|
|
}
|
|
if len(all) != 3 {
|
|
t.Fatalf("expected 3 workloads, got %d", len(all))
|
|
}
|
|
|
|
projects, err := s.ListWorkloads(WorkloadKindProject)
|
|
if err != nil {
|
|
t.Fatalf("ListWorkloads project: %v", err)
|
|
}
|
|
if len(projects) != 2 {
|
|
t.Fatalf("expected 2 project workloads, got %d", len(projects))
|
|
}
|
|
}
|
|
|
|
func TestDeleteWorkloadByRef(t *testing.T) {
|
|
s := newTestStore(t)
|
|
|
|
w, _ := s.CreateWorkload(Workload{Kind: "project", RefID: "p1", Name: "n"})
|
|
|
|
if err := s.DeleteWorkloadByRef(WorkloadKindProject, "p1"); err != nil {
|
|
t.Fatalf("DeleteWorkloadByRef: %v", err)
|
|
}
|
|
if _, err := s.GetWorkloadByID(w.ID); !errors.Is(err, ErrNotFound) {
|
|
t.Fatalf("expected NotFound after delete, got %v", err)
|
|
}
|
|
|
|
// Idempotent — deleting non-existent ref is fine.
|
|
if err := s.DeleteWorkloadByRef(WorkloadKindProject, "ghost"); err != nil {
|
|
t.Fatalf("DeleteWorkloadByRef should be idempotent: %v", err)
|
|
}
|
|
}
|