A proof's time limit is the reader's to set
Build, test, deploy / site (push) Successful in 7m44s

The Prove view gives each routine 3 seconds on the clock. On a slow or
busy device that runs out before the proof does, and claims stay open
with nothing to say why.

- The view says when the time, not the proof, stopped the checker, that
  what was not finished is open and not disproved, and offers to prove
  again with the next longer time. The setting is at the foot of the
  view: 3, 10 or 30 seconds or 2 minutes for each routine, kept in the
  browser (pplus.proveclock).
- A proof rendered with Quarto takes prove-seconds on the shortcode or
  pplus-prove-seconds for the site, and the render warns when the time
  ran out.
- The home page's own example is proved with no time on the clock, and
  the tests that hold a proof's outcome give it time to spare, so
  neither depends on the machine.
- core moves to 38e6e2c, whose report says which routines the clock
  stopped.
This commit is contained in:
alexm committed 2026-11-13 07:01:35 -05:00
1 parent d1955ad358
commit 7000662539
19 files changed
+240 -6

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
// SPDX-License-Identifier: Apache-2.0
// The time a proof may take is the reader's to set (src/core/proveclock.ts): the Prove view says when the clock, not
// the proof, stopped the checker, offers more time, and proves again; a page rendered with Quarto takes its time
// from the shortcode or the site, and warns its author when it ran out.
import test from 'node:test';
import assert from 'node:assert/strict';
import { installDocument } from '../dist/quarto/dom.js';
installDocument();
const { PROVE_CLOCKS, DEFAULT_PROVE_CLOCK, loadProveClock, saveProveClock, longerProveClock, clockWords } = await import('../dist/core/proveclock.js');
const { Session } = await import('../dist/core/session.js');
const { problemById, stateForProblem } = await import('../dist/core/catalog.js');
const { proofView } = await import('../dist/ui/views/panels.js');
const { renderStatic } = await import('../dist/quarto/render.js');
const memory = () => { const m = new Map(); return { getItem: (k) => (m.has(k) ? m.get(k) : null), setItem: (k, v) => { m.set(k, String(v)); }, removeItem: (k) => { m.delete(k); }, m }; };
const hooks = (live) => ({ reveal() {}, fix() {}, live });
const draw = (session, live) => { const root = document.createElement('div'); proofView(session, root, hooks(live)); return root; };
const proved = () => new Session(stateForProblem(problemById('count-base-proved')), { storageId: null });
test('the setting is one of the listed times, 3 seconds unless the reader chose another, and kept under a pplus name', () => {
assert.equal(DEFAULT_PROVE_CLOCK, 3000);
assert.deepEqual(PROVE_CLOCKS.map((c) => c.ms), [3000, 10000, 30000, 120000]);
const store = memory();
assert.equal(loadProveClock(store), 3000);
assert.equal(saveProveClock(30000, store), 30000);
assert.deepEqual([...store.m.keys()], ['pplus.proveclock']);
assert.equal(loadProveClock(store), 30000);
// anything that is not a listed time is the default, stored or asked for
store.setItem('pplus.proveclock', '99999999');
assert.equal(loadProveClock(store), 3000);
assert.equal(saveProveClock(7, store), 3000);
assert.equal(store.m.size, 0, 'the default is kept by keeping nothing');
assert.equal(loadProveClock(null), 3000);
assert.equal(longerProveClock(3000), 10000);
assert.equal(longerProveClock(120000), null);
assert.equal(clockWords(120000), '2 minutes');
assert.equal(clockWords(1500), '1.5 seconds');
});
test('a proof the clock stopped says so, offers the next longer time, and is proved again with it', () => {
const s = proved();
assert.equal(s.proofClock(), 3000);
// a clock that has already run out, which is what 3 seconds are on a slow or busy device
s.proofBudgetMs = -1;
const cut = s.proof().report;
assert.ok(cut.clock.stopped.length >= 1, JSON.stringify(cut.clock));
assert.equal(cut.counts.broken, 0);
const view = draw(s, true);
const notice = view.querySelector('.proof-timeout');
assert.match(notice.textContent, /Time ran out on .*shown open, not disproved/);
assert.match(notice.querySelector('button').textContent, /^Prove again with 3 seconds$/);
assert.ok(view.querySelector('select#proof-clock'), 'and the setting itself is in the view');
// the setter proves again and tells the views
let told = 0;
s.onChange((what) => { if (what === 'run') told++; });
s.setProofClock(10000);
assert.equal(s.proofClock(), 10000);
assert.equal(told, 1);
const whole = s.proof().report;
assert.deepEqual(whole.clock, { budgetMs: 10000, stopped: [] });
assert.ok(whole.counts.proved > cut.counts.proved);
assert.equal(draw(s, true).querySelector('.proof-timeout'), null);
assert.equal(draw(s, true).querySelector('select#proof-clock').value, '10000');
s.setProofClock(10000);
assert.equal(told, 1, 'the same time again is no change');
s.setProofClock(3000);
});
test('a view that is not live (a page rendered with Quarto) says the time ran out and offers no control', () => {
const s = proved();
s.proofBudgetMs = -1;
const view = draw(s, false);
assert.match(view.querySelector('.proof-timeout').textContent, /Time ran out/);
assert.equal(view.querySelector('button.btn'), null);
assert.equal(view.querySelector('select'), null);
});
test('a rendered proof takes its time from the request, and has no warning when the time was enough', () => {
const p = problemById('count-base-proved');
const files = { pseudo: p.sources.pseudo, speco: p.sources.speco };
const r = renderStatic({ view: 'proof', files, proveSeconds: 600 });
assert.match(r.html, /[1-9]\d* proved/);
assert.doesNotMatch(r.html, /Time ran out/);
assert.deepEqual(r.warnings, []);
});