feat(course): audit fixes and twelve extensions (Modules 7b, 12, 13)

Audit pass:
- Frame rule counts frames since the last move, so every step lasts
  exactly movesEvery(score) frames, also right after a speed-up
- clampTime + MAX_GAP_MS: a hidden tab no longer replays the whole gap
- Pong Restart keeps held keys
- Fact corrections (mulberry32 output coverage, Haskell IO, uniform)
- New fixture cases from a mutation analysis

Extensions (all three tracks, shared fixtures, course text):
- Turn queue (Exercise 10.6), persisted high score (10.7),
  replay viewer (10.8), play() end-to-end helper (9.5)
- Optional State (4.7) and optional Module 7b, stack-safe IO
- Module 12, property-based testing with generators, shrinking,
  invariants and a model-based oracle
- Module 13, Conway's Life with a Click event
- JS type checking via jsconfig, JSDoc and types.d.ts
- Maintainer tools: scripts/mutate.mjs, scripts/typecheck-js.sh,
  Playwright end-to-end suite (e2e/, scripts/e2e.sh)

Docs: docs/contract.md is the canonical contract; specs and build log
under docs/superpowers.

Verified: JS 728, Scala 689, F# 691 unit tests; stubs and progression
M01-M13 and M07b; 176 end-to-end tests on Chromium and WebKit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Fable 5.2 committed 2026-11-11 12:05:29 +01:00
1 parent 876f5aabb1
commit edd57f0148
253 files changed
+21753 -503

No files matched your search

+36 -1
View File
@@ -1,13 +1,21 @@
// m08 stream: an event stream is a pure automaton (a Mealy machine).
// Stream<A> = { step: input => [outputs, nextStream] }
// There is no hidden state: whatever a stream "remembers" lives in the next stream it returns.
/** @import { Point, Input, Stream } from './types' */
// Sources may return themselves as the next stream, since they remember nothing.
/** @type {Stream<string>} */
export const keyDowns = { step: (i) => [i.tag === 'KeyDown' ? [i.key] : [], keyDowns] }
/** @type {Stream<string>} */
export const keyUps = { step: (i) => [i.tag === 'KeyUp' ? [i.key] : [], keyUps] }
// (m13, given in src/) The position of every Click input, in canvas pixels. Like the key sources it remembers nothing.
/** @type {Stream<Point>} */
export const clicks = { step: (i) => [i.tag === 'Click' ? [{ x: i.x, y: i.y }] : [], clicks] }
// `last` is the time of the previous Time input. Multiples of ms in (last, t] fire, ascending.
/** @type {(ms: number, last: number) => Stream<number>} */
const intervalFrom = (ms, last) => ({
step: (i) => {
if (i.tag !== 'Time') return [[], intervalFrom(ms, last)]
@@ -17,9 +25,11 @@ const intervalFrom = (ms, last) => ({
},
})
/** @type {(ms: number) => Stream<number>} */
export const interval = (ms) => intervalFrom(ms, 0)
// Each combinator steps its inputs and wraps the *next* streams in the same combinator.
/** @type {<A, B>(s: Stream<A>, f: (a: A) => B) => Stream<B>} */
export const map = (s, f) => ({
step: (i) => {
const [out, next] = s.step(i)
@@ -27,6 +37,7 @@ export const map = (s, f) => ({
},
})
/** @type {<A>(s: Stream<A>, p: (a: A) => boolean) => Stream<A>} */
export const filter = (s, p) => ({
step: (i) => {
const [out, next] = s.step(i)
@@ -34,8 +45,10 @@ export const filter = (s, p) => ({
},
})
export const filterMap = (s, f) => filter(map(s, f), (b) => b !== null)
/** @type {<A, B>(s: Stream<A>, f: (a: A) => B | null) => Stream<B>} */
export const filterMap = (s, f) => /** @type {any} */ (filter(map(s, f), (b) => b !== null))
/** @type {<A>(a: Stream<A>, b: Stream<A>) => Stream<A>} */
export const merge = (a, b) => ({
step: (i) => {
const [outA, nextA] = a.step(i)
@@ -45,6 +58,7 @@ export const merge = (a, b) => ({
})
// The accumulator travels in the arguments of the next scan, not in a variable.
/** @type {<A, B>(s: Stream<A>, f: (acc: B, a: A) => B, z: B) => Stream<B>} */
export const scan = (s, f, z) => ({
step: (i) => {
const [out, next] = s.step(i)
@@ -54,6 +68,7 @@ export const scan = (s, f, z) => ({
})
// Only the first step is special; afterwards we are just `next`.
/** @type {<A>(s: Stream<A>, v: A) => Stream<A>} */
export const startWith = (s, v) => ({
step: (i) => {
const [out, next] = s.step(i)
@@ -61,8 +76,28 @@ export const startWith = (s, v) => ({
},
})
// (m10) `last` is the previous real time, `clock` the time the inner stream has been told. A long silence
// (a background tab) moves `clock` by at most `maxGap`, so the inner stream never has to catch up on minutes of beats.
/** @type {<A>(s: Stream<A>, maxGap: number, last: number, clock: number) => Stream<A>} */
const clampFrom = (s, maxGap, last, clock) => ({
step: (i) => {
if (i.tag !== 'Time') {
const [out, next] = s.step(i)
return [out, clampFrom(next, maxGap, last, clock)]
}
const now = clock + Math.min(Math.max(i.t - last, 0), maxGap)
const [out, next] = s.step({ tag: 'Time', t: now })
return [out, clampFrom(next, maxGap, i.t, now)]
},
})
/** @type {<A>(s: Stream<A>, maxGap: number) => Stream<A>} */
export const clampTime = (s, maxGap) => clampFrom(s, maxGap, 0, 0)
/** @type {<A>(s: Stream<A>, inputs: Input[]) => A[]} */
export const run = (s, inputs) =>
inputs.reduce(
/** @type {(acc: [any[], typeof s], i: Input) => [any[], typeof s]} */
([outs, stream], i) => {
const [out, next] = stream.step(i)
return [[...outs, ...out], next]