diff --git a/changelog.d/fixed-writeback-kind-table-parity.md b/changelog.d/fixed-writeback-kind-table-parity.md new file mode 100644 index 0000000000..9d118ce9db --- /dev/null +++ b/changelog.d/fixed-writeback-kind-table-parity.md @@ -0,0 +1 @@ +- Saving the write-back per-kind matrix under Settings → Features no longer wipes overrides it could not show. The table edited only `min_level` and `require_label` but rebuilt the whole `writeback.kinds` map on save, so any edit there silently dropped every kind's `unlabeled_min_level` and `own_only` (and an own-only kind's `min_level`), undoing what hive.yaml or the admin MCP `writeback.kind_policy` operation had set. The table now has *Without label* and *Hive-authored only* columns for those two fields, and saving sends each kind's override with every field nobody changed on the page kept as it was; the `writeback.kind_policy` preview no longer warns about the dashboard dropping them (#17555). diff --git a/src/docs/admin-mcp.md b/src/docs/admin-mcp.md index 546d3333cf..c7b2f14f0b 100644 --- a/src/docs/admin-mcp.md +++ b/src/docs/admin-mcp.md @@ -851,11 +851,11 @@ change between the preview and the confirm, the confirm is refused; preview again. Neither operation kicks an agent, labels, approves or merges anything itself. -The dashboard's write-back kind table edits only `min_level` and -`require_label`, and saving an edit there rewrites every kind's override from -the table, which drops `unlabeled_min_level` and `own_only`. The -`writeback.kind_policy` preview warns when an override it writes carries -either. +The dashboard's write-back kind table (Settings → Features → Write-back +containment) edits the same four fields. Saving there sends every kind's +override from the table, and a field nobody changed on the page is sent as +it was, so an override written by `writeback.kind_policy` survives a later +dashboard edit. `auto_merge.update` changes merge settings, the same settings as the dashboard's merge controls, through `PATCH /api/config/auto-merge`. It is owner diff --git a/src/docs/operator-reference/sweeps-and-operations.md b/src/docs/operator-reference/sweeps-and-operations.md index a61f92a676..5a440315be 100644 --- a/src/docs/operator-reference/sweeps-and-operations.md +++ b/src/docs/operator-reference/sweeps-and-operations.md @@ -519,11 +519,14 @@ the foreign PR. The gate is per write-back *kind*. Each kind has a minimum ACMM level and whether the review opt-in label (`review.require_labels`, default `hive-review`) is required on the PR; both are overridable per kind under -`writeback.kinds..{min_level, require_label, unlabeled_min_level}`. -An owner changes these under Settings → Features, or with the admin MCP -operation `writeback.kind_policy`, which also sets `unlabeled_min_level` and -`own_only` and keeps the overrides of kinds it does not name -([admin-mcp.md](../admin-mcp.md#registered-operations)). +`writeback.kinds..{min_level, require_label, unlabeled_min_level, own_only}`. +`unlabeled_min_level` is the level from which the kind also writes on an +item without the opt-in label; `own_only` keeps it to hive-authored items. +An owner changes all four in the per-kind matrix under Settings → Features +(columns *Min level*, *Opt-in label*, *Without label*, *Hive-authored only*; +saving keeps every field nobody changed on the page), or with the admin MCP +operation `writeback.kind_policy`, which keeps the overrides of kinds it +does not name ([admin-mcp.md](../admin-mcp.md#registered-operations)). The rationale for each default is the same question: does the hive have, at that level, the power the write-back exists to govern? diff --git a/src/pkg/adminmcp/tools_cadence_writeback_ops.go b/src/pkg/adminmcp/tools_cadence_writeback_ops.go index de89806b89..7b46a9aeea 100644 --- a/src/pkg/adminmcp/tools_cadence_writeback_ops.go +++ b/src/pkg/adminmcp/tools_cadence_writeback_ops.go @@ -653,7 +653,7 @@ func (writebackKindPolicyOp) PreviewWithProvider(ctx context.Context, args map[s } var changes []settingChange - var widen, narrow, changed, dashboardLossy []string + var widen, narrow, changed []string for _, kind := range named { cur, present := st.Kinds[kind] next, err := applyWritebackKindChange(kind, cur, present, req[kind]) @@ -719,15 +719,11 @@ func (writebackKindPolicyOp) PreviewWithProvider(ctx context.Context, args map[s var kept []string for k, ov := range after { kindsBody[k] = writebackKindOverrideBody(ov) - if ov.UnlabeledMinLevel != nil || ov.OwnOnly != nil { - dashboardLossy = append(dashboardLossy, k) - } if _, isNamed := req[k]; !isNamed { kept = append(kept, k) } } sort.Strings(kept) - sort.Strings(dashboardLossy) effects := make([]string, 0, len(changes)+5) for _, c := range changes { @@ -741,9 +737,6 @@ func (writebackKindPolicyOp) PreviewWithProvider(ctx context.Context, args map[s "Hive saves it through Settings → Features (PUT /api/config/governor/features, writebackKinds), records a config_governor_features audit entry, and the write-back gate applies it from its next decision, with no restart. That endpoint replaces the whole override map, so this write sends every override with the change merged in. "+keptNote, "The effective policy shown ignores writeback.unsolicited.min_level, which when set still raises every kind's level, and writeback.per_repo, which still sets each repository's mode.", ) - if len(dashboardLossy) > 0 { - effects = append(effects, "Settings → Features' write-back kind table edits only min_level and require_label, and saving an edit there rewrites every kind's override from that table: it would drop unlabeled_min_level and own_only from "+strings.Join(dashboardLossy, ", ")+". Change those through this operation or hive.yaml.") - } effects = append(effects, "This write itself posts, labels, closes and merges nothing.") narrowNote := "" diff --git a/src/pkg/adminmcp/tools_cadence_writeback_ops_test.go b/src/pkg/adminmcp/tools_cadence_writeback_ops_test.go index 1949e6278f..22ff5ff629 100644 --- a/src/pkg/adminmcp/tools_cadence_writeback_ops_test.go +++ b/src/pkg/adminmcp/tools_cadence_writeback_ops_test.go @@ -289,11 +289,16 @@ func TestWritebackKindPolicyOpKeepsUntouchedKinds(t *testing.T) { t.Fatalf("request = %s %s %s, want PUT /api/config/governor/features %s", preview.Request.Method, preview.Request.Path, bodyJSON(t, preview.Request.Body), want) } effects := strings.Join(preview.Effects, "\n") - for _, s := range []string{"writeback.kinds.base_refresh: no override → {unlabeled_min_level: 6}", "L6 with the opt-in label → L6, any item", "(stage_label) are sent unchanged", "would drop unlabeled_min_level and own_only from base_refresh"} { + for _, s := range []string{"writeback.kinds.base_refresh: no override → {unlabeled_min_level: 6}", "L6 with the opt-in label → L6, any item", "(stage_label) are sent unchanged"} { if !strings.Contains(effects, s) { t.Errorf("effects lack %q:\n%s", s, effects) } } + // Settings → Features' kind table now edits and keeps all four fields, + // so the preview no longer warns that a dashboard save would drop them. + if strings.Contains(effects, "would drop") { + t.Errorf("effects still warn that the dashboard drops fields:\n%s", effects) + } if _, err := h.ConfirmWrite(context.Background(), map[string]any{"confirmation_id": id}); err != nil { t.Fatalf("confirm: %v", err) } diff --git a/src/pkg/dashboard/settings_parity_allowlist.txt b/src/pkg/dashboard/settings_parity_allowlist.txt index 57b0fd952d..00b3bbb5c4 100644 --- a/src/pkg/dashboard/settings_parity_allowlist.txt +++ b/src/pkg/dashboard/settings_parity_allowlist.txt @@ -702,8 +702,6 @@ runs.spektacular.interview # TODO #11854 task_mcp.launch_token_ttl # TODO #11854 task_mcp.lease_rate_limit_per_minute # TODO #11854 upstream_watch.repos..start_from # TODO #11854 -writeback.kinds..own_only # policy-file knob; the Settings matrix shows it read-only as the kind's scope -writeback.kinds..unlabeled_min_level # policy-file knob; the Settings matrix shows it read-only in the kind's scope governor.hotspot_enabled # merge-hotspot advisor; yaml-only governor.hotspot_window_days # merge-hotspot advisor; yaml-only governor.hotspot_min_prs # merge-hotspot advisor; yaml-only diff --git a/src/pkg/dashboard/static-src/js/config-sentinel.js b/src/pkg/dashboard/static-src/js/config-sentinel.js index b6f0c387aa..da518f947c 100644 --- a/src/pkg/dashboard/static-src/js/config-sentinel.js +++ b/src/pkg/dashboard/static-src/js/config-sentinel.js @@ -140,11 +140,17 @@ const k = String(row.kind || ''); const p = row.policy || {}; const ov = overrides[k] || {}; const scope = p.own_only ? 'hive-authored only' : (p.require_label ? 'opt-in label' : 'any item'); const unl = p.unlabeled_min_level ? ` · without label L${esc(String(p.unlabeled_min_level))}` : ''; - return ` + const unlOptions = [0, 1, 2, 3, 4, 5, 6].map(n => ``).join(''); + // data-wb-override carries the override this row was rendered from, + // so markDirtyWritebackKinds keeps any field whose control is absent + // or disabled here (an own-only kind's level and label) on save. + return ` ${esc(k)} ${esc(scope)}${unl} ${p.own_only ? '—' : ``} + ${p.own_only ? '—' : ``} + `; }).join(''); return ` @@ -157,8 +163,8 @@
Only PRs carrying the review opt-in label ${settingHelpMark('settings', 'features', 'Write-back requires opt-in label', `When on (default), unsolicited write-backs on a foreign PR also need the review opt-in label (${esc(optIn)}, from review.require_labels). Turning it off lets each kind's level floor alone decide.`)}
Backfill pre-existing items ${settingHelpMark('settings', 'features', 'Write-back backfill', `Off (default): when hive first sees a repo, or first gains write access to one, PRs and issues created before that moment are never written to unsolicited. On: process them like new items.`)}
-
Per-kind matrix ${yamlHint('writeback.kinds..{min_level,require_label}')} ${settingHelpMark('settings', 'features', 'Write-back per-kind matrix', `What hive will say on GitHub at each ACMM level. Each kind has a minimum level and whether the opt-in label is required; leave a cell empty to keep the default shown as placeholder.`)} - ${rows}
KindScopeMin levelOpt-in label
+
Per-kind matrix ${yamlHint('writeback.kinds..{min_level,require_label,unlabeled_min_level,own_only}')} ${settingHelpMark('settings', 'features', 'Write-back per-kind matrix', `What hive will say on GitHub at each ACMM level. Each kind has a minimum level, whether the opt-in label is required, the level from which it also writes on items without that label, and whether it writes on hive-authored items only. Leave a cell empty or on default to keep the value shown. Saving sends every kind's override from this table; a field you did not change is kept.`)} + ${rows}
KindScopeMin levelOpt-in labelWithout label ${settingHelpMark('settings', 'features', 'Write-back level without the opt-in label', `unlabeled_min_level: from this ACMM level the kind also writes on items that do not carry the opt-in label (the sentinel's "L5 with the label, L6 without"). 0 (off) never admits an unlabelled item; default keeps the value shown. Only matters while the kind requires the label.`)}Hive-authored only ${settingHelpMark('settings', 'features', 'Write-back hive-authored only', `own_only: yes means the kind writes only on PRs and issues hive opened, never on anyone else's at any level, and the level and label cells no longer apply. Default keeps the value shown.`)}
Suppressed write-backs (last 24h): …
@@ -179,13 +185,29 @@ markDirty('features', 'writebackPerRepo', out); } + // The Features endpoint replaces the whole writeback.kinds map, so every + // row is rebuilt here. Each starts from the override it was rendered with + // (data-wb-override) and only a live control changes its field: a field + // with no control on the row, or a disabled one, is sent unchanged. function markDirtyWritebackKinds() { const out = {}; document.querySelectorAll('#wb-kind-table tr[data-wb-kind]').forEach(tr => { - const kind = tr.dataset.wbKind; const lvl = tr.querySelector('.wb-kind-level'); const lab = tr.querySelector('.wb-kind-label'); - const ov = {}; - if (lvl && !lvl.disabled && lvl.value !== '') ov.min_level = +lvl.value; - if (lab && lab.value !== '') ov.require_label = lab.value === 'true'; + const kind = tr.dataset.wbKind; + let ov = {}; + try { ov = Object.assign({}, JSON.parse(tr.dataset.wbOverride || '{}')); } catch (e) { ov = {}; } + const level = (el, field) => { + if (!el || el.disabled) return; + if (el.value === '') delete ov[field]; else ov[field] = +el.value; + }; + const flag = (el, field) => { + if (!el || el.disabled) return; + if (el.value === '') delete ov[field]; else ov[field] = el.value === 'true'; + }; + level(tr.querySelector('.wb-kind-level'), 'min_level'); + flag(tr.querySelector('.wb-kind-label'), 'require_label'); + level(tr.querySelector('.wb-kind-unlabeled'), 'unlabeled_min_level'); + flag(tr.querySelector('.wb-kind-own'), 'own_only'); + Object.keys(ov).forEach(field => { if (ov[field] == null) delete ov[field]; }); out[kind] = Object.keys(ov).length ? ov : null; }); markDirty('features', 'writebackKinds', out); diff --git a/src/pkg/dashboard/static-src/js/config-state.js b/src/pkg/dashboard/static-src/js/config-state.js index b222ff690f..caf9302b9b 100644 --- a/src/pkg/dashboard/static-src/js/config-state.js +++ b/src/pkg/dashboard/static-src/js/config-state.js @@ -115,7 +115,7 @@ { tab: 'Features', section: 'Integrations & observability', label: 'GitLab and Gitea forges', key: 'gitlab.gitlab_url', text: 'gitlab gitea forgejo codeberg forge instance url token env gitlab.gitlab_url gitlab.token_env gitea.gitea_url gitea.token_env' }, { tab: 'Features', section: 'Agents & tooling', label: 'Token mint key and TTL', key: 'mint.max_ttl_seconds', text: 'token mint signing key path max ttl lifetime jwt mint.key_path mint.max_ttl_seconds' }, { tab: 'Features', section: 'Autonomy & ACMM', label: 'Design-first planning', key: 'planning.design_approved_label', text: 'planning design approved label architect revisions concurrent designs plan from label planning.design_approved_label planning.max_concurrent_designs planning.max_design_revisions planning.plan_from_label' }, - { tab: 'Features', section: 'Autonomy & ACMM', label: 'Write-back containment', key: 'writeback.unsolicited.min_level', text: 'write-back writeback containment unsolicited comments labels sentinel hold-gate stage labels opt-in label backfill per repo mode suppressed acmm level duplicate dedupe burst rate cap hourly writeback.unsolicited.min_level writeback.unsolicited.require_labels writeback.unsolicited.backfill writeback.per_repo writeback.kinds writeback.dedupe.enabled writeback.dedupe.same_item_ttl writeback.dedupe.burst_items writeback.dedupe.burst_window writeback.dedupe.hourly_cap' }, + { tab: 'Features', section: 'Autonomy & ACMM', label: 'Write-back containment', key: 'writeback.unsolicited.min_level', text: 'write-back writeback containment unsolicited comments labels sentinel hold-gate stage labels opt-in label backfill per repo mode suppressed acmm level duplicate dedupe burst rate cap hourly writeback.unsolicited.min_level writeback.unsolicited.require_labels writeback.unsolicited.backfill writeback.per_repo writeback.kinds unlabeled_min_level own_only without label hive-authored only writeback.dedupe.enabled writeback.dedupe.same_item_ttl writeback.dedupe.burst_items writeback.dedupe.burst_window writeback.dedupe.hourly_cap' }, { tab: 'Features', section: 'Work intake & issue lifecycle', label: 'Superseded PR grace period', key: 'supersession_sweep.grace_period', text: 'supersession superseded grace period close contributor pr supersession_sweep.grace_period' }, { tab: 'Features', section: 'Quality loops & release health', label: 'Compliance posture windows', key: 'compliance.posture_checks.window_days', text: 'compliance posture look-back window history retention compliance.posture_checks.window_days compliance.posture_checks.history_days' }, { tab: 'Features', section: 'Agents & tooling', label: 'Swarm banner wording', key: 'swarm.event_name', text: 'swarm event name call to arms leaderboard title banner swarm.event_name swarm.call_to_arms swarm.leaderboard_title' }, diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 43e061302c..313f760177 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -56549,7 +56549,7 @@

Configure LiteLLM

{ tab: 'Features', section: 'Integrations & observability', label: 'GitLab and Gitea forges', key: 'gitlab.gitlab_url', text: 'gitlab gitea forgejo codeberg forge instance url token env gitlab.gitlab_url gitlab.token_env gitea.gitea_url gitea.token_env' }, { tab: 'Features', section: 'Agents & tooling', label: 'Token mint key and TTL', key: 'mint.max_ttl_seconds', text: 'token mint signing key path max ttl lifetime jwt mint.key_path mint.max_ttl_seconds' }, { tab: 'Features', section: 'Autonomy & ACMM', label: 'Design-first planning', key: 'planning.design_approved_label', text: 'planning design approved label architect revisions concurrent designs plan from label planning.design_approved_label planning.max_concurrent_designs planning.max_design_revisions planning.plan_from_label' }, - { tab: 'Features', section: 'Autonomy & ACMM', label: 'Write-back containment', key: 'writeback.unsolicited.min_level', text: 'write-back writeback containment unsolicited comments labels sentinel hold-gate stage labels opt-in label backfill per repo mode suppressed acmm level duplicate dedupe burst rate cap hourly writeback.unsolicited.min_level writeback.unsolicited.require_labels writeback.unsolicited.backfill writeback.per_repo writeback.kinds writeback.dedupe.enabled writeback.dedupe.same_item_ttl writeback.dedupe.burst_items writeback.dedupe.burst_window writeback.dedupe.hourly_cap' }, + { tab: 'Features', section: 'Autonomy & ACMM', label: 'Write-back containment', key: 'writeback.unsolicited.min_level', text: 'write-back writeback containment unsolicited comments labels sentinel hold-gate stage labels opt-in label backfill per repo mode suppressed acmm level duplicate dedupe burst rate cap hourly writeback.unsolicited.min_level writeback.unsolicited.require_labels writeback.unsolicited.backfill writeback.per_repo writeback.kinds unlabeled_min_level own_only without label hive-authored only writeback.dedupe.enabled writeback.dedupe.same_item_ttl writeback.dedupe.burst_items writeback.dedupe.burst_window writeback.dedupe.hourly_cap' }, { tab: 'Features', section: 'Work intake & issue lifecycle', label: 'Superseded PR grace period', key: 'supersession_sweep.grace_period', text: 'supersession superseded grace period close contributor pr supersession_sweep.grace_period' }, { tab: 'Features', section: 'Quality loops & release health', label: 'Compliance posture windows', key: 'compliance.posture_checks.window_days', text: 'compliance posture look-back window history retention compliance.posture_checks.window_days compliance.posture_checks.history_days' }, { tab: 'Features', section: 'Agents & tooling', label: 'Swarm banner wording', key: 'swarm.event_name', text: 'swarm event name call to arms leaderboard title banner swarm.event_name swarm.call_to_arms swarm.leaderboard_title' }, @@ -68531,11 +68531,17 @@

${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}

+ const unlOptions = [0, 1, 2, 3, 4, 5, 6].map(n => ``).join(''); + // data-wb-override carries the override this row was rendered from, + // so markDirtyWritebackKinds keeps any field whose control is absent + // or disabled here (an own-only kind's level and label) on save. + return ` ${esc(k)} ${esc(scope)}${unl} ${p.own_only ? '—' : ``} + ${p.own_only ? '—' : ``} + `; }).join(''); return ` @@ -68548,8 +68554,8 @@

${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}

Only PRs carrying the review opt-in label ${settingHelpMark('settings', 'features', 'Write-back requires opt-in label', `When on (default), unsolicited write-backs on a foreign PR also need the review opt-in label (${esc(optIn)}, from review.require_labels). Turning it off lets each kind's level floor alone decide.`)}
Backfill pre-existing items ${settingHelpMark('settings', 'features', 'Write-back backfill', `Off (default): when hive first sees a repo, or first gains write access to one, PRs and issues created before that moment are never written to unsolicited. On: process them like new items.`)}
-
Per-kind matrix ${yamlHint('writeback.kinds..{min_level,require_label}')} ${settingHelpMark('settings', 'features', 'Write-back per-kind matrix', `What hive will say on GitHub at each ACMM level. Each kind has a minimum level and whether the opt-in label is required; leave a cell empty to keep the default shown as placeholder.`)} - ${rows}
KindScopeMin levelOpt-in label
+
Per-kind matrix ${yamlHint('writeback.kinds..{min_level,require_label,unlabeled_min_level,own_only}')} ${settingHelpMark('settings', 'features', 'Write-back per-kind matrix', `What hive will say on GitHub at each ACMM level. Each kind has a minimum level, whether the opt-in label is required, the level from which it also writes on items without that label, and whether it writes on hive-authored items only. Leave a cell empty or on default to keep the value shown. Saving sends every kind's override from this table; a field you did not change is kept.`)} + ${rows}
KindScopeMin levelOpt-in labelWithout label ${settingHelpMark('settings', 'features', 'Write-back level without the opt-in label', `unlabeled_min_level: from this ACMM level the kind also writes on items that do not carry the opt-in label (the sentinel's "L5 with the label, L6 without"). 0 (off) never admits an unlabelled item; default keeps the value shown. Only matters while the kind requires the label.`)}Hive-authored only ${settingHelpMark('settings', 'features', 'Write-back hive-authored only', `own_only: yes means the kind writes only on PRs and issues hive opened, never on anyone else's at any level, and the level and label cells no longer apply. Default keeps the value shown.`)}
Suppressed write-backs (last 24h): …
@@ -68570,13 +68576,29 @@

${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}

{ - const kind = tr.dataset.wbKind; const lvl = tr.querySelector('.wb-kind-level'); const lab = tr.querySelector('.wb-kind-label'); - const ov = {}; - if (lvl && !lvl.disabled && lvl.value !== '') ov.min_level = +lvl.value; - if (lab && lab.value !== '') ov.require_label = lab.value === 'true'; + const kind = tr.dataset.wbKind; + let ov = {}; + try { ov = Object.assign({}, JSON.parse(tr.dataset.wbOverride || '{}')); } catch (e) { ov = {}; } + const level = (el, field) => { + if (!el || el.disabled) return; + if (el.value === '') delete ov[field]; else ov[field] = +el.value; + }; + const flag = (el, field) => { + if (!el || el.disabled) return; + if (el.value === '') delete ov[field]; else ov[field] = el.value === 'true'; + }; + level(tr.querySelector('.wb-kind-level'), 'min_level'); + flag(tr.querySelector('.wb-kind-label'), 'require_label'); + level(tr.querySelector('.wb-kind-unlabeled'), 'unlabeled_min_level'); + flag(tr.querySelector('.wb-kind-own'), 'own_only'); + Object.keys(ov).forEach(field => { if (ov[field] == null) delete ov[field]; }); out[kind] = Object.keys(ov).length ? ov : null; }); markDirty('features', 'writebackKinds', out); diff --git a/src/pkg/dashboard/writeback_kind_table_parity_test.go b/src/pkg/dashboard/writeback_kind_table_parity_test.go new file mode 100644 index 0000000000..ef08798530 --- /dev/null +++ b/src/pkg/dashboard/writeback_kind_table_parity_test.go @@ -0,0 +1,153 @@ +package dashboard + +import ( + "os" + "os/exec" + "path/filepath" + "strings" + "testing" +) + +// TestWritebackKindTableKeepsEveryOverrideField runs the Settings → Features +// write-back kind table (renderWritebackContainmentSection) and its save +// handler (markDirtyWritebackKinds) in node. +// +// PUT /api/config/governor/features replaces the whole writeback.kinds map, +// and the handler rebuilds that map from every row of the table. It used to +// read only the min level and opt-in label cells, so any dashboard edit of +// the table silently dropped unlabeled_min_level and own_only from every +// kind (and an own-only kind's min_level, whose cell is disabled), undoing +// what hive.yaml or the admin MCP writeback.kind_policy operation had set. +// +// The fixture's rows are parsed out of the rendered markup, so the handler +// reads exactly the values the operator sees. +func TestWritebackKindTableKeepsEveryOverrideField(t *testing.T) { + node, err := exec.LookPath("node") + if err != nil { + t.Skip("node not on PATH — the write-back kind table save was NOT executed by this run") + } + html := indexHTML(t) + script := strings.Join([]string{ + "function settingHelpMark() { return ''; }", + "function yamlHint() { return ''; }", + "function loadWritebackSuppressed() {}", + "let dirty = {};", + "function markDirty(section, key, value) { dirty[section] = dirty[section] || {}; dirty[section][key] = value; }", + "let rows = [];", + "const document = { querySelectorAll: sel => sel === '#wb-kind-table tr[data-wb-kind]' ? rows : [] };", + jsFunc(t, html, "esc"), + jsFunc(t, html, "renderWritebackContainmentSection"), + jsFunc(t, html, "markDirtyWritebackKinds"), + }, "\n") + writebackKindTableAssertions + + path := filepath.Join(t.TempDir(), "wbkinds.js") + if err := os.WriteFile(path, []byte(script), 0o600); err != nil { + t.Fatal(err) + } + if out, err := exec.Command(node, path).CombinedOutput(); err != nil { + t.Fatalf("write-back kind table check failed:\n%s", strings.TrimSpace(string(out))) + } +} + +const writebackKindTableAssertions = ` +const assert = require('node:assert/strict'); +const decode = s => s.replace(/"/g, '"').replace(/'/g, "'").replace(/`/g, '` + "`" + `').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&'); + +// A browser-shaped row per : dataset from its attributes, +// and each control's value as the browser would report it (a select with no +// selected option reports its first option, the "default" one, value ""). +function parseRows(markup) { + const out = []; + const trRe = /]*)>([\s\S]*?)<\/tr>/g; + let m; + while ((m = trRe.exec(markup))) { + const dataset = { wbKind: decode(m[1]) }; + const ov = /data-wb-override="([^"]*)"/.exec(m[2]); + if (ov) dataset.wbOverride = decode(ov[1]); + const controls = {}; + // Quote-aware: data-setting-key values carry "", whose ">" would + // end a naive [^>]* match before value= and disabled. + const input = /])*class="wb-kind-level"(?:"[^"]*"|[^">])*>/.exec(m[3]); + if (input) { + const v = / value="([^"]*)"/.exec(input[0]); + controls['.wb-kind-level'] = { value: v ? decode(v[1]) : '', disabled: / disabled[ >]/.test(input[0]) }; + } + const selRe = /