diff --git a/Taskfile.yml b/Taskfile.yml index 6fa9eaf54..da0472a3f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -44,16 +44,27 @@ tasks: cmds: - govulncheck ./... - ui: - desc: Build the dashboard into ui/dist (committed; the Go build embeds it) + ui:deps: + desc: Install the dashboard's node dependencies (ui/node_modules is gitignored) + internal: true dir: ui cmds: - npm install --no-audit --no-fund + + ui: + desc: Build the dashboard into ui/dist (committed; the Go build embeds it) + dir: ui + deps: [ui:deps] + cmds: - npm run build test:ui: desc: Run the dashboard's node tests (DOM-building primitives) dir: ui + # Without this, a fresh clone fails the gate on a missing jsdom rather + # than a real test failure: ui/node_modules is gitignored and nothing + # else in `task check` installs it. + deps: [ui:deps] cmds: - npm test diff --git a/internal/app/archied/bootstrap.go b/internal/app/archied/bootstrap.go index 7464cdda8..99ca64f44 100644 --- a/internal/app/archied/bootstrap.go +++ b/internal/app/archied/bootstrap.go @@ -352,10 +352,22 @@ func (b *boot) setupObservability() { // issue is re-polled and the work is done again. It gets only that one // method, not the forge client. b.web.Issues = b.forgeClient - // Capture storage: openProductionTaskStore's declared return type is the - // narrow store.TaskStore, so the CaptureStore surface (implemented by - // the same *store.Store) needs its own assertion here rather than a - // direct field reuse. See docs/prds/event-capture-storage.md. + b.wireWebStoreSurfaces() + sink := bus.Subscribe(256) + go persistAndBroadcastEvents(sink, b.st, b.web, log) +} + +// wireWebStoreSurfaces attaches the dashboard's optional storage surfaces. +// openProductionTaskStore's declared return type is the narrow +// store.TaskStore, so each wider surface (all implemented by the same +// *store.Store) needs its own assertion here rather than a direct field +// reuse. A store that does not implement one degrades that dashboard feature +// with a warning instead of aborting bootstrap. The BindingStore/ +// BindingDispatcher/BindingTaskCreator split keeps each interface under the +// interfacebloat limit. See docs/prds/event-capture-storage.md, +// docs/prds/payload-field-mapping.md and docs/prds/webhook-intake-security.md. +func (b *boot) wireWebStoreSurfaces() { + cfg, log := b.cfg, b.log if cs, ok := b.st.(store.CaptureStore); ok { b.web.Captures = cs } else { @@ -365,21 +377,11 @@ func (b *boot) setupObservability() { b.web.CaptureMaxEvents = cfg.Capture.MaxEvents b.web.CaptureMaxBodyBytes = int64(cfg.Capture.MaxBodyBytes) b.web.CaptureLimiter = webhookguard.NewRateLimiter(cfg.Capture.RatePerSecond, cfg.Capture.RateBurst, time.Now) - // Mapping storage: same narrow-assertion pattern as CaptureStore above, - // for the same reason -- openProductionTaskStore's declared return type - // doesn't expose it. See docs/prds/payload-field-mapping.md. if ms, ok := b.st.(store.MappingStore); ok { b.web.Mappings = ms } else { log.Warn("mapping storage unavailable: task store does not implement MappingStore") } - // Binding storage: same narrow-assertion pattern as CaptureStore/MappingStore - // above, for the same reason. The daemon arm/dispatch logic is wired in - // Phase E; here only the storage handle is shared so /api/bindings has - // somewhere to read/write. The BindingStore/BindingDispatcher/ - // BindingTaskCreator split keeps each interface under the - // interfacebloat limit; the concrete *store.Store satisfies all three. - // See docs/prds/webhook-intake-security.md. if bs, ok := b.st.(store.BindingStore); ok { b.web.Bindings = bs } else { @@ -390,8 +392,6 @@ func (b *boot) setupObservability() { } else { log.Warn("binding dispatcher unavailable: task store does not implement BindingDispatcher") } - sink := bus.Subscribe(256) - go persistAndBroadcastEvents(sink, b.st, b.web, log) } // connectNATS opens the NATS client. External mode dials cfg.NATS.URL; @@ -413,25 +413,11 @@ func (b *boot) connectNATS(ctx context.Context) error { return err } } else { - // Embedded. Start the in-process server before dialing, and register - // its shutdown BEFORE the client close below so the client closes - // first (cleanups run LIFO). - host := "" - if b.containerPool != nil { - host = b.containerPool.HostGateway() - } - srv, err := nats.StartEmbedded(ctx, nats.EmbeddedOptions{ - Host: host, - StoreDir: filepath.Join(filepath.Dir(cfg.DBPath), "nats"), - }, log) + var err error + url, natsToken, err = b.startEmbeddedNATS(ctx) if err != nil { - log.Error("embedded nats start failed", "err", err) return err } - b.addCleanup(func() { srv.Shutdown() }) - url = srv.ClientURL() - natsToken = srv.Token() - log.Info("embedded nats started", "url", url) } // Composition owns the subject list: the bus must not know which @@ -454,6 +440,28 @@ func (b *boot) connectNATS(ctx context.Context) error { return nil } +// startEmbeddedNATS starts the in-process nats-server and returns the client +// URL and token to dial it with. Its shutdown is registered BEFORE the caller +// registers the client close, so the client closes first (cleanups run LIFO). +func (b *boot) startEmbeddedNATS(ctx context.Context) (string, string, error) { + cfg, log := b.cfg, b.log + host := "" + if b.containerPool != nil { + host = b.containerPool.HostGateway() + } + srv, err := nats.StartEmbedded(ctx, nats.EmbeddedOptions{ + Host: host, + StoreDir: filepath.Join(filepath.Dir(cfg.DBPath), "nats"), + }, log) + if err != nil { + log.Error("embedded nats start failed", "err", err) + return "", "", err + } + b.addCleanup(func() { srv.Shutdown() }) + log.Info("embedded nats started", "url", srv.ClientURL()) + return srv.ClientURL(), srv.Token(), nil +} + // setupContainers builds the managed autonomous-worker pool. Failure degrades // rather than aborting because the native interactive agent and dashboard do // not require Docker; repository tasks park instead of falling back to a host diff --git a/internal/app/archied/shutdown_watchdog_test.go b/internal/app/archied/shutdown_watchdog_test.go index 62df797e6..c9b119cd8 100644 --- a/internal/app/archied/shutdown_watchdog_test.go +++ b/internal/app/archied/shutdown_watchdog_test.go @@ -1,7 +1,6 @@ package archied import ( - "context" "log/slog" "testing" "time" @@ -73,8 +72,7 @@ func TestShutdownWatchdogCompletingWithinLeashDoesNotExit(t *testing.T) { // needed. func TestBootStartShutdownWatchdogDisarmRunsLast(t *testing.T) { b := newBootstrap() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + ctx := t.Context() b.startShutdownWatchdog(ctx) if len(b.cleanups) != 1 { diff --git a/internal/app/archied/telegram_setup_test.go b/internal/app/archied/telegram_setup_test.go index 8742e6694..b0cbe36d3 100644 --- a/internal/app/archied/telegram_setup_test.go +++ b/internal/app/archied/telegram_setup_test.go @@ -1,7 +1,6 @@ package archied import ( - "os" "testing" "github.com/samcharles93/archie-core/internal/config" @@ -61,8 +60,7 @@ func TestResolveTelegramTokenDoesNotUseTokenEnvWhenSecretRefIsSet(t *testing.T) Token: secret.SecretRef{Engine: "bws", Key: "telegram-token"}, TokenEnv: "TELEGRAM_LEGACY_TOKEN", } - os.Setenv("TELEGRAM_LEGACY_TOKEN", "token-from-env") - t.Cleanup(func() { os.Unsetenv("TELEGRAM_LEGACY_TOKEN") }) + t.Setenv("TELEGRAM_LEGACY_TOKEN", "token-from-env") got, err := resolveTelegramToken(cfg, registry) if err != nil { diff --git a/internal/releaseupdate/install_script_test.go b/internal/releaseupdate/install_script_test.go index 1b7b2fae1..4cbcc8d57 100644 --- a/internal/releaseupdate/install_script_test.go +++ b/internal/releaseupdate/install_script_test.go @@ -140,7 +140,7 @@ func TestUpdateWatchdogRestoresTaskDatabaseOnDaemonRollback(t *testing.T) { } } for path, version := range map[string]int{dbPath: 2, backupPath: 1} { - if output, err := exec.Command("sqlite3", path, fmt.Sprintf("PRAGMA user_version=%d; CREATE TABLE tasks (id INTEGER);", version)).CombinedOutput(); err != nil { + if output, err := exec.CommandContext(t.Context(), "sqlite3", path, fmt.Sprintf("PRAGMA user_version=%d; CREATE TABLE tasks (id INTEGER);", version)).CombinedOutput(); err != nil { t.Fatalf("create database %s: %v: %s", path, err, output) } } @@ -157,7 +157,7 @@ func TestUpdateWatchdogRestoresTaskDatabaseOnDaemonRollback(t *testing.T) { if output, err := cmd.CombinedOutput(); err != nil { t.Fatalf("watchdog failed: %v\n%s", err, output) } - output, err := exec.Command("sqlite3", dbPath, "PRAGMA user_version;").Output() + output, err := exec.CommandContext(t.Context(), "sqlite3", dbPath, "PRAGMA user_version;").Output() if err != nil { t.Fatal(err) }