@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.
- package/README.md +93 -3
- package/bin/plugin-qualify-sync.mjs +3 -1
- package/dist/clap-qualify.d.ts +3 -1
- package/dist/clap-qualify.js +3 -1
- package/dist/clap-qualify.js.map +1 -1
- package/dist/distributed-records.d.ts +4 -2
- package/dist/distributed-records.js +1 -1
- package/dist/distributed-records.js.map +1 -1
- package/dist/host-admission.d.ts +21 -0
- package/dist/host-admission.js +33 -3
- package/dist/host-admission.js.map +1 -1
- package/dist/hostd-pin-files.js +3 -1
- package/dist/hostd-pin-files.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/measurement/format.d.ts +10 -0
- package/dist/measurement/format.js +8 -0
- package/dist/measurement/format.js.map +1 -1
- package/dist/measurement/probe-json.js +2 -1
- package/dist/measurement/probe-json.js.map +1 -1
- package/dist/probe-judge.d.ts +11 -0
- package/dist/probe-judge.js +6 -3
- package/dist/probe-judge.js.map +1 -1
- package/dist/probe-runner.js +3 -2
- package/dist/probe-runner.js.map +1 -1
- package/dist/qualification-record.d.ts +113 -8
- package/dist/qualification-record.js +18 -13
- package/dist/qualification-record.js.map +1 -1
- package/dist/qualify-adapter-pass.d.ts +67 -0
- package/dist/qualify-adapter-pass.js +255 -0
- package/dist/qualify-adapter-pass.js.map +1 -0
- package/dist/qualify-declarations.d.ts +30 -0
- package/dist/qualify-declarations.js +24 -1
- package/dist/qualify-declarations.js.map +1 -1
- package/dist/qualify-isolated.d.ts +70 -0
- package/dist/qualify-isolated.js +184 -0
- package/dist/qualify-isolated.js.map +1 -0
- package/dist/qualify-rejudge.d.ts +82 -0
- package/dist/qualify-rejudge.js +434 -0
- package/dist/qualify-rejudge.js.map +1 -0
- package/dist/qualify-sync.d.ts +97 -1
- package/dist/qualify-sync.js +276 -24
- package/dist/qualify-sync.js.map +1 -1
- package/fixtures/records-0.16.1/http___example.org_raffo@unversioned-2060c09ff626.default.probe.json +46 -0
- package/fixtures/records-0.16.1/http___example.org_raffo@unversioned-2060c09ff626.default.qualification.json +185 -0
- package/fixtures/records-0.16.1/http___lv2plug.in_plugins_eg-amp@unversioned-f046a60efd45.default.probe.json +51 -0
- package/fixtures/records-0.16.1/http___lv2plug.in_plugins_eg-amp@unversioned-f046a60efd45.default.qualification.json +232 -0
- package/fixtures/records-0.16.1/https___github.com_lucianodato_noise-repellent@unversioned-c3b5e21dd9a7.default.probe.json +51 -0
- package/fixtures/records-0.16.1/https___github.com_lucianodato_noise-repellent@unversioned-c3b5e21dd9a7.default.qualification.json +245 -0
- package/fixtures/records-0.16.1/in.lsp-plug.impulse_responses_mono@unversioned-d5235d2f5f53.custom.probe.json +52 -0
- package/fixtures/records-0.16.1/in.lsp-plug.impulse_responses_mono@unversioned-d5235d2f5f53.custom.qualification.json +145 -0
- package/fixtures/records-0.16.1/in.lsp-plug.trigger_midi_mono@unversioned-d5235d2f5f53.custom.probe.json +52 -0
- package/fixtures/records-0.16.1/in.lsp-plug.trigger_midi_mono@unversioned-d5235d2f5f53.custom.qualification.json +155 -0
- package/package.json +1 -1
- package/src/clap-qualify.ts +5 -1
- package/src/distributed-records.ts +1 -1
- package/src/host-admission.ts +40 -3
- package/src/hostd-pin-files.ts +3 -1
- package/src/index.ts +2 -0
- package/src/measurement/format.ts +17 -0
- package/src/measurement/probe-json.ts +2 -1
- package/src/probe-judge.ts +10 -3
- package/src/probe-runner.ts +2 -2
- package/src/qualification-record.ts +126 -15
- package/src/qualify-adapter-pass.ts +278 -0
- package/src/qualify-declarations.ts +26 -1
- package/src/qualify-isolated.ts +201 -0
- package/src/qualify-rejudge.ts +466 -0
- package/src/qualify-sync.ts +295 -24
- package/tools/isolated-step.mjs +122 -0
- package/tools/lv2_resolve.py +49 -0
- package/tools/mod-host-admit.mjs +99 -7
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
// Copyright (C) 2026 Pau Aliagas <linuxnow@gmail.com>
|
|
3
|
+
/**
|
|
4
|
+
* The steps of one plugin's pass, and the last of them: `verdict=isolated` means the plugin was seen running alone in a
|
|
5
|
+
* worker of its own (plugin-qualify#249). A plugin the RT-safety step finds unsafe takes the isolated step in the same
|
|
6
|
+
* pass, and so does one that crashed or hung in the probe. The step runs on a private JACK server at the host's rate and
|
|
7
|
+
* quantum, under a plugin-hostd of its own: the plugin is added alone, `worker_list` must show it alone, and a sine plays
|
|
8
|
+
* through it for a window. Only a plugin that was added, stayed alive and gave finite, non-silent output is isolated. A
|
|
9
|
+
* machine that could not run the step decides nothing about the plugin: no verdict word, and the sync tries it again.
|
|
10
|
+
*
|
|
11
|
+
* Every record says which steps judged it. {@link missingSteps} is what the sync refuses a record by; a record from before
|
|
12
|
+
* the steps has no `run` at all, owes the isolated step if its outcome calls for one, and a completion adds it
|
|
13
|
+
* ({@link completeIsolated}), measuring nothing else.
|
|
14
|
+
*/
|
|
15
|
+
import { spawnSync } from "node:child_process";
|
|
16
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
17
|
+
import { basename, join } from "node:path";
|
|
18
|
+
|
|
19
|
+
import { ADAPTER_PASS_CELLS, startPrivateJack, type JackStarter } from "./qualify-adapter-pass.js";
|
|
20
|
+
import type { GridCell } from "./measurement-grid.js";
|
|
21
|
+
import type { PinEntry } from "./pins-file.js";
|
|
22
|
+
import { PROBE_OK, readProbeOutput } from "./probe-output.js";
|
|
23
|
+
import type { IsolatedFigures, QualificationRecord, RunBlock, RunStep } from "./qualification-record.js";
|
|
24
|
+
import { ISOLATED_SIGNAL_TOOL_ENV, ISOLATED_SIGNAL_TOOL_NAME } from "./qualify-declarations.js";
|
|
25
|
+
import { locateNativeTool, toolsDir } from "./tool-paths.js";
|
|
26
|
+
import { writeFileWhole } from "./whole-file.js";
|
|
27
|
+
|
|
28
|
+
/** The steps of a pass, in the order they run. */
|
|
29
|
+
export const RUN_STEP = { scan: "scan", describe: "describe", probe: "probe", rtSafety: "rt-safety", isolated: "isolated" } as const;
|
|
30
|
+
|
|
31
|
+
export const ISOLATED_RESULT = { isolated: "isolated", refused: "refused", notRun: "not-run" } as const;
|
|
32
|
+
|
|
33
|
+
/** Why the step refused a plugin, or why it could not run. */
|
|
34
|
+
export const ISOLATED_CODE = {
|
|
35
|
+
crashed: "isolated.crashed",
|
|
36
|
+
notAdded: "isolated.not-added",
|
|
37
|
+
noWorker: "isolated.no-worker",
|
|
38
|
+
notAlone: "isolated.not-alone",
|
|
39
|
+
nonFinite: "isolated.non-finite-output",
|
|
40
|
+
silent: "isolated.silent-output",
|
|
41
|
+
noServer: "isolated.no-private-server",
|
|
42
|
+
noHost: "isolated.no-host",
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
/** The outcomes of a probe that take the isolated step as well: the plugin never reached a verdict in-process. */
|
|
46
|
+
const PROBE_FAILED_HARD = new Set(["probe.crashed", "probe.timeout"]);
|
|
47
|
+
|
|
48
|
+
/** What one run of the step saw. A run that never reached the plugin says `started: false`, and `problem`. */
|
|
49
|
+
export interface IsolatedRunFacts {
|
|
50
|
+
readonly started: boolean;
|
|
51
|
+
readonly problem?: string;
|
|
52
|
+
readonly added?: boolean;
|
|
53
|
+
/** How many workers `worker_list` showed, and how many instances the plugin's holds. */
|
|
54
|
+
readonly workers?: number;
|
|
55
|
+
readonly instancesInWorker?: number;
|
|
56
|
+
readonly alive?: boolean;
|
|
57
|
+
readonly latencyFrames?: number;
|
|
58
|
+
readonly cpuPercent?: number;
|
|
59
|
+
readonly xruns?: number;
|
|
60
|
+
readonly finite?: boolean;
|
|
61
|
+
readonly silent?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type IsolatedRunner = (uri: string, cell: GridCell, env: Readonly<Record<string, string | undefined>>) => IsolatedRunFacts;
|
|
65
|
+
|
|
66
|
+
/** The decision table of the step, with the figures it took. Pure. */
|
|
67
|
+
export function judgeIsolatedRun(run: IsolatedRunFacts): RunStep {
|
|
68
|
+
const step = (result: string, code?: string, detail?: string): RunStep => ({
|
|
69
|
+
step: RUN_STEP.isolated,
|
|
70
|
+
result,
|
|
71
|
+
...(code === undefined ? {} : { code }),
|
|
72
|
+
...(detail === undefined ? {} : { detail }),
|
|
73
|
+
...(figuresOf(run) === undefined ? {} : { figures: figuresOf(run)! }),
|
|
74
|
+
});
|
|
75
|
+
if (!run.started) return step(ISOLATED_RESULT.notRun, ISOLATED_CODE.noHost, run.problem);
|
|
76
|
+
if (run.added !== true) return step(ISOLATED_RESULT.refused, ISOLATED_CODE.notAdded, run.problem);
|
|
77
|
+
if (run.alive !== true) return step(ISOLATED_RESULT.refused, ISOLATED_CODE.crashed, run.problem);
|
|
78
|
+
if ((run.workers ?? 0) < 1) return step(ISOLATED_RESULT.refused, ISOLATED_CODE.noWorker);
|
|
79
|
+
if (run.workers !== 1 || run.instancesInWorker !== 1) return step(ISOLATED_RESULT.refused, ISOLATED_CODE.notAlone);
|
|
80
|
+
if (run.finite !== true) return step(ISOLATED_RESULT.refused, ISOLATED_CODE.nonFinite);
|
|
81
|
+
if (run.silent !== false) return step(ISOLATED_RESULT.refused, ISOLATED_CODE.silent);
|
|
82
|
+
return step(ISOLATED_RESULT.isolated);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function figuresOf(run: IsolatedRunFacts): IsolatedFigures | undefined {
|
|
86
|
+
if (run.latencyFrames === undefined && run.cpuPercent === undefined && run.xruns === undefined) return undefined;
|
|
87
|
+
return {
|
|
88
|
+
...(run.latencyFrames === undefined ? {} : { latencyFrames: run.latencyFrames }),
|
|
89
|
+
...(run.cpuPercent === undefined ? {} : { cpuPercent: run.cpuPercent }),
|
|
90
|
+
...(run.xruns === undefined ? {} : { xruns: run.xruns }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Whether a record's outcome calls for the isolated step: rated `conditional` by some host, or a probe that crashed or hung. */
|
|
95
|
+
export function owesIsolated(record: QualificationRecord): boolean {
|
|
96
|
+
return PROBE_FAILED_HARD.has(record.probe.outcome) || record.verdicts.some((v) => v.measured && v.rating === "conditional");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Whether the isolated step saw this plugin running alone. A record's word alone never says so. */
|
|
100
|
+
export function provenAlone(record: QualificationRecord): boolean {
|
|
101
|
+
return record.run?.steps.some((s) => s.step === RUN_STEP.isolated && s.result === ISOLATED_RESULT.isolated) === true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The steps a record's outcome calls for. */
|
|
105
|
+
export function stepsCalledFor(record: QualificationRecord): readonly string[] {
|
|
106
|
+
return [
|
|
107
|
+
RUN_STEP.scan,
|
|
108
|
+
RUN_STEP.describe,
|
|
109
|
+
RUN_STEP.probe,
|
|
110
|
+
...(record.probe.outcome === PROBE_OK ? [RUN_STEP.rtSafety] : []),
|
|
111
|
+
...(owesIsolated(record) ? [RUN_STEP.isolated] : []),
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The steps a record that carries a `run` lacks, for the sync to refuse it by. A record from before the steps has none to lack. */
|
|
116
|
+
export function missingSteps(record: QualificationRecord): readonly string[] {
|
|
117
|
+
if (record.run === undefined) return [];
|
|
118
|
+
const had = new Set(record.run.steps.map((s) => s.step));
|
|
119
|
+
return stepsCalledFor(record).filter((s) => !had.has(s));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The steps every record has by the time it is written, from what it says of them. Pure. */
|
|
123
|
+
export function baseSteps(record: QualificationRecord, describeProblem?: string): RunStep[] {
|
|
124
|
+
const measured = record.measurements.grid.some((p) => p.rtSafety !== undefined);
|
|
125
|
+
return [
|
|
126
|
+
{ step: RUN_STEP.scan, result: "ok" },
|
|
127
|
+
describeProblem === undefined ? { step: RUN_STEP.describe, result: "ok" } : { step: RUN_STEP.describe, result: "failed", detail: describeProblem },
|
|
128
|
+
{ step: RUN_STEP.probe, result: record.probe.outcome },
|
|
129
|
+
...(record.probe.outcome === PROBE_OK
|
|
130
|
+
? [{ step: RUN_STEP.rtSafety, result: !measured ? "not-measured" : record.verdicts.some((v) => v.rating === "conditional") ? "unsafe" : "safe" }]
|
|
131
|
+
: []),
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** How long the sine plays, and what a step may take beyond it: the host's start and its answers. */
|
|
136
|
+
const ISOLATED_WINDOW_MS = 3000;
|
|
137
|
+
const ISOLATED_STEP_SLACK_MS = 90000;
|
|
138
|
+
|
|
139
|
+
/** The step as it runs on a device: a private server at the cell, and `tools/isolated-step.mjs` under it. */
|
|
140
|
+
export function spawnedIsolatedRunner(jack: JackStarter = startPrivateJack): IsolatedRunner {
|
|
141
|
+
return (uri, cell, env) => {
|
|
142
|
+
const signal = locateNativeTool(ISOLATED_SIGNAL_TOOL_NAME, env, existsSync).path;
|
|
143
|
+
if (signal === undefined) return { started: false, problem: `no ${ISOLATED_SIGNAL_TOOL_NAME}` };
|
|
144
|
+
const server = jack(cell);
|
|
145
|
+
if (server === undefined) return { started: false, problem: `${ISOLATED_CODE.noServer} at ${String(cell.rate)}/${String(cell.quantum)}` };
|
|
146
|
+
try {
|
|
147
|
+
const r = spawnSync(process.execPath, [join(toolsDir(), "isolated-step.mjs"), uri, String(ISOLATED_WINDOW_MS)], {
|
|
148
|
+
encoding: "utf8",
|
|
149
|
+
timeout: ISOLATED_WINDOW_MS + ISOLATED_STEP_SLACK_MS,
|
|
150
|
+
killSignal: "SIGKILL",
|
|
151
|
+
env: { ...env, JACK_DEFAULT_SERVER: server.name, [ISOLATED_SIGNAL_TOOL_ENV]: signal },
|
|
152
|
+
});
|
|
153
|
+
if (r.error !== undefined || r.status !== 0) return { started: false, problem: `isolated-step: ${r.error?.message ?? `exit ${String(r.status)}`}: ${(r.stderr ?? "").trim()}` };
|
|
154
|
+
return JSON.parse(r.stdout) as IsolatedRunFacts;
|
|
155
|
+
} finally {
|
|
156
|
+
server.stop();
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The cell the step runs at: the rate and quantum the host's cost was judged at, else the first cell a Pi runs. */
|
|
162
|
+
export function isolatedCell(record: QualificationRecord, host: string): GridCell {
|
|
163
|
+
const at = record.cost.find((c) => c.host === host) ?? record.cost[0];
|
|
164
|
+
return at === undefined ? ADAPTER_PASS_CELLS[0]! : { rate: at.rate, quantum: at.quantum };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The pin once the step has spoken: its verdict word follows the step, and a step that could not run leaves none. Pure. */
|
|
168
|
+
export function pinAfterStep(pin: PinEntry | undefined, step: RunStep): PinEntry | undefined {
|
|
169
|
+
if (pin === undefined) return undefined;
|
|
170
|
+
const { verdict: _had, ...rest } = pin;
|
|
171
|
+
if (step.result === ISOLATED_RESULT.isolated) return { ...rest, verdict: "isolated" };
|
|
172
|
+
if (step.result === ISOLATED_RESULT.refused) return { ...rest, verdict: "refused" };
|
|
173
|
+
return rest;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The run id of a record from before the steps: its probe output's, read from the copy beside it. */
|
|
177
|
+
function runIdOf(record: QualificationRecord, dir: string): string | undefined {
|
|
178
|
+
if (record.run !== undefined) return record.run.id;
|
|
179
|
+
if (record.rejudged !== undefined) return record.rejudged.figures.runId;
|
|
180
|
+
try {
|
|
181
|
+
const read = readProbeOutput(readFileSync(join(dir, basename(record.probe.file)), "utf8"));
|
|
182
|
+
return read.ok ? read.output.run.id : undefined;
|
|
183
|
+
} catch {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The missing isolated step of a record already judged: the run keeps its id and gains the step, and nothing else is
|
|
190
|
+
* measured. `undefined` when it owes none, or has no run id to extend. Writes the record whole.
|
|
191
|
+
*/
|
|
192
|
+
export function completeIsolated(path: string, record: QualificationRecord, uri: string, cell: GridCell, runner: IsolatedRunner, env: Readonly<Record<string, string | undefined>>): { readonly record: QualificationRecord; readonly step: RunStep } | undefined {
|
|
193
|
+
if (!owesIsolated(record) || record.run?.steps.some((s) => s.step === RUN_STEP.isolated) === true) return undefined;
|
|
194
|
+
const id = runIdOf(record, join(path, ".."));
|
|
195
|
+
if (id === undefined) return undefined;
|
|
196
|
+
const step = judgeIsolatedRun(runner(uri, cell, env));
|
|
197
|
+
const run: RunBlock = { id, steps: [...(record.run?.steps ?? baseSteps(record)), step] };
|
|
198
|
+
const next = { ...record, run };
|
|
199
|
+
writeFileWhole(path, `${JSON.stringify(next, null, 2)}\n`);
|
|
200
|
+
return { record: next, step };
|
|
201
|
+
}
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
// Copyright (C) 2026 Pau Aliagas <linuxnow@gmail.com>
|
|
3
|
+
/**
|
|
4
|
+
* Keeping a device's qualification records through an upgrade, instead of measuring every plugin again. An upgrade is a
|
|
5
|
+
* different host (`HOSTING_NOTE`): the figures are carried across and judged again, never trusted.
|
|
6
|
+
*
|
|
7
|
+
* `plugin-qualify-sync --rejudge` measures nothing. Each record's probe output goes through the one judge
|
|
8
|
+
* (`judgeProbeOutput`) under today's rules, with the host runs the record already holds, and the verdicts, the tiers and
|
|
9
|
+
* the plugin's pin word are replaced; the figures and their provenance are not touched, and the record says who took the
|
|
10
|
+
* figures and when. A verdict that needs a run the record lacks (an LV2 plugin's omx-clap-host verdict is decided by its
|
|
11
|
+
* adapter run) reads `unknown`, and the record owes that run: nothing is guessed, and a run that never happened gives a
|
|
12
|
+
* plugin no pin word. A record whose plugin's bytes changed, or whose probe output is not the one it names, is left as it
|
|
13
|
+
* is and owes a qualification. A second run changes nothing.
|
|
14
|
+
*
|
|
15
|
+
* `plugin-qualify-sync --memory-only` takes one figure: the footprint of each recorded plugin at the cells a Pi runs,
|
|
16
|
+
* through the probe runner, under the limits of an ordinary run, in a world of its bundle only. Only the `memory` of those
|
|
17
|
+
* cells changes in the record. It judges nothing: a `--rejudge` afterwards reads the footprints. Growth over time needs a
|
|
18
|
+
* soak, which this does not run: the record says so in `notMeasured`.
|
|
19
|
+
*/
|
|
20
|
+
import { mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync } from "node:fs";
|
|
21
|
+
import { tmpdir } from "node:os";
|
|
22
|
+
import { basename, dirname, join } from "node:path";
|
|
23
|
+
|
|
24
|
+
import { outcomeOfVerdict } from "./distributed-records.js";
|
|
25
|
+
import { ADAPTER_RUN_HOSTS, ADMITTED_HOSTS, type HostAdmission } from "./host-admission.js";
|
|
26
|
+
import { OMX_CLAP_HOST_CONFIGURED_EXTENSIONS, shippedHostProfile, type HostProfile } from "./host-profiles.js";
|
|
27
|
+
import { HOSTING_CODE } from "./hosting-codes.js";
|
|
28
|
+
import { readMemoryFootprint } from "./measurement/format.js";
|
|
29
|
+
import type { PluginTarget } from "./loader.js";
|
|
30
|
+
import { cellKey, type GridCell } from "./measurement-grid.js";
|
|
31
|
+
import { pinVerdictOf } from "./pins-file.js";
|
|
32
|
+
import { failedOutcome, judgeProbeOutput, type RecordReason } from "./probe-judge.js";
|
|
33
|
+
import { PROBE_OK, readProbeOutput, sha256Hex, type ProbeGridPoint, type ProbeOutput } from "./probe-output.js";
|
|
34
|
+
import { probeTarget, ProbeRunnerError, type ProbeRun } from "./probe-runner.js";
|
|
35
|
+
import { proberOffer } from "./clap-qualify.js";
|
|
36
|
+
import {
|
|
37
|
+
IN_PROCESS_TIER_HOST,
|
|
38
|
+
ISOLATED_TIER_HOST,
|
|
39
|
+
QUALIFICATION_RECORD_SCHEMA,
|
|
40
|
+
memoryOfCell,
|
|
41
|
+
tiersOf,
|
|
42
|
+
unmeasuredWordOf,
|
|
43
|
+
verdictRows,
|
|
44
|
+
type NotMeasured,
|
|
45
|
+
type OwedMeasurement,
|
|
46
|
+
type QualificationRecord,
|
|
47
|
+
type RecordGridPoint,
|
|
48
|
+
type RecordVerdict,
|
|
49
|
+
type RunBlock,
|
|
50
|
+
} from "./qualification-record.js";
|
|
51
|
+
import { ISOLATED_RESULT, RUN_STEP, pinAfterStep, provenAlone } from "./qualify-isolated.js";
|
|
52
|
+
import { PI_CELLS, PROBE_MEMORY_ONLY_ENV, PROBE_NOTES_ENV } from "./qualify-declarations.js";
|
|
53
|
+
import { SYNC_STATE_SCHEMA, digestFiles, recordStem, type SyncContext, type SyncEntry, type SyncPlugin, type SyncState } from "./qualify-sync.js";
|
|
54
|
+
import type { SuitabilityRating } from "./rating.js";
|
|
55
|
+
import { writeFileWhole } from "./whole-file.js";
|
|
56
|
+
|
|
57
|
+
/** The codes of a measurement a record owes. */
|
|
58
|
+
export const OWED_CODE = {
|
|
59
|
+
isolatedStep: "qualify.sync.isolated-step-owed",
|
|
60
|
+
/** An LV2 verdict of a host that runs it through the adapter, and no measured adapter run. */
|
|
61
|
+
adapterRun: "qualify.sync.adapter-run-owed",
|
|
62
|
+
/** A verdict decided by a run under its host (mod-host, jalv), and no run in the record. */
|
|
63
|
+
hostRun: "qualify.sync.host-run-owed",
|
|
64
|
+
/** The plugin's files are not the bytes the record measured. */
|
|
65
|
+
bytesChanged: "qualify.sync.bytes-changed",
|
|
66
|
+
/** The probe output is missing, is not the copy the record names, or does not read. */
|
|
67
|
+
figuresUnreadable: "qualify.sync.figures-unreadable",
|
|
68
|
+
/** The plugin has a record that holds no figures at all. */
|
|
69
|
+
noFigures: "qualify.sync.no-figures",
|
|
70
|
+
} as const;
|
|
71
|
+
|
|
72
|
+
/** The cells the memory-only pass measures: the ones a Pi runs, 48 kHz at 128 and 256 frames. */
|
|
73
|
+
export const MEMORY_PASS_CELLS: readonly GridCell[] = PI_CELLS;
|
|
74
|
+
|
|
75
|
+
/** What a memory-only pass cannot say, in every record it writes to: growth over time needs a soak. */
|
|
76
|
+
export const MEMORY_PASS_NOT_MEASURED: NotMeasured = { dimension: "memoryGrowth", code: HOSTING_CODE.stabilityUnsoaked };
|
|
77
|
+
|
|
78
|
+
const RECORD_SUFFIX = ".qualification.json";
|
|
79
|
+
|
|
80
|
+
/** The tool as the record says it: this package's own version, read where it is installed. */
|
|
81
|
+
export function rejudgeToolName(): string {
|
|
82
|
+
try {
|
|
83
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { version?: string };
|
|
84
|
+
return `plugin-qualify ${pkg.version ?? "unknown"}`;
|
|
85
|
+
} catch {
|
|
86
|
+
return "plugin-qualify unknown";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A world holding one bundle, as plugin-hostd runs a pinned LV2 plugin, for as long as `body` runs. */
|
|
91
|
+
export function lv2World<T>(bundle: string, body: (world: string) => T): T {
|
|
92
|
+
const world = mkdtempSync(join(tmpdir(), "plugin-qualify-sync-world-"));
|
|
93
|
+
try {
|
|
94
|
+
symlinkSync(bundle, join(world, basename(bundle)));
|
|
95
|
+
return body(world);
|
|
96
|
+
} finally {
|
|
97
|
+
rmSync(world, { recursive: true, force: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// --- the judgment of one record ---------------------------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
/** The probe output with the footprints a memory-only pass merged into the record: the probe copy itself stays as it was taken. */
|
|
104
|
+
function withMemoryRun(output: ProbeOutput, record: QualificationRecord): ProbeOutput {
|
|
105
|
+
const merged = record.memoryRun;
|
|
106
|
+
if (merged === undefined) return output;
|
|
107
|
+
const grid: ProbeGridPoint[] = [...output.grid];
|
|
108
|
+
for (const c of merged.cells) {
|
|
109
|
+
const point = record.measurements.grid.find((p) => p.rate === c.rate && p.quantum === c.quantum);
|
|
110
|
+
const memory = readMemoryFootprint(point?.memory);
|
|
111
|
+
if (memory === undefined) continue;
|
|
112
|
+
const at = grid.findIndex((p) => p.rate === c.rate && p.quantum === c.quantum);
|
|
113
|
+
if (at >= 0) grid[at] = { ...grid[at]!, memory };
|
|
114
|
+
else grid.push({ rate: c.rate, quantum: c.quantum, outcome: PROBE_OK, memory });
|
|
115
|
+
}
|
|
116
|
+
return { ...output, grid };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The offer a profile is judged under for a CLAP plugin; `undefined` for a host the prober cannot stand in for. */
|
|
120
|
+
const offerIdOf = (profile: HostProfile): string | undefined => {
|
|
121
|
+
const offer = proberOffer(profile);
|
|
122
|
+
return offer === undefined ? undefined : offer.length > 0 ? "custom" : "default";
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The profiles a record is judged under: the hosts it has verdicts for, the console's two tiers, the host of this run, and
|
|
127
|
+
* the Pi boards, whose budgets read the footprints. A host only joins a CLAP plugin's record of its own offer.
|
|
128
|
+
*/
|
|
129
|
+
function rejudgeProfiles(record: QualificationRecord, output: ProbeOutput, host: string): { profiles: HostProfile[]; kept: RecordVerdict[] } {
|
|
130
|
+
const format = output.plugin.format;
|
|
131
|
+
const added = [IN_PROCESS_TIER_HOST, ISOLATED_TIER_HOST[format], host, ...ADAPTER_RUN_HOSTS].filter((id): id is string => id !== undefined);
|
|
132
|
+
const profiles = new Map<string, HostProfile>();
|
|
133
|
+
const kept: RecordVerdict[] = [];
|
|
134
|
+
for (const v of record.verdicts) {
|
|
135
|
+
const p = shippedHostProfile(v.host);
|
|
136
|
+
if (p === undefined) kept.push(v);
|
|
137
|
+
else profiles.set(p.id, p);
|
|
138
|
+
}
|
|
139
|
+
for (const id of added) {
|
|
140
|
+
const p = shippedHostProfile(id);
|
|
141
|
+
if (p === undefined || profiles.has(id)) continue;
|
|
142
|
+
if (format === "lv2" || offerIdOf(p) === output.offer.id) profiles.set(id, p);
|
|
143
|
+
}
|
|
144
|
+
return { profiles: [...profiles.values()], kept };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The runs the record holds, as the judge takes them: its adapter run, and each `run` verdict of a host that is decided by one. */
|
|
148
|
+
function admissionsOf(record: QualificationRecord): Record<string, HostAdmission> {
|
|
149
|
+
const out: Record<string, HostAdmission> = {};
|
|
150
|
+
for (const v of record.verdicts) {
|
|
151
|
+
const host = ADMITTED_HOSTS.find((h) => h === v.host);
|
|
152
|
+
if (host === undefined || v.arm !== "run") continue;
|
|
153
|
+
const r = v.reasons.find((x) => x.dimension === "hostAdmission");
|
|
154
|
+
out[host] = r === undefined ? { host, measured: true, admitted: true, params: {} } : { host, measured: r.rating !== "unknown", admitted: false, code: r.code, params: r.params };
|
|
155
|
+
}
|
|
156
|
+
const a = record.adapter;
|
|
157
|
+
if (a?.measured === true) {
|
|
158
|
+
const run: HostAdmission = { host: "omx-clap-host", measured: true, admitted: a.admitted, ...(a.code === undefined ? {} : { code: a.code }), params: a.params };
|
|
159
|
+
for (const id of ADAPTER_RUN_HOSTS) out[id] = run;
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const owedReason = (code: string, params: RecordReason["params"]): RecordReason => ({ dimension: "hostAdmission", rating: "unknown", code, params });
|
|
165
|
+
|
|
166
|
+
/** The runs the verdicts of these profiles need and the record does not hold. A run that did not end well decides nothing, so it owes none. */
|
|
167
|
+
function runsOwed(record: QualificationRecord, output: ProbeOutput, profiles: readonly HostProfile[]): { reasons: Record<string, RecordReason>; owes: OwedMeasurement[] } {
|
|
168
|
+
const reasons: Record<string, RecordReason> = {};
|
|
169
|
+
const owes: OwedMeasurement[] = [];
|
|
170
|
+
if (failedOutcome(output) !== undefined) return { reasons, owes };
|
|
171
|
+
if (output.plugin.format === "lv2" && record.adapter?.measured !== true) {
|
|
172
|
+
const why = record.adapter?.code;
|
|
173
|
+
const params: RecordReason["params"] = why === undefined ? {} : { lastRun: why };
|
|
174
|
+
for (const p of profiles) if (ADAPTER_RUN_HOSTS.includes(p.id)) reasons[p.id] = owedReason(OWED_CODE.adapterRun, params);
|
|
175
|
+
owes.push({ measurement: "adapter-run", host: "omx-clap-host", code: OWED_CODE.adapterRun, ...(why === undefined ? {} : { detail: why }) });
|
|
176
|
+
}
|
|
177
|
+
for (const v of record.verdicts) {
|
|
178
|
+
if (!ADMITTED_HOSTS.some((h) => h === v.host) || v.arm === "run") continue;
|
|
179
|
+
reasons[v.host] = owedReason(OWED_CODE.hostRun, { host: v.host });
|
|
180
|
+
owes.push({ measurement: "host-run", host: v.host, code: OWED_CODE.hostRun });
|
|
181
|
+
}
|
|
182
|
+
return { reasons, owes };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export class RejudgeRefusal extends Error {}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* One record judged again from its probe output, with what it owes. The figures, who took them and when are as they were;
|
|
189
|
+
* only the verdicts, the tiers and the cost reasons beside them are new. `at` is the prior re-judge's when nothing else
|
|
190
|
+
* differs, so that a second run leaves the file alone.
|
|
191
|
+
*/
|
|
192
|
+
export function rejudgeRecord(record: QualificationRecord, probeBytes: Uint8Array, options: { readonly host: string; readonly by: string; readonly at: string }): { record: QualificationRecord; owes: readonly OwedMeasurement[] } {
|
|
193
|
+
if (sha256Hex(probeBytes) !== record.probe.sha256) throw new RejudgeRefusal(`${record.probe.file} is not the probe output the record names (its SHA-256 differs)`);
|
|
194
|
+
const read = readProbeOutput(Buffer.from(probeBytes).toString("utf8"));
|
|
195
|
+
if (!read.ok) throw new RejudgeRefusal(`${record.probe.file}: ${read.code}: ${read.problem}`);
|
|
196
|
+
const output = withMemoryRun(read.output, record);
|
|
197
|
+
const { profiles, kept } = rejudgeProfiles(record, output, options.host);
|
|
198
|
+
const { reasons, owes: runs } = runsOwed(record, output, profiles);
|
|
199
|
+
const judgment = judgeProbeOutput(output, profiles, { admissions: admissionsOf(record), owed: reasons });
|
|
200
|
+
// decides no verdict: a record from before the steps that reads isolated stays offered, runs alone, and is not proven by the step
|
|
201
|
+
const readsIsolated = judgment.hosts.some((h) => h.verdict.measured && h.verdict.rating === "conditional");
|
|
202
|
+
const owes = readsIsolated && !provenAlone(record) ? [...runs, { measurement: "isolated-step" as const, code: OWED_CODE.isolatedStep }] : runs;
|
|
203
|
+
const memory = record.memoryRun === undefined ? {} : { memory: { tool: record.memoryRun.tool, measuredAt: record.memoryRun.measuredAt } };
|
|
204
|
+
const a = record.adapter;
|
|
205
|
+
const adapterTaken = a?.versions === undefined || a.measuredAt === undefined ? {} : { adapter: { versions: a.versions, measuredAt: a.measuredAt } };
|
|
206
|
+
const { rejudged: prior, ...rest } = record;
|
|
207
|
+
const next = (at: string): QualificationRecord => ({
|
|
208
|
+
...rest,
|
|
209
|
+
verdicts: [...verdictRows(judgment), ...kept],
|
|
210
|
+
tiers: tiersOf(judgment),
|
|
211
|
+
cost: judgment.hosts.map((h) => ({ host: h.verdict.host, ...h.cost })),
|
|
212
|
+
rejudged: {
|
|
213
|
+
at,
|
|
214
|
+
by: options.by,
|
|
215
|
+
figures: { tool: record.tool, measuredAt: record.measuredAt, runId: read.output.run.id, ...memory, ...adapterTaken },
|
|
216
|
+
...(owes.length === 0 ? {} : { owes }),
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
const same = prior !== undefined && JSON.stringify(next(prior.at)) === JSON.stringify(record);
|
|
220
|
+
return { record: same ? record : next(options.at), owes };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// --- a device's records -----------------------------------------------------------------------------------------------
|
|
224
|
+
|
|
225
|
+
/** The file that lists what a re-judge left owing, beside the state file. */
|
|
226
|
+
export const owedFile = (stateFile: string): string => join(dirname(stateFile), "qualify-owed.json");
|
|
227
|
+
|
|
228
|
+
export const OWED_SCHEMA = "plugin-qualify.owed/1";
|
|
229
|
+
|
|
230
|
+
export interface OwingRecord {
|
|
231
|
+
readonly plugin: string;
|
|
232
|
+
/** The record's file name, when the plugin has one. */
|
|
233
|
+
readonly record?: string;
|
|
234
|
+
readonly owes: readonly OwedMeasurement[];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface RejudgeResult {
|
|
238
|
+
readonly state: SyncState;
|
|
239
|
+
readonly changed: number;
|
|
240
|
+
readonly unchanged: number;
|
|
241
|
+
readonly owing: readonly OwingRecord[];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** The entries whose files are not the bytes they were qualified from, and their records' stems. */
|
|
245
|
+
function changedStems(state: SyncState): { stems: Set<string>; entries: Set<string> } {
|
|
246
|
+
const stems = new Set<string>();
|
|
247
|
+
const entries = new Set<string>();
|
|
248
|
+
for (const [key, e] of Object.entries(state.entries)) {
|
|
249
|
+
const now = digestFiles(e.root, e.files.map((f) => f.path), e.files);
|
|
250
|
+
if (now !== undefined && now.every((f) => e.files.some((x) => x.path === f.path && x.sha256 === f.sha256))) continue;
|
|
251
|
+
entries.add(key);
|
|
252
|
+
for (const p of e.plugins) {
|
|
253
|
+
const stem = p.record === undefined ? undefined : recordStem(p.record);
|
|
254
|
+
if (stem !== undefined) stems.add(stem);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return { stems, entries };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const readRecord = (path: string): QualificationRecord | undefined => {
|
|
261
|
+
try {
|
|
262
|
+
const r = JSON.parse(readFileSync(path, "utf8")) as QualificationRecord;
|
|
263
|
+
return r.schema === QUALIFICATION_RECORD_SCHEMA ? r : undefined;
|
|
264
|
+
} catch {
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const nameOf = (record: QualificationRecord): string => record.plugin.id;
|
|
270
|
+
|
|
271
|
+
/** A state plugin with the verdict its record now holds for the host: the pin's files stay as they are, only its word follows. */
|
|
272
|
+
function pluginWithVerdict(plugin: SyncPlugin, v: RecordVerdict, run?: RunBlock): SyncPlugin {
|
|
273
|
+
const { pin, code: _code, ...rest } = plugin;
|
|
274
|
+
const word = v.measured ? pinVerdictOf(v.rating as SuitabilityRating) : undefined;
|
|
275
|
+
// a rating does not make a plugin isolated: a run seen alone does, and a re-judge measures nothing. A record from before
|
|
276
|
+
// the steps keeps its word until a completion has run it.
|
|
277
|
+
if (word === "isolated" && run !== undefined) {
|
|
278
|
+
const step = run.steps.find((s) => s.step === RUN_STEP.isolated);
|
|
279
|
+
const kept = pinAfterStep(pin, step ?? { step: RUN_STEP.isolated, result: ISOLATED_RESULT.notRun });
|
|
280
|
+
const refused = step?.result === ISOLATED_RESULT.refused;
|
|
281
|
+
return { ...rest, outcome: refused ? "refused" : outcomeOfVerdict(v), ...(refused && step.code !== undefined ? { code: step.code } : v.deciding === undefined ? {} : { code: v.deciding }), ...(kept === undefined ? {} : { pin: kept }) };
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
...rest,
|
|
285
|
+
outcome: outcomeOfVerdict(v),
|
|
286
|
+
...(v.deciding === undefined ? {} : { code: v.deciding }),
|
|
287
|
+
...(pin === undefined ? {} : { pin: { uri: pin.uri, integrity: pin.integrity, ...(word === undefined ? {} : { verdict: word }) } }),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Every record of the device's qualification directory judged again, the state's outcomes and pin words brought into line,
|
|
293
|
+
* and the list of what is owed written beside the state file. Each file is written whole, and only when it differs.
|
|
294
|
+
*/
|
|
295
|
+
export function rejudgeState(ctx: SyncContext, state: SyncState, now: () => string = () => new Date().toISOString()): RejudgeResult {
|
|
296
|
+
const { qualificationDir: dir, hostProfile, stateFile } = ctx.settings;
|
|
297
|
+
const by = rejudgeToolName();
|
|
298
|
+
const at = now();
|
|
299
|
+
const changed = changedStems(state);
|
|
300
|
+
const judged = new Map<string, QualificationRecord>();
|
|
301
|
+
const owing: OwingRecord[] = [];
|
|
302
|
+
let changedCount = 0;
|
|
303
|
+
let unchanged = 0;
|
|
304
|
+
let names: string[] = [];
|
|
305
|
+
try {
|
|
306
|
+
names = readdirSync(dir).filter((f) => f.endsWith(RECORD_SUFFIX)).sort();
|
|
307
|
+
} catch {
|
|
308
|
+
// no directory, no record
|
|
309
|
+
}
|
|
310
|
+
for (const name of names) {
|
|
311
|
+
const path = join(dir, name);
|
|
312
|
+
const record = readRecord(path);
|
|
313
|
+
if (record === undefined) {
|
|
314
|
+
ctx.log(`${name}: does not read as a record; left as it is`);
|
|
315
|
+
owing.push({ plugin: name, record: name, owes: [{ measurement: "qualification", code: OWED_CODE.figuresUnreadable }] });
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
if (changed.stems.has(recordStem(name) ?? "")) {
|
|
319
|
+
owing.push({ plugin: nameOf(record), record: name, owes: [{ measurement: "qualification", code: OWED_CODE.bytesChanged }] });
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
let result: ReturnType<typeof rejudgeRecord>;
|
|
323
|
+
try {
|
|
324
|
+
result = rejudgeRecord(record, readFileSync(join(dir, record.probe.file)), { host: hostProfile.id, by, at });
|
|
325
|
+
} catch (e) {
|
|
326
|
+
const detail = e instanceof RejudgeRefusal ? e.message : `${record.probe.file}: ${(e as NodeJS.ErrnoException).code ?? String(e)}`;
|
|
327
|
+
ctx.log(`${name}: ${detail}; left as it is`);
|
|
328
|
+
owing.push({ plugin: nameOf(record), record: name, owes: [{ measurement: "qualification", code: OWED_CODE.figuresUnreadable, detail }] });
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (result.record === record) unchanged++;
|
|
332
|
+
else {
|
|
333
|
+
writeFileWhole(path, `${JSON.stringify(result.record, null, 2)}\n`);
|
|
334
|
+
changedCount++;
|
|
335
|
+
}
|
|
336
|
+
judged.set(name, result.record);
|
|
337
|
+
if (result.owes.length > 0) owing.push({ plugin: nameOf(record), record: name, owes: result.owes });
|
|
338
|
+
}
|
|
339
|
+
const entries: Record<string, SyncEntry> = {};
|
|
340
|
+
for (const [key, entry] of Object.entries(state.entries)) {
|
|
341
|
+
if (changed.entries.has(key)) {
|
|
342
|
+
entries[key] = entry;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
const plugins = entry.plugins.map((plugin) => {
|
|
346
|
+
const record = plugin.record === undefined ? undefined : judged.get(basename(plugin.record));
|
|
347
|
+
const v = record?.verdicts.find((x) => x.host === hostProfile.id);
|
|
348
|
+
if (v !== undefined) return pluginWithVerdict(plugin, v, record?.run);
|
|
349
|
+
if (record === undefined && plugin.outcome === "unmeasured" && plugin.record?.endsWith(RECORD_SUFFIX) !== true) {
|
|
350
|
+
owing.push({ plugin: plugin.uri, ...(plugin.record === undefined ? {} : { record: basename(plugin.record) }), owes: [{ measurement: "qualification", code: OWED_CODE.noFigures }] });
|
|
351
|
+
}
|
|
352
|
+
return plugin;
|
|
353
|
+
});
|
|
354
|
+
entries[key] = { ...entry, plugins };
|
|
355
|
+
}
|
|
356
|
+
owing.sort((a, b) => (a.record ?? a.plugin).localeCompare(b.record ?? b.plugin));
|
|
357
|
+
for (const o of owing) ctx.log(`owes: ${o.plugin}: ${o.owes.map((x) => `${x.measurement}${x.host === undefined ? "" : ` under ${x.host}`}`).join(", ")}`);
|
|
358
|
+
writeIfDifferent(owedFile(stateFile), `${JSON.stringify({ schema: OWED_SCHEMA, owing }, null, 1)}\n`);
|
|
359
|
+
return { state: { schema: SYNC_STATE_SCHEMA, entries }, changed: changedCount, unchanged, owing };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function writeIfDifferent(path: string, text: string): void {
|
|
363
|
+
try {
|
|
364
|
+
if (readFileSync(path, "utf8") === text) return;
|
|
365
|
+
} catch {
|
|
366
|
+
// not there yet
|
|
367
|
+
}
|
|
368
|
+
writeFileWhole(path, text);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// --- the memory-only pass ---------------------------------------------------------------------------------------------
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* A memory-only run's footprints in a record: the `memory` of each cell and nothing else of it, a cell the record's grid
|
|
375
|
+
* does not hold joined with no other figure. A cell the run could not read says why instead of a figure, so that it is
|
|
376
|
+
* never read as fitting. Pure.
|
|
377
|
+
*/
|
|
378
|
+
export function mergeMemoryRun(record: QualificationRecord, output: ProbeOutput, cells: readonly GridCell[]): QualificationRecord {
|
|
379
|
+
const grid: RecordGridPoint[] = [...record.measurements.grid];
|
|
380
|
+
const said: { rate: number; quantum: number; outcome: string; memoryLimit?: { bytes: number; mechanism: string } }[] = [];
|
|
381
|
+
for (const c of cells) {
|
|
382
|
+
const p = output.grid.find((g) => cellKey(g) === cellKey(c));
|
|
383
|
+
const outcome = p?.outcome ?? output.run.outcome;
|
|
384
|
+
const memory = p?.memory ?? { unmeasuredReason: unmeasuredWordOf(outcome), unmeasuredDetail: `the memory-only run ended ${outcome}` };
|
|
385
|
+
const figures = memoryOfCell({ rate: c.rate, quantum: c.quantum, outcome, memory });
|
|
386
|
+
const at = grid.findIndex((g) => cellKey(g) === cellKey(c));
|
|
387
|
+
if (at >= 0) grid[at] = { ...grid[at]!, ...figures };
|
|
388
|
+
else grid.push({ rate: c.rate, quantum: c.quantum, outcome: PROBE_OK, latency: { unmeasuredReason: "not-attempted", code: HOSTING_CODE.latencyUnmeasured }, ...figures });
|
|
389
|
+
said.push({ rate: c.rate, quantum: c.quantum, outcome, ...(p?.memoryLimit === undefined ? {} : { memoryLimit: p.memoryLimit }) });
|
|
390
|
+
}
|
|
391
|
+
const notMeasured = record.notMeasured ?? [];
|
|
392
|
+
return {
|
|
393
|
+
...record,
|
|
394
|
+
measurements: { ...record.measurements, grid },
|
|
395
|
+
notMeasured: notMeasured.some((n) => n.dimension === MEMORY_PASS_NOT_MEASURED.dimension) ? notMeasured : [...notMeasured, MEMORY_PASS_NOT_MEASURED],
|
|
396
|
+
memoryRun: { tool: output.run.tools, measuredAt: output.run.startedAt, runId: output.run.id, cells: said },
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** Whether a record already holds this pass's footprints. */
|
|
401
|
+
const memoryTaken = (record: QualificationRecord, cells: readonly GridCell[]): boolean =>
|
|
402
|
+
record.memoryRun !== undefined && cells.every((c) => record.memoryRun!.cells.some((m) => cellKey(m) === cellKey(c)));
|
|
403
|
+
|
|
404
|
+
export interface MemoryPassResult {
|
|
405
|
+
readonly measured: number;
|
|
406
|
+
readonly already: number;
|
|
407
|
+
readonly failed: number;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** The extensions a record was measured with: its file says which offer it is. */
|
|
411
|
+
const offerOf = (recordName: string): readonly string[] => (recordName.endsWith(`.custom${RECORD_SUFFIX}`) ? OMX_CLAP_HOST_CONFIGURED_EXTENSIONS : []);
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* The footprint of each plugin of the state, at `MEMORY_PASS_CELLS`, merged into the record its verdict for this run's host
|
|
415
|
+
* came from. One plugin's failure is that plugin's; each record is written whole as its plugin ends, so a pass cut short
|
|
416
|
+
* keeps what it finished, and a pass run again skips those unless `force`.
|
|
417
|
+
*/
|
|
418
|
+
export function memoryPass(ctx: SyncContext, state: SyncState, options: { readonly force?: boolean; readonly run?: ProbeRun } = {}): MemoryPassResult {
|
|
419
|
+
const { memory, budgetS, memoryNotes } = ctx.settings;
|
|
420
|
+
const count = { measured: 0, already: 0, failed: 0 };
|
|
421
|
+
const changed = changedStems(state);
|
|
422
|
+
for (const [key, entry] of Object.entries(state.entries)) {
|
|
423
|
+
if (changed.entries.has(key)) {
|
|
424
|
+
ctx.log(`${key}: its files changed since it was measured; the sync measures it whole`);
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
for (const plugin of entry.plugins) {
|
|
428
|
+
if (plugin.record === undefined || !plugin.record.endsWith(RECORD_SUFFIX)) continue;
|
|
429
|
+
const name = basename(plugin.record);
|
|
430
|
+
const path = join(ctx.settings.qualificationDir, name);
|
|
431
|
+
const record = readRecord(path);
|
|
432
|
+
if (record === undefined) {
|
|
433
|
+
ctx.log(`${plugin.uri}: its record ${name} does not read; no footprint taken`);
|
|
434
|
+
count.failed++;
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
if (options.force !== true && memoryTaken(record, MEMORY_PASS_CELLS)) {
|
|
438
|
+
count.already++;
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
const started = Date.now();
|
|
442
|
+
const env = { ...ctx.env, [PROBE_MEMORY_ONLY_ENV]: "1", [PROBE_NOTES_ENV]: String(memoryNotes) };
|
|
443
|
+
const limits = { rates: [...new Set(MEMORY_PASS_CELLS.map((c) => c.rate))], cells: MEMORY_PASS_CELLS, wallS: budgetS, ...(memory === undefined ? {} : { memory }), ...(options.run === undefined ? {} : { run: options.run }) };
|
|
444
|
+
try {
|
|
445
|
+
const probed =
|
|
446
|
+
entry.format === "clap"
|
|
447
|
+
? probeTarget(clapTarget(key, entry, record), { ...limits, offer: offerOf(name), env })
|
|
448
|
+
: lv2World(entry.root, (world) => probeTarget({ format: "lv2", uri: record.plugin.id, bundle: entry.root }, { ...limits, env: { ...env, LV2_PATH: world } }));
|
|
449
|
+
if (probed.output.binary.sha256 !== record.binary.sha256) throw new ProbeRunnerError(`measured binary ${probed.output.binary.sha256.slice(0, 12)}, the record's is ${record.binary.sha256.slice(0, 12)}`);
|
|
450
|
+
writeFileWhole(path, `${JSON.stringify(mergeMemoryRun(record, probed.output, MEMORY_PASS_CELLS), null, 2)}\n`);
|
|
451
|
+
count.measured++;
|
|
452
|
+
ctx.log(`${plugin.uri}: footprint taken at ${MEMORY_PASS_CELLS.map(cellKey).join(", ")} in ${((Date.now() - started) / 1000).toFixed(1)} s`);
|
|
453
|
+
} catch (e) {
|
|
454
|
+
if (!(e instanceof ProbeRunnerError)) throw e;
|
|
455
|
+
count.failed++;
|
|
456
|
+
ctx.log(`${plugin.uri}: no footprint: ${e.message}`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return count;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function clapTarget(key: string, entry: SyncEntry, record: QualificationRecord): PluginTarget {
|
|
464
|
+
const file = key.startsWith("clap:") ? key.slice("clap:".length) : join(entry.root, record.binary.files[0]?.path ?? "");
|
|
465
|
+
return { format: "clap", uri: `urn:clap:${record.plugin.id}`, bundle: entry.root, binary: basename(file), binaryPath: file };
|
|
466
|
+
}
|