Skip to content

Commit f89f037

Browse files
fix: Simplify the diagnosis run and fix the statement-store submit example (#174)
* Run all diagnosis methods sequentially, no skips * Improve diagnosis [Before you start] section
1 parent 67a9263 commit f89f037

3 files changed

Lines changed: 13 additions & 35 deletions

File tree

playground/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The Diagnosis screen emits a per-host markdown report via "Copy report". Aggrega
3838
| `src/lib/transport.ts` | Singleton `Provider`/`Transport`/`TrUApiClient` over iframe postMessage or webview MessagePort. Owns the handshake and connection status. |
3939
| `src/lib/example-runner.ts` | Transpiles each rustdoc `ts` example via sucrase, runs it inside an `AsyncFunction` with `truapi`, `console`, rxjs, and an ambient `assert` as bindings. Failure is explicit: an example fails iff it throws (via `assert(...)`, a timeout, or any uncaught error); `console.*` is pure output. A tracking Proxy auto-unsubscribes inner `.subscribe(...)` calls so subscriptions clean up when the run ends or the user navigates away. |
4040
| `src/lib/monaco-setup.ts` | Configures Monaco's TS worker: registers the bundled `@parity/truapi` types (`truapi-dts`), every rxjs `.d.ts`, and an ambient block (`declare const truapi: Client`, `assert`, `crypto`, `Uint8Array` hex helpers) so examples typecheck without manual imports. Defines the light/dark themes that match the design tokens. |
41-
| `src/lib/auto-test.ts` | Runs each method's example and reports pass / fail. A method passes when its example resolves within the timeout and fails when it throws (the thrown/`assert` message plus any logs become the failure output); unary and subscription examples are awaited identically. `runDiagnosis` runs every method one at a time: automatic methods first, then the methods that prompt the user (signing, permission/resource requests, `navigate_to`) last so each interaction completes in isolation. `runSingleTest` replays one method (used by the Diagnosis row replay). |
41+
| `src/lib/auto-test.ts` | Runs each method's example and reports pass / fail. A method passes when its example resolves within the timeout and fails when it throws (the thrown/`assert` message plus any logs become the failure output); unary and subscription examples are awaited identically. `runDiagnosis` runs every method one at a time, in service order; methods that prompt the user (signing, permission/resource requests) block on their host dialog before the run continues. `runSingleTest` replays one method (used by the Diagnosis row replay). |
4242
| `src/lib/diagnosis-report.ts` | Renders the diagnosis results as a copy-pasteable GitHub-flavoured markdown table: a `## Truapi <Web\|Desktop\|Android\|iOS> Diagnosis` title (host mode via `detectHostMode` — a native host (Electron UA or `__HOST_WEBVIEW_MARK__`) is split by user-agent into Desktop / Android / iOS, a browser iframe ⇒ Web) and one method/status row per method. Deterministic for a given set of results (no timestamp). Consumed by the explorer's matrix aggregator. |
4343
| `src/lib/host-api-bridge.ts` | Just `stringify`, the JSON-with-bigint helper shared across components. |
4444
| `src/components/ExampleEditor.tsx` | Monaco editor wrapper. Auto-folds `// #region helpers` blocks on mount. |

playground/src/components/DiagnosisView.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,16 @@ export function DiagnosisView({
125125
<p className="panel__desc">
126126
Runs every TrUAPI method against the connected host to build a coverage
127127
report — which methods work, which fail, and which aren&apos;t wired
128-
yet. Methods run one at a time; those that need your approval (signing,
129-
permission and resource requests) run last. When it finishes, copy the
130-
report below.
128+
yet. Methods run one at a time, in order; those that need your approval
129+
(signing, permission and resource requests) wait on your response
130+
before the run continues. When it finishes, copy the report below.
131131
</p>
132132
<p className="diag__callout">
133133
Before you start: make sure you are <strong>logged in</strong>, and
134134
keep your <strong>phone nearby</strong> to sign transactions and
135-
approve pop-ups from the Polkadot app as they appear.
135+
approve pop-ups from the Polkadot app as they appear. Some payment
136+
methods need an <strong>available balance</strong> in the Polkadot app
137+
— without it they fail with an insufficient-balance error.
136138
</p>
137139
</div>
138140

playground/src/lib/auto-test.ts

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ const SIGNING_TIMEOUT_MS = 30_000;
2121

2222
// Services skipped wholesale in the diagnosis until hosts wire them up.
2323
const SKIPPED_SERVICES = new Set(["Coin Payment"]);
24-
// Methods run last, after the automatic checks: they prompt the user (signing,
25-
// permission/resource requests) or navigate away (`navigate_to`), so deferring
26-
// them keeps each interaction isolated at the end of the run.
27-
const DEFERRED_METHODS = new Set([
28-
"System/navigate_to",
29-
"Permissions/request_device_permission",
30-
"Permissions/request_remote_permission",
31-
"Resource Allocation/request",
32-
"Signing/sign_payload",
33-
"Signing/sign_raw",
34-
"Signing/sign_raw_with_legacy_account",
35-
"Signing/sign_payload_with_legacy_account",
36-
"Signing/create_transaction",
37-
"Signing/create_transaction_with_legacy_account",
38-
"Account/get_account_alias",
39-
]);
4024
// Methods whose first call implicitly triggers a host permission/signing
4125
// prompt, so they need the longer signing-class timeout to allow for the user
4226
// to respond. `get_account_alias` and `Preimage/submit` prompt on first use.
@@ -134,27 +118,19 @@ export async function runSingleTest(
134118
await runOne({ serviceName, method, onUpdate });
135119
}
136120

137-
// Full diagnosis: run every method one at a time. Automatic checks run first;
138-
// methods that prompt the user or navigate away are deferred to the end so each
139-
// runs in isolation. Produces a complete worked / failed / not-wired matrix
140-
// suitable for the copy-pasteable report.
121+
// Full diagnosis: run every method one at a time, in service order. Methods
122+
// that prompt the user (signing, permission/resource requests) block on their
123+
// host dialog before the run continues. Produces a complete worked / failed /
124+
// not-wired matrix suitable for the copy-pasteable report.
141125
export async function runDiagnosis(
142126
services: ServiceInfo[],
143127
onUpdate: (id: string, entry: TestEntry) => void,
144128
signal?: AbortSignal,
145129
): Promise<void> {
146-
const immediate: Array<{ serviceName: string; method: MethodInfo }> = [];
147-
const deferred: typeof immediate = [];
148130
for (const svc of services) {
149131
for (const method of svc.methods) {
150-
const bucket = DEFERRED_METHODS.has(`${svc.name}/${method.name}`)
151-
? deferred
152-
: immediate;
153-
bucket.push({ serviceName: svc.name, method });
132+
if (signal?.aborted) return;
133+
await runOne({ serviceName: svc.name, method, onUpdate });
154134
}
155135
}
156-
for (const { serviceName, method } of [...immediate, ...deferred]) {
157-
if (signal?.aborted) return;
158-
await runOne({ serviceName, method, onUpdate });
159-
}
160136
}

0 commit comments

Comments
 (0)