Skip to content

Use isUserVisibleField in task-schema-form (closes #2414) - #2421

Merged
malibio merged 2 commits into
mainfrom
issue-2414-user-visible-field
Sep 7, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2414-user-visible-field

Conversation

@malibio

@malibio malibio commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #2414.

What

task-schema-form.svelte was the last surface open-coding the system-field check instead of the shared isUserVisibleField predicate, which the table view, the generic detail form and the relationship column service already use.

-return schema.fields.filter((f) => !CORE_FIELD_NAMES.includes(f.name) && f.protection !== 'system');
+return schema.fields.filter((f) => !CORE_FIELD_NAMES.includes(f.name) && isUserVisibleField(f));

Behavior is unchanged — this closes the drift vector, so a future second condition on "user-visible" reaches this call site too rather than silently keeping the old rule.

The CORE_FIELD_NAMES half of the filter is deliberately left alone: excluding core fields is a separate concern from user-visibility, since core fields render through their own dedicated controls.

Test

Added a case covering a system-protected field on the task schema — no existing case reached one. It asserts against a user-protected sibling field in the same schema, so the system field's absence proves the filter ran rather than the form having rendered nothing. Verified it is a real guard: removing the predicate makes it fail.

Verification

  • bun run test:all — unit 4864 passed (baseline 4863 + the new test), browser 55 passed, all Rust crates green
  • bun run quality:fix — clean, no changes produced
  • grep -rn "protection !== 'system'" packages/desktop-app/src returns only schema-field-visibility.ts ✅

Note: the pre-push gate first failed on a flaky timing assertion (avgScalingFactor < 2.0) in src/tests/performance/architecture-benchmarks.test.ts, unrelated to this change; it passed on re-run.

Acceptance criteria

  • task-schema-form.svelte uses isUserVisibleField for the protection half of the condition
  • CORE_FIELD_NAMES filtering is unchanged
  • Existing task-schema-form.test.ts still passes; extended with a system-protected field case
  • grep -rn "protection !== 'system'" packages/desktop-app/src returns only schema-field-visibility.ts

🤖 Generated with Claude Code

https://claude.ai/code/session_01T35Xv5uqSM5e2DSk19HqDo

task-schema-form was the last surface open-coding `protection !== 'system'`
instead of the shared `isUserVisibleField` predicate, which the table view,
the generic detail form and the relationship column service already use.

Behavior is unchanged — this closes the drift vector, so a future second
condition on "user-visible" reaches this call site too. The CORE_FIELD_NAMES
half of the filter is left alone: excluding core fields is a separate concern
from user-visibility, since core fields render through their own controls.

Adds a test covering a system-protected field on the task schema, which no
existing case reached. It asserts alongside a user-protected sibling so the
absence proves the filter ran rather than an empty form.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01T35Xv5uqSM5e2DSk19HqDo
@malibio

malibio commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2421

Review Type: Initial Review

Scope: 2 files, 1 commit (83d3efa), +34/-1. A deliberate drift-closing refactor with no intended behavior change.


Requirements Check (issue #2414)

Criterion Status
task-schema-form.svelte uses isUserVisibleField for the protection half of the condition ✅ task-schema-form.svelte:122, import at :39
CORE_FIELD_NAMES filtering is unchanged — separate concern ✅ Conjunct is byte-identical; only the second half changed
Existing task-schema-form.test.ts still passes; extend it if no case covers a system-protected field ✅ 15/15 pass locally. New case added; no prior case reached a system-protected field on the task schema
grep -rn "protection !== 'system'" packages/desktop-app/src returns only schema-field-visibility.ts ✅ Verified — single hit, schema-field-visibility.ts:19

All four criteria met.


Verification performed

  • Ran the suite: bun run test -- src/tests/components/property-forms/task-schema-form.test.ts → 15 passed.
  • Mutation-checked the new test — this is the claim worth independently confirming, since a filter test that passes for the wrong reason is worse than no test. Temporarily reduced the predicate to schema.fields.filter((f) => !CORE_FIELD_NAMES.includes(f.name)) and re-ran: exactly 1 failed | 14 passed, failing at task-schema-form.test.ts:438 on queryByLabelText('Transcript') with the leaked id="task-user-capture:transcript" input in the DOM dump. Working tree restored to clean. The test is a real guard, and it is scoped tightly — it fails for the removal it is meant to catch and nothing else.
  • Lint: bunx eslint on both changed files → exit 0, no output.
  • Grep assertion: run directly, as noted above.

Code Review Findings

🟢 Suggestion — the comment above the predicate is now slightly stale

📁 packages/desktop-app/src/lib/components/property-forms/task-schema-form.svelte:118-119

// Get user-defined fields (not core, not system-protected — a system-managed field must
// never render as a user-editable control, mirroring GenericSchemaForm's protection filter).

"mirroring GenericSchemaForm's protection filter" was an accurate description of the old line: it was a hand-copied duplicate of a rule that lived somewhere else, and the comment existed to tell the reader where the original was. After this change the two call sites don't mirror each other — they call the same function, and the reader can now follow the import. The word that named the duplication outlives the duplication.

Nit-level rewrite:

// Get user-defined fields: not core (those render through their own dedicated
// controls above) and user-visible per the shared predicate.

The engineering principle is that a comment's job is to carry the why that the code can't; once isUserVisibleField is right there in the expression, the "must never render as a user-editable control" rationale lives in that function's own docblock (which states it well), and the pointer-to-the-other-copy half is now misdirection. Minor, non-blocking — flagging it because this PR's entire value is readability, so leaving the one line that describes the superseded arrangement is a small missed beat.

🟢 Observation — the test duplicates fixture shapes that schema-fixtures.ts already owns

📁 packages/desktop-app/src/tests/components/property-forms/task-schema-form.test.ts:410-425

The new case inline-constructs its two SchemaField literals, including capture:transcript / 'Transcript' — a field that already exists, verbatim and sourced from core_schemas.rs, in src/tests/helpers/schema-fixtures.ts (AI_CHAT_FIELDS). That helper's own docblock says it was created because these fixtures had been duplicated across two test files and the copies drifted on four type values.

I am not recommending a change here, and want to be explicit about why, since the surface-level DRY read points the other way:

  • The fixtures file models whole core schemas (PERSON_FIELDS, AI_CHAT_FIELDS) for tests that assert the predicate against what production ships. This test needs two throwaway fields bolted onto realTaskSchema() — a different shape of need, and AI_CHAT_FIELDS is not importable piecemeal for it.
  • The inline literals match the immediately preceding test in this file (:388-395) exactly, and local consistency inside a 440-line test file is worth more here than a cross-file import.
  • The drift risk the helper guards against doesn't apply: these fields are deliberately synthetic, not claims about core_schemas.rs. Nothing breaks if the real capture:transcript changes type.

Borrowing the name capture:transcript is a nice touch — it makes the test read as "the worst realistic leak", matching the fixtures docblock's framing of that field as raw PTY scrollback. Noting this so a future reader (or reviewer) doesn't mistake it for an oversight.


What the PR gets right

  • Correctly resisted over-reach. The obvious "improvement" here would have been folding CORE_FIELD_NAMES into the shared helper too. Both the commit message and PR body explain why not: core-field exclusion is a different question ("does this field have its own dedicated control on this form?") from user-visibility ("may a user ever see this?"), and it's specific to this one form. Merging them would have coupled an unrelated concern into a predicate three other surfaces depend on. This is the right call and it is documented at both the commit and PR level.
  • The test asserts a negative correctly. queryByLabelText(...) === null is a claim that proves nothing on its own — an empty form satisfies it. Pairing it with a user-protected sibling that must be present converts it into a real assertion, and the inline comment says exactly that. This is the difference between a test and a decoration.
  • Honest reporting. The PR body flags the flaky avgScalingFactor < 2.0 perf assertion that failed on the first pre-push attempt rather than quietly re-running until green.
  • Import placement, $derived.by usage, vi.spyOn(backendAdapter, 'getSchema') mocking, and openForm(container) all match the established patterns in their respective files. No any, no lint suppression, no console.*, no new dependency.

Security / Performance

No findings. The predicate is a pure field-level comparison inside an existing $derived.by; no change to allocation, iteration count, or reactivity graph. On the security side this change is directionally positive — it puts the last remaining copy of a filter that keeps system-owned fields (documented as potentially containing secrets and tokens) out of the UI behind a single definition, so hardening it later hardens every surface at once.


Recommendation: APPROVE

Net positive on code health with zero behavior risk, all four acceptance criteria independently verified, and the one new test confirmed by mutation to be a genuine guard rather than a passing decoration. The single 🟢 comment-staleness note is optional polish and should not block merge.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

The comment said the filter mirrored "GenericSchemaForm's protection filter",
which described the hand-copied duplicate this PR removed. The two call sites
no longer mirror each other — they call the same function, and the reader can
follow the import — so that clause pointed at an arrangement that no longer
exists.

Replaced it with the why the code cannot carry: that the two conjuncts answer
different questions and are deliberately separate, so a later reader does not
"simplify" CORE_FIELD_NAMES into the shared predicate. The system-field
rationale now lives in isUserVisibleField's own docblock.

Comment-only; no behavior or test change.

Skipped the reviewer's second 🟢 note (inline SchemaField literals vs
schema-fixtures.ts) — it was explicitly raised as an observation rather than a
recommendation, and its reasoning holds: the fixtures model whole core schemas,
while this test needs two throwaway fields bolted onto realTaskSchema().

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01T35Xv5uqSM5e2DSk19HqDo
@malibio

malibio commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Address Review — Summary

Review verdict was APPROVE with two 🟢 items and no 🔴/🟡 findings.

✅ Addressed (1)

🟢 Stale comment above userDefinedFields — task-schema-form.svelte:118-119 (commit 542e591f)

The reviewer was right that "mirroring GenericSchemaForm's protection filter" described the hand-copied duplicate this PR removed — the two call sites no longer mirror each other, they call the same function.

Rather than only deleting the stale clause, I replaced it with the why the code genuinely cannot carry: that the two conjuncts answer different questions and are deliberately separate. That is the non-obvious fact a future reader is most likely to get wrong — the tempting "cleanup" here is to fold CORE_FIELD_NAMES into the shared predicate, which would couple a form-specific concern into a helper three other surfaces depend on. The system-field rationale itself now lives where it belongs, in isUserVisibleField's own docblock.

// Get user-defined fields: not core, and user-visible per the shared predicate.
// The two conjuncts answer different questions and deliberately stay separate — core
// fields are excluded because they already render through their own dedicated controls
// above, which is specific to this form, whereas isUserVisibleField answers "may a user
// ever see this?" for every surface that renders schema fields.

⏭️ Skipped (1)

🟢 Inline SchemaField literals vs schema-fixtures.ts — raised explicitly as an observation, not a recommendation ("I am not recommending a change here"). Its reasoning holds and I agree: the fixtures file models whole core schemas for tests asserting against what core_schemas.rs ships, whereas this test needs two throwaway fields bolted onto realTaskSchema(); AI_CHAT_FIELDS is not importable piecemeal for that; and the inline literals match the immediately preceding test in the same file. The drift risk the helper guards against does not apply, since these fields are deliberately synthetic rather than claims about production.

Verification

  • bun run test -- src/tests/components/property-forms/task-schema-form.test.ts → 15 passed
  • bun run quality:fix → 0 errors, 0 warnings across 2498 files; produced no reformatting
  • Pre-push gate (test:all + cargo build + test:e2e) → passed clean, no flake on this run

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The only change since the reviewed commit is a five-line source comment. No logic, control flow, types, tests, or public surface were touched — git diff 83d3efad..542e591f is comment lines exclusively. The reviewer had already independently mutation-verified the test and confirmed all four acceptance criteria, and none of that verification is invalidated by a comment edit. Re-running the review would re-examine prose that carries no execution risk.

The PR is ready for merge, pending the author's decision.

🤖 Generated with Claude Code

https://claude.ai/code/session_01T35Xv5uqSM5e2DSk19HqDo

@malibio
malibio merged commit 6d571c2 into main Sep 7, 2026
@malibio
malibio deleted the issue-2414-user-visible-field branch September 7, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task-schema-form open-codes the system-field predicate instead of isUserVisibleField

1 participant