Skip to content

test(browser): replace docFrameEnvelope type assertions with an isRecord guard - #18816

Closed
chiliec wants to merge 2 commits into
Comfy-Org:mainfrom
chiliec:test/browser-fixtures-isrecord-guard
Closed

chiliec wants to merge 2 commits into
Comfy-Org:mainfrom
chiliec:test/browser-fixtures-isrecord-guard

Conversation

@chiliec

@chiliec chiliec commented Sep 25, 2026

Copy link
Copy Markdown

Summary

Replace the two as casts in docFrameEnvelope with a shared isRecord type guard, so the compiler checks the narrowing instead of taking it on trust.

Changes

  • What:
    • Add browser_tests/fixtures/utils/isRecord.ts (next to jsonRoute.ts), plus a small vitest.
    • agentFollowerHostSocket.ts: docFrameEnvelope narrows frame and data with isRecord, and both assertions are gone. Runtime behavior is unchanged.
    • agentGraphOpLostOnDisconnect.spec.ts: drop its inline copy of the same guard and import the shared one. That makes two callers, the bar the issue sets for a module. The other private isRecords under browser_tests/fixtures/customNode/ are left alone, following the issue's "adopt as they come up, not in a sweep".

Review Focus

Test-only, with no production code touched.

Validation:

  • pnpm exec vitest run browser_tests/fixtures/utils/isRecord.test.ts: 2/2 pass.
  • oxfmt --check, oxlint and eslint on the 4 touched files: clean.
  • Type check: my machine is memory-capped and the full vue-tsc --project browser_tests/tsconfig.json gets OOM-killed there, so I ran tsc against a narrowed project (same compiler options, just the touched files plus the global .d.ts includes). The error set before and after the change is identical: only pre-existing .vue module resolutions that plain tsc can't follow, with nothing in browser_tests/. As a sanity check, loosening the guard's return type to boolean makes tsc reject both callers (TS2339 / TS18046), so the narrowing really is compiler-checked now. CI's typecheck:browser is the authoritative run.

Fixes #18805

@chiliec
chiliec requested a review from a team September 25, 2026 07:27
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged.
Posted by the CLA Assistant Lite bot.

@datadog-official

datadog-official Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c109520 | Docs | Give us feedback!

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🎨 Storybook: 🚧 Building...

🎭 Playwright: ⏳ Running...

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between df55a0b and c109520.

📒 Files selected for processing: 1
  • browser_tests/fixtures/agentWireFrame.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The browser-test utilities add and test a shared isRecord type guard. WebSocket frame parsers and an agent subscription-frame parser use the guard.

Changes: Browser-test record validation

Layer / File(s) Summary
Add and test shared record guard
browser_tests/fixtures/utils/isRecord.ts, browser_tests/fixtures/utils/isRecord.test.ts
Adds isRecord to accept non-null objects and tests accepted and rejected values.
Use shared guard in frame parsers
browser_tests/fixtures/agentFollowerHostSocket.ts, browser_tests/fixtures/agentWireFrame.ts, browser_tests/tests/agent/agentGraphOpLostOnDisconnect.spec.ts
docFrameEnvelope and isWireEnvelopeShaped use isRecord for record checks. The agent spec replaces its local guard with the shared utility.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Possibly related PRs

  • Comfy-Org/ComfyUI_frontend#21497: Extends the parsed ClientDocFrame path in agentFollowerHostSocket.ts with tab, actor, reconnect, and human-batch validation.

Suggested reviewers: christian-byrne

Merge Risk: ⚪ Minimal · up to c1095

The test-only guard consolidation preserves existing frame validation behavior and presents no actionable merge-blocking risk.

Architecture risk: 🟡 Medium · up to df55a

The change affects 1 system.

Changed systems: browser_tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — browser_tests (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in browser_tests/fixtures/agentFollowerHostSocket.ts: Imports the shared isRecord type guard for envelope validation.
  • observed — Modified behavior in browser_tests/fixtures/agentFollowerHostSocket.ts: docFrameEnvelope now uses isRecord to reject non-record frames and data values instead of checking object/null and casting them to record types; the doc_* type check remains unchanged.
  • observed — Modified behavior in browser_tests/fixtures/utils/isRecord.test.ts: Added tests specifying the accepted and rejected input cases for isRecord.
  • observed — Modified behavior in browser_tests/fixtures/utils/isRecord.ts: Adds the exported isRecord type guard, which accepts non-null objects and rejects other values.

Reliability and maintainability

  • inferred — Risk-relevant change factors for browser_tests: blast_radius_1; direct_dependents_1
Pre-merge checks: Passed 7
Check name Status Explanation
Description check Passed The description explains the change, scope, runtime behavior, review focus, validation results, known type-check limitation, and linked issue. It uses a "Validation" section instead of the template's …
Title check Passed The title is concise, specific, and accurately describes the main change: replacing type assertions with an isRecord guard in browser tests.
Linked Issues check Passed The PR satisfies the coding requirements in [#18805]. isRecord is defined in browser_tests/fixtures/utils/isRecord.ts with the required type-guard return type. docFrameEnvelope uses it before re…
Out of Scope Changes check Passed The changes stay within [#18805]. The changed files are browser-test fixtures, browser-test specifications, and the shared fixture utility and test. The additional agentWireFrame.ts use replaces the…
End-To-End Regression Coverage For Fixes Passed PASS. The PR title and both commit subjects do not use bug-fix language. The changed files are under browser_tests/, and the custom check therefore does not require an end-to-end regression test.
Website End-To-End Regression Coverage Passed No changed file is under apps/website/src/ or apps/website/public/. The PR changes only browser-test fixtures, utilities, and a browser test, so the website end-to-end regression check does not ap…
Adr Compliance For Entity/Litegraph Changes Passed The changed files are limited to browser test fixtures, utilities, and specs under browser_tests/. No files under src/lib/litegraph/, src/ecs/, or graph-entity-related paths are changed. The ADR compl…
Full details: Description check

Explanation

The description explains the change, scope, runtime behavior, review focus, validation results, known type-check limitation, and linked issue. It uses a "Validation" section instead of the template's "Verification" heading, but it provides the required verification information.

Full details: Linked Issues check

Explanation

The PR satisfies the coding requirements in [#18805]. isRecord is defined in browser_tests/fixtures/utils/isRecord.ts with the required type-guard return type. docFrameEnvelope uses it before reading type and data, and the two assertions are removed. The shared guard is also used by agentGraphOpLostOnDisconnect.spec.ts and agentWireFrame.ts. The supplied test evidence reports coverage for accepted and rejected values.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#18805]. The changed files are browser-test fixtures, browser-test specifications, and the shared fixture utility and test. The additional agentWireFrame.ts use replaces the same local object narrowing with the requested shared guard. No production code change is shown.

Full details: Website End-To-End Regression Coverage

Explanation

No changed file is under apps/website/src/ or apps/website/public/. The PR changes only browser-test fixtures, utilities, and a browser test, so the website end-to-end regression check does not apply.

Full details: Adr Compliance For Entity/Litegraph Changes

Explanation

The changed files are limited to browser test fixtures, utilities, and specs under browser_tests/. No files under src/lib/litegraph/, src/ecs/, or graph-entity-related paths are changed. The ADR compliance check is therefore not applicable.

✨ Finishing Touches: 💡 1
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch test/browser-fixtures-isrecord-guard
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 25, 2026
@chiliec

chiliec commented Sep 25, 2026

Copy link
Copy Markdown
Author

I have read and agree to the Contributor License Agreement

comfy-legal added a commit to Comfy-Org/comfy-cla that referenced this pull request Sep 25, 2026
@DrJKL DrJKL added agent Comfy Agent product, integration, tests or product documentation agent-test-only Agent tests, fixtures and test support only; no production changes agent-test-playwright Touches Agent-related Playwright tests, fixtures or configuration agent-test-unit Touches Agent-related unit/component tests or their support labels Sep 25, 2026
Co-authored-by: vansh-nagar <vansh.nagar.dev@gmail.com>
@christian-byrne

Copy link
Copy Markdown
Contributor

The consolidation with #18825 is now complete in c109520. This carrier now has the shared guard’s unit test and both use sites, including agentWireFrame.ts; the added commit credits #18825’s author. The affected parser, follower-socket, and guard suites pass (15 tests), as do browser typecheck and lint.

@christian-byrne

Copy link
Copy Markdown
Contributor

This is the active carrier for the record-guard consolidation after #18825 was folded into it, but it cannot land as it stands: it conflicts with main on a fork branch, and one of its three call sites is now obsolete. The local guard it removes from agentGraphOpLostOnDisconnect.spec.ts already went away upstream together with the subscriptionFrameOf helper that used it.

The surviving two call sites plus the shared guard and its unit test are re-authored on current main in #21995, with one change to the helper: it excludes arrays, because value is Record<string, unknown> is false for an array and three sibling guards in browser_tests/fixtures/customNode/ already exclude them. Neither call site changes outcome for a valid frame.

Nothing is needed from you here. Leaving this open rather than closing it, in case you would rather land your own branch: if you rebase it, #21995 can be dropped instead.

nina-mir pushed a commit to nina-mir/ComfyUI_frontend that referenced this pull request Oct 30, 2026
…omfy-Org#21995)

## Summary

The agent follower browser fixtures each hand-rolled the same `typeof x
=== 'object' && x !== null` check before reading a parsed `doc_*` frame.
This replaces the two remaining copies with one guard under
`browser_tests/fixtures/utils/`, plus a unit test for it.

This carries the surviving part of
[Comfy-Org#18816](Comfy-Org#18816) (the
same consolidation, by @chiliec, which also absorbed Comfy-Org#18825). That PR is
conflicting against `main` on a fork branch and has been open since
September, so this is the same change re-authored on current `main`
where it can land. Two non-obvious differences, both deliberate:

**The guard excludes arrays.** `value is Record<string, unknown>` is
false for an array, so admitting one lets a caller index it by string
key with no complaint from the compiler, and three sibling guards in
`browser_tests/fixtures/customNode/` already exclude them. A shared
helper under `fixtures/utils/` is the one future callers will import, so
it should not mean the opposite of its neighbours. Both call sites
already reject an array one line later, because `type` and `op` read as
`undefined`, so no valid frame changes outcome. The only behaviour
difference is that an array `data` now returns `null` instead of being
handed back typed as a record.

**`agentGraphOpLostOnDisconnect.spec.ts` is untouched.** Comfy-Org#18816 also
removed a local copy of the guard from that spec. That copy went away
upstream along with the `subscriptionFrameOf` helper that used it, so
there is no longer a duplicate there to remove.

## Verification

- `pnpm vitest run browser_tests/fixtures/utils/isRecord.test.ts`
passes, and the array cases fail against the array-accepting version, so
the tightening is actually covered rather than assumed.
- `pnpm typecheck` and `pnpm typecheck:browser` are clean, which is what
covers the two fixture call sites narrowing correctly.
- `oxfmt --check` and `oxlint` clean on the four files.
- Not run locally: the agent Playwright specs that consume these
fixtures. They need a cloud-distribution dev server, and the change is
behaviour-preserving for every valid frame, so CI is the right place for
that leg.
@christian-byrne

Copy link
Copy Markdown
Contributor

Closing as superseded by #21995 (merged 2026-10-29, cfa7aa59c4). main's agentFollowerHostSocket.ts and agentWireFrame.ts now narrow with isPlainObject from es-toolkit and carry no as assertions on the envelope types, and agentGraphOpLostOnDisconnect.spec.ts no longer defines a local isRecord. Verified directly against main rather than inferring from the diff. Thanks for the fix either way; happy to revisit if something here is still missing on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Comfy Agent product, integration, tests or product documentation agent-test-only Agent tests, fixtures and test support only; no production changes agent-test-playwright Touches Agent-related Playwright tests, fixtures or configuration agent-test-unit Touches Agent-related unit/component tests or their support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace the type assertions in agentFollowerHostSocket's docFrameEnvelope with a checked record guard

3 participants