ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)
Go aiai-agentsautonomous-agentsbug-bountydockergolanglinuxllmmcpnextjspenetration-testingpentestpostgresqlreareactred-teamsecuritysecurity-automationsqlitetypescript
Refactor PostgreSQL test skipping logic
Alexandrelab-200db0aae365755
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex f949165..320b606 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -125,7 +125,7 @@ jobs:# shellcheck is preinstalled on the ubuntu runners. -S warning: the scripts# currently have only info-level notes (intentional A && B || C chains in# update.sh, an unquoted glob in backup.sh's prune), so fail on warnings.- - run: shellcheck -S warning install.sh update.sh start.sh scripts/backup.sh reset-password.sh scripts/extract-changelog-section.sh scripts/test-extract-changelog-section.sh .github/scripts/bot.sh scripts/test-bot-context.sh+ - run: shellcheck -S warning install.sh update.sh start.sh scripts/backup.sh scripts/verify.sh reset-password.sh scripts/extract-changelog-section.sh scripts/test-extract-changelog-section.sh .github/scripts/bot.sh scripts/test-bot-context.sh- run: bash scripts/test-extract-changelog-section.sh# The triage bot's repository summary must expose every top-level# directory; a truncated file list once made it deny that docs/ anddiff --git a/README.md b/README.mdindex 307a035..b44fd9c 100644--- a/README.md+++ b/README.md@@ -651,6 +651,7 @@ CGO_ENABLED=0 go build -tags embedui -o artex ./cmd/artex- Backend: `go run ./cmd/artex` (without `-tags embedui`, the frontend is not embedded)- Frontend: `cd web && npm run dev` (`/api` is reverse-proxied to the backend, with hot reload)- Tests: `go test ./...`+- Reproduce all CI checks locally: `./scripts/verify.sh` (add `--full` for `-race` and the static web build)- Mock preview (no backend): `cd web && NEXT_PUBLIC_MOCK=1 npm run dev`---@@ -718,6 +719,10 @@ flowchart TB| **db** | PostgreSQL persistence (pgx); embedded schema and numbered migrations applied at startup || **Supporting** | Recording MITM proxy, approval gate, async enrichment, MCP/skills/memory/report |+For the code-level map (execution flow, trust boundaries, decisions) see+[docs/ARCHITECTURE.md](docs/ARCHITECTURE.md); for startup, configuration precedence,+backup and key rotation see [docs/OPS.md](docs/OPS.md).+---## Securitydiff --git a/agent/blackboard_inheritance_test.go b/agent/blackboard_inheritance_test.goindex 94c099f..def03eb 100644--- a/agent/blackboard_inheritance_test.go+++ b/agent/blackboard_inheritance_test.go@@ -26,7 +26,15 @@ func callReadJSON(t *testing.T, tool actool.CoreTool, input string) any {}func TestGraphOverviewExpandsAssociatedCompanyScope(t *testing.T) {- t.Skip("known failure with a fresh database, pre-existing on unmodified upstream; tracked in BaaRai/ARTEX#9")+ // Known failure with a freshly seeded database (BaaRai/ARTEX#9). Repro:+ // ARTEX_PG_DSN=postgres://artex:testpass@localhost:5432/artextest_agent \+ // go test ./agent -run TestGraphOverviewExpandsAssociatedCompanyScope -count=1 -v+ // On a fresh DB the company-scope expansion in graphOverviewData is not+ // visible to the task: the t.Fatalf checks after QueryByTask and+ // graphOverviewData (company asset linkage, company_scope rows and+ // company_keywords) fail. Keep the skip until seeding is ordered correctly;+ // do not delete it.+ t.Skip("known failure with a fresh database; repro and failing assertions documented above; BaaRai/ARTEX#9")d := testDB(t)defer d.Close()diff --git a/agent/capture_approval_test.go b/agent/capture_approval_test.goindex 9d96fbd..24369c4 100644--- a/agent/capture_approval_test.go+++ b/agent/capture_approval_test.go@@ -17,10 +17,17 @@ import (// Exercise the actual SDK event -> hook -> execution -> result path. No real// model or command is used; the probe tool only returns a fixed string.func TestCaptureApprovalLifecycle(t *testing.T) {- t.Skip("known failure with a fresh database, pre-existing on unmodified upstream; tracked in BaaRai/ARTEX#9")+ // Known failure with a freshly seeded database (BaaRai/ARTEX#9). Repro:+ // ARTEX_PG_DSN=postgres://artex:testpass@localhost:5432/artextest_agent \+ // go test ./agent -run TestCaptureApprovalLifecycle -count=1 -v+ // The checks after ListTaskIntercepts / GetInterceptDetail and the+ // "unexpected review" t.Fatalf below fail before any other test has seeded+ // intercept state. Keep this skipped until the fresh-DB setup is fixed;+ // do not simply delete the skip.+ t.Skip("known failure with a fresh database; repro and failing assertion documented above; BaaRai/ARTEX#9")dsn, _, err := db.DSN()if err != nil {- t.Skip("no test database configured")+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/agent/insert_assets_test.go b/agent/insert_assets_test.goindex a852f24..03021af 100644--- a/agent/insert_assets_test.go+++ b/agent/insert_assets_test.go@@ -15,11 +15,11 @@ func testDB(t *testing.T) *db.DB {t.Helper()dsn, _, err := db.DSN()if err != nil {- t.Skipf("no database config (%v)", err)+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}return d}diff --git a/agent/review_context_test.go b/agent/review_context_test.goindex b990959..5470788 100644--- a/agent/review_context_test.go+++ b/agent/review_context_test.go@@ -19,7 +19,7 @@ import (func TestWorkerReviewContextAcrossToolCalls(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skip("no test database configured")+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/agent/untrusted_boundary.go b/agent/untrusted_boundary.goindex 47141b9..41e5df6 100644--- a/agent/untrusted_boundary.go+++ b/agent/untrusted_boundary.go@@ -5,6 +5,11 @@ import ("strings")+// UntrustedBoundaryEnabled reports whether the untrusted-output boundary is on.+// Exported for the startup configuration snapshot; the agents themselves keep+// calling the private helper below.+func UntrustedBoundaryEnabled() bool { return untrustedBoundaryEnabled() }+// untrustedBoundaryEnabled reports whether Norma's untrusted-output boundary// (agentcore.Options.UntrustedOutputBoundary: tool results framed between// nonce-tagged markers) is on. It is on by default: unset, empty or any otherdiff --git a/cmd/artex/main.go b/cmd/artex/main.goindex 1cba3d4..25cb8d9 100644--- a/cmd/artex/main.go+++ b/cmd/artex/main.go@@ -5,6 +5,7 @@ package mainimport ("context"+ "encoding/json""flag""fmt""log"@@ -18,9 +19,41 @@ import ("github.com/Autumn-27/artex/agent""github.com/Autumn-27/artex/config"+ "github.com/Autumn-27/artex/egress""github.com/Autumn-27/artex/server")+// configSnapshot is the single startup log line describing the effective+// configuration. It carries no credential material: the DSN is passed through+// config.Redact, and no key or token value is ever included.+type configSnapshot struct {+ Version string `json:"version"`+ ConfigFile string `json:"config_file"`+ ConfigFileFound bool `json:"config_file_found"`+ PGDSN string `json:"pg_dsn"`+ PGDSNSource string `json:"pg_dsn_source"`+ DataDir string `json:"data_dir"`+ SkillDir string `json:"skill_dir"`+ KeyDir string `json:"key_dir"`+ Addr string `json:"addr"`+ Proxy string `json:"proxy"`+ NoiseProfile string `json:"noise_profile"`+ UntrustedBoundary bool `json:"untrusted_boundary"`+ TrustedProxies []string `json:"trusted_proxies"`+}++// logConfigSnapshot emits one structured line so an operator can reproduce the+// exact configuration of a run from the logs. A serialization failure is+// reported but never aborts startup.+func logConfigSnapshot(s configSnapshot) {+ b, err := json.Marshal(s)+ if err != nil {+ log.Printf("[config] snapshot unavailable: %v", err)+ return+ }+ log.Printf("[config] snapshot %s", b)+}+// version is the build version, injected at release time via// -ldflags "-X main.version=<tag>". Defaults to "dev" for local builds.var version = "dev"@@ -65,50 +98,71 @@ func run() int {// page can show a live log stream. Do this first, to catch startup logs too.server.StartLogCapture()- // surface which config file the binary reads (absolute, so `go run`'s relative- // "config.json" — resolved against the CWD — is unambiguous).- cfgPath := config.Path()+ // Resolve every effective setting before starting the stores, then emit a+ // single structured snapshot line. The old code logged the same facts in+ // five scattered lines, which made a run hard to reproduce from logs.+ cfgPath := config.Path() // absolute, so `go run`'s relative CWD is unambiguousif abs, e := filepath.Abs(cfgPath); e == nil {cfgPath = abs}- if _, e := os.Stat(cfgPath); e == nil {- log.Printf("[config] config file: %s", cfgPath)- } else {- log.Printf("[config] config file: %s (not found — will only try the environment variable ARTEX_PG_DSN)", cfgPath)- }-- sigCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)- defer stop()- ctx, shutdown := shutdownContext(sigCtx)- defer shutdown(agent.AbortShutdown)-- mgr, err := server.NewManager(*dataDir, *proxy)- if err != nil {- log.Fatalf("open stores: %v", err)- }- defer mgr.Close()+ _, statErr := os.Stat(cfgPath)+ cfgFound := statErr == nilskillDir, err := config.SkillDir()if err != nil {log.Printf("[config] %v", err)return 1}- if abs, err := filepath.Abs(skillDir); err == nil {+ if abs, e := filepath.Abs(skillDir); e == nil {skillDir = abs}- log.Printf("[config] skill directory: %s", skillDir)// JWT signing key directory (also holds secret.key, see server.NewManager).keyDir := config.KeyDir()- log.Printf("[config] JWT key directory: %s", keyDir)// Proxies whose X-Forwarded-For the login rate limit reads; empty trusts none.trusted, err := server.ParseTrustedProxies(os.Getenv("ARTEX_TRUSTED_PROXIES"))if err != nil {log.Printf("[config] ARTEX_TRUSTED_PROXIES: %v", err)return 1}- if len(trusted) > 0 {- log.Printf("[config] trusted proxies: %v", trusted)+ trustedAddrs := make([]string, 0, len(trusted))+ for _, p := range trusted {+ trustedAddrs = append(trustedAddrs, p.String())+ }++ // NewManager resolves the DSN too, but does so internally. Calling+ // PostgresDSN here is idempotent (no connection, no side effects) and lets+ // the snapshot show the source and a redacted view even on a failed start.+ dsn, dsnSource, dsnErr := config.PostgresDSN()+ if dsnErr != nil {+ dsn, dsnSource = "", "unavailable"+ }+ logConfigSnapshot(configSnapshot{+ Version: version,+ ConfigFile: cfgPath,+ ConfigFileFound: cfgFound,+ PGDSN: config.Redact(dsn),+ PGDSNSource: dsnSource,+ DataDir: *dataDir,+ SkillDir: skillDir,+ KeyDir: keyDir,+ Addr: *addr,+ Proxy: *proxy,+ NoiseProfile: egress.ProfileFromEnv().Name,+ UntrustedBoundary: agent.UntrustedBoundaryEnabled(),+ TrustedProxies: trustedAddrs,+ })++ sigCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)+ defer stop()+ ctx, shutdown := shutdownContext(sigCtx)+ defer shutdown(agent.AbortShutdown)++ mgr, err := server.NewManager(*dataDir, *proxy)+ if err != nil {+ log.Fatalf("open stores: %v", err)}+ defer mgr.Close()+srv := server.New(ctx, mgr, skillDir, *dataDir, keyDir, server.WithSecretScrub(), server.WithTrustedProxies(trusted))// ReadTimeout bounds how long the request headers and body may take to arrive.// It does not limit how long a handler runs, so an event stream stays open.diff --git a/cmd/artex/main_test.go b/cmd/artex/main_test.goindex 5e63227..0953647 100644--- a/cmd/artex/main_test.go+++ b/cmd/artex/main_test.go@@ -2,11 +2,37 @@ package mainimport ("context"+ "encoding/json"+ "strings""testing""github.com/Autumn-27/artex/agent"+ "github.com/Autumn-27/artex/config")+// The startup snapshot is meant to be safe to paste into an issue: no DSN+// password may survive redaction.+func TestConfigSnapshotRedactsDSNPassword(t *testing.T) {+ s := configSnapshot{+ Version: "test",+ ConfigFileFound: true,+ PGDSN: config.Redact("postgres://artex:super-secret@localhost:5432/artex?sslmode=disable"),+ PGDSNSource: "environment variable ARTEX_PG_DSN",+ TrustedProxies: []string{},+ }+ b, err := json.Marshal(s)+ if err != nil {+ t.Fatal(err)+ }+ out := string(b)+ if strings.Contains(out, "super-secret") {+ t.Fatalf("DSN password leaked into snapshot: %s", out)+ }+ if !strings.Contains(out, "****") {+ t.Fatalf("redaction marker missing from snapshot: %s", out)+ }+}+// The shutdown cause must survive the parent context being cancelled first;// losing it would drop the diagnostic on every graceful stop.func TestShutdownContextPreservesNamedCause(t *testing.T) {diff --git a/db/activity_outbox_test.go b/db/activity_outbox_test.goindex a27deb3..3d088d7 100644--- a/db/activity_outbox_test.go+++ b/db/activity_outbox_test.go@@ -20,7 +20,7 @@ func TestActivityOutboxKeepsDetail(t *testing.T) {func TestFlushActivityOutboxReplaysOnce(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()expID, err := d.CreateExploration("outbox", "replay")@@ -63,7 +63,7 @@ func TestFlushActivityOutboxReplaysOnce(t *testing.T) {func TestFlushActivityOutboxDropsStuckRow(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()const missing = int64(9_000_000_000_001)diff --git a/db/activity_page_test.go b/db/activity_page_test.goindex a1022de..3d90840 100644--- a/db/activity_page_test.go+++ b/db/activity_page_test.go@@ -8,7 +8,7 @@ import "testing"func TestActivityPageSessions(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -129,7 +129,7 @@ func TestActivityPageSessions(t *testing.T) {func TestListByKindPage(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/assets_test.go b/db/assets_test.goindex d1f7f24..762a08e 100644--- a/db/assets_test.go+++ b/db/assets_test.go@@ -14,7 +14,7 @@ func testSetup(t *testing.T) (*DB, *AssetStore, *CompanyStore) {t.Helper()d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}return d, d.Assets(), d.Companies()}diff --git a/db/browser_mcp_test.go b/db/browser_mcp_test.goindex 5786c49..01a0964 100644--- a/db/browser_mcp_test.go+++ b/db/browser_mcp_test.go@@ -168,7 +168,7 @@ func TestRewriteStockNpxBrowserMCPDoesNotAliasInput(t *testing.T) {func TestSeedAndMigrateBrowserMCP(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}origCmd, _, origRaw := readBrowserMCP(t, d)diff --git a/db/companies_test.go b/db/companies_test.goindex 25ee77a..111d73e 100644--- a/db/companies_test.go+++ b/db/companies_test.go@@ -17,7 +17,7 @@ func cleanupCompany(d *DB, id int64) {func TestCompanyUpsertAndGet(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -64,7 +64,7 @@ func TestCompanyUpsertAndGet(t *testing.T) {func TestCreateCompanyWithScopeRejectsNormalizedDuplicate(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -103,7 +103,7 @@ func TestCreateCompanyWithScopeRejectsNormalizedDuplicate(t *testing.T) {func TestCreateCompanyWithScopeRollsBackOnScopeWriteFailure(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -128,7 +128,7 @@ func TestCreateCompanyWithScopeRollsBackOnScopeWriteFailure(t *testing.T) {func TestCompanyScope(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -166,7 +166,7 @@ func TestCompanyScope(t *testing.T) {func TestCompanyScopeInvalid(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -195,7 +195,7 @@ func TestCompanyScopeInvalid(t *testing.T) {func TestResolveCompany(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -236,7 +236,7 @@ func TestResolveCompany(t *testing.T) {func TestUpdateScope(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -281,7 +281,7 @@ func TestUpdateScope(t *testing.T) {func TestUpdateScopeRollsBackOnInsertFailure(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -316,7 +316,7 @@ func TestUpdateScopeRollsBackOnInsertFailure(t *testing.T) {func TestDeleteCompany(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -344,7 +344,7 @@ func TestDeleteCompany(t *testing.T) {func TestDeleteCompanyWithAssetsDeletesBoth(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -391,7 +391,7 @@ RETURNING id`, domain, id).Scan(&assetID); err != nil {func TestRecomputeAttribution(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()@@ -433,7 +433,7 @@ func TestRecomputeAttribution(t *testing.T) {func TestListCompanies(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()cs := d.Companies()diff --git a/db/company_scope_consistency_test.go b/db/company_scope_consistency_test.goindex 8ce0c96..e2d7014 100644--- a/db/company_scope_consistency_test.go+++ b/db/company_scope_consistency_test.go@@ -233,7 +233,7 @@ func TestCompanyScopeLimitsAndCheckedErrors(t *testing.T) {func TestCompanyScopeCheckedReturnsSystemErrorSeparately(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}companies := d.Companies()if err := d.Close(); err != nil {diff --git a/db/company_scope_test.go b/db/company_scope_test.goindex 32ddd02..77e225d 100644--- a/db/company_scope_test.go+++ b/db/company_scope_test.go@@ -233,7 +233,7 @@ func TestParseStructuredCompanyScope(t *testing.T) {func TestCompanyICPAttribution(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Closing the connection must go through t.Cleanup and be **registered before// the data cleanup**: t.Cleanup is last-in-first-out, so registering Close@@ -322,7 +322,7 @@ func TestCompanyICPAttribution(t *testing.T) {func TestCompanyScopeAttribution(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}as := d.Assets()cs := d.Companies()diff --git a/db/config_max_tokens_test.go b/db/config_max_tokens_test.goindex 4406fc1..7f157b2 100644--- a/db/config_max_tokens_test.go+++ b/db/config_max_tokens_test.go@@ -9,7 +9,7 @@ import "testing"func TestProfileMaxTokensRoundTrip(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Close via Cleanup, registered FIRST so it runs LAST: cleanups are LIFO, and a// plain `defer d.Close()` would fire before them — the row-deleting cleanups@@ -77,7 +77,7 @@ func TestProfileMaxTokensRoundTrip(t *testing.T) {func TestProfileMaxTokensDefaults(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Close via Cleanup, registered FIRST so it runs LAST: cleanups are LIFO, and a// plain `defer d.Close()` would fire before them — the row-deleting cleanupsdiff --git a/db/config_test.go b/db/config_test.goindex a9376fa..4d848f0 100644--- a/db/config_test.go+++ b/db/config_test.go@@ -17,7 +17,7 @@ import (func TestPoolProfilesOrder(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Close via Cleanup, registered FIRST so it runs LAST: a plain defer would// close the pool before the row-deleting cleanups below run.@@ -83,7 +83,7 @@ func TestDeleteProfileContextHonorsCancellation(t *testing.T) {func TestConfigStores(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/conversation_pin_test.go b/db/conversation_pin_test.goindex e967457..adf389b 100644--- a/db/conversation_pin_test.go+++ b/db/conversation_pin_test.go@@ -9,7 +9,7 @@ import (func TestConversationPinOrderingAndPatch(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })diff --git a/db/coverage_graph_large_test.go b/db/coverage_graph_large_test.goindex 2ca706c..d529ec0 100644--- a/db/coverage_graph_large_test.go+++ b/db/coverage_graph_large_test.go@@ -87,7 +87,7 @@ INSERT INTO exploration_anchors(node_id,asset_id) SELECT fn.id, an.id FROM fn JOfunc TestBuildCoverageGraphLargeInvariants(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })f := seedLargeCoverageFixture(t, d)diff --git a/db/coverage_ledger_test.go b/db/coverage_ledger_test.goindex 7a7f964..78ed31d 100644--- a/db/coverage_ledger_test.go+++ b/db/coverage_ledger_test.go@@ -100,7 +100,7 @@ func TestCoverageJSONCarriesLedger(t *testing.T) {func TestRecordCoverageUpsertHistory(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -157,7 +157,7 @@ func TestRecordCoverageUpsertHistory(t *testing.T) {func TestCoverageCompletenessBudgetThenReviveDone(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -221,7 +221,7 @@ func TestCoverageCompletenessBudgetThenReviveDone(t *testing.T) {func TestRecordCoverageRowCap(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })diff --git a/db/customtool_test.go b/db/customtool_test.goindex d2fa7b7..0b6860b 100644--- a/db/customtool_test.go+++ b/db/customtool_test.go@@ -10,7 +10,7 @@ import (func TestCustomToolCRUD(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })diff --git a/db/db_test.go b/db/db_test.goindex 445f19f..1d66a09 100644--- a/db/db_test.go+++ b/db/db_test.go@@ -75,7 +75,7 @@ func testDSN(t *testing.T) string {t.Helper()dsn, _, err := DSN()if err != nil {- t.Skipf("no database config (%v) — skipping", err)+ SkipPGUnavailable(t, err)}return dsn}@@ -85,7 +85,7 @@ func testDSN(t *testing.T) string {func TestOpenSeed(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/evidence_secrets_test.go b/db/evidence_secrets_test.goindex eabf1c1..d49079e 100644--- a/db/evidence_secrets_test.go+++ b/db/evidence_secrets_test.go@@ -92,7 +92,7 @@ func assertClearHeads(t *testing.T, d *DB, findingID int64, want TrafficEvidencefunc TestEvidenceHeadsSealedAtInsert(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })_, fid, s := evidenceFixture(t, d, "insert", false)@@ -106,7 +106,7 @@ func TestEvidenceHeadsSealedAtInsert(t *testing.T) {func TestEvidenceHeadsBackfillAndKeyChecks(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })_, fid, s := evidenceFixture(t, d, "legacy", true)@@ -171,7 +171,7 @@ func TestEvidenceHeadsBackfillAndKeyChecks(t *testing.T) {func TestEvidenceHeadsArchiveRoundTrip(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })if err = d.EnsureLLMRecordsTable(); err != nil {diff --git a/db/exploration_sources_test.go b/db/exploration_sources_test.goindex bbf12a8..d7e1693 100644--- a/db/exploration_sources_test.go+++ b/db/exploration_sources_test.go@@ -8,7 +8,7 @@ import (func TestInheritedActivityReadsRequireTerminalIntent(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -92,7 +92,7 @@ func TestInheritedActivityReadsRequireTerminalIntent(t *testing.T) {func TestExplorationDirectSourceReadView(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -315,7 +315,7 @@ func TestExplorationDirectSourceReadView(t *testing.T) {func TestTaskAssetContextUsesDirectSourceScopeAndAnchors(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })diff --git a/db/exploration_test.go b/db/exploration_test.goindex 1585ffb..64f3118 100644--- a/db/exploration_test.go+++ b/db/exploration_test.go@@ -8,7 +8,7 @@ import (func TestExplorationFlow(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -119,7 +119,7 @@ func TestExplorationFlow(t *testing.T) {func TestIntentPauseResumeAndCancelCleanup(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -252,7 +252,7 @@ func TestIntentPauseResumeAndCancelCleanup(t *testing.T) {func TestNodesPageQueryMatchesID(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/exploration_tokens_test.go b/db/exploration_tokens_test.goindex 9dbbc00..e643a90 100644--- a/db/exploration_tokens_test.go+++ b/db/exploration_tokens_test.go@@ -8,7 +8,7 @@ import (func TestTokenStatsBySessionUsesCompleteIntentHistory(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/finding_assets_test.go b/db/finding_assets_test.goindex b268416..08cb14d 100644--- a/db/finding_assets_test.go+++ b/db/finding_assets_test.go@@ -53,7 +53,7 @@ func nodeByKey(tree *FindingAssetTree, key string) *FindingAssetNode {func TestBuildFindingAssetTree(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -164,7 +164,7 @@ func TestBuildFindingAssetTree(t *testing.T) {func TestFindingAssetScopeFilter(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/finding_quality_test.go b/db/finding_quality_test.goindex a40cfa6..e29ec9b 100644--- a/db/finding_quality_test.go+++ b/db/finding_quality_test.go@@ -10,7 +10,7 @@ import "testing"func TestFindingQualityByNodeID(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()tk, err := d.CreateTask("finding quality lookup", "goal", nil, 0, 0)diff --git a/db/finding_reasoning_test.go b/db/finding_reasoning_test.goindex 9ed400f..5f63d07 100644--- a/db/finding_reasoning_test.go+++ b/db/finding_reasoning_test.go@@ -10,7 +10,7 @@ import (func TestFindingReasoningFieldsRoundTrip(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()tk, err := d.CreateTask("finding reasoning fields", "goal", nil, 0, 0)diff --git a/db/findings_test.go b/db/findings_test.goindex c88006f..d8fea5e 100644--- a/db/findings_test.go+++ b/db/findings_test.go@@ -35,7 +35,7 @@ func TestValidFindingReportState(t *testing.T) {func TestDeleteFinding(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -81,7 +81,7 @@ func TestDeleteFinding(t *testing.T) {func TestSetFindingStatusMirrorsNodePayload(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -144,7 +144,7 @@ func TestSetFindingStatusMirrorsNodePayload(t *testing.T) {func TestFindingReportState(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -256,7 +256,7 @@ func TestFindingReportState(t *testing.T) {func TestFindingsPageAndStats(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -414,7 +414,7 @@ func TestFindingsPageAndStats(t *testing.T) {func TestListFindingsPageUsesStableIDTieBreaker(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -462,7 +462,7 @@ func TestListFindingsPageUsesStableIDTieBreaker(t *testing.T) {func TestFindingGroupsAndUnassignedPaging(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -606,7 +606,7 @@ func TestFindingGroupsAndUnassignedPaging(t *testing.T) {func TestAddFindingFollowUpIntent(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/intent_claim_test.go b/db/intent_claim_test.goindex 9efaeb9..2485793 100644--- a/db/intent_claim_test.go+++ b/db/intent_claim_test.go@@ -16,7 +16,7 @@ func openClaimInstances(t *testing.T) (*DB, *ExplorationStore, *ExplorationStoredsn := testDSN(t)a, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { a.Close() })b, err := Open(dsn)@@ -341,7 +341,7 @@ func TestIntentClaimTakeoverRacesHeartbeatAtomically(t *testing.T) {func TestIntentClaimColumnsMigrateIdempotently(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/intent_control_test.go b/db/intent_control_test.goindex 6cfb9cb..67423cf 100644--- a/db/intent_control_test.go+++ b/db/intent_control_test.go@@ -11,7 +11,7 @@ import (func TestCompareAndSetIntentStateAllowsSingleWinner(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()expID, err := d.CreateExploration("intent CAS", "only one controller wins")@@ -61,7 +61,7 @@ func TestCompareAndSetIntentStateAllowsSingleWinner(t *testing.T) {func TestCancelIntentPreservesTokenMeteringWithoutDoubleCount(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()expID, err := d.CreateExploration("cancel token rollup", "preserve consumed tokens")@@ -229,7 +229,7 @@ func assertDailyTokenBucketsEqual(t *testing.T, got, want map[string]DailyTokenBfunc TestCancelIntentPreservesOutputsYieldedByAnotherIntent(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()expID, err := d.CreateExploration("shared intent output", "preserve shared facts and findings")diff --git a/db/intent_delete_test.go b/db/intent_delete_test.goindex 9af784e..bce27bd 100644--- a/db/intent_delete_test.go+++ b/db/intent_delete_test.go@@ -41,7 +41,7 @@ func gone(t *testing.T, es *ExplorationStore, id int64) bool {func TestSoftDeleteIntent(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()expID, err := d.CreateExploration("soft delete", "soft delete")@@ -89,7 +89,7 @@ func TestSoftDeleteIntent(t *testing.T) {func TestHardDeleteCascadesExclusiveDescendants(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()expID, err := d.CreateExploration("hard cascade", "cascade delete")@@ -127,7 +127,7 @@ func TestHardDeleteCascadesExclusiveDescendants(t *testing.T) {func TestHardDeletePreservesSharedAndGoal(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()expID, err := d.CreateExploration("hard preserve", "keep shared/goal")diff --git a/db/lessons_test.go b/db/lessons_test.goindex 09d0387..2044551 100644--- a/db/lessons_test.go+++ b/db/lessons_test.go@@ -76,7 +76,7 @@ func TestRenderLessonsUsageOmitsTruncated(t *testing.T) {func TestTaskLessonsUsesTaskScopeAndRanksCompanyFirst(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -174,7 +174,7 @@ func TestTaskLessonsUsesTaskScopeAndRanksCompanyFirst(t *testing.T) {func TestExtractLessonsScopesSingleCompanyFromTaskScope(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -226,7 +226,7 @@ func TestExtractLessonsScopesSingleCompanyFromTaskScope(t *testing.T) {func TestExtractLessonsSkipsMultiCompanyTask(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -273,7 +273,7 @@ func TestExtractLessonsSkipsMultiCompanyTask(t *testing.T) {func TestExtractLessonsGenericWhenTaskHasNoCompany(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -311,7 +311,7 @@ func TestExtractLessonsGenericWhenTaskHasNoCompany(t *testing.T) {func TestTaskLessonsRanksCategoryBeforeGeneric(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -377,7 +377,7 @@ func TestTaskLessonsRanksCategoryBeforeGeneric(t *testing.T) {func TestLogLessonUsageRecordsOnlyRendered(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -457,7 +457,7 @@ func insertLessonFinding(t *testing.T, d *DB, taskID int64, status string) int64func TestExtractLessonsRetractsReversedDisposition(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -569,7 +569,7 @@ func TestExtractLessonsRetractsReversedDisposition(t *testing.T) {func TestExtractLessonsRetireOnlyWhenLastEvidence(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -660,7 +660,7 @@ func TestExtractLessonsRetireOnlyWhenLastEvidence(t *testing.T) {func TestExtractLessonsRetractsAllRetests(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -731,7 +731,7 @@ func TestExtractLessonsRetractsAllRetests(t *testing.T) {func TestExtractLessonsDoesNotUnretireWithEvidence(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -777,7 +777,7 @@ func TestExtractLessonsDoesNotUnretireWithEvidence(t *testing.T) {func TestExtractLessonsLeavesAdopted(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -820,7 +820,7 @@ func TestExtractLessonsLeavesAdopted(t *testing.T) {func TestExtractLessonsReopenRetractsNothing(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })diff --git a/db/llm_records_migrate_test.go b/db/llm_records_migrate_test.goindex c40fb46..7214826 100644--- a/db/llm_records_migrate_test.go+++ b/db/llm_records_migrate_test.go@@ -12,7 +12,7 @@ import (func TestLLMRecordsMigrateAddsRawColumnsToOldTable(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()if err := d.EnsureLLMRecordsTable(); err != nil {diff --git a/db/llm_usage_ts_index_test.go b/db/llm_usage_ts_index_test.goindex 04f9a40..1951c66 100644--- a/db/llm_usage_ts_index_test.go+++ b/db/llm_usage_ts_index_test.go@@ -12,7 +12,7 @@ import (func TestLLMUsageTsIndex(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })diff --git a/db/llmretry_test.go b/db/llmretry_test.goindex ba4dfe4..7076bf6 100644--- a/db/llmretry_test.go+++ b/db/llmretry_test.go@@ -13,7 +13,7 @@ import (func TestProfileRetryRoundTrip(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -71,7 +71,7 @@ func TestProfileRetryRoundTrip(t *testing.T) {func TestProfileRetryClampedOnSave(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -98,7 +98,7 @@ func TestProfileRetryClampedOnSave(t *testing.T) {func TestLLMRetryPolicyRoundTrip(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the restore below.t.Cleanup(func() { d.Close() })diff --git a/db/migrate_test.go b/db/migrate_test.goindex 49b2ca8..026c4a1 100644--- a/db/migrate_test.go+++ b/db/migrate_test.go@@ -52,11 +52,11 @@ func scratchDSN(t *testing.T, suffix string) string {admin.Path = "/postgres"conn, err := sql.Open("pgx", admin.String())if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}if err := conn.Ping(); err != nil {conn.Close()- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}drop := func() error {_, err := conn.Exec(`DROP DATABASE IF EXISTS "` + name + `" WITH (FORCE)`)@@ -189,7 +189,7 @@ func TestOpenRecordsEmbeddedMigrations(t *testing.T) {dsn := testDSN(t)d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}applied := assertEmbeddedApplied(t, d)d.Close()diff --git a/db/notification_test.go b/db/notification_test.goindex dd7c807..40f7bfd 100644--- a/db/notification_test.go+++ b/db/notification_test.go@@ -18,7 +18,7 @@ func notifyTestDB(t *testing.T) *DB {t.Helper()d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })return ddiff --git a/db/secrets_test.go b/db/secrets_test.goindex f7551d8..b1b6f1a 100644--- a/db/secrets_test.go+++ b/db/secrets_test.go@@ -200,7 +200,7 @@ func assertPlainReads(t *testing.T, d *DB, r secretRows) {func TestSecretsAtRestWriteRead(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() }) // after the fixture cleanupr := secretFixture(t, d, false)@@ -214,7 +214,7 @@ func TestSecretsAtRestWriteRead(t *testing.T) {func TestSecretsBackfillLegacyAndKeyChecks(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() }) // after the fixture cleanupr := secretFixture(t, d, true)@@ -287,7 +287,7 @@ func encryptedCount(t *testing.T, d *DB, dir string) int {func TestSecretSettingsEmptyAndClear(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() {d.Exec(deleteSecretSettings)diff --git a/db/settings_insert_test.go b/db/settings_insert_test.goindex fd80657..37e460d 100644--- a/db/settings_insert_test.go+++ b/db/settings_insert_test.go@@ -13,7 +13,7 @@ import (func TestInsertSettingIfAbsentDoesNotOverwrite(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -50,7 +50,7 @@ func TestInsertSettingIfAbsentDoesNotOverwrite(t *testing.T) {func TestRotatePasswordRollsBackHashWhenVersionCannotIncrement(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/skill_usage_test.go b/db/skill_usage_test.goindex 4625696..57f5ead 100644--- a/db/skill_usage_test.go+++ b/db/skill_usage_test.go@@ -11,7 +11,7 @@ import (func TestSkillUsageLedger(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/target_pins_test.go b/db/target_pins_test.goindex 53f5397..9e4fbec 100644--- a/db/target_pins_test.go+++ b/db/target_pins_test.go@@ -19,7 +19,7 @@ func openTargetDB(t *testing.T) *DB {t.Helper()d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })return ddiff --git a/db/task_archives_test.go b/db/task_archives_test.goindex 62f5167..727ffc7 100644--- a/db/task_archives_test.go+++ b/db/task_archives_test.go@@ -123,7 +123,7 @@ func TestTaskArchiveFormatCompatibility(t *testing.T) {func TestTaskArchiveDatabaseRoundTrip(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()if err := d.EnsureLLMRecordsTable(); err != nil {@@ -335,7 +335,7 @@ VALUES($1,$2,0,'quota_exhausted','balance exhausted',$3,$4,$3)`, task.ID, llmProfunc TestTaskArchiveBlockersIgnoreQueuedDependents(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()source, err := d.CreateTaskWithOptions("archive blocker source", "source", TaskCreateOptions{})@@ -400,7 +400,7 @@ func assertPerTaskBlockers(t *testing.T, d *DB, global map[int64]int64, want mapfunc TestRecoverInterruptedArchiveRequiresManualRetry(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()task, err := d.CreateTaskWithOptions("interrupted archive", "must not restart automatically", TaskCreateOptions{})diff --git a/db/task_assets_test.go b/db/task_assets_test.goindex 8cc2487..479cc98 100644--- a/db/task_assets_test.go+++ b/db/task_assets_test.go@@ -10,7 +10,7 @@ import (func TestRegisterTaskAssetScopesCreatesAssetsAndPersistsTextScope(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -93,7 +93,7 @@ func TestRegisterTaskAssetScopesCreatesAssetsAndPersistsTextScope(t *testing.T)func TestTaskAssetAttachDetachPreservesGlobalAssetAndAnchors(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -150,7 +150,7 @@ func TestTaskAssetAttachDetachPreservesGlobalAssetAndAnchors(t *testing.T) {func TestIntentAssetsIncludesDirectSourceProvenance(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })diff --git a/db/task_categories_test.go b/db/task_categories_test.goindex cb34d1e..b23ee13 100644--- a/db/task_categories_test.go+++ b/db/task_categories_test.go@@ -11,7 +11,7 @@ import (func TestTaskCategoryCRUDAndTaskAssignment(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -73,7 +73,7 @@ func TestTaskCategoryCRUDAndTaskAssignment(t *testing.T) {func TestCreateTaskRejectsMissingCategoryAtomically(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -94,7 +94,7 @@ func TestCreateTaskRejectsMissingCategoryAtomically(t *testing.T) {func TestSetTasksCategoryBatch(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -155,7 +155,7 @@ func TestSetTasksCategoryBatch(t *testing.T) {func TestSetTasksCategoryRejectsBadInputAtomically(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })diff --git a/db/task_context_lock_test.go b/db/task_context_lock_test.goindex 34ca4ae..fd6d5ee 100644--- a/db/task_context_lock_test.go+++ b/db/task_context_lock_test.go@@ -11,7 +11,7 @@ func TestTaskLLMProfileMutationsLockTaskBeforeProfile(t *testing.T) {dsn := testDSN(t)d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -111,7 +111,7 @@ func TestDeleteProfileLocksNonTaskReferencesBeforeProfile(t *testing.T) {t.Run("agent", func(t *testing.T) {d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -169,7 +169,7 @@ func TestDeleteProfileLocksNonTaskReferencesBeforeProfile(t *testing.T) {t.Run("conversation", func(t *testing.T) {d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -226,7 +226,7 @@ func TestNonTaskProfileMutationsLockReferenceBeforeProfile(t *testing.T) {t.Run("agent", func(t *testing.T) {d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -275,7 +275,7 @@ func TestNonTaskProfileMutationsLockReferenceBeforeProfile(t *testing.T) {t.Run("conversation", func(t *testing.T) {d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -326,7 +326,7 @@ func TestCreateConversationAndDeleteProfileDoNotDeadlock(t *testing.T) {dsn := testDSN(t)d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -407,7 +407,7 @@ func TestDeleteProfileRetriesReferenceCommittedAfterInitialScan(t *testing.T) {dsn := testDSN(t)d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })diff --git a/db/task_delete_concurrency_test.go b/db/task_delete_concurrency_test.goindex 0d65191..5d90ee3 100644--- a/db/task_delete_concurrency_test.go+++ b/db/task_delete_concurrency_test.go@@ -13,7 +13,7 @@ func TestDeleteTaskTrafficHostsUseOneLockedTransaction(t *testing.T) {dsn := testDSN(t)d, err := Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/task_list_performance_test.go b/db/task_list_performance_test.goindex cef7b23..3db2626 100644--- a/db/task_list_performance_test.go+++ b/db/task_list_performance_test.go@@ -9,7 +9,7 @@ import (func TestListTasksBulkHydratesTaskContext(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -71,7 +71,7 @@ func TestListTasksBulkHydratesTaskContext(t *testing.T) {func TestTaskListMetricsAll(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -123,7 +123,7 @@ VALUES ($1,'goal','{}','met'), ($1,'goal','{}','open')`, task.ExplorationID); erfunc TestTaskListMetricsMatchesAll(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })diff --git a/db/task_llm_spend_test.go b/db/task_llm_spend_test.goindex 7c807f2..ec3e9e2 100644--- a/db/task_llm_spend_test.go+++ b/db/task_llm_spend_test.go@@ -11,7 +11,7 @@ import (func TestTaskLLMSpendCountsJudgeNotChat(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/task_metadata_test.go b/db/task_metadata_test.goindex 85f327c..bd5ebec 100644--- a/db/task_metadata_test.go+++ b/db/task_metadata_test.go@@ -9,7 +9,7 @@ import (func TestTaskPinOrderingAndRename(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()@@ -71,7 +71,7 @@ func TestTaskPinOrderingAndRename(t *testing.T) {func TestDeleteConversationsReturnsExistingIDs(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/task_queue_test.go b/db/task_queue_test.goindex a9b949b..377bcc3 100644--- a/db/task_queue_test.go+++ b/db/task_queue_test.go@@ -8,7 +8,7 @@ import (func TestTaskQueuePreservesBootstrapAndFIFOPosition(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/task_rotation_test.go b/db/task_rotation_test.goindex 1fd97c8..1edbbff 100644--- a/db/task_rotation_test.go+++ b/db/task_rotation_test.go@@ -9,7 +9,7 @@ import (func TestTaskRotationPersistenceAndFailover(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable: %v", err)+ SkipPGUnavailable(t, err)}defer d.Close()ids := []int64{}diff --git a/db/task_scope_test.go b/db/task_scope_test.goindex 25f7d7a..2248799 100644--- a/db/task_scope_test.go+++ b/db/task_scope_test.go@@ -12,7 +12,7 @@ func TestCoverageEnabledWithoutTask(t *testing.T) {func TestCoverageEnabledMissingRowStaysOn(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}defer d.Close()on, err := d.Assets().CoverageEnabled(9_000_000_000_001)@@ -24,7 +24,7 @@ func TestCoverageEnabledMissingRowStaysOn(t *testing.T) {func TestCoverageEnabledQueryErrorStaysOn(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ SkipPGUnavailable(t, err)}if err := d.Close(); err != nil {t.Fatal(err)diff --git a/db/task_templates_test.go b/db/task_templates_test.goindex 83bcb2a..7e2318e 100644--- a/db/task_templates_test.go+++ b/db/task_templates_test.go@@ -12,7 +12,7 @@ import (func TestTaskTemplateCRUDAndNormalizedUniqueness(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })@@ -87,7 +87,7 @@ func TestTaskTemplateCRUDAndNormalizedUniqueness(t *testing.T) {func TestTaskTemplateDisjointPatchesCompose(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanup below.t.Cleanup(func() { d.Close() })diff --git a/db/tasks_test.go b/db/tasks_test.goindex c30b506..df1fe4e 100644--- a/db/tasks_test.go+++ b/db/tasks_test.go@@ -11,7 +11,7 @@ import (func TestTaskLifecycleAndDeleteCascade(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() { d.Close() })@@ -85,7 +85,7 @@ func TestTaskLifecycleAndDeleteCascade(t *testing.T) {func TestTaskDeleteCascadeAssets(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -211,7 +211,7 @@ func TestTaskDeleteCascadeAssets(t *testing.T) {func TestTaskRelationsAndLLMFailoverChain(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -470,7 +470,7 @@ func TestTaskRelationsAndLLMFailoverChain(t *testing.T) {func TestTaskContextRejectsDuplicatesAndAllowsTerminalLLMEdits(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -525,7 +525,7 @@ func TestTaskContextRejectsDuplicatesAndAllowsTerminalLLMEdits(t *testing.T) {func TestCreateTaskWithCompanyScopes(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })@@ -680,7 +680,7 @@ RETURNING id`, domainB, companyB).Scan(&companyAssetB); err != nil {func TestListTasksOrderByIDDesc(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}// Registered FIRST so it runs LAST, after the row cleanups below.t.Cleanup(func() { d.Close() })diff --git a/db/testpg.go b/db/testpg.gonew file mode 100644index 0000000..74a9c12--- /dev/null+++ b/db/testpg.go@@ -0,0 +1,32 @@+package db++// skipper is the part of testing.TB used by the PostgreSQL test helpers below.+// A local interface keeps the production package from importing "testing":+// *testing.T, *testing.B and the test-only wrappers all satisfy it.+type skipper interface {+ Helper()+ Skipf(format string, args ...any)+}++// SkipPGUnavailable skips the calling test with one uniform reason when err+// reports that the test database could not be configured or opened.+//+// Every PostgreSQL-dependent test uses this instead of spelling the skip text+// inline (the old variants differed by package: "no database config",+// "database unavailable", "postgres unavailable — skipping", ...). Call it+// with the err returned by DSN(), Open() or NewManager(). It does not change+// when a test skips — only how the reason is reported.+func SkipPGUnavailable(t skipper, err error) {+ t.Helper()+ if err != nil {+ t.Skipf("postgres unavailable (%v)", err)+ }+}++// SkipNoPG skips with the same uniform reason when a store is unexpectedly nil+// after a successful open (for example Manager.pg when only some backends are+// configured). It carries no error because there is none to report.+func SkipNoPG(t skipper) {+ t.Helper()+ t.Skip("postgres unavailable")+}diff --git a/db/tool_usage_test.go b/db/tool_usage_test.goindex 3f8e580..712c312 100644--- a/db/tool_usage_test.go+++ b/db/tool_usage_test.go@@ -5,7 +5,7 @@ import "testing"func TestToolUsageLedger(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ SkipPGUnavailable(t, err)}defer d.Close()diff --git a/db/tools_secrets_test.go b/db/tools_secrets_test.goindex 874a440..2dd32bc 100644--- a/db/tools_secrets_test.go+++ b/db/tools_secrets_test.go@@ -77,7 +77,7 @@ func jsonEqual(t *testing.T, a, b string) bool {func TestToolExecSealedAtRest(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() {d.Exec(`DELETE FROM tools WHERE key LIKE 't_secexec%'`)@@ -129,7 +129,7 @@ func TestToolExecSealedAtRest(t *testing.T) {func TestToolExecBackfillAndKeyChecks(t *testing.T) {d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}t.Cleanup(func() {d.Exec(`DELETE FROM tools WHERE key LIKE 't_secexec%'`)diff --git a/db/traffic_rewrite_test.go b/db/traffic_rewrite_test.goindex f1b614f..d852186 100644--- a/db/traffic_rewrite_test.go+++ b/db/traffic_rewrite_test.go@@ -26,7 +26,7 @@ func openRewriteRules(t *testing.T) *DB {t.Helper()d, err := Open(testDSN(t))if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ SkipPGUnavailable(t, err)}clean := func() { d.Exec(`DELETE FROM traffic_rewrite_rules WHERE name LIKE 't-rw-%'`) }clean()diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdnew file mode 100644index 0000000..8d38935--- /dev/null+++ b/docs/ARCHITECTURE.md@@ -0,0 +1,110 @@+# ARTEX architecture (code-level companion)++The README's [Architecture](https://github.com/BaaRai/ARTEX#architecture) section has the+component diagram and the 10,000-foot view. This document records the code-level map,+the execution flow and the trust boundaries that are easy to miss when reading the+packages in isolation.++## 1. The two graphs++ARTEX keeps two linked graphs, both in PostgreSQL (`db/schema.sql`):++| Graph | Answers | Main tables | Code |+| --- | --- | --- | --- |+| **Asset graph** | *What exists?* | `companies`, `company_scope`, `assets`, `task_scope` | `db/assets.go`, `db/companies.go`, `db/company_scope.go`, `db/task_assets.go` |+| **Exploration graph** | *What was tried, with what result and why?* | `explorations`, `exploration_nodes`, `activity`, `intent_*`, `coverage_*` | `db/exploration.go`, `db/coverage_ledger.go`, `db/finding_assets.go` |++Anchors tie a finding to the assets that justify it (`db/finding_assets.go`). Traffic+snapshots are archived separately and referenced from findings+(`db/finding_traffic.go`, `db/finding_traffic_archive.go`, `traffic/archive.go`).++`db.Open` executes the idempotent `schema.sql` on every startup, then applies pending+numbered migrations from `db/migrations/*.sql`, recording name + SHA-256 in+`schema_migrations`. A published migration is never edited; fix forward with a new one.++## 2. Package map++| Package | Responsibility | Notes |+| --- | --- | --- |+| `cmd/artex` | Process entry point | Flags (`-addr`, `-data`, `-proxy`), startup config snapshot, signal handling, graceful drain |+| `config` | Resolve config file + env | `Path`, `Load`, `PostgresDSN`, `SkillDir`, `KeyDir`, `Redact`. Env wins over file |+| `db` | All persistence | `DB`, `Manager`-independent stores; AES-256-GCM secret columns in `secrets.go` |+| `agent` | LLM roles and tools | `goals`, `planner`, `worker`, `mainagent`, `retester`; `ToolSet` in `tools.go`; tool catalog in `toolcatalog.go` |+| `server` | HTTP API + orchestration | `net/http` mux (~270 routes), `Manager`, `Engine`, JWT auth, SSE broadcaster |+| `traffic` | Recording proxy | MITM proxy built on `go-mitmproxy`, replay, rewrite rules, body archive |+| `evidence` | Evidence store | Persisted request/response snapshots used by findings |+| `intercept` | Approval gate | Judge, argv grammar, target gate, pins, risk scoring (a `PreToolUse` hook) |+| `guard` | Hook wiring | Binds `intercept` decisions into Norma's hook registry; `NewTargetOnly` for planner/mainagent |+| `egress` | Noise governor | Per-host token bucket, jitter, concurrency caps, 429/503 backoff; default profile is strict passthrough |+| `llmpool` / `llmrec` | Provider pool / recorder | Rotation, health, usage + raw wire capture |+| `mcphttp` | MCP client | HTTP/SSE transport for configured MCP servers |+| `notify` | Outbound notifications | Email, webhook, Telegram, Feishu, DingTalk with masking and SSRF guards |+| `report` | Deliverables | Markdown, CSV and JSON rendering of findings |+| `sidequestion` | Operator Q&A | Asks a human mid-run and suspends intent until answered |+| `skills/` | Skill definitions | One `SKILL.md` per subdirectory, loaded from `SkillDir()` |++The frontend lives in `web/` (Next.js 16, React 19) and is embedded into the Go+binary via `server/webui_embed.go` when built with `-tags embedui`.++## 3. End-to-end flow: goal → finding with evidence++1. **Task creation.** `server.createTask` → `Manager.CreateTaskWithOptions` writes the+ task, its scope and seed goals, and creates the exploration graph (`db/tasks.go`).+2. **Loop start.** `Engine.Run` (`server/engine.go`) starts a planner loop and N worker+ goroutines under a task-scoped context. Nothing needs an LLM to be configured for the+ loops to exist; they idle until one is.+3. **Decomposition.** The `goals` role writes goals and operation constraints through+ `set_goals` / `set_constraints` (`agent/toolcatalog.go`, `agent/tools.go`).+4. **Planning.** `Planner.Plan` (`agent/planner.go`) reads the route, queries the asset+ graph, judges goals and emits intents (`addOneIntent`). Every intent is an+ exploration node, so it is auditable like any other activity.+5. **Execution.** `Worker.Execute` (`agent/worker.go`) claims an intent, runs tools with+ the guard hooks attached and writes observed facts back to the exploration graph.+6. **Tools and traffic.** Shell and HTTP/WebFetch calls go through the recording proxy+ and the egress governor. Platform-owned HTTP clients use `intercept.PinnedDialer`+ and `intercept.RedirectCheck` so a redirect or a direct retry cannot leave the gate.+7. **Findings.** `addFinding` (`agent/tools.go`) records severity, class, confidence and+ asset references; `db/findings.go` dedups and keeps the status workflow. Evidence is+ linked to captured traffic (`traffic/evidence.go`, `db/finding_traffic.go`).+8. **Completion.** `prove_goal` marks a goal met; the last met goal completes the task.+ `goal_met` is deliberately unbound by default because it bypasses per-goal proof.++## 4. Execution control++- **Per-task context:** pause/cancel/kill attach a named cause via+ `context.WithCancelCause` so the activity trace records who initiated a stop.+- **Per-intent control:** the UI can pause/cancel one intent; `steerBox` queues a+ planner course-correction that the worker's `PreToolUse` hook drains before the next+ tool call, re-planning without killing the run.+- **Delete barrier:** `Engine.BeginDelete` makes installing the barrier atomic with+ registering an in-flight operation; after it returns, no new task-owned writes are+ admitted and the task context is cancelled once existing writers drain.+- **Quiet mode:** an unchanged open-goal fingerprint suppresses redundant planning+ rounds while work is still in flight.++## 5. Trust boundaries++| Boundary | Implementation |+| --- | --- |+| Tool output → model | Norma's untrusted-output boundary: nonce-tagged markers around tool results. On unless `ARTEX_UNTRUSTED_BOUNDARY` disables it. See `agent/untrusted_boundary.go` |+| Command → host | `intercept.ParseSimpleCommand` parses exactly one Bash simple command; pipelines, redirections, wrappers (`env`, `exec`, `eval`, `command`), substitutions and expansions are rejected. `ArgvPrefixOf` derives the human-readable prefix for allow/deny rules |+| URL → network | Target gate + `PinnedDialer` + `RedirectCheck`: scope decisions are re-made against a fresh DNS lookup at dial time, and the client connects only to the addresses it compared |+| Secrets → disk/log | `db/secrets.go` seals API keys, proxy credentials, MCP env, task credentials and captured auth headers with AES-256-GCM, nonce per value, AAD `table.column`. JWT keys live in `KeyDir()`, never in the browsable data dir. The boot snapshot logs only `config.Redact(dsn)` |+| Approval → audit | Every decision records the approver (`jwtSubject`), source and decision; history is queryable through `/api/intercept/history` and `/api/intercept/history/{id}` (with `/execution` for the audit detail). `/api/tasks/{id}/intercept-rules` manages rules, not history |++## 6. Decisions++- **ADR-001 — Nonce-tagged untrusted output.** Tool output is framed with a per-run+ nonce rather than trusting the model to distinguish instructions from data.+- **ADR-002 — Pin at dial time.** A URL decision is not enough: DNS can change between+ the hook and the connection, so the dialer re-resolves and connects only to compared+ addresses.+- **ADR-003 — AES-GCM with per-column AAD.** Sealed values are bound to their table and+ column (and settings to their key), so a ciphertext cannot be moved to another field.++## 7. Where to look next++- `docs/OPS.md` for startup, configuration precedence, backup and key rotation.+- `docs/vulnerability-traffic-evidence.md` for how a finding keeps its receipts.+- `docs/traffic-rewrite-rules.md` for the rewrite engine.+- `scripts/verify.sh` to reproduce the CI checks locally.diff --git a/docs/OPS.md b/docs/OPS.mdnew file mode 100644index 0000000..22b7082--- /dev/null+++ b/docs/OPS.md@@ -0,0 +1,93 @@+# ARTEX operations++## 1. Startup++Docker (recommended):++```bash+cp .env.example .env # set POSTGRES_PASSWORD; optionally an LLM key+docker compose up -d --build+docker compose logs artex | grep "Setup token"+```++Open `http://localhost:8787`. The first visit to `/setup` asks for the one-time setup+token printed at startup (`[auth] no admin password is set. Setup token for the /setup+page: ...` in `server/auth.go`).++From source (no embedded UI):++```bash+go run ./cmd/artex # backend only, 127.0.0.1:8787+cd web && npm run dev # UI on :5173, /api proxied to the backend+# or: ./dev.sh # both, plus the traffic proxy on :8788+```++The process prints one `[config] snapshot {...}` line at startup. It is the authoritative+record of the effective configuration: config path, DSN source and **redacted** DSN,+data/skill/key directories, listen address, proxy, noise profile, untrusted-output+boundary and trusted proxies. No password or token value is ever logged there.++## 2. Configuration precedence++| Setting | Resolution order | Code |+| --- | --- | --- |+| Config file | `ARTEX_CONFIG` → `./config.json` → `config.json` next to the binary | `config.Path` |+| PostgreSQL DSN | `ARTEX_PG_DSN` → `database.dsn` → assembled `host/port/user/password/dbname` | `config.PostgresDSN` |+| Skill directory | `ARTEX_SKILL_DIR` → `skill_dir` → `<binary dir>/skills` | `config.SkillDir` |+| JWT / secret key directory | `ARTEX_JWT_KEY_DIR` → `<binary dir>` (never the browsable data dir) | `config.KeyDir` |+| Secret encryption key | `ARTEX_SECRET_KEY` → `<key dir>/secret.key` → newly generated key file | `db.InitSecrets` |+| Noise profile | `ARTEX_NOISE_PROFILE` (`off` default; `quiet`, `balanced`, `aggressive`), also settable in UI | `egress.ProfileFromEnv` |+| Untrusted-output boundary | on by default; `ARTEX_UNTRUSTED_BOUNDARY=0\|false\|off\|no` disables it | `agent/untrusted_boundary.go` |+| Trusted proxies for login rate limit | `ARTEX_TRUSTED_PROXIES` (comma-separated IPs/CIDRs; empty trusts none) | `server.ParseTrustedProxies` |+| Target user agent | `ARTEX_TARGET_USER_AGENT` (applied by non-`off` noise profiles) | `egress.ProfileByName` |+| Budgets | `ARTEX_TASK_BUDGET_TOKENS` / `_TURNS`, `ARTEX_INTENT_BUDGET_TOKENS` / `_TURNS` | `agent/budget.go` |+| Live model judge test | `ARTEX_REVIEW_LIVE_CONFIG` (opt-in integration test only) | `server/intercept_live_test.go` |++Agent profiles, providers, notifications and other runtime settings live in the database+and are edited in **System → LLM / Settings / Notify**, not in `config.json`.++## 3. Backup and restore++```bash+scripts/backup.sh # database dump only, 14 rotations+scripts/backup.sh --with-data --keep 30 # also archive the data/ bind mount+```++The dump runs inside the `postgres` compose service, so no host `psql` is needed. Restore:++```bash+gunzip -c backups/artex-db-<ts>.sql.gz | docker compose exec -T postgres \+ psql -U "$POSTGRES_USER" -d "$POSTGRES_DB"+```++Back up the key directory as well: without it, JWTs cannot be verified and sealed+secrets cannot be decrypted. Keep it outside the database backup but under the same+access controls.++## 4. Key rotation++- **`jwt.key`** — signing key for the 7-day HS256 session tokens. Replacing it+ invalidates every existing session; all users must log in again. Existing key files+ are never overwritten by startup (`loadOrCreateJWTKey`).+- **`secret.key`** (or `ARTEX_SECRET_KEY`) — AES-256-GCM key for API keys, MCP env,+ task credentials and captured auth headers. Startup never overwrites an existing key.+ If it changes, values sealed under the old key cannot be decrypted (the code returns+ an error rather than leaking ciphertext as plaintext). Re-enter those secrets in the+ UI, or keep the previous key available until the migration is complete.++Plan a short maintenance window for either rotation.++## 5. Diagnostics and local verification++- `GET /api/health` — liveness, build version and provider health.+- `GET /api/logs`, `GET /api/logs/stream` — live backend log sink; the UI shows it under+ **System → Logs**. The startup snapshot line is here too.+- `scripts/verify.sh` — reproduces the CI checks locally (gofmt, build, vet, tests,+ web type-check and unit tests, shellcheck, python checks). `--full` adds `-race` and+ the web static build; `--go-only` / `--web-only` narrow the run.+- `./scripts/backup.sh --help` — backup options.++When Postgres is not configured, database-dependent tests skip themselves; that is+expected. Set `ARTEX_PG_DSN` to run them. CI uses `go test -p 1 ./...` because test+packages share a Postgres service and use suffixed per-package databases+(`SuffixTestDatabase`).diff --git a/guard/target_gate_test.go b/guard/target_gate_test.goindex f22b5d9..7a24aef 100644--- a/guard/target_gate_test.go+++ b/guard/target_gate_test.go@@ -325,7 +325,7 @@ func newGateDB(t *testing.T) *gateDB {t.Helper()dsn, _, err := db.DSN()if err != nil {- t.Skipf("no database config (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/intercept/target_request_test.go b/intercept/target_request_test.goindex 5110254..81a5172 100644--- a/intercept/target_request_test.go+++ b/intercept/target_request_test.go@@ -55,7 +55,7 @@ func targetTestDB(t *testing.T) *db.DB {t.Helper()dsn, _, err := db.DSN()if err != nil {- t.Skipf("no database config (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/llmrec/llmrec_test.go b/llmrec/llmrec_test.goindex fdf6680..497d79c 100644--- a/llmrec/llmrec_test.go+++ b/llmrec/llmrec_test.go@@ -151,7 +151,15 @@ func (meteredStreamProvider) Stream(context.Context, llm.CompletionRequest) iter}func TestSideUsageRecordedOnceOnConsumerCancellation(t *testing.T) {- t.Skip("timing-sensitive: passes locally, flaky on CI runners; tracked in BaaRai/ARTEX#9")+ // Timing-sensitive on 2-core CI runners (BaaRai/ARTEX#9). Repro:+ // ARTEX_PG_DSN=postgres://artex:testpass@localhost:5432/artextest_race \+ // go test ./llmrec -run TestSideUsageRecordedOnceOnConsumerCancellation -count=20 -race -v+ // The `early=` t.Fatalf assertion below compares the single llm_usage row's+ // count/input/output/worker/status; in the `early` branch the status+ // occasionally comes back "ok" instead of "error" because the consumer's+ // cancellation and the recorder's deferred finish race on a loaded runner.+ // Keep the skip until the metering status is made cancellation-explicit.+ t.Skip("timing-sensitive on CI runners; repro and failing assertion documented above; BaaRai/ARTEX#9")dsn := os.Getenv("ARTEX_PG_DSN")if dsn == "" {t.Skip("requires isolated ARTEX_PG_DSN")diff --git a/llmrec/usage_echo_test.go b/llmrec/usage_echo_test.goindex 0b7a340..85cd83e 100644--- a/llmrec/usage_echo_test.go+++ b/llmrec/usage_echo_test.go@@ -88,11 +88,11 @@ func TestStreamUsageEchoCountedOnce(t *testing.T) {func TestStreamUsageEchoLedgerRow(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skipf("no database config (%v)", err)+ db.SkipPGUnavailable(t, err)}pg, err := db.Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer pg.Close()if err := pg.EnsureLLMUsageTable(); err != nil {diff --git a/scripts/verify.sh b/scripts/verify.shnew file mode 100755index 0000000..b6fb56c--- /dev/null+++ b/scripts/verify.sh@@ -0,0 +1,161 @@+#!/usr/bin/env bash+# Verify ARTEX locally, reproducing the checks from .github/workflows/ci.yml.+#+# Usage:+# scripts/verify.sh [--full] [--go-only] [--web-only] [--keep-going]+#+# --full also run `go test -race` (the CI package list) and the web static build+# --go-only run only the Go checks+# --web-only run only the web checks+# --keep-going continue after a failed step and report every failure at the end+# -h, --help show this help+#+# The default is the fast set: gofmt, build, vet, tests, web type-check and web+# unit tests, shellcheck and the shell/python checks. It does not need Docker.+set -euo pipefail+cd "$(dirname "$0")/.."++usage() { sed -n '2,14p' "$0" | sed 's/^# \?//'; }++FULL=0+GO_ONLY=0+WEB_ONLY=0+KEEP_GOING=0+while [ $# -gt 0 ]; do+ case "$1" in+ --full) FULL=1; shift ;;+ --go-only) GO_ONLY=1; shift ;;+ --web-only) WEB_ONLY=1; shift ;;+ --keep-going) KEEP_GOING=1; shift ;;+ -h|--help) usage; exit 0 ;;+ *) echo "unknown option: $1" >&2; usage >&2; exit 2 ;;+ esac+done+if [ "$GO_ONLY" -eq 1 ] && [ "$WEB_ONLY" -eq 1 ]; then+ echo "--go-only and --web-only are mutually exclusive" >&2+ exit 2+fi++FAILED=0+run_step() {+ local label="$1"+ shift+ printf '\n==> %s\n' "$label"+ if "$@"; then+ return 0+ fi+ printf 'FAILED: %s\n' "$label" >&2+ FAILED=1+ if [ "$KEEP_GOING" -eq 0 ]; then+ exit 1+ fi+ return 0+}++require_cmd() {+ if ! command -v "$1" >/dev/null 2>&1; then+ printf 'missing prerequisite: %s\n' "$1" >&2+ exit 127+ fi+}++# --go-only and --web-only narrow the run; otherwise both halves are checked.+want_go() { [ "$WEB_ONLY" -eq 0 ]; }+want_web() { [ "$GO_ONLY" -eq 0 ]; }++if want_go; then+ require_cmd go+ require_cmd git++ want=$(awk '/^go /{print $2; exit}' go.mod)+ got=$(go env GOVERSION | sed 's/^go//')+ # Numeric compare, portable to macOS (no GNU `sort -V`). A newer toolchain+ # is fine: CI deliberately runs a `go-stable` job alongside the pinned floor.+ version_ge() {+ awk -v a="$1" -v b="$2" 'BEGIN {+ split(a, A, "."); split(b, B, ".")+ for (i = 1; i <= 3; i++) {+ if (A[i] + 0 > B[i] + 0) exit 0+ if (A[i] + 0 < B[i] + 0) exit 1+ }+ exit 0+ }'+ }+ if [ -z "$want" ] || [ -z "$got" ] || ! version_ge "$got" "$want"; then+ printf 'Go %s does not meet the go.mod floor %s\n' "$got" "$want" >&2+ exit 1+ fi++ if [ -z "${ARTEX_PG_DSN:-}" ]; then+ printf 'note: ARTEX_PG_DSN is unset; PostgreSQL-dependent tests will skip themselves\n'+ fi++ check_gofmt() {+ local -a files=()+ local out+ mapfile -t files < <(git ls-files '*.go')+ if [ "${#files[@]}" -eq 0 ]; then+ return 0+ fi+ out=$(gofmt -l "${files[@]}")+ if [ -n "$out" ]; then+ printf 'gofmt required:\n%s\n' "$out"+ return 1+ fi+ }++ run_step "gofmt" check_gofmt+ run_step "go build" go build ./...+ run_step "go vet" go vet ./...+ run_step "go test -p 1" go test -p 1 ./...++ if [ "$FULL" -eq 1 ]; then+ RACE_PKGS=(+ ./agent ./cmd/artex ./config ./db ./evidence ./guard+ ./intercept ./llmpool ./llmrec ./mcphttp ./notify ./server+ ./sidequestion ./traffic ./traffic/rewrite+ )+ run_step "go test -race -p 1" go test -race -p 1 "${RACE_PKGS[@]}"+ fi+fi++if want_web; then+ require_cmd npm+ require_cmd npx++ if [ ! -d web/node_modules ] || [ web/package-lock.json -nt web/node_modules ]; then+ run_step "npm ci" npm --prefix web ci+ fi+ run_step "tsc --noEmit" bash -c 'cd web && npx tsc --noEmit'+ run_step "web polling tests" bash -c 'cd web && npm run test:polling'+ run_step "web replay tests" bash -c 'cd web && npm run test:replay'+ run_step "web upload tests" bash -c 'cd web && npm run test:upload'+ if [ "$FULL" -eq 1 ]; then+ run_step "web static build" bash -c 'cd web && npm run build:static'+ fi+fi++# The shell/python checks are part of neither --go-only nor --web-only: they+# are cheap and guard the install/update path used by every deployment.+if [ "$GO_ONLY" -eq 0 ] && [ "$WEB_ONLY" -eq 0 ]; then+ require_cmd python3+ if command -v shellcheck >/dev/null 2>&1; then+ run_step "shellcheck" shellcheck -S warning \+ install.sh update.sh start.sh scripts/backup.sh scripts/verify.sh \+ reset-password.sh scripts/extract-changelog-section.sh \+ scripts/test-extract-changelog-section.sh .github/scripts/bot.sh \+ scripts/test-bot-context.sh+ else+ printf 'note: shellcheck is not installed; skipping the shellcheck step\n'+ fi+ run_step "posture check" python3 scripts/posture_check_test.py+ run_step "changelog section tests" bash scripts/test-extract-changelog-section.sh+ run_step "bot context tests" bash scripts/test-bot-context.sh+fi++printf '\n'+if [ "$FAILED" -ne 0 ]; then+ printf 'verification FAILED (one or more steps above)\n' >&2+ exit 1+fi+printf 'verification passed\n'diff --git a/server/assembly_test.go b/server/assembly_test.goindex 2cb1bba..b6eae9b 100644--- a/server/assembly_test.go+++ b/server/assembly_test.go@@ -28,11 +28,11 @@ func hasSkillTool(tools []actool.CoreTool) bool {func TestAssembleVisibleSkill(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skipf("no database config (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}pg, err := db.Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer pg.Close()diff --git a/server/assets_scope_test.go b/server/assets_scope_test.goindex dcff3e3..7dc2075 100644--- a/server/assets_scope_test.go+++ b/server/assets_scope_test.go@@ -36,7 +36,7 @@ func TestCompanyScopeInputsAcceptStructuredAndLegacyRules(t *testing.T) {func TestCreateCompanyRejectsNormalizedDuplicateWithoutChangingScope(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -76,7 +76,7 @@ func TestCreateCompanyRejectsNormalizedDuplicateWithoutChangingScope(t *testing.func TestDeleteCompanyRefreshesLiveTaskCompanyIDs(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -117,7 +117,7 @@ func TestDeleteCompanyRefreshesLiveTaskCompanyIDs(t *testing.T) {func TestCompanyScopeHTTPErrorClassificationAndBounds(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()s := &Server{m: m}@@ -191,7 +191,7 @@ func TestCompanyScopeHTTPErrorClassificationAndBounds(t *testing.T) {func TestListAssetsClassifiesValidationAndDatabaseErrors(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()s := &Server{m: m}@@ -217,7 +217,7 @@ func TestListAssetsClassifiesValidationAndDatabaseErrors(t *testing.T) {func TestDeleteCompanyRejectsBadJSONAndReportsMissing(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()s := &Server{m: m}@@ -256,7 +256,7 @@ func TestDeleteCompanyRejectsBadJSONAndReportsMissing(t *testing.T) {func TestCompanyScopeSystemFailureIsHTTP500(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()s := &Server{m: m}diff --git a/server/auth_epoch_test.go b/server/auth_epoch_test.goindex 33af285..e5d5cb0 100644--- a/server/auth_epoch_test.go+++ b/server/auth_epoch_test.go@@ -9,6 +9,8 @@ import ("sync""testing""time"++ "github.com/Autumn-27/artex/db")func TestPasswordVersionClaim(t *testing.T) {@@ -50,7 +52,7 @@ func TestPasswordVersionClaim(t *testing.T) {func TestChangePasswordRevokesOldTokenAndKeepsItWhenSaveFails(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -150,7 +152,7 @@ func TestChangePasswordRevokesOldTokenAndKeepsItWhenSaveFails(t *testing.T) {func TestUnreadablePasswordVersionRejectsSessions(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()key := []byte("0123456789abcdef0123456789abcdef")@@ -186,7 +188,7 @@ func TestUnreadablePasswordVersionRejectsSessions(t *testing.T) {func TestLoginRereadsPasswordVersionWhenUnreadable(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -250,7 +252,7 @@ func TestLoginRereadsPasswordVersionWhenUnreadable(t *testing.T) {func TestAbsentPasswordVersionKeepsSessions(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()key := []byte("0123456789abcdef0123456789abcdef")diff --git a/server/auth_test.go b/server/auth_test.goindex 9a3ad59..9fec246 100644--- a/server/auth_test.go+++ b/server/auth_test.go@@ -8,6 +8,8 @@ import ("runtime""strings""testing"++ "github.com/Autumn-27/artex/db")// jwtKeyDirs returns fresh key, data and legacy base dirs and points@@ -194,7 +196,7 @@ func TestLoadOrCreateJWTKeyNeverOverwrites(t *testing.T) {func TestAuthStatusFailsClosedWhenDataSourceUnavailable(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()// Close the pool so subsequent GetSetting returns an error instead of sql.ErrNoRows.@@ -220,7 +222,7 @@ func TestAuthStatusFailsClosedWhenDataSourceUnavailable(t *testing.T) {func TestAuthInitFailsClosedWhenDataSourceUnavailable(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()if err := m.pg.Close(); err != nil {@@ -245,7 +247,7 @@ func TestAuthInitFailsClosedWhenDataSourceUnavailable(t *testing.T) {func TestAuthInitRequiresSetupToken(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()clearPassword := func() {diff --git a/server/change_password_limit_test.go b/server/change_password_limit_test.goindex 6436752..e9ce8f7 100644--- a/server/change_password_limit_test.go+++ b/server/change_password_limit_test.go@@ -9,6 +9,7 @@ import ("testing""time"+ "github.com/Autumn-27/artex/db""golang.org/x/crypto/bcrypt")@@ -61,7 +62,7 @@ func changePasswordServer(t *testing.T, clk *fakeClock) (*Server, string, func(rt.Helper()m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}t.Cleanup(func() { m.Close() })diff --git a/server/chat_llm_resolve_test.go b/server/chat_llm_resolve_test.goindex b4851b8..19539a6 100644--- a/server/chat_llm_resolve_test.go+++ b/server/chat_llm_resolve_test.go@@ -14,7 +14,7 @@ import (func TestChatUnavailableReasonDistinguishesStates(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()td := t.TempDir()@@ -66,7 +66,7 @@ func TestChatUnavailableReasonDistinguishesStates(t *testing.T) {func TestResolveChatAgentHonoursConversationProfile(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()td := t.TempDir()diff --git a/server/chat_mentions_test.go b/server/chat_mentions_test.goindex 6b268ca..ef94edd 100644--- a/server/chat_mentions_test.go+++ b/server/chat_mentions_test.go@@ -119,7 +119,7 @@ func TestChatMentionPagination(t *testing.T) {func TestChatMentionWorkerReceivesServerDetails(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()ctx, cancel := context.WithCancel(context.Background())diff --git a/server/core_test.go b/server/core_test.goindex 0fc0da8..8bd71d8 100644--- a/server/core_test.go+++ b/server/core_test.go@@ -20,7 +20,7 @@ import (func TestCoreTaskLifecyclePG(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()td := t.TempDir()diff --git a/server/cost_ledger_test.go b/server/cost_ledger_test.goindex e277eea..bfc73ad 100644--- a/server/cost_ledger_test.go+++ b/server/cost_ledger_test.go@@ -16,7 +16,7 @@ func TestCostLedgerEurOnUsage(t *testing.T) {}t.Cleanup(func() { m.Close() })if m.pg == nil {- t.Skip("no postgres for this run")+ db.SkipNoPG(t)}pid, err := m.pg.SaveProfile(&db.LLMProfile{diff --git a/server/engine_budget_test.go b/server/engine_budget_test.goindex c3a8ebd..f29a7f4 100644--- a/server/engine_budget_test.go+++ b/server/engine_budget_test.go@@ -82,7 +82,7 @@ func TestResetSettledRunReseedsBudgetFromUsage(t *testing.T) {t.Setenv("ARTEX_TASK_BUDGET_TOKENS", "100000")m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()diff --git a/server/finding_retests_test.go b/server/finding_retests_test.goindex 78a8170..8769306 100644--- a/server/finding_retests_test.go+++ b/server/finding_retests_test.go@@ -38,7 +38,7 @@ func newRetestServer(t *testing.T) (*Server, int64) {t.Helper()dsn, _, err := db.DSN()if err != nil {- t.Skip("test postgres not configured")+ db.SkipPGUnavailable(t, err)}pg, err := db.Open(dsn)if err != nil {diff --git a/server/findings_groups_test.go b/server/findings_groups_test.goindex f0dd20c..eefd361 100644--- a/server/findings_groups_test.go+++ b/server/findings_groups_test.go@@ -39,7 +39,7 @@ func TestFindingPaginationParam(t *testing.T) {func TestFindingGroupsReturnsTaskBucketsAndNormalizesPagination(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()marker := fmt.Sprintf("__server_finding_groups_%d__", time.Now().UnixNano())@@ -149,7 +149,7 @@ func TestFindingGroupsReturnsTaskBucketsAndNormalizesPagination(t *testing.T) {func TestDeepenFindingCreatesAuditedIntentAndRevivesTask(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -278,7 +278,7 @@ func TestDeepenFindingValidatesDescription(t *testing.T) {func TestDeepenAdmissionFailureDiscardsFollowUpIntent(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("deepen rollback", "leave no orphan intent", nil, 0, 0)diff --git a/server/inheritance_api_test.go b/server/inheritance_api_test.goindex 627d6f7..03bbfa6 100644--- a/server/inheritance_api_test.go+++ b/server/inheritance_api_test.go@@ -26,7 +26,7 @@ func TestInheritedActivityDetailAndRelationDeletion(t *testing.T) {m, err := NewManager(dir, "")if err != nil {_ = os.RemoveAll(dir)- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}t.Cleanup(func() {_ = m.Close()diff --git a/server/intercept_always_allow_pg_test.go b/server/intercept_always_allow_pg_test.goindex 1c707b3..54d9230 100644--- a/server/intercept_always_allow_pg_test.go+++ b/server/intercept_always_allow_pg_test.go@@ -17,7 +17,7 @@ import (func TestInterceptAlwaysAllowPG(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skip("no test database configured")+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/server/intercept_batch_decide_test.go b/server/intercept_batch_decide_test.goindex 31d73e0..632c861 100644--- a/server/intercept_batch_decide_test.go+++ b/server/intercept_batch_decide_test.go@@ -17,7 +17,7 @@ import (func TestInterceptBatchDecideHTTP(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skip("no test database configured")+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/server/intercept_decided_by_test.go b/server/intercept_decided_by_test.goindex 114298f..3fb0b38 100644--- a/server/intercept_decided_by_test.go+++ b/server/intercept_decided_by_test.go@@ -34,7 +34,7 @@ func TestInterceptFilterParamsDecidedBy(t *testing.T) {func TestInterceptDecidedByHTTP(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skip("no test database configured")+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/server/intercept_detail_test.go b/server/intercept_detail_test.goindex 956bc46..b42de2e 100644--- a/server/intercept_detail_test.go+++ b/server/intercept_detail_test.go@@ -15,7 +15,7 @@ import (func TestInterceptDetailHTTP(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skip("no test database configured")+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/server/intercept_filter_test.go b/server/intercept_filter_test.goindex 432e23f..cfe5865 100644--- a/server/intercept_filter_test.go+++ b/server/intercept_filter_test.go@@ -13,7 +13,7 @@ import (func TestInterceptFilterHTTP(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skip("no test database configured")+ db.SkipPGUnavailable(t, err)}d, err := db.Open(dsn)if err != nil {diff --git a/server/lessons_test.go b/server/lessons_test.goindex 8da1f68..6ab6052 100644--- a/server/lessons_test.go+++ b/server/lessons_test.go@@ -8,6 +8,8 @@ import ("strconv""strings""testing"++ "github.com/Autumn-27/artex/db")func TestRSILessonsMode(t *testing.T) {@@ -23,7 +25,7 @@ func TestRSILessonsMode(t *testing.T) {func TestTaskLessonsExtractionAndIdempotency(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()if _, err := m.pg.Exec(`DELETE FROM rsi_lessons`); err != nil {@@ -124,7 +126,7 @@ SELECT id,'completed','fixed','{}'::jsonb FROM findings WHERE task_id=$1 AND namfunc TestTerminalStatusExtractsLessons(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()if _, err := m.pg.Exec(`DELETE FROM rsi_lessons`); err != nil {diff --git a/server/llm_key_endpoint_test.go b/server/llm_key_endpoint_test.goindex 6e59826..8d1a2a4 100644--- a/server/llm_key_endpoint_test.go+++ b/server/llm_key_endpoint_test.go@@ -124,7 +124,7 @@ func TestLLMTestValidatesUserAgent(t *testing.T) {func TestStoredProfileKeyOnlyForStoredEndpoint(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v)", err)+ db.SkipPGUnavailable(t, err)}t.Cleanup(func() { m.Close() })ctx, cancel := context.WithCancel(context.Background())diff --git a/server/llm_ollama_test.go b/server/llm_ollama_test.goindex 655a410..0af10ed 100644--- a/server/llm_ollama_test.go+++ b/server/llm_ollama_test.go@@ -110,7 +110,7 @@ func TestOllamaKeylessProfileLifecycle(t *testing.T) {}t.Cleanup(func() { m.Close() })if m.pg == nil {- t.Skip("no postgres for this run")+ db.SkipNoPG(t)}ctx, cancel := context.WithCancel(context.Background())cancel()@@ -197,7 +197,7 @@ func TestOllamaListModels(t *testing.T) {}t.Cleanup(func() { m.Close() })if m.pg == nil {- t.Skip("no postgres for this run")+ db.SkipNoPG(t)}ctx, cancel := context.WithCancel(context.Background())cancel()diff --git a/server/llm_test_fallback_test.go b/server/llm_test_fallback_test.goindex 2411c37..b6d59bd 100644--- a/server/llm_test_fallback_test.go+++ b/server/llm_test_fallback_test.go@@ -25,7 +25,7 @@ func TestLLMTestStoredKeyFallbackIsTrimmed(t *testing.T) {}t.Cleanup(func() { m.Close() })if m.pg == nil {- t.Skip("no postgres for this run")+ db.SkipNoPG(t)}ctx, cancel := context.WithCancel(context.Background())cancel()@@ -105,7 +105,7 @@ func TestLLMTestStoredProfileUsesProfileEndpoint(t *testing.T) {}t.Cleanup(func() { m.Close() })if m.pg == nil {- t.Skip("no postgres for this run")+ db.SkipNoPG(t)}ctx, cancel := context.WithCancel(context.Background())cancel()diff --git a/server/llmrec_raw_test.go b/server/llmrec_raw_test.goindex 673ce1a..e6dd70f 100644--- a/server/llmrec_raw_test.go+++ b/server/llmrec_raw_test.go@@ -10,6 +10,7 @@ import ("testing""github.com/Autumn-27/artex/agent"+ "github.com/Autumn-27/artex/db""github.com/Autumn-27/artex/llmrec""github.com/Autumn-27/norma/llm""github.com/Autumn-27/norma/transcript"@@ -21,7 +22,7 @@ import (func TestRecorderPersistsRawWireBodies(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()pg := m.PG()diff --git a/server/manager_delete_files_test.go b/server/manager_delete_files_test.goindex 48de983..b560354 100644--- a/server/manager_delete_files_test.go+++ b/server/manager_delete_files_test.go@@ -15,7 +15,7 @@ import (func TestSeedAssociatesTargetAssetWithTask(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("seed ownership", "seed ownership", nil, 0, 0)@@ -174,7 +174,7 @@ func TestManagerDeleteTaskRestoresFilesAndTrafficWhenPostgresDeleteFails(t *testdataDir := t.TempDir()m, err := NewManager(dataDir, "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}t.Cleanup(func() { _ = m.Close() })diff --git a/server/mgmt_test.go b/server/mgmt_test.goindex ea50f47..5ff1bb2 100644--- a/server/mgmt_test.go+++ b/server/mgmt_test.go@@ -7,16 +7,18 @@ import ("net/http""net/http/httptest""testing"++ "github.com/Autumn-27/artex/db")// TestMgmtAPI exercises the PostgreSQL-backed management API through the real mux.func TestMgmtAPI(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("database unavailable (%v) — skipping management API test", err)+ db.SkipPGUnavailable(t, err)}if m.pg == nil {- t.Skip("postgres unavailable — skipping management API test")+ db.SkipNoPG(t)}// New starts the notifier and task-archive workers on context.Background();// closing the pool stops them from claiming later tests' digest batchesdiff --git a/server/planner_quiet_test.go b/server/planner_quiet_test.goindex 9cb424f..8109ed2 100644--- a/server/planner_quiet_test.go+++ b/server/planner_quiet_test.go@@ -17,7 +17,7 @@ func TestPlannerQuietSkipEdge(t *testing.T) {}t.Cleanup(func() { _ = m.Close() })if m.pg == nil {- t.Skip("no postgres for this run")+ db.SkipNoPG(t)}created, err := m.CreateTaskWithOptions("quiet-mode probe", "probe goal", db.TaskCreateOptions{})@@ -86,7 +86,7 @@ func TestPlannerQuietModeToggleMidRun(t *testing.T) {}t.Cleanup(func() { _ = m.Close() })if m.pg == nil {- t.Skip("no postgres for this run")+ db.SkipNoPG(t)}created, err := m.CreateTaskWithOptions("quiet-toggle probe", "goal", db.TaskCreateOptions{})diff --git a/server/side_questions_test.go b/server/side_questions_test.goindex cbdad89..a277b58 100644--- a/server/side_questions_test.go+++ b/server/side_questions_test.go@@ -142,7 +142,7 @@ func newSideHTTPFixture(t *testing.T) *sideHTTPFixture {t.Helper()m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}ctx, cancel := context.WithCancel(context.Background())s := &Server{m: m, engine: NewEngine(m), ctx: ctx, jwtKey: []byte("btw-test-signing-key-only"), chatBusy: map[string]bool{}}diff --git a/server/skill_gaps_test.go b/server/skill_gaps_test.goindex 846632e..487241c 100644--- a/server/skill_gaps_test.go+++ b/server/skill_gaps_test.go@@ -7,12 +7,14 @@ import ("net/http/httptest""strconv""testing"++ "github.com/Autumn-27/artex/db")func TestSkillGapsReport(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("skill gaps", "goal", nil, 0, 0)diff --git a/server/task_admission_test.go b/server/task_admission_test.goindex 6a3e1ef..7d7b628 100644--- a/server/task_admission_test.go+++ b/server/task_admission_test.go@@ -45,7 +45,7 @@ func restoreConcurrencySetting(t *testing.T, m *Manager) func() {func TestAdmitAlreadyRunningTaskDoesNotQueueAfterLimitDecrease(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -87,7 +87,7 @@ func TestAdmitAlreadyRunningTaskDoesNotQueueAfterLimitDecrease(t *testing.T) {func TestAdmissionDoesNotOverwriteConcurrentTerminalStatus(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()defer restoreConcurrencySetting(t, m)()@@ -124,7 +124,7 @@ func TestAdmissionDoesNotOverwriteConcurrentTerminalStatus(t *testing.T) {func TestAdmitKeepsQueuedBootstrapMode(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -167,7 +167,7 @@ func TestAdmitKeepsQueuedBootstrapMode(t *testing.T) {func TestTerminalTaskQueuedByAdmissionKeepsExecutionBarrier(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()defer restoreConcurrencySetting(t, m)()@@ -215,7 +215,7 @@ func TestTerminalTaskQueuedByAdmissionKeepsExecutionBarrier(t *testing.T) {func TestTimedOutTaskRevivalResetsClockAndSettlingAcrossFIFO(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()defer restoreConcurrencySetting(t, m)()@@ -301,7 +301,7 @@ func TestTimedOutTaskRevivalResetsClockAndSettlingAcrossFIFO(t *testing.T) {func TestQueuedTaskCanPauseAndResumeAtFIFOTail(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()defer restoreConcurrencySetting(t, m)()@@ -351,7 +351,7 @@ func TestQueuedTaskCanPauseAndResumeAtFIFOTail(t *testing.T) {func TestReadyFIFOIsAdmittedBeforeNewTask(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()defer restoreConcurrencySetting(t, m)()@@ -398,7 +398,7 @@ func TestReadyFIFOIsAdmittedBeforeNewTask(t *testing.T) {func TestUnavailableTaskReleasesSlotForReadyQueue(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()defer restoreConcurrencySetting(t, m)()@@ -437,7 +437,7 @@ func TestUnavailableTaskReleasesSlotForReadyQueue(t *testing.T) {func TestUnavailableTaskWaitsForActiveLLMCallBeforeParking(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()defer restoreConcurrencySetting(t, m)()@@ -491,7 +491,7 @@ func TestUnavailableTaskWaitsForActiveLLMCallBeforeParking(t *testing.T) {func TestRerunAdmissionFailureRestoresIntentState(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("failed rerun admission", "restore intent", nil, 0, 0)@@ -535,7 +535,7 @@ func TestRerunAdmissionFailureRestoresIntentState(t *testing.T) {func TestTaskLLMResolutionRejectsInvalidExplicitProfile(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -576,7 +576,7 @@ func TestTaskLLMResolutionRejectsInvalidExplicitProfile(t *testing.T) {func TestTaskLLMResolutionPrefersAgentBindingOverTaskChain(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()@@ -643,7 +643,7 @@ func TestTaskLLMResolutionPrefersAgentBindingOverTaskChain(t *testing.T) {func TestTaskLLMResolutionReportsDatabaseFailure(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("resolution storage failure", "return server error", nil, 0, 0)@@ -688,7 +688,7 @@ func TestTokenStatsWithoutTaskReturnsStableShape(t *testing.T) {func TestBatchControlLimitCountsDeduplicatedIDs(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()s := newAdmissionTestServer(m, nil)@@ -762,7 +762,7 @@ func TestBatchControlLimitCountsDeduplicatedIDs(t *testing.T) {func TestPauseTaskToolPersistsAndDequeuesTask(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("orchestrated pause", "persist queued pause", nil, 0, 0)@@ -798,7 +798,7 @@ func TestPauseTaskToolPersistsAndDequeuesTask(t *testing.T) {func TestPauseTaskToolUsesOrchestratorCancellationCause(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("orchestrated pause cause", "keep audit reason", nil, 0, 0)diff --git a/server/task_archives_test.go b/server/task_archives_test.goindex 3d02999..05fe6ca 100644--- a/server/task_archives_test.go+++ b/server/task_archives_test.go@@ -9,12 +9,14 @@ import ("strconv""strings""testing"++ "github.com/Autumn-27/artex/db")func TestTaskArchiveAPIQueueListAndLimits(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("archive api", "verify 202", nil, 0, 0)diff --git a/server/task_categories_test.go b/server/task_categories_test.goindex 29deb4e..a6ed758 100644--- a/server/task_categories_test.go+++ b/server/task_categories_test.go@@ -7,6 +7,8 @@ import ("net/http/httptest""strings""testing"++ "github.com/Autumn-27/artex/db")// TestTaskCategoryBatchRoute pins the contract of the batch move endpoint: it is@@ -16,7 +18,7 @@ import (func TestTaskCategoryBatchRoute(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()diff --git a/server/task_control_routes_test.go b/server/task_control_routes_test.goindex 33cdae1..283556a 100644--- a/server/task_control_routes_test.go+++ b/server/task_control_routes_test.go@@ -6,12 +6,14 @@ import ("net/http/httptest""strings""testing"++ "github.com/Autumn-27/artex/db")func TestWorkerControlRoutes(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()diff --git a/server/task_delete_barrier_test.go b/server/task_delete_barrier_test.goindex 04e4082..d13650d 100644--- a/server/task_delete_barrier_test.go+++ b/server/task_delete_barrier_test.go@@ -13,6 +13,7 @@ import ("time""github.com/Autumn-27/artex/agent"+ "github.com/Autumn-27/artex/db")func TestEngineDeleteBarrierRejectsNewTaskOperations(t *testing.T) {@@ -147,7 +148,7 @@ func TestTaskLifecycleRechecksDeleteBarrierAfterConcLock(t *testing.T) {func TestAbortTaskDeleteUsesPersistedPauseAndQueueState(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("delete abort state", "restore persisted barrier", nil, 0, 0)diff --git a/server/task_detail_metrics_test.go b/server/task_detail_metrics_test.goindex 672644e..857918a 100644--- a/server/task_detail_metrics_test.go+++ b/server/task_detail_metrics_test.go@@ -7,12 +7,14 @@ import ("net/http/httptest""strconv""testing"++ "github.com/Autumn-27/artex/db")func TestTaskDetailReturnsListMetrics(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("detail metrics", "goal", nil, 0, 0)diff --git a/server/task_llm_rotation_test.go b/server/task_llm_rotation_test.goindex b590dd4..803614d 100644--- a/server/task_llm_rotation_test.go+++ b/server/task_llm_rotation_test.go@@ -30,7 +30,7 @@ func TestLLMProfilePinRoundTrip(t *testing.T) {func TestRotationConcurrentProvidersAndPrecedence(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable: %v", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)diff --git a/server/task_llm_test.go b/server/task_llm_test.goindex afd2caa..60324f4 100644--- a/server/task_llm_test.go+++ b/server/task_llm_test.go@@ -654,7 +654,7 @@ func TestTaskLLMStreamStopsWhenChainExhausted(t *testing.T) {func TestProfileDeleteRestoresQuotaBlockedIntentWhenFallbackAvailable(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) - skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()diff --git a/server/task_llm_usage_test.go b/server/task_llm_usage_test.goindex fb743a6..9143273 100644--- a/server/task_llm_usage_test.go+++ b/server/task_llm_usage_test.go@@ -259,7 +259,7 @@ func TestTaskLLMOpaqueThinkingCommitsStream(t *testing.T) {func TestTaskLLMRetryKeepsOneLedgerRowPerPhysicalCall(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()pg := m.PG()diff --git a/server/task_metadata_test.go b/server/task_metadata_test.goindex b36a59a..cce96ac 100644--- a/server/task_metadata_test.go+++ b/server/task_metadata_test.go@@ -10,12 +10,14 @@ import ("strconv""strings""testing"++ "github.com/Autumn-27/artex/db")func TestTaskMetadataPatchReturnsRenameAndPin(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("metadata patch", "goal", nil, 0, 0)@@ -65,7 +67,7 @@ func TestTaskMetadataPatchReturnsRenameAndPin(t *testing.T) {func TestConversationBatchDeleteReportsMissing(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()ctx, cancel := context.WithCancel(context.Background())diff --git a/server/task_outcome_test.go b/server/task_outcome_test.goindex c321560..3d2b56e 100644--- a/server/task_outcome_test.go+++ b/server/task_outcome_test.go@@ -14,7 +14,7 @@ import (func TestTaskOutcomeCard(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()task, err := m.CreateTask("outcome card", "goal", nil, 0, 0)diff --git a/server/task_templates_test.go b/server/task_templates_test.goindex 82a18cd..63b6c04 100644--- a/server/task_templates_test.go+++ b/server/task_templates_test.go@@ -17,7 +17,7 @@ import (func TestTaskTemplateHTTPCRUD(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()ctx, cancel := context.WithCancel(context.Background())@@ -89,7 +89,7 @@ func TestTaskTemplateHTTPCRUD(t *testing.T) {func TestConversationPatchReturnsPinState(t *testing.T) {m, err := NewManager(t.TempDir(), "")if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer m.Close()ctx, cancel := context.WithCancel(context.Background())diff --git a/server/testmain_test.go b/server/testmain_test.goindex 817f2f3..9aece34 100644--- a/server/testmain_test.go+++ b/server/testmain_test.go@@ -41,6 +41,6 @@ func TestMain(m *testing.M) {func skipWithoutDSN(t *testing.T) {t.Helper()if _, _, err := db.DSN(); err != nil {- t.Skipf("no database config (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}}diff --git a/server/tools_wire_test.go b/server/tools_wire_test.goindex 15682e1..89ebf2f 100644--- a/server/tools_wire_test.go+++ b/server/tools_wire_test.go@@ -24,11 +24,11 @@ func names(tools []actool.CoreTool) map[string]actool.CoreTool {func TestWireTools(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skipf("no database config (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}pg, err := db.Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}defer pg.Close()@@ -109,11 +109,11 @@ func TestWireTools(t *testing.T) {func TestHealListTaskCredentialsSchema(t *testing.T) {dsn, _, err := db.DSN()if err != nil {- t.Skipf("no database config (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}pg, err := db.Open(dsn)if err != nil {- t.Skipf("postgres unavailable (%v) — skipping", err)+ db.SkipPGUnavailable(t, err)}t.Cleanup(func() { pg.Close() })s := &Server{m: &Manager{pg: pg}}