feat!: la famille ORM est publiee enveloppee, et le ng publie cesse de rendre des promesses

This commit is contained in:
Sylvain Duchesne
2026-09-21 12:38:17 +02:00
parent 2aac703784
commit d0ea043a5b
21 changed files with 1102 additions and 35 deletions
+60
View File
@@ -89,3 +89,63 @@ test("write guard: passthrough when anchor is omitted (cannot scope the guard)",
await proxy.sparql_update("sid", "INSERT DATA {}", undefined); // no anchor → passthrough
expect(ng.sparql_update).toHaveBeenCalledTimes(1);
});
// --- the passthrough, against the shape the REAL `ng` actually has ----------
/**
* A stand-in for `@ng-org/web`'s `ng`, faithful in the one way every fake above is not:
* it is a PROXY, not a property bag.
*
* Read from the installed `@ng-org/web@0.1.2-alpha.14` (`dist/ngweb.js`, the `l(e = [])`
* factory): every key - including `bind`, `length`, `name` - answers with a fresh
* path-carrying CALLABLE, calling one posts a remote request named after the first path
* segment and returns a PROMISE, and the reflection traps throw outright.
*
* Every other fake in this suite is a plain object, on which `bind` behaves. That is why
* a passthrough that could not survive the real thing stayed green here for months.
*/
function asyncProxyNg(calls: string[]): Record<string, unknown> {
const make = (path: string[]): unknown =>
new Proxy(function (): void {} as object, {
get: (_t, k) => make([...path, String(k)]),
apply: (_t, _this, args: unknown[]) => {
calls.push(`${path.join(".")}/${args.length}`);
return Promise.resolve("ok");
},
has() { throw new Error('Async proxy does not support "has" handler.'); },
getOwnPropertyDescriptor() { throw new Error('Async proxy does not support "getOwnPropertyDescriptor" handler.'); },
ownKeys() { throw new Error('Async proxy does not support "ownKeys" handler.'); },
});
return make([]) as Record<string, unknown>;
}
// THE regression. `Reflect.get(ng, prop).bind(ng)` looks like a passthrough and is not:
// against the real `ng`, `bind` is just another key, so what came back was a PROMISE and
// a caller got `<member> is not a function`. The library's own internals never go through
// this proxy, so nothing here noticed until the ORM was handed it.
test("passthrough: a member of the REAL (proxy-shaped) `ng` comes back callable", async () => {
const calls: string[] = [];
const ng = asyncProxyNg(calls);
configure({ ng, useShape: () => undefined });
const proxy = makeNg();
expect(typeof proxy.orm_start_graph).toBe("function");
// Upstream's own arity and argument shapes (`index.d.ts:orm_start_graph`).
await proxy.orm_start_graph!(["did:ng:i"], [], {}, "sid", {}, () => {});
// ...and exactly ONE remote request went out, named after the member - not a `bind` one.
expect(calls).toEqual(["orm_start_graph/6"]);
});
// A plain-object `ng` still gets its receiver: forwarding must not cost what binding
// bought. The unit fakes are all of this kind, and so is any `ng` that is a real object.
test("passthrough: a plain-object `ng` keeps its receiver", async () => {
const ng = {
mark: "the real ng",
whoAmI(this: { mark: string }) {
return this.mark;
},
};
configure({ ng, useShape: () => undefined });
const proxy = makeNg() as unknown as { whoAmI: () => string };
expect(proxy.whoAmI()).toBe("the real ng");
});