Skip to content

fix(build): support consolidated Dashboard chat preferences - #196

Merged
zouyonghe merged 2 commits into
mainfrom
fix/upstream-chat-preferences-check
Nov 21, 2026
Merged

zouyonghe merged 2 commits into
mainfrom
fix/upstream-chat-preferences-check

Conversation

@zouyonghe

@zouyonghe zouyonghe commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary / 改动概述

AstrBot Core moved chat transport preferences into chatPreferences(). The desktop resource verifier still expected direct localStorage reads and writes in the chat components, which stopped all six platform jobs during the November 20 nightly build for Core feb3e82.

  • Accept the direct storage API used by stable releases and the consolidated preferences API used by nightly.
  • When the components use chatPreferences(), require evidence that it imports and persists the legacy transport key that the desktop bridge seeds for the WebSocket default. Validate the shared helper once.

Verification / 验证方式

  • pnpm run prepare:webui completed on Windows against the exact Core SHA from the failed nightly and produced resources/webui/index.html.
  • Strict bridge validation passed against the upstream Dashboard sources from both v4.29.4 and feb3e82.
  • All 19 focused bridge tests passed, including coverage for both storage formats and rejection of a broken legacy mapping.
  • The full Node script suite on Windows reported 181 passed, 39 failed, and 2 skipped. The same 39 tests failed on base 807c5eb on this machine.

Checklist / 检查清单

  • Validated locally.
  • Current stable and nightly source formats are covered.

Summary by Sourcery

Update desktop bridge validation to support consolidated Dashboard chat preferences while preserving compatibility with the legacy transport storage key.

Bug Fixes:

  • Support both legacy direct localStorage and consolidated chatPreferences() formats for chat transport settings during desktop resource verification.
  • Require consolidated preferences to preserve migration of the legacy WebSocket transport key, including for tagged releases.

Enhancements:

  • Ensure Chat.vue and StandaloneChat.vue use a consistent chat transport preference format and avoid duplicate bridge expectations.

Build:

  • Update desktop bridge resource validation to recognize and validate both stable and nightly Dashboard source formats.

Tests:

  • Add focused coverage for legacy and consolidated preference formats, migration validation, format mismatches, and tagged-release enforcement.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/prepare-resources/desktop-bridge-expectations.mjs" line_range="71" />
<code_context>
+    const file = path.join(dashboardDir, ...relativePath.split('/'));
+    await mkdir(path.dirname(file), { recursive: true });
+    await writeFile(file, source, 'utf8');
+  };
+
+  await writeSource(
</code_context>
<issue_to_address>
**Tagged builds miss seeded transport default**

When a tagged Dashboard uses consolidated preferences without a working migration and strict bridge checks are disabled, `shouldEnforceDesktopBridgeExpectation` returns false for the required migration, so `verifyDesktopBridgeArtifacts` only warns and the build continues; consolidated preferences do not import the bridge-seeded WebSocket default, so the chat UI uses the wrong transport default.

Make required migration expectations enforceable for tagged builds even when strict bridge checks are disabled.

Also at `scripts/prepare-resources/desktop-bridge-expectations.mjs:127`.
</issue_to_address>

### Comment 2
<location path="scripts/prepare-resources/desktop-bridge-expectations.mjs" line_range="126" />
<code_context>
     filePath: ['src', 'components', 'chat', 'Chat.vue'],
-    pattern: DESKTOP_BRIDGE_PATTERNS.chatTransportPreferenceRead,
+    pattern: DESKTOP_BRIDGE_PATTERNS.legacyChatTransportPreferenceRead,
+    fallbackPattern: DESKTOP_BRIDGE_PATTERNS.chatTransportPreferenceRead,
+    fallbackRequirement: CHAT_TRANSPORT_MIGRATION,
     label: 'chat transport preference read',
</code_context>
<issue_to_address>
**Mixed preferences drift apart**

When an upstream Dashboard updates only one chat component to `chatPreferences()` while another still reads the legacy key, the verifier accepts each component’s format independently, so a Dashboard with consolidated preferences in `Chat.vue` and legacy storage in `StandaloneChat.vue` passes after the helper migration is checked. When the user changes the transport in `Chat.vue`, the consolidated preference changes but the standalone component still reads the old storage value, so the two chat views use different transports.

Require both chat components to use the same preference format, or otherwise verify that writes keep both formats synchronized.

Also at `scripts/prepare-resources/desktop-bridge-expectations.mjs:136`, `scripts/prepare-resources/desktop-bridge-expectations.mjs:144`.
</issue_to_address>

### Comment 3
<location path="scripts/prepare-resources/desktop-bridge-checks.mjs" line_range="143" />
<code_context>
-      } else {
-        console.warn(`${message} (compatibility check skipped)`);
-      }
+    if (expectation.pattern.test(source)) continue;
+    if (expectation.fallbackPattern?.test(source)) {
+      expectations.add(expectation.fallbackRequirement);
</code_context>
<issue_to_address>
**Broken migration passes bridge validation**

When a component retains matching legacy storage access while also using `chatPreferences()`, `verifyDesktopBridgeArtifacts` matches the legacy pattern and continues before checking the fallback pattern, so it never queues the migration requirement; validation passes with a broken migration and consolidated preferences can miss the bridge-seeded WebSocket default.

Check for consolidated preference usage and queue its migration requirement even when the legacy pattern also matches.
</issue_to_address>

### Comment 4
<location path="scripts/prepare-resources/desktop-bridge-expectations.mjs" line_range="58-61" />
<code_context>
+  ),
+  chatTransportPreferenceWrite:
+    /chatPreferences\(\s*\(\s*(\w+)\s*\)\s*=>\s*\{\s*\1\.global\.transportMode\s*=/,
+  chatTransportPreferenceMigration: new RegExp(
+    String.raw`["']${CHAT_TRANSPORT_STORAGE_KEY_PATTERN}["']\s*:\s*["']transportMode["']` +
+      String.raw`[\s\S]*?target\.getItem\(key\)[\s\S]*?preferences\.global\[field\]\s*\?\?=\s*value` +
+      String.raw`[\s\S]*?target\.setItem\(CHAT_PREFERENCES_KEY,`,
+  ),
+};
</code_context>
<issue_to_address>
**Unrelated helper snippets satisfy migration check**

When the expected mapping, assignment, and persistence expressions appear in separate or inactive code, the migration regex scans the whole helper source without verifying that these operations belong to the same reachable migration path, so the verifier accepts a broken helper and desktop builds can ship without persisting the seeded WebSocket preference.

Verify that the mapping, assignment, and persistence operations occur together on the reachable migration path.
</issue_to_address>

Sourcery assessment

Approval pending. 4 findings to address first.

Blocking findings: scripts/prepare-resources/desktop-bridge-expectations.mjs:71, scripts/prepare-resources/desktop-bridge-expectations.mjs:126, scripts/prepare-resources/desktop-bridge-checks.mjs:143, scripts/prepare-resources/desktop-bridge-expectations.mjs:61


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@zouyonghe
zouyonghe merged commit 69033e6 into main Nov 21, 2026
4 checks passed
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.

1 participant