Files
archie/internal/webui/config_schema_test.go
T
sam 757b75de94 feat(postgres): wire the State Store to Postgres — DB URL, fail-closed pool, composition seam
Wave 1 of the Postgres migration (archie-core-7r0x.9). This is the shared shape
every port lane builds on; nothing here switches a live path to Postgres yet.

- config: add `database_url` beside `db_path` (config.go), mark it bootstrap-only
  in denied_keys, expose it in the webui StorageView/config schema, and add it to
  config.example.toml plus all deployments/*.toml.
- docker-compose: add a postgres:18 service; `task dev` (dev:postgres) brings it
  up and waits for it before the State Store boots.
- archied: `openStateStore` now opens and migrates the process-scoped Postgres
  pool via `openStateStorePool`. The State Store fails closed (D1.2) when
  database_url is absent or invalid rather than fall back to SQLite; serving
  against Postgres later requires an import-completion record (D1.3), which is a
  later lane's gate, not this one.
- composition seam: task-store construction (state_store_task.go) and EDA-store
  construction (state_store_eda.go) are extracted from openStateStore, with the
  pool open in state_store_pool.go. This is a behaviour-preserving refactor only
  — no store, interface, error, ordering or logging change — so L1 and L2 build
  against separate files instead of sharing state_store.go.

Tests: fail-closed pool behaviour is pinned (absent/invalid URL); the State Store
boot/restart tests now run against a throwaway Postgres 18 container (pgtest
TestMain). Scoped test command and module-wide build pass; see lane report.
2026-09-24 02:18:56 +10:00

161 lines
6.8 KiB
Go

package webui
import "testing"
// TestConfigFieldDescriptorsAreComplete guards the deliberateness the design
// doc asks for (docs/prds/config-schema.md): every field must carry a key,
// label, and type, and every field's Editable/RestartRequired must have been
// set by a case in configFieldDescriptors rather than defaulted to Go's
// zero value. Since Go cannot distinguish "explicitly false" from
// "unset," this test instead pins the exact set of keys and their
// deliberate values, so a new field added to the catalog without visiting
// this test fails loudly rather than silently inheriting Editable: false.
func TestConfigFieldDescriptorsAreComplete(t *testing.T) {
seen := map[string]bool{}
for _, section := range configFieldDescriptors() {
if section.ID == "" {
t.Errorf("section with empty ID, label %q", section.Label)
}
if section.Label == "" {
t.Errorf("section %q has no label", section.ID)
}
if section.Description == "" {
t.Errorf("section %q has no description", section.ID)
}
if len(section.Fields) == 0 {
t.Errorf("section %q has no fields", section.ID)
}
for _, f := range section.Fields {
if f.Key == "" {
t.Fatalf("section %q has a field with no key", section.ID)
}
if seen[f.Key] {
t.Errorf("duplicate field key %q", f.Key)
}
seen[f.Key] = true
if f.Label == "" {
t.Errorf("field %q has no label", f.Key)
}
if f.Type == "" {
t.Errorf("field %q has no type", f.Key)
}
if f.Type == FieldEnum && len(f.Options) == 0 {
t.Errorf("field %q is type enum but has no options", f.Key)
}
if f.Type != FieldEnum && len(f.Options) != 0 {
t.Errorf("field %q has options but is not type enum", f.Key)
}
// Value/LockedReason are attached per-instance
// against a live ConfigView (archie-core-b6ew.2), not part of
// the static catalog -- the catalog must not pre-populate them.
if f.Value != nil {
t.Errorf("field %q has a static Value; that is attached per-request", f.Key)
}
if f.LockedReason != "" {
t.Errorf("field %q has a static LockedReason; that is attached per-request", f.Key)
}
}
}
// Every dotted key settings.js hardcodes today must have a descriptor,
// so the schema is a superset (ideally exact set) of what the frontend
// currently renders -- see ui/src/settings/settings.js.
wantKeys := []string{
"bot_user", "bot_email", "label", "forge.type", "forge.host", "diff_cap_lines",
"repos", "models", "providers",
"budgets.max_steps", "budgets.wall_clock", "budgets.gate_max_failures",
"work_dir", "db_path", "database_url", "skills_dir", "plugin_dir", "secret_engine_dir",
"containers.image", "containers.max_concurrency", "containers.max_uptime",
"containers.volume_ttl", "containers.pull_policy", "containers.network",
"web.listen",
}
for _, key := range wantKeys {
if !seen[key] {
t.Errorf("missing descriptor for %q, which settings.js already hardcodes", key)
}
}
if len(seen) != len(wantKeys) {
t.Errorf("configFieldDescriptors has %d keys, want exactly %d (extra keys need adding to wantKeys deliberately)", len(seen), len(wantKeys))
}
}
// TestConfigFieldDescriptorsRestartRequiredIsDeliberate pins the exact
// RestartRequired value per field against the evidence in
// configFieldDescriptors' own doc comment (internal/app/archied/reload.go's
// reloadableFields/reloadableSubFields allowlist), so a field added or
// reclassified without checking reload.go fails loudly instead of quietly
// defaulting to false ("this takes effect immediately") when it does not.
func TestConfigFieldDescriptorsRestartRequiredIsDeliberate(t *testing.T) {
want := map[string]bool{
"bot_user": false,
"bot_email": false,
"label": false,
"forge.type": true, // reloadableSubFields["Forge"] allows only Host
"forge.host": false,
"diff_cap_lines": false,
"repos": false,
"models": false,
"providers": false,
"budgets.max_steps": false,
"budgets.wall_clock": false,
"budgets.gate_max_failures": false,
"work_dir": false, // locked, not merely restart-required
"db_path": false, // locked, not merely restart-required
"database_url": false, // locked, not merely restart-required
"skills_dir": true, // absent from reloadableFields
"plugin_dir": true,
"secret_engine_dir": true,
"containers.image": true, // absent from reloadableSubFields["Containers"]
"containers.max_concurrency": true,
"containers.max_uptime": true,
"containers.volume_ttl": false, // reloadableSubFields["Containers"] allows VolumeTTL
"containers.pull_policy": true,
"containers.network": true,
"web.listen": true, // Web is absent from both allowlists entirely
}
for _, section := range configFieldDescriptors() {
for _, f := range section.Fields {
wantRestart, ok := want[f.Key]
if !ok {
t.Errorf("field %q has no RestartRequired expectation in this test; add one against internal/app/archied/reload.go before adding the field", f.Key)
continue
}
if f.RestartRequired != wantRestart {
t.Errorf("field %q RestartRequired = %v, want %v", f.Key, f.RestartRequired, wantRestart)
}
}
}
}
// TestConfigFieldDescriptorsStructuredFieldsAreNotEditable pins the design
// decision that structured fields (repositories, models, providers) stay
// read-only until archie-core-b6ew.4 gives them a dedicated editor -- the
// generic scalar renderer (archie-core-b6ew.3) must skip them, not attempt
// a text-input edit on a field whose Value is an array or map.
func TestConfigFieldDescriptorsStructuredFieldsAreNotEditable(t *testing.T) {
for _, section := range configFieldDescriptors() {
for _, f := range section.Fields {
if f.Type == FieldStructured && f.Editable {
t.Errorf("field %q is type structured but marked editable; structured fields need archie-core-b6ew.4's dedicated editor first", f.Key)
}
}
}
}
// TestConfigFieldDescriptorsLockedStorageFieldsAreNotEditable pins
// work_dir/db_path as Editable: false in the static catalog. They are also
// reported LockedReason at runtime via overlay.DeniedKeys (api_config.go),
// but the catalog marks them non-editable independently so the generic
// renderer does not need runtime state to know not to offer an edit
// affordance for a key that can never succeed.
func TestConfigFieldDescriptorsLockedStorageFieldsAreNotEditable(t *testing.T) {
locked := map[string]bool{"work_dir": true, "db_path": true, "database_url": true}
for _, section := range configFieldDescriptors() {
for _, f := range section.Fields {
if locked[f.Key] && f.Editable {
t.Errorf("field %q is denied at runtime (overlay.DeniedKeys) but marked editable in the static catalog", f.Key)
}
}
}
}