Skip to content

Latest commit

 

History

History
149 lines (122 loc) · 9.49 KB

verification.md

File metadata and controls

149 lines (122 loc) · 9.49 KB

Verification: what is checked, and how

How sure are we that the code does what it says? This page is the honest list: what is proved, what is tested on generated inputs, what is checked while the app runs, and what nothing covers. Keep it current: a row is added with its test, and TestVerificationNamesChecksThatExist (internal/audit) fails for a row whose test does not exist.

The security claims have their own list, with a check for each: SECURITY.md.

How much to test

A new app changes shape every week. Tests that exist only for coverage slow every change and prove little, and a slow run stops being run. So:

  • A handful of tests to start: the checks behind the security claims, one property test and one fuzz target as worked examples (below). Not a test per function.
  • Add a test where the logic is critical, or where a bug was found. Critical logic (money, scheduling, permissions) gets a property. A parser of bytes that come from outside gets a fuzz target. A bug that reached a person gets a regression test.
  • CI has a budget: a pull request's run in about five minutes, in two jobs. Property tests run rapid's default number of cases. Fuzz targets run on their saved inputs only; searching for new inputs is make fuzz, by hand or on a schedule, never in a pull request's run.
  • The browser tests come later, when the app has users and a settled UI (E2E=true, see AGENTS.md).

Proved

Nothing yet.

Planned: a prove option for the template, with Gobra, a verifier for Go. The specification is written next to the code, in //@ comments (what a function requires, what it ensures, what a loop keeps true), and make prove checks, for every input, that the code meets it. It will come with one worked example in a small package of pure logic (internal/core), run from Gobra's container image, and a row here for each function that is proved. It is being piloted in another project first and will be added from there once it works; until then this section stays empty rather than promising more than is checked.

A proof covers the code it is written for and the properties it states, no others: what is proved goes in this section, and everything else stays in the sections below.

Property-tested

Statements that must hold for every input, checked on generated inputs (rapid; a failure is shrunk to the smallest input that still fails).

What must hold Test
The permission rule: nobody is refused a read they may make; anything but a GET or a HEAD needs a caller who may write; nobody is let in without being a caller; a writer is let through until the write limit and then told to wait internal/auth/auth_test.go TestCheckProperties

Fuzzed

Parsers of bytes that come from outside, given arbitrary input: they must not panic, must refuse what is malformed with a documented error, and must not accept what is not whole. make test runs each target on its saved inputs (testdata/fuzz/); make fuzz searches for new ones.

What is parsed Target
A backup file's contents: its records and each table's rows in PostgreSQL's binary COPY format internal/backup/fuzz_test.go FuzzVerify

Checked at run time

What a job states about its result just before it stores it (internal/invariant). When one does not hold, nothing is stored, the job exits non-zero and the error names the invariant. This is what catches the input nobody thought of, on the real data.

What must hold Where Test
A backup is kept only if it reads back, with its key, to its authenticated end, and holds the tables and the number of rows that were copied cmd/app/backup.go (verifyBackup), internal/backup (Write, Verify) cmd/app/backup_test.go TestBackupAndRestoreCommands internal/backup/fuzz_test.go TestVerifyCountsRows

A new job states its own before it stores anything: sums that must match, counts that must not be negative, a total that must equal its parts (the package comment of internal/invariant shows how).

Not covered

Said plainly, so that nobody assumes otherwise:

  • Nothing is formally proved. Every check above samples inputs; it shows no counterexample among those tried, not that there is none.
  • The handlers' logic beyond the security claims has example tests for the notes feature only. A feature that replaces it brings its own.
  • The web app has unit tests for what it shows to whom, and one Playwright flow that CI does not run until E2E=true.
  • Concurrency: the Go tests run with the race detector, which finds races on the paths the tests take. Nothing checks orderings they do not take.
  • Restoring a backup at another schema version is refused, not supported.
  • Behaviour under load, or with the database slow or gone mid-request, beyond the timeouts and the one 503 the tests drive.

The iPad app (ios/, Swift)

The iPad app is outside the Go audit above: internal/audit does not read Swift tests, so this is a plain list. swift test in ios/GameKit, ios/PitchKit and ios/PianoKit runs it, and CI runs it on every change under ios/ (.github/workflows/ios.yml), then builds the app for the simulator without signing.

Tested, on synthetic signals (ios/PitchKit/Tests): every key of the profile (F2-F5), through a model of a small speaker (weak below 200 Hz), with the fundamental missing, with a thin voice (most energy in the second harmonic), with fast decay, and out of tune by 18 cents; wait mode accepts the right key and refuses its neighbours, a whole tone, a fifth and the octaves; two keys at once; room noise and speech-like noise under the key; silence, room noise alone and speech alone; the streaming path (every press found and named, the first answer about 60 ms after the attack, the same answer whatever the block size); the recording guide stays on the keyboard; the evaluator lines up detections with the script, counts a missed press, and reports a wrong octave.

Tested, the game's rules (ios/GameKit/Tests, ios/PianoKit/Tests):

  • What counts as a note is one rule, WaitRule, shared by the app and pitch-eval: a key the detector accepts is accepted at any confidence (NoteEvent.vetted, so the engine does not gate it a second time); a different key is a miss only when it is confident and the attack is sharp, and room noise and speech are never a miss.
  • Repeated notes: one press never satisfies two notes in a row on the same key (RepeatGate), while two real presses of one key do; pitch-eval reports extra onsets per press.
  • The octave: a profile can be shifted by whole octaves, a wide search names the true octave of a key the profile does not have, a take's sidecar records the keys it was made with, and the songs are moved by whole octaves to fit (Song.fitted(to:)).
  • The microphone's life (MicrophoneSession, with a fake audio backend): users are counted and share one start; leaving a song while the permission prompt is up never switches the engine on; a refused permission releases its hold; an interruption pauses and its end listens again; a route change, a configuration change and a media-services reset restart the engine, and the engine's own echo right after starting does not; the background pauses and coming back resumes; a failed restart says why and the retry works; the block size reported is the one the answer was made on.
  • The screen stays on while a song is open and is given back once (ScreenWake).

Known weaknesses, not hidden:

  • Synthetic is not real. Nothing here says the detector hears a Remie. The recordings do; the numbers in the code (AnalysisConfig, OnsetConfig, WaitRule, RepeatGate) are first guesses to be tuned on them.
  • The octave of a low key is a guess from its harmonics, because a small speaker may leave out the fundamental. The range check shows the pitch heard and the key named; the parent confirms it against the keyboard.
  • Nothing runs on a real iPad in CI: the audio session, the engine and the tap or sink node (AVAudioBackend) are not exercised by any test; the session logic above them is, with a fake. Whether the tap delivers small blocks, whether an interruption really ends with the engine restartable, and the real press-to-screen latency need an iPad.
  • Voiced speech can look like a key. It is harmonic, steady over 140 ms and in range. In the synthetic test, wait mode accepts a speech onset as the expected key for fewer than 8% of the keys it could be waiting for, and any such onset is also reported as an "extra" press. The attack's sharpness now keeps it from being called a wrong key; it can still be taken for the right one.
  • Onsets in loud rooms. With room noise 3 dB under the key every press in the synthetic test is found; with it 3 dB over the key about half are. In a loud room the attack's rise is small too, so a real wrong key is ignored rather than counted. Nothing is said about real rooms until they are recorded.
  • The attack's position is found to within a few milliseconds on a quiet room and to within about 35 ms when a key is struck while another still rings.
  • Chords by ear: the upper key of two together is not found (G is a harmonic of C), so a chord step needs the screen keys. No bundled song has one.
  • Not measured off the iPad: the press-to-screen latency, which only the app can measure (about 60 ms of the budget is the detector's wait for enough of the sound), and which needs a Release build.