0eb25286c8
Deux mouvements de surface, aucun changement de comportement. **`packages/client` → `packages/sdk`, `@ng-eventually/client` → `@ng-eventually/sdk`.** « client » ne disait rien : ce paquet EST le SDK que l'application appelle, et c'est tout ce qu'elle appelle. L'ancien nom reste comme mot-clé de recherche dans `docs/source-layout-by-fate.md` et le tableau des paquets du README. **Une seule entrée.** L'entrée `./polyfill` disparaît ; ses symboles applicatifs — `configure`, `configureStoreRegistry`, `setCurrentUser`, `connectedUser` et leurs types — vivent dans un bloc `POLYFILL-ERA` de `src/index.ts`. Ce que la seconde porte portait mérite d'être nommé avant d'être retiré : *ce qu'on importe de ce chemin est exactement ce qu'on supprimera à la migration*. Une seule porte perd ce signal — rien à la ligne d'import ne distingue `configure`, qui part, de `docs`, que le vrai SDK remplace sur place. Trois choses le portent désormais : le bloc lui-même, l'inventaire d'exports de `docs/api-contract.md` (épinglé par `test/vocabulary.test.ts`, donc il ne peut pas rancir en silence), et le contrôle de vocabulaire sur les noms publiés. **Six symboles quittent la surface au passage**, et la fusion est ce qui a rendu le choix visible plutôt qu'hérité : - `getConfig` / `getStoreRegistryDeps` — câblage interne, atteint par `shared-wallet/bootstrap` ; - `resetConfig` / `resetStoreRegistry` / `resetCaps` — remises à zéro de test, atteintes par leur chemin interne, ce qui est leur raison d'être ; - le `share` direct — `inbox.share` a toujours été la même fonction, et la publier deux fois brouillait la frontière qu'elle servait à marquer. Corrections d'affirmations fausses trouvées en chemin : le contrat annonçait `isNuri` / `hasReadCap` sur la porte SDK alors qu'ils ne sont plus exportés depuis le passage au permissif en entrée (`NuriLike` validé à la porte) ; le README du paquet documentait `capFor`, `shareCap`, `getCaps` et `publishRepoLink`, dont aucun n'existe ; et le README de l'app d'exemple affirmait que la suite e2e la pilote, ce qui reste à faire. 179 tests unitaires, typecheck bibliothèque / exemple / harnais, e2e 42/42 contre le broker en ligne — mesuré une fois après le renommage, une fois après la fusion.
122 lines
5.3 KiB
TypeScript
122 lines
5.3 KiB
TypeScript
/**
|
|
* COLD-START repro — a genuinely FRESH wallet (never ran the app) driving the
|
|
* shim's first account resolution/provision.
|
|
*
|
|
* Unlike `run.ts`, which reuses ONE dedicated wallet (always "hot" — its
|
|
* private-store repo is already in the verifier's `self.repos`), this mints a
|
|
* BRAND-NEW wallet + fresh profile per run and opens the SDK page over it as the
|
|
* very first session. It then, in order:
|
|
* 1) probes the RAW anchored shim SELECT on `did:ng:${private_store_id}` — the
|
|
* cold-start bug surfaces here as `RepoNotFound` (the private-store repo not
|
|
* yet open) rather than a silent 0 rows;
|
|
* 2) runs `ensureAccount` (resetRegistryCache first) — the app's first-login
|
|
* bootstrap — and asserts it provisions 3 scope docs WITHOUT throwing;
|
|
* 3) re-resolves the SAME id from a fresh anchored read and asserts it returns
|
|
* the SAME docs (real persistence in the shim).
|
|
*
|
|
* Expected BEFORE the fix: step 1 throws RepoNotFound; step 2/3 fail to persist.
|
|
* Expected AFTER the fix: step 1 may still throw (raw, no open), but step 2/3
|
|
* succeed because ensureAccount opens the anchor repo before read/write.
|
|
*
|
|
* Run: `bun run e2e/repro-fresh-wallet.ts`.
|
|
*/
|
|
|
|
import * as fs from "node:fs";
|
|
import type { Frame, Page, BrowserContext } from "playwright";
|
|
import { buildBundle, serveHarness, createFreshWalletContext, setupBrokerPage } from "./broker";
|
|
|
|
type Check = { name: string; ok: boolean; detail?: string };
|
|
const results: Check[] = [];
|
|
function check(name: string, ok: boolean, detail?: string): void {
|
|
results.push({ name, ok, detail });
|
|
console.log(` [${ok ? "PASS" : "FAIL"}] ${name}${detail ? " — " + detail : ""}`);
|
|
}
|
|
|
|
function sdk<T>(frame: Frame, method: string, ...args: unknown[]): Promise<T> {
|
|
return frame.evaluate(
|
|
([m, a]) => (window as any).__sdk[m as string](...(a as unknown[])),
|
|
[method, args] as const,
|
|
) as Promise<T>;
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
console.log("[repro] building SDK page bundle...");
|
|
buildBundle();
|
|
const { url, close: closeServer } = await serveHarness();
|
|
console.log(`[repro] harness served at ${url}`);
|
|
|
|
console.log("[repro] creating a BRAND-NEW wallet (fresh profile)...");
|
|
let ctx: BrowserContext | null = null;
|
|
let dir: string | null = null;
|
|
let page: Page | null = null;
|
|
try {
|
|
const fresh = await createFreshWalletContext();
|
|
ctx = fresh.ctx;
|
|
dir = fresh.dir;
|
|
console.log(`[repro] fresh wallet: ${fresh.name}`);
|
|
|
|
page = await ctx.newPage();
|
|
page.on("pageerror", (e) => console.error("[iframe error]", e.message));
|
|
page.on("console", (m) => {
|
|
if (m.type() === "error") console.error("[iframe console]", m.text());
|
|
});
|
|
|
|
console.log("[repro] opening SDK page over the FRESH wallet (first-ever app session)...");
|
|
const frame = await setupBrokerPage(page, url);
|
|
await frame.waitForFunction(() => (window as any).__sdk !== undefined, { timeout: 30000 });
|
|
await frame.waitForFunction(() => (window as any).__sdk.status() === "connected", {
|
|
timeout: 60000,
|
|
});
|
|
console.log("[repro] connected. Driving the cold-start shim resolution...");
|
|
|
|
// 1) RAW anchored shim probe — the diagnostic. Reports RepoNotFound if the
|
|
// private-store repo is not yet open in this fresh session.
|
|
const probe = await sdk<any>(frame, "shimAnchorProbe");
|
|
console.log(
|
|
` [DIAG] raw anchored shim read: threw=${probe.threw} error=${probe.error} rows=${probe.rows}`,
|
|
);
|
|
|
|
// 2) ensureAccount — the real bootstrap. This MUST provision cleanly on a fresh
|
|
// wallet (all 3 docs truthy, no throw). This is the load-bearing assertion.
|
|
const ensured = await sdk<any>(frame, "coldEnsureAccount", "@cold-user-1");
|
|
check(
|
|
"fresh wallet: ensureAccount provisions the account without throwing",
|
|
!ensured.threw && !!ensured.docPublic && !!ensured.docProtected && !!ensured.docPrivate,
|
|
ensured.threw
|
|
? `THREW: ${ensured.error}`
|
|
: `pub=${String(ensured.docPublic).slice(0, 22)}… prot=${String(ensured.docProtected).slice(0, 22)}…`,
|
|
);
|
|
|
|
// 3) Re-resolve from a FRESH anchored read — proves the shim actually persisted.
|
|
const verified = await sdk<any>(frame, "verifyShimPersisted", "@cold-user-1");
|
|
check(
|
|
"fresh wallet: the provisioned account persists (re-resolves the SAME docs, no RepoNotFound)",
|
|
!verified.threw &&
|
|
verified.docPublic === ensured.docPublic &&
|
|
verified.docProtected === ensured.docProtected &&
|
|
verified.docPrivate === ensured.docPrivate,
|
|
verified.threw
|
|
? `THREW: ${verified.error}`
|
|
: `same=${verified.docPublic === ensured.docPublic && verified.docProtected === ensured.docProtected}`,
|
|
);
|
|
} finally {
|
|
try { if (page) await page.close(); } catch { /* ignore */ }
|
|
try { if (ctx) await ctx.close(); } catch { /* ignore */ }
|
|
try { if (dir) fs.rmSync(dir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
closeServer();
|
|
}
|
|
|
|
const passed = results.filter((r) => r.ok).length;
|
|
const failed = results.length - passed;
|
|
console.log(`\n══ cold-start repro: ${passed} passed, ${failed} failed ══`);
|
|
if (failed > 0) {
|
|
for (const r of results.filter((x) => !x.ok)) console.log(` - ${r.name}: ${r.detail ?? ""}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error("[repro] fatal:", e);
|
|
process.exit(1);
|
|
});
|