Skip to content

No unit tests for core viewer-client.ts logic: toolbar state machine, hydrateViewer, and syncAllControllers #83915

Description

@davinci282828

Severity: medium / Confidence: high / Category: test-gap
Triage: test-gap
Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18)
Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol

Evidence

  • extensions/diffs/src/viewer-client.ts:1-330 (None)

  • extensions/diffs/src/config.test.ts:383-394 (serves the runtime bundle body)

it("serves the runtime bundle body", async () => {
    const runtime = await getServedViewerAsset(VIEWER_RUNTIME_PATH);
    expect(runtime?.contentType).toBe("text/javascript; charset=utf-8");
    expect(String(runtime?.body)).toContain("openclawDiffsReady");
    expect(String(runtime?.body)).toContain('style.width="24px"');
    expect(String(runtime?.body)).toContain('style.gap="6px"');
  });

Reasoning

viewer-client.ts owns the entire client-side diff viewer: payload parsing, shadow-root attachment, toolbar construction, theme/layout toggle state, and multi-card synchronization. The only test coverage it receives is a bundle-content grep in config.test.ts that checks for three minified style string literals. This means: (1) the viewerState singleton's initial-value seeding from firstPayload is untested; (2) toolbar button toggle logic is untested; (3) the ensureShadowRoot fallback path (no template present) is untested; (4) the getHydrateProps branching between fileDiff and oldFile/newFile payloads is untested. A regression in any of these would only be caught at screenshot/E2E level.

Recommendation

Add a viewer-client.test.ts using jsdom (Vitest's default environment) that mocks @pierre/diffs (FileDiff, preloadHighlighter) and exercises: card discovery via getCards, hydrateViewer initial state seeding, toolbar button click toggling viewerState and calling syncAllControllers, and ensureShadowRoot template-clone path.

Why existing tests miss this

No test file targets viewer-client.ts. The associated test list in the feature metadata contains only server-side plugin tests (store, render, config, browser, manifest).

Suggested regression test

Create extensions/diffs/src/viewer-client.test.ts with jsdom environment. Mock @pierre/diffs to expose a FileDiff spy. Set document.readyState to 'complete', inject two .oc-diff-card elements with valid payload scripts and shadow host templates, import the module, and assert (a) controllers has length 2, (b) clicking the layout toggle button updates all controllers via setOptions.

Minimum fix scope

New test file extensions/diffs/src/viewer-client.test.ts covering at minimum: initial viewerState seeding, toolbar toggle round-trip, and the per-card hydration loop.


Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID: fnd_sig-feat-cli-command-1f351e9797-_80cde1830b.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions