Fifth revision: share-link AI safety, sturdier generation, cleaner UI
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 1m0s

- Malformed model JSON is sent back for repair, then retried; a failed job
  starts over once before it fails. Visitors can dismiss failed sets.
- Generated sets get a short distinct name and description; flashcards are
  atomic and have no hints; standard study shows known/learning counts.
- Share links: "In progress" list, finished sets join the normal lists with a
  "New" tag, plain progress steps, newest exam first.
- Share-link AI expires after a week, can be limited to the US or Arizona
  (DB-IP Lite or Cloudflare headers) and is locked by abuse protection
  (migration 8).
- The assistant never answers from general knowledge; MCP and web search
  tools load without a manual test.
- Plain-text copy, no question count in exam mode, filler text removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-11-16 09:17:50 -07:00
parent d8df5edf30
commit 85d5c9186d
46 changed files with 1242 additions and 283 deletions

View file

@ -18,6 +18,8 @@ export interface MockAi {
failNext: (status: number, times?: number) => void;
/** Delay every chat call by this many milliseconds (0 turns it off). */
delayChat: (ms: number) => void;
/** The next N calls of this tool send arguments that are not valid JSON (beyond jsonrepair). */
badJsonNext: (tool: string, times?: number) => void;
close: () => Promise<void>;
}
@ -90,7 +92,9 @@ function toolArgs(name: string, userText: string, all: string): Record<string, u
}
return { questions: questions(count, refs, offset) };
case 'submit_flashcards':
return { cards: Array.from({ length: count }, (_, i) => ({ front: `Mock term ${i + 1 + offset}`, back: `Mock definition ${i + 1 + offset}`, hint: '', tags: ['mock'] })) };
return { cards: Array.from({ length: count }, (_, i) => ({ front: `Mock term ${i + 1 + offset}`, back: `Mock definition ${i + 1 + offset}`, tags: ['mock'] })) };
case 'name_set':
return /quiz of/i.test(userText) ? { title: 'Heart Failure and Pharmacology', description: 'Covers heart failure care and the drugs used for it.' } : { title: 'Mock Terms', description: 'Covers the mock terms.' };
case 'generate_quiz':
return { count: Math.min(count, 5), topic: 'heart failure', style: 'nclex', use_all_class_documents: /document/i.test(userText), from_weak_areas: /wrong|weak|miss/i.test(userText) };
case 'generate_flashcards':
@ -146,6 +150,7 @@ export function startMockAi(port = 0): Promise<MockAi> {
const requests: MockAi['requests'] = [];
let fail = { status: 0, times: 0 };
let delayMs = 0;
let badJson: { tool: string; times: number } | null = null;
const server = http.createServer((req, res) => {
const chunks: Buffer[] = [];
@ -198,7 +203,11 @@ export function startMockAi(port = 0): Promise<MockAi> {
res.end();
};
const callTool = (name: string) => {
const args = JSON.stringify(toolArgs(name, userText, all));
let args = JSON.stringify(toolArgs(name, userText, all));
if (badJson && badJson.tool === name && badJson.times > 0) {
badJson.times -= 1;
args = '{"cards": [{"front": "Broken" "back": ]]]} :: not json';
}
send({ role: 'assistant', content: null, tool_calls: [{ index: 0, id: `call_${Math.random().toString(36).slice(2, 10)}`, type: 'function', function: { name, arguments: '' } }] });
// Arguments arrive in fragments, like a real provider.
for (let i = 0; i < args.length; i += 37) send({ tool_calls: [{ index: 0, function: { arguments: args.slice(i, i + 37) } }] });
@ -265,6 +274,9 @@ export function startMockAi(port = 0): Promise<MockAi> {
delayChat: (ms) => {
delayMs = ms;
},
badJsonNext: (tool, times = 1) => {
badJson = { tool, times };
},
close: () => new Promise((done) => server.close(() => done())),
});
});