@mostra/conformance 0.8.0 → 0.10.0

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/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as SCENARIOS, t as runConformance, y as readBaseline } from "./runner-DYbtXiL9.js";
2
+ import { n as SCENARIOS, t as runConformance, y as readBaseline } from "./runner-DcOgbosK.js";
3
3
  import { parseArgs } from "node:util";
4
4
  //#region src/cli.ts
5
5
  /**
package/dist/index.d.ts CHANGED
@@ -136,18 +136,23 @@ export declare function send(ask: Ask): Promise<Answer>;
136
136
  interface ParsedLink {
137
137
  /** The shell's origin. */
138
138
  readonly origin: string;
139
- /** The artifact the link opens. */
139
+ /** The artifact the link opens; on a hosted link, its hosted route (`rte_…`, §18.4). */
140
140
  readonly artifactId: string;
141
141
  /** The token's secret, from the fragment. */
142
142
  readonly secret: string;
143
143
  /** The version number the link pins, if it pins one. */
144
144
  readonly version?: string;
145
145
  }
146
- /** Reads a capability link (`http://host:port/a/<artifactId>[/v/<n>]#t=<secret>`). */
146
+ /**
147
+ * Reads a capability link (`http://host:port/a/<artifactId>[/v/<n>]#t=<secret>`), or a hosted one
148
+ * (`https://<domain>/a/<routeId>…`).
149
+ */
147
150
  export declare function parseLink(link: string): ParsedLink;
148
151
  /** A browser-like client with a per-host cookie jar. */
149
152
  export declare class Browser {
150
153
  #private;
154
+ /** Sends `secret` as `X-Mostra-Shell` on every later request under `prefix`, as a hosted shell does. */
155
+ keepShell(prefix: string, secret: string): void;
151
156
  /** Signs every later request to `origin` with a worker-mode frame session, as its worker does. */
152
157
  enterFrame(origin: string, secret: string): void;
153
158
  /** Whether `origin` has a worker-mode frame session in this browser. */
@@ -350,6 +355,8 @@ export declare class ScenarioContext {
350
355
  requireFeature(feature: string): void;
351
356
  /** The socket of the home's running instance, from `instance.json` (D81). */
352
357
  socket(): string | undefined;
358
+ /** Runs `cleanup` when the scenario ends, before its hosts stop (a server it started). */
359
+ defer(cleanup: () => Promise<void>): void;
353
360
  /** Ends every shim, stops a daemon the scenario left, and removes the directory. */
354
361
  close(): Promise<void>;
355
362
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/baseline.ts","../src/fixtures.ts","../src/harness/client.ts","../src/harness/serve.ts","../src/viewer.ts","../src/scenario.ts","../src/runner.ts","../src/scenarios/index.ts"],"mappings":";;;;UAciB;;WAEN;;WAEA,kBAAkB,SAAS;;;qBASzB,aAAa;;;;;wBAMV,aAAa,cAAc,2BAA2B;;;;;;;;;KC1B1D,UAAU,SAAS;;qBA2ElB,UAAU,SAAS,eAAe;;;;qBCtClC,sBAAsB;;WAExB;;WAEA;;WAEA,MAAM;EAEf,YAAY,gBAAgB,OAAO;;;qBAUxB;;;EAMX,MAAM;UAEE;;SA4CK,MACX,iBACA,MAAK,SAAS,0BACb,QAAQ;;MAgBP;;EAKJ,OAAO;;EAIP,SAAS;;EAST,cAAoB,QAAQ,cAAc,QAAQ;;EAKlD,QAAc,gBAAgB,iBAAiB,qBAAqB,QAAQ;;EAW5E,KAAW,IAAI,yBACb,gBACA,iBACA,qBACC,QAAQ;;EAOX,gBAAsB;;EAKtB,SAAe,QAAQ;;EAKvB,OAAa,QAAQ,eAAe;;EAKpC,OAAa,QAAQ,eAAe,QAAQ;;;;;;;;EAa5C,SAAe;;;wBAwCD,OAAO;;;;UCrNN;;EAEf,cAAc,KAAK,gCAAgC,QAAQ,KAAK;;EAEhE,MAAM,QAAQ,cAAc,cAAc,QAAQ;;EAElD,KAAK,gBAAgB,iBAAiB;;EAEtC,eAAe;;EAEf,SAAS,cAAc,QAAQ;;EAE/B,QAAQ,QAAQ,sBAAsB;;EAEtC,QAAQ,QAAQ,eAAe,eAAe,QAAQ;;;;;;wBAcxC,aACd,gBAAgB,uBAChB;EAAM,QAAQ,OAAO;EAAgB,SAAS,OAAO;IACpD;;;;UCzCc;;WAEN;;WAEA,SAAS,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qBAIE;;;WAEF,UAAU;;WAEV;;WAEA;;EAET,MAAO;EAIP,YAAY,UAAU,aAAa;;EAOnC,QAAc;;EAKd,eAAqB,QAAQ;;EAO7B,YAAY,QAAO,SAAS,0BAA+B;;EAU3D,MACE;IACE,MAAM,SAAS;IACf,OAAO;IACP,OAAO;MAER,QAAQ;;EAUX,QAAc;IAAW,MAAM,SAAS;MAAiC,QAAQ;;EAMjF,OAAO,SAAS,SAAS;;EAWzB,QAAQ,aAAa,SAAS;;EAK9B,QACE,aACA;IAAW;IAAkB;MAC5B;IACD;IACA;IACA;IACA;IACA;IACA;;;EAUF,UACE,SAAS,SACT;IAAW;MACV;IACD;IACA;IACA;IACA;IACA;IACA;IACA;;;EAOF,KAAW,oBAAoB,SAAQ,0BAA+B;;EAStE,OACE,oBACA;IAAW,OAAO;IAAyB,UAAU;MACpD,QAAQ;;EAOX,QAAQ,oBAAoB,sBAAsB,QAAQ;;EAQ1D,OACE;IAAU;IAAsB;KAChC,iBACC;IAAU,QAAQ;IAAe;;;EAKpC,SAAS,QAAQ;;EAKjB,WAAiB,GACf,cACA,iBAAiB,QAAQ,yBAAyB,uBAClD,qBACC,QAAQ;;EAWX,YAAY;;EAKZ,eAAe;;EAMf;;EAYA,SAAe;;;;;KC9RL;;UAaK;;WAEN;;WAEA;;WAEA;;WAEA,QAAQ;;WAER;;WAEA;;;UAIM;;WAEN,MAAM;;WAEN,mBAAmB;;WAEnB;;;UAIM;;WAEN;;WAEA,UAAU,SAAS;;WAEnB;;WAEA,WAAW;;WAEX;;WAEA;;WAEA;;WAEA,aAAa,SAAS;;WAEtB,qBAAqB;;;wBAqDV,eAAe,SAAS,aAAa,QAAQ;;;;qBC9GtD,oBAAoB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/baseline.ts","../src/fixtures.ts","../src/harness/client.ts","../src/harness/serve.ts","../src/viewer.ts","../src/scenario.ts","../src/runner.ts","../src/scenarios/index.ts"],"mappings":";;;;UAciB;;WAEN;;W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AAS;;EAWzB,QAAQ,aAAa,SAAS;;EAK9B,QACE,aACA;IAAW;IAAkB;MAC5B;IACD;IACA;IACA;IACA;IACA;IACA;;;EAUF,UACE,SAAS,SACT;IAAW;MACV;IACD;IACA;IACA;IACA;IACA;IACA;IACA;;;EAOF,KAAW,oBAAoB,SAAQ,0BAA+B;;EAStE,OACE,oBACA;IAAW,OAAO;IAAyB,UAAU;MACpD,QAAQ;;EAOX,QAAQ,oBAAoB,sBAAsB,QAAQ;;EAQ1D,OACE;IAAU;IAAsB;KAChC,iBACC;IAAU,QAAQ;IAAe;;;EAKpC,SAAS,QAAQ;;EAKjB,WAAiB,GACf,cACA,iBAAiB,QAAQ,yBAAyB,uBAClD,qBACC,QAAQ;;EAWX,YAAY;;EAKZ,eAAe;;EAMf;;EAYA,MAAM,eAAe;;EAKrB,SAAe;;;;;KCpSL;;UAaK;;WAEN;;WAEA;;WAEA;;WAEA,QAAQ;;WAER;;WAEA;;;UAIM;;WAEN,MAAM;;WAEN,mBAAmB;;WAEnB;;;UAIM;;WAEN;;WAEA,UAAU,SAAS;;WAEnB;;WAEA,WAAW;;WAEX;;WAEA;;WAEA;;WAEA,aAAa,SAAS;;WAEtB,qBAAqB;;;wBAqDV,eAAe,SAAS,aAAa,QAAQ;;;;qBC7GtD,oBAAoB"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as FIXTURES, a as ScenarioFailure, c as Browser, d as parseLink, f as resultOf, g as codeOf, h as InstanceError, i as ScenarioContext, l as OpenError, m as HostUnderTest, n as SCENARIOS, o as check, p as send, r as NotApplicable, s as same, t as runConformance, u as Viewer, v as NO_BASELINE, y as readBaseline } from "./runner-DYbtXiL9.js";
1
+ import { _ as FIXTURES, a as ScenarioFailure, c as Browser, d as parseLink, f as resultOf, g as codeOf, h as InstanceError, i as ScenarioContext, l as OpenError, m as HostUnderTest, n as SCENARIOS, o as check, p as send, r as NotApplicable, s as same, t as runConformance, u as Viewer, v as NO_BASELINE, y as readBaseline } from "./runner-DcOgbosK.js";
2
2
  import { a as HARNESS_METHODS, o as HARNESS_REVISIONS } from "./protocol-Bi4gZzsu.js";
3
3
  import { i as serveHarness, n as ReferenceStore, r as runReferenceHost, t as REFERENCE_FAULTS } from "./reference-host-BAAxMabg.js";
4
4
  export { Browser, FIXTURES, HARNESS_METHODS, HARNESS_REVISIONS, HostUnderTest, InstanceError, NO_BASELINE, NotApplicable, OpenError, REFERENCE_FAULTS, ReferenceStore, SCENARIOS, ScenarioContext, ScenarioFailure, Viewer, check, codeOf, parseLink, readBaseline, resultOf, runConformance, runReferenceHost, same, send, serveHarness };
@@ -8,6 +8,7 @@ import { dirname, join } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
9
  import { tmpdir } from "node:os";
10
10
  import { request } from "node:http";
11
+ import { createServer } from "node:net";
11
12
  //#region src/baseline.ts
12
13
  /**
13
14
  * Expected-failure baselines (HO-05): a host that knows it fails some scenarios today records them,
@@ -393,7 +394,9 @@ async function windowsHelperOrNone() {
393
394
  * `Origin`, `Sec-Fetch-*` and CSRF headers a browser sends. It also sends what no browser would,
394
395
  * for the hygiene scenarios. It never follows redirects. Where the shell and the artifact are two
395
396
  * sites (a host's external bases, a Cloudflare share), it enters the frame as the bootstrap page
396
- * does and signs the frame's requests as Mostra's service worker does (D70, D158 item 5).
397
+ * does and signs the frame's requests as Mostra's service worker does (D70, D158 item 5). On a
398
+ * remote server's hosted link (`/a/<routeId>`) it keeps the shell's session as the hosted shell
399
+ * does, in a header and never a cookie (`X-Mostra-Shell`, D165 item 8).
397
400
  */
398
401
  /** The browser-protocol revision the kit speaks: the first, which every gateway serves. */
399
402
  const REVISION = BROWSER_PROTOCOL_REVISIONS[0];
@@ -443,10 +446,13 @@ function send(ask) {
443
446
  req.end();
444
447
  });
445
448
  }
446
- /** Reads a capability link (`http://host:port/a/<artifactId>[/v/<n>]#t=<secret>`). */
449
+ /**
450
+ * Reads a capability link (`http://host:port/a/<artifactId>[/v/<n>]#t=<secret>`), or a hosted one
451
+ * (`https://<domain>/a/<routeId>…`).
452
+ */
447
453
  function parseLink(link) {
448
454
  const url = new URL(link);
449
- const match = /^\/a\/(art_[0-9A-Z]{26})(?:\/v\/(\d+))?$/.exec(url.pathname);
455
+ const match = /^\/a\/((?:art|rte)_[0-9A-Z]{26})(?:\/v\/(\d+))?$/.exec(url.pathname);
450
456
  const secret = new URLSearchParams(url.hash.slice(1)).get("t");
451
457
  if (!match?.[1] || !secret) throw new Error(`${url.origin}${url.pathname} isn't a capability link.`);
452
458
  return {
@@ -461,6 +467,12 @@ var Browser = class {
461
467
  #jar = /* @__PURE__ */ new Map();
462
468
  /** Worker-mode frame sessions by origin: the header Mostra's service worker adds (D70). */
463
469
  #frames = /* @__PURE__ */ new Map();
470
+ /** Hosted shells' sessions by `<origin>/a/<routeId>`: the header the hosted shell sends. */
471
+ #shells = /* @__PURE__ */ new Map();
472
+ /** Sends `secret` as `X-Mostra-Shell` on every later request under `prefix`, as a hosted shell does. */
473
+ keepShell(prefix, secret) {
474
+ this.#shells.set(prefix, secret);
475
+ }
464
476
  /** Signs every later request to `origin` with a worker-mode frame session, as its worker does. */
465
477
  enterFrame(origin, secret) {
466
478
  this.#frames.set(origin, secret);
@@ -482,11 +494,13 @@ var Browser = class {
482
494
  const cookie = ask.noCookies ? "" : this.cookiesFor(ask.url);
483
495
  const url = new URL(ask.url);
484
496
  const frame = url.searchParams.has("ticket") ? void 0 : this.#frames.get(url.origin);
497
+ const shell = ask.noCookies ? void 0 : [...this.#shells].find(([prefix]) => ask.url === prefix || ask.url.startsWith(`${prefix}/`))?.[1];
485
498
  const answer = await send({
486
499
  ...ask,
487
500
  headers: {
488
501
  ...cookie ? { cookie } : {},
489
502
  ...frame !== void 0 ? { "x-mostra-frame": frame } : {},
503
+ ...shell !== void 0 ? { "x-mostra-shell": shell } : {},
490
504
  ...ask.headers
491
505
  }
492
506
  });
@@ -567,6 +581,8 @@ var Viewer = class Viewer {
567
581
  });
568
582
  if (exchange.status !== 200) throw new OpenError("exchange", exchange);
569
583
  const shellCsrf = exchange.json().csrf;
584
+ const hosted = exchange.json().session;
585
+ if (hosted !== void 0) browser.keepShell(`${parsed.origin}/a/${parsed.artifactId}`, hosted);
570
586
  const ticketAnswer = await browser.fetchJson(parsed.origin, `${api}/ticket`, {
571
587
  body: parsed.version !== void 0 ? { version: Number(parsed.version) } : {},
572
588
  csrf: shellCsrf
@@ -763,6 +779,7 @@ var ScenarioContext = class {
763
779
  /** The host: its name and version. */
764
780
  host;
765
781
  #hosts = [];
782
+ #cleanups = [];
766
783
  #published = 0;
767
784
  constructor(settings, dir) {
768
785
  this.settings = settings;
@@ -891,8 +908,13 @@ var ScenarioContext = class {
891
908
  return;
892
909
  }
893
910
  }
911
+ /** Runs `cleanup` when the scenario ends, before its hosts stop (a server it started). */
912
+ defer(cleanup) {
913
+ this.#cleanups.push(cleanup);
914
+ }
894
915
  /** Ends every shim, stops a daemon the scenario left, and removes the directory. */
895
916
  async close() {
917
+ for (const cleanup of this.#cleanups.splice(0).reverse()) await cleanup().catch(() => void 0);
896
918
  for (const host of this.#hosts) {
897
919
  await host.stopInstance().catch(() => void 0);
898
920
  await host.close().catch(() => void 0);
@@ -1883,6 +1905,253 @@ const PORT_SCENARIOS = [
1883
1905
  }
1884
1906
  ];
1885
1907
  //#endregion
1908
+ //#region src/remote.ts
1909
+ /**
1910
+ * A remote server the kit runs for the remote scenarios (WP-29, INTERFACES §18): `mostra-runtime
1911
+ * server` from the runtime the host uses, on loopback, with a development identity provider, and
1912
+ * the host's instance signed in to it by the device grant, the person approving on the server's
1913
+ * device page as a browser would.
1914
+ */
1915
+ async function freePort() {
1916
+ return new Promise((resolve, reject) => {
1917
+ const probe = createServer();
1918
+ probe.once("error", reject);
1919
+ probe.listen(0, "127.0.0.1", () => {
1920
+ const address = probe.address();
1921
+ probe.close(() => resolve(typeof address === "object" && address ? address.port : 0));
1922
+ });
1923
+ });
1924
+ }
1925
+ /** Starts a server for `context`, stopped when the scenario ends. */
1926
+ async function startRemoteServer(context) {
1927
+ const port = await freePort();
1928
+ const dir = join(context.dir, "server");
1929
+ mkdirSync(dir, {
1930
+ recursive: true,
1931
+ mode: 448
1932
+ });
1933
+ const config = join(dir, "server.json");
1934
+ writeFileSync(config, JSON.stringify({
1935
+ apiOrigin: `http://api.localhost:${port}`,
1936
+ domains: { active: `content.localhost:${port}` },
1937
+ scheme: "http",
1938
+ identityProviders: [{
1939
+ id: "dev",
1940
+ kind: "development",
1941
+ label: "Development sign-in"
1942
+ }]
1943
+ }));
1944
+ const env = {
1945
+ ...process.env,
1946
+ ...context.settings.hostEnv
1947
+ };
1948
+ const runtime = await resolveRuntime({ env });
1949
+ const child = spawn(runtime.node, [
1950
+ runtime.runtimeEntry,
1951
+ "server",
1952
+ "--data",
1953
+ join(dir, "data"),
1954
+ "--config",
1955
+ config,
1956
+ "--listen",
1957
+ `127.0.0.1:${port}`
1958
+ ], {
1959
+ env,
1960
+ stdio: [
1961
+ "ignore",
1962
+ "pipe",
1963
+ "pipe"
1964
+ ],
1965
+ windowsHide: true
1966
+ });
1967
+ const exited = new Promise((done) => child.once("exit", () => done()));
1968
+ context.defer(async () => {
1969
+ if (child.exitCode === null) {
1970
+ child.kill();
1971
+ const timer = setTimeout(() => child.kill("SIGKILL"), 1e4);
1972
+ await exited;
1973
+ clearTimeout(timer);
1974
+ }
1975
+ });
1976
+ await new Promise((resolve, reject) => {
1977
+ let out = "";
1978
+ const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("the remote server didn't start in 60 s")), 6e4);
1979
+ child.stdout?.on("data", (chunk) => {
1980
+ out += chunk.toString("utf8");
1981
+ const line = out.split("\n")[0];
1982
+ if (!out.includes("\n") || line === void 0) return;
1983
+ clearTimeout(timer);
1984
+ if (JSON.parse(line).status === "started") resolve();
1985
+ else reject(/* @__PURE__ */ new Error(`the remote server didn't start: ${line}`));
1986
+ });
1987
+ child.once("exit", (code) => {
1988
+ clearTimeout(timer);
1989
+ reject(/* @__PURE__ */ new Error(`the remote server exited with ${code}`));
1990
+ });
1991
+ });
1992
+ return {
1993
+ origin: `http://api.localhost:${port}`,
1994
+ port,
1995
+ env: { MOSTRA_TEST_SERVER_ADDRESS: `127.0.0.1:${port}` }
1996
+ };
1997
+ }
1998
+ /** Posts a form to the server as its own device page does (with its own `Origin`). */
1999
+ function postForm(server, path, fields) {
2000
+ const body = new URLSearchParams(fields).toString();
2001
+ return new Promise((resolve, reject) => {
2002
+ const req = request({
2003
+ host: "127.0.0.1",
2004
+ port: server.port,
2005
+ method: "POST",
2006
+ path,
2007
+ headers: {
2008
+ host: new URL(server.origin).host,
2009
+ origin: server.origin,
2010
+ "content-type": "application/x-www-form-urlencoded",
2011
+ "content-length": Buffer.byteLength(body)
2012
+ },
2013
+ agent: false
2014
+ }, (res) => {
2015
+ const chunks = [];
2016
+ res.on("data", (chunk) => chunks.push(chunk));
2017
+ res.on("end", () => resolve({
2018
+ status: res.statusCode ?? 0,
2019
+ body: Buffer.concat(chunks).toString("utf8")
2020
+ }));
2021
+ });
2022
+ req.setTimeout(3e4, () => req.destroy(/* @__PURE__ */ new Error(`${path} didn't answer in 30 s`)));
2023
+ req.on("error", reject);
2024
+ req.end(body);
2025
+ });
2026
+ }
2027
+ /**
2028
+ * Signs the host's instance in to `server` through the host (`remote/login`, then
2029
+ * `remote/login.wait`), approving the code on the device page as `name`; the instance's link.
2030
+ */
2031
+ async function signIn(context, server, name = "Ada") {
2032
+ const started = await context.host.call("remote/login", { server: server.origin });
2033
+ const approved = await postForm(server, "/device", {
2034
+ user_code: started.userCode,
2035
+ name,
2036
+ provider: "dev",
2037
+ decision: "approve"
2038
+ });
2039
+ if (approved.status !== 200) throw new Error(`the device page refused the approval: ${approved.status}`);
2040
+ const waited = await context.host.call("remote/login.wait", {
2041
+ loginId: started.loginId,
2042
+ timeoutMs: 3e4
2043
+ }, 4e4);
2044
+ if (waited.status !== "signed-in") throw new Error(`remote/login.wait: ${waited.status}`);
2045
+ return { instanceId: waited.instanceId };
2046
+ }
2047
+ //#endregion
2048
+ //#region src/scenarios/remote.ts
2049
+ /**
2050
+ * A host whose instance shares to a remote server (WP-29, RM-02, RM-04; INTERFACES §18): the kit
2051
+ * runs the server, the host's instance signs in by the device grant and shares through the host's
2052
+ * own client, and the kit answers the hosted page as a respondent would. Hosted submissions reach
2053
+ * the host through its instance's local outbox, with H-04's guarantees, and a hosted page's
2054
+ * actions run on the host's instance, with its secrets, through the relay.
2055
+ */
2056
+ /** Starts a server and the host's instance, signed in to it. */
2057
+ async function linked(context) {
2058
+ const server = await startRemoteServer(context);
2059
+ await context.start({ env: server.env });
2060
+ await signIn(context, server);
2061
+ return server;
2062
+ }
2063
+ /** Shares `artifactId` to the server through the host; the hosted link. */
2064
+ async function hostedLink(context, artifactId, params = {}) {
2065
+ const shared = await context.host.call("share/start", {
2066
+ artifact: { artifactId },
2067
+ via: "remote",
2068
+ ...params
2069
+ }, 12e4);
2070
+ same(shared.via, "remote", "the share's way");
2071
+ return shared.url;
2072
+ }
2073
+ /** Every remote scenario. */
2074
+ const REMOTE_SCENARIOS = [{
2075
+ id: "remote.delivery",
2076
+ title: "An answer on a hosted link is told only that it was sent, reaches the host's submissions port once through its instance's local outbox, and reads locally with wait and results/get",
2077
+ covers: [
2078
+ "RM-02",
2079
+ "HO-05",
2080
+ "IN-12",
2081
+ "IN-13",
2082
+ "H-04"
2083
+ ],
2084
+ async run(context) {
2085
+ const server = await linked(context);
2086
+ const receipt = await context.published(FORM);
2087
+ const url = await hostedLink(context, receipt.artifactId);
2088
+ check(new URL(url).host === `content.localhost:${server.port}` && url.includes("/a/rte_"), `a hosted link on the user-content domain, by route (${new URL(url).origin}${new URL(url).pathname})`);
2089
+ const viewer = await Viewer.open(url);
2090
+ const channel = viewer.ticket.submitChannels.includes("artifact") ? "artifact" : "shell";
2091
+ const answer = await viewer.answer({
2092
+ name: "Ada",
2093
+ comment: "From the server"
2094
+ }, channel);
2095
+ same(answer.status, 200, `the hosted submit's status (${answer.body})`);
2096
+ const summary = answer.json();
2097
+ same(summary.deliveries, void 0, "the delivery states a respondent is shown");
2098
+ same((await context.host.call("wait", {
2099
+ artifact: { artifactId: receipt.artifactId },
2100
+ until: "submitted",
2101
+ timeoutMs: 6e4
2102
+ }, 7e4)).status, "satisfied", "wait --until submitted on the host's instance");
2103
+ const results = await context.eventually("results/get reads the hosted answer", async () => {
2104
+ const read = await context.results(receipt.artifactId);
2105
+ return read.submission.id === summary.id ? read : void 0;
2106
+ });
2107
+ same(results.answers, {
2108
+ name: "Ada",
2109
+ comment: "From the server"
2110
+ }, "the answers");
2111
+ check(results.submission.origin !== void 0, "the submission names the hosted home it came from");
2112
+ if (context.host.serves("submissions")) {
2113
+ same((await context.eventually("the host's store holds the submission", async () => (await context.store()).deliveries.find((entry) => entry.submissionId === summary.id))).stored, 1, "copies the host's store holds");
2114
+ await new Promise((done) => setTimeout(done, 2e3));
2115
+ const later = (await context.store()).deliveries.filter((entry) => entry.submissionId === summary.id);
2116
+ same(later.length, 1, "deliveries of the hosted answer");
2117
+ same(later[0]?.stored, 1, "copies after a while");
2118
+ }
2119
+ }
2120
+ }, {
2121
+ id: "remote.relay",
2122
+ title: "An action pressed on a hosted page runs on the host's instance with the instance's own secret, and what it raises reaches the host's events",
2123
+ covers: [
2124
+ "RM-04",
2125
+ "AC-05",
2126
+ "HO-05"
2127
+ ],
2128
+ async run(context) {
2129
+ await linked(context);
2130
+ const receipt = await context.published(ACTIONS);
2131
+ await context.host.call("secret/set", {
2132
+ name: "MAIL_KEY",
2133
+ value: "k-0123456789",
2134
+ artifact: { artifactId: receipt.artifactId }
2135
+ });
2136
+ const url = await hostedLink(context, receipt.artifactId, { viewer: {
2137
+ ref: "grace@example.com",
2138
+ name: "Grace"
2139
+ } });
2140
+ const viewer = await Viewer.open(url);
2141
+ const length = await viewer.run("actions.ts#secretLength", ["MAIL_KEY"]);
2142
+ same(length.status, "succeeded", "the relayed run's end");
2143
+ same(await resultOf(length), 12, "the secret's length, read on the host's instance");
2144
+ same((await viewer.run("actions.ts#notify", ["grace@example.com"])).status, "succeeded", "the second relayed run's end");
2145
+ await context.eventually("the host's instance follows what the run raised", async () => {
2146
+ const read = await context.host.call("events/read", { filter: {
2147
+ artifacts: [receipt.artifactId],
2148
+ types: ["host.mail.sent"]
2149
+ } });
2150
+ return read.events.length === 1 ? read : void 0;
2151
+ });
2152
+ }
2153
+ }];
2154
+ //#endregion
1886
2155
  //#region src/privacy.ts
1887
2156
  /**
1888
2157
  * Whether a path of a host's home is owner-only, as the kit judges it (H-16, D44, D85, D150
@@ -2260,7 +2529,8 @@ const SCENARIOS = [
2260
2529
  ...DELIVERY_SCENARIOS,
2261
2530
  ...INTERACTION_SCENARIOS,
2262
2531
  ...PORT_SCENARIOS,
2263
- ...VIEWING_SCENARIOS
2532
+ ...VIEWING_SCENARIOS,
2533
+ ...REMOTE_SCENARIOS
2264
2534
  ];
2265
2535
  //#endregion
2266
2536
  //#region src/runner.ts
@@ -2358,4 +2628,4 @@ async function runConformance(options) {
2358
2628
  //#endregion
2359
2629
  export { FIXTURES as _, ScenarioFailure as a, Browser as c, parseLink as d, resultOf as f, codeOf as g, InstanceError as h, ScenarioContext as i, OpenError as l, HostUnderTest as m, SCENARIOS as n, check as o, send as p, NotApplicable as r, same as s, runConformance as t, Viewer as u, NO_BASELINE as v, readBaseline as y };
2360
2630
 
2361
- //# sourceMappingURL=runner-DYbtXiL9.js.map
2631
+ //# sourceMappingURL=runner-DcOgbosK.js.map