150 lines
5.1 KiB
TypeScript
150 lines
5.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { join, sep } from 'node:path';
|
|
import { packagedResourcesDirectory } from '../../scripts/probe-pi-packaged-runtime.mjs';
|
|
import {
|
|
buildEvidenceWaivers,
|
|
buildMissingEvidence,
|
|
buildPiProviderConfig,
|
|
createStrictJsonlParser,
|
|
lockEntrySupportsCurrentPlatform,
|
|
MAKELore_PROVIDER_PROTOCOLS,
|
|
mapMakeloreProtocolToPi,
|
|
parseProbeArgs,
|
|
percentile,
|
|
summarizeMeasurements,
|
|
} from '../../scripts/probe-pi-runtime.mjs';
|
|
|
|
describe('Pi runtime qualification probe', () => {
|
|
it('locates macOS resources beside Contents/MacOS', () => {
|
|
const executable = join('probe-root', 'MakelorePiProbe.app', 'Contents', 'MacOS', 'MakelorePiProbe');
|
|
const resources = packagedResourcesDirectory(executable, 'darwin');
|
|
|
|
expect(resources.split(sep).slice(-3)).toEqual([
|
|
'MakelorePiProbe.app',
|
|
'Contents',
|
|
'Resources',
|
|
]);
|
|
});
|
|
|
|
it('parses strict LF-delimited JSONL without splitting Unicode separators', () => {
|
|
const records: unknown[] = [];
|
|
const parser = createStrictJsonlParser((record) => records.push(record));
|
|
const source = `${JSON.stringify({ text: 'left\u2028middle\u2029right' })}\n${JSON.stringify({ ok: true })}\r\n`;
|
|
const bytes = Buffer.from(source);
|
|
|
|
parser.push(bytes.subarray(0, 9));
|
|
parser.push(bytes.subarray(9, 25));
|
|
parser.push(bytes.subarray(25));
|
|
parser.finish();
|
|
|
|
expect(records).toEqual([
|
|
{ text: 'left\u2028middle\u2029right' },
|
|
{ ok: true },
|
|
]);
|
|
});
|
|
|
|
it('uses nearest-rank p50 and p95 measurements', () => {
|
|
expect(percentile([5, 1, 4, 2, 3], 50)).toBe(3);
|
|
expect(percentile([5, 1, 4, 2, 3], 95)).toBe(5);
|
|
expect(summarizeMeasurements([1.2, 2.8, 9.1])).toEqual({
|
|
samples: 3,
|
|
p50: 3,
|
|
p95: 9,
|
|
max: 9,
|
|
});
|
|
});
|
|
|
|
it('requires explicit, bounded CLI arguments', () => {
|
|
expect(parseProbeArgs(['--stage', '--samples', '3', '--timeout-ms', '2000'])).toMatchObject({
|
|
stage: true,
|
|
samples: 3,
|
|
timeoutMs: 2000,
|
|
});
|
|
expect(() => parseProbeArgs(['--samples', '0'])).toThrow(/positive integer/);
|
|
expect(() => parseProbeArgs(['--keep-stage'])).toThrow(/requires --stage/);
|
|
expect(() => parseProbeArgs(['--electron-executable', 'electron.exe'])).toThrow(/provided together/);
|
|
expect(() => parseProbeArgs([
|
|
'--stage',
|
|
'--electron-executable',
|
|
'electron.exe',
|
|
'--cli-path',
|
|
'app.asar/dist/cli.js',
|
|
])).toThrow(/cannot be combined/);
|
|
expect(parseProbeArgs([
|
|
'--electron-executable',
|
|
'electron.exe',
|
|
'--cli-path',
|
|
'app.asar/dist/cli.js',
|
|
'--artifact-label',
|
|
'controlled-app-asar',
|
|
])).toMatchObject({ artifactLabel: 'controlled-app-asar' });
|
|
});
|
|
|
|
it('covers every current Makelore provider protocol', () => {
|
|
expect(MAKELore_PROVIDER_PROTOCOLS).toEqual([
|
|
'openai-completions',
|
|
'openai-responses',
|
|
'anthropic-messages',
|
|
'openrouter',
|
|
]);
|
|
expect(mapMakeloreProtocolToPi('openai-responses')).toEqual({
|
|
api: 'openai-responses',
|
|
compat: undefined,
|
|
});
|
|
expect(mapMakeloreProtocolToPi('openrouter')).toEqual({
|
|
api: 'openai-completions',
|
|
compat: {
|
|
thinkingFormat: 'openrouter',
|
|
sessionAffinityFormat: 'openrouter',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('reports the user-approved macOS deferral separately from Phase-0 aggregation', () => {
|
|
expect(buildMissingEvidence()).toContain(
|
|
'Phase-0 artifact aggregation: Windows x64 and Linux x64; macOS x64/arm64 deferred to PI-150 by user decision on 2026-08-22',
|
|
);
|
|
expect(buildMissingEvidence()).not.toContain('Linux unpackaged and packaged samples');
|
|
});
|
|
|
|
it('reports real Provider validation as explicitly waived without claiming a real turn', () => {
|
|
expect(buildMissingEvidence()).not.toEqual(expect.arrayContaining([
|
|
expect.stringContaining('real-provider'),
|
|
expect.stringContaining('real provider'),
|
|
]));
|
|
expect(buildEvidenceWaivers()).toEqual(expect.arrayContaining([
|
|
expect.stringContaining('QG-004/QG-005'),
|
|
expect.stringContaining('explicitly waived'),
|
|
expect.stringContaining('remain unverified'),
|
|
]));
|
|
});
|
|
|
|
it('builds a Pi provider model using an environment reference, not a credential value', () => {
|
|
const config = buildPiProviderConfig({
|
|
id: 'probe-openrouter',
|
|
apiProtocol: 'openrouter',
|
|
baseUrl: 'https://openrouter.ai/api/v1',
|
|
apiKeyEnv: 'PROBE_OPENROUTER_KEY',
|
|
headers: { 'X-OpenRouter-Title': 'Makelore qualification' },
|
|
model: { id: 'anthropic/claude-sonnet-4' },
|
|
});
|
|
|
|
expect(config.providers['probe-openrouter']).toMatchObject({
|
|
api: 'openai-completions',
|
|
apiKey: '$PROBE_OPENROUTER_KEY',
|
|
models: [{
|
|
id: 'anthropic/claude-sonnet-4',
|
|
compat: {
|
|
thinkingFormat: 'openrouter',
|
|
sessionAffinityFormat: 'openrouter',
|
|
},
|
|
}],
|
|
});
|
|
});
|
|
|
|
it('rejects lock entries for a different operating system', () => {
|
|
expect(lockEntrySupportsCurrentPlatform({ os: [`!${process.platform}`] })).toBe(false);
|
|
expect(lockEntrySupportsCurrentPlatform({ os: [process.platform], cpu: [process.arch] })).toBe(true);
|
|
});
|
|
});
|