@openmixer/plugin-qualify 0.18.0 → 0.18.2

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.
Files changed (73) hide show
  1. package/README.md +93 -3
  2. package/bin/plugin-qualify-sync.mjs +3 -1
  3. package/dist/clap-qualify.d.ts +3 -1
  4. package/dist/clap-qualify.js +3 -1
  5. package/dist/clap-qualify.js.map +1 -1
  6. package/dist/distributed-records.d.ts +4 -2
  7. package/dist/distributed-records.js +1 -1
  8. package/dist/distributed-records.js.map +1 -1
  9. package/dist/host-admission.d.ts +21 -0
  10. package/dist/host-admission.js +33 -3
  11. package/dist/host-admission.js.map +1 -1
  12. package/dist/hostd-pin-files.js +3 -1
  13. package/dist/hostd-pin-files.js.map +1 -1
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/measurement/format.d.ts +10 -0
  18. package/dist/measurement/format.js +8 -0
  19. package/dist/measurement/format.js.map +1 -1
  20. package/dist/measurement/probe-json.js +2 -1
  21. package/dist/measurement/probe-json.js.map +1 -1
  22. package/dist/probe-judge.d.ts +11 -0
  23. package/dist/probe-judge.js +6 -3
  24. package/dist/probe-judge.js.map +1 -1
  25. package/dist/probe-runner.js +3 -2
  26. package/dist/probe-runner.js.map +1 -1
  27. package/dist/qualification-record.d.ts +113 -8
  28. package/dist/qualification-record.js +18 -13
  29. package/dist/qualification-record.js.map +1 -1
  30. package/dist/qualify-adapter-pass.d.ts +67 -0
  31. package/dist/qualify-adapter-pass.js +255 -0
  32. package/dist/qualify-adapter-pass.js.map +1 -0
  33. package/dist/qualify-declarations.d.ts +30 -0
  34. package/dist/qualify-declarations.js +24 -1
  35. package/dist/qualify-declarations.js.map +1 -1
  36. package/dist/qualify-isolated.d.ts +70 -0
  37. package/dist/qualify-isolated.js +184 -0
  38. package/dist/qualify-isolated.js.map +1 -0
  39. package/dist/qualify-rejudge.d.ts +82 -0
  40. package/dist/qualify-rejudge.js +434 -0
  41. package/dist/qualify-rejudge.js.map +1 -0
  42. package/dist/qualify-sync.d.ts +97 -1
  43. package/dist/qualify-sync.js +276 -24
  44. package/dist/qualify-sync.js.map +1 -1
  45. package/fixtures/records-0.16.1/http___example.org_raffo@unversioned-2060c09ff626.default.probe.json +46 -0
  46. package/fixtures/records-0.16.1/http___example.org_raffo@unversioned-2060c09ff626.default.qualification.json +185 -0
  47. package/fixtures/records-0.16.1/http___lv2plug.in_plugins_eg-amp@unversioned-f046a60efd45.default.probe.json +51 -0
  48. package/fixtures/records-0.16.1/http___lv2plug.in_plugins_eg-amp@unversioned-f046a60efd45.default.qualification.json +232 -0
  49. package/fixtures/records-0.16.1/https___github.com_lucianodato_noise-repellent@unversioned-c3b5e21dd9a7.default.probe.json +51 -0
  50. package/fixtures/records-0.16.1/https___github.com_lucianodato_noise-repellent@unversioned-c3b5e21dd9a7.default.qualification.json +245 -0
  51. package/fixtures/records-0.16.1/in.lsp-plug.impulse_responses_mono@unversioned-d5235d2f5f53.custom.probe.json +52 -0
  52. package/fixtures/records-0.16.1/in.lsp-plug.impulse_responses_mono@unversioned-d5235d2f5f53.custom.qualification.json +145 -0
  53. package/fixtures/records-0.16.1/in.lsp-plug.trigger_midi_mono@unversioned-d5235d2f5f53.custom.probe.json +52 -0
  54. package/fixtures/records-0.16.1/in.lsp-plug.trigger_midi_mono@unversioned-d5235d2f5f53.custom.qualification.json +155 -0
  55. package/package.json +1 -1
  56. package/src/clap-qualify.ts +5 -1
  57. package/src/distributed-records.ts +1 -1
  58. package/src/host-admission.ts +40 -3
  59. package/src/hostd-pin-files.ts +3 -1
  60. package/src/index.ts +2 -0
  61. package/src/measurement/format.ts +17 -0
  62. package/src/measurement/probe-json.ts +2 -1
  63. package/src/probe-judge.ts +10 -3
  64. package/src/probe-runner.ts +2 -2
  65. package/src/qualification-record.ts +126 -15
  66. package/src/qualify-adapter-pass.ts +278 -0
  67. package/src/qualify-declarations.ts +26 -1
  68. package/src/qualify-isolated.ts +201 -0
  69. package/src/qualify-rejudge.ts +466 -0
  70. package/src/qualify-sync.ts +295 -24
  71. package/tools/isolated-step.mjs +122 -0
  72. package/tools/lv2_resolve.py +49 -0
  73. package/tools/mod-host-admit.mjs +99 -7
@@ -43,6 +43,52 @@ export interface RecordVerdict {
43
43
  readonly reasons: readonly RecordReason[];
44
44
  }
45
45
 
46
+ /**
47
+ * An LV2 plugin's run under the adapter. The top is what the judge reads. `--adapter-only` adds the versions of the hosts
48
+ * it ran under, when, and how each cell went.
49
+ */
50
+ export interface AdapterBlock {
51
+ readonly host: string;
52
+ readonly measured: boolean;
53
+ readonly admitted: boolean;
54
+ readonly code?: string;
55
+ readonly params: Readonly<Record<string, string | number>>;
56
+ readonly versions?: Readonly<Record<string, string>>;
57
+ readonly measuredAt?: string;
58
+ readonly cells?: readonly {
59
+ readonly rate: number;
60
+ readonly quantum: number;
61
+ readonly measured: boolean;
62
+ readonly admitted: boolean;
63
+ readonly code?: string;
64
+ readonly params: Readonly<Record<string, string | number>>;
65
+ }[];
66
+ }
67
+
68
+ /** What the isolated step measured over its window. */
69
+ export interface IsolatedFigures {
70
+ /** The latency JACK reports at the plugin's output. */
71
+ readonly latencyFrames?: number;
72
+ /** The worker's CPU over the window, in percent of one core. */
73
+ readonly cpuPercent?: number;
74
+ readonly xruns?: number;
75
+ }
76
+
77
+ /** One step of a plugin's pass and how it ended. */
78
+ export interface RunStep {
79
+ readonly step: string;
80
+ readonly result: string;
81
+ readonly code?: string;
82
+ readonly detail?: string;
83
+ readonly figures?: IsolatedFigures;
84
+ }
85
+
86
+ /** The pass that judged a record: its id, and every step that ran. */
87
+ export interface RunBlock {
88
+ readonly id: string;
89
+ readonly steps: readonly RunStep[];
90
+ }
91
+
46
92
  /** One tier of the console as a verdict: the host it is judged under and whether the plugin qualified there. */
47
93
  export interface TierVerdict {
48
94
  readonly host: string;
@@ -50,9 +96,15 @@ export interface TierVerdict {
50
96
  readonly qualified: boolean;
51
97
  readonly rating: string;
52
98
  readonly deciding?: string;
99
+ /** The isolated tier of a `conditional` plugin: it is offered, and runs alone in a worker of its own, never grouped. */
100
+ readonly runsAlone?: true;
53
101
  }
54
102
 
55
- /** The console's two tiers (what the console's roster offers): offered where the verdict qualified, dimmed with the reason when neither did. */
103
+ /**
104
+ * The console's two tiers (what the console's roster offers): in-process where its verdict qualified; isolated where its
105
+ * verdict qualified or is `conditional`, which pins `isolated` and runs alone (`runsAlone`); dimmed with the reason when
106
+ * neither. `qualified` stays `rating === "suitable"`, as the interchange's reader holds it.
107
+ */
56
108
  export interface RecordTiers {
57
109
  readonly inProcess?: TierVerdict;
58
110
  readonly isolated?: TierVerdict;
@@ -117,8 +169,11 @@ const word = (key: keyof typeof MEASUREMENT_UNMEASURED_REASONS): string => MEASU
117
169
  /** The same, for the test. */
118
170
  export const memoryOfCellForTest = (p: ProbeGridPoint): Pick<RecordGridPoint, "memory"> => memoryOfCell(p);
119
171
 
172
+ /** The contract's word for a cell whose run ended with this outcome, `probe-error` for one it has no word of. */
173
+ export const unmeasuredWordOf = (outcome: string): string => OUTCOME_WORD[outcome] ?? word("probeError");
174
+
120
175
  /** A cell's footprint with what it comes to; only a footprint with no reason beside it comes to anything a client may add up. */
121
- function memoryOfCell(p: ProbeGridPoint): Pick<RecordGridPoint, "memory"> {
176
+ export function memoryOfCell(p: ProbeGridPoint): Pick<RecordGridPoint, "memory"> {
122
177
  if (p.memory === undefined) return {};
123
178
  const first = p.memory.unmeasuredReason === undefined ? firstInstanceKb(p.memory) : undefined;
124
179
  const per = p.memory.unmeasuredReason === undefined ? perInstanceKb(p.memory) : undefined;
@@ -181,6 +236,51 @@ export interface HistoryBlock {
181
236
  readonly verdicts: readonly ({ readonly host: string } & Adjustment)[];
182
237
  }
183
238
 
239
+ /** One measurement a record lacks, and what it keeps from being decided. */
240
+ export interface OwedMeasurement {
241
+ /** `adapter-run`: the plugin under omx-clap-host's LV2 adapter. `host-run`: under the host named. `qualification`: the whole of it. `isolated-step`: the plugin seen running alone. */
242
+ readonly measurement: "adapter-run" | "host-run" | "qualification" | "isolated-step";
243
+ readonly host?: string;
244
+ readonly code: string;
245
+ readonly detail?: string;
246
+ }
247
+
248
+ /**
249
+ * The verdicts are not the ones of the run that took the figures: `plugin-qualify-sync --rejudge` derived them later, from
250
+ * those figures, under the rules of `by`. `figures` says who took the figures and when; the verdicts claim nothing more.
251
+ */
252
+ export interface RejudgedBlock {
253
+ /** The UTC time the verdicts last changed. */
254
+ readonly at: string;
255
+ /** The plugin-qualify whose rules judged them. */
256
+ readonly by: string;
257
+ readonly figures: {
258
+ readonly tool: Readonly<Record<string, string>>;
259
+ readonly measuredAt: string;
260
+ readonly runId: string;
261
+ /** The footprints, when a memory-only pass took them later than the rest. */
262
+ readonly memory?: { readonly tool: Readonly<Record<string, string>>; readonly measuredAt: string };
263
+ /** The adapter run, when an adapter-only pass took it later than the rest. */
264
+ readonly adapter?: { readonly versions: Readonly<Record<string, string>>; readonly measuredAt: string };
265
+ };
266
+ /** What these verdicts could not decide and left `unknown`; absent when nothing is owed. */
267
+ readonly owes?: readonly OwedMeasurement[];
268
+ }
269
+
270
+ /** The memory-only pass that took this record's footprints: every other figure is older and comes from `tool`. */
271
+ export interface MemoryRunBlock {
272
+ readonly tool: Readonly<Record<string, string>>;
273
+ readonly measuredAt: string;
274
+ readonly runId: string;
275
+ readonly cells: readonly {
276
+ readonly rate: number;
277
+ readonly quantum: number;
278
+ /** How the cell's run ended; its figures are in the grid's point of that cell. */
279
+ readonly outcome: string;
280
+ readonly memoryLimit?: { readonly bytes: number; readonly mechanism: string };
281
+ }[];
282
+ }
283
+
184
284
  export interface QualificationRecord {
185
285
  readonly schema: typeof QUALIFICATION_RECORD_SCHEMA;
186
286
  readonly plugin: { readonly format: string; readonly id: string; readonly name?: string };
@@ -192,7 +292,7 @@ export interface QualificationRecord {
192
292
  * An LV2 plugin run under plugin-hostd's LV2 adapter (omx-clap-host), as under mod-host: admitted, or refused with
193
293
  * its code, or `measured: false` when it was not tried. Beside the verdicts, which it does not change (#223).
194
294
  */
195
- readonly adapter?: { readonly host: string; readonly measured: boolean; readonly admitted: boolean; readonly code?: string; readonly params: Readonly<Record<string, string | number>> };
295
+ readonly adapter?: AdapterBlock;
196
296
  readonly tiers: RecordTiers;
197
297
  /** The cost reasons at each host's rate and quantum, beside the verdicts; an instrument's with the notes it held. */
198
298
  readonly cost: readonly {
@@ -216,6 +316,8 @@ export interface QualificationRecord {
216
316
  * qualification of `plugin-qualify-sync` takes no soak, and says so here rather than leave it unstated.
217
317
  */
218
318
  readonly notMeasured?: readonly NotMeasured[];
319
+ /** The pass that judged it; absent on a record from before the steps, which owes what its outcome calls for. */
320
+ readonly run?: RunBlock;
219
321
  /** Who measured and when. */
220
322
  readonly tool: Readonly<Record<string, string>>;
221
323
  readonly measuredAt: string;
@@ -223,6 +325,10 @@ export interface QualificationRecord {
223
325
  readonly history?: readonly HistoryBlock[];
224
326
  /** Where the record came from when it was not measured on this device: the distributed set's provenance, as the set's package wrote it. */
225
327
  readonly provenance?: Readonly<Record<string, unknown>>;
328
+ /** Present when the verdicts were derived later from the figures below, measuring nothing. */
329
+ readonly rejudged?: RejudgedBlock;
330
+ /** Present when a memory-only pass merged footprints into the grid. */
331
+ readonly memoryRun?: MemoryRunBlock;
226
332
  /** The probe output this record judged. */
227
333
  readonly probe: {
228
334
  readonly file: string;
@@ -264,18 +370,32 @@ function tierOf(judgment: Judgment, host: string | undefined): TierVerdict | und
264
370
  export function tiersOf(judgment: Judgment): RecordTiers {
265
371
  const inProcess = tierOf(judgment, IN_PROCESS_TIER_HOST);
266
372
  const isolated = tierOf(judgment, ISOLATED_TIER_HOST[judgment.output.plugin.format]);
373
+ const runsAlone = isolated?.measured === true && isolated.rating === "conditional";
267
374
  const offeredOn: ("in-process" | "isolated")[] = [];
268
375
  if (inProcess?.qualified === true) offeredOn.push("in-process");
269
- if (isolated?.qualified === true) offeredOn.push("isolated");
376
+ if (isolated?.qualified === true || runsAlone) offeredOn.push("isolated");
270
377
  const why = [inProcess, isolated].flatMap((t) => (t === undefined ? [] : [`${t.host}: ${t.deciding ?? t.rating}`]));
271
378
  return {
272
379
  ...(inProcess === undefined ? {} : { inProcess }),
273
- ...(isolated === undefined ? {} : { isolated }),
380
+ ...(isolated === undefined ? {} : { isolated: { ...isolated, ...(runsAlone ? { runsAlone: true as const } : {}) } }),
274
381
  offeredOn,
275
382
  ...(offeredOn.length === 0 ? { dimmed: why.length === 0 ? "no tier was judged" : why.join("; ") } : {}),
276
383
  };
277
384
  }
278
385
 
386
+ /** A judgment's verdicts as the record writes them. */
387
+ export const verdictRows = (judgment: Judgment): RecordVerdict[] =>
388
+ judgment.hosts.map((h) => ({
389
+ host: h.verdict.host,
390
+ measured: h.verdict.measured,
391
+ rating: h.verdict.rating,
392
+ qualified: h.verdict.qualified,
393
+ hosting: h.hosting,
394
+ arm: h.arm,
395
+ ...(h.verdict.deciding === undefined ? {} : { deciding: h.verdict.deciding }),
396
+ reasons: h.reasons,
397
+ }));
398
+
279
399
  export function buildQualificationRecord(
280
400
  judgment: Judgment,
281
401
  copy: { file: string; sha256: string; bytes: number },
@@ -287,16 +407,7 @@ export function buildQualificationRecord(
287
407
  plugin: { format: o.plugin.format, id: o.plugin.id, ...(o.plugin.name === undefined ? {} : { name: o.plugin.name }) },
288
408
  ...(o.plugin.version === undefined ? {} : { testedVersion: o.plugin.version }),
289
409
  binary: o.binary,
290
- verdicts: judgment.hosts.map((h) => ({
291
- host: h.verdict.host,
292
- measured: h.verdict.measured,
293
- rating: h.verdict.rating,
294
- qualified: h.verdict.qualified,
295
- hosting: h.hosting,
296
- arm: h.arm,
297
- ...(h.verdict.deciding === undefined ? {} : { deciding: h.verdict.deciding }),
298
- reasons: h.reasons,
299
- })),
410
+ verdicts: verdictRows(judgment),
300
411
  ...(judgment.adapter === undefined ? {} : { adapter: judgment.adapter }),
301
412
  tiers: tiersOf(judgment),
302
413
  cost: judgment.hosts.map((h) => ({ host: h.verdict.host, ...h.cost })),
@@ -0,0 +1,278 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ // Copyright (C) 2026 Pau Aliagas <linuxnow@gmail.com>
3
+ /**
4
+ * `plugin-qualify-sync --adapter-only`: an LV2 plugin's verdict on omx-clap-host is decided by its run under plugin-hostd's
5
+ * LV2 adapter, and a record without one owes it (`qualify-rejudge.ts`). This pass makes only that run, for each plugin, at
6
+ * each cell a Pi runs, and puts the block in the record; every other figure stays as it was, and `--rejudge` reads it.
7
+ *
8
+ * Each cell has a private JACK server of its own (`jackd -d dummy`, the rate and quantum on its command line), so that the
9
+ * run can never reach the device's live server (plugin-qualify#187), and each run a fresh host, its time limited by
10
+ * `budget_s` a command and its address space by the limit of a direct spawn. A crash or a timeout is the plugin's recorded
11
+ * outcome. A pass does not start without the versions of the hosts it runs, or without a private server: nothing it could
12
+ * write would say what it measured. A plugin is finished when its block was taken at these host versions at every cell,
13
+ * so a pass cut short can be run again; a host that could not be run decides nothing, and that plugin is tried again.
14
+ */
15
+ import { spawn, spawnSync, type ChildProcess } from "node:child_process";
16
+ import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs";
17
+ import { tmpdir } from "node:os";
18
+ import { basename, join } from "node:path";
19
+
20
+ import { ADAPTER_HOST, SPAWNED_ADMISSIONS, admitUnderAdapter, type AdmissionRuns, type HostAdmission } from "./host-admission.js";
21
+ import { HOSTD_ENV } from "./hostd-pin-files.js";
22
+ import { cellKey, type GridCell } from "./measurement-grid.js";
23
+ import { defaultAddressSpaceLimit } from "./direct-limit.js";
24
+ import { PROBE_OK } from "./probe-output.js";
25
+ import { QUALIFICATION_RECORD_SCHEMA, type AdapterBlock, type QualificationRecord } from "./qualification-record.js";
26
+ import { ADMIT_ADDRESS_KB_ENV, ADMIT_STATE_DIR_ENV, ADMIT_STEP_MS_ENV, PI_CELLS } from "./qualify-declarations.js";
27
+ import { digestFiles, type SyncContext, type SyncState } from "./qualify-sync.js";
28
+ import { writeFileWhole } from "./whole-file.js";
29
+
30
+ /** The cells the pass runs at: the ones a Pi runs. */
31
+ export const ADAPTER_PASS_CELLS: readonly GridCell[] = PI_CELLS;
32
+
33
+ /** The code of a cell no private server could be had for: the run did not happen. */
34
+ export const NO_PRIVATE_SERVER = `${ADAPTER_HOST}.no-private-server`;
35
+
36
+ const RECORD_SUFFIX = ".qualification.json";
37
+ const SERVER_WAIT_MS = 5000;
38
+ const SERVER_SETTLE_MS = 300;
39
+ const SERVER_STOP_MS = 2000;
40
+
41
+ /** What a program answers to `--version`: its last word on the line that says `version`. */
42
+ export function parseVersion(text: string): string | undefined {
43
+ return /version:?\s+(\S+)/.exec(text)?.[1];
44
+ }
45
+
46
+ export type VersionRun = (tool: string) => { readonly status: number | null; readonly stdout: string };
47
+
48
+ const spawnVersion: VersionRun = (tool) => {
49
+ const r = spawnSync(tool, ["--version"], { encoding: "utf8", timeout: 10000, killSignal: "SIGKILL" });
50
+ return { status: r.status, stdout: `${r.stdout ?? ""}\n${r.stderr ?? ""}` };
51
+ };
52
+
53
+ /** The versions of the hosts as installed now, or which of them could not say. */
54
+ export function hostVersions(env: Readonly<Record<string, string | undefined>>, run: VersionRun = spawnVersion): { ok: true; versions: Readonly<Record<string, string>> } | { ok: false; error: string } {
55
+ const versions: Record<string, string> = {};
56
+ for (const [name, tool] of [[ADAPTER_HOST, ADAPTER_HOST], ["plugin-hostd", env[HOSTD_ENV] ?? "plugin-hostd"]] as const) {
57
+ const r = run(tool);
58
+ const version = r.status === 0 ? parseVersion(r.stdout) : undefined;
59
+ if (version === undefined) return { ok: false, error: `${tool} --version names no version, so a run could not say which host it was under` };
60
+ versions[name] = version;
61
+ }
62
+ return { ok: true, versions };
63
+ }
64
+
65
+ /** A private JACK server for one cell, for as long as a pass needs it. */
66
+ export interface PrivateJack {
67
+ readonly name: string;
68
+ alive(): boolean;
69
+ stop(): void;
70
+ }
71
+
72
+ export type JackStarter = (cell: GridCell) => PrivateJack | undefined;
73
+
74
+ const sleepSync = (ms: number): void => {
75
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
76
+ };
77
+
78
+ /** `jackd` on a name of its own and the dummy driver, at the cell's rate and quantum; `undefined` when none came up. */
79
+ export const startPrivateJack: JackStarter = (cell) => {
80
+ const name = `omx-qualify-${String(process.pid)}-${String(cell.quantum)}`;
81
+ let child: ChildProcess;
82
+ let ended = false;
83
+ try {
84
+ child = spawn("jackd", ["-r", "-n", name, "-d", "dummy", "-r", String(cell.rate), "-p", String(cell.quantum)], { stdio: "ignore", detached: true });
85
+ } catch {
86
+ return undefined;
87
+ }
88
+ child.on("error", () => (ended = true));
89
+ child.on("exit", () => (ended = true));
90
+ child.unref();
91
+ const running = (): boolean => {
92
+ if (ended || child.pid === undefined) return false;
93
+ // the exit event needs the loop this synchronous pass holds: the process table says
94
+ return existsSync(`/proc/${String(child.pid)}`) && !/^\S+ \(.*\) Z/.test(readStat(child.pid));
95
+ };
96
+ // a TERM first: jackd frees the shared memory it holds under /dev/shm itself, which a KILL would leave behind for good
97
+ const signal = (sig: NodeJS.Signals): void => {
98
+ try {
99
+ if (child.pid !== undefined) process.kill(-child.pid, sig);
100
+ } catch {
101
+ // already gone
102
+ }
103
+ };
104
+ const stop = (): void => {
105
+ signal("SIGTERM");
106
+ const until = Date.now() + SERVER_STOP_MS;
107
+ while (running() && Date.now() < until) sleepSync(20);
108
+ if (running()) signal("SIGKILL");
109
+ for (const d of serverDirs(name)) rmSync(d, { recursive: true, force: true });
110
+ };
111
+ const until = Date.now() + SERVER_WAIT_MS;
112
+ while (Date.now() < until) {
113
+ if (child.pid === undefined || !running()) {
114
+ stop();
115
+ return undefined;
116
+ }
117
+ if (serverDirs(name).length > 0) {
118
+ sleepSync(SERVER_SETTLE_MS);
119
+ return { name, alive: running, stop };
120
+ }
121
+ sleepSync(50);
122
+ }
123
+ stop();
124
+ return undefined;
125
+ };
126
+
127
+ const readStat = (pid: number): string => {
128
+ try {
129
+ return readFileSync(`/proc/${String(pid)}/stat`, "utf8");
130
+ } catch {
131
+ return "";
132
+ }
133
+ };
134
+
135
+ /** Where jackd keeps a server's sockets, and its semaphores: the socket appears as the server opens it. */
136
+ function serverDirs(name: string): string[] {
137
+ try {
138
+ return readdirSync("/dev/shm").filter((d) => d.startsWith(`jack_${name}_`) || new RegExp(`^jack_sem\\.\\d+_${name}_`).test(d)).map((d) => join("/dev/shm", d));
139
+ } catch {
140
+ return [];
141
+ }
142
+ }
143
+
144
+ /** Whether a machine can give a pass its private server at all: the program is there. */
145
+ function jackdInstalled(env: Readonly<Record<string, string | undefined>>): boolean {
146
+ return (env["PATH"] ?? process.env["PATH"] ?? "").split(":").some((d) => d !== "" && existsSync(join(d, "jackd")));
147
+ }
148
+
149
+ // --- the block --------------------------------------------------------------------------------------------------------
150
+
151
+ /**
152
+ * The runs of every cell as one block. Its top is what the judge reads: a refusal or a crash at any cell decides, with the
153
+ * cell it happened at, whatever the others say; then a cell where the host could not be run leaves it not measured, so
154
+ * still owed; only every cell admitted is admitted. Pure.
155
+ */
156
+ export function adapterBlockOf(runs: readonly { readonly cell: GridCell; readonly run: HostAdmission }[], versions: Readonly<Record<string, string>>, measuredAt: string): AdapterBlock {
157
+ const cells = runs.map(({ cell, run }) => ({ rate: cell.rate, quantum: cell.quantum, measured: run.measured, admitted: run.admitted, ...(run.code === undefined ? {} : { code: run.code }), params: run.params }));
158
+ const worst = cells.find((c) => c.measured && !c.admitted) ?? cells.find((c) => !c.measured);
159
+ const top =
160
+ worst === undefined
161
+ ? { measured: true, admitted: true, params: {} }
162
+ : { measured: worst.measured, admitted: false, ...(worst.code === undefined ? {} : { code: worst.code }), params: { ...worst.params, rate: worst.rate, quantum: worst.quantum } };
163
+ return { host: ADAPTER_HOST, ...top, versions, measuredAt, cells };
164
+ }
165
+
166
+ /** The record with the block, and every other byte of it as it was. Pure. */
167
+ export const mergeAdapterRun = (record: QualificationRecord, block: AdapterBlock): QualificationRecord => ({ ...record, adapter: block });
168
+
169
+ /** Whether a record's adapter run is done: at these host versions, measured, at every cell. */
170
+ export function adapterFinished(record: QualificationRecord, versions: Readonly<Record<string, string>>, cells: readonly GridCell[] = ADAPTER_PASS_CELLS): boolean {
171
+ const a = record.adapter;
172
+ if (a === undefined || !a.measured || a.versions === undefined || a.cells === undefined) return false;
173
+ const same = Object.keys(versions).length === Object.keys(a.versions).length && Object.entries(versions).every(([k, v]) => a.versions![k] === v);
174
+ return same && cells.every((c) => a.cells!.some((x) => cellKey(x) === cellKey(c)));
175
+ }
176
+
177
+ // --- the pass ---------------------------------------------------------------------------------------------------------
178
+
179
+ export interface AdapterPassOptions {
180
+ readonly force?: boolean;
181
+ readonly runs?: AdmissionRuns;
182
+ readonly jack?: JackStarter;
183
+ readonly versions?: VersionRun;
184
+ /** The test's stand-in for jackd says it is there; the real pass looks. */
185
+ readonly jackdPresent?: boolean;
186
+ readonly now?: () => string;
187
+ }
188
+
189
+ export interface AdapterPassResult {
190
+ readonly measured: number;
191
+ readonly already: number;
192
+ readonly failed: number;
193
+ readonly versions: Readonly<Record<string, string>>;
194
+ }
195
+
196
+ /** The pass could not start: nothing was run and nothing written. */
197
+ export class AdapterPassRefused extends Error {}
198
+
199
+ const readRecord = (path: string): QualificationRecord | undefined => {
200
+ try {
201
+ const r = JSON.parse(readFileSync(path, "utf8")) as QualificationRecord;
202
+ return r.schema === QUALIFICATION_RECORD_SCHEMA ? r : undefined;
203
+ } catch {
204
+ return undefined;
205
+ }
206
+ };
207
+
208
+ /**
209
+ * The run of each LV2 plugin of the state whose probe ended well (one that did not has no verdict a run could decide), at
210
+ * each cell. Each record is written whole as its plugin ends.
211
+ */
212
+ export function adapterPass(ctx: SyncContext, state: SyncState, options: AdapterPassOptions = {}): AdapterPassResult {
213
+ const read = hostVersions(ctx.env, options.versions);
214
+ if (!read.ok) throw new AdapterPassRefused(read.error);
215
+ if (!(options.jackdPresent ?? jackdInstalled(ctx.env))) throw new AdapterPassRefused(`no jackd on the path: ${NO_PRIVATE_SERVER}, and the device's own JACK server is never used for this`);
216
+ const { versions } = read;
217
+ const starter = options.jack ?? startPrivateJack;
218
+ const runs = options.runs ?? SPAWNED_ADMISSIONS;
219
+ const now = options.now ?? (() => new Date().toISOString());
220
+ const servers = new Map<string, PrivateJack>();
221
+ const serverFor = (cell: GridCell): PrivateJack | undefined => {
222
+ const key = cellKey(cell);
223
+ const had = servers.get(key);
224
+ if (had?.alive() === true) return had;
225
+ had?.stop();
226
+ servers.delete(key);
227
+ const fresh = starter(cell);
228
+ if (fresh !== undefined) servers.set(key, fresh);
229
+ return fresh;
230
+ };
231
+ const count = { measured: 0, already: 0, failed: 0 };
232
+ const limit = { [ADMIT_STEP_MS_ENV]: String(ctx.settings.budgetS * 1000), [ADMIT_ADDRESS_KB_ENV]: String(Math.ceil(defaultAddressSpaceLimit() / 2 ** 10)) };
233
+ try {
234
+ for (const [key, entry] of Object.entries(state.entries)) {
235
+ if (entry.format !== "lv2") continue;
236
+ const files = digestFiles(entry.root, entry.files.map((f) => f.path), entry.files);
237
+ if (files === undefined || !files.every((f) => entry.files.some((x) => x.path === f.path && x.sha256 === f.sha256))) {
238
+ ctx.log(`${key}: its files changed since it was measured; the sync measures it whole`);
239
+ continue;
240
+ }
241
+ for (const plugin of entry.plugins) {
242
+ if (plugin.record === undefined || !plugin.record.endsWith(RECORD_SUFFIX)) continue;
243
+ const path = join(ctx.settings.qualificationDir, basename(plugin.record));
244
+ const record = readRecord(path);
245
+ if (record === undefined) {
246
+ ctx.log(`${plugin.uri}: its record does not read; no adapter run`);
247
+ count.failed++;
248
+ continue;
249
+ }
250
+ if (record.probe.outcome !== PROBE_OK) continue;
251
+ if (options.force !== true && adapterFinished(record, versions)) {
252
+ count.already++;
253
+ continue;
254
+ }
255
+ const started = Date.now();
256
+ const done = ADAPTER_PASS_CELLS.map((cell) => {
257
+ const server = serverFor(cell);
258
+ if (server === undefined) return { cell, run: { host: ADAPTER_HOST, measured: false, admitted: false, code: NO_PRIVATE_SERVER, params: {} } as HostAdmission };
259
+ const stateDir = mkdtempSync(join(tmpdir(), "plugin-qualify-adapter-state-"));
260
+ try {
261
+ const env = { ...ctx.env, ...limit, [ADMIT_STATE_DIR_ENV]: stateDir, LV2_PATH: ctx.settings.lv2Dirs.join(":"), JACK_DEFAULT_SERVER: server.name, JACK_NO_START_SERVER: "1" };
262
+ return { cell, run: admitUnderAdapter(record.plugin.id, runs, env) ?? ({ host: ADAPTER_HOST, measured: false, admitted: false, code: `${ADAPTER_HOST}.admission-failed`, params: {} } as HostAdmission) };
263
+ } finally {
264
+ rmSync(stateDir, { recursive: true, force: true });
265
+ }
266
+ });
267
+ const block = adapterBlockOf(done, versions, now());
268
+ writeFileWhole(path, `${JSON.stringify(mergeAdapterRun(record, block), null, 2)}\n`);
269
+ if (block.measured) count.measured++;
270
+ else count.failed++;
271
+ ctx.log(`${plugin.uri}: adapter ${block.measured ? (block.admitted ? "admitted" : `refused (${block.code ?? ""})`) : `not run (${block.code ?? ""})`} in ${((Date.now() - started) / 1000).toFixed(1)} s`);
272
+ }
273
+ }
274
+ } finally {
275
+ for (const s of servers.values()) s.stop();
276
+ }
277
+ return { ...count, versions };
278
+ }
@@ -104,12 +104,17 @@ export const CLAP_QUALIFY_TOOL_ENV = "OMX_CLAP_QUALIFY";
104
104
  export const LV2_MEASURE_TOOL_ENV = "OMX_LV2_MEASURE";
105
105
  export const RT_INTERPOSE_ENV = "OMX_RT_INTERPOSE";
106
106
  export const LV2_HOST_PROBE_TOOL_ENV = "OMX_LV2_HOST_PROBE";
107
+ export const ISOLATED_SIGNAL_TOOL_ENV = "OMX_ISOLATED_SIGNAL";
108
+ /** `native/jack-peak.c`, the level of an instrument under a held note in the adapter run (`tools/mod-host-admit.mjs`). */
109
+ export const JACK_PEAK_TOOL_ENV = "OMX_JACK_PEAK";
107
110
 
108
111
  /** The file names of the native tools, in every place they are looked for. */
109
112
  export const CLAP_QUALIFY_TOOL_NAME = "clap-qualify";
113
+ export const ISOLATED_SIGNAL_TOOL_NAME = "isolated_signal";
110
114
  export const LV2_MEASURE_TOOL_NAME = "lv2_measure";
111
115
  export const RT_INTERPOSE_NAME = "rt_interpose.so";
112
116
  export const LV2_HOST_PROBE_TOOL_NAME = "lv2_host_probe";
117
+ export const JACK_PEAK_TOOL_NAME = "jack_peak";
113
118
 
114
119
  /**
115
120
  * The ONE list of the native tools the packages install, each with the setting that names it.
@@ -120,6 +125,8 @@ export const NATIVE_TOOLS: readonly { readonly name: string; readonly env: strin
120
125
  { name: LV2_MEASURE_TOOL_NAME, env: LV2_MEASURE_TOOL_ENV },
121
126
  { name: RT_INTERPOSE_NAME, env: RT_INTERPOSE_ENV },
122
127
  { name: LV2_HOST_PROBE_TOOL_NAME, env: LV2_HOST_PROBE_TOOL_ENV },
128
+ { name: ISOLATED_SIGNAL_TOOL_NAME, env: ISOLATED_SIGNAL_TOOL_ENV },
129
+ { name: JACK_PEAK_TOOL_NAME, env: JACK_PEAK_TOOL_ENV },
123
130
  ];
124
131
 
125
132
  /**
@@ -156,6 +163,24 @@ export const ADDRESS_SPACE_LIMIT_RAM_FRACTION = 1;
156
163
  export const MEMORY_BOUND_EXIT_ENV = "OMX_RT_OOM_EXIT";
157
164
  export const MEMORY_BOUND_EXIT_STATUS = 121;
158
165
 
166
+ /**
167
+ * The memory-only pass (`plugin-qualify-sync --memory-only`). With `PROBE_MEMORY_ONLY_ENV` set the probers take the
168
+ * footprint and nothing else; the probe runner passes its environment on, so its limits hold unchanged.
169
+ * `PROBE_NOTES_ENV` is the count of notes an instrument that declares no voice capacity holds, basis `probe`:
170
+ * `MEMORY_PASS_PROBE_NOTES` unless `memory_notes` says otherwise.
171
+ */
172
+ export const PROBE_MEMORY_ONLY_ENV = "OMX_PROBE_MEMORY_ONLY";
173
+ export const PROBE_NOTES_ENV = "OMX_PROBE_NOTES";
174
+ export const MEMORY_PASS_PROBE_NOTES = 16;
175
+
176
+ /**
177
+ * What `tools/mod-host-admit.mjs` is told in an adapter-only pass: how long the host has for one command, its address
178
+ * space (`ulimit -v`, in KB) and the directory for the state files of the plugin it loads.
179
+ */
180
+ export const ADMIT_STEP_MS_ENV = "OMX_ADMIT_STEP_MS";
181
+ export const ADMIT_ADDRESS_KB_ENV = "OMX_ADMIT_ADDRESS_KB";
182
+ export const ADMIT_STATE_DIR_ENV = "OMX_ADMIT_STATE_DIR";
183
+
159
184
  /** Seconds one `.clap` may take to qualify at every rate before the prober is killed. */
160
185
  export const CLAP_QUALIFY_TIMEOUT_S = 120;
161
186
 
@@ -286,7 +311,7 @@ const piMemory = (ramGib: number): NonNullable<HostBudget["memory"]> => ({
286
311
  * the other kits, the one a Pi 5 with no kit card also ran its stress and first boot at. The Zynthian benchmark's matrix sweeps
287
312
  * more cells; these two are what a Pi is set to.
288
313
  */
289
- const PI_CELLS = [
314
+ export const PI_CELLS = [
290
315
  { rate: MEASURE_BASE_RATE, quantum: 128 },
291
316
  { rate: MEASURE_BASE_RATE, quantum: 256 },
292
317
  ];