open-standards/wai/wai-quantum-js/test/smoke.mjs
Transaction Science a1bbce7fad
Some checks failed
wai-audit collector and player integration / does this change touch it (push) Successful in 21s
WAI operation catalogue / does this change touch it (push) Successful in 21s
wai-quantum clippy / does this change touch it (push) Successful in 23s
wai-quantum command line / does this change touch it (push) Successful in 27s
wai-quantum docs, course and locales / does this change touch it (push) Successful in 21s
wai-quantum error correction and mitigation / does this change touch it (push) Successful in 15s
wai-quantum qudit jobs / does this change touch it (push) Successful in 18s
wai-quantum for Python / does this change touch it (push) Successful in 22s
wai-quantum extension points / does this change touch it (push) Successful in 23s
wai-quantum service / does this change touch it (push) Successful in 24s
wai-quantum studio and desktop / does this change touch it (push) Successful in 21s
wai-quantum service / service energy · linux packages (push) Failing after 8s
wai-quantum variational and algorithm library / does this change touch it (push) Successful in 26s
wai-quantum verdicts and repairs / does this change touch it (push) Successful in 19s
wai-quantum views in agent hosts / does this change touch it (push) Successful in 19s
wai-quantum on Windows / does this change touch it (push) Successful in 32s
wai-sink-android native sink library / does this change touch it (push) Successful in 21s
wai-sink-swift native sink package / does this change touch it (push) Successful in 25s
wai-quantum for JavaScript / does this change touch it (push) Successful in 2m37s
WAI Studio / does this change touch it (push) Successful in 12s
wai-quantum OpenQASM reader / does this change touch it (push) Successful in 2m43s
wai-quantum editors / does this change touch it (push) Successful in 2m55s
wai-quantum pulse and dynamics / does this change touch it (push) Successful in 2m42s
wai-quantum contract / does this change touch it (push) Successful in 2m59s
wai-quantum other formats / does this change touch it (push) Successful in 2m48s
wai-quantum-landscape-fpga reference design / does this change touch it (push) Successful in 2m45s
wai-quantum resource estimation / does this change touch it (push) Successful in 2m51s
WAI breaking changes and the conformance runner / WAI breaking · does this change touch WAI (push) Successful in 11s
WAI examples / WAI examples · does this change touch them (push) Successful in 22s
wai-quantum landscape stage 0, the sampler against the exact law / does this change touch it (push) Successful in 10s
wai-quantum landscape energy to solution / does this change touch it (push) Successful in 17s
wai-quantum energy-landscape jobs / does this change touch it (push) Successful in 12s
wai-audit collector and player integration / collector · linux (push) Successful in 3m47s
wai-quantum clippy / clippy, warnings denied, every feature set · linux (push) Successful in 3m46s
wai-quantum docs, course and locales / the Studio's words in every locale · linux (push) Successful in 16s
wai-quantum wasmQ / does this change touch it (push) Successful in 19s
wai-quantum qudit jobs / the module and the conformance set under wasm32-wasip2 (wasmtime) (push) Successful in 2m28s
wai-quantum docs, course and locales / the course and the command line's languages · linux (push) Successful in 3m53s
wai-quantum studio and desktop / studio · browser (push) Successful in 4m10s
WAI operation catalogue / the catalogue and every door · linux (push) Successful in 12m50s
wai-quantum extension points / the registry under wasm32-wasip2 (wasmtime) (push) Successful in 5m9s
wai-quantum verdicts and repairs / the intent set and the verdict under wasm32-wasip2 (wasmtime) (push) Successful in 1m37s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux, release (push) Successful in 2m35s
wai-quantum verdicts and repairs / verdicts, repairs and the intent set · linux (push) Successful in 2m58s
wai-quantum error correction and mitigation / codes, decoders, texts and mitigation · linux, release (push) Successful in 10m5s
WAI Studio / the catalogue's actions, the unit tests and the core · linux (push) Successful in 2m21s
wai-quantum studio and desktop / desktop app · linux (push) Successful in 7m30s
wai-quantum OpenQASM reader / corpus under wasm32-wasip2 (wasmtime) (push) Successful in 51s
wai-quantum contract / the policy is linked, and the deprecations page reads (push) Successful in 13s
wai-quantum qudit jobs / the module, the job, the conformance set, the referee and the verb · linux (push) Successful in 12m45s
wai-quantum views in agent hosts / views · the page and its engine (push) Successful in 4m54s
wai-quantum extension points / the registry and the example · linux (push) Successful in 11m13s
wai-quantum for JavaScript / javascript · linux (push) Successful in 4m55s
wai-quantum for Python / python · linux (push) Successful in 12m31s
wai-quantum OpenQASM reader / reader and corpus · linux (push) Successful in 4m0s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs under wasm32-wasip2 (wasmtime) (push) Successful in 1m22s
wai-quantum command line / command line · linux (push) Successful in 19m37s
wai-quantum pulse and dynamics / reader, simulator and pulse jobs · linux, release (push) Successful in 3m20s
wai-quantum editors / editors · linux (push) Successful in 3m41s
wai-quantum other formats / the set under wasm32-wasip2 (wasmtime) (push) Successful in 3m7s
WAI breaking changes and the conformance runner / WAI breaking · wire, record and API against main · linux (push) Successful in 2m44s
wai-quantum landscape stage 0, the sampler against the exact law / the small tier, to the byte · linux (push) Successful in 1m4s
wai-quantum service / service · linux (push) Successful in 17m3s
wai-quantum landscape energy to solution / the small tier, to the byte · linux (push) Successful in 2m23s
wai-quantum views in agent hosts / views · a scripted host (push) Successful in 14m9s
wai-quantum contract / schemas and the committed tool lists · linux (push) Successful in 10m9s
wai-quantum other formats / readers, writers and the set · linux (push) Successful in 9m28s
WAI breaking changes and the conformance runner / WAI breaking and conform · their tests, and the independent verifiers through wai conform · linux (push) Successful in 7m43s
wai-quantum contract / API compatibility · linux (push) Successful in 11m25s
wai-quantum wasmQ / the reference modules rebuild to their modules of record · linux (push) Successful in 34s
WAI Studio / Studio in WebKit · linux (push) Successful in 14m43s
wai-quantum resource estimation / estimation and calibration · linux, release (push) Successful in 10m56s
wai-quantum energy-landscape jobs / native against WebAssembly, over many seeds (push) Successful in 8m32s
wai-quantum wasmQ / interpreter and vectors under wasm32-wasip2 (wasmtime) (push) Successful in 6m27s
WAI examples / WAI examples · portable · linux (push) Successful in 11m57s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · linux (push) Successful in 8m56s
wai-quantum energy-landscape jobs / the module under wasm32-wasip2 (wasmtime) (push) Successful in 13m28s
wai-quantum-landscape-fpga reference design / the member against the model of the logic, and the logic against the model · linux, release (push) Successful in 22m33s
wai-quantum energy-landscape jobs / reader, kernels, answers and the stated result · linux, release (push) Successful in 17m1s
wai-quantum docs, course and locales / every command and snippet in the docs · linux (push) Successful in 40m14s
wai-audit collector and player integration / collector, player integration and the browser end to end · macos (push) Successful in 2m13s
wai-quantum command line / command line · macos (push) Successful in 2m55s
wai-quantum qudit jobs / the same bits · macos (push) Successful in 1m47s
wai-quantum for Python / python · macos (push) Successful in 3m41s
wai-quantum studio and desktop / desktop app · macos (push) Successful in 5m34s
wai-quantum service / service · macos (push) Successful in 7m44s
wai-quantum editors / editors · macos (push) Successful in 1m53s
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (push) Successful in 9m39s
wai-quantum pulse and dynamics / the same bits · macos (push) Successful in 1m33s
wai-sink-android native sink library / every ABI, the AAR, and the instrumented tests in a headless emulator · macos (push) Successful in 6m5s
wai-quantum landscape stage 0, the sampler against the exact law / the small tier, to the byte · macos (push) Successful in 33s
wai-quantum extension points / the registry and the example · linux-arm64 (push) Successful in 7m49s
wai-quantum landscape energy to solution / the small tier, to the byte · macos (push) Successful in 2m5s
wai-quantum-landscape-fpga reference design / the board's code on the board's processor's architecture · linux-arm64, release (push) Successful in 1m50s
wai-quantum variational and algorithm library / parameters, gradients, optimisers, VQE, QAOA and builders · linux-arm64, release (push) Successful in 4m21s
wai-quantum pulse and dynamics / the same bits · linux-arm64 (push) Successful in 3m11s
WAI Studio / Studio in Chromium and Firefox · macos (push) Successful in 11m4s
wai-quantum energy-landscape jobs / the same bits · macos (push) Successful in 7m36s
wai-sink-android native sink library / the JNI layer and the platform-free half on the host JVM · linux-arm64 (push) Successful in 10m54s
wai-quantum wasmQ / profile, engines, reference modules, adversarial, vectors · macos (push) Successful in 2m40s
WAI examples / WAI examples · the archive, the readiness check, the browser and Apple · macos (push) Successful in 21m33s
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (push) Failing after 28m52s
WAI examples / WAI examples · android-app · linux-arm64 (push) Successful in 15m51s
wai-quantum energy-landscape jobs / the same bits · linux-arm64 (push) Successful in 19m35s
wai-quantum on Windows / engine · windows (push) Has been cancelled
wai-quantum on Windows / command line · windows (push) Has been cancelled
wai-quantum on Windows / job service · windows (push) Has been cancelled
wai-quantum on Windows / python · windows (push) Has been cancelled
wai-quantum studio and desktop / desktop app · windows (push) Has been cancelled
WAI Quantum: the sign-off loop on the job service, in Python and npm; a grade held to the service's bounds case by case; a whole task set graded
The sign-off loop (check, grade, attest; 4b17804c2) ran on the command line and
its MCP server. It now runs wherever the engine does, with the same answers.

- engine::front holds the check, the attestation and the loop's MCP tools
  (check_quantum_program, grade_quantum_program, attest_quantum_job, in one
  wording with the sealer named), which the command line, both MCP servers, the
  Python package and the npm package call; the command line keeps its flags and
  its printing. The output schemas of check and attest move from the command
  line's local-tools.v1.json into the engine's tools.v1.json ($defs/check,
  $defs/attest), which both servers name.
- The job service serves the three tools on its MCP server and as POST
  /v1/check, /v1/grade and /v1/attest (GET /v1, the OpenAPI document and the
  README list them), a grade and a sign-off sealed with its own key, their
  energy unmetered with the reason. Each is counted as a check, held to its
  bounds and made in a reading child, each case within half the child's memory.
  A check of a task, a grade, and a sealed grade POST /v1/verify works out again
  are now held case by case (analysis::grade_bounds: each case's intent that
  compares the program with a reference held to the equivalence check's bound
  with the program written out at that case's inputs, and the task's job read as
  a job's is), where before a grade was remade within the reading child's budget
  whole; a case past them is refused at that case (J031, "case N: ...", naming
  wai-quantum grade). An attestation holds what verifying the job works out
  again and the intent its sign-off checks to the same bounds (naming
  wai-quantum attest).
- Python: wq.check, wq.grade, wq.attest (and _engine.check/grade/attest); npm:
  QuantumEngine.check, .grade, .attest; each with a test (test_engine.py,
  smoke.mjs, a wasm32 test in wai-web) and a README example.
- The instructions both MCP servers give at initialize describe the loop
  (guide::LOOP), and the committed lists (docs/local-mcp.json,
  docs/service-mcp.json), llms.txt, llms-full.txt and the skill's tools.md are
  written again from the live lists.
- A whole task set graded: wai-quantum grade --set FILE --programs ANSWERS (the
  model harness's set; the programs a JSON object of programs or of a model's
  answers as eval run --scripted reads them, or a directory of NAME.qasm files),
  or --course --programs DIR; engine::grade::batch, wai.quantum.grades/1
  (schemas/grades.v1.json), quantum-providers §8.10 "A task set graded": one
  sealed grade a task, missing and refused tasks said so, the set's digest and
  a summary. The batch is not sealed; wai-quantum verify works it out again
  (grade::check_batch): each grade checked and made again, each entry's name and
  grade held to what its grade seals, a refused entry refused again, the digest
  and the summary made again from the sealed results. The same set, programs and
  key give the same bytes. quantum-conformance/grades/ holds a batch and six
  changed ones with what a reader must say (written by hand from §8.10),
  natively and under wasm32-wasip2 (tests/grades_conformance.rs), including one
  that shows what a batch does not: a grade dropped as missing with the summary
  made to agree is valid; that a task had no program is the grader's statement.
- wai-web's pinned digest of a level-2 compile (COMPILE_DIGEST) follows the
  compile of 7c00ef138, which writes each region of CNOT and phase gates again
  at level 2 and so changed those sealed bytes; wai-web wasm32 runs on pull
  requests and nightly only, so nothing had run it since. Native and wasm32 give
  the new digest alike. The npm smoke runs the loop on an engine of 1 GiB: one of
  256 MiB says an intent's exact check is unchecked, and why (asserted too).
- Which trust list an attester used stays outside the seal: sealing it would add
  a member to the sign-off's closed request, which every released verifier
  refuses (J001), and it would show only which keys the attester trusted, which
  is each reader's to decide; the changes entry and the skill say so.

Tests: engine::front, engine::grade (the batch), the guide's instructions,
service analysis (bounds case by case), mcp (an agent runs the loop over the
service's server; every tool's answer held to its output schema), verify.rs
(the loop over HTTP in a running service, its grade and sign-off verified),
the command line's front_door.rs (a whole set graded through the binary,
verified, a changed summary found) and check_schemas.py (the batch and an
attestation held to their schemas). wai-quantum-verdict.yml, -service.yml,
-cli.yml and wai-web-wasm.yml require the new tests by name. schema::FILES gains
grades.v1.json (acknowledged in the changes entry).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-11 17:14:39 -05:00

158 lines
12 KiB
JavaScript

// The package as an installer leaves it: its bindings and its WebAssembly, loaded in
// Node with nothing else installed.
//
// node wai/wai-quantum-js/test/smoke.mjs PACKAGE_DIR
//
// Prints one line per check and exits non-zero on the first that fails.
import assert from 'node:assert/strict';
import { randomBytes } from 'node:crypto';
import { readFile } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
const dir = resolve(process.argv[2] ?? '.');
const pkg = JSON.parse(await readFile(join(dir, 'package.json'), 'utf8'));
const wq = await import(pathToFileURL(join(dir, pkg.main)).href);
// In Node the module is given its WebAssembly's bytes; a page lets it fetch them.
await wq.default({ module_or_path: await readFile(join(dir, 'wai_quantum_bg.wasm')) });
console.log('node', process.versions.node, pkg.name, pkg.version);
const BELL = 'OPENQASM 3.0; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; c = measure q;';
// A job run with a fresh key, and its receipt checked.
const engine = new wq.QuantumEngine(randomBytes(32), 256);
const signer = engine.signer_did();
assert.match(signer, /^did:key:z6Mk/, signer);
const job = JSON.parse(engine.run(JSON.stringify({ qasm: BELL, shots: 1000, seed: 7 })));
assert.equal(job.status, 'done', JSON.stringify(job).slice(0, 400));
const counts = job.result.counts;
assert.ok(Object.keys(counts).length > 0 && Object.keys(counts).every((k) => k === '00' || k === '11'), JSON.stringify(counts));
const v = JSON.parse(wq.engine_verify(JSON.stringify(job)));
assert.equal(v.valid, true, JSON.stringify(v));
assert.equal(v.signer, signer, JSON.stringify(v));
console.log(`run and verify: ${job.method}, ${Object.values(counts).reduce((a, b) => a + b, 0)} shots, signed by this engine's key`);
// A result changed after it was sealed does not verify.
const forged = structuredClone(job);
const k = Object.keys(forged.result.counts)[0];
forged.result.counts[k] += 1;
assert.notEqual(JSON.parse(wq.engine_verify(JSON.stringify(forged))).valid, true);
console.log('a forged result does not verify');
// A program read and drawn.
const lint = JSON.parse(wq.engine_lint(BELL));
assert.equal(lint.ok, true, JSON.stringify(lint));
assert.equal(lint.qubits, 2, JSON.stringify(lint));
const drawn = JSON.parse(wq.engine_draw(BELL, 80));
assert.ok(typeof drawn.text === 'string' && drawn.text.trim().length > 0, JSON.stringify(drawn));
console.log(`lint and draw: ${lint.qubits} qubits, ${lint.gates} gates; drawn in ${drawn.text.trimEnd().split('\n').length} lines`);
// A program the engine refuses says why, with its diagnostic code.
const WHILE = 'OPENQASM 3.0; qubit[1] q; bit[1] c; c[0] = measure q[0]; while (c[0]) { x q[0]; c[0] = measure q[0]; }';
const refused = JSON.parse(engine.run(JSON.stringify({ qasm: WHILE, shots: 10 })));
assert.ok(typeof refused.error === 'string' && /^Q\d{3}$/.test(refused.code ?? ''), JSON.stringify(refused));
console.log(`a refused program says why: [${refused.code}] ${refused.meaning}`);
// An energy-landscape job (wai.quantum.landscape/1): run in Node, sealed with this engine's
// key, its receipt and its form checked (quantum-landscape section 5.4); a changed member
// is no answer a host would seal; a program the reader refuses names its line.
const PROGRAM = 'vars 4\ncost 1\nagree 0 1\nagree 0 2\nagree 1 2\noppose 2 3\nagree 3 0\nsolve restarts=2 steps=9\n';
const land = JSON.parse(engine.landscape('run', JSON.stringify({ program: PROGRAM, seed: '7' })));
assert.equal(land.result.schema, 'wai.quantum.landscape/1', JSON.stringify(land).slice(0, 400));
const lv = JSON.parse(wq.engine_verify(JSON.stringify(land)));
assert.equal(lv.valid, true, JSON.stringify(lv));
assert.equal(lv.landscape.op, 'run', JSON.stringify(lv));
const graded = structuredClone(land);
graded.result.member.parity = 'bit-exact';
assert.ok(JSON.parse(wq.engine_verify(JSON.stringify(graded))).reasons.includes('landscape_form'));
const lref = JSON.parse(engine.landscape('run', JSON.stringify({ program: 'vars 2\noppos 0 1\nsolve\n' })));
assert.equal(lref.line, 2, JSON.stringify(lref));
console.log(`landscape: ${land.result.verdict} at energy ${land.result.energy}, its form checked; a refused program names line ${lref.line}`);
// The second version (wai.quantum.landscape/2), named in the request: a constraint the first
// version cannot write, run and sealed here, its answer naming the version, a sampling run's
// joules stated unpriced and a run at temperature 0 priced, and its receipt held to that
// version's form (quantum-landscape-2 section 5.4); the same program is none of the first's.
const SECOND = 'wai.quantum.landscape/2';
const ONE_OF_THREE = 'vars 3\nexactly 1 0 1 2\nsolve restarts=2 steps=9\n';
const land2 = JSON.parse(engine.landscape('run', JSON.stringify({ program: ONE_OF_THREE, protocol: SECOND, seed: '7' })));
assert.deepEqual([land2.result.schema, land2.result.protocol, land2.result.joules.kind, land2.result.joules.pj], [SECOND, SECOND, 'unpriced', null], JSON.stringify(land2).slice(0, 400));
const lv2 = JSON.parse(wq.engine_verify(JSON.stringify(land2)));
assert.ok(lv2.valid === true && lv2.landscape.problems.length === 0, JSON.stringify(lv2));
const cold2 = JSON.parse(engine.landscape('run', JSON.stringify({ program: ONE_OF_THREE, protocol: SECOND, temperature: '0' })));
assert.equal(cold2.result.joules.kind, 'priced', JSON.stringify(cold2.result.joules));
const priced2 = structuredClone(land2);
priced2.result.joules.kind = 'priced';
assert.ok(JSON.parse(wq.engine_verify(JSON.stringify(priced2))).reasons.includes('landscape_form'));
assert.equal(JSON.parse(engine.landscape('run', JSON.stringify({ program: ONE_OF_THREE }))).line, 2);
console.log(`landscape/2: ${land2.result.verdict} at energy ${land2.result.energy}, its joules ${land2.result.joules.kind}, its form checked`);
// A qudit job (wai.quantum.qudit/1): a qutrit Bell pair run in Node, sealed with this
// engine's key, its receipt checked and its request run again to the same bits; a
// dimension the engine holds no roots for is refused with its code.
const QUTRITS = { d: 3, qudits: 2, gates: [{ gate: 'fourier', qudits: [0] }, { gate: 'csum', qudits: [0, 1] }], shots: 300, seed: 7, amplitudes: ['00'] };
const qj = JSON.parse(engine.qudit(JSON.stringify(QUTRITS)));
assert.equal(qj.result.schema, 'wai.quantum.qudit/1', JSON.stringify(qj).slice(0, 400));
assert.ok(Object.keys(qj.result.counts).every((k) => ['00', '11', '22'].includes(k)), JSON.stringify(qj.result.counts));
assert.deepEqual(qj.result.amplitudes['00'], { re: 619925131, im: 0 });
assert.equal(JSON.parse(wq.engine_verify(JSON.stringify(qj))).valid, true);
const qc = JSON.parse(wq.engine_qudit_check(JSON.stringify(qj)));
assert.equal(qc.verified, true, JSON.stringify(qc));
const qref = JSON.parse(engine.qudit(JSON.stringify({ d: 5, qudits: 1, gates: [] })));
assert.equal(qref.code, 'J091', JSON.stringify(qref));
console.log(`qudit: a qutrit Bell pair, ${Object.keys(qj.result.counts).length} outcomes, sealed, run again to the same bits; d = 5 refused (${qref.code})`);
// wasmQ envelopes (wai.quantum.wasmq/1 and /2): every example the engine carries, run in
// Node on the crate's own interpreter, sealed with this engine's key, held to the
// profile's form, and run again from its envelope to the same result; another envelope
// is not the one the receipt binds; an envelope the profile refuses names its code.
const examples = JSON.parse(wq.engine_wasmq_examples());
assert.ok(examples.length >= 5 && examples.some((e) => e.profile === 'wai.quantum.wasmq/2'), JSON.stringify(examples));
for (const e of examples) {
const envelope = wq.engine_wasmq_example(e.name);
assert.equal(envelope.length, e.bytes, e.name);
const wj = JSON.parse(engine.wasmq(envelope));
assert.equal(wj.result.profile, e.profile, `${e.name}: ${JSON.stringify(wj).slice(0, 400)}`);
const wv = JSON.parse(wq.engine_verify(JSON.stringify(wj)));
assert.equal(wv.valid, true, `${e.name}: ${JSON.stringify(wv)}`);
const again = JSON.parse(wq.engine_wasmq_verify(JSON.stringify(wj), envelope));
assert.ok(again.valid && again.bundle === true && again.reproduced === true, `${e.name}: ${JSON.stringify(again)}`);
if (e.profile === 'wai.quantum.wasmq/2') assert.deepEqual(Object.keys(wj.result.energy.run), ['unmetered'], e.name);
}
const fault = JSON.parse(engine.wasmq(wq.engine_wasmq_example('fault-fuel')));
assert.equal(fault.result.fault.reason, 'fuel_exhausted', JSON.stringify(fault.result));
const elsewhere = JSON.parse(wq.engine_wasmq_verify(JSON.stringify(fault), wq.engine_wasmq_example('v2-t-toffoli')));
assert.ok(elsewhere.bundle === false && elsewhere.valid === false, JSON.stringify(elsewhere));
const wref = JSON.parse(engine.wasmq(new TextEncoder().encode('WAI1 not an envelope')));
assert.equal(wref.code, 'W013', JSON.stringify(wref));
console.log(`wasmQ: ${examples.length} envelopes run in Node, each sealed, held to its form and run again to the same result; a fault sealed; W013 refused`);
// The sign-off loop: a program checked against what it must do (each case by the strongest
// layer, nothing sealed), its grade sealed with this engine's key and made again by
// engine_verify, and a job another key sealed attested against a trust list naming that key;
// a task that would publish its answer and a key the list does not name are refused. The
// engine is given 1 GiB: an intent's exact check takes a state vector with 256 MiB of room
// beside it, so an engine of 256 MiB says such a case is unchecked, and why.
const FAIR = { distribution: { '00': 0.5, '11': 0.5 } };
const looping = new wq.QuantumEngine(randomBytes(32), 1024);
const small = JSON.parse(engine.check(JSON.stringify({ qasm: BELL, intent: FAIR })));
assert.deepEqual([small.passed, small.grade.cases[0].grade], [false, 'unchecked'], JSON.stringify(small).slice(0, 400));
const checked = JSON.parse(looping.check(JSON.stringify({ qasm: BELL, intent: FAIR })));
assert.deepEqual([checked.passed, checked.grade.cases[0].layer], [true, 'exact_simulation'], JSON.stringify(checked).slice(0, 400));
const gradedJob = looping.grade(JSON.stringify({ grade: { task: { title: 'A Bell pair', intent: FAIR }, program: BELL } }));
const gv = JSON.parse(wq.engine_verify(gradedJob));
assert.ok(gv.valid === true && gv.answer.again === 'reproduced' && gv.signer === looping.signer_did(), JSON.stringify(gv));
const leaky = JSON.parse(looping.grade(JSON.stringify({ grade: { task: { intent: FAIR, reference: BELL }, program: BELL } })));
assert.ok(leaky.error.endsWith('[J001]'), JSON.stringify(leaky));
const host = new wq.QuantumEngine(randomBytes(32), 256);
const hosted = host.run(JSON.stringify({ qasm: BELL, shots: 64, seed: 3 }));
const listed = { format: 'wai.quantum.receipt-keys/1', keys: [{ key: JSON.parse(hosted).result.receipt.key }] };
const att = JSON.parse(looping.attest(JSON.stringify({ job: hosted, intent: { outcomes: ['00', '11'] }, trust: listed })));
assert.deepEqual([att.result.verdict.holds, att.attested.verified.valid, att.attested.held_to.trust], [true, true, true], JSON.stringify(att).slice(0, 400));
const av = JSON.parse(wq.engine_verify(JSON.stringify({ request: att.request, result: att.result })));
assert.ok(av.valid === true && av.answer.again === 'reproduced', JSON.stringify(av));
const untrusted = JSON.parse(looping.attest(JSON.stringify({ job: hosted, trust: { format: 'wai.quantum.receipt-keys/1', keys: [{ key: '00'.repeat(32) }] } })));
assert.ok(untrusted.error.includes('key_untrusted'), JSON.stringify(untrusted));
console.log(`sign-off loop: checked (${checked.grade.cases[0].layer}; unchecked in 256 MiB), graded and made again, attested against a trust list; a leaky task and an untrusted key refused`);
console.log('smoke: every check passed');