@openmixer/plugin-qualify 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -2
- package/bin/plugin-qualify-sync.mjs +3 -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 +2 -0
- package/dist/host-admission.js +12 -3
- package/dist/host-admission.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/probe-judge.d.ts +11 -0
- package/dist/probe-judge.js +4 -1
- 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 +90 -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 +25 -0
- package/dist/qualify-declarations.js +17 -1
- package/dist/qualify-declarations.js.map +1 -1
- package/dist/qualify-rejudge.d.ts +81 -0
- package/dist/qualify-rejudge.js +421 -0
- package/dist/qualify-rejudge.js.map +1 -0
- package/dist/qualify-sync.d.ts +72 -1
- package/dist/qualify-sync.js +176 -17
- 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/distributed-records.ts +1 -1
- package/src/host-admission.ts +13 -3
- package/src/index.ts +2 -0
- package/src/probe-judge.ts +8 -1
- package/src/probe-runner.ts +2 -2
- package/src/qualification-record.ts +100 -15
- package/src/qualify-adapter-pass.ts +278 -0
- package/src/qualify-declarations.ts +19 -1
- package/src/qualify-rejudge.ts +452 -0
- package/src/qualify-sync.ts +192 -17
- package/tools/lv2_resolve.py +49 -0
- package/tools/mod-host-admit.mjs +21 -5
|
@@ -0,0 +1,452 @@
|
|
|
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
|
+
} from "./qualification-record.js";
|
|
50
|
+
import { PI_CELLS, PROBE_MEMORY_ONLY_ENV, PROBE_NOTES_ENV } from "./qualify-declarations.js";
|
|
51
|
+
import { SYNC_STATE_SCHEMA, digestFiles, recordStem, type SyncContext, type SyncEntry, type SyncPlugin, type SyncState } from "./qualify-sync.js";
|
|
52
|
+
import type { SuitabilityRating } from "./rating.js";
|
|
53
|
+
import { writeFileWhole } from "./whole-file.js";
|
|
54
|
+
|
|
55
|
+
/** The codes of a measurement a record owes. */
|
|
56
|
+
export const OWED_CODE = {
|
|
57
|
+
/** An LV2 verdict of a host that runs it through the adapter, and no measured adapter run. */
|
|
58
|
+
adapterRun: "qualify.sync.adapter-run-owed",
|
|
59
|
+
/** A verdict decided by a run under its host (mod-host, jalv), and no run in the record. */
|
|
60
|
+
hostRun: "qualify.sync.host-run-owed",
|
|
61
|
+
/** The plugin's files are not the bytes the record measured. */
|
|
62
|
+
bytesChanged: "qualify.sync.bytes-changed",
|
|
63
|
+
/** The probe output is missing, is not the copy the record names, or does not read. */
|
|
64
|
+
figuresUnreadable: "qualify.sync.figures-unreadable",
|
|
65
|
+
/** The plugin has a record that holds no figures at all. */
|
|
66
|
+
noFigures: "qualify.sync.no-figures",
|
|
67
|
+
} as const;
|
|
68
|
+
|
|
69
|
+
/** The cells the memory-only pass measures: the ones a Pi runs, 48 kHz at 128 and 256 frames. */
|
|
70
|
+
export const MEMORY_PASS_CELLS: readonly GridCell[] = PI_CELLS;
|
|
71
|
+
|
|
72
|
+
/** What a memory-only pass cannot say, in every record it writes to: growth over time needs a soak. */
|
|
73
|
+
export const MEMORY_PASS_NOT_MEASURED: NotMeasured = { dimension: "memoryGrowth", code: HOSTING_CODE.stabilityUnsoaked };
|
|
74
|
+
|
|
75
|
+
const RECORD_SUFFIX = ".qualification.json";
|
|
76
|
+
|
|
77
|
+
/** The tool as the record says it: this package's own version, read where it is installed. */
|
|
78
|
+
export function rejudgeToolName(): string {
|
|
79
|
+
try {
|
|
80
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { version?: string };
|
|
81
|
+
return `plugin-qualify ${pkg.version ?? "unknown"}`;
|
|
82
|
+
} catch {
|
|
83
|
+
return "plugin-qualify unknown";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A world holding one bundle, as plugin-hostd runs a pinned LV2 plugin, for as long as `body` runs. */
|
|
88
|
+
export function lv2World<T>(bundle: string, body: (world: string) => T): T {
|
|
89
|
+
const world = mkdtempSync(join(tmpdir(), "plugin-qualify-sync-world-"));
|
|
90
|
+
try {
|
|
91
|
+
symlinkSync(bundle, join(world, basename(bundle)));
|
|
92
|
+
return body(world);
|
|
93
|
+
} finally {
|
|
94
|
+
rmSync(world, { recursive: true, force: true });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// --- the judgment of one record ---------------------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
/** The probe output with the footprints a memory-only pass merged into the record: the probe copy itself stays as it was taken. */
|
|
101
|
+
function withMemoryRun(output: ProbeOutput, record: QualificationRecord): ProbeOutput {
|
|
102
|
+
const merged = record.memoryRun;
|
|
103
|
+
if (merged === undefined) return output;
|
|
104
|
+
const grid: ProbeGridPoint[] = [...output.grid];
|
|
105
|
+
for (const c of merged.cells) {
|
|
106
|
+
const point = record.measurements.grid.find((p) => p.rate === c.rate && p.quantum === c.quantum);
|
|
107
|
+
const memory = readMemoryFootprint(point?.memory);
|
|
108
|
+
if (memory === undefined) continue;
|
|
109
|
+
const at = grid.findIndex((p) => p.rate === c.rate && p.quantum === c.quantum);
|
|
110
|
+
if (at >= 0) grid[at] = { ...grid[at]!, memory };
|
|
111
|
+
else grid.push({ rate: c.rate, quantum: c.quantum, outcome: PROBE_OK, memory });
|
|
112
|
+
}
|
|
113
|
+
return { ...output, grid };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The offer a profile is judged under for a CLAP plugin; `undefined` for a host the prober cannot stand in for. */
|
|
117
|
+
const offerIdOf = (profile: HostProfile): string | undefined => {
|
|
118
|
+
const offer = proberOffer(profile);
|
|
119
|
+
return offer === undefined ? undefined : offer.length > 0 ? "custom" : "default";
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The profiles a record is judged under: the hosts it has verdicts for, the console's two tiers, the host of this run, and
|
|
124
|
+
* the Pi boards, whose budgets read the footprints. A host only joins a CLAP plugin's record of its own offer.
|
|
125
|
+
*/
|
|
126
|
+
function rejudgeProfiles(record: QualificationRecord, output: ProbeOutput, host: string): { profiles: HostProfile[]; kept: RecordVerdict[] } {
|
|
127
|
+
const format = output.plugin.format;
|
|
128
|
+
const added = [IN_PROCESS_TIER_HOST, ISOLATED_TIER_HOST[format], host, ...ADAPTER_RUN_HOSTS].filter((id): id is string => id !== undefined);
|
|
129
|
+
const profiles = new Map<string, HostProfile>();
|
|
130
|
+
const kept: RecordVerdict[] = [];
|
|
131
|
+
for (const v of record.verdicts) {
|
|
132
|
+
const p = shippedHostProfile(v.host);
|
|
133
|
+
if (p === undefined) kept.push(v);
|
|
134
|
+
else profiles.set(p.id, p);
|
|
135
|
+
}
|
|
136
|
+
for (const id of added) {
|
|
137
|
+
const p = shippedHostProfile(id);
|
|
138
|
+
if (p === undefined || profiles.has(id)) continue;
|
|
139
|
+
if (format === "lv2" || offerIdOf(p) === output.offer.id) profiles.set(id, p);
|
|
140
|
+
}
|
|
141
|
+
return { profiles: [...profiles.values()], kept };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 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. */
|
|
145
|
+
function admissionsOf(record: QualificationRecord): Record<string, HostAdmission> {
|
|
146
|
+
const out: Record<string, HostAdmission> = {};
|
|
147
|
+
for (const v of record.verdicts) {
|
|
148
|
+
const host = ADMITTED_HOSTS.find((h) => h === v.host);
|
|
149
|
+
if (host === undefined || v.arm !== "run") continue;
|
|
150
|
+
const r = v.reasons.find((x) => x.dimension === "hostAdmission");
|
|
151
|
+
out[host] = r === undefined ? { host, measured: true, admitted: true, params: {} } : { host, measured: r.rating !== "unknown", admitted: false, code: r.code, params: r.params };
|
|
152
|
+
}
|
|
153
|
+
const a = record.adapter;
|
|
154
|
+
if (a?.measured === true) {
|
|
155
|
+
const run: HostAdmission = { host: "omx-clap-host", measured: true, admitted: a.admitted, ...(a.code === undefined ? {} : { code: a.code }), params: a.params };
|
|
156
|
+
for (const id of ADAPTER_RUN_HOSTS) out[id] = run;
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const owedReason = (code: string, params: RecordReason["params"]): RecordReason => ({ dimension: "hostAdmission", rating: "unknown", code, params });
|
|
162
|
+
|
|
163
|
+
/** 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. */
|
|
164
|
+
function runsOwed(record: QualificationRecord, output: ProbeOutput, profiles: readonly HostProfile[]): { reasons: Record<string, RecordReason>; owes: OwedMeasurement[] } {
|
|
165
|
+
const reasons: Record<string, RecordReason> = {};
|
|
166
|
+
const owes: OwedMeasurement[] = [];
|
|
167
|
+
if (failedOutcome(output) !== undefined) return { reasons, owes };
|
|
168
|
+
if (output.plugin.format === "lv2" && record.adapter?.measured !== true) {
|
|
169
|
+
const why = record.adapter?.code;
|
|
170
|
+
const params: RecordReason["params"] = why === undefined ? {} : { lastRun: why };
|
|
171
|
+
for (const p of profiles) if (ADAPTER_RUN_HOSTS.includes(p.id)) reasons[p.id] = owedReason(OWED_CODE.adapterRun, params);
|
|
172
|
+
owes.push({ measurement: "adapter-run", host: "omx-clap-host", code: OWED_CODE.adapterRun, ...(why === undefined ? {} : { detail: why }) });
|
|
173
|
+
}
|
|
174
|
+
for (const v of record.verdicts) {
|
|
175
|
+
if (!ADMITTED_HOSTS.some((h) => h === v.host) || v.arm === "run") continue;
|
|
176
|
+
reasons[v.host] = owedReason(OWED_CODE.hostRun, { host: v.host });
|
|
177
|
+
owes.push({ measurement: "host-run", host: v.host, code: OWED_CODE.hostRun });
|
|
178
|
+
}
|
|
179
|
+
return { reasons, owes };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export class RejudgeRefusal extends Error {}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* One record judged again from its probe output, with what it owes. The figures, who took them and when are as they were;
|
|
186
|
+
* only the verdicts, the tiers and the cost reasons beside them are new. `at` is the prior re-judge's when nothing else
|
|
187
|
+
* differs, so that a second run leaves the file alone.
|
|
188
|
+
*/
|
|
189
|
+
export function rejudgeRecord(record: QualificationRecord, probeBytes: Uint8Array, options: { readonly host: string; readonly by: string; readonly at: string }): { record: QualificationRecord; owes: readonly OwedMeasurement[] } {
|
|
190
|
+
if (sha256Hex(probeBytes) !== record.probe.sha256) throw new RejudgeRefusal(`${record.probe.file} is not the probe output the record names (its SHA-256 differs)`);
|
|
191
|
+
const read = readProbeOutput(Buffer.from(probeBytes).toString("utf8"));
|
|
192
|
+
if (!read.ok) throw new RejudgeRefusal(`${record.probe.file}: ${read.code}: ${read.problem}`);
|
|
193
|
+
const output = withMemoryRun(read.output, record);
|
|
194
|
+
const { profiles, kept } = rejudgeProfiles(record, output, options.host);
|
|
195
|
+
const { reasons, owes } = runsOwed(record, output, profiles);
|
|
196
|
+
const judgment = judgeProbeOutput(output, profiles, { admissions: admissionsOf(record), owed: reasons });
|
|
197
|
+
const memory = record.memoryRun === undefined ? {} : { memory: { tool: record.memoryRun.tool, measuredAt: record.memoryRun.measuredAt } };
|
|
198
|
+
const a = record.adapter;
|
|
199
|
+
const adapterTaken = a?.versions === undefined || a.measuredAt === undefined ? {} : { adapter: { versions: a.versions, measuredAt: a.measuredAt } };
|
|
200
|
+
const { rejudged: prior, ...rest } = record;
|
|
201
|
+
const next = (at: string): QualificationRecord => ({
|
|
202
|
+
...rest,
|
|
203
|
+
verdicts: [...verdictRows(judgment), ...kept],
|
|
204
|
+
tiers: tiersOf(judgment),
|
|
205
|
+
cost: judgment.hosts.map((h) => ({ host: h.verdict.host, ...h.cost })),
|
|
206
|
+
rejudged: {
|
|
207
|
+
at,
|
|
208
|
+
by: options.by,
|
|
209
|
+
figures: { tool: record.tool, measuredAt: record.measuredAt, runId: read.output.run.id, ...memory, ...adapterTaken },
|
|
210
|
+
...(owes.length === 0 ? {} : { owes }),
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
const same = prior !== undefined && JSON.stringify(next(prior.at)) === JSON.stringify(record);
|
|
214
|
+
return { record: same ? record : next(options.at), owes };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// --- a device's records -----------------------------------------------------------------------------------------------
|
|
218
|
+
|
|
219
|
+
/** The file that lists what a re-judge left owing, beside the state file. */
|
|
220
|
+
export const owedFile = (stateFile: string): string => join(dirname(stateFile), "qualify-owed.json");
|
|
221
|
+
|
|
222
|
+
export const OWED_SCHEMA = "plugin-qualify.owed/1";
|
|
223
|
+
|
|
224
|
+
export interface OwingRecord {
|
|
225
|
+
readonly plugin: string;
|
|
226
|
+
/** The record's file name, when the plugin has one. */
|
|
227
|
+
readonly record?: string;
|
|
228
|
+
readonly owes: readonly OwedMeasurement[];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface RejudgeResult {
|
|
232
|
+
readonly state: SyncState;
|
|
233
|
+
readonly changed: number;
|
|
234
|
+
readonly unchanged: number;
|
|
235
|
+
readonly owing: readonly OwingRecord[];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The entries whose files are not the bytes they were qualified from, and their records' stems. */
|
|
239
|
+
function changedStems(state: SyncState): { stems: Set<string>; entries: Set<string> } {
|
|
240
|
+
const stems = new Set<string>();
|
|
241
|
+
const entries = new Set<string>();
|
|
242
|
+
for (const [key, e] of Object.entries(state.entries)) {
|
|
243
|
+
const now = digestFiles(e.root, e.files.map((f) => f.path), e.files);
|
|
244
|
+
if (now !== undefined && now.every((f) => e.files.some((x) => x.path === f.path && x.sha256 === f.sha256))) continue;
|
|
245
|
+
entries.add(key);
|
|
246
|
+
for (const p of e.plugins) {
|
|
247
|
+
const stem = p.record === undefined ? undefined : recordStem(p.record);
|
|
248
|
+
if (stem !== undefined) stems.add(stem);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return { stems, entries };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const readRecord = (path: string): QualificationRecord | undefined => {
|
|
255
|
+
try {
|
|
256
|
+
const r = JSON.parse(readFileSync(path, "utf8")) as QualificationRecord;
|
|
257
|
+
return r.schema === QUALIFICATION_RECORD_SCHEMA ? r : undefined;
|
|
258
|
+
} catch {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const nameOf = (record: QualificationRecord): string => record.plugin.id;
|
|
264
|
+
|
|
265
|
+
/** 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. */
|
|
266
|
+
function pluginWithVerdict(plugin: SyncPlugin, v: RecordVerdict): SyncPlugin {
|
|
267
|
+
const { pin, code: _code, ...rest } = plugin;
|
|
268
|
+
const word = v.measured ? pinVerdictOf(v.rating as SuitabilityRating) : undefined;
|
|
269
|
+
return {
|
|
270
|
+
...rest,
|
|
271
|
+
outcome: outcomeOfVerdict(v),
|
|
272
|
+
...(v.deciding === undefined ? {} : { code: v.deciding }),
|
|
273
|
+
...(pin === undefined ? {} : { pin: { uri: pin.uri, integrity: pin.integrity, ...(word === undefined ? {} : { verdict: word }) } }),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Every record of the device's qualification directory judged again, the state's outcomes and pin words brought into line,
|
|
279
|
+
* and the list of what is owed written beside the state file. Each file is written whole, and only when it differs.
|
|
280
|
+
*/
|
|
281
|
+
export function rejudgeState(ctx: SyncContext, state: SyncState, now: () => string = () => new Date().toISOString()): RejudgeResult {
|
|
282
|
+
const { qualificationDir: dir, hostProfile, stateFile } = ctx.settings;
|
|
283
|
+
const by = rejudgeToolName();
|
|
284
|
+
const at = now();
|
|
285
|
+
const changed = changedStems(state);
|
|
286
|
+
const judged = new Map<string, QualificationRecord>();
|
|
287
|
+
const owing: OwingRecord[] = [];
|
|
288
|
+
let changedCount = 0;
|
|
289
|
+
let unchanged = 0;
|
|
290
|
+
let names: string[] = [];
|
|
291
|
+
try {
|
|
292
|
+
names = readdirSync(dir).filter((f) => f.endsWith(RECORD_SUFFIX)).sort();
|
|
293
|
+
} catch {
|
|
294
|
+
// no directory, no record
|
|
295
|
+
}
|
|
296
|
+
for (const name of names) {
|
|
297
|
+
const path = join(dir, name);
|
|
298
|
+
const record = readRecord(path);
|
|
299
|
+
if (record === undefined) {
|
|
300
|
+
ctx.log(`${name}: does not read as a record; left as it is`);
|
|
301
|
+
owing.push({ plugin: name, record: name, owes: [{ measurement: "qualification", code: OWED_CODE.figuresUnreadable }] });
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (changed.stems.has(recordStem(name) ?? "")) {
|
|
305
|
+
owing.push({ plugin: nameOf(record), record: name, owes: [{ measurement: "qualification", code: OWED_CODE.bytesChanged }] });
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
let result: ReturnType<typeof rejudgeRecord>;
|
|
309
|
+
try {
|
|
310
|
+
result = rejudgeRecord(record, readFileSync(join(dir, record.probe.file)), { host: hostProfile.id, by, at });
|
|
311
|
+
} catch (e) {
|
|
312
|
+
const detail = e instanceof RejudgeRefusal ? e.message : `${record.probe.file}: ${(e as NodeJS.ErrnoException).code ?? String(e)}`;
|
|
313
|
+
ctx.log(`${name}: ${detail}; left as it is`);
|
|
314
|
+
owing.push({ plugin: nameOf(record), record: name, owes: [{ measurement: "qualification", code: OWED_CODE.figuresUnreadable, detail }] });
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (result.record === record) unchanged++;
|
|
318
|
+
else {
|
|
319
|
+
writeFileWhole(path, `${JSON.stringify(result.record, null, 2)}\n`);
|
|
320
|
+
changedCount++;
|
|
321
|
+
}
|
|
322
|
+
judged.set(name, result.record);
|
|
323
|
+
if (result.owes.length > 0) owing.push({ plugin: nameOf(record), record: name, owes: result.owes });
|
|
324
|
+
}
|
|
325
|
+
const entries: Record<string, SyncEntry> = {};
|
|
326
|
+
for (const [key, entry] of Object.entries(state.entries)) {
|
|
327
|
+
if (changed.entries.has(key)) {
|
|
328
|
+
entries[key] = entry;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const plugins = entry.plugins.map((plugin) => {
|
|
332
|
+
const record = plugin.record === undefined ? undefined : judged.get(basename(plugin.record));
|
|
333
|
+
const v = record?.verdicts.find((x) => x.host === hostProfile.id);
|
|
334
|
+
if (v !== undefined) return pluginWithVerdict(plugin, v);
|
|
335
|
+
if (record === undefined && plugin.outcome === "unmeasured" && plugin.record?.endsWith(RECORD_SUFFIX) !== true) {
|
|
336
|
+
owing.push({ plugin: plugin.uri, ...(plugin.record === undefined ? {} : { record: basename(plugin.record) }), owes: [{ measurement: "qualification", code: OWED_CODE.noFigures }] });
|
|
337
|
+
}
|
|
338
|
+
return plugin;
|
|
339
|
+
});
|
|
340
|
+
entries[key] = { ...entry, plugins };
|
|
341
|
+
}
|
|
342
|
+
owing.sort((a, b) => (a.record ?? a.plugin).localeCompare(b.record ?? b.plugin));
|
|
343
|
+
for (const o of owing) ctx.log(`owes: ${o.plugin}: ${o.owes.map((x) => `${x.measurement}${x.host === undefined ? "" : ` under ${x.host}`}`).join(", ")}`);
|
|
344
|
+
writeIfDifferent(owedFile(stateFile), `${JSON.stringify({ schema: OWED_SCHEMA, owing }, null, 1)}\n`);
|
|
345
|
+
return { state: { schema: SYNC_STATE_SCHEMA, entries }, changed: changedCount, unchanged, owing };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function writeIfDifferent(path: string, text: string): void {
|
|
349
|
+
try {
|
|
350
|
+
if (readFileSync(path, "utf8") === text) return;
|
|
351
|
+
} catch {
|
|
352
|
+
// not there yet
|
|
353
|
+
}
|
|
354
|
+
writeFileWhole(path, text);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// --- the memory-only pass ---------------------------------------------------------------------------------------------
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* 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
|
|
361
|
+
* 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
|
|
362
|
+
* never read as fitting. Pure.
|
|
363
|
+
*/
|
|
364
|
+
export function mergeMemoryRun(record: QualificationRecord, output: ProbeOutput, cells: readonly GridCell[]): QualificationRecord {
|
|
365
|
+
const grid: RecordGridPoint[] = [...record.measurements.grid];
|
|
366
|
+
const said: { rate: number; quantum: number; outcome: string; memoryLimit?: { bytes: number; mechanism: string } }[] = [];
|
|
367
|
+
for (const c of cells) {
|
|
368
|
+
const p = output.grid.find((g) => cellKey(g) === cellKey(c));
|
|
369
|
+
const outcome = p?.outcome ?? output.run.outcome;
|
|
370
|
+
const memory = p?.memory ?? { unmeasuredReason: unmeasuredWordOf(outcome), unmeasuredDetail: `the memory-only run ended ${outcome}` };
|
|
371
|
+
const figures = memoryOfCell({ rate: c.rate, quantum: c.quantum, outcome, memory });
|
|
372
|
+
const at = grid.findIndex((g) => cellKey(g) === cellKey(c));
|
|
373
|
+
if (at >= 0) grid[at] = { ...grid[at]!, ...figures };
|
|
374
|
+
else grid.push({ rate: c.rate, quantum: c.quantum, outcome: PROBE_OK, latency: { unmeasuredReason: "not-attempted", code: HOSTING_CODE.latencyUnmeasured }, ...figures });
|
|
375
|
+
said.push({ rate: c.rate, quantum: c.quantum, outcome, ...(p?.memoryLimit === undefined ? {} : { memoryLimit: p.memoryLimit }) });
|
|
376
|
+
}
|
|
377
|
+
const notMeasured = record.notMeasured ?? [];
|
|
378
|
+
return {
|
|
379
|
+
...record,
|
|
380
|
+
measurements: { ...record.measurements, grid },
|
|
381
|
+
notMeasured: notMeasured.some((n) => n.dimension === MEMORY_PASS_NOT_MEASURED.dimension) ? notMeasured : [...notMeasured, MEMORY_PASS_NOT_MEASURED],
|
|
382
|
+
memoryRun: { tool: output.run.tools, measuredAt: output.run.startedAt, runId: output.run.id, cells: said },
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Whether a record already holds this pass's footprints. */
|
|
387
|
+
const memoryTaken = (record: QualificationRecord, cells: readonly GridCell[]): boolean =>
|
|
388
|
+
record.memoryRun !== undefined && cells.every((c) => record.memoryRun!.cells.some((m) => cellKey(m) === cellKey(c)));
|
|
389
|
+
|
|
390
|
+
export interface MemoryPassResult {
|
|
391
|
+
readonly measured: number;
|
|
392
|
+
readonly already: number;
|
|
393
|
+
readonly failed: number;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** The extensions a record was measured with: its file says which offer it is. */
|
|
397
|
+
const offerOf = (recordName: string): readonly string[] => (recordName.endsWith(`.custom${RECORD_SUFFIX}`) ? OMX_CLAP_HOST_CONFIGURED_EXTENSIONS : []);
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* The footprint of each plugin of the state, at `MEMORY_PASS_CELLS`, merged into the record its verdict for this run's host
|
|
401
|
+
* came from. One plugin's failure is that plugin's; each record is written whole as its plugin ends, so a pass cut short
|
|
402
|
+
* keeps what it finished, and a pass run again skips those unless `force`.
|
|
403
|
+
*/
|
|
404
|
+
export function memoryPass(ctx: SyncContext, state: SyncState, options: { readonly force?: boolean; readonly run?: ProbeRun } = {}): MemoryPassResult {
|
|
405
|
+
const { memory, budgetS, memoryNotes } = ctx.settings;
|
|
406
|
+
const count = { measured: 0, already: 0, failed: 0 };
|
|
407
|
+
const changed = changedStems(state);
|
|
408
|
+
for (const [key, entry] of Object.entries(state.entries)) {
|
|
409
|
+
if (changed.entries.has(key)) {
|
|
410
|
+
ctx.log(`${key}: its files changed since it was measured; the sync measures it whole`);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
for (const plugin of entry.plugins) {
|
|
414
|
+
if (plugin.record === undefined || !plugin.record.endsWith(RECORD_SUFFIX)) continue;
|
|
415
|
+
const name = basename(plugin.record);
|
|
416
|
+
const path = join(ctx.settings.qualificationDir, name);
|
|
417
|
+
const record = readRecord(path);
|
|
418
|
+
if (record === undefined) {
|
|
419
|
+
ctx.log(`${plugin.uri}: its record ${name} does not read; no footprint taken`);
|
|
420
|
+
count.failed++;
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
if (options.force !== true && memoryTaken(record, MEMORY_PASS_CELLS)) {
|
|
424
|
+
count.already++;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const started = Date.now();
|
|
428
|
+
const env = { ...ctx.env, [PROBE_MEMORY_ONLY_ENV]: "1", [PROBE_NOTES_ENV]: String(memoryNotes) };
|
|
429
|
+
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 }) };
|
|
430
|
+
try {
|
|
431
|
+
const probed =
|
|
432
|
+
entry.format === "clap"
|
|
433
|
+
? probeTarget(clapTarget(key, entry, record), { ...limits, offer: offerOf(name), env })
|
|
434
|
+
: lv2World(entry.root, (world) => probeTarget({ format: "lv2", uri: record.plugin.id, bundle: entry.root }, { ...limits, env: { ...env, LV2_PATH: world } }));
|
|
435
|
+
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)}`);
|
|
436
|
+
writeFileWhole(path, `${JSON.stringify(mergeMemoryRun(record, probed.output, MEMORY_PASS_CELLS), null, 2)}\n`);
|
|
437
|
+
count.measured++;
|
|
438
|
+
ctx.log(`${plugin.uri}: footprint taken at ${MEMORY_PASS_CELLS.map(cellKey).join(", ")} in ${((Date.now() - started) / 1000).toFixed(1)} s`);
|
|
439
|
+
} catch (e) {
|
|
440
|
+
if (!(e instanceof ProbeRunnerError)) throw e;
|
|
441
|
+
count.failed++;
|
|
442
|
+
ctx.log(`${plugin.uri}: no footprint: ${e.message}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return count;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function clapTarget(key: string, entry: SyncEntry, record: QualificationRecord): PluginTarget {
|
|
450
|
+
const file = key.startsWith("clap:") ? key.slice("clap:".length) : join(entry.root, record.binary.files[0]?.path ?? "");
|
|
451
|
+
return { format: "clap", uri: `urn:clap:${record.plugin.id}`, bundle: entry.root, binary: basename(file), binaryPath: file };
|
|
452
|
+
}
|