@volter/twin-standard 1.0.157 → 1.0.159
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/README.md +3 -2
- package/client-sdks/import.mjs +2 -0
- package/client-sdks/package.json +4 -0
- package/client-sdks/pnpm-lock.yaml +609 -0
- package/dist/client-sdks/import.mjs +2 -0
- package/dist/client-sdks/package.json +4 -0
- package/dist/client-sdks/pnpm-lock.yaml +609 -0
- package/dist/src/assessment.d.ts +13 -3
- package/dist/src/assessment.js +10 -6
- package/dist/src/browser-assessment.js +16 -13
- package/dist/src/clients/harness.d.ts +25 -4
- package/dist/src/clients/harness.js +184 -22
- package/dist/src/clients/jira.js +11 -2
- package/dist/src/clients/run.js +19 -14
- package/dist/src/clients/tinybird.js +15 -6
- package/dist/src/clients/vercel.d.ts +2 -0
- package/dist/src/clients/vercel.js +73 -0
- package/dist/src/conformance.d.ts +2 -0
- package/dist/src/conformance.js +392 -184
- package/dist/src/consumer.d.ts +22 -1
- package/dist/src/consumer.js +91 -26
- package/dist/src/credential-issuer-import.d.ts +3 -0
- package/dist/src/credential-issuer-import.js +42 -0
- package/dist/src/derive.js +3 -0
- package/dist/src/gate.js +4 -0
- package/dist/src/lanes.d.ts +2 -0
- package/dist/src/lanes.js +7 -0
- package/dist/src/protocol-3.js +8 -3
- package/dist/src/spec-documents.d.ts +4 -0
- package/dist/src/spec-documents.js +110 -3
- package/dist/src/tools/life-coverage-walk.js +38 -26
- package/dist/src/tools/score-pack.js +6 -5
- package/dist/src/tools/vendor-examples.js +91 -80
- package/dist/src/walk/behavior-journey.d.ts +22 -14
- package/dist/src/walk/behavior-journey.js +182 -133
- package/dist/src/walk/journey-kit.d.ts +3 -2
- package/dist/src/walk/journey-kit.js +6 -2
- package/dist/src/walk/replay.d.ts +23 -0
- package/dist/src/walk/replay.js +118 -0
- package/dist/src/walk/serve-pack.d.ts +2 -2
- package/dist/src/walk/serve-pack.js +38 -2
- package/dist/src/walk/shape.d.ts +25 -4
- package/dist/src/walk/shape.js +166 -56
- package/dist/src/walk/vendor-fetch.d.ts +7 -2
- package/dist/src/walk/vendor-fetch.js +13 -2
- package/dist/src/walk/walk-database.d.ts +9 -1
- package/dist/src/walk/walk-database.js +35 -13
- package/dist/src/walk/xml-view.d.ts +3 -2
- package/dist/src/walk/xml-view.js +5 -4
- package/package.json +4 -3
- package/src/assessment.ts +12 -8
- package/src/browser-assessment.ts +12 -5
- package/src/clients/harness.ts +142 -19
- package/src/clients/jira.ts +4 -2
- package/src/clients/run.ts +17 -15
- package/src/clients/tinybird.ts +8 -6
- package/src/clients/vercel.ts +67 -0
- package/src/conformance.ts +313 -128
- package/src/consumer.ts +83 -21
- package/src/credential-issuer-import.ts +38 -0
- package/src/derive.ts +3 -1
- package/src/gate.ts +3 -0
- package/src/lanes.ts +7 -0
- package/src/protocol-3.ts +7 -3
- package/src/spec-documents.ts +92 -3
- package/src/tools/life-coverage-walk.ts +32 -22
- package/src/tools/score-pack.ts +7 -6
- package/src/tools/vendor-examples.ts +88 -75
- package/src/walk/behavior-journey.ts +145 -109
- package/src/walk/journey-kit.ts +7 -5
- package/src/walk/replay.ts +103 -0
- package/src/walk/serve-pack.ts +25 -5
- package/src/walk/shape.ts +156 -54
- package/src/walk/vendor-fetch.ts +16 -4
- package/src/walk/walk-database.ts +41 -15
- package/src/walk/xml-view.ts +5 -4
package/dist/src/conformance.js
CHANGED
|
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
6
6
|
}
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
|
-
import { hasOwnSurface } from "./lanes.js";
|
|
9
|
+
import { hasOwnSurface, unitsIn } from "./lanes.js";
|
|
10
10
|
// CONFORMANCE — the deterministic half of the Protocol 3 standard that executes the pack: the contract it serves, run the
|
|
11
11
|
// way an application calls it, and every rule a pack's author follows that a machine can decide (docs/contributing/
|
|
12
12
|
// architecture.md, "Conformance"). One command, the same for a contributor, the catalog's admission and its regular
|
|
@@ -19,24 +19,50 @@ import { hasOwnSurface } from "./lanes.js";
|
|
|
19
19
|
// judges (the life's plausibility) is the proof section's. Each check names the defect it was written against: one
|
|
20
20
|
// that escaped review once fails here when reintroduced.
|
|
21
21
|
import { spawn, spawnSync } from 'node:child_process';
|
|
22
|
-
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
22
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
23
23
|
import { createRequire } from 'node:module';
|
|
24
24
|
import { connect } from 'node:net';
|
|
25
25
|
import { tmpdir } from 'node:os';
|
|
26
26
|
import { basename, dirname, extname, join, matchesGlob, relative, resolve, sep } from 'node:path';
|
|
27
27
|
// A path relative to another with '/' between its parts on every platform (Windows' relative() joins with '\').
|
|
28
28
|
const rel = (from, to) => relative(from, to).split(sep).join('/');
|
|
29
|
+
import { hostRules } from '@volter/world-core/host-routing';
|
|
30
|
+
import { twinEnvStem } from '@volter/world-core/vendor-hosts';
|
|
29
31
|
import { citations, sourceHeld } from "./check-sources.js";
|
|
30
32
|
import { fileURLToPath } from 'node:url';
|
|
31
|
-
import {
|
|
33
|
+
import { parseEnv } from 'node:util';
|
|
34
|
+
import { openWebSocket, readHttpResponse, servedHttpFetch, worldProxy } from "./clients/harness.js";
|
|
32
35
|
import { servePack as serve } from "./walk/serve-pack.js";
|
|
36
|
+
import { walkPackDirectory } from "./walk/pack-directory.js";
|
|
37
|
+
import { formBody, sigv4Headers } from "./walk/journey-kit.js";
|
|
38
|
+
import { consumerClientProof, consumerRecipe, runConsumerCommand } from "./consumer.js";
|
|
39
|
+
import { declaredResponseStatuses } from "./spec-documents.js";
|
|
33
40
|
const pascal = (s) => s.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join('');
|
|
34
41
|
const readJson = (p) => (existsSync(p) ? JSON.parse(readFileSync(p, 'utf8')) : undefined);
|
|
35
|
-
/**
|
|
36
|
-
function
|
|
37
|
-
return
|
|
42
|
+
/** Exercise the door's declared organization and deployment, as the World renderer does. */
|
|
43
|
+
function credentialDoorBody(door) {
|
|
44
|
+
return JSON.stringify({ ...door.body, ...(door.account ? { [door.account.field]: 'default' } : {}), ...(door.deployment ? { [door.deployment.field]: 'conformance' } : {}) });
|
|
38
45
|
}
|
|
39
46
|
const nameOf = (pack, unit) => rel(resolve(pack, '..'), unit);
|
|
47
|
+
/** A credential door's native successful object and nonempty string outputs, through the served HTTP owner. */
|
|
48
|
+
async function credentialFields(server, door, host) {
|
|
49
|
+
await server.managedDatabaseUrl?.();
|
|
50
|
+
const port = server.inspectPort ?? server.port;
|
|
51
|
+
const answer = await readHttpResponse(servedHttpFetch(port), new Request(`http://${host ?? `127.0.0.1:${port}`}${door.path}`, {
|
|
52
|
+
method: 'POST', headers: { 'content-type': 'application/json', 'x-volter-world-activity': 'provisioning' }, body: credentialDoorBody(door),
|
|
53
|
+
}));
|
|
54
|
+
if (answer.bodyError)
|
|
55
|
+
throw new Error(`credential door ${door.path}: ${answer.bodyError.message}`);
|
|
56
|
+
if (answer.status < 200 || answer.status >= 300)
|
|
57
|
+
throw new Error(`credential door ${door.path} answered ${answer.status}`);
|
|
58
|
+
const { decodeResponse } = await import("./walk/shape.js");
|
|
59
|
+
const values = decodeResponse(answer.text, undefined);
|
|
60
|
+
if (!values || typeof values !== 'object' || Array.isArray(values))
|
|
61
|
+
throw new Error(`credential door ${door.path} supplies no JSON object`);
|
|
62
|
+
const fields = values;
|
|
63
|
+
const outputs = Object.fromEntries(Object.entries(door.fill).flatMap(([name, field]) => typeof fields[field] === 'string' && fields[field] ? [[name, fields[field]]] : []));
|
|
64
|
+
return { values: fields, outputs };
|
|
65
|
+
}
|
|
40
66
|
/** The files conformance reads from a unit: its manifest, its spec's record, its vendor's life and its decision table
|
|
41
67
|
* (a lane's journeys are its own `journeys/` or else its vendor's). A release publishes each (published()), and a
|
|
42
68
|
* pack's standing counts it in the form only when every unit holds them (twin-world's scripts/pack-standing.ts, by
|
|
@@ -308,7 +334,6 @@ async function allowance(pack, runtime) {
|
|
|
308
334
|
}
|
|
309
335
|
return out;
|
|
310
336
|
}
|
|
311
|
-
const within = (ms, p) => Promise.race([p, new Promise((r) => setTimeout(() => r('timeout'), ms))]);
|
|
312
337
|
/** Served by its server.ts as a World runs it (its boot id set), the pack answers HTTP and the boot probe, and every socket
|
|
313
338
|
* its manifests declare takes an upgrade. Escaped twice: serveHttp never took the upgrade a pack's fetch carries, then
|
|
314
339
|
* read it off the boot probe's wrapper of the fetch, so OpenAI Realtime's /v1/realtime answered 404, first everywhere
|
|
@@ -320,35 +345,33 @@ async function standalone(pack) {
|
|
|
320
345
|
for (const s of (await manifestOf(unit)).sockets ?? [])
|
|
321
346
|
sockets.push({ unit: nameOf(pack, unit), path: s.path, ...(s.host ? { host: s.host } : {}) });
|
|
322
347
|
// served the way a World runs it: the boot id set, so the seam wraps the fetch with the World's boot probe
|
|
323
|
-
const
|
|
324
|
-
const before = env.VOLTER_WORLD_BOOT_ID;
|
|
325
|
-
env.VOLTER_WORLD_BOOT_ID = 'conformance';
|
|
326
|
-
let server;
|
|
327
|
-
try {
|
|
328
|
-
server = await serve(pack, {});
|
|
329
|
-
}
|
|
330
|
-
finally {
|
|
331
|
-
if (before === undefined)
|
|
332
|
-
delete env.VOLTER_WORLD_BOOT_ID;
|
|
333
|
-
else
|
|
334
|
-
env.VOLTER_WORLD_BOOT_ID = before;
|
|
335
|
-
}
|
|
348
|
+
const server = await serve(pack, {});
|
|
336
349
|
try {
|
|
337
|
-
const http =
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
350
|
+
const http = servedHttpFetch(server.inspectPort ?? server.port);
|
|
351
|
+
const probe = (path) => readHttpResponse(http, new Request(`http://127.0.0.1:${server.inspectPort ?? server.port}${path}`, { signal: AbortSignal.timeout(5000) }));
|
|
352
|
+
try {
|
|
353
|
+
const answer = await probe('/');
|
|
354
|
+
if (answer.bodyError)
|
|
355
|
+
out.push(`served as a World runs it, its HTTP response failed (${answer.bodyError.message})`);
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
out.push(`served as a World runs it, it answers no HTTP request (${String(error)})`);
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const boot = await probe('/__volter/world-boot');
|
|
362
|
+
if (boot.bodyError || JSON.parse(boot.text).boot !== 'conformance')
|
|
363
|
+
throw new Error('missing boot identity');
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
342
366
|
out.push("served as a World runs it, it does not answer the World's boot probe (/__volter/world-boot)");
|
|
367
|
+
}
|
|
343
368
|
for (const s of sockets) {
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
const timer = setTimeout(() => { ws.close(); done('no upgrade in 5 s'); }, 5000);
|
|
347
|
-
ws.onopen = () => { clearTimeout(timer); ws.close(); done(undefined); };
|
|
348
|
-
ws.onerror = () => { clearTimeout(timer); done('the upgrade was refused'); };
|
|
349
|
-
});
|
|
369
|
+
const ws = new WebSocket(`ws://127.0.0.1:${server.port}${s.path}`, { headers: s.host ? { host: s.host } : {} });
|
|
370
|
+
const upgraded = await openWebSocket(ws);
|
|
350
371
|
if (upgraded)
|
|
351
|
-
|
|
372
|
+
ws.close();
|
|
373
|
+
else
|
|
374
|
+
out.push(`${s.unit}: the socket at ${s.host ?? ''}${s.path}: no upgrade in 5 s or the upgrade was refused`);
|
|
352
375
|
}
|
|
353
376
|
}
|
|
354
377
|
finally {
|
|
@@ -382,163 +405,392 @@ function sweepRequest(op, basePath, host, credential) {
|
|
|
382
405
|
headers.set('content-type', 'application/xml');
|
|
383
406
|
body = '';
|
|
384
407
|
}
|
|
385
|
-
else if (op.bodyEncoding === 'json'
|
|
408
|
+
else if (op.bodyEncoding === 'json') {
|
|
386
409
|
headers.set('content-type', 'application/json');
|
|
387
410
|
body = '{}';
|
|
388
411
|
}
|
|
412
|
+
else if (op.bodyEncoding === 'multipart') {
|
|
413
|
+
const formed = formBody({ parts: [] }, {});
|
|
414
|
+
headers.set('content-type', formed.contentType);
|
|
415
|
+
body = formed.bytes;
|
|
416
|
+
}
|
|
389
417
|
return new Request(url, { method, headers, ...(body !== undefined && !['GET', 'HEAD'].includes(method) ? { body } : {}) });
|
|
390
418
|
}
|
|
419
|
+
/** Obtain authorization through the existing customer recipe, with any declared issuer on the same World as the API. */
|
|
420
|
+
async function consumerAuthorization(pack, scratch, root, server, descriptor, outputs, claimsAuthorization, consumer) {
|
|
421
|
+
const vendor = (await manifestOf(pack)).vendor ?? basename(pack);
|
|
422
|
+
const issuer = descriptor.credentialIssuer;
|
|
423
|
+
const companion = issuer ? walkPackDirectory(dirname(pack), issuer, pack) : undefined;
|
|
424
|
+
if (issuer && !companion)
|
|
425
|
+
throw new Error(`${vendor}: its declared credential issuer ${issuer} is not installed`);
|
|
426
|
+
const issuerDoor = companion ? (await manifestOf(companion)).descriptor?.credentialDoor : undefined;
|
|
427
|
+
if (companion && !issuerDoor)
|
|
428
|
+
throw new Error(`${issuer}: its declared credential door is missing`);
|
|
429
|
+
const recipe = consumerRecipe(vendor, pack);
|
|
430
|
+
if (!consumer)
|
|
431
|
+
throw new Error(`${vendor}: native authorization requires its prepared installed customer application`);
|
|
432
|
+
mkdirSync(scratch, { recursive: true });
|
|
433
|
+
const appDir = consumer.appDir;
|
|
434
|
+
for (const [path, contents] of Object.entries(recipe.files))
|
|
435
|
+
if (path !== 'package.json' && path !== '.gitignore' && readFileSync(join(appDir, path), 'utf8') !== contents)
|
|
436
|
+
throw new Error(`${vendor}: its prepared customer file ${path} differs from its native first-use recipe`);
|
|
437
|
+
const proxies = [];
|
|
438
|
+
let servedIssuer;
|
|
439
|
+
let granted;
|
|
440
|
+
const { forwardableHeaders } = await import('@volter/world-runtime');
|
|
441
|
+
try {
|
|
442
|
+
const env = { ...outputs };
|
|
443
|
+
if (companion && issuerDoor) {
|
|
444
|
+
servedIssuer = await serve(companion, { root });
|
|
445
|
+
Object.assign(env, (await credentialFields(servedIssuer, issuerDoor)).outputs);
|
|
446
|
+
}
|
|
447
|
+
const credentialNames = new Set([...Object.keys(descriptor.credentialDoor?.fill ?? {}), ...Object.keys(issuerDoor?.fill ?? {})]);
|
|
448
|
+
for (const name of Object.keys(parseEnv(recipe.files['.env.example'])))
|
|
449
|
+
if (credentialNames.has(name) && !env[name])
|
|
450
|
+
throw new Error(`${vendor}: its native credential doors supplied no ${name}`);
|
|
451
|
+
const selectedProxy = await worldProxy(server.inspectPort ?? server.port, (request, response) => {
|
|
452
|
+
const url = new URL(request.url);
|
|
453
|
+
if (response.status >= 200 && response.status < 300 && !url.pathname.startsWith('/_twin/') && claimsAuthorization(url.hostname, url.pathname)) {
|
|
454
|
+
const headers = forwardableHeaders(request.headers);
|
|
455
|
+
for (const name of [...headers.keys()])
|
|
456
|
+
if (/^(host|forwarded|x-forwarded-.*|x-volter-.*|x-twins-key|proxy-.*|via|content-.*|digest)$/i.test(name))
|
|
457
|
+
headers.delete(name);
|
|
458
|
+
granted = { headers: Object.fromEntries(headers), url };
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
proxies.push(selectedProxy);
|
|
462
|
+
const selected = [{ vendor, dir: pack, port: selectedProxy.port }];
|
|
463
|
+
if (issuer && companion && servedIssuer) {
|
|
464
|
+
const issuerProxy = await worldProxy(servedIssuer.inspectPort ?? servedIssuer.port);
|
|
465
|
+
proxies.push(issuerProxy);
|
|
466
|
+
selected.push({ vendor: issuer, dir: companion, port: issuerProxy.port });
|
|
467
|
+
}
|
|
468
|
+
const { compilePackFacts, renderPackFacts } = await import("./pack-facts.js");
|
|
469
|
+
const facts = await compilePackFacts(selected.map(({ vendor, dir }) => ({ vendor, dir })));
|
|
470
|
+
if (facts.undeclared.length)
|
|
471
|
+
throw new Error('Customer authorization requires declared pack descriptors');
|
|
472
|
+
const packFacts = join(scratch, 'pack-facts.json');
|
|
473
|
+
writeFileSync(packFacts, renderPackFacts(facts));
|
|
474
|
+
const instance = join(scratch, 'instance.json');
|
|
475
|
+
writeFileSync(instance, JSON.stringify({ packFacts: [packFacts] }));
|
|
476
|
+
const routes = Object.fromEntries(selected.flatMap(({ vendor, port }) => (facts.packs[vendor]?.hosts ?? []).map((rule) => [rule.key ?? vendor, `http://127.0.0.1:${port}`])));
|
|
477
|
+
const endpoints = Object.fromEntries(Object.entries(routes).map(([key, url]) => [`${twinEnvStem(key)}_TWIN_URL`, url]));
|
|
478
|
+
const require = createRequire(join(pack, 'package.json'));
|
|
479
|
+
const inject = require.resolve('@volter/world-core/inject');
|
|
480
|
+
const result = await runConsumerCommand(recipe.run, appDir, {
|
|
481
|
+
...process.env, ...endpoints, ...env, VOLTER_WORLD_INSTANCE: instance,
|
|
482
|
+
TWIN_INJECT: Object.entries(routes).map(([name, url]) => `${name}=${url}`).join(','),
|
|
483
|
+
NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ''} --require ${JSON.stringify(inject)}`.trim(),
|
|
484
|
+
VOLTER_TWIN_STRICT_EGRESS: '1',
|
|
485
|
+
}, AbortSignal.timeout(10_000));
|
|
486
|
+
if (result.exitCode !== 0)
|
|
487
|
+
throw new Error(`${vendor}: its native first-use command exited ${result.exitCode}`);
|
|
488
|
+
if (!granted)
|
|
489
|
+
throw new Error(`${vendor}: its native first-use command made no successful authorized request to the selected API`);
|
|
490
|
+
return granted;
|
|
491
|
+
}
|
|
492
|
+
finally {
|
|
493
|
+
const cleanup = await Promise.allSettled([...proxies.map((proxy) => proxy.stop()), ...(servedIssuer ? [Promise.resolve().then(() => servedIssuer.stop())] : [])]);
|
|
494
|
+
const failed = cleanup.find((result) => result.status === 'rejected');
|
|
495
|
+
if (failed?.status === 'rejected')
|
|
496
|
+
throw failed.reason;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
391
499
|
/** Every operation the pack serves, called over HTTP as an application calls it, against its server.ts served as a World
|
|
392
500
|
* runs it: once plainly and once with a scenario loaded (an empty one, as a World that scripts nothing loads it). Each
|
|
393
501
|
* answers within 10 s, never with a 500 the spec does not declare, never with a field of the twin's own (`_`
|
|
394
502
|
* bookkeeping, the kernel's `updatedAt`) and, answered successfully, in the shape the spec gives the operation; and every
|
|
395
|
-
* refresh list a fresh account can read (one with no parameter in its path)
|
|
396
|
-
*
|
|
503
|
+
* refresh list a fresh account can read (one with no parameter in its path) succeeds or remains unread under the
|
|
504
|
+
* native 403 contract while another read succeeds, or matches the pack's own removal at the World clock.
|
|
505
|
+
* Escaped before: the scenario hang (a served pack given a scenario answered
|
|
397
506
|
* nothing), leaked kernel fields in answers no life step read, and refresh scopes on operations the pack answered with
|
|
398
507
|
* the gap. The life walks what a customer does; this calls what the pack declares it serves. */
|
|
399
|
-
async function surfaceSwept(pack, scratch) {
|
|
508
|
+
async function surfaceSwept(pack, scratch, runtime, consumer) {
|
|
400
509
|
const out = [];
|
|
401
510
|
const descriptor = (await manifestOf(pack)).descriptor;
|
|
402
511
|
const fetchOf = (await import(__rewriteRelativeImportExtension(join(pack, 'src', 'fetch.ts'))))[fetchName(pack)];
|
|
403
512
|
const root = fetchOf?.();
|
|
404
513
|
const byUnit = root?.ownersByUnit?.() ?? { '': root?.owners?.() ?? {} };
|
|
405
|
-
const { shapeChecker } = await import("./walk/shape.js");
|
|
406
|
-
const { leaked } = await import("./walk/behavior-journey.js");
|
|
514
|
+
const { decodeResponse, responseProblems, shapeChecker, vendorFieldsOf } = await import("./walk/shape.js");
|
|
407
515
|
const shape = await shapeChecker(pack);
|
|
408
516
|
const units = [];
|
|
409
|
-
const vendorFields =
|
|
517
|
+
const vendorFields = await vendorFieldsOf(pack);
|
|
410
518
|
for (const unit of unitsIn(pack).filter(hasOwnSurface)) {
|
|
411
519
|
const surface = readJson(join(unit, 'src', 'generated', 'surface.gen.json'));
|
|
412
|
-
|
|
413
|
-
for (const f of r.fields)
|
|
414
|
-
vendorFields.add(f.name);
|
|
520
|
+
const m = (await manifestOf(unit));
|
|
415
521
|
// a line protocol and a command table ride in no path of their own: the life's line steps and the examples read them
|
|
416
522
|
if (!surface?.operations || ['command-reply', 'command-table'].includes(String(surface.format)))
|
|
417
523
|
continue;
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
out.push(`${nameOf(pack, unit)}: no host is named (its manifest's hosts or the descriptor's) for an application to call it at`);
|
|
524
|
+
const hosts = m.hosts ?? m.descriptor?.hosts ?? descriptor?.hosts ?? [];
|
|
525
|
+
if (!hosts.length) {
|
|
526
|
+
out.push(`${nameOf(pack, unit)}: no host is claimed (its manifest's hosts or the descriptor's) for an application to call it at`);
|
|
422
527
|
continue;
|
|
423
528
|
}
|
|
424
529
|
const owners = byUnit[unit === pack ? '' : basename(unit)] ?? {};
|
|
425
530
|
const refreshLists = Object.entries(m.resources ?? {}).flatMap(([resource, decl]) => (decl.refresh?.list ? [{ resource, id: decl.refresh.list }] : []));
|
|
426
|
-
|
|
531
|
+
const refreshReads = Object.values(m.resources ?? {}).flatMap((decl) => [decl.refresh?.list, decl.refresh?.get, decl.refresh?.detail].filter((id) => !!id));
|
|
532
|
+
const declaredAuth = m.descriptor?.auth ?? descriptor?.auth;
|
|
533
|
+
const strategy = declaredAuth?.in === 'lanes' ? declaredAuth.lanes[unit === pack ? '' : basename(unit)] : declaredAuth;
|
|
534
|
+
const shared = join(unit, 'src/semantics/shared.ts');
|
|
535
|
+
const removedAt = existsSync(shared) ? (await import(__rewriteRelativeImportExtension(shared))).removedAt : undefined;
|
|
536
|
+
units.push({ name: nameOf(pack, unit), lane: unit === pack ? '' : basename(unit), hosts, basePath: surface.basePath ?? '', manifest: m, ops: surface.operations.filter((o) => owners[o.id] !== undefined && owners[o.id] !== 'gap'), responseStatuses: declaredResponseStatuses(join(unit, 'spec')), refreshLists, refreshReads, ...(m.auth ? { auth: m.auth } : {}), ...(strategy ? { strategy } : {}), ...(typeof removedAt === 'function' ? { removedAt } : {}) });
|
|
427
537
|
}
|
|
428
538
|
if (!units.length)
|
|
429
539
|
return { failures: out, note: 'no unit serves an operation on a path of its own' };
|
|
430
|
-
const tally = { calls: 0, ok: 0, refused: 0 };
|
|
431
|
-
const
|
|
540
|
+
const tally = { calls: 0, ok: 0, refused: 0, unread: 0, removed: 0 };
|
|
541
|
+
const replayedHeaders = new Set();
|
|
432
542
|
const scenarioPath = join(scratch, 'surface-scenario.json');
|
|
433
543
|
writeFileSync(scenarioPath, '{"handlers":[]}');
|
|
434
544
|
for (const mode of ['plain', 'scenario']) {
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
let server;
|
|
438
|
-
try {
|
|
439
|
-
server = await serve(pack, { root: join(scratch, `surface-${mode}`), ...(mode === 'scenario' ? { scenarioPath } : {}) });
|
|
440
|
-
}
|
|
441
|
-
finally {
|
|
442
|
-
if (before === undefined)
|
|
443
|
-
delete env.VOLTER_WORLD_BOOT_ID;
|
|
444
|
-
else
|
|
445
|
-
env.VOLTER_WORLD_BOOT_ID = before;
|
|
446
|
-
}
|
|
545
|
+
const root = join(scratch, `surface-${mode}`);
|
|
546
|
+
const server = await serve(pack, { root, ...(mode === 'scenario' ? { scenarioPath } : {}) });
|
|
447
547
|
const http = servedHttpFetch(server.inspectPort ?? server.port);
|
|
448
548
|
const send = async (request) => {
|
|
449
549
|
await server.managedDatabaseUrl?.();
|
|
450
|
-
const abort = new AbortController();
|
|
451
550
|
try {
|
|
452
|
-
return await
|
|
551
|
+
return await readHttpResponse(http, request);
|
|
453
552
|
}
|
|
454
553
|
catch (error) {
|
|
455
|
-
return error;
|
|
456
|
-
}
|
|
457
|
-
finally {
|
|
458
|
-
abort.abort();
|
|
554
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
459
555
|
}
|
|
460
556
|
};
|
|
461
557
|
try {
|
|
558
|
+
const said = mode === 'scenario' ? ' with a scenario loaded' : '';
|
|
462
559
|
// the account an application holds: the key the credential door issues, sent as the vendor reads its credential
|
|
463
560
|
let issued;
|
|
561
|
+
let nativeHeaders;
|
|
562
|
+
let recipeAuthorized = false;
|
|
563
|
+
let nativeUrl;
|
|
564
|
+
const outputs = {};
|
|
464
565
|
if (descriptor?.credentialDoor) {
|
|
465
566
|
const door = descriptor.credentialDoor;
|
|
466
|
-
const
|
|
467
|
-
const
|
|
468
|
-
|
|
567
|
+
const fields = await credentialFields(server, door);
|
|
568
|
+
const values = fields.values;
|
|
569
|
+
Object.assign(outputs, fields.outputs);
|
|
570
|
+
issued = Object.values(door.fill).map((f) => values[f]).find((v) => typeof v === 'string' && v.length > 0);
|
|
571
|
+
if (typeof values.authorization === 'string' && values.authorization) {
|
|
572
|
+
nativeHeaders = { authorization: values.authorization };
|
|
573
|
+
if (typeof values.url === 'string') {
|
|
574
|
+
try {
|
|
575
|
+
nativeUrl = new URL(values.url);
|
|
576
|
+
}
|
|
577
|
+
catch {
|
|
578
|
+
out.push(`${nameOf(pack, pack)}: credential door supplies an invalid native url`);
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
if (nativeUrl.protocol !== 'https:' || nativeUrl.username || nativeUrl.password) {
|
|
582
|
+
out.push(`${nameOf(pack, pack)}: credential door supplies a native url without a vendor HTTPS origin`);
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
const headerUnits = units.filter((unit) => !unit.strategy);
|
|
589
|
+
const ambiguousHeaderCredential = !nativeHeaders && new Set(Object.values(outputs)).size > 1 && headerUnits.length > 0
|
|
590
|
+
&& Object.keys(parseEnv(consumerRecipe((await manifestOf(pack)).vendor ?? basename(pack), pack).files['.env.example'])).some((name) => outputs[name]);
|
|
591
|
+
if (descriptor && (descriptor.credentialIssuer || ambiguousHeaderCredential)) {
|
|
592
|
+
const headerClaims = headerUnits.map((unit) => hostRules(unit.hosts));
|
|
593
|
+
const otherClaims = units.filter((unit) => unit.strategy).map((unit) => hostRules(unit.hosts));
|
|
594
|
+
const claimsAuthorization = descriptor.credentialIssuer ? hostRules(descriptor.hosts ?? []).takes
|
|
595
|
+
: (host, path) => headerClaims.some((claims) => claims.takes(host, path)) && !otherClaims.some((claims) => claims.takes(host, path));
|
|
596
|
+
const granted = await consumerAuthorization(pack, join(scratch, `authorization-${mode}`), root, server, descriptor, outputs, claimsAuthorization, consumer);
|
|
597
|
+
nativeHeaders = granted.headers;
|
|
598
|
+
recipeAuthorized = true;
|
|
599
|
+
for (const name of Object.keys(nativeHeaders))
|
|
600
|
+
replayedHeaders.add(name);
|
|
601
|
+
nativeUrl = granted.url;
|
|
602
|
+
issued = undefined;
|
|
603
|
+
}
|
|
604
|
+
const endpoints = Object.values(outputs).flatMap((value) => {
|
|
605
|
+
try {
|
|
606
|
+
const url = new URL(value);
|
|
607
|
+
return url.protocol === 'https:' && !url.username && !url.password ? [url] : [];
|
|
608
|
+
}
|
|
609
|
+
catch {
|
|
610
|
+
return [];
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
const claimsNativeUrl = (u) => {
|
|
614
|
+
return nativeUrl !== undefined && hostRules(u.hosts).takes(nativeUrl.hostname, nativeUrl.pathname);
|
|
615
|
+
};
|
|
616
|
+
if (nativeUrl && !units.some(claimsNativeUrl)) {
|
|
617
|
+
out.push(`${units.map((u) => u.name).join(', ')}: credential door native url ${nativeUrl.origin} matches no selected unit's declared host rules${said}`);
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
const hostCandidates = (u) => {
|
|
621
|
+
const claims = hostRules(u.hosts);
|
|
622
|
+
const remote = u.manifest.remoteHost;
|
|
623
|
+
const remoteHost = remote?.template.replace(/\{([^}]+)\}/g, (_match, name) => Object.values(remote.values?.[name] ?? {})[0] ?? 'conformance');
|
|
624
|
+
if (remoteHost && !claims.names(new URL(`https://${remoteHost}`).hostname))
|
|
625
|
+
throw new Error(`${u.name}: its remote host ${remoteHost} matches none of its declared host rules`);
|
|
626
|
+
return [...new Set([
|
|
627
|
+
...(nativeUrl && claimsNativeUrl(u) ? [nativeUrl.host] : []),
|
|
628
|
+
...endpoints.map((url) => url.host),
|
|
629
|
+
...(remoteHost ? [remoteHost] : []),
|
|
630
|
+
...u.hosts.flatMap((rule) => 'host' in rule && rule.exclude !== true ? [rule.host] : []),
|
|
631
|
+
])];
|
|
632
|
+
};
|
|
633
|
+
const answers = new Map(units.map((u) => [u, new Map()]));
|
|
634
|
+
const removed = new Set();
|
|
635
|
+
const callOperation = async (u, op, request) => {
|
|
636
|
+
const now = Date.parse(runtime.worldNow());
|
|
637
|
+
const signing = u.strategy?.in === 'signature' && u.strategy.algorithm === 'aws-sigv4' ? u.strategy : undefined;
|
|
638
|
+
if (signing) {
|
|
639
|
+
const keyPart = (suffix) => {
|
|
640
|
+
const values = [...new Set(Object.entries(outputs).filter(([name]) => name === suffix || name.endsWith(`_${suffix}`)).map(([, value]) => value))];
|
|
641
|
+
return values.length === 1 && values[0] ? values[0] : undefined;
|
|
642
|
+
};
|
|
643
|
+
const accessKeyId = keyPart('ACCESS_KEY_ID');
|
|
644
|
+
const secretAccessKey = keyPart('SECRET_ACCESS_KEY');
|
|
645
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
646
|
+
out.push(`${u.name}: its SigV4 credential door supplies no unambiguous access-key-id and secret-access-key pair${said}`);
|
|
647
|
+
return undefined;
|
|
648
|
+
}
|
|
649
|
+
const url = new URL(request.url);
|
|
650
|
+
const headers = Object.fromEntries(request.headers);
|
|
651
|
+
const body = request.body === null ? undefined : await request.clone().text();
|
|
652
|
+
const scope = typeof signing.scope === 'function' ? signing.scope({ method: request.method, path: url.pathname + url.search, host: url.host, headers, ...(body === undefined ? {} : { body }) }) : signing.scope;
|
|
653
|
+
const signed = sigv4Headers({ accessKeyId, secretAccessKey, ...scope }, {}, request.method, request.url, headers, body, now);
|
|
654
|
+
request = new Request(request, { headers: { ...headers, ...signed } });
|
|
655
|
+
}
|
|
656
|
+
const where = `${u.name}: ${op?.id ?? 'GraphQL refresh'} (${request.method} ${new URL(request.url).pathname})`;
|
|
657
|
+
const graphqlBody = request.method === 'POST' && u.manifest.graphql?.paths.includes(new URL(request.url).pathname)
|
|
658
|
+
? await request.clone().json().catch(() => undefined) : undefined;
|
|
659
|
+
const res = await send(request);
|
|
660
|
+
if (res instanceof Error) {
|
|
661
|
+
out.push(`${where}: the connection failed${said} (${res.message})`);
|
|
662
|
+
return undefined;
|
|
663
|
+
}
|
|
664
|
+
if (op)
|
|
665
|
+
answers.get(u).set(op.id, res.status);
|
|
666
|
+
if (mode === 'plain') {
|
|
667
|
+
tally.calls++;
|
|
668
|
+
if (res.status < 300)
|
|
669
|
+
tally.ok++;
|
|
670
|
+
else
|
|
671
|
+
tally.refused++;
|
|
672
|
+
}
|
|
673
|
+
if (res.bodyError) {
|
|
674
|
+
out.push(`${where}: response body failed${said} (${res.bodyError.message})`);
|
|
675
|
+
return undefined;
|
|
676
|
+
}
|
|
677
|
+
const text = res.text;
|
|
678
|
+
const response = { status: res.status, headers: res.headers, body: text, bodyBytes: res.bodyBytes };
|
|
679
|
+
const removal = op ? u.removedAt?.(op.id, Math.floor(now / 1000)) : undefined;
|
|
680
|
+
if (removal) {
|
|
681
|
+
const expected = runtime.vendorError(u.manifest, removal);
|
|
682
|
+
if (res.status === expected.status && text === await expected.text())
|
|
683
|
+
removed.add(`${u.name}:${op.id}`);
|
|
684
|
+
else
|
|
685
|
+
out.push(`${where} does not match its declared native removal at ${new Date(now).toISOString()}${said}: expected ${removal.status} and its exact native body, received ${res.status}: ${text.slice(0, 160)}`);
|
|
686
|
+
}
|
|
687
|
+
const statuses = op ? u.responseStatuses.get(op.id) : undefined;
|
|
688
|
+
if (res.status === 500 && !statuses?.has('500') && !statuses?.has('5XX') && !statuses?.has('default'))
|
|
689
|
+
out.push(`${where} answered 500${said}, which the spec does not declare: ${text.slice(0, 160)}`);
|
|
690
|
+
const type = res.headers['content-type'];
|
|
691
|
+
const judged = responseProblems(shape, vendorFields, { method: request.method, path: request.url, requestHeaders: Object.fromEntries(request.headers), graphqlBody,
|
|
692
|
+
status: res.status, mediaType: type, body: decodeResponse(text, type), text });
|
|
693
|
+
for (const key of judged.leaks)
|
|
694
|
+
out.push(`${where} answers the twin's own field ${key}${said}`);
|
|
695
|
+
for (const detail of judged.shape)
|
|
696
|
+
out.push(`${where}: ${detail}${said}`);
|
|
697
|
+
return response;
|
|
698
|
+
};
|
|
699
|
+
const refreshed = new Set();
|
|
700
|
+
const nativeRefreshOwnsReads = recipeAuthorized && nativeHeaders !== undefined && units.some((unit) => unit.refreshReads.length > 0);
|
|
701
|
+
if (nativeRefreshOwnsReads) {
|
|
702
|
+
const vendor = (await manifestOf(pack)).vendor ?? basename(pack);
|
|
703
|
+
const refresh = runtime.getPack(vendor)?.stateSystem?.refresh;
|
|
704
|
+
if (!refresh)
|
|
705
|
+
throw new Error(`${vendor}: its registered native refresh adapter is missing`);
|
|
706
|
+
try {
|
|
707
|
+
await refresh(async (call) => {
|
|
708
|
+
const u = units.find((unit) => unit.lane === (call.lane ?? ''));
|
|
709
|
+
if (!u)
|
|
710
|
+
throw new Error(`${vendor}: its native refresh names no selected unit`);
|
|
711
|
+
const url = hostCandidates(u).map((host) => new URL(call.path, `https://${host}`)).find((candidate) => hostRules(u.hosts).takes(candidate.hostname, candidate.pathname));
|
|
712
|
+
if (!url)
|
|
713
|
+
throw new Error(`${u.name}: its native refresh request matches no declared host`);
|
|
714
|
+
const headers = { ...call.headers, ...(claimsNativeUrl(u) ? nativeHeaders : {}) };
|
|
715
|
+
const request = new Request(url, { method: call.method, headers, ...(call.body === undefined ? {} : { body: call.body }) });
|
|
716
|
+
const operation = shape?.operationOf(call.method, url.href, Object.fromEntries(request.headers));
|
|
717
|
+
const op = (operation?.lane ?? '') === u.lane ? u.ops.find((candidate) => candidate.id === operation?.op.id) : undefined;
|
|
718
|
+
const graphql = call.method.toUpperCase() === 'POST' && u.manifest.graphql?.paths.includes(url.pathname);
|
|
719
|
+
if (!op && !graphql)
|
|
720
|
+
throw new Error(`${u.name}: its native refresh matches no served operation or declared GraphQL endpoint`);
|
|
721
|
+
if (op)
|
|
722
|
+
refreshed.add(`${u.name}:${op.id}`);
|
|
723
|
+
const response = await callOperation(u, op, request);
|
|
724
|
+
if (!response)
|
|
725
|
+
throw new Error(`${u.name}: its native refresh request failed`);
|
|
726
|
+
return response;
|
|
727
|
+
}, { root });
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
731
|
+
const secrets = Object.values(nativeHeaders).flatMap((value) => [value, value.split(/\s+/).slice(1).join(' ')]).filter(Boolean);
|
|
732
|
+
out.push(`${vendor}: its native refresh adapter failed${said}: ${secrets.reduce((message, secret) => message.replaceAll(secret, '[redacted]'), detail)}`);
|
|
733
|
+
}
|
|
469
734
|
}
|
|
470
|
-
const said = mode === 'scenario' ? ' with a scenario loaded' : '';
|
|
471
735
|
for (const u of units) {
|
|
472
|
-
//
|
|
473
|
-
// one, a bearer token, and a refusal of it is no finding of the refresh below
|
|
736
|
+
// A front that checks its own key receives the door's token as a bearer.
|
|
474
737
|
const auth = u.auth ?? { header: 'authorization', scheme: 'Bearer' };
|
|
475
|
-
const
|
|
476
|
-
const
|
|
738
|
+
const native = nativeHeaders !== undefined && (!nativeUrl || claimsNativeUrl(u));
|
|
739
|
+
const credential = native ? nativeHeaders : issued ? { [auth.header]: auth.scheme ? `${auth.scheme} ${issued}` : issued } : {};
|
|
740
|
+
const signing = u.strategy?.in === 'signature' && u.strategy.algorithm === 'aws-sigv4' ? u.strategy : undefined;
|
|
741
|
+
if (!signing && u.auth && !native && !issued) {
|
|
742
|
+
out.push(`${u.name}: its credential door supplies no nonempty credential for ${auth.header}${said}`);
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
const claims = hostRules(u.hosts);
|
|
746
|
+
let hosts;
|
|
747
|
+
try {
|
|
748
|
+
hosts = hostCandidates(u);
|
|
749
|
+
}
|
|
750
|
+
catch (error) {
|
|
751
|
+
out.push(`${error.message}${said}`);
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
477
754
|
for (const op of u.ops) {
|
|
478
|
-
|
|
479
|
-
const where = `${u.name}: ${op.id} (${request.method} ${new URL(request.url).pathname})`;
|
|
480
|
-
const res = await send(request);
|
|
481
|
-
if (res === 'timeout') {
|
|
482
|
-
out.push(`${where} answered nothing in 10 s${said}`);
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
if (res instanceof Error) {
|
|
486
|
-
out.push(`${where}: the connection failed${said} (${res.message})`);
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
answered.set(op.id, res.status);
|
|
490
|
-
if (mode === 'plain') {
|
|
491
|
-
tally.calls++;
|
|
492
|
-
if (res.status < 300)
|
|
493
|
-
tally.ok++;
|
|
494
|
-
else
|
|
495
|
-
tally.refused++;
|
|
496
|
-
}
|
|
497
|
-
const text = await res.text();
|
|
498
|
-
if (res.status === 500 && !op.responseMedia?.['500'] && !op.responseMedia?.['5XX']) {
|
|
499
|
-
out.push(`${where} answered 500${said}, which the spec does not declare: ${text.slice(0, 160)}`);
|
|
755
|
+
if (refreshed.has(`${u.name}:${op.id}`))
|
|
500
756
|
continue;
|
|
501
|
-
}
|
|
502
|
-
|
|
757
|
+
const request = hosts.map((host) => sweepRequest(op, u.basePath, host, signing ? {} : credential)).find((candidate) => {
|
|
758
|
+
const url = new URL(candidate.url);
|
|
759
|
+
return claims.takes(url.hostname, url.pathname);
|
|
760
|
+
});
|
|
761
|
+
if (!request) {
|
|
762
|
+
out.push(`${u.name}: ${op.id} has no concrete declared host or issued HTTPS endpoint matching its host rules${said}`);
|
|
503
763
|
continue;
|
|
504
|
-
const type = res.headers.get('content-type') ?? '';
|
|
505
|
-
let body;
|
|
506
|
-
if (/json/.test(type)) {
|
|
507
|
-
try {
|
|
508
|
-
body = JSON.parse(text);
|
|
509
|
-
}
|
|
510
|
-
catch {
|
|
511
|
-
body = undefined;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
for (const key of leaked(body, vendorFields, '', !op.answers || res.status >= 300))
|
|
515
|
-
out.push(`${where} answers the twin's own field ${key}`);
|
|
516
|
-
if (res.status >= 200 && res.status < 300 && shape) {
|
|
517
|
-
const hit = shape.operationOf(request.method, request.url, Object.fromEntries(request.headers));
|
|
518
|
-
if (hit)
|
|
519
|
-
for (const detail of shape.failures(hit.op, body, type, request.headers.get('accept') ?? undefined, res.status, { method: request.method, responseText: text }))
|
|
520
|
-
out.push(`${where}: ${detail}`);
|
|
521
764
|
}
|
|
765
|
+
await callOperation(u, op, request);
|
|
522
766
|
}
|
|
523
|
-
|
|
767
|
+
}
|
|
768
|
+
const readSomething = units.some((u) => u.refreshReads.some((id) => { const status = answers.get(u)?.get(id); return status !== undefined && status >= 200 && status < 300; }));
|
|
769
|
+
if (mode === 'plain' && !nativeRefreshOwnsReads)
|
|
770
|
+
for (const u of units)
|
|
524
771
|
for (const r of u.refreshLists) {
|
|
525
772
|
const op = u.ops.find((o) => o.id === r.id);
|
|
526
773
|
if (!op || op.path.includes('{') || (op.basePath ?? '').includes('{'))
|
|
527
774
|
continue;
|
|
528
|
-
const status =
|
|
529
|
-
if (
|
|
775
|
+
const status = answers.get(u)?.get(r.id);
|
|
776
|
+
if (removed.has(`${u.name}:${r.id}`)) {
|
|
777
|
+
tally.removed++;
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
if (status === 403 && readSomething) {
|
|
781
|
+
tally.unread++;
|
|
530
782
|
continue;
|
|
783
|
+
}
|
|
531
784
|
if (status !== undefined && (status < 200 || status >= 300))
|
|
532
785
|
out.push(`${u.name}: ${r.resource}'s refresh lists by ${r.id}, which answered a fresh account ${status}: a World rooted at this twin reads nothing back`);
|
|
533
786
|
}
|
|
534
|
-
}
|
|
535
787
|
}
|
|
536
788
|
finally {
|
|
537
789
|
await server.stop();
|
|
538
790
|
}
|
|
539
791
|
}
|
|
540
792
|
// one defect repeated over a surface reads as one: the first 40 findings, and how many more
|
|
541
|
-
return { failures: out.length > 40 ? [...out.slice(0, 40), `… ${out.length - 40} more`] : out, note: `${tally.calls} served operations called, twice each: ${tally.ok} answered successfully, ${tally.refused} refused, unscripted` };
|
|
793
|
+
return { failures: out.length > 40 ? [...out.slice(0, 40), `… ${out.length - 40} more`] : out, note: `${tally.calls} served operations called, twice each: ${tally.ok} answered successfully, ${tally.refused} refused, unscripted; ${tally.unread} refresh resources unread (403), ${tally.removed} match declared native removals${replayedHeaders.size ? `; replayed application headers (values redacted): ${[...replayedHeaders].sort().join(', ')}` : ''}` };
|
|
542
794
|
}
|
|
543
795
|
/** A line protocol's connection over TCP, in the walk's stream shape. A line drew its replies when bytes arrived and then
|
|
544
796
|
* 50 ms passed with no more (a multi-line reply arrives in pieces), or when 500 ms passed with none (a line that draws no
|
|
@@ -580,42 +832,22 @@ async function lifeServed(pack) {
|
|
|
580
832
|
return ['journeys/customer-life.json is missing'];
|
|
581
833
|
const { inMemoryWorld, usePacks, walk } = await import("./walk/behavior-journey.js");
|
|
582
834
|
usePacks(dirname(pack), { dependenciesFrom: pack });
|
|
583
|
-
const env = globalThis.process.env;
|
|
584
835
|
const served = async (root, options) => {
|
|
585
|
-
const
|
|
586
|
-
env.VOLTER_WORLD_BOOT_ID = 'conformance';
|
|
587
|
-
let server;
|
|
588
|
-
try {
|
|
589
|
-
server = await serve(pack, { root, ...options });
|
|
590
|
-
}
|
|
591
|
-
finally {
|
|
592
|
-
if (before === undefined)
|
|
593
|
-
delete env.VOLTER_WORLD_BOOT_ID;
|
|
594
|
-
else
|
|
595
|
-
env.VOLTER_WORLD_BOOT_ID = before;
|
|
596
|
-
}
|
|
836
|
+
const server = await serve(pack, { root, ...options });
|
|
597
837
|
const port = server.inspectPort ?? server.port;
|
|
598
838
|
const http = servedHttpFetch(port);
|
|
599
839
|
return {
|
|
600
840
|
// the vendor's URL as the application called it, sent to the served pack: its host carried in the Host header
|
|
601
|
-
fetch: Object.assign(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
return answer === 'timeout' ? new Response(`no answer in 10 s from the served pack (${request.method} ${new URL(request.url).pathname})`, { status: 599 }) : answer;
|
|
607
|
-
}
|
|
608
|
-
finally {
|
|
609
|
-
abort.abort();
|
|
610
|
-
}
|
|
611
|
-
}, server.managedDatabaseUrl ? { managedDatabaseUrl: server.managedDatabaseUrl } : {}),
|
|
841
|
+
fetch: Object.assign(http, {
|
|
842
|
+
managedDatabaseUrl: server.managedDatabaseUrl,
|
|
843
|
+
managedDatabaseClock: server.managedDatabaseClock,
|
|
844
|
+
managedDatabaseConnection: server.managedDatabaseConnection,
|
|
845
|
+
}),
|
|
612
846
|
// a socket opened as an application opens it: a WebSocket to the served port, the vendor's host in its Host header
|
|
613
847
|
socket: (url, headers) => new WebSocket(`ws://127.0.0.1:${port}${url}`, { headers }),
|
|
614
848
|
// TCP to the native wire: a separate listener beside HTTP, or the primary protocol port.
|
|
615
849
|
stream: lineConnection(server.wirePort ?? server.port),
|
|
616
|
-
|
|
617
|
-
// 1.3.11: the walk ended and the stop spun at full CPU for 45 minutes), so the check waits 5 s and goes on
|
|
618
|
-
stop: async () => { await within(5000, Promise.resolve(server.stop())); },
|
|
850
|
+
stop: () => server.stop(),
|
|
619
851
|
};
|
|
620
852
|
};
|
|
621
853
|
const world = inMemoryWorld(`conform-${basename(pack)}`);
|
|
@@ -630,63 +862,39 @@ async function lifeServed(pack) {
|
|
|
630
862
|
}
|
|
631
863
|
/** The pack driven by the vendor's own client (clients/<vendor>.ts): served as a World runs it, its credentials issued
|
|
632
864
|
* by its credential door, the cases run in Node as an application runs the vendor's SDK (clients/run.ts), each the
|
|
633
|
-
* vendor's documented behaviour.
|
|
634
|
-
*
|
|
635
|
-
async function clientCases(pack, scratch) {
|
|
865
|
+
* vendor's documented behaviour. Without a built-in module, the current installed workflow can supply that proof;
|
|
866
|
+
* otherwise a vendor naming npm clients needs cases or clientCasesNone saying why none is owed. */
|
|
867
|
+
async function clientCases(pack, scratch, consumer) {
|
|
636
868
|
const vendor = (await manifestOf(pack)).vendor ?? basename(pack);
|
|
637
869
|
const clients = join(dirname(fileURLToPath(import.meta.url)), 'clients');
|
|
638
870
|
const extension = extname(fileURLToPath(import.meta.url));
|
|
639
871
|
if (!existsSync(join(clients, `${vendor}${extension}`))) {
|
|
640
|
-
// a vendor whose descriptor names npm clients (adoption.sdks) is held to them: no case is no proof the SDK works,
|
|
641
|
-
// unless the descriptor says why none is owed (clientCasesNone: no official SDK, or none the demand's applications
|
|
642
|
-
// use); one an application calls with no SDK of the vendor's (a raw HTTP catalog) has no client to drive
|
|
643
872
|
const descriptor = (await manifestOf(pack)).descriptor;
|
|
644
873
|
const sdks = descriptor?.adoption?.sdks ?? [];
|
|
645
874
|
if (descriptor?.clientCasesNone)
|
|
646
875
|
return { failures: [], note: `${vendor} owes no client case: ${descriptor.clientCasesNone}` };
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
876
|
+
if (!sdks.length)
|
|
877
|
+
return { failures: [], note: `${vendor} declares no SDK of its own` };
|
|
878
|
+
const proof = consumerClientProof(pack, vendor, sdks, consumer);
|
|
879
|
+
return { ...proof, failures: proof.failures.map((failure) => `${vendor} names npm clients (${sdks.join(', ')}) and has no built-in client cases: ${failure}`) };
|
|
650
880
|
}
|
|
651
881
|
const descriptor = (await manifestOf(pack)).descriptor;
|
|
652
882
|
// the first host that names one: a descriptor may lead with a suffix (a region's hosts under one domain), which no
|
|
653
883
|
// request addresses; the case's client reaches whatever host its issued credentials name
|
|
654
884
|
// a raw protocol's pack (hostsNone: SMTP, whose relay is whatever host the operator names) is reached by its TCP
|
|
655
885
|
// connection alone; its client names a stand-in host the connection never resolves
|
|
656
|
-
const host = descriptor?.hosts?.
|
|
886
|
+
const host = descriptor?.hosts?.flatMap((h) => 'host' in h && h.exclude !== true ? [h.host] : [])[0] ?? (descriptor?.hostsNone ? 'relay.world.test' : undefined);
|
|
657
887
|
if (!host)
|
|
658
888
|
return { failures: ['the descriptor names no host for its client to address'] };
|
|
659
889
|
const scenarioPath = join(scratch, 'client-scenario.json');
|
|
660
890
|
writeFileSync(scenarioPath, '{"handlers":[]}');
|
|
661
|
-
const
|
|
662
|
-
const before = env.VOLTER_WORLD_BOOT_ID;
|
|
663
|
-
env.VOLTER_WORLD_BOOT_ID = 'conformance';
|
|
664
|
-
let server;
|
|
665
|
-
try {
|
|
666
|
-
server = await serve(pack, { root: join(scratch, 'client-world'), scenarioPath });
|
|
667
|
-
}
|
|
668
|
-
finally {
|
|
669
|
-
if (before === undefined)
|
|
670
|
-
delete env.VOLTER_WORLD_BOOT_ID;
|
|
671
|
-
else
|
|
672
|
-
env.VOLTER_WORLD_BOOT_ID = before;
|
|
673
|
-
}
|
|
891
|
+
const server = await serve(pack, { root: join(scratch, 'client-world'), scenarioPath });
|
|
674
892
|
try {
|
|
675
893
|
// the World's credentials: what the pack's credential door issues, by the variable a World sets each in
|
|
676
894
|
const issued = {};
|
|
677
895
|
const door = descriptor?.credentialDoor;
|
|
678
896
|
if (door) {
|
|
679
|
-
|
|
680
|
-
// nothing once held this request open for good)
|
|
681
|
-
const abort = new AbortController();
|
|
682
|
-
const asked = await within(10_000, fetch(`http://127.0.0.1:${server.port}${door.path}`, { method: 'POST', headers: { host, 'content-type': 'application/json' }, body: JSON.stringify(door.body), signal: abort.signal }).then((r) => r.json().catch(() => ({}))));
|
|
683
|
-
abort.abort();
|
|
684
|
-
if (asked === 'timeout')
|
|
685
|
-
return { failures: [`the credential door (POST ${door.path}) answered nothing in 10 s, served with a scenario loaded`] };
|
|
686
|
-
const answer = asked;
|
|
687
|
-
for (const [name, field] of Object.entries(door.fill))
|
|
688
|
-
if (answer[field] !== undefined)
|
|
689
|
-
issued[name] = String(answer[field]);
|
|
897
|
+
Object.assign(issued, (await credentialFields(server, door, host)).outputs);
|
|
690
898
|
}
|
|
691
899
|
const job = join(scratch, 'client-job.json');
|
|
692
900
|
// a release carries its facts (generated/pack-facts.json, `twin-standard facts`); a source checkout does not, so its
|
|
@@ -790,7 +998,7 @@ export async function conformance(dir, options = {}) {
|
|
|
790
998
|
options.onCheck?.('client');
|
|
791
999
|
const asks = "driven by the vendor's own client (its official SDK), served as a World runs it, the vendor's documented behaviour holds";
|
|
792
1000
|
try {
|
|
793
|
-
const r = await clientCases(pack, scratch);
|
|
1001
|
+
const r = await clientCases(pack, scratch, options.consumer);
|
|
794
1002
|
return { id: 'client', asks, failures: r.failures, ...(r.note ? { note: r.note } : {}) };
|
|
795
1003
|
}
|
|
796
1004
|
catch (error) {
|
|
@@ -799,7 +1007,7 @@ export async function conformance(dir, options = {}) {
|
|
|
799
1007
|
})(),
|
|
800
1008
|
await run('life', 'the life walked over HTTP against the pack served as a World runs it, with its scenario: every check held', () => lifeServed(pack)),
|
|
801
1009
|
await run('standalone', 'served by its server.ts as a World runs it, the pack answers HTTP and the boot probe, and each declared socket upgrades', () => standalone(pack)),
|
|
802
|
-
await run('surface', 'every served operation called over HTTP as an application calls it, plainly and with a scenario loaded: answered within 10 s, no undeclared 500, no field of the twin\'s own, a success in the spec\'s shape, and every refresh list
|
|
1010
|
+
await run('surface', 'every served operation called over HTTP as an application calls it, plainly and with a scenario loaded: answered within 10 s, no undeclared 500, no field of the twin\'s own, a success in the spec\'s shape, and every refresh list answering, remaining unread under the native 403 contract, or matching its declared removal at the World clock', () => surfaceSwept(pack, scratch, runtime, options.consumer)),
|
|
803
1011
|
await run('records', 'each demand row cites the line it was read at, the spec\'s record names a vendored file that is there, the life names its author, the package has its README', () => records(pack)),
|
|
804
1012
|
await run('form', 'every unit passes the form section of the grade (the gate): the layout, the handler and kernel contracts, the manifest as data, the rules an author\'s code holds', () => formOf(pack)),
|
|
805
1013
|
];
|