@mostra/conformance 0.5.0 → 0.6.1
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 +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/reference-host-BJ-A_Qd_.d.ts.map +1 -1
- package/dist/{reference-host-d6gs3Tal.js → reference-host-D7fe25go.js} +18 -3
- package/dist/reference-host-D7fe25go.js.map +1 -0
- package/dist/reference-host.js +1 -2
- package/dist/{runner-BlBQXUFz.js → runner-C8SO70qb.js} +264 -33
- package/dist/runner-C8SO70qb.js.map +1 -0
- package/package.json +9 -9
- package/src/harness/client.ts +50 -14
- package/src/harness/tree.ts +85 -0
- package/src/privacy.ts +122 -0
- package/src/reference-host.ts +19 -4
- package/src/scenario.ts +31 -18
- package/src/scenarios/delivery.ts +15 -6
- package/src/scenarios/session.ts +10 -7
- package/dist/reference-host-d6gs3Tal.js.map +0 -1
- package/dist/runner-BlBQXUFz.js.map +0 -1
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-
|
|
2
|
+
import { n as SCENARIOS, t as runConformance, y as readBaseline } from "./runner-C8SO70qb.js";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
4
|
//#region src/cli.ts
|
|
5
5
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,13 @@ export declare class HostUnderTest {
|
|
|
66
66
|
script(params: ScriptParams): Promise<void>;
|
|
67
67
|
/** `harness/events` (feature `events`). */
|
|
68
68
|
events(params: EventsParams): Promise<EventsResult>;
|
|
69
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Ends the shim: stdin closes, then SIGTERM to its process group, then SIGKILL. Windows has no
|
|
71
|
+
* process groups or signals (D150 item 6): there the kit notes the shell's process tree while it
|
|
72
|
+
* runs, and after 5 s ends the shell's tree (`taskkill /T`, while the shell lives) and every
|
|
73
|
+
* process it noted (`mostra-win reap`, which ends one only while its creation time matches), so
|
|
74
|
+
* a descendant of a shell that already exited is ended too (Opus review of WP-W3, finding 3).
|
|
75
|
+
*/
|
|
70
76
|
close(): Promise<void>;
|
|
71
77
|
}
|
|
72
78
|
/** A diagnostic code from an error the kit saw: the instance's, an RPC error's, or none. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;;;;
|
|
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,Q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;;;;KCvRL;;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"}
|
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-
|
|
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-C8SO70qb.js";
|
|
2
2
|
import { a as HARNESS_METHODS, o as HARNESS_REVISIONS } from "./protocol-RQ9lbehE.js";
|
|
3
|
-
import { i as serveHarness, n as ReferenceStore, r as runReferenceHost, t as REFERENCE_FAULTS } from "./reference-host-
|
|
3
|
+
import { i as serveHarness, n as ReferenceStore, r as runReferenceHost, t as REFERENCE_FAULTS } from "./reference-host-D7fe25go.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 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference-host-BJ-A_Qd_.d.ts","names":[],"sources":["../src/harness/protocol.ts","../src/reference-host.ts"],"mappings":";;;;cAsBa;;cAGA;WACF;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;;KAgBC;;UAGK;;WAEN;;WAEA;aAAgB;aAAuB;;;;UAIjC;;WAEN;;WAEA;aAAiB;aAAuB;;;WAExC;;WAEA,mBAAmB;;;cAIjB,kBAAkB,EAAE,QAAQ;;UAQxB;;WAEN;;WAEA,KAAK,SAAS;;WAEd;;;cAIE,aAAa,EAAE,QAAQ;;UAOnB;;WAEN;;WAEA;aACE;aACA;aACA;aACA;aACA;;;WAGF;aAA8B;;;;cAI5B,aAAa,EAAE,QAAQ;;UAanB;;WAEN;;WAEA;;WAEA;;;cAIE,YAAY,EAAE,QAAQ;;UAOlB;;WAEN;;WAEA;aAAiB;aAAuB;MAAqB;;;KAI5D;WAAwB;;WAA+B,OAAO;;;cAG7D,YAAY,EAAE,QAAQ;;UAMlB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN,qBAAqB;;WAErB;aACE;aACA;aACA;aACA;;;WAGF;aACE;aACA;aACA;;;;;;;WAOF;aACE;aACA;aACA;aACA;eAAoB;eAAsB;;;;;;;WAM5C;aACE;aACA;eACE;eACA;;;;WAIJ;aAA6B;aAA6B;;;;cAIxD,aAAa,EAAE,QAAQ;;KAoDxB;WAEG;WACA;;WAGA;WACA;aAIM;aACA;;;WAIN;;WAEA;aAKM;aAAsB;;;WAE5B;WAA0B,QAAQ,SAAS;;;cAG7C,cAAc,EAAE,QAAQ;;UA8BpB;;WAEN;;WAEA;aAAmB;aAAwC;;;WAE3D;;WAEA;;;cAIE,cAAc,EAAE,QAAQ;;UAWpB;;WAEN;aACE;aACA;eAA6B;eAAyB;QAAiB;;;;cAQvE,cAAc,EAAE,QAAQ;;;;
|
|
1
|
+
{"version":3,"file":"reference-host-BJ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AAO,QAAQ;;EAyCf,SAAS;;EAuFT,YAAY;;;iBAaQ,iBACpB;EAAW;EAAsB;EAAsB;IACtD"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { a as HARNESS_METHODS, c as ScriptParams, f as kitVersion, l as StartParams, o as HARNESS_REVISIONS, r as EventsParams, t as CallParams } from "./protocol-RQ9lbehE.js";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
2
3
|
import { LineSplitter, RpcError, RpcPeer, createDiagnostic, encodeLine, hostMethods } from "@mostra/protocol";
|
|
3
|
-
import { parseArgs } from "node:util";
|
|
4
4
|
import { createMostra } from "@mostra/sdk";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
5
7
|
//#region src/harness/serve.ts
|
|
6
8
|
/**
|
|
7
9
|
* The host's side of the harness protocol, for hosts written in TypeScript: `serveHarness` reads
|
|
@@ -383,7 +385,20 @@ async function runReferenceHost(options = {}) {
|
|
|
383
385
|
}
|
|
384
386
|
});
|
|
385
387
|
}
|
|
386
|
-
|
|
388
|
+
/**
|
|
389
|
+
* Whether this module is the program Node.js was started with: by file URL, which spells a
|
|
390
|
+
* Windows path (`file:///D:/…`) as no string concatenation does, through any link, or as the
|
|
391
|
+
* installed binary (`mostra-conformance-reference-host`, a link or npm's shim to `dist/`).
|
|
392
|
+
*/
|
|
393
|
+
function isMain() {
|
|
394
|
+
const entry = process.argv[1];
|
|
395
|
+
if (entry === void 0) return false;
|
|
396
|
+
try {
|
|
397
|
+
if (pathToFileURL(realpathSync(entry)).href === import.meta.url) return true;
|
|
398
|
+
} catch {}
|
|
399
|
+
return entry.endsWith("reference-host.js");
|
|
400
|
+
}
|
|
401
|
+
if (isMain()) {
|
|
387
402
|
const { values } = parseArgs({
|
|
388
403
|
options: {
|
|
389
404
|
standalone: { type: "boolean" },
|
|
@@ -406,4 +421,4 @@ if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith
|
|
|
406
421
|
//#endregion
|
|
407
422
|
export { serveHarness as i, ReferenceStore as n, runReferenceHost as r, REFERENCE_FAULTS as t };
|
|
408
423
|
|
|
409
|
-
//# sourceMappingURL=reference-host-
|
|
424
|
+
//# sourceMappingURL=reference-host-D7fe25go.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-host-D7fe25go.js","names":[],"sources":["../src/harness/serve.ts","../src/reference-host.ts"],"sourcesContent":["/**\n * The host's side of the harness protocol, for hosts written in TypeScript: `serveHarness` reads\n * the kit's requests on stdin and answers them with the host's implementation, on stdout. A host\n * writes its shim as one small program around its real integration:\n *\n * ```ts\n * serveHarness({\n * initialize: () => ({ host: { name: \"my-host\", version: \"1.0.0\" }, ports: [\"submissions\"], features: [] }),\n * start: (params) => myHost.startMostra(params.home, params.env),\n * call: (method, params) => myHost.mostra.call(method, params),\n * stop: () => myHost.stopMostra(),\n * store: () => myHost.conformanceStore(),\n * });\n * ```\n *\n * Nothing but protocol messages may go to stdout; log to stderr.\n */\nimport { createDiagnostic, encodeLine, LineSplitter, RpcError, RpcPeer } from \"@mostra/protocol\";\nimport {\n CallParams,\n type CallResult,\n EventsParams,\n type EventsResult,\n HARNESS_METHODS,\n HARNESS_REVISIONS,\n type InitializeResult,\n ScriptParams,\n StartParams,\n type StartResult,\n type StoreResult,\n} from \"./protocol.ts\";\n\n/** What a TypeScript host implements to be driven by the kit. */\nexport interface HarnessImplementation {\n /** Who the host is, the ports it serves and its features. */\n initialize(): Omit<InitializeResult, \"revision\"> | Promise<Omit<InitializeResult, \"revision\">>;\n /** Starts (or attaches to) the host's instance for `params.home`, with its real ports. */\n start(params: StartParams): StartResult | Promise<StartResult>;\n /** Sends one host-protocol request through the host's client; throw an `RpcError` for an error answer. */\n call(method: string, params: unknown, timeoutMs?: number): unknown;\n /** Ends the host's session. */\n stop(): void | Promise<void>;\n /** What the host's own store holds. */\n store(): StoreResult | Promise<StoreResult>;\n /** Feature `faults`: answer a port as the kit asks. */\n script?(params: ScriptParams): void | Promise<void>;\n /** Feature `events`: read pages from the host's own named event stream. */\n events?(params: EventsParams): EventsResult | Promise<EventsResult>;\n}\n\nfunction invalid(method: string, message: string): RpcError {\n return new RpcError(\n createDiagnostic(\"MOSTRA_HOST_INVALID_PARAMS\", { message: `${method}: ${message}` }),\n -32602,\n );\n}\n\n/**\n * Serves the harness protocol on this process's stdin and stdout until stdin ends, then stops\n * the host's session and resolves.\n */\nexport function serveHarness(\n implementation: HarnessImplementation,\n io: { input?: NodeJS.ReadableStream; output?: NodeJS.WritableStream } = {},\n): Promise<void> {\n const input = io.input ?? process.stdin;\n const output = io.output ?? process.stdout;\n const peer = new RpcPeer({\n send: (message) => {\n output.write(encodeLine(message));\n },\n onRequest: async (method, params) => {\n switch (method) {\n case HARNESS_METHODS.initialize: {\n const revision = HARNESS_REVISIONS.at(-1) as string;\n return { revision, ...(await implementation.initialize()) };\n }\n case HARNESS_METHODS.start: {\n const parsed = StartParams.safeParse(params);\n if (!parsed.success) throw invalid(method, parsed.error.message);\n return await implementation.start(parsed.data);\n }\n case HARNESS_METHODS.call: {\n const parsed = CallParams.safeParse(params);\n if (!parsed.success) throw invalid(method, parsed.error.message);\n try {\n const result = await implementation.call(\n parsed.data.method,\n parsed.data.params,\n parsed.data.timeoutMs,\n );\n return { result: result ?? null } satisfies CallResult;\n } catch (error) {\n if (error instanceof RpcError)\n return {\n error: { code: error.code, data: { ...error.diagnostic } },\n } satisfies CallResult;\n throw error;\n }\n }\n case HARNESS_METHODS.stop:\n await implementation.stop();\n return {};\n case HARNESS_METHODS.store:\n return await implementation.store();\n case HARNESS_METHODS.script: {\n if (!implementation.script) break;\n const parsed = ScriptParams.safeParse(params);\n if (!parsed.success) throw invalid(method, parsed.error.message);\n await implementation.script(parsed.data);\n return {};\n }\n case HARNESS_METHODS.events: {\n if (!implementation.events) break;\n const parsed = EventsParams.safeParse(params);\n if (!parsed.success) throw invalid(method, parsed.error.message);\n return await implementation.events(parsed.data);\n }\n }\n throw new RpcError(\n createDiagnostic(\"MOSTRA_HOST_METHOD_UNKNOWN\", {\n message: `This host serves no harness method ${method}.`,\n }),\n -32601,\n );\n },\n onInternalError: (error, method) => {\n process.stderr.write(`harness: ${method} failed: ${(error as Error).stack ?? error}\\n`);\n },\n });\n const lines = new LineSplitter();\n (input as NodeJS.ReadStream).setEncoding?.(\"utf8\");\n input.on(\"data\", (chunk: string) => {\n for (const line of lines.push(chunk)) peer.receiveLine(line);\n });\n return new Promise((done) => {\n input.on(\"end\", () => {\n void Promise.resolve(implementation.stop())\n .catch(() => undefined)\n .finally(() => {\n peer.close();\n done();\n });\n });\n });\n}\n","#!/usr/bin/env node\n/**\n * `mostra-conformance-reference-host`: the TypeScript reference host (HO-05). A host built the way\n * the docs recommend, on `@mostra/sdk`, with a store that keeps each submission once by its\n * `deliveryId` (H-03), every port the SDK serves, and the harness shim the kit drives. It is the\n * model a TypeScript host copies, and the kit's own proof that its scenarios pass.\n *\n * mostra-conformance-reference-host every port\n * mostra-conformance-reference-host --standalone no port: Mostra's built-in adapters\n * mostra-conformance-reference-host --unscripted every port, without the `faults` feature:\n * its policy allows both channels and it names people by its own IDs (`user-1` …), so the\n * kit judges it by the answers it reports, as it must any host that can't be scripted\n * mostra-conformance-reference-host --break <fault,…> a deliberately broken host:\n * store-duplicates stores every delivery call, so a redelivery is stored twice\n * drafts-as-submissions takes draft mirrors for submissions\n * ignore-policy allows both channels whatever the kit scripted\n *\n * Its own runtime is found like any SDK host's (`MOSTRA_BUNDLE`, `MOSTRA_RUNTIME_BIN`, the pinned\n * bundle, a development checkout).\n */\nimport { realpathSync } from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport { parseArgs } from \"node:util\";\nimport {\n type ArtifactSummary,\n type ControlsPolicy,\n createDiagnostic,\n type DraftMirror,\n hostMethods,\n type PortIdentityResolveParams,\n type PortSecretsGetParams,\n type PortTrustedControlsActivatedParams,\n RpcError,\n type SubmissionEnvelope,\n type SubmissionsDeliverResult,\n} from \"@mostra/protocol\";\nimport { createMostra, type Mostra, type Ports } from \"@mostra/sdk\";\nimport type {\n EventsParams,\n EventsResult,\n ScriptParams,\n StartParams,\n StartResult,\n StoredDelivery,\n StoreResult,\n} from \"./harness/protocol.ts\";\nimport { serveHarness } from \"./harness/serve.ts\";\nimport { kitVersion } from \"./version.ts\";\n\n/** The faults a broken reference host can carry. */\nexport const REFERENCE_FAULTS: readonly string[] = [\n \"store-duplicates\",\n \"drafts-as-submissions\",\n \"ignore-policy\",\n];\n\n/** The reference host's store and port answers: what a real host keeps in its own database. */\nexport class ReferenceStore {\n readonly #deliveries = new Map<string, StoredDelivery & { attempts: number[] }>();\n readonly #drafts: StoreResult[\"drafts\"][number][] = [];\n readonly #activations: StoreResult[\"activations\"][number][] = [];\n readonly #identity: StoreResult[\"identity\"][number][] = [];\n readonly #policies: StoreResult[\"policies\"][number][] = [];\n readonly #secrets: StoreResult[\"secrets\"][number][] = [];\n readonly #faults: ReadonlySet<string>;\n #order = 0;\n /** How the scripted ports answer (feature `faults`). */\n #deliver: Extract<ScriptParams, { port: \"submissions\" }>[\"answer\"] = \"accept\";\n #policy: Extract<ScriptParams, { port: \"trustedControls\" }>[\"answer\"] = {\n submitChannels: [\"shell\"],\n controls: [\"submit\", \"choose\", \"approve\"],\n };\n #person: Extract<ScriptParams, { port: \"identity\" }>[\"answer\"] = \"headers\";\n #secretValues: Readonly<Record<string, string>> = {};\n\n /** People by the header that named them, for an unscripted host's own IDs. */\n readonly #people = new Map<string, string>();\n readonly #unscripted: boolean;\n\n constructor(faults: ReadonlySet<string> = new Set(), unscripted = false) {\n this.#faults = faults;\n this.#unscripted = unscripted;\n if (unscripted) this.#policy = { submitChannels: [\"artifact\", \"shell\"] };\n }\n\n /** Sets how a port answers from now on (feature `faults`). */\n script(params: ScriptParams): void {\n if (params.port === \"submissions\") this.#deliver = params.answer;\n else if (params.port === \"trustedControls\") this.#policy = params.answer;\n else if (params.port === \"identity\") this.#person = params.answer;\n else this.#secretValues = params.answer;\n }\n\n /** Records one delivery the way a host's database would: once per `deliveryId`. */\n #record(envelope: SubmissionEnvelope | (DraftMirror & { kind: string })): void {\n const id =\n \"deliveryId\" in envelope\n ? envelope.deliveryId\n : `draft-${envelope.viewerId}-${envelope.revision}`;\n const existing = this.#deliveries.get(id);\n const attempt = \"attempt\" in envelope ? envelope.attempt : 1;\n if (existing) {\n existing.attempts.push(attempt);\n (existing as { calls: number }).calls += 1;\n if (this.#faults.has(\"store-duplicates\")) (existing as { stored: number }).stored += 1;\n return;\n }\n const results = \"results\" in envelope ? envelope.results : undefined;\n this.#order += 1;\n this.#deliveries.set(id, {\n deliveryId: id,\n submissionId: results?.submission.id ?? \"\",\n artifactId: envelope.artifactId,\n calls: 1,\n stored: 1,\n attempts: [attempt],\n kind: envelope.kind,\n channel: results?.submission.channel ?? \"\",\n viewerKind: results?.submission.viewer.kind ?? \"\",\n ...(results?.submission.viewer.ref !== undefined\n ? { viewerRef: results.submission.viewer.ref }\n : {}),\n order: this.#order,\n });\n }\n\n /** The ports, as the SDK takes them. */\n ports(): Ports {\n return {\n submissions: {\n deliver: async (envelope: SubmissionEnvelope): Promise<SubmissionsDeliverResult> => {\n const answer = this.#deliver;\n if (answer === \"fail\") throw new Error(\"the host's store is unavailable\");\n if (answer === \"hang\") return new Promise(() => undefined);\n if (answer === \"retry\") return { accepted: false, reason: \"busy\", retry: true };\n if (answer === \"undeliverable\")\n return { accepted: false, reason: \"undeliverable\", retry: false };\n if (answer === \"reject\") return { accepted: false, reason: \"invalid\", retry: false };\n // A redelivery of a delivery the store holds is accepted again, never stored twice.\n this.#record(envelope);\n return { accepted: true };\n },\n },\n drafts: {\n mirror: (draft: DraftMirror) => {\n this.#drafts.push({\n artifactId: draft.artifactId,\n viewerId: draft.viewerId,\n revision: draft.revision,\n kind: draft.kind,\n });\n if (this.#faults.has(\"drafts-as-submissions\")) this.#record(draft);\n },\n },\n identity: {\n resolve: async (request: PortIdentityResolveParams) => {\n const call = {\n artifactId: request.artifactId,\n via: request.via,\n headers: Object.keys(request.headers).sort(),\n };\n const answer = this.#person;\n if (answer === \"fail\" || answer === \"hang\") {\n this.#identity.push(call);\n if (answer === \"fail\") throw new Error(\"the host's directory is unavailable\");\n return new Promise<never>(() => undefined);\n }\n let person: { ref: string; name?: string } | null = answer === \"headers\" ? null : answer;\n if (answer === \"headers\") {\n const user = request.headers[\"x-forwarded-user\"];\n if (user && this.#unscripted && !this.#people.has(user)) {\n this.#people.set(user, `user-${this.#people.size + 1}`);\n }\n const ref = user && this.#unscripted ? this.#people.get(user) : user;\n person = user && ref ? { ref, name: user.split(\"@\")[0] ?? user } : null;\n }\n this.#identity.push({ ...call, answer: person });\n return person;\n },\n },\n trustedControls: {\n policy: async (artifact: ArtifactSummary): Promise<ControlsPolicy> => {\n const answer = this.#policy;\n if (this.#faults.has(\"ignore-policy\")) {\n const both: ControlsPolicy = { submitChannels: [\"shell\", \"artifact\"] };\n this.#policies.push({ artifactId: artifact.id, answer: both });\n return both;\n }\n if (answer === \"fail\" || answer === \"hang\") {\n this.#policies.push({ artifactId: artifact.id });\n if (answer === \"fail\") throw new Error(\"the host's policy service is unavailable\");\n return new Promise<never>(() => undefined);\n }\n this.#policies.push({ artifactId: artifact.id, answer: answer as ControlsPolicy });\n return answer as ControlsPolicy;\n },\n activated: (event: PortTrustedControlsActivatedParams) => {\n this.#activations.push({\n artifactId: event.artifactId,\n control: event.control,\n viewId: event.viewId,\n });\n },\n },\n secrets: {\n get: (request: PortSecretsGetParams) => {\n this.#secrets.push({ artifactId: request.artifactId, name: request.name });\n return this.#secretValues[request.name] ?? null;\n },\n },\n };\n }\n\n /** What the store holds now. */\n snapshot(): StoreResult {\n return {\n deliveries: [...this.#deliveries.values()].sort((a, b) => a.order - b.order),\n drafts: [...this.#drafts],\n activations: [...this.#activations],\n identity: [...this.#identity],\n policies: [...this.#policies],\n secrets: [...this.#secrets],\n };\n }\n}\n\n/** Runs the reference host's harness on stdio. */\nexport async function runReferenceHost(\n options: { standalone?: boolean; unscripted?: boolean; faults?: readonly string[] } = {},\n): Promise<void> {\n const faults = new Set(options.faults ?? []);\n const unscripted = options.unscripted ?? false;\n const store = new ReferenceStore(faults, unscripted);\n let mostra: Mostra | undefined;\n const ports = options.standalone ? {} : store.ports();\n const portNames = Object.keys(ports);\n const name = options.standalone\n ? \"reference-host-ts-standalone\"\n : unscripted\n ? \"reference-host-ts-unscripted\"\n : faults.size > 0\n ? \"reference-host-ts-broken\"\n : \"reference-host-ts\";\n await serveHarness({\n initialize: () => ({\n host: { name, version: kitVersion() },\n ports: portNames,\n features: options.standalone || unscripted ? [\"events\"] : [\"faults\", \"events\"],\n }),\n async start(params: StartParams): Promise<StartResult> {\n if (params.mode === \"attach\") {\n throw new RpcError(\n createDiagnostic(\"MOSTRA_HOST_INVALID_PARAMS\", {\n message: \"The TypeScript reference host spawns its instance; it doesn't attach.\",\n }),\n );\n }\n await mostra?.close();\n mostra = await createMostra({\n home: params.home,\n client: { name, version: kitVersion() },\n ports,\n env: { ...process.env, ...params.env },\n onLog: () => undefined,\n });\n return {\n revision: mostra.revision,\n instance: mostra.instance,\n warnings: mostra.warnings,\n };\n },\n async call(method: string, params: unknown, timeoutMs?: number) {\n const definition = hostMethods.find((candidate) => candidate.method === method);\n if (!mostra) {\n throw new RpcError(\n createDiagnostic(\"MOSTRA_HOST_CONNECTION_CLOSED\", { message: \"No instance runs.\" }),\n );\n }\n if (!definition) {\n throw new RpcError(\n createDiagnostic(\"MOSTRA_HOST_METHOD_UNKNOWN\", { message: `No method ${method}.` }),\n -32601,\n );\n }\n return mostra.call(definition, params, timeoutMs !== undefined ? { timeoutMs } : {});\n },\n async stop() {\n const current = mostra;\n mostra = undefined;\n await current?.close();\n },\n store: () => store.snapshot(),\n ...(options.standalone || unscripted\n ? {}\n : { script: (params: ScriptParams) => store.script(params) }),\n async events(params: EventsParams): Promise<EventsResult> {\n if (!mostra) throw new Error(\"No instance runs.\");\n const pages: EventsResult[\"pages\"][number][] = [];\n const stream = mostra\n .events({\n name: params.name,\n filter: {\n ...(params.filter.artifacts ? { artifacts: [...params.filter.artifacts] } : {}),\n ...(params.filter.types ? { types: [...params.filter.types] } : {}),\n },\n })\n [Symbol.asyncIterator]();\n const deadline = Date.now() + params.timeoutMs;\n try {\n while (pages.length < params.pages) {\n const left = deadline - Date.now();\n if (left <= 0) break;\n const next = await Promise.race([\n stream.next(),\n new Promise<\"timeout\">((done) => setTimeout(() => done(\"timeout\"), left)),\n ]);\n if (next === \"timeout\" || next.done) break;\n pages.push({\n cursor: next.value.cursor,\n events: next.value.events.map((event) => ({ ...event })),\n });\n }\n } finally {\n // Asking for the next page is what tells the SDK the last one was handled: it acknowledges\n // it at once, then waits for a page this stream won't read, so the wait is cut short.\n await Promise.race([\n stream.next().catch(() => undefined),\n new Promise((done) => setTimeout(done, 1000)),\n ]);\n await stream.return?.();\n }\n return { pages };\n },\n });\n}\n\n/**\n * Whether this module is the program Node.js was started with: by file URL, which spells a\n * Windows path (`file:///D:/…`) as no string concatenation does, through any link, or as the\n * installed binary (`mostra-conformance-reference-host`, a link or npm's shim to `dist/`).\n */\nfunction isMain(): boolean {\n const entry = process.argv[1];\n if (entry === undefined) return false;\n try {\n if (pathToFileURL(realpathSync(entry)).href === import.meta.url) return true;\n } catch {\n // An entry that doesn't exist as a file is judged by its name alone.\n }\n return entry.endsWith(\"reference-host.js\");\n}\n\nif (isMain()) {\n const { values } = parseArgs({\n options: {\n standalone: { type: \"boolean\" },\n unscripted: { type: \"boolean\" },\n break: { type: \"string\" },\n },\n strict: true,\n });\n const faults = values.break ? values.break.split(\",\").filter(Boolean) : [];\n for (const fault of faults) {\n if (!REFERENCE_FAULTS.includes(fault)) {\n process.stderr.write(`Unknown fault ${fault}; known: ${REFERENCE_FAULTS.join(\", \")}\\n`);\n process.exit(2);\n }\n }\n void runReferenceHost({\n standalone: values.standalone ?? false,\n unscripted: values.unscripted ?? false,\n faults,\n }).then(() => process.exit(0));\n}\n"],"mappings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TS, ReferenceStore, runReferenceHost };
|
|
2
|
+
export { t as REFERENCE_FAULTS, n as ReferenceStore, r as runReferenceHost } from "./reference-host-D7fe25go.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { a as HARNESS_METHODS, d as StoreResult, f as kitVersion, i as EventsResult, n as CallResult, o as HARNESS_REVISIONS, s as InitializeResult, u as StartResult } from "./protocol-RQ9lbehE.js";
|
|
2
2
|
import { chmodSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, rmdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import * as z from "zod";
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
4
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import { BROWSER_PROTOCOL_REVISIONS, HOST_PROTOCOL_REVISIONS, LineSplitter, MutationId, RpcError, RpcPeer, createDiagnostic, deserializeAll, encodeLine, serializeAll } from "@mostra/protocol";
|
|
6
|
+
import { connectControl, resolveRuntime, windowsHelper } from "@mostra/sdk";
|
|
6
7
|
import { dirname, join } from "node:path";
|
|
7
|
-
import { connectControl, resolveRuntime } from "@mostra/sdk";
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
import { request } from "node:http";
|
|
10
10
|
//#region src/baseline.ts
|
|
@@ -109,6 +109,83 @@ const FIXTURES = {
|
|
|
109
109
|
actions: ACTIONS
|
|
110
110
|
};
|
|
111
111
|
//#endregion
|
|
112
|
+
//#region src/harness/tree.ts
|
|
113
|
+
/**
|
|
114
|
+
* A shim's process tree on Windows, for ending it when the shim won't close (Opus review of WP-W3,
|
|
115
|
+
* finding 3). Windows has no process groups: `taskkill /T` walks parent PIDs from a process that
|
|
116
|
+
* must still run, so once the shell a host command runs in has exited, its descendants can't be
|
|
117
|
+
* reached from its PID. The kit therefore notes the tree while the shell runs (the helper's
|
|
118
|
+
* `processes`: PID, parent and creation time of every process) and ends exactly those processes
|
|
119
|
+
* later with the helper's `reap`, which ends a process only while its creation time still matches,
|
|
120
|
+
* so a PID Windows handed to another process meanwhile is never touched.
|
|
121
|
+
*/
|
|
122
|
+
function created(entry) {
|
|
123
|
+
const match = /^win\/(\d+)$/.exec(entry.startTime ?? "");
|
|
124
|
+
return match ? BigInt(match[1]) : void 0;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* `root` and every process below it in `processes`. A process counts as a child of another only
|
|
128
|
+
* when it was created after it, since a parent PID outlives its process and can name a later one;
|
|
129
|
+
* processes without a creation time (another user's) are left out, as they can't be ended safely.
|
|
130
|
+
*/
|
|
131
|
+
function treeOf(processes, root) {
|
|
132
|
+
const byParent = /* @__PURE__ */ new Map();
|
|
133
|
+
for (const entry of processes) {
|
|
134
|
+
if (entry.ppid === void 0 || entry.ppid === entry.pid) continue;
|
|
135
|
+
const siblings = byParent.get(entry.ppid) ?? [];
|
|
136
|
+
siblings.push(entry);
|
|
137
|
+
byParent.set(entry.ppid, siblings);
|
|
138
|
+
}
|
|
139
|
+
const top = processes.find((entry) => entry.pid === root);
|
|
140
|
+
const topCreated = top ? created(top) : void 0;
|
|
141
|
+
if (top === void 0 || topCreated === void 0) return [];
|
|
142
|
+
const out = [{
|
|
143
|
+
pid: root,
|
|
144
|
+
startTime: top.startTime
|
|
145
|
+
}];
|
|
146
|
+
const queue = [[root, topCreated]];
|
|
147
|
+
const seen = /* @__PURE__ */ new Set([root]);
|
|
148
|
+
while (queue.length > 0) {
|
|
149
|
+
const [parent, parentCreated] = queue.shift();
|
|
150
|
+
for (const child of byParent.get(parent) ?? []) {
|
|
151
|
+
const born = created(child);
|
|
152
|
+
if (born === void 0 || born < parentCreated || seen.has(child.pid)) continue;
|
|
153
|
+
seen.add(child.pid);
|
|
154
|
+
out.push({
|
|
155
|
+
pid: child.pid,
|
|
156
|
+
startTime: child.startTime
|
|
157
|
+
});
|
|
158
|
+
queue.push([child.pid, born]);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
/** Runs the helper with `args`; its `result`, or `undefined` when it fails. */
|
|
164
|
+
function helperResult(helper, args) {
|
|
165
|
+
const run = spawnSync(helper, args, {
|
|
166
|
+
encoding: "utf8",
|
|
167
|
+
windowsHide: true,
|
|
168
|
+
timeout: 3e4
|
|
169
|
+
});
|
|
170
|
+
if (run.status !== 0) return void 0;
|
|
171
|
+
try {
|
|
172
|
+
const answer = JSON.parse(run.stdout);
|
|
173
|
+
return answer.ok === true ? answer.result : void 0;
|
|
174
|
+
} catch {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** The tree under `root` now, through the helper; empty when the helper can't list processes. */
|
|
179
|
+
function snapshotTree(helper, root) {
|
|
180
|
+
const listed = helperResult(helper, ["processes"]);
|
|
181
|
+
return Array.isArray(listed) ? treeOf(listed, root) : [];
|
|
182
|
+
}
|
|
183
|
+
/** Ends every member still running with its noted creation time (`mostra-win reap`). */
|
|
184
|
+
function endTree(helper, members) {
|
|
185
|
+
if (members.length === 0) return;
|
|
186
|
+
helperResult(helper, ["reap", ...members.map((member) => `${member.pid}:${member.startTime}`)]);
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
112
189
|
//#region src/harness/client.ts
|
|
113
190
|
/**
|
|
114
191
|
* The kit's side of the harness protocol: starts a host's shim (a command line), speaks to it
|
|
@@ -118,6 +195,8 @@ const FIXTURES = {
|
|
|
118
195
|
*/
|
|
119
196
|
/** How long one harness request may take before the kit gives up on the host. */
|
|
120
197
|
const HARNESS_TIMEOUT_MS = 12e4;
|
|
198
|
+
/** Whether the kit runs on Windows, where a shim's tree ends by `taskkill`. */
|
|
199
|
+
const WINDOWS = process.platform === "win32";
|
|
121
200
|
/** An instance's error, carried through the host: its diagnostic code and JSON-RPC code. */
|
|
122
201
|
var InstanceError = class extends Error {
|
|
123
202
|
/** The diagnostic code (`MOSTRA_…`). */
|
|
@@ -154,7 +233,8 @@ var HostUnderTest = class HostUnderTest {
|
|
|
154
233
|
...process.env,
|
|
155
234
|
...env
|
|
156
235
|
},
|
|
157
|
-
detached:
|
|
236
|
+
detached: !WINDOWS,
|
|
237
|
+
windowsHide: true
|
|
158
238
|
});
|
|
159
239
|
this.#exited = new Promise((done) => {
|
|
160
240
|
this.#child.on("close", (code) => done(code));
|
|
@@ -246,19 +326,46 @@ var HostUnderTest = class HostUnderTest {
|
|
|
246
326
|
async events(params) {
|
|
247
327
|
return EventsResult.parse(await this.#request(HARNESS_METHODS.events, params, params.timeoutMs + 3e4));
|
|
248
328
|
}
|
|
249
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Ends the shim: stdin closes, then SIGTERM to its process group, then SIGKILL. Windows has no
|
|
331
|
+
* process groups or signals (D150 item 6): there the kit notes the shell's process tree while it
|
|
332
|
+
* runs, and after 5 s ends the shell's tree (`taskkill /T`, while the shell lives) and every
|
|
333
|
+
* process it noted (`mostra-win reap`, which ends one only while its creation time matches), so
|
|
334
|
+
* a descendant of a shell that already exited is ended too (Opus review of WP-W3, finding 3).
|
|
335
|
+
*/
|
|
250
336
|
async close() {
|
|
251
|
-
this.#child.stdin?.end();
|
|
252
337
|
const pid = this.#child.pid;
|
|
338
|
+
const helper = WINDOWS && pid !== void 0 ? await windowsHelperOrNone() : void 0;
|
|
339
|
+
const tree = helper !== void 0 && pid !== void 0 ? snapshotTree(helper, pid) : [];
|
|
340
|
+
this.#child.stdin?.end();
|
|
341
|
+
const wait = (ms) => Promise.race([this.#exited.then(() => "exited"), new Promise((done) => setTimeout(() => done("waiting"), ms))]);
|
|
342
|
+
if (WINDOWS) {
|
|
343
|
+
if (await wait(5e3) === "waiting" && pid !== void 0) {
|
|
344
|
+
const system = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
345
|
+
spawnSync(`${system}\\System32\\taskkill.exe`, [
|
|
346
|
+
"/pid",
|
|
347
|
+
String(pid),
|
|
348
|
+
"/T",
|
|
349
|
+
"/F"
|
|
350
|
+
], {
|
|
351
|
+
stdio: "ignore",
|
|
352
|
+
windowsHide: true
|
|
353
|
+
});
|
|
354
|
+
if (helper !== void 0) endTree(helper, tree);
|
|
355
|
+
await wait(5e3);
|
|
356
|
+
}
|
|
357
|
+
this.#peer.close();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
253
360
|
const signal = (name) => {
|
|
254
361
|
if (pid === void 0) return;
|
|
255
362
|
try {
|
|
256
363
|
process.kill(-pid, name);
|
|
257
364
|
} catch {}
|
|
258
365
|
};
|
|
259
|
-
if (await
|
|
366
|
+
if (await wait(5e3) === "waiting") {
|
|
260
367
|
signal("SIGTERM");
|
|
261
|
-
if (await
|
|
368
|
+
if (await wait(5e3) === "waiting") signal("SIGKILL");
|
|
262
369
|
}
|
|
263
370
|
this.#peer.close();
|
|
264
371
|
}
|
|
@@ -268,6 +375,14 @@ function codeOf(error) {
|
|
|
268
375
|
if (error instanceof InstanceError) return error.code;
|
|
269
376
|
if (error instanceof RpcError) return error.diagnostic.code;
|
|
270
377
|
}
|
|
378
|
+
/** The Windows helper beside the runtime the kit resolves, or none (the tree then isn't noted). */
|
|
379
|
+
async function windowsHelperOrNone() {
|
|
380
|
+
try {
|
|
381
|
+
return windowsHelper(await resolveRuntime().catch(() => void 0), process.env);
|
|
382
|
+
} catch {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
271
386
|
//#endregion
|
|
272
387
|
//#region src/viewer.ts
|
|
273
388
|
/**
|
|
@@ -740,31 +855,46 @@ var ScenarioContext = class {
|
|
|
740
855
|
await session?.peer.request("mostra/shutdown", {}, { timeoutMs: 1e4 }).catch(() => void 0);
|
|
741
856
|
session?.close();
|
|
742
857
|
}
|
|
743
|
-
removeTree(this.dir);
|
|
858
|
+
await removeTree(this.dir);
|
|
744
859
|
}
|
|
745
860
|
};
|
|
746
861
|
/**
|
|
747
|
-
* Removes a scenario's directory. A home's versions are sealed read-only (
|
|
748
|
-
*
|
|
862
|
+
* Removes a scenario's directory. A home's versions are sealed read-only (DATA_MODEL §1): on POSIX
|
|
863
|
+
* by mode (files 0444, directories 0555), so directories are made writable first; on Windows by
|
|
864
|
+
* a protected access list (D150 item 3), which only the runtime's helper resets (`mostra-win
|
|
865
|
+
* unseal`, found beside the runtime as every client finds it). Windows also holds a file a process
|
|
866
|
+
* just closed (Defender, the indexer), so removal is retried for a while.
|
|
749
867
|
*/
|
|
750
|
-
function removeTree(dir) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
}
|
|
762
|
-
|
|
868
|
+
async function removeTree(dir) {
|
|
869
|
+
if (process.platform === "win32") {
|
|
870
|
+
const helper = windowsHelper(await resolveRuntime().catch(() => void 0), process.env);
|
|
871
|
+
await new Promise((done) => {
|
|
872
|
+
const child = spawn(helper, ["unseal", dir], {
|
|
873
|
+
stdio: "ignore",
|
|
874
|
+
windowsHide: true
|
|
875
|
+
});
|
|
876
|
+
child.on("exit", () => done());
|
|
877
|
+
child.on("error", () => done());
|
|
878
|
+
});
|
|
879
|
+
} else {
|
|
880
|
+
const open = (path) => {
|
|
881
|
+
let stats;
|
|
882
|
+
try {
|
|
883
|
+
stats = lstatSync(path);
|
|
884
|
+
} catch {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
if (!stats.isDirectory()) return;
|
|
888
|
+
chmodSync(path, 448);
|
|
889
|
+
for (const name of readdirSync(path)) open(join(path, name));
|
|
890
|
+
};
|
|
891
|
+
open(dir);
|
|
892
|
+
}
|
|
763
893
|
rmSync(dir, {
|
|
764
894
|
recursive: true,
|
|
765
895
|
force: true,
|
|
766
|
-
maxRetries:
|
|
767
|
-
retryDelay:
|
|
896
|
+
maxRetries: 10,
|
|
897
|
+
retryDelay: 300
|
|
768
898
|
});
|
|
769
899
|
}
|
|
770
900
|
/** Connects to an instance's socket and initializes a session as `@mostra/conformance`. */
|
|
@@ -913,10 +1043,14 @@ const DELIVERY_SCENARIOS = [
|
|
|
913
1043
|
const read = await context.results(artifactId);
|
|
914
1044
|
return read.submission.delivery === "pending" ? read : void 0;
|
|
915
1045
|
});
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
1046
|
+
await context.eventually("a submission.retrying event while the delivery waits (IN-13)", async () => {
|
|
1047
|
+
const retrying = await context.events({
|
|
1048
|
+
artifacts: [artifactId],
|
|
1049
|
+
types: ["submission.retrying"]
|
|
1050
|
+
});
|
|
1051
|
+
return retrying.events.length > 0 ? retrying : void 0;
|
|
1052
|
+
});
|
|
1053
|
+
check((await context.results(artifactId)).submission.delivery === "pending", "the delivery stopped waiting while the host still answered retry");
|
|
920
1054
|
await context.host.script({
|
|
921
1055
|
port: "submissions",
|
|
922
1056
|
answer: "accept"
|
|
@@ -1554,6 +1688,101 @@ const PORT_SCENARIOS = [
|
|
|
1554
1688
|
}
|
|
1555
1689
|
}
|
|
1556
1690
|
];
|
|
1691
|
+
//#endregion
|
|
1692
|
+
//#region src/privacy.ts
|
|
1693
|
+
/**
|
|
1694
|
+
* Whether a path of a host's home is owner-only, as the kit judges it (H-16, D44, D85, D150
|
|
1695
|
+
* item 3): on POSIX by its mode (`0700` for a directory, `0600` for a file); on Windows by its
|
|
1696
|
+
* access list, which allows no one but the user and `SYSTEM`, and for a directory is protected
|
|
1697
|
+
* (inherits nothing from above; a file inside inherits the directory's). Windows has no modes, and Node.js reads no access list, so the kit reads the
|
|
1698
|
+
* list's SDDL (the same in every language) through Windows PowerShell's `Get-Acl`, and the user's
|
|
1699
|
+
* SID through `whoami`.
|
|
1700
|
+
*/
|
|
1701
|
+
/** `SYSTEM`, as SDDL names it by alias and by SID. */
|
|
1702
|
+
const SYSTEM = /* @__PURE__ */ new Set(["SY", "S-1-5-18"]);
|
|
1703
|
+
/** `CREATOR OWNER`: an inheritable entry for whoever creates a child, which in an owner-only
|
|
1704
|
+
* directory only the user or `SYSTEM` can do (Opus review of WP-W3, finding 7). */
|
|
1705
|
+
const CREATOR_OWNER = /* @__PURE__ */ new Set(["CO", "S-1-3-0"]);
|
|
1706
|
+
/** The entry types that deny: they grant no one anything (finding 7). */
|
|
1707
|
+
const DENY = /* @__PURE__ */ new Set([
|
|
1708
|
+
"D",
|
|
1709
|
+
"OD",
|
|
1710
|
+
"XD"
|
|
1711
|
+
]);
|
|
1712
|
+
/** Whether an SDDL trustee (a SID or an alias) is the user `user` (a SID). */
|
|
1713
|
+
function isUser(trustee, user, aliases) {
|
|
1714
|
+
return trustee === user || Object.hasOwn(aliases, trustee) && aliases[trustee] === user;
|
|
1715
|
+
}
|
|
1716
|
+
/** What is wrong with `path`'s privacy, or `undefined` when it is owner-only. */
|
|
1717
|
+
function notOwnerOnly(path, platform = process.platform) {
|
|
1718
|
+
if (platform !== "win32") {
|
|
1719
|
+
const stats = statSync(path);
|
|
1720
|
+
const want = stats.isDirectory() ? 448 : 384;
|
|
1721
|
+
const mode = stats.mode & 511;
|
|
1722
|
+
return mode === want ? void 0 : `mode ${mode.toString(8)}, not ${want.toString(8)}`;
|
|
1723
|
+
}
|
|
1724
|
+
const { sddl, aliases } = windowsSddl(path);
|
|
1725
|
+
return judgeSddl(sddl, windowsUser(), statSync(path).isDirectory(), aliases);
|
|
1726
|
+
}
|
|
1727
|
+
/** What is wrong with a Windows access list (`sddl`) for the user `user` (a SID). */
|
|
1728
|
+
function judgeSddl(sddl, user, directory, aliases = {}) {
|
|
1729
|
+
const start = sddl.indexOf("D:");
|
|
1730
|
+
if (start < 0) return `no access list (${sddl})`;
|
|
1731
|
+
const rest = sddl.slice(start + 2);
|
|
1732
|
+
const end = rest.search(/S:/);
|
|
1733
|
+
const dacl = end < 0 ? rest : rest.slice(0, end);
|
|
1734
|
+
const flags = dacl.slice(0, dacl.indexOf("(") < 0 ? dacl.length : dacl.indexOf("("));
|
|
1735
|
+
if (flags.includes("NO_ACCESS_CONTROL")) return `its access list is NULL, which grants everyone access (${dacl})`;
|
|
1736
|
+
if (directory && !flags.includes("P")) return `its access list inherits from above (${dacl})`;
|
|
1737
|
+
for (const ace of dacl.matchAll(/\(([^)]*)\)/g)) {
|
|
1738
|
+
const [type, , , , , sid] = (ace[1] ?? "").split(";");
|
|
1739
|
+
if (type !== void 0 && DENY.has(type)) continue;
|
|
1740
|
+
if (sid === void 0 || !(isUser(sid, user, aliases) || SYSTEM.has(sid) || CREATOR_OWNER.has(sid))) return `it grants ${sid ?? "someone"} access (${dacl})`;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
function windowsUser() {
|
|
1744
|
+
const system = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
1745
|
+
const answer = spawnSync(`${system}\\System32\\whoami.exe`, [
|
|
1746
|
+
"/user",
|
|
1747
|
+
"/fo",
|
|
1748
|
+
"csv",
|
|
1749
|
+
"/nh"
|
|
1750
|
+
], {
|
|
1751
|
+
encoding: "utf8",
|
|
1752
|
+
windowsHide: true
|
|
1753
|
+
});
|
|
1754
|
+
const sid = /"(S-1-[0-9-]+)"/.exec(answer.stdout ?? "")?.[1];
|
|
1755
|
+
if (sid === void 0) throw new Error(`whoami named no SID: ${answer.stdout}${answer.stderr}`);
|
|
1756
|
+
return sid;
|
|
1757
|
+
}
|
|
1758
|
+
/** The path's SDDL, and the SIDs of this machine's `LA` and `LG` (absent when unresolvable). */
|
|
1759
|
+
function windowsSddl(path) {
|
|
1760
|
+
const system = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
1761
|
+
const answer = spawnSync(`${system}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`, [
|
|
1762
|
+
"-NoProfile",
|
|
1763
|
+
"-NonInteractive",
|
|
1764
|
+
"-Command",
|
|
1765
|
+
["(Get-Acl -LiteralPath $env:MOSTRA_KIT_PATH).Sddl", "foreach ($a in 'LA','LG') { try { $a + '=' + ([Security.Principal.SecurityIdentifier]$a).Value } catch { $a + '=' } }"].join("; ")
|
|
1766
|
+
], {
|
|
1767
|
+
encoding: "utf8",
|
|
1768
|
+
windowsHide: true,
|
|
1769
|
+
env: {
|
|
1770
|
+
...process.env,
|
|
1771
|
+
MOSTRA_KIT_PATH: path
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
const [sddl = "", ...rest] = (answer.stdout ?? "").trim().split(/\r?\n/);
|
|
1775
|
+
if (answer.status !== 0 || sddl.trim() === "") throw new Error(`Get-Acl couldn't read ${path}: ${answer.stderr}`);
|
|
1776
|
+
const aliases = {};
|
|
1777
|
+
for (const line of rest) {
|
|
1778
|
+
const match = /^(LA|LG)=(S-1-[0-9-]+)\s*$/.exec(line.trim());
|
|
1779
|
+
if (match) aliases[match[1]] = match[2];
|
|
1780
|
+
}
|
|
1781
|
+
return {
|
|
1782
|
+
sddl: sddl.trim(),
|
|
1783
|
+
aliases
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1557
1786
|
/** The session scenarios. */
|
|
1558
1787
|
const SESSION_SCENARIOS = [
|
|
1559
1788
|
{
|
|
@@ -1630,7 +1859,7 @@ const SESSION_SCENARIOS = [
|
|
|
1630
1859
|
"H-11"
|
|
1631
1860
|
],
|
|
1632
1861
|
async run(context) {
|
|
1633
|
-
same((await context.start()).instance.home, realpathSync(context.home), "the home the instance owns");
|
|
1862
|
+
same((await context.start()).instance.home, realpathSync.native(context.home), "the home the instance owns");
|
|
1634
1863
|
const receipt = await context.published(FORM);
|
|
1635
1864
|
const viewer = await context.viewer(receipt.artifactId);
|
|
1636
1865
|
const channel = viewer.ticket.submitChannels.includes("artifact") ? "artifact" : "shell";
|
|
@@ -1672,12 +1901,14 @@ const SESSION_SCENARIOS = [
|
|
|
1672
1901
|
async run(context) {
|
|
1673
1902
|
const started = await context.start();
|
|
1674
1903
|
check(JSON.parse(readFileSync(join(context.home, "config.json"), "utf8")).hostConfigured, "config.json has no hostConfigured mark (D140 item 4)");
|
|
1675
|
-
|
|
1904
|
+
const home = notOwnerOnly(context.home);
|
|
1905
|
+
check(home === void 0, `the home isn't owner-only: ${home}`);
|
|
1676
1906
|
await context.host.call("secret/set", {
|
|
1677
1907
|
name: "CONFORMANCE_TOKEN",
|
|
1678
1908
|
value: "kept-private-123"
|
|
1679
1909
|
});
|
|
1680
|
-
|
|
1910
|
+
const secret = notOwnerOnly(join(context.home, "secrets", "home", "CONFORMANCE_TOKEN"));
|
|
1911
|
+
check(secret === void 0, `a secret isn't owner-only: ${secret}`);
|
|
1681
1912
|
const status = await context.host.call("instance/status", {});
|
|
1682
1913
|
same(status.gateway?.bind, "127.0.0.1", "the gateway's bind address");
|
|
1683
1914
|
const elsewhere = await send({ url: `http://localhost:${new URL(status.gateway?.shell ?? "http://127.0.0.1:1").port}/` }).catch(() => void 0);
|
|
@@ -1933,4 +2164,4 @@ async function runConformance(options) {
|
|
|
1933
2164
|
//#endregion
|
|
1934
2165
|
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 };
|
|
1935
2166
|
|
|
1936
|
-
//# sourceMappingURL=runner-
|
|
2167
|
+
//# sourceMappingURL=runner-C8SO70qb.js.map
|