Repository navigation
Prove the tests catch real mistakes, and tell the admin stories in plain English #2011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
7fd1e90
6a6fe10
707a48e
1b2d2a1
b57c9b4
21ea8a8
b5c2565
dbd1025
52910d3
9528978
596ce08
dd448a9
32c2aed
93c6dba
b70bd07
2ec5a06
606d218
27c7203
db8219e
c985d99
1813dcf
d669a9f
1f58f63
c0cc322
c4506a1
cb80ec6
8c5702f
5ee84cc
adf3ace
85a9d20
da36269
8463395
5a33bdf
9f15574
1e915f2
89e0a47
2e81e83
9b5e2b8
3b82cfe
730c254
d8a843b
1748578
79bbcfd
e7a6912
e1fdb04
c63fa7d
4fdf504
28c2a21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ import { getAllListings } from "#shared/db/listings/records.ts"; | |
| import { getAllModifiers } from "#shared/db/modifiers.ts"; | ||
| import { | ||
| flatCollectionSwap, | ||
| insertScopedOrderedRow, | ||
| scopedCollectionSwap, | ||
| } from "#shared/db/ordered-collection.ts"; | ||
| import { | ||
|
|
@@ -174,17 +175,22 @@ const handleQuestionsPost = createAuthedFormRoute({ | |
| onInvalid: ({ error }) => errorRedirect("/admin/questions", error), | ||
| onValid: async ({ values: { display_type, text } }) => { | ||
| const displayType = requireQuestionDisplayType(display_type); | ||
| const question = await questionsTable.insert({ | ||
| displayType, | ||
| text, | ||
| }); | ||
| await questionsOrder.append({ key: question.id }); | ||
| await logActivity(`Question '${text}' created`); | ||
| return redirect( | ||
| `/admin/questions/${question.id}`, | ||
| "Question created", | ||
| true, | ||
| // One transaction: a question must never exist without its order entry | ||
| // or its log line. | ||
| const questionId = await writeRowInTransaction( | ||
|
Comment on lines
+98
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This refactor grows AGENTS.md reference: AGENTS.md:L82-L82 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 52910d3 — the module is now three files: Generated by Claude Code |
||
| await questionsTable.insertStatement!({ displayType, text }), | ||
| null, | ||
| async (transaction, id) => { | ||
| await questionsOrder.append({ key: id, transaction }); | ||
|
Comment on lines
+100
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fresh evidence beyond the resolved attribute review is that this later change also makes question and answer creation atomic, but the question suites never force AGENTS.md reference: AGENTS.md:L84-L84 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 52910d3 (and refined in 596ce08) — route-level failing-append tests now cover both creations: Generated by Claude Code |
||
| await logActivity( | ||
| `Question '${text}' created`, | ||
| undefined, | ||
| undefined, | ||
| transaction, | ||
| ); | ||
| }, | ||
| ); | ||
| return redirect(`/admin/questions/${questionId}`, "Question created", true); | ||
| }, | ||
| }); | ||
|
|
||
|
|
@@ -284,17 +290,27 @@ const handleAddAnswer = createAuthedFormRoute< | |
| "Free-text questions don't have answer options", | ||
| ); | ||
| } | ||
| const answer = await answersTable.insert({ | ||
| questionId: params.id, | ||
| sortOrder: 0, | ||
| text, | ||
| }); | ||
| await answersOrder.append({ key: answer.id, scope: params.id }); | ||
| await logActivity(`Answer '${text}' added to question ${params.id}`); | ||
| // One transaction: an answer must never exist without its place in the | ||
| // order or its log line. The inserted sortOrder is a placeholder the | ||
| // append overwrites before anything can read it. | ||
| await addAnswerRow( | ||
| params.id, | ||
| { questionId: params.id, sortOrder: 0, text }, | ||
| (transaction) => | ||
| logActivity( | ||
| `Answer '${text}' added to question ${params.id}`, | ||
| undefined, | ||
| undefined, | ||
| transaction, | ||
| ), | ||
| ); | ||
| return redirect(`/admin/questions/${params.id}`, "Answer added", true); | ||
| }, | ||
| }); | ||
|
|
||
| /** Insert an answer and place it in its question's order, atomically. */ | ||
| const addAnswerRow = insertScopedOrderedRow(answersTable, answersOrder); | ||
|
|
||
| /** Confirmed-delete handlers for questions */ | ||
| const questionDelete = createConfirmedHandlers<QuestionWithAnswers>({ | ||
| // The confirmation page shows the flattened text (newlines → " / "), and a | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { | |
| resultRows, | ||
| type TxScope, | ||
| useTransaction, | ||
| writeRowInTransaction, | ||
| } from "#shared/db/client.ts"; | ||
|
|
||
| type Columns = string | readonly [string, ...string[]]; | ||
|
|
@@ -194,3 +195,39 @@ export const defineOrderedCollection = < | |
|
|
||
| return { append, next, nextMany, swap }; | ||
| }; | ||
|
|
||
| /** | ||
| * Insert a child row and give it the next place in its scoped order — one | ||
| * transaction, with any extra writes (like the log line) riding along. A | ||
| * failed order write or log rolls the insert back with it. | ||
| */ | ||
| export const insertScopedOrderedRow = | ||
| <Input>( | ||
|
Comment on lines
+211
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The returned closure has a AGENTS.md reference: AGENTS.md:L97-L97 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 52910d3 — the curried type now has a name, Generated by Claude Code |
||
| table: { | ||
| insertStatement?: (input: Input) => Promise<{ | ||
| args: InValue[]; | ||
| sql: string; | ||
| }>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If this shared helper is passed one of the façade tables that legitimately omits AGENTS.md reference: AGENTS.md:L128-L137 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 32c2aed — Generated by Claude Code |
||
| }, | ||
| order: { | ||
| append: (operation: { | ||
| key: number; | ||
| scope: number; | ||
| transaction: TxScope; | ||
| }) => Promise<void>; | ||
| }, | ||
| ) => | ||
| ( | ||
| scope: number, | ||
| input: Input, | ||
| log: (transaction: TxScope) => Promise<unknown>, | ||
| ): Promise<number> => | ||
| (async () => | ||
| writeRowInTransaction( | ||
| await table.insertStatement!(input), | ||
| null, | ||
| async (transaction, id) => { | ||
| await order.append({ key: id, scope, transaction }); | ||
| await log(transaction); | ||
| }, | ||
| ))(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These additions take
scripts/mutation/equivalent-mutants.txtfrom 996 to 1,008 lines, crossing the repository's hard 1,000-line ceiling. Refactor the ignore loader to consume focused registry files, or otherwise split this registry, instead of continuing to append proofs to a single oversized file.AGENTS.md reference: AGENTS.md:L82-L82
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9528978 — the registry is now the
scripts/mutation/equivalent-mutants/directory: nine focused per-area files (largest 236 lines) plus a README with the recording rules.loadIgnoreListmerges every*.txtin the directory, the static audit checks and prunes each file in place, and cross-file duplicates fail the run just as same-file ones did. Covered by new loader and audit tests (directory merge, cross-file duplicate, per-file prune).Generated by Claude Code