Varied question openers, readable rationales, plain practice score
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 30s

- Stems no longer all open the same way: the writing rules, batch prompt and
  planner ask for varied openings (age openings stay part of the mix), and when
  one opener covers more than a quarter of a quiz the excess stems have only
  their opening reworded, keeping every number, before the check.
- Rationales are asked for as Markdown (a bold key point, then short bullets);
  older one-paragraph rationales are laid out the same way on display.
- The practice score in the quiz header is a plain "x/y correct", with no
  percentage or colour.
- Fix a flaky assertion: the mock's answer-key fix is a no-op when the shuffle
  already put the answer in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-16 12:05:46 -07:00
parent 10be5c39da
commit 517278be71
15 changed files with 382 additions and 24 deletions

34
tests/rationale.test.ts Normal file
View file

@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';
import { formatRationale, splitSentences } from '../shared/rationale.ts';
describe('rationale layout', () => {
it('keeps decimals and abbreviations inside a sentence', () => {
expect(splitSentences('Give 2.5 mg now, e.g. with food. Recheck the level in 6 hr. Then report it.')).toEqual(['Give 2.5 mg now, e.g. with food.', 'Recheck the level in 6 hr. Then report it.']);
});
it('breaks a long paragraph into a lead sentence and short paragraphs', () => {
const brick =
'Potassium of 2.9 mEq/L is hypokalemia caused by loop-diuretic potassium loss. It explains the cramps, weakness and palpitations the client reports. Hypokalemia destabilises cardiac membranes and can cause dysrhythmias. This is more dangerous in a client who also takes digoxin. The nurse notifies the provider and anticipates potassium replacement. The weight loss and urine output show the drug is working as intended.';
const out = formatRationale(brick);
const blocks = out.split('\n\n');
expect(blocks[0]).toBe('**Potassium of 2.9 mEq/L is hypokalemia caused by loop-diuretic potassium loss.**');
expect(blocks.length).toBeGreaterThanOrEqual(3);
expect(out.replace(/\*\*/g, '').replace(/\s+/g, ' ')).toBe(brick);
});
it('turns a walk-through of the choices into a list', () => {
const brick =
'The priority is airway, so suctioning comes first in this situation for the client. Option A is wrong because repositioning does not clear secretions. It also delays care. Option B is wrong because oxygen will not help a blocked airway. Option D can wait until the airway is clear and the client is stable. The nurse reassesses breath sounds after suctioning.';
const out = formatRationale(brick);
expect(out).toMatch(/\n- Option A is wrong because repositioning does not clear secretions\. It also delays care\.\n/);
expect(out).toMatch(/\n- Option B is wrong/);
// A closing sentence on a new subject ends the list.
expect(out).toMatch(/stable\.\n\nThe nurse reassesses/);
});
it('leaves short or already structured rationales alone', () => {
expect(formatRationale('Short and clear.')).toBe('Short and clear.');
const md = '**Furosemide is a loop diuretic.**\n\n- Check potassium before each dose and report any low value.\n- Weigh daily at the same time with the same scale and clothing.\n- Give it in the morning to prevent nocturia and falls overnight at home.';
expect(formatRationale(md)).toBe(md);
});
});