Files
buzz/desktop/src/shared/api/tauri.test.mjs
Wes f3408fc620 fix(desktop): isolate quota backoff and reuse channel discovery rosters (#6998)
Pinky, an AI agent, is updating this PR on Wes's behalf.

## Targeted repair, not a startup rewrite

This replaces the previous readiness/replay candidate. Current head:
**`83ac81ff6ae439b0e68f4a3dafd4b2af6dbadcdb`**, two independent commits
on main base `3c7f288c60d67df78577b237e27c3dfc8831aaa1`:

1. **`0b6681de2` — keep quota backoff on its transport.** HTTP 429s
retain native HTTP backoff without arming the renderer WebSocket gate.
WebSocket quota/concurrency CLOSED retains its retry deadline without
damping HTTP's separate quota. The explicit `rate-limited: shared
admission unavailable` signal still damps HTTP too. Reuse existing
all-channel live streams for Home mention invalidation instead of a
second per-channel mention subscription; retain kind, recipient, self,
membership, replay-deduplication, notification and unread boundaries.
2. **`83ac81ff6` — reuse complete membership rosters within each channel
fetch.** Discovery already returns full paginated rosters. Retain those
results and request only uncovered directory/pending-owner channel IDs.
Skip empty fallback filters and preserve covered counts/pubkeys if that
tolerant fallback fails. The next fetch reads current membership again;
there is no persistent cache or new invalidation state.

No send-route, AUTH-readiness, replay-ordering, scheduler, pacing, relay
policy, dependency, or authorization changes. Refresh triggers and
activity batching stay unchanged. Independent tracing did not establish
a safe-to-delete duplicate normal-startup refresh; recovery
invalidations at different replay stages are not interchangeable.

**Size:** 18 files, +1,066/-350 overall; nine production paths +76/-205
(**129 fewer production lines**). The roster follow-up itself touches
only `fetch.rs` (+31/-14) and its new 378-line regression file. Test
bulk is not new startup machinery.

## Comparative roster measurement

Actual native HTTP fetch code against a synthetic Axum loopback fixture:
265 channels × 100 members, deterministic signed events, debug build.
Seven iterations per condition; medians below exclude the first warm-up.
Baseline is `0b6681de2` production fetch, candidate is `83ac81ff6`
production fetch, with the same temporary benchmark harness.

| Measure | Baseline | Candidate |
| --- | ---: | ---: |
| HTTP reads per fetch | 7 | 6 |
| JSON response-body bytes per fetch | 4,803,136 | 2,453,380 |
| Median, no artificial request delay | 262.9 ms | 149.3 ms |
| Median, 25 ms artificial delay per request | 376.7 ms | 282.7 ms |

Channel/member assertions and output hash (`fa7cc551bc855e4d`) match
throughout. This removes **one batched roster request**, not 265
requests. The measured ~43%/~25% reductions describe this large-roster
synthetic fixture, **not production startup latency**. Activity requests
run concurrently with roster enrichment, so real savings vary. Counts
now use the discovery snapshot rather than a later reread within that
same non-atomic fetch.

## Verification

At pushed head **`83ac81ff6`**:

- All enabled pre-push gates passed without bypass: `push-head-scope`,
`branch-skew`, `desktop-check`, `file-size-check`, `desktop-typecheck`,
`desktop-test`, `desktop-tauri-checks` (native fmt/Clippy/tests).
- Full Desktop frontend suite: **6,457 passed**, zero failures; separate
tooling suite: **10 passed**.
- Full native Desktop workspace: **3,276 passed**, zero failures, 20
ignored, across unit/integration/doc bins. The main native lib accounts
for 3,175 passed / 19 ignored; this is not 3,276 lib tests.
- `pnpm build` passed the protected-feature artifact matrix; `pnpm
build:e2e` also passed. Existing chunk-size/dynamic-import warnings
remain. No full repository `just ci` run locally.
- **130 selected headless mock-bridge smoke cases passed across two
runs**: messaging, reconnect, reconnect affordances, inbox live updates,
sidebar snapshots, send-channel binding, boot splash. The first
invocation hit the shell's 300-second limit after 117 passes and no
failures; all remaining 13 passed in a separate invocation. This is not
a claim the interrupted invocation completed.
- Six new tests invoke production `fetch_channels` through the real
native HTTP client and cover 265/501-channel pagination (including
same-timestamp continuation), exact requests, complete/deduplicated
rosters, directory/pending fallback, hidden DMs, repeated
membership/identity/relay changes, empty lists and errors.
- Falsification in an isolated source copy: restoring the redundant
baseline fetch fails four roster regressions; removing missing-roster
fallback fails two. Restored candidate passes all six. Earlier transport
mutations fail HTTP→WS coupling, WS→HTTP coupling, omitted shared-outage
damping and duplicate-mention regressions. No mutation was applied to
the committed worktree.
- Brain's independent static reviews found no blockers in the transport
repair or immutable roster patch. Source tracing confirms relay
discovery serializes complete rosters, not projected matching p-tags.
This was source review, not independent test execution or approval.

### Hosted CI

[CI run
34185670504](https://github.com/block/buzz/actions/runs/34185670504)
**completed successfully** for this head. GitHub checked out merge ref
`25bcf09627e129887481d4441a1af3c6cb0af1ff`; its Git tree is identical to
`83ac81ff6` (`49a01f3c2ebf4e547bbe3cd31406f984ac6cefe8`), verified
through the GitHub Git API. The final PR rollup has 33 successful checks
and 28 skipped, with none failing or pending.

- Desktop Core passed frontend/native suites and compiled-feature
verification. Windows Rust tests, Windows Desktop build, macOS
`.app`/`.dmg` build, all four smoke shards and both relay-backed E2E job
shards passed, as did Rust lint, DCO, Semgrep and zizmor.
- Browser job totals: **1,620 passed, 13 flaky cases passing automatic
retry #1, five skipped, zero terminal failures**. Smoke accounts for
1,389 passed / 12 flaky / three skipped; integration jobs report 231
passed / one flaky / two skipped. No manual CI reruns or source changes
to obtain green.
- The retries cover channel-browser, empty-edit, huddle menu,
runtime-install, overscroll, onboarding avatar, video attachment and
workflow UI assertions. They are disclosed, not collectively declared
unrelated. The video case reaches the changed real TS all-channel hook
despite mocking native I/O: independent tracing found no regression
mechanism or blocker, but the missing second-video player remains
**unexplained**, and an indirect timing effect is not excluded. The
self-authored, unmentioned event cannot use either the new mention
branch or the removed old mention handler as a delivery path. A passing
retry does not diagnose its cause.
- The separate “Desktop Release Candidate” check skipped its validation
step; it is not additional release validation. Codex security review was
skipped, not passed.

## Remaining acceptance limits

Wes's earlier manual trial of the transport-only candidate reported
improvement; relay readback found both a top-level message and a thread
reply. That was not a fingerprinted or timed trial of the new roster
commit. The remaining few-second top-level send wait is
**unattributed**, and this PR does not claim to resolve every startup
delay.

No visible app launch, relaunch, laptop input automation, or production
test messages during this follow-up. Local native tests use fixtures;
browser suites do not run the Tauri backend. CI building an app does not
validate bundled macOS alerts or inactive-channel notification delivery.
Those bundled real-workflow checks remain outstanding. No visual UI
changes or screenshots; no approval or merge performed.

Originating conversation:
buzz://message?channel=5b130804-d759-40ad-a564-d64cc907fa8e&id=cb432417e290e06a1842639cfe0268f9d43d186defbcb59260930d129a26af83

---------

Signed-off-by: Pinky <5f5ab050ec58ae208332edd544ebf705221e24c1b86d82a6ca07038a7a8f6ac9@buzz.block.builderlab.xyz>
Co-authored-by: Pinky <5f5ab050ec58ae208332edd544ebf705221e24c1b86d82a6ca07038a7a8f6ac9@buzz.block.builderlab.xyz>
2026-09-11 09:11:39 -06:00

148 lines
4.7 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
// ── fromRawAcpRuntimeCatalogEntry: custom row API-boundary (B-2) ─────────────
//
// These tests feed real raw custom catalog rows through fromRawAcpRuntimeCatalogEntry
// and verify the Rust→TypeScript mapping boundary: definition_env (snake_case)
// arrives as definitionEnv (camelCase), source "custom" is preserved, and the
// env round-trips end-to-end so a save-then-edit cycle cannot erase env.
const { fromRawAcpRuntimeCatalogEntry } = await import("./tauri.ts");
test("fromRawAcpRuntimeCatalogEntry maps definition_env to definitionEnv", () => {
const raw = {
id: "my-harness",
label: "My Harness",
availability: "available",
command: "my-bin",
source: "custom",
definition_env: { ANTHROPIC_API_KEY: "sk-test", MODEL: "claude-3" },
default_args: [],
can_auto_install: false,
requires_external_cli: false,
install_hint: "",
install_instructions_url: "",
};
const entry = fromRawAcpRuntimeCatalogEntry(raw);
assert.deepStrictEqual(entry.definitionEnv, {
ANTHROPIC_API_KEY: "sk-test",
MODEL: "claude-3",
});
assert.equal(entry.source, "custom");
});
test("fromRawAcpRuntimeCatalogEntry defaults definitionEnv to {} when absent", () => {
// Rust serialization skips empty BTreeMap, so definition_env will be absent
// for harnesses with no env defined — the mapper must default to {}.
const raw = {
id: "no-env-harness",
label: "No Env",
availability: "available",
command: "no-env-bin",
source: "custom",
default_args: [],
can_auto_install: false,
requires_external_cli: false,
install_hint: "",
install_instructions_url: "",
};
const entry = fromRawAcpRuntimeCatalogEntry(raw);
assert.deepStrictEqual(
entry.definitionEnv,
{},
"absent definition_env must map to empty object, not undefined",
);
});
test("fromRawAcpRuntimeCatalogEntry preserves source preset", () => {
const raw = {
id: "cursor",
label: "Cursor",
availability: "available",
command: "cursor",
source: "preset",
default_args: [],
can_auto_install: false,
requires_external_cli: false,
install_hint: "",
install_instructions_url: "",
};
const entry = fromRawAcpRuntimeCatalogEntry(raw);
assert.equal(entry.source, "preset");
assert.deepStrictEqual(entry.definitionEnv, {});
});
test("fromRawAcpRuntimeCatalogEntry env round-trips through edit payload shape", () => {
// Simulate the full save → re-open cycle: raw entry comes back from Rust
// with definition_env populated; the edit form reads entry.definitionEnv.
// Verify the env values are identical before and after the mapper.
const envValues = { OPENAI_API_KEY: "sk-live-abc", REGION: "us-east-1" };
const raw = {
id: "openai-harness",
label: "OpenAI",
availability: "not_installed",
command: "openai-agent",
source: "custom",
definition_env: envValues,
default_args: ["--acp"],
can_auto_install: false,
requires_external_cli: true,
install_hint: "Install the OpenAI CLI",
install_instructions_url: "https://platform.openai.com/docs",
};
const entry = fromRawAcpRuntimeCatalogEntry(raw);
// The edit form reads entry.definitionEnv; it must equal the original env.
assert.deepStrictEqual(
entry.definitionEnv,
envValues,
"env must round-trip: edit form must see the same values that Rust serialized",
);
});
// ── max_parallelism → maxParallelism mapping ──────────────────────────────────
test("fromRawAcpRuntimeCatalogEntry maps max_parallelism to maxParallelism when present", () => {
const raw = {
id: "openclaw",
label: "OpenClaw",
availability: "not_installed",
command: null,
source: "preset",
default_args: [],
can_auto_install: false,
requires_external_cli: false,
install_hint: "",
install_instructions_url: "",
max_parallelism: 5,
};
const entry = fromRawAcpRuntimeCatalogEntry(raw);
assert.equal(
entry.maxParallelism,
5,
"max_parallelism: 5 must map to maxParallelism: 5",
);
});
test("fromRawAcpRuntimeCatalogEntry omits maxParallelism when max_parallelism is absent", () => {
const raw = {
id: "goose",
label: "Goose",
availability: "available",
command: "goose",
source: "builtin",
default_args: [],
can_auto_install: false,
requires_external_cli: false,
install_hint: "",
install_instructions_url: "",
// No max_parallelism field — uncapped harness.
};
const entry = fromRawAcpRuntimeCatalogEntry(raw);
assert.equal(
entry.maxParallelism,
undefined,
"uncapped harness must have maxParallelism: undefined",
);
});