@spellkave/session 0.0.0-bootstrap
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/LICENSE +89 -0
- package/bin/spellkave-session-daemon.js +5 -0
- package/package.json +60 -0
- package/src/acting-context.ts +222 -0
- package/src/authoring/caller-tools.ts +227 -0
- package/src/authoring/index.ts +28 -0
- package/src/authoring/live-applyset-port.ts +432 -0
- package/src/authoring/live-author-target.ts +995 -0
- package/src/authoring/live-can-i-port.ts +152 -0
- package/src/authoring/live-exploration-port.ts +274 -0
- package/src/authoring/live-grants-port.ts +172 -0
- package/src/authoring/live-scenes-port.ts +84 -0
- package/src/authoring/live-scoped-instance-port.ts +355 -0
- package/src/binding.ts +125 -0
- package/src/index.ts +24 -0
- package/src/live/discovery-closure-walk.ts +318 -0
- package/src/live/kernel-convergence-support.ts +122 -0
- package/src/live/seed.ts +37 -0
- package/src/live/support.ts +82 -0
- package/src/node/client.ts +233 -0
- package/src/node/connection-controller.ts +469 -0
- package/src/node/daemon-entry.ts +57 -0
- package/src/node/daemon.ts +629 -0
- package/src/node/index.ts +110 -0
- package/src/node/live-delta.ts +229 -0
- package/src/node/observability.ts +481 -0
- package/src/node/paths.ts +83 -0
- package/src/node/player-run-observer.ts +122 -0
- package/src/node/protocol.ts +200 -0
- package/src/node/spawn.ts +225 -0
- package/src/node/world-events.ts +270 -0
- package/src/player-tools/delta-tracker.ts +1 -0
- package/src/player-tools/index.ts +10 -0
- package/src/player-tools/node-adapter.ts +9 -0
- package/src/player-tools/observation.ts +1 -0
- package/src/player-tools/player-host.ts +92 -0
- package/src/player-tools/push-events.ts +1 -0
- package/src/player-tools/query-protocol.ts +1 -0
- package/src/player-tools/refusal-prose.ts +1 -0
- package/src/player-tools/resolution.ts +1 -0
- package/src/player-tools/tool-registry.ts +1 -0
- package/src/player-tools/tools.ts +42 -0
- package/src/player-tools/world-events.ts +119 -0
- package/src/session.ts +604 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// The DISCOVERY-CLOSURE funnel walk, session-owned copy. `createLiveAuthorTarget` (the live
|
|
2
|
+
// `spellkave_query` target) lives in this package, and srd-cc depends on session (not the reverse), so
|
|
3
|
+
// the live walk needs a home here. The srd-cc original
|
|
4
|
+
// (`packages/spellkave-srd-cc/src/test/shared/discovery-closure.ts`) stays for the offline tier
|
|
5
|
+
// until the deletion phase; the walk and its grounded ref exceptions are the same content-agnostic
|
|
6
|
+
// funnel (summary -> list -> detail -> outbound refs -> schema vocabulary). Full walk, no sampling.
|
|
7
|
+
import { expect } from "vitest";
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// `spellkave_query` result shapes — LOCAL interfaces mirroring the tool's
|
|
11
|
+
// runtime output (the SAME convention `fixtures-author-tool/harness.ts` uses:
|
|
12
|
+
// these types aren't part of `@spellkave/tool-player`'s public surface,
|
|
13
|
+
// see that file's own `QuerySummaryResult`/`QueryListResult`/
|
|
14
|
+
// `QueryDetailResult` interfaces), not re-declared as a dependency on the
|
|
15
|
+
// tool's internal `authoring-verbs.ts` types.
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
export interface DiscoverySummaryResult {
|
|
19
|
+
shape: "summary";
|
|
20
|
+
source: string;
|
|
21
|
+
bundle_ids: string[];
|
|
22
|
+
row_kinds: Record<string, number>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DiscoveryListItem {
|
|
26
|
+
id: string;
|
|
27
|
+
bundle_id?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DiscoveryListResult {
|
|
31
|
+
shape: "list";
|
|
32
|
+
kind: string;
|
|
33
|
+
source: string;
|
|
34
|
+
items: DiscoveryListItem[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface DiscoveryOutboundRef {
|
|
38
|
+
field: string;
|
|
39
|
+
value: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface DiscoveryDetailResult {
|
|
43
|
+
shape: "detail";
|
|
44
|
+
kind: string;
|
|
45
|
+
id: string;
|
|
46
|
+
found: boolean;
|
|
47
|
+
source?: string;
|
|
48
|
+
row?: Record<string, unknown>;
|
|
49
|
+
outbound_refs?: DiscoveryOutboundRef[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface DiscoverySchemaIndexResult {
|
|
53
|
+
shape: "schema";
|
|
54
|
+
kinds: {
|
|
55
|
+
kind: string;
|
|
56
|
+
queryable: boolean;
|
|
57
|
+
natural_key?: string;
|
|
58
|
+
composite_key?: string[];
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type DiscoveryQueryResult =
|
|
63
|
+
| DiscoverySummaryResult
|
|
64
|
+
| DiscoveryListResult
|
|
65
|
+
| DiscoveryDetailResult
|
|
66
|
+
| DiscoverySchemaIndexResult;
|
|
67
|
+
|
|
68
|
+
/** The abstract executor the shared walk drives — bound to `spellkave_query`
|
|
69
|
+
* against a local `fixtures/` target (offline) or a live seeded node (live-
|
|
70
|
+
* preseeded); see each tier's own test file for how it wires this. */
|
|
71
|
+
export type DiscoveryQueryExecutor = (
|
|
72
|
+
params: Record<string, unknown>,
|
|
73
|
+
) => Promise<DiscoveryQueryResult>;
|
|
74
|
+
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// DISCOVERY_CLOSURE_REF_EXCEPTIONS — the named, GROUNDED exceptions to
|
|
77
|
+
// "every outbound ref resolves to found:true when re-queried". An ungrounded
|
|
78
|
+
// unresolved ref is a real finding (recorded to `ledger/findings.md`), not
|
|
79
|
+
// silently added here.
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
export interface DiscoveryRefContext {
|
|
83
|
+
fromKind: string;
|
|
84
|
+
fromId: string;
|
|
85
|
+
field: string;
|
|
86
|
+
value: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface DiscoveryRefException {
|
|
90
|
+
name: string;
|
|
91
|
+
/** One-line grounding: WHY this shape is a legitimate never-a-row
|
|
92
|
+
* reference, pinned to a file/doc, never asserted from memory. */
|
|
93
|
+
grounding: string;
|
|
94
|
+
matches: (ref: DiscoveryRefContext) => boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const DISCOVERY_CLOSURE_REF_EXCEPTIONS: DiscoveryRefException[] = [
|
|
98
|
+
{
|
|
99
|
+
name: "unset optional *_id field (empty-string schema-default sentinel)",
|
|
100
|
+
grounding:
|
|
101
|
+
"packages/spellkave-world-author/docs/tool-reference.md documents this convention verbatim " +
|
|
102
|
+
"for multiple *_id-shaped optional fields (e.g. action_definitions.session_def_id/on_failure/ " +
|
|
103
|
+
"resolution_predicate_source: 'Omit for none (schema default: empty string)') — an unauthored optional " +
|
|
104
|
+
"*_id column round-trips as the empty string, never as a real row's natural key (every " +
|
|
105
|
+
"observed natural key across this bundle's fixtures is a non-empty slug/path), so an empty " +
|
|
106
|
+
"value is the field's own absence-sentinel, not a dangling pointer.",
|
|
107
|
+
matches: (ref) => ref.value === "",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "capability:<capability_id> synthetic niche",
|
|
111
|
+
grounding:
|
|
112
|
+
"packages/spellkave-tool-authoring/src/authoring-verbs.ts's spellkave_define_action_verb doc " +
|
|
113
|
+
"block (~lines 6169-6210) names the `capability:<capability_id>` synthetic-niche convention " +
|
|
114
|
+
"(dozens of uses across world-fixtures/phandelver/**) as a niche_id shape with deliberately NO " +
|
|
115
|
+
"niche_definitions row to check against — the same doc block states existence-checking niche_id " +
|
|
116
|
+
"there would false-reject this convention's own grounding call sites.",
|
|
117
|
+
matches: (ref) => ref.field === "niche_id" && ref.value.startsWith("capability:"),
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "bare tag / entity_def_id-derived target niche",
|
|
121
|
+
grounding: "Definition IDs and tags can serve as target niche identifiers.",
|
|
122
|
+
matches: (ref) => ref.field === "niche_id",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "place_nodes.local_id composite-PK fragment (own-row id, not a ref)",
|
|
126
|
+
grounding: "A place node’s local ID is part of its own key.",
|
|
127
|
+
matches: (ref) => ref.fromKind === "place_nodes" && ref.field === "local_id",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "outcome graph node key (graph-local node_id / root_node_id, not a row reference)",
|
|
131
|
+
grounding: "Outcome graph node IDs are local to the graph.",
|
|
132
|
+
matches: (ref) =>
|
|
133
|
+
(ref.fromKind === "outcome_graph_nodes" && ref.field === "node_id") ||
|
|
134
|
+
(ref.fromKind === "outcome_graphs" && ref.field === "root_node_id"),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "roll_table_entries.result_ref for an int-result_kind table (literal payload, not a row reference)",
|
|
138
|
+
grounding: "For an integer result table, the result reference is an integer literal.",
|
|
139
|
+
matches: (ref) =>
|
|
140
|
+
ref.fromKind === "roll_table_entries" &&
|
|
141
|
+
ref.field === "result_ref" &&
|
|
142
|
+
/^\d+$/.test(ref.value),
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "bare capability_id with no capability_definitions row (walk-edge convention)",
|
|
146
|
+
grounding:
|
|
147
|
+
"world-fixtures' own base bundle ships `<walk-capability>` as a plain string referenced by " +
|
|
148
|
+
"`actor_capabilities`/`affordance_templates.capability_id`/predicate text ONLY, with NO matching " +
|
|
149
|
+
"capability_definitions row anywhere (grepped directly) — crates/spellkave-validate/src/refs.rs's " +
|
|
150
|
+
"MF-VAL-266 checks capability_definitions.capability_id for DUPLICATES only, never existence of a " +
|
|
151
|
+
"referencing capability_id. `grid-units.ts`'s own module header names this precedent and follows " +
|
|
152
|
+
"the same bare-id shape for `srd/capability/walk`.",
|
|
153
|
+
matches: (ref) => ref.field === "capability_id" && ref.value === "srd/capability/walk",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "combat_grid_blueprints.distance_metric_id naming a core-seeded metric (module vocabulary, no manifest row)",
|
|
157
|
+
grounding:
|
|
158
|
+
"ADR-0134 D-1: the three `core/metric/*` distance_metric_definitions rows are seeded by the " +
|
|
159
|
+
"module itself (the built-in distance metric IDs, mirrored as " +
|
|
160
|
+
"`spellkave_schema::CORE_DISTANCE_METRIC_IDS`), the way `extent_kind_definitions` core seeds " +
|
|
161
|
+
"ship — crates/spellkave-validate/src/action_economy.rs's MF-VAL-332 resolves a blueprint's " +
|
|
162
|
+
"distance_metric_id against those seeds plus any manifest rows, so `srd/combat-grid/" +
|
|
163
|
+
"standard-10x10` (ADR-0134 D-5, `core/metric/chebyshev`) legitimately names an id this " +
|
|
164
|
+
"bundle's fixtures never declare. Narrowed to the three seeded ids: an authored metric id " +
|
|
165
|
+
"with no [[distance_metric_definitions]] row still fails the walk.",
|
|
166
|
+
matches: (ref) =>
|
|
167
|
+
ref.fromKind === "combat_grid_blueprints" &&
|
|
168
|
+
ref.field === "distance_metric_id" &&
|
|
169
|
+
["core/metric/euclidean", "core/metric/chebyshev", "core/metric/manhattan"].includes(
|
|
170
|
+
ref.value,
|
|
171
|
+
),
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
export interface DiscoveryClosureReport {
|
|
176
|
+
bundleIds: string[];
|
|
177
|
+
kindCounts: Record<string, number>;
|
|
178
|
+
totalRowsWalked: number;
|
|
179
|
+
totalOutboundRefs: number;
|
|
180
|
+
exceptedRefCounts: { name: string; count: number }[];
|
|
181
|
+
elapsedMs: number;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Run the content-agnostic discovery funnel walk against `query`, asserting
|
|
186
|
+
* every structural invariant inline (vitest `expect`, so a failure names
|
|
187
|
+
* exactly which funnel step/kind/id/ref broke). Returns a small report for
|
|
188
|
+
* the caller to log (row/ref counts, elapsed time) — never itself a
|
|
189
|
+
* content-specific assertion surface.
|
|
190
|
+
*
|
|
191
|
+
* `expectBundle`: the bundle_id the caller expects present in the summary
|
|
192
|
+
* (e.g. `BUNDLE_ID` from `chapters/playing-the-game/index.ts`) — asserted
|
|
193
|
+
* with `toContain`, never `toEqual`, so a source that legitimately carries
|
|
194
|
+
* MORE bundles (the live-preseeded node's `core` + `srd`) still passes.
|
|
195
|
+
*/
|
|
196
|
+
export async function runDiscoveryClosureWalk(
|
|
197
|
+
query: DiscoveryQueryExecutor,
|
|
198
|
+
options: { expectBundle: string },
|
|
199
|
+
): Promise<DiscoveryClosureReport> {
|
|
200
|
+
const startedAt = Date.now();
|
|
201
|
+
|
|
202
|
+
// (a) No-args summary: non-empty bundles incl. the expected one, non-empty
|
|
203
|
+
// kind -> count map.
|
|
204
|
+
const summary = (await query({})) as DiscoverySummaryResult;
|
|
205
|
+
expect(summary.shape, "no-args spellkave_query call must return the summary shape").toBe(
|
|
206
|
+
"summary",
|
|
207
|
+
);
|
|
208
|
+
expect(summary.bundle_ids.length, "summary.bundle_ids must be non-empty").toBeGreaterThan(0);
|
|
209
|
+
expect(
|
|
210
|
+
summary.bundle_ids,
|
|
211
|
+
`summary.bundle_ids must include '${options.expectBundle}' (additional bundles are tolerated, ` +
|
|
212
|
+
"never asserted exclusive)",
|
|
213
|
+
).toContain(options.expectBundle);
|
|
214
|
+
const kinds = Object.keys(summary.row_kinds);
|
|
215
|
+
expect(kinds.length, "summary.row_kinds must be non-empty").toBeGreaterThan(0);
|
|
216
|
+
|
|
217
|
+
// (b) + (c) + (d), interleaved per kind: list every kind (id-count must
|
|
218
|
+
// match the summary), then detail EVERY listed id (found:true, non-empty
|
|
219
|
+
// row) and chase EVERY outbound ref for closure — full walk, no sampling.
|
|
220
|
+
const idsToKinds = new Map<string, string[]>();
|
|
221
|
+
const rowsByKind = new Map<string, string[]>();
|
|
222
|
+
|
|
223
|
+
for (const kind of kinds) {
|
|
224
|
+
const list = (await query({ kind })) as DiscoveryListResult;
|
|
225
|
+
expect(list.shape, `kind='${kind}' list call must return the list shape`).toBe("list");
|
|
226
|
+
expect(
|
|
227
|
+
list.items.length,
|
|
228
|
+
`kind='${kind}' list id-count must match summary.row_kinds['${kind}']`,
|
|
229
|
+
).toBe(summary.row_kinds[kind]);
|
|
230
|
+
const ids = list.items.map((item) => item.id);
|
|
231
|
+
rowsByKind.set(kind, ids);
|
|
232
|
+
for (const id of ids) {
|
|
233
|
+
const owners = idsToKinds.get(id) ?? [];
|
|
234
|
+
owners.push(kind);
|
|
235
|
+
idsToKinds.set(id, owners);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let totalRowsWalked = 0;
|
|
240
|
+
let totalOutboundRefs = 0;
|
|
241
|
+
const exceptedCounts = new Map<string, number>();
|
|
242
|
+
|
|
243
|
+
for (const [kind, ids] of rowsByKind) {
|
|
244
|
+
for (const id of ids) {
|
|
245
|
+
totalRowsWalked += 1;
|
|
246
|
+
const detail = (await query({ kind, id, refs: "outbound" })) as DiscoveryDetailResult;
|
|
247
|
+
expect(detail.shape, `detail(kind='${kind}', id='${id}') must return the detail shape`).toBe(
|
|
248
|
+
"detail",
|
|
249
|
+
);
|
|
250
|
+
expect(
|
|
251
|
+
detail.found,
|
|
252
|
+
`detail(kind='${kind}', id='${id}') must resolve found:true for an id the list call just returned`,
|
|
253
|
+
).toBe(true);
|
|
254
|
+
expect(detail.row, `detail(kind='${kind}', id='${id}') must carry a row`).toBeDefined();
|
|
255
|
+
expect(
|
|
256
|
+
Object.keys(detail.row ?? {}).length,
|
|
257
|
+
`detail(kind='${kind}', id='${id}') row must be non-empty`,
|
|
258
|
+
).toBeGreaterThan(0);
|
|
259
|
+
|
|
260
|
+
for (const ref of detail.outbound_refs ?? []) {
|
|
261
|
+
totalOutboundRefs += 1;
|
|
262
|
+
const ownerKinds = idsToKinds.get(ref.value);
|
|
263
|
+
if (ownerKinds !== undefined) {
|
|
264
|
+
// REF CLOSURE: chase the ref by RE-QUERYING spellkave_query with
|
|
265
|
+
// its own {kind, id} — the tool's own documented "chase a
|
|
266
|
+
// reference" idiom — and require it resolves.
|
|
267
|
+
for (const targetKind of ownerKinds) {
|
|
268
|
+
const rechased = (await query({
|
|
269
|
+
kind: targetKind,
|
|
270
|
+
id: ref.value,
|
|
271
|
+
refs: "none",
|
|
272
|
+
})) as DiscoveryDetailResult;
|
|
273
|
+
expect(
|
|
274
|
+
rechased.found,
|
|
275
|
+
`ref closure: ${kind}/${id}'s outbound ref ${ref.field}='${ref.value}' must resolve ` +
|
|
276
|
+
`via re-query {kind: '${targetKind}', id: '${ref.value}'}`,
|
|
277
|
+
).toBe(true);
|
|
278
|
+
}
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const exception = DISCOVERY_CLOSURE_REF_EXCEPTIONS.find((entry) =>
|
|
282
|
+
entry.matches({ fromKind: kind, fromId: id, field: ref.field, value: ref.value }),
|
|
283
|
+
);
|
|
284
|
+
expect(
|
|
285
|
+
exception,
|
|
286
|
+
`ref closure gap: ${kind}/${id}'s outbound ref ${ref.field}='${ref.value}' does not resolve ` +
|
|
287
|
+
"to any known row and matches no grounded DISCOVERY_CLOSURE_REF_EXCEPTIONS entry — a " +
|
|
288
|
+
"genuine query-tool/content finding, not a silent exception.",
|
|
289
|
+
).toBeDefined();
|
|
290
|
+
if (exception !== undefined) {
|
|
291
|
+
exceptedCounts.set(exception.name, (exceptedCounts.get(exception.name) ?? 0) + 1);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// (e) schema:true (no kind): the row-kind vocabulary must name every kind
|
|
298
|
+
// the summary reported (schema is a documented SUPERSET, ~78 kinds vs the
|
|
299
|
+
// ~52 addressable ones — this direction only, never the reverse).
|
|
300
|
+
const schema = (await query({ schema: true })) as DiscoverySchemaIndexResult;
|
|
301
|
+
expect(schema.shape, "schema:true (no kind) call must return the schema shape").toBe("schema");
|
|
302
|
+
const schemaKindNames = new Set(schema.kinds.map((entry) => entry.kind));
|
|
303
|
+
for (const kind of kinds) {
|
|
304
|
+
expect(
|
|
305
|
+
schemaKindNames.has(kind),
|
|
306
|
+
`schema:true's row-kind vocabulary must include summary kind '${kind}'`,
|
|
307
|
+
).toBe(true);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
bundleIds: summary.bundle_ids,
|
|
312
|
+
kindCounts: { ...summary.row_kinds },
|
|
313
|
+
totalRowsWalked,
|
|
314
|
+
totalOutboundRefs,
|
|
315
|
+
exceptedRefCounts: [...exceptedCounts.entries()].map(([name, count]) => ({ name, count })),
|
|
316
|
+
elapsedMs: Date.now() - startedAt,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared pieces of the kernel-convergence live twins (`pnpm test:live`). The mechanic DEFINITIONS
|
|
3
|
+
* (damage, buff and cure actions, the hp pool, the poisoned-equivalent condition) come from the
|
|
4
|
+
* seeded `mech_kernel_convergence` bundle; every twin builds its OWN scene entities and attaches
|
|
5
|
+
* the capability niche it needs to its own arena, so nothing is shared between tests or runs.
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
type EntityRef,
|
|
9
|
+
readActorSnapshot,
|
|
10
|
+
readObjectStateInt,
|
|
11
|
+
readWorldStatus,
|
|
12
|
+
} from "@spellkave/sdk";
|
|
13
|
+
import type { SnapshotDb } from "@spellkave/sdk/replay";
|
|
14
|
+
import type { Scene, TestWorld } from "@spellkave/test-lab";
|
|
15
|
+
import { applySceneExtras } from "./support";
|
|
16
|
+
|
|
17
|
+
export const KC_BUNDLE = "mech_kernel_convergence";
|
|
18
|
+
export const KC_DEPS = ["core", KC_BUNDLE] as const;
|
|
19
|
+
|
|
20
|
+
export const HP_RESOURCE = `${KC_BUNDLE}/hp`;
|
|
21
|
+
export const HP_INITIAL = 50;
|
|
22
|
+
export const HP_SEEDED_TARGET_DEF = `${KC_BUNDLE}/hp_seeded_target_def`;
|
|
23
|
+
export const POISON_TARGET_DEF = `${KC_BUNDLE}/poisoned_equiv_target_def`;
|
|
24
|
+
|
|
25
|
+
export const DAMAGE_CAPABILITY = `${KC_BUNDLE}/capability/damage`;
|
|
26
|
+
export const DAMAGE_ACTION = `${KC_BUNDLE}/cast_damage`;
|
|
27
|
+
/** `1d10 + 5` (see `DAMAGE_DELTA_SOURCE` in `@spellkave/mechanics`): the bound of one cast. */
|
|
28
|
+
export const DAMAGE_RANGE: readonly [number, number] = [6, 15];
|
|
29
|
+
|
|
30
|
+
export const BUFF_CAPABILITY = `${KC_BUNDLE}/capability/buff`;
|
|
31
|
+
export const BUFF_ACTION = `${KC_BUNDLE}/cast_buff`;
|
|
32
|
+
export const BUFF_CONDITION = `${KC_BUNDLE}/buffed`;
|
|
33
|
+
|
|
34
|
+
export const CURE_CAPABILITY = `${KC_BUNDLE}/capability/cure`;
|
|
35
|
+
export const CURE_ACTION = `${KC_BUNDLE}/cast_cure`;
|
|
36
|
+
export const POISON_CONDITION = `${KC_BUNDLE}/poisoned_equiv`;
|
|
37
|
+
/** The claim condition `r_manipulate` commits; anchors causal ordering of a removal. */
|
|
38
|
+
export const CONTROLLED_CONDITION = "core/condition/controlled";
|
|
39
|
+
|
|
40
|
+
/** Attach the place-provided capability niche to the scene's arena (the niche itself is seeded). */
|
|
41
|
+
export async function attachCapabilityNiche(
|
|
42
|
+
s: Scene,
|
|
43
|
+
place: string,
|
|
44
|
+
capabilityId: string,
|
|
45
|
+
): Promise<void> {
|
|
46
|
+
await applySceneExtras(
|
|
47
|
+
s,
|
|
48
|
+
`[[spatial_niche_attachments]]
|
|
49
|
+
bundle_id = "${s.prefix}"
|
|
50
|
+
place_node_id = "${s.reads.nodeId(place)}"
|
|
51
|
+
niche_id = "capability:${capabilityId}"
|
|
52
|
+
condition_bool = true
|
|
53
|
+
ecological_invariant = false
|
|
54
|
+
visibility = "Public"
|
|
55
|
+
`,
|
|
56
|
+
KC_DEPS,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** An integer object state as one connection's own cache holds it; `null` when it holds no row. */
|
|
61
|
+
export function stateOf(world: TestWorld, entityId: bigint, stateId: string): number | null {
|
|
62
|
+
const value = readObjectStateInt(world.db() as unknown as SnapshotDb, {
|
|
63
|
+
targetKind: "entity",
|
|
64
|
+
targetId: String(entityId),
|
|
65
|
+
stateId,
|
|
66
|
+
});
|
|
67
|
+
return value === null ? null : Number(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SeenCondition {
|
|
71
|
+
condition_definition_id: string;
|
|
72
|
+
applied_at_tick: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The conditions one connection's cache shows on an entity (player-facing snapshot reader), or
|
|
77
|
+
* `null` when that cache cannot see the entity at all (so an empty list is never a vacuous pass).
|
|
78
|
+
*/
|
|
79
|
+
export function conditionsOf(world: TestWorld, entityId: bigint): SeenCondition[] | null {
|
|
80
|
+
const snapshot = readActorSnapshot(
|
|
81
|
+
world.db() as unknown as SnapshotDb,
|
|
82
|
+
String(entityId) as EntityRef,
|
|
83
|
+
);
|
|
84
|
+
return snapshot === null ? null : (snapshot.conditions as unknown as SeenCondition[]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function hasCondition(world: TestWorld, entityId: bigint, conditionId: string): boolean {
|
|
88
|
+
return (conditionsOf(world, entityId) ?? []).some(
|
|
89
|
+
(c) => c.condition_definition_id === conditionId,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The world tick one connection's cache holds. */
|
|
94
|
+
export function tickOf(world: TestWorld): number {
|
|
95
|
+
return Number(readWorldStatus(world.db() as unknown as SnapshotDb)?.tick ?? 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface SeenProvenance {
|
|
99
|
+
provenanceId: string;
|
|
100
|
+
subjectId: string;
|
|
101
|
+
draws: number[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Provenance rows one connection's cache holds, or `null` when its cache has no such table. */
|
|
105
|
+
export function provenanceOf(world: TestWorld): SeenProvenance[] | null {
|
|
106
|
+
const db = world.db() as unknown as Record<
|
|
107
|
+
string,
|
|
108
|
+
{ iter(): Iterable<Record<string, unknown>> } | undefined
|
|
109
|
+
>;
|
|
110
|
+
const handle = db.visibleEvaluationProvenance ?? db.visible_evaluation_provenance;
|
|
111
|
+
if (handle === undefined) return null;
|
|
112
|
+
return [...handle.iter()].map((row) => {
|
|
113
|
+
const draws = (row.stochasticDraws ?? row.stochastic_draws ?? []) as {
|
|
114
|
+
value: number | bigint;
|
|
115
|
+
}[];
|
|
116
|
+
return {
|
|
117
|
+
provenanceId: String(row.provenanceId ?? row.provenance_id),
|
|
118
|
+
subjectId: String(row.subjectId ?? row.subject_id),
|
|
119
|
+
draws: draws.map((draw) => Number(draw.value)),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}
|
package/src/live/seed.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-level seed for the session live tests (`pnpm test:live`).
|
|
3
|
+
*
|
|
4
|
+
* One database per run, seeded once: gatekeeper first (scene() needs the owner bound to it
|
|
5
|
+
* and it must be the first thing that creates actors), then the `core` substrate and the two
|
|
6
|
+
* mechanic bundles whose DEFINITIONS the scenes depend on (`fastlane`: strike action + combat
|
|
7
|
+
* session; `mech_kernel_convergence`: damage/buff/cure actions, hp pool, poisoned-equivalent).
|
|
8
|
+
* Their fixed fixture actors are never used: each test builds its own scene entities.
|
|
9
|
+
* Re-running against a seeded database is a no-op. Never wipes or publishes.
|
|
10
|
+
*/
|
|
11
|
+
import { resolveSpacetimeConfigPathToken } from "@spellkave/sdk/node";
|
|
12
|
+
import {
|
|
13
|
+
applyManifestSource,
|
|
14
|
+
connectTestWorld,
|
|
15
|
+
ensureApplyManifestAuthority,
|
|
16
|
+
readFixtureSource,
|
|
17
|
+
} from "@spellkave/test-lab";
|
|
18
|
+
|
|
19
|
+
const token = resolveSpacetimeConfigPathToken();
|
|
20
|
+
if (!token) throw new Error("publisher credential required (SPACETIME_CONFIG_PATH)");
|
|
21
|
+
const world = await connectTestWorld({ token });
|
|
22
|
+
try {
|
|
23
|
+
await ensureApplyManifestAuthority(world);
|
|
24
|
+
for (const fixture of ["core", "fastlane", "mech_kernel_convergence"]) {
|
|
25
|
+
await applyManifestSource(
|
|
26
|
+
world,
|
|
27
|
+
readFixtureSource(`packages/spellkave-mechanics/fixtures/${fixture}`),
|
|
28
|
+
{ tolerateAlreadyApplied: true },
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
console.log(
|
|
32
|
+
"session live seed: gatekeeper + mechanics core, fastlane, mech_kernel_convergence (or already present)",
|
|
33
|
+
);
|
|
34
|
+
} finally {
|
|
35
|
+
world.disconnect();
|
|
36
|
+
}
|
|
37
|
+
process.exit(0);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// embedded-manifest: {"category": "exact_text_oracle", "rationale": "live scene extras need a minimal bundle envelope so a delta validates on its own against the shared package database"}
|
|
2
|
+
/**
|
|
3
|
+
* Shared helpers for the session live tests (`pnpm test:live`). The package seeds ONE database
|
|
4
|
+
* once (`seed.ts`); every test builds its own prefixed scene on it. Nothing here wipes,
|
|
5
|
+
* publishes or reseeds.
|
|
6
|
+
*/
|
|
7
|
+
import { resolveSpacetimeConfigPathToken } from "@spellkave/sdk/node";
|
|
8
|
+
import {
|
|
9
|
+
applyManifestDelta,
|
|
10
|
+
connectTestWorld,
|
|
11
|
+
type Scene,
|
|
12
|
+
type SceneWorldRef,
|
|
13
|
+
serializeApplyPerDb,
|
|
14
|
+
type TestWorld,
|
|
15
|
+
} from "@spellkave/test-lab";
|
|
16
|
+
|
|
17
|
+
export const localNode = process.env.SPELLKAVE_LOCAL_NODE === "1";
|
|
18
|
+
|
|
19
|
+
export function liveWorldRef(): SceneWorldRef {
|
|
20
|
+
const token = resolveSpacetimeConfigPathToken();
|
|
21
|
+
if (!token) throw new Error("owned node publisher credential required (SPACETIME_CONFIG_PATH)");
|
|
22
|
+
return {
|
|
23
|
+
url: process.env.SPELLKAVE_URL ?? "http://127.0.0.1:3000",
|
|
24
|
+
db: process.env.SPELLKAVE_DB ?? "spellkave-dev",
|
|
25
|
+
token,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let extrasOwner: Promise<TestWorld> | undefined;
|
|
30
|
+
/** One owner-token connection per process (bound to the gatekeeper by the first scene apply). */
|
|
31
|
+
export function ownerConnection(): Promise<TestWorld> {
|
|
32
|
+
const w = liveWorldRef();
|
|
33
|
+
extrasOwner ??= connectTestWorld({ url: w.url, db: w.db, token: w.token });
|
|
34
|
+
return extrasOwner;
|
|
35
|
+
}
|
|
36
|
+
export async function closeExtrasOwner(): Promise<void> {
|
|
37
|
+
if (extrasOwner === undefined) return;
|
|
38
|
+
const owner = await extrasOwner;
|
|
39
|
+
extrasOwner = undefined;
|
|
40
|
+
owner.disconnect();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Apply extra rows to a scene bundle already applied. `rows` is TOML without the header.
|
|
45
|
+
* `dependsOn` must repeat the scene's own `bundleDeps` when the rows name definitions of a bundle
|
|
46
|
+
* other than `core`.
|
|
47
|
+
*/
|
|
48
|
+
export async function applySceneExtras(
|
|
49
|
+
target: Scene,
|
|
50
|
+
rows: string,
|
|
51
|
+
dependsOn: readonly string[] = ["core"],
|
|
52
|
+
): Promise<void> {
|
|
53
|
+
const w = liveWorldRef();
|
|
54
|
+
const owner = await ownerConnection();
|
|
55
|
+
await serializeApplyPerDb(w, () =>
|
|
56
|
+
applyManifestDelta(
|
|
57
|
+
owner,
|
|
58
|
+
`#:schema https://spellkave.dev/schema/world-manifest-1.0.0.json
|
|
59
|
+
schema_version = "1.0.0"
|
|
60
|
+
|
|
61
|
+
[[bundles]]
|
|
62
|
+
bundle_id = "${target.prefix}"
|
|
63
|
+
display_name = "Scene ${target.prefix}"
|
|
64
|
+
author = "spellkave-test"
|
|
65
|
+
version = "1.0.0"
|
|
66
|
+
depends_on = ["${dependsOn.join('", "')}"]
|
|
67
|
+
|
|
68
|
+
${rows}`,
|
|
69
|
+
{ tolerateAlreadyApplied: true, label: `scene ${target.prefix} extras` },
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The `r_session_open` wire of a hero's connection, for the PLAYER `spellkave_session_open` tool
|
|
76
|
+
* under test (`act.callRSessionOpen`). The tool dispatches it; a test never calls it directly,
|
|
77
|
+
* so the step stays inside the tool call that a pattern `act` counts.
|
|
78
|
+
*/
|
|
79
|
+
export function sessionOpenPort(world: TestWorld) {
|
|
80
|
+
return (args: Parameters<TestWorld["conn"]["reducers"]["rSessionOpen"]>[0]) =>
|
|
81
|
+
world.conn.reducers.rSessionOpen(args);
|
|
82
|
+
}
|