@mostra/conformance 0.5.0 → 0.6.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 +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 -1
- package/dist/{runner-BlBQXUFz.js → runner-C8SO70qb.js} +264 -33
- package/dist/runner-C8SO70qb.js.map +1 -0
- package/package.json +4 -4
- 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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shim's process tree on Windows, for ending it when the shim won't close (Opus review of WP-W3,
|
|
3
|
+
* finding 3). Windows has no process groups: `taskkill /T` walks parent PIDs from a process that
|
|
4
|
+
* must still run, so once the shell a host command runs in has exited, its descendants can't be
|
|
5
|
+
* reached from its PID. The kit therefore notes the tree while the shell runs (the helper's
|
|
6
|
+
* `processes`: PID, parent and creation time of every process) and ends exactly those processes
|
|
7
|
+
* later with the helper's `reap`, which ends a process only while its creation time still matches,
|
|
8
|
+
* so a PID Windows handed to another process meanwhile is never touched.
|
|
9
|
+
*/
|
|
10
|
+
import { spawnSync } from "node:child_process";
|
|
11
|
+
|
|
12
|
+
/** One process as `mostra-win processes` lists it. */
|
|
13
|
+
export interface ProcessEntry {
|
|
14
|
+
readonly pid: number;
|
|
15
|
+
readonly ppid?: number | undefined;
|
|
16
|
+
/** `win/<100 ns since 1601>`; absent for a process this user can't open. */
|
|
17
|
+
readonly startTime?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A process to end later: its PID and creation time. */
|
|
21
|
+
export interface TreeMember {
|
|
22
|
+
readonly pid: number;
|
|
23
|
+
readonly startTime: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function created(entry: ProcessEntry): bigint | undefined {
|
|
27
|
+
const match = /^win\/(\d+)$/.exec(entry.startTime ?? "");
|
|
28
|
+
return match ? BigInt(match[1] as string) : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* `root` and every process below it in `processes`. A process counts as a child of another only
|
|
33
|
+
* when it was created after it, since a parent PID outlives its process and can name a later one;
|
|
34
|
+
* processes without a creation time (another user's) are left out, as they can't be ended safely.
|
|
35
|
+
*/
|
|
36
|
+
export function treeOf(processes: readonly ProcessEntry[], root: number): TreeMember[] {
|
|
37
|
+
const byParent = new Map<number, ProcessEntry[]>();
|
|
38
|
+
for (const entry of processes) {
|
|
39
|
+
if (entry.ppid === undefined || entry.ppid === entry.pid) continue;
|
|
40
|
+
const siblings = byParent.get(entry.ppid) ?? [];
|
|
41
|
+
siblings.push(entry);
|
|
42
|
+
byParent.set(entry.ppid, siblings);
|
|
43
|
+
}
|
|
44
|
+
const top = processes.find((entry) => entry.pid === root);
|
|
45
|
+
const topCreated = top ? created(top) : undefined;
|
|
46
|
+
if (top === undefined || topCreated === undefined) return [];
|
|
47
|
+
const out: TreeMember[] = [{ pid: root, startTime: top.startTime as string }];
|
|
48
|
+
const queue: [number, bigint][] = [[root, topCreated]];
|
|
49
|
+
const seen = new Set([root]);
|
|
50
|
+
while (queue.length > 0) {
|
|
51
|
+
const [parent, parentCreated] = queue.shift() as [number, bigint];
|
|
52
|
+
for (const child of byParent.get(parent) ?? []) {
|
|
53
|
+
const born = created(child);
|
|
54
|
+
if (born === undefined || born < parentCreated || seen.has(child.pid)) continue;
|
|
55
|
+
seen.add(child.pid);
|
|
56
|
+
out.push({ pid: child.pid, startTime: child.startTime as string });
|
|
57
|
+
queue.push([child.pid, born]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Runs the helper with `args`; its `result`, or `undefined` when it fails. */
|
|
64
|
+
function helperResult(helper: string, args: readonly string[]): unknown {
|
|
65
|
+
const run = spawnSync(helper, args, { encoding: "utf8", windowsHide: true, timeout: 30_000 });
|
|
66
|
+
if (run.status !== 0) return undefined;
|
|
67
|
+
try {
|
|
68
|
+
const answer = JSON.parse(run.stdout) as { ok?: boolean; result?: unknown };
|
|
69
|
+
return answer.ok === true ? answer.result : undefined;
|
|
70
|
+
} catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The tree under `root` now, through the helper; empty when the helper can't list processes. */
|
|
76
|
+
export function snapshotTree(helper: string, root: number): TreeMember[] {
|
|
77
|
+
const listed = helperResult(helper, ["processes"]);
|
|
78
|
+
return Array.isArray(listed) ? treeOf(listed as ProcessEntry[], root) : [];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Ends every member still running with its noted creation time (`mostra-win reap`). */
|
|
82
|
+
export function endTree(helper: string, members: readonly TreeMember[]): void {
|
|
83
|
+
if (members.length === 0) return;
|
|
84
|
+
helperResult(helper, ["reap", ...members.map((member) => `${member.pid}:${member.startTime}`)]);
|
|
85
|
+
}
|
package/src/privacy.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a path of a host's home is owner-only, as the kit judges it (H-16, D44, D85, D150
|
|
3
|
+
* item 3): on POSIX by its mode (`0700` for a directory, `0600` for a file); on Windows by its
|
|
4
|
+
* access list, which allows no one but the user and `SYSTEM`, and for a directory is protected
|
|
5
|
+
* (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
|
|
6
|
+
* list's SDDL (the same in every language) through Windows PowerShell's `Get-Acl`, and the user's
|
|
7
|
+
* SID through `whoami`.
|
|
8
|
+
*/
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { statSync } from "node:fs";
|
|
11
|
+
|
|
12
|
+
/** `SYSTEM`, as SDDL names it by alias and by SID. */
|
|
13
|
+
const SYSTEM = new Set(["SY", "S-1-5-18"]);
|
|
14
|
+
|
|
15
|
+
/** `CREATOR OWNER`: an inheritable entry for whoever creates a child, which in an owner-only
|
|
16
|
+
* directory only the user or `SYSTEM` can do (Opus review of WP-W3, finding 7). */
|
|
17
|
+
const CREATOR_OWNER = new Set(["CO", "S-1-3-0"]);
|
|
18
|
+
|
|
19
|
+
/** The entry types that deny: they grant no one anything (finding 7). */
|
|
20
|
+
const DENY = new Set(["D", "OD", "XD"]);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The SIDs this machine's own account aliases stand for: SDDL writes the built-in Administrator
|
|
24
|
+
* (`LA`) and Guest (`LG`) of the local machine by alias (GitHub's runners run as the former). An
|
|
25
|
+
* alias is the user only when it resolves to exactly the user's SID, never by its relative ID
|
|
26
|
+
* alone: a domain's Administrator ends in -500 too (finding 6). An alias that couldn't be resolved
|
|
27
|
+
* is no one's, so its entry fails the check.
|
|
28
|
+
*/
|
|
29
|
+
export type AccountAliases = Readonly<Record<string, string>>;
|
|
30
|
+
|
|
31
|
+
/** Whether an SDDL trustee (a SID or an alias) is the user `user` (a SID). */
|
|
32
|
+
function isUser(trustee: string, user: string, aliases: AccountAliases): boolean {
|
|
33
|
+
return trustee === user || (Object.hasOwn(aliases, trustee) && aliases[trustee] === user);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What is wrong with `path`'s privacy, or `undefined` when it is owner-only. */
|
|
37
|
+
export function notOwnerOnly(
|
|
38
|
+
path: string,
|
|
39
|
+
platform: string = process.platform,
|
|
40
|
+
): string | undefined {
|
|
41
|
+
if (platform !== "win32") {
|
|
42
|
+
const stats = statSync(path);
|
|
43
|
+
const want = stats.isDirectory() ? 0o700 : 0o600;
|
|
44
|
+
const mode = stats.mode & 0o777;
|
|
45
|
+
return mode === want ? undefined : `mode ${mode.toString(8)}, not ${want.toString(8)}`;
|
|
46
|
+
}
|
|
47
|
+
const { sddl, aliases } = windowsSddl(path);
|
|
48
|
+
return judgeSddl(sddl, windowsUser(), statSync(path).isDirectory(), aliases);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** What is wrong with a Windows access list (`sddl`) for the user `user` (a SID). */
|
|
52
|
+
export function judgeSddl(
|
|
53
|
+
sddl: string,
|
|
54
|
+
user: string,
|
|
55
|
+
directory: boolean,
|
|
56
|
+
aliases: AccountAliases = {},
|
|
57
|
+
): string | undefined {
|
|
58
|
+
const start = sddl.indexOf("D:");
|
|
59
|
+
if (start < 0) return `no access list (${sddl})`;
|
|
60
|
+
const rest = sddl.slice(start + 2);
|
|
61
|
+
const end = rest.search(/S:/);
|
|
62
|
+
const dacl = end < 0 ? rest : rest.slice(0, end);
|
|
63
|
+
const flags = dacl.slice(0, dacl.indexOf("(") < 0 ? dacl.length : dacl.indexOf("("));
|
|
64
|
+
// A NULL access list (the flag `NO_ACCESS_CONTROL`, beside any others) holds no entry and
|
|
65
|
+
// grants everyone everything (GPT review of WP-W3).
|
|
66
|
+
if (flags.includes("NO_ACCESS_CONTROL"))
|
|
67
|
+
return `its access list is NULL, which grants everyone access (${dacl})`;
|
|
68
|
+
if (directory && !flags.includes("P")) return `its access list inherits from above (${dacl})`;
|
|
69
|
+
for (const ace of dacl.matchAll(/\(([^)]*)\)/g)) {
|
|
70
|
+
const fields = (ace[1] ?? "").split(";");
|
|
71
|
+
const [type, , , , , sid] = fields;
|
|
72
|
+
if (type !== undefined && DENY.has(type)) continue;
|
|
73
|
+
if (
|
|
74
|
+
sid === undefined ||
|
|
75
|
+
!(isUser(sid, user, aliases) || SYSTEM.has(sid) || CREATOR_OWNER.has(sid))
|
|
76
|
+
) {
|
|
77
|
+
return `it grants ${sid ?? "someone"} access (${dacl})`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function windowsUser(): string {
|
|
84
|
+
// Windows' own, by path: a `whoami` earlier on `PATH` (Git's coreutils) takes no `/user`.
|
|
85
|
+
const system = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
86
|
+
const answer = spawnSync(`${system}\\System32\\whoami.exe`, ["/user", "/fo", "csv", "/nh"], {
|
|
87
|
+
encoding: "utf8",
|
|
88
|
+
windowsHide: true,
|
|
89
|
+
});
|
|
90
|
+
const sid = /"(S-1-[0-9-]+)"/.exec(answer.stdout ?? "")?.[1];
|
|
91
|
+
if (sid === undefined) throw new Error(`whoami named no SID: ${answer.stdout}${answer.stderr}`);
|
|
92
|
+
return sid;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The path's SDDL, and the SIDs of this machine's `LA` and `LG` (absent when unresolvable). */
|
|
96
|
+
function windowsSddl(path: string): { sddl: string; aliases: AccountAliases } {
|
|
97
|
+
const system = process.env["SystemRoot"] ?? "C:\\Windows";
|
|
98
|
+
const answer = spawnSync(
|
|
99
|
+
`${system}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,
|
|
100
|
+
[
|
|
101
|
+
"-NoProfile",
|
|
102
|
+
"-NonInteractive",
|
|
103
|
+
"-Command",
|
|
104
|
+
[
|
|
105
|
+
"(Get-Acl -LiteralPath $env:MOSTRA_KIT_PATH).Sddl",
|
|
106
|
+
// Single quotes only: Windows PowerShell 5 takes double quotes in `-Command` apart.
|
|
107
|
+
"foreach ($a in 'LA','LG') { try { $a + '=' + ([Security.Principal.SecurityIdentifier]$a).Value } catch { $a + '=' } }",
|
|
108
|
+
].join("; "),
|
|
109
|
+
],
|
|
110
|
+
{ encoding: "utf8", windowsHide: true, env: { ...process.env, MOSTRA_KIT_PATH: path } },
|
|
111
|
+
);
|
|
112
|
+
const [sddl = "", ...rest] = (answer.stdout ?? "").trim().split(/\r?\n/);
|
|
113
|
+
if (answer.status !== 0 || sddl.trim() === "") {
|
|
114
|
+
throw new Error(`Get-Acl couldn't read ${path}: ${answer.stderr}`);
|
|
115
|
+
}
|
|
116
|
+
const aliases: Record<string, string> = {};
|
|
117
|
+
for (const line of rest) {
|
|
118
|
+
const match = /^(LA|LG)=(S-1-[0-9-]+)\s*$/.exec(line.trim());
|
|
119
|
+
if (match) aliases[match[1] as string] = match[2] as string;
|
|
120
|
+
}
|
|
121
|
+
return { sddl: sddl.trim(), aliases };
|
|
122
|
+
}
|
package/src/reference-host.ts
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* Its own runtime is found like any SDK host's (`MOSTRA_BUNDLE`, `MOSTRA_RUNTIME_BIN`, the pinned
|
|
19
19
|
* bundle, a development checkout).
|
|
20
20
|
*/
|
|
21
|
+
import { realpathSync } from "node:fs";
|
|
22
|
+
import { pathToFileURL } from "node:url";
|
|
21
23
|
import { parseArgs } from "node:util";
|
|
22
24
|
import {
|
|
23
25
|
type ArtifactSummary,
|
|
@@ -332,10 +334,23 @@ export async function runReferenceHost(
|
|
|
332
334
|
});
|
|
333
335
|
}
|
|
334
336
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
)
|
|
337
|
+
/**
|
|
338
|
+
* Whether this module is the program Node.js was started with: by file URL, which spells a
|
|
339
|
+
* Windows path (`file:///D:/…`) as no string concatenation does, through any link, or as the
|
|
340
|
+
* installed binary (`mostra-conformance-reference-host`, a link or npm's shim to `dist/`).
|
|
341
|
+
*/
|
|
342
|
+
function isMain(): boolean {
|
|
343
|
+
const entry = process.argv[1];
|
|
344
|
+
if (entry === undefined) return false;
|
|
345
|
+
try {
|
|
346
|
+
if (pathToFileURL(realpathSync(entry)).href === import.meta.url) return true;
|
|
347
|
+
} catch {
|
|
348
|
+
// An entry that doesn't exist as a file is judged by its name alone.
|
|
349
|
+
}
|
|
350
|
+
return entry.endsWith("reference-host.js");
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (isMain()) {
|
|
339
354
|
const { values } = parseArgs({
|
|
340
355
|
options: {
|
|
341
356
|
standalone: { type: "boolean" },
|
package/src/scenario.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* have, checked through the host's own client and ports (the harness) and a viewer playing the
|
|
4
4
|
* browser. Each runs against a fresh home in its own directory, with a fresh host shim.
|
|
5
5
|
*/
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
6
7
|
import {
|
|
7
8
|
chmodSync,
|
|
8
9
|
lstatSync,
|
|
@@ -23,7 +24,7 @@ import {
|
|
|
23
24
|
RpcError,
|
|
24
25
|
RpcPeer,
|
|
25
26
|
} from "@mostra/protocol";
|
|
26
|
-
import { connectControl, resolveRuntime } from "@mostra/sdk";
|
|
27
|
+
import { connectControl, resolveRuntime, windowsHelper } from "@mostra/sdk";
|
|
27
28
|
import type { Fixture } from "./fixtures.ts";
|
|
28
29
|
import { HostUnderTest } from "./harness/client.ts";
|
|
29
30
|
import type { StartParams, StartResult, StoreResult } from "./harness/protocol.ts";
|
|
@@ -302,28 +303,40 @@ export class ScenarioContext {
|
|
|
302
303
|
.catch(() => undefined);
|
|
303
304
|
session?.close();
|
|
304
305
|
}
|
|
305
|
-
removeTree(this.dir);
|
|
306
|
+
await removeTree(this.dir);
|
|
306
307
|
}
|
|
307
308
|
}
|
|
308
309
|
|
|
309
310
|
/**
|
|
310
|
-
* Removes a scenario's directory. A home's versions are sealed read-only (
|
|
311
|
-
*
|
|
311
|
+
* Removes a scenario's directory. A home's versions are sealed read-only (DATA_MODEL §1): on POSIX
|
|
312
|
+
* by mode (files 0444, directories 0555), so directories are made writable first; on Windows by
|
|
313
|
+
* a protected access list (D150 item 3), which only the runtime's helper resets (`mostra-win
|
|
314
|
+
* unseal`, found beside the runtime as every client finds it). Windows also holds a file a process
|
|
315
|
+
* just closed (Defender, the indexer), so removal is retried for a while.
|
|
312
316
|
*/
|
|
313
|
-
export function removeTree(dir: string): void {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
317
|
+
export async function removeTree(dir: string): Promise<void> {
|
|
318
|
+
if (process.platform === "win32") {
|
|
319
|
+
const helper = windowsHelper(await resolveRuntime().catch(() => undefined), process.env);
|
|
320
|
+
await new Promise<void>((done) => {
|
|
321
|
+
const child = spawn(helper, ["unseal", dir], { stdio: "ignore", windowsHide: true });
|
|
322
|
+
child.on("exit", () => done());
|
|
323
|
+
child.on("error", () => done());
|
|
324
|
+
});
|
|
325
|
+
} else {
|
|
326
|
+
const open = (path: string): void => {
|
|
327
|
+
let stats: ReturnType<typeof lstatSync>;
|
|
328
|
+
try {
|
|
329
|
+
stats = lstatSync(path);
|
|
330
|
+
} catch {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (!stats.isDirectory()) return;
|
|
334
|
+
chmodSync(path, 0o700);
|
|
335
|
+
for (const name of readdirSync(path)) open(join(path, name));
|
|
336
|
+
};
|
|
337
|
+
open(dir);
|
|
338
|
+
}
|
|
339
|
+
rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 300 });
|
|
327
340
|
}
|
|
328
341
|
|
|
329
342
|
/** A raw protocol session over the home's socket, opened by the kit itself. */
|
|
@@ -116,13 +116,22 @@ export const retry: Scenario = {
|
|
|
116
116
|
const read = await context.results(artifactId);
|
|
117
117
|
return read.submission.delivery === "pending" ? read : undefined;
|
|
118
118
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
// A delivery reads pending from the moment it is enqueued, before its first attempt; the
|
|
120
|
+
// event follows the host's first retry answer, so it is waited for, while the host still
|
|
121
|
+
// answers retry and the delivery still waits (it once ran before the first answer, under load).
|
|
122
|
+
await context.eventually(
|
|
123
|
+
"a submission.retrying event while the delivery waits (IN-13)",
|
|
124
|
+
async () => {
|
|
125
|
+
const retrying = await context.events({
|
|
126
|
+
artifacts: [artifactId],
|
|
127
|
+
types: ["submission.retrying"],
|
|
128
|
+
});
|
|
129
|
+
return retrying.events.length > 0 ? retrying : undefined;
|
|
130
|
+
},
|
|
131
|
+
);
|
|
123
132
|
check(
|
|
124
|
-
|
|
125
|
-
"
|
|
133
|
+
(await context.results(artifactId)).submission.delivery === "pending",
|
|
134
|
+
"the delivery stopped waiting while the host still answered retry",
|
|
126
135
|
);
|
|
127
136
|
await context.host.script({ port: "submissions", answer: "accept" });
|
|
128
137
|
await context.eventually(
|
package/src/scenarios/session.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { join } from "node:path";
|
|
|
7
7
|
import { HOST_PROTOCOL_REVISIONS } from "@mostra/protocol";
|
|
8
8
|
import { FORM } from "../fixtures.ts";
|
|
9
9
|
import { codeOf } from "../harness/client.ts";
|
|
10
|
+
import { notOwnerOnly } from "../privacy.ts";
|
|
10
11
|
import { check, connectSocket, rpcCode, type Scenario, same } from "../scenario.ts";
|
|
11
12
|
import { send } from "../viewer.ts";
|
|
12
13
|
|
|
@@ -104,7 +105,9 @@ export const authoringRemoved: Scenario = {
|
|
|
104
105
|
covers: ["HO-05", "HO-08", "H-11"],
|
|
105
106
|
async run(context) {
|
|
106
107
|
const started = await context.start();
|
|
107
|
-
|
|
108
|
+
// The instance spells its home as the system does (D151 item 5): links followed, Windows'
|
|
109
|
+
// 8.3 short names written out.
|
|
110
|
+
same(started.instance.home, realpathSync.native(context.home), "the home the instance owns");
|
|
108
111
|
const receipt = await context.published(FORM);
|
|
109
112
|
const viewer = await context.viewer(receipt.artifactId);
|
|
110
113
|
const channel = viewer.ticket.submitChannels.includes("artifact") ? "artifact" : "shell";
|
|
@@ -151,13 +154,13 @@ export const privacy: Scenario = {
|
|
|
151
154
|
hostConfigured?: { client: string };
|
|
152
155
|
};
|
|
153
156
|
check(config.hostConfigured, "config.json has no hostConfigured mark (D140 item 4)");
|
|
154
|
-
|
|
157
|
+
// Owner-only: modes 0700 and 0600 on POSIX, an access list for the user and SYSTEM alone on
|
|
158
|
+
// Windows (D150 item 3).
|
|
159
|
+
const home = notOwnerOnly(context.home);
|
|
160
|
+
check(home === undefined, `the home isn't owner-only: ${home}`);
|
|
155
161
|
await context.host.call("secret/set", { name: "CONFORMANCE_TOKEN", value: "kept-private-123" });
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
0o600,
|
|
159
|
-
"a secret's mode",
|
|
160
|
-
);
|
|
162
|
+
const secret = notOwnerOnly(join(context.home, "secrets", "home", "CONFORMANCE_TOKEN"));
|
|
163
|
+
check(secret === undefined, `a secret isn't owner-only: ${secret}`);
|
|
161
164
|
const status = await context.host.call<{ gateway?: { bind: string; shell: string } }>(
|
|
162
165
|
"instance/status",
|
|
163
166
|
{},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reference-host-d6gs3Tal.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 { 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\nif (\n import.meta.url === `file://${process.argv[1]}` ||\n process.argv[1]?.endsWith(\"reference-host.js\")\n) {\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":";;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAS,QAAQ,QAAgB,SAA2B;CAC1D,OAAO,IAAI,SACT,iBAAiB,8BAA8B,EAAE,SAAS,GAAG,OAAO,IAAI,UAAU,CAAC,GACnF,MACF;AACF;;;;;AAMA,SAAgB,aACd,gBACA,KAAwE,CAAC,GAC1D;CACf,MAAM,QAAQ,GAAG,SAAS,QAAQ;CAClC,MAAM,SAAS,GAAG,UAAU,QAAQ;CACpC,MAAM,OAAO,IAAI,QAAQ;EACvB,OAAO,YAAY;GACjB,OAAO,MAAM,WAAW,OAAO,CAAC;EAClC;EACA,WAAW,OAAO,QAAQ,WAAW;GACnC,QAAQ,QAAR;IACE,KAAK,gBAAgB,YAEnB,OAAO;KAAE,UADQ,kBAAkB,GAAG,EACtB;KAAG,GAAI,MAAM,eAAe,WAAW;IAAG;IAE5D,KAAK,gBAAgB,OAAO;KAC1B,MAAM,SAAS,YAAY,UAAU,MAAM;KAC3C,IAAI,CAAC,OAAO,SAAS,MAAM,QAAQ,QAAQ,OAAO,MAAM,OAAO;KAC/D,OAAO,MAAM,eAAe,MAAM,OAAO,IAAI;IAC/C;IACA,KAAK,gBAAgB,MAAM;KACzB,MAAM,SAAS,WAAW,UAAU,MAAM;KAC1C,IAAI,CAAC,OAAO,SAAS,MAAM,QAAQ,QAAQ,OAAO,MAAM,OAAO;KAC/D,IAAI;MAMF,OAAO,EAAE,QAAQ,MALI,eAAe,KAClC,OAAO,KAAK,QACZ,OAAO,KAAK,QACZ,OAAO,KAAK,SACd,KAC2B,KAAK;KAClC,SAAS,OAAO;MACd,IAAI,iBAAiB,UACnB,OAAO,EACL,OAAO;OAAE,MAAM,MAAM;OAAM,MAAM,EAAE,GAAG,MAAM,WAAW;MAAE,EAC3D;MACF,MA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