// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 // When there is no run to step, the stepper and the Run view say what is in the way (src/core/norun.ts): how many // problems the stepped pane has and the first one, what an engine said when it stopped, or that the pane is empty. // "Nothing to run yet." alone told a student with a typo nothing. import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import { Session } from '../dist/core/session.js'; import { stateForProblem, problemById } from '../dist/core/catalog.js'; import { whyNoRun } from '../dist/core/norun.js'; globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } }; const open = (id, area) => new Session(stateForProblem(problemById(id)), { area, storageId: null }); test('a pane with problems says how many, and names the first with its line', () => { const s = open('count-base', 'bridge'); s.setLang('pseudo'); s.setSource('pseudo', s.source('pseudo') + '\nTotal <- Totl + \n'); assert.equal(s.trace(), null); const why = whyNoRun(s); assert.equal(why.lang, 'pseudo'); assert.ok(why.errors >= 2, `${why.errors} errors`); assert.equal(why.headline, `No run yet: the pseudo pane has ${why.errors} problems to fix first.`); const first = s.diagnostics('pseudo').find((d) => d.severity === 'error'); assert.equal(why.detail, `Line ${first.line}: ${first.message}`); assert.equal(why.line, first.line); }); test('one problem is "a problem", and Mojo\'s own errors are counted the same way', () => { const s = open('count-base', 'dev'); s.setLang('mojo'); s.setSource('mojo', 'def main():\n var s = String("hi")\n var t = s^\n print(s)\n'); assert.equal(s.trace(), null); assert.deepEqual(whyNoRun(s), { headline: 'No run yet: the Mojo pane has a problem to fix first.', detail: "Line 4: use of uninitialized value 's'", errors: 1, lang: 'mojo', line: 4 }); }); test('an empty pane says it is empty', () => { const s = open('count-base', 'dev'); s.setLang('mojo'); s.setSource('mojo', ' \n'); assert.equal(s.trace(), null); assert.deepEqual(whyNoRun(s), { headline: 'Nothing to run yet: the Mojo pane is empty.', detail: null, errors: 0, lang: 'mojo', line: null }); }); test('a pane that runs has no such reason to give: the views ask only when trace() is null', () => { const s = open('count-base', 'bridge'); s.setLang('pseudo'); assert.ok(s.trace()); for (const f of ['src/ui/views/run.ts', 'src/ui/views/trace.ts']) { const text = fs.readFileSync(new URL(`../${f}`, import.meta.url), 'utf8'); assert.match(text, /whyNoRun\(session\)/, `${f} no longer asks whyNoRun`); assert.doesNotMatch(text, /'Nothing to run yet\.'/, `${f} has its own "Nothing to run yet." again`); } });