Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): scope Morse drill types out of scored-session schema, add round-completion test coverage

Adam Eivyfd0fbaae9161
diff --git a/client/src/components/meatspace/post/MorseTrainer.test.jsx b/client/src/components/meatspace/post/MorseTrainer.test.jsx
index 5db382682a..1a5cfd3585 100644
--- a/client/src/components/meatspace/post/MorseTrainer.test.jsx
+++ b/client/src/components/meatspace/post/MorseTrainer.test.jsx
@@ -16,6 +16,33 @@ vi.mock('../../../services/api', () => ({
import MorseTrainer, { MODES, MORSE_MODE_IDS, MORSE_TABLE, isNodeOnPath } from './MorseTrainer';
import { submitTrainingEntry, getTrainingStats } from '../../../services/api';
+// Minimal Web Audio mock so CopyDrill's round flow (which calls ensureCtx →
+// playMorse) can run in jsdom without a real AudioContext. No existing shared
+// mock exists for this in the repo (each audio-consuming test file rolls its
+// own) — mirrors that convention. `stop()` resolves playMorse's promise on
+// the next tick, matching the real oscillator's `onended` callback shape.
+class MockOscillator {
+ constructor() { this.onended = null; this.frequency = { value: 0 }; }
+ connect() { return this; }
+ start() {}
+ stop() { if (this.onended) setTimeout(() => this.onended(), 0); }
+ disconnect() {}
+}
+class MockGainNode {
+ constructor() {
+ this.gain = { value: 0, setValueAtTime() {}, linearRampToValueAtTime() {}, cancelScheduledValues() {} };
+ }
+ connect() { return this; }
+ disconnect() {}
+}
+class MockAudioContext {
+ constructor() { this.currentTime = 0; this.destination = {}; this.state = 'running'; }
+ createOscillator() { return new MockOscillator(); }
+ createGain() { return new MockGainNode(); }
+ resume() {}
+ close() {}
+}
+
// Surfaces the live URL (path + search) so tests can assert the reference tab
// is encoded in the query string — the "URL is the source of truth" contract.
function LocationProbe() {
@@ -120,6 +147,35 @@ describe('MorseTrainer training log integration', () => {
expect(container.textContent).toContain('Morse logged: 4');
expect(container.textContent).toContain('80% avg');
});
+
+ it('logs a completed Head Copy round to the training log with the right payload shape', async () => {
+ window.AudioContext = MockAudioContext;
+ renderMorse({ mode: 'head-copy', onSelectMode: vi.fn(), onExitMode: vi.fn() });
+
+ fireEvent.click(await screen.findByRole('button', { name: /Start Round/i }));
+
+ // 10-question round (ROUND_SIZE): submit a deliberately wrong guess each
+ // time so correctCount is deterministic (0), then advance past feedback.
+ for (let i = 0; i < 10; i++) {
+ const input = await screen.findByPlaceholderText('????');
+ fireEvent.change(input, { target: { value: 'ZZZZZ' } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+ if (i < 9) {
+ const nextButton = await screen.findByRole('button', { name: /Next/i });
+ fireEvent.click(nextButton);
+ }
+ }
+
+ await waitFor(() => {
+ expect(submitTrainingEntry).toHaveBeenCalledWith(expect.objectContaining({
+ module: 'morse',
+ drillType: 'morse-head-copy',
+ questionCount: 10,
+ correctCount: 0,
+ }));
+ });
+ delete window.AudioContext;
+ });
});
describe('MorseTrainer Tree reference view', () => {
diff --git a/server/lib/postValidation.js b/server/lib/postValidation.js
index 16dc24b7d9..0e299d6589 100644
--- a/server/lib/postValidation.js
+++ b/server/lib/postValidation.js
@@ -53,9 +53,17 @@ const MEMORY_DRILL_TYPES = ['memory-fill-blank', 'memory-sequence', 'memory-elem
const POST_SUPPORTED_MEMORY_TYPES = ['memory-sequence', 'memory-element-flash'];
// Cognitive drills (deterministic, no LLM) — n-back / digit-span / stroop.
// Sourced from meatspacePostCognitive.js so the type list has one owner.
+const DRILL_TYPES = [...MATH_DRILL_TYPES, ...LLM_DRILL_TYPES, ...MEMORY_DRILL_TYPES, ...COGNITIVE_DRILL_TYPES];
// Morse trainer drill types (client-side scoring — exact-match copy/send comparison).
+// Deliberately NOT spliced into DRILL_TYPES: that array also backs
+// taskResultSchema.type (the *scored* full-session submit endpoint,
+// postSessionSubmitSchema) and postDrillRequestSchema.type (server-side drill
+// generation). meatspacePost.js's scoring dispatch only special-cases
+// LLM/MEMORY/COGNITIVE types and falls through everything else to scoreDrill's
+// math-expression parser (computeExpectedFromPrompt) — a Morse task type would
+// pass validation there but silently mis-score as a failed math drill instead
+// of being rejected. Morse only ever posts through trainingEntrySchema below.
const MORSE_DRILL_TYPES = ['morse-copy', 'morse-head-copy', 'morse-send'];
-const DRILL_TYPES = [...MATH_DRILL_TYPES, ...LLM_DRILL_TYPES, ...MEMORY_DRILL_TYPES, ...COGNITIVE_DRILL_TYPES, ...MORSE_DRILL_TYPES];
const drillTypeConfigSchema = z.object({
enabled: z.boolean().optional(),
@@ -269,7 +277,11 @@ export const memoryDrillRequestSchema = z.object({
// Training log entry submission
export const trainingEntrySchema = z.object({
module: z.string(),
- drillType: z.enum(DRILL_TYPES),
+ // Training log entries also cover Morse (client-side scored, never a scored
+ // POST session) — union in MORSE_DRILL_TYPES here rather than in the shared
+ // DRILL_TYPES so postSessionSubmitSchema/postDrillRequestSchema can't accept
+ // a Morse type (see the MORSE_DRILL_TYPES comment above).
+ drillType: z.enum([...DRILL_TYPES, ...MORSE_DRILL_TYPES]),
questionCount: z.number().int().min(0),
correctCount: z.number().int().min(0),
totalMs: z.number().min(0),