skills_dir, plugin_dir, secret_engine_dir and containers.* were listed as editable in /api/config's schema while the plugin-settings and container-runtime-policies resources own those values at runtime; nothing could save them there. Drop them from the catalog, and delete the settings components that rendered the catalog, none of which any page used.
150 lines
6.2 KiB
Go
150 lines
6.2 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", "state_dir", "database_url",
|
|
"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
|
|
"state_dir": false, // locked, not merely restart-required
|
|
"database_url": false, // locked, not merely restart-required
|
|
"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/database_url 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, "state_dir": 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)
|
|
}
|
|
}
|
|
}
|
|
}
|