Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5ee5a50
WIP: notes are about a record, not only an attendee — NOT VERIFIED, f…
claude Jul 28, 2026
8d97fc2
Retire the attendee-only index from the note table's first migration
claude Jul 28, 2026
2eec413
Answer the schema, registry and code-quality checks the change moves
claude Jul 28, 2026
873189f
Open one note through the same opener as a batch
claude Jul 28, 2026
506d29a
Put the note routes' tests where the source can find them, and let a …
claude Jul 28, 2026
fc912b9
Give the new files direct tests, and record the four modules that hav…
claude Jul 28, 2026
8063d91
Answer the review: read the primary, refuse an empty ask, fix the plans
claude Jul 28, 2026
eec0f5b
Answer the second review: cover the walk fix, read one the same way a…
claude Jul 28, 2026
cb1c0dd
Ask whether it is a directory before reading it
claude Jul 28, 2026
bb7beb2
Read a folder's contents one way across the scripts
claude Jul 28, 2026
4f459d6
Answer the third review: strict walker, resumable index, batched note…
claude Jul 28, 2026
7ba7447
Say what happens when adding a column fails for another reason
claude Jul 28, 2026
d2b4a29
Take the database's word on every step, not just adding a column
claude Jul 28, 2026
b72a98e
Pin each step's tolerance to its own answer, and drop a call that did…
claude Jul 28, 2026
6a0fec5
Merge remote-tracking branch 'origin/main' into claude/site-tidyup-mi…
claude Jul 28, 2026
25e7844
Re-anchor equivalent mutants after merging main
claude Jul 28, 2026
2c5ffa7
Point the importer plan at where the notes store now lives
claude Jul 28, 2026
21e7fd2
Assert the empty note delete really asks the database nothing
claude Jul 28, 2026
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
40 changes: 36 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,14 @@ re-rendering. Migration is deliberately gradual and hardest-first.

- **Slice 4 — the long tail.** Questions and `history/:hmac` remain. Groups,
holidays, users, built sites, and attendee statuses are complete.
- **Slice 5 — generalize `system_notes`** from attendee-only to
`(entity_type, entity_id)` so any entity page can carry a notes section. The
notes DB module currently has no `entity_type` column; this is a small
migration + query change that unblocks notes tabs on the other entities.
- **Slice 5 — generalize `system_notes`: done.** A note now names the kind of
record it is about and which one (`entity_type`, `entity_id`), and the notes
module works in those terms (`src/shared/db/notes/`). What remains is per-page
work: add `"listing"` (or whichever record is next) to `NOTE_ENTITIES` in
`notes/target.ts`, give that record's delete path the notes delete statement,
and add the notes section to its entity page. The list drives the database
`CHECK`, so adding a kind ships with a small rebuild migration — as
`2026-06-20_free_text_questions` did for `questions.display_type`.

---

Expand Down Expand Up @@ -1761,3 +1765,31 @@ as the supervisor is up, closing the gap. That means changing what
and thinking again about the startup grace, which exists because a process id
can be given to somebody else after the original has gone. Start at
`RUN_STARTUP_GRACE_MS` in `isolation-state.ts` and the comment above it.

## Four feature modules have no test at their mirrored path

*Origin: `deno task precommit:mutation` on the notes-migration branch, which
could not start.*

The mutation gate refuses to run a source that has mutants but no test at its
mirrored path under `test/`. Four modules are in that state:

- `src/features/admin/attendee-page.ts` (55 mutants)
- `src/features/admin/attendees-list.ts` (37)
- `src/features/admin/listing-page-data.ts` (45)
- `src/features/api/payment-processing/store-refund.ts` (29)

Nothing needs moving: no test imports any of them. They are reached only
through the app, by integration and Cucumber journeys, so each needs a direct
test written at `test/features/…` to match its path.

This blocks the gate for *any* branch that touches one of them, however small
the change — the notes migration only swapped an import in each. Until they
have direct tests, a branch touching them can prove its own work with a
targeted `deno task mutation <source> <tests>` run instead.

`src/features/admin/attendee-notes.ts` was in the same state and is now fixed:
its route suite drives real pages through the session helpers, so it moved from
`test/integration/admin/` to `test/features/admin/`, which is where that kind
of suite belongs (see "Let the misplaced-test list see past request helpers"
above). The other four have no such suite to move.
10 changes: 6 additions & 4 deletions docs/importer-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1429,10 +1429,12 @@ Implementation notes:
raw-deletes the source attendee and never touches `system_notes`, so the
imported audit trail (stored as a `system_notes` owner note) would be left
orphaned on the deleted source id. The merge must **repoint the source's
`system_notes` rows to the target** (`UPDATE system_notes SET attendee_id =
targetId WHERE attendee_id = sourceId`, in the same transaction — the
`booking_imports` remap's sibling), with a test that a merged imported source's
audit note survives on the target.
`system_notes` rows to the target** (`UPDATE system_notes SET entity_id =
targetId WHERE entity_type = 'attendee' AND entity_id = sourceId`, in the same
transaction — the `booking_imports` remap's sibling), with a test that a merged
imported source's audit note survives on the target. A note names the kind of
record it is about and which one, so both parts are matched; see
`src/shared/db/notes/target.ts`.
- The `attendee_answers` XOR/validation triggers will `ABORT` a malformed answer
row (e.g. both `answer_id` and `string_id` set). The importer only ever writes
the text-answer shape (`answer_id` NULL, `question_id` + `string_id` set), so a
Expand Down
59 changes: 1 addition & 58 deletions scripts/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* Usage: deno task mutation <source-glob> <test-glob> [options]
*/

import { globToRegExp, join, normalize, SEPARATOR } from "@std/path";
import { DEFAULT_TIMEOUT, parseArgs } from "./mutation/args.ts";
import { expand } from "./mutation/expand.ts";
import { runIsolatedMutationCommand } from "./mutation/isolation.ts";
import {
isSnapshotChild,
Expand All @@ -45,63 +45,6 @@ Examples:
deno task mutation src/shared/dates.ts test/shared/dates.test.ts
deno task mutation 'src/shared/forms/definition.ts' 'test/shared/forms/definition/*.test.ts' --exhaustive`;

/** Glob metacharacters; a path segment with none is a fixed directory name. */
const GLOB_CHARS = /[*?{}[\]]/;

/** Every file under `dir`, recursively; a missing directory yields nothing. */
async function* walkFiles(dir: string): AsyncGenerator<string> {
let entries: AsyncIterable<Deno.DirEntry>;
try {
entries = Deno.readDir(dir);
} catch {
return;
}
for await (const entry of entries) {
const path = join(dir, entry.name);
if (entry.isDirectory) yield* walkFiles(path);
else if (entry.isFile) yield path;
}
}

/** The leading, glob-free directory of `glob` — where a walk can start without
* scanning the whole tree. An exact path (no metacharacters) returns itself. */
const staticBase = (glob: string): string => {
const fixed: string[] = [];
for (const segment of normalize(glob).split(SEPARATOR)) {
if (GLOB_CHARS.test(segment)) break;
fixed.push(segment);
}
return fixed.length > 0 ? fixed.join(SEPARATOR) : ".";
};

/**
* Expand source/test globs to absolute file paths. Replaces `@std/fs`'s
* `expandGlob` (not in this project's lock, so unfetchable in a sandboxed run)
* with `@std/path`'s `globToRegExp` over a `Deno.readDir` walk — same contract:
* absolute paths to existing files, sorted and de-duplicated.
*/
const expand = async (globs: string[]): Promise<string[]> => {
const cwd = Deno.cwd();
const paths = new Set<string>();
for (const glob of globs) {
const absGlob = join(cwd, glob);
const pattern = globToRegExp(absGlob, { extended: true, globstar: true });
const base = staticBase(absGlob);
try {
if ((await Deno.stat(base)).isFile) {
if (pattern.test(base)) paths.add(base);
continue;
}
} catch {
// base doesn't exist; the walk below simply yields nothing
}
for await (const path of walkFiles(base)) {
if (pattern.test(path)) paths.add(path);
}
}
return [...paths].sort();
};

const main = async (): Promise<void> => {
const args = parseArgs(Deno.args);
if (args.error !== null) {
Expand Down
67 changes: 67 additions & 0 deletions scripts/mutation/expand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Turning source/test globs into the files they name.
*
* Replaces `@std/fs`'s `expandGlob` (not in this project's lock, so unfetchable
* in a sandboxed run) with `@std/path`'s `globToRegExp` over a `Deno.readDir`
* walk — same contract: absolute paths to existing files, sorted and without
* repeats.
*/

import { globToRegExp, join, normalize, SEPARATOR } from "@std/path";
import { statOrNull } from "#scripts/not-found.ts";
import { collectFiles } from "#scripts/walk-files.ts";

/** Glob metacharacters; a path segment with none is a fixed directory name. */
const GLOB_CHARS = /[*?{}[\]]/;

/**
* The leading, glob-free directory of `glob` — where a walk can start without
* scanning the whole tree. An exact path (no metacharacters) returns itself.
* Every glob reaching here is an absolute path, so there is always at least the
* leading separator to start from.
*/
const staticBase = (glob: string): string => {
const fixed: string[] = [];
for (const segment of normalize(glob).split(SEPARATOR)) {
if (GLOB_CHARS.test(segment)) break;
fixed.push(segment);
}
return fixed.join(SEPARATOR);
};

/** Every file a glob names below `basePath` — or the path itself, when the
* glob named an exact file rather than somewhere to look. */
const matchesUnder = (
base: Deno.FileInfo,
basePath: string,
matches: (path: string) => boolean,
): Promise<string[]> =>
base.isDirectory
? collectFiles(basePath, matches)
: Promise.resolve(matches(basePath) ? [basePath] : []);

/**
* The files these globs name, sorted and without repeats. A glob whose
* directory is not there names no files rather than failing: the changed set a
* run is given is a branch's committed diff, which still names test files that
* have since moved.
*/
export const expand = async (
globs: string[],
from: string = Deno.cwd(),
): Promise<string[]> => {
const paths = new Set<string>();
for (const glob of globs) {
const absGlob = join(from, glob);
const pattern = globToRegExp(absGlob, { extended: true, globstar: true });
const basePath = staticBase(absGlob);
const base = await statOrNull(basePath);
if (base === null) continue;
for (const path of await matchesUnder(base, basePath, (candidate) =>
pattern.test(candidate),
)) {
paths.add(path);
}
}
return [...paths].sort();
};
4 changes: 2 additions & 2 deletions scripts/mutation/isolation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { isAbsolute, join, relative, resolve, SEPARATOR } from "@std/path";
import * as v from "valibot";
import { projectRoot } from "#scripts/project-root.ts";
import { directoryEntries } from "#scripts/walk-files.ts";

export const MUTATION_RUNS_DIR = ".mutation-runs";
export const MUTATION_WORK_DIR = "work";
Expand Down Expand Up @@ -139,8 +140,7 @@ const copyDirectory = async (
const toDir = join(toRoot, relativePath);
await Deno.mkdir(toDir, { recursive: true });

const entries: Deno.DirEntry[] = [];
for await (const entry of Deno.readDir(fromDir)) entries.push(entry);
const entries = await directoryEntries(fromDir);
Comment thread
stefan-burke marked this conversation as resolved.
Resolved

for (const entry of entries.sort((left, right) =>
left.name.localeCompare(right.name),
Expand Down
19 changes: 17 additions & 2 deletions scripts/walk-files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { join } from "@std/path";

/**
* What `directory` holds, as a list. A directory that is not there fails here,
* loudly: a caller asking to walk somewhere that has gone is asking about a
* root it believes in, and answering "nothing" would read as "nothing to do".
*/
export const directoryEntries = async (
directory: string,
): Promise<Deno.DirEntry[]> => {
const entries: Deno.DirEntry[] = [];
for await (const entry of Deno.readDir(directory)) entries.push(entry);
return entries;
};
Comment thread
stefan-burke marked this conversation as resolved.
Resolved

/** Recursively yield every file path beneath `directory` (depth-first). */
export async function* walkFiles(directory: string): AsyncGenerator<string> {
for await (const entry of Deno.readDir(directory)) {
const path = `${directory}/${entry.name}`;
for (const entry of await directoryEntries(directory)) {
const path = join(directory, entry.name);
if (entry.isDirectory) {
yield* walkFiles(path);
continue;
Expand Down
15 changes: 8 additions & 7 deletions src/features/admin/attendee-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import { getSearchParam } from "#routes/url.ts";
import { getAttendeeOrNull } from "#shared/db/attendees/queries.ts";
import {
createOwnerNote,
deleteAttendeeNote,
getAttendeeNote,
type SystemNote,
} from "#shared/db/system-notes.ts";
deleteNotes,
getNote,
} from "#shared/db/notes/queries.ts";
import { attendeeNotes } from "#shared/db/notes/target.ts";
import type { SystemNote } from "#shared/db/notes/types.ts";
import type { ResponseHandler } from "#shared/response-steps.ts";
import { requireRequestPrivateKey } from "#shared/session-private-key.ts";
import type { AdminSession, Attendee } from "#shared/types.ts";
Expand Down Expand Up @@ -73,7 +74,7 @@ const loadNote = async ({
attendeeId,
noteId,
}: NoteRouteParams): Promise<SystemNote | null> =>
getAttendeeNote(attendeeId, noteId, await requireRequestPrivateKey());
getNote(attendeeNotes(attendeeId), noteId, await requireRequestPrivateKey());
const noteEntityHandler = createEntityHandler<NoteRouteParams, SystemNote>(
loadNote,
);
Expand Down Expand Up @@ -134,7 +135,7 @@ const handleAddNotePost: TypedRouteHandler<"POST /admin/attendee/:attendeeId/not
400,
);
}
await createOwnerNote(attendeeId, note);
await createOwnerNote(attendeeNotes(attendeeId), note);
return redirect(
returnTarget(attendeeId, returnUrl),
t("notes.added"),
Expand Down Expand Up @@ -162,7 +163,7 @@ const handleDeleteNoteGet: TypedRouteHandler<"GET /admin/attendee/:attendeeId/no
/** POST /admin/attendee/:attendeeId/note/:noteId/delete — delete the note. */
const handleDeleteNotePost: TypedRouteHandler<"POST /admin/attendee/:attendeeId/note/:noteId/delete"> =
noteHandlers.post(async (note, _session, form, _request, { attendeeId }) => {
await deleteAttendeeNote(attendeeId, note.id);
await deleteNotes(attendeeNotes(attendeeId), [note.id]);
return redirect(
returnTarget(attendeeId, form.getString("return_url")),
t("notes.deleted"),
Expand Down
7 changes: 4 additions & 3 deletions src/features/admin/attendee-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ import { loadPreviousBookings } from "#routes/admin/previous-bookings.ts";
import { requireSessionOr } from "#routes/auth.ts";
import { getEffectiveDomain } from "#shared/config.ts";
import { attendeeStatuses } from "#shared/db/attendee-statuses.ts";
import { getNotesFor } from "#shared/db/notes/queries.ts";
import { attendeeNotes } from "#shared/db/notes/target.ts";
import { settings } from "#shared/db/settings.ts";
import { getNotesForAttendee } from "#shared/db/system-notes.ts";
import { isReadOnly } from "#shared/env.ts";
import { requireRequestPrivateKey } from "#shared/session-private-key.ts";
import { isOwnerRole } from "#shared/types.ts";
Expand Down Expand Up @@ -201,8 +202,8 @@ export const attendeePage: EntityPage<LoadedAttendee> = defineEntityPage({
attendeeBanner({
attendee,
isOwner: ctx.session.adminLevel === "owner",
notes: await getNotesForAttendee(
attendee.id,
notes: await getNotesFor(
attendeeNotes(attendee.id),
await requireRequestPrivateKey(),
),
statuses: await attendeeStatuses.getAll(),
Expand Down
31 changes: 19 additions & 12 deletions src/features/admin/attendees-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ import { logActivity } from "#shared/db/activityLog.ts";
import { decryptAttendeeOrNull } from "#shared/db/attendees/pii.ts";
import { getAttendeeRaw } from "#shared/db/attendees/queries.ts";
import { queryOne } from "#shared/db/client.ts";
import {
createSystemNote,
deleteNotes,
getNotesFor,
} from "#shared/db/notes/queries.ts";
import { attendeeNotes } from "#shared/db/notes/target.ts";
import {
getRefundPaymentReferencesForAttendee,
markPaymentReferencesProviderRefunded,
type RefundPaymentReference,
} from "#shared/db/payment-references.ts";
import {
createSystemNote,
deleteAttendeeNote,
getNotesForAttendee,
} from "#shared/db/system-notes.ts";
import type { FormParams } from "#shared/form-data.ts";
import { legMatches } from "#shared/ledger/legs.ts";
import type { PaymentProvider } from "#shared/payments.ts";
Expand Down Expand Up @@ -151,7 +152,10 @@ const recordConfirmedRefund = async (
// stale note could still be there if the previous cleanup failed).
await cleanupStaleManualRefundNote(attendeeId, privateKey);
if (isPlaceholder) {
await createSystemNote(attendeeId, t("note.placeholder_refund_confirmed"));
await createSystemNote(
attendeeNotes(attendeeId),
t("note.placeholder_refund_confirmed"),
);
}
return null;
};
Expand All @@ -164,12 +168,15 @@ const cleanupStaleManualRefundNote = async (
attendeeId: number,
privateKey: CryptoKey,
): Promise<void> => {
const notes = await getNotesForAttendee(attendeeId, privateKey);
for (const note of notes) {
if (note.type === "system" && note.note.includes("could NOT be refunded")) {
await deleteAttendeeNote(attendeeId, note.id);
}
}
const notes = await getNotesFor(attendeeNotes(attendeeId), privateKey);
const stale = notes.filter(
(note) =>
note.type === "system" && note.note.includes("could NOT be refunded"),
);
await deleteNotes(
attendeeNotes(attendeeId),
stale.map((note) => note.id),
);
};

/** Load the attendee, listing, and payment references for a refresh. Returns
Expand Down
2 changes: 1 addition & 1 deletion src/features/admin/attendees-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
} from "#shared/db/attendees/queries.ts";
import { getActiveHolidays } from "#shared/db/holidays.ts";
import { getAllListings } from "#shared/db/listings/records.ts";
import { loadNotesForAttendees } from "#shared/db/notes/queries.ts";
import { settings } from "#shared/db/settings.ts";
import { loadNotesForAttendees } from "#shared/db/system-notes.ts";
import {
type ListingFilter,
listingCategory,
Expand Down
Loading