Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
- name: tests
working-directory: .
run: npm test
# ESLint: undefined names, the rules of hooks, and every suppression says why.
- run: npm run lint
- run: npm run build

# The iPhone app: strict TypeScript over mobile/src, including the lib copies.
Expand Down
344 changes: 56 additions & 288 deletions AGENTS.md

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions app/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ESLint for the web app (#98). Two jobs, both cheap and both real failures this
// codebase has had: a name that is not defined (an import lost in a move renders
// nothing until the line runs), and the rules of hooks. `exhaustive-deps` is on,
// and a suppression must say why after `--` (`local/disable-says-why`): ten of
// them sat unexplained, and nothing checked them, before this file existed.
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'

/** An `eslint-disable…` comment with no ` -- reason` after its rule. */
const disableSaysWhy = {
meta: { type: 'problem', messages: { why: 'Say why after `--`: {{text}}' } },
create(context) {
return {
Program() {
for (const c of context.sourceCode.getAllComments()) {
const text = c.value.trim()
if (/^eslint-disable/.test(text) && !/\s--\s+\S/.test(text)) context.report({ loc: c.loc, messageId: 'why', data: { text } })
}
},
}
},
}

export default [
{ ignores: ['node_modules/**', 'dist/**', '**/.*.mjs', '../dist/**'] },
{
files: ['src/**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: { ecmaFeatures: { jsx: true } },
globals: { ...globals.browser },
},
linterOptions: { reportUnusedDisableDirectives: 'error' },
plugins: { 'react-hooks': reactHooks, local: { rules: { 'disable-says-why': disableSaysWhy } } },
rules: {
'no-undef': 'error',
'no-unused-vars': ['error', { args: 'none', varsIgnorePattern: '^_', caughtErrors: 'none', ignoreRestSiblings: true }],
'no-dupe-keys': 'error',
'no-unreachable': 'error',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',
'local/disable-says-why': 'error',
},
},
]
4 changes: 3 additions & 1 deletion app/gear.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ check('every profile field is renderable', () => {
ok(g.key && g.name && g.icon, `group ${g.key} is missing something`)
for (const f of g.fields) {
ok(f.key && f.label && f.type, `${g.key}.${f.key} is missing something`)
ok(['number', 'text'].includes(f.type), `${f.key}: unknown type ${f.type}`)
ok(['number', 'text', 'grade'].includes(f.type), `${f.key}: unknown type ${f.type}`)
// A grade says which ladder it is picked off (#98): the field decides, never the number.
if (f.type === 'grade') ok(['yds', 'v'].includes(f.scale), `${f.key}: a grade with no scale`)
}
}
})
Expand Down
92 changes: 92 additions & 0 deletions app/merge.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// The client's and the server's last-write-wins merge (#98, H F6), fed the same
// inputs. They share the rule (per entry, on its own updatedAt, a tie to the
// incoming copy, tombstones as entries, settings by settingsUpdatedAt) and the
// comment above lib/store.js `mergeState` used to claim they were identical.
// They are not: the server also stamps an entry that arrives with no updatedAt
// and keeps an old client's bare untick (`keepUntick`). The shared cases are
// held equal here; the two differences are pinned as differences, so neither
// side is "fixed" to match the other by someone trusting a comment.
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { mergeState as clientMerge } from './src/lib/store.js'

const require = createRequire(import.meta.url)
const { mergeState: serverMerge } = require('../server/server.js')

const tests = []
const test = (name, fn) => tests.push([name, fn])

const e = (id, updatedAt, data = {}, more = {}) => ({ id, kind: 'daily', date: '2026-11-08', updatedAt, data, ...more })
const base = () => ({
entries: {
a: e('a', '2026-11-08T10:00:00.000Z', { name: 'Old' }),
b: e('b', '2026-11-08T12:00:00.000Z', { name: 'Kept' }),
c: e('c', '2026-11-08T09:00:00.000Z', { name: 'Going' }),
},
settings: { units: 'lb' },
settingsUpdatedAt: '2026-11-08T08:00:00.000Z',
})

const SHARED = [
['a newer entry wins', { entries: { a: e('a', '2026-11-08T11:00:00.000Z', { name: 'New' }) } }],
['an older entry loses', { entries: { b: e('b', '2026-11-08T11:00:00.000Z', { name: 'Stale' }) } }],
['a tie goes to the incoming copy', { entries: { a: e('a', '2026-11-08T10:00:00.000Z', { name: 'Same time' }) } }],
['a newer tombstone deletes', { entries: { c: e('c', '2026-11-08T10:00:00.000Z', {}, { deleted: true }) } }],
['an older tombstone does not', { entries: { b: e('b', '2026-11-08T01:00:00.000Z', {}, { deleted: true }) } }],
['a new entry is added under its key', { entries: { z: e('elsewhere', '2026-11-08T13:00:00.000Z', { name: 'New one' }) } }],
['what is not an entry is skipped', { entries: { x: null, y: 'nope', a: e('a', '2026-11-08T11:00:00.000Z') } }],
['newer settings win', { entries: {}, settings: { units: 'kg' }, settingsUpdatedAt: '2026-11-08T09:00:00.000Z' }],
['older settings lose', { entries: {}, settings: { units: 'kg' }, settingsUpdatedAt: '2026-11-08T07:00:00.000Z' }],
['a done entry ticked done again is just newer', { entries: { a: e('a', '2026-11-08T11:00:00.000Z', { done: true }) } }],
]

for (const [name, incoming] of SHARED) {
test(`same answer: ${name}`, () => {
const b1 = base(), b2 = base()
const c = clientMerge(b1, structuredClone(incoming))
const s = serverMerge(b2, structuredClone(incoming))
assert.deepEqual(c, s, 'the client and the server merge disagree')
assert.deepEqual(b1, base(), 'the merge changed what it was given')
})
}

test('the cases say what they claim', () => {
const m = clientMerge(base(), SHARED[0][1])
assert.equal(m.entries.a.data.name, 'New')
assert.equal(clientMerge(base(), SHARED[1][1]).entries.b.data.name, 'Kept')
assert.equal(clientMerge(base(), SHARED[2][1]).entries.a.data.name, 'Same time')
assert.equal(clientMerge(base(), SHARED[3][1]).entries.c.deleted, true)
assert.equal(clientMerge(base(), SHARED[5][1]).entries.z.id, 'z', 'the key, not the body, is the id')
assert.equal(clientMerge(base(), SHARED[7][1]).settings.units, 'kg')
assert.equal(clientMerge(base(), SHARED[8][1]).settings.units, 'lb')
})

test('a difference, on purpose: only the server stamps an entry that arrives with no updatedAt', () => {
const incoming = { entries: { n: { id: 'n', kind: 'daily', date: '2026-11-08', data: {} } } }
assert.equal(clientMerge(base(), incoming).entries.n.updatedAt, undefined)
assert.ok(serverMerge(base(), incoming).entries.n.updatedAt, 'the server kept an unstamped entry unstamped')
})

test("a difference, on purpose: only the server keeps an old client's bare untick as one (keepUntick)", () => {
const b = base()
b.entries.a.data = { done: true }
const incoming = { entries: { a: e('a', '2026-11-08T11:00:00.000Z', { done: false }) } }
assert.equal(clientMerge(structuredClone(b), incoming).entries.a.data.undone, undefined)
assert.equal(serverMerge(structuredClone(b), incoming).entries.a.data.undone, true)
})

test('the comment on the client merge says what it shares and what it does not', () => {
for (const f of ['./src/lib/store.js', '../mobile/src/lib/store.js']) {
const src = readFileSync(new URL(f, import.meta.url), 'utf8')
if (/Identical to the server's/.test(src)) throw new Error(`${f} claims the merges are identical again`)
if (!/keepUntick/.test(src) || !/app\/merge\.test\.js/.test(src)) throw new Error(`${f} no longer names the difference and this test`)
}
})

let failed = 0
for (const [name, fn] of tests) {
try { await fn(); console.log(` ok ${name}`) } catch (err) { failed += 1; console.log(` FAIL ${name}\n ${err.message}`) }
}
console.log(failed ? `${failed} of ${tests.length} merge cases failed` : `${tests.length} merge cases`)
process.exit(failed ? 1 : 0)
21 changes: 21 additions & 0 deletions app/native.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ test('every Input carries the keyboard bar, and no sheet footer is a Close', ()
assert.deepEqual(bad, [], 'a Close is back in a sheet footer')
})

test('the coach is gone from the dock too (#31, F F8)', () => {
if (/coach/.test(read('shell/TabBar.tsx'))) throw new Error('the tab bar still checks for a coach tab')
if (/coach/i.test(read('lib/foreground.ts'))) throw new Error('foreground.ts still names a coach provider')
})

/*
* The typecheck means something only where nothing is cast away (#98, H F4):
* a lib function TypeScript reads too narrowly gets a JSDoc type in the lib
* (both copies), never an `as any` at the call. A ratchet: these numbers only
* go down. Lower them when you remove casts.
*/
const AS_ANY = { total: 217, hot: { 'features/sheet.tsx': 0, 'features/editor.tsx': 1, 'features/exercises.tsx': 3, 'features/runner.tsx': 2 } }
test(`no more \`as any\` than the ratchet (${AS_ANY.total} in mobile/src)`, () => {
const count = (f) => (read(f).match(/\bas any\b/g) || []).length
const total = walk('.').reduce((n, f) => n + count(f), 0)
if (total > AS_ANY.total) throw new Error(`${total} \`as any\` in mobile/src, up from ${AS_ANY.total}: type the lib function with JSDoc instead`)
for (const [f, n] of Object.entries(AS_ANY.hot)) {
if (count(f) > n) throw new Error(`${f}: ${count(f)} \`as any\`, up from ${n}`)
}
})

let failed = 0
for (const [name, fn] of tests) {
try { await fn(); console.log(` ok ${name}`) } catch (e) { failed += 1; console.log(` FAIL ${name}\n ${e.message}`) }
Expand Down
Loading
Loading