@celestia-island/hikari 0.55.457 → 0.55.458
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/components/HkLoginFlow.d.ts +6 -0
- package/dist/types/scene3d/declare-caps.d.ts +10 -0
- package/dist/types/scene3d/wasmFleetSpec.d.ts +13 -0
- package/package.json +3 -2
- package/src/components/HkLoginFlow.test.tsx +36 -0
- package/src/components/HkLoginFlow.tsx +7 -1
- package/src/scene3d/declare-caps.ts +29 -0
- package/src/scene3d/scene3dHostSurface.test.ts +334 -0
- package/src/scene3d/wasmFleetSpec.ts +93 -10
|
@@ -22,6 +22,12 @@ export interface HkLoginCredentialsChannel {
|
|
|
22
22
|
* on identifier logins); HkSignInCard's runtime credential policy
|
|
23
23
|
* resolves the default. */
|
|
24
24
|
usernameAutocomplete?: string;
|
|
25
|
+
/** Per-channel seed override for the username field. The flow-level
|
|
26
|
+
* `initialUsername` exists for the account→verify→back round-trip of
|
|
27
|
+
* ONE channel; a channel that never collects that value (the org
|
|
28
|
+
* email funnel) overrides with "" so the OTHER channel's account
|
|
29
|
+
* name never leaks into its field (chest R4 seam finding). */
|
|
30
|
+
initialUsername?: string;
|
|
25
31
|
/** Classic two-field card. Defaults to FALSE — account-first is the
|
|
26
32
|
* family-wide posture since the MFA redesign: the password is proven
|
|
27
33
|
* on the verify step as one factor among the announced ones, so the
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const SCENE3D_CAPABILITIES: {
|
|
2
|
+
interfaces: string[];
|
|
3
|
+
wasiModules: string[];
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The value the publish returned (the previous declaration). Exported and read
|
|
7
|
+
* by the spec builder so this module cannot be dropped as dead code by a
|
|
8
|
+
* bundler that honours `sideEffects`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SCENE3D_DECLARATION_PUBLISHED: import("@celestia-island/tairitsu-host-client").CapabilityDeclaration | undefined;
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import { HostClientError } from "@celestia-island/tairitsu-host-client";
|
|
1
2
|
import type { FleetRowLike, FleetSceneSpec } from "./holographicFleetSpec";
|
|
3
|
+
/** Thrown when the spec builder is called before the component is usable. */
|
|
4
|
+
export declare class Scene3dNotReadyError extends Error {
|
|
5
|
+
constructor(cause?: unknown);
|
|
6
|
+
}
|
|
7
|
+
/** Resolves once the component is usable; rejects if it could not be built. */
|
|
8
|
+
export declare const scene3dReady: Promise<void>;
|
|
9
|
+
/** Keeps the declaration module live for bundlers that honour `sideEffects`. */
|
|
10
|
+
export declare const scene3dCapabilities: {
|
|
11
|
+
interfaces: string[];
|
|
12
|
+
wasiModules: string[];
|
|
13
|
+
};
|
|
2
14
|
/** Build the fleet scene spec through the wasm component. */
|
|
3
15
|
export declare function buildFleetSceneSpecWasm(rows: readonly FleetRowLike[]): FleetSceneSpec;
|
|
16
|
+
export { HostClientError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celestia-island/hikari",
|
|
3
|
-
"version": "0.55.
|
|
3
|
+
"version": "0.55.458",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Hikari UI library, Vue 3 runtime — one design system for Vue 3 and Rust/WASM applications",
|
|
@@ -107,7 +107,8 @@
|
|
|
107
107
|
"**/*.scss",
|
|
108
108
|
"**/*.css",
|
|
109
109
|
"**/qr/declare-caps.ts",
|
|
110
|
-
"**/mermaid/declare-caps.ts"
|
|
110
|
+
"**/mermaid/declare-caps.ts",
|
|
111
|
+
"**/scene3d/declare-caps.ts"
|
|
111
112
|
],
|
|
112
113
|
"peerDependenciesMeta": {
|
|
113
114
|
"pinia": {
|
|
@@ -391,6 +391,42 @@ describe("HkLoginFlow — host wiring details", () => {
|
|
|
391
391
|
expect(active?.textContent).toContain("Celestia Cloud");
|
|
392
392
|
});
|
|
393
393
|
|
|
394
|
+
it("keeps one channel's account name out of another channel's field", () => {
|
|
395
|
+
// The per-channel seed override: the org (email) channel pins "" so
|
|
396
|
+
// the cloud channel's typed account name — seeded flow-level for the
|
|
397
|
+
// verify round-trip — never pre-fills the org email field. Both
|
|
398
|
+
// postures mounted statically (the channel swap's crossfade settles
|
|
399
|
+
// on environment-dependent timing; the MOUNT-TIME seed is the
|
|
400
|
+
// contract under test).
|
|
401
|
+
const orgMount = mount(
|
|
402
|
+
h(HkLoginFlow, {
|
|
403
|
+
channels: [
|
|
404
|
+
{ key: "cloud", mode: "credentials" },
|
|
405
|
+
{ key: "org", mode: "credentials", usernameType: "email", usernameAutocomplete: "email", initialUsername: "" },
|
|
406
|
+
],
|
|
407
|
+
modelValue: "org",
|
|
408
|
+
initialUsername: "cloud-user",
|
|
409
|
+
}),
|
|
410
|
+
);
|
|
411
|
+
expect(
|
|
412
|
+
orgMount.querySelector<HTMLInputElement>('input[name="signin-username"]')?.value,
|
|
413
|
+
).toBe("");
|
|
414
|
+
|
|
415
|
+
const cloudMount = mount(
|
|
416
|
+
h(HkLoginFlow, {
|
|
417
|
+
channels: [
|
|
418
|
+
{ key: "cloud", mode: "credentials" },
|
|
419
|
+
{ key: "org", mode: "credentials", usernameType: "email", usernameAutocomplete: "email", initialUsername: "" },
|
|
420
|
+
],
|
|
421
|
+
modelValue: "cloud",
|
|
422
|
+
initialUsername: "cloud-user",
|
|
423
|
+
}),
|
|
424
|
+
);
|
|
425
|
+
expect(
|
|
426
|
+
cloudMount.querySelector<HTMLInputElement>('input[name="signin-username"]')?.value,
|
|
427
|
+
).toBe("cloud-user");
|
|
428
|
+
});
|
|
429
|
+
|
|
394
430
|
it("forwards per-channel autocomplete tokens to the username field", () => {
|
|
395
431
|
const c = mount(
|
|
396
432
|
h(HkLoginFlow, {
|
|
@@ -33,6 +33,12 @@ export interface HkLoginCredentialsChannel {
|
|
|
33
33
|
* on identifier logins); HkSignInCard's runtime credential policy
|
|
34
34
|
* resolves the default. */
|
|
35
35
|
usernameAutocomplete?: string;
|
|
36
|
+
/** Per-channel seed override for the username field. The flow-level
|
|
37
|
+
* `initialUsername` exists for the account→verify→back round-trip of
|
|
38
|
+
* ONE channel; a channel that never collects that value (the org
|
|
39
|
+
* email funnel) overrides with "" so the OTHER channel's account
|
|
40
|
+
* name never leaks into its field (chest R4 seam finding). */
|
|
41
|
+
initialUsername?: string;
|
|
36
42
|
/** Classic two-field card. Defaults to FALSE — account-first is the
|
|
37
43
|
* family-wide posture since the MFA redesign: the password is proven
|
|
38
44
|
* on the verify step as one factor among the announced ones, so the
|
|
@@ -237,7 +243,7 @@ export const HkLoginFlow = defineComponent({
|
|
|
237
243
|
usernamePlaceholder={channel.usernamePlaceholder}
|
|
238
244
|
usernameAutocomplete={channel.usernameAutocomplete}
|
|
239
245
|
submitLabel={channel.submitLabel}
|
|
240
|
-
initialUsername={props.initialUsername}
|
|
246
|
+
initialUsername={channel.initialUsername ?? props.initialUsername}
|
|
241
247
|
onSubmit={(username: string, password: string) =>
|
|
242
248
|
emit("account-submit", channel.key, username, password)
|
|
243
249
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The capability declaration the scene3d component runs under, published from a
|
|
2
|
+
// SIDE-EFFECT module so it is in force before the wrapper's own module graph is
|
|
3
|
+
// evaluated: ES module imports are hoisted, so a statement in the consumer file
|
|
4
|
+
// can never run earlier than the imports below it.
|
|
5
|
+
//
|
|
6
|
+
// What this declaration is, precisely: the scene3d artifact has **no glue
|
|
7
|
+
// interface** (its `interfaces/` are type declarations only) and gets WASI from
|
|
8
|
+
// its own direct `@bytecodealliance/preview2-shim/*` imports — not from the
|
|
9
|
+
// host. Nothing in this component, or in its artifact, reads the published
|
|
10
|
+
// realm value at all (`__TAIRITSU_CAPABILITIES__`: zero hits under
|
|
11
|
+
// `src/wasm/scene3d/**`). So the publish is **inert for this component today**.
|
|
12
|
+
//
|
|
13
|
+
// What actually guards anything is the **argument**: `wasmFleetSpec` passes
|
|
14
|
+
// this same object to `createSurface(module, capabilities)`, and the door
|
|
15
|
+
// refuses a non-empty declaration. The publish and that argument are two
|
|
16
|
+
// independent facts — publishing a value does not put it in front of the door —
|
|
17
|
+
// so a future glue-bearing rewrite must keep passing the object it declares
|
|
18
|
+
// here. That hand-off is what `scene3dHostSurface.test.ts` pins; the publish
|
|
19
|
+
// alone guards nothing.
|
|
20
|
+
import { publishCapabilities } from "@celestia-island/tairitsu-host-client";
|
|
21
|
+
|
|
22
|
+
export const SCENE3D_CAPABILITIES = { interfaces: [] as string[], wasiModules: [] as string[] };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The value the publish returned (the previous declaration). Exported and read
|
|
26
|
+
* by the spec builder so this module cannot be dropped as dead code by a
|
|
27
|
+
* bundler that honours `sideEffects`.
|
|
28
|
+
*/
|
|
29
|
+
export const SCENE3D_DECLARATION_PUBLISHED = publishCapabilities(SCENE3D_CAPABILITIES);
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// Wiring pins for the scene3d spec builder: it must reach the component
|
|
2
|
+
// **through the tairitsu host client's call surface**, and it must **hand its
|
|
3
|
+
// capability declaration to the door** rather than only publishing it.
|
|
4
|
+
//
|
|
5
|
+
// Why a separate file: the frozen golden (`__golden.test.ts`) pins the output of
|
|
6
|
+
// `buildFleetSceneSpecWasm`, and nothing more. A direct call to the generated
|
|
7
|
+
// wrapper produces identical output, so bypassing the host leaves the golden
|
|
8
|
+
// green. The golden also says nothing about the declaration: whether that
|
|
9
|
+
// constant is ever *passed* to `createSurface` is invisible to an output-only
|
|
10
|
+
// test. These pins observe the seam itself.
|
|
11
|
+
//
|
|
12
|
+
// The declaration half is the defect #1475 recorded (QR) and #1476 fixed:
|
|
13
|
+
// `createSurface(module, capabilities = {})` defaults to `{}`, so with the second
|
|
14
|
+
// argument omitted both `sync-door-cannot-provide` branches are unreachable and
|
|
15
|
+
// the declaration is decoration.
|
|
16
|
+
//
|
|
17
|
+
// The four pins below are the shape #1476 converged on after seven review
|
|
18
|
+
// rounds (#1474's older shape was missing three of them):
|
|
19
|
+
// ① build count, asserted AFTER the call — the factory is callable repeatedly,
|
|
20
|
+
// so a lazy second door is otherwise invisible;
|
|
21
|
+
// ② the declaration pin reads the FIRST build — a later door must not make it
|
|
22
|
+
// fail with `undefined`, i.e. for the wrong reason;
|
|
23
|
+
// ③ the data path: substitute the door's return and require the caller's
|
|
24
|
+
// value to be that substitution, across the WHOLE result — a discarded
|
|
25
|
+
// decoy call or a partially-used door otherwise stays green;
|
|
26
|
+
// ④ every assertion named in a comment here must exist in this file.
|
|
27
|
+
//
|
|
28
|
+
// (Run from `packages/vue` — that is where vite.config.ts registers the plugins.)
|
|
29
|
+
import { describe, expect, it, vi } from "vitest";
|
|
30
|
+
|
|
31
|
+
interface Seam {
|
|
32
|
+
/** Argument list of every `surface.call(name, …)`. */
|
|
33
|
+
calls: Array<{ name: string; args: unknown[] }>;
|
|
34
|
+
/** What each observed `surface.call` returned, in order. */
|
|
35
|
+
results: unknown[];
|
|
36
|
+
/** The namespace handed to `createSurface`. */
|
|
37
|
+
handed: Record<string, unknown> | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Test seam: when set, the wrapped door delegates to this instead of the
|
|
40
|
+
* real export. Lets a probe substitute the door's return value and see
|
|
41
|
+
* whether the builder consumes it.
|
|
42
|
+
*/
|
|
43
|
+
doorOverride?: (name: string, ...args: unknown[]) => unknown;
|
|
44
|
+
/**
|
|
45
|
+
* The declaration handed on the FIRST build — the one that guarded module
|
|
46
|
+
* load, and the one the declaration pin asserts. Captured separately (not
|
|
47
|
+
* "latest build wins") because a later build would otherwise overwrite it
|
|
48
|
+
* and make that pin fail with `undefined`: the wrong reason, while the
|
|
49
|
+
* build-count pin names the actual fault.
|
|
50
|
+
*/
|
|
51
|
+
firstHandedCapabilities: unknown;
|
|
52
|
+
/** Every `createSurface` call's argument list, in order. */
|
|
53
|
+
surfaceBuilds: unknown[][];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const seam: Seam = {
|
|
57
|
+
calls: [],
|
|
58
|
+
results: [],
|
|
59
|
+
handed: undefined,
|
|
60
|
+
firstHandedCapabilities: undefined,
|
|
61
|
+
surfaceBuilds: [],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
vi.mock("@celestia-island/tairitsu-host-client", async (importOriginal) => {
|
|
65
|
+
const actual = await importOriginal<
|
|
66
|
+
typeof import("@celestia-island/tairitsu-host-client")
|
|
67
|
+
>();
|
|
68
|
+
return {
|
|
69
|
+
...actual,
|
|
70
|
+
createSurface: (
|
|
71
|
+
module: Record<string, unknown>,
|
|
72
|
+
...rest: unknown[]
|
|
73
|
+
): ReturnType<typeof actual.createSurface> => {
|
|
74
|
+
seam.handed = module;
|
|
75
|
+
if (seam.surfaceBuilds.length === 0) seam.firstHandedCapabilities = rest[0];
|
|
76
|
+
// Every build is recorded, not just the first: the factory is callable
|
|
77
|
+
// more than once, so a builder (or a copier's builder) could build a
|
|
78
|
+
// SECOND unwrapped surface and route calls through it while a
|
|
79
|
+
// first-call-only pin stayed green.
|
|
80
|
+
seam.surfaceBuilds.push([module, ...rest]);
|
|
81
|
+
// `rest` is passed through untouched, so the door's real refusal logic
|
|
82
|
+
// runs against whatever the builder declared.
|
|
83
|
+
const live = (
|
|
84
|
+
actual.createSurface as (
|
|
85
|
+
m: Record<string, unknown>,
|
|
86
|
+
...r: unknown[]
|
|
87
|
+
) => ReturnType<typeof actual.createSurface>
|
|
88
|
+
)(module, ...rest);
|
|
89
|
+
const realCall = live.call.bind(live);
|
|
90
|
+
// Wrap the surface's call door: this is where the builder must arrive.
|
|
91
|
+
live.call = ((name: string, ...args: unknown[]) => {
|
|
92
|
+
seam.calls.push({ name, args });
|
|
93
|
+
const value =
|
|
94
|
+
seam.doorOverride !== undefined
|
|
95
|
+
? seam.doorOverride(name, ...args)
|
|
96
|
+
: realCall(name, ...args);
|
|
97
|
+
seam.results.push(value);
|
|
98
|
+
return value;
|
|
99
|
+
}) as typeof live.call;
|
|
100
|
+
return live;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const { buildFleetSceneSpecWasm, scene3dCapabilities } = await import(
|
|
106
|
+
"./wasmFleetSpec"
|
|
107
|
+
);
|
|
108
|
+
// The artifact itself, for the door-substitution probe.
|
|
109
|
+
const realWrapper = await import("../wasm/scene3d/hikari_wasm_scene3d.js");
|
|
110
|
+
const { SCENE3D_CAPABILITIES } = await import("./declare-caps");
|
|
111
|
+
import type { FleetRowLike } from "./holographicFleetSpec";
|
|
112
|
+
|
|
113
|
+
const ROWS: FleetRowLike[] = [
|
|
114
|
+
{ node_id: "hub-a", tier: 3, station_count: 2, label: "Hub A" },
|
|
115
|
+
{ node_id: "hub-b", tier: 3, station_count: 1, label: "Hub B" },
|
|
116
|
+
{ node_id: "node-1", tier: 2, station_count: 5, label: "Node 1" },
|
|
117
|
+
{ node_id: "node-2", tier: 2, station_count: 0, label: "Node 2" },
|
|
118
|
+
{ node_id: "node-3", tier: 2, station_count: 8, label: "Node 3" },
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
/** The JS export name the wrapper actually carries. */
|
|
122
|
+
const EXPORT = "buildFleetScene";
|
|
123
|
+
|
|
124
|
+
describe("scene3d spec builder goes through the host client", () => {
|
|
125
|
+
it("hands the wrapper namespace to createSurface", () => {
|
|
126
|
+
expect(seam.handed).toBeDefined();
|
|
127
|
+
// The very artifact module — it carries the component's own export.
|
|
128
|
+
expect(typeof seam.handed![EXPORT]).toBe("function");
|
|
129
|
+
expect(typeof seam.handed!._util).toBe("object");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("calls the component export through the surface, not the wrapper", () => {
|
|
133
|
+
seam.calls.length = 0;
|
|
134
|
+
const spec = buildFleetSceneSpecWasm(ROWS);
|
|
135
|
+
expect(spec.planets.length).toBeGreaterThan(0);
|
|
136
|
+
|
|
137
|
+
const buildCalls = seam.calls.filter((c) => c.name === EXPORT);
|
|
138
|
+
// A direct `scene3dWrapper.buildFleetScene(...)` bypasses the surface
|
|
139
|
+
// entirely and leaves this empty — that is the mutation this pin catches.
|
|
140
|
+
expect(buildCalls).toHaveLength(1);
|
|
141
|
+
|
|
142
|
+
// ① Exactly one surface was ever built, and it was built BEFORE the call
|
|
143
|
+
// (module load). The factory is callable repeatedly, so a lazy second
|
|
144
|
+
// surface inside the builder would be a fresh, unseen door that every other
|
|
145
|
+
// pin here would still pass.
|
|
146
|
+
expect(seam.surfaceBuilds).toHaveLength(1);
|
|
147
|
+
|
|
148
|
+
// ③ The observed door must be the door the *returned value* came through,
|
|
149
|
+
// not merely a door that was called: counting calls alone is satisfiable by
|
|
150
|
+
// a decoy whose result is discarded, with the raw namespace supplying the
|
|
151
|
+
// real spec. The substitution case below is what actually proves the path;
|
|
152
|
+
// this only asserts the call reached the door once.
|
|
153
|
+
expect(seam.results).toHaveLength(1);
|
|
154
|
+
|
|
155
|
+
// The rows reach the component shaped as the WIT `fleet-row` expects.
|
|
156
|
+
const first = (buildCalls[0]!.args[0] as Array<Record<string, unknown>>)[0]!;
|
|
157
|
+
expect(first.nodeId).toBe("hub-a");
|
|
158
|
+
expect(first.stationCount).toBe(2);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("uses the whole value the observed door returned, not a parallel build", () => {
|
|
162
|
+
// Behavioural discriminator for the decoy shape that every count pin above
|
|
163
|
+
// passes: a discarded `surface.call(…)` for the pins plus a direct
|
|
164
|
+
// `scene3dWrapper.buildFleetScene(…)` that supplies the real spec. Mark
|
|
165
|
+
// EVERY field of the door's return for the duration of one call — if the
|
|
166
|
+
// builder consumes the marked value the door is the data path; if it
|
|
167
|
+
// returns the real spec instead, it went around.
|
|
168
|
+
const original = seam.doorOverride;
|
|
169
|
+
// Mark EVERY carried field, not just `label`. `FleetBodySpec` has ~15
|
|
170
|
+
// renderer-driving fields; marking one lets a builder source the rest from
|
|
171
|
+
// a parallel raw read and still pass (measured: 75/75 with all of
|
|
172
|
+
// orbitPhase/status/color/… taken from the raw namespace).
|
|
173
|
+
seam.doorOverride = (name, ...args) => {
|
|
174
|
+
if (name !== EXPORT) return rawBuild(...(args as [never]));
|
|
175
|
+
const value = rawBuild(...(args as [never]));
|
|
176
|
+
const mark = (b: (typeof value.stars)[number], kind: string, i: number) => ({
|
|
177
|
+
...b,
|
|
178
|
+
id: `M-${kind}-id-${i}`,
|
|
179
|
+
label: `M-${kind}-label-${i}`,
|
|
180
|
+
status: `M-${kind}-status-${i}`,
|
|
181
|
+
detail: `M-${kind}-detail-${i}`,
|
|
182
|
+
online: !b.online,
|
|
183
|
+
color: [0.111, 0.222, 0.333] as [number, number, number],
|
|
184
|
+
radius: b.radius + 1000,
|
|
185
|
+
orbitCenter: [1.5, 2.5, 3.5] as [number, number, number],
|
|
186
|
+
orbitRadius: b.orbitRadius + 2000,
|
|
187
|
+
orbitPeriodSec: b.orbitPeriodSec + 3000,
|
|
188
|
+
orbitPhase: b.orbitPhase + 0.375,
|
|
189
|
+
orbitTilt: b.orbitTilt + 0.5,
|
|
190
|
+
spinPeriodSec: b.spinPeriodSec + 4000,
|
|
191
|
+
satellites: b.satellites + 7,
|
|
192
|
+
satelliteTotal: b.satelliteTotal + 9,
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
stars: value.stars.map((b, i) => mark(b, "star", i)),
|
|
196
|
+
planets: value.planets.map((b, i) => mark(b, "planet", i)),
|
|
197
|
+
hasRegistryCore: !value.hasRegistryCore,
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
let marked: ReturnType<typeof buildFleetSceneSpecWasm>;
|
|
201
|
+
try {
|
|
202
|
+
marked = buildFleetSceneSpecWasm(ROWS);
|
|
203
|
+
} finally {
|
|
204
|
+
seam.doorOverride = original;
|
|
205
|
+
}
|
|
206
|
+
const plain = buildFleetSceneSpecWasm(ROWS);
|
|
207
|
+
|
|
208
|
+
// EVERY field of EVERY body must be the door's value. Comparing whole
|
|
209
|
+
// objects (rather than one marked key per body) is what closes the
|
|
210
|
+
// field-level partial door: a builder that takes the door's labels and the
|
|
211
|
+
// raw namespace's numbers passes a label-only check.
|
|
212
|
+
expect(marked.stars).toHaveLength(plain.stars.length);
|
|
213
|
+
marked.stars.forEach((b, i) => {
|
|
214
|
+
expect(b).not.toEqual(plain.stars[i]);
|
|
215
|
+
expect(b.id).toBe(`M-star-id-${i}`);
|
|
216
|
+
expect(b.label).toBe(`M-star-label-${i}`);
|
|
217
|
+
expect(b.status).toBe(`M-star-status-${i}`);
|
|
218
|
+
expect(b.detail).toBe(`M-star-detail-${i}`);
|
|
219
|
+
// The adapter normalises role to "star"/"planet", so it is asserted by
|
|
220
|
+
// value rather than by a mark: a marked non-star would read as "planet".
|
|
221
|
+
expect(b.role).toBe("star");
|
|
222
|
+
expect(b.online).toBe(!plain.stars[i]!.online);
|
|
223
|
+
expect(b.color).toEqual([0.111, 0.222, 0.333]);
|
|
224
|
+
expect(b.radius).toBeCloseTo(plain.stars[i]!.radius + 1000, 5);
|
|
225
|
+
expect(b.orbitCenter).toEqual([1.5, 2.5, 3.5]);
|
|
226
|
+
expect(b.orbitRadius).toBeCloseTo(plain.stars[i]!.orbitRadius + 2000, 5);
|
|
227
|
+
expect(b.orbitPeriodSec).toBeCloseTo(plain.stars[i]!.orbitPeriodSec + 3000, 5);
|
|
228
|
+
expect(b.orbitPhase).toBeCloseTo(plain.stars[i]!.orbitPhase + 0.375, 5);
|
|
229
|
+
expect(b.orbitTilt).toBeCloseTo(plain.stars[i]!.orbitTilt + 0.5, 5);
|
|
230
|
+
expect(b.spinPeriodSec).toBeCloseTo(plain.stars[i]!.spinPeriodSec + 4000, 5);
|
|
231
|
+
expect(b.satellites).toBe(plain.stars[i]!.satellites + 7);
|
|
232
|
+
expect(b.satelliteTotal).toBe(plain.stars[i]!.satelliteTotal + 9);
|
|
233
|
+
});
|
|
234
|
+
expect(marked.planets).toHaveLength(plain.planets.length);
|
|
235
|
+
// The planet block must assert the SAME field set as the star block. An
|
|
236
|
+
// earlier revision checked only nine of the fifteen fields here, so four of
|
|
237
|
+
// them (colour, orbit centre, tilt, spin) leaked from a parallel raw read
|
|
238
|
+
// and the suite stayed green (measured: 75/75).
|
|
239
|
+
marked.planets.forEach((b, i) => {
|
|
240
|
+
expect(b).not.toEqual(plain.planets[i]);
|
|
241
|
+
expect(b.id).toBe(`M-planet-id-${i}`);
|
|
242
|
+
expect(b.label).toBe(`M-planet-label-${i}`);
|
|
243
|
+
expect(b.status).toBe(`M-planet-status-${i}`);
|
|
244
|
+
expect(b.detail).toBe(`M-planet-detail-${i}`);
|
|
245
|
+
// The adapter normalises a planet's role to "planet" whatever the
|
|
246
|
+
// component said, so assert the normalised value rather than a mark.
|
|
247
|
+
expect(b.role).toBe("planet");
|
|
248
|
+
expect(b.online).toBe(!plain.planets[i]!.online);
|
|
249
|
+
expect(b.color).toEqual([0.111, 0.222, 0.333]);
|
|
250
|
+
expect(b.radius).toBeCloseTo(plain.planets[i]!.radius + 1000, 5);
|
|
251
|
+
expect(b.orbitCenter).toEqual([1.5, 2.5, 3.5]);
|
|
252
|
+
expect(b.orbitRadius).toBeCloseTo(plain.planets[i]!.orbitRadius + 2000, 5);
|
|
253
|
+
expect(b.orbitPeriodSec).toBeCloseTo(plain.planets[i]!.orbitPeriodSec + 3000, 5);
|
|
254
|
+
expect(b.orbitPhase).toBeCloseTo(plain.planets[i]!.orbitPhase + 0.375, 5);
|
|
255
|
+
expect(b.orbitTilt).toBeCloseTo(plain.planets[i]!.orbitTilt + 0.5, 5);
|
|
256
|
+
expect(b.spinPeriodSec).toBeCloseTo(plain.planets[i]!.spinPeriodSec + 4000, 5);
|
|
257
|
+
expect(b.satellites).toBe(plain.planets[i]!.satellites + 7);
|
|
258
|
+
expect(b.satelliteTotal).toBe(plain.planets[i]!.satelliteTotal + 9);
|
|
259
|
+
});
|
|
260
|
+
expect(marked.hasRegistryCore).toBe(!plain.hasRegistryCore);
|
|
261
|
+
// Guard against a trivially empty comparison.
|
|
262
|
+
expect(marked.stars.length + marked.planets.length).toBeGreaterThan(0);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// The raw export, for the substitution case. Named so the override above can
|
|
266
|
+
// delegate to it (the door wraps this same function).
|
|
267
|
+
function rawBuild(rows: Parameters<typeof realWrapper.buildFleetScene>[0]) {
|
|
268
|
+
return realWrapper.buildFleetScene(rows);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
it("publishes the empty declaration the sync door requires", () => {
|
|
272
|
+
// Empty is not cosmetic: `createSurface` refuses any non-empty declaration
|
|
273
|
+
// (it cannot provide capabilities for an already-evaluated wrapper), so a
|
|
274
|
+
// glue-bearing declaration here would make the builder unusable.
|
|
275
|
+
expect(SCENE3D_CAPABILITIES).toEqual({ interfaces: [], wasiModules: [] });
|
|
276
|
+
|
|
277
|
+
// …and the builder must hand that declaration to the door, not merely
|
|
278
|
+
// publish it. Omitting the argument lets `createSurface` default to `{}`,
|
|
279
|
+
// so its refusal never fires and the declared value would never be
|
|
280
|
+
// consulted. Asserted against the FIRST build (②) so a later surface cannot
|
|
281
|
+
// turn this into an `undefined` failure for the wrong reason — the
|
|
282
|
+
// build-count pin reports a second door, this one reports the declaration
|
|
283
|
+
// that actually guarded module load.
|
|
284
|
+
// Scope, precisely: this pin catches **the argument being dropped**
|
|
285
|
+
// (verified: it is the only case that fails then). It is not a general "no
|
|
286
|
+
// wrong declaration can ship" guard — it asserts identity with whatever
|
|
287
|
+
// `declare-caps.ts` exports, so changing that file to a non-empty
|
|
288
|
+
// declaration passes here and is refused by the door instead (which is what
|
|
289
|
+
// the next case documents).
|
|
290
|
+
expect(seam.firstHandedCapabilities).toBe(SCENE3D_CAPABILITIES);
|
|
291
|
+
|
|
292
|
+
// The identity assertion above is the guard for "the declaration was handed
|
|
293
|
+
// over": dropping the argument and passing `undefined` both red it and
|
|
294
|
+
// nothing else (verified by mutation). An arity assertion used to sit here;
|
|
295
|
+
// it was removed as redundant — every shape it could fail on (an omitted
|
|
296
|
+
// argument, `undefined`, a foreign object) already reds the identity check
|
|
297
|
+
// above, and `rest` is length 2 for the latter two, so it added nothing
|
|
298
|
+
// except a sentence about itself that three revisions could not state
|
|
299
|
+
// truthfully.
|
|
300
|
+
//
|
|
301
|
+
// Scope, precisely: this pin is *stricter* than the door's contract. The
|
|
302
|
+
// door only reads `.interfaces`/`.wasiModules`, so a builder passing a
|
|
303
|
+
// different object with the same contents would be functionally correct —
|
|
304
|
+
// and still red here (verified by mutation). That is deliberate: the
|
|
305
|
+
// declaration is a single exported singleton, and handing over anything
|
|
306
|
+
// else means the builder has stopped using what `declare-caps.ts` publishes.
|
|
307
|
+
|
|
308
|
+
// Exported and read by the builder — the read the package's `sideEffects`
|
|
309
|
+
// whitelist entry keeps alive.
|
|
310
|
+
expect(scene3dCapabilities).toBe(SCENE3D_CAPABILITIES);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("refuses a non-empty declaration instead of silently granting it", async () => {
|
|
314
|
+
// Documents the door's contract with the REAL client: a glue- or
|
|
315
|
+
// WASI-bearing declaration is refused. DISCLOSURE: this calls
|
|
316
|
+
// `createSurface` directly, so it passes even if the builder stops handing
|
|
317
|
+
// the declaration over — it is NOT the regression guard for that. The guard
|
|
318
|
+
// is `expect(seam.firstHandedCapabilities).toBe(SCENE3D_CAPABILITIES)` above.
|
|
319
|
+
const { createSurface, HostClientError } = await vi.importActual<
|
|
320
|
+
typeof import("@celestia-island/tairitsu-host-client")
|
|
321
|
+
>("@celestia-island/tairitsu-host-client");
|
|
322
|
+
const namespace = seam.handed!;
|
|
323
|
+
expect(() =>
|
|
324
|
+
createSurface(namespace, { interfaces: ["document"], wasiModules: [] }),
|
|
325
|
+
).toThrow(HostClientError);
|
|
326
|
+
expect(() =>
|
|
327
|
+
createSurface(namespace, { interfaces: [], wasiModules: ["random"] }),
|
|
328
|
+
).toThrow(HostClientError);
|
|
329
|
+
// The empty declaration is the one the door accepts.
|
|
330
|
+
expect(() =>
|
|
331
|
+
createSurface(namespace, { interfaces: [], wasiModules: [] }),
|
|
332
|
+
).not.toThrow();
|
|
333
|
+
});
|
|
334
|
+
});
|
|
@@ -1,26 +1,101 @@
|
|
|
1
|
-
// wasmFleetSpec.ts — the wasm-backed fleet scene spec builder
|
|
1
|
+
// wasmFleetSpec.ts — the wasm-backed fleet scene spec builder, loaded through
|
|
2
|
+
// the tairitsu host client (stage 3).
|
|
2
3
|
//
|
|
3
4
|
// Bridges hikari-wasm-scene3d (the Rust component that computes the
|
|
4
5
|
// deterministic solar-system layout) into the TS FleetSceneSpec shape the
|
|
5
6
|
// three.js renderer consumes. The TS buildFleetSceneSpec stays as the
|
|
6
7
|
// reference implementation and test oracle; this bridge routes production
|
|
7
8
|
// traffic through the wasm component.
|
|
9
|
+
//
|
|
10
|
+
// The facade is SYNCHRONOUS (user ruling: callers do not change). The host
|
|
11
|
+
// client's synchronous door (`createSurface`) is what makes that possible: the
|
|
12
|
+
// wrapper is in this module graph, so its exports are callable as soon as the
|
|
13
|
+
// module is evaluated — no readiness dance in the common path.
|
|
14
|
+
import { SCENE3D_CAPABILITIES, SCENE3D_DECLARATION_PUBLISHED } from "./declare-caps";
|
|
15
|
+
import * as scene3dWrapper from "../wasm/scene3d/hikari_wasm_scene3d.js";
|
|
16
|
+
import {
|
|
17
|
+
createSurface,
|
|
18
|
+
HostClientError,
|
|
19
|
+
type HostComponent,
|
|
20
|
+
} from "@celestia-island/tairitsu-host-client";
|
|
8
21
|
|
|
9
|
-
import { buildFleetScene as wasmBuild } from "../wasm/scene3d/hikari_wasm_scene3d.js";
|
|
10
22
|
import type { FleetBodySpec, FleetRowLike, FleetSceneSpec } from "./holographicFleetSpec";
|
|
11
23
|
import type { Vec3 } from "../utils/scene3d";
|
|
12
24
|
|
|
25
|
+
/** The component's `hikari:scene3d/types` shape, as the wrapper returns it. */
|
|
26
|
+
interface WasmFleetBodySpec {
|
|
27
|
+
id: string;
|
|
28
|
+
label: string;
|
|
29
|
+
status: string;
|
|
30
|
+
online: boolean;
|
|
31
|
+
detail: string;
|
|
32
|
+
role: string;
|
|
33
|
+
color: readonly [number, number, number];
|
|
34
|
+
radius: number;
|
|
35
|
+
orbitCenter: readonly [number, number, number];
|
|
36
|
+
orbitRadius: number;
|
|
37
|
+
orbitPeriodSec: number;
|
|
38
|
+
orbitPhase: number;
|
|
39
|
+
orbitTilt: number;
|
|
40
|
+
spinPeriodSec: number;
|
|
41
|
+
satellites: number;
|
|
42
|
+
satelliteTotal: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface WasmFleetSceneSpec {
|
|
46
|
+
stars: WasmFleetBodySpec[];
|
|
47
|
+
planets: WasmFleetBodySpec[];
|
|
48
|
+
hasRegistryCore: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Thrown when the spec builder is called before the component is usable. */
|
|
52
|
+
export class Scene3dNotReadyError extends Error {
|
|
53
|
+
constructor(cause?: unknown) {
|
|
54
|
+
super(
|
|
55
|
+
"the scene3d component is not loaded; await scene3dReady (or render again once it resolves)",
|
|
56
|
+
{ cause },
|
|
57
|
+
);
|
|
58
|
+
this.name = "Scene3dNotReadyError";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let surface: HostComponent | undefined;
|
|
63
|
+
let loadFailure: Scene3dNotReadyError | undefined;
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
surface = createSurface(
|
|
67
|
+
scene3dWrapper as unknown as Record<string, unknown>,
|
|
68
|
+
// Hand the declaration to the door, don't just publish it: with the
|
|
69
|
+
// parameter omitted it defaults to `{}`, so the door's own refusal
|
|
70
|
+
// (`sync-door-cannot-provide`) can never fire and a wrong declaration would
|
|
71
|
+
// pass unnoticed. Passing it makes the declaration checkable here.
|
|
72
|
+
SCENE3D_CAPABILITIES,
|
|
73
|
+
);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
// Recognisable at the call site: callers that can wait use `scene3dReady`.
|
|
76
|
+
// The underlying cause is kept.
|
|
77
|
+
loadFailure = new Scene3dNotReadyError(error);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Resolves once the component is usable; rejects if it could not be built. */
|
|
81
|
+
export const scene3dReady: Promise<void> = surface
|
|
82
|
+
? Promise.resolve()
|
|
83
|
+
: Promise.reject(loadFailure ?? new Scene3dNotReadyError());
|
|
84
|
+
|
|
85
|
+
/** Keeps the declaration module live for bundlers that honour `sideEffects`. */
|
|
86
|
+
export const scene3dCapabilities = SCENE3D_CAPABILITIES;
|
|
87
|
+
void SCENE3D_DECLARATION_PUBLISHED;
|
|
88
|
+
|
|
89
|
+
scene3dReady.catch(() => {
|
|
90
|
+
// Consumed by callers that care; a rejected module-level promise nobody
|
|
91
|
+
// handles would be an unhandled rejection.
|
|
92
|
+
});
|
|
93
|
+
|
|
13
94
|
/** WIT tuple → TS Vec3 (both are 3-element arrays at runtime). */
|
|
14
95
|
const toVec3 = (t: readonly [number, number, number]): Vec3 => [t[0], t[1], t[2]];
|
|
15
96
|
|
|
16
97
|
/** Adapt the wasm component's FleetBodySpec to the TS shape. */
|
|
17
|
-
function adaptBody(b: {
|
|
18
|
-
id: string; label: string; status: string; online: boolean; detail: string;
|
|
19
|
-
role: string; color: readonly [number, number, number]; radius: number;
|
|
20
|
-
orbitCenter: readonly [number, number, number]; orbitRadius: number;
|
|
21
|
-
orbitPeriodSec: number; orbitPhase: number; orbitTilt: number;
|
|
22
|
-
spinPeriodSec: number; satellites: number; satelliteTotal: number;
|
|
23
|
-
}): FleetBodySpec {
|
|
98
|
+
function adaptBody(b: WasmFleetBodySpec): FleetBodySpec {
|
|
24
99
|
return {
|
|
25
100
|
id: b.id,
|
|
26
101
|
label: b.label,
|
|
@@ -43,6 +118,7 @@ function adaptBody(b: {
|
|
|
43
118
|
|
|
44
119
|
/** Build the fleet scene spec through the wasm component. */
|
|
45
120
|
export function buildFleetSceneSpecWasm(rows: readonly FleetRowLike[]): FleetSceneSpec {
|
|
121
|
+
if (!surface) throw loadFailure ?? new Scene3dNotReadyError();
|
|
46
122
|
const wasmRows = rows.map((r) => ({
|
|
47
123
|
nodeId: r.node_id,
|
|
48
124
|
tier: r.tier,
|
|
@@ -52,10 +128,17 @@ export function buildFleetSceneSpecWasm(rows: readonly FleetRowLike[]): FleetSce
|
|
|
52
128
|
online: r.online,
|
|
53
129
|
detail: r.detail,
|
|
54
130
|
}));
|
|
55
|
-
|
|
131
|
+
// The wrapper's export is `buildFleetScene`, not the WIT func name
|
|
132
|
+
// (`build-fleet-scene`): jco names JS exports in camelCase and the host
|
|
133
|
+
// client's `pickExport` looks up an exact own property, so the call must use
|
|
134
|
+
// the JS name. (The QR/Mermaid cuts export bare identifiers, which is why
|
|
135
|
+
// this only shows up here.)
|
|
136
|
+
const result = surface.call<WasmFleetSceneSpec>("buildFleetScene", wasmRows);
|
|
56
137
|
return {
|
|
57
138
|
stars: result.stars.map(adaptBody),
|
|
58
139
|
planets: result.planets.map(adaptBody),
|
|
59
140
|
hasRegistryCore: result.hasRegistryCore,
|
|
60
141
|
};
|
|
61
142
|
}
|
|
143
|
+
|
|
144
|
+
export { HostClientError };
|